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