1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
25 # module for Chart of Accounts, Income Statement and Balance Sheet
26 # search and edit transactions posted by the GL, AR and AP
28 #======================================================================
35 # this is for our long dates
36 # $locale->text('January')
37 # $locale->text('February')
38 # $locale->text('March')
39 # $locale->text('April')
40 # $locale->text('May ')
41 # $locale->text('June')
42 # $locale->text('July')
43 # $locale->text('August')
44 # $locale->text('September')
45 # $locale->text('October')
46 # $locale->text('November')
47 # $locale->text('December')
49 # this is for our short month
50 # $locale->text('Jan')
51 # $locale->text('Feb')
52 # $locale->text('Mar')
53 # $locale->text('Apr')
54 # $locale->text('May')
55 # $locale->text('Jun')
56 # $locale->text('Jul')
57 # $locale->text('Aug')
58 # $locale->text('Sep')
59 # $locale->text('Oct')
60 # $locale->text('Nov')
61 # $locale->text('Dec')
64 sub chart_of_accounts {
66 CA->all_accounts(\%myconfig, \%$form);
68 @column_index = qw(accno gifi_accno description debit credit);
70 $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</th>\n|;
71 $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</th>\n|;
72 $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</th>\n|;
73 $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</th>\n|;
74 $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</th>\n|;
77 $form->{title} = $locale->text('Chart of Accounts');
79 $colspan = $#column_index + 1;
86 <table border=0 width=100%>
87 <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
89 <tr class=listheading>|;
91 map { print $column_header{$_} } @column_index;
98 foreach $ca (@{ $form->{CA} }) {
100 $description = $form->escape($ca->{description});
101 $gifi_description = $form->escape($ca->{gifi_description});
103 $href = qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
105 if ($ca->{charttype} eq "H") {
106 print qq|<tr class=listheading>|;
107 map { $column_data{$_} = "<th class=listheading>$ca->{$_}</th>"; } qw(accno description);
108 $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno} </th>";
111 print qq|<tr class=listrow$i>|;
112 $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
113 $column_data{gifi_accno} = "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a> </td>";
114 $column_data{description} = "<td>$ca->{description}</td>";
117 $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>\n";
118 $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>\n";
120 $totaldebit += $ca->{debit};
121 $totalcredit += $ca->{credit};
123 map { print $column_data{$_} } @column_index;
130 map { $column_data{$_} = "<td> </td>"; } qw(accno gifi_accno description);
132 $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</th>";
133 $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</th>";
135 print "<tr class=listtotal>";
137 map { print $column_data{$_} } @column_index;
142 <td colspan=$colspan><hr size=3 noshade></td>
155 $form->{title} = $locale->text('List Transactions');
156 if ($form->{accounttype} eq 'gifi') {
157 $form->{title} .= " - ".$locale->text('GIFI')." $form->{gifi_accno}";
159 $form->{title} .= " - ".$locale->text('Account')." $form->{accno}";
163 $form->all_departments(\%myconfig);
164 if (@{ $form->{all_departments} }) {
165 $form->{selectdepartment} = "<option>\n";
167 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
172 <th align=right nowrap>|.$locale->text('Department').qq|</th>
173 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
175 | if $form->{selectdepartment};
178 $form->{selectaccountingyear} = "<option>\n";
179 map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} };
180 $form->{selectaccountingmonth} = "<option>\n";
181 map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} };
185 <th align=right>|.$locale->text('Period').qq|</th>
187 <select name=month>$form->{selectaccountingmonth}</select>
188 <select name=year>$form->{selectaccountingyear}</select>
189 <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
190 <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
191 <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
192 <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
200 map { $form->{$_} = $form->quote($form->{$_}) } qw(description gifi_description);
205 <form method=post action=$form->{script}>
207 <input type=hidden name=accno value=$form->{accno}>
208 <input type=hidden name=description value="$form->{description}">
209 <input type=hidden name=sort value=transdate>
211 <input type=hidden name=accounttype value=$form->{accounttype}>
212 <input type=hidden name=gifi_accno value=$form->{gifi_accno}>
213 <input type=hidden name=gifi_description value="$form->{gifi_description}">
215 <table border=0 width=100%>
216 <tr><th class=listtop>$form->{title}</th></tr>
223 <th align=right>|.$locale->text('From').qq|</th>
224 <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
225 <th align=right>|.$locale->text('To').qq|</th>
226 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
230 <th align=right>|.$locale->text('Include in Report').qq|</th>
232 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
237 <tr><td><hr size=3 noshade></td></tr>
240 <input type=hidden name=login value=$form->{login}>
241 <input type=hidden name=path value=$form->{path}>
242 <input type=hidden name=sessionid value=$form->{sessionid}>
244 <br><input class=submit type=submit name=action value="|.$locale->text('List Transactions').qq|">
254 sub list_transactions {
256 CA->all_transactions(\%myconfig, \%$form);
258 $description = $form->escape($form->{description});
259 $gifi_description = $form->escape($form->{gifi_description});
260 $department = $form->escape($form->{department});
261 $projectnumber = $form->escape($form->{projectnumber});
262 $title = $form->escape($form->{title});
265 $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&title=$title";
269 $description = $form->escape($form->{description},1);
270 $gifi_description = $form->escape($form->{gifi_description},1);
271 $department = $form->escape($form->{department},1);
272 $projectnumber = $form->escape($form->{projectnumber},1);
273 $title = $form->escape($form->{title},1);
276 $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&title=$title";
278 # figure out which column comes first
279 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
280 $column_header{reference} = qq|<th><a class=listheading href=$href&sort=reference>|.$locale->text('Reference').qq|</a></th>|;
281 $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
282 $column_header{cleared} = qq|<th class=listheading>|.$locale->text('R').qq|</th>|;
283 $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
284 $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
285 $column_header{balance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
287 @column_index = $form->sort_columns(qw(transdate reference description debit credit));
289 if ($form->{link} =~ /_paid/) {
290 @column_index = $form->sort_columns(qw(transdate reference description cleared debit credit));
293 if ($form->{accounttype} eq 'gifi') {
294 map { $form->{$_} = $form->{"gifi_$_"} } qw(accno description);
296 if ($form->{accno}) {
297 push @column_index, "balance";
300 $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account');
302 $form->{title} .= " $form->{accno} - $form->{description}";
304 if ($form->{department}) {
305 ($department) = split /--/, $form->{department};
306 $options = $locale->text('Department')." : $department<br>";
308 if ($form->{projectnumber}) {
309 ($projectnumber) = split /--/, $form->{projectnumber};
310 $options .= $locale->text('Project Number')." : $projectnumber<br>";
313 if ($form->{fromdate} || $form->{todate}) {
314 if ($form->{fromdate}) {
315 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
317 if ($form->{todate}) {
318 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
321 $form->{period} = "$fromdate - $todate";
323 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig),1);
326 $options .= $form->{period};
335 <th class=listtop>$form->{title}</th>
344 <tr class=listheading>
347 map { print "$column_header{$_}\n" } @column_index;
353 # add sort to callback
354 $callback = $form->escape($callback . "&sort=$form->{sort}");
356 if (@{ $form->{CA} }) {
357 $sameitem = $form->{CA}->[0]->{$form->{sort}};
360 $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
361 if ($form->{accno} && $form->{balance}) {
363 map { $column_data{$_} = "<td> </td>" } @column_index;
365 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
371 map { print $column_data{$_} } @column_index;
377 foreach $ca (@{ $form->{CA} }) {
379 if ($form->{l_subtotal} eq 'Y') {
380 if ($sameitem ne $ca->{$form->{sort}}) {
385 # construct link to source
386 $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{reference}</a>";
389 $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>";
390 $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>";
392 $form->{balance} += $ca->{amount};
393 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
395 $subtotaldebit += $ca->{debit};
396 $subtotalcredit += $ca->{credit};
398 $totaldebit += $ca->{debit};
399 $totalcredit += $ca->{credit};
401 $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
402 $column_data{reference} = qq|<td>$href</td>|;
403 $column_data{description} = qq|<td>$ca->{description} </td>|;
405 $column_data{cleared} = ($ca->{cleared}) ? qq|<td>*</td>| : qq|<td> </td>|;
412 map { print $column_data{$_} } @column_index;
421 if ($form->{l_subtotal} eq 'Y') {
426 map { $column_data{$_} = "<td> </td>" } @column_index;
428 $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>";
429 $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>";
430 $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
436 map { print $column_data{$_} } @column_index;
444 <td><hr size=3 noshade></td>
457 map { $column_data{$_} = "<td> </td>" } @column_index;
459 $column_data{debit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotaldebit, 2, " ") . "</th>";
460 $column_data{credit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotalcredit, 2, " ") . "</th>";
465 $sameitem = $ca->{$form->{sort}};
468 <tr class=listsubtotal>
471 map { print "$column_data{$_}\n" } @column_index;