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};
 
  53   # if we use a selection
 
  54   if ($form->{"select$name"}) {
 
  55     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"}|) {
 
  78       # 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));
 
 110   $lxdebug->leave_sub();
 
 115 # $locale->text('Customer not on file!')
 
 116 # $locale->text('Vendor not on file!')
 
 119   $lxdebug->enter_sub();
 
 123   @column_index = qw(ndx name address);
 
 125   $label             = ucfirst $table;
 
 126   $column_data{ndx}  = qq|<th> </th>|;
 
 128     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
 
 129   $column_data{address} =
 
 130     qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
 
 132   # list items with radio button on a form
 
 135   $title = $locale->text('Select from one of the names below');
 
 140 <form method=post action=$form->{script}>
 
 144     <th class=listtop>$title</th>
 
 150         <tr class=listheading>|;
 
 152   map { print "\n$column_data{$_}" } @column_index;
 
 159   foreach $ref (@{ $form->{name_list} }) {
 
 160     $checked = ($i++) ? "" : "checked";
 
 162     $ref->{name} =~ s/\"/"/g;
 
 165       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
 
 167       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
 
 168     $column_data{address} = qq|<td>$ref->{address} </td>|;
 
 173         <tr class=listrow$j>|;
 
 175     map { print "\n$column_data{$_}" } @column_index;
 
 180 <input name="new_id_$i" type=hidden value=$ref->{id}>
 
 191     <td><hr size=3 noshade></td>
 
 195 <input name=lastndx type=hidden value=$i>
 
 200   map { delete $form->{$_} } qw(action name_list header);
 
 202   # save all other form variables
 
 203   foreach $key (keys %${form}) {
 
 204     $form->{$key} =~ s/\"/"/g;
 
 205     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
 
 209 <input type=hidden name=nextsub value=name_selected>
 
 211 <input type=hidden name=vc value=$table>
 
 213 <input class=submit type=submit name=action value="|
 
 214     . $locale->text('Continue') . qq|">
 
 221   $lxdebug->leave_sub();
 
 225   $lxdebug->enter_sub();
 
 227   # replace the variable with the one checked
 
 232   $form->{ $form->{vc} }    = $form->{"new_name_$i"};
 
 233   $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
 
 234   $form->{"old$form->{vc}"} =
 
 235     qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
 
 237   # delete all the new_ variables
 
 238   for $i (1 .. $form->{lastndx}) {
 
 239     map { delete $form->{"new_${_}_$i"} } (id, name);
 
 242   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 244   IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
 
 245   IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
 
 249   $lxdebug->leave_sub();
 
 252 sub add_transaction {
 
 253   $lxdebug->enter_sub();
 
 257   delete $form->{script};
 
 258   $form->{action} = "add";
 
 259   $form->{type}   = "invoice" if $module =~ /(is|ir)/;
 
 261   $form->{callback} = $form->escape($form->{callback}, 1);
 
 262   map { $argv .= "$_=$form->{$_}&" } keys %$form;
 
 264   $form->{callback} = "$module.pl?$argv";
 
 268   $lxdebug->leave_sub();
 
 272   $lxdebug->enter_sub();
 
 274   for $i (1 .. $form->{rowcount}) {
 
 275     $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
 
 276     if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) {
 
 277       if ($form->{"projectnumber_$i"}) {
 
 280         $form->{projectnumber} = $form->{"projectnumber_$i"};
 
 281         if (($rows = PE->projects(\%myconfig, $form)) > 1) {
 
 283           # check form->{project_list} how many there are
 
 284           $form->{rownumber} = $i;
 
 290           $form->{"project_id_$i"}    = $form->{project_list}->[0]->{id};
 
 291           $form->{"projectnumber_$i"} =
 
 292             $form->{project_list}->[0]->{projectnumber};
 
 293           $form->{"oldprojectnumber_$i"} =
 
 294             $form->{project_list}->[0]->{projectnumber};
 
 298           $form->error($locale->text('Project not on file!'));
 
 301         $form->{"oldprojectnumber_$i"} = "";
 
 306   $lxdebug->leave_sub();
 
 310   $lxdebug->enter_sub();
 
 312   @column_index = qw(ndx projectnumber description);
 
 314   $column_data{ndx}           = qq|<th> </th>|;
 
 315   $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
 
 316   $column_data{description}   =
 
 317     qq|<th>| . $locale->text('Description') . qq|</th>|;
 
 319   # list items with radio button on a form
 
 322   $title = $locale->text('Select from one of the projects below');
 
 327 <form method=post action=$form->{script}>
 
 329 <input type=hidden name=rownumber value=$form->{rownumber}>
 
 333     <th class=listtop>$title</th>
 
 339         <tr class=listheading>|;
 
 341   map { print "\n$column_data{$_}" } @column_index;
 
 348   foreach $ref (@{ $form->{project_list} }) {
 
 349     $checked = ($i++) ? "" : "checked";
 
 351     $ref->{name} =~ s/\"/"/g;
 
 354       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
 
 355     $column_data{projectnumber} =
 
 356       qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
 
 357     $column_data{description} = qq|<td>$ref->{description}</td>|;
 
 362         <tr class=listrow$j>|;
 
 364     map { print "\n$column_data{$_}" } @column_index;
 
 369 <input name="new_id_$i" type=hidden value=$ref->{id}>
 
 380     <td><hr size=3 noshade></td>
 
 384 <input name=lastndx type=hidden value=$i>
 
 388   # delete action variable
 
 389   map { delete $form->{$_} } qw(action project_list header);
 
 391   # save all other form variables
 
 392   foreach $key (keys %${form}) {
 
 393     $form->{$key} =~ s/\"/"/g;
 
 394     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
 
 398 <input type=hidden name=nextsub value=project_selected>
 
 401 <input class=submit type=submit name=action value="|
 
 402     . $locale->text('Continue') . qq|">
 
 409   $lxdebug->leave_sub();
 
 412 sub project_selected {
 
 413   $lxdebug->enter_sub();
 
 415   # replace the variable with the one checked
 
 420   $form->{"projectnumber_$form->{rownumber}"} =
 
 421     $form->{"new_projectnumber_$i"};
 
 422   $form->{"oldprojectnumber_$form->{rownumber}"} =
 
 423     $form->{"new_projectnumber_$i"};
 
 424   $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
 
 426   # delete all the new_ variables
 
 427   for $i (1 .. $form->{lastndx}) {
 
 428     map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
 
 431   map { delete $form->{$_} } qw(ndx lastndx nextsub);
 
 433   if ($form->{update}) {
 
 434     &{ $form->{update} };
 
 439   $lxdebug->leave_sub();
 
 442 sub continue       { &{ $form->{nextsub} } }
 
 443 sub gl_transaction { &add }
 
 444 sub ar_transaction { &add_transaction(ar) }
 
 445 sub ap_transaction { &add_transaction(ap) }
 
 446 sub sales_invoice  { &add_transaction(is) }
 
 447 sub vendor_invoice { &add_transaction(ir) }