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