require SL::DB::Employee;
require SL::DB::Inventory;
- my $employee = SL::DB::Manager::Employee->find_by(login => $::form->{login});
+ my $employee = SL::DB::Manager::Employee->find_by(login => $::myconfig{login});
my ($now) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT current_date|);
my @directions = (undef, qw(out in transfer));
my @trans_ids;
my $db = SL::DB::Inventory->new->db;
- $db->do_transaction(sub{
+ $db->with_transaction(sub{
while (my $transfer = shift @args) {
my ($trans_id) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT nextval('id')|);
trans_id => $trans_id,
shippingdate => !$transfer->{shippingdate} || $transfer->{shippingdate} eq 'current_date'
? $now : $transfer->{shippingdate},
- map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id delivery_order_items_stock_id comment),
+ map { $_ => $transfer->{$_} } qw(chargenumber bestbefore oe_id delivery_order_items_stock_id invoice_id comment),
);
if ($unit) {
)->save;
# Standardlagerplatz in Stammdaten gleich mitverschieben
if (defined($transfer->{change_default_bin})){
- my $part = SL::DB::Part->new(id => conv_i($transfer->{parts_id}))->load;
- $part->update_attributes(warehouse_id => conv_i($transfer->{dst_warehouse_id}));
- $part->update_attributes(bin_id => conv_i($transfer->{dst_bin_id}));
+ $part->update_attributes(warehouse_id => $dst_wh->id, bin_id => $dst_bin->id);
}
- }
+ }
push @trans_ids, $trans_id;
}
+
+ 1;
}) or do {
$::form->error("Warehouse transfer error: " . join("\n", (split(/\n/, $db->error))[0..2]));
};
}
if ($form->{fromdate}) {
- push @filter_ary, "?::DATE <= i1.itime::DATE";
+ push @filter_ary, "? <= i1.shippingdate";
push @filter_vars, $form->{fromdate};
}
if ($form->{todate}) {
- push @filter_ary, "?::DATE >= i1.itime::DATE";
+ push @filter_ary, "? >= i1.shippingdate";
push @filter_vars, $form->{todate};
}
my $sort_order = $form->{order};
$sort_col = $filter{sort} unless $sort_col;
- $sort_order = ($sort_col = 'itime') unless $sort_col;
- $sort_col = 'itime' if $sort_col eq 'date';
+ $sort_order = ($sort_col = 'shippingdate') unless $sort_col;
+ $sort_col = 'shippingdate' if $sort_col eq 'date';
$sort_order = $filter{order} unless $sort_order;
my $sort_spec = "${sort_col} " . ($sort_order ? " DESC" : " ASC");
"trans_type" => "tt.description",
"trans_id" => "i1.trans_id",
"oe_id" => "COALESCE(i1.oe_id, i2.oe_id)",
- "date" => "i1.itime::DATE",
+ "invoice_id" => "COALESCE(i1.invoice_id, i2.invoice_id)",
+ "date" => "i1.shippingdate",
"itime" => "i1.itime",
+ "shippingdate" => "i1.shippingdate",
"employee" => "e.name",
"projectnumber" => "COALESCE(pr.projectnumber, '$filter{na}')",
};
"warehouse_from" => "'$filter{na}'",
};
+ $form->{l_invoice_id} = $form->{l_oe_id} if $form->{l_oe_id};
+
# build the select clauses.
# take all the requested ones from the first hash and overwrite them from the out/in hashes if present.
for my $i ('trans', 'out', 'in') {
$select{$i} = join ', ', map { +/^l_/; ($select_tokens{$i}{"$'"} || $select_tokens{'trans'}{"$'"}) . " AS r_$'" }
- ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_qty l_partunit l_itime) );
+ ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_qty l_partunit l_shippingdate) );
}
my $group_clause = join ", ", map { +/^l_/; "r_$'" }
- ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_itime) );
+ ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_shippingdate) );
$where_clause = defined($where_clause) ? $where_clause : '';
+
my $query =
qq|SELECT DISTINCT $select{trans}
FROM inventory i1
SELECT ap.id AS id, ap.invnumber AS number, 'purchase_invoice' AS type
FROM ap
WHERE ap.id = ?
+
+ UNION
+
+ SELECT ar.id AS id, ar.invnumber AS number, 'sales_invoice' AS type
+ FROM ar
+ WHERE ar.id = (SELECT trans_id FROM invoice WHERE id = ?)
+
+ UNION
+
+ SELECT ap.id AS id, ap.invnumber AS number, 'purchase_invoice' AS type
+ FROM ap
+ WHERE ap.id = (SELECT trans_id FROM invoice WHERE id = ?)
SQL
$h_oe_id = prepare_query($form, $dbh, $q_oe_id);
}
next if (('<=' eq $f_qty_op) && ($qty > $f_qty));
}
- if ($h_oe_id && $ref->{oe_id}) {
- do_statement($form, $h_oe_id, $q_oe_id, ($ref->{oe_id}) x 4);
+ if ($h_oe_id && ($ref->{oe_id} || $ref->{invoice_id})) {
+ my $id = $ref->{oe_id} ? $ref->{oe_id} : $ref->{invoice_id};
+ do_statement($form, $h_oe_id, $q_oe_id, ($id) x 6);
$ref->{oe_id_info} = $h_oe_id->fetchrow_hashref() || {};
}
}
if ($filter{date}) {
- push @filter_ary, "i.itime <= ?";
+ push @filter_ary, "i.shippingdate <= ?";
push @filter_vars, $filter{date};
}
if (!$filter{include_invalid_warehouses}){
while (my $ref = $sth_QTY->fetchrow_hashref()) { # wir laufen über alle Haltbarkeiten und Chargen(s.a. SQL-Query oben)
$max_qty_parts += $ref->{sum};
$i++;
- if ($ref->{chargenumber} || $ref->{bestbefore}){
- $error=1;
+ if (($ref->{chargenumber} || $ref->{bestbefore}) && $ref->{sum} != 0){
+ $error = 1;
}
}
- #if ($i < 1){
- # $error = 2;
- #}
-
$main::lxdebug->leave_sub();
return ($max_qty_parts, $error);
=head1 DESCRIPTION
-Backend for lx-office warehousing functions.
+Backend for kivitendo warehousing functions.
=head1 FUNCTIONS
qty => 12.45,
transfer_type => 'transfer',
src_warehouse_id => 12,
- stc_bin_id => 23,
+ src_bin_id => 23,
dst_warehouse_id => 25,
dst_bin_id => 167,
});