Revision bdaa8c2f
Von Philip Reetz vor fast 18 Jahren hinzugefügt
SL/AR.pm | ||
---|---|---|
377 | 377 |
return $rc; |
378 | 378 |
} |
379 | 379 |
|
380 |
sub post_payment { |
|
381 |
$main::lxdebug->enter_sub(); |
|
382 |
|
|
383 |
my ($self, $myconfig, $form, $locale) = @_; |
|
384 |
|
|
385 |
# connect to database, turn off autocommit |
|
386 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
387 |
|
|
388 |
$form->{datepaid} = $form->{invdate}; |
|
389 |
|
|
390 |
# total payments, don't move we need it here |
|
391 |
for my $i (1 .. $form->{paidaccounts}) { |
|
392 |
if ($form->{type} eq "credit_note") { |
|
393 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}) * -1; |
|
394 |
} else { |
|
395 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}); |
|
396 |
} |
|
397 |
$form->{paid} += $form->{"paid_$i"}; |
|
398 |
$form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"}); |
|
399 |
} |
|
400 |
|
|
401 |
$form->{exchangerate} = |
|
402 |
$form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, |
|
403 |
"buy"); |
|
404 |
|
|
405 |
# record payments and offsetting AR |
|
406 |
for my $i (1 .. $form->{paidaccounts}) { |
|
407 |
|
|
408 |
if ($form->{"paid_$i"} != 0) { |
|
409 |
my ($accno) = split /--/, $form->{"AR_paid_$i"}; |
|
410 |
$form->{"datepaid_$i"} = $form->{invdate} |
|
411 |
unless ($form->{"datepaid_$i"}); |
|
412 |
$form->{datepaid} = $form->{"datepaid_$i"}; |
|
413 |
|
|
414 |
$exchangerate = 0; |
|
415 |
if (($form->{currency} eq $form->{defaultcurrency}) || ($form->{defaultcurrency} eq "")) { |
|
416 |
$form->{"exchangerate_$i"} = 1; |
|
417 |
} else { |
|
418 |
$exchangerate = |
|
419 |
$form->check_exchangerate($myconfig, $form->{currency}, |
|
420 |
$form->{"datepaid_$i"}, 'buy'); |
|
421 |
|
|
422 |
$form->{"exchangerate_$i"} = |
|
423 |
($exchangerate) |
|
424 |
? $exchangerate |
|
425 |
: $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); |
|
426 |
} |
|
427 |
|
|
428 |
# record AR |
|
429 |
$amount = |
|
430 |
$form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"}, |
|
431 |
2); |
|
432 |
|
|
433 |
|
|
434 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
435 |
WHERE c.accno = '$form->{AR}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; |
|
436 |
$dbh->do($query) || $form->dberror($query); |
|
437 |
|
|
438 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
439 |
transdate) |
|
440 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
441 |
WHERE c.accno = '$form->{AR}'), |
|
442 |
$amount, '$form->{"datepaid_$i"}')|; |
|
443 |
$dbh->do($query) || $form->dberror($query); |
|
444 |
|
|
445 |
|
|
446 |
# record payment |
|
447 |
$form->{"paid_$i"} *= -1; |
|
448 |
|
|
449 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
450 |
WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|; |
|
451 |
$dbh->do($query) || $form->dberror($query); |
|
452 |
|
|
453 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
454 |
source, memo) |
|
455 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
456 |
WHERE c.accno = '$accno'), |
|
457 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
458 |
'$form->{"source_$i"}', '$form->{"memo_$i"}')|; |
|
459 |
$dbh->do($query) || $form->dberror($query); |
|
460 |
|
|
461 |
|
|
462 |
# gain/loss |
|
463 |
$amount = |
|
464 |
$form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * |
|
465 |
$form->{"exchangerate_$i"}; |
|
466 |
if ($amount > 0) { |
|
467 |
$form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += |
|
468 |
$amount; |
|
469 |
} else { |
|
470 |
$form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += |
|
471 |
$amount; |
|
472 |
} |
|
473 |
|
|
474 |
$diff = 0; |
|
475 |
|
|
476 |
# update exchange rate |
|
477 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
|
478 |
$form->update_exchangerate($dbh, $form->{currency}, |
|
479 |
$form->{"datepaid_$i"}, |
|
480 |
$form->{"exchangerate_$i"}, 0); |
|
481 |
} |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
# record exchange rate differences and gains/losses |
|
486 |
foreach my $accno (keys %{ $form->{fx} }) { |
|
487 |
foreach my $transdate (keys %{ $form->{fx}{$accno} }) { |
|
488 |
if ( |
|
489 |
($form->{fx}{$accno}{$transdate} = |
|
490 |
$form->round_amount($form->{fx}{$accno}{$transdate}, 2) |
|
491 |
) != 0 |
|
492 |
) { |
|
493 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
494 |
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|; |
|
495 |
$dbh->do($query) || $form->dberror($query); |
|
496 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
497 |
transdate, cleared, fx_transaction) |
|
498 |
VALUES ($form->{id}, |
|
499 |
(SELECT c.id FROM chart c |
|
500 |
WHERE c.accno = '$accno'), |
|
501 |
$form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|; |
|
502 |
$dbh->do($query) || $form->dberror($query); |
|
503 |
} |
|
504 |
} |
|
505 |
} |
|
506 |
my $datepaid = ($form->{paid}) ? qq|'$form->{datepaid}'| : "NULL"; |
|
507 |
|
|
508 |
# save AR record |
|
509 |
my $query = qq|UPDATE ar set |
|
510 |
paid = $form->{paid}, |
|
511 |
datepaid = $datepaid |
|
512 |
WHERE id=$form->{id}|; |
|
513 |
|
|
514 |
$dbh->do($query) || $form->dberror($query); |
|
515 |
|
|
516 |
my $rc = $dbh->commit; |
|
517 |
$dbh->disconnect; |
|
518 |
|
|
519 |
$main::lxdebug->leave_sub(); |
|
520 |
|
|
521 |
return $rc; |
|
522 |
} |
|
523 |
|
|
380 | 524 |
sub delete_transaction { |
381 | 525 |
$main::lxdebug->enter_sub(); |
382 | 526 |
|
Auch abrufbar als: Unified diff
Bei Kreditoren- und Debitorenbuchungen eine Funktion zum spaeteren Buchen eines Zahlungseingangs
hinzugefuegt