use Data::Dumper;
use SL::AM;
+use SL::Common;
+use SL::DBUtils;
sub invoice_details {
$main::lxdebug->enter_sub();
$form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
- if ($form->{"qty_$i"} != 0) {
+ if ($form->{"id_$i"} != 0) {
# add number, description and qty to $form->{number},
if ($form->{"subtotal_$i"} && !$subtotal_header) {
($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
$form->{total} =
$form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
+
$form->{invtotal} = $form->format_amount($myconfig, $form->{invtotal}, 2);
- $form->set_payment_options($myconfig, $form->{invdate});
$form->{paid} = $form->format_amount($myconfig, $form->{paid}, 2);
+ $form->set_payment_options($myconfig, $form->{invdate});
$form->{username} = $myconfig->{name};
# remove id and taxincluded before copy back
delete @$ref{qw(id taxincluded)};
+ @wanted_vars = grep({ $_ } @wanted_vars);
if (scalar(@wanted_vars) > 0) {
my %h_wanted_vars;
map({ $h_wanted_vars{$_} = 1; } @wanted_vars);
$form->get_employee($dbh);
}
- $form->{contact_id} = $form->{cp_id};
- $form->{contact_id} *= 1;
$form->{payment_id} *= 1;
$form->{language_id} *= 1;
$form->{taxzone_id} *= 1;
$form->{"qty_$i"} *= -1;
}
- if ($form->{"qty_$i"} != 0) {
+ if ($form->{"id_$i"}) {
# get item baseunit
$query = qq|SELECT p.unit
# save AR record
$query = qq|UPDATE ar set
invnumber = '$form->{invnumber}',
- ordnumber = '$form->{ordnumber}',
- quonumber = '$form->{quonumber}',
- cusordnumber = '$form->{cusordnumber}',
+ ordnumber = '$form->{ordnumber}',
+ quonumber = '$form->{quonumber}',
+ cusordnumber = '$form->{cusordnumber}',
transdate = '$form->{invdate}',
+ orddate = | . conv_dateq($form->{orddate}) . qq|,
+ quodate = | . conv_dateq($form->{quodate}) . qq|,
customer_id = $form->{customer_id},
amount = $amount,
netamount = $netamount,
paid = $form->{paid},
- datepaid = $datepaid,
- duedate = $duedate,
+ datepaid = $datepaid,
+ duedate = $duedate,
deliverydate = $deliverydate,
- invoice = '1',
- shippingpoint = '$form->{shippingpoint}',
- shipvia = '$form->{shipvia}',
- terms = $form->{terms},
- notes = '$form->{notes}',
- intnotes = '$form->{intnotes}',
- taxincluded = '$form->{taxincluded}',
- curr = '$form->{currency}',
- department_id = $form->{department_id},
- payment_id = $form->{payment_id},
+ invoice = '1',
+ shippingpoint = '$form->{shippingpoint}',
+ shipvia = '$form->{shipvia}',
+ terms = $form->{terms},
+ notes = '$form->{notes}',
+ intnotes = '$form->{intnotes}',
+ taxincluded = '$form->{taxincluded}',
+ curr = '$form->{currency}',
+ department_id = $form->{department_id},
+ payment_id = $form->{payment_id},
type = '$form->{type}',
- language_id = $form->{language_id},
- taxzone_id = $form->{taxzone_id},
- shipto_id = $form->{shipto_id},
- delivery_customer_id = $form->{delivery_customer_id},
- delivery_vendor_id = $form->{delivery_vendor_id},
- employee_id = $form->{employee_id},
+ language_id = $form->{language_id},
+ taxzone_id = $form->{taxzone_id},
+ shipto_id = $form->{shipto_id},
+ delivery_customer_id = $form->{delivery_customer_id},
+ delivery_vendor_id = $form->{delivery_vendor_id},
+ employee_id = $form->{employee_id},
storno = '$form->{storno}',
- cp_id = $form->{contact_id}
+ cp_id = | . conv_i($form->{"cp_id"}, 'NULL') . qq|
WHERE id = $form->{id}
|;
$dbh->do($query) || $form->dberror($query);
# save printed, emailed and queued
$form->save_status($dbh);
- 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.invnumber, a.ordnumber, a.quonumber, a.cusordnumber,
+ a.orddate, a.quodate,
a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes, a.taxzone_id,
a.duedate, a.taxincluded, a.curr AS currency, a.shipto_id, a.cp_id,
}
$sth->finish;
- if ($form->{webdav}) {
- &webdav_folder($myconfig, $form);
- }
+ Common::webdav_folder($form) if ($main::webdav);
}
my $rc = $dbh->commit;
}
$sth->finish;
- $form->get_contacts($dbh, $form->{customer_id});
- $form->{cp_id} *= 1;
-
- # get contact if selected
- if ($form->{cp_id}) {
- $form->get_contact($dbh, $form->{cp_id});
- }
-
# get shipto if we did not converted an order or invoice
if (!$form->{shipto}) {
map { delete $form->{$_} }
}
$sth->finish;
- # get shipping addresses
- $query = qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1
- FROM shipto s
- WHERE s.trans_id = $form->{customer_id}|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $customertax = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push(@{ $form->{SHIPTO} }, $ref);
- }
- $sth->finish;
-
# setup last accounts used for this customer
if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) {
$query = qq|SELECT c.accno, c.description, c.link, c.category
$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();
-}
-
1;