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}";
147 $form->all_departments(\%myconfig);
148 if (@{ $form->{all_departments} }) {
149 $form->{selectdepartment} = "<option>\n";
152 $form->{selectdepartment} .=
153 "<option>$_->{description}--$_->{id}\n"
154 } (@{ $form->{all_departments} });
159 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
160 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
162 | if $form->{selectdepartment};
166 $form->{description} =~ s/\"/"/g;
171 <form method=post action=$form->{script}>
173 <input type=hidden name=accno value=$form->{accno}>
174 <input type=hidden name=description value="$form->{description}">
175 <input type=hidden name=sort value=transdate>
176 <input type=hidden name=eur value=$eur>
177 <input type=hidden name=accounttype value=$form->{accounttype}>
179 <table border=0 width=100%>
180 <tr><th class=listtop>$form->{title}</th></tr>
187 <th align=right>| . $locale->text('From') . qq|</th>
188 <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
189 <th align=right>| . $locale->text('To') . qq|</th>
190 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
193 <th align=right>| . $locale->text('Include in Report') . qq|</th>
195 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
196 . $locale->text('Subtotal') . qq|</td>
201 <tr><td><hr size=3 noshade></td></tr>
204 <br><input class=submit type=submit name=action value="|
205 . $locale->text('List Transactions') . qq|">
212 $lxdebug->leave_sub();
215 sub list_transactions {
216 $lxdebug->enter_sub();
218 $auth->assert('report');
220 $form->{title} = $locale->text('Account') . " $form->{accno} - $form->{description}";
222 CA->all_transactions(\%myconfig, \%$form);
225 if ($form->{department}) {
226 my ($department) = split /--/, $form->{department};
227 push @options, $locale->text('Department') . " : $department";
229 if ($form->{projectnumber}) {
230 push @options, $locale->text('Project Number') . " : $form->{projectnumber}<br>";
234 if ($form->{fromdate} || $form->{todate}) {
235 my ($fromdate, $todate);
237 if ($form->{fromdate}) {
238 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
240 if ($form->{todate}) {
241 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
244 $period = "$fromdate - $todate";
247 $period = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
250 push @options, $period;
252 my @columns = qw(transdate reference description debit credit balance);
254 'transdate' => { 'text' => $locale->text('Date'), },
255 'reference' => { 'text' => $locale->text('Reference'), },
256 'description' => { 'text' => $locale->text('Description'), },
257 'debit' => { 'text' => $locale->text('Debit'), },
258 'credit' => { 'text' => $locale->text('Credit'), },
259 'balance' => { 'text' => $locale->text('Balance'), },
261 my %column_alignment = map { $_ => 'right' } qw(debit credit balance);
263 my @hidden_variables = qw(accno fromdate todate description accounttype l_heading l_subtotal department projectnumber project_id sort);
265 my $link = build_std_url('action=list_transactions', grep { $form->{$_} } @hidden_variables);
266 map { $column_defs{$_}->{link} = $link . "&sort=$_" } qw(transdate reference description);
268 $form->{callback} = $link . '&sort=' . E($form->{sort});
270 my $report = SL::ReportGenerator->new(\%myconfig, $form);
272 $report->set_options('top_info_text' => join("\n", @options),
273 'output_format' => 'HTML',
274 'title' => $form->{title},
275 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
276 'std_column_visibility' => 1,
278 $report->set_options_from_form();
280 $report->set_columns(%column_defs);
281 $report->set_column_order(@columns);
283 $report->set_export_options('list_transactions', @hidden_variables);
285 $report->set_sort_indicator($form->{sort}, 1);
287 $column_defs->{balance}->{visible} = $form->{accno} ? 1 : 0;
289 my $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
291 if ($form->{accno} && $form->{balance}) {
294 'data' => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2),
299 $report->add_data($row);
303 my %totals = ( 'debit' => 0, 'credit' => 0 );
304 my %subtotals = ( 'debit' => 0, 'credit' => 0 );
305 my ($previous_index, $row_set);
307 foreach my $ca (@{ $form->{CA} }) {
308 $form->{balance} += $ca->{amount};
310 foreach (qw(debit credit)) {
311 $subtotals{$_} += $ca->{$_};
312 $totals{$_} += $ca->{$_};
313 $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_} != 0);
316 $ca->{balance} = $form->format_amount(\%myconfig, $form->{balance} * $ml, 2);
323 'align' => $column_alignment{$_},
327 if ($ca->{index} ne $previous_index) {
328 $report->add_data($row_set) if ($row_set);
331 $previous_index = $ca->{index};
333 $row->{reference}->{link} = build_std_url("script=$ca->{module}.pl", 'action=edit', 'id=' . E($ca->{id}), 'callback');
336 map { $row->{$_}->{data} = '' } qw(reference description);
337 $row->{transdate}->{data} = '' if ($form->{sort} eq 'transdate');
340 push @{ $row_set }, $row;
342 if (($form->{l_subtotal} eq 'Y')
343 && (($idx == scalar @{ $form->{CA} } - 1)
344 || ($ca->{$form->{sort}} ne $form->{CA}->[$idx + 1]->{$form->{sort}}))) {
345 $report->add_data(create_subtotal_row(\%subtotals, \@columns, \%column_alignment, 'listsubtotal'));
351 $report->add_data($row_set) if ($row_set);
353 $report->add_separator();
355 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, 'listtotal');
356 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance} * $ml, 2);
357 $report->add_data($row);
359 $report->generate_with_headers();
361 $lxdebug->leave_sub();
364 sub create_subtotal_row {
365 $lxdebug->enter_sub();
367 my ($totals, $columns, $column_alignment, $class) = @_;
369 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
371 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(credit debit);
373 map { $totals->{$_} = 0 } qw(debit credit);
375 $lxdebug->leave_sub();