Revision ad635c66
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
SL/GL.pm | ||
---|---|---|
39 | 39 |
|
40 | 40 |
package GL; |
41 | 41 |
|
42 |
use List::Util qw(first); |
|
43 |
|
|
42 | 44 |
use Data::Dumper; |
43 | 45 |
use SL::DATEV qw(:CONSTANTS); |
44 | 46 |
use SL::DBUtils; |
47 |
use SL::DB::Chart; |
|
45 | 48 |
use SL::Util qw(trim); |
46 | 49 |
use SL::DB; |
47 | 50 |
|
... | ... | |
131 | 134 |
|
132 | 135 |
# insert acc_trans transactions |
133 | 136 |
for $i (1 .. $form->{rowcount}) { |
134 |
# extract accno |
|
135 |
my ($accno) = split(/--/, $form->{"accno_$i"}); |
|
136 | 137 |
($form->{"tax_id_$i"}) = split(/--/, $form->{"taxchart_$i"}); |
137 | 138 |
if ($form->{"tax_id_$i"} ne "") { |
138 | 139 |
$query = qq|SELECT taxkey, rate FROM tax WHERE id = ?|; |
... | ... | |
161 | 162 |
$query = |
162 | 163 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
163 | 164 |
source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id, chart_link) |
164 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), |
|
165 |
?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE accno = ?))|; |
|
166 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}), |
|
167 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}), $accno); |
|
165 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE id = ?))|; |
|
166 |
@values = (conv_i($form->{id}), $form->{"accno_id_$i"}, $amount, conv_date($form->{transdate}), |
|
167 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}), $form->{"accno_id_$i"}); |
|
168 | 168 |
do_query($form, $dbh, $query, @values); |
169 | 169 |
} |
170 | 170 |
|
... | ... | |
650 | 650 |
$query = |
651 | 651 |
qq|SELECT c.accno, t.taxkey AS accnotaxkey, a.amount, a.memo, a.source, |
652 | 652 |
a.transdate, a.cleared, a.project_id, p.projectnumber, |
653 |
a.taxkey, t.rate AS taxrate, t.id, |
|
653 |
a.taxkey, t.rate AS taxrate, t.id, a.chart_id,
|
|
654 | 654 |
(SELECT c1.accno |
655 | 655 |
FROM chart c1, tax t1 |
656 | 656 |
WHERE (t1.id = t.id) AND (c1.id = t.chart_id)) AS taxaccno, |
... | ... | |
754 | 754 |
} |
755 | 755 |
|
756 | 756 |
sub get_chart_balances { |
757 |
$main::lxdebug->enter_sub(); |
|
758 |
|
|
759 |
my $self = shift; |
|
760 |
my %params = @_; |
|
761 |
|
|
762 |
Common::check_params(\%params, qw(charts)); |
|
757 |
my ($self, @chart_ids) = @_; |
|
763 | 758 |
|
764 |
my $myconfig = \%main::myconfig; |
|
765 |
my $form = $main::form; |
|
766 |
|
|
767 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
768 |
|
|
769 |
my @ids = map { $_->{id} } @{ $params{charts} }; |
|
770 |
|
|
771 |
if (!@ids) { |
|
772 |
$main::lxdebug->leave_sub(); |
|
773 |
return; |
|
774 |
} |
|
759 |
return () unless @chart_ids; |
|
775 | 760 |
|
761 |
my $placeholders = join ', ', ('?') x scalar(@chart_ids); |
|
776 | 762 |
my $query = qq|SELECT chart_id, SUM(amount) AS sum |
777 | 763 |
FROM acc_trans |
778 |
WHERE chart_id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)
|
|
764 |
WHERE chart_id IN (${placeholders})
|
|
779 | 765 |
GROUP BY chart_id|; |
780 | 766 |
|
781 |
my %balances = selectall_as_map($form, $dbh, $query, 'chart_id', 'sum', @ids);
|
|
767 |
my %balances = selectall_as_map($::form, $::form->get_standard_dbh(\%::myconfig), $query, 'chart_id', 'sum', @chart_ids);
|
|
782 | 768 |
|
783 |
foreach my $chart (@{ $params{charts} }) { |
|
784 |
$chart->{balance} = $balances{ $chart->{id} } || 0; |
|
785 |
} |
|
786 |
|
|
787 |
$main::lxdebug->leave_sub(); |
|
769 |
return %balances; |
|
788 | 770 |
} |
789 | 771 |
|
790 |
sub get_tax_dropdown { |
|
791 |
my ($self, $accno) = @_; |
|
792 |
|
|
793 |
my $myconfig = \%main::myconfig; |
|
794 |
my $form = $main::form; |
|
772 |
sub get_active_taxes_for_chart { |
|
773 |
my ($self, $chart_id, $transdate) = @_; |
|
795 | 774 |
|
796 |
my $dbh = $form->get_standard_dbh($myconfig); |
|
775 |
my $chart = SL::DB::Chart->new(id => $chart_id)->load; |
|
776 |
my $active_taxkey = $chart->get_active_taxkey($transdate); |
|
777 |
my $taxes = SL::DB::Manager::Tax->get_all( |
|
778 |
where => [ chart_categories => { like => '%' . $chart->category . '%' }], |
|
779 |
sort_by => 'taxkey, rate', |
|
780 |
); |
|
797 | 781 |
|
798 |
my $query = qq|SELECT category FROM chart WHERE accno = ?|; |
|
799 |
my ($category) = selectrow_query($form, $dbh, $query, $accno); |
|
800 |
|
|
801 |
$query = qq|SELECT * FROM tax WHERE chart_categories like '%$category%' order by taxkey, rate|; |
|
802 |
|
|
803 |
my $sth = prepare_execute_query($form, $dbh, $query); |
|
804 |
|
|
805 |
my @tax_accounts = (); |
|
806 |
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { |
|
807 |
push(@tax_accounts, $ref); |
|
808 |
} |
|
782 |
my $default_tax = first { $active_taxkey->tax_id == $_->id } @{ $taxes }; |
|
783 |
$default_tax->{is_default} = 1 if $default_tax; |
|
809 | 784 |
|
810 |
return @tax_accounts;
|
|
785 |
return @{ $taxes };
|
|
811 | 786 |
} |
812 | 787 |
|
813 | 788 |
1; |
Auch abrufbar als: Unified diff
Dialogbuchen auf Verwendung des Chart-Pickers umgestellt