my $query =
qq|SELECT dord.id, dord.donumber, dord.ordnumber, dord.transdate,
- ct.name, dord.${vc}_id, dord.globalproject_id,
+ ct.${vc}number, ct.name, dord.${vc}_id, dord.globalproject_id,
dord.closed, dord.delivered, dord.shippingpoint, dord.shipvia,
dord.transaction_description,
pr.projectnumber AS globalprojectnumber,
+ dep.description AS department,
e.name AS employee,
sm.name AS salesman
FROM delivery_orders dord
LEFT JOIN $vc ct ON (dord.${vc}_id = ct.id)
LEFT JOIN employee e ON (dord.employee_id = e.id)
LEFT JOIN employee sm ON (dord.salesman_id = sm.id)
- LEFT JOIN project pr ON (dord.globalproject_id = pr.id)|;
+ LEFT JOIN project pr ON (dord.globalproject_id = pr.id)
+ LEFT JOIN department dep ON (dord.department_id = dep.id)
+|;
push @where, ($form->{type} eq 'sales_delivery_order' ? '' : 'NOT ') . qq|COALESCE(dord.is_sales, FALSE)|;
- my $department_id = (split /--/, $form->{department})[1];
- if ($department_id) {
+ if ($form->{department_id}) {
push @where, qq|dord.department_id = ?|;
- push @values, conv_i($department_id);
+ push @values, conv_i($form->{department_id});
}
if ($form->{project_id}) {
"employee" => "e.name",
"salesman" => "sm.name",
"shipvia" => "dord.shipvia",
- "transaction_description" => "dord.transaction_description"
+ "transaction_description" => "dord.transaction_description",
+ "department" => "lower(dep.description)",
);
my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
}
my $project_id;
- my $reqdate;
+ my $items_reqdate;
$form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
id, delivery_order_id, parts_id, description, longdescription, qty, base_qty,
sellprice, discount, unit, reqdate, project_id, serialnumber,
ordnumber, transdate, cusordnumber,
- lastcost, price_factor_id, price_factor, marge_price_factor)
+ lastcost, price_factor_id, price_factor, marge_price_factor, pricegroup_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
- (SELECT factor FROM price_factors WHERE id = ?), ?)|;
+ (SELECT factor FROM price_factors WHERE id = ?), ?, ?)|;
my $h_item = prepare_query($form, $dbh, $q_item);
my $q_item_stock =
$price_factor = $price_factors{ $form->{"price_factor_id_$i"} } || 1;
my $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor, 2);
- $reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
+ $items_reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
do_statement($form, $h_item_id, $q_item_id);
my ($item_id) = $h_item_id->fetchrow_array();
$form->{"description_$i"}, $form->{"longdescription_$i"},
$form->{"qty_$i"}, $baseqty,
$form->{"sellprice_$i"}, $form->{"discount_$i"} / 100,
- $form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}),
+ $form->{"unit_$i"}, conv_date($items_reqdate), conv_i($form->{"project_id_$i"}),
$form->{"serialnumber_$i"},
$form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
$form->{"cusordnumber_$i"},
$form->{"lastcost_$i"},
conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
- conv_i($form->{"marge_price_factor_$i"}));
+ conv_i($form->{"marge_price_factor_$i"}),
+ conv_i($form->{"pricegroup_id_$i"}));
do_statement($form, $h_item, $q_item, @values);
my $stock_info = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_$i"});
$h_item->finish();
$h_item_stock->finish();
- ($null, $form->{department_id}) = split(/--/, $form->{department});
+ # reqdate is last items reqdate (?: old behaviour) if not already set
+ $form->{reqdate} ||= $items_reqdate;
# save DO record
$query =
qq|UPDATE delivery_orders SET
@values = ($form->{donumber}, $form->{ordnumber},
$form->{cusordnumber}, conv_date($form->{transdate}),
conv_i($form->{vendor_id}), conv_i($form->{customer_id}),
- conv_date($reqdate), $form->{shippingpoint}, $form->{shipvia},
+ conv_date($form->{reqdate}), $form->{shippingpoint}, $form->{shipvia},
$form->{notes}, $form->{intnotes},
$form->{closed} ? 't' : 'f', $form->{delivered} ? "t" : "f",
conv_i($form->{department_id}), conv_i($form->{language_id}), conv_i($form->{shipto_id}),
my $mode = !$params{ids} ? 'default' : ref $params{ids} eq 'ARRAY' ? 'multi' : 'single';
if ($mode eq 'default') {
- $ref = selectfirst_hashref_query($form, $dbh, qq|SELECT current_date AS transdate, current_date AS reqdate|);
+ $ref = selectfirst_hashref_query($form, $dbh, qq|SELECT current_date AS transdate|);
map { $form->{$_} = $ref->{$_} } keys %$ref;
+ # if reqdate is not set from oe-workflow, set it to transdate (which is current date)
+ $form->{reqdate} ||= $form->{transdate};
+
# get last name used
$form->lastname_used($dbh, $myconfig, $vc) unless $form->{"${vc}_id"};
doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.bin, p.notes AS partnotes,
doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost,
doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription,
- doi.price_factor_id, doi.price_factor, doi.marge_price_factor,
+ doi.price_factor_id, doi.price_factor, doi.marge_price_factor, doi.pricegroup_id,
pr.projectnumber, dord.transdate AS dord_transdate,
pg.partsgroup
FROM delivery_order_items doi