summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: 900b47bedc0b4f3a2f94522e8a01420fb0016a5e (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2001
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
  22. # Benjamin Lee <benjaminlee@consultant.com>
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # module for preparing Income Statement and Balance Sheet
  40. #
  41. #======================================================================
  42. use Error qw(:try);
  43. require "bin/arap.pl";
  44. use LedgerSMB::Template;
  45. use LedgerSMB::PE;
  46. use LedgerSMB::RP;
  47. 1;
  48. # end of main
  49. # this is for our long dates
  50. # $locale->text('January')
  51. # $locale->text('February')
  52. # $locale->text('March')
  53. # $locale->text('April')
  54. # $locale->text('May ')
  55. # $locale->text('June')
  56. # $locale->text('July')
  57. # $locale->text('August')
  58. # $locale->text('September')
  59. # $locale->text('October')
  60. # $locale->text('November')
  61. # $locale->text('December')
  62. # this is for our short month
  63. # $locale->text('Jan')
  64. # $locale->text('Feb')
  65. # $locale->text('Mar')
  66. # $locale->text('Apr')
  67. # $locale->text('May')
  68. # $locale->text('Jun')
  69. # $locale->text('Jul')
  70. # $locale->text('Aug')
  71. # $locale->text('Sep')
  72. # $locale->text('Oct')
  73. # $locale->text('Nov')
  74. # $locale->text('Dec')
  75. # $locale->text('Balance Sheet')
  76. # $locale->text('Income Statement')
  77. # $locale->text('Trial Balance')
  78. # $locale->text('AR Aging')
  79. # $locale->text('AP Aging')
  80. # $locale->text('Tax collected')
  81. # $locale->text('Tax paid')
  82. # $locale->text('Receipts')
  83. # $locale->text('Payments')
  84. # $locale->text('Project Transactions')
  85. # $locale->text('Non-taxable Sales')
  86. # $locale->text('Non-taxable Purchases')
  87. sub report {
  88. %report = (
  89. balance_sheet => { title => 'Balance Sheet' },
  90. income_statement => { title => 'Income Statement' },
  91. trial_balance => { title => 'Trial Balance' },
  92. ar_aging => { title => 'AR Aging', vc => 'customer' },
  93. ap_aging => { title => 'AP Aging', vc => 'vendor' },
  94. tax_collected => { title => 'Tax collected', vc => 'customer' },
  95. tax_paid => { title => 'Tax paid' },
  96. nontaxable_sales => { title => 'Non-taxable Sales', vc => 'customer' },
  97. nontaxable_purchases => { title => 'Non-taxable Purchases' },
  98. receipts => { title => 'Receipts', vc => 'customer' },
  99. payments => { title => 'Payments' },
  100. projects => { title => 'Project Transactions' },
  101. inv_activity => { title => 'Inventory Activity' },
  102. );
  103. $form->{title} = $locale->text( $report{ $form->{report} }->{title} );
  104. $gifi = qq|
  105. <tr>
  106. <th align=right>| . $locale->text('Accounts') . qq|</th>
  107. <td><input name=accounttype class=radio type=radio value=standard checked> |
  108. . $locale->text('Standard') . qq|
  109. <input name=accounttype class=radio type=radio value=gifi> |
  110. . $locale->text('GIFI') . qq|
  111. </td>
  112. </tr>
  113. |;
  114. # get departments
  115. $form->all_departments( \%myconfig, undef,
  116. $report{ $form->{report} }->{vc} );
  117. if ( @{ $form->{all_department} } ) {
  118. $form->{selectdepartment} = "<option>\n";
  119. for ( @{ $form->{all_department} } ) {
  120. $form->{selectdepartment} .=
  121. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  122. }
  123. }
  124. $department = qq|
  125. <tr>
  126. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  127. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  128. </tr>
  129. | if $form->{selectdepartment};
  130. if ( @{ $form->{all_years} } ) {
  131. # accounting years
  132. $form->{selectaccountingyear} = "<option>\n";
  133. for ( @{ $form->{all_years} } ) {
  134. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  135. }
  136. $form->{selectaccountingmonth} = "<option>\n";
  137. for ( sort keys %{ $form->{all_month} } ) {
  138. $form->{selectaccountingmonth} .=
  139. qq|<option value=$_>|
  140. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  141. }
  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;|
  149. . $locale->text('Current') . qq|
  150. <input name=interval class=radio type=radio value=1>&nbsp;|
  151. . $locale->text('Month') . qq|
  152. <input name=interval class=radio type=radio value=3>&nbsp;|
  153. . $locale->text('Quarter') . qq|
  154. <input name=interval class=radio type=radio value=12>&nbsp;|
  155. . $locale->text('Year') . qq|
  156. </td>
  157. </tr>
  158. |;
  159. $selectto = qq|
  160. <tr>
  161. <th align=right></th>
  162. <td>
  163. <select name=month>$form->{selectaccountingmonth}</select>
  164. <select name=year>$form->{selectaccountingyear}</select>
  165. </td>
  166. </tr>
  167. |;
  168. }
  169. $summary = qq|
  170. <tr>
  171. <th></th>
  172. <td><input name=summary type=radio class=radio value=1 checked> |
  173. . $locale->text('Summary') . qq|
  174. <input name=summary type=radio class=radio value=0> |
  175. . $locale->text('Detail') . qq|
  176. </td>
  177. </tr>
  178. |;
  179. # get projects
  180. $form->all_projects( \%myconfig );
  181. if ( @{ $form->{all_project} } ) {
  182. $form->{selectproject} = "<option>\n";
  183. for ( @{ $form->{all_project} } ) {
  184. $form->{selectproject} .=
  185. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  186. }
  187. $project = qq|
  188. <tr>
  189. <th align=right nowrap>| . $locale->text('Project') . qq|</th>
  190. <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
  191. </tr>|;
  192. }
  193. $form->header;
  194. print qq|
  195. <body>
  196. <form method=post action=$form->{script}>
  197. <input type=hidden name=title value="$form->{title}">
  198. <table width=100%>
  199. <tr>
  200. <th class=listtop>$form->{title}</th>
  201. </tr>
  202. <tr height="5"></tr>
  203. <tr>
  204. <td>
  205. <table>
  206. $department
  207. |;
  208. if ( $form->{report} eq "projects" ) {
  209. print qq|
  210. $project
  211. <input type=hidden name=nextsub value=generate_projects>
  212. <tr>
  213. <th align=right>| . $locale->text('From') . qq|</th>
  214. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  215. <th align=right>| . $locale->text('To') . qq|</th>
  216. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  217. </tr>
  218. $selectfrom
  219. </table>
  220. </td>
  221. </tr>
  222. <tr>
  223. <td>
  224. <table>
  225. <tr>
  226. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  227. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
  228. . $locale->text('Heading') . qq|
  229. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
  230. . $locale->text('Subtotal')
  231. . qq|</td>
  232. </tr>
  233. |;
  234. }
  235. if ( $form->{report} eq "inv_activity" ) {
  236. $gifi = '';
  237. print qq|
  238. <input type=hidden name=nextsub value=generate_inv_activity>
  239. <tr>
  240. <th align=right>| . $locale->text('From') . qq|</th>
  241. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  242. <th align=right>| . $locale->text('To') . qq|</th>
  243. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  244. </tr>
  245. <tr>
  246. <th align=right>| . $locale->text('Period') . qq|</th>
  247. <td colspan=3>
  248. <select name=frommonth>$form->{selectaccountingmonth}</select>
  249. <select name=fromyear>$form->{selectaccountingyear}</select>
  250. <input name=interval class=radio type=radio value=0 checked>|
  251. . $locale->text('Current') . qq|
  252. <input name=interval class=radio type=radio value=1>|
  253. . $locale->text('Month') . qq|
  254. <input name=interval class=radio type=radio value=3>|
  255. . $locale->text('Quarter') . qq|
  256. <input name=interval class=radio type=radio value=12>|
  257. . $locale->text('Year') . qq|
  258. </td>
  259. </tr>
  260. </table>
  261. <table>
  262. <tr>
  263. <th>| . $locale->text("Part Number") . qq|</th>
  264. <td><input name=partnumber></td>
  265. <th>| . $locale->text('Description') . qq|</th>
  266. <td><input type=text name=description></td>
  267. </tr>|;
  268. }
  269. if ( $form->{report} eq "income_statement" ) {
  270. print qq|
  271. $project
  272. <input type=hidden name=nextsub value=generate_income_statement>
  273. <tr>
  274. <th align=right>| . $locale->text('From') . qq|</th>
  275. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  276. <th align=right>| . $locale->text('To') . qq|</th>
  277. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  278. </tr>
  279. |;
  280. if ($selectfrom) {
  281. print qq|
  282. <tr>
  283. <th align=right>| . $locale->text('Period') . qq|</th>
  284. <td colspan=3>
  285. <select name=frommonth>$form->{selectaccountingmonth}</select>
  286. <select name=fromyear>$form->{selectaccountingyear}</select>
  287. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  288. . $locale->text('Current') . qq|
  289. <input name=interval class=radio type=radio value=1>&nbsp;|
  290. . $locale->text('Month') . qq|
  291. <input name=interval class=radio type=radio value=3>&nbsp;|
  292. . $locale->text('Quarter') . qq|
  293. <input name=interval class=radio type=radio value=12>&nbsp;|
  294. . $locale->text('Year') . qq|
  295. </td>
  296. </tr>
  297. |;
  298. }
  299. print qq|
  300. <tr>
  301. <th align=right>| . $locale->text('Compare to') . qq|</th>
  302. </tr>
  303. <tr>
  304. <th align=right>| . $locale->text('From') . qq|</th>
  305. <td><input class="date" name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
  306. <th align=right>| . $locale->text('To') . qq|</th>
  307. <td><input class="date" name=comparetodate size=11 title="$myconfig{dateformat}"></td>
  308. </tr>
  309. |;
  310. if ($selectto) {
  311. print qq|
  312. <tr>
  313. <th align=right>| . $locale->text('Period') . qq|</th>
  314. <td>
  315. <select name=comparemonth>$form->{selectaccountingmonth}</select>
  316. <select name=compareyear>$form->{selectaccountingyear}</select>
  317. </td>
  318. </tr>
  319. |;
  320. }
  321. print qq|
  322. <tr>
  323. <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
  324. <td><input name=decimalplaces size=3 value=2></td>
  325. </tr>
  326. </table>
  327. </td>
  328. </tr>
  329. <tr>
  330. <td>
  331. <table>
  332. <tr>
  333. <th align=right>| . $locale->text('Method') . qq|</th>
  334. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|
  335. . $locale->text('Accrual') . qq|
  336. &nbsp;<input name=method class=radio type=radio value=cash>|
  337. . $locale->text('Cash')
  338. . qq|</td>
  339. </tr>
  340. <tr>
  341. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  342. <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
  343. . $locale->text('Heading') . qq|
  344. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
  345. . $locale->text('Subtotal') . qq|
  346. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|
  347. . $locale->text('Account Number')
  348. . qq|</td>
  349. </tr>
  350. |;
  351. }
  352. if ( $form->{report} eq "balance_sheet" ) {
  353. print qq|
  354. <input type=hidden name=nextsub value=generate_balance_sheet>
  355. <tr>
  356. <th align=right>| . $locale->text('as at') . qq|</th>
  357. <td><input class="date" name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
  358. |;
  359. if ($selectfrom) {
  360. print qq|
  361. <td>
  362. <select name=asofmonth>$form->{selectaccountingmonth}</select>
  363. <select name=asofyear>$form->{selectaccountingyear}</select>
  364. </td>
  365. |;
  366. }
  367. print qq|
  368. </tr>
  369. <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
  370. <td><input class="date" name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
  371. <td>
  372. |;
  373. if ($selectto) {
  374. print qq|
  375. <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
  376. <select name=compareasofyear>$form->{selectaccountingyear}</select>
  377. </td>
  378. |;
  379. }
  380. print qq|
  381. </tr>
  382. <tr>
  383. <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
  384. <td><input name=decimalplaces size=3 value=2></td>
  385. </tr>
  386. </table>
  387. </td>
  388. </tr>
  389. <tr>
  390. <td>
  391. <table>
  392. <tr>
  393. <th align=right>| . $locale->text('Method') . qq|</th>
  394. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|
  395. . $locale->text('Accrual') . qq|
  396. &nbsp;<input name=method class=radio type=radio value=cash>|
  397. . $locale->text('Cash')
  398. . qq|</td>
  399. </tr>
  400. <tr>
  401. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  402. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
  403. . $locale->text('Heading') . qq|
  404. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
  405. . $locale->text('Subtotal') . qq|
  406. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|
  407. . $locale->text('Account Number')
  408. . qq|</td>
  409. </tr>
  410. |;
  411. }
  412. if ( $form->{report} eq "trial_balance" ) {
  413. print qq|
  414. <input type=hidden name=nextsub value=generate_trial_balance>
  415. <tr>
  416. <th align=right>| . $locale->text('From') . qq|</th>
  417. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  418. <th align=right>| . $locale->text('To') . qq|</th>
  419. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  420. </tr>
  421. $selectfrom
  422. </table>
  423. </td>
  424. </tr>
  425. <tr>
  426. <td>
  427. <table>
  428. <tr>
  429. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  430. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
  431. . $locale->text('Heading') . qq|
  432. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
  433. . $locale->text('Subtotal') . qq|
  434. <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|
  435. . $locale->text('All Accounts')
  436. . qq|</td>
  437. </tr>
  438. |;
  439. }
  440. if ( $form->{report} =~ /^tax_/ ) {
  441. $gifi = "";
  442. $form->{db} = ( $form->{report} =~ /_collected/ ) ? "ar" : "ap";
  443. RP->get_taxaccounts( \%myconfig, \%$form );
  444. print qq|
  445. <input type=hidden name=nextsub value=generate_tax_report>
  446. <tr>
  447. <th align=right>| . $locale->text('From') . qq|</th>
  448. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  449. <th align=right>| . $locale->text('To') . qq|</th>
  450. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  451. </tr>
  452. $selectfrom
  453. $summary
  454. <tr>
  455. <th align=right>| . $locale->text('Report for') . qq|</th>
  456. <td colspan=3>
  457. |;
  458. $checked = "checked";
  459. foreach $ref ( @{ $form->{taxaccounts} } ) {
  460. print
  461. qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
  462. <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
  463. <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  464. $checked = "";
  465. }
  466. print qq|
  467. <input type=hidden name=db value=$form->{db}>
  468. <input type=hidden name=sort value=transdate>
  469. </td>
  470. </tr>
  471. |;
  472. if ( @{ $form->{gifi_taxaccounts} } ) {
  473. print qq|
  474. <tr>
  475. <th align=right>| . $locale->text('GIFI') . qq|</th>
  476. <td colspan=3>
  477. |;
  478. foreach $ref ( @{ $form->{gifi_taxaccounts} } ) {
  479. print
  480. qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
  481. <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
  482. <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  483. }
  484. print qq|
  485. </td>
  486. </tr>
  487. |;
  488. }
  489. print qq|
  490. <tr>
  491. <th align=right>| . $locale->text('Method') . qq|</th>
  492. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|
  493. . $locale->text('Accrual') . qq|
  494. &nbsp;<input name=method class=radio type=radio value=cash>|
  495. . $locale->text('Cash')
  496. . qq|</td>
  497. </tr>
  498. </table>
  499. </td>
  500. </tr>
  501. <tr>
  502. <td>
  503. <table>
  504. <tr>
  505. <th align=right>| . $locale->text('Include in Report') . qq|</th>
  506. <td>
  507. <table>
  508. <tr>
  509. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  510. <td>| . $locale->text('ID') . qq|</td>
  511. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  512. <td>| . $locale->text('Invoice') . qq|</td>
  513. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  514. <td>| . $locale->text('Date') . qq|</td>
  515. </tr>
  516. <tr>
  517. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  518. |;
  519. if ( $form->{db} eq 'ar' ) {
  520. print qq|<td>| . $locale->text('Customer') . qq|</td>|;
  521. }
  522. if ( $form->{db} eq 'ap' ) {
  523. print qq|<td>| . $locale->text('Vendor') . qq|</td>|;
  524. }
  525. print qq|
  526. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  527. <td>| . $locale->text('Description') . qq|</td>
  528. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  529. <td>| . $locale->text('Amount') . qq|</td>
  530. <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
  531. <td>| . $locale->text('Tax') . qq|</td>
  532. <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
  533. <td>| . $locale->text('Total') . qq|</td>
  534. </tr>
  535. <tr>
  536. </tr>
  537. <tr>
  538. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  539. <td>| . $locale->text('Subtotal') . qq|</td>
  540. </tr>
  541. </table>
  542. </td>
  543. </tr>
  544. |;
  545. }
  546. if ( $form->{report} =~ /^nontaxable_/ ) {
  547. $gifi = "";
  548. $form->{db} = ( $form->{report} =~ /_sales/ ) ? "ar" : "ap";
  549. print qq|
  550. <input type=hidden name=nextsub value=generate_tax_report>
  551. <input type=hidden name=db value=$form->{db}>
  552. <input type=hidden name=sort value=transdate>
  553. <input type=hidden name=report value=$form->{report}>
  554. <tr>
  555. <th align=right>| . $locale->text('From') . qq|</th>
  556. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  557. <th align=right>| . $locale->text('To') . qq|</th>
  558. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  559. </tr>
  560. $selectfrom
  561. $summary
  562. <tr>
  563. <th align=right>| . $locale->text('Method') . qq|</th>
  564. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|
  565. . $locale->text('Accrual') . qq|
  566. &nbsp;<input name=method class=radio type=radio value=cash>|
  567. . $locale->text('Cash')
  568. . qq|</td>
  569. </tr>
  570. <tr>
  571. <th align=right>| . $locale->text('Include in Report') . qq|</th>
  572. <td colspan=3>
  573. <table>
  574. <tr>
  575. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  576. <td>| . $locale->text('ID') . qq|</td>
  577. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  578. <td>| . $locale->text('Invoice') . qq|</td>
  579. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  580. <td>| . $locale->text('Date') . qq|</td>
  581. </tr>
  582. <tr>
  583. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  584. |;
  585. if ( $form->{db} eq 'ar' ) {
  586. print qq|<td>| . $locale->text('Customer') . qq|</td>|;
  587. }
  588. if ( $form->{db} eq 'ap' ) {
  589. print qq|<td>| . $locale->text('Vendor') . qq|</td>|;
  590. }
  591. print qq|
  592. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  593. <td>| . $locale->text('Description') . qq|</td>
  594. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  595. <td>| . $locale->text('Amount') . qq|</td>
  596. </tr>
  597. <tr>
  598. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  599. <td>| . $locale->text('Subtotal') . qq|</td>
  600. </tr>
  601. </table>
  602. </td>
  603. </tr>
  604. |;
  605. }
  606. if ( ( $form->{report} eq "ar_aging" )
  607. || ( $form->{report} eq "ap_aging" ) )
  608. {
  609. $gifi = "";
  610. if ( $form->{report} eq 'ar_aging' ) {
  611. $label = $locale->text('Customer');
  612. $form->{vc} = 'customer';
  613. }
  614. else {
  615. $label = $locale->text('Vendor');
  616. $form->{vc} = 'vendor';
  617. }
  618. $nextsub = "generate_$form->{report}";
  619. # setup vc selection
  620. $form->all_vc( \%myconfig, $form->{vc},
  621. ( $form->{vc} eq 'customer' ) ? "AR" : "AP" );
  622. for ( @{ $form->{"all_$form->{vc}"} } ) {
  623. $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  624. }
  625. $vc =
  626. ($vc)
  627. ? qq|<select name=$form->{vc}><option>\n$vc</select>|
  628. : qq|<input name=$form->{vc} size=35>|;
  629. $postscript = "ps" if $myconfig{printer};
  630. print qq|
  631. <tr>
  632. <th align=right>| . $locale->text($label) . qq|</th>
  633. <td>$vc</td>
  634. </tr>
  635. <tr>
  636. <th align=right>| . $locale->text('To') . qq|</th>
  637. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  638. </tr>
  639. $selectto
  640. <input type=hidden name=type value=statement>
  641. <input type=hidden name=format value=$postscript>
  642. <input type=hidden name=media value="$myconfig{printer}">
  643. <input type=hidden name=nextsub value=$nextsub>
  644. <input type=hidden name=action value=$nextsub>
  645. $summary
  646. <tr>
  647. <table>
  648. <tr>
  649. <th>| . $locale->text('Include in Report') . qq|</th>
  650. <td>
  651. <table>
  652. <tr>
  653. <td nowrap><input name=overdue type=radio class=radio value=0 checked> |
  654. . $locale->text('Aged')
  655. . qq|</td>
  656. <td nowrap><input name=overdue type=radio class=radio value=1> |
  657. . $locale->text('Overdue')
  658. . qq|</td>
  659. </tr>
  660. <tr>
  661. <td nowrap width=70><input name=c0 type=checkbox class=checkbox value=1 checked> |
  662. . $locale->text('Current')
  663. . qq|</td>
  664. <td nowrap width=70><input name=c30 type=checkbox class=checkbox value=1 checked> 30</td>
  665. <td nowrap width=70><input name=c60 type=checkbox class=checkbox value=1 checked> 60</td>
  666. <td nowrap width=70><input name=c90 type=checkbox class=checkbox value=1 checked> 90</td>
  667. </td>
  668. </tr>
  669. </table>
  670. </td>
  671. </tr>
  672. </table>
  673. </tr>
  674. |;
  675. }
  676. # above action can be removed if there is more than one input field
  677. if ( $form->{report} =~ /(receipts|payments)$/ ) {
  678. $gifi = "";
  679. $form->{db} = ( $form->{report} =~ /payments$/ ) ? "ap" : "ar";
  680. RP->paymentaccounts( \%myconfig, \%$form );
  681. $selection = "<option>\n";
  682. foreach $ref ( @{ $form->{PR} } ) {
  683. $paymentaccounts .= "$ref->{accno} ";
  684. $selection .= "<option>$ref->{accno}--$ref->{description}\n";
  685. }
  686. chop $paymentaccounts;
  687. print qq|
  688. <input type=hidden name=nextsub value=list_payments>
  689. <tr>
  690. <th align=right nowrap>| . $locale->text('Account') . qq|</th>
  691. <td colspan=3><select name=account>$selection</select>
  692. <input type=hidden name=paymentaccounts value="$paymentaccounts">
  693. </td>
  694. </tr>
  695. <tr>
  696. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  697. <td colspan=3><input name=description size=35></td>
  698. </tr>
  699. <tr>
  700. <th align=right nowrap>| . $locale->text('Source') . qq|</th>
  701. <td colspan=3><input name=source></td>
  702. </tr>
  703. <tr>
  704. <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
  705. <td colspan=3><input name=memo size=30></td>
  706. </tr>
  707. <tr>
  708. <th align=right>| . $locale->text('From') . qq|</th>
  709. <td><input class="date" name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  710. <th align=right>| . $locale->text('To') . qq|</th>
  711. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}"></td>
  712. </tr>
  713. $selectfrom
  714. <tr>
  715. <td align=right><input type=checkbox class=checkbox name=fx_transaction value=1 checked></td>
  716. <td colspan=3>|
  717. . $locale->text('Include Exchange Rate Difference')
  718. . qq|</td>
  719. </tr>
  720. <tr>
  721. <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
  722. <td align=left colspan=3>| . $locale->text('Subtotal') . qq|</th>
  723. </tr>
  724. <input type=hidden name=db value=$form->{db}>
  725. <input type=hidden name=sort value=transdate>
  726. |;
  727. }
  728. $form->{login} = 'test';
  729. print qq|
  730. $gifi
  731. </table>
  732. </td>
  733. </tr>
  734. <tr>
  735. <td><hr size=3 noshade></td>
  736. </tr>
  737. </table>
  738. <br>
  739. <input type="hidden" name="path" value="$form->{path}">
  740. <input type="hidden" name="login" value="$form->{login}">
  741. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  742. <button type="submit" class="submit" name="action" value="continue">|
  743. . $locale->text('Continue')
  744. . qq|</button>
  745. </form>
  746. |;
  747. if ( $form->{lynx} ) {
  748. require "bin/menu.pl";
  749. &menubar;
  750. }
  751. print qq|
  752. </body>
  753. </html>
  754. |;
  755. }
  756. sub continue { &{ $form->{nextsub} } }
  757. sub generate_inv_activity {
  758. my %hiddens;
  759. my @options;
  760. my $title = $form->{title};
  761. RP->inventory_activity( \%myconfig, \%$form );
  762. # if ($form->{department}) {
  763. # ($department) = split /--/, $form->{department};
  764. # $options = $locale->text('Department')." : $department<br>";
  765. # $department = $form->escape($form->{department});
  766. # }
  767. ## if ($form->{projectnumber}) {
  768. # ($projectnumber) = split /--/, $form->{projectnumber};
  769. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  770. # $projectnumber = $form->escape($form->{projectnumber});
  771. # }
  772. # if there are any dates
  773. if ( $form->{fromdate} || $form->{todate} ) {
  774. if ( $form->{fromdate} ) {
  775. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  776. }
  777. if ( $form->{todate} ) {
  778. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  779. }
  780. $form->{period} = "$fromdate - $todate";
  781. } else {
  782. $form->{period} =
  783. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  784. }
  785. push @options, $form->{period};
  786. my @column_index = qw(partnumber description sold revenue received expense);
  787. my $href =
  788. qq|rp.pl?path=$form->{path}&action=continue&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
  789. my %column_header;
  790. $column_header{partnumber} = {
  791. text => $locale->text('Part Number'),
  792. href => "$href&sort_col=partnumber",
  793. };
  794. $column_header{description} = {
  795. text => $locale->text('Description'),
  796. href => "$href&sort_col=description",
  797. };
  798. $column_header{sold} = {
  799. text => $locale->text('Sold'),
  800. href => "$href&sort_col=sold",
  801. };
  802. $column_header{revenue} = {
  803. text => $locale->text('Revenue'),
  804. href => "$href&sort_col=revenue",
  805. };
  806. $column_header{received} = {
  807. text => $locale->text('Received'),
  808. href => "$href&sort_col=received",
  809. };
  810. $column_header{expense} = {
  811. text => $locale->text('Expense'),
  812. href => "$href&sort_col=expense",
  813. };
  814. if ( $form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue' ) {
  815. $form->{sort_type} = 'numeric';
  816. }
  817. my $i = 0;
  818. my $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  819. my $dates =
  820. "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  821. my $base =
  822. "path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  823. $form->{callback} = "rp.pl?action=continue&$base";
  824. $form->{callback} = $form->escape( $form->{callback} );
  825. $callback = "callback=$form->{callback}";
  826. # sort the whole thing by account numbers and display
  827. my @rows;
  828. foreach my $ref ( @{ $form->{TB} } ) {
  829. my $description = $form->escape( $ref->{description} );
  830. my %column_data;
  831. $i = $i % 2;
  832. $column_data{i} = $i;
  833. $pnumhref =
  834. "ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  835. $soldhref =
  836. "ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  837. $rechref =
  838. "ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  839. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  840. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, " " );
  841. $credit =
  842. $form->format_amount( \%myconfig, $ref->{credit}, 2, " " );
  843. $begbalance =
  844. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2, " " );
  845. $endbalance =
  846. $form->format_amount( \%myconfig,
  847. ( $ref->{balance} + $ref->{amount} ) * $ml,
  848. 2, " " );
  849. $column_data{partnumber} = {
  850. text => $ref->{partnumber},
  851. href => $pnumhref,
  852. };
  853. $column_data{sold} = {
  854. text => $ref->{sold},
  855. href => $soldhref,
  856. };
  857. $column_data{received} = {
  858. text => $ref->{received},
  859. href => $rechref,
  860. };
  861. push @rows, \%column_data;
  862. ++$i;
  863. }
  864. my $template = LedgerSMB::Template->new_UI(
  865. user => \%myconfig,
  866. locale => $locale,
  867. template => 'form-dynatable',
  868. );
  869. $template->render({
  870. form => $form,
  871. hiddens => \%hiddens,
  872. options => \@options,
  873. columns => \@column_index,
  874. heading => \%column_header,
  875. rows => \@rows,
  876. row_alignment => {
  877. sold => 'right',
  878. revenue => 'right',
  879. received => 'right',
  880. expense => 'right',
  881. },
  882. });
  883. }
  884. sub generate_income_statement {
  885. RP->income_statement( \%myconfig, \%$form );
  886. ( $form->{department} ) = split /--/, $form->{department};
  887. ( $form->{projectnumber} ) = split /--/, $form->{projectnumber};
  888. $form->{period} =
  889. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  890. $form->{todate} = $form->current_date( \%myconfig ) unless $form->{todate};
  891. # if there are any dates construct a where
  892. unless ( $form->{todate} ) {
  893. $form->{todate} = $form->current_date( \%myconfig );
  894. }
  895. $longtodate = $locale->date( \%myconfig, $form->{todate}, 1 );
  896. $shorttodate = $locale->date( \%myconfig, $form->{todate}, 0 );
  897. $longfromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  898. $shortfromdate = $locale->date( \%myconfig, $form->{fromdate}, 0 );
  899. $form->{this_period_from} = $shortfromdate;
  900. $form->{this_period_to} = $shorttodate;
  901. # example output: 2006-01-01 To 2007-01-01
  902. $form->{period} = $locale->text('[_1] To [_2]', $longfromdate, $longtodate);
  903. if ( $form->{comparefromdate} || $form->{comparetodate} ) {
  904. $longcomparefromdate =
  905. $locale->date( \%myconfig, $form->{comparefromdate}, 1 );
  906. $shortcomparefromdate =
  907. $locale->date( \%myconfig, $form->{comparefromdate}, 0 );
  908. $longcomparetodate =
  909. $locale->date( \%myconfig, $form->{comparetodate}, 1 );
  910. $shortcomparetodate =
  911. $locale->date( \%myconfig, $form->{comparetodate}, 0 );
  912. $form->{last_period_from} = $shortcomparefromdate;
  913. $form->{last_period_to} = $shortcomparetodate;
  914. $form->{compare_period} = $locale->text('[_1] To [_2]',
  915. $longcomparefromdate, $longcomparetodate);
  916. }
  917. # setup variables for the form
  918. my @vars = qw(company address businessnumber);
  919. for (@vars) { $form->{$_} = $myconfig{$_} }
  920. ##SC: START HTML
  921. $form->{address} =~ s/\\n/<br>/g;
  922. ##SC: END HTML
  923. my $template = LedgerSMB::Template->new(
  924. user => \%myconfig,
  925. locale => $locale,
  926. template => 'income_statement',
  927. format => 'HTML',
  928. #no_escape => '1'
  929. );
  930. try {
  931. $template->render($form);
  932. $template->output(%{$form});
  933. }
  934. catch Error::Simple with {
  935. my $E = shift;
  936. $form->error( $E->stacktrace );
  937. };
  938. }
  939. sub generate_balance_sheet {
  940. RP->balance_sheet( \%myconfig, \%$form );
  941. $form->{asofdate} = $form->current_date( \%myconfig )
  942. unless $form->{asofdate};
  943. $form->{period} =
  944. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  945. ( $form->{department} ) = split /--/, $form->{department};
  946. # define Current Earnings account
  947. push(
  948. @{ $form->{equity_account} }, {
  949. current_earnings => 1,
  950. text => $locale->text('Current Earnings')
  951. },
  952. );
  953. $form->{this_period} = $locale->date( \%myconfig, $form->{asofdate}, 0 );
  954. $form->{last_period} =
  955. $locale->date( \%myconfig, $form->{compareasofdate}, 0 );
  956. # setup company variables for the form
  957. for (qw(company address businessnumber nativecurr login)) {
  958. $form->{$_} = $myconfig{$_};
  959. }
  960. ##SC: START HTML
  961. $form->{address} =~ s/\\n/<br>/g;
  962. ##SC: END HTML
  963. $form->{templates} = $myconfig{templates};
  964. my $template = LedgerSMB::Template->new(
  965. user => \%myconfig,
  966. locale => $locale,
  967. template => 'balance_sheet',
  968. format => $form->{format}? uc $form->{format}: 'HTML',
  969. no_auto_output => 1,
  970. );
  971. try {
  972. $template->render($form);
  973. $template->output(%{$form});
  974. }
  975. catch Error::Simple with {
  976. my $E = shift;
  977. $form->error( $E->stacktrace );
  978. };
  979. }
  980. sub generate_projects {
  981. $form->{nextsub} = "generate_projects";
  982. $form->{title} = $locale->text('Project Transactions');
  983. RP->trial_balance( \%myconfig, \%$form );
  984. &list_accounts;
  985. }
  986. sub csv_generate_projects { &generate_projects }
  987. sub xls_generate_projects { &generate_projects }
  988. sub ods_generate_projects { &generate_projects }
  989. # Antonio Gallardo
  990. #
  991. # D.S. Feb 16, 2001
  992. # included links to display transactions for period entered
  993. # added headers and subtotals
  994. #
  995. sub generate_trial_balance {
  996. # get for each account initial balance, debits and credits
  997. RP->trial_balance( \%myconfig, \%$form );
  998. $form->{nextsub} = "generate_trial_balance";
  999. $form->{title} = $locale->text('Trial Balance');
  1000. $form->{callback} = "$form->{script}?action=generate_trial_balance";
  1001. for (
  1002. qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)
  1003. )
  1004. {
  1005. $form->{callback} .= "&$_=$form->{$_}";
  1006. }
  1007. $form->{callback} = $form->escape( $form->{callback} );
  1008. &list_accounts;
  1009. }
  1010. sub csv_generate_trial_balance { &generate_trial_balance }
  1011. sub xls_generate_trial_balance { &generate_trial_balance }
  1012. sub ods_generate_trial_balance { &generate_trial_balance }
  1013. sub list_accounts {
  1014. $title = $form->escape( $form->{title} );
  1015. my %hiddens = (
  1016. path => $form->{path},
  1017. sessionid => $form->{sessionid},
  1018. login => $form->{login},
  1019. accounttype => $form->{accounttype},
  1020. fromdate => $form->{fromdate},
  1021. todate => $form->{todate},
  1022. l_heading => $form->{l_heading},
  1023. l_subtotal => $form->{l_subtotal},
  1024. all_accounts => $form->{all_accounts},
  1025. department => $form->{department},
  1026. projectnumber => $form->{projectnumber},
  1027. project_id => $form->{project_id},
  1028. );
  1029. my @options;
  1030. if ( $form->{department} ) {
  1031. ($department) = split /--/, $form->{department};
  1032. push @options, $locale->text('Department: [_1]', $department);
  1033. $department = $form->escape( $form->{department} );
  1034. }
  1035. if ( $form->{projectnumber} ) {
  1036. ($projectnumber) = split /--/, $form->{projectnumber};
  1037. push @options, $locale->text('Project Number: [_1]', $projectnumber);
  1038. $projectnumber = $form->escape( $form->{projectnumber} );
  1039. }
  1040. # if there are any dates
  1041. if ( $form->{fromdate} || $form->{todate} ) {
  1042. if ( $form->{fromdate} ) {
  1043. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1044. }
  1045. if ( $form->{todate} ) {
  1046. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1047. }
  1048. $form->{period} = "$fromdate - $todate";
  1049. } else {
  1050. $form->{period} =
  1051. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1052. }
  1053. push @options, $form->{period};
  1054. my @column_index = qw(accno description begbalance debit credit endbalance);
  1055. my %column_header;
  1056. $column_header{accno} = $locale->text('Account');
  1057. $column_header{description} = $locale->text('Description');
  1058. $column_header{debit} = $locale->text('Debit');
  1059. $column_header{credit} = $locale->text('Credit');
  1060. $column_header{begbalance} = $locale->text('Balance');
  1061. $column_header{endbalance} = $locale->text('Balance');
  1062. if ( $form->{accounttype} eq 'gifi' ) {
  1063. $column_header{accno} = $locale->text('GIFI');
  1064. }
  1065. # sort the whole thing by account numbers and display
  1066. my @rows;
  1067. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} } ) {
  1068. my %column_data;
  1069. my $description = $form->escape( $ref->{description} );
  1070. my $href =
  1071. qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&prevreport=$form->{callback}|;
  1072. if ( $form->{accounttype} eq 'gifi' ) {
  1073. $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
  1074. $na = $locale->text('N/A');
  1075. if ( !$ref->{accno} ) {
  1076. for (qw(accno description)) { $ref->{$_} = $na }
  1077. }
  1078. }
  1079. else {
  1080. $href .= "&accno=$ref->{accno}&description=$description";
  1081. }
  1082. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  1083. $ml *= -1 if $ref->{contra};
  1084. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, " " );
  1085. $credit =
  1086. $form->format_amount( \%myconfig, $ref->{credit}, 2, " " );
  1087. $begbalance =
  1088. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  1089. " " );
  1090. $endbalance =
  1091. $form->format_amount( \%myconfig,
  1092. ( $ref->{balance} + $ref->{amount} ) * $ml, 2, " " );
  1093. if ( $ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal} ) {
  1094. if ($subtotal) {
  1095. for (qw(accno begbalance endbalance)) {
  1096. $column_data{$_} = " ";
  1097. }
  1098. $subtotalbegbalance =
  1099. $form->format_amount( \%myconfig, $subtotalbegbalance, 2,
  1100. " " );
  1101. $subtotalendbalance =
  1102. $form->format_amount( \%myconfig, $subtotalendbalance, 2,
  1103. " " );
  1104. $subtotaldebit =
  1105. $form->format_amount( \%myconfig, $subtotaldebit, 2,
  1106. " " );
  1107. $subtotalcredit =
  1108. $form->format_amount( \%myconfig, $subtotalcredit, 2,
  1109. " " );
  1110. $column_data{description} = $subtotaldescription;
  1111. $column_data{begbalance} = $subtotalbegbalance;
  1112. $column_data{endbalance} = $subtotalendbalance;
  1113. $column_data{debit} = $subtotaldebit;
  1114. $column_data{credit} = $subtotalcredit;
  1115. $column_data{class} = 'subtotal';
  1116. push @rows, \%column_data;
  1117. }
  1118. }
  1119. if ( $ref->{charttype} eq "H" ) {
  1120. $subtotal = 1;
  1121. $subtotaldescription = $ref->{description};
  1122. $subtotaldebit = $ref->{debit};
  1123. $subtotalcredit = $ref->{credit};
  1124. $subtotalbegbalance = 0;
  1125. $subtotalendbalance = 0;
  1126. if ( $form->{l_heading} ) {
  1127. if ( !$form->{all_accounts} and
  1128. ( $subtotaldebit + $subtotalcredit ) == 0 ) {
  1129. $subtotal = 0;
  1130. next;
  1131. }
  1132. } else {
  1133. $subtotal = 0;
  1134. if ( $form->{all_accounts} || ( $form->{l_subtotal} &&
  1135. ( ( $subtotaldebit + $subtotalcredit ) != 0 ) )) {
  1136. $subtotal = 1;
  1137. }
  1138. next;
  1139. }
  1140. for (qw(accno debit credit begbalance endbalance)) {
  1141. $column_data{$_} = " ";
  1142. }
  1143. $column_data{description} = $ref->{description};
  1144. $column_data{class} = 'heading';
  1145. }
  1146. if ( $ref->{charttype} eq "A" ) {
  1147. $column_data{accno} = {text => $ref->{accno}, href => $href};
  1148. $column_data{description} = $ref->{description};
  1149. $column_data{debit} = $debit;
  1150. $column_data{credit} = $credit;
  1151. $column_data{begbalance} = $begbalance;
  1152. $column_data{endbalance} = $endbalance;
  1153. $totaldebit += $ref->{debit};
  1154. $totalcredit += $ref->{credit};
  1155. $cml = ( $ref->{contra} ) ? -1 : 1;
  1156. $subtotalbegbalance += $ref->{balance} * $ml * $cml;
  1157. $subtotalendbalance +=
  1158. ( $ref->{balance} + $ref->{amount} ) * $ml * $cml;
  1159. }
  1160. if ( $ref->{charttype} eq "H" ) {
  1161. $column_data{class} = 'heading';
  1162. }
  1163. if ( $ref->{charttype} eq "A" ) {
  1164. $i++;
  1165. $i %= 2;
  1166. $column_data{i} = $i;
  1167. }
  1168. push @rows, \%column_data;
  1169. }
  1170. # print last subtotal
  1171. if ( $subtotal && $form->{l_subtotal} ) {
  1172. my %column_data;
  1173. for (qw(accno begbalance endbalance)) {
  1174. $column_data{$_} = " ";
  1175. }
  1176. $subtotalbegbalance =
  1177. $form->format_amount( \%myconfig, $subtotalbegbalance, 2, " " );
  1178. $subtotalendbalance =
  1179. $form->format_amount( \%myconfig, $subtotalendbalance, 2, " " );
  1180. $subtotaldebit =
  1181. $form->format_amount( \%myconfig, $subtotaldebit, 2, " " );
  1182. $subtotalcredit =
  1183. $form->format_amount( \%myconfig, $subtotalcredit, 2, " " );
  1184. $column_data{description} = $subtotaldescription;
  1185. $column_data{begbalance} = $subtotalbegbalance;
  1186. $column_data{endbalance} = $subtotalendbalance;
  1187. $column_data{debit} = $subtotaldebit;
  1188. $column_data{credit} = $subtotalcredit;
  1189. $column_data{class} = 'subtotal';
  1190. push @rows, \%column_data;
  1191. }
  1192. my %column_data;
  1193. $totaldebit = $form->format_amount( \%myconfig, $totaldebit, 2, " " );
  1194. $totalcredit =
  1195. $form->format_amount( \%myconfig, $totalcredit, 2, " " );
  1196. for (qw(accno description begbalance endbalance)) {
  1197. $column_data{$_} = "";
  1198. }
  1199. $column_data{debit} = $totaldebit;
  1200. $column_data{credit} = $totalcredit;
  1201. my @buttons;
  1202. for my $type (qw(CSV XLS ODS)) {
  1203. push @buttons, {
  1204. name => 'action',
  1205. value => lc "${type}_$form->{nextsub}",
  1206. text => $locale->text("$type Report"),
  1207. type => 'submit',
  1208. class => 'submit',
  1209. };
  1210. }
  1211. my $format;
  1212. if ($form->{action} eq 'continue') {
  1213. $format = 'HTML';
  1214. } else {
  1215. $format = uc substr $form->{action}, 0, 3;
  1216. push @column_index, 'class';
  1217. $column_header{class} = 'rowtype';
  1218. }
  1219. my $template = LedgerSMB::Template->new(
  1220. user => \%myconfig,
  1221. locale => $locale,
  1222. template => 'form-dynatable',
  1223. path => 'UI',
  1224. format => $format,
  1225. );
  1226. $template->render({
  1227. form => $form,
  1228. hiddens => \%hiddens,
  1229. buttons => \@buttons,
  1230. options => \@options,
  1231. columns => \@column_index,
  1232. heading => \%column_header,
  1233. rows => \@rows,
  1234. totals => \%column_data,
  1235. row_alignment => {
  1236. 'credit' => 'right',
  1237. 'debit' => 'right',
  1238. 'begbalance' => 'right',
  1239. 'endbalance' => 'right'
  1240. },
  1241. });
  1242. }
  1243. sub generate_ar_aging {
  1244. # split customer
  1245. ( $form->{customer} ) = split( /--/, $form->{customer} );
  1246. $customer = $form->escape( $form->{customer}, 1 );
  1247. $title = $form->escape( $form->{title}, 1 );
  1248. $media = $form->escape( $form->{media}, 1 );
  1249. $form->{ct} = "customer";
  1250. $form->{arap} = "ar";
  1251. RP->aging( \%myconfig, \%$form );
  1252. $form->{callback} =
  1253. qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
  1254. &aging;
  1255. }
  1256. sub csv_generate_ar_aging { &generate_ar_aging }
  1257. sub generate_ap_aging {
  1258. # split vendor
  1259. ( $form->{vendor} ) = split( /--/, $form->{vendor} );
  1260. $vendor = $form->escape( $form->{vendor}, 1 );
  1261. $title = $form->escape( $form->{title}, 1 );
  1262. $media = $form->escape( $form->{media}, 1 );
  1263. $form->{ct} = "vendor";
  1264. $form->{arap} = "ap";
  1265. RP->aging( \%myconfig, \%$form );
  1266. $form->{callback} =
  1267. qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
  1268. &aging;
  1269. }
  1270. sub aging {
  1271. my %hiddens;
  1272. my @buttons;
  1273. my @options;
  1274. my %column_header;
  1275. my @column_index;
  1276. my %row_alignment;
  1277. $column_header{statement} = ' ';
  1278. $column_header{ct} = $locale->text( ucfirst $form->{ct} );
  1279. $column_header{language} = $locale->text('Language');
  1280. $column_header{invnumber} = $locale->text('Invoice');
  1281. $column_header{ordnumber} = $locale->text('Order');
  1282. $column_header{transdate} = $locale->text('Date');
  1283. $column_header{duedate} = $locale->text('Due Date');
  1284. $column_header{c0} = $locale->text('Current');
  1285. $column_header{c30} = '30';
  1286. $column_header{c60} = '60';
  1287. $column_header{c90} = '90';
  1288. $column_header{total} = $locale->text('Total');
  1289. @column_index = qw(statement ct);
  1290. if ( @{ $form->{all_language} } && $form->{arap} eq 'ar' ) {
  1291. push @column_index, "language";
  1292. $form->{language_options} = [{text => ' ', value => ''}];
  1293. for ( @{ $form->{all_language} } ) {
  1294. push @{$form->{language_options}},
  1295. {text => $_->{description}, value => $_->{code}};
  1296. }
  1297. }
  1298. my @c = ();
  1299. for (qw(c0 c30 c60 c90)) {
  1300. if ( $form->{$_} ) {
  1301. push @c, $_;
  1302. $form->{callback} .= "&$_=$form->{$_}";
  1303. }
  1304. }
  1305. if ( !$form->{summary} ) {
  1306. push @column_index, qw(invnumber ordnumber transdate duedate);
  1307. }
  1308. push @column_index, @c;
  1309. push @column_index, "total";
  1310. if ( $form->{overdue} ) {
  1311. push @options, $locale->text('Aged Overdue');
  1312. $form->{callback} .= "&overdue=$form->{overdue}";
  1313. } else {
  1314. push @options, $locale->text('Aged');
  1315. }
  1316. if ( $form->{department} ) {
  1317. ($department) = split /--/, $form->{department};
  1318. push @options, $locale->text('Department: [_1]', $department);
  1319. $department = $form->escape( $form->{department}, 1 );
  1320. $form->{callback} .= "&department=$department";
  1321. }
  1322. if ( $form->{arap} eq 'ar' ) {
  1323. if ( $form->{customer} ) {
  1324. push @options, $form->{customer};
  1325. }
  1326. }
  1327. if ( $form->{arap} eq 'ap' ) {
  1328. shift @column_index;
  1329. if ( $form->{vendor} ) {
  1330. push @options, $form->{vendor};
  1331. }
  1332. }
  1333. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1334. push @options, $locale->text('for Period To [_1]', $todate);
  1335. $ctid = 0;
  1336. $i = 0;
  1337. $k = 0;
  1338. $l = $#{ $form->{AG} };
  1339. my @currencies;
  1340. foreach my $ref ( @{ $form->{AG} } ) {
  1341. if ( $curr ne $ref->{curr} ) {
  1342. my %column_data;
  1343. $ctid = 0;
  1344. for (@column_index) { $column_data{$_} = ' ' }
  1345. if ($curr) {
  1346. $c0total = $form->format_amount(\%myconfig, $c0total, 2, ' ');
  1347. $c30total = $form->format_amount(\%myconfig, $c30total, 2, ' ');
  1348. $c60total = $form->format_amount(\%myconfig, $c60total, 2, ' ');
  1349. $c90total = $form->format_amount(\%myconfig, $c90total, 2, ' ');
  1350. $total = $form->format_amount(\%myconfig, $total, 2, ' ' );
  1351. for (qw(ct statement language)) {
  1352. $column_data{$_} = ' ';
  1353. }
  1354. $column_data{c0} = $c0total;
  1355. $column_data{c30} = $c30total;
  1356. $column_data{c60} = $c60total;
  1357. $column_data{c90} = $c90total;
  1358. $column_data{total} = $total;
  1359. push @{$currencies[0]{totals}}, \%column_data;
  1360. $c0subtotal = 0;
  1361. $c30subtotal = 0;
  1362. $c60subtotal = 0;
  1363. $c90subtotal = 0;
  1364. $subtotal = 0;
  1365. $c0total = 0;
  1366. $c30total = 0;
  1367. $c60total = 0;
  1368. $c90total = 0;
  1369. $total = 0;
  1370. }
  1371. unshift @currencies, {};
  1372. $curr = $ref->{curr};
  1373. $currencies[0]{curr} = $curr;
  1374. }
  1375. $k++;
  1376. my %column_data;
  1377. if ( $ctid != $ref->{ctid} or $form->{summary}) {
  1378. $i++;
  1379. $column_data{ct} = $ref->{name};
  1380. $column_data{language} = {
  1381. name => "language_code_$i",
  1382. options => $form->{language_options},
  1383. default_value => $ref->{language_code},
  1384. } if $form->{language_options};
  1385. $column_data{statement} = {
  1386. name => "statement_$i",
  1387. type => 'checkbox',
  1388. value => '1',
  1389. };
  1390. $column_data{statement}{checked} = 'checked' if $ref->{checked};
  1391. $hiddens{"$form->{ct}_id_$i"} = $ref->{ctid};
  1392. $hiddens{"curr_$i"} = $ref->{curr};
  1393. }
  1394. $ctid = $ref->{ctid};
  1395. for (qw(c0 c30 c60 c90)) {
  1396. $ref->{$_} =
  1397. $form->round_amount( $ref->{$_} / $ref->{exchangerate}, 2 );
  1398. }
  1399. $c0subtotal += $ref->{c0};
  1400. $c30subtotal += $ref->{c30};
  1401. $c60subtotal += $ref->{c60};
  1402. $c90subtotal += $ref->{c90};
  1403. $c0total += $ref->{c0};
  1404. $c30total += $ref->{c30};
  1405. $c60total += $ref->{c60};
  1406. $c90total += $ref->{c90};
  1407. $ref->{total} =
  1408. ( $ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90} );
  1409. $subtotal += $ref->{total};
  1410. $total += $ref->{total};
  1411. $ref->{c0} =
  1412. $form->format_amount( \%myconfig, $ref->{c0}, 2, ' ' );
  1413. $ref->{c30} =
  1414. $form->format_amount( \%myconfig, $ref->{c30}, 2, ' ' );
  1415. $ref->{c60} =
  1416. $form->format_amount( \%myconfig, $ref->{c60}, 2, ' ' );
  1417. $ref->{c90} =
  1418. $form->format_amount( \%myconfig, $ref->{c90}, 2, ' ' );
  1419. $ref->{total} =
  1420. $form->format_amount( \%myconfig, $ref->{total}, 2, ' ' );
  1421. $href =
  1422. qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|
  1423. . $form->escape( $form->{callback} );
  1424. $column_data{invnumber} = {text => $ref->{invnumber}, href => $href};
  1425. for (qw(c0 c30 c60 c90 total ordnumber transdate duedate)) {
  1426. $column_data{$_} = $ref->{$_};
  1427. }
  1428. if ( !$form->{summary} ) {
  1429. $j++;
  1430. $j %= 2;
  1431. $column_data{i} = $j;
  1432. my $rowref = {};
  1433. $rowref->{$_} = $column_data{$_} for keys %column_data;
  1434. push @{$currencies[0]{rows}}, $rowref;
  1435. for (qw(ct statement language)) {
  1436. $column_data{$_} = ' ';
  1437. }
  1438. }
  1439. $column_data{ct} = $ref->{name};
  1440. # prepare subtotal
  1441. $nextid = ( $k <= $l ) ? $form->{AG}->[$k]->{ctid} : 0;
  1442. if ( $ctid != $nextid ) {
  1443. $c0subtotal =
  1444. $form->format_amount( \%myconfig, $c0subtotal, 2, ' ' );
  1445. $c30subtotal =
  1446. $form->format_amount( \%myconfig, $c30subtotal, 2, ' ' );
  1447. $c60subtotal =
  1448. $form->format_amount( \%myconfig, $c60subtotal, 2, ' ' );
  1449. $c90subtotal =
  1450. $form->format_amount( \%myconfig, $c90subtotal, 2, ' ' );
  1451. $subtotal =
  1452. $form->format_amount( \%myconfig, $subtotal, 2, ' ' );
  1453. if ( $form->{summary} ) {
  1454. $column_data{c0} = $c0subtotal;
  1455. $column_data{c30} = $c30subtotal;
  1456. $column_data{c60} = $c60subtotal;
  1457. $column_data{c90} = $c90subtotal;
  1458. $column_data{total} = $subtotal;
  1459. $j++;
  1460. $j %= 2;
  1461. $column_data{i} = $j;
  1462. push @{$currencies[0]{rows}}, \%column_data;
  1463. } else {
  1464. for (@column_index) { $column_data{$_} = ' ' }
  1465. $column_data{c0} = $c0subtotal;
  1466. $column_data{c30} = $c30subtotal;
  1467. $column_data{c60} = $c60subtotal;
  1468. $column_data{c90} = $c90subtotal;
  1469. $column_data{total} = $subtotal;
  1470. $column_data{class} = 'subtotal';
  1471. push @{$currencies[0]{rows}}, \%column_data;
  1472. }
  1473. $c0subtotal = 0;
  1474. $c30subtotal = 0;
  1475. $c60subtotal = 0;
  1476. $c90subtotal = 0;
  1477. $subtotal = 0;
  1478. }
  1479. }
  1480. my %column_data;
  1481. for (@column_index) { $column_data{$_} = ' ' }
  1482. $c0total = $form->format_amount( \%myconfig, $c0total, 2, ' ' );
  1483. $c30total = $form->format_amount( \%myconfig, $c30total, 2, ' ' );
  1484. $c60total = $form->format_amount( \%myconfig, $c60total, 2, ' ' );
  1485. $c90total = $form->format_amount( \%myconfig, $c90total, 2, ' ' );
  1486. $total = $form->format_amount( \%myconfig, $total, 2, ' ' );
  1487. $column_data{c0} = $c0total;
  1488. $column_data{c30} = $c30total;
  1489. $column_data{c60} = $c60total;
  1490. $column_data{c90} = $c90total;
  1491. $column_data{total} = $total;
  1492. $currencies[0]{total} = \%column_data;
  1493. $row_alignment{c0} = 'right';
  1494. $row_alignment{c30} = 'right';
  1495. $row_alignment{c60} = 'right';
  1496. $row_alignment{c90} = 'right';
  1497. $row_alignment{total} = 'right';
  1498. $hiddens{rowcount} = $i;
  1499. &print_options if ( $form->{arap} eq 'ar' );
  1500. my @buttons;
  1501. if ( $form->{arap} eq 'ar' ) {
  1502. $hiddens{$_} = $form->{$_} foreach qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid);
  1503. $hiddens{$form->{ct}} = $form->{$form->{ct}};
  1504. # type=submit $locale->text('Select all')
  1505. # type=submit $locale->text('Print')
  1506. # type=submit $locale->text('E-mail')
  1507. my %button = (
  1508. 'select_all' =>
  1509. { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1510. 'print' =>
  1511. { ndx => 2, key => 'P', value => $locale->text('Print') },
  1512. 'e_mail' =>
  1513. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1514. );
  1515. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1516. {
  1517. push @buttons, {
  1518. accesskey => $button{$_}->{key},
  1519. text => $button{$_}->{value},
  1520. title => "$button{$_}->{value} [Alt-$button{$_}->{key}]",
  1521. value => $_,
  1522. name => 'action',
  1523. };
  1524. }
  1525. }
  1526. ##SC: Temporary commenting
  1527. ## if ( $form->{lynx} ) {
  1528. ## require "bin/menu.pl";
  1529. ## &menubar;
  1530. ## }
  1531. for my $type (qw(CSV XLS ODS)) {
  1532. push @buttons, {
  1533. name => 'action',
  1534. value => lc "${type}_$form->{nextsub}",
  1535. text => $locale->text("$type Report"),
  1536. type => 'submit',
  1537. class => 'submit',
  1538. };
  1539. }
  1540. my $format;
  1541. if ($form->{action} =~ /^(continue|generate_)/) {
  1542. $format = 'HTML';
  1543. } else {
  1544. $format = uc substr $form->{action}, 0, 3;
  1545. push @column_index, 'class';
  1546. @column_index = grep {!/^(language|statement)$/} @column_index;
  1547. $column_header{class} = 'rowtype';
  1548. }
  1549. my $template = LedgerSMB::Template->new(
  1550. user => \%myconfig,
  1551. locale => $locale,
  1552. template => 'rp-aging',
  1553. path => 'UI',
  1554. format => $format,
  1555. );
  1556. $template->render({
  1557. form => $form,
  1558. hiddens => \%hiddens,
  1559. buttons => \@buttons,
  1560. options => \@options,
  1561. columns => \@column_index,
  1562. heading => \%column_header,
  1563. currencies => [reverse @currencies],
  1564. row_alignment => {
  1565. 'credit' => 'right',
  1566. 'debit' => 'right',
  1567. 'begbalance' => 'right',
  1568. 'endbalance' => 'right'
  1569. },
  1570. });
  1571. }
  1572. sub select_all {
  1573. RP->aging( \%myconfig, \%$form );
  1574. for ( @{ $form->{AG} } ) { $_->{checked} = "checked" }
  1575. &aging;
  1576. }
  1577. sub print_options {
  1578. $form->{sendmode} = "attachment";
  1579. $form->{copies} = 1 unless $form->{copies};
  1580. $form->{print}{format} = {name => 'format', default_values => $form->{format}};
  1581. $form->{print}{template} = {name => 'type', default_values => $form->{type}};
  1582. my @formats = ();
  1583. my @media = ();
  1584. my @templates = ();
  1585. push @formats, {text => 'HTML', value => 'html'};
  1586. push @templates, {text => $locale->text('Statement'), value => 'statement'};
  1587. if ( $form->{media} eq 'email' ) {
  1588. $form->{print}{medium} = {name => 'sendmode', default_values => $form->{sendmode}};
  1589. push @media, {text => $locale->text('Attachment'), value => 'attachment'};
  1590. push @media, {text => $locale->text('In-line'), value => 'inline'};
  1591. if ($form->{SM}{attachment}) {
  1592. $form->{print}{medium}{default_values} = $form->{SM}{attachment};
  1593. } elsif ($form->{SM}{inline}) {
  1594. $form->{print}{medium}{default_values} = $form->{SM}{inline};
  1595. }
  1596. } else {
  1597. $form->{print}{medium} = {name => 'media'};
  1598. push @media, {text => $locale->text('Screen'), value => 'screen'};
  1599. if ( %{LedgerSMB::Sysconfig::printer}
  1600. && ${LedgerSMB::Sysconfig::latex} )
  1601. {
  1602. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1603. push @media, {text => $_, value => $_};
  1604. }
  1605. }
  1606. }
  1607. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1608. push @formats, {text => $locale->text('PDF'), value => 'pdf'};
  1609. push @formats, {text => $locale->text('Postscript'), value => 'ps'};
  1610. }
  1611. if ( %{LedgerSMB::Sysconfig::printer}
  1612. && ${LedgerSMB::Sysconfig::latex}
  1613. && $form->{media} ne 'email' )
  1614. {
  1615. $form->{print}{copies} = {
  1616. label => $locale->text('Copies'),
  1617. name => 'copies',
  1618. value => $form->{copies},
  1619. size => 2,
  1620. };
  1621. }
  1622. $form->{print}{template}{options} = \@templates;
  1623. $form->{print}{format}{options} = \@formats;
  1624. $form->{print}{medium}{options} = \@media;
  1625. }
  1626. sub e_mail {
  1627. my %hiddens;
  1628. # get name and email addresses
  1629. for $i ( 1 .. $form->{rowcount} ) {
  1630. if ( $form->{"statement_$i"} ) {
  1631. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1632. $form->{"statement_1"} = 1;
  1633. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1634. $form->{"curr_1"} = $form->{"curr_$i"};
  1635. RP->get_customer( \%myconfig, \%$form );
  1636. $selected = 1;
  1637. last;
  1638. }
  1639. }
  1640. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1641. $form->{media} = "email";
  1642. &print_options;
  1643. for (qw(email cc bcc subject message type sendmode format action nextsub)) {
  1644. delete $form->{$_};
  1645. }
  1646. for (keys %$form) {
  1647. $hiddens{$_} = $form->{$_} unless ref $form->{$_};
  1648. }
  1649. my @buttons = ({
  1650. name => 'action',
  1651. value => 'send_email',
  1652. text => $locale->text('Continue'),
  1653. });
  1654. my $template = LedgerSMB::Template->new_UI(
  1655. user => \%myconfig,
  1656. locale => $locale,
  1657. template => 'rp-email',
  1658. );
  1659. $template->render({
  1660. form => $form,
  1661. user => \%myconfig,
  1662. hiddens => \%hiddens,
  1663. buttons => \@buttons,
  1664. });
  1665. }
  1666. sub send_email {
  1667. $form->{subject} = $locale->text( 'Statement - [_1]', $form->{todate} )
  1668. unless $form->{subject};
  1669. $form->isblank( "email", $locale->text('E-mail address missing!') );
  1670. RP->aging( \%myconfig, $form );
  1671. my $data = &print_form;
  1672. delete $form->{header};
  1673. my $template = LedgerSMB::Template->new(
  1674. user => \%myconfig,
  1675. template => $form->{'formname'} || $form->{'type'},
  1676. format => uc $form->{format},
  1677. method => 'email',
  1678. output_options => {
  1679. to => $form->{email},
  1680. cc => $form->{cc},
  1681. bcc => $form->{bcc},
  1682. from => $form->{form},
  1683. subject => $form->{subject},
  1684. message => $form->{message},
  1685. notify => $form->{read_receipt},
  1686. attach => ($form->{sendmode} eq 'attachment')? 1: 0,
  1687. },
  1688. );
  1689. try {
  1690. $template->render({data => [$data]});
  1691. }
  1692. catch Error::Simple with {
  1693. my $E = shift;
  1694. $form->error( $E->stacktrace );
  1695. };
  1696. $form->redirect(
  1697. $locale->text( 'Statement sent to [_1]', $form->{ $form->{ct} } ) );
  1698. exit;
  1699. }
  1700. sub print {
  1701. if ( $form->{media} !~ /(screen|email)/ ) {
  1702. $form->error( $locale->text('Select postscript or PDF!') )
  1703. if ( $form->{format} !~ /(postscript|pdf)/ );
  1704. }
  1705. my @batch_data = ();
  1706. my $selected;
  1707. for $i ( 1 .. $form->{rowcount} ) {
  1708. if ( $form->{"statement_$i"} ) {
  1709. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1710. $language_code = $form->{"language_code_$i"};
  1711. $curr = $form->{"curr_$i"};
  1712. $selected = 1;
  1713. if ( $form->{media} !~ /(screen|email)/ ) {
  1714. # SC: I may not need this anymore...
  1715. # But I'll wait until lpr output is working before deciding
  1716. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  1717. $form->{"$form->{ct}_id"} = "";
  1718. $SIG{INT} = 'IGNORE';
  1719. }
  1720. else {
  1721. $form->{"statement_1"} = 1;
  1722. $form->{"language_code_1"} = $language_code;
  1723. $form->{"curr_1"} = $curr;
  1724. }
  1725. RP->aging( \%myconfig, \%$form );
  1726. $printhash = &print_form;
  1727. push @batch_data, $printhash;
  1728. }
  1729. }
  1730. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1731. my $template = LedgerSMB::Template->new(
  1732. user => \%myconfig,
  1733. template => $form->{'formname'} || $form->{'type'},
  1734. format => uc $form->{format}
  1735. );
  1736. try {
  1737. $template->render({data => \@batch_data});
  1738. $template->output($form);
  1739. }
  1740. catch Error::Simple with {
  1741. my $E = shift;
  1742. $form->error( $E->stacktrace );
  1743. };
  1744. $form->redirect( $locale->text('Statements sent to printer!') )
  1745. if ( $form->{media} !~ /(screen|email)/ );
  1746. }
  1747. sub print_form {
  1748. $form->{statementdate} = $locale->date( \%myconfig, $form->{todate}, 1 );
  1749. $form->{templates} = "$myconfig{templates}";
  1750. # setup variables for the form
  1751. my @vars = qw(company address businessnumber tel fax);
  1752. for (@vars) { $form->{$_} = $myconfig{$_} }
  1753. $form->{address} =~ s/\\n/\n/g;
  1754. @vars = qw(name address1 address2 city state zipcode country contact);
  1755. push @vars, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1756. push @vars, 'email' if !$form->{media} eq 'email';
  1757. my $i = 0;
  1758. while ( @{ $form->{AG} } ) {
  1759. my $ref = shift @{ $form->{AG} };
  1760. if ( $ctid != $ref->{ctid} ) {
  1761. $ctid = $ref->{ctid};
  1762. $i++;
  1763. if ( $form->{"statement_$i"} ) {
  1764. for (@vars) { $form->{$_} = $ref->{$_} }
  1765. $form->{ $form->{ct} } = $form->{name};
  1766. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1767. $form->{language_code} = $form->{"language_code_$i"};
  1768. $form->{currency} = $form->{"curr_$i"};
  1769. for (qw(invnumber ordnumber ponumber notes invdate duedate)) {
  1770. $form->{$_} = ();
  1771. }
  1772. $form->{total} = 0;
  1773. foreach $item (qw(c0 c30 c60 c90)) {
  1774. $form->{$item} = ();
  1775. $form->{"${item}total"} = 0;
  1776. }
  1777. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1778. while ($ref) {
  1779. if ( scalar( @{ $form->{AG} } ) > 0 ) {
  1780. # one or more left to go
  1781. if ( $ctid == $form->{AG}->[0]->{ctid} ) {
  1782. $ref = shift @{ $form->{AG} };
  1783. &statement_details($ref)
  1784. if $ref->{curr} eq $form->{currency};
  1785. # any more?
  1786. $ref = scalar( @{ $form->{AG} } );
  1787. }
  1788. else {
  1789. $ref = 0;
  1790. }
  1791. }
  1792. else {
  1793. # set initial ref to 0
  1794. $ref = 0;
  1795. }
  1796. }
  1797. for ( "c0", "c30", "c60", "c90", "" ) {
  1798. $form->{"${_}total"} =
  1799. $form->format_amount( \%myconfig, $form->{"${_}total"},
  1800. 2 );
  1801. }
  1802. my $printhash = {};
  1803. for (keys %$form) { $printhash->{$_} = $form->{$_}}
  1804. return $printhash;
  1805. }
  1806. }
  1807. }
  1808. }
  1809. sub statement_details {
  1810. my ($ref) = @_;
  1811. $ref->{invdate} = $ref->{transdate};
  1812. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1813. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1814. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1815. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1816. foreach $item (qw(c0 c30 c60 c90)) {
  1817. eval {
  1818. $ref->{$item} =
  1819. $form->round_amount( $ref->{$item} / $ref->{exchangerate}, 2 );
  1820. };
  1821. $form->{"${item}total"} += $ref->{$item};
  1822. $form->{total} += $ref->{$item};
  1823. push @{ $form->{$item} },
  1824. $form->format_amount( \%myconfig, $ref->{$item}, 2 );
  1825. }
  1826. }
  1827. sub generate_tax_report {
  1828. RP->tax_report( \%myconfig, \%$form );
  1829. my %hiddens;
  1830. my @options;
  1831. my $descvar = "$form->{accno}_description";
  1832. my $description = $form->escape( $form->{$descvar} );
  1833. my $ratevar = "$form->{accno}_rate";
  1834. my $taxrate = $form->{"$form->{accno}_rate"};
  1835. if ( $form->{accno} =~ /^gifi_/ ) {
  1836. $descvar = "gifi_$form->{accno}_description";
  1837. $description = $form->escape( $form->{$descvar} );
  1838. $ratevar = "gifi_$form->{accno}_rate";
  1839. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1840. }
  1841. my $department = $form->escape( $form->{department} );
  1842. # construct href
  1843. my $href =
  1844. "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
  1845. # construct callback
  1846. $description = $form->escape( $form->{$descvar}, 1 );
  1847. $department = $form->escape( $form->{department}, 1 );
  1848. $form->sort_order();
  1849. my $callback =
  1850. "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
  1851. $form->{title} = $locale->text('GIFI') . " - "
  1852. if ( $form->{accno} =~ /^gifi_/ );
  1853. my $title = $form->escape( $form->{title} );
  1854. $href .= "&title=$title";
  1855. $title = $form->escape( $form->{title}, 1 );
  1856. $callback .= "&title=$title";
  1857. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1858. my @columns =
  1859. $form->sort_columns(
  1860. qw(id transdate invnumber name description netamount tax total));
  1861. $form->{"l_description"} = "" if $form->{summary};
  1862. my @column_index;
  1863. foreach my $item (@columns) {
  1864. if ( $form->{"l_$item"} eq "Y" ) {
  1865. push @column_index, $item;
  1866. # add column to href and callback
  1867. $callback .= "&l_$item=Y";
  1868. $href .= "&l_$item=Y";
  1869. }
  1870. }
  1871. if ( $form->{l_subtotal} eq 'Y' ) {
  1872. $callback .= "&l_subtotal=Y";
  1873. $href .= "&l_subtotal=Y";
  1874. }
  1875. if ( $form->{department} ) {
  1876. ($department) = split /--/, $form->{department};
  1877. push @options, $locale->text('Department: [_1]', $department);
  1878. }
  1879. # if there are any dates
  1880. my $fromdate;
  1881. my $todate;
  1882. if ( $form->{fromdate} || $form->{todate} ) {
  1883. if ( $form->{fromdate} ) {
  1884. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1885. }
  1886. if ( $form->{todate} ) {
  1887. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1888. }
  1889. $form->{period} = "$fromdate - $todate";
  1890. }
  1891. else {
  1892. $form->{period} =
  1893. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1894. }
  1895. my $name;
  1896. my $invoice;
  1897. my $arap;
  1898. if ( $form->{db} eq 'ar' ) {
  1899. $name = $locale->text('Customer');
  1900. $invoice = 'is.pl';
  1901. $arap = 'ar.pl';
  1902. }
  1903. if ( $form->{db} eq 'ap' ) {
  1904. $name = $locale->text('Vendor');
  1905. $invoice = 'ir.pl';
  1906. $arap = 'ap.pl';
  1907. }
  1908. push @options, $form->{period};
  1909. my %column_header;
  1910. $column_header{id} = {
  1911. href => "$href&sort=id",
  1912. text => $locale->text('ID'),
  1913. };
  1914. $column_header{invnumber} = {
  1915. href => "$href&sort=invnumber",
  1916. text => $locale->text('Invoice')
  1917. };
  1918. $column_header{transdate} = {
  1919. href => "$href&sort=transdate",
  1920. text => $locale->text('Date'),
  1921. };
  1922. $column_header{netamount} = $locale->text('Amount');
  1923. $column_header{tax} = $locale->text('Tax');
  1924. $column_header{total} = $locale->text('Total');
  1925. $column_header{name} = {
  1926. href => "$href&sort=name",
  1927. text => $name,
  1928. };
  1929. $column_header{description} = {
  1930. href => "$href&sort=description",
  1931. text => $locale->text('Description'),
  1932. };
  1933. # add sort and escape callback
  1934. $callback = $form->escape( $callback . "&sort=$form->{sort}" );
  1935. my $sameitem;
  1936. if ( @{ $form->{TR} } ) {
  1937. $sameitem = $form->{TR}->[0]->{ $form->{sort} };
  1938. }
  1939. my $totalnetamount;
  1940. my @rows;
  1941. my $i;
  1942. foreach my $ref ( @{ $form->{TR} } ) {
  1943. my %column_data;
  1944. my $module = ( $ref->{invoice} ) ? $invoice : $arap;
  1945. $module = 'ps.pl' if $ref->{till};
  1946. if ( $form->{l_subtotal} eq 'Y' ) {
  1947. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1948. push @rows, &tax_subtotal(\@column_index);
  1949. $sameitem = $ref->{ $form->{sort} };
  1950. }
  1951. }
  1952. $totalnetamount += $ref->{netamount};
  1953. $totaltax += $ref->{tax};
  1954. $ref->{total} = $ref->{netamount} + $ref->{tax};
  1955. $subtotalnetamount += $ref->{netamount};
  1956. $subtotaltax += $ref->{tax};
  1957. for (qw(netamount tax total)) {
  1958. $ref->{$_} =
  1959. $form->format_amount( \%myconfig, $ref->{$_}, 2, ' ' );
  1960. }
  1961. $column_data{id} = $ref->{id};
  1962. $column_data{invnumber} = {
  1963. href => "$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  1964. text => $ref->{invnumber},
  1965. };
  1966. for (qw(id transdate name partnumber description)) {
  1967. $column_data{$_} = $ref->{$_};
  1968. }
  1969. for (qw(netamount tax total)) {
  1970. $column_data{$_} = $ref->{$_};
  1971. }
  1972. $i++;
  1973. $i %= 2;
  1974. $column_data{i} = $i;
  1975. push @rows, \%column_data;
  1976. }
  1977. if ( $form->{l_subtotal} eq 'Y' ) {
  1978. push @rows, &tax_subtotal(\@column_index);
  1979. }
  1980. my %column_data;
  1981. for (@column_index) { $column_data{$_} = ' ' }
  1982. $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax,
  1983. 2, ' ' );
  1984. $totalnetamount =
  1985. $form->format_amount( \%myconfig, $totalnetamount, 2, ' ' );
  1986. $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, ' ' );
  1987. $column_data{netamount} = $totalnetamount;
  1988. $column_data{tax} = $totaltax;
  1989. $column_data{total} = $total;
  1990. my $template = LedgerSMB::Template->new_UI(
  1991. user => \%myconfig,
  1992. locale => $locale,
  1993. template => 'form-dynatable',
  1994. );
  1995. $template->render({
  1996. form => $form,
  1997. hiddens => \%hiddens,
  1998. options => \@options,
  1999. columns => \@column_index,
  2000. heading => \%column_header,
  2001. rows => \@rows,
  2002. totals => \%column_data,
  2003. row_alignment => {
  2004. netamount => 'right',
  2005. tax => 'right',
  2006. total => 'right',
  2007. },
  2008. });
  2009. }
  2010. sub tax_subtotal {
  2011. my $column_index = shift;
  2012. my %column_data;
  2013. for (@{$column_index}) { $column_data{$_} = ' ' }
  2014. #SC: Yes, right now these are global, inherited from generate_tax_report
  2015. $subtotal =
  2016. $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax,
  2017. 2, ' ' );
  2018. $subtotalnetamount =
  2019. $form->format_amount( \%myconfig, $subtotalnetamount, 2, ' ' );
  2020. $subtotaltax =
  2021. $form->format_amount( \%myconfig, $subtotaltax, 2, ' ' );
  2022. $column_data{netamount} = {
  2023. class => 'subtotal',
  2024. text => $subtotalnetamount,
  2025. };
  2026. $column_data{tax} = {
  2027. class => 'subtotal',
  2028. text => $subtotaltax,
  2029. };
  2030. $column_data{total} = {
  2031. class => 'subtotal',
  2032. text => $subtotal,
  2033. };
  2034. $subtotalnetamount = 0;
  2035. $subtotaltax = 0;
  2036. \%column_data;
  2037. }
  2038. sub list_payments {
  2039. my %hiddens;
  2040. my @options;
  2041. if ( $form->{account} ) {
  2042. ( $form->{paymentaccounts} ) = split /--/, $form->{account};
  2043. }
  2044. if ( $form->{department} ) {
  2045. ( $department, $form->{department_id} ) = split /--/,
  2046. $form->{department};
  2047. push @options, $locale->text('Department: [_1]', $department);
  2048. }
  2049. RP->payments( \%myconfig, \%$form );
  2050. my @columns = $form->sort_columns(qw(transdate name paid source memo));
  2051. if ( $form->{till} ) {
  2052. @columns =
  2053. $form->sort_columns(qw(transdate name paid curr source till));
  2054. if ( $myconfig{role} ne 'user' ) {
  2055. @columns =
  2056. $form->sort_columns(
  2057. qw(transdate name paid curr source till employee));
  2058. }
  2059. }
  2060. # construct href
  2061. my $title = $form->escape( $form->{title} );
  2062. $form->{paymentaccounts} =~ s/ /%20/g;
  2063. my $href =
  2064. "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title="
  2065. . $form->escape( $form->{title} );
  2066. $form->sort_order();
  2067. $form->{callback} =
  2068. "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title="
  2069. . $form->escape( $form->{title}, 1 );
  2070. my $callback;
  2071. if ( $form->{account} ) {
  2072. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  2073. $href .= "&account=" . $form->escape( $form->{account} );
  2074. push @options, $locale->text('Account: [_1]', $form->{account});
  2075. }
  2076. if ( $form->{department} ) {
  2077. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  2078. $href .= "&department=" . $form->escape( $form->{department} );
  2079. push @options, $locale->text('Department: [_1]', $form->{department});
  2080. }
  2081. if ( $form->{description} ) {
  2082. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  2083. $href .= "&description=" . $form->escape( $form->{description} );
  2084. push @options, $locale->text('Description: [_1]', $form->{description});
  2085. }
  2086. if ( $form->{source} ) {
  2087. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  2088. $href .= "&source=" . $form->escape( $form->{source} );
  2089. push @options, $locale->text('Source: [_1]', $form->{source});
  2090. }
  2091. if ( $form->{memo} ) {
  2092. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  2093. $href .= "&memo=" . $form->escape( $form->{memo} );
  2094. push @options, $locale->text('Memo: [_1]', $form->{memo});
  2095. }
  2096. if ( $form->{fromdate} ) {
  2097. push @options,
  2098. $locale->text('From [_1]',
  2099. $locale->date( \%myconfig, $form->{fromdate}, 1 ));
  2100. }
  2101. if ( $form->{todate} ) {
  2102. push @options,
  2103. $locale->text('To [_1]',
  2104. $locale->date( \%myconfig, $form->{todate}, 1 ));
  2105. }
  2106. $callback = $form->escape( $form->{callback} );
  2107. my %column_header;
  2108. $column_header{name} = {
  2109. href => "$href&sort=name",
  2110. text => $locale->text('Description'),
  2111. };
  2112. $column_header{transdate} = {
  2113. href => "$href&sort=transdate",
  2114. text => $locale->text('Date'),
  2115. };
  2116. $column_header{paid} = $locale->text('Amount');
  2117. $column_header{curr} = $locale->text('Curr');
  2118. $column_header{source} = {
  2119. href => "$href&sort=source",
  2120. text => $locale->text('Source'),
  2121. };
  2122. $column_header{memo} = {
  2123. href => "$href&sort=memo",
  2124. text => $locale->text('Memo'),
  2125. };
  2126. $column_header{employee} = {
  2127. href => "$href&sort=employee",
  2128. text => $locale->text('Salesperson'),
  2129. };
  2130. $column_header{till} = {
  2131. href => "$href&sort=till",
  2132. text => $locale->text('Till'),
  2133. };
  2134. my @column_index = @columns;
  2135. my @accounts;
  2136. my $i;
  2137. foreach my $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) {
  2138. next unless @{ $form->{ $ref->{id} } };
  2139. push @accounts, {header => "$ref->{accno}--$ref->{description}"};
  2140. if ( @{ $form->{ $ref->{id} } } ) {
  2141. $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} };
  2142. }
  2143. my @rows;
  2144. foreach my $payment ( @{ $form->{ $ref->{id} } } ) {
  2145. if ( $form->{l_subtotal} ) {
  2146. if ( $payment->{ $form->{sort} } ne $sameitem ) {
  2147. # print subtotal
  2148. push @rows, &payment_subtotal(\@column_index);
  2149. }
  2150. }
  2151. next if ( $form->{till} && !$payment->{till} );
  2152. my %column_data;
  2153. $column_data{name} = $payment->{name};
  2154. $column_data{transdate} = $payment->{transdate};
  2155. $column_data{paid} =
  2156. $form->format_amount(\%myconfig, $payment->{paid}, 2, ' ');
  2157. $column_data{curr} = $payment->{curr};
  2158. $column_data{source} = $payment->{source};
  2159. $column_data{memo} = $payment->{memo};
  2160. $column_data{employee} = $payment->{employee};
  2161. $column_data{till} = $payment->{till};
  2162. $subtotalpaid += $payment->{paid};
  2163. $accounttotalpaid += $payment->{paid};
  2164. $totalpaid += $payment->{paid};
  2165. $i++;
  2166. $i %= 2;
  2167. $column_data{i} = $i;
  2168. push @rows, \%column_data;
  2169. $sameitem = $payment->{ $form->{sort} };
  2170. }
  2171. push @rows, &payment_subtotal(\@column_index) if $form->{l_subtotal};
  2172. $accounts[$#accounts]{rows} = \@rows;
  2173. # print account totals
  2174. my %column_data;
  2175. for (@column_index) { $column_data{$_} = ' ' }
  2176. $column_data{paid} =
  2177. $form->format_amount( \%myconfig, $accounttotalpaid, 2, ' ' );
  2178. $accounts[$#accounts]{totals} = \%column_data;
  2179. $accounttotalpaid = 0;
  2180. }
  2181. # prepare total
  2182. my %column_data;
  2183. for (@column_index) { $column_data{$_} = ' ' }
  2184. $column_data{paid} = $form->format_amount( \%myconfig, $totalpaid, 2, ' ' );
  2185. ##SC: Temporary removal
  2186. ## if ( $form->{lynx} ) {
  2187. ## require "bin/menu.pl";
  2188. ## &menubar;
  2189. ## }
  2190. my $template = LedgerSMB::Template->new_UI(
  2191. user => \%myconfig,
  2192. locale => $locale,
  2193. template => 'rp-payments',
  2194. );
  2195. $template->render({
  2196. form => $form,
  2197. hiddens => \%hiddens,
  2198. options => \@options,
  2199. columns => \@column_index,
  2200. heading => \%column_header,
  2201. accounts => \@accounts,
  2202. totals => \%column_data,
  2203. row_alignment => {
  2204. paid => 'right',
  2205. },
  2206. });
  2207. }
  2208. sub payment_subtotal {
  2209. my $column_index = shift;
  2210. my %column_data;
  2211. if ( $subtotalpaid != 0 ) {
  2212. for (@column_index) { $column_data{$_} = ' ' }
  2213. $column_data{paid} =
  2214. $form->format_amount( \%myconfig, $subtotalpaid, 2, ' ' );
  2215. $column_data{class} = 'subtotal';
  2216. }
  2217. $subtotalpaid = 0;
  2218. \%column_data;
  2219. }