summaryrefslogtreecommitdiff
path: root/bin/mozilla/rc.pl
blob: 9e14dad42169cfd049890731b4accf241a5b0bb4 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2003
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #======================================================================
  35. #
  36. # Account reconciliation module
  37. #
  38. #======================================================================
  39. use LedgerSMB::RC;
  40. 1;
  41. # end of main
  42. # this is for our long dates
  43. # $locale->text('January')
  44. # $locale->text('February')
  45. # $locale->text('March')
  46. # $locale->text('April')
  47. # $locale->text('May ')
  48. # $locale->text('June')
  49. # $locale->text('July')
  50. # $locale->text('August')
  51. # $locale->text('September')
  52. # $locale->text('October')
  53. # $locale->text('November')
  54. # $locale->text('December')
  55. # this is for our short month
  56. # $locale->text('Jan')
  57. # $locale->text('Feb')
  58. # $locale->text('Mar')
  59. # $locale->text('Apr')
  60. # $locale->text('May')
  61. # $locale->text('Jun')
  62. # $locale->text('Jul')
  63. # $locale->text('Aug')
  64. # $locale->text('Sep')
  65. # $locale->text('Oct')
  66. # $locale->text('Nov')
  67. # $locale->text('Dec')
  68. sub reconciliation {
  69. RC->paymentaccounts(\%myconfig, \%$form);
  70. $selection = "";
  71. for (@{ $form->{PR} }) { $selection .= "<option>$_->{accno}--$_->{description}\n" }
  72. $form->{title} = $locale->text('Reconciliation');
  73. if ($form->{report}) {
  74. $form->{title} = $locale->text('Reconciliation Report');
  75. $cleared = qq|
  76. <input type=hidden name=report value=1>
  77. <tr>
  78. <td align=right><input type=checkbox class=checkbox name=outstanding value=1 checked></td>
  79. <td>|.$locale->text('Outstanding').qq|</td>
  80. <td align=right><input type=checkbox class=checkbox name=cleared value=1></td>
  81. <td>|.$locale->text('Cleared').qq|</td>
  82. </tr>
  83. |;
  84. }
  85. if (@{ $form->{all_years} }) {
  86. # accounting years
  87. $form->{selectaccountingyear} = "<option>\n";
  88. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  89. $form->{selectaccountingmonth} = "<option>\n";
  90. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  91. $selectfrom = qq|
  92. <tr>
  93. <th align=right>|.$locale->text('Period').qq|</th>
  94. <td colspan=3>
  95. <select name=month>$form->{selectaccountingmonth}</select>
  96. <select name=year>$form->{selectaccountingyear}</select>
  97. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  98. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  99. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  100. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  101. </td>
  102. </tr>
  103. |;
  104. }
  105. $form->header;
  106. print qq|
  107. <body>
  108. <form method=post action=$form->{script}>
  109. <table width=100%>
  110. <tr>
  111. <th class=listtop>$form->{title}</th>
  112. </tr>
  113. <tr height="5"></tr>
  114. <tr>
  115. <td>
  116. <table>
  117. <tr>
  118. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  119. <td colspan=3><select name=accno>$selection</select></td>
  120. </tr>
  121. <tr>
  122. <th align=right>|.$locale->text('From').qq|</th>
  123. <td colspan=3><input name=fromdate size=11 title="$myconfig{dateformat}"> <b>|.$locale->text('To').qq|</b> <input name=todate size=11 title="$myconfig{dateformat}"></td>
  124. </tr>
  125. $selectfrom
  126. $cleared
  127. <tr>
  128. <td></td>
  129. <td colspan=3><input type=radio style=radio name=summary value=1 checked> |.$locale->text('Summary').qq|
  130. <input type=radio style=radio name=summary value=0> |.$locale->text('Detail').qq|</td>
  131. </tr>
  132. <tr>
  133. <td></td>
  134. <td colspan=3><input type=checkbox class=checkbox name=fx_transaction value=1 checked> |.$locale->text('Include Exchange Rate Difference').qq|</td>
  135. </tr>
  136. </table>
  137. </td>
  138. </tr>
  139. <tr>
  140. <td><hr size=3 noshade></td>
  141. </tr>
  142. </table>
  143. <br>
  144. <input type=hidden name=nextsub value=get_payments>
  145. |;
  146. $form->hide_form(qw(path login sessionid));
  147. print qq|
  148. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  149. </form>
  150. |;
  151. if ($form->{menubar}) {
  152. require "$form->{path}/menu.pl";
  153. &menubar;
  154. }
  155. print qq|
  156. </body>
  157. </html>
  158. |;
  159. }
  160. sub continue { &{ $form->{nextsub} } };
  161. sub till_closing {
  162. $form->{callback} = "$form->{script}?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  163. @colheadings = qw(Source Actual Expected Error);
  164. $form->{title} = "Closing Till For $form->{login}";
  165. require "pos.conf.pl";
  166. RC->getposlines(\%myconfig, \%$form);
  167. $form->header;
  168. print qq|
  169. <body>
  170. <form method=post action=$form->{script}>
  171. <input type=hidden name=path value=$form->{path}>
  172. <input type=hidden name=login value=$form->{login}>
  173. <input type=hidden name=sessionid value=$form->{sessionid}>
  174. <input type=hidden name=callback value="$form->{callback}">
  175. <input type=hidden name=sum value="|.$form->{sum} * -1 .qq|">
  176. <table width=100%>
  177. <tr>
  178. <th class=listtop>$form->{title}</th>
  179. </tr>
  180. </table>
  181. <table width=100%>
  182. |;
  183. print "<tr>";
  184. map {print "<td class=listheading>$_</td>";} @colheadings;
  185. print "</tr>";
  186. my $j;
  187. my $source;
  188. foreach $source (sort keys %pos_sources){
  189. $amount = 0;
  190. foreach $ref (@{$form->{TB}}){
  191. if ($ref->{source} eq $source){
  192. $amount = $ref->{amount} * -1;
  193. last;
  194. }
  195. }
  196. ++$j;
  197. $j = $j % 2;
  198. print qq|<tr class=listrow$j><td>|.$pos_sources{$source}.qq|</td>
  199. <td><input name="amount_$source">
  200. <input type=hidden name="expected_$source"
  201. value="$amount"></td>
  202. <td>\$$amount</td>
  203. <td id="error_$source">&nbsp;</td></tr>|;
  204. }
  205. print qq|
  206. <script type='text/javascript'>
  207. function money_round(m){
  208. var r;
  209. r = Math.round(m * 100)/100;
  210. return r;
  211. }
  212. function custom_calc_total(){
  213. document.forms[0].sub_100.value = document.forms[0].calc_100.value * 100;
  214. document.forms[0].sub_50.value = document.forms[0].calc_50.value * 50;
  215. document.forms[0].sub_20.value = document.forms[0].calc_20.value * 20;
  216. document.forms[0].sub_10.value = document.forms[0].calc_10.value * 10;
  217. document.forms[0].sub_5.value = document.forms[0].calc_5.value * 5;
  218. document.forms[0].sub_1.value = document.forms[0].calc_1.value * 1;
  219. document.forms[0].sub_050.value = document.forms[0].calc_050.value * .5;
  220. document.forms[0].sub_025.value = document.forms[0].calc_025.value * .25;
  221. document.forms[0].sub_010.value = document.forms[0].calc_010.value * .10;
  222. document.forms[0].sub_005.value = document.forms[0].calc_005.value * .05;
  223. document.forms[0].sub_001.value = document.forms[0].calc_001.value * .01;
  224. document.forms[0].sub_sub.value = document.forms[0].sub_100.value * 1 +
  225. document.forms[0].sub_50.value*1 + document.forms[0].sub_20.value*1 +
  226. document.forms[0].sub_10.value*1 + document.forms[0].sub_5.value*1 +
  227. document.forms[0].sub_1.value*1 + document.forms[0].sub_050.value*1 +
  228. document.forms[0].sub_025.value*1 + document.forms[0].sub_010.value*1 +
  229. document.forms[0].sub_005.value*1 + document.forms[0].sub_001.value*1;
  230. document.forms[0].sub_001.value =
  231. money_round(document.forms[0].sub_001.value);
  232. document.forms[0].sub_010.value =
  233. money_round(document.forms[0].sub_010.value);
  234. document.forms[0].sub_005.value =
  235. money_round(document.forms[0].sub_005.value);
  236. document.forms[0].sub_sub.value =
  237. money_round(document.forms[0].sub_sub.value);
  238. document.forms[0].amount_cash.value = money_round(
  239. document.forms[0].sub_sub.value - $pos_config{till_cash});
  240. check_errors();
  241. }
  242. function check_errors(){
  243. var cumulative_error = 0;
  244. var source_error = 0;
  245. var err_cell;
  246. |;
  247. map {
  248. print " source_error = money_round(
  249. document.forms[0].amount_$_.value -
  250. document.forms[0].expected_$_.value);
  251. cumulative_error = cumulative_error + source_error;
  252. err_cell = document.getElementById('error_$_');
  253. err_cell.innerHTML = '\$' + source_error;\n";
  254. } (keys %pos_sources);
  255. print qq|
  256. alert('Cumulative Error: \$' + money_round(cumulative_error));
  257. }
  258. </script>
  259. <table>
  260. <col><col><col>
  261. <tr>
  262. <td><input type=text name=calc_100 value="$form->{calc_100}"></td>
  263. <th>X \$100 = </th>
  264. <td><input type=text name=sub_100 value="$form->{sub_100}"></td>
  265. </tr>
  266. <tr>
  267. <td><input type=text name=calc_50 value="$form->{calc_50}"></td>
  268. <th>X \$50 = </th>
  269. <td><input type=text name=sub_50 value="$form->{sub_50}"></td>
  270. </tr>
  271. <tr>
  272. <td><input type=text name=calc_20 value="$form->{calc_20}"></td>
  273. <th>X \$20 = </th>
  274. <td><input type=text name=sub_20 value="$form->{sub_20}"></td>
  275. </tr>
  276. <tr>
  277. <td><input type=text name=calc_10 value="$form->{calc_10}"></td>
  278. <th>X \$10 = </th>
  279. <td><input type=text name=sub_10 value="$form->{sub_10}"></td>
  280. </tr>
  281. <tr>
  282. <td><input type=text name=calc_5 value="$form->{calc_5}"></td>
  283. <th>X \$5 = </th>
  284. <td><input type=text name=sub_5 value="$form->{sub_5}"></td>
  285. </tr>
  286. <tr>
  287. <td><input type=text name=calc_1 value="$form->{calc_1}"></td>
  288. <th>X \$1 = </th>
  289. <td><input type=text name=sub_1 value="$form->{sub_1}"></td>
  290. </tr>
  291. <tr>
  292. <td><input type=text name=calc_050 value="$form->{calc_050}"></td>
  293. <th>X \$0.50 = </th>
  294. <td><input type=text name=sub_050 value="$form->{sub_050}"></td>
  295. </tr>
  296. <tr>
  297. <td><input type=text name=calc_025 value="$form->{calc_025}"></td>
  298. <th>X \$.25 = </th>
  299. <td><input type=text name=sub_025 value="$form->{sub_025}"></td>
  300. </tr>
  301. <tr>
  302. <td><input type=text name=calc_010 value="$form->{calc_010}"></td>
  303. <th>X \$.10 = </th>
  304. <td><input type=text name=sub_010 value="$form->{sub_010}"></td>
  305. </tr>
  306. <tr>
  307. <td><input type=text name=calc_005 value="$form->{calc_005}"></td>
  308. <th>X \$.05 = </th>
  309. <td><input type=text name=sub_005 value="$form->{sub_005}"></td>
  310. </tr>
  311. <tr>
  312. <td><input type=text name=calc_001 value="$form->{calc_001}"></td>
  313. <th>X \$.01 = </th>
  314. <td><input type=text name=sub_001 value="$form->{sub_001}"></td>
  315. </tr>
  316. <tr>
  317. <td>&nbsp;</td>
  318. <th>Subtotal:</th>
  319. <td><input type=text name=sub_sub value="$form->{sub_sub}"></td>
  320. </table>
  321. <input type=button name=calculate class=submit onClick="custom_calc_total()"
  322. value='Calculate'>
  323. |;
  324. print qq|</table><input type=submit name=action value="|.
  325. $locale->text("close_till").qq|">|;
  326. print qq|
  327. </form>
  328. </body>
  329. </html>
  330. |;
  331. }
  332. sub close_till {
  333. use LedgerSMB::GL;
  334. require 'pos.conf.pl';
  335. RC->clear_till(\%myconfig, \%$form);
  336. my $amount = 0;
  337. my $expected = 0;
  338. my $difference = 0;
  339. my $lines = '';
  340. $form->{rowcount} = 2;
  341. foreach $key (keys %pos_sources){
  342. $amount = 0;
  343. $expected = 0;
  344. $amount = $form->parse_amount(\%myconfig, $form->{"amount_$key"});
  345. $expected = $form->parse_amount(\%myconfig, $form->{"expected_$key"});
  346. $gl_entry = "Closing Till $pos_config{till} source = $key";
  347. $accno1 = $pos_config{till_accno};
  348. if (${$pos_config{'source_accno_override'}{$key}}){
  349. $accno2 = ${$pos_config{'source_accno_override'}{$key}};
  350. } else {
  351. $accno2 = $pos_config{'close_cash_accno'};
  352. }
  353. $form->{reference} = $gl_entry;
  354. $form->{accno_1} = $accno1;
  355. $form->{credit_1} = $amount;
  356. $form->{accno_2} = $accno2;
  357. $form->{debit_2} = $amount;
  358. $form->{transdate} = $form->current_date(\%myconfig);
  359. GL->post_transaction(\%myconfig, \%$form);
  360. delete $form->{id};
  361. $error = $amount - $expected;
  362. $difference += $error;
  363. $lines .= "Source: $key, Amount: $amount\nExpected: $expected. Error= $error\n\n";
  364. }
  365. $gl_entry = "Closing Till: $pos_config{till} Over/Under";
  366. $amount = $difference * -1;
  367. $form->{reference} = $gl_entry;
  368. $form->{accno_1} = $accno1;
  369. $form->{credit_1} = $amount;
  370. $form->{accno_2} = $pos_config{coa_prefix};
  371. $form->{debit_2} = $amount;
  372. $form->{transdate} = $form->current_date(\%myconfig);
  373. GL->post_transaction(\%myconfig, \%$form);
  374. delete $form->{id};
  375. $lines .= "Cumulative Error: $amount";
  376. $form->{accno} = $form->{accno_1};
  377. RC->getbalance(\%myconfig, \%$form);
  378. $amount = $form->{balance} * -1;
  379. $gl_entry = "Resetting Till: $pos_config{till}";
  380. $form->{reference} = $gl_entry;
  381. $form->{accno_1} = $accno1;
  382. $form->{credit_1} = $amount;
  383. $form->{accno_2} = $pos_config{coa_prefix};
  384. $form->{debit_2} = $amount;
  385. $form->{transdate} = $form->current_date(\%myconfig);
  386. GL->post_transaction(\%myconfig, \%$form);
  387. delete $form->{id};
  388. $head = "Closing Till $pos_config{till} for $form->{login}\n".
  389. "Date: $form->{transdate}\n\n\n";
  390. $cash = join ("\n",
  391. ("Cash Breakdown:",
  392. "$form->{calc_100} x 100 = $form->{sub_100}",
  393. "$form->{calc_50} x 50 = $form->{sub_50}",
  394. "$form->{calc_20} x 20 = $form->{sub_20}",
  395. "$form->{calc_10} x 10 = $form->{sub_10}",
  396. "$form->{calc_5} x 5 = $form->{sub_5}",
  397. "$form->{calc_1} x 1 = $form->{sub_1}",
  398. "$form->{calc_050} x 0.50 = $form->{sub_050}",
  399. "$form->{calc_025} x 0.25 = $form->{sub_025}",
  400. "$form->{calc_010} x 0.10 = $form->{sub_010}",
  401. "$form->{calc_005} x 0.05 = $form->{sub_005}",
  402. "$form->{calc_001} x 0.01 = $form->{sub_001}",
  403. "Total Cash in Drawer: $form->{sub_sub}",
  404. "Less Cash in Till At Start: $pos_config{till_cash}",
  405. "\n"));
  406. $foot = "Cumulative Error: $difference\n Reset Till By $amount\n\n\n\n\n\n\n\n\n\n";
  407. open (PRN, "|-", $printer{Printer});
  408. print PRN $head;
  409. print PRN $lines;
  410. print PRN $cash;
  411. print PRN $cash;
  412. print PRN $foot;
  413. close PRN;
  414. if ($difference > 0){
  415. $message = "You are over by ".$difference;
  416. } elsif ($difference < 0){
  417. $message = "You are under by ".$difference * -1;
  418. }
  419. else {
  420. $message = "Congradulations! Your till is exactly balanced.";
  421. }
  422. $form->info($message);
  423. }
  424. sub get_payments {
  425. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  426. if ($form->{'pos'}){
  427. require "pos.conf.pl";
  428. $form->{fromdate} = $form->current_date(\%myconfig);
  429. unless ($form->{source}){
  430. $form->{source} = (sort keys(%pos_sources))[0];
  431. }
  432. if ($form->{source} eq 'cash'){
  433. $form->{summary} = "true";
  434. } else {
  435. $form->{summary} = "";
  436. }
  437. $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
  438. $form->{account} = $form->{source};
  439. }
  440. RC->payment_transactions(\%myconfig, \%$form);
  441. $ml = ($form->{category} eq 'A') ? -1 : 1;
  442. $form->{statementbalance} = $form->{endingbalance} * $ml;
  443. if (! $form->{fx_transaction}) {
  444. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  445. }
  446. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  447. &display_form;
  448. }
  449. sub display_form {
  450. if ($form->{report}) {
  451. @column_index = qw(transdate source name cleared debit credit);
  452. } else {
  453. @column_index = qw(transdate source name cleared debit credit balance);
  454. }
  455. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  456. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  457. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  458. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  459. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  460. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  461. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  462. if ($form->{fromdate}) {
  463. $option .= "\n<br>" if ($option);
  464. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  465. }
  466. if ($form->{todate}) {
  467. $option .= "\n<br>" if ($option);
  468. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  469. }
  470. $form->{title} = "$form->{accno}--$form->{account}";
  471. $form->header;
  472. print qq|
  473. <body>
  474. <form method=post action=$form->{script}>
  475. <input type=hidden name=source value="$form->{source}">
  476. <input type=hidden name=cumulative_error value="$form->{cumulative_error}">
  477. <table width=100%>
  478. <tr>
  479. <th class=listtop>$form->{title}</th>
  480. </tr>
  481. <tr height="5"></tr>
  482. <tr>
  483. <td>$option</td>
  484. </tr>
  485. <tr>
  486. <td>
  487. <table width=100%>
  488. <tr class=listheading>
  489. |;
  490. for (@column_index) { print "\n$column_header{$_}" }
  491. print qq|
  492. </tr>
  493. |;
  494. $ml = ($form->{category} eq 'A') ? -1 : 1;
  495. $form->{beginningbalance} *= $ml;
  496. $form->{fx_balance} *= $ml;
  497. if (! $form->{fx_transaction}) {
  498. $form->{beginningbalance} -= $form->{fx_balance};
  499. }
  500. $balance = $form->{beginningbalance};
  501. $i = 0;
  502. $j = 0;
  503. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  504. if (! $form->{report}) {
  505. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  506. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  507. print qq|
  508. <tr class=listrow$j>
  509. |;
  510. for (@column_index) { print "\n$column_data{$_}" }
  511. print qq|
  512. </tr>
  513. |;
  514. }
  515. foreach $ref (@{ $form->{PR} }) {
  516. $i++;
  517. if (! $form->{fx_transaction}) {
  518. next if $ref->{fx_transaction};
  519. }
  520. $checked = ($ref->{cleared}) ? "checked" : "";
  521. %temp = ();
  522. if (!$ref->{fx_transaction}) {
  523. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  524. }
  525. $column_data{name} = "<td>";
  526. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  527. $column_data{name} .= "</td>";
  528. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  529. <input type=hidden name="id_$i" value=$ref->{id}>|;
  530. $column_data{debit} = "<td>&nbsp;</td>";
  531. $column_data{credit} = "<td>&nbsp;</td>";
  532. $balance += $ref->{amount} * $ml;
  533. if ($ref->{amount} < 0) {
  534. $totaldebits += $ref->{amount} * -1;
  535. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  536. } else {
  537. $totalcredits += $ref->{amount};
  538. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  539. }
  540. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  541. if ($ref->{fx_transaction}) {
  542. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  543. $cleared += $ref->{amount} * $ml if $clearfx;
  544. } else {
  545. if ($form->{report}) {
  546. if ($ref->{cleared}) {
  547. $column_data{cleared} = qq|<td align=center>*</td>|;
  548. $clearfx = 1;
  549. } else {
  550. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  551. $clearfx = 0;
  552. }
  553. } else {
  554. if ($ref->{oldcleared}) {
  555. $cleared += $ref->{amount} * $ml;
  556. $clearfx = 1;
  557. $column_data{cleared} = qq|<td align=center>*</td>
  558. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  559. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  560. <input type=hidden name="source_$i" value="$ref->{source}">
  561. <input type=hidden name="amount_$1" value="$ref->{amount}">|;
  562. } else {
  563. $cleared += $ref->{amount} * $ml if $checked;
  564. $clearfx = ($checked) ? 1 : 0;
  565. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  566. <input type=hidden name="source_$i" value="$ref->{source}">
  567. <input type=hidden name="amount_$i" value="$ref->{amount}">
  568. </td>|;
  569. }
  570. }
  571. }
  572. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  573. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  574. $j++; $j %= 2;
  575. print qq|
  576. <tr class=listrow$j>
  577. |;
  578. for (@column_index) { print "\n$column_data{$_}" }
  579. print qq|
  580. </tr>
  581. |;
  582. }
  583. $form->{rowcount} = $i;
  584. # print totals
  585. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  586. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  587. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  588. print qq|
  589. <tr class=listtotal>
  590. |;
  591. for (@column_index) { print "\n$column_data{$_}" }
  592. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  593. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  594. if ($form->{source}){
  595. $difference = 0;
  596. }
  597. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  598. print qq|
  599. </tr>
  600. </table>
  601. </td>
  602. </tr>
  603. |;
  604. if ($form->{'pos'}){
  605. $close_next = qq|<input type=submit class=submit name=action
  606. value="|.$locale->text('close_next').qq|">|;
  607. $done = "";
  608. }
  609. else {
  610. $close_next = "";
  611. $done = qq|<input type=submit class=submit name=action
  612. value="|.$locale->text('Done').qq|">|;
  613. }
  614. if ($form->{'pos'}){
  615. $difference = qq|
  616. <tr>
  617. <th align=right><select name=over_under>
  618. <option value=under>|.$locale->text('Under').qq|</option>
  619. <option value=over>|.$locale->text('Over').qq|</option>
  620. </select><input type=hidden name=pos value='true'>
  621. </th>
  622. <td width=10%></td>
  623. <td align=right><input name=null size=11
  624. value='|.$form->{null2}.qq|'></td>
  625. <input type=hidden name=difference
  626. value=$difference>
  627. |;
  628. if ($form->{'over_under'}){
  629. $o_u = $form->{'over_under'};
  630. $difference =~ s/(value=$o_u)/SELECTED $1/g;
  631. }
  632. } else {
  633. $difference = qq|
  634. <tr>
  635. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  636. <td width=10%></td>
  637. <td align=right><input name=null size=11 value=$difference></td>
  638. <input type=hidden name=difference value=$difference>
  639. </tr>|;
  640. }
  641. if ($form->{report}) {
  642. print qq|
  643. </tr>
  644. </table>
  645. |;
  646. } else {
  647. print qq|
  648. <tr>
  649. <td>
  650. <table width=100%>
  651. <tr>
  652. <td align=right>
  653. <table>
  654. <tr>
  655. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  656. <td width=10%></td>
  657. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  658. </tr>
  659. $difference
  660. </table>
  661. </td>
  662. </tr>
  663. </table>
  664. </td>
  665. </tr>
  666. <tr>
  667. <td><hr size=3 noshade></td>
  668. </tr>
  669. </table>
  670. |;
  671. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  672. print qq|
  673. <br>
  674. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  675. <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|">
  676. $done
  677. $close_next |;
  678. }
  679. if ($form->{menubar}) {
  680. require "$form->{path}/menu.pl";
  681. &menubar;
  682. }
  683. print qq|
  684. </form>
  685. </body>
  686. </html>
  687. |;
  688. }
  689. sub update {
  690. $form->{null2} = $form->{null};
  691. RC->payment_transactions(\%myconfig, \%$form);
  692. $i = 0;
  693. foreach $ref (@{ $form->{PR} }) {
  694. $i++;
  695. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  696. }
  697. &display_form;
  698. }
  699. sub select_all {
  700. RC->payment_transactions(\%myconfig, \%$form);
  701. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  702. &display_form;
  703. }
  704. sub done {
  705. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  706. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  707. RC->reconcile(\%myconfig, \%$form);
  708. $form->redirect;
  709. }