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