1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # common routines for gl, ar, ap, is, ir, oe
33 # any custom scripts for this one
34 if (-f "$form->{path}/custom_arap.pl") {
35 eval { require "$form->{path}/custom_arap.pl"; };
37 if (-f "$form->{path}/$form->{login}_arap.pl") {
38 eval { require "$form->{path}/$form->{login}_arap.pl"; };
47 $lxdebug->enter_sub();
51 my ($new_name, $new_id) = split /--/, $form->{$name};
54 # if we use a selection
55 if ($form->{"select$name"}) {
56 if ($form->{"old$name"} ne $form->{$name}) {
57 # this is needed for is, ir and oe
59 # for credit calculations
60 $form->{oldinvtotal} = 0;
61 $form->{oldtotalpaid} = 0;
64 $form->{"${name}_id"} = $new_id;
66 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
67 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
69 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
75 # check name, combine name and id
76 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
77 # this is needed for is, ir and oe
79 # for credit calculations
80 $form->{oldinvtotal} = 0;
81 $form->{oldtotalpaid} = 0;
84 # return one name or a list of names in $form->{name_list}
85 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
92 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
93 $form->{$name} = $form->{name_list}[0]->{name};
94 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
96 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
97 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
100 # name is not on file
101 $msg = ucfirst $name . " not on file or locked!";
102 $form->error($locale->text($msg));
107 $lxdebug->leave_sub();
112 # $locale->text('Customer not on file!')
113 # $locale->text('Vendor not on file!')
118 $lxdebug->enter_sub();
122 @column_index = qw(ndx name address);
124 $label = ucfirst $table;
125 $column_data{ndx} = qq|<th> </th>|;
126 $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
127 $column_data{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|;
129 # list items with radio button on a form
132 $title = $locale->text('Select from one of the names below');
137 <form method=post action=$form->{script}>
141 <th class=listtop>$title</th>
147 <tr class=listheading>|;
149 map { print "\n$column_data{$_}" } @column_index;
156 foreach $ref (@{ $form->{name_list} }) {
157 $checked = ($i++) ? "" : "checked";
159 $ref->{name} =~ s/\"/"/g;
161 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
162 $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
163 $column_data{address} = qq|<td>$ref->{address} </td>|;
167 <tr class=listrow$j>|;
169 map { print "\n$column_data{$_}" } @column_index;
174 <input name="new_id_$i" type=hidden value=$ref->{id}>
185 <td><hr size=3 noshade></td>
189 <input name=lastndx type=hidden value=$i>
194 map { delete $form->{$_} } qw(action name_list header);
196 # save all other form variables
197 foreach $key (keys %${form}) {
198 $form->{$key} =~ s/\"/"/g;
199 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
203 <input type=hidden name=nextsub value=name_selected>
205 <input type=hidden name=vc value=$table>
207 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
214 $lxdebug->leave_sub();
220 $lxdebug->enter_sub();
223 # replace the variable with the one checked
228 $form->{$form->{vc}} = $form->{"new_name_$i"};
229 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
230 $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
232 # delete all the new_ variables
233 for $i (1 .. $form->{lastndx}) {
234 map { delete $form->{"new_${_}_$i"} } (id, name);
237 map { delete $form->{$_} } qw(ndx lastndx nextsub);
239 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
240 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
244 $lxdebug->leave_sub();
248 sub add_transaction {
249 $lxdebug->enter_sub();
253 delete $form->{script};
254 $form->{action} = "add";
255 $form->{type} = "invoice" if $module =~ /(is|ir)/;
257 $form->{callback} = $form->escape($form->{callback},1);
258 map { $argv .= "$_=$form->{$_}&" } keys %$form;
260 $form->{callback} = "$module.pl?$argv";
264 $lxdebug->leave_sub();
270 $lxdebug->enter_sub();
273 for $i (1 .. $form->{rowcount}) {
274 $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
275 if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) {
276 if ($form->{"projectnumber_$i"}) {
278 $form->{projectnumber} = $form->{"projectnumber_$i"};
279 if (($rows = PE->projects(\%myconfig, $form)) > 1) {
280 # check form->{project_list} how many there are
281 $form->{rownumber} = $i;
287 $form->{"project_id_$i"} = $form->{project_list}->[0]->{id};
288 $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
289 $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
292 $form->error($locale->text('Project not on file!'));
295 $form->{"oldprojectnumber_$i"} = "";
300 $lxdebug->leave_sub();
305 $lxdebug->enter_sub();
308 @column_index = qw(ndx projectnumber description);
310 $column_data{ndx} = qq|<th> </th>|;
311 $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|;
312 $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|;
314 # list items with radio button on a form
317 $title = $locale->text('Select from one of the projects below');
322 <form method=post action=$form->{script}>
324 <input type=hidden name=rownumber value=$form->{rownumber}>
328 <th class=listtop>$title</th>
334 <tr class=listheading>|;
336 map { print "\n$column_data{$_}" } @column_index;
343 foreach $ref (@{ $form->{project_list} }) {
344 $checked = ($i++) ? "" : "checked";
346 $ref->{name} =~ s/\"/"/g;
348 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
349 $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
350 $column_data{description} = qq|<td>$ref->{description}</td>|;
354 <tr class=listrow$j>|;
356 map { print "\n$column_data{$_}" } @column_index;
361 <input name="new_id_$i" type=hidden value=$ref->{id}>
372 <td><hr size=3 noshade></td>
376 <input name=lastndx type=hidden value=$i>
380 # delete action variable
381 map { delete $form->{$_} } qw(action project_list header);
383 # save all other form variables
384 foreach $key (keys %${form}) {
385 $form->{$key} =~ s/\"/"/g;
386 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
390 <input type=hidden name=nextsub value=project_selected>
393 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
400 $lxdebug->leave_sub();
404 sub project_selected {
405 $lxdebug->enter_sub();
408 # replace the variable with the one checked
413 $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
414 $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
415 $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
417 # delete all the new_ variables
418 for $i (1 .. $form->{lastndx}) {
419 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
422 map { delete $form->{$_} } qw(ndx lastndx nextsub);
424 if ($form->{update}) {
425 &{ $form->{update} };
430 $lxdebug->leave_sub();
434 sub continue { &{ $form->{nextsub} } };
435 sub gl_transaction { &add };
436 sub ar_transaction { &add_transaction(ar) };
437 sub ap_transaction { &add_transaction(ap) };
438 sub sales_invoice { &add_transaction(is) };
439 sub vendor_invoice { &add_transaction(ir) };