Revision a8ab0931
Von Martin Helmling mh@waldpark.octosoft.eu vor mehr als 8 Jahren hinzugefügt
SL/DO.pm | ||
---|---|---|
536 | 536 |
|
537 | 537 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
538 | 538 |
|
539 |
my %ship = $self->get_shipped_qty('do_id' => $form->{id}, 'delivered' => 1); |
|
539 |
my %ship = $self->get_shipped_qty('dbh' => $dbh, 'do_id' => $form->{id}, 'delivered' => 1);
|
|
540 | 540 |
|
541 | 541 |
foreach my $oe_id (keys %ship) { |
542 | 542 |
do_query($form, $dbh,"UPDATE oe SET delivered = ".($ship{$oe_id}->{delivered}?"TRUE":"FALSE")." WHERE id = ?", $oe_id); |
... | ... | |
1215 | 1215 |
my $self = shift; |
1216 | 1216 |
my %params = @_; |
1217 | 1217 |
|
1218 |
# Eigentlich unkritisch: wenn keine der Parameter gesetzt ist kommt ein leerer Hash zurück |
|
1219 |
croak ("Need at least one parameter oe_id or do_id") unless $params{oe_id} || $params{do_id}; |
|
1220 |
|
|
1218 | 1221 |
my $myconfig = \%main::myconfig; |
1219 | 1222 |
my $form = $main::form; |
1220 |
my $dbh = $form->get_standard_dbh($myconfig);
|
|
1223 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
|
|
1221 | 1224 |
my %ship = (); |
1222 | 1225 |
|
1223 | 1226 |
my @oe_ids; |
1224 | 1227 |
|
1225 |
if ( $params{oe_id} ) {
|
|
1228 |
if ($params{oe_id} ) { |
|
1226 | 1229 |
push @oe_ids, $params{oe_id}; |
1227 |
} |
|
1228 |
elsif ($params{do_id}) { |
|
1230 |
} elsif ($params{do_id}) { |
|
1229 | 1231 |
my @links = RecordLinks->get_links( 'dbh' => $dbh, |
1230 | 1232 |
'from_table' => 'oe', |
1231 | 1233 |
'to_table' => 'delivery_orders', |
... | ... | |
1235 | 1237 |
} |
1236 | 1238 |
|
1237 | 1239 |
if (scalar (@oe_ids) > 0 ) { |
1238 |
|
|
1239 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"oeid=".$params{oe_id}." doid=".$params{do_id}); |
|
1240 |
my $all_units = AM->retrieve_all_units(); |
|
1241 |
my $query = qq|SELECT oi.id, oi.position, oi.parts_id, oi.qty, oi.unit, oi.trans_id, |
|
1242 |
p.unit AS partunit FROM orderitems oi |
|
1243 |
LEFT JOIN parts p ON (oi.parts_id = p.id) |
|
1244 |
WHERE trans_id IN (| . |
|
1245 |
join(', ', ('?') x scalar @oe_ids) . qq|) ORDER BY position ASC|; |
|
1246 |
|
|
1247 |
my $orderitems = selectall_hashref_query($form, $dbh, $query, @oe_ids); |
|
1248 |
foreach my $oe_entry (@{ $orderitems }) { |
|
1249 |
$oe_entry->{qty} *= AM->convert_unit($oe_entry->{unit}, $oe_entry->{partunit}, $all_units); |
|
1250 |
$oe_entry->{qty_notdelivered} = $oe_entry->{qty}; |
|
1251 |
|
|
1252 |
# Bei oe Modus auf jeden Fall einen Record anlegen |
|
1253 |
if ( $params{oe_id} ) { |
|
1254 |
$ship{$oe_entry->{position}} = { |
|
1255 |
'qty_ordered' => $oe_entry->{qty} , |
|
1256 |
'qty_notdelivered' => $oe_entry->{qty} |
|
1257 |
}; |
|
1258 |
} |
|
1259 |
} |
|
1260 |
|
|
1261 |
my @dolinks = RecordLinks->get_links('dbh' => $dbh, |
|
1262 |
'from_table' => 'oe', |
|
1263 |
'to_table' => 'delivery_orders', |
|
1264 |
'from_id' => @oe_ids); |
|
1265 |
|
|
1266 |
my @do_ids = map { $_->{to_id} } @dolinks ; |
|
1267 |
if (scalar (@do_ids) == 0) { |
|
1268 |
$main::lxdebug->leave_sub(); |
|
1269 |
return %ship; |
|
1240 |
my $all_units = AM->retrieve_all_units(); |
|
1241 |
my $placeholders = join(', ', ('?') x scalar @oe_ids); |
|
1242 |
my $query = qq|SELECT oi.id, oi.position, oi.parts_id, oi.qty, oi.unit, oi.trans_id, |
|
1243 |
p.unit AS partunit FROM orderitems oi |
|
1244 |
LEFT JOIN parts p ON (oi.parts_id = p.id) |
|
1245 |
WHERE trans_id IN (${placeholders}) |
|
1246 |
ORDER BY position ASC|; |
|
1247 |
|
|
1248 |
my $orderitems = selectall_hashref_query($form, $dbh, $query, @oe_ids); |
|
1249 |
foreach my $oe_entry (@{ $orderitems }) { |
|
1250 |
$oe_entry->{qty} *= AM->convert_unit($oe_entry->{unit}, $oe_entry->{partunit}, $all_units); |
|
1251 |
$oe_entry->{qty_notdelivered} = $oe_entry->{qty}; |
|
1252 |
|
|
1253 |
# Bei oe Modus auf jeden Fall einen Record anlegen |
|
1254 |
if ( $params{oe_id} ) { |
|
1255 |
$ship{$oe_entry->{position}} = { |
|
1256 |
'qty_ordered' => $oe_entry->{qty} , |
|
1257 |
'qty_notdelivered' => $oe_entry->{qty} |
|
1258 |
}; |
|
1270 | 1259 |
} |
1260 |
} |
|
1271 | 1261 |
|
1272 |
my %oeitems_by_id = map { $_->{id} => $_ } @{ $orderitems }; |
|
1273 |
|
|
1262 |
my @dolinks = RecordLinks->get_links('dbh' => $dbh, |
|
1263 |
'from_table' => 'oe', |
|
1264 |
'to_table' => 'delivery_orders', |
|
1265 |
'from_id' => @oe_ids); |
|
1274 | 1266 |
|
1275 |
$query = qq|SELECT doi.parts_id, doi.id, doi.qty, doi.unit, doi.position, |
|
1276 |
doi.delivery_order_id, COALESCE(rlitem.from_id,0) as from_id, |
|
1277 |
p.unit AS partunit |
|
1278 |
FROM delivery_order_items doi |
|
1279 |
LEFT JOIN parts p ON (doi.parts_id = p.id) |
|
1280 |
LEFT JOIN record_links rlitem |
|
1281 |
ON (rlitem.to_id = doi.id AND rlitem.to_table='delivery_order_items') |
|
1282 |
WHERE doi.delivery_order_id IN (| . join(', ', ('?') x scalar @do_ids) . qq|)|; |
|
1267 |
my @do_ids = map { $_->{to_id} } @dolinks ; |
|
1268 |
if (scalar (@do_ids) == 0) { |
|
1269 |
$main::lxdebug->leave_sub(); |
|
1270 |
return %ship; |
|
1271 |
} |
|
1283 | 1272 |
|
1284 |
my $deliveryorderitems = selectall_hashref_query($form, $dbh, $query, @do_ids); |
|
1273 |
my %oeitems_by_id = map { $_->{id} => $_ } @{ $orderitems }; |
|
1274 |
|
|
1275 |
|
|
1276 |
$placeholders = join(', ', ('?') x scalar @do_ids); |
|
1277 |
$query = qq|SELECT doi.parts_id, doi.id, doi.qty, doi.unit, doi.position, |
|
1278 |
doi.delivery_order_id, COALESCE(rlitem.from_id,0) as from_id, |
|
1279 |
p.unit AS partunit |
|
1280 |
FROM delivery_order_items doi |
|
1281 |
LEFT JOIN parts p ON (doi.parts_id = p.id) |
|
1282 |
LEFT JOIN record_links rlitem |
|
1283 |
ON (rlitem.to_id = doi.id AND rlitem.to_table='delivery_order_items') |
|
1284 |
WHERE doi.delivery_order_id IN (${placeholders})|; |
|
1285 |
|
|
1286 |
my $deliveryorderitems = selectall_hashref_query($form, $dbh, $query, @do_ids); |
|
1287 |
|
|
1288 |
# erst mal qty der links bearbeiten |
|
1289 |
foreach my $do_entry (@{ $deliveryorderitems }) { |
|
1290 |
$do_entry->{qty} *= AM->convert_unit($do_entry->{unit}, $do_entry->{partunit}, $all_units); |
|
1291 |
if ($do_entry->{from_id} > 0 ) { |
|
1292 |
# record link zwischen items vorhanden, kann auch von anderem Auftrag sein |
|
1293 |
my $oe_entry = $oeitems_by_id{$do_entry->{from_id}}; |
|
1294 |
if ( $oe_entry ) { |
|
1295 |
$oe_entry->{qty_notdelivered} -= $do_entry->{qty}; |
|
1296 |
# derzeit nur ein link pro do_item |
|
1297 |
$do_entry->{oe_entry} = $oe_entry; |
|
1298 |
} |
|
1299 |
} else { |
|
1300 |
$main::lxdebug->message(LXDebug->DEBUG2(),"no entry for=".$do_entry->{id}." part=".$do_entry->{parts_id}); |
|
1301 |
} |
|
1302 |
} |
|
1303 |
# nun den rest ohne links bearbeiten |
|
1304 |
foreach my $do_entry (@{ $deliveryorderitems }) { |
|
1305 |
next if $do_entry->{from_id} > 0; |
|
1306 |
next if $do_entry->{qty} == 0; |
|
1285 | 1307 |
|
1286 |
# erst mal qty der links bearbeiten |
|
1287 |
foreach my $do_entry (@{ $deliveryorderitems }) { |
|
1288 |
$do_entry->{qty} *= AM->convert_unit($do_entry->{unit}, $do_entry->{partunit}, $all_units); |
|
1289 |
if ($do_entry->{from_id} > 0 ) { |
|
1290 |
# record link zwischen items vorhanden, kann auch von anderem Auftrag sein |
|
1291 |
my $oe_entry = $oeitems_by_id{$do_entry->{from_id}}; |
|
1292 |
if ( $oe_entry ) { |
|
1293 |
$oe_entry->{qty_notdelivered} -= $do_entry->{qty}; |
|
1294 |
# derzeit nur ein link pro do_item |
|
1295 |
$do_entry->{oe_entry} = $oe_entry; |
|
1296 |
} |
|
1308 |
foreach my $oe_entry (@{ $orderitems }) { |
|
1309 |
next if $oe_entry->{qty_notdelivered} == 0; |
|
1310 |
if ( $do_entry->{parts_id} == $oe_entry->{parts_id} ) { |
|
1311 |
# zu viele geliefert auf andere position ? |
|
1312 |
if ( $oe_entry->{qty_notdelivered} < 0 ) { |
|
1313 |
$do_entry->{qty} += - $oe_entry->{qty_notdelivered}; |
|
1314 |
$oe_entry->{qty_notdelivered} = 0; |
|
1297 | 1315 |
} else { |
1298 |
$main::lxdebug->message(LXDebug->DEBUG2(),"no entry for=".$do_entry->{id}." part=".$do_entry->{parts_id}); |
|
1316 |
if ( $do_entry->{qty} < $oe_entry->{qty_notdelivered} ) { |
|
1317 |
$oe_entry->{qty_notdelivered} -= $do_entry->{qty}; |
|
1318 |
$do_entry->{qty} = 0; |
|
1319 |
} else { |
|
1320 |
$do_entry->{qty} -= $oe_entry->{qty_notdelivered}; |
|
1321 |
$oe_entry->{qty_notdelivered} = 0; |
|
1322 |
} |
|
1323 |
# derzeit nur ein link pro do_item |
|
1324 |
$do_entry->{oe_entry} = $oe_entry if !$do_entry->{oe_entry}; |
|
1299 | 1325 |
} |
1326 |
} |
|
1327 |
last if $do_entry->{qty} <= 0; |
|
1328 |
} |
|
1329 |
} |
|
1330 |
if ( $params{oe_id} ) { |
|
1331 |
$ship{$_->{position}}->{qty_notdelivered} = $_->{qty_notdelivered} for @{ $orderitems }; |
|
1332 |
} |
|
1333 |
elsif ($params{do_id} && $params{delivered}) { |
|
1334 |
foreach my $oe_entry (@{ $orderitems }) { |
|
1335 |
if ( !$ship{$oe_entry->{trans_id}} ) { |
|
1336 |
$ship{$oe_entry->{trans_id}} = { 'delivered' => 1 }; |
|
1337 |
} |
|
1338 |
$ship{$oe_entry->{trans_id}}->{delivered} = 0 if $oe_entry->{qty_notdelivered} > 0; |
|
1300 | 1339 |
} |
1301 |
# nun den rest ohne links bearbeiten |
|
1340 |
} |
|
1341 |
elsif ($params{do_id}) { |
|
1302 | 1342 |
foreach my $do_entry (@{ $deliveryorderitems }) { |
1303 |
next if $do_entry->{from_id} > 0; |
|
1304 |
next if $do_entry->{qty} == 0; |
|
1305 |
|
|
1306 |
foreach my $oe_entry (@{ $orderitems }) { |
|
1307 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"do oe_entry ".$oe_entry." id=".$oe_entry->{id}." not del=".$oe_entry->{qty_notdelivered}); |
|
1308 |
next if $oe_entry->{qty_notdelivered} == 0; |
|
1309 |
if ( $do_entry->{parts_id} == $oe_entry->{parts_id} ) { |
|
1310 |
# zu viele geliefert auf andere position ? |
|
1311 |
if ( $oe_entry->{qty_notdelivered} < 0 ) { |
|
1312 |
$do_entry->{qty} += - $oe_entry->{qty_notdelivered}; |
|
1313 |
$oe_entry->{qty_notdelivered} = 0; |
|
1314 |
} else { |
|
1315 |
if ( $do_entry->{qty} < $oe_entry->{qty_notdelivered} ) { |
|
1316 |
$oe_entry->{qty_notdelivered} -= $do_entry->{qty}; |
|
1317 |
$do_entry->{qty} = 0; |
|
1318 |
} else { |
|
1319 |
$do_entry->{qty} -= $oe_entry->{qty_notdelivered}; |
|
1320 |
$oe_entry->{qty_notdelivered} = 0; |
|
1321 |
} |
|
1322 |
# derzeit nur ein link pro do_item |
|
1323 |
$do_entry->{oe_entry} = $oe_entry if !$do_entry->{oe_entry}; |
|
1324 |
} |
|
1325 |
} |
|
1326 |
last if $do_entry->{qty} <= 0; |
|
1343 |
next if $params{do_id} != $do_entry->{delivery_order_id}; |
|
1344 |
my $position = $do_entry->{position}; |
|
1345 |
if ( $position > 0 && $do_entry->{oe_entry}) { |
|
1346 |
if ( !$ship{$position} ) { |
|
1347 |
$ship{$position} = { |
|
1348 |
'qty_ordered' => $do_entry->{oe_entry}->{qty} , |
|
1349 |
'qty_notdelivered' => $do_entry->{oe_entry}->{qty_notdelivered} |
|
1350 |
}; |
|
1351 |
} else { |
|
1352 |
$ship{$position}->{qty_ordered} += $do_entry->{oe_entry}->{qty}; |
|
1353 |
$ship{$position}->{qty_notdelivered} += $do_entry->{oe_entry}->{qty_notdelivered}; |
|
1327 | 1354 |
} |
1328 |
|
|
1329 |
} |
|
1330 |
if ( $params{oe_id} ) { |
|
1331 |
map { $ship{$_->{position}}->{qty_notdelivered} = $_->{qty_notdelivered}; } @{ $orderitems }; |
|
1332 |
} |
|
1333 |
elsif ($params{do_id} && $params{delivered}) { |
|
1334 |
map { |
|
1335 |
if ( !$ship{$_->{trans_id}} ) { |
|
1336 |
$ship{$_->{trans_id}} = { 'delivered' => 1 }; |
|
1337 |
} |
|
1338 |
$ship{$_->{trans_id}}->{delivered} = 0 if $_->{qty_notdelivered} > 0; |
|
1339 |
} @{ $orderitems }; |
|
1340 |
} |
|
1341 |
elsif ($params{do_id}) { |
|
1342 |
foreach my $do_entry (@{ $deliveryorderitems }) { |
|
1343 |
next if $params{do_id} != $do_entry->{delivery_order_id}; |
|
1344 |
my $position = $do_entry->{position}; |
|
1345 |
if ( $position > 0 && $do_entry->{oe_entry}) { |
|
1346 |
if ( !$ship{$position} ) { |
|
1347 |
$ship{$position} = { |
|
1348 |
'qty_ordered' => $do_entry->{oe_entry}->{qty} , |
|
1349 |
'qty_notdelivered' => $do_entry->{oe_entry}->{qty_notdelivered} |
|
1350 |
}; |
|
1351 |
} |
|
1352 |
else { |
|
1353 |
$ship{$position}->{qty_ordered} += $do_entry->{oe_entry}->{qty}; |
|
1354 |
$ship{$position}->{qty_notdelivered} += $do_entry->{oe_entry}->{qty_notdelivered}; |
|
1355 |
} |
|
1356 |
} |
|
1357 | 1355 |
} |
1358 | 1356 |
} |
1357 |
} |
|
1359 | 1358 |
} |
1360 | 1359 |
$main::lxdebug->leave_sub(); |
1361 | 1360 |
return %ship; |
Auch abrufbar als: Unified diff
Gelieferte Mengen über Recordlinks ermitteln(2)
Für den Verschönerungsverein einige Stilanpassungen