Revision bdaa8c2f
Von Philip Reetz vor fast 18 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
490 | 490 |
$main::lxdebug->leave_sub(); |
491 | 491 |
} |
492 | 492 |
|
493 |
|
|
494 |
sub post_payment { |
|
495 |
$main::lxdebug->enter_sub(); |
|
496 |
|
|
497 |
my ($self, $myconfig, $form, $locale) = @_; |
|
498 |
|
|
499 |
# connect to database, turn off autocommit |
|
500 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
501 |
|
|
502 |
$form->{datepaid} = $form->{invdate}; |
|
503 |
|
|
504 |
# total payments, don't move we need it here |
|
505 |
for my $i (1 .. $form->{paidaccounts}) { |
|
506 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}); |
|
507 |
$form->{paid} += $form->{"paid_$i"}; |
|
508 |
$form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"}); |
|
509 |
} |
|
510 |
|
|
511 |
$form->{exchangerate} = |
|
512 |
$form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, |
|
513 |
"buy"); |
|
514 |
|
|
515 |
# record payments and offsetting AP |
|
516 |
for my $i (1 .. $form->{paidaccounts}) { |
|
517 |
|
|
518 |
if ($form->{"paid_$i"} != 0) { |
|
519 |
my ($accno) = split /--/, $form->{"AP_paid_$i"}; |
|
520 |
$form->{"datepaid_$i"} = $form->{invdate} |
|
521 |
unless ($form->{"datepaid_$i"}); |
|
522 |
$form->{datepaid} = $form->{"datepaid_$i"}; |
|
523 |
|
|
524 |
$exchangerate = 0; |
|
525 |
if (($form->{currency} eq $form->{defaultcurrency}) || ($form->{defaultcurrency} eq "")) { |
|
526 |
$form->{"exchangerate_$i"} = 1; |
|
527 |
} else { |
|
528 |
$exchangerate = |
|
529 |
$form->check_exchangerate($myconfig, $form->{currency}, |
|
530 |
$form->{"datepaid_$i"}, 'buy'); |
|
531 |
|
|
532 |
$form->{"exchangerate_$i"} = |
|
533 |
($exchangerate) |
|
534 |
? $exchangerate |
|
535 |
: $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); |
|
536 |
} |
|
537 |
|
|
538 |
# record AP |
|
539 |
$amount = |
|
540 |
$form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"}, |
|
541 |
2) * -1; |
|
542 |
|
|
543 |
|
|
544 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
545 |
WHERE c.accno = '$form->{AP}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; |
|
546 |
$dbh->do($query) || $form->dberror($query); |
|
547 |
|
|
548 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
549 |
transdate) |
|
550 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
551 |
WHERE c.accno = '$form->{AP}'), |
|
552 |
$amount, '$form->{"datepaid_$i"}')|; |
|
553 |
$dbh->do($query) || $form->dberror($query); |
|
554 |
|
|
555 |
|
|
556 |
|
|
557 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
558 |
WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|; |
|
559 |
$dbh->do($query) || $form->dberror($query); |
|
560 |
|
|
561 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
562 |
source, memo) |
|
563 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
564 |
WHERE c.accno = '$accno'), |
|
565 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
566 |
'$form->{"source_$i"}', '$form->{"memo_$i"}')|; |
|
567 |
$dbh->do($query) || $form->dberror($query); |
|
568 |
|
|
569 |
|
|
570 |
# gain/loss |
|
571 |
$amount = |
|
572 |
$form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * |
|
573 |
$form->{"exchangerate_$i"}; |
|
574 |
if ($amount > 0) { |
|
575 |
$form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += |
|
576 |
$amount; |
|
577 |
} else { |
|
578 |
$form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += |
|
579 |
$amount; |
|
580 |
} |
|
581 |
|
|
582 |
$diff = 0; |
|
583 |
|
|
584 |
# update exchange rate |
|
585 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
|
586 |
$form->update_exchangerate($dbh, $form->{currency}, |
|
587 |
$form->{"datepaid_$i"}, |
|
588 |
$form->{"exchangerate_$i"}, 0); |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
|
|
593 |
# record exchange rate differences and gains/losses |
|
594 |
foreach my $accno (keys %{ $form->{fx} }) { |
|
595 |
foreach my $transdate (keys %{ $form->{fx}{$accno} }) { |
|
596 |
if ( |
|
597 |
($form->{fx}{$accno}{$transdate} = |
|
598 |
$form->round_amount($form->{fx}{$accno}{$transdate}, 2) |
|
599 |
) != 0 |
|
600 |
) { |
|
601 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
602 |
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|; |
|
603 |
$dbh->do($query) || $form->dberror($query); |
|
604 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
605 |
transdate, cleared, fx_transaction) |
|
606 |
VALUES ($form->{id}, |
|
607 |
(SELECT c.id FROM chart c |
|
608 |
WHERE c.accno = '$accno'), |
|
609 |
$form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|; |
|
610 |
$dbh->do($query) || $form->dberror($query); |
|
611 |
} |
|
612 |
} |
|
613 |
} |
|
614 |
my $datepaid = ($form->{paid}) ? qq|'$form->{datepaid}'| : "NULL"; |
|
615 |
|
|
616 |
# save AP record |
|
617 |
my $query = qq|UPDATE ap set |
|
618 |
paid = $form->{paid}, |
|
619 |
datepaid = $datepaid |
|
620 |
WHERE id=$form->{id}|; |
|
621 |
|
|
622 |
$dbh->do($query) || $form->dberror($query); |
|
623 |
|
|
624 |
my $rc = $dbh->commit; |
|
625 |
$dbh->disconnect; |
|
626 |
|
|
627 |
$main::lxdebug->leave_sub(); |
|
628 |
|
|
629 |
return $rc; |
|
630 |
} |
|
631 |
|
|
493 | 632 |
1; |
494 | 633 |
|
Auch abrufbar als: Unified diff
Bei Kreditoren- und Debitorenbuchungen eine Funktion zum spaeteren Buchen eines Zahlungseingangs
hinzugefuegt