summaryrefslogtreecommitdiff
path: root/bin/rc.pl
blob: e9d23b786ea810e00603edd0fc901ada0b1c38c7 (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. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  149. </form>
  150. |;
  151. if ($form->{lynx}) {
  152. require "bin/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. my $curren = $pos_config{'curren'};
  165. $form->{title} = $locale->text("Closing Till For [_1]", $form->{login});
  166. require "pos.conf.pl";
  167. RC->getposlines(\%myconfig, \%$form);
  168. $form->header;
  169. print qq|
  170. <body>
  171. <form method=post action=$form->{script}>
  172. <input type=hidden name=path value=$form->{path}>
  173. <input type=hidden name=login value=$form->{login}>
  174. <input type=hidden name=sessionid value=$form->{sessionid}>
  175. <input type=hidden name=callback value="$form->{callback}">
  176. <input type=hidden name=sum value="|.$form->{sum} * -1 .qq|">
  177. <table width=100%>
  178. <tr>
  179. <th class=listtop>$form->{title}</th>
  180. </tr>
  181. </table>
  182. <table width=100%>
  183. |;
  184. print "<tr>";
  185. map {print "<td class=listheading>$_</td>";} @colheadings;
  186. print "</tr>";
  187. my $j;
  188. my $source;
  189. foreach $source (sort keys %pos_sources){
  190. $amount = 0;
  191. foreach $ref (@{$form->{TB}}){
  192. if ($ref->{source} eq $source){
  193. $amount = $ref->{amount} * -1;
  194. last;
  195. }
  196. }
  197. ++$j;
  198. $j = $j % 2;
  199. print qq|<tr class=listrow$j><td>|.$pos_sources{$source}.qq|</td>
  200. <td><input name="amount_$source">
  201. <input type=hidden name="expected_$source"
  202. value="$amount"></td>
  203. <td>${curren}$amount</td>
  204. <td id="error_$source">&nbsp;</td></tr>|;
  205. }
  206. print qq|
  207. <script type='text/javascript'>
  208. function money_round(m){
  209. var r;
  210. r = Math.round(m * 100)/100;
  211. return r;
  212. }
  213. function custom_calc_total(){
  214. |;
  215. my $subgen = 'document.forms[0].sub_sub.value = ';
  216. my $toround = '';
  217. foreach my $unit (@{$pos_config{'breakdown'}}) {
  218. # XXX Needs to take into account currencies that don't use 2 dp
  219. my $parsed = $form->parse_amount(\%pos_config, $unit);
  220. my $calcval = $parsed;
  221. $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
  222. my $subval = 'sub_' . $calcval;
  223. $calcval = 'calc_' . $calcval;
  224. print qq|
  225. document.forms[0].${subval}.value = document.forms[0].${calcval}.value * $parsed;
  226. |;
  227. $subgen .= "document.forms[0].${subval}.value * 1 + ";
  228. $toround .= qq|
  229. document.forms[0].${subval}.value =
  230. money_round(document.forms[0].${subval}.value); |;
  231. }
  232. print $subgen . "0;";
  233. print $toround;
  234. print qq|document.forms[0].sub_sub.value =
  235. money_round(document.forms[0].sub_sub.value);
  236. document.forms[0].amount_cash.value = money_round(
  237. document.forms[0].sub_sub.value - $pos_config{till_cash});
  238. check_errors();
  239. }
  240. function check_errors(){
  241. var cumulative_error = 0;
  242. var source_error = 0;
  243. var err_cell;
  244. |;
  245. map {
  246. print " source_error = money_round(
  247. document.forms[0].amount_$_.value -
  248. document.forms[0].expected_$_.value);
  249. cumulative_error = cumulative_error + source_error;
  250. err_cell = document.getElementById('error_$_');
  251. err_cell.innerHTML = '$curren' + source_error;\n";
  252. } (keys %pos_sources);
  253. print qq|
  254. alert('|.$locale->text('Cumulative Error:').qq| $curren' + money_round(cumulative_error));
  255. }
  256. </script>
  257. <table>
  258. <col><col><col>|;
  259. foreach my $unit (@{$pos_config{'breakdown'}}) {
  260. # XXX Needs to take into account currencies that don't use 2 dp
  261. my $calcval = $form->parse_amount(\%pos_config, $unit);
  262. $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
  263. my $subval = 'sub_' . $calcval;
  264. $calcval = 'calc_' . $calcval;
  265. print qq|<tr>
  266. <td><input type=text name=$calcval value="$form->{$calcval}"></td>
  267. <th>X ${curren}${unit} = </th>
  268. <td><input type=text name=$subval value="$form->{$subval}"></td>
  269. </tr>|;
  270. }
  271. print qq|<tr>
  272. <td>&nbsp;</td>
  273. <th>Subtotal:</th>
  274. <td><input type=text name=sub_sub value="$form->{sub_sub}"></td>
  275. </tr>
  276. </table>
  277. <input type=button name=calculate class=submit onClick="custom_calc_total()"
  278. value='|.$locale->text('Calculate').qq|'>
  279. |;
  280. print qq|</table><button type="submit" name="action" value="close_till">|.
  281. $locale->text("Close Till").qq|</button>|;
  282. print qq|
  283. </form>
  284. </body>
  285. </html>
  286. |;
  287. }
  288. sub close_till {
  289. use LedgerSMB::GL;
  290. require 'pos.conf.pl';
  291. RC->clear_till(\%myconfig, \%$form);
  292. my $amount = 0;
  293. my $expected = 0;
  294. my $difference = 0;
  295. my $lines = '';
  296. $form->{rowcount} = 2;
  297. foreach $key (keys %pos_sources){
  298. $amount = 0;
  299. $expected = 0;
  300. $amount = $form->parse_amount(\%myconfig, $form->{"amount_$key"});
  301. $expected = $form->parse_amount(\%myconfig, $form->{"expected_$key"});
  302. $gl_entry = "Closing Till $pos_config{till} source = $key";
  303. $accno1 = $pos_config{till_accno};
  304. if (${$pos_config{'source_accno_override'}{$key}}){
  305. $accno2 = ${$pos_config{'source_accno_override'}{$key}};
  306. } else {
  307. $accno2 = $pos_config{'close_cash_accno'};
  308. }
  309. $form->{reference} = $gl_entry;
  310. $form->{accno_1} = $accno1;
  311. $form->{credit_1} = $amount;
  312. $form->{accno_2} = $accno2;
  313. $form->{debit_2} = $amount;
  314. $form->{transdate} = $form->current_date(\%myconfig);
  315. GL->post_transaction(\%myconfig, \%$form);
  316. delete $form->{id};
  317. $error = $amount - $expected;
  318. $difference += $error;
  319. $lines .= "Source: $key, Amount: $amount\nExpected: $expected. Error= $error\n\n";
  320. }
  321. $gl_entry = "Closing Till: $pos_config{till} Over/Under";
  322. $amount = $difference * -1;
  323. $form->{reference} = $gl_entry;
  324. $form->{accno_1} = $accno1;
  325. $form->{credit_1} = $amount;
  326. $form->{accno_2} = $pos_config{coa_prefix};
  327. $form->{debit_2} = $amount;
  328. $form->{transdate} = $form->current_date(\%myconfig);
  329. GL->post_transaction(\%myconfig, \%$form);
  330. delete $form->{id};
  331. $lines .= "Cumulative Error: $amount";
  332. $form->{accno} = $form->{accno_1};
  333. RC->getbalance(\%myconfig, \%$form);
  334. $amount = $form->{balance} * -1;
  335. $gl_entry = "Resetting Till: $pos_config{till}";
  336. $form->{reference} = $gl_entry;
  337. $form->{accno_1} = $accno1;
  338. $form->{credit_1} = $amount;
  339. $form->{accno_2} = $pos_config{coa_prefix};
  340. $form->{debit_2} = $amount;
  341. $form->{transdate} = $form->current_date(\%myconfig);
  342. GL->post_transaction(\%myconfig, \%$form);
  343. delete $form->{id};
  344. $head = "Closing Till $pos_config{till} for $form->{login}\n".
  345. "Date: $form->{transdate}\n\n\n";
  346. my @cashlines = [$locale->text("Cash Breakdown:")];
  347. foreach my $unit (@{$pos_config{'breakdown'}}) {
  348. # XXX Needs to take into account currencies that don't use 2 dp
  349. my $parsed = $form->parse_amount(\%pos_config, $unit);
  350. my $calcval = $parsed;
  351. $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
  352. my $subval = 'sub_' . $calcval;
  353. $calcval = 'calc_' . $calcval;
  354. push @cashlines, "$form->{$calcval} x $parseval = $form->{$subval}";
  355. }
  356. push @cashlines, $locale->text("Total Cash in Drawer: [_1]",
  357. $form->{sub_sub});
  358. push @cashlines, $locale->text("Less Cash in Till At Start: [_1]",
  359. $form->{till_cash});
  360. push @cashlines, "\n";
  361. $cash = join ("\n", @cashlines);
  362. $foot = $locale->text("Cumulative Error: [_1]", $difference)."\n";
  363. $foot .= $locale->text('Reset Till By [_1]', $amount)."\n\n\n\n\n\n\n\n\n\n";
  364. open (PRN, "|-", ${LedgerSMB::Sysconfig::printer}{Printer});
  365. print PRN $head;
  366. print PRN $lines;
  367. print PRN $cash;
  368. print PRN $cash;
  369. print PRN $foot;
  370. close PRN;
  371. if ($difference > 0){
  372. $message = $locale->text("You are over by [_1]", $difference);
  373. } elsif ($difference < 0){
  374. $message = $locale->text("You are under by [_1]", $difference * -1);
  375. }
  376. else {
  377. $message = $local->text("Congratulations! Your till is exactly balanced.");
  378. }
  379. $form->info($message);
  380. }
  381. sub get_payments {
  382. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  383. if ($form->{'pos'}){
  384. require "pos.conf.pl";
  385. $form->{fromdate} = $form->current_date(\%myconfig);
  386. unless ($form->{source}){
  387. $form->{source} = (sort keys(%pos_sources))[0];
  388. }
  389. if ($form->{source} eq 'cash'){
  390. $form->{summary} = "true";
  391. } else {
  392. $form->{summary} = "";
  393. }
  394. $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
  395. $form->{account} = $form->{source};
  396. }
  397. RC->payment_transactions(\%myconfig, \%$form);
  398. $ml = ($form->{category} eq 'A') ? -1 : 1;
  399. $form->{statementbalance} = $form->{endingbalance} * $ml;
  400. if (! $form->{fx_transaction}) {
  401. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  402. }
  403. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  404. &display_form;
  405. }
  406. sub display_form {
  407. if ($form->{report}) {
  408. @column_index = qw(transdate source name cleared debit credit);
  409. } else {
  410. @column_index = qw(transdate source name cleared debit credit balance);
  411. }
  412. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  413. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  414. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  415. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  416. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  417. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  418. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  419. if ($form->{fromdate}) {
  420. $option .= "\n<br>" if ($option);
  421. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  422. }
  423. if ($form->{todate}) {
  424. $option .= "\n<br>" if ($option);
  425. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  426. }
  427. $form->{title} = "$form->{accno}--$form->{account}";
  428. $form->header;
  429. print qq|
  430. <body>
  431. <form method=post action=$form->{script}>
  432. <input type=hidden name=source value="$form->{source}">
  433. <input type=hidden name=cumulative_error value="$form->{cumulative_error}">
  434. <table width=100%>
  435. <tr>
  436. <th class=listtop>$form->{title}</th>
  437. </tr>
  438. <tr height="5"></tr>
  439. <tr>
  440. <td>$option</td>
  441. </tr>
  442. <tr>
  443. <td>
  444. <table width=100%>
  445. <tr class=listheading>
  446. |;
  447. for (@column_index) { print "\n$column_header{$_}" }
  448. print qq|
  449. </tr>
  450. |;
  451. $ml = ($form->{category} eq 'A') ? -1 : 1;
  452. $form->{beginningbalance} *= $ml;
  453. $form->{fx_balance} *= $ml;
  454. if (! $form->{fx_transaction}) {
  455. $form->{beginningbalance} -= $form->{fx_balance};
  456. }
  457. $balance = $form->{beginningbalance};
  458. $i = 0;
  459. $j = 0;
  460. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  461. if (! $form->{report}) {
  462. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  463. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  464. print qq|
  465. <tr class=listrow$j>
  466. |;
  467. for (@column_index) { print "\n$column_data{$_}" }
  468. print qq|
  469. </tr>
  470. |;
  471. }
  472. foreach $ref (@{ $form->{PR} }) {
  473. $i++;
  474. if (! $form->{fx_transaction}) {
  475. next if $ref->{fx_transaction};
  476. }
  477. $checked = ($ref->{cleared}) ? "checked" : "";
  478. %temp = ();
  479. if (!$ref->{fx_transaction}) {
  480. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  481. }
  482. $column_data{name} = "<td>";
  483. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  484. $column_data{name} .= "</td>";
  485. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  486. <input type=hidden name="id_$i" value=$ref->{id}>|;
  487. $column_data{debit} = "<td>&nbsp;</td>";
  488. $column_data{credit} = "<td>&nbsp;</td>";
  489. $balance += $ref->{amount} * $ml;
  490. if ($ref->{amount} < 0) {
  491. $totaldebits += $ref->{amount} * -1;
  492. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  493. } else {
  494. $totalcredits += $ref->{amount};
  495. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  496. }
  497. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  498. if ($ref->{fx_transaction}) {
  499. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  500. $cleared += $ref->{amount} * $ml if $clearfx;
  501. } else {
  502. if ($form->{report}) {
  503. if ($ref->{cleared}) {
  504. $column_data{cleared} = qq|<td align=center>*</td>|;
  505. $clearfx = 1;
  506. } else {
  507. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  508. $clearfx = 0;
  509. }
  510. } else {
  511. if ($ref->{oldcleared}) {
  512. $cleared += $ref->{amount} * $ml;
  513. $clearfx = 1;
  514. $column_data{cleared} = qq|<td align=center>*</td>
  515. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  516. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  517. <input type=hidden name="source_$i" value="$ref->{source}">
  518. <input type=hidden name="amount_$1" value="$ref->{amount}">|;
  519. } else {
  520. $cleared += $ref->{amount} * $ml if $checked;
  521. $clearfx = ($checked) ? 1 : 0;
  522. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  523. <input type=hidden name="source_$i" value="$ref->{source}">
  524. <input type=hidden name="amount_$i" value="$ref->{amount}">
  525. </td>|;
  526. }
  527. }
  528. }
  529. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  530. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  531. $j++; $j %= 2;
  532. print qq|
  533. <tr class=listrow$j>
  534. |;
  535. for (@column_index) { print "\n$column_data{$_}" }
  536. print qq|
  537. </tr>
  538. |;
  539. }
  540. $form->{rowcount} = $i;
  541. # print totals
  542. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  543. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  544. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  545. print qq|
  546. <tr class=listtotal>
  547. |;
  548. for (@column_index) { print "\n$column_data{$_}" }
  549. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  550. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  551. if ($form->{source}){
  552. $difference = 0;
  553. }
  554. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  555. print qq|
  556. </tr>
  557. </table>
  558. </td>
  559. </tr>
  560. |;
  561. if ($form->{'pos'}){
  562. $close_next = qq|<button type="submit" class="submit" name="action"
  563. value="close_next">|.$locale->text('Close Next').qq|</button>|;
  564. $done = "";
  565. }
  566. else {
  567. $close_next = "";
  568. $done = qq|<button type="submit" class="submit" name="action"
  569. value="done">|.$locale->text('Done').qq|</button>|;
  570. }
  571. if ($form->{'pos'}){
  572. $difference = qq|
  573. <tr>
  574. <th align=right><select name=over_under>
  575. <option value=under>|.$locale->text('Under').qq|</option>
  576. <option value=over>|.$locale->text('Over').qq|</option>
  577. </select><input type=hidden name=pos value='true'>
  578. </th>
  579. <td width=10%></td>
  580. <td align=right><input name=null size=11
  581. value='|.$form->{null2}.qq|'></td>
  582. <input type=hidden name=difference
  583. value=$difference>
  584. |;
  585. if ($form->{'over_under'}){
  586. $o_u = $form->{'over_under'};
  587. $difference =~ s/(value=$o_u)/SELECTED $1/g;
  588. }
  589. } else {
  590. $difference = qq|
  591. <tr>
  592. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  593. <td width=10%></td>
  594. <td align=right><input name=null size=11 value=$difference></td>
  595. <input type=hidden name=difference value=$difference>
  596. </tr>|;
  597. }
  598. if ($form->{report}) {
  599. print qq|
  600. </tr>
  601. </table>
  602. |;
  603. } else {
  604. print qq|
  605. <tr>
  606. <td>
  607. <table width=100%>
  608. <tr>
  609. <td align=right>
  610. <table>
  611. <tr>
  612. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  613. <td width=10%></td>
  614. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  615. </tr>
  616. $difference
  617. </table>
  618. </td>
  619. </tr>
  620. </table>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td><hr size=3 noshade></td>
  625. </tr>
  626. </table>
  627. |;
  628. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  629. print qq|
  630. <br>
  631. <button type="submit" class="submit" name="action" value="update">|.$locale->text('Update').qq|</button>
  632. <button type="submit" class="submit" name="action" value="select_all">|.$locale->text('Select all').qq|</button>
  633. $done
  634. $close_next |;
  635. }
  636. if ($form->{lynx}) {
  637. require "bin/menu.pl";
  638. &menubar;
  639. }
  640. print qq|
  641. </form>
  642. </body>
  643. </html>
  644. |;
  645. }
  646. sub update {
  647. $form->{null2} = $form->{null};
  648. RC->payment_transactions(\%myconfig, \%$form);
  649. $i = 0;
  650. foreach $ref (@{ $form->{PR} }) {
  651. $i++;
  652. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  653. }
  654. &display_form;
  655. }
  656. sub select_all {
  657. RC->payment_transactions(\%myconfig, \%$form);
  658. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  659. &display_form;
  660. }
  661. sub done {
  662. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  663. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  664. RC->reconcile(\%myconfig, \%$form);
  665. $form->redirect;
  666. }