1 #====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (C) 1999-2003
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  29 #======================================================================
 
  33 #======================================================================
 
  38   $main::lxdebug->enter_sub();
 
  40   my ($self, $myconfig, $form) = @_;
 
  43   my $dbh = $form->dbconnect($myconfig);
 
  46   my $ordnumber = 'ordnumber';
 
  48   my ($null, $department_id) = split /--/, $form->{department};
 
  50   my $department = " AND o.department_id = $department_id" if $department_id;
 
  52   my $rate = ($form->{vc} eq 'customer') ? 'buy' : 'sell';
 
  54   if ($form->{type} =~ /_quotation$/) {
 
  56     $ordnumber = 'quonumber';
 
  59   my $number = $form->like(lc $form->{$ordnumber});
 
  60   my $name   = $form->like(lc $form->{ $form->{vc} });
 
  62   my $query = qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate,
 
  63                  o.amount, ct.name, o.netamount, o.$form->{vc}_id,
 
  64                  ex.$rate AS exchangerate,
 
  65                  o.closed, o.quonumber, o.shippingpoint, o.shipvia,
 
  68                  JOIN $form->{vc} ct ON (o.$form->{vc}_id = ct.id)
 
  69                  LEFT JOIN employee e ON (o.employee_id = e.id)
 
  70                  LEFT JOIN exchangerate ex ON (ex.curr = o.curr
 
  71                                                AND ex.transdate = o.transdate)
 
  72                  WHERE o.quotation = '$quotation'
 
  75   # build query if type eq (ship|receive)_order
 
  76   if ($form->{type} =~ /(ship|receive)_order/) {
 
  77     my ($warehouse, $warehouse_id) = split /--/, $form->{warehouse};
 
  79     $query = qq|SELECT DISTINCT ON (o.id) o.id, o.ordnumber, o.transdate,
 
  80                  o.reqdate, o.amount, ct.name, o.netamount, o.$form->{vc}_id,
 
  81                  ex.$rate AS exchangerate,
 
  82                  o.closed, o.quonumber, o.shippingpoint, o.shipvia,
 
  85                  JOIN $form->{vc} ct ON (o.$form->{vc}_id = ct.id)
 
  86                  JOIN orderitems oi ON (oi.trans_id = o.id)
 
  87                  JOIN parts p ON (p.id = oi.parts_id)|;
 
  89     if ($warehouse_id && $form->{type} eq 'ship_order') {
 
  91                  JOIN inventory i ON (oi.parts_id = i.parts_id)
 
  96                  LEFT JOIN employee e ON (o.employee_id = e.id)
 
  97                  LEFT JOIN exchangerate ex ON (ex.curr = o.curr
 
  98                                                AND ex.transdate = o.transdate)
 
  99                  WHERE o.quotation = '0'
 
 100                  AND (p.inventory_accno_id > 0 OR p.assembly = '1')
 
 101                  AND oi.qty <> oi.ship
 
 104     if ($warehouse_id && $form->{type} eq 'ship_order') {
 
 106                  AND i.warehouse_id = $warehouse_id
 
 107                  AND i.qty >= (oi.qty - oi.ship)
 
 113   if ($form->{"$form->{vc}_id"}) {
 
 114     $query .= qq| AND o.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
 
 116     if ($form->{ $form->{vc} }) {
 
 117       $query .= " AND lower(ct.name) LIKE '$name'";
 
 120   if (!$form->{open} && !$form->{closed}) {
 
 121     $query .= " AND o.id = 0";
 
 122   } elsif (!($form->{open} && $form->{closed})) {
 
 123     $query .= ($form->{open}) ? " AND o.closed = '0'" : " AND o.closed = '1'";
 
 126   my $sortorder = join ', ',
 
 127     ("o.id", $form->sort_columns(transdate, $ordnumber, name));
 
 128   $sortorder = $form->{sort} unless $sortorder;
 
 130   $query .= " AND lower($ordnumber) LIKE '$number'" if $form->{$ordnumber};
 
 131   $query .= " AND o.transdate >= '$form->{transdatefrom}'"
 
 132     if $form->{transdatefrom};
 
 133   $query .= " AND o.transdate <= '$form->{transdateto}'"
 
 134     if $form->{transdateto};
 
 135   $query .= " ORDER by $sortorder";
 
 137   my $sth = $dbh->prepare($query);
 
 138   $sth->execute || $form->dberror($query);
 
 141   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 142     $ref->{exchangerate} = 1 unless $ref->{exchangerate};
 
 143     push @{ $form->{OE} }, $ref if $ref->{id} != $id{ $ref->{id} };
 
 144     $id{ $ref->{id} } = $ref->{id};
 
 150   $main::lxdebug->leave_sub();
 
 154   $main::lxdebug->enter_sub();
 
 156   my ($self, $myconfig, $form) = @_;
 
 158   # connect to database, turn off autocommit
 
 159   my $dbh = $form->dbconnect_noauto($myconfig);
 
 161   my ($query, $sth, $null);
 
 162   my $exchangerate = 0;
 
 164   ($null, $form->{employee_id}) = split /--/, $form->{employee};
 
 165   unless ($form->{employee_id}) {
 
 166     $form->get_employee($dbh);
 
 169   ($null, $form->{contact_id}) = split /--/, $form->{contact};
 
 170   $form->{contact_id} *= 1;
 
 172   my $ml = ($form->{type} eq 'sales_order') ? 1 : -1;
 
 176     &adj_onhand($dbh, $form, $ml) if $form->{type} =~ /_order$/;
 
 178     $query = qq|DELETE FROM orderitems
 
 179                 WHERE trans_id = $form->{id}|;
 
 180     $dbh->do($query) || $form->dberror($query);
 
 182     $query = qq|DELETE FROM shipto
 
 183                 WHERE trans_id = $form->{id}|;
 
 184     $dbh->do($query) || $form->dberror($query);
 
 188     my $uid = rand() . time;
 
 190     $uid .= $form->{login};
 
 192     $uid = substr($uid, 2, 75);
 
 194     $query = qq|INSERT INTO oe (ordnumber, employee_id)
 
 195                 VALUES ('$uid', $form->{employee_id})|;
 
 196     $dbh->do($query) || $form->dberror($query);
 
 198     $query = qq|SELECT o.id FROM oe o
 
 199                 WHERE o.ordnumber = '$uid'|;
 
 200     $sth = $dbh->prepare($query);
 
 201     $sth->execute || $form->dberror($query);
 
 203     ($form->{id}) = $sth->fetchrow_array;
 
 207   map { $form->{$_} =~ s/\'/\'\'/g }
 
 208     qw(ordnumber quonumber shippingpoint shipvia notes intnotes message);
 
 223   for my $i (1 .. $form->{rowcount}) {
 
 226       $form->{"${_}_$i"} = $form->parse_amount($myconfig, $form->{"${_}_$i"})
 
 229     if ($form->{"qty_$i"}) {
 
 231       map { $form->{"${_}_$i"} =~ s/\'/\'\'/g }
 
 232         qw(partnumber description unit);
 
 234       # set values to 0 if nothing entered
 
 235       $form->{"discount_$i"} =
 
 236         $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100;
 
 238       $form->{"sellprice_$i"} =
 
 239         $form->parse_amount($myconfig, $form->{"sellprice_$i"});
 
 240       $fxsellprice = $form->{"sellprice_$i"};
 
 242       my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 244       my $decimalplaces = ($dec > 2) ? $dec : 2;
 
 247         $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"},
 
 249       $form->{"sellprice_$i"} =
 
 250         $form->round_amount($form->{"sellprice_$i"} - $discount,
 
 253       $form->{"inventory_accno_$i"} *= 1;
 
 254       $form->{"expense_accno_$i"}   *= 1;
 
 257         $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
 
 259       @taxaccounts = split / /, $form->{"taxaccounts_$i"};
 
 263       map { $taxrate += $form->{"${_}_rate"} } @taxaccounts;
 
 265       if ($form->{taxincluded}) {
 
 266         $taxamount = $linetotal * $taxrate / (1 + $taxrate);
 
 267         $taxbase   = $linetotal - $taxamount;
 
 269         # we are not keeping a natural price, do not round
 
 270         $form->{"sellprice_$i"} =
 
 271           $form->{"sellprice_$i"} * (1 / (1 + $taxrate));
 
 273         $taxamount = $linetotal * $taxrate;
 
 274         $taxbase   = $linetotal;
 
 277       if ($form->round_amount($taxrate, 7) == 0) {
 
 278         if ($form->{taxincluded}) {
 
 279           foreach $item (@taxaccounts) {
 
 281               $form->round_amount($linetotal * $form->{"${item}_rate"} /
 
 282                                     (1 + abs($form->{"${item}_rate"})),
 
 285             $taxaccounts{$item} += $taxamount;
 
 286             $taxdiff            += $taxamount;
 
 288             $taxbase{$item} += $taxbase;
 
 290           $taxaccounts{ $taxaccounts[0] } += $taxdiff;
 
 292           foreach $item (@taxaccounts) {
 
 293             $taxaccounts{$item} += $linetotal * $form->{"${item}_rate"};
 
 294             $taxbase{$item}     += $taxbase;
 
 298         foreach $item (@taxaccounts) {
 
 299           $taxaccounts{$item} +=
 
 300             $taxamount * $form->{"${item}_rate"} / $taxrate;
 
 301           $taxbase{$item} += $taxbase;
 
 305       $netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"};
 
 307       $project_id = 'NULL';
 
 308       if ($form->{"projectnumber_$i"}) {
 
 309         $project_id = $form->{"projectnumber_$i"};
 
 312         ($form->{"reqdate_$i"}) ? qq|'$form->{"reqdate_$i"}'| : "NULL";
 
 314       # get pricegroup_id and save ist
 
 315       ($null, my $pricegroup_id) = split /--/, $form->{"sellprice_drag_$i"};
 
 318       # save detail record in orderitems table
 
 319       $query = qq|INSERT INTO orderitems (|;
 
 320       $query .= "id, " if $form->{"orderitems_id_$i"};
 
 321       $query .= qq|trans_id, parts_id, description, qty, sellprice, discount,
 
 322                    unit, reqdate, project_id, serialnumber, ship, pricegroup_id,
 
 323                    ordnumber, transdate, cusordnumber)
 
 325       $query .= qq|$form->{"orderitems_id_$i"},|
 
 326         if $form->{"orderitems_id_$i"};
 
 327       $query .= qq|$form->{id}, $form->{"id_$i"},
 
 328                    '$form->{"description_$i"}', $form->{"qty_$i"},
 
 329                    $fxsellprice, $form->{"discount_$i"},
 
 330                    '$form->{"unit_$i"}', $reqdate, (SELECT id from project where projectnumber = '$project_id'),
 
 331                    '$form->{"serialnumber_$i"}', $form->{"ship_$i"}, '$pricegroup_id',
 
 332                    '$form->{"ordnumber_$i"}', '$form->{"transdate_$i"}', '$form->{"cusordnumber_$i"}')|;
 
 333       $dbh->do($query) || $form->dberror($query);
 
 335       $form->{"sellprice_$i"} = $fxsellprice;
 
 336       $form->{"discount_$i"} *= 100;
 
 340   # set values which could be empty
 
 341   map { $form->{$_} *= 1 }
 
 342     qw(vendor_id customer_id taxincluded closed quotation);
 
 344   $reqdate = ($form->{reqdate}) ? qq|'$form->{reqdate}'| : "NULL";
 
 348   map { $tax += $form->round_amount($taxaccounts{$_}, 2) } keys %taxaccounts;
 
 350   $amount = $form->round_amount($netamount + $tax, 2);
 
 351   $netamount = $form->round_amount($netamount, 2);
 
 353   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 354     $form->{exchangerate} = 1;
 
 357       $form->check_exchangerate($myconfig,
 
 360                                 ($form->{vc} eq 'customer') ? 'buy' : 'sell');
 
 363   $form->{exchangerate} =
 
 366     : $form->parse_amount($myconfig, $form->{exchangerate});
 
 370   # fill in subject if there is none
 
 371   if ($form->{type} =~ /_order$/) {
 
 373     $form->{subject} = qq|$form->{label} $form->{ordnumber}|
 
 374       unless $form->{subject};
 
 377     $form->{subject} = qq|$form->{label} $form->{quonumber}|
 
 378       unless $form->{subject};
 
 381   # if there is a message stuff it into the intnotes
 
 382   my $cc  = "Cc: $form->{cc}\\r\n"   if $form->{cc};
 
 383   my $bcc = "Bcc: $form->{bcc}\\r\n" if $form->{bcc};
 
 384   my $now = scalar localtime;
 
 385   $form->{intnotes} .= qq|\r
 
 386 \r| if $form->{intnotes};
 
 388   $form->{intnotes} .= qq|[email]\r
 
 391 $cc${bcc}Subject: $form->{subject}\r
 
 393 Message: $form->{message}\r| if $form->{message};
 
 395   ($null, $form->{department_id}) = split(/--/, $form->{department});
 
 396   $form->{department_id} *= 1;
 
 399   $query = qq|UPDATE oe set
 
 400               ordnumber = '$form->{ordnumber}',
 
 401               quonumber = '$form->{quonumber}',
 
 402               cusordnumber = '$form->{cusordnumber}',
 
 403               transdate = '$form->{transdate}',
 
 404               vendor_id = $form->{vendor_id},
 
 405               customer_id = $form->{customer_id},
 
 407               netamount = $netamount,
 
 409               taxincluded = '$form->{taxincluded}',
 
 410               shippingpoint = '$form->{shippingpoint}',
 
 411               shipvia = '$form->{shipvia}',
 
 412               notes = '$form->{notes}',
 
 413               intnotes = '$form->{intnotes}',
 
 414               curr = '$form->{currency}',
 
 415               closed = '$form->{closed}',
 
 416               quotation = '$quotation',
 
 417               department_id = $form->{department_id},
 
 418               employee_id = $form->{employee_id},
 
 419               cp_id = $form->{contact_id}
 
 420               WHERE id = $form->{id}|;
 
 421   $dbh->do($query) || $form->dberror($query);
 
 423   $form->{ordtotal} = $amount;
 
 425   if ($form->{webdav}) {
 
 426     &webdav_folder($myconfig, $form);
 
 430   $form->{name} = $form->{ $form->{vc} };
 
 431   $form->{name} =~ s/--$form->{"$form->{vc}_id"}//;
 
 432   $form->add_shipto($dbh, $form->{id});
 
 434   # save printed, emailed, queued
 
 435   $form->save_status($dbh);
 
 437   if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
 
 438     if ($form->{vc} eq 'customer') {
 
 439       $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate},
 
 440                                  $form->{exchangerate}, 0);
 
 442     if ($form->{vc} eq 'vendor') {
 
 443       $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate},
 
 444                                  0, $form->{exchangerate});
 
 448   if ($form->{type} =~ /_order$/) {
 
 451     &adj_onhand($dbh, $form, $ml * -1);
 
 452     &adj_inventory($dbh, $myconfig, $form);
 
 455   my $rc = $dbh->commit;
 
 458   $main::lxdebug->leave_sub();
 
 463 # this function closes multiple orders given in $form->{ordnumber_#}. 
 
 464 # use this for multiple orders that don't have to be saved back
 
 465 # single orders should use OE::save instead.
 
 467   $main::lxdebug->enter_sub();
 
 469   my ($self, $myconfig ,$form) = @_;
 
 471   for my $i (1 .. $form->{rowcount}) {
 
 474       $form->{"${_}_$i"} = $form->parse_amount($myconfig, $form->{"${_}_$i"})
 
 477       $form->{"orderitems_id_$i"} = "";
 
 480     if ($form->{"qty_$i"}) {
 
 482       # set values to 0 if nothing entered
 
 483       $form->{"discount_$i"} =
 
 484         $form->parse_amount($myconfig, $form->{"discount_$i"});
 
 486       $form->{"sellprice_$i"} =
 
 487         $form->parse_amount($myconfig, $form->{"sellprice_$i"});
 
 491   map { push @ids, $form->{"ordnumber_$_"} if $form->{"ordnumber_$_"} } (1 .. $form->{rowcount});
 
 493   my $dbh = $form->dbconnect($myconfig);
 
 494   $query = qq|UPDATE oe SET
 
 496               WHERE ordnumber IN (|.join(', ', map{ $dbh->quote($_) }@ids).qq|)|;
 
 497   $dbh->do($query) || $form->dberror($query);
 
 500   $main::lxdebug->leave_sub();
 
 504   $main::lxdebug->enter_sub();
 
 506   my ($self, $myconfig, $form, $spool) = @_;
 
 508   # connect to database
 
 509   my $dbh = $form->dbconnect_noauto($myconfig);
 
 512   my $query = qq|SELECT s.spoolfile FROM status s
 
 513                  WHERE s.trans_id = $form->{id}|;
 
 514   $sth = $dbh->prepare($query);
 
 515   $sth->execute || $self->dberror($query);
 
 520   while (($spoolfile) = $sth->fetchrow_array) {
 
 521     push @spoolfiles, $spoolfile;
 
 525   $query = qq|SELECT o.parts_id, o.ship FROM orderitems o
 
 526               WHERE o.trans_id = $form->{id}|;
 
 527   $sth = $dbh->prepare($query);
 
 528   $sth->execute || $self->dberror($query);
 
 530   while (my ($id, $ship) = $sth->fetchrow_array) {
 
 531     $form->update_balance($dbh, "parts", "onhand", qq|id = $id|, $ship * -1);
 
 536   $query = qq|DELETE FROM inventory
 
 537               WHERE oe_id = $form->{id}|;
 
 538   $dbh->do($query) || $form->dberror($query);
 
 540   # delete status entries
 
 541   $query = qq|DELETE FROM status
 
 542               WHERE trans_id = $form->{id}|;
 
 543   $dbh->do($query) || $form->dberror($query);
 
 546   $query = qq|DELETE FROM oe
 
 547               WHERE id = $form->{id}|;
 
 548   $dbh->do($query) || $form->dberror($query);
 
 550   # delete individual entries
 
 551   $query = qq|DELETE FROM orderitems
 
 552               WHERE trans_id = $form->{id}|;
 
 553   $dbh->do($query) || $form->dberror($query);
 
 555   $query = qq|DELETE FROM shipto
 
 556               WHERE trans_id = $form->{id}|;
 
 557   $dbh->do($query) || $form->dberror($query);
 
 559   my $rc = $dbh->commit;
 
 563     foreach $spoolfile (@spoolfiles) {
 
 564       unlink "$spool/$spoolfile" if $spoolfile;
 
 568   $main::lxdebug->leave_sub();
 
 574   $main::lxdebug->enter_sub();
 
 576   my ($self, $myconfig, $form) = @_;
 
 578   # connect to database
 
 579   my $dbh = $form->dbconnect_noauto($myconfig);
 
 583   # translate the ids (given by id_# and trans_id_#) into one array of ids, so we can join them later
 
 584   map { push @ids, $form->{"trans_id_$_"} if ($form->{"id_$_"}) } (1 .. $form->{"rowcount"});
 
 586   # if called in multi id mode, and still only got one id, switch back to single id 
 
 587   if ($form->{"rowcount"} and $#ids == 0) {
 
 588     $form->{"id"} = $ids[0];
 
 594     # get default accounts and last order number
 
 595     $query = qq|SELECT (SELECT c.accno FROM chart c
 
 596                         WHERE d.inventory_accno_id = c.id) AS inventory_accno,
 
 597                        (SELECT c.accno FROM chart c
 
 598                         WHERE d.income_accno_id = c.id) AS income_accno,
 
 599                        (SELECT c.accno FROM chart c
 
 600                         WHERE d.expense_accno_id = c.id) AS expense_accno,
 
 601                        (SELECT c.accno FROM chart c
 
 602                         WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
 
 603                        (SELECT c.accno FROM chart c
 
 604                         WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
 
 608     $query = qq|SELECT (SELECT c.accno FROM chart c
 
 609                         WHERE d.inventory_accno_id = c.id) AS inventory_accno,
 
 610                        (SELECT c.accno FROM chart c
 
 611                         WHERE d.income_accno_id = c.id) AS income_accno,
 
 612                        (SELECT c.accno FROM chart c
 
 613                         WHERE d.expense_accno_id = c.id) AS expense_accno,
 
 614                        (SELECT c.accno FROM chart c
 
 615                         WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
 
 616                        (SELECT c.accno FROM chart c
 
 617                         WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
 
 618                 d.curr AS currencies,
 
 619                 current_date AS transdate, current_date AS reqdate
 
 622   my $sth = $dbh->prepare($query);
 
 623   $sth->execute || $form->dberror($query);
 
 625   my $ref = $sth->fetchrow_hashref(NAME_lc);
 
 626   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
 629   ($form->{currency}) = split /:/, $form->{currencies};
 
 631   if ($form->{id} or @ids) {
 
 633     # retrieve order for single id
 
 634     # NOTE: this query is intended to fetch all information only ONCE.
 
 635     # so if any of these infos is important (or even different) for any item, 
 
 636     # it will be killed out and then has to be fetched from the item scope query further down
 
 637     $query = qq|SELECT o.cp_id, o.ordnumber, o.transdate, o.reqdate,
 
 638                 o.taxincluded, o.shippingpoint, o.shipvia, o.notes, o.intnotes,
 
 639                 o.curr AS currency, e.name AS employee, o.employee_id,
 
 640                 o.$form->{vc}_id, cv.name AS $form->{vc}, o.amount AS invtotal,
 
 641                 o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
 
 642                 d.description AS department
 
 644                 JOIN $form->{vc} cv ON (o.$form->{vc}_id = cv.id)
 
 645                 LEFT JOIN employee e ON (o.employee_id = e.id)
 
 646                 LEFT JOIN department d ON (o.department_id = d.id)
 
 648                    ? qq|WHERE o.id = $form->{id}| 
 
 649                    : qq|WHERE o.id IN (|.join(', ', @ids).qq|)|
 
 652 #$main::lxdebug->message(0, $query);
 
 654     $sth = $dbh->prepare($query);
 
 655     $sth->execute || $form->dberror($query);
 
 657     $ref = $sth->fetchrow_hashref(NAME_lc);
 
 658     map { $form->{$_} = $ref->{$_} } keys %$ref;
 
 660     # destroy all entries for multiple ids that yield different information
 
 661     while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 662       map { undef $form->{$_} if ($ref->{$_} ne $form->{$_}) } keys %$ref;
 
 665     # if not given, fill transdate with current_date
 
 666     $form->{transdate} = $form->current_date($myconfig) unless $form->{transdate};
 
 670     # shipto and pinted/mailed/queued status makes only sense for single id retrieve 
 
 672       $query = qq|SELECT s.* FROM shipto s
 
 673                   WHERE s.trans_id = $form->{id}|;
 
 674       $sth = $dbh->prepare($query);
 
 675       $sth->execute || $form->dberror($query);
 
 677       $ref = $sth->fetchrow_hashref(NAME_lc);
 
 678       map { $form->{$_} = $ref->{$_} } keys %$ref;
 
 681       # get printed, emailed and queued
 
 682       $query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname
 
 684                   WHERE s.trans_id = $form->{id}|;
 
 685       $sth = $dbh->prepare($query);
 
 686       $sth->execute || $form->dberror($query);
 
 688       while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 689         $form->{printed} .= "$ref->{formname} " if $ref->{printed};
 
 690         $form->{emailed} .= "$ref->{formname} " if $ref->{emailed};
 
 691         $form->{queued} .= "$ref->{formname} $ref->{spoolfile} " if $ref->{spoolfile};
 
 694       map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued);
 
 697     my %oid = ('Pg'     => 'oid',
 
 698                'Oracle' => 'rowid');
 
 700     # retrieve individual items
 
 701     # this query looks up all information about the items
 
 702     # stuff different from the whole will not be overwritten, but saved with a suffix.
 
 703     $query = qq|SELECT o.id AS orderitems_id,
 
 704                 c1.accno AS inventory_accno,
 
 705                 c2.accno AS income_accno,
 
 706                 c3.accno AS expense_accno,
 
 707                 oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe, 
 
 708                 p.partnumber, p.assembly, o.description, o.qty,
 
 709                 o.sellprice, o.parts_id AS id, o.unit, o.discount, p.bin, p.notes AS partnotes,
 
 710                 o.reqdate, o.project_id, o.serialnumber, o.ship,
 
 711                 o.ordnumber, o.transdate, o.cusordnumber,
 
 713                 pg.partsgroup, o.pricegroup_id, (SELECT pricegroup FROM pricegroup WHERE id=o.pricegroup_id) as pricegroup
 
 715                 JOIN parts p ON (o.parts_id = p.id)
 
 716                 JOIN oe ON (o.trans_id = oe.id)
 
 717                 LEFT JOIN chart c1 ON (p.inventory_accno_id = c1.id)
 
 718                 LEFT JOIN chart c2 ON (p.income_accno_id = c2.id)
 
 719                 LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id)
 
 720                 LEFT JOIN project pr ON (o.project_id = pr.id)
 
 721                 LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
 
 723                    ? qq|WHERE o.trans_id = $form->{id}| 
 
 724                    : qq|WHERE o.trans_id IN (|.join(", ", @ids).qq|)| 
 
 726                 ORDER BY o.$oid{$myconfig->{dbdriver}}|;
 
 728     $sth = $dbh->prepare($query);
 
 729     $sth->execute || $form->dberror($query);
 
 731     while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 733       # in collective order, copy global ordnumber, transdate, cusordnumber into item scope
 
 734       #   unless already present there 
 
 735       # remove _oe entries afterwards
 
 736       map { $ref->{$_} = $ref->{"${_}_oe"} if ($ref->{$_} eq '') }
 
 737         qw|ordnumber transdate cusordnumber| if (@ids);
 
 738       map{ delete $ref->{$_} } 
 
 739         qw|ordnumber_oe transdate_oe cusordnumber_oe|;
 
 741       #set expense_accno=inventory_accno if they are different => bilanz
 
 743         ($ref->{expense_accno} != $ref->{inventory_accno})
 
 744         ? $ref->{inventory_accno}
 
 745         : $ref->{expense_accno};
 
 747       # get tax rates and description
 
 749         ($form->{vc} eq "customer") ? $ref->{income_accno} : $vendor_accno;
 
 750       $query = qq|SELECT c.accno, c.description, t.rate, t.taxnumber
 
 752                  WHERE c.id=t.chart_id AND t.taxkey in (SELECT taxkey_id from chart where accno = '$accno_id')
 
 754       $stw = $dbh->prepare($query);
 
 755       $stw->execute || $form->dberror($query);
 
 756       $ref->{taxaccounts} = "";
 
 757       while ($ptr = $stw->fetchrow_hashref(NAME_lc)) {
 
 759         #    if ($customertax{$ref->{accno}}) {
 
 760         $ref->{taxaccounts} .= "$ptr->{accno} ";
 
 761         if (!($form->{taxaccounts} =~ /$ptr->{accno}/)) {
 
 762           $form->{"$ptr->{accno}_rate"}        = $ptr->{rate};
 
 763           $form->{"$ptr->{accno}_description"} = $ptr->{description};
 
 764           $form->{"$ptr->{accno}_taxnumber"}   = $ptr->{taxnumber};
 
 765           $form->{taxaccounts} .= "$ptr->{accno} ";
 
 770       chop $ref->{taxaccounts};
 
 771       push @{ $form->{form_details} }, $ref;
 
 779     $form->lastname_used($dbh, $myconfig, $form->{vc})
 
 780       unless $form->{"$form->{vc}_id"};
 
 784   $form->{exchangerate} =
 
 785     $form->get_exchangerate($dbh, $form->{currency}, $form->{transdate},
 
 786                             ($form->{vc} eq 'customer') ? "buy" : "sell");
 
 788   if ($form->{webdav}) {
 
 789     &webdav_folder($myconfig, $form);
 
 792   my $rc = $dbh->commit;
 
 795   $main::lxdebug->leave_sub();
 
 801   $main::lxdebug->enter_sub();
 
 803   my ($self, $myconfig, $form) = @_;
 
 805   # connect to database
 
 806   my $dbh = $form->dbconnect($myconfig);
 
 814   my %oid = ('Pg'     => 'oid',
 
 815              'Oracle' => 'rowid');
 
 817   # sort items by partsgroup
 
 818   for $i (1 .. $form->{rowcount}) {
 
 820     if ($form->{"partsgroup_$i"} && $form->{groupitems}) {
 
 821       $form->format_string("partsgroup_$i");
 
 822       $partsgroup = $form->{"partsgroup_$i"};
 
 824     push @partsgroup, [$i, $partsgroup];
 
 827   # if there is a warehouse limit picking
 
 828   if ($form->{warehouse_id} && $form->{formname} =~ /(pick|packing)_list/) {
 
 830     # run query to check for inventory
 
 831     $query = qq|SELECT sum(i.qty) AS qty
 
 834                 AND i.warehouse_id = ?|;
 
 835     $sth = $dbh->prepare($query) || $form->dberror($query);
 
 837     for $i (1 .. $form->{rowcount}) {
 
 838       $sth->execute($form->{"id_$i"}, $form->{warehouse_id}) || $form->dberror;
 
 840       ($qty) = $sth->fetchrow_array;
 
 843       $form->{"qty_$i"} = 0 if $qty == 0;
 
 845       if ($form->parse_amount($myconfig, $form->{"ship_$i"}) > $qty) {
 
 846         $form->{"ship_$i"} = $form->format_amount($myconfig, $qty);
 
 852   foreach $item (sort { $a->[1] cmp $b->[1] } @partsgroup) {
 
 855     if ($item->[1] ne $sameitem) {
 
 856       push(@{ $form->{description} }, qq|$item->[1]|);
 
 857       $sameitem = $item->[1];
 
 859       map { push(@{ $form->{$_} }, "") }
 
 860         qw(runningnumber number qty ship unit bin partnotes serialnumber reqdate sellprice listprice netprice discount linetotal);
 
 863     $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
 
 865     if ($form->{"qty_$i"} != 0) {
 
 867       # add number, description and qty to $form->{number}, ....
 
 868       push(@{ $form->{runningnumber} }, $i);
 
 869       push(@{ $form->{number} },        qq|$form->{"partnumber_$i"}|);
 
 870       push(@{ $form->{description} },   qq|$form->{"description_$i"}|);
 
 871       push(@{ $form->{qty} },
 
 872            $form->format_amount($myconfig, $form->{"qty_$i"}));
 
 873       push(@{ $form->{ship} },
 
 874            $form->format_amount($myconfig, $form->{"ship_$i"}));
 
 875       push(@{ $form->{unit} },         qq|$form->{"unit_$i"}|);
 
 876       push(@{ $form->{bin} },          qq|$form->{"bin_$i"}|);
 
 877       push(@{ $form->{"partnotes"} },  qq|$form->{"partnotes_$i"}|);
 
 878       push(@{ $form->{serialnumber} }, qq|$form->{"serialnumber_$i"}|);
 
 879       push(@{ $form->{reqdate} },      qq|$form->{"reqdate_$i"}|);
 
 881       push(@{ $form->{sellprice} }, $form->{"sellprice_$i"});
 
 883       push(@{ $form->{listprice} }, $form->{"listprice_$i"});
 
 885       my $sellprice = $form->parse_amount($myconfig, $form->{"sellprice_$i"});
 
 886       my ($dec) = ($sellprice =~ /\.(\d+)/);
 
 888       my $decimalplaces = ($dec > 2) ? $dec : 2;
 
 892                             $sellprice * $form->parse_amount($myconfig,
 
 893                                                  $form->{"discount_$i"}) / 100,
 
 896       # keep a netprice as well, (sellprice - discount)
 
 897       $form->{"netprice_$i"} = $sellprice - $discount;
 
 900         $form->round_amount($form->{"qty_$i"} * $form->{"netprice_$i"}, 2);
 
 902       push(@{ $form->{netprice} },
 
 903            ($form->{"netprice_$i"} != 0)
 
 904            ? $form->format_amount(
 
 905                                  $myconfig, $form->{"netprice_$i"},
 
 912         ? $form->format_amount($myconfig, $discount * -1, $decimalplaces)
 
 914       $linetotal = ($linetotal != 0) ? $linetotal : " ";
 
 916       push(@{ $form->{discount} }, $discount);
 
 918       $form->{ordtotal} += $linetotal;
 
 920       push(@{ $form->{linetotal} },
 
 921            $form->format_amount($myconfig, $linetotal, 2));
 
 923       my ($taxamount, $taxbase);
 
 926       map { $taxrate += $form->{"${_}_rate"} } split / /,
 
 927         $form->{"taxaccounts_$i"};
 
 929       if ($form->{taxincluded}) {
 
 932         $taxamount = $linetotal * $taxrate / (1 + $taxrate);
 
 933         $taxbase = $linetotal / (1 + $taxrate);
 
 935         $taxamount = $linetotal * $taxrate;
 
 936         $taxbase   = $linetotal;
 
 939       if ($taxamount != 0) {
 
 940         foreach my $item (split / /, $form->{"taxaccounts_$i"}) {
 
 941           $taxaccounts{$item} +=
 
 942             $taxamount * $form->{"${item}_rate"} / $taxrate;
 
 943           $taxbase{$item} += $taxbase;
 
 947       $tax_rate = $taxrate*100;
 
 948       push(@{ $form->{tax_rate} }, qq|$tax_rate|);
 
 950       if ($form->{"assembly_$i"}) {
 
 953         # get parts and push them onto the stack
 
 955         if ($form->{groupitems}) {
 
 957             qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
 
 959           $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|;
 
 962         $query = qq|SELECT p.partnumber, p.description, p.unit, a.qty,
 
 965                     JOIN parts p ON (a.parts_id = p.id)
 
 966                     LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
 
 968                     AND a.id = '$form->{"id_$i"}'
 
 970         $sth = $dbh->prepare($query);
 
 971         $sth->execute || $form->dberror($query);
 
 973         while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 974           if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) {
 
 975             map { push(@{ $form->{$_} }, "") }
 
 976               qw(runningnumber ship bin serialnumber number unit bin qty reqdate sellprice listprice netprice discount linetotal);
 
 977             $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--";
 
 978             push(@{ $form->{description} }, $sameitem);
 
 981           push(@{ $form->{description} },
 
 982                $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"}
 
 984                  . qq|, $ref->{partnumber}, $ref->{description}|);
 
 986           map { push(@{ $form->{$_} }, "") }
 
 987             qw(number unit qty runningnumber ship bin serialnumber reqdate sellprice listprice netprice discount linetotal);
 
 997   foreach $item (sort keys %taxaccounts) {
 
 998     if ($form->round_amount($taxaccounts{$item}, 2) != 0) {
 
 999       push(@{ $form->{taxbase} },
 
1000            $form->format_amount($myconfig, $taxbase{$item}, 2));
 
1002       $tax += $taxamount = $form->round_amount($taxaccounts{$item}, 2);
 
1004       push(@{ $form->{tax} }, $form->format_amount($myconfig, $taxamount, 2));
 
1005       push(@{ $form->{taxdescription} }, $form->{"${item}_description"});
 
1006       push(@{ $form->{taxrate} },
 
1007            $form->format_amount($myconfig, $form->{"${item}_rate"} * 100));
 
1008       push(@{ $form->{taxnumber} }, $form->{"${item}_taxnumber"});
 
1012   $form->{subtotal} = $form->format_amount($myconfig, $form->{ordtotal}, 2);
 
1014     ($form->{taxincluded}) ? $form->{ordtotal} : $form->{ordtotal} + $tax;
 
1017   $form->{quototal} = $form->{ordtotal} =
 
1018     $form->format_amount($myconfig, $form->{ordtotal}, 2);
 
1020   # myconfig variables
 
1021   map { $form->{$_} = $myconfig->{$_} }
 
1022     (qw(company address tel fax signature businessnumber));
 
1023   $form->{username} = $myconfig->{name};
 
1027   $main::lxdebug->leave_sub();
 
1030 sub project_description {
 
1031   $main::lxdebug->enter_sub();
 
1033   my ($self, $dbh, $id) = @_;
 
1035   my $query = qq|SELECT p.description
 
1038   my $sth = $dbh->prepare($query);
 
1039   $sth->execute || $form->dberror($query);
 
1041   ($_) = $sth->fetchrow_array;
 
1045   $main::lxdebug->leave_sub();
 
1050 sub get_warehouses {
 
1051   $main::lxdebug->enter_sub();
 
1053   my ($self, $myconfig, $form) = @_;
 
1055   my $dbh = $form->dbconnect($myconfig);
 
1058   my $query = qq|SELECT id, description
 
1061   my $sth = $dbh->prepare($query);
 
1062   $sth->execute || $form->dberror($query);
 
1064   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
1065     push @{ $form->{all_warehouses} }, $ref;
 
1071   $main::lxdebug->leave_sub();
 
1074 sub save_inventory {
 
1075   $main::lxdebug->enter_sub();
 
1077   my ($self, $myconfig, $form) = @_;
 
1079   my ($null, $warehouse_id) = split /--/, $form->{warehouse};
 
1083   ($null, $employee_id) = split /--/, $form->{employee};
 
1085   my $ml = ($form->{type} eq 'ship_order') ? -1 : 1;
 
1087   my $dbh = $form->dbconnect_noauto($myconfig);
 
1093   $query = qq|SELECT o.serialnumber, o.ship
 
1095               WHERE o.trans_id = ?
 
1098   $sth = $dbh->prepare($query) || $form->dberror($query);
 
1100   $query = qq|SELECT sum(i.qty)
 
1102               WHERE i.parts_id = ?
 
1103               AND i.warehouse_id = ?|;
 
1104   $wth = $dbh->prepare($query) || $form->dberror($query);
 
1106   for my $i (1 .. $form->{rowcount} - 1) {
 
1109       (abs($form->{"ship_$i"}) > abs($form->{"qty_$i"}))
 
1111       : $form->{"ship_$i"};
 
1113     if ($warehouse_id && $form->{type} eq 'ship_order') {
 
1115       $wth->execute($form->{"id_$i"}, $warehouse_id) || $form->dberror;
 
1117       ($qty) = $wth->fetchrow_array;
 
1128       $query = qq|INSERT INTO inventory (parts_id, warehouse_id,
 
1129                   qty, oe_id, orderitems_id, shippingdate, employee_id)
 
1130                   VALUES ($form->{"id_$i"}, $warehouse_id,
 
1131                   $ship, $form->{"id"},
 
1132                   $form->{"orderitems_id_$i"}, '$form->{shippingdate}',
 
1134       $dbh->do($query) || $form->dberror($query);
 
1136       # add serialnumber, ship to orderitems
 
1137       $sth->execute($form->{id}, $form->{"orderitems_id_$i"})
 
1139       ($serialnumber, $ship) = $sth->fetchrow_array;
 
1142       $serialnumber .= " " if $serialnumber;
 
1143       $serialnumber .= qq|$form->{"serialnumber_$i"}|;
 
1144       $ship += $form->{"ship_$i"};
 
1146       $query = qq|UPDATE orderitems SET
 
1147                   serialnumber = '$serialnumber',
 
1149                   WHERE trans_id = $form->{id}
 
1150                   AND id = $form->{"orderitems_id_$i"}|;
 
1151       $dbh->do($query) || $form->dberror($query);
 
1153       # update order with ship via
 
1154       $query = qq|UPDATE oe SET
 
1155                   shippingpoint = '$form->{shippingpoint}',
 
1156                   shipvia = '$form->{shipvia}'
 
1157                   WHERE id = $form->{id}|;
 
1158       $dbh->do($query) || $form->dberror($query);
 
1160       # update onhand for parts
 
1161       $form->update_balance($dbh, "parts", "onhand",
 
1162                             qq|id = $form->{"id_$i"}|,
 
1163                             $form->{"ship_$i"} * $ml);
 
1168   my $rc = $dbh->commit;
 
1171   $main::lxdebug->leave_sub();
 
1177   $main::lxdebug->enter_sub();
 
1179   my ($dbh, $form, $ml) = @_;
 
1181   my $query = qq|SELECT oi.parts_id, oi.ship, p.inventory_accno_id, p.assembly
 
1183                  JOIN parts p ON (p.id = oi.parts_id)
 
1184                  WHERE oi.trans_id = $form->{id}|;
 
1185   my $sth = $dbh->prepare($query);
 
1186   $sth->execute || $form->dberror($query);
 
1188   $query = qq|SELECT sum(p.inventory_accno_id)
 
1190               JOIN assembly a ON (a.parts_id = p.id)
 
1192   my $ath = $dbh->prepare($query) || $form->dberror($query);
 
1196   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
1198     if ($ref->{inventory_accno_id} || $ref->{assembly}) {
 
1200       # do not update if assembly consists of all services
 
1201       if ($ref->{assembly}) {
 
1202         $ath->execute($ref->{parts_id}) || $form->dberror($query);
 
1204         ($ispa) = $sth->fetchrow_array;
 
1211       # adjust onhand in parts table
 
1212       $form->update_balance($dbh, "parts", "onhand",
 
1213                             qq|id = $ref->{parts_id}|,
 
1214                             $ref->{ship} * $ml);
 
1220   $main::lxdebug->leave_sub();
 
1224   $main::lxdebug->enter_sub();
 
1226   my ($dbh, $myconfig, $form) = @_;
 
1228   my %oid = ('Pg'     => 'oid',
 
1229              'Oracle' => 'rowid');
 
1231   # increase/reduce qty in inventory table
 
1232   my $query = qq|SELECT oi.id, oi.parts_id, oi.ship
 
1234                  WHERE oi.trans_id = $form->{id}|;
 
1235   my $sth = $dbh->prepare($query);
 
1236   $sth->execute || $form->dberror($query);
 
1238   $query = qq|SELECT $oid{$myconfig->{dbdriver}} AS oid, qty,
 
1239                      (SELECT SUM(qty) FROM inventory
 
1240                       WHERE oe_id = $form->{id}
 
1241                       AND orderitems_id = ?) AS total
 
1243               WHERE oe_id = $form->{id}
 
1244               AND orderitems_id = ?|;
 
1245   my $ith = $dbh->prepare($query) || $form->dberror($query);
 
1248   my $ml = ($form->{type} =~ /(ship|sales)_order/) ? -1 : 1;
 
1250   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
1252     $ith->execute($ref->{id}, $ref->{id}) || $form->dberror($query);
 
1254     while (my $inv = $ith->fetchrow_hashref(NAME_lc)) {
 
1256       if (($qty = (($inv->{total} * $ml) - $ref->{ship})) >= 0) {
 
1257         $qty = $inv->{qty} if ($qty > ($inv->{qty} * $ml));
 
1259         $form->update_balance($dbh, "inventory", "qty",
 
1260                               qq|$oid{$myconfig->{dbdriver}} = $inv->{oid}|,
 
1269   # delete inventory entries if qty = 0
 
1270   $query = qq|DELETE FROM inventory
 
1271               WHERE oe_id = $form->{id}
 
1273   $dbh->do($query) || $form->dberror($query);
 
1275   $main::lxdebug->leave_sub();
 
1279   $main::lxdebug->enter_sub();
 
1281   my ($self, $myconfig, $form) = @_;
 
1283   my ($null, $warehouse_id) = split /--/, $form->{warehouse};
 
1286   my $dbh = $form->dbconnect($myconfig);
 
1288   my $query = qq|SELECT p.id, p.partnumber, p.description, p.onhand,
 
1291                  LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
 
1292                  WHERE p.onhand > 0|;
 
1294   if ($form->{partnumber}) {
 
1295     $var = $form->like(lc $form->{partnumber});
 
1297                  AND lower(p.partnumber) LIKE '$var'";
 
1299   if ($form->{description}) {
 
1300     $var = $form->like(lc $form->{description});
 
1302                  AND lower(p.description) LIKE '$var'";
 
1304   if ($form->{partsgroup}) {
 
1305     $var = $form->like(lc $form->{partsgroup});
 
1307                  AND lower(pg.partsgroup) LIKE '$var'";
 
1310   $sth = $dbh->prepare($query);
 
1311   $sth->execute || $form->dberror($query);
 
1313   $query = qq|SELECT sum(i.qty), w.description, w.id
 
1315               LEFT JOIN warehouse w ON (w.id = i.warehouse_id)
 
1316               WHERE i.parts_id = ?
 
1317               AND NOT i.warehouse_id = $warehouse_id
 
1318               GROUP BY w.description, w.id|;
 
1319   $wth = $dbh->prepare($query) || $form->dberror($query);
 
1321   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
 
1323     $wth->execute($ref->{id}) || $form->dberror;
 
1325     while (($qty, $warehouse, $warehouse_id) = $wth->fetchrow_array) {
 
1326       push @{ $form->{all_inventory} },
 
1327         { 'id'           => $ref->{id},
 
1328           'partnumber'   => $ref->{partnumber},
 
1329           'description'  => $ref->{description},
 
1330           'partsgroup'   => $ref->{partsgroup},
 
1332           'warehouse_id' => $warehouse_id,
 
1333           'warehouse'    => $warehouse }
 
1343   @{ $form->{all_inventory} } =
 
1344     sort { $a->{ $form->{sort} } cmp $b->{ $form->{sort} } }
 
1345     @{ $form->{all_inventory} };
 
1347   $main::lxdebug->leave_sub();
 
1349   return @{ $form->{all_inventory} };
 
1353   $main::lxdebug->enter_sub();
 
1355   my ($self, $myconfig, $form) = @_;
 
1357   my $dbh = $form->dbconnect_noauto($myconfig);
 
1359   my $query = qq|INSERT INTO inventory
 
1360                  (warehouse_id, parts_id, qty, shippingdate, employee_id)
 
1361                  VALUES (?, ?, ?, ?, ?)|;
 
1362   $sth = $dbh->prepare($query) || $form->dberror($query);
 
1364   $form->get_employee($dbh);
 
1369   $shippingdate = "$a[5]-$a[4]-$a[3]";
 
1371   for my $i (1 .. $form->{rowcount}) {
 
1372     $qty = $form->parse_amount($myconfig, $form->{"transfer_$i"});
 
1374     $qty = $form->{"qty_$i"} if ($qty > $form->{"qty_$i"});
 
1379       $sth->execute($form->{warehouse_id}, $form->{"id_$i"}, $qty,
 
1380                     $shippingdate, $form->{employee_id})
 
1386       $sth->execute($form->{"warehouse_id_$i"},
 
1387                     $form->{"id_$i"}, $qty * -1, $shippingdate,
 
1388                     $form->{employee_id})
 
1395   my $rc = $dbh->commit;
 
1398   $main::lxdebug->leave_sub();
 
1404   $main::lxdebug->enter_sub();
 
1406   my ($myconfig, $form) = @_;
 
1409     $path = "webdav/angebote/" . $form->{quonumber}, last SWITCH
 
1410       if ($form->{type} eq "sales_quotation");
 
1411     $path = "webdav/bestellungen/" . $form->{ordnumber}, last SWITCH
 
1412       if ($form->{type} eq "sales_order");
 
1413     $path = "webdav/anfragen/" . $form->{quonumber}, last SWITCH
 
1414       if ($form->{type} eq "request_quotation");
 
1415     $path = "webdav/lieferantenbestellungen/" . $form->{ordnumber}, last SWITCH
 
1416       if ($form->{type} eq "purchase_order");
 
1420     mkdir($path, 0770) or die "can't make directory $!\n";
 
1424       foreach $file (@files) {
 
1425         $file =~ /\/([^\/]*)$/;
 
1427         $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//;
 
1429         $link  = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file;
 
1430         $form->{WEBDAV}{$fname} = $link;
 
1435   $main::lxdebug->leave_sub();