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
35 # any custom scripts for this one
36 if (-f "bin/mozilla/custom_arap.pl") {
37 eval { require "bin/mozilla/custom_arap.pl"; };
39 if (-f "bin/mozilla/$form->{login}_arap.pl") {
40 eval { require "bin/mozilla/$form->{login}_arap.pl"; };
45 require "bin/mozilla/common.pl";
50 $lxdebug->enter_sub();
52 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
53 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
57 $name = $name eq "customer" ? "customer" : "vendor";
59 my ($new_name, $new_id) = split /--/, $form->{$name};
61 # if we use a selection
62 if ($form->{"select$name"}) {
63 if ($form->{"old$name"} ne $form->{$name}) {
65 # this is needed for is, ir and oe
67 # for credit calculations
68 $form->{oldinvtotal} = 0;
69 $form->{oldtotalpaid} = 0;
72 $form->{"${name}_id"} = $new_id;
74 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
75 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
77 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
83 # check name, combine name and id
84 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
86 # this is needed for is, ir and oe
89 # for credit calculations
90 $form->{oldinvtotal} = 0;
91 $form->{oldtotalpaid} = 0;
94 # return one name or a list of names in $form->{name_list}
95 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
103 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
104 $form->{$name} = $form->{name_list}[0]->{name};
105 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
107 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
108 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
112 # name is not on file
113 # $locale->text('Customer not on file or locked!')
114 # $locale->text('Vendor not on file or locked!')
115 $msg = ucfirst $name . " not on file or locked!";
116 $form->error($locale->text($msg));
120 $form->language_payment(\%myconfig);
122 $lxdebug->leave_sub();
127 # $locale->text('Customer not on file!')
128 # $locale->text('Vendor not on file!')
131 $lxdebug->enter_sub();
133 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
134 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
138 @column_index = qw(ndx name address);
140 $label = ucfirst $table;
141 $column_data{ndx} = qq|<th> </th>|;
143 qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
144 $column_data{address} =
145 qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
147 # list items with radio button on a form
150 $title = $locale->text('Select from one of the names below');
155 <form method=post action=$form->{script}>
159 <th class=listtop>$title</th>
165 <tr class=listheading>|;
167 map { print "\n$column_data{$_}" } @column_index;
174 foreach $ref (@{ $form->{name_list} }) {
175 $checked = ($i++) ? "" : "checked";
177 $ref->{name} =~ s/\"/"/g;
180 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
182 qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
183 $column_data{address} = qq|<td>$ref->{address} </td>|;
188 <tr class=listrow$j>|;
190 map { print "\n$column_data{$_}" } @column_index;
195 <input name="new_id_$i" type=hidden value=$ref->{id}>
206 <td><hr size=3 noshade></td>
210 <input name=lastndx type=hidden value=$i>
215 map { delete $form->{$_} } qw(action name_list header);
217 # save all other form variables
218 foreach $key (keys %${form}) {
219 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
220 $form->{$key} =~ s/\"/"/g;
221 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
225 <input type=hidden name=nextsub value=name_selected>
227 <input type=hidden name=vc value=$table>
229 <input class=submit type=submit name=action value="|
230 . $locale->text('Continue') . qq|">
237 $lxdebug->leave_sub();
241 $lxdebug->enter_sub();
243 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
244 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
246 # replace the variable with the one checked
251 $form->{ $form->{vc} } = $form->{"new_name_$i"};
252 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
253 $form->{"old$form->{vc}"} =
254 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
256 # delete all the new_ variables
257 for $i (1 .. $form->{lastndx}) {
258 map { delete $form->{"new_${_}_$i"} } qw(id name);
261 map { delete $form->{$_} } qw(ndx lastndx nextsub);
263 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
264 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
268 $lxdebug->leave_sub();
272 $lxdebug->enter_sub();
274 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
275 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
277 for $i (1 .. $form->{rowcount}) {
278 my $suffix = $i ? "_$i" : "";
279 my $prefix = $i ? "" : "global";
280 $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
281 if ($form->{"${prefix}projectnumber${suffix}"} ne $form->{"old${prefix}projectnumber${suffix}"}) {
282 if ($form->{"${prefix}projectnumber${suffix}"}) {
285 $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
286 my %params = map { $_ => $form->{$_} } qw(projectnumber description active);
287 if (($rows = Projects->search_projects(%params)) > 1) {
289 # check form->{project_list} how many there are
290 $form->{rownumber} = $i;
291 &select_project($i ? undef : 1);
296 $form->{"${prefix}project_id${suffix}"} = $form->{project_list}->[0]->{id};
297 $form->{"${prefix}projectnumber${suffix}"} = $form->{project_list}->[0]->{projectnumber};
298 $form->{"old${prefix}projectnumber${suffix}"} = $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 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
317 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
319 my ($is_global) = @_;
321 @column_index = qw(ndx projectnumber description);
323 $column_data{ndx} = qq|<th> </th>|;
324 $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
325 $column_data{description} =
326 qq|<th>| . $locale->text('Description') . qq|</th>|;
328 # list items with radio button on a form
331 $title = $locale->text('Select from one of the projects below');
336 <form method=post action=$form->{script}>
338 <input type=hidden name=rownumber value=$form->{rownumber}>
342 <th class=listtop>$title</th>
348 <tr class=listheading>|;
350 map { print "\n$column_data{$_}" } @column_index;
357 foreach $ref (@{ $form->{project_list} }) {
358 $checked = ($i++) ? "" : "checked";
360 $ref->{name} =~ s/\"/"/g;
363 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
364 $column_data{projectnumber} =
365 qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
366 $column_data{description} = qq|<td>$ref->{description}</td>|;
371 <tr class=listrow$j>|;
373 map { print "\n$column_data{$_}" } @column_index;
378 <input name="new_id_$i" type=hidden value=$ref->{id}>
389 <td><hr size=3 noshade></td>
393 <input name=lastndx type=hidden value=$i>
397 # delete action variable
398 map { delete $form->{$_} } qw(action project_list header update);
400 # save all other form variables
401 foreach $key (keys %${form}) {
402 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
403 $form->{$key} =~ s/\"/"/g;
404 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
408 <input type="hidden" name="is_global" value="$is_global">
409 <input type=hidden name=nextsub value=project_selected>
412 <input class=submit type=submit name=action value="|
413 . $locale->text('Continue') . qq|">
420 $lxdebug->leave_sub();
423 sub project_selected {
424 $lxdebug->enter_sub();
426 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
427 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
429 # replace the variable with the one checked
434 my $prefix = $form->{"is_global"} ? "global" : "";
435 my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
437 $form->{"${prefix}projectnumber${suffix}"} =
438 $form->{"new_projectnumber_$i"};
439 $form->{"old${prefix}projectnumber${suffix}"} =
440 $form->{"new_projectnumber_$i"};
441 $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
443 # delete all the new_ variables
444 for $i (1 .. $form->{lastndx}) {
445 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
448 map { delete $form->{$_} } qw(ndx lastndx nextsub is_global);
450 if ($form->{update}) {
451 call_sub($form->{"update"});
456 $lxdebug->leave_sub();
459 sub continue { call_sub($form->{"nextsub"}); }