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 |' .
54 'purchase_delivery_order_edit | sales_delivery_order_edit');
58 $name = $name eq "customer" ? "customer" : "vendor";
60 my ($new_name, $new_id) = split /--/, $form->{$name};
62 # if we use a selection
63 if ($form->{"select$name"}) {
64 if ($form->{"old$name"} ne $form->{$name}) {
66 # this is needed for is, ir and oe
68 # for credit calculations
69 $form->{oldinvtotal} = 0;
70 $form->{oldtotalpaid} = 0;
73 $form->{"${name}_id"} = $new_id;
75 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
76 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
78 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
84 # check name, combine name and id
85 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
87 # this is needed for is, ir and oe
90 # for credit calculations
91 $form->{oldinvtotal} = 0;
92 $form->{oldtotalpaid} = 0;
95 # return one name or a list of names in $form->{name_list}
96 if (($i = $form->get_name(\%myconfig, $name)) > 1) {
104 $form->{"${name}_id"} = $form->{name_list}[0]->{id};
105 $form->{$name} = $form->{name_list}[0]->{name};
106 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
108 IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
109 IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
113 # name is not on file
114 # $locale->text('Customer not on file or locked!')
115 # $locale->text('Vendor not on file or locked!')
116 $msg = ucfirst $name . " not on file or locked!";
117 $form->error($locale->text($msg));
121 $form->language_payment(\%myconfig);
123 $lxdebug->leave_sub();
128 # $locale->text('Customer not on file!')
129 # $locale->text('Vendor not on file!')
132 $lxdebug->enter_sub();
134 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
135 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
139 @column_index = qw(ndx name address);
141 $label = ucfirst $table;
142 $column_data{ndx} = qq|<th> </th>|;
144 qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
145 $column_data{address} =
146 qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
148 # list items with radio button on a form
151 $title = $locale->text('Select from one of the names below');
156 <form method=post action=$form->{script}>
160 <th class=listtop>$title</th>
166 <tr class=listheading>|;
168 map { print "\n$column_data{$_}" } @column_index;
175 foreach $ref (@{ $form->{name_list} }) {
176 $checked = ($i++) ? "" : "checked";
178 $ref->{name} =~ s/\"/"/g;
181 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
183 qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
184 $column_data{address} = qq|<td>$ref->{address} </td>|;
189 <tr class=listrow$j>|;
191 map { print "\n$column_data{$_}" } @column_index;
196 <input name="new_id_$i" type=hidden value=$ref->{id}>
207 <td><hr size=3 noshade></td>
211 <input name=lastndx type=hidden value=$i>
216 map { delete $form->{$_} } qw(action name_list header);
218 # save all other form variables
219 foreach $key (keys %${form}) {
220 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
221 $form->{$key} =~ s/\"/"/g;
222 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
226 <input type=hidden name=nextsub value=name_selected>
228 <input type=hidden name=vc value=$table>
230 <input class=submit type=submit name=action value="|
231 . $locale->text('Continue') . qq|">
238 $lxdebug->leave_sub();
242 $lxdebug->enter_sub();
244 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
245 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
247 # replace the variable with the one checked
252 $form->{ $form->{vc} } = $form->{"new_name_$i"};
253 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
254 $form->{"old$form->{vc}"} =
255 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
257 # delete all the new_ variables
258 for $i (1 .. $form->{lastndx}) {
259 map { delete $form->{"new_${_}_$i"} } qw(id name);
262 map { delete $form->{$_} } qw(ndx lastndx nextsub);
264 IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
265 IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
269 $lxdebug->leave_sub();
273 $lxdebug->enter_sub();
275 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
276 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
278 for $i (1 .. $form->{rowcount}) {
279 my $suffix = $i ? "_$i" : "";
280 my $prefix = $i ? "" : "global";
281 $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
282 if ($form->{"${prefix}projectnumber${suffix}"} ne $form->{"old${prefix}projectnumber${suffix}"}) {
283 if ($form->{"${prefix}projectnumber${suffix}"}) {
286 $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
287 my %params = map { $_ => $form->{$_} } qw(projectnumber description active);
288 if (($rows = Projects->search_projects(%params)) > 1) {
290 # check form->{project_list} how many there are
291 $form->{rownumber} = $i;
292 &select_project($i ? undef : 1);
297 $form->{"${prefix}project_id${suffix}"} = $form->{project_list}->[0]->{id};
298 $form->{"${prefix}projectnumber${suffix}"} = $form->{project_list}->[0]->{projectnumber};
299 $form->{"old${prefix}projectnumber${suffix}"} = $form->{project_list}->[0]->{projectnumber};
303 $form->error($locale->text('Project not on file!'));
306 $form->{"old${prefix}projectnumber${suffix}"} = "";
311 $lxdebug->leave_sub();
315 $lxdebug->enter_sub();
317 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
318 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
320 my ($is_global) = @_;
322 @column_index = qw(ndx projectnumber description);
324 $column_data{ndx} = qq|<th> </th>|;
325 $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
326 $column_data{description} =
327 qq|<th>| . $locale->text('Description') . qq|</th>|;
329 # list items with radio button on a form
332 $title = $locale->text('Select from one of the projects below');
337 <form method=post action=$form->{script}>
339 <input type=hidden name=rownumber value=$form->{rownumber}>
343 <th class=listtop>$title</th>
349 <tr class=listheading>|;
351 map { print "\n$column_data{$_}" } @column_index;
358 foreach $ref (@{ $form->{project_list} }) {
359 $checked = ($i++) ? "" : "checked";
361 $ref->{name} =~ s/\"/"/g;
364 qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
365 $column_data{projectnumber} =
366 qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
367 $column_data{description} = qq|<td>$ref->{description}</td>|;
372 <tr class=listrow$j>|;
374 map { print "\n$column_data{$_}" } @column_index;
379 <input name="new_id_$i" type=hidden value=$ref->{id}>
390 <td><hr size=3 noshade></td>
394 <input name=lastndx type=hidden value=$i>
398 # delete action variable
399 map { delete $form->{$_} } qw(action project_list header update);
401 # save all other form variables
402 foreach $key (keys %${form}) {
403 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
404 $form->{$key} =~ s/\"/"/g;
405 print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
409 <input type="hidden" name="is_global" value="$is_global">
410 <input type=hidden name=nextsub value=project_selected>
413 <input class=submit type=submit name=action value="|
414 . $locale->text('Continue') . qq|">
421 $lxdebug->leave_sub();
424 sub project_selected {
425 $lxdebug->enter_sub();
427 $auth->assert('general_ledger | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
428 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash | report');
430 # replace the variable with the one checked
435 my $prefix = $form->{"is_global"} ? "global" : "";
436 my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
438 $form->{"${prefix}projectnumber${suffix}"} =
439 $form->{"new_projectnumber_$i"};
440 $form->{"old${prefix}projectnumber${suffix}"} =
441 $form->{"new_projectnumber_$i"};
442 $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
444 # delete all the new_ variables
445 for $i (1 .. $form->{lastndx}) {
446 map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
449 map { delete $form->{$_} } qw(ndx lastndx nextsub is_global);
451 if ($form->{update}) {
452 call_sub($form->{"update"});
457 $lxdebug->leave_sub();
460 sub continue { call_sub($form->{"nextsub"}); }