35a7761cba5a04896d9cf54750ef187af2b8472f
[kivitendo-erp.git] / bin / mozilla / arap.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 # MA 02110-1335, USA.
29 #======================================================================
30 #
31 # common routines for gl, ar, ap, is, ir, oe
32 #
33
34 use strict;
35
36 # any custom scripts for this one
37 if (-f "bin/mozilla/custom_arap.pl") {
38   eval { require "bin/mozilla/custom_arap.pl"; };
39 }
40 if (-f "bin/mozilla/$::myconfig{login}_arap.pl") {
41   eval { require "bin/mozilla/$::myconfig{login}_arap.pl"; };
42 }
43
44 1;
45
46 require "bin/mozilla/common.pl";
47
48 # end of main
49
50 sub select_project {
51   $::lxdebug->enter_sub;
52
53   $::auth->assert('ar_transactions | ap_transactions | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
54                   'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash         | report');
55
56   my ($is_global, $nextsub) = @_;
57   my $project_list = delete $::form->{project_list};
58
59   map { delete $::form->{$_} } qw(action header update);
60
61   my @hiddens;
62   for my $key (keys %$::form) {
63     next if $key eq 'login' || $key eq 'password' || '' ne ref $::form->{$key};
64     push @hiddens, { key => $key, value => $::form->{$key} };
65   }
66   push @hiddens, { key => 'is_global',                value => $is_global },
67                  { key => 'project_selected_nextsub', value => $nextsub };
68
69   $::form->header;
70   print $::form->parse_html_template('arap/select_project', { hiddens => \@hiddens, project_list => $project_list });
71
72   $::lxdebug->leave_sub;
73 }
74
75 sub project_selected {
76   $main::lxdebug->enter_sub();
77
78   my $form     = $main::form;
79
80   $main::auth->assert('ar_transactions  | ap_transactions    | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
81                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash         | report');
82
83   # replace the variable with the one checked
84
85   # index for new item
86   my $i = $form->{ndx};
87
88   my $prefix = $form->{"is_global"} ? "global" : "";
89   my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
90
91   $form->{"${prefix}projectnumber${suffix}"} =
92     $form->{"new_projectnumber_$i"};
93   $form->{"old${prefix}projectnumber${suffix}"} =
94     $form->{"new_projectnumber_$i"};
95   $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
96
97   # delete all the new_ variables
98   for $i (1 .. $form->{lastndx}) {
99     map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
100   }
101
102   my $nextsub = $form->{project_selected_nextsub} || 'update';
103
104   map { delete $form->{$_} } qw(ndx lastndx nextsub is_global project_selected_nextsub);
105
106   call_sub($nextsub);
107
108   $main::lxdebug->leave_sub();
109 }
110
111 sub continue       { call_sub($main::form->{"nextsub"}); }
112
113 1;
114
115 __END__
116
117 =head1 NAME
118
119 arap.pl - helper functions or customer/vendor retrieval
120
121 =head1 SYNOPSIS
122
123  check_name('vendor')
124
125 =head1 DESCRIPTION
126
127 Don't use anyting in this file without extreme care, and even then be prepared for massive headaches.
128
129 It's a collection of helper routines that wrap the customer/vendor dropdown/textfield duality into something even complexer.
130
131 =cut