use List::Util qw(max first);
use SL::AM;
use SL::Common;
+use SL::CVar;
use SL::DBUtils;
use SL::IC;
qq| o.marge_total, o.marge_percent, | .
qq| ex.$rate AS exchangerate, | .
qq| pr.projectnumber AS globalprojectnumber, | .
- qq| e.name AS employee, s.name AS salesman | .
+ qq| e.name AS employee, s.name AS salesman, | .
+ qq| ct.country, ct.ustid | .
qq|FROM oe o | .
qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | .
qq|LEFT JOIN employee e ON (o.employee_id = e.id) | .
qq|WHERE (o.quotation = ?) |;
push(@values, $quotation);
- my ($null, $department_id) = split /--/, $form->{department};
+ my ($null, $split_department_id) = split /--/, $form->{department};
+ my $department_id = $form->{department_id} || $split_department_id;
if ($department_id) {
$query .= qq| AND o.department_id = ?|;
push(@values, $department_id);
my $all_units = AM->retrieve_units($myconfig, $form);
$form->{all_units} = $all_units;
+ my $ic_cvar_configs = CVar->get_configs(module => 'IC',
+ dbh => $dbh);
+
$form->{employee_id} = (split /--/, $form->{employee})[1] if !$form->{employee_id};
unless ($form->{employee_id}) {
$form->get_employee($dbh);
my $ml = ($form->{type} eq 'sales_order') ? 1 : -1;
if ($form->{id}) {
+ $query = qq|DELETE FROM custom_variables
+ WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE module = 'IC'))
+ AND (sub_module = 'orderitems')
+ AND (trans_id IN (SELECT id FROM orderitems WHERE trans_id = ?))|;
+ do_query($form, $dbh, $query, $form->{id});
$query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
do_query($form, $dbh, $query, $form->{id});
$pricegroup_id *= 1;
# save detail record in orderitems table
+ my $orderitems_id = $form->{"orderitems_id_$i"};
+ ($orderitems_id) = selectfirst_array_query($form, $dbh, qq|SELECT nextval('orderitemsid')|) if (!$orderitems_id);
+
@values = ();
- $query = qq|INSERT INTO orderitems (|;
- if ($form->{"orderitems_id_$i"}) {
- $query .= "id, ";
- }
- $query .= qq|trans_id, parts_id, description, longdescription, qty, base_qty, | .
- qq|sellprice, discount, unit, reqdate, project_id, serialnumber, ship, | .
- qq|pricegroup_id, ordnumber, transdate, cusordnumber, subtotal, | .
- qq|marge_percent, marge_total, lastcost, price_factor_id, price_factor, marge_price_factor) | .
- qq|VALUES (|;
- if($form->{"orderitems_id_$i"}) {
- $query .= qq|?,|;
- push(@values, $form->{"orderitems_id_$i"});
- }
- $query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
- (SELECT factor FROM price_factors WHERE id = ?), ?)|;
+ $query = qq|INSERT INTO orderitems (
+ id, trans_id, parts_id, description, longdescription, qty, base_qty,
+ sellprice, discount, unit, reqdate, project_id, serialnumber, ship,
+ pricegroup_id, ordnumber, transdate, cusordnumber, subtotal,
+ marge_percent, marge_total, lastcost, price_factor_id, price_factor, marge_price_factor)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
+ (SELECT factor FROM price_factors WHERE id = ?), ?)|;
push(@values,
- conv_i($form->{id}), conv_i($form->{"id_$i"}),
+ conv_i($orderitems_id), conv_i($form->{id}), conv_i($form->{"id_$i"}),
$form->{"description_$i"}, $form->{"longdescription_$i"},
$form->{"qty_$i"}, $baseqty,
$fxsellprice, $form->{"discount_$i"},
$form->{"sellprice_$i"} = $fxsellprice;
$form->{"discount_$i"} *= 100;
+
+ CVar->save_custom_variables(module => 'IC',
+ sub_module => 'orderitems',
+ trans_id => $orderitems_id,
+ configs => $ic_cvar_configs,
+ variables => $form,
+ name_prefix => 'ic_',
+ name_postfix => "_$i",
+ dbh => $dbh);
}
}
my ($query, $query_add, @values, @ids, $sth);
+ my $ic_cvar_configs = CVar->get_configs(module => 'IC',
+ dbh => $dbh);
+
# translate the ids (given by id_# and trans_id_#) into one array of ids, so we can join them later
map {
push @ids, $form->{"trans_id_$_"}
$sth = prepare_execute_query($form, $dbh, $query, @values);
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ # Retrieve custom variables.
+ my $cvars = CVar->get_custom_variables(dbh => $dbh,
+ module => 'IC',
+ sub_module => 'orderitems',
+ trans_id => $ref->{orderitems_id},
+ );
+ map { $ref->{"ic_cvar_$_->{name}"} = $_->{value} } @{ $cvars };
+
+ # Handle accounts.
if (!$ref->{"part_inventory_accno_id"}) {
map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid));
}
}
chop $ref->{taxaccounts};
+
push @{ $form->{form_details} }, $ref;
$stw->finish;
}
$form->{discount} = [];
+ $form->{TEMPLATE_ARRAYS} = { };
IC->prepare_parts_for_printing();
+ my $ic_cvar_configs = CVar->get_configs(module => 'IC');
+
my @arrays =
qw(runningnumber number description longdescription qty ship unit bin
partnotes serialnumber reqdate sellprice listprice netprice
linetotal nodiscount_linetotal tax_rate projectnumber
price_factor price_factor_name partsgroup);
+ push @arrays, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
+
my @tax_arrays = qw(taxbase tax taxdescription taxrate taxnumber);
- $form->{TEMPLATE_ARRAYS} = { map { $_ => [] } (@arrays, @tax_arrays) };
+ map { $form->{TEMPLATE_ARRAYS}->{$_} = [] } (@arrays, @tax_arrays);
my $sameitem = "";
foreach $item (sort { $a->[1] cmp $b->[1] } @partsgroup) {
$sth->finish;
}
+ map { push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, $form->{"ic_cvar_$_->{name}_$i"} } @{ $ic_cvar_configs };
}
}