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} }) {
110 next unless defined $ca->{amount};
113 foreach (qw(debit credit)) {
114 $totals{$_} += $ca->{$_} * 1;
115 $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_});
118 map { $row->{$_} = { 'data' => $ca->{$_} } } @columns;
120 map { $row->{$_}->{align} = 'right' } qw(debit credit);
121 map { $row->{$_}->{class} = 'listheading' } @columns if ($ca->{charttype} eq "H");
123 $row->{accno}->{link} = build_std_url('action=list', 'accno=' . E($ca->{accno}), 'description=' . E($ca->{description}));
125 $report->add_data($row);
128 my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns };
129 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit);
131 $report->add_separator();
132 $report->add_data($row);
134 $report->generate_with_headers();
136 $lxdebug->leave_sub();
140 $lxdebug->enter_sub();
142 $auth->assert('report');
144 $form->{title} = $locale->text('List Transactions');
145 $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
146 $year = (localtime)[5] + 1900;
149 $form->all_departments(\%myconfig);
150 if (@{ $form->{all_departments} }) {
151 $form->{selectdepartment} = "<option>\n";
154 $form->{selectdepartment} .=
155 "<option>$_->{description}--$_->{id}\n"
156 } (@{ $form->{all_departments} });
161 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
162 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
164 | if $form->{selectdepartment};
165 $accrual = ($eur) ? "" : "checked";
166 $cash = ($eur) ? "checked" : "";
168 $name_1 = "fromdate";
170 $value_1 = "$form->{fromdate}";
171 $trigger_1 = "trigger1";
175 $trigger_2 = "trigger2";
178 # with JavaScript Calendar
179 if ($form->{jsscript}) {
183 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
185 <input type=button name=$name_2 id="$trigger_2" value=|
186 . $locale->text('button') . qq|>|;
190 Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
193 <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\" value="$value_1">|;
195 <input type=button name=$name_1 id="$trigger_1" value=|
196 . $locale->text('button') . qq|>|;
198 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
200 <input type=button name=$name_2 id="$trigger_2" value=|
201 . $locale->text('button') . qq|>
206 Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
207 "$name_2", "BL", "$trigger_2");
211 # without JavaScript Calendar
214 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
217 qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
219 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
222 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
224 $onload = qq|focus()|;
225 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
226 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
231 $form->{description} =~ s/\"/"/g;
234 <body onLoad="$onload">
236 <form method=post action=$form->{script}>
238 <input type=hidden name=accno value=$form->{accno}>
239 <input type=hidden name=description value="$form->{description}">
240 <input type=hidden name=sort value=transdate>
241 <input type=hidden name=eur value=$eur>
242 <input type=hidden name=accounttype value=$form->{accounttype}>
244 <table border=0 width=100%>
246 <th class=listtop>$form->{title}</th>
252 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
253 . $locale->text('Customized Report') . qq|</th>
256 <th colspan=1>| . $locale->text('Year') . qq|</th>
257 <td><input name=year size=11 title="|
258 . $locale->text('YYYY') . qq|" value="$year"></td>
265 <b> | . $locale->text('Yearly') . qq|</b> </td>
266 <th align=left>| . $locale->text('Quarterly') . qq|</th>
267 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
270 <td align=right> <input name=duetyp class=radio type=radio value="13"
272 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
273 . $locale->text('Quarter') . qq|</td>
275 $checked = "checked";
277 <td><input name=duetyp class=radio type=radio value="1" $checked > |
278 . $locale->text('January') . qq|</td>
282 <td><input name=duetyp class=radio type=radio value="5" $checked > |
283 . $locale->text('May') . qq|</td>
284 <td><input name=duetyp class=radio type=radio value="9" $checked > |
285 . $locale->text('September') . qq|</td>
289 <td align= right> </td>
290 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
291 . $locale->text('Quarter') . qq|</td>
292 <td><input name=duetyp class=radio type=radio value="2" $checked > |
293 . $locale->text('February') . qq|</td>
294 <td><input name=duetyp class=radio type=radio value="6" $checked > |
295 . $locale->text('June') . qq|</td>
296 <td><input name=duetyp class=radio type=radio value="10" $checked > |
297 . $locale->text('October') . qq|</td>
301 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
302 . $locale->text('Quarter') . qq|</td>
303 <td><input name=duetyp class=radio type=radio value="3" $checked > |
304 . $locale->text('March') . qq|</td>
305 <td><input name=duetyp class=radio type=radio value="7" $checked > |
306 . $locale->text('July') . qq|</td>
307 <td><input name=duetyp class=radio type=radio value="11" $checked > |
308 . $locale->text('November') . qq|</td>
313 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
314 . $locale->text('Quarter') . qq| </td>
315 <td><input name=duetyp class=radio type=radio value="4" $checked > |
316 . $locale->text('April') . qq|</td>
317 <td><input name=duetyp class=radio type=radio value="8" $checked > |
318 . $locale->text('August') . qq|</td>
319 <td><input name=duetyp class=radio type=radio value="12" $checked > |
320 . $locale->text('December') . qq|</td>
324 <td colspan=5><hr size=3 noshade></td>
327 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
328 . $locale->text('Free report period') . qq|</th>
329 <td align=left colspan=4>| . $locale->text('From') . qq|
332 | . $locale->text('Bis') . qq|
338 <td colspan=5><hr size=3 noshade></td>
341 <th align=leftt>| . $locale->text('Method') . qq|</th>
342 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
343 . $locale->text('Accrual') . qq|
344 <input name=method class=radio type=radio value=cash $cash>|
345 . $locale->text('EUR') . qq|</td>
348 <th align=right colspan=4>|
349 . $locale->text('Decimalplaces')
351 <td><input name=decimalplaces size=3 value="2"></td>
354 <td><input name="subtotal" class=checkbox type=checkbox value=1> | . $locale->text('Subtotal') . qq|</td>
358 <tr><td colspan=5 ><hr size=3 noshade></td></tr>
361 <br><input class=submit type=submit name=action value="|
362 . $locale->text('List Transactions') . qq|">
369 $lxdebug->leave_sub();
372 sub format_debit_credit {
373 $lxdebug->enter_sub();
377 my $formatted_dc = $form->format_amount(\%myconfig, abs($dc), 2) . ' ';
378 $formatted_dc .= ($dc > 0) ? $locale->text('Credit (one letter abbreviation)') : $locale->text('Debit (one letter abbreviation)');
380 $lxdebug->leave_sub();
382 return $formatted_dc;
386 sub list_transactions {
387 $lxdebug->enter_sub();
389 $auth->assert('report');
391 $form->{title} = $locale->text('Account') . " $form->{accno} - $form->{description}";
393 if ($form->{reporttype} eq "custom") {
395 #forgotten the year --> thisyear
396 if ($form->{year} !~ m/^\d\d\d\d$/) {
397 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
403 if ($form->{duetyp} eq "13") {
404 $form->{fromdate} = "1.1.$form->{year}";
405 $form->{todate} = "31.12.$form->{year}";
409 if ($form->{duetyp} eq "A") {
410 $form->{fromdate} = "1.1.$form->{year}";
411 $form->{todate} = "31.3.$form->{year}";
413 if ($form->{duetyp} eq "B") {
414 $form->{fromdate} = "1.4.$form->{year}";
415 $form->{todate} = "30.6.$form->{year}";
417 if ($form->{duetyp} eq "C") {
418 $form->{fromdate} = "1.7.$form->{year}";
419 $form->{todate} = "30.9.$form->{year}";
421 if ($form->{duetyp} eq "D") {
422 $form->{fromdate} = "1.10.$form->{year}";
423 $form->{todate} = "31.12.$form->{year}";
428 $form->{duetyp} eq "1" && do {
429 $form->{fromdate} = "1.1.$form->{year}";
430 $form->{todate} = "31.1.$form->{year}";
433 $form->{duetyp} eq "2" && do {
434 $form->{fromdate} = "1.2.$form->{year}";
436 #this works from 1901 to 2099, 1900 and 2100 fail.
437 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
438 $form->{todate} = "$leap.2.$form->{year}";
441 $form->{duetyp} eq "3" && do {
442 $form->{fromdate} = "1.3.$form->{year}";
443 $form->{todate} = "31.3.$form->{year}";
446 $form->{duetyp} eq "4" && do {
447 $form->{fromdate} = "1.4.$form->{year}";
448 $form->{todate} = "30.4.$form->{year}";
451 $form->{duetyp} eq "5" && do {
452 $form->{fromdate} = "1.5.$form->{year}";
453 $form->{todate} = "31.5.$form->{year}";
456 $form->{duetyp} eq "6" && do {
457 $form->{fromdate} = "1.6.$form->{year}";
458 $form->{todate} = "30.6.$form->{year}";
461 $form->{duetyp} eq "7" && do {
462 $form->{fromdate} = "1.7.$form->{year}";
463 $form->{todate} = "31.7.$form->{year}";
466 $form->{duetyp} eq "8" && do {
467 $form->{fromdate} = "1.8.$form->{year}";
468 $form->{todate} = "31.8.$form->{year}";
471 $form->{duetyp} eq "9" && do {
472 $form->{fromdate} = "1.9.$form->{year}";
473 $form->{todate} = "30.9.$form->{year}";
476 $form->{duetyp} eq "10" && do {
477 $form->{fromdate} = "1.10.$form->{year}";
478 $form->{todate} = "31.10.$form->{year}";
481 $form->{duetyp} eq "11" && do {
482 $form->{fromdate} = "1.11.$form->{year}";
483 $form->{todate} = "30.11.$form->{year}";
486 $form->{duetyp} eq "12" && do {
487 $form->{fromdate} = "1.12.$form->{year}";
488 $form->{todate} = "31.12.$form->{year}";
494 CA->all_transactions(\%myconfig, \%$form);
496 $form->{saldo_old} += $form->{beginning_balance};
497 $form->{saldo_new} += $form->{beginning_balance};
498 my $saldo_old = format_debit_credit($form->{saldo_old});
499 my $eb_string = format_debit_credit($form->{beginning_balance});
500 $form->{balance} = $form->{saldo_old};
503 if ($form->{department}) {
504 my ($department) = split /--/, $form->{department};
505 push @options, $locale->text('Department') . " : $department";
507 if ($form->{projectnumber}) {
508 push @options, $locale->text('Project Number') . " : $form->{projectnumber}<br>";
512 if ($form->{fromdate} || $form->{todate}) {
513 my ($fromdate, $todate);
515 if ($form->{fromdate}) {
516 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
518 if ($form->{todate}) {
519 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
522 $period = "$fromdate - $todate";
525 $period = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
528 push @options, $period;
530 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
531 push (@options, $form->{print_date});
533 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
534 push (@options, $form->{company});
536 my @columns = qw(transdate reference description gegenkonto debit credit ustkonto ustrate balance);
538 'transdate' => { 'text' => $locale->text('Date'), },
539 'reference' => { 'text' => $locale->text('Reference'), },
540 'description' => { 'text' => $locale->text('Description'), },
541 'debit' => { 'text' => $locale->text('Debit'), },
542 'credit' => { 'text' => $locale->text('Credit'), },
543 'gegenkonto' => { 'text' => $locale->text('Gegenkonto'), },
544 'ustkonto' => { 'text' => $locale->text('USt-Konto'), },
545 'balance' => { 'text' => $locale->text('Balance'), },
546 'ustrate' => { 'text' => $locale->text('Satz %'), },
549 my @hidden_variables = qw(accno fromdate todate description accounttype l_heading subtotal department projectnumber project_id sort);
551 my $link = build_std_url('action=list_transactions', grep { $form->{$_} } @hidden_variables);
553 $form->{callback} = $link . '&sort=' . E($form->{sort});
555 my %column_alignment = map { $_ => 'right' } qw(debit credit);
557 @custom_headers = ();
559 push @custom_headers, [
560 { 'text' => 'Letzte Buchung', },
561 { 'text' => 'EB-Wert', },
562 { 'text' => 'Saldo alt', 'colspan' => 2, },
563 { 'text' => 'Jahresverkehrszahlen alt', 'colspan' => 2, },
564 { 'text' => '', 'colspan' => 2, },
566 push @custom_headers, [
567 { 'text' => $form->{last_transaction}, },
568 { 'text' => $eb_string, },
569 { 'text' => $saldo_old, 'colspan' => 2, },
570 { 'text' => $form->format_amount(\%myconfig, abs($form->{old_balance_debit}), 2) . " S", },
571 { 'text' => $form->format_amount(\%myconfig, $form->{old_balance_credit}, 2) . " H", },
572 { 'text' => '', 'colspan' => 2, },
575 push @custom_headers, [
576 { 'text' => $locale->text('Date'), 'link' => $link . "&sort=transdate", },
577 { 'text' => $locale->text('Reference'), 'link' => $link . "&sort=reference", },
578 { 'text' => $locale->text('Description'), 'link' => $link . "&sort=description", },
579 { 'text' => $locale->text('Gegenkonto'), },
580 { 'text' => $locale->text('Debit'), },
581 { 'text' => $locale->text('Credit'), },
582 { 'text' => $locale->text('USt-Konto'), },
583 { 'text' => $locale->text('Satz %'), },
584 { 'text' => $locale->text('Balance'), },
591 my $report = SL::ReportGenerator->new(\%myconfig, $form);
592 $report->set_custom_headers(@custom_headers);
594 $report->set_options('top_info_text' => join("\n", @options),
595 'output_format' => 'HTML',
596 'title' => $form->{title},
597 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
598 'std_column_visibility' => 1,
600 $report->set_options_from_form();
602 $report->set_columns(%column_defs);
603 $report->set_column_order(@columns);
605 $report->set_export_options('list_transactions', @hidden_variables);
607 $report->set_sort_indicator($form->{sort}, 1);
609 $column_defs->{balance}->{visible} = 1;
611 my $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
615 my %totals = ( 'debit' => 0, 'credit' => 0 );
616 my %subtotals = ( 'debit' => 0, 'credit' => 0 );
617 my ($previous_index, $row_set);
619 foreach my $ca (@{ $form->{CA} }) {
621 foreach (qw(debit credit)) {
622 $subtotals{$_} += $ca->{$_};
623 $totals{$_} += $ca->{$_};
624 if ($_ =~ /debit.*/) {
629 $form->{balance}= $form->{balance} + $ca->{$_} * $ml;
630 $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_} != 0);
634 if (($form->{subtotal})
635 && (($idx == scalar @{ $form->{CA} } - 1)
636 || ($ca->{$form->{sort}} ne $form->{CA}->[$idx + 1]->{$form->{sort}}))) {
642 $ca->{ustrate} = $form->format_amount(\%myconfig, $ca->{ustrate} * 100, 2) if ($ca->{ustrate} != 0);
644 if ($ca->{memo} ne "") {
645 $ca->{description} .= " \n " . $ca->{memo};
650 foreach my $gegenkonto (@{ $ca->{GEGENKONTO} }) {
651 if ($ca->{gegenkonto} eq "") {
652 $ca->{gegenkonto} = $gegenkonto->{accno};
654 $ca->{gegenkonto} .= ", " . $gegenkonto->{accno};
661 'align' => $column_alignment{$_},
665 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2, 'DRCR');
667 if ($ca->{index} ne $previous_index) {
668 # $report->add_data($row_set) if ($row_set);
671 $previous_index = $ca->{index};
673 $row->{reference}->{link} = build_std_url("script=$ca->{module}.pl", 'action=edit', 'id=' . E($ca->{id}), 'callback');
675 } elsif ($ca->{index} eq $previous_index) {
676 map { $row->{$_}->{data} = '' } qw(reference description);
677 $row->{transdate}->{data} = '' if ($form->{sort} eq 'transdate');
682 push @{ $row_set }, $row;
684 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, 'listsubtotal') if ($do_subtotal);
688 $report->add_data($row_set);
692 $report->add_data($row_set) if ($row_set);
694 $report->add_separator();
696 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, 'listtotal');
699 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2, 'DRCR');
701 $report->add_data($row);
704 $report->add_separator();
708 'class' => 'listtotal',
711 'data' => $locale->text('EB-Wert'),
712 'class' => 'listtotal',
715 'data' => $locale->text('Saldo neu'),
717 'class' => 'listtotal',
720 'data' => $locale->text('Jahresverkehrszahlen neu'),
723 'class' => 'listtotal',
729 'class' => 'listtotal',
733 $report->add_data($row);
734 my $saldo_new = format_debit_credit($form->{saldo_new});
738 'class' => 'listtotal',
741 'data' => $eb_string,
742 'class' => 'listtotal',
745 'data' => $saldo_new,
747 'class' => 'listtotal',
750 'data' => $form->format_amount(\%myconfig, abs($form->{current_balance_debit}) , 2) . " S",
751 'class' => 'listtotal',
754 'data' => $form->format_amount(\%myconfig, $form->{current_balance_credit}, 2) . " H",
755 'class' => 'listtotal',
760 'class' => 'listtotal',
764 $report->add_data($row);
766 $report->generate_with_headers();
768 $lxdebug->leave_sub();
771 sub create_subtotal_row {
772 $lxdebug->enter_sub();
774 my ($totals, $columns, $column_alignment, $class) = @_;
776 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
778 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(credit debit);
780 map { $totals->{$_} = 0 } qw(debit credit);
782 $lxdebug->leave_sub();