summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: 1cd178ad138c9a8f2320ecb57268a81e64474df9 (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. print qq|
  729. $gifi
  730. </table>
  731. </td>
  732. </tr>
  733. <tr>
  734. <td><hr size=3 noshade></td>
  735. </tr>
  736. </table>
  737. <br>
  738. <input type="hidden" name="path" value="$form->{path}">
  739. <input type="hidden" name="login" value="$form->{login}">
  740. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  741. <button type="submit" class="submit" name="action" value="continue">|
  742. . $locale->text('Continue')
  743. . qq|</button>
  744. </form>
  745. |;
  746. if ( $form->{lynx} ) {
  747. require "bin/menu.pl";
  748. &menubar;
  749. }
  750. print qq|
  751. </body>
  752. </html>
  753. |;
  754. }
  755. sub continue { &{ $form->{nextsub} } }
  756. sub generate_inv_activity {
  757. $form->header;
  758. RP->inventory_activity( \%myconfig, \%$form );
  759. $title = $form->escape( $form->{title} );
  760. # if ($form->{department}) {
  761. # ($department) = split /--/, $form->{department};
  762. # $options = $locale->text('Department')." : $department<br>";
  763. # $department = $form->escape($form->{department});
  764. # }
  765. ## if ($form->{projectnumber}) {
  766. # ($projectnumber) = split /--/, $form->{projectnumber};
  767. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  768. # $projectnumber = $form->escape($form->{projectnumber});
  769. # }
  770. # if there are any dates
  771. if ( $form->{fromdate} || $form->{todate} ) {
  772. if ( $form->{fromdate} ) {
  773. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  774. }
  775. if ( $form->{todate} ) {
  776. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  777. }
  778. $form->{period} = "$fromdate - $todate";
  779. }
  780. else {
  781. $form->{period} =
  782. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  783. }
  784. $options .= $form->{period};
  785. @column_index = qw(partnumber description sold revenue received expense);
  786. $href =
  787. 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}|;
  788. $column_header{partnumber} = qq|
  789. <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
  790. . $locale->text('Part Number') . qq|</a></th>|;
  791. $column_header{description} = qq|
  792. <th class=listheading><a class=listheading href="$href&sort_col=description">|
  793. . $locale->text('Description') . qq|</a></th>|;
  794. $column_header{sold} = qq|
  795. <th class=listheading><a class=listheading href="$href&sort_col=sold">|
  796. . $locale->text('Sold') . qq|</a></th>|;
  797. $column_header{revenue} = qq|
  798. <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
  799. . $locale->text('Revenue') . qq|</a></th>|;
  800. $column_header{received} = qq|
  801. <th class=listheading><a class=listheading href="$href&sort_col=received">|
  802. . $locale->text('Received') . qq|</a></th>|;
  803. $column_header{expense} = qq|
  804. <th class=listheading><a class=listheading href="$href&sort_col=expense">|
  805. . $locale->text('Expense') . qq|</a></th>|;
  806. print qq|
  807. <body>
  808. <table width=100%>
  809. <tr>
  810. <th class=listtop>$form->{title}</th>
  811. </tr>
  812. <tr height="5"></tr>
  813. <tr>
  814. <td>$options</td>
  815. </tr>
  816. <tr>
  817. <td>
  818. <table width=100%>
  819. <tr>|;
  820. map { print "$column_header{$_}\n" } @column_index;
  821. print qq|
  822. </tr>
  823. |;
  824. if ( $form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue' ) {
  825. $form->{sort_type} = 'numeric';
  826. }
  827. $i = 0;
  828. $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  829. $dates =
  830. "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  831. $base =
  832. "path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  833. $form->{callback} = "rp.pl?action=continue&$base";
  834. $form->{callback} = $form->escape( $form->{callback} );
  835. $callback = "callback=$form->{callback}";
  836. # sort the whole thing by account numbers and display
  837. foreach $ref ( @{ $form->{TB} } ) {
  838. $description = $form->escape( $ref->{description} );
  839. $i = $i % 2;
  840. $pnumhref =
  841. "ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  842. $soldhref =
  843. "ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  844. $rechref =
  845. "ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  846. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  847. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  848. $credit =
  849. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  850. $begbalance =
  851. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  852. "&nbsp;" );
  853. $endbalance =
  854. $form->format_amount( \%myconfig,
  855. ( $ref->{balance} + $ref->{amount} ) * $ml,
  856. 2, "&nbsp;" );
  857. $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
  858. $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
  859. $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
  860. map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
  861. print qq|
  862. <tr class=listrow$i>
  863. |;
  864. map { print "<td>$ref->{$_}</td>\n" } @column_index;
  865. print qq|
  866. </tr>
  867. |;
  868. ++$i;
  869. }
  870. print qq|
  871. </tr>
  872. </table>
  873. </td>
  874. </tr>
  875. <tr>
  876. <td><hr size=3 noshade></td>
  877. </tr>
  878. </table>
  879. </body>
  880. </html>
  881. |;
  882. }
  883. sub generate_income_statement {
  884. $form->{padding} = "&nbsp;&nbsp;";
  885. $form->{bold} = "<b>";
  886. $form->{endbold} = "</b>";
  887. $form->{br} = "<br>";
  888. RP->income_statement( \%myconfig, \%$form );
  889. ( $form->{department} ) = split /--/, $form->{department};
  890. ( $form->{projectnumber} ) = split /--/, $form->{projectnumber};
  891. $form->{period} =
  892. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  893. $form->{todate} = $form->current_date( \%myconfig ) unless $form->{todate};
  894. # if there are any dates construct a where
  895. if ( $form->{fromdate} || $form->{todate} ) {
  896. unless ( $form->{todate} ) {
  897. $form->{todate} = $form->current_date( \%myconfig );
  898. }
  899. $longtodate = $locale->date( \%myconfig, $form->{todate}, 1 );
  900. $shorttodate = $locale->date( \%myconfig, $form->{todate}, 0 );
  901. $longfromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  902. $shortfromdate = $locale->date( \%myconfig, $form->{fromdate}, 0 );
  903. $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
  904. $form->{period} =
  905. $locale->text('for Period')
  906. . qq|<br>\n$longfromdate |
  907. . $locale->text('To')
  908. . qq| $longtodate|;
  909. }
  910. if ( $form->{comparefromdate} || $form->{comparetodate} ) {
  911. $longcomparefromdate =
  912. $locale->date( \%myconfig, $form->{comparefromdate}, 1 );
  913. $shortcomparefromdate =
  914. $locale->date( \%myconfig, $form->{comparefromdate}, 0 );
  915. $longcomparetodate =
  916. $locale->date( \%myconfig, $form->{comparetodate}, 1 );
  917. $shortcomparetodate =
  918. $locale->date( \%myconfig, $form->{comparetodate}, 0 );
  919. $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
  920. $form->{period} .=
  921. "<br>\n$longcomparefromdate "
  922. . $locale->text('To')
  923. . qq| $longcomparetodate|;
  924. }
  925. # setup variables for the form
  926. @a = qw(company address businessnumber);
  927. for (@a) { $form->{$_} = $myconfig{$_} }
  928. $form->{address} =~ s/\\n/<br>/g;
  929. $form->{templates} = $myconfig{templates};
  930. $form->{IN} = "income_statement.html";
  931. my $template = LedgerSMB::Template->new( user => \%myconfig,
  932. template => $form->{'formname'}, format => uc $form->{format} );
  933. try {
  934. $template->render($form);
  935. $template->output(%{$form});
  936. }
  937. catch Error::Simple with {
  938. my $E = shift;
  939. $form->error( $E->stacktrace );
  940. };
  941. }
  942. sub generate_balance_sheet {
  943. ##SC: START HTML
  944. $form->{padding} = "&nbsp;&nbsp;";
  945. $form->{bold} = "<b>";
  946. $form->{endbold} = "</b>";
  947. $form->{br} = "<br>";
  948. RP->balance_sheet( \%myconfig, \%$form );
  949. $form->{asofdate} = $form->current_date( \%myconfig )
  950. unless $form->{asofdate};
  951. $form->{period} =
  952. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  953. ( $form->{department} ) = split /--/, $form->{department};
  954. # define Current Earnings account
  955. $padding = ( $form->{l_heading} ) ? $form->{padding} : "";
  956. push(
  957. @{ $form->{equity_account} }, { current_earnings => 1,
  958. text => $locale->text('Current Earnings')}
  959. );
  960. $form->{this_period} = $locale->date( \%myconfig, $form->{asofdate}, 0 );
  961. $form->{last_period} =
  962. $locale->date( \%myconfig, $form->{compareasofdate}, 0 );
  963. # setup company variables for the form
  964. for (qw(company address businessnumber nativecurr login)) {
  965. $form->{$_} = $myconfig{$_};
  966. }
  967. $form->{address} =~ s/\\n/<br>/g;
  968. ##SC: END HTML
  969. $form->{templates} = $myconfig{templates};
  970. my $template = LedgerSMB::Template->new(
  971. user => \%myconfig,
  972. locale => $locale,
  973. template => 'balance_sheet',
  974. format => $form->{format}? uc $form->{format}: 'HTML',
  975. no_auto_output => 1,
  976. );
  977. try {
  978. $template->render($form);
  979. $template->output(%{$form});
  980. }
  981. catch Error::Simple with {
  982. my $E = shift;
  983. $form->error( $E->stacktrace );
  984. };
  985. }
  986. sub generate_projects {
  987. $form->{nextsub} = "generate_projects";
  988. $form->{title} = $locale->text('Project Transactions');
  989. RP->trial_balance( \%myconfig, \%$form );
  990. &list_accounts;
  991. }
  992. # Antonio Gallardo
  993. #
  994. # D.S. Feb 16, 2001
  995. # included links to display transactions for period entered
  996. # added headers and subtotals
  997. #
  998. sub generate_trial_balance {
  999. # get for each account initial balance, debits and credits
  1000. RP->trial_balance( \%myconfig, \%$form );
  1001. $form->{nextsub} = "generate_trial_balance";
  1002. $form->{title} = $locale->text('Trial Balance');
  1003. $form->{callback} = "$form->{script}?action=generate_trial_balance";
  1004. for (
  1005. qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)
  1006. )
  1007. {
  1008. $form->{callback} .= "&$_=$form->{$_}";
  1009. }
  1010. $form->{callback} = $form->escape( $form->{callback} );
  1011. &list_accounts;
  1012. }
  1013. sub list_accounts {
  1014. $title = $form->escape( $form->{title} );
  1015. if ( $form->{department} ) {
  1016. ($department) = split /--/, $form->{department};
  1017. $options = $locale->text('Department') . " : $department<br>";
  1018. $department = $form->escape( $form->{department} );
  1019. }
  1020. if ( $form->{projectnumber} ) {
  1021. ($projectnumber) = split /--/, $form->{projectnumber};
  1022. $options .= $locale->text('Project Number') . " : $projectnumber<br>";
  1023. $projectnumber = $form->escape( $form->{projectnumber} );
  1024. }
  1025. # if there are any dates
  1026. if ( $form->{fromdate} || $form->{todate} ) {
  1027. if ( $form->{fromdate} ) {
  1028. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1029. }
  1030. if ( $form->{todate} ) {
  1031. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1032. }
  1033. $form->{period} = "$fromdate - $todate";
  1034. }
  1035. else {
  1036. $form->{period} =
  1037. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1038. }
  1039. $options .= $form->{period};
  1040. @column_index = qw(accno description begbalance debit credit endbalance);
  1041. $column_header{accno} =
  1042. qq|<th class=listheading>| . $locale->text('Account') . qq|</th>|;
  1043. $column_header{description} =
  1044. qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
  1045. $column_header{debit} =
  1046. qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>|;
  1047. $column_header{credit} =
  1048. qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>|;
  1049. $column_header{begbalance} =
  1050. qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
  1051. $column_header{endbalance} =
  1052. qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
  1053. if ( $form->{accounttype} eq 'gifi' ) {
  1054. $column_header{accno} =
  1055. qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>|;
  1056. }
  1057. $form->header;
  1058. print qq|
  1059. <body>
  1060. <table width=100%>
  1061. <tr>
  1062. <th class=listtop>$form->{title}</th>
  1063. </tr>
  1064. <tr height="5"></tr>
  1065. <tr>
  1066. <td>$options</td>
  1067. </tr>
  1068. <tr>
  1069. <td>
  1070. <table width=100%>
  1071. <tr>|;
  1072. for (@column_index) { print "$column_header{$_}\n" }
  1073. print qq|
  1074. </tr>
  1075. |;
  1076. # sort the whole thing by account numbers and display
  1077. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} } ) {
  1078. $description = $form->escape( $ref->{description} );
  1079. $href =
  1080. 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}|;
  1081. if ( $form->{accounttype} eq 'gifi' ) {
  1082. $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
  1083. $na = $locale->text('N/A');
  1084. if ( !$ref->{accno} ) {
  1085. for (qw(accno description)) { $ref->{$_} = $na }
  1086. }
  1087. }
  1088. else {
  1089. $href .= "&accno=$ref->{accno}&description=$description";
  1090. }
  1091. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  1092. $ml *= -1 if $ref->{contra};
  1093. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  1094. $credit =
  1095. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  1096. $begbalance =
  1097. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  1098. "&nbsp;" );
  1099. $endbalance =
  1100. $form->format_amount( \%myconfig,
  1101. ( $ref->{balance} + $ref->{amount} ) * $ml,
  1102. 2, "&nbsp;" );
  1103. if ( $ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal} ) {
  1104. if ($subtotal) {
  1105. for (qw(accno begbalance endbalance)) {
  1106. $column_data{$_} = "<th>&nbsp;</th>";
  1107. }
  1108. $subtotalbegbalance =
  1109. $form->format_amount( \%myconfig, $subtotalbegbalance, 2,
  1110. "&nbsp;" );
  1111. $subtotalendbalance =
  1112. $form->format_amount( \%myconfig, $subtotalendbalance, 2,
  1113. "&nbsp;" );
  1114. $subtotaldebit =
  1115. $form->format_amount( \%myconfig, $subtotaldebit, 2,
  1116. "&nbsp;" );
  1117. $subtotalcredit =
  1118. $form->format_amount( \%myconfig, $subtotalcredit, 2,
  1119. "&nbsp;" );
  1120. $column_data{description} =
  1121. "<th class=listsubtotal>$subtotaldescription</th>";
  1122. $column_data{begbalance} =
  1123. "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  1124. $column_data{endbalance} =
  1125. "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  1126. $column_data{debit} =
  1127. "<th align=right class=listsubtotal>$subtotaldebit</th>";
  1128. $column_data{credit} =
  1129. "<th align=right class=listsubtotal>$subtotalcredit</th>";
  1130. print qq|
  1131. <tr class=listsubtotal>
  1132. |;
  1133. for (@column_index) { print "$column_data{$_}\n" }
  1134. print qq|
  1135. </tr>
  1136. |;
  1137. }
  1138. }
  1139. if ( $ref->{charttype} eq "H" ) {
  1140. $subtotal = 1;
  1141. $subtotaldescription = $ref->{description};
  1142. $subtotaldebit = $ref->{debit};
  1143. $subtotalcredit = $ref->{credit};
  1144. $subtotalbegbalance = 0;
  1145. $subtotalendbalance = 0;
  1146. if ( $form->{l_heading} ) {
  1147. if ( !$form->{all_accounts} ) {
  1148. if ( ( $subtotaldebit + $subtotalcredit ) == 0 ) {
  1149. $subtotal = 0;
  1150. next;
  1151. }
  1152. }
  1153. }
  1154. else {
  1155. $subtotal = 0;
  1156. if (
  1157. $form->{all_accounts}
  1158. || ( $form->{l_subtotal}
  1159. && ( ( $subtotaldebit + $subtotalcredit ) != 0 ) )
  1160. )
  1161. {
  1162. $subtotal = 1;
  1163. }
  1164. next;
  1165. }
  1166. for (qw(accno debit credit begbalance endbalance)) {
  1167. $column_data{$_} = "<th>&nbsp;</th>";
  1168. }
  1169. $column_data{description} =
  1170. "<th class=listheading>$ref->{description}</th>";
  1171. }
  1172. if ( $ref->{charttype} eq "A" ) {
  1173. $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
  1174. $column_data{description} = "<td>$ref->{description}</td>";
  1175. $column_data{debit} = "<td align=right>$debit</td>";
  1176. $column_data{credit} = "<td align=right>$credit</td>";
  1177. $column_data{begbalance} = "<td align=right>$begbalance</td>";
  1178. $column_data{endbalance} = "<td align=right>$endbalance</td>";
  1179. $totaldebit += $ref->{debit};
  1180. $totalcredit += $ref->{credit};
  1181. $cml = ( $ref->{contra} ) ? -1 : 1;
  1182. $subtotalbegbalance += $ref->{balance} * $ml * $cml;
  1183. $subtotalendbalance +=
  1184. ( $ref->{balance} + $ref->{amount} ) * $ml * $cml;
  1185. }
  1186. if ( $ref->{charttype} eq "H" ) {
  1187. print qq|
  1188. <tr class=listheading>
  1189. |;
  1190. }
  1191. if ( $ref->{charttype} eq "A" ) {
  1192. $i++;
  1193. $i %= 2;
  1194. print qq|
  1195. <tr class=listrow$i>
  1196. |;
  1197. }
  1198. for (@column_index) { print "$column_data{$_}\n" }
  1199. print qq|
  1200. </tr>
  1201. |;
  1202. }
  1203. # print last subtotal
  1204. if ( $subtotal && $form->{l_subtotal} ) {
  1205. for (qw(accno begbalance endbalance)) {
  1206. $column_data{$_} = "<th>&nbsp;</th>";
  1207. }
  1208. $subtotalbegbalance =
  1209. $form->format_amount( \%myconfig, $subtotalbegbalance, 2, "&nbsp;" );
  1210. $subtotalendbalance =
  1211. $form->format_amount( \%myconfig, $subtotalendbalance, 2, "&nbsp;" );
  1212. $subtotaldebit =
  1213. $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
  1214. $subtotalcredit =
  1215. $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
  1216. $column_data{description} =
  1217. "<th class=listsubtotal>$subtotaldescription</th>";
  1218. $column_data{begbalance} =
  1219. "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  1220. $column_data{endbalance} =
  1221. "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  1222. $column_data{debit} =
  1223. "<th align=right class=listsubtotal>$subtotaldebit</th>";
  1224. $column_data{credit} =
  1225. "<th align=right class=listsubtotal>$subtotalcredit</th>";
  1226. print qq|
  1227. <tr class=listsubtotal>
  1228. |;
  1229. for (@column_index) { print "$column_data{$_}\n" }
  1230. print qq|
  1231. </tr>
  1232. |;
  1233. }
  1234. $totaldebit = $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" );
  1235. $totalcredit =
  1236. $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" );
  1237. for (qw(accno description begbalance endbalance)) {
  1238. $column_data{$_} = "<th>&nbsp;</th>";
  1239. }
  1240. $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
  1241. $column_data{credit} =
  1242. qq|<th align=right class=listtotal>$totalcredit</th>|;
  1243. print qq|
  1244. <tr class=listtotal>
  1245. |;
  1246. for (@column_index) { print "$column_data{$_}\n" }
  1247. print qq|
  1248. </tr>
  1249. </table>
  1250. </td>
  1251. </tr>
  1252. <tr>
  1253. <td><hr size=3 noshade></td>
  1254. </tr>
  1255. </table>
  1256. </body>
  1257. </html>
  1258. |;
  1259. }
  1260. sub generate_ar_aging {
  1261. # split customer
  1262. ( $form->{customer} ) = split( /--/, $form->{customer} );
  1263. $customer = $form->escape( $form->{customer}, 1 );
  1264. $title = $form->escape( $form->{title}, 1 );
  1265. $media = $form->escape( $form->{media}, 1 );
  1266. $form->{ct} = "customer";
  1267. $form->{arap} = "ar";
  1268. RP->aging( \%myconfig, \%$form );
  1269. $form->{callback} =
  1270. 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}|;
  1271. &aging;
  1272. }
  1273. sub generate_ap_aging {
  1274. # split vendor
  1275. ( $form->{vendor} ) = split( /--/, $form->{vendor} );
  1276. $vendor = $form->escape( $form->{vendor}, 1 );
  1277. $title = $form->escape( $form->{title}, 1 );
  1278. $media = $form->escape( $form->{media}, 1 );
  1279. $form->{ct} = "vendor";
  1280. $form->{arap} = "ap";
  1281. RP->aging( \%myconfig, \%$form );
  1282. $form->{callback} =
  1283. 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}|;
  1284. &aging;
  1285. }
  1286. sub aging {
  1287. $form->header;
  1288. $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
  1289. $column_header{ct} =
  1290. qq|<th class=listheading width=60%>|
  1291. . $locale->text( ucfirst $form->{ct} )
  1292. . qq|</th>|;
  1293. $column_header{language} =
  1294. qq|<th class=listheading>| . $locale->text('Language') . qq|</th>|;
  1295. $column_header{invnumber} =
  1296. qq|<th class=listheading>| . $locale->text('Invoice') . qq|</th>|;
  1297. $column_header{ordnumber} =
  1298. qq|<th class=listheading>| . $locale->text('Order') . qq|</th>|;
  1299. $column_header{transdate} =
  1300. qq|<th class=listheading nowrap>| . $locale->text('Date') . qq|</th>|;
  1301. $column_header{duedate} =
  1302. qq|<th class=listheading nowrap>| . $locale->text('Due Date') . qq|</th>|;
  1303. $column_header{c0} =
  1304. qq|<th class=listheading width=10% nowrap>|
  1305. . $locale->text('Current')
  1306. . qq|</th>|;
  1307. $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
  1308. $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
  1309. $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
  1310. $column_header{total} =
  1311. qq|<th class=listheading width=10% nowrap>|
  1312. . $locale->text('Total')
  1313. . qq|</th>|;
  1314. @column_index = qw(statement ct);
  1315. if ( @{ $form->{all_language} } && $form->{arap} eq 'ar' ) {
  1316. push @column_index, "language";
  1317. $form->{selectlanguage} = qq|<option>\n|;
  1318. for ( @{ $form->{all_language} } ) {
  1319. $form->{selectlanguage} .=
  1320. qq|<option value="$_->{code}">$_->{description}\n|;
  1321. }
  1322. }
  1323. @c = ();
  1324. for (qw(c0 c30 c60 c90)) {
  1325. if ( $form->{$_} ) {
  1326. push @c, $_;
  1327. $form->{callback} .= "&$_=$form->{$_}";
  1328. }
  1329. }
  1330. if ( !$form->{summary} ) {
  1331. push @column_index, qw(invnumber ordnumber transdate duedate);
  1332. }
  1333. push @column_index, @c;
  1334. push @column_index, "total";
  1335. $option = $locale->text('Aged');
  1336. if ( $form->{overdue} ) {
  1337. $option = $locale->text('Aged Overdue');
  1338. $form->{callback} .= "&overdue=$form->{overdue}";
  1339. }
  1340. if ( $form->{department} ) {
  1341. $option .= "\n<br>" if $option;
  1342. ($department) = split /--/, $form->{department};
  1343. $option .= $locale->text('Department') . " : $department";
  1344. $department = $form->escape( $form->{department}, 1 );
  1345. $form->{callback} .= "&department=$department";
  1346. }
  1347. if ( $form->{arap} eq 'ar' ) {
  1348. if ( $form->{customer} ) {
  1349. $option .= "\n<br>" if $option;
  1350. $option .= $form->{customer};
  1351. }
  1352. }
  1353. if ( $form->{arap} eq 'ap' ) {
  1354. shift @column_index;
  1355. if ( $form->{vendor} ) {
  1356. $option .= "\n<br>" if $option;
  1357. $option .= $form->{vendor};
  1358. }
  1359. }
  1360. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1361. $option .= "\n<br>" if $option;
  1362. $option .=
  1363. $locale->text('for Period') . " " . $locale->text('To') . " $todate";
  1364. print qq|
  1365. <body>
  1366. <form method=post action=$form->{script}>
  1367. <table width=100%>
  1368. <tr>
  1369. <th class=listtop>$form->{title}</th>
  1370. </tr>
  1371. <tr height="5"></tr>
  1372. <tr>
  1373. <td>$option</td>
  1374. </tr>
  1375. <tr>
  1376. <td>
  1377. <table width=100%>
  1378. |;
  1379. $ctid = 0;
  1380. $i = 0;
  1381. $k = 0;
  1382. $l = $#{ $form->{AG} };
  1383. foreach $ref ( @{ $form->{AG} } ) {
  1384. if ( $curr ne $ref->{curr} ) {
  1385. $ctid = 0;
  1386. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1387. if ($curr) {
  1388. $c0total =
  1389. $form->format_amount( \%myconfig, $c0total, 2, "&nbsp" );
  1390. $c30total =
  1391. $form->format_amount( \%myconfig, $c30total, 2, "&nbsp" );
  1392. $c60total =
  1393. $form->format_amount( \%myconfig, $c60total, 2, "&nbsp" );
  1394. $c90total =
  1395. $form->format_amount( \%myconfig, $c90total, 2, "&nbsp" );
  1396. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp" );
  1397. for (qw(ct statement language)) {
  1398. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1399. }
  1400. $column_data{c0} = qq|<th align=right>$c0total</th>|;
  1401. $column_data{c30} = qq|<th align=right>$c30total</th>|;
  1402. $column_data{c60} = qq|<th align=right>$c60total</th>|;
  1403. $column_data{c90} = qq|<th align=right>$c90total</th>|;
  1404. $column_data{total} = qq|<th align=right>$total</th>|;
  1405. print qq|
  1406. <tr class=listtotal>
  1407. |;
  1408. for (@column_index) { print "$column_data{$_}\n" }
  1409. print qq|
  1410. </tr>
  1411. |;
  1412. $c0subtotal = 0;
  1413. $c30subtotal = 0;
  1414. $c60subtotal = 0;
  1415. $c90subtotal = 0;
  1416. $subtotal = 0;
  1417. $c0total = 0;
  1418. $c30total = 0;
  1419. $c60total = 0;
  1420. $c90total = 0;
  1421. $total = 0;
  1422. }
  1423. $curr = $ref->{curr};
  1424. print qq|
  1425. <tr>
  1426. <td></td>
  1427. <th>$curr</th>
  1428. </tr>
  1429. <tr class=listheading>
  1430. |;
  1431. for (@column_index) { print "$column_header{$_}\n" }
  1432. print qq|
  1433. </tr>
  1434. |;
  1435. }
  1436. $k++;
  1437. if ( $ctid != $ref->{ctid} ) {
  1438. $i++;
  1439. $column_data{ct} = qq|<td>$ref->{name}</td>|;
  1440. if ( $form->{selectlanguage} ) {
  1441. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1442. $form->{"selectlanguage_$i"} =~
  1443. s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
  1444. $column_data{language} =
  1445. qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
  1446. }
  1447. $column_data{statement} =
  1448. qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
  1449. <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
  1450. <input type=hidden name="curr_$i" value=$ref->{curr}>
  1451. </td>|;
  1452. }
  1453. $ctid = $ref->{ctid};
  1454. for (qw(c0 c30 c60 c90)) {
  1455. $ref->{$_} =
  1456. $form->round_amount( $ref->{$_} / $ref->{exchangerate}, 2 );
  1457. }
  1458. $c0subtotal += $ref->{c0};
  1459. $c30subtotal += $ref->{c30};
  1460. $c60subtotal += $ref->{c60};
  1461. $c90subtotal += $ref->{c90};
  1462. $c0total += $ref->{c0};
  1463. $c30total += $ref->{c30};
  1464. $c60total += $ref->{c60};
  1465. $c90total += $ref->{c90};
  1466. $ref->{total} =
  1467. ( $ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90} );
  1468. $subtotal += $ref->{total};
  1469. $total += $ref->{total};
  1470. $ref->{c0} =
  1471. $form->format_amount( \%myconfig, $ref->{c0}, 2, "&nbsp;" );
  1472. $ref->{c30} =
  1473. $form->format_amount( \%myconfig, $ref->{c30}, 2, "&nbsp;" );
  1474. $ref->{c60} =
  1475. $form->format_amount( \%myconfig, $ref->{c60}, 2, "&nbsp;" );
  1476. $ref->{c90} =
  1477. $form->format_amount( \%myconfig, $ref->{c90}, 2, "&nbsp;" );
  1478. $ref->{total} =
  1479. $form->format_amount( \%myconfig, $ref->{total}, 2, "&nbsp;" );
  1480. $href =
  1481. qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|
  1482. . $form->escape( $form->{callback} );
  1483. $column_data{invnumber} =
  1484. qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
  1485. for (qw(ordnumber transdate duedate)) {
  1486. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  1487. }
  1488. for (qw(c0 c30 c60 c90 total)) {
  1489. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  1490. }
  1491. if ( !$form->{summary} ) {
  1492. $j++;
  1493. $j %= 2;
  1494. print qq|
  1495. <tr class=listrow$j>
  1496. |;
  1497. for (@column_index) { print "$column_data{$_}\n" }
  1498. print qq|
  1499. </tr>
  1500. |;
  1501. for (qw(ct statement language)) {
  1502. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1503. }
  1504. }
  1505. # print subtotal
  1506. $nextid = ( $k <= $l ) ? $form->{AG}->[$k]->{ctid} : 0;
  1507. if ( $ctid != $nextid ) {
  1508. $c0subtotal =
  1509. $form->format_amount( \%myconfig, $c0subtotal, 2, "&nbsp" );
  1510. $c30subtotal =
  1511. $form->format_amount( \%myconfig, $c30subtotal, 2, "&nbsp" );
  1512. $c60subtotal =
  1513. $form->format_amount( \%myconfig, $c60subtotal, 2, "&nbsp" );
  1514. $c90subtotal =
  1515. $form->format_amount( \%myconfig, $c90subtotal, 2, "&nbsp" );
  1516. $subtotal =
  1517. $form->format_amount( \%myconfig, $subtotal, 2, "&nbsp" );
  1518. if ( $form->{summary} ) {
  1519. $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
  1520. $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
  1521. $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
  1522. $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
  1523. $column_data{total} = qq|<td align=right>$subtotal</th>|;
  1524. $j++;
  1525. $j %= 2;
  1526. print qq|
  1527. <tr class=listrow$j>
  1528. |;
  1529. for (@column_index) { print "$column_data{$_}\n" }
  1530. print qq|
  1531. </tr>
  1532. |;
  1533. }
  1534. else {
  1535. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1536. $column_data{c0} =
  1537. qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
  1538. $column_data{c30} =
  1539. qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
  1540. $column_data{c60} =
  1541. qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
  1542. $column_data{c90} =
  1543. qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
  1544. $column_data{total} =
  1545. qq|<th class=listsubtotal align=right>$subtotal</th>|;
  1546. # print subtotals
  1547. print qq|
  1548. <tr class=listsubtotal>
  1549. |;
  1550. for (@column_index) { print "$column_data{$_}\n" }
  1551. print qq|
  1552. </tr>
  1553. |;
  1554. }
  1555. $c0subtotal = 0;
  1556. $c30subtotal = 0;
  1557. $c60subtotal = 0;
  1558. $c90subtotal = 0;
  1559. $subtotal = 0;
  1560. }
  1561. }
  1562. print qq|
  1563. </tr>
  1564. <tr class=listtotal>
  1565. |;
  1566. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1567. $c0total = $form->format_amount( \%myconfig, $c0total, 2, "&nbsp;" );
  1568. $c30total = $form->format_amount( \%myconfig, $c30total, 2, "&nbsp;" );
  1569. $c60total = $form->format_amount( \%myconfig, $c60total, 2, "&nbsp;" );
  1570. $c90total = $form->format_amount( \%myconfig, $c90total, 2, "&nbsp;" );
  1571. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp;" );
  1572. $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
  1573. $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
  1574. $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
  1575. $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
  1576. $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
  1577. for (@column_index) { print "$column_data{$_}\n" }
  1578. print qq|
  1579. </tr>
  1580. <input type=hidden name=rowcount value=$i>
  1581. </table>
  1582. </td>
  1583. </tr>
  1584. <tr>
  1585. <td>
  1586. |;
  1587. &print_options if ( $form->{arap} eq 'ar' );
  1588. print qq|
  1589. </td>
  1590. </tr>
  1591. <tr>
  1592. <td><hr size=3 noshade></td>
  1593. </tr>
  1594. </table>
  1595. |;
  1596. if ( $form->{arap} eq 'ar' ) {
  1597. $form->hide_form(
  1598. qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid)
  1599. );
  1600. print qq|
  1601. <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
  1602. |;
  1603. # type=submit $locale->text('Select all')
  1604. # type=submit $locale->text('Print')
  1605. # type=submit $locale->text('E-mail')
  1606. %button = (
  1607. 'select_all' =>
  1608. { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1609. 'print' =>
  1610. { ndx => 2, key => 'P', value => $locale->text('Print') },
  1611. 'e_mail' =>
  1612. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1613. );
  1614. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1615. {
  1616. $form->print_button( \%button, $_ );
  1617. }
  1618. }
  1619. if ( $form->{lynx} ) {
  1620. require "bin/menu.pl";
  1621. &menubar;
  1622. }
  1623. print qq|
  1624. </form>
  1625. </body>
  1626. </html>
  1627. |;
  1628. }
  1629. sub select_all {
  1630. RP->aging( \%myconfig, \%$form );
  1631. for ( @{ $form->{AG} } ) { $_->{checked} = "checked" }
  1632. &aging;
  1633. }
  1634. sub print_options {
  1635. $form->{sendmode} = "attachment";
  1636. $form->{copies} = 1 unless $form->{copies};
  1637. $form->{PD}{ $form->{type} } = "selected";
  1638. $form->{DF}{ $form->{format} } = "selected";
  1639. $form->{SM}{ $form->{sendmode} } = "selected";
  1640. $format = qq|
  1641. <option value=html $form->{PD}{format}>html|;
  1642. $type = qq|
  1643. <option value=statement $form->{PD}{statement}>|
  1644. . $locale->text('Statement');
  1645. if ( $form->{media} eq 'email' ) {
  1646. $media = qq|
  1647. <td><select name=sendmode>
  1648. <option value=attachment $form->{SM}{attachment}>|
  1649. . $locale->text('Attachment') . qq|
  1650. <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
  1651. }
  1652. else {
  1653. $media = qq|
  1654. <td><select name=media>
  1655. <option value=screen>| . $locale->text('Screen');
  1656. if ( %{LedgerSMB::Sysconfig::printer}
  1657. && ${LedgerSMB::Sysconfig::latex} )
  1658. {
  1659. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1660. $media .= qq|
  1661. <option value="$_">$_|;
  1662. }
  1663. }
  1664. }
  1665. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1666. $media .= qq|</select></td>|;
  1667. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1668. $format .= qq|
  1669. <option value=ps $form->{DF}{postscript}>|
  1670. . $locale->text('Postscript') . qq|
  1671. <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
  1672. }
  1673. print qq|
  1674. <table>
  1675. <tr>
  1676. <td><select name=type>$type</select></td>
  1677. <td><select name=format>$format</select></td>
  1678. $media
  1679. |;
  1680. if ( %{LedgerSMB::Sysconfig::printer}
  1681. && ${LedgerSMB::Sysconfig::latex}
  1682. && $form->{media} ne 'email' )
  1683. {
  1684. print qq|
  1685. <td>| . $locale->text('Copies') . qq|
  1686. <input name=copies size=2 value=$form->{copies}></td>
  1687. |;
  1688. }
  1689. print qq|
  1690. </tr>
  1691. </table>
  1692. |;
  1693. }
  1694. sub e_mail {
  1695. # get name and email addresses
  1696. for $i ( 1 .. $form->{rowcount} ) {
  1697. if ( $form->{"statement_$i"} ) {
  1698. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1699. $form->{"statement_1"} = 1;
  1700. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1701. $form->{"curr_1"} = $form->{"curr_$i"};
  1702. RP->get_customer( \%myconfig, \%$form );
  1703. $selected = 1;
  1704. last;
  1705. }
  1706. }
  1707. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1708. if ( $myconfig{role} =~ /(admin|manager)/ ) {
  1709. $bcc = qq|
  1710. <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
  1711. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  1712. |;
  1713. }
  1714. $title =
  1715. $locale->text( 'E-mail Statement to [_1]', $form->{ $form->{ct} } );
  1716. $form->{media} = "email";
  1717. $form->header;
  1718. print qq|
  1719. <body>
  1720. <form method=post action=$form->{script}>
  1721. <table width=100%>
  1722. <tr class=listtop>
  1723. <th>$title</th>
  1724. </tr>
  1725. <tr height="5"></tr>
  1726. <tr>
  1727. <td>
  1728. <table width=100%>
  1729. <tr>
  1730. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  1731. <td><input name=email size=30 value="$form->{email}"></td>
  1732. <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
  1733. <td><input name=cc size=30 value="$form->{cc}"></td>
  1734. </tr>
  1735. <tr>
  1736. <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
  1737. <td><input name=subject size=30 value="$form->{subject}"></td>
  1738. $bcc
  1739. </tr>
  1740. </table>
  1741. </td>
  1742. </tr>
  1743. <tr>
  1744. <td>
  1745. <table width=100%>
  1746. <tr>
  1747. <th align=left nowrap>| . $locale->text('Message') . qq|</th>
  1748. </tr>
  1749. <tr>
  1750. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  1751. </tr>
  1752. </table>
  1753. </td>
  1754. </tr>
  1755. <tr>
  1756. <td>
  1757. |;
  1758. &print_options;
  1759. for (qw(email cc bcc subject message type sendmode format action nextsub)) {
  1760. delete $form->{$_};
  1761. }
  1762. $form->hide_form;
  1763. print qq|
  1764. </td>
  1765. </tr>
  1766. <tr>
  1767. <td><hr size=3 noshade></td>
  1768. </tr>
  1769. </table>
  1770. <input type="hidden" name="nextsub" value="send_email">
  1771. <br>
  1772. <button name="action" class="submit" type="submit" value="continue">|
  1773. . $locale->text('Continue')
  1774. . qq|</button>
  1775. </form>
  1776. </body>
  1777. </html>
  1778. |;
  1779. }
  1780. sub send_email {
  1781. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1782. $form->{printmode} = '|-';
  1783. $form->{subject} = $locale->text( 'Statement - [_1]', $form->{todate} )
  1784. unless $form->{subject};
  1785. $form->isblank( "email", $locale->text('E-mail address missing!') );
  1786. RP->aging( \%myconfig, \%$form );
  1787. &print_form;
  1788. $form->redirect(
  1789. $locale->text( 'Statement sent to [_1]', $form->{ $form->{ct} } ) );
  1790. }
  1791. sub print {
  1792. if ( $form->{media} !~ /(screen|email)/ ) {
  1793. $form->error( $locale->text('Select postscript or PDF!') )
  1794. if ( $form->{format} !~ /(postscript|pdf)/ );
  1795. }
  1796. my @batch_data = ();
  1797. for $i ( 1 .. $form->{rowcount} ) {
  1798. if ( $form->{"statement_$i"} ) {
  1799. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1800. $language_code = $form->{"language_code_$i"};
  1801. $curr = $form->{"curr_$i"};
  1802. $selected = 1;
  1803. if ( $form->{media} !~ /(screen|email)/ ) {
  1804. # SC: I may not need this anymore...
  1805. # But I'll wait until lpr output is working before deciding
  1806. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  1807. $form->{"$form->{ct}_id"} = "";
  1808. $SIG{INT} = 'IGNORE';
  1809. }
  1810. else {
  1811. $form->{"statement_1"} = 1;
  1812. $form->{"language_code_1"} = $language_code;
  1813. $form->{"curr_1"} = $curr;
  1814. }
  1815. RP->aging( \%myconfig, \%$form );
  1816. $printhash = &print_form;
  1817. push @batch_data, $printhash;
  1818. }
  1819. }
  1820. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1821. my $template = LedgerSMB::Template->new(
  1822. user => \%myconfig,
  1823. template => $form->{'formname'} || $form->{'type'},
  1824. format => uc $form->{format}
  1825. );
  1826. try {
  1827. $template->render({data => \@batch_data});
  1828. $template->output($form);
  1829. }
  1830. catch Error::Simple with {
  1831. my $E = shift;
  1832. $form->error( $E->stacktrace );
  1833. };
  1834. $form->redirect( $locale->text('Statements sent to printer!') )
  1835. if ( $form->{media} !~ /(screen|email)/ );
  1836. }
  1837. sub print_form {
  1838. $form->{statementdate} = $locale->date( \%myconfig, $form->{todate}, 1 );
  1839. $form->{templates} = "$myconfig{templates}";
  1840. # setup variables for the form
  1841. @a = qw(company address businessnumber tel fax);
  1842. for (@a) { $form->{$_} = $myconfig{$_} }
  1843. $form->{address} =~ s/\\n/\n/g;
  1844. $form->format_string(@a);
  1845. $form->{IN} = "$form->{type}.html";
  1846. if ( $form->{format} eq 'postscript' ) {
  1847. $form->{IN} =~ s/html$/tex/;
  1848. }
  1849. if ( $form->{format} eq 'pdf' ) {
  1850. $form->{IN} =~ s/html$/tex/;
  1851. }
  1852. @a = qw(name address1 address2 city state zipcode country contact);
  1853. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1854. push @a, 'email' if !$form->{media} eq 'email';
  1855. $i = 0;
  1856. while ( @{ $form->{AG} } ) {
  1857. $ref = shift @{ $form->{AG} };
  1858. if ( $ctid != $ref->{ctid} ) {
  1859. $ctid = $ref->{ctid};
  1860. $i++;
  1861. if ( $form->{"statement_$i"} ) {
  1862. for (@a) { $form->{$_} = $ref->{$_} }
  1863. $form->format_string(@a);
  1864. $form->{ $form->{ct} } = $form->{name};
  1865. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1866. $form->{language_code} = $form->{"language_code_$i"};
  1867. $form->{currency} = $form->{"curr_$i"};
  1868. for (qw(invnumber ordnumber ponumber notes invdate duedate)) {
  1869. $form->{$_} = ();
  1870. }
  1871. $form->{total} = 0;
  1872. foreach $item (qw(c0 c30 c60 c90)) {
  1873. $form->{$item} = ();
  1874. $form->{"${item}total"} = 0;
  1875. }
  1876. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1877. while ($ref) {
  1878. if ( scalar( @{ $form->{AG} } ) > 0 ) {
  1879. # one or more left to go
  1880. if ( $ctid == $form->{AG}->[0]->{ctid} ) {
  1881. $ref = shift @{ $form->{AG} };
  1882. &statement_details($ref)
  1883. if $ref->{curr} eq $form->{currency};
  1884. # any more?
  1885. $ref = scalar( @{ $form->{AG} } );
  1886. }
  1887. else {
  1888. $ref = 0;
  1889. }
  1890. }
  1891. else {
  1892. # set initial ref to 0
  1893. $ref = 0;
  1894. }
  1895. }
  1896. for ( "c0", "c30", "c60", "c90", "" ) {
  1897. $form->{"${_}total"} =
  1898. $form->format_amount( \%myconfig, $form->{"${_}total"},
  1899. 2 );
  1900. }
  1901. my $printhash = {};
  1902. for (keys %$form) { $printhash->{$_} = $form->{$_}}
  1903. return $printhash;
  1904. }
  1905. }
  1906. }
  1907. }
  1908. sub statement_details {
  1909. my ($ref) = @_;
  1910. $ref->{invdate} = $ref->{transdate};
  1911. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1912. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1913. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1914. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1915. foreach $item (qw(c0 c30 c60 c90)) {
  1916. eval {
  1917. $ref->{$item} =
  1918. $form->round_amount( $ref->{$item} / $ref->{exchangerate}, 2 );
  1919. };
  1920. $form->{"${item}total"} += $ref->{$item};
  1921. $form->{total} += $ref->{$item};
  1922. push @{ $form->{$item} },
  1923. $form->format_amount( \%myconfig, $ref->{$item}, 2 );
  1924. }
  1925. }
  1926. sub generate_tax_report {
  1927. RP->tax_report( \%myconfig, \%$form );
  1928. $descvar = "$form->{accno}_description";
  1929. $description = $form->escape( $form->{$descvar} );
  1930. $ratevar = "$form->{accno}_rate";
  1931. $taxrate = $form->{"$form->{accno}_rate"};
  1932. if ( $form->{accno} =~ /^gifi_/ ) {
  1933. $descvar = "gifi_$form->{accno}_description";
  1934. $description = $form->escape( $form->{$descvar} );
  1935. $ratevar = "gifi_$form->{accno}_rate";
  1936. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1937. }
  1938. $department = $form->escape( $form->{department} );
  1939. # construct href
  1940. $href =
  1941. "$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}";
  1942. # construct callback
  1943. $description = $form->escape( $form->{$descvar}, 1 );
  1944. $department = $form->escape( $form->{department}, 1 );
  1945. $form->sort_order();
  1946. $callback =
  1947. "$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}";
  1948. $form->{title} = $locale->text('GIFI') . " - "
  1949. if ( $form->{accno} =~ /^gifi_/ );
  1950. $title = $form->escape( $form->{title} );
  1951. $href .= "&title=$title";
  1952. $title = $form->escape( $form->{title}, 1 );
  1953. $callback .= "&title=$title";
  1954. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1955. @columns =
  1956. $form->sort_columns(
  1957. qw(id transdate invnumber name description netamount tax total));
  1958. $form->{"l_description"} = "" if $form->{summary};
  1959. foreach $item (@columns) {
  1960. if ( $form->{"l_$item"} eq "Y" ) {
  1961. push @column_index, $item;
  1962. # add column to href and callback
  1963. $callback .= "&l_$item=Y";
  1964. $href .= "&l_$item=Y";
  1965. }
  1966. }
  1967. if ( $form->{l_subtotal} eq 'Y' ) {
  1968. $callback .= "&l_subtotal=Y";
  1969. $href .= "&l_subtotal=Y";
  1970. }
  1971. if ( $form->{department} ) {
  1972. ($department) = split /--/, $form->{department};
  1973. $option = $locale->text('Department') . " : $department";
  1974. }
  1975. # if there are any dates
  1976. if ( $form->{fromdate} || $form->{todate} ) {
  1977. if ( $form->{fromdate} ) {
  1978. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1979. }
  1980. if ( $form->{todate} ) {
  1981. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1982. }
  1983. $form->{period} = "$fromdate - $todate";
  1984. }
  1985. else {
  1986. $form->{period} =
  1987. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1988. }
  1989. if ( $form->{db} eq 'ar' ) {
  1990. $name = $locale->text('Customer');
  1991. $invoice = 'is.pl';
  1992. $arap = 'ar.pl';
  1993. }
  1994. if ( $form->{db} eq 'ap' ) {
  1995. $name = $locale->text('Vendor');
  1996. $invoice = 'ir.pl';
  1997. $arap = 'ap.pl';
  1998. }
  1999. $option .= "<br>" if $option;
  2000. $option .= "$form->{period}";
  2001. $column_header{id} =
  2002. qq|<th><a class=listheading href=$href&sort=id>|
  2003. . $locale->text('ID')
  2004. . qq|</th>|;
  2005. $column_header{invnumber} =
  2006. qq|<th><a class=listheading href=$href&sort=invnumber>|
  2007. . $locale->text('Invoice')
  2008. . qq|</th>|;
  2009. $column_header{transdate} =
  2010. qq|<th><a class=listheading href=$href&sort=transdate>|
  2011. . $locale->text('Date')
  2012. . qq|</th>|;
  2013. $column_header{netamount} =
  2014. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  2015. $column_header{tax} =
  2016. qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
  2017. $column_header{total} =
  2018. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  2019. $column_header{name} =
  2020. qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  2021. $column_header{description} =
  2022. qq|<th><a class=listheading href=$href&sort=description>|
  2023. . $locale->text('Description')
  2024. . qq|</th>|;
  2025. $form->header;
  2026. print qq|
  2027. <body>
  2028. <table width=100%>
  2029. <tr>
  2030. <th class=listtop colspan=$colspan>$form->{title}</th>
  2031. </tr>
  2032. <tr height="5"></tr>
  2033. <tr>
  2034. <td>$option</td>
  2035. </tr>
  2036. <tr>
  2037. <td>
  2038. <table width=100%>
  2039. <tr class=listheading>
  2040. |;
  2041. for (@column_index) { print "$column_header{$_}\n" }
  2042. print qq|
  2043. </tr>
  2044. |;
  2045. # add sort and escape callback
  2046. $callback = $form->escape( $callback . "&sort=$form->{sort}" );
  2047. if ( @{ $form->{TR} } ) {
  2048. $sameitem = $form->{TR}->[0]->{ $form->{sort} };
  2049. }
  2050. foreach $ref ( @{ $form->{TR} } ) {
  2051. $module = ( $ref->{invoice} ) ? $invoice : $arap;
  2052. $module = 'ps.pl' if $ref->{till};
  2053. if ( $form->{l_subtotal} eq 'Y' ) {
  2054. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  2055. &tax_subtotal;
  2056. $sameitem = $ref->{ $form->{sort} };
  2057. }
  2058. }
  2059. $totalnetamount += $ref->{netamount};
  2060. $totaltax += $ref->{tax};
  2061. $ref->{total} = $ref->{netamount} + $ref->{tax};
  2062. $subtotalnetamount += $ref->{netamount};
  2063. $subtotaltax += $ref->{tax};
  2064. for (qw(netamount tax total)) {
  2065. $ref->{$_} =
  2066. $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" );
  2067. }
  2068. $column_data{id} = qq|<td>$ref->{id}</td>|;
  2069. $column_data{invnumber} =
  2070. 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>|;
  2071. for (qw(id transdate name partnumber description)) {
  2072. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  2073. }
  2074. for (qw(netamount tax total)) {
  2075. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  2076. }
  2077. $i++;
  2078. $i %= 2;
  2079. print qq|
  2080. <tr class=listrow$i>
  2081. |;
  2082. for (@column_index) { print "$column_data{$_}\n" }
  2083. print qq|
  2084. </tr>
  2085. |;
  2086. }
  2087. if ( $form->{l_subtotal} eq 'Y' ) {
  2088. &tax_subtotal;
  2089. }
  2090. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  2091. print qq|
  2092. </tr>
  2093. <tr class=listtotal>
  2094. |;
  2095. $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax,
  2096. 2, "&nbsp;" );
  2097. $totalnetamount =
  2098. $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" );
  2099. $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, "&nbsp;" );
  2100. $column_data{netamount} =
  2101. qq|<th class=listtotal align=right>$totalnetamount</th>|;
  2102. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  2103. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  2104. for (@column_index) { print "$column_data{$_}\n" }
  2105. print qq|
  2106. </tr>
  2107. </table>
  2108. </td>
  2109. </tr>
  2110. <tr>
  2111. <td><hr size=3 noshade></td>
  2112. </tr>
  2113. </table>
  2114. </body>
  2115. </html>
  2116. |;
  2117. }
  2118. sub tax_subtotal {
  2119. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2120. $subtotal =
  2121. $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax,
  2122. 2, "&nbsp;" );
  2123. $subtotalnetamount =
  2124. $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" );
  2125. $subtotaltax =
  2126. $form->format_amount( \%myconfig, $subtotaltax, 2, "&nbsp;" );
  2127. $column_data{netamount} =
  2128. "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  2129. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  2130. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  2131. $subtotalnetamount = 0;
  2132. $subtotaltax = 0;
  2133. print qq|
  2134. <tr class=listsubtotal>
  2135. |;
  2136. for (@column_index) { print "\n$column_data{$_}" }
  2137. print qq|
  2138. </tr>
  2139. |;
  2140. }
  2141. sub list_payments {
  2142. if ( $form->{account} ) {
  2143. ( $form->{paymentaccounts} ) = split /--/, $form->{account};
  2144. }
  2145. if ( $form->{department} ) {
  2146. ( $department, $form->{department_id} ) = split /--/,
  2147. $form->{department};
  2148. $option = $locale->text('Department') . " : $department";
  2149. }
  2150. RP->payments( \%myconfig, \%$form );
  2151. @columns = $form->sort_columns(qw(transdate name paid source memo));
  2152. if ( $form->{till} ) {
  2153. @columns =
  2154. $form->sort_columns(qw(transdate name paid curr source till));
  2155. if ( $myconfig{role} ne 'user' ) {
  2156. @columns =
  2157. $form->sort_columns(
  2158. qw(transdate name paid curr source till employee));
  2159. }
  2160. }
  2161. # construct href
  2162. $title = $form->escape( $form->{title} );
  2163. $form->{paymentaccounts} =~ s/ /%20/g;
  2164. $href =
  2165. "$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="
  2166. . $form->escape( $form->{title} );
  2167. $form->sort_order();
  2168. $form->{callback} =
  2169. "$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="
  2170. . $form->escape( $form->{title}, 1 );
  2171. if ( $form->{account} ) {
  2172. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  2173. $href .= "&account=" . $form->escape( $form->{account} );
  2174. $option .= "\n<br>" if ($option);
  2175. $option .= $locale->text('Account') . " : $form->{account}";
  2176. }
  2177. if ( $form->{department} ) {
  2178. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  2179. $href .= "&department=" . $form->escape( $form->{department} );
  2180. $option .= "\n<br>" if ($option);
  2181. $option .= $locale->text('Department') . " : $form->{department}";
  2182. }
  2183. if ( $form->{description} ) {
  2184. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  2185. $href .= "&description=" . $form->escape( $form->{description} );
  2186. $option .= "\n<br>" if ($option);
  2187. $option .= $locale->text('Description') . " : $form->{description}";
  2188. }
  2189. if ( $form->{source} ) {
  2190. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  2191. $href .= "&source=" . $form->escape( $form->{source} );
  2192. $option .= "\n<br>" if ($option);
  2193. $option .= $locale->text('Source') . " : $form->{source}";
  2194. }
  2195. if ( $form->{memo} ) {
  2196. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  2197. $href .= "&memo=" . $form->escape( $form->{memo} );
  2198. $option .= "\n<br>" if ($option);
  2199. $option .= $locale->text('Memo') . " : $form->{memo}";
  2200. }
  2201. if ( $form->{fromdate} ) {
  2202. $option .= "\n<br>" if ($option);
  2203. $option .=
  2204. $locale->text('From') . "&nbsp;"
  2205. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  2206. }
  2207. if ( $form->{todate} ) {
  2208. $option .= "\n<br>" if ($option);
  2209. $option .=
  2210. $locale->text('To') . "&nbsp;"
  2211. . $locale->date( \%myconfig, $form->{todate}, 1 );
  2212. }
  2213. $callback = $form->escape( $form->{callback} );
  2214. $column_header{name} =
  2215. "<th><a class=listheading href=$href&sort=name>"
  2216. . $locale->text('Description')
  2217. . "</a></th>";
  2218. $column_header{transdate} =
  2219. "<th><a class=listheading href=$href&sort=transdate>"
  2220. . $locale->text('Date')
  2221. . "</a></th>";
  2222. $column_header{paid} =
  2223. "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
  2224. $column_header{curr} =
  2225. "<th class=listheading>" . $locale->text('Curr') . "</a></th>";
  2226. $column_header{source} =
  2227. "<th><a class=listheading href=$href&sort=source>"
  2228. . $locale->text('Source')
  2229. . "</a></th>";
  2230. $column_header{memo} =
  2231. "<th><a class=listheading href=$href&sort=memo>"
  2232. . $locale->text('Memo')
  2233. . "</a></th>";
  2234. $column_header{employee} =
  2235. "<th><a class=listheading href=$href&sort=employee>"
  2236. . $locale->text('Salesperson')
  2237. . "</a></th>";
  2238. $column_header{till} =
  2239. "<th><a class=listheading href=$href&sort=till>"
  2240. . $locale->text('Till')
  2241. . "</a></th>";
  2242. @column_index = @columns;
  2243. $colspan = $#column_index + 1;
  2244. $form->header;
  2245. print qq|
  2246. <body>
  2247. <table width=100%>
  2248. <tr>
  2249. <th class=listtop>$form->{title}</th>
  2250. </tr>
  2251. <tr height="5"></tr>
  2252. <tr>
  2253. <td>$option</td>
  2254. </tr>
  2255. <tr>
  2256. <td>
  2257. <table width=100%>
  2258. <tr class=listheading>
  2259. |;
  2260. for (@column_index) { print "\n$column_header{$_}" }
  2261. print qq|
  2262. </tr>
  2263. |;
  2264. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) {
  2265. next unless @{ $form->{ $ref->{id} } };
  2266. print qq|
  2267. <tr>
  2268. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  2269. </tr>
  2270. |;
  2271. if ( @{ $form->{ $ref->{id} } } ) {
  2272. $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} };
  2273. }
  2274. foreach $payment ( @{ $form->{ $ref->{id} } } ) {
  2275. if ( $form->{l_subtotal} ) {
  2276. if ( $payment->{ $form->{sort} } ne $sameitem ) {
  2277. # print subtotal
  2278. &payment_subtotal;
  2279. }
  2280. }
  2281. next if ( $form->{till} && !$payment->{till} );
  2282. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  2283. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  2284. $column_data{paid} =
  2285. "<td align=right>"
  2286. . $form->format_amount( \%myconfig, $payment->{paid}, 2,
  2287. "&nbsp;" )
  2288. . "</td>";
  2289. $column_data{curr} = "<td>$payment->{curr}</td>";
  2290. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  2291. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  2292. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  2293. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  2294. $subtotalpaid += $payment->{paid};
  2295. $accounttotalpaid += $payment->{paid};
  2296. $totalpaid += $payment->{paid};
  2297. $i++;
  2298. $i %= 2;
  2299. print qq|
  2300. <tr class=listrow$i>
  2301. |;
  2302. for (@column_index) { print "\n$column_data{$_}" }
  2303. print qq|
  2304. </tr>
  2305. |;
  2306. $sameitem = $payment->{ $form->{sort} };
  2307. }
  2308. &payment_subtotal if $form->{l_subtotal};
  2309. # print account totals
  2310. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2311. $column_data{paid} =
  2312. "<th class=listtotal align=right>"
  2313. . $form->format_amount( \%myconfig, $accounttotalpaid, 2, "&nbsp;" )
  2314. . "</th>";
  2315. print qq|
  2316. <tr class=listtotal>
  2317. |;
  2318. for (@column_index) { print "\n$column_data{$_}" }
  2319. print qq|
  2320. </tr>
  2321. |;
  2322. $accounttotalpaid = 0;
  2323. }
  2324. # print total
  2325. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2326. $column_data{paid} =
  2327. "<th class=listtotal align=right>"
  2328. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  2329. print qq|
  2330. <tr class=listtotal>
  2331. |;
  2332. for (@column_index) { print "\n$column_data{$_}" }
  2333. print qq|
  2334. </tr>
  2335. </table>
  2336. </td>
  2337. </tr>
  2338. <tr>
  2339. <td><hr size=3 noshade></td>
  2340. </tr>
  2341. </table>
  2342. |;
  2343. if ( $form->{lynx} ) {
  2344. require "bin/menu.pl";
  2345. &menubar;
  2346. }
  2347. print qq|
  2348. </body>
  2349. </html>
  2350. |;
  2351. }
  2352. sub payment_subtotal {
  2353. if ( $subtotalpaid != 0 ) {
  2354. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2355. $column_data{paid} =
  2356. "<th class=listsubtotal align=right>"
  2357. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  2358. . "</th>";
  2359. print qq|
  2360. <tr class=listsubtotal>
  2361. |;
  2362. for (@column_index) { print "\n$column_data{$_}" }
  2363. print qq|
  2364. </tr>
  2365. |;
  2366. }
  2367. $subtotalpaid = 0;
  2368. }