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