1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
24 # common routines for gl, ar, ap, is, ir, oe
27 # any custom scripts for this one
28 if (-f "$form->{path}/custom_arap.pl") {
29 eval { require "$form->{path}/custom_arap.pl"; };
31 if (-f "$form->{path}/$form->{login}_arap.pl") {
32 eval { require "$form->{path}/$form->{login}_arap.pl"; };
43 my ($new_name, $new_id) = split /--/, $form->{$name};
46 # if we use a selection
47 if ($form->{"select$name"}) {
48 if ($form->{"old$name"} ne $form->{$name}) {
49 # this is needed for is, ir and oe
50 map { delete $form->{"${_}_rate"} } (split / /, $form->{taxaccounts});
52 # for credit calculations
53 $form->{oldinvtotal} = 0;
54 $form->{oldtotalpaid} = 0;
56 $form->{"${name}_id"} = $new_id;
57 $form->{"old$name"} = "$new_name--$new_id";
59 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
60 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
66 # check name, combine name and id
67 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
68 # this is needed for is, ir and oe
69 map { delete $form->{"${_}_rate"} } (split / /, $form->{taxaccounts});
71 # for credit calculations
72 $form->{oldinvtotal} = 0;
73 $form->{oldtotalpaid} = 0;
75 # return one name or a list of names in $form->{name_list}
76 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
83 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
84 $form->{$name} = $form->{name_list}[0]->{name};
85 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
87 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
88 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
92 $msg = ucfirst $name . " not on file!";
93 $form->error($locale->text($msg));
102 # $locale->text('Customer not on file!')
103 # $locale->text('Vendor not on file!')
110 @column_index = qw(ndx name address);
112 $label = ucfirst $table;
113 $column_data{ndx} = qq|<th> </th>|;
114 $column_data{name} = qq|<th>|.$locale->text($label).qq|</th>|;
115 $column_data{address} = qq|<th>|.$locale->text('Address').qq|</th>|;
117 # list items with radio button on a form
120 $title = $locale->text('Select from one of the names below');
125 <form method=post action=$form->{script}>
129 <th class=listtop>$title</th>
135 <tr class=listheading>|;
137 map { print "\n$column_data{$_}" } @column_index;
144 foreach $ref (@{ $form->{name_list} }) {
145 $checked = ($i++) ? "" : "checked";
147 $ref->{name} =~ s/"/"/g;
149 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
150 $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
151 $column_data{address} = qq|<td>$ref->{address}</td>|;
155 <tr class=listrow$j>|;
157 map { print "\n$column_data{$_}" } @column_index;
162 <input name="new_id_$i" type=hidden value=$ref->{id}>
173 <td><hr size=3 noshade></td>
177 <input name=lastndx type=hidden value=$i>
181 # delete action variable
182 delete $form->{action};
183 delete $form->{name_list};
185 # save all other form variables
186 foreach $key (keys %${form}) {
187 $form->{$key} =~ s/"/"/g;
188 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
192 <input type=hidden name=nextsub value=name_selected>
194 <input type=hidden name=vc value=$table>
196 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
209 # replace the variable with the one checked
214 $form->{$form->{vc}} = $form->{"new_name_$i"};
215 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
216 $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
218 # delete all the new_ variables
219 for $i (1 .. $form->{lastndx}) {
220 map { delete $form->{"new_${_}_$i"} } (id, name);
223 map { delete $form->{$_} } qw(ndx lastndx nextsub);
225 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
226 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
233 sub add_transaction {
236 delete $form->{script};
237 $form->{action} = "add";
238 $form->{type} = "invoice" if $module =~ /(is|ir)/;
240 $form->{callback} = $form->escape($form->{callback},1);
241 map { $argv .= "$_=$form->{$_}&" } keys %$form;
243 exec ("perl", "$module.pl", $argv);
251 for $i (1 .. $form->{rowcount}) {
252 $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
253 if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) {
254 if ($form->{"projectnumber_$i"}) {
256 $form->{projectnumber} = $form->{"projectnumber_$i"};
257 if (($rows = PE->projects(\%myconfig, $form)) > 1) {
258 # check form->{project_list} how many there are
259 $form->{rownumber} = $i;
265 $form->{"project_id_$i"} = $form->{project_list}->[0]->{id};
266 $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
267 $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
270 $form->error($locale->text('Project not on file!'));
281 @column_index = qw(ndx projectnumber description);
283 $column_data{ndx} = qq|<th> </th>|;
284 $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|;
285 $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|;
287 # list items with radio button on a form
290 $title = $locale->text('Select from one of the projects below');
295 <form method=post action=$form->{script}>
297 <input type=hidden name=rownumber value=$form->{rownumber}>
301 <th class=listtop>$title</th>
307 <tr class=listheading>|;
309 map { print "\n$column_data{$_}" } @column_index;
316 foreach $ref (@{ $form->{project_list} }) {
317 $checked = ($i++) ? "" : "checked";
319 $ref->{name} =~ s/"/"/g;
321 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
322 $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
323 $column_data{description} = qq|<td>$ref->{description}</td>|;
327 <tr class=listrow$j>|;
329 map { print "\n$column_data{$_}" } @column_index;
334 <input name="new_id_$i" type=hidden value=$ref->{id}>
345 <td><hr size=3 noshade></td>
349 <input name=lastndx type=hidden value=$i>
353 # delete action variable
354 delete $form->{action};
355 delete $form->{project_list};
357 # save all other form variables
358 foreach $key (keys %${form}) {
359 $form->{$key} =~ s/"/"/g;
360 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
364 <input type=hidden name=nextsub value=project_selected>
367 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
377 sub project_selected {
379 # replace the variable with the one checked
384 $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
385 $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
386 $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
388 # delete all the new_ variables
389 for $i (1 .. $form->{lastndx}) {
390 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
393 map { delete $form->{$_} } qw(ndx lastndx nextsub);
400 sub continue { &{ $form->{nextsub} } };
401 sub gl_transaction { &add };
402 sub ar_transaction { &add_transaction(ar) };
403 sub ap_transaction { &add_transaction(ap) };
404 sub sales_invoice { &add_transaction(is) };
405 sub vendor_invoice { &add_transaction(ir) };