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