summaryrefslogtreecommitdiff
path: root/bin/lynx/ca.pl
blob: 8ea9980d94bf1846215a99aa615c6568dfc776b3 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2001
  4. #
  5. # Author: DWS Systems Inc.
  6. # Web: http://sourceforge.net/projects/ledger-smb/
  7. #
  8. # Contributors:
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #======================================================================
  23. #
  24. # module for Chart of Accounts, Income Statement and Balance Sheet
  25. # search and edit transactions posted by the GL, AR and AP
  26. #
  27. #======================================================================
  28. use SL::CA;
  29. 1;
  30. # end of main
  31. # this is for our long dates
  32. # $locale->text('January')
  33. # $locale->text('February')
  34. # $locale->text('March')
  35. # $locale->text('April')
  36. # $locale->text('May ')
  37. # $locale->text('June')
  38. # $locale->text('July')
  39. # $locale->text('August')
  40. # $locale->text('September')
  41. # $locale->text('October')
  42. # $locale->text('November')
  43. # $locale->text('December')
  44. # this is for our short month
  45. # $locale->text('Jan')
  46. # $locale->text('Feb')
  47. # $locale->text('Mar')
  48. # $locale->text('Apr')
  49. # $locale->text('May')
  50. # $locale->text('Jun')
  51. # $locale->text('Jul')
  52. # $locale->text('Aug')
  53. # $locale->text('Sep')
  54. # $locale->text('Oct')
  55. # $locale->text('Nov')
  56. # $locale->text('Dec')
  57. sub chart_of_accounts {
  58. CA->all_accounts(\%myconfig, \%$form);
  59. @column_index = qw(accno gifi_accno description debit credit);
  60. $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</th>\n|;
  61. $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</th>\n|;
  62. $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</th>\n|;
  63. $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</th>\n|;
  64. $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</th>\n|;
  65. $form->{title} = $locale->text('Chart of Accounts');
  66. $colspan = $#column_index + 1;
  67. $form->header;
  68. print qq|
  69. <body>
  70. <table border=0 width=100%>
  71. <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
  72. <tr height="5"></tr>
  73. <tr class=listheading>|;
  74. for (@column_index) { print $column_header{$_} }
  75. print qq|
  76. </tr>
  77. |;
  78. foreach $ca (@{ $form->{CA} }) {
  79. $description = $form->escape($ca->{description});
  80. $gifi_description = $form->escape($ca->{gifi_description});
  81. $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|;
  82. if ($ca->{charttype} eq "H") {
  83. print qq|<tr class=listheading>|;
  84. for (qw(accno description)) { $column_data{$_} = "<th class=listheading>$ca->{$_}</th>" }
  85. $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno}&nbsp;</th>";
  86. } else {
  87. $i++; $i %= 2;
  88. print qq|<tr class=listrow$i>|;
  89. $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
  90. $column_data{gifi_accno} = "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a>&nbsp;</td>";
  91. $column_data{description} = "<td>$ca->{description}</td>";
  92. }
  93. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;")."</td>\n";
  94. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;")."</td>\n";
  95. $totaldebit += $ca->{debit};
  96. $totalcredit += $ca->{credit};
  97. for (@column_index) { print "$column_data{$_}\n" }
  98. print qq|
  99. </tr>
  100. |;
  101. }
  102. for (qw(accno gifi_accno description)) { $column_data{$_} = "<td>&nbsp;</td>" }
  103. $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</th>";
  104. $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</th>";
  105. print "<tr class=listtotal>";
  106. for (@column_index) { print "$column_data{$_}\n" }
  107. print qq|
  108. </tr>
  109. <tr>
  110. <td colspan=$colspan><hr size=3 noshade></td>
  111. </tr>
  112. </table>
  113. </body>
  114. </html>
  115. |;
  116. }
  117. sub list {
  118. $form->{title} = $locale->text('List Transactions');
  119. if ($form->{accounttype} eq 'gifi') {
  120. $form->{title} .= " - ".$locale->text('GIFI')." $form->{gifi_accno} - $form->{gifi_description}";
  121. } else {
  122. $form->{title} .= " - ".$locale->text('Account')." $form->{accno} - $form->{description}";
  123. }
  124. # get departments
  125. $form->all_departments(\%myconfig);
  126. if (@{ $form->{all_department} }) {
  127. $form->{selectdepartment} = "<option>\n";
  128. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  129. }
  130. $department = qq|
  131. <tr>
  132. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  133. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  134. </tr>
  135. | if $form->{selectdepartment};
  136. if (@{ $form->{all_years} }) {
  137. # accounting years
  138. $form->{selectaccountingyear} = "<option>\n";
  139. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  140. $form->{selectaccountingmonth} = "<option>\n";
  141. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  142. $selectfrom = qq|
  143. <tr>
  144. <th align=right>|.$locale->text('Period').qq|</th>
  145. <td colspan=3>
  146. <select name=month>$form->{selectaccountingmonth}</select>
  147. <select name=year>$form->{selectaccountingyear}</select>
  148. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  149. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  150. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  151. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  152. </td>
  153. </tr>
  154. |;
  155. }
  156. $form->header;
  157. print qq|
  158. <body>
  159. <form method=post action=$form->{script}>
  160. <input type=hidden name=accno value=$form->{accno}>
  161. <input type=hidden name=description value="$form->{description}">
  162. <input type=hidden name=sort value=transdate>
  163. <input type=hidden name=oldsort value=transdate>
  164. <input type=hidden name=accounttype value=$form->{accounttype}>
  165. <input type=hidden name=gifi_accno value=$form->{gifi_accno}>
  166. <input type=hidden name=gifi_description value="$form->{gifi_description}">
  167. <table border=0 width=100%>
  168. <tr><th class=listtop>$form->{title}</th></tr>
  169. <tr height="5"></tr
  170. <tr valign=top>
  171. <td>
  172. <table>
  173. $department
  174. <tr>
  175. <th align=right>|.$locale->text('From').qq|</th>
  176. <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
  177. <th align=right>|.$locale->text('To').qq|</th>
  178. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  179. </tr>
  180. $selectfrom
  181. <tr>
  182. <th align=right>|.$locale->text('Include in Report').qq|</th>
  183. <td colspan=3>
  184. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('AR/AP').qq|
  185. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  186. </td>
  187. </tr>
  188. </table>
  189. </td>
  190. </tr>
  191. <tr><td><hr size=3 noshade></td></tr>
  192. </table>
  193. <input type=hidden name=login value=$form->{login}>
  194. <input type=hidden name=path value=$form->{path}>
  195. <input type=hidden name=sessionid value=$form->{sessionid}>
  196. <br><input class=submit type=submit name=action value="|.$locale->text('List Transactions').qq|">
  197. </form>
  198. </body>
  199. </html>
  200. |;
  201. }
  202. sub list_transactions {
  203. CA->all_transactions(\%myconfig, \%$form);
  204. $department = $form->escape($form->{department});
  205. $projectnumber = $form->escape($form->{projectnumber});
  206. $title = $form->escape($form->{title});
  207. # construct href
  208. $href = "$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
  209. for (qw(path oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno)) { $href .= "&$_=$form->{$_}" }
  210. $drilldown = $href;
  211. $drilldown .= "&sort=$form->{sort}";
  212. $href .= "&direction=$form->{direction}";
  213. $form->sort_order();
  214. $drilldown .= "&direction=$form->{direction}";
  215. $form->{prevreport} = $href unless $form->{prevreport};
  216. $href .= "&prevreport=".$form->escape($form->{prevreport});
  217. $drilldown .= "&prevreport=".$form->escape($form->{prevreport});
  218. # figure out which column comes first
  219. $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
  220. $column_header{reference} = qq|<th><a class=listheading href=$href&sort=reference>|.$locale->text('Reference').qq|</a></th>|;
  221. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  222. $column_header{cleared} = qq|<th class=listheading>|.$locale->text('R').qq|</th>|;
  223. $column_header{source} = qq|<th class=listheading>|.$locale->text('Source').qq|</th>|;
  224. $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
  225. $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
  226. $column_header{balance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
  227. $column_header{accno} = qq|<th class=listheading>|.$locale->text('AR/AP').qq|</th>|;
  228. @columns = qw(transdate reference description debit credit);
  229. if ($form->{link} =~ /_paid/) {
  230. @columns = qw(transdate reference description source cleared debit credit);
  231. }
  232. push @columns, "accno" if $form->{l_accno};
  233. @column_index = $form->sort_columns(@columns);
  234. if ($form->{accounttype} eq 'gifi') {
  235. for (qw(accno description)) { $form->{$_} = $form->{"gifi_$_"} }
  236. }
  237. if ($form->{accno}) {
  238. push @column_index, "balance";
  239. }
  240. $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account');
  241. $form->{title} .= " $form->{accno} - $form->{description}";
  242. if ($form->{department}) {
  243. ($department) = split /--/, $form->{department};
  244. $options = $locale->text('Department')." : $department<br>";
  245. }
  246. if ($form->{projectnumber}) {
  247. ($projectnumber) = split /--/, $form->{projectnumber};
  248. $options .= $locale->text('Project Number')." : $projectnumber<br>";
  249. }
  250. if ($form->{fromdate} || $form->{todate}) {
  251. if ($form->{fromdate}) {
  252. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  253. }
  254. if ($form->{todate}) {
  255. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  256. }
  257. $form->{period} = "$fromdate - $todate";
  258. } else {
  259. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  260. }
  261. $form->{period} = "<a href=$form->{prevreport}>$form->{period}</a>" if $form->{prevreport};
  262. $options .= $form->{period};
  263. # construct callback
  264. $department = $form->escape($form->{department},1);
  265. $projectnumber = $form->escape($form->{projectnumber},1);
  266. $title = $form->escape($form->{title},1);
  267. $form->{prevreport} = $form->escape($form->{prevreport},1);
  268. $form->{callback} = "$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
  269. for (qw(path direction oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno prevreport)) { $form->{callback} .= "&$_=$form->{$_}" }
  270. $form->header;
  271. print qq|
  272. <body>
  273. <table width=100%>
  274. <tr>
  275. <th class=listtop>$form->{title}</th>
  276. </tr>
  277. <tr height="5"></tr>
  278. <tr>
  279. <td>$options</td>
  280. </tr>
  281. <tr>
  282. <td>
  283. <table width=100%>
  284. <tr class=listheading>
  285. |;
  286. for (@column_index) { print "$column_header{$_}\n" }
  287. print qq|
  288. </tr>
  289. |;
  290. # add sort to callback
  291. $form->{callback} = $form->escape($form->{callback} . "&sort=$form->{sort}");
  292. if (@{ $form->{CA} }) {
  293. $sameitem = $form->{CA}->[0]->{$form->{sort}};
  294. }
  295. $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
  296. $ml *= -1 if $form->{contra};
  297. if ($form->{accno} && $form->{balance}) {
  298. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  299. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
  300. $i++; $i %= 2;
  301. print qq|
  302. <tr class=listrow$i>
  303. |;
  304. for (@column_index) { print "$column_data{$_}\n" }
  305. print qq|
  306. </tr>
  307. |;
  308. }
  309. foreach $ca (@{ $form->{CA} }) {
  310. if ($form->{l_subtotal} eq 'Y') {
  311. if ($sameitem ne $ca->{$form->{sort}}) {
  312. &ca_subtotal;
  313. }
  314. }
  315. # construct link to source
  316. $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$form->{callback}>$ca->{reference}</a>";
  317. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;")."</td>";
  318. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;")."</td>";
  319. $form->{balance} += $ca->{amount};
  320. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
  321. $subtotaldebit += $ca->{debit};
  322. $subtotalcredit += $ca->{credit};
  323. $totaldebit += $ca->{debit};
  324. $totalcredit += $ca->{credit};
  325. $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
  326. $column_data{reference} = qq|<td>$href</td>|;
  327. $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
  328. $column_data{cleared} = ($ca->{cleared}) ? qq|<td>*</td>| : qq|<td>&nbsp;</td>|;
  329. $column_data{source} = qq|<td>$ca->{source}&nbsp;</td>|;
  330. $column_data{accno} = qq|<td>|;
  331. for (@{ $ca->{accno} }) { $column_data{accno} .= "<a href=$drilldown&accno=$_>$_</a> " }
  332. $column_data{accno} .= qq|&nbsp;</td>|;
  333. if ($ca->{id} != $sameid) {
  334. $i++; $i %= 2;
  335. }
  336. $sameid = $ca->{id};
  337. print qq|
  338. <tr class=listrow$i>
  339. |;
  340. for (@column_index) { print "$column_data{$_}\n" }
  341. print qq|
  342. </tr>
  343. |;
  344. }
  345. if ($form->{l_subtotal} eq 'Y') {
  346. &ca_subtotal;
  347. }
  348. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  349. $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
  350. $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
  351. $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
  352. print qq|
  353. <tr class=listtotal>
  354. |;
  355. for (@column_index) { print "$column_data{$_}\n" }
  356. print qq|
  357. </tr>
  358. </table>
  359. </td>
  360. </tr>
  361. <tr>
  362. <td><hr size=3 noshade></td>
  363. </tr>
  364. </table>
  365. </body>
  366. </html>
  367. |;
  368. }
  369. sub ca_subtotal {
  370. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  371. $column_data{debit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;") . "</th>";
  372. $column_data{credit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;") . "</th>";
  373. $subtotaldebit = 0;
  374. $subtotalcredit = 0;
  375. $sameitem = $ca->{$form->{sort}};
  376. print qq|
  377. <tr class=listsubtotal>
  378. |;
  379. for (@column_index) { print "$column_data{$_}\n" }
  380. print qq|
  381. </tr>
  382. |;
  383. }