1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # module for Chart of Accounts, Income Statement and Balance Sheet
31 # search and edit transactions posted by the GL, AR and AP
33 #======================================================================
35 use POSIX qw(strftime);
38 use SL::ReportGenerator;
40 require "bin/mozilla/reportgenerator.pl";
46 # this is for our long dates
47 # $locale->text('January')
48 # $locale->text('February')
49 # $locale->text('March')
50 # $locale->text('April')
51 # $locale->text('May ')
52 # $locale->text('June')
53 # $locale->text('July')
54 # $locale->text('August')
55 # $locale->text('September')
56 # $locale->text('October')
57 # $locale->text('November')
58 # $locale->text('December')
60 # this is for our short month
61 # $locale->text('Jan')
62 # $locale->text('Feb')
63 # $locale->text('Mar')
64 # $locale->text('Apr')
65 # $locale->text('May')
66 # $locale->text('Jun')
67 # $locale->text('Jul')
68 # $locale->text('Aug')
69 # $locale->text('Sep')
70 # $locale->text('Oct')
71 # $locale->text('Nov')
72 # $locale->text('Dec')
74 sub chart_of_accounts {
75 $lxdebug->enter_sub();
77 $auth->assert('report');
79 $form->{title} = $locale->text('Chart of Accounts');
81 CA->all_accounts(\%myconfig, \%$form);
83 my @columns = qw(accno description debit credit);
85 'accno' => { 'text' => $locale->text('Account'), },
86 'description' => { 'text' => $locale->text('Description'), },
87 'debit' => { 'text' => $locale->text('Debit'), },
88 'credit' => { 'text' => $locale->text('Credit'), },
91 my $report = SL::ReportGenerator->new(\%myconfig, $form);
93 $report->set_options('output_format' => 'HTML',
94 'title' => $form->{title},
95 'attachment_basename' => $locale->text('chart_of_accounts') . strftime('_%Y%m%d', localtime time),
96 'std_column_visibility' => 1,
98 $report->set_options_from_form();
100 $report->set_columns(%column_defs);
101 $report->set_column_order(@columns);
103 $report->set_export_options('chart_of_accounts');
105 $report->set_sort_indicator($form->{sort}, 1);
107 my %totals = ('debit' => 0, 'credit' => 0);
109 foreach my $ca (@{ $form->{CA} }) {
112 foreach (qw(debit credit)) {
113 $totals{$_} += $ca->{$_} * 1;
114 $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_});
117 map { $row->{$_} = { 'data' => $ca->{$_} } } @columns;
119 map { $row->{$_}->{align} = 'right' } qw(debit credit);
120 map { $row->{$_}->{class} = 'listheading' } @columns if ($ca->{charttype} eq "H");
122 $row->{accno}->{link} = build_std_url('action=list', 'accno=' . E($ca->{accno}), 'description=' . E($ca->{description}));
124 $report->add_data($row);
127 my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns };
128 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit);
130 $report->add_separator();
131 $report->add_data($row);
133 $report->generate_with_headers();
135 $lxdebug->leave_sub();
139 $lxdebug->enter_sub();
141 $auth->assert('report');
143 $form->{title} = $locale->text('List Transactions');
144 $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
145 $year = (localtime)[5] + 1900;
148 $form->all_departments(\%myconfig);
149 if (@{ $form->{all_departments} }) {
150 $form->{selectdepartment} = "<option>\n";
153 $form->{selectdepartment} .=
154 "<option>$_->{description}--$_->{id}\n"
155 } (@{ $form->{all_departments} });
160 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
161 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
163 | if $form->{selectdepartment};
164 $accrual = ($eur) ? "" : "checked";
165 $cash = ($eur) ? "checked" : "";
167 $name_1 = "fromdate";
169 $value_1 = "$form->{fromdate}";
170 $trigger_1 = "trigger1";
174 $trigger_2 = "trigger2";
177 # with JavaScript Calendar
178 if ($form->{jsscript}) {
182 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
184 <input type=button name=$name_2 id="$trigger_2" value=|
185 . $locale->text('button') . qq|>|;
189 Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
192 <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\" value="$value_1">|;
194 <input type=button name=$name_1 id="$trigger_1" value=|
195 . $locale->text('button') . qq|>|;
197 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
199 <input type=button name=$name_2 id="$trigger_2" value=|
200 . $locale->text('button') . qq|>
205 Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
206 "$name_2", "BL", "$trigger_2");
210 # without JavaScript Calendar
213 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
216 qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
218 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
221 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
223 $onload = qq|focus()|;
224 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
225 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
230 $form->{description} =~ s/\"/"/g;
233 <body onLoad="$onload">
235 <form method=post action=$form->{script}>
237 <input type=hidden name=accno value=$form->{accno}>
238 <input type=hidden name=description value="$form->{description}">
239 <input type=hidden name=sort value=transdate>
240 <input type=hidden name=eur value=$eur>
241 <input type=hidden name=accounttype value=$form->{accounttype}>
243 <table border=0 width=100%>
245 <th class=listtop>$form->{title}</th>
251 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
252 . $locale->text('Customized Report') . qq|</th>
255 <th colspan=1>| . $locale->text('Year') . qq|</th>
256 <td><input name=year size=11 title="|
257 . $locale->text('YYYY') . qq|" value="$year"></td>
264 <b> | . $locale->text('Yearly') . qq|</b> </td>
265 <th align=left>| . $locale->text('Quarterly') . qq|</th>
266 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
269 <td align=right> <input name=duetyp class=radio type=radio value="13"
271 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
272 . $locale->text('Quarter') . qq|</td>
274 $checked = "checked";
276 <td><input name=duetyp class=radio type=radio value="1" $checked > |
277 . $locale->text('January') . qq|</td>
281 <td><input name=duetyp class=radio type=radio value="5" $checked > |
282 . $locale->text('May') . qq|</td>
283 <td><input name=duetyp class=radio type=radio value="9" $checked > |
284 . $locale->text('September') . qq|</td>
288 <td align= right> </td>
289 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
290 . $locale->text('Quarter') . qq|</td>
291 <td><input name=duetyp class=radio type=radio value="2" $checked > |
292 . $locale->text('February') . qq|</td>
293 <td><input name=duetyp class=radio type=radio value="6" $checked > |
294 . $locale->text('June') . qq|</td>
295 <td><input name=duetyp class=radio type=radio value="10" $checked > |
296 . $locale->text('October') . qq|</td>
300 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
301 . $locale->text('Quarter') . qq|</td>
302 <td><input name=duetyp class=radio type=radio value="3" $checked > |
303 . $locale->text('March') . qq|</td>
304 <td><input name=duetyp class=radio type=radio value="7" $checked > |
305 . $locale->text('July') . qq|</td>
306 <td><input name=duetyp class=radio type=radio value="11" $checked > |
307 . $locale->text('November') . qq|</td>
312 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
313 . $locale->text('Quarter') . qq| </td>
314 <td><input name=duetyp class=radio type=radio value="4" $checked > |
315 . $locale->text('April') . qq|</td>
316 <td><input name=duetyp class=radio type=radio value="8" $checked > |
317 . $locale->text('August') . qq|</td>
318 <td><input name=duetyp class=radio type=radio value="12" $checked > |
319 . $locale->text('December') . qq|</td>
323 <td colspan=5><hr size=3 noshade></td>
326 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
327 . $locale->text('Free report period') . qq|</th>
328 <td align=left colspan=4>| . $locale->text('From') . qq|
331 | . $locale->text('Bis') . qq|
337 <td colspan=5><hr size=3 noshade></td>
340 <th align=leftt>| . $locale->text('Method') . qq|</th>
341 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
342 . $locale->text('Accrual') . qq|
343 <input name=method class=radio type=radio value=cash $cash>|
344 . $locale->text('EUR') . qq|</td>
347 <th align=right colspan=4>|
348 . $locale->text('Decimalplaces')
350 <td><input name=decimalplaces size=3 value="2"></td>
354 <tr><td colspan=5 ><hr size=3 noshade></td></tr>
357 <br><input class=submit type=submit name=action value="|
358 . $locale->text('List Transactions') . qq|">
365 $lxdebug->leave_sub();
368 sub list_transactions {
369 $lxdebug->enter_sub();
371 $auth->assert('report');
373 $form->{title} = $locale->text('Account') . " $form->{accno} - $form->{description}";
375 if ($form->{reporttype} eq "custom") {
377 #forgotten the year --> thisyear
378 if ($form->{year} !~ m/^\d\d\d\d$/) {
379 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
385 if ($form->{duetyp} eq "13") {
386 $form->{fromdate} = "1.1.$form->{year}";
387 $form->{todate} = "31.12.$form->{year}";
391 if ($form->{duetyp} eq "A") {
392 $form->{fromdate} = "1.1.$form->{year}";
393 $form->{todate} = "31.3.$form->{year}";
395 if ($form->{duetyp} eq "B") {
396 $form->{fromdate} = "1.4.$form->{year}";
397 $form->{todate} = "30.6.$form->{year}";
399 if ($form->{duetyp} eq "C") {
400 $form->{fromdate} = "1.7.$form->{year}";
401 $form->{todate} = "30.9.$form->{year}";
403 if ($form->{duetyp} eq "D") {
404 $form->{fromdate} = "1.10.$form->{year}";
405 $form->{todate} = "31.12.$form->{year}";
410 $form->{duetyp} eq "1" && do {
411 $form->{fromdate} = "1.1.$form->{year}";
412 $form->{todate} = "31.1.$form->{year}";
415 $form->{duetyp} eq "2" && do {
416 $form->{fromdate} = "1.2.$form->{year}";
418 #this works from 1901 to 2099, 1900 and 2100 fail.
419 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
420 $form->{todate} = "$leap.2.$form->{year}";
423 $form->{duetyp} eq "3" && do {
424 $form->{fromdate} = "1.3.$form->{year}";
425 $form->{todate} = "31.3.$form->{year}";
428 $form->{duetyp} eq "4" && do {
429 $form->{fromdate} = "1.4.$form->{year}";
430 $form->{todate} = "30.4.$form->{year}";
433 $form->{duetyp} eq "5" && do {
434 $form->{fromdate} = "1.5.$form->{year}";
435 $form->{todate} = "31.5.$form->{year}";
438 $form->{duetyp} eq "6" && do {
439 $form->{fromdate} = "1.6.$form->{year}";
440 $form->{todate} = "30.6.$form->{year}";
443 $form->{duetyp} eq "7" && do {
444 $form->{fromdate} = "1.7.$form->{year}";
445 $form->{todate} = "31.7.$form->{year}";
448 $form->{duetyp} eq "8" && do {
449 $form->{fromdate} = "1.8.$form->{year}";
450 $form->{todate} = "31.8.$form->{year}";
453 $form->{duetyp} eq "9" && do {
454 $form->{fromdate} = "1.9.$form->{year}";
455 $form->{todate} = "30.9.$form->{year}";
458 $form->{duetyp} eq "10" && do {
459 $form->{fromdate} = "1.10.$form->{year}";
460 $form->{todate} = "31.10.$form->{year}";
463 $form->{duetyp} eq "11" && do {
464 $form->{fromdate} = "1.11.$form->{year}";
465 $form->{todate} = "30.11.$form->{year}";
468 $form->{duetyp} eq "12" && do {
469 $form->{fromdate} = "1.12.$form->{year}";
470 $form->{todate} = "31.12.$form->{year}";
476 CA->all_transactions(\%myconfig, \%$form);
479 my $saldo_old = ($form->{saldo_old} > 0) ? $form->format_amount(\%myconfig, $form->{saldo_old}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{saldo_old}) , 2) . " S";
481 my $eb_string = ($form->{beginning_balance} > 0) ? $form->format_amount(\%myconfig, $form->{beginning_balance}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{beginning_balance}), 2) . " S";
484 if ($form->{department}) {
485 my ($department) = split /--/, $form->{department};
486 push @options, $locale->text('Department') . " : $department";
488 if ($form->{projectnumber}) {
489 push @options, $locale->text('Project Number') . " : $form->{projectnumber}<br>";
493 if ($form->{fromdate} || $form->{todate}) {
494 my ($fromdate, $todate);
496 if ($form->{fromdate}) {
497 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
499 if ($form->{todate}) {
500 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
503 $period = "$fromdate - $todate";
506 $period = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
509 push @options, $period;
511 my @columns = qw(transdate reference description gegenkonto debit credit ustkonto ustrate);
513 'transdate' => { 'text' => $locale->text('Date'), },
514 'reference' => { 'text' => $locale->text('Reference'), },
515 'description' => { 'text' => $locale->text('Description'), },
516 'debit' => { 'text' => $locale->text('Debit'), },
517 'credit' => { 'text' => $locale->text('Credit'), },
518 'gegenkonto' => { 'text' => $locale->text('Gegenkonto'), },
519 'ustkonto' => { 'text' => $locale->text('USt-Konto'), },
520 'ustrate' => { 'text' => $locale->text('Satz %'), },
522 my %column_alignment = map { $_ => 'right' } qw(debit credit);
524 @custom_headers = ();
526 push @custom_headers, [
527 { 'text' => 'Letzte Buchung', },
528 { 'text' => 'EB-Wert', },
529 { 'text' => 'Saldo alt', 'colspan' => 2, },
530 { 'text' => 'Jahresverkehrszahlen alt', 'colspan' => 2, },
531 { 'text' => '', 'colspan' => 2, },
533 push @custom_headers, [
534 { 'text' => $form->{last_transaction}, },
535 { 'text' => $eb_string, },
536 { 'text' => $saldo_old, 'colspan' => 2, },
537 { 'text' => $form->format_amount(\%myconfig, abs($form->{old_balance_debit}), 2) . " S", },
538 { 'text' => $form->format_amount(\%myconfig, $form->{old_balance_credit}, 2) . " H", },
539 { 'text' => '', 'colspan' => 2, },
542 push @custom_headers, [
543 { 'text' => $locale->text('Date'), },
544 { 'text' => $locale->text('Reference'), },
545 { 'text' => $locale->text('Description'), },
546 { 'text' => $locale->text('Gegenkonto'), },
547 { 'text' => $locale->text('Debit'), },
548 { 'text' => $locale->text('Credit'), },
549 { 'text' => $locale->text('USt-Konto'), },
550 { 'text' => $locale->text('Satz %'), },
555 my @hidden_variables = qw(accno fromdate todate description accounttype l_heading l_subtotal department projectnumber project_id sort);
557 my $link = build_std_url('action=list_transactions', grep { $form->{$_} } @hidden_variables);
558 map { $column_defs{$_}->{link} = $link . "&sort=$_" } qw(transdate reference description);
560 $form->{callback} = $link . '&sort=' . E($form->{sort});
562 my $report = SL::ReportGenerator->new(\%myconfig, $form);
563 $report->set_custom_headers(@custom_headers);
565 $report->set_options('top_info_text' => join("\n", @options),
566 'output_format' => 'HTML',
567 'title' => $form->{title},
568 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
569 'std_column_visibility' => 1,
571 $report->set_options_from_form();
573 $report->set_columns(%column_defs);
574 $report->set_column_order(@columns);
576 $report->set_export_options('list_transactions', @hidden_variables);
578 $report->set_sort_indicator($form->{sort}, 1);
580 $column_defs->{balance}->{visible} = $form->{accno} ? 1 : 0;
582 my $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
586 my %totals = ( 'debit' => 0, 'credit' => 0 );
587 my %subtotals = ( 'debit' => 0, 'credit' => 0 );
588 my ($previous_index, $row_set);
590 foreach my $ca (@{ $form->{CA} }) {
592 foreach (qw(debit credit)) {
593 $subtotals{$_} += $ca->{$_};
594 $totals{$_} += $ca->{$_};
595 $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_} != 0);
601 $ca->{ustrate} = $form->format_amount(\%myconfig, $ca->{ustrate} * 100, 2) if ($ca->{ustrate} != 0);
603 if ($ca->{memo} ne "") {
604 $ca->{description} .= " \n " . $ca->{memo};
609 foreach my $gegenkonto (@{ $ca->{GEGENKONTO} }) {
610 if ($ca->{gegenkonto} eq "") {
611 $ca->{gegenkonto} = $gegenkonto->{accno};
613 $ca->{gegenkonto} .= ", " . $gegenkonto->{accno};
620 'align' => $column_alignment{$_},
624 if ($ca->{index} ne $previous_index) {
625 $report->add_data($row_set) if ($row_set);
628 $previous_index = $ca->{index};
630 $row->{reference}->{link} = build_std_url("script=$ca->{module}.pl", 'action=edit', 'id=' . E($ca->{id}), 'callback');
633 map { $row->{$_}->{data} = '' } qw(reference description);
634 $row->{transdate}->{data} = '' if ($form->{sort} eq 'transdate');
637 push @{ $row_set }, $row;
639 if (($form->{l_subtotal} eq 'Y')
640 && (($idx == scalar @{ $form->{CA} } - 1)
641 || ($ca->{$form->{sort}} ne $form->{CA}->[$idx + 1]->{$form->{sort}}))) {
642 $report->add_data(create_subtotal_row(\%subtotals, \@columns, \%column_alignment, 'listsubtotal'));
648 $report->add_data($row_set) if ($row_set);
650 $report->add_separator();
652 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, 'listtotal');
653 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance} * $ml, 2);
654 $report->add_data($row);
657 $report->add_separator();
661 'class' => 'listtotal',
664 'data' => $locale->text('EB-Wert'),
665 'class' => 'listtotal',
668 'data' => $locale->text('Saldo neu'),
670 'class' => 'listtotal',
673 'data' => $locale->text('Jahresverkehrszahlen neu'),
676 'class' => 'listtotal',
682 'class' => 'listtotal',
686 $report->add_data($row);
687 my $saldo_new = ($form->{saldo_new} > 0) ? $form->format_amount(\%myconfig, $form->{saldo_new}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{saldo_new}) , 2) . " S";
691 'class' => 'listtotal',
694 'data' => $eb_string,
695 'class' => 'listtotal',
698 'data' => $saldo_new,
700 'class' => 'listtotal',
703 'data' => $form->format_amount(\%myconfig, abs($form->{current_balance_debit}) , 2) . " S",
704 'class' => 'listtotal',
707 'data' => $form->format_amount(\%myconfig, $form->{current_balance_credit}, 2) . " H",
708 'class' => 'listtotal',
713 'class' => 'listtotal',
717 $report->add_data($row);
719 $report->generate_with_headers();
721 $lxdebug->leave_sub();
724 sub create_subtotal_row {
725 $lxdebug->enter_sub();
727 my ($totals, $columns, $column_alignment, $class) = @_;
729 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
731 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(credit debit);
733 map { $totals->{$_} = 0 } qw(debit credit);
735 $lxdebug->leave_sub();