package IR;
use SL::AM;
+use SL::Common;
use SL::DBUtils;
sub post_invoice {
$sth->finish;
}
- ($null, $form->{contact_id}) = split /--/, $form->{contact};
- $form->{contact_id} *= 1;
-
map { $form->{$_} =~ s/\'/\'\'/g } qw(invnumber ordnumber quonumber);
my ($amount, $linetotal, $lastinventoryaccno, $lastexpenseaccno);
}
- $project_id = 'NULL';
- if ($form->{"projectnumber_$i"}) {
- $project_id = $form->{"projectnumber_$i"};
- }
$deliverydate =
($form->{"deliverydate_$i"})
? qq|'$form->{"deliverydate_$i"}'|
VALUES ($form->{id}, $form->{"id_$i"},
'$form->{"description_$i"}', | . ($form->{"qty_$i"} * -1) . qq|, | . ($baseqty * -1) . qq|,
$form->{"sellprice_$i"}, $fxsellprice, $allocated,
- '$form->{"unit_$i"}', $deliverydate, (SELECT id FROM project WHERE projectnumber = '$project_id'),
+ '$form->{"unit_$i"}', $deliverydate, | . conv_i($form->{"project_id_$i"}, 'NULL') . qq|,
'$form->{"serialnumber_$i"}')|;
$dbh->do($query) || $form->dberror($query);
}
}
+ $project_id = conv_i($form->{"globalproject_id"});
+
$form->{datepaid} = $form->{invdate};
# all amounts are in natural state, netamount includes the taxes
) != 0
) {
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, taxkey)
+ transdate, taxkey, project_id)
VALUES ($trans_id, (SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
$form->{amount}{$trans_id}{$accno}, '$form->{invdate}',
- (SELECT taxkey_id FROM chart WHERE accno = '$accno'))|;
- $dbh->do($query) || $form->dberror($query);
+ (SELECT taxkey_id FROM chart WHERE accno = '$accno'), ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
}
}
if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) {
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate)
+ transdate, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$form->{AP}'),
- $amount, '$form->{"datepaid_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
# record payment
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo)
+ source, memo, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
$form->{"paid_$i"}, '$form->{"datepaid_$i"}',
- '$form->{"source_$i"}', '$form->{"memo_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ '$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
$exchangerate = 0;
) {
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, cleared, fx_transaction)
+ transdate, cleared, fx_transaction, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
- $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|;
- $dbh->do($query) || $form->dberror($query);
+ $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
}
}
curr = '$form->{currency}',
department_id = $form->{department_id},
storno = '$form->{storno}',
- cp_id = $form->{contact_id}
+ globalproject_id = | . conv_i($form->{"globalproject_id"}, 'NULL') . qq|,
+ cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq|
WHERE id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
WHERE amount = 0|;
$dbh->do($query) || $form->dberror($query);
- if ($form->{webdav}) {
- &webdav_folder($myconfig, $form);
- }
+ Common::webdav_folder($form) if ($main::webdav);
my $rc = $dbh->commit;
$dbh->disconnect;
# retrieve invoice
$query = qq|SELECT a.cp_id, a.invnumber, a.transdate AS invdate, a.duedate,
- a.orddate, a.quodate,
+ a.orddate, a.quodate, a.globalproject_id,
a.ordnumber, a.quonumber, a.paid, a.taxincluded, a.notes, a.taxzone_id, a.storno, a.gldate,
a.intnotes, a.curr AS currency
FROM ap a
}
$sth->finish;
- if ($form->{webdav}) {
- &webdav_folder($myconfig, $form);
- }
-
+ Common::webdav_folder($form) if ($main::webdav);
}
my $rc = $dbh->commit;
my $query = qq|SELECT v.name AS vendor, v.creditlimit, v.terms,
v.email, v.cc, v.bcc, v.language_id, v.payment_id,
v.street, v.zipcode, v.city, v.country, v.taxzone_id,
- $duedate + v.terms AS duedate
+ $duedate + v.terms AS duedate,
+ b.description AS business
FROM vendor v
+ LEFT JOIN business b ON b.id = v.business_id
WHERE v.id = $form->{vendor_id}|;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
}
$sth->finish;
- $form->get_contacts($dbh, $form->{vendor_id});
-
- ($null, $form->{cp_id}) = split /--/, $form->{contact};
-
- # get contact if selected
- if ($form->{contact} ne "--" && $form->{contact} ne "") {
- $form->get_contact($dbh, $form->{cp_id});
- }
-
# get shipto if we do not convert an order or invoice
if (!$form->{shipto}) {
map { delete $form->{$_} }
$main::lxdebug->leave_sub();
}
-sub webdav_folder {
- $main::lxdebug->enter_sub();
-
- my ($myconfig, $form) = @_;
-
-SWITCH: {
- $path = "webdav/rechnungen/" . $form->{invnumber}, last SWITCH
- if ($form->{vc} eq "customer");
- $path = "webdav/einkaufsrechnungen/" . $form->{invnumber}, last SWITCH
- if ($form->{vc} eq "vendor");
- }
-
- if (!-d $path) {
- mkdir($path, 0770) or die "can't make directory $!\n";
- } else {
- if ($form->{id}) {
- @files = <$path/*>;
- foreach $file (@files) {
-
- $file =~ /\/([^\/]*)$/;
- $fname = $1;
- $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//;
- $lxerp = $1;
- $link = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file;
- $form->{WEBDAV}{$fname} = $link;
- }
- }
- }
-
- $main::lxdebug->leave_sub();
-}
-
sub post_payment {
$main::lxdebug->enter_sub();
$form->get_exchangerate($dbh, $form->{currency}, $form->{invdate},
"buy");
+ my $project_id = conv_i($form->{"globalproject_id"});
+
# record payments and offsetting AP
for my $i (1 .. $form->{paidaccounts}) {
$dbh->do($query) || $form->dberror($query);
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate)
+ transdate, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$form->{AP}'),
- $amount, '$form->{"datepaid_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
$dbh->do($query) || $form->dberror($query);
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo)
+ source, memo, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
$form->{"paid_$i"}, '$form->{"datepaid_$i"}',
- '$form->{"source_$i"}', '$form->{"memo_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ '$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
# gain/loss
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|;
$dbh->do($query) || $form->dberror($query);
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, cleared, fx_transaction)
+ transdate, cleared, fx_transaction, project_id)
VALUES ($form->{id},
(SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
- $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|;
- $dbh->do($query) || $form->dberror($query);
+ $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
}
}