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