summaryrefslogtreecommitdiff
path: root/bin/lynx/rp.pl
blob: d9803c939e4155731ee3db9353363e30802cd359 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (c) 2001
  4. #
  5. # Author: DWS Systems Inc.
  6. # Web: http://sourceforge.net/projects/ledger-smb/
  7. #
  8. # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
  9. # Benjamin Lee <benjaminlee@consultant.com>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. #======================================================================
  24. #
  25. # module for preparing Income Statement and Balance Sheet
  26. #
  27. #======================================================================
  28. require "$form->{path}/arap.pl";
  29. use SL::PE;
  30. use SL::RP;
  31. 1;
  32. # end of main
  33. # this is for our long dates
  34. # $locale->text('January')
  35. # $locale->text('February')
  36. # $locale->text('March')
  37. # $locale->text('April')
  38. # $locale->text('May ')
  39. # $locale->text('June')
  40. # $locale->text('July')
  41. # $locale->text('August')
  42. # $locale->text('September')
  43. # $locale->text('October')
  44. # $locale->text('November')
  45. # $locale->text('December')
  46. # this is for our short month
  47. # $locale->text('Jan')
  48. # $locale->text('Feb')
  49. # $locale->text('Mar')
  50. # $locale->text('Apr')
  51. # $locale->text('May')
  52. # $locale->text('Jun')
  53. # $locale->text('Jul')
  54. # $locale->text('Aug')
  55. # $locale->text('Sep')
  56. # $locale->text('Oct')
  57. # $locale->text('Nov')
  58. # $locale->text('Dec')
  59. # $locale->text('Balance Sheet')
  60. # $locale->text('Income Statement')
  61. # $locale->text('Trial Balance')
  62. # $locale->text('AR Aging')
  63. # $locale->text('AP Aging')
  64. # $locale->text('Tax collected')
  65. # $locale->text('Tax paid')
  66. # $locale->text('Receipts')
  67. # $locale->text('Payments')
  68. # $locale->text('Project Transactions')
  69. # $locale->text('Non-taxable Sales')
  70. # $locale->text('Non-taxable Purchases')
  71. sub report {
  72. %report = ( balance_sheet => { title => 'Balance Sheet' },
  73. income_statement => { title => 'Income Statement' },
  74. trial_balance => { title => 'Trial Balance' },
  75. ar_aging => { title => 'AR Aging', vc => 'customer' },
  76. ap_aging => { title => 'AP Aging', vc => 'vendor' },
  77. tax_collected => { title => 'Tax collected', vc => 'customer' },
  78. tax_paid => { title => 'Tax paid' },
  79. nontaxable_sales => { title => 'Non-taxable Sales', vc => 'customer' },
  80. nontaxable_purchases => { title => 'Non-taxable Purchases' },
  81. receipts => { title => 'Receipts', vc => 'customer' },
  82. payments => { title => 'Payments' },
  83. projects => { title => 'Project Transactions' },
  84. );
  85. $form->{title} = $locale->text($report{$form->{report}}->{title});
  86. $gifi = qq|
  87. <tr>
  88. <th align=right>|.$locale->text('Accounts').qq|</th>
  89. <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
  90. <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
  91. </td>
  92. </tr>
  93. |;
  94. # get departments
  95. $form->all_departments(\%myconfig, undef, $report{$form->{report}}->{vc});
  96. if (@{ $form->{all_department} }) {
  97. $form->{selectdepartment} = "<option>\n";
  98. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  99. }
  100. $department = qq|
  101. <tr>
  102. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  103. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  104. </tr>
  105. | if $form->{selectdepartment};
  106. if (@{ $form->{all_years} }) {
  107. # accounting years
  108. $form->{selectaccountingyear} = "<option>\n";
  109. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  110. $form->{selectaccountingmonth} = "<option>\n";
  111. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  112. $selectfrom = qq|
  113. <tr>
  114. <th align=right>|.$locale->text('Period').qq|</th>
  115. <td colspan=3>
  116. <select name=month>$form->{selectaccountingmonth}</select>
  117. <select name=year>$form->{selectaccountingyear}</select>
  118. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  119. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  120. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  121. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  122. </td>
  123. </tr>
  124. |;
  125. $selectto = qq|
  126. <tr>
  127. <th align=right></th>
  128. <td>
  129. <select name=month>$form->{selectaccountingmonth}</select>
  130. <select name=year>$form->{selectaccountingyear}</select>
  131. </td>
  132. </tr>
  133. |;
  134. }
  135. $summary = qq|
  136. <tr>
  137. <th></th>
  138. <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
  139. <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
  140. </td>
  141. </tr>
  142. |;
  143. # get projects
  144. $form->all_projects(\%myconfig);
  145. if (@{ $form->{all_project} }) {
  146. $form->{selectproject} = "<option>\n";
  147. for (@{ $form->{all_project} }) { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  148. $project = qq|
  149. <tr>
  150. <th align=right nowrap>|.$locale->text('Project').qq|</th>
  151. <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
  152. </tr>|;
  153. }
  154. $form->header;
  155. print qq|
  156. <body>
  157. <form method=post action=$form->{script}>
  158. <input type=hidden name=title value="$form->{title}">
  159. <table width=100%>
  160. <tr>
  161. <th class=listtop>$form->{title}</th>
  162. </tr>
  163. <tr height="5"></tr>
  164. <tr>
  165. <td>
  166. <table>
  167. $department
  168. |;
  169. if ($form->{report} eq "projects") {
  170. print qq|
  171. $project
  172. <input type=hidden name=nextsub value=generate_projects>
  173. <tr>
  174. <th align=right>|.$locale->text('From').qq|</th>
  175. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  176. <th align=right>|.$locale->text('To').qq|</th>
  177. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  178. </tr>
  179. $selectfrom
  180. </table>
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>
  185. <table>
  186. <tr>
  187. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  188. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  189. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
  190. </tr>
  191. |;
  192. }
  193. if ($form->{report} eq "income_statement") {
  194. print qq|
  195. $project
  196. <input type=hidden name=nextsub value=generate_income_statement>
  197. <tr>
  198. <th align=right>|.$locale->text('From').qq|</th>
  199. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  200. <th align=right>|.$locale->text('To').qq|</th>
  201. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  202. </tr>
  203. |;
  204. if ($selectfrom) {
  205. print qq|
  206. <tr>
  207. <th align=right>|.$locale->text('Period').qq|</th>
  208. <td colspan=3>
  209. <select name=frommonth>$form->{selectaccountingmonth}</select>
  210. <select name=fromyear>$form->{selectaccountingyear}</select>
  211. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  212. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  213. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  214. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  215. </td>
  216. </tr>
  217. |;
  218. }
  219. print qq|
  220. <tr>
  221. <th align=right>|.$locale->text('Compare to').qq|</th>
  222. </tr>
  223. <tr>
  224. <th align=right>|.$locale->text('From').qq|</th>
  225. <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
  226. <th align=right>|.$locale->text('To').qq|</th>
  227. <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
  228. </tr>
  229. |;
  230. if ($selectto) {
  231. print qq|
  232. <tr>
  233. <th align=right>|.$locale->text('Period').qq|</th>
  234. <td>
  235. <select name=comparemonth>$form->{selectaccountingmonth}</select>
  236. <select name=compareyear>$form->{selectaccountingyear}</select>
  237. </td>
  238. </tr>
  239. |;
  240. }
  241. print qq|
  242. <tr>
  243. <th align=right>|.$locale->text('Decimalplaces').qq|</th>
  244. <td><input name=decimalplaces size=3 value=2></td>
  245. </tr>
  246. </table>
  247. </td>
  248. </tr>
  249. <tr>
  250. <td>
  251. <table>
  252. <tr>
  253. <th align=right>|.$locale->text('Method').qq|</th>
  254. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  255. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  256. </tr>
  257. <tr>
  258. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  259. <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  260. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  261. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
  262. </tr>
  263. |;
  264. }
  265. if ($form->{report} eq "balance_sheet") {
  266. print qq|
  267. <input type=hidden name=nextsub value=generate_balance_sheet>
  268. <tr>
  269. <th align=right>|.$locale->text('as at').qq|</th>
  270. <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
  271. |;
  272. if ($selectfrom) {
  273. print qq|
  274. <td>
  275. <select name=asofmonth>$form->{selectaccountingmonth}</select>
  276. <select name=asofyear>$form->{selectaccountingyear}</select>
  277. </td>
  278. |;
  279. }
  280. print qq|
  281. </tr>
  282. <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
  283. <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
  284. <td>
  285. |;
  286. if ($selectto) {
  287. print qq|
  288. <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
  289. <select name=compareasofyear>$form->{selectaccountingyear}</select>
  290. </td>
  291. |;
  292. }
  293. print qq|
  294. </tr>
  295. <tr>
  296. <th align=right>|.$locale->text('Decimalplaces').qq|</th>
  297. <td><input name=decimalplaces size=3 value=2></td>
  298. </tr>
  299. </table>
  300. </td>
  301. </tr>
  302. <tr>
  303. <td>
  304. <table>
  305. <tr>
  306. <th align=right>|.$locale->text('Method').qq|</th>
  307. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  308. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  309. </tr>
  310. <tr>
  311. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  312. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  313. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  314. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
  315. </tr>
  316. |;
  317. }
  318. if ($form->{report} eq "trial_balance") {
  319. print qq|
  320. <input type=hidden name=nextsub value=generate_trial_balance>
  321. <tr>
  322. <th align=right>|.$locale->text('From').qq|</th>
  323. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  324. <th align=right>|.$locale->text('To').qq|</th>
  325. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  326. </tr>
  327. $selectfrom
  328. </table>
  329. </td>
  330. </tr>
  331. <tr>
  332. <td>
  333. <table>
  334. <tr>
  335. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  336. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  337. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  338. <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('All Accounts').qq|</td>
  339. </tr>
  340. |;
  341. }
  342. if ($form->{report} =~ /^tax_/) {
  343. $gifi = "";
  344. $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
  345. RP->get_taxaccounts(\%myconfig, \%$form);
  346. print qq|
  347. <input type=hidden name=nextsub value=generate_tax_report>
  348. <tr>
  349. <th align=right>|.$locale->text('From').qq|</th>
  350. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  351. <th align=right>|.$locale->text('To').qq|</th>
  352. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  353. </tr>
  354. $selectfrom
  355. $summary
  356. <tr>
  357. <th align=right>|.$locale->text('Report for').qq|</th>
  358. <td colspan=3>
  359. |;
  360. $checked = "checked";
  361. foreach $ref (@{ $form->{taxaccounts} }) {
  362. print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
  363. <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
  364. <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  365. $checked = "";
  366. }
  367. print qq|
  368. <input type=hidden name=db value=$form->{db}>
  369. <input type=hidden name=sort value=transdate>
  370. </td>
  371. </tr>
  372. |;
  373. if (@{ $form->{gifi_taxaccounts} }) {
  374. print qq|
  375. <tr>
  376. <th align=right>|.$locale->text('GIFI').qq|</th>
  377. <td colspan=3>
  378. |;
  379. foreach $ref (@{ $form->{gifi_taxaccounts} }) {
  380. print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
  381. <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
  382. <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  383. }
  384. print qq|
  385. </td>
  386. </tr>
  387. |;
  388. }
  389. print qq|
  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>|.$locale->text('Accrual').qq|
  393. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  394. </tr>
  395. </table>
  396. </td>
  397. </tr>
  398. <tr>
  399. <td>
  400. <table>
  401. <tr>
  402. <th align=right>|.$locale->text('Include in Report').qq|</th>
  403. <td>
  404. <table>
  405. <tr>
  406. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  407. <td>|.$locale->text('ID').qq|</td>
  408. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  409. <td>|.$locale->text('Invoice').qq|</td>
  410. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  411. <td>|.$locale->text('Date').qq|</td>
  412. </tr>
  413. <tr>
  414. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  415. |;
  416. if ($form->{db} eq 'ar') {
  417. print qq|<td>|.$locale->text('Customer').qq|</td>|;
  418. }
  419. if ($form->{db} eq 'ap') {
  420. print qq|<td>|.$locale->text('Vendor').qq|</td>|;
  421. }
  422. print qq|
  423. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  424. <td>|.$locale->text('Description').qq|</td>
  425. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  426. <td>|.$locale->text('Amount').qq|</td>
  427. <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
  428. <td>|.$locale->text('Tax').qq|</td>
  429. <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
  430. <td>|.$locale->text('Total').qq|</td>
  431. </tr>
  432. <tr>
  433. </tr>
  434. <tr>
  435. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  436. <td>|.$locale->text('Subtotal').qq|</td>
  437. </tr>
  438. </table>
  439. </td>
  440. </tr>
  441. |;
  442. }
  443. if ($form->{report} =~ /^nontaxable_/) {
  444. $gifi = "";
  445. $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
  446. print qq|
  447. <input type=hidden name=nextsub value=generate_tax_report>
  448. <input type=hidden name=db value=$form->{db}>
  449. <input type=hidden name=sort value=transdate>
  450. <input type=hidden name=report value=$form->{report}>
  451. <tr>
  452. <th align=right>|.$locale->text('From').qq|</th>
  453. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  454. <th align=right>|.$locale->text('To').qq|</th>
  455. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  456. </tr>
  457. $selectfrom
  458. $summary
  459. <tr>
  460. <th align=right>|.$locale->text('Method').qq|</th>
  461. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  462. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  463. </tr>
  464. <tr>
  465. <th align=right>|.$locale->text('Include in Report').qq|</th>
  466. <td colspan=3>
  467. <table>
  468. <tr>
  469. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  470. <td>|.$locale->text('ID').qq|</td>
  471. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  472. <td>|.$locale->text('Invoice').qq|</td>
  473. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  474. <td>|.$locale->text('Date').qq|</td>
  475. </tr>
  476. <tr>
  477. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  478. |;
  479. if ($form->{db} eq 'ar') {
  480. print qq|<td>|.$locale->text('Customer').qq|</td>|;
  481. }
  482. if ($form->{db} eq 'ap') {
  483. print qq|<td>|.$locale->text('Vendor').qq|</td>|;
  484. }
  485. print qq|
  486. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  487. <td>|.$locale->text('Description').qq|</td>
  488. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  489. <td>|.$locale->text('Amount').qq|</td>
  490. </tr>
  491. <tr>
  492. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  493. <td>|.$locale->text('Subtotal').qq|</td>
  494. </tr>
  495. </table>
  496. </td>
  497. </tr>
  498. |;
  499. }
  500. if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
  501. $gifi = "";
  502. if ($form->{report} eq 'ar_aging') {
  503. $label = $locale->text('Customer');
  504. $form->{vc} = 'customer';
  505. } else {
  506. $label = $locale->text('Vendor');
  507. $form->{vc} = 'vendor';
  508. }
  509. $nextsub = "generate_$form->{report}";
  510. # setup vc selection
  511. $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
  512. for (@{ $form->{"all_$form->{vc}"} }) { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  513. $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
  514. $postscript = "postscript" if $myconfig{printer};
  515. print qq|
  516. <tr>
  517. <th align=right>|.$locale->text($label).qq|</th>
  518. <td>$vc</td>
  519. </tr>
  520. <tr>
  521. <th align=right>|.$locale->text('To').qq|</th>
  522. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  523. </tr>
  524. $selectto
  525. <input type=hidden name=type value=statement>
  526. <input type=hidden name=format value=$postscript>
  527. <input type=hidden name=media value="$myconfig{printer}">
  528. <input type=hidden name=nextsub value=$nextsub>
  529. <input type=hidden name=action value=$nextsub>
  530. $summary
  531. <tr>
  532. <table>
  533. <tr>
  534. <th>|.$locale->text('Include in Report').qq|</th>
  535. <td>
  536. <table>
  537. <tr>
  538. <td nowrap><input name=overdue type=radio class=radio value=0 checked> |.$locale->text('Aged').qq|</td>
  539. <td nowrap><input name=overdue type=radio class=radio value=1> |.$locale->text('Overdue').qq|</td>
  540. </tr>
  541. <tr>
  542. <td nowrap width=70><input name=c0 type=checkbox class=checkbox value=1 checked> |.$locale->text('Current').qq|</td>
  543. <td nowrap width=70><input name=c30 type=checkbox class=checkbox value=1 checked> 30</td>
  544. <td nowrap width=70><input name=c60 type=checkbox class=checkbox value=1 checked> 60</td>
  545. <td nowrap width=70><input name=c90 type=checkbox class=checkbox value=1 checked> 90</td>
  546. </td>
  547. </tr>
  548. </table>
  549. </td>
  550. </tr>
  551. </table>
  552. </tr>
  553. |;
  554. }
  555. # above action can be removed if there is more than one input field
  556. if ($form->{report} =~ /(receipts|payments)$/) {
  557. $gifi = "";
  558. $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
  559. RP->paymentaccounts(\%myconfig, \%$form);
  560. $selection = "<option>\n";
  561. foreach $ref (@{ $form->{PR} }) {
  562. $paymentaccounts .= "$ref->{accno} ";
  563. $selection .= "<option>$ref->{accno}--$ref->{description}\n";
  564. }
  565. chop $paymentaccounts;
  566. print qq|
  567. <input type=hidden name=nextsub value=list_payments>
  568. <tr>
  569. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  570. <td colspan=3><select name=account>$selection</select>
  571. <input type=hidden name=paymentaccounts value="$paymentaccounts">
  572. </td>
  573. </tr>
  574. <tr>
  575. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  576. <td colspan=3><input name=description size=35></td>
  577. </tr>
  578. <tr>
  579. <th align=right nowrap>|.$locale->text('Source').qq|</th>
  580. <td colspan=3><input name=source></td>
  581. </tr>
  582. <tr>
  583. <th align=right nowrap>|.$locale->text('Memo').qq|</th>
  584. <td colspan=3><input name=memo size=30></td>
  585. </tr>
  586. <tr>
  587. <th align=right>|.$locale->text('From').qq|</th>
  588. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  589. <th align=right>|.$locale->text('To').qq|</th>
  590. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  591. </tr>
  592. $selectfrom
  593. <tr>
  594. <td align=right><input type=checkbox class=checkbox name=fx_transaction value=1 checked></td>
  595. <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td>
  596. </tr>
  597. <tr>
  598. <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
  599. <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th>
  600. </tr>
  601. <input type=hidden name=db value=$form->{db}>
  602. <input type=hidden name=sort value=transdate>
  603. |;
  604. }
  605. print qq|
  606. $gifi
  607. </table>
  608. </td>
  609. </tr>
  610. <tr>
  611. <td><hr size=3 noshade></td>
  612. </tr>
  613. </table>
  614. <br>
  615. <input type=hidden name=path value=$form->{path}>
  616. <input type=hidden name=login value=$form->{login}>
  617. <input type=hidden name=sessionid value=$form->{sessionid}>
  618. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  619. </form>
  620. |;
  621. if ($form->{menubar}) {
  622. require "$form->{path}/menu.pl";
  623. &menubar;
  624. }
  625. print qq|
  626. </body>
  627. </html>
  628. |;
  629. }
  630. sub continue { &{$form->{nextsub}} };
  631. sub generate_income_statement {
  632. $form->{padding} = "&nbsp;&nbsp;";
  633. $form->{bold} = "<b>";
  634. $form->{endbold} = "</b>";
  635. $form->{br} = "<br>";
  636. RP->income_statement(\%myconfig, \%$form);
  637. ($form->{department}) = split /--/, $form->{department};
  638. ($form->{projectnumber}) = split /--/, $form->{projectnumber};
  639. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  640. $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
  641. # if there are any dates construct a where
  642. if ($form->{fromdate} || $form->{todate}) {
  643. unless ($form->{todate}) {
  644. $form->{todate} = $form->current_date(\%myconfig);
  645. }
  646. $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
  647. $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
  648. $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  649. $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
  650. $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
  651. $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;
  652. }
  653. if ($form->{comparefromdate} || $form->{comparetodate}) {
  654. $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
  655. $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
  656. $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
  657. $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
  658. $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
  659. $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;
  660. }
  661. # setup variables for the form
  662. @a = qw(company address businessnumber);
  663. for (@a) { $form->{$_} = $myconfig{$_} }
  664. $form->{address} =~ s/\\n/<br>/g;
  665. $form->{templates} = $myconfig{templates};
  666. $form->{IN} = "income_statement.html";
  667. $form->parse_template;
  668. }
  669. sub generate_balance_sheet {
  670. $form->{padding} = "&nbsp;&nbsp;";
  671. $form->{bold} = "<b>";
  672. $form->{endbold} = "</b>";
  673. $form->{br} = "<br>";
  674. RP->balance_sheet(\%myconfig, \%$form);
  675. $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
  676. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  677. ($form->{department}) = split /--/, $form->{department};
  678. # define Current Earnings account
  679. $padding = ($form->{l_heading}) ? $form->{padding} : "";
  680. push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings'));
  681. $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
  682. $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
  683. $form->{IN} = "balance_sheet.html";
  684. # setup company variables for the form
  685. for (qw(company address businessnumber nativecurr)) { $form->{$_} = $myconfig{$_} }
  686. $form->{address} =~ s/\\n/<br>/g;
  687. $form->{templates} = $myconfig{templates};
  688. $form->parse_template;
  689. }
  690. sub generate_projects {
  691. $form->{nextsub} = "generate_projects";
  692. $form->{title} = $locale->text('Project Transactions');
  693. RP->trial_balance(\%myconfig, \%$form);
  694. &list_accounts;
  695. }
  696. # Antonio Gallardo
  697. #
  698. # D.S. Feb 16, 2001
  699. # included links to display transactions for period entered
  700. # added headers and subtotals
  701. #
  702. sub generate_trial_balance {
  703. # get for each account initial balance, debits and credits
  704. RP->trial_balance(\%myconfig, \%$form);
  705. $form->{nextsub} = "generate_trial_balance";
  706. $form->{title} = $locale->text('Trial Balance');
  707. $form->{callback} = "$form->{script}?action=generate_trial_balance";
  708. for (qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)) { $form->{callback} .= "&$_=$form->{$_}" }
  709. $form->{callback} = $form->escape($form->{callback});
  710. &list_accounts;
  711. }
  712. sub list_accounts {
  713. $title = $form->escape($form->{title});
  714. if ($form->{department}) {
  715. ($department) = split /--/, $form->{department};
  716. $options = $locale->text('Department')." : $department<br>";
  717. $department = $form->escape($form->{department});
  718. }
  719. if ($form->{projectnumber}) {
  720. ($projectnumber) = split /--/, $form->{projectnumber};
  721. $options .= $locale->text('Project Number')." : $projectnumber<br>";
  722. $projectnumber = $form->escape($form->{projectnumber});
  723. }
  724. # if there are any dates
  725. if ($form->{fromdate} || $form->{todate}) {
  726. if ($form->{fromdate}) {
  727. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  728. }
  729. if ($form->{todate}) {
  730. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  731. }
  732. $form->{period} = "$fromdate - $todate";
  733. } else {
  734. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  735. }
  736. $options .= $form->{period};
  737. @column_index = qw(accno description begbalance debit credit endbalance);
  738. $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
  739. $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  740. $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
  741. $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
  742. $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
  743. $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
  744. if ($form->{accounttype} eq 'gifi') {
  745. $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
  746. }
  747. $form->header;
  748. print qq|
  749. <body>
  750. <table width=100%>
  751. <tr>
  752. <th class=listtop>$form->{title}</th>
  753. </tr>
  754. <tr height="5"></tr>
  755. <tr>
  756. <td>$options</td>
  757. </tr>
  758. <tr>
  759. <td>
  760. <table width=100%>
  761. <tr>|;
  762. for (@column_index) { print "$column_header{$_}\n" }
  763. print qq|
  764. </tr>
  765. |;
  766. # sort the whole thing by account numbers and display
  767. foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
  768. $description = $form->escape($ref->{description});
  769. $href = 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}|;
  770. if ($form->{accounttype} eq 'gifi') {
  771. $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
  772. $na = $locale->text('N/A');
  773. if (!$ref->{accno}) {
  774. for (qw(accno description)) { $ref->{$_} = $na }
  775. }
  776. } else {
  777. $href .= "&accno=$ref->{accno}&description=$description";
  778. }
  779. $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
  780. $ml *= -1 if $ref->{contra};
  781. $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
  782. $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
  783. $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
  784. $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
  785. if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
  786. if ($subtotal) {
  787. for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  788. $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
  789. $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
  790. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  791. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  792. $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
  793. $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  794. $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  795. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
  796. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
  797. print qq|
  798. <tr class=listsubtotal>
  799. |;
  800. for (@column_index) { print "$column_data{$_}\n" }
  801. print qq|
  802. </tr>
  803. |;
  804. }
  805. }
  806. if ($ref->{charttype} eq "H") {
  807. $subtotal = 1;
  808. $subtotaldescription = $ref->{description};
  809. $subtotaldebit = $ref->{debit};
  810. $subtotalcredit = $ref->{credit};
  811. $subtotalbegbalance = 0;
  812. $subtotalendbalance = 0;
  813. if ($form->{l_heading}) {
  814. if (! $form->{all_accounts}) {
  815. if (($subtotaldebit + $subtotalcredit) == 0) {
  816. $subtotal = 0;
  817. next;
  818. }
  819. }
  820. } else {
  821. $subtotal = 0;
  822. if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) {
  823. $subtotal = 1;
  824. }
  825. next;
  826. }
  827. for (qw(accno debit credit begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  828. $column_data{description} = "<th class=listheading>$ref->{description}</th>";
  829. }
  830. if ($ref->{charttype} eq "A") {
  831. $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
  832. $column_data{description} = "<td>$ref->{description}</td>";
  833. $column_data{debit} = "<td align=right>$debit</td>";
  834. $column_data{credit} = "<td align=right>$credit</td>";
  835. $column_data{begbalance} = "<td align=right>$begbalance</td>";
  836. $column_data{endbalance} = "<td align=right>$endbalance</td>";
  837. $totaldebit += $ref->{debit};
  838. $totalcredit += $ref->{credit};
  839. $cml = ($ref->{contra}) ? -1 : 1;
  840. $subtotalbegbalance += $ref->{balance} * $ml * $cml;
  841. $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;
  842. }
  843. if ($ref->{charttype} eq "H") {
  844. print qq|
  845. <tr class=listheading>
  846. |;
  847. }
  848. if ($ref->{charttype} eq "A") {
  849. $i++; $i %= 2;
  850. print qq|
  851. <tr class=listrow$i>
  852. |;
  853. }
  854. for (@column_index) { print "$column_data{$_}\n" }
  855. print qq|
  856. </tr>
  857. |;
  858. }
  859. # print last subtotal
  860. if ($subtotal && $form->{l_subtotal}) {
  861. for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  862. $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
  863. $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
  864. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  865. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  866. $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
  867. $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  868. $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  869. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
  870. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
  871. print qq|
  872. <tr class=listsubtotal>
  873. |;
  874. for (@column_index) { print "$column_data{$_}\n" }
  875. print qq|
  876. </tr>
  877. |;
  878. }
  879. $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;");
  880. $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
  881. for (qw(accno description begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  882. $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
  883. $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
  884. print qq|
  885. <tr class=listtotal>
  886. |;
  887. for (@column_index) { print "$column_data{$_}\n" }
  888. print qq|
  889. </tr>
  890. </table>
  891. </td>
  892. </tr>
  893. <tr>
  894. <td><hr size=3 noshade></td>
  895. </tr>
  896. </table>
  897. </body>
  898. </html>
  899. |;
  900. }
  901. sub generate_ar_aging {
  902. # split customer
  903. ($form->{customer}) = split(/--/, $form->{customer});
  904. $customer = $form->escape($form->{customer},1);
  905. $title = $form->escape($form->{title},1);
  906. $media = $form->escape($form->{media},1);
  907. $form->{ct} = "customer";
  908. $form->{arap} = "ar";
  909. RP->aging(\%myconfig, \%$form);
  910. $form->{callback} = 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}|;
  911. &aging;
  912. }
  913. sub generate_ap_aging {
  914. # split vendor
  915. ($form->{vendor}) = split(/--/, $form->{vendor});
  916. $vendor = $form->escape($form->{vendor},1);
  917. $title = $form->escape($form->{title},1);
  918. $media = $form->escape($form->{media},1);
  919. $form->{ct} = "vendor";
  920. $form->{arap} = "ap";
  921. RP->aging(\%myconfig, \%$form);
  922. $form->{callback} = 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}|;
  923. &aging;
  924. }
  925. sub aging {
  926. $form->header;
  927. $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
  928. $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
  929. $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;
  930. $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
  931. $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
  932. $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|;
  933. $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|;
  934. $column_header{c0} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Current').qq|</th>|;
  935. $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
  936. $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
  937. $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
  938. $column_header{total} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Total').qq|</th>|;
  939. @column_index = qw(statement ct);
  940. if (@{ $form->{all_language} } && $form->{arap} eq 'ar') {
  941. push @column_index, "language";
  942. $form->{selectlanguage} = qq|<option>\n|;
  943. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  944. }
  945. @c = ();
  946. for (qw(c0 c30 c60 c90)) {
  947. if ($form->{$_}) {
  948. push @c, $_;
  949. $form->{callback} .= "&$_=$form->{$_}";
  950. }
  951. }
  952. if (!$form->{summary}) {
  953. push @column_index, qw(invnumber ordnumber transdate duedate);
  954. }
  955. push @column_index, @c;
  956. push @column_index, "total";
  957. $option = $locale->text('Aged');
  958. if ($form->{overdue}) {
  959. $option= $locale->text('Aged Overdue');
  960. $form->{callback} .= "&overdue=$form->{overdue}";
  961. }
  962. if ($form->{department}) {
  963. $option .= "\n<br>" if $option;
  964. ($department) = split /--/, $form->{department};
  965. $option .= $locale->text('Department')." : $department";
  966. $department = $form->escape($form->{department},1);
  967. $form->{callback} .= "&department=$department";
  968. }
  969. if ($form->{arap} eq 'ar') {
  970. if ($form->{customer}) {
  971. $option .= "\n<br>" if $option;
  972. $option .= $form->{customer};
  973. }
  974. }
  975. if ($form->{arap} eq 'ap') {
  976. shift @column_index;
  977. if ($form->{vendor}) {
  978. $option .= "\n<br>" if $option;
  979. $option .= $form->{vendor};
  980. }
  981. }
  982. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  983. $option .= "\n<br>" if $option;
  984. $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";
  985. print qq|
  986. <body>
  987. <form method=post action=$form->{script}>
  988. <table width=100%>
  989. <tr>
  990. <th class=listtop>$form->{title}</th>
  991. </tr>
  992. <tr height="5"></tr>
  993. <tr>
  994. <td>$option</td>
  995. </tr>
  996. <tr>
  997. <td>
  998. <table width=100%>
  999. |;
  1000. $ctid = 0;
  1001. $i = 0;
  1002. $k = 0;
  1003. $l = $#{ $form->{AG} };
  1004. foreach $ref (@{ $form->{AG} }) {
  1005. if ($curr ne $ref->{curr}) {
  1006. $ctid = 0;
  1007. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1008. if ($curr) {
  1009. $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp");
  1010. $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp");
  1011. $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp");
  1012. $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp");
  1013. $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp");
  1014. for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
  1015. $column_data{c0} = qq|<th align=right>$c0total</th>|;
  1016. $column_data{c30} = qq|<th align=right>$c30total</th>|;
  1017. $column_data{c60} = qq|<th align=right>$c60total</th>|;
  1018. $column_data{c90} = qq|<th align=right>$c90total</th>|;
  1019. $column_data{total} = qq|<th align=right>$total</th>|;
  1020. print qq|
  1021. <tr class=listtotal>
  1022. |;
  1023. for (@column_index) { print "$column_data{$_}\n" }
  1024. print qq|
  1025. </tr>
  1026. |;
  1027. $c0subtotal = 0;
  1028. $c30subtotal = 0;
  1029. $c60subtotal = 0;
  1030. $c90subtotal = 0;
  1031. $subtotal = 0;
  1032. $c0total = 0;
  1033. $c30total = 0;
  1034. $c60total = 0;
  1035. $c90total = 0;
  1036. $total = 0;
  1037. }
  1038. $curr = $ref->{curr};
  1039. print qq|
  1040. <tr>
  1041. <td></td>
  1042. <th>$curr</th>
  1043. </tr>
  1044. <tr class=listheading>
  1045. |;
  1046. for (@column_index) { print "$column_header{$_}\n" }
  1047. print qq|
  1048. </tr>
  1049. |;
  1050. }
  1051. $k++;
  1052. if ($ctid != $ref->{ctid}) {
  1053. $i++;
  1054. $column_data{ct} = qq|<td>$ref->{name}</td>|;
  1055. if ($form->{selectlanguage}) {
  1056. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1057. $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
  1058. $column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
  1059. }
  1060. $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
  1061. <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
  1062. <input type=hidden name="curr_$i" value=$ref->{curr}>
  1063. </td>|;
  1064. }
  1065. $ctid = $ref->{ctid};
  1066. for (qw(c0 c30 c60 c90)) { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) }
  1067. $c0subtotal += $ref->{c0};
  1068. $c30subtotal += $ref->{c30};
  1069. $c60subtotal += $ref->{c60};
  1070. $c90subtotal += $ref->{c90};
  1071. $c0total += $ref->{c0};
  1072. $c30total += $ref->{c30};
  1073. $c60total += $ref->{c60};
  1074. $c90total += $ref->{c90};
  1075. $ref->{total} = ($ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90});
  1076. $subtotal += $ref->{total};
  1077. $total += $ref->{total};
  1078. $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, "&nbsp;");
  1079. $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
  1080. $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
  1081. $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
  1082. $ref->{total} = $form->format_amount(\%myconfig, $ref->{total}, 2, "&nbsp;");
  1083. $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});
  1084. $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
  1085. for (qw(ordnumber transdate duedate)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  1086. for (qw(c0 c30 c60 c90 total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
  1087. if (!$form->{summary}) {
  1088. $j++; $j %= 2;
  1089. print qq|
  1090. <tr class=listrow$j>
  1091. |;
  1092. for (@column_index) { print "$column_data{$_}\n" }
  1093. print qq|
  1094. </tr>
  1095. |;
  1096. for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
  1097. }
  1098. # print subtotal
  1099. $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0;
  1100. if ($ctid != $nextid) {
  1101. $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
  1102. $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
  1103. $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
  1104. $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
  1105. $subtotal = $form->format_amount(\%myconfig, $subtotal, 2, "&nbsp");
  1106. if ($form->{summary}) {
  1107. $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
  1108. $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
  1109. $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
  1110. $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
  1111. $column_data{total} = qq|<td align=right>$subtotal</th>|;
  1112. $j++; $j %= 2;
  1113. print qq|
  1114. <tr class=listrow$j>
  1115. |;
  1116. for (@column_index) { print "$column_data{$_}\n" }
  1117. print qq|
  1118. </tr>
  1119. |;
  1120. } else {
  1121. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1122. $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
  1123. $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
  1124. $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
  1125. $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
  1126. $column_data{total} = qq|<th class=listsubtotal align=right>$subtotal</th>|;
  1127. # print subtotals
  1128. print qq|
  1129. <tr class=listsubtotal>
  1130. |;
  1131. for (@column_index) { print "$column_data{$_}\n" }
  1132. print qq|
  1133. </tr>
  1134. |;
  1135. }
  1136. $c0subtotal = 0;
  1137. $c30subtotal = 0;
  1138. $c60subtotal = 0;
  1139. $c90subtotal = 0;
  1140. $subtotal = 0;
  1141. }
  1142. }
  1143. print qq|
  1144. </tr>
  1145. <tr class=listtotal>
  1146. |;
  1147. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1148. $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp;");
  1149. $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
  1150. $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
  1151. $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
  1152. $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp;");
  1153. $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
  1154. $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
  1155. $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
  1156. $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
  1157. $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
  1158. for (@column_index) { print "$column_data{$_}\n" }
  1159. print qq|
  1160. </tr>
  1161. <input type=hidden name=rowcount value=$i>
  1162. </table>
  1163. </td>
  1164. </tr>
  1165. <tr>
  1166. <td>
  1167. |;
  1168. &print_options if ($form->{arap} eq 'ar');
  1169. print qq|
  1170. </td>
  1171. </tr>
  1172. <tr>
  1173. <td><hr size=3 noshade></td>
  1174. </tr>
  1175. </table>
  1176. |;
  1177. if ($form->{arap} eq 'ar') {
  1178. $form->hide_form(qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid));
  1179. print qq|
  1180. <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
  1181. |;
  1182. # type=submit $locale->text('Select all')
  1183. # type=submit $locale->text('Print')
  1184. # type=submit $locale->text('E-mail')
  1185. %button = ('Select all' => { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1186. 'Print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  1187. 'E-mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1188. );
  1189. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  1190. }
  1191. if ($form->{menubar}) {
  1192. require "$form->{path}/menu.pl";
  1193. &menubar;
  1194. }
  1195. print qq|
  1196. </form>
  1197. </body>
  1198. </html>
  1199. |;
  1200. }
  1201. sub select_all {
  1202. RP->aging(\%myconfig, \%$form);
  1203. for (@{ $form->{AG} }) { $_->{checked} = "checked" }
  1204. &aging;
  1205. }
  1206. sub print_options {
  1207. $form->{sendmode} = "attachment";
  1208. $form->{copies} = 1 unless $form->{copies};
  1209. $form->{PD}{$form->{type}} = "selected";
  1210. $form->{DF}{$form->{format}} = "selected";
  1211. $form->{SM}{$form->{sendmode}} = "selected";
  1212. $format = qq|
  1213. <option value=html $form->{PD}{format}>html|;
  1214. $type = qq|
  1215. <option value=statement $form->{PD}{statement}>|.$locale->text('Statement');
  1216. if ($form->{media} eq 'email') {
  1217. $media = qq|
  1218. <td><select name=sendmode>
  1219. <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
  1220. <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
  1221. } else {
  1222. $media = qq|
  1223. <td><select name=media>
  1224. <option value=screen>|.$locale->text('Screen');
  1225. if (%printer && $latex) {
  1226. for (sort keys %printer) { $media .= qq|
  1227. <option value="$_">$_| }
  1228. }
  1229. }
  1230. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1231. $media .= qq|</select></td>|;
  1232. if ($latex) {
  1233. $format .= qq|
  1234. <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
  1235. <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
  1236. }
  1237. print qq|
  1238. <table>
  1239. <tr>
  1240. <td><select name=type>$type</select></td>
  1241. <td><select name=format>$format</select></td>
  1242. $media
  1243. |;
  1244. if (%printer && $latex && $form->{media} ne 'email') {
  1245. print qq|
  1246. <td>|.$locale->text('Copies').qq|
  1247. <input name=copies size=2 value=$form->{copies}></td>
  1248. |;
  1249. }
  1250. print qq|
  1251. </tr>
  1252. </table>
  1253. |;
  1254. }
  1255. sub e_mail {
  1256. # get name and email addresses
  1257. for $i (1 .. $form->{rowcount}) {
  1258. if ($form->{"statement_$i"}) {
  1259. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1260. $form->{"statement_1"} = 1;
  1261. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1262. $form->{"curr_1"} = $form->{"curr_$i"};
  1263. RP->get_customer(\%myconfig, \%$form);
  1264. $selected = 1;
  1265. last;
  1266. }
  1267. }
  1268. $form->error($locale->text('Nothing selected!')) unless $selected;
  1269. if ($myconfig{role} =~ /(admin|manager)/) {
  1270. $bcc = qq|
  1271. <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
  1272. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  1273. |;
  1274. }
  1275. $title = $locale->text('E-mail Statement to')." $form->{$form->{ct}}";
  1276. $form->{media} = "email";
  1277. $form->header;
  1278. print qq|
  1279. <body>
  1280. <form method=post action=$form->{script}>
  1281. <table width=100%>
  1282. <tr class=listtop>
  1283. <th>$title</th>
  1284. </tr>
  1285. <tr height="5"></tr>
  1286. <tr>
  1287. <td>
  1288. <table width=100%>
  1289. <tr>
  1290. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1291. <td><input name=email size=30 value="$form->{email}"></td>
  1292. <th align=right nowrap>|.$locale->text('Cc').qq|</th>
  1293. <td><input name=cc size=30 value="$form->{cc}"></td>
  1294. </tr>
  1295. <tr>
  1296. <th align=right nowrap>|.$locale->text('Subject').qq|</th>
  1297. <td><input name=subject size=30 value="$form->{subject}"></td>
  1298. $bcc
  1299. </tr>
  1300. </table>
  1301. </td>
  1302. </tr>
  1303. <tr>
  1304. <td>
  1305. <table width=100%>
  1306. <tr>
  1307. <th align=left nowrap>|.$locale->text('Message').qq|</th>
  1308. </tr>
  1309. <tr>
  1310. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  1311. </tr>
  1312. </table>
  1313. </td>
  1314. </tr>
  1315. <tr>
  1316. <td>
  1317. |;
  1318. &print_options;
  1319. for (qw(email cc bcc subject message type sendmode format action nextsub)) { delete $form->{$_} }
  1320. $form->hide_form;
  1321. print qq|
  1322. </td>
  1323. </tr>
  1324. <tr>
  1325. <td><hr size=3 noshade></td>
  1326. </tr>
  1327. </table>
  1328. <input type=hidden name=nextsub value=send_email>
  1329. <br>
  1330. <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
  1331. </form>
  1332. </body>
  1333. </html>
  1334. |;
  1335. }
  1336. sub send_email {
  1337. $form->{OUT} = "$sendmail";
  1338. $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject};
  1339. $form->isblank("email", $locale->text('E-mail address missing!'));
  1340. RP->aging(\%myconfig, \%$form);
  1341. &print_form;
  1342. $form->redirect($locale->text('Statement sent to')." $form->{$form->{ct}}");
  1343. }
  1344. sub print {
  1345. if ($form->{media} !~ /(screen|email)/) {
  1346. $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
  1347. }
  1348. for $i (1 .. $form->{rowcount}) {
  1349. if ($form->{"statement_$i"}) {
  1350. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1351. $language_code = $form->{"language_code_$i"};
  1352. $curr = $form->{"curr_$i"};
  1353. $selected = 1;
  1354. last;
  1355. }
  1356. }
  1357. $form->error($locale->text('Nothing selected!')) unless $selected;
  1358. if ($form->{media} !~ /(screen|email)/) {
  1359. $form->{OUT} = "| $printer{$form->{media}}";
  1360. $form->{"$form->{ct}_id"} = "";
  1361. $SIG{INT} = 'IGNORE';
  1362. } else {
  1363. $form->{"statement_1"} = 1;
  1364. $form->{"language_code_1"} = $language_code;
  1365. $form->{"curr_1"} = $curr;
  1366. }
  1367. RP->aging(\%myconfig, \%$form);
  1368. &print_form;
  1369. $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);
  1370. }
  1371. sub print_form {
  1372. $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
  1373. $form->{templates} = "$myconfig{templates}";
  1374. # setup variables for the form
  1375. @a = qw(company address businessnumber tel fax);
  1376. for (@a) { $form->{$_} = $myconfig{$_} }
  1377. $form->{address} =~ s/\\n/\n/g;
  1378. $form->format_string(@a);
  1379. $form->{IN} = "$form->{type}.html";
  1380. if ($form->{format} eq 'postscript') {
  1381. $form->{IN} =~ s/html$/tex/;
  1382. }
  1383. if ($form->{format} eq 'pdf') {
  1384. $form->{IN} =~ s/html$/tex/;
  1385. }
  1386. @a = qw(name address1 address2 city state zipcode country contact);
  1387. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1388. push @a, 'email' if ! $form->{media} eq 'email';
  1389. $i = 0;
  1390. while (@{ $form->{AG} }) {
  1391. $ref = shift @{ $form->{AG} };
  1392. if ($ctid != $ref->{ctid}) {
  1393. $ctid = $ref->{ctid};
  1394. $i++;
  1395. if ($form->{"statement_$i"}) {
  1396. for (@a) { $form->{$_} = $ref->{$_} }
  1397. $form->format_string(@a);
  1398. $form->{$form->{ct}} = $form->{name};
  1399. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1400. $form->{language_code} = $form->{"language_code_$i"};
  1401. $form->{currency} = $form->{"curr_$i"};
  1402. for (qw(invnumber ordnumber ponumber notes invdate duedate)) { $form->{$_} = () }
  1403. $form->{total} = 0;
  1404. foreach $item (qw(c0 c30 c60 c90)) {
  1405. $form->{$item} = ();
  1406. $form->{"${item}total"} = 0;
  1407. }
  1408. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1409. while ($ref) {
  1410. if (scalar (@{ $form->{AG} }) > 0) {
  1411. # one or more left to go
  1412. if ($ctid == $form->{AG}->[0]->{ctid}) {
  1413. $ref = shift @{ $form->{AG} };
  1414. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1415. # any more?
  1416. $ref = scalar (@{ $form->{AG} });
  1417. } else {
  1418. $ref = 0;
  1419. }
  1420. } else {
  1421. # set initial ref to 0
  1422. $ref = 0;
  1423. }
  1424. }
  1425. for ("c0", "c30", "c60", "c90", "") { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) }
  1426. $form->parse_template(\%myconfig, $userspath);
  1427. }
  1428. }
  1429. }
  1430. }
  1431. sub statement_details {
  1432. my ($ref) = @_;
  1433. $ref->{invdate} = $ref->{transdate};
  1434. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1435. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1436. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1437. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1438. foreach $item (qw(c0 c30 c60 c90)) {
  1439. eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };
  1440. $form->{"${item}total"} += $ref->{$item};
  1441. $form->{total} += $ref->{$item};
  1442. push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
  1443. }
  1444. }
  1445. sub generate_tax_report {
  1446. RP->tax_report(\%myconfig, \%$form);
  1447. $descvar = "$form->{accno}_description";
  1448. $description = $form->escape($form->{$descvar});
  1449. $ratevar = "$form->{accno}_rate";
  1450. $taxrate = $form->{"$form->{accno}_rate"};
  1451. if ($form->{accno} =~ /^gifi_/) {
  1452. $descvar = "gifi_$form->{accno}_description";
  1453. $description = $form->escape($form->{$descvar});
  1454. $ratevar = "gifi_$form->{accno}_rate";
  1455. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1456. }
  1457. $department = $form->escape($form->{department});
  1458. # construct href
  1459. $href = "$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}";
  1460. # construct callback
  1461. $description = $form->escape($form->{$descvar},1);
  1462. $department = $form->escape($form->{department},1);
  1463. $form->sort_order();
  1464. $callback = "$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}";
  1465. $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
  1466. $title = $form->escape($form->{title});
  1467. $href .= "&title=$title";
  1468. $title = $form->escape($form->{title},1);
  1469. $callback .= "&title=$title";
  1470. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1471. @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total));
  1472. $form->{"l_description"} = "" if $form->{summary};
  1473. foreach $item (@columns) {
  1474. if ($form->{"l_$item"} eq "Y") {
  1475. push @column_index, $item;
  1476. # add column to href and callback
  1477. $callback .= "&l_$item=Y";
  1478. $href .= "&l_$item=Y";
  1479. }
  1480. }
  1481. if ($form->{l_subtotal} eq 'Y') {
  1482. $callback .= "&l_subtotal=Y";
  1483. $href .= "&l_subtotal=Y";
  1484. }
  1485. if ($form->{department}) {
  1486. ($department) = split /--/, $form->{department};
  1487. $option = $locale->text('Department')." : $department";
  1488. }
  1489. # if there are any dates
  1490. if ($form->{fromdate} || $form->{todate}) {
  1491. if ($form->{fromdate}) {
  1492. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  1493. }
  1494. if ($form->{todate}) {
  1495. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  1496. }
  1497. $form->{period} = "$fromdate - $todate";
  1498. } else {
  1499. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  1500. }
  1501. if ($form->{db} eq 'ar') {
  1502. $name = $locale->text('Customer');
  1503. $invoice = 'is.pl';
  1504. $arap = 'ar.pl';
  1505. }
  1506. if ($form->{db} eq 'ap') {
  1507. $name = $locale->text('Vendor');
  1508. $invoice = 'ir.pl';
  1509. $arap = 'ap.pl';
  1510. }
  1511. $option .= "<br>" if $option;
  1512. $option .= "$form->{period}";
  1513. $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
  1514. $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
  1515. $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
  1516. $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
  1517. $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
  1518. $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
  1519. $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  1520. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
  1521. $form->header;
  1522. print qq|
  1523. <body>
  1524. <table width=100%>
  1525. <tr>
  1526. <th class=listtop colspan=$colspan>$form->{title}</th>
  1527. </tr>
  1528. <tr height="5"></tr>
  1529. <tr>
  1530. <td>$option</td>
  1531. </tr>
  1532. <tr>
  1533. <td>
  1534. <table width=100%>
  1535. <tr class=listheading>
  1536. |;
  1537. for (@column_index) { print "$column_header{$_}\n" }
  1538. print qq|
  1539. </tr>
  1540. |;
  1541. # add sort and escape callback
  1542. $callback = $form->escape($callback . "&sort=$form->{sort}");
  1543. if (@{ $form->{TR} }) {
  1544. $sameitem = $form->{TR}->[0]->{$form->{sort}};
  1545. }
  1546. foreach $ref (@{ $form->{TR} }) {
  1547. $module = ($ref->{invoice}) ? $invoice : $arap;
  1548. $module = 'ps.pl' if $ref->{till};
  1549. if ($form->{l_subtotal} eq 'Y') {
  1550. if ($sameitem ne $ref->{$form->{sort}}) {
  1551. &tax_subtotal;
  1552. $sameitem = $ref->{$form->{sort}};
  1553. }
  1554. }
  1555. $totalnetamount += $ref->{netamount};
  1556. $totaltax += $ref->{tax};
  1557. $ref->{total} = $ref->{netamount} + $ref->{tax};
  1558. $subtotalnetamount += $ref->{netamount};
  1559. $subtotaltax += $ref->{tax};
  1560. for (qw(netamount tax total)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;"); }
  1561. $column_data{id} = qq|<td>$ref->{id}</td>|;
  1562. $column_data{invnumber} = 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>|;
  1563. for (qw(id transdate name partnumber description)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  1564. for (qw(netamount tax total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
  1565. $i++; $i %= 2;
  1566. print qq|
  1567. <tr class=listrow$i>
  1568. |;
  1569. for (@column_index) { print "$column_data{$_}\n" }
  1570. print qq|
  1571. </tr>
  1572. |;
  1573. }
  1574. if ($form->{l_subtotal} eq 'Y') {
  1575. &tax_subtotal;
  1576. }
  1577. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1578. print qq|
  1579. </tr>
  1580. <tr class=listtotal>
  1581. |;
  1582. $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
  1583. $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
  1584. $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
  1585. $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
  1586. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  1587. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  1588. for (@column_index) { print "$column_data{$_}\n" }
  1589. print qq|
  1590. </tr>
  1591. </table>
  1592. </td>
  1593. </tr>
  1594. <tr>
  1595. <td><hr size=3 noshade></td>
  1596. </tr>
  1597. </table>
  1598. </body>
  1599. </html>
  1600. |;
  1601. }
  1602. sub tax_subtotal {
  1603. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1604. $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
  1605. $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
  1606. $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
  1607. $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  1608. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  1609. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  1610. $subtotalnetamount = 0;
  1611. $subtotaltax = 0;
  1612. print qq|
  1613. <tr class=listsubtotal>
  1614. |;
  1615. for (@column_index) { print "\n$column_data{$_}" }
  1616. print qq|
  1617. </tr>
  1618. |;
  1619. }
  1620. sub list_payments {
  1621. if ($form->{account}) {
  1622. ($form->{paymentaccounts}) = split /--/, $form->{account};
  1623. }
  1624. if ($form->{department}) {
  1625. ($department, $form->{department_id}) = split /--/, $form->{department};
  1626. $option = $locale->text('Department')." : $department";
  1627. }
  1628. RP->payments(\%myconfig, \%$form);
  1629. @columns = $form->sort_columns(qw(transdate name paid source memo));
  1630. if ($form->{till}) {
  1631. @columns = $form->sort_columns(qw(transdate name paid curr source till));
  1632. if ($myconfig{role} ne 'user') {
  1633. @columns = $form->sort_columns(qw(transdate name paid curr source till employee));
  1634. }
  1635. }
  1636. # construct href
  1637. $title = $form->escape($form->{title});
  1638. $form->{paymentaccounts} =~ s/ /%20/g;
  1639. $href = "$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=".$form->escape($form->{title});
  1640. $form->sort_order();
  1641. $form->{callback} = "$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=".$form->escape($form->{title},1);
  1642. if ($form->{account}) {
  1643. $callback .= "&account=".$form->escape($form->{account},1);
  1644. $href .= "&account=".$form->escape($form->{account});
  1645. $option .= "\n<br>" if ($option);
  1646. $option .= $locale->text('Account')." : $form->{account}";
  1647. }
  1648. if ($form->{department}) {
  1649. $callback .= "&department=".$form->escape($form->{department},1);
  1650. $href .= "&department=".$form->escape($form->{department});
  1651. $option .= "\n<br>" if ($option);
  1652. $option .= $locale->text('Department')." : $form->{department}";
  1653. }
  1654. if ($form->{description}) {
  1655. $callback .= "&description=".$form->escape($form->{description},1);
  1656. $href .= "&description=".$form->escape($form->{description});
  1657. $option .= "\n<br>" if ($option);
  1658. $option .= $locale->text('Description')." : $form->{description}";
  1659. }
  1660. if ($form->{source}) {
  1661. $callback .= "&source=".$form->escape($form->{source},1);
  1662. $href .= "&source=".$form->escape($form->{source});
  1663. $option .= "\n<br>" if ($option);
  1664. $option .= $locale->text('Source')." : $form->{source}";
  1665. }
  1666. if ($form->{memo}) {
  1667. $callback .= "&memo=".$form->escape($form->{memo},1);
  1668. $href .= "&memo=".$form->escape($form->{memo});
  1669. $option .= "\n<br>" if ($option);
  1670. $option .= $locale->text('Memo')." : $form->{memo}";
  1671. }
  1672. if ($form->{fromdate}) {
  1673. $option .= "\n<br>" if ($option);
  1674. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  1675. }
  1676. if ($form->{todate}) {
  1677. $option .= "\n<br>" if ($option);
  1678. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  1679. }
  1680. $callback = $form->escape($form->{callback});
  1681. $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
  1682. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  1683. $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
  1684. $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";
  1685. $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
  1686. $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
  1687. $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>";
  1688. $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";
  1689. @column_index = @columns;
  1690. $colspan = $#column_index + 1;
  1691. $form->header;
  1692. print qq|
  1693. <body>
  1694. <table width=100%>
  1695. <tr>
  1696. <th class=listtop>$form->{title}</th>
  1697. </tr>
  1698. <tr height="5"></tr>
  1699. <tr>
  1700. <td>$option</td>
  1701. </tr>
  1702. <tr>
  1703. <td>
  1704. <table width=100%>
  1705. <tr class=listheading>
  1706. |;
  1707. for (@column_index) { print "\n$column_header{$_}" }
  1708. print qq|
  1709. </tr>
  1710. |;
  1711. foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
  1712. next unless @{ $form->{$ref->{id}} };
  1713. print qq|
  1714. <tr>
  1715. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  1716. </tr>
  1717. |;
  1718. if (@{ $form->{$ref->{id}} }) {
  1719. $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}};
  1720. }
  1721. foreach $payment (@{ $form->{$ref->{id}} }) {
  1722. if ($form->{l_subtotal}) {
  1723. if ($payment->{$form->{sort}} ne $sameitem) {
  1724. # print subtotal
  1725. &payment_subtotal;
  1726. }
  1727. }
  1728. next if ($form->{till} && ! $payment->{till});
  1729. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  1730. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  1731. $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")."</td>";
  1732. $column_data{curr} = "<td>$payment->{curr}</td>";
  1733. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  1734. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  1735. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  1736. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  1737. $subtotalpaid += $payment->{paid};
  1738. $accounttotalpaid += $payment->{paid};
  1739. $totalpaid += $payment->{paid};
  1740. $i++; $i %= 2;
  1741. print qq|
  1742. <tr class=listrow$i>
  1743. |;
  1744. for (@column_index) { print "\n$column_data{$_}" }
  1745. print qq|
  1746. </tr>
  1747. |;
  1748. $sameitem = $payment->{$form->{sort}};
  1749. }
  1750. &payment_subtotal if $form->{l_subtotal};
  1751. # print account totals
  1752. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1753. $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, "&nbsp;")."</th>";
  1754. print qq|
  1755. <tr class=listtotal>
  1756. |;
  1757. for (@column_index) { print "\n$column_data{$_}" }
  1758. print qq|
  1759. </tr>
  1760. |;
  1761. $accounttotalpaid = 0;
  1762. }
  1763. # print total
  1764. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1765. $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
  1766. print qq|
  1767. <tr class=listtotal>
  1768. |;
  1769. for (@column_index) { print "\n$column_data{$_}" }
  1770. print qq|
  1771. </tr>
  1772. </table>
  1773. </td>
  1774. </tr>
  1775. <tr>
  1776. <td><hr size=3 noshade></td>
  1777. </tr>
  1778. </table>
  1779. |;
  1780. if ($form->{menubar}) {
  1781. require "$form->{path}/menu.pl";
  1782. &menubar;
  1783. }
  1784. print qq|
  1785. </body>
  1786. </html>
  1787. |;
  1788. }
  1789. sub payment_subtotal {
  1790. if ($subtotalpaid != 0) {
  1791. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1792. $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
  1793. print qq|
  1794. <tr class=listsubtotal>
  1795. |;
  1796. for (@column_index) { print "\n$column_data{$_}" }
  1797. print qq|
  1798. </tr>
  1799. |;
  1800. }
  1801. $subtotalpaid = 0;
  1802. }