summaryrefslogtreecommitdiff
path: root/bin/rc.pl
blob: 32301e77d72f04f2dbfb9cd83de683f17f50a5a9 (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->{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} = "Closing Till For $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('Cumulative Error: $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='Calculate'>
  279. |;
  280. print qq|</table><input type=submit name=action value="|.
  281. $locale->text("close_till").qq|">|;
  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:") . $form->{sub_sub};
  357. push @cashlines, $locale->text("Less Cash in Till At Start:") .
  358. $form->{till_cash};
  359. push @cashlines, "\n";
  360. $cash = join ("\n", @cashlines);
  361. $foot = $locale->text("Cumulative Error: ")."$difference\n";
  362. $foot .= $locale->text('Reset Till By ')."$amount\n\n\n\n\n\n\n\n\n\n";
  363. open (PRN, "|-", $printer{Printer});
  364. print PRN $head;
  365. print PRN $lines;
  366. print PRN $cash;
  367. print PRN $cash;
  368. print PRN $foot;
  369. close PRN;
  370. if ($difference > 0){
  371. $message = $locale->text("You are over by ").$difference;
  372. } elsif ($difference < 0){
  373. $message = $locale->text("You are under by ").$difference * -1;
  374. }
  375. else {
  376. $message = $local->text("Congratulations! Your till is exactly balanced.");
  377. }
  378. $form->info($message);
  379. }
  380. sub get_payments {
  381. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  382. if ($form->{'pos'}){
  383. require "pos.conf.pl";
  384. $form->{fromdate} = $form->current_date(\%myconfig);
  385. unless ($form->{source}){
  386. $form->{source} = (sort keys(%pos_sources))[0];
  387. }
  388. if ($form->{source} eq 'cash'){
  389. $form->{summary} = "true";
  390. } else {
  391. $form->{summary} = "";
  392. }
  393. $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
  394. $form->{account} = $form->{source};
  395. }
  396. RC->payment_transactions(\%myconfig, \%$form);
  397. $ml = ($form->{category} eq 'A') ? -1 : 1;
  398. $form->{statementbalance} = $form->{endingbalance} * $ml;
  399. if (! $form->{fx_transaction}) {
  400. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  401. }
  402. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  403. &display_form;
  404. }
  405. sub display_form {
  406. if ($form->{report}) {
  407. @column_index = qw(transdate source name cleared debit credit);
  408. } else {
  409. @column_index = qw(transdate source name cleared debit credit balance);
  410. }
  411. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  412. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  413. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  414. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  415. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  416. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  417. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  418. if ($form->{fromdate}) {
  419. $option .= "\n<br>" if ($option);
  420. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  421. }
  422. if ($form->{todate}) {
  423. $option .= "\n<br>" if ($option);
  424. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  425. }
  426. $form->{title} = "$form->{accno}--$form->{account}";
  427. $form->header;
  428. print qq|
  429. <body>
  430. <form method=post action=$form->{script}>
  431. <input type=hidden name=source value="$form->{source}">
  432. <input type=hidden name=cumulative_error value="$form->{cumulative_error}">
  433. <table width=100%>
  434. <tr>
  435. <th class=listtop>$form->{title}</th>
  436. </tr>
  437. <tr height="5"></tr>
  438. <tr>
  439. <td>$option</td>
  440. </tr>
  441. <tr>
  442. <td>
  443. <table width=100%>
  444. <tr class=listheading>
  445. |;
  446. for (@column_index) { print "\n$column_header{$_}" }
  447. print qq|
  448. </tr>
  449. |;
  450. $ml = ($form->{category} eq 'A') ? -1 : 1;
  451. $form->{beginningbalance} *= $ml;
  452. $form->{fx_balance} *= $ml;
  453. if (! $form->{fx_transaction}) {
  454. $form->{beginningbalance} -= $form->{fx_balance};
  455. }
  456. $balance = $form->{beginningbalance};
  457. $i = 0;
  458. $j = 0;
  459. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  460. if (! $form->{report}) {
  461. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  462. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  463. print qq|
  464. <tr class=listrow$j>
  465. |;
  466. for (@column_index) { print "\n$column_data{$_}" }
  467. print qq|
  468. </tr>
  469. |;
  470. }
  471. foreach $ref (@{ $form->{PR} }) {
  472. $i++;
  473. if (! $form->{fx_transaction}) {
  474. next if $ref->{fx_transaction};
  475. }
  476. $checked = ($ref->{cleared}) ? "checked" : "";
  477. %temp = ();
  478. if (!$ref->{fx_transaction}) {
  479. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  480. }
  481. $column_data{name} = "<td>";
  482. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  483. $column_data{name} .= "</td>";
  484. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  485. <input type=hidden name="id_$i" value=$ref->{id}>|;
  486. $column_data{debit} = "<td>&nbsp;</td>";
  487. $column_data{credit} = "<td>&nbsp;</td>";
  488. $balance += $ref->{amount} * $ml;
  489. if ($ref->{amount} < 0) {
  490. $totaldebits += $ref->{amount} * -1;
  491. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  492. } else {
  493. $totalcredits += $ref->{amount};
  494. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  495. }
  496. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  497. if ($ref->{fx_transaction}) {
  498. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  499. $cleared += $ref->{amount} * $ml if $clearfx;
  500. } else {
  501. if ($form->{report}) {
  502. if ($ref->{cleared}) {
  503. $column_data{cleared} = qq|<td align=center>*</td>|;
  504. $clearfx = 1;
  505. } else {
  506. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  507. $clearfx = 0;
  508. }
  509. } else {
  510. if ($ref->{oldcleared}) {
  511. $cleared += $ref->{amount} * $ml;
  512. $clearfx = 1;
  513. $column_data{cleared} = qq|<td align=center>*</td>
  514. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  515. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  516. <input type=hidden name="source_$i" value="$ref->{source}">
  517. <input type=hidden name="amount_$1" value="$ref->{amount}">|;
  518. } else {
  519. $cleared += $ref->{amount} * $ml if $checked;
  520. $clearfx = ($checked) ? 1 : 0;
  521. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  522. <input type=hidden name="source_$i" value="$ref->{source}">
  523. <input type=hidden name="amount_$i" value="$ref->{amount}">
  524. </td>|;
  525. }
  526. }
  527. }
  528. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  529. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  530. $j++; $j %= 2;
  531. print qq|
  532. <tr class=listrow$j>
  533. |;
  534. for (@column_index) { print "\n$column_data{$_}" }
  535. print qq|
  536. </tr>
  537. |;
  538. }
  539. $form->{rowcount} = $i;
  540. # print totals
  541. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  542. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  543. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  544. print qq|
  545. <tr class=listtotal>
  546. |;
  547. for (@column_index) { print "\n$column_data{$_}" }
  548. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  549. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  550. if ($form->{source}){
  551. $difference = 0;
  552. }
  553. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  554. print qq|
  555. </tr>
  556. </table>
  557. </td>
  558. </tr>
  559. |;
  560. if ($form->{'pos'}){
  561. $close_next = qq|<input type=submit class=submit name=action
  562. value="|.$locale->text('close_next').qq|">|;
  563. $done = "";
  564. }
  565. else {
  566. $close_next = "";
  567. $done = qq|<input type=submit class=submit name=action
  568. value="|.$locale->text('Done').qq|">|;
  569. }
  570. if ($form->{'pos'}){
  571. $difference = qq|
  572. <tr>
  573. <th align=right><select name=over_under>
  574. <option value=under>|.$locale->text('Under').qq|</option>
  575. <option value=over>|.$locale->text('Over').qq|</option>
  576. </select><input type=hidden name=pos value='true'>
  577. </th>
  578. <td width=10%></td>
  579. <td align=right><input name=null size=11
  580. value='|.$form->{null2}.qq|'></td>
  581. <input type=hidden name=difference
  582. value=$difference>
  583. |;
  584. if ($form->{'over_under'}){
  585. $o_u = $form->{'over_under'};
  586. $difference =~ s/(value=$o_u)/SELECTED $1/g;
  587. }
  588. } else {
  589. $difference = qq|
  590. <tr>
  591. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  592. <td width=10%></td>
  593. <td align=right><input name=null size=11 value=$difference></td>
  594. <input type=hidden name=difference value=$difference>
  595. </tr>|;
  596. }
  597. if ($form->{report}) {
  598. print qq|
  599. </tr>
  600. </table>
  601. |;
  602. } else {
  603. print qq|
  604. <tr>
  605. <td>
  606. <table width=100%>
  607. <tr>
  608. <td align=right>
  609. <table>
  610. <tr>
  611. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  612. <td width=10%></td>
  613. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  614. </tr>
  615. $difference
  616. </table>
  617. </td>
  618. </tr>
  619. </table>
  620. </td>
  621. </tr>
  622. <tr>
  623. <td><hr size=3 noshade></td>
  624. </tr>
  625. </table>
  626. |;
  627. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  628. print qq|
  629. <br>
  630. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  631. <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|">
  632. $done
  633. $close_next |;
  634. }
  635. if ($form->{lynx}) {
  636. require "bin/menu.pl";
  637. &menubar;
  638. }
  639. print qq|
  640. </form>
  641. </body>
  642. </html>
  643. |;
  644. }
  645. sub update {
  646. $form->{null2} = $form->{null};
  647. RC->payment_transactions(\%myconfig, \%$form);
  648. $i = 0;
  649. foreach $ref (@{ $form->{PR} }) {
  650. $i++;
  651. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  652. }
  653. &display_form;
  654. }
  655. sub select_all {
  656. RC->payment_transactions(\%myconfig, \%$form);
  657. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  658. &display_form;
  659. }
  660. sub done {
  661. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  662. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  663. RC->reconcile(\%myconfig, \%$form);
  664. $form->redirect;
  665. }