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