2 use Test::More tests => 4;
5 use Support::TestSetup;
10 use SL::DB::GLTransaction;
12 use SL::DBUtils qw(selectall_hashref_query);
14 Support::TestSetup::login();
18 my $cash = SL::DB::Manager::Chart->find_by( description => 'Kasse' );
19 my $bank = SL::DB::Manager::Chart->find_by( description => 'Bank' );
20 my $betriebsbedarf = SL::DB::Manager::Chart->find_by( description => 'Betriebsbedarf' );
22 my $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19);
23 my $tax_8 = SL::DB::Manager::Tax->find_by(taxkey => 8, rate => 0.07);
24 my $tax_0 = SL::DB::Manager::Tax->find_by(taxkey => 0, rate => 0.00);
26 my $dbh = SL::DB->client->dbh;
28 # example with chaining of add_chart_booking
29 my $gl_transaction = SL::DB::GLTransaction->new(
31 reference => 'bank/cash',
32 description => 'bank/cash',
33 transdate => DateTime->today_local,
44 # example where bookings is prepared separately as an arrayref
45 my $gl_transaction_2 = SL::DB::GLTransaction->new(
46 reference => 'betriebsbedarf several rows',
47 description => 'betriebsbedarf',
49 transdate => DateTime->today_local,
54 chart => $betriebsbedarf,
61 chart => $betriebsbedarf,
75 $gl_transaction_2->add_chart_booking(%{$_}) foreach @{ $bookings };
76 $gl_transaction_2->post;
79 # example where add_chart_booking is called via a foreach
80 my $gl_transaction_3 = SL::DB::GLTransaction->new(
81 reference => 'betriebsbedarf tax included',
84 transdate => DateTime->today_local,
86 $gl_transaction_3->add_chart_booking(%{$_}) foreach (
88 chart => $betriebsbedarf,
93 chart => $betriebsbedarf,
98 chart => $betriebsbedarf,
100 tax_id => $tax_0->id,
105 tax_id => $tax_0->id,
108 $gl_transaction_3->post;
110 my $gl_transaction_4 = SL::DB::GLTransaction->new(
111 reference => 'betriebsbedarf tax not included',
112 description => 'bar',
114 transdate => DateTime->today_local,
116 $gl_transaction_4->add_chart_booking(%{$_}) foreach (
118 chart => $betriebsbedarf,
120 tax_id => $tax_9->id,
123 chart => $betriebsbedarf,
125 tax_id => $tax_8->id,
128 chart => $betriebsbedarf,
130 tax_id => $tax_0->id,
135 tax_id => $tax_0->id,
138 $gl_transaction_4->post;
140 is(SL::DB::Manager::GLTransaction->get_all_count(), 4, "gl transactions created ok");
142 is_deeply(&get_account_balances,
150 'sum' => '-100.00000'
162 'sum' => '-800.00000'
169 note('testing subcent');
171 my $gl_transaction_5_taxinc = SL::DB::GLTransaction->new(
173 reference => 'subcent tax included',
174 description => 'subcent tax included',
175 transdate => DateTime->today_local,
176 )->add_chart_booking(
177 chart => $betriebsbedarf,
179 tax_id => $tax_9->id,
180 )->add_chart_booking(
183 tax_id => $tax_0->id,
186 my $gl_transaction_5_taxnoinc = SL::DB::GLTransaction->new(
188 reference => 'subcent tax not included',
189 description => 'subcent tax not included',
190 transdate => DateTime->today_local,
191 )->add_chart_booking(
192 chart => $betriebsbedarf,
194 tax_id => $tax_9->id,
195 )->add_chart_booking(
198 tax_id => $tax_0->id,
201 my $gl_transaction_6_taxinc = SL::DB::GLTransaction->new(
203 reference => 'cent tax included',
204 description => 'cent tax included',
205 transdate => DateTime->today_local,
206 )->add_chart_booking(
207 chart => $betriebsbedarf,
209 tax_id => $tax_9->id,
210 )->add_chart_booking(
213 tax_id => $tax_0->id,
216 my $gl_transaction_6_taxnoinc = SL::DB::GLTransaction->new(
218 reference => 'cent tax included',
219 description => 'cent tax included',
220 transdate => DateTime->today_local,
221 )->add_chart_booking(
222 chart => $betriebsbedarf,
224 tax_id => $tax_9->id,
225 )->add_chart_booking(
228 tax_id => $tax_0->id,
231 is(SL::DB::Manager::GLTransaction->get_all_count(), 8, "gl transactions created ok");
234 is_deeply(&get_account_balances,
242 'sum' => '-100.00000'
254 'sum' => '-800.12000'
266 "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(
272 sub get_account_balances {
277 left join chart c on (c.id = a.chart_id)
282 my $result = selectall_hashref_query($::form, $dbh, $query);