summaryrefslogtreecommitdiff
path: root/bin/rc.pl
blob: fe55c3973dc84f2983bfb41557c690dc19aa27cb (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} } ) {
  72. $selection .= "<option>$_->{accno}--$_->{description}\n";
  73. }
  74. $form->{title} = $locale->text('Reconciliation');
  75. if ( $form->{report} ) {
  76. $form->{title} = $locale->text('Reconciliation Report');
  77. $cleared = qq|
  78. <input type="hidden" name="report" value="1">
  79. <tr>
  80. <td align="right"><input type="checkbox" class="checkbox" name="outstanding" value="1" checked></td>
  81. <td>| . $locale->text('Outstanding') . qq|</td>
  82. <td align="right"><input type="checkbox" class="checkbox" name="cleared" value="1"></td>
  83. <td>| . $locale->text('Cleared') . qq|</td>
  84. </tr>
  85. |;
  86. }
  87. if ( @{ $form->{all_years} } ) {
  88. # accounting years
  89. $form->{selectaccountingyear} = "<option>\n";
  90. for ( @{ $form->{all_years} } ) {
  91. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  92. }
  93. $form->{selectaccountingmonth} = "<option>\n";
  94. for ( sort keys %{ $form->{all_month} } ) {
  95. $form->{selectaccountingmonth} .=
  96. qq|<option value=$_>|
  97. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  98. }
  99. $selectfrom = qq|
  100. <tr>
  101. <th align="right">| . $locale->text('Period') . qq|</th>
  102. <td colspan="3">
  103. <select name="month">$form->{selectaccountingmonth}</select>
  104. <select name="year">$form->{selectaccountingyear}</select>
  105. <input name="interval" class="radio" type="radio" value="0" checked>&nbsp;|
  106. . $locale->text('Current') . qq|
  107. <input name="interval" class="radio" type="radio" value="1">&nbsp;|
  108. . $locale->text('Month') . qq|
  109. <input name="interval" class="radio" type="radio" value="3">&nbsp;|
  110. . $locale->text('Quarter') . qq|
  111. <input name="interval" class="radio" type="radio" value="12">&nbsp;|
  112. . $locale->text('Year') . qq|
  113. </td>
  114. </tr>
  115. |;
  116. }
  117. $form->header;
  118. print qq|
  119. <body>
  120. <form method="post" action="$form->{script}">
  121. <table width="100%">
  122. <tr>
  123. <th class="listtop">$form->{title}</th>
  124. </tr>
  125. <tr height="5"></tr>
  126. <tr>
  127. <td>
  128. <table>
  129. <tr>
  130. <th align="right" nowrap>| . $locale->text('Account') . qq|</th>
  131. <td colspan="3"><select name="accno">$selection</select></td>
  132. </tr>
  133. <tr>
  134. <th align="right">| . $locale->text('From') . qq|</th>
  135. <td colspan="3"><input name="fromdate" size="11" title="$myconfig{dateformat}"> <b>|
  136. . $locale->text('To')
  137. . qq|</b> <input name="todate" size="11" title="$myconfig{dateformat}"></td>
  138. </tr>
  139. $selectfrom
  140. $cleared
  141. <tr>
  142. <td></td>
  143. <td colspan="3"><input type="radio" style="radio" name="summary" value="1" checked> |
  144. . $locale->text('Summary') . qq|
  145. <input type="radio" style="radio" name="summary" value="0"> |
  146. . $locale->text('Detail')
  147. . qq|</td>
  148. </tr>
  149. <tr>
  150. <td></td>
  151. <td colspan="3"><input type="checkbox" class="checkbox" name="fx_transaction" value="1" checked> |
  152. . $locale->text('Include Exchange Rate Difference')
  153. . qq|</td>
  154. </tr>
  155. </table>
  156. </td>
  157. </tr>
  158. <tr>
  159. <td><hr size="3" noshade></td>
  160. </tr>
  161. </table>
  162. <br>
  163. <input type="hidden" name="nextsub" value="get_payments">
  164. |;
  165. $form->hide_form(qw(path login sessionid));
  166. print qq|
  167. <button type="submit" class="submit" name="action" value="continue">|
  168. . $locale->text('Continue')
  169. . qq|</button>
  170. </form>
  171. |;
  172. if ( $form->{lynx} ) {
  173. require "bin/menu.pl";
  174. &menubar;
  175. }
  176. print qq|
  177. </body>
  178. </html>
  179. |;
  180. }
  181. sub continue { &{ $form->{nextsub} } }
  182. sub till_closing {
  183. $form->{callback} =
  184. "$form->{script}?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  185. # $locale->text("Source");
  186. # $locale->text("Actual");
  187. # $locale->text("Expected");
  188. # $locale->text("Error");
  189. @colheadings = qw(Source Actual Expected Error);
  190. my $curren = $pos_config{'curren'};
  191. $form->{title} = $locale->text( "Closing Till For [_1]", $form->{login} );
  192. require "pos.conf.pl";
  193. RC->getposlines( \%myconfig, \%$form );
  194. $form->header;
  195. print qq|
  196. <body>
  197. <form method="post" action="$form->{script}">
  198. <input type="hidden" name="path" value="$form->{path}">
  199. <input type="hidden" name="login" value="$form->{login}">
  200. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  201. <input type="hidden" name="callback" value="$form->{callback}">
  202. <input type="hidden" name="sum" value="| . $form->{sum} * -1 . qq|">
  203. <table width="100%">
  204. <tr>
  205. <th class="listtop">$form->{title}</th>
  206. </tr>
  207. </table>
  208. <table width="100%">
  209. |;
  210. print "<tr>";
  211. map { print '<td class="listheading">' . $locale->text($_) . "</td>"; }
  212. @colheadings;
  213. print "</tr>";
  214. my $j;
  215. my $source;
  216. foreach $source ( sort keys %pos_sources ) {
  217. $amount = 0;
  218. foreach $ref ( @{ $form->{TB} } ) {
  219. if ( $ref->{memo} eq $source ) {
  220. $amount = $ref->{amount} * -1;
  221. last;
  222. }
  223. }
  224. ++$j;
  225. $j = $j % 2;
  226. print qq|<tr class="listrow$j"><td>| . $pos_sources{$source} . qq|</td>
  227. <td><input name="amount_$source">
  228. <input type="hidden" name="expected_$source"
  229. value="$amount"></td>
  230. <td>${curren}$amount</td>
  231. <td id="error_$source">&nbsp;</td></tr>|;
  232. }
  233. print qq|
  234. <script type='text/javascript'>
  235. function money_round(m){
  236. var r;
  237. r = Math.round(m * 100)/100;
  238. return r;
  239. }
  240. function custom_calc_total(){
  241. |;
  242. my $subgen = 'document.forms[0].sub_sub.value = ';
  243. my $toround = '';
  244. foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
  245. # XXX Needs to take into account currencies that don't use 2 dp
  246. my $parsed = $form->parse_amount( \%pos_config, $unit );
  247. my $calcval = $parsed;
  248. $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
  249. my $subval = 'sub_' . $calcval;
  250. $calcval = 'calc_' . $calcval;
  251. print qq|
  252. document.forms[0].${subval}.value = document.forms[0].${calcval}.value * $parsed;
  253. |;
  254. $subgen .= "document.forms[0].${subval}.value * 1 + ";
  255. $toround .= qq|
  256. document.forms[0].${subval}.value =
  257. money_round(document.forms[0].${subval}.value); |;
  258. }
  259. print $subgen . "0;";
  260. print $toround;
  261. print qq|document.forms[0].sub_sub.value =
  262. money_round(document.forms[0].sub_sub.value);
  263. document.forms[0].amount_cash.value = money_round(
  264. document.forms[0].sub_sub.value - $pos_config{till_cash});
  265. check_errors();
  266. }
  267. function check_errors(){
  268. var cumulative_error = 0;
  269. var source_error = 0;
  270. var err_cell;
  271. |;
  272. map {
  273. print " source_error = money_round(
  274. document.forms[0].amount_$_.value -
  275. document.forms[0].expected_$_.value);
  276. cumulative_error = cumulative_error + source_error;
  277. err_cell = document.getElementById('error_$_');
  278. err_cell.innerHTML = '$curren' + source_error;\n";
  279. } ( keys %pos_sources );
  280. print qq|
  281. alert('|
  282. . $locale->text('Cumulative Error:')
  283. . qq| $curren' + money_round(cumulative_error));
  284. }
  285. </script>
  286. <table>
  287. <col><col><col>|;
  288. foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
  289. # XXX Needs to take into account currencies that don't use 2 dp
  290. my $calcval = $form->parse_amount( \%pos_config, $unit );
  291. $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
  292. my $subval = 'sub_' . $calcval;
  293. $calcval = 'calc_' . $calcval;
  294. print qq|<tr>
  295. <td><input type="text" name="$calcval" value="$form->{$calcval}"></td>
  296. <th>X ${curren}${unit} = </th>
  297. <td><input type="text" name="$subval" value="$form->{$subval}"></td>
  298. </tr>|;
  299. }
  300. print qq|<tr>
  301. <td>&nbsp;</td>
  302. <th>| . $locale->text("Subtotal") . qq|:</th>
  303. <td><input type="text" name="sub_sub" value="$form->{sub_sub}"></td>
  304. </tr>
  305. </table>
  306. <input type="button" name="calculate" class="submit" onClick="custom_calc_total()"
  307. value='| . $locale->text('Calculate') . qq|'>
  308. |;
  309. print qq|</table><button type="submit" name="action" value="close_till">|
  310. . $locale->text("Close Till")
  311. . qq|</button>|;
  312. print qq|
  313. </form>
  314. </body>
  315. </html>
  316. |;
  317. }
  318. sub close_till {
  319. use LedgerSMB::GL;
  320. require 'pos.conf.pl';
  321. RC->clear_till( \%myconfig, \%$form );
  322. my $amount = 0;
  323. my $expected = 0;
  324. my $difference = 0;
  325. my $lines = '';
  326. $form->{rowcount} = 2;
  327. foreach $key ( keys %pos_sources ) {
  328. $amount = 0;
  329. $expected = 0;
  330. $amount = $form->parse_amount( \%myconfig, $form->{"amount_$key"} );
  331. $expected = $form->parse_amount( \%myconfig, $form->{"expected_$key"} );
  332. $gl_entry = "Closing Till $pos_config{till} source = $key";
  333. $accno1 = $pos_config{till_accno};
  334. if ( ${ $pos_config{'source_accno_override'}{$key} } ) {
  335. $accno2 = ${ $pos_config{'source_accno_override'}{$key} };
  336. }
  337. else {
  338. $accno2 = $pos_config{'close_cash_accno'};
  339. }
  340. $form->{reference} = $gl_entry;
  341. $form->{accno_1} = $accno1;
  342. $form->{credit_1} = $amount;
  343. $form->{accno_2} = $accno2;
  344. $form->{debit_2} = $amount;
  345. $form->{transdate} = $form->current_date( \%myconfig );
  346. GL->post_transaction( \%myconfig, \%$form );
  347. delete $form->{id};
  348. $error = $amount - $expected;
  349. $difference += $error;
  350. $lines .=
  351. "Source: $key, Amount: $amount\nExpected: $expected. Error= $error\n\n";
  352. }
  353. $gl_entry = "Closing Till: $pos_config{till} Over/Under";
  354. $amount = $difference * -1;
  355. $form->{reference} = $gl_entry;
  356. $form->{accno_1} = $accno1;
  357. $form->{credit_1} = $amount;
  358. $form->{accno_2} = $pos_config{coa_prefix};
  359. $form->{debit_2} = $amount;
  360. $form->{transdate} = $form->current_date( \%myconfig );
  361. GL->post_transaction( \%myconfig, \%$form );
  362. delete $form->{id};
  363. $lines .= "Cumulative Error: $amount\n\n";
  364. $form->{accno} = $form->{accno_1};
  365. RC->getbalance( \%myconfig, \%$form );
  366. $amount = $form->{balance} * -1;
  367. $gl_entry = "Resetting Till: $pos_config{till}";
  368. $form->{reference} = $gl_entry;
  369. $form->{accno_1} = $accno1;
  370. $form->{credit_1} = $amount;
  371. $form->{accno_2} = $pos_config{coa_prefix};
  372. $form->{debit_2} = $amount;
  373. $form->{transdate} = $form->current_date( \%myconfig );
  374. GL->post_transaction( \%myconfig, \%$form );
  375. delete $form->{id};
  376. $head =
  377. "Closing Till $pos_config{till} for $form->{login}\n"
  378. . "Date: $form->{transdate}\n\n\n";
  379. my @cashlines = ( $locale->text("Cash Breakdown:") );
  380. foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
  381. # XXX Needs to take into account currencies that don't use 2 dp
  382. my $parsed = $form->parse_amount( \%pos_config, $unit );
  383. my $calcval = $parsed;
  384. $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
  385. my $subval = 'sub_' . $calcval;
  386. $calcval = 'calc_' . $calcval;
  387. push @cashlines, "$form->{$calcval} x $parsed = $form->{$subval}";
  388. }
  389. push @cashlines,
  390. $locale->text( "Total Cash in Drawer: [_1]", $form->{sub_sub} );
  391. push @cashlines,
  392. $locale->text( "Less Cash in Till At Start: [_1]", $pos_config{till_cash} );
  393. push @cashlines, "\n";
  394. $cash = join( "\n", @cashlines );
  395. $foot = $locale->text( "Cumulative Error: [_1]", $difference ) . "\n";
  396. $foot .=
  397. $locale->text( 'Reset Till By [_1]', $amount ) . "\n\n\n\n\n\n\n\n\n\n";
  398. open( PRN, "|-", ${LedgerSMB::Sysconfig::printer}{Printer} );
  399. print PRN $head;
  400. print PRN $lines;
  401. print PRN $cash;
  402. print PRN $foot;
  403. close PRN;
  404. if ( $difference < 0 ) {
  405. $message = $locale->text( "You are over by [_1]", $difference );
  406. }
  407. elsif ( $difference > 0 ) {
  408. $message = $locale->text( "You are under by [_1]", $difference * -1 );
  409. }
  410. else {
  411. $message =
  412. $locale->text("Congratulations! Your till is exactly balanced.");
  413. }
  414. $form->info($message);
  415. }
  416. sub get_payments {
  417. ( $form->{accno}, $form->{account} ) = split /--/, $form->{accno};
  418. if ( $form->{'pos'} ) {
  419. require "pos.conf.pl";
  420. $form->{fromdate} = $form->current_date( \%myconfig );
  421. unless ( $form->{source} ) {
  422. $form->{source} = ( sort keys(%pos_sources) )[0];
  423. }
  424. if ( $form->{source} eq 'cash' ) {
  425. $form->{summary} = "true";
  426. }
  427. else {
  428. $form->{summary} = "";
  429. }
  430. $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
  431. $form->{account} = $form->{source};
  432. }
  433. RC->payment_transactions( \%myconfig, \%$form );
  434. $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
  435. $form->{statementbalance} = $form->{endingbalance} * $ml;
  436. if ( !$form->{fx_transaction} ) {
  437. $form->{statementbalance} =
  438. ( $form->{endingbalance} - $form->{fx_endingbalance} ) * $ml;
  439. }
  440. $form->{statementbalance} =
  441. $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
  442. &display_form;
  443. }
  444. sub display_form {
  445. if ( $form->{report} ) {
  446. @column_index = qw(transdate source name cleared debit credit);
  447. }
  448. else {
  449. @column_index = qw(transdate source name cleared debit credit balance);
  450. }
  451. $column_header{cleared} = qq|<th>| . $locale->text('R') . qq|</th>|;
  452. $column_header{source} =
  453. '<th class="listheading">' . $locale->text('Source') . "</a></th>";
  454. $column_header{name} =
  455. '<th class="listheading">' . $locale->text('Description') . "</a></th>";
  456. $column_header{transdate} =
  457. '<th class="listheading">' . $locale->text('Date') . "</a></th>";
  458. $column_header{debit} =
  459. '<th class="listheading">' . $locale->text('Debit') . "</a></th>";
  460. $column_header{credit} =
  461. '<th class="listheading">' . $locale->text('Credit') . "</a></th>";
  462. $column_header{balance} =
  463. '<th class="listheading">' . $locale->text('Balance') . "</a></th>";
  464. if ( $form->{fromdate} ) {
  465. $option .= "\n<br>" if ($option);
  466. $option .=
  467. $locale->text('From') . "&nbsp;"
  468. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  469. }
  470. if ( $form->{todate} ) {
  471. $option .= "\n<br>" if ($option);
  472. $option .=
  473. $locale->text('To') . "&nbsp;"
  474. . $locale->date( \%myconfig, $form->{todate}, 1 );
  475. }
  476. $form->{title} = "$form->{accno}--$form->{account}";
  477. $form->header;
  478. print qq|
  479. <body>
  480. <form method="post" action="$form->{script}">
  481. <input type="hidden" name="source" value="$form->{source}">
  482. <input type="hidden" name="cumulative_error" value="$form->{cumulative_error}">
  483. <table width="100%">
  484. <tr>
  485. <th class="listtop">$form->{title}</th>
  486. </tr>
  487. <tr height="5"></tr>
  488. <tr>
  489. <td>$option</td>
  490. </tr>
  491. <tr>
  492. <td>
  493. <table width="100%">
  494. <tr class="listheading">
  495. |;
  496. for (@column_index) { print "\n$column_header{$_}" }
  497. print qq|
  498. </tr>
  499. |;
  500. $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
  501. $form->{beginningbalance} *= $ml;
  502. $form->{fx_balance} *= $ml;
  503. if ( !$form->{fx_transaction} ) {
  504. $form->{beginningbalance} -= $form->{fx_balance};
  505. }
  506. $balance = $form->{beginningbalance};
  507. $i = 0;
  508. $j = 0;
  509. for (qw(cleared transdate source debit credit)) {
  510. $column_data{$_} = "<td>&nbsp;</td>";
  511. }
  512. if ( !$form->{report} ) {
  513. $column_data{name} =
  514. qq|<td>| . $locale->text('Beginning Balance') . qq|</td>|;
  515. $column_data{balance} =
  516. "<td align=right>"
  517. . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
  518. print qq|
  519. <tr class=listrow$j>
  520. |;
  521. for (@column_index) { print "\n$column_data{$_}" }
  522. print qq|
  523. </tr>
  524. |;
  525. }
  526. foreach $ref ( @{ $form->{PR} } ) {
  527. $i++;
  528. if ( !$form->{fx_transaction} ) {
  529. next if $ref->{fx_transaction};
  530. }
  531. $checked = ( $ref->{cleared} ) ? "checked" : "";
  532. %temp = ();
  533. if ( !$ref->{fx_transaction} ) {
  534. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  535. }
  536. $column_data{name} = "<td>";
  537. for ( @{ $temp{name} } ) { $column_data{name} .= "$_<br>" }
  538. $column_data{name} .= "</td>";
  539. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  540. <input type="hidden" name="id_$i" value="$ref->{id}">|;
  541. $column_data{debit} = "<td>&nbsp;</td>";
  542. $column_data{credit} = "<td>&nbsp;</td>";
  543. $balance += $ref->{amount} * $ml;
  544. if ( $ref->{amount} < 0 ) {
  545. $totaldebits += $ref->{amount} * -1;
  546. $column_data{debit} = '<td align="right">'
  547. . $form->format_amount( \%myconfig, $ref->{amount} * -1,
  548. 2, "&nbsp;" )
  549. . "</td>";
  550. }
  551. else {
  552. $totalcredits += $ref->{amount};
  553. $column_data{credit} =
  554. '<td align="right">'
  555. . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
  556. . "</td>";
  557. }
  558. $column_data{balance} =
  559. '<td align="right">'
  560. . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
  561. if ( $ref->{fx_transaction} ) {
  562. $column_data{cleared} =
  563. ($clearfx) ? qq|<td align="center">*</td>| : qq|<td>&nbsp;</td>|;
  564. $cleared += $ref->{amount} * $ml if $clearfx;
  565. }
  566. else {
  567. if ( $form->{report} ) {
  568. if ( $ref->{cleared} ) {
  569. $column_data{cleared} = qq|<td align="center">*</td>|;
  570. $clearfx = 1;
  571. }
  572. else {
  573. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  574. $clearfx = 0;
  575. }
  576. }
  577. else {
  578. if ( $ref->{oldcleared} ) {
  579. $cleared += $ref->{amount} * $ml;
  580. $clearfx = 1;
  581. $column_data{cleared} = qq|<td align="center">*</td>
  582. <input type="hidden" name="cleared_$i" value="$ref->{cleared}">
  583. <input type="hidden" name="oldcleared_$i" value="$ref->{oldcleared}">
  584. <input type="hidden" name="source_$i" value="$ref->{source}">
  585. <input type="hidden" name="amount_$1" value="$ref->{amount}">|;
  586. }
  587. else {
  588. $cleared += $ref->{amount} * $ml if $checked;
  589. $clearfx = ($checked) ? 1 : 0;
  590. $column_data{cleared} =
  591. qq|<td align="center"><input name="cleared_$i" type="checkbox" class="checkbox" value="1" $checked>
  592. <input type="hidden" name="source_$i" value="$ref->{source}">
  593. <input type="hidden" name="amount_$i" value="$ref->{amount}">
  594. </td>|;
  595. }
  596. }
  597. }
  598. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  599. <input type="hidden" name="transdate_$i" value="$ref->{transdate}">|;
  600. $j++;
  601. $j %= 2;
  602. print qq|
  603. <tr class="listrow$j">
  604. |;
  605. for (@column_index) { print "\n$column_data{$_}" }
  606. print qq|
  607. </tr>
  608. |;
  609. }
  610. $form->{rowcount} = $i;
  611. # print totals
  612. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  613. $column_data{debit} =
  614. '<th class="listtotal" align="right">'
  615. . $form->format_amount( \%myconfig, $totaldebits, 2, "&nbsp;" ) . "</th>";
  616. $column_data{credit} =
  617. '<th class="listtotal" align="right">'
  618. . $form->format_amount( \%myconfig, $totalcredits, 2, "&nbsp;" )
  619. . "</th>";
  620. print qq|
  621. <tr class="listtotal">
  622. |;
  623. for (@column_index) { print "\n$column_data{$_}" }
  624. $form->{statementbalance} =
  625. $form->parse_amount( \%myconfig, $form->{statementbalance} );
  626. $difference =
  627. $form->format_amount( \%myconfig,
  628. $form->{beginningbalance} + $cleared - $form->{statementbalance},
  629. 2, 0 );
  630. if ( $form->{source} ) {
  631. $difference = 0;
  632. }
  633. $form->{statementbalance} =
  634. $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
  635. print qq|
  636. </tr>
  637. </table>
  638. </td>
  639. </tr>
  640. |;
  641. if ( $form->{'pos'} ) {
  642. $close_next = qq|<button type="submit" class="submit" name="action"
  643. value="close_next">| . $locale->text('Close Next') . qq|</button>|;
  644. $done = "";
  645. }
  646. else {
  647. $close_next = "";
  648. $done = qq|<button type="submit" class="submit" name="action"
  649. value="done">| . $locale->text('Done') . qq|</button>|;
  650. }
  651. if ( $form->{'pos'} ) {
  652. $difference = qq|
  653. <tr>
  654. <th align="right"><select name="over_under">
  655. <option value="under">|
  656. . $locale->text('Under')
  657. . qq|</option>
  658. <option value="over">| . $locale->text('Over') . qq|</option>
  659. </select><input type="hidden" name="pos" value='true'>
  660. </th>
  661. <td width="10%"></td>
  662. <td align="right"><input name="null" size="11"
  663. value='| . $form->{null2} . qq|'></td>
  664. <input type="hidden" name="difference"
  665. value="$difference">
  666. |;
  667. if ( $form->{'over_under'} ) {
  668. $o_u = $form->{'over_under'};
  669. $difference =~ s/(value=$o_u)/SELECTED $1/g;
  670. }
  671. }
  672. else {
  673. $difference = qq|
  674. <tr>
  675. <th align="right" nowrap>| . $locale->text('Difference') . qq|</th>
  676. <td width="10%"></td>
  677. <td align="right"><input name="null" size="11" value="$difference"></td>
  678. <input type="hidden" name="difference" value="$difference">
  679. </tr>|;
  680. }
  681. if ( $form->{report} ) {
  682. print qq|
  683. </tr>
  684. </table>
  685. |;
  686. }
  687. else {
  688. print qq|
  689. <tr>
  690. <td>
  691. <table width="100%">
  692. <tr>
  693. <td align="right">
  694. <table>
  695. <tr>
  696. <th align="right" nowrap>| . $locale->text('Statement Balance') . qq|</th>
  697. <td width="10%"></td>
  698. <td align="right"><input name="statementbalance" size="11" value="$form->{statementbalance}"></td>
  699. </tr>
  700. $difference
  701. </table>
  702. </td>
  703. </tr>
  704. </table>
  705. </td>
  706. </tr>
  707. <tr>
  708. <td><hr size="3" noshade></td>
  709. </tr>
  710. </table>
  711. |;
  712. $form->hide_form(
  713. qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid)
  714. );
  715. print qq|
  716. <br>
  717. <button type="submit" class="submit" name="action" value="update">|
  718. . $locale->text('Update')
  719. . qq|</button>
  720. <button type="submit" class="submit" name="action" value="select_all">|
  721. . $locale->text('Select all')
  722. . qq|</button>
  723. $done
  724. $close_next |;
  725. }
  726. if ( $form->{lynx} ) {
  727. require "bin/menu.pl";
  728. &menubar;
  729. }
  730. print qq|
  731. </form>
  732. </body>
  733. </html>
  734. |;
  735. }
  736. sub update {
  737. $form->{null2} = $form->{null};
  738. RC->payment_transactions( \%myconfig, \%$form );
  739. $i = 0;
  740. foreach $ref ( @{ $form->{PR} } ) {
  741. $i++;
  742. $ref->{cleared} = ( $form->{"cleared_$i"} ) ? 1 : 0;
  743. }
  744. &display_form;
  745. }
  746. sub select_all {
  747. RC->payment_transactions( \%myconfig, \%$form );
  748. for ( @{ $form->{PR} } ) { $_->{cleared} = 1 }
  749. &display_form;
  750. }
  751. sub done {
  752. $form->{callback} =
  753. "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  754. $form->error( $locale->text('Out of balance!') )
  755. if ( $form->{difference} *= 1 );
  756. RC->reconcile( \%myconfig, \%$form );
  757. $form->redirect;
  758. }