Revision 57342517
Von Jan Büren vor mehr als 2 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
39 | 39 |
use SL::DBUtils; |
40 | 40 |
use SL::IO; |
41 | 41 |
use SL::MoreCommon; |
42 |
use SL::DB::ApGl; |
|
42 | 43 |
use SL::DB::Default; |
43 | 44 |
use SL::DB::Draft; |
44 | 45 |
use SL::DB::Order; |
... | ... | |
406 | 407 |
SL::DB::Manager::Draft->delete_all(where => [ id => delete($form->{draft_id}) ]); |
407 | 408 |
} |
408 | 409 |
|
410 |
# hook for taxkey 94 |
|
411 |
$self->_reverse_charge($myconfig, $form); |
|
409 | 412 |
# safety check datev export |
410 | 413 |
if ($::instance_conf->get_datev_check_on_ap_transaction) { |
411 | 414 |
my $datev = SL::DATEV->new( |
... | ... | |
422 | 425 |
return 1; |
423 | 426 |
} |
424 | 427 |
|
428 |
sub _reverse_charge { |
|
429 |
my ($self, $myconfig, $form) = @_; |
|
430 |
|
|
431 |
# check taxkey settings or return |
|
432 |
my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => 94 ]); |
|
433 |
return unless ref $tax eq 'SL::DB::Tax'; |
|
434 |
|
|
435 |
# delete previous bookings, if they exists (repost) |
|
436 |
my $ap_gl = SL::DB::Manager::ApGl->get_first(where => [ ap_id => $form->{id} ]); |
|
437 |
my $gl_id = ref $ap_gl eq 'SL::DB::ApGl' ? $ap_gl->gl_id : undef; |
|
438 |
|
|
439 |
SL::DB::Manager::GLTransaction->delete_all(where => [ id => $gl_id ]) if $gl_id; |
|
440 |
SL::DB::Manager::ApGl-> delete_all(where => [ ap_id => $form->{id} ]) if $gl_id; |
|
441 |
SL::DB::Manager::RecordLink-> delete_all(where => [ from_table => 'ap', to_table => 'gl', from_id => $form->{id} ]); |
|
442 |
|
|
443 |
# gl booking |
|
444 |
my ($credit, $debit); |
|
445 |
$credit = SL::DB::Manager::Chart->find_by(id => $tax->chart_id); |
|
446 |
$debit = SL::DB::Manager::Chart->find_by(id => $tax->reverse_charge_chart_id); |
|
447 |
|
|
448 |
croak("No such Chart ID" . $tax->chart_id) unless ref $credit eq 'SL::DB::Chart'; |
|
449 |
croak("No such Chart ID" . $tax->reverse_chart_id) unless ref $debit eq 'SL::DB::Chart'; |
|
450 |
|
|
451 |
my ($i, $current_transaction); |
|
452 |
|
|
453 |
for $i (1 .. $form->{rowcount}) { |
|
454 |
next unless $form->{"taxkey_$i"} == 94; |
|
455 |
|
|
456 |
my ($tmpnetamount, $tmptaxamount) = $form->calculate_tax($form->{"amount_$i"}, 0.19, $form->{taxincluded}, 2); |
|
457 |
$current_transaction = SL::DB::GLTransaction->new( |
|
458 |
employee_id => $form->{employee_id}, |
|
459 |
transdate => $form->{transdate}, |
|
460 |
description => $form->{notes} || $form->{invnumber}, |
|
461 |
reference => $form->{invnumber}, |
|
462 |
department_id => $form->{department_id} ? $form->{department_id} : undef, |
|
463 |
imported => 0, # not imported |
|
464 |
taxincluded => 0, |
|
465 |
)->add_chart_booking( |
|
466 |
chart => $tmptaxamount < 0 ? $credit : $debit, |
|
467 |
credit => abs($tmptaxamount), |
|
468 |
source => "Reverse Charge for " . $form->{invnumber}, |
|
469 |
)->add_chart_booking( |
|
470 |
chart => $tmptaxamount < 0 ? $debit : $credit, |
|
471 |
debit => abs($tmptaxamount), |
|
472 |
source => "Reverse Charge for " . $form->{invnumber}, |
|
473 |
)->post; |
|
474 |
# add a stable link from ap to gl |
|
475 |
my %props_gl = ( |
|
476 |
ap_id => $form->{id}, |
|
477 |
gl_id => $current_transaction->id, |
|
478 |
); |
|
479 |
SL::DB::ApGl->new(%props_gl)->save; |
|
480 |
# Record a record link from ap to gl |
|
481 |
my %props_rl = ( |
|
482 |
from_table => 'ap', |
|
483 |
from_id => $form->{id}, |
|
484 |
to_table => 'gl', |
|
485 |
to_id => $current_transaction->id, |
|
486 |
); |
|
487 |
SL::DB::RecordLink->new(%props_rl)->save; |
|
488 |
} |
|
489 |
} |
|
490 |
|
|
425 | 491 |
sub delete_transaction { |
426 | 492 |
$main::lxdebug->enter_sub(); |
427 | 493 |
|
428 | 494 |
my ($self, $myconfig, $form) = @_; |
429 | 495 |
|
430 | 496 |
SL::DB->client->with_transaction(sub { |
497 |
|
|
498 |
# if tax 94 reverse charge, clear all GL bookings and links |
|
499 |
my $ap_gl = SL::DB::Manager::ApGl->get_first(where => [ ap_id => $form->{id} ]); |
|
500 |
my $gl_id = ref $ap_gl eq 'SL::DB::ApGl' ? $ap_gl->gl_id : undef; |
|
501 |
|
|
502 |
SL::DB::Manager::GLTransaction->delete_all(where => [ id => $gl_id ]) if $gl_id; |
|
503 |
SL::DB::Manager::ApGl-> delete_all(where => [ ap_id => $form->{id} ]) if $gl_id; |
|
504 |
SL::DB::Manager::RecordLink-> delete_all(where => [ from_table => 'ap', to_table => 'gl', from_id => $form->{id} ]); |
|
505 |
# done gl delete for tax 94 case |
|
506 |
|
|
507 |
# begin ap delete |
|
431 | 508 |
my $query = qq|DELETE FROM ap WHERE id = ?|; |
432 | 509 |
do_query($form, SL::DB->client->dbh, $query, $form->{id}); |
433 | 510 |
1; |
SL/DATEV.pm | ||
---|---|---|
835 | 835 |
} |
836 | 836 |
if ($transaction->[$i]->{'taxkey'}) { |
837 | 837 |
$taxkey = $transaction->[$i]->{'taxkey'}; |
838 |
$taxkey = 0 if $taxkey == 94; # taxbookings are in gl |
|
838 | 839 |
} |
839 | 840 |
if ($transaction->[$i]->{'charttax'}) { |
840 | 841 |
$charttax = $transaction->[$i]->{'charttax'}; |
bin/mozilla/ap.pl | ||
---|---|---|
493 | 493 |
$form->{"selected_taxchart_$i"} = $selected_taxchart; |
494 | 494 |
$form->{"AP_amount_chart_id_$i"} = $amount_chart_id; |
495 | 495 |
$form->{"taxcharts_$i"} = \@taxcharts; |
496 |
|
|
497 |
# reverse charge hack for template, display two taxes |
|
498 |
if ($taxchart_to_use->taxkey == 94) { |
|
499 |
my $tmpnetamount; |
|
500 |
($tmpnetamount, $form->{"tax_reverse_$i"}) = $form->calculate_tax($form->parse_amount(\%myconfig, $form->{"amount_$i"}), 0.19, $form->{taxincluded},2); |
|
501 |
$form->{"tax_charge_$i"} = $form->{"tax_reverse_$i"} * -1; |
|
502 |
$form->{"tax_reverse_$i"} = $form->format_amount(\%myconfig, $form->{"tax_reverse_$i"}, 2); |
|
503 |
$form->{"tax_charge_$i"} = $form->format_amount(\%myconfig, $form->{"tax_charge_$i"}, 2); |
|
504 |
} |
|
496 | 505 |
} |
497 | 506 |
|
498 | 507 |
$form->{taxchart_value_title_sub} = sub { |
... | ... | |
797 | 806 |
$form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig)); |
798 | 807 |
|
799 | 808 |
my $zero_amount_posting = 1; |
809 |
# no taxincluded for 94 |
|
810 |
my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => 94 ]); |
|
811 |
my $tax_id = ref $tax eq 'SL::DB::Tax' ? $tax->id : undef; |
|
800 | 812 |
for my $i (1 .. $form->{rowcount}) { |
813 |
# no taxincluded for 94 |
|
814 |
if ($tax_id && $form->{"taxchart_$i"} =~ m/^$tax_id--/ && $form->{taxincluded}) { |
|
815 |
$form->error($locale->text('Cannot Post AP transaction with tax included!')); |
|
816 |
} |
|
801 | 817 |
if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) { |
802 | 818 |
$zero_amount_posting = 0; |
803 |
last; |
|
804 | 819 |
} |
805 | 820 |
} |
806 | 821 |
|
... | ... | |
1348 | 1363 |
|
1349 | 1364 |
$is_linked_bank_transaction = 1; |
1350 | 1365 |
} |
1366 |
my $is_linked_gl_transaction; |
|
1367 |
if ($::form->{id} && SL::DB::Manager::ApGl->find_by(ap_id => $::form->{id})) { |
|
1368 |
$is_linked_gl_transaction = 1; |
|
1369 |
} |
|
1351 | 1370 |
|
1352 | 1371 |
my $create_post_action = sub { |
1353 | 1372 |
# $_[0]: description |
... | ... | |
1419 | 1438 |
: $is_storno ? t8('Reversal invoices cannot be canceled.') |
1420 | 1439 |
: $::form->{totalpaid} ? t8('Invoices with payments cannot be canceled.') |
1421 | 1440 |
: $has_sepa_exports ? t8('This invoice has been linked with a sepa export, undo this first.') |
1441 |
: $is_linked_gl_transaction ? t8('This transaction is linked with a gl transaction. Please delete the ap transaction booking if needed.') |
|
1422 | 1442 |
: undef, |
1423 | 1443 |
], |
1424 | 1444 |
action => [ t8('Delete'), |
... | ... | |
1426 | 1446 |
confirm => t8('Do you really want to delete this object?'), |
1427 | 1447 |
disabled => !$may_edit_create ? t8('You must not change this AP transaction.') |
1428 | 1448 |
: !$::form->{id} ? t8('This invoice has not been posted yet.') |
1429 |
: $change_never ? t8('Changing invoices has been disabled in the configuration.') |
|
1430 |
: $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.') |
|
1431 |
: $has_storno ? t8('This invoice has been canceled already.') |
|
1432 | 1449 |
: $is_closed ? t8('The billing period has already been locked.') |
1433 | 1450 |
: $has_sepa_exports ? t8('This invoice has been linked with a sepa export, undo this first.') |
1434 | 1451 |
: $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.') |
1452 |
: $is_linked_gl_transaction ? undef # linked transactions can be deleted, if period is not closed |
|
1453 |
: $change_never ? t8('Changing invoices has been disabled in the configuration.') |
|
1454 |
: $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.') |
|
1455 |
: $has_storno ? t8('This invoice has been canceled already.') |
|
1435 | 1456 |
: undef, |
1436 | 1457 |
], |
1437 | 1458 |
], # end of combobox "Storno" |
templates/webpages/ap/form_header.html | ||
---|---|---|
211 | 211 |
<input name="amount_[% i %]" size="10" value="[% temp = "amount_"_ i %][% $temp | html %]"> |
212 | 212 |
</td> |
213 | 213 |
<td> |
214 |
[% temp = "tax_"_ i %][% $temp | html %] |
|
214 |
[% IF "tax_reverse_"_ i %] |
|
215 |
[% temp_r = "tax_reverse_"_ i %][% $temp_r | html %] |
|
216 |
|
|
217 |
[% temp_c = "tax_charge_"_ i %][% $temp_c | html %] |
|
218 |
[% ELSE %] |
|
219 |
[% temp = "tax_"_ i %][% $temp | html %] |
|
220 |
[% END %] |
|
215 | 221 |
</td> |
216 | 222 |
<td> |
217 | 223 |
[% temp = 'selected_taxchart_'_ i %] |
Auch abrufbar als: Unified diff
Kreditorenbuchung um Steuerschlüssel 94 (reverse charge) erweitert
Bucht die gegensätzliche Steuer auf eine verknüpfte Dialogbuchung
und setzt den Steuerschlüssel beim DATEV-Export auf 0. Ferner sind
Steuer inklusive Buchungen unterbunden und die Dialogbuchung ist
nicht veränderbar, wird aber entsprechend modifiziert wenn die
Quell-Buchung geändert (gelöscht) wird.