- if ($form->round_amount($taxaccounts{$item}, 2) != 0) {
- push(@{ $form->{taxbase} },
- $form->format_amount($myconfig, $taxbase{$item}, 2));
-
- $tax += $taxamount = $form->round_amount($taxaccounts{$item}, 2);
-
- push(@{ $form->{tax} }, $form->format_amount($myconfig, $taxamount, 2));
- push(@{ $form->{taxdescription} }, $form->{"${item}_description"});
- push(@{ $form->{taxrate} },
- $form->format_amount($myconfig, $form->{"${item}_rate"} * 100));
- push(@{ $form->{taxnumber} }, $form->{"${item}_taxnumber"});
- }
- }
-
- $form->{subtotal} = $form->format_amount($myconfig, $form->{ordtotal}, 2);
- $form->{ordtotal} =
- ($form->{taxincluded}) ? $form->{ordtotal} : $form->{ordtotal} + $tax;
-
- # format amounts
- $form->{quototal} = $form->{ordtotal} =
- $form->format_amount($myconfig, $form->{ordtotal}, 2);
-
- # myconfig variables
- map { $form->{$_} = $myconfig->{$_} }
- (qw(company address tel fax signature businessnumber));
- $form->{username} = $myconfig->{name};
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub project_description {
- $main::lxdebug->enter_sub();
-
- my ($self, $dbh, $id) = @_;
-
- my $query = qq|SELECT p.description
- FROM project p
- WHERE p.id = $id|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- ($_) = $sth->fetchrow_array;
-
- $sth->finish;
-
- $main::lxdebug->leave_sub();
-
- return $_;
-}
-
-sub get_warehouses {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->dbconnect($myconfig);
-
- # setup warehouses
- my $query = qq|SELECT id, description
- FROM warehouse|;
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_warehouses} }, $ref;
- }
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_inventory {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- my ($null, $warehouse_id) = split /--/, $form->{warehouse};
- $warehouse_id *= 1;
-
- my $employee_id;
- ($null, $employee_id) = split /--/, $form->{employee};
-
- my $ml = ($form->{type} eq 'ship_order') ? -1 : 1;
-
- my $dbh = $form->dbconnect_noauto($myconfig);
- my $sth;
- my $wth;
- my $serialnumber;
- my $ship;
-
- $query = qq|SELECT o.serialnumber, o.ship
- FROM orderitems o
- WHERE o.trans_id = ?
- AND o.id = ?
- FOR UPDATE|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- $query = qq|SELECT sum(i.qty)
- FROM inventory i
- WHERE i.parts_id = ?
- AND i.warehouse_id = ?|;
- $wth = $dbh->prepare($query) || $form->dberror($query);
-
- for my $i (1 .. $form->{rowcount} - 1) {
-
- $ship =
- (abs($form->{"ship_$i"}) > abs($form->{"qty_$i"}))
- ? $form->{"qty_$i"}
- : $form->{"ship_$i"};