summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: 38da89eb9639db5ee0e83f15b3c94df5f9c84a93 (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. $form->header;
  759. RP->inventory_activity( \%myconfig, \%$form );
  760. $title = $form->escape( $form->{title} );
  761. # if ($form->{department}) {
  762. # ($department) = split /--/, $form->{department};
  763. # $options = $locale->text('Department')." : $department<br>";
  764. # $department = $form->escape($form->{department});
  765. # }
  766. ## if ($form->{projectnumber}) {
  767. # ($projectnumber) = split /--/, $form->{projectnumber};
  768. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  769. # $projectnumber = $form->escape($form->{projectnumber});
  770. # }
  771. # if there are any dates
  772. if ( $form->{fromdate} || $form->{todate} ) {
  773. if ( $form->{fromdate} ) {
  774. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  775. }
  776. if ( $form->{todate} ) {
  777. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  778. }
  779. $form->{period} = "$fromdate - $todate";
  780. }
  781. else {
  782. $form->{period} =
  783. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  784. }
  785. $options .= $form->{period};
  786. @column_index = qw(partnumber description sold revenue received expense);
  787. $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. $column_header{partnumber} = qq|
  790. <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
  791. . $locale->text('Part Number') . qq|</a></th>|;
  792. $column_header{description} = qq|
  793. <th class=listheading><a class=listheading href="$href&sort_col=description">|
  794. . $locale->text('Description') . qq|</a></th>|;
  795. $column_header{sold} = qq|
  796. <th class=listheading><a class=listheading href="$href&sort_col=sold">|
  797. . $locale->text('Sold') . qq|</a></th>|;
  798. $column_header{revenue} = qq|
  799. <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
  800. . $locale->text('Revenue') . qq|</a></th>|;
  801. $column_header{received} = qq|
  802. <th class=listheading><a class=listheading href="$href&sort_col=received">|
  803. . $locale->text('Received') . qq|</a></th>|;
  804. $column_header{expense} = qq|
  805. <th class=listheading><a class=listheading href="$href&sort_col=expense">|
  806. . $locale->text('Expense') . qq|</a></th>|;
  807. print qq|
  808. <body>
  809. <table width=100%>
  810. <tr>
  811. <th class=listtop>$form->{title}</th>
  812. </tr>
  813. <tr height="5"></tr>
  814. <tr>
  815. <td>$options</td>
  816. </tr>
  817. <tr>
  818. <td>
  819. <table width=100%>
  820. <tr>|;
  821. map { print "$column_header{$_}\n" } @column_index;
  822. print qq|
  823. </tr>
  824. |;
  825. if ( $form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue' ) {
  826. $form->{sort_type} = 'numeric';
  827. }
  828. $i = 0;
  829. $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  830. $dates =
  831. "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  832. $base =
  833. "path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  834. $form->{callback} = "rp.pl?action=continue&$base";
  835. $form->{callback} = $form->escape( $form->{callback} );
  836. $callback = "callback=$form->{callback}";
  837. # sort the whole thing by account numbers and display
  838. foreach $ref ( @{ $form->{TB} } ) {
  839. $description = $form->escape( $ref->{description} );
  840. $i = $i % 2;
  841. $pnumhref =
  842. "ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  843. $soldhref =
  844. "ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  845. $rechref =
  846. "ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  847. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  848. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  849. $credit =
  850. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  851. $begbalance =
  852. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  853. "&nbsp;" );
  854. $endbalance =
  855. $form->format_amount( \%myconfig,
  856. ( $ref->{balance} + $ref->{amount} ) * $ml,
  857. 2, "&nbsp;" );
  858. $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
  859. $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
  860. $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
  861. map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
  862. print qq|
  863. <tr class=listrow$i>
  864. |;
  865. map { print "<td>$ref->{$_}</td>\n" } @column_index;
  866. print qq|
  867. </tr>
  868. |;
  869. ++$i;
  870. }
  871. print qq|
  872. </tr>
  873. </table>
  874. </td>
  875. </tr>
  876. <tr>
  877. <td><hr size=3 noshade></td>
  878. </tr>
  879. </table>
  880. </body>
  881. </html>
  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 generate_ap_aging {
  1257. # split vendor
  1258. ( $form->{vendor} ) = split( /--/, $form->{vendor} );
  1259. $vendor = $form->escape( $form->{vendor}, 1 );
  1260. $title = $form->escape( $form->{title}, 1 );
  1261. $media = $form->escape( $form->{media}, 1 );
  1262. $form->{ct} = "vendor";
  1263. $form->{arap} = "ap";
  1264. RP->aging( \%myconfig, \%$form );
  1265. $form->{callback} =
  1266. 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}|;
  1267. &aging;
  1268. }
  1269. sub aging {
  1270. my %hiddens;
  1271. my @buttons;
  1272. my @options;
  1273. my %column_header;
  1274. my @column_index;
  1275. my %row_alignment;
  1276. $column_header{statement} = ' ';
  1277. $column_header{ct} = $locale->text( ucfirst $form->{ct} );
  1278. $column_header{language} = $locale->text('Language');
  1279. $column_header{invnumber} = $locale->text('Invoice');
  1280. $column_header{ordnumber} = $locale->text('Order');
  1281. $column_header{transdate} = $locale->text('Date');
  1282. $column_header{duedate} = $locale->text('Due Date');
  1283. $column_header{c0} = $locale->text('Current');
  1284. $column_header{c30} = '30';
  1285. $column_header{c60} = '60';
  1286. $column_header{c90} = '90';
  1287. $column_header{total} = $locale->text('Total');
  1288. @column_index = qw(statement ct);
  1289. if ( @{ $form->{all_language} } && $form->{arap} eq 'ar' ) {
  1290. push @column_index, "language";
  1291. $form->{language_options} = [];
  1292. for ( @{ $form->{all_language} } ) {
  1293. push @{$form->{language_options}},
  1294. {text => $_->{description}, value => $_->{code}};
  1295. }
  1296. }
  1297. my @c = ();
  1298. for (qw(c0 c30 c60 c90)) {
  1299. if ( $form->{$_} ) {
  1300. push @c, $_;
  1301. $form->{callback} .= "&$_=$form->{$_}";
  1302. }
  1303. }
  1304. if ( !$form->{summary} ) {
  1305. push @column_index, qw(invnumber ordnumber transdate duedate);
  1306. }
  1307. push @column_index, @c;
  1308. push @column_index, "total";
  1309. if ( $form->{overdue} ) {
  1310. push @options, $locale->text('Aged Overdue');
  1311. $form->{callback} .= "&overdue=$form->{overdue}";
  1312. } else {
  1313. push @options, $locale->text('Aged');
  1314. }
  1315. if ( $form->{department} ) {
  1316. ($department) = split /--/, $form->{department};
  1317. push @options, $locale->text('Department: [_1]', $department);
  1318. $department = $form->escape( $form->{department}, 1 );
  1319. $form->{callback} .= "&department=$department";
  1320. }
  1321. if ( $form->{arap} eq 'ar' ) {
  1322. if ( $form->{customer} ) {
  1323. push @options, $form->{customer};
  1324. }
  1325. }
  1326. if ( $form->{arap} eq 'ap' ) {
  1327. shift @column_index;
  1328. if ( $form->{vendor} ) {
  1329. push @options, $form->{vendor};
  1330. }
  1331. }
  1332. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1333. push @options, $locale->text('for Period To [_1]', $todate);
  1334. $ctid = 0;
  1335. $i = 0;
  1336. $k = 0;
  1337. $l = $#{ $form->{AG} };
  1338. my @currencies;
  1339. foreach my $ref ( @{ $form->{AG} } ) {
  1340. if ( $curr ne $ref->{curr} ) {
  1341. my %column_data;
  1342. $ctid = 0;
  1343. for (@column_index) { $column_data{$_} = ' ' }
  1344. if ($curr) {
  1345. $c0total = $form->format_amount(\%myconfig, $c0total, 2, ' ');
  1346. $c30total = $form->format_amount(\%myconfig, $c30total, 2, ' ');
  1347. $c60total = $form->format_amount(\%myconfig, $c60total, 2, ' ');
  1348. $c90total = $form->format_amount(\%myconfig, $c90total, 2, ' ');
  1349. $total = $form->format_amount(\%myconfig, $total, 2, ' ' );
  1350. for (qw(ct statement language)) {
  1351. $column_data{$_} = ' ';
  1352. }
  1353. $column_data{c0} = $c0total;
  1354. $column_data{c30} = $c30total;
  1355. $column_data{c60} = $c60total;
  1356. $column_data{c90} = $c90total;
  1357. $column_data{total} = $total;
  1358. push @{$currencies[0]{totals}}, \%column_data;
  1359. $c0subtotal = 0;
  1360. $c30subtotal = 0;
  1361. $c60subtotal = 0;
  1362. $c90subtotal = 0;
  1363. $subtotal = 0;
  1364. $c0total = 0;
  1365. $c30total = 0;
  1366. $c60total = 0;
  1367. $c90total = 0;
  1368. $total = 0;
  1369. }
  1370. push @currencies, {};
  1371. $curr = $ref->{curr};
  1372. $currencies[0]{curr} = $curr;
  1373. }
  1374. $k++;
  1375. my %column_data;
  1376. if ( $ctid != $ref->{ctid} ) {
  1377. $i++;
  1378. $column_data{ct} = $ref->{name};
  1379. $column_data{language} = {
  1380. name => "language_code_$i",
  1381. options => $form->{language_options},
  1382. default_value => $ref->{language_code},
  1383. } if $form->{language_options};
  1384. $column_data{statement} = {
  1385. name => "statement_$i",
  1386. type => 'checkbox',
  1387. value => '1',
  1388. };
  1389. $column_data{statement}{checked} = 'checked' if $ref->{checked};
  1390. $hiddens{"$form->{ct}_id_$i"} = $ref->{ctid};
  1391. $hiddens{"curr_$i"} = $ref->{curr};
  1392. }
  1393. $ctid = $ref->{ctid};
  1394. for (qw(c0 c30 c60 c90)) {
  1395. $ref->{$_} =
  1396. $form->round_amount( $ref->{$_} / $ref->{exchangerate}, 2 );
  1397. }
  1398. $c0subtotal += $ref->{c0};
  1399. $c30subtotal += $ref->{c30};
  1400. $c60subtotal += $ref->{c60};
  1401. $c90subtotal += $ref->{c90};
  1402. $c0total += $ref->{c0};
  1403. $c30total += $ref->{c30};
  1404. $c60total += $ref->{c60};
  1405. $c90total += $ref->{c90};
  1406. $ref->{total} =
  1407. ( $ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90} );
  1408. $subtotal += $ref->{total};
  1409. $total += $ref->{total};
  1410. $ref->{c0} =
  1411. $form->format_amount( \%myconfig, $ref->{c0}, 2, ' ' );
  1412. $ref->{c30} =
  1413. $form->format_amount( \%myconfig, $ref->{c30}, 2, ' ' );
  1414. $ref->{c60} =
  1415. $form->format_amount( \%myconfig, $ref->{c60}, 2, ' ' );
  1416. $ref->{c90} =
  1417. $form->format_amount( \%myconfig, $ref->{c90}, 2, ' ' );
  1418. $ref->{total} =
  1419. $form->format_amount( \%myconfig, $ref->{total}, 2, ' ' );
  1420. $href =
  1421. qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|
  1422. . $form->escape( $form->{callback} );
  1423. $column_data{invnumber} = {text => $ref->{invnumber}, href => $href};
  1424. for (qw(c0 c30 c60 c90 total ordnumber transdate duedate)) {
  1425. $column_data{$_} = $ref->{$_};
  1426. }
  1427. if ( !$form->{summary} ) {
  1428. $j++;
  1429. $j %= 2;
  1430. $column_data{i} = $j;
  1431. push @{$currencies[0]{rows}}, \%column_data;
  1432. for (qw(ct statement language)) {
  1433. $column_data{$_} = ' ';
  1434. }
  1435. }
  1436. # prepare subtotal
  1437. $nextid = ( $k <= $l ) ? $form->{AG}->[$k]->{ctid} : 0;
  1438. if ( $ctid != $nextid ) {
  1439. $c0subtotal =
  1440. $form->format_amount( \%myconfig, $c0subtotal, 2, ' ' );
  1441. $c30subtotal =
  1442. $form->format_amount( \%myconfig, $c30subtotal, 2, ' ' );
  1443. $c60subtotal =
  1444. $form->format_amount( \%myconfig, $c60subtotal, 2, ' ' );
  1445. $c90subtotal =
  1446. $form->format_amount( \%myconfig, $c90subtotal, 2, ' ' );
  1447. $subtotal =
  1448. $form->format_amount( \%myconfig, $subtotal, 2, ' ' );
  1449. if ( $form->{summary} ) {
  1450. $column_data{c0} = $c0subtotal;
  1451. $column_data{c30} = $c30subtotal;
  1452. $column_data{c60} = $c60subtotal;
  1453. $column_data{c90} = $c90subtotal;
  1454. $column_data{total} = $subtotal;
  1455. $j++;
  1456. $j %= 2;
  1457. $column_data{i} = $j;
  1458. push @{$currencies[0]{rows}}, \%column_data;
  1459. } else {
  1460. for (@column_index) { $column_data{$_} = ' ' }
  1461. $column_data{c0} = $c0subtotal;
  1462. $column_data{c30} = $c30subtotal;
  1463. $column_data{c60} = $c60subtotal;
  1464. $column_data{c90} = $c90subtotal;
  1465. $column_data{total} = $subtotal;
  1466. $column_data{class} = 'subtotal';
  1467. push @{$currencies[0]{rows}}, \%column_data;
  1468. }
  1469. $c0subtotal = 0;
  1470. $c30subtotal = 0;
  1471. $c60subtotal = 0;
  1472. $c90subtotal = 0;
  1473. $subtotal = 0;
  1474. }
  1475. }
  1476. my %column_data;
  1477. for (@column_index) { $column_data{$_} = ' ' }
  1478. $c0total = $form->format_amount( \%myconfig, $c0total, 2, ' ' );
  1479. $c30total = $form->format_amount( \%myconfig, $c30total, 2, ' ' );
  1480. $c60total = $form->format_amount( \%myconfig, $c60total, 2, ' ' );
  1481. $c90total = $form->format_amount( \%myconfig, $c90total, 2, ' ' );
  1482. $total = $form->format_amount( \%myconfig, $total, 2, ' ' );
  1483. $column_data{c0} = $c0total;
  1484. $column_data{c30} = $c30total;
  1485. $column_data{c60} = $c60total;
  1486. $column_data{c90} = $c90total;
  1487. $column_data{total} = $total;
  1488. $currencies[0]{total} = \%column_data;
  1489. $row_alignment{c0} = 'right';
  1490. $row_alignment{c30} = 'right';
  1491. $row_alignment{c60} = 'right';
  1492. $row_alignment{c90} = 'right';
  1493. $row_alignment{total} = 'right';
  1494. $hiddens{rowcount} = $i;
  1495. &print_options if ( $form->{arap} eq 'ar' );
  1496. my @buttons;
  1497. if ( $form->{arap} eq 'ar' ) {
  1498. $hiddens{$_} = $form->{$_} foreach qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid);
  1499. $hiddens{$form->{ct}} = $form->{$form->{ct}};
  1500. # type=submit $locale->text('Select all')
  1501. # type=submit $locale->text('Print')
  1502. # type=submit $locale->text('E-mail')
  1503. my %button = (
  1504. 'select_all' =>
  1505. { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1506. 'print' =>
  1507. { ndx => 2, key => 'P', value => $locale->text('Print') },
  1508. 'e_mail' =>
  1509. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1510. );
  1511. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1512. {
  1513. push @buttons, {
  1514. accesskey => $button{$_}->{key},
  1515. text => $button{$_}->{value},
  1516. title => "$button{$_}->{value} [Alt-$button{$_}->{key}]",
  1517. value => $_,
  1518. name => 'action',
  1519. };
  1520. }
  1521. }
  1522. ##SC: Temporary commenting
  1523. ## if ( $form->{lynx} ) {
  1524. ## require "bin/menu.pl";
  1525. ## &menubar;
  1526. ## }
  1527. for my $type (qw(CSV XLS ODS)) {
  1528. push @buttons, {
  1529. name => 'action',
  1530. value => lc "${type}_$form->{nextsub}",
  1531. text => $locale->text("$type Report"),
  1532. type => 'submit',
  1533. class => 'submit',
  1534. };
  1535. }
  1536. my $format;
  1537. if ($form->{action} eq 'continue') {
  1538. $format = 'HTML';
  1539. } else {
  1540. $format = uc substr $form->{action}, 0, 3;
  1541. push @column_index, 'class';
  1542. $column_header{class} = 'rowtype';
  1543. }
  1544. my $template = LedgerSMB::Template->new(
  1545. user => \%myconfig,
  1546. locale => $locale,
  1547. template => 'rp-aging',
  1548. path => 'UI',
  1549. format => $format,
  1550. );
  1551. $template->render({
  1552. form => $form,
  1553. hiddens => \%hiddens,
  1554. buttons => \@buttons,
  1555. options => \@options,
  1556. columns => \@column_index,
  1557. heading => \%column_header,
  1558. currencies => [reverse @currencies],
  1559. row_alignment => {
  1560. 'credit' => 'right',
  1561. 'debit' => 'right',
  1562. 'begbalance' => 'right',
  1563. 'endbalance' => 'right'
  1564. },
  1565. });
  1566. }
  1567. sub select_all {
  1568. RP->aging( \%myconfig, \%$form );
  1569. for ( @{ $form->{AG} } ) { $_->{checked} = "checked" }
  1570. &aging;
  1571. }
  1572. sub print_options {
  1573. $form->{sendmode} = "attachment";
  1574. $form->{copies} = 1 unless $form->{copies};
  1575. $form->{print}{format} = {name => 'format', default_values => $form->{format}};
  1576. $form->{print}{template} = {name => 'type', default_values => $form->{type}};
  1577. my @formats = ();
  1578. my @media = ();
  1579. my @templates = ();
  1580. push @formats, {text => 'HTML', value => 'html'};
  1581. push @templates, {text => $locale->text('Statement'), value => 'statement'};
  1582. if ( $form->{media} eq 'email' ) {
  1583. $form->{print}{medium} = {name => 'sendmode', default_values => $form->{sendmode}};
  1584. push @media, {text => $locale->text('Attachement'), value => 'attachement'};
  1585. push @media, {text => $locale->text('In-line'), value => 'inline'};
  1586. if ($form->{SM}{attachment}) {
  1587. $form->{print}{medium}{default_values} = $form->{SM}{attachment};
  1588. } elsif ($form->{SM}{inline}) {
  1589. $form->{print}{medium}{default_values} = $form->{SM}{inline};
  1590. }
  1591. } else {
  1592. $form->{print}{medium} = {name => 'media'};
  1593. push @media, {text => $locale->text('Screen'), value => 'screen'};
  1594. if ( %{LedgerSMB::Sysconfig::printer}
  1595. && ${LedgerSMB::Sysconfig::latex} )
  1596. {
  1597. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1598. push @media, {text => $_, value => $_};
  1599. }
  1600. }
  1601. }
  1602. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1603. push @formats, {text => $locale->text('PDF'), value => 'pdf'};
  1604. push @formats, {text => $locale->text('Postscript'), value => 'ps'};
  1605. }
  1606. if ( %{LedgerSMB::Sysconfig::printer}
  1607. && ${LedgerSMB::Sysconfig::latex}
  1608. && $form->{media} ne 'email' )
  1609. {
  1610. $form->{print}{copies} = {
  1611. label => $locale->text('Copies'),
  1612. name => 'copies',
  1613. value => $form->{copies},
  1614. size => 2,
  1615. };
  1616. }
  1617. $form->{print}{template}{options} = \@templates;
  1618. $form->{print}{format}{options} = \@formats;
  1619. $form->{print}{medium}{options} = \@media;
  1620. }
  1621. sub e_mail {
  1622. my %hiddens;
  1623. # get name and email addresses
  1624. for $i ( 1 .. $form->{rowcount} ) {
  1625. if ( $form->{"statement_$i"} ) {
  1626. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1627. $form->{"statement_1"} = 1;
  1628. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1629. $form->{"curr_1"} = $form->{"curr_$i"};
  1630. RP->get_customer( \%myconfig, \%$form );
  1631. $selected = 1;
  1632. last;
  1633. }
  1634. }
  1635. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1636. $form->{media} = "email";
  1637. &print_options;
  1638. for (qw(email cc bcc subject message type sendmode format action nextsub)) {
  1639. delete $form->{$_};
  1640. }
  1641. for (keys %$form) {
  1642. $hiddens{$_} = $form->{$_} unless ref $form->{$_};
  1643. }
  1644. my @buttons = ({
  1645. name => 'action',
  1646. value => 'send_email',
  1647. text => $locale->text('Continue'),
  1648. });
  1649. my $template = LedgerSMB::Template->new_UI(
  1650. user => \%myconfig,
  1651. locale => $locale,
  1652. template => 'rp-email',
  1653. );
  1654. $template->render({
  1655. form => $form,
  1656. user => \%myconfig,
  1657. hiddens => \%hiddens,
  1658. buttons => \@buttons,
  1659. });
  1660. }
  1661. sub send_email {
  1662. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1663. $form->{printmode} = '|-';
  1664. $form->{subject} = $locale->text( 'Statement - [_1]', $form->{todate} )
  1665. unless $form->{subject};
  1666. $form->isblank( "email", $locale->text('E-mail address missing!') );
  1667. RP->aging( \%myconfig, \%$form );
  1668. &print_form;
  1669. $form->redirect(
  1670. $locale->text( 'Statement sent to [_1]', $form->{ $form->{ct} } ) );
  1671. }
  1672. sub print {
  1673. if ( $form->{media} !~ /(screen|email)/ ) {
  1674. $form->error( $locale->text('Select postscript or PDF!') )
  1675. if ( $form->{format} !~ /(postscript|pdf)/ );
  1676. }
  1677. my @batch_data = ();
  1678. for $i ( 1 .. $form->{rowcount} ) {
  1679. if ( $form->{"statement_$i"} ) {
  1680. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1681. $language_code = $form->{"language_code_$i"};
  1682. $curr = $form->{"curr_$i"};
  1683. $selected = 1;
  1684. if ( $form->{media} !~ /(screen|email)/ ) {
  1685. # SC: I may not need this anymore...
  1686. # But I'll wait until lpr output is working before deciding
  1687. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  1688. $form->{"$form->{ct}_id"} = "";
  1689. $SIG{INT} = 'IGNORE';
  1690. }
  1691. else {
  1692. $form->{"statement_1"} = 1;
  1693. $form->{"language_code_1"} = $language_code;
  1694. $form->{"curr_1"} = $curr;
  1695. }
  1696. RP->aging( \%myconfig, \%$form );
  1697. $printhash = &print_form;
  1698. push @batch_data, $printhash;
  1699. }
  1700. }
  1701. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1702. my $template = LedgerSMB::Template->new(
  1703. user => \%myconfig,
  1704. template => $form->{'formname'} || $form->{'type'},
  1705. format => uc $form->{format}
  1706. );
  1707. try {
  1708. $template->render({data => \@batch_data});
  1709. $template->output($form);
  1710. }
  1711. catch Error::Simple with {
  1712. my $E = shift;
  1713. $form->error( $E->stacktrace );
  1714. };
  1715. $form->redirect( $locale->text('Statements sent to printer!') )
  1716. if ( $form->{media} !~ /(screen|email)/ );
  1717. }
  1718. sub print_form {
  1719. $form->{statementdate} = $locale->date( \%myconfig, $form->{todate}, 1 );
  1720. $form->{templates} = "$myconfig{templates}";
  1721. # setup variables for the form
  1722. @a = qw(company address businessnumber tel fax);
  1723. for (@a) { $form->{$_} = $myconfig{$_} }
  1724. $form->{address} =~ s/\\n/\n/g;
  1725. $form->format_string(@a);
  1726. $form->{IN} = "$form->{type}.html";
  1727. if ( $form->{format} eq 'postscript' ) {
  1728. $form->{IN} =~ s/html$/tex/;
  1729. }
  1730. if ( $form->{format} eq 'pdf' ) {
  1731. $form->{IN} =~ s/html$/tex/;
  1732. }
  1733. @a = qw(name address1 address2 city state zipcode country contact);
  1734. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1735. push @a, 'email' if !$form->{media} eq 'email';
  1736. $i = 0;
  1737. while ( @{ $form->{AG} } ) {
  1738. $ref = shift @{ $form->{AG} };
  1739. if ( $ctid != $ref->{ctid} ) {
  1740. $ctid = $ref->{ctid};
  1741. $i++;
  1742. if ( $form->{"statement_$i"} ) {
  1743. for (@a) { $form->{$_} = $ref->{$_} }
  1744. $form->format_string(@a);
  1745. $form->{ $form->{ct} } = $form->{name};
  1746. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1747. $form->{language_code} = $form->{"language_code_$i"};
  1748. $form->{currency} = $form->{"curr_$i"};
  1749. for (qw(invnumber ordnumber ponumber notes invdate duedate)) {
  1750. $form->{$_} = ();
  1751. }
  1752. $form->{total} = 0;
  1753. foreach $item (qw(c0 c30 c60 c90)) {
  1754. $form->{$item} = ();
  1755. $form->{"${item}total"} = 0;
  1756. }
  1757. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1758. while ($ref) {
  1759. if ( scalar( @{ $form->{AG} } ) > 0 ) {
  1760. # one or more left to go
  1761. if ( $ctid == $form->{AG}->[0]->{ctid} ) {
  1762. $ref = shift @{ $form->{AG} };
  1763. &statement_details($ref)
  1764. if $ref->{curr} eq $form->{currency};
  1765. # any more?
  1766. $ref = scalar( @{ $form->{AG} } );
  1767. }
  1768. else {
  1769. $ref = 0;
  1770. }
  1771. }
  1772. else {
  1773. # set initial ref to 0
  1774. $ref = 0;
  1775. }
  1776. }
  1777. for ( "c0", "c30", "c60", "c90", "" ) {
  1778. $form->{"${_}total"} =
  1779. $form->format_amount( \%myconfig, $form->{"${_}total"},
  1780. 2 );
  1781. }
  1782. my $printhash = {};
  1783. for (keys %$form) { $printhash->{$_} = $form->{$_}}
  1784. return $printhash;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. sub statement_details {
  1790. my ($ref) = @_;
  1791. $ref->{invdate} = $ref->{transdate};
  1792. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1793. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1794. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1795. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1796. foreach $item (qw(c0 c30 c60 c90)) {
  1797. eval {
  1798. $ref->{$item} =
  1799. $form->round_amount( $ref->{$item} / $ref->{exchangerate}, 2 );
  1800. };
  1801. $form->{"${item}total"} += $ref->{$item};
  1802. $form->{total} += $ref->{$item};
  1803. push @{ $form->{$item} },
  1804. $form->format_amount( \%myconfig, $ref->{$item}, 2 );
  1805. }
  1806. }
  1807. sub generate_tax_report {
  1808. RP->tax_report( \%myconfig, \%$form );
  1809. $descvar = "$form->{accno}_description";
  1810. $description = $form->escape( $form->{$descvar} );
  1811. $ratevar = "$form->{accno}_rate";
  1812. $taxrate = $form->{"$form->{accno}_rate"};
  1813. if ( $form->{accno} =~ /^gifi_/ ) {
  1814. $descvar = "gifi_$form->{accno}_description";
  1815. $description = $form->escape( $form->{$descvar} );
  1816. $ratevar = "gifi_$form->{accno}_rate";
  1817. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1818. }
  1819. $department = $form->escape( $form->{department} );
  1820. # construct href
  1821. $href =
  1822. "$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}";
  1823. # construct callback
  1824. $description = $form->escape( $form->{$descvar}, 1 );
  1825. $department = $form->escape( $form->{department}, 1 );
  1826. $form->sort_order();
  1827. $callback =
  1828. "$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}";
  1829. $form->{title} = $locale->text('GIFI') . " - "
  1830. if ( $form->{accno} =~ /^gifi_/ );
  1831. $title = $form->escape( $form->{title} );
  1832. $href .= "&title=$title";
  1833. $title = $form->escape( $form->{title}, 1 );
  1834. $callback .= "&title=$title";
  1835. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1836. @columns =
  1837. $form->sort_columns(
  1838. qw(id transdate invnumber name description netamount tax total));
  1839. $form->{"l_description"} = "" if $form->{summary};
  1840. foreach $item (@columns) {
  1841. if ( $form->{"l_$item"} eq "Y" ) {
  1842. push @column_index, $item;
  1843. # add column to href and callback
  1844. $callback .= "&l_$item=Y";
  1845. $href .= "&l_$item=Y";
  1846. }
  1847. }
  1848. if ( $form->{l_subtotal} eq 'Y' ) {
  1849. $callback .= "&l_subtotal=Y";
  1850. $href .= "&l_subtotal=Y";
  1851. }
  1852. if ( $form->{department} ) {
  1853. ($department) = split /--/, $form->{department};
  1854. $option = $locale->text('Department') . " : $department";
  1855. }
  1856. # if there are any dates
  1857. if ( $form->{fromdate} || $form->{todate} ) {
  1858. if ( $form->{fromdate} ) {
  1859. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1860. }
  1861. if ( $form->{todate} ) {
  1862. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1863. }
  1864. $form->{period} = "$fromdate - $todate";
  1865. }
  1866. else {
  1867. $form->{period} =
  1868. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1869. }
  1870. if ( $form->{db} eq 'ar' ) {
  1871. $name = $locale->text('Customer');
  1872. $invoice = 'is.pl';
  1873. $arap = 'ar.pl';
  1874. }
  1875. if ( $form->{db} eq 'ap' ) {
  1876. $name = $locale->text('Vendor');
  1877. $invoice = 'ir.pl';
  1878. $arap = 'ap.pl';
  1879. }
  1880. $option .= "<br>" if $option;
  1881. $option .= "$form->{period}";
  1882. $column_header{id} =
  1883. qq|<th><a class=listheading href=$href&sort=id>|
  1884. . $locale->text('ID')
  1885. . qq|</th>|;
  1886. $column_header{invnumber} =
  1887. qq|<th><a class=listheading href=$href&sort=invnumber>|
  1888. . $locale->text('Invoice')
  1889. . qq|</th>|;
  1890. $column_header{transdate} =
  1891. qq|<th><a class=listheading href=$href&sort=transdate>|
  1892. . $locale->text('Date')
  1893. . qq|</th>|;
  1894. $column_header{netamount} =
  1895. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  1896. $column_header{tax} =
  1897. qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
  1898. $column_header{total} =
  1899. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  1900. $column_header{name} =
  1901. qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  1902. $column_header{description} =
  1903. qq|<th><a class=listheading href=$href&sort=description>|
  1904. . $locale->text('Description')
  1905. . qq|</th>|;
  1906. $form->header;
  1907. print qq|
  1908. <body>
  1909. <table width=100%>
  1910. <tr>
  1911. <th class=listtop colspan=$colspan>$form->{title}</th>
  1912. </tr>
  1913. <tr height="5"></tr>
  1914. <tr>
  1915. <td>$option</td>
  1916. </tr>
  1917. <tr>
  1918. <td>
  1919. <table width=100%>
  1920. <tr class=listheading>
  1921. |;
  1922. for (@column_index) { print "$column_header{$_}\n" }
  1923. print qq|
  1924. </tr>
  1925. |;
  1926. # add sort and escape callback
  1927. $callback = $form->escape( $callback . "&sort=$form->{sort}" );
  1928. if ( @{ $form->{TR} } ) {
  1929. $sameitem = $form->{TR}->[0]->{ $form->{sort} };
  1930. }
  1931. foreach $ref ( @{ $form->{TR} } ) {
  1932. $module = ( $ref->{invoice} ) ? $invoice : $arap;
  1933. $module = 'ps.pl' if $ref->{till};
  1934. if ( $form->{l_subtotal} eq 'Y' ) {
  1935. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1936. &tax_subtotal;
  1937. $sameitem = $ref->{ $form->{sort} };
  1938. }
  1939. }
  1940. $totalnetamount += $ref->{netamount};
  1941. $totaltax += $ref->{tax};
  1942. $ref->{total} = $ref->{netamount} + $ref->{tax};
  1943. $subtotalnetamount += $ref->{netamount};
  1944. $subtotaltax += $ref->{tax};
  1945. for (qw(netamount tax total)) {
  1946. $ref->{$_} =
  1947. $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" );
  1948. }
  1949. $column_data{id} = qq|<td>$ref->{id}</td>|;
  1950. $column_data{invnumber} =
  1951. qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|;
  1952. for (qw(id transdate name partnumber description)) {
  1953. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  1954. }
  1955. for (qw(netamount tax total)) {
  1956. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  1957. }
  1958. $i++;
  1959. $i %= 2;
  1960. print qq|
  1961. <tr class=listrow$i>
  1962. |;
  1963. for (@column_index) { print "$column_data{$_}\n" }
  1964. print qq|
  1965. </tr>
  1966. |;
  1967. }
  1968. if ( $form->{l_subtotal} eq 'Y' ) {
  1969. &tax_subtotal;
  1970. }
  1971. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1972. print qq|
  1973. </tr>
  1974. <tr class=listtotal>
  1975. |;
  1976. $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax,
  1977. 2, "&nbsp;" );
  1978. $totalnetamount =
  1979. $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" );
  1980. $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, "&nbsp;" );
  1981. $column_data{netamount} =
  1982. qq|<th class=listtotal align=right>$totalnetamount</th>|;
  1983. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  1984. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  1985. for (@column_index) { print "$column_data{$_}\n" }
  1986. print qq|
  1987. </tr>
  1988. </table>
  1989. </td>
  1990. </tr>
  1991. <tr>
  1992. <td><hr size=3 noshade></td>
  1993. </tr>
  1994. </table>
  1995. </body>
  1996. </html>
  1997. |;
  1998. }
  1999. sub tax_subtotal {
  2000. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2001. $subtotal =
  2002. $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax,
  2003. 2, "&nbsp;" );
  2004. $subtotalnetamount =
  2005. $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" );
  2006. $subtotaltax =
  2007. $form->format_amount( \%myconfig, $subtotaltax, 2, "&nbsp;" );
  2008. $column_data{netamount} =
  2009. "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  2010. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  2011. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  2012. $subtotalnetamount = 0;
  2013. $subtotaltax = 0;
  2014. print qq|
  2015. <tr class=listsubtotal>
  2016. |;
  2017. for (@column_index) { print "\n$column_data{$_}" }
  2018. print qq|
  2019. </tr>
  2020. |;
  2021. }
  2022. sub list_payments {
  2023. if ( $form->{account} ) {
  2024. ( $form->{paymentaccounts} ) = split /--/, $form->{account};
  2025. }
  2026. if ( $form->{department} ) {
  2027. ( $department, $form->{department_id} ) = split /--/,
  2028. $form->{department};
  2029. $option = $locale->text('Department') . " : $department";
  2030. }
  2031. RP->payments( \%myconfig, \%$form );
  2032. @columns = $form->sort_columns(qw(transdate name paid source memo));
  2033. if ( $form->{till} ) {
  2034. @columns =
  2035. $form->sort_columns(qw(transdate name paid curr source till));
  2036. if ( $myconfig{role} ne 'user' ) {
  2037. @columns =
  2038. $form->sort_columns(
  2039. qw(transdate name paid curr source till employee));
  2040. }
  2041. }
  2042. # construct href
  2043. $title = $form->escape( $form->{title} );
  2044. $form->{paymentaccounts} =~ s/ /%20/g;
  2045. $href =
  2046. "$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="
  2047. . $form->escape( $form->{title} );
  2048. $form->sort_order();
  2049. $form->{callback} =
  2050. "$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="
  2051. . $form->escape( $form->{title}, 1 );
  2052. if ( $form->{account} ) {
  2053. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  2054. $href .= "&account=" . $form->escape( $form->{account} );
  2055. $option .= "\n<br>" if ($option);
  2056. $option .= $locale->text('Account') . " : $form->{account}";
  2057. }
  2058. if ( $form->{department} ) {
  2059. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  2060. $href .= "&department=" . $form->escape( $form->{department} );
  2061. $option .= "\n<br>" if ($option);
  2062. $option .= $locale->text('Department') . " : $form->{department}";
  2063. }
  2064. if ( $form->{description} ) {
  2065. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  2066. $href .= "&description=" . $form->escape( $form->{description} );
  2067. $option .= "\n<br>" if ($option);
  2068. $option .= $locale->text('Description') . " : $form->{description}";
  2069. }
  2070. if ( $form->{source} ) {
  2071. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  2072. $href .= "&source=" . $form->escape( $form->{source} );
  2073. $option .= "\n<br>" if ($option);
  2074. $option .= $locale->text('Source') . " : $form->{source}";
  2075. }
  2076. if ( $form->{memo} ) {
  2077. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  2078. $href .= "&memo=" . $form->escape( $form->{memo} );
  2079. $option .= "\n<br>" if ($option);
  2080. $option .= $locale->text('Memo') . " : $form->{memo}";
  2081. }
  2082. if ( $form->{fromdate} ) {
  2083. $option .= "\n<br>" if ($option);
  2084. $option .=
  2085. $locale->text('From') . "&nbsp;"
  2086. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  2087. }
  2088. if ( $form->{todate} ) {
  2089. $option .= "\n<br>" if ($option);
  2090. $option .=
  2091. $locale->text('To') . "&nbsp;"
  2092. . $locale->date( \%myconfig, $form->{todate}, 1 );
  2093. }
  2094. $callback = $form->escape( $form->{callback} );
  2095. $column_header{name} =
  2096. "<th><a class=listheading href=$href&sort=name>"
  2097. . $locale->text('Description')
  2098. . "</a></th>";
  2099. $column_header{transdate} =
  2100. "<th><a class=listheading href=$href&sort=transdate>"
  2101. . $locale->text('Date')
  2102. . "</a></th>";
  2103. $column_header{paid} =
  2104. "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
  2105. $column_header{curr} =
  2106. "<th class=listheading>" . $locale->text('Curr') . "</a></th>";
  2107. $column_header{source} =
  2108. "<th><a class=listheading href=$href&sort=source>"
  2109. . $locale->text('Source')
  2110. . "</a></th>";
  2111. $column_header{memo} =
  2112. "<th><a class=listheading href=$href&sort=memo>"
  2113. . $locale->text('Memo')
  2114. . "</a></th>";
  2115. $column_header{employee} =
  2116. "<th><a class=listheading href=$href&sort=employee>"
  2117. . $locale->text('Salesperson')
  2118. . "</a></th>";
  2119. $column_header{till} =
  2120. "<th><a class=listheading href=$href&sort=till>"
  2121. . $locale->text('Till')
  2122. . "</a></th>";
  2123. @column_index = @columns;
  2124. $colspan = $#column_index + 1;
  2125. $form->header;
  2126. print qq|
  2127. <body>
  2128. <table width=100%>
  2129. <tr>
  2130. <th class=listtop>$form->{title}</th>
  2131. </tr>
  2132. <tr height="5"></tr>
  2133. <tr>
  2134. <td>$option</td>
  2135. </tr>
  2136. <tr>
  2137. <td>
  2138. <table width=100%>
  2139. <tr class=listheading>
  2140. |;
  2141. for (@column_index) { print "\n$column_header{$_}" }
  2142. print qq|
  2143. </tr>
  2144. |;
  2145. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) {
  2146. next unless @{ $form->{ $ref->{id} } };
  2147. print qq|
  2148. <tr>
  2149. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  2150. </tr>
  2151. |;
  2152. if ( @{ $form->{ $ref->{id} } } ) {
  2153. $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} };
  2154. }
  2155. foreach $payment ( @{ $form->{ $ref->{id} } } ) {
  2156. if ( $form->{l_subtotal} ) {
  2157. if ( $payment->{ $form->{sort} } ne $sameitem ) {
  2158. # print subtotal
  2159. &payment_subtotal;
  2160. }
  2161. }
  2162. next if ( $form->{till} && !$payment->{till} );
  2163. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  2164. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  2165. $column_data{paid} =
  2166. "<td align=right>"
  2167. . $form->format_amount( \%myconfig, $payment->{paid}, 2,
  2168. "&nbsp;" )
  2169. . "</td>";
  2170. $column_data{curr} = "<td>$payment->{curr}</td>";
  2171. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  2172. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  2173. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  2174. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  2175. $subtotalpaid += $payment->{paid};
  2176. $accounttotalpaid += $payment->{paid};
  2177. $totalpaid += $payment->{paid};
  2178. $i++;
  2179. $i %= 2;
  2180. print qq|
  2181. <tr class=listrow$i>
  2182. |;
  2183. for (@column_index) { print "\n$column_data{$_}" }
  2184. print qq|
  2185. </tr>
  2186. |;
  2187. $sameitem = $payment->{ $form->{sort} };
  2188. }
  2189. &payment_subtotal if $form->{l_subtotal};
  2190. # print account totals
  2191. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2192. $column_data{paid} =
  2193. "<th class=listtotal align=right>"
  2194. . $form->format_amount( \%myconfig, $accounttotalpaid, 2, "&nbsp;" )
  2195. . "</th>";
  2196. print qq|
  2197. <tr class=listtotal>
  2198. |;
  2199. for (@column_index) { print "\n$column_data{$_}" }
  2200. print qq|
  2201. </tr>
  2202. |;
  2203. $accounttotalpaid = 0;
  2204. }
  2205. # print total
  2206. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2207. $column_data{paid} =
  2208. "<th class=listtotal align=right>"
  2209. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  2210. print qq|
  2211. <tr class=listtotal>
  2212. |;
  2213. for (@column_index) { print "\n$column_data{$_}" }
  2214. print qq|
  2215. </tr>
  2216. </table>
  2217. </td>
  2218. </tr>
  2219. <tr>
  2220. <td><hr size=3 noshade></td>
  2221. </tr>
  2222. </table>
  2223. |;
  2224. if ( $form->{lynx} ) {
  2225. require "bin/menu.pl";
  2226. &menubar;
  2227. }
  2228. print qq|
  2229. </body>
  2230. </html>
  2231. |;
  2232. }
  2233. sub payment_subtotal {
  2234. if ( $subtotalpaid != 0 ) {
  2235. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2236. $column_data{paid} =
  2237. "<th class=listsubtotal align=right>"
  2238. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  2239. . "</th>";
  2240. print qq|
  2241. <tr class=listsubtotal>
  2242. |;
  2243. for (@column_index) { print "\n$column_data{$_}" }
  2244. print qq|
  2245. </tr>
  2246. |;
  2247. }
  2248. $subtotalpaid = 0;
  2249. }