Revision 454df69e
Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt
SL/DO.pm | ||
---|---|---|
425 | 425 |
sub retrieve { |
426 | 426 |
$main::lxdebug->enter_sub(); |
427 | 427 |
|
428 |
my ($self) = @_; |
|
428 |
my $self = shift; |
|
429 |
my %params = @_; |
|
429 | 430 |
|
430 | 431 |
my $myconfig = \%main::myconfig; |
431 | 432 |
my $form = $main::form; |
... | ... | |
435 | 436 |
|
436 | 437 |
my ($query, $query_add, @values, $sth, $ref); |
437 | 438 |
|
438 |
if (!$form->{id}) { |
|
439 |
my $vc = $params{vc} eq 'customer' ? 'customer' : 'vendor'; |
|
440 |
|
|
441 |
my $mode = !$params{ids} ? 'default' : ref $params{ids} eq 'ARRAY' ? 'multi' : 'single'; |
|
442 |
|
|
443 |
if ($mode eq 'default') { |
|
439 | 444 |
$ref = selectfirst_hashref_query($form, $dbh, qq|SELECT current_date AS transdate, current_date AS reqdate|); |
440 | 445 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
446 |
|
|
447 |
# get last name used |
|
448 |
$form->lastname_used($dbh, $myconfig, $vc) unless $form->{"${vc}_id"}; |
|
449 |
|
|
450 |
$main::lxdebug->leave_sub(); |
|
451 |
|
|
452 |
return 1; |
|
441 | 453 |
} |
442 | 454 |
|
443 |
my $vc = $form->{vc} eq "customer" ? "customer" : "vendor"; |
|
455 |
my @do_ids = map { conv_i($_) } ($mode eq 'multi' ? @{ $params{ids} } : ($params{ids})); |
|
456 |
my $do_ids_placeholders = join(', ', ('?') x scalar(@do_ids)); |
|
444 | 457 |
|
445 |
if ($form->{id}) { |
|
458 |
# retrieve order for single id |
|
459 |
# NOTE: this query is intended to fetch all information only ONCE. |
|
460 |
# so if any of these infos is important (or even different) for any item, |
|
461 |
# it will be killed out and then has to be fetched from the item scope query further down |
|
462 |
$query = |
|
463 |
qq|SELECT dord.cp_id, dord.donumber, dord.ordnumber, dord.transdate, dord.reqdate, |
|
464 |
dord.shippingpoint, dord.shipvia, dord.notes, dord.intnotes, |
|
465 |
e.name AS employee, dord.employee_id, dord.salesman_id, |
|
466 |
dord.${vc}_id, cv.name AS ${vc}, |
|
467 |
dord.closed, dord.reqdate, dord.department_id, dord.cusordnumber, |
|
468 |
d.description AS department, dord.language_id, |
|
469 |
dord.shipto_id, |
|
470 |
dord.globalproject_id, dord.delivered, dord.transaction_description |
|
471 |
FROM delivery_orders dord |
|
472 |
JOIN ${vc} cv ON (dord.${vc}_id = cv.id) |
|
473 |
LEFT JOIN employee e ON (dord.employee_id = e.id) |
|
474 |
LEFT JOIN department d ON (dord.department_id = d.id) |
|
475 |
WHERE dord.id IN ($do_ids_placeholders)|; |
|
476 |
$sth = prepare_execute_query($form, $dbh, $query, @do_ids); |
|
446 | 477 |
|
447 |
# retrieve order for single id |
|
448 |
# NOTE: this query is intended to fetch all information only ONCE. |
|
449 |
# so if any of these infos is important (or even different) for any item, |
|
450 |
# it will be killed out and then has to be fetched from the item scope query further down |
|
451 |
$query = |
|
452 |
qq|SELECT dord.cp_id, dord.donumber, dord.ordnumber, dord.transdate, dord.reqdate, |
|
453 |
dord.shippingpoint, dord.shipvia, dord.notes, dord.intnotes, |
|
454 |
e.name AS employee, dord.employee_id, dord.salesman_id, |
|
455 |
dord.${vc}_id, cv.name AS ${vc}, |
|
456 |
dord.closed, dord.reqdate, dord.department_id, dord.cusordnumber, |
|
457 |
d.description AS department, dord.language_id, |
|
458 |
dord.shipto_id, |
|
459 |
dord.globalproject_id, dord.delivered, dord.transaction_description |
|
460 |
FROM delivery_orders dord |
|
461 |
JOIN ${vc} cv ON (dord.${vc}_id = cv.id) |
|
462 |
LEFT JOIN employee e ON (dord.employee_id = e.id) |
|
463 |
LEFT JOIN department d ON (dord.department_id = d.id) |
|
464 |
WHERE dord.id = ?|; |
|
465 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
466 |
|
|
467 |
$ref = $sth->fetchrow_hashref(NAME_lc); |
|
468 |
$sth->finish(); |
|
478 |
delete $form->{"${vc}_id"}; |
|
479 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
480 |
if ($form->{"${vc}_id"} && ($ref->{"${vc}_id"} != $form->{"${vc}_id"})) { |
|
481 |
$sth->finish(); |
|
482 |
$main::lxdebug->leave_sub(); |
|
483 |
|
|
484 |
return 0; |
|
485 |
} |
|
469 | 486 |
|
470 | 487 |
map { $form->{$_} = $ref->{$_} } keys %$ref if ($ref); |
488 |
} |
|
489 |
$sth->finish(); |
|
471 | 490 |
|
472 |
$form->{saved_donumber} = $form->{donumber};
|
|
491 |
$form->{saved_donumber} = $form->{donumber}; |
|
473 | 492 |
|
474 |
# if not given, fill transdate with current_date
|
|
475 |
$form->{transdate} = $form->current_date($myconfig) unless $form->{transdate};
|
|
493 |
# if not given, fill transdate with current_date |
|
494 |
$form->{transdate} = $form->current_date($myconfig) unless $form->{transdate}; |
|
476 | 495 |
|
496 |
if ($mode eq 'single') { |
|
477 | 497 |
$query = qq|SELECT s.* FROM shipto s WHERE s.trans_id = ? AND s.module = 'DO'|; |
478 |
$sth = prepare_execute_query($form, $dbh, $query, $form->{id}); |
|
498 |
$sth = prepare_execute_query($form, $dbh, $query, $form->{id});
|
|
479 | 499 |
|
480 |
$ref = $sth->fetchrow_hashref(NAME_lc); |
|
481 |
delete($ref->{id});
|
|
500 |
$ref = $sth->fetchrow_hashref(NAME_lc);
|
|
501 |
delete $ref->{id};
|
|
482 | 502 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
483 |
$sth->finish; |
|
503 |
$sth->finish();
|
|
484 | 504 |
|
485 | 505 |
# get printed, emailed and queued |
486 | 506 |
$query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname FROM status s WHERE s.trans_id = ?|; |
487 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
507 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id}));
|
|
488 | 508 |
|
489 | 509 |
while ($ref = $sth->fetchrow_hashref(NAME_lc)) { |
490 | 510 |
$form->{printed} .= "$ref->{formname} " if $ref->{printed}; |
491 | 511 |
$form->{emailed} .= "$ref->{formname} " if $ref->{emailed}; |
492 | 512 |
$form->{queued} .= "$ref->{formname} $ref->{spoolfile} " if $ref->{spoolfile}; |
493 | 513 |
} |
494 |
$sth->finish; |
|
514 |
$sth->finish();
|
|
495 | 515 |
map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued); |
496 | 516 |
|
497 |
my %oid = ('Pg' => 'oid', |
|
498 |
'Oracle' => 'rowid'); |
|
499 |
|
|
500 |
my $transdate = $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date"; |
|
517 |
} else { |
|
518 |
delete $form->{id}; |
|
519 |
} |
|
501 | 520 |
|
502 |
# retrieve individual items |
|
503 |
# this query looks up all information about the items |
|
504 |
# stuff different from the whole will not be overwritten, but saved with a suffix. |
|
505 |
$query = |
|
506 |
qq|SELECT doi.id AS delivery_order_items_id, |
|
507 |
p.partnumber, p.assembly, doi.description, doi.qty, |
|
508 |
doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.bin, p.notes AS partnotes, |
|
509 |
doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost, |
|
510 |
doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription, |
|
511 |
doi.price_factor_id, doi.price_factor, doi.marge_price_factor, |
|
512 |
pr.projectnumber, |
|
513 |
pg.partsgroup |
|
514 |
FROM delivery_order_items doi |
|
515 |
JOIN parts p ON (doi.parts_id = p.id) |
|
516 |
JOIN delivery_orders dord ON (doi.delivery_order_id = dord.id) |
|
517 |
LEFT JOIN project pr ON (doi.project_id = pr.id) |
|
518 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
519 |
WHERE doi.delivery_order_id = ? |
|
520 |
ORDER BY doi.$oid{$myconfig->{dbdriver}}|; |
|
521 |
|
|
522 |
$form->{form_details} = selectall_hashref_query($form, $dbh, $query, conv_i($form->{id})); |
|
521 |
my %oid = ('Pg' => 'oid', |
|
522 |
'Oracle' => 'rowid'); |
|
523 | 523 |
|
524 |
# retrieve individual items |
|
525 |
# this query looks up all information about the items |
|
526 |
# stuff different from the whole will not be overwritten, but saved with a suffix. |
|
527 |
$query = |
|
528 |
qq|SELECT doi.id AS delivery_order_items_id, |
|
529 |
p.partnumber, p.assembly, doi.description, doi.qty, |
|
530 |
doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.bin, p.notes AS partnotes, |
|
531 |
doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost, |
|
532 |
doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription, |
|
533 |
doi.price_factor_id, doi.price_factor, doi.marge_price_factor, |
|
534 |
pr.projectnumber, |
|
535 |
pg.partsgroup |
|
536 |
FROM delivery_order_items doi |
|
537 |
JOIN parts p ON (doi.parts_id = p.id) |
|
538 |
JOIN delivery_orders dord ON (doi.delivery_order_id = dord.id) |
|
539 |
LEFT JOIN project pr ON (doi.project_id = pr.id) |
|
540 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
541 |
WHERE doi.delivery_order_id IN ($do_ids_placeholders) |
|
542 |
ORDER BY doi.$oid{$myconfig->{dbdriver}}|; |
|
543 |
|
|
544 |
$form->{form_details} = selectall_hashref_query($form, $dbh, $query, @do_ids); |
|
545 |
|
|
546 |
if ($mode eq 'single') { |
|
524 | 547 |
my $in_out = $form->{type} =~ /^sales/ ? 'out' : 'in'; |
525 | 548 |
|
526 | 549 |
$query = |
527 | 550 |
qq|SELECT qty, unit, bin_id, warehouse_id, chargenumber |
528 |
FROM delivery_order_items_stock
|
|
529 |
WHERE delivery_order_item_id = ?|;
|
|
551 |
FROM delivery_order_items_stock |
|
552 |
WHERE delivery_order_item_id = ?|; |
|
530 | 553 |
my $sth = prepare_query($form, $dbh, $query); |
531 | 554 |
|
532 | 555 |
foreach my $doi (@{ $form->{form_details} }) { |
... | ... | |
540 | 563 |
} |
541 | 564 |
|
542 | 565 |
$sth->finish(); |
543 |
|
|
544 |
} else { |
|
545 |
# get last name used |
|
546 |
$form->lastname_used($dbh, $myconfig, $form->{vc}) unless $form->{"$form->{vc}_id"}; |
|
547 |
|
|
548 | 566 |
} |
549 | 567 |
|
550 | 568 |
Common::webdav_folder($form) if ($main::webdav); |
551 | 569 |
|
552 | 570 |
$main::lxdebug->leave_sub(); |
571 |
|
|
572 |
return 1; |
|
553 | 573 |
} |
554 | 574 |
|
555 | 575 |
sub order_details { |
Auch abrufbar als: Unified diff
Erstellen von Rechnungen aus mehreren Lieferscheinen heraus.