use SL::DB::Status;
use SL::DB::Tax;
use SL::DBUtils;
+use SL::HTML::Restrict;
use SL::IC;
+use SL::TransNumber;
use strict;
my $vc = $form->{vc} eq "customer" ? "customer" : "vendor";
+ my %billed_amount;
+ my %billed_netamount;
+ if ($form->{l_remaining_amount} || $form->{l_remaining_netamount}) {
+ $query = <<'';
+ SELECT from_id, ar.amount, ar.netamount FROM (
+ SELECT from_id, to_id
+ FROM record_links
+ WHERE from_table = 'oe' AND to_table = 'ar'
+ UNION
+ SELECT rl1.from_id, rl2.to_id
+ FROM record_links rl1
+ LEFT JOIN record_links rl2 ON (rl1.to_table = rl2.from_table AND rl1.to_id = rl2.from_id)
+ WHERE rl1.from_table = 'oe' AND rl2.to_table = 'ar'
+ ) rl
+ LEFT JOIN ar ON ar.id = rl.to_id
+
+ for my $ref (@{ selectall_hashref_query($form, $dbh, $query) }) {
+ $billed_amount{ $ref->{from_id}} += $ref->{amount};
+ $billed_netamount{$ref->{from_id}} += $ref->{netamount};
+ }
+ }
+
$query =
qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate, | .
qq| o.amount, ct.${vc}number, ct.name, o.netamount, o.${vc}_id, o.globalproject_id, | .
- qq| o.closed, o.delivered, o.quonumber, o.shippingpoint, o.shipvia, | .
+ qq| o.closed, o.delivered, o.quonumber, o.cusordnumber, o.shippingpoint, o.shipvia, | .
qq| o.transaction_description, | .
qq| o.marge_total, o.marge_percent, | .
qq| ex.$rate AS exchangerate, | .
push(@values, '%' . $form->{$ordnumber} . '%');
}
+ if ($form->{cusordnumber}) {
+ $query .= qq| AND o.cusordnumber ILIKE ?|;
+ push(@values, '%' . $form->{cusordnumber} . '%');
+ }
+
if($form->{transdatefrom}) {
$query .= qq| AND o.transdate >= ?|;
push(@values, conv_date($form->{transdatefrom}));
"reqdate" => "o.reqdate",
"id" => "o.id",
"ordnumber" => "o.ordnumber",
+ "cusordnumber" => "o.cusordnumber",
"quonumber" => "o.quonumber",
"name" => "ct.name",
"employee" => "e.name",
my %id = ();
$form->{OE} = [];
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+ $ref->{billed_amount} = $billed_amount{$ref->{id}};
+ $ref->{billed_netamount} = $billed_netamount{$ref->{id}};
+ $ref->{remaining_amount} = $ref->{amount} - $ref->{billed_amount};
+ $ref->{remaining_netamount} = $ref->{netamount} - $ref->{billed_netamount};
$ref->{exchangerate} = 1 unless $ref->{exchangerate};
push @{ $form->{OE} }, $ref if $ref->{id} != $id{ $ref->{id} };
$id{ $ref->{id} } = $ref->{id};
# connect to database, turn off autocommit
my $dbh = $form->get_standard_dbh;
+ my $restricter = SL::HTML::Restrict->create;
my ($query, @values, $sth, $null);
my $exchangerate = 0;
my $ml = ($form->{type} eq 'sales_order') ? 1 : -1;
+ my $number_field = $form->{type} =~ m{order} ? 'ordnumber' : 'quonumber';
+ my $trans_number = SL::TransNumber->new(type => $form->{type}, dbh => $dbh, number => $form->{$number_field}, id => $form->{id});
+ $form->{$number_field} ||= $trans_number->create_unique;
+
if ($form->{id}) {
$query = qq|DELETE FROM custom_variables
WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE module = 'IC'))
(SELECT factor FROM price_factors WHERE id = ?), ?)|;
push(@values,
conv_i($orderitems_id), conv_i($form->{id}), conv_i($form->{"id_$i"}),
- $form->{"description_$i"}, $form->{"longdescription_$i"},
+ $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}),
$form->{"qty_$i"}, $baseqty,
$fxsellprice, $form->{"discount_$i"},
$form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}),