Revision 090de47c
Von Sven Schöling vor mehr als 17 Jahren hinzugefügt
SL/GL.pm | ||
---|---|---|
638 | 638 |
$main::lxdebug->leave_sub(); |
639 | 639 |
} |
640 | 640 |
|
641 |
sub storno { |
|
642 |
$main::lxdebug->enter_sub(); |
|
643 |
|
|
644 |
my ($self, $form, $myconfig, $id) = @_; |
|
645 |
|
|
646 |
my ($query, $new_id, $storno_row, $acc_trans_rows); |
|
647 |
my $dbh = $form->get_standard_dbh($myconfig); |
|
648 |
|
|
649 |
$query = qq|SELECT nextval('glid')|; |
|
650 |
($new_id) = selectrow_query($form, $dbh, $query); |
|
651 |
|
|
652 |
$query = qq|SELECT * FROM gl WHERE id = ?|; |
|
653 |
$storno_row = selectfirst_hashref_query($form, $dbh, $query, $id); |
|
654 |
|
|
655 |
$storno_row->{id} = $new_id; |
|
656 |
$storno_row->{storno_id} = $id; |
|
657 |
$storno_row->{storno} = 't'; |
|
658 |
$storno_row->{reference} = 'Storno-' . $storno_row->{reference}; |
|
659 |
|
|
660 |
delete @$storno_row{qw(itime mtime)}; |
|
661 |
|
|
662 |
$query = sprintf 'INSERT INTO gl (%s) VALUES (%s)', join(', ', keys %$storno_row), join(', ', map '?', values %$storno_row); |
|
663 |
do_query($form, $dbh, $query, (values %$storno_row)); |
|
664 |
|
|
665 |
# now copy acc_trans entries |
|
666 |
$query = qq|SELECT * FROM acc_trans WHERE trans_id = ?|; |
|
667 |
my $rowref = selectall_hashref_query($form, $dbh, $query, $id); |
|
668 |
|
|
669 |
for my $row (@$rowref) { |
|
670 |
delete @$row{qw(itime mtime)}; |
|
671 |
$query = sprintf 'INSERT INTO acc_trans (%s) VALUES (%s)', join(', ', keys %$row), join(', ', map '?', values %$row); |
|
672 |
$row->{trans_id} = $new_id; |
|
673 |
$row->{amount} *= -1; |
|
674 |
do_query($form, $dbh, $query, (values %$row)); |
|
675 |
} |
|
676 |
|
|
677 |
$dbh->commit; |
|
678 |
|
|
679 |
$main::lxdebug->leave_sub(); |
|
680 |
} |
|
681 |
|
|
641 | 682 |
1; |
bin/mozilla/gl.pl | ||
---|---|---|
1783 | 1783 |
sub storno { |
1784 | 1784 |
$lxdebug->enter_sub(); |
1785 | 1785 |
|
1786 |
# don't cancel cancelled transactions |
|
1786 | 1787 |
if (IS->has_storno(\%myconfig, $form, 'gl')) { |
1787 |
$form->{title} = $locale->text("Cancel General Ledger Transaction");
|
|
1788 |
$form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
|
|
1788 | 1789 |
$form->error($locale->text("Transaction has already been cancelled!")); |
1789 | 1790 |
} |
1790 | 1791 |
|
1791 |
my %keep_keys = map { $_, 1 } qw(login password id stylesheet); |
|
1792 |
map { delete $form->{$_} unless $keep_keys{$_} } keys %{ $form }; |
|
1793 |
|
|
1794 |
prepare_transaction(); |
|
1795 |
|
|
1796 |
for my $i (1 .. $form->{rowcount}) { |
|
1797 |
for (qw(debit credit tax)) { |
|
1798 |
$form->{"${_}_$i"} = |
|
1799 |
($form->{"${_}_$i"}) |
|
1800 |
? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) |
|
1801 |
: ""; |
|
1802 |
} |
|
1803 |
} |
|
1804 |
|
|
1805 |
$form->{storno} = 1; |
|
1806 |
$form->{storno_id} = $form->{id}; |
|
1807 |
$form->{id} = 0; |
|
1808 |
|
|
1809 |
$form->{reference} = "Storno-" . $form->{reference}; |
|
1810 |
$form->{description} = "Storno-" . $form->{description}; |
|
1811 |
|
|
1812 |
for my $i (1 .. $form->{rowcount}) { |
|
1813 |
next if (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")); |
|
1814 |
|
|
1815 |
if ($form->{"debit_$i"} ne "") { |
|
1816 |
$form->{"credit_$i"} = $form->{"debit_$i"}; |
|
1817 |
$form->{"debit_$i"} = ""; |
|
1818 |
|
|
1819 |
} else { |
|
1820 |
$form->{"debit_$i"} = $form->{"credit_$i"}; |
|
1821 |
$form->{"credit_$i"} = ""; |
|
1822 |
} |
|
1823 |
} |
|
1824 |
|
|
1825 |
post_transaction(); |
|
1792 |
GL->storno($form, \%myconfig, $form->{id}); |
|
1826 | 1793 |
|
1827 | 1794 |
# saving the history |
1828 | 1795 |
if(!exists $form->{addition} && $form->{id} ne "") { |
1829 |
$form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
|
|
1830 |
$form->{addition} = "STORNO";
|
|
1831 |
$form->save_history($form->dbconnect(\%myconfig));
|
|
1796 |
$form->{snumbers} = "ordnumber_$form->{ordnumber}";
|
|
1797 |
$form->{addition} = "STORNO";
|
|
1798 |
$form->save_history($form->dbconnect(\%myconfig));
|
|
1832 | 1799 |
} |
1833 | 1800 |
# /saving the history |
1834 | 1801 |
|
1835 | 1802 |
$form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); |
1836 | 1803 |
|
1837 | 1804 |
$lxdebug->leave_sub(); |
1838 |
|
|
1839 | 1805 |
} |
1840 | 1806 |
|
Auch abrufbar als: Unified diff
Stornomechanismus mal auf Dialogbuchen ausgeweitet