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
37 # any custom scripts for this one
38 if (-f "bin/mozilla/custom_arap.pl") {
39 eval { require "bin/mozilla/custom_arap.pl"; };
41 if (-f "bin/mozilla/$main::form->{login}_arap.pl") {
42 eval { require "bin/mozilla/$main::form->{login}_arap.pl"; };
47 require "bin/mozilla/common.pl";
52 $main::lxdebug->enter_sub();
54 my $form = $main::form;
55 my %myconfig = %main::myconfig;
56 my $locale = $main::locale;
58 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
59 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash |' .
60 'purchase_delivery_order_edit | sales_delivery_order_edit');
64 $name = $name eq "customer" ? "customer" : "vendor";
66 my ($new_name, $new_id) = split /--/, $form->{$name};
68 # if we use a selection
69 if ($form->{"select$name"}) {
70 if ($form->{"old$name"} ne $form->{$name}) {
72 # this is needed for is, ir and oe
74 # for credit calculations
75 $form->{oldinvtotal} = 0;
76 $form->{oldtotalpaid} = 0;
79 $form->{"${name}_id"} = $new_id;
81 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
82 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
84 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
90 # check name, combine name and id
91 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
93 # this is needed for is, ir and oe
96 # for credit calculations
97 $form->{oldinvtotal} = 0;
98 $form->{oldtotalpaid} = 0;
101 # return one name or a list of names in $form->{name_list}
102 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
110 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
111 $form->{$name} = $form->{name_list}[0]->{name};
112 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
114 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
115 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
119 # name is not on file
120 # $locale->text('Customer not on file or locked!')
121 # $locale->text('Vendor not on file or locked!')
122 my $msg = ucfirst $name . " not on file or locked!";
123 $form->error($locale->text($msg));
127 $form->language_payment(\%myconfig);
129 $main::lxdebug->leave_sub();
134 # $locale->text('Customer not on file!')
135 # $locale->text('Vendor not on file!')
138 $main::lxdebug->enter_sub();
140 my $form = $main::form;
141 my $locale = $main::locale;
143 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
144 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
148 my @column_index = qw(ndx name address);
150 my $label = ucfirst $table;
152 $column_data{ndx} = qq|<th> </th>|;
154 qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
155 $column_data{address} =
156 qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
158 # list items with radio button on a form
161 my $title = $locale->text('Select from one of the names below');
166 <form method=post action=$form->{script}>
170 <th class=listtop>$title</th>
176 <tr class=listheading>|;
178 map { print "\n$column_data{$_}" } @column_index;
186 foreach my $ref (@{ $form->{name_list} }) {
187 my $checked = ($i++) ? "" : "checked";
189 $ref->{name} =~ s/\"/"/g;
192 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
194 qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
195 $column_data{address} = qq|<td>$ref->{address} </td>|;
200 <tr class=listrow$j>|;
202 map { print "\n$column_data{$_}" } @column_index;
207 <input name="new_id_$i" type=hidden value=$ref->{id}>
218 <td><hr size=3 noshade></td>
222 <input name=lastndx type=hidden value=$i>
227 map { delete $form->{$_} } qw(action name_list header);
229 # save all other form variables
230 foreach my $key (keys %${form}) {
231 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
232 $form->{$key} =~ s/\"/"/g;
233 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
237 <input type=hidden name=nextsub value=name_selected>
239 <input type=hidden name=vc value=$table>
241 <input class=submit type=submit name=action value="|
242 . $locale->text('Continue') . qq|">
249 $main::lxdebug->leave_sub();
253 $main::lxdebug->enter_sub();
255 my $form = $main::form;
256 my %myconfig = %main::myconfig;
258 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
259 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
261 # replace the variable with the one checked
264 my $i = $form->{ndx};
266 $form->{ $form->{vc} } = $form->{"new_name_$i"};
267 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
268 $form->{"old$form->{vc}"} =
269 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
271 # delete all the new_ variables
272 for $i (1 .. $form->{lastndx}) {
273 map { delete $form->{"new_${_}_$i"} } qw(id name);
276 map { delete $form->{$_} } qw(ndx lastndx nextsub);
278 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
279 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
283 $main::lxdebug->leave_sub();
287 $main::lxdebug->enter_sub();
289 my $form = $main::form;
290 my $locale = $main::locale;
292 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
293 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
295 my $nextsub = shift || 'update';
297 for my $i (1 .. $form->{rowcount}) {
298 my $suffix = $i ? "_$i" : "";
299 my $prefix = $i ? "" : "global";
300 $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
301 if ($form->{"${prefix}projectnumber${suffix}"} ne $form->{"old${prefix}projectnumber${suffix}"}) {
302 if ($form->{"${prefix}projectnumber${suffix}"}) {
305 $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
306 my %params = map { $_ => $form->{$_} } qw(projectnumber description active);
308 if (($rows = Projects->search_projects(%params)) > 1) {
310 # check form->{project_list} how many there are
311 $form->{rownumber} = $i;
312 &select_project($i ? undef : 1, $nextsub);
317 $form->{"${prefix}project_id${suffix}"} = $form->{project_list}->[0]->{id};
318 $form->{"${prefix}projectnumber${suffix}"} = $form->{project_list}->[0]->{projectnumber};
319 $form->{"old${prefix}projectnumber${suffix}"} = $form->{project_list}->[0]->{projectnumber};
323 $form->error($locale->text('Project not on file!'));
326 $form->{"old${prefix}projectnumber${suffix}"} = "";
331 $main::lxdebug->leave_sub();
335 $main::lxdebug->enter_sub();
337 my $form = $main::form;
338 my $locale = $main::locale;
339 my $cgi = $main::cgi;
341 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
342 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
344 my ($is_global, $nextsub) = @_;
346 my @column_index = qw(ndx projectnumber description);
349 $column_data{ndx} = qq|<th> </th>|;
350 $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
351 $column_data{description} =
352 qq|<th>| . $locale->text('Description') . qq|</th>|;
354 # list items with radio button on a form
357 my $title = $locale->text('Select from one of the projects below');
362 <form method=post action=$form->{script}>
364 <input type=hidden name=rownumber value=$form->{rownumber}>
368 <th class=listtop>$title</th>
374 <tr class=listheading>|;
376 map { print "\n$column_data{$_}" } @column_index;
384 foreach my $ref (@{ $form->{project_list} }) {
385 my $checked = ($i++) ? "" : "checked";
387 $ref->{name} =~ s/\"/"/g;
390 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
391 $column_data{projectnumber} =
392 qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
393 $column_data{description} = qq|<td>$ref->{description}</td>|;
398 <tr class=listrow$j>|;
400 map { print "\n$column_data{$_}" } @column_index;
405 <input name="new_id_$i" type=hidden value=$ref->{id}>
416 <td><hr size=3 noshade></td>
420 <input name=lastndx type=hidden value=$i>
424 # delete action variable
425 map { delete $form->{$_} } qw(action project_list header update);
427 # save all other form variables
428 foreach my $key (keys %${form}) {
429 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
430 $form->{$key} =~ s/\"/"/g;
431 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
435 $cgi->hidden('-name' => 'is_global', '-default' => [$is_global])
436 . $cgi->hidden('-name' => 'project_selected_nextsub', '-default' => [$nextsub])
437 . qq|<input type=hidden name=nextsub value=project_selected>
440 <input class=submit type=submit name=action value="|
441 . $locale->text('Continue') . qq|">
448 $main::lxdebug->leave_sub();
451 sub project_selected {
452 $main::lxdebug->enter_sub();
454 my $form = $main::form;
456 $main::auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
457 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
459 # replace the variable with the one checked
462 my $i = $form->{ndx};
464 my $prefix = $form->{"is_global"} ? "global" : "";
465 my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
467 $form->{"${prefix}projectnumber${suffix}"} =
468 $form->{"new_projectnumber_$i"};
469 $form->{"old${prefix}projectnumber${suffix}"} =
470 $form->{"new_projectnumber_$i"};
471 $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
473 # delete all the new_ variables
474 for $i (1 .. $form->{lastndx}) {
475 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
478 my $nextsub = $form->{project_selected_nextsub} || 'update';
480 map { delete $form->{$_} } qw(ndx lastndx nextsub is_global project_selected_nextsub);
484 $main::lxdebug->leave_sub();
487 sub continue { call_sub($main::form->{"nextsub"}); }