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"; };
46 $lxdebug->enter_sub();
50 my ($new_name, $new_id) = split /--/, $form->{$name};
52 # if we use a selection
53 if ($form->{"select$name"}) {
54 if ($form->{"old$name"} ne $form->{$name}) {
56 # this is needed for is, ir and oe
58 # for credit calculations
59 $form->{oldinvtotal} = 0;
60 $form->{oldtotalpaid} = 0;
63 $form->{"${name}_id"} = $new_id;
65 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
66 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
68 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
74 # check name, combine name and id
75 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
77 # this is needed for is, ir and oe
80 # for credit calculations
81 $form->{oldinvtotal} = 0;
82 $form->{oldtotalpaid} = 0;
85 # return one name or a list of names in $form->{name_list}
86 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
94 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
95 $form->{$name} = $form->{name_list}[0]->{name};
96 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
98 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
99 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
103 # name is not on file
104 $msg = ucfirst $name . " not on file or locked!";
105 $form->error($locale->text($msg));
109 $form->language_payment(\%myconfig);
111 $lxdebug->leave_sub();
116 # $locale->text('Customer not on file!')
117 # $locale->text('Vendor not on file!')
120 $lxdebug->enter_sub();
124 @column_index = qw(ndx name address);
126 $label = ucfirst $table;
127 $column_data{ndx} = qq|<th> </th>|;
129 qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
130 $column_data{address} =
131 qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
133 # list items with radio button on a form
136 $title = $locale->text('Select from one of the names below');
141 <form method=post action=$form->{script}>
145 <th class=listtop>$title</th>
151 <tr class=listheading>|;
153 map { print "\n$column_data{$_}" } @column_index;
160 foreach $ref (@{ $form->{name_list} }) {
161 $checked = ($i++) ? "" : "checked";
163 $ref->{name} =~ s/\"/"/g;
166 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
168 qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
169 $column_data{address} = qq|<td>$ref->{address} </td>|;
174 <tr class=listrow$j>|;
176 map { print "\n$column_data{$_}" } @column_index;
181 <input name="new_id_$i" type=hidden value=$ref->{id}>
192 <td><hr size=3 noshade></td>
196 <input name=lastndx type=hidden value=$i>
201 map { delete $form->{$_} } qw(action name_list header);
203 # save all other form variables
204 foreach $key (keys %${form}) {
205 $form->{$key} =~ s/\"/"/g;
206 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
210 <input type=hidden name=nextsub value=name_selected>
212 <input type=hidden name=vc value=$table>
214 <input class=submit type=submit name=action value="|
215 . $locale->text('Continue') . qq|">
222 $lxdebug->leave_sub();
226 $lxdebug->enter_sub();
228 # replace the variable with the one checked
233 $form->{ $form->{vc} } = $form->{"new_name_$i"};
234 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
235 $form->{"old$form->{vc}"} =
236 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
238 # delete all the new_ variables
239 for $i (1 .. $form->{lastndx}) {
240 map { delete $form->{"new_${_}_$i"} } qw(id name);
243 map { delete $form->{$_} } qw(ndx lastndx nextsub);
245 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
246 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
250 $lxdebug->leave_sub();
253 sub add_transaction {
254 $lxdebug->enter_sub();
258 delete $form->{script};
259 $form->{action} = "add";
260 $form->{type} = "invoice" if $module =~ /(is|ir)/;
262 $form->{callback} = $form->escape($form->{callback}, 1);
263 map { $argv .= "$_=$form->{$_}&" } keys %$form;
265 $form->{callback} = "$module.pl?$argv";
269 $lxdebug->leave_sub();
273 $lxdebug->enter_sub();
275 for $i (1 .. $form->{rowcount}) {
276 my $suffix = $i ? "_$i" : "";
277 my $prefix = $i ? "" : "global";
278 $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
279 if ($form->{"${prefix}projectnumber${suffix}"} ne $form->{"old${prefix}projectnumber${suffix}"}) {
280 if ($form->{"${prefix}projectnumber${suffix}"}) {
283 $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
284 if (($rows = PE->projects(\%myconfig, $form)) > 1) {
286 # check form->{project_list} how many there are
287 $form->{rownumber} = $i;
288 &select_project($i ? undef : 1);
293 $form->{"${prefix}project_id${suffix}"} =
294 $form->{project_list}->[0]->{id};
295 $form->{"${prefix}projectnumber${suffix}"} =
296 $form->{project_list}->[0]->{projectnumber};
297 $form->{"old${prefix}projectnumber${suffix}"} =
298 $form->{project_list}->[0]->{projectnumber};
302 $form->error($locale->text('Project not on file!'));
305 $form->{"old${prefix}projectnumber${suffix}"} = "";
310 $lxdebug->leave_sub();
314 $lxdebug->enter_sub();
316 my ($is_global) = @_;
318 @column_index = qw(ndx projectnumber description);
320 $column_data{ndx} = qq|<th> </th>|;
321 $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
322 $column_data{description} =
323 qq|<th>| . $locale->text('Description') . qq|</th>|;
325 # list items with radio button on a form
328 $title = $locale->text('Select from one of the projects below');
333 <form method=post action=$form->{script}>
335 <input type=hidden name=rownumber value=$form->{rownumber}>
339 <th class=listtop>$title</th>
345 <tr class=listheading>|;
347 map { print "\n$column_data{$_}" } @column_index;
354 foreach $ref (@{ $form->{project_list} }) {
355 $checked = ($i++) ? "" : "checked";
357 $ref->{name} =~ s/\"/"/g;
360 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
361 $column_data{projectnumber} =
362 qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
363 $column_data{description} = qq|<td>$ref->{description}</td>|;
368 <tr class=listrow$j>|;
370 map { print "\n$column_data{$_}" } @column_index;
375 <input name="new_id_$i" type=hidden value=$ref->{id}>
386 <td><hr size=3 noshade></td>
390 <input name=lastndx type=hidden value=$i>
394 # delete action variable
395 map { delete $form->{$_} } qw(action project_list header update);
397 # save all other form variables
398 foreach $key (keys %${form}) {
399 $form->{$key} =~ s/\"/"/g;
400 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
404 <input type="hidden" name="is_global" value="$is_global">
405 <input type=hidden name=nextsub value=project_selected>
408 <input class=submit type=submit name=action value="|
409 . $locale->text('Continue') . qq|">
416 $lxdebug->leave_sub();
419 sub project_selected {
420 $lxdebug->enter_sub();
422 # replace the variable with the one checked
427 my $prefix = $form->{"is_global"} ? "global" : "";
428 my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
430 $form->{"${prefix}projectnumber${suffix}"} =
431 $form->{"new_projectnumber_$i"};
432 $form->{"old${prefix}projectnumber${suffix}"} =
433 $form->{"new_projectnumber_$i"};
434 $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
436 # delete all the new_ variables
437 for $i (1 .. $form->{lastndx}) {
438 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
441 map { delete $form->{$_} } qw(ndx lastndx nextsub is_global);
443 if ($form->{update}) {
444 &{ $form->{update} };
449 $lxdebug->leave_sub();
452 sub continue { &{ $form->{nextsub} } }
453 sub gl_transaction { &add }
454 sub ar_transaction { &add_transaction('ar') }
455 sub ap_transaction { &add_transaction('ap') }
456 sub sales_invoice { &add_transaction('is') }
457 sub vendor_invoice { &add_transaction('ir') }