summaryrefslogtreecommitdiff
path: root/tests/home/testuser/.ssh/proxy-command
diff options
context:
space:
mode:
Diffstat (limited to 'tests/home/testuser/.ssh/proxy-command')
0 files changed, 0 insertions, 0 deletions
/span>
  • use LedgerSMB::PriceMatrix;
  • use LedgerSMB::Sysconfig;
  • use Math::BigFloat;
  • sub post_invoice {
  • my ($self, $myconfig, $form) = @_;
  • my $dbh = $form->{dbh};
  • for (1 .. $form->{rowcount}){
  • unless ($form->{"deliverydate_$_"}){
  • $form->{"deliverydate_$_"} = $form->{transdate};
  • }
  • }
  • my $query;
  • my $sth;
  • my $ref;
  • my $null;
  • my $project_id;
  • my $exchangerate = 0;
  • my $allocated;
  • my $taxrate;
  • my $taxamount;
  • my $diff = 0;
  • my $item;
  • my $invoice_id;
  • my $keepcleared;
  • ($null, $form->{employee_id}) = split /--/, $form->{employee};
  • unless ($form->{employee_id}) {
  • ($form->{employee}, $form->{employee_id})
  • = $form->get_employee($dbh);
  • }
  • ($null, $form->{department_id}) = split(/--/, $form->{department});
  • $form->{department_id} *= 1;
  • $query = qq|
  • SELECT (SELECT value FROM defaults
  • WHERE setting_key = 'fxgain_accno_id')
  • AS fxgain_accno_id,
  • (SELECT value FROM defaults
  • WHERE setting_key = 'fxloss_accno_id')
  • AS fxloss_accno_id|;
  • my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
  • $query = qq|
  • SELECT inventory_accno_id, income_accno_id, expense_accno_id
  • FROM parts
  • WHERE id = ?|;
  • my $pth = $dbh->prepare($query) || $form->dberror($query);
  • my %updparts = ();
  • if ($form->{id}) {
  • my $sth;
  • $keepcleared = 1;
  • $query = qq|SELECT id FROM ap WHERE id = ?|;
  • $sth = $dbh->prepare($query);
  • $sth->execute($form->{id});
  • if ($sth->fetchrow_array) {
  • $query = qq|
  • SELECT p.id, p.inventory_accno_id,
  • p.income_accno_id
  • FROM invoice i
  • JOIN parts p ON (p.id = i.parts_id)
  • WHERE i.trans_id = ?|;
  • $sth = $dbh->prepare($query);
  • $sth->execute($form->{id}) || $form->dberror($query);
  • while ($ref = $sth->fetchrow_hashref) {
  • if ($ref->{inventory_accno_id}
  • && $ref->{income_accno_id}) {
  • $updparts{$ref->{id}} = 1;
  • }
  • }
  • $sth->finish;
  • &reverse_invoice($dbh, $form);
  • } else {
  • $query = qq|INSERT INTO ap (id) VALUES (?)|;
  • $sth = $dbh->prepare($query);
  • $sth->execute($form->{id}) || $form->dberror($query);
  • }
  • }
  • my $uid = localtime;
  • $uid .= "$$";
  • if (! $form->{id}) {
  • $query = qq|
  • INSERT INTO ap (invnumber, employee_id)
  • VALUES ('$uid', (SELECT id FROM employee
  • WHERE login = ?))|;
  • $sth = $dbh->prepare($query);
  • $sth->execute($form->{login}) || $form->dberror($query);
  • $query = qq|SELECT id FROM ap WHERE invnumber = '$uid'|;
  • $sth = $dbh->prepare($query);
  • $sth->execute || $form->dberror($query);
  • ($form->{id}) = $sth->fetchrow_array;
  • $sth->finish;
  • }
  • my $amount;
  • my $grossamount;
  • my $allocated;
  • my $invamount = 0;
  • my $invnetamount = 0;
  • if ($form->{currency} eq $form->{defaultcurrency}) {
  • $form->{exchangerate} = 1;
  • } else {
  • $exchangerate =
  • $form->check_exchangerate(
  • $myconfig, $form->{currency},
  • $form->{transdate}, 'sell');
  • }
  • $form->{exchangerate} =
  • ($exchangerate)
  • ? $exchangerate
  • : $form->parse_amount($myconfig, $form->{exchangerate});
  • for my $i (1 .. $form->{rowcount}) {
  • $form->{"qty_$i"} =
  • $form->parse_amount($myconfig, $form->{"qty_$i"});
  • if ($form->{"qty_$i"}) {
  • $pth->execute($form->{"id_$i"});
  • $ref = $pth->fetchrow_hashref(NAME_lc);
  • for (keys %$ref) {
  • $form->{"${_}_$i"} = $ref->{$_};
  • }
  • $pth->finish;
  • # project
  • if ($form->{"projectnumber_$i"} ne "") {
  • ($null, $project_id) =
  • split /--/, $form->{"projectnumber_$i"};
  • }
  • # undo discount formatting
  • $form->{"discount_$i"} =
  • $form->parse_amount(
  • $myconfig,
  • $form->{"discount_$i"}) / 100;
  • # keep entered selling price
  • my $fxsellprice =
  • $form->parse_amount(
  • $myconfig, $form->{"sellprice_$i"});
  • my ($dec) = ($fxsellprice =~ /\.(\d+)/);
  • $dec = length $dec;
  • my $decimalplaces = ($dec > 2) ? $dec : 2;
  • # deduct discount
  • $form->{"sellprice_$i"} =
  • $fxsellprice - $form->round_amount(
  • $fxsellprice * $form->{"discount_$i"},
  • $decimalplaces);
  • # linetotal
  • my $fxlinetotal = $form->round_amount(
  • $form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
  • $amount = $fxlinetotal * $form->{exchangerate};
  • my $linetotal = $form->round_amount($amount, 2);
  • $fxdiff += $amount - $linetotal;
  • @taxaccounts = Tax::init_taxes(
  • $form, $form->{"taxaccounts_$i"});
  • $tax = Math::BigFloat->bzero();
  • $fxtax = Math::BigFloat->bzero();
  • if ($form->{taxincluded}) {
  • $tax += $amount = Tax::calculate_taxes(
  • \@taxaccounts, $form, $linetotal, 1);
  • $form->{"sellprice_$i"}
  • -= $amount / $form->{"qty_$i"};
  • } else {
  • $tax += $amount = Tax::calculate_taxes(
  • \@taxaccounts, $form, $linetotal, 0);
  • $fxtax += Tax::calculate_taxes(
  • \@taxaccounts, $form, $fxlinetotal, 0);
  • }
  • for (@taxaccounts) {
  • $form->{acc_trans}{$form->{id}}{$_->account}{amount} += $_->value;
  • }
  • $grossamount = $form->round_amount($linetotal, 2);
  • if ($form->{taxincluded}) {
  • $amount = $form->round_amount($tax, 2);
  • $linetotal -= $form->round_amount(
  • $tax - $diff, 2);
  • $diff = ($amount - $tax);
  • }
  • $amount = $form->round_amount($linetotal, 2);
  • $allocated = 0;
  • # adjust and round sellprice
  • $form->{"sellprice_$i"} = $form->round_amount(
  • $form->{"sellprice_$i"} * $form->{exchangerate},
  • $decimalplaces);
  • # save detail record in invoice table
  • $query = qq|
  • INSERT INTO invoice (description)
  • VALUES ('$uid')|;
  • $dbh->do($query) || $form->dberror($query);
  • $query = qq|
  • SELECT id FROM invoice
  • WHERE description = '$uid'|;
  • ($invoice_id) = $dbh->selectrow_array($query);
  • $form->debug;
  • $query = qq|
  • UPDATE invoice
  • SET trans_id = ?,
  • parts_id = ?,
  • description = ?,
  • qty = ? * -1,
  • sellprice = ?,
  • fxsellprice = ?,
  • discount = ?,
  • allocated = ?,
  • unit = ?,
  • deliverydate = ?,
  • project_id = ?,
  • serialnumber = ?,
  • notes = ?
  • WHERE id = ?|;
  • $sth = $dbh->prepare($query);
  • $sth->execute(
  • $form->{id}, $form->{"id_$i"},
  • $form->{"description_$i"}, $form->{"qty_$i"},
  • $form->{"sellprice_$i"}, $fxsellprice,
  • $form->{"discount_$i"}, $allocated,
  • $form->{"unit_$i"}, $form->{"deliverydate_$i"},
  • $project_id, $form->{"serialnumber_$i"},
  • $form->{"notes_$i"}, $invoice_id)
  • || $form->dberror($query);
  • if ($form->{"inventory_accno_id_$i"}) {
  • # add purchase to inventory
  • push @{ $form->{acc_trans}{lineitems} },
  • {chart_id =>
  • $form->{"inventory_accno_id_$i"},
  • amount => $amount,
  • fxgrossamount => $fxlinetotal +
  • $form->round_amount($fxtax, 2),
  • grossamount => $grossamount,
  • project_id => $project_id,
  • invoice_id => $invoice_id };
  • $updparts{$form->{"id_$i"}} = 1;
  • # update parts table
  • $form->update_balance(
  • $dbh, "parts", "onhand",
  • qq|id = $form->{"id_$i"}|,
  • $form->{"qty_$i"})
  • unless $form->{shipped};