summaryrefslogtreecommitdiff
path: root/bin/rc.pl
blob: 6428ff63c556bea6cc9267170c7be72619ae5c1f (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->{source} 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";
  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 $parseval = $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]", $form->{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 $cash;
  403. print PRN $foot;
  404. close PRN;
  405. if ( $difference > 0 ) {
  406. $message = $locale->text( "You are over by [_1]", $difference );
  407. }
  408. elsif ( $difference < 0 ) {
  409. $message = $locale->text( "You are under by [_1]", $difference * -1 );
  410. }
  411. else {
  412. $message =
  413. $local->text("Congratulations! Your till is exactly balanced.");
  414. }
  415. $form->info($message);
  416. }
  417. sub get_payments {
  418. ( $form->{accno}, $form->{account} ) = split /--/, $form->{accno};
  419. if ( $form->{'pos'} ) {
  420. require "pos.conf.pl";
  421. $form->{fromdate} = $form->current_date( \%myconfig );
  422. unless ( $form->{source} ) {
  423. $form->{source} = ( sort keys(%pos_sources) )[0];
  424. }
  425. if ( $form->{source} eq 'cash' ) {
  426. $form->{summary} = "true";
  427. }
  428. else {
  429. $form->{summary} = "";
  430. }
  431. $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
  432. $form->{account} = $form->{source};
  433. }
  434. RC->payment_transactions( \%myconfig, \%$form );
  435. $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
  436. $form->{statementbalance} = $form->{endingbalance} * $ml;
  437. if ( !$form->{fx_transaction} ) {
  438. $form->{statementbalance} =
  439. ( $form->{endingbalance} - $form->{fx_endingbalance} ) * $ml;
  440. }
  441. $form->{statementbalance} =
  442. $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
  443. &display_form;
  444. }
  445. sub display_form {
  446. if ( $form->{report} ) {
  447. @column_index = qw(transdate source name cleared debit credit);
  448. }
  449. else {
  450. @column_index = qw(transdate source name cleared debit credit balance);
  451. }
  452. $column_header{cleared} = qq|<th>| . $locale->text('R') . qq|</th>|;
  453. $column_header{source} =
  454. "<th class=listheading>" . $locale->text('Source') . "</a></th>";
  455. $column_header{name} =
  456. "<th class=listheading>" . $locale->text('Description') . "</a></th>";
  457. $column_header{transdate} =
  458. "<th class=listheading>" . $locale->text('Date') . "</a></th>";
  459. $column_header{debit} =
  460. "<th class=listheading>" . $locale->text('Debit') . "</a></th>";
  461. $column_header{credit} =
  462. "<th class=listheading>" . $locale->text('Credit') . "</a></th>";
  463. $column_header{balance} =
  464. "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
  465. if ( $form->{fromdate} ) {
  466. $option .= "\n<br>" if ($option);
  467. $option .=
  468. $locale->text('From') . "&nbsp;"
  469. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  470. }
  471. if ( $form->{todate} ) {
  472. $option .= "\n<br>" if ($option);
  473. $option .=
  474. $locale->text('To') . "&nbsp;"
  475. . $locale->date( \%myconfig, $form->{todate}, 1 );
  476. }
  477. $form->{title} = "$form->{accno}--$form->{account}";
  478. $form->header;
  479. print qq|
  480. <body>
  481. <form method=post action=$form->{script}>
  482. <input type=hidden name=source value="$form->{source}">
  483. <input type=hidden name=cumulative_error value="$form->{cumulative_error}">
  484. <table width=100%>
  485. <tr>
  486. <th class=listtop>$form->{title}</th>
  487. </tr>
  488. <tr height="5"></tr>
  489. <tr>
  490. <td>$option</td>
  491. </tr>
  492. <tr>
  493. <td>
  494. <table width=100%>
  495. <tr class=listheading>
  496. |;
  497. for (@column_index) { print "\n$column_header{$_}" }
  498. print qq|
  499. </tr>
  500. |;
  501. $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
  502. $form->{beginningbalance} *= $ml;
  503. $form->{fx_balance} *= $ml;
  504. if ( !$form->{fx_transaction} ) {
  505. $form->{beginningbalance} -= $form->{fx_balance};
  506. }
  507. $balance = $form->{beginningbalance};
  508. $i = 0;
  509. $j = 0;
  510. for (qw(cleared transdate source debit credit)) {
  511. $column_data{$_} = "<td>&nbsp;</td>";
  512. }
  513. if ( !$form->{report} ) {
  514. $column_data{name} =
  515. qq|<td>| . $locale->text('Beginning Balance') . qq|</td>|;
  516. $column_data{balance} =
  517. "<td align=right>"
  518. . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
  519. print qq|
  520. <tr class=listrow$j>
  521. |;
  522. for (@column_index) { print "\n$column_data{$_}" }
  523. print qq|
  524. </tr>
  525. |;
  526. }
  527. foreach $ref ( @{ $form->{PR} } ) {
  528. $i++;
  529. if ( !$form->{fx_transaction} ) {
  530. next if $ref->{fx_transaction};
  531. }
  532. $checked = ( $ref->{cleared} ) ? "checked" : "";
  533. %temp = ();
  534. if ( !$ref->{fx_transaction} ) {
  535. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  536. }
  537. $column_data{name} = "<td>";
  538. for ( @{ $temp{name} } ) { $column_data{name} .= "$_<br>" }
  539. $column_data{name} .= "</td>";
  540. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  541. <input type=hidden name="id_$i" value=$ref->{id}>|;
  542. $column_data{debit} = "<td>&nbsp;</td>";
  543. $column_data{credit} = "<td>&nbsp;</td>";
  544. $balance += $ref->{amount} * $ml;
  545. if ( $ref->{amount} < 0 ) {
  546. $totaldebits += $ref->{amount} * -1;
  547. $column_data{debit} = "<td align=right>"
  548. . $form->format_amount( \%myconfig, $ref->{amount} * -1,
  549. 2, "&nbsp;" )
  550. . "</td>";
  551. }
  552. else {
  553. $totalcredits += $ref->{amount};
  554. $column_data{credit} =
  555. "<td align=right>"
  556. . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
  557. . "</td>";
  558. }
  559. $column_data{balance} =
  560. "<td align=right>"
  561. . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
  562. if ( $ref->{fx_transaction} ) {
  563. $column_data{cleared} =
  564. ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  565. $cleared += $ref->{amount} * $ml if $clearfx;
  566. }
  567. else {
  568. if ( $form->{report} ) {
  569. if ( $ref->{cleared} ) {
  570. $column_data{cleared} = qq|<td align=center>*</td>|;
  571. $clearfx = 1;
  572. }
  573. else {
  574. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  575. $clearfx = 0;
  576. }
  577. }
  578. else {
  579. if ( $ref->{oldcleared} ) {
  580. $cleared += $ref->{amount} * $ml;
  581. $clearfx = 1;
  582. $column_data{cleared} = qq|<td align=center>*</td>
  583. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  584. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  585. <input type=hidden name="source_$i" value="$ref->{source}">
  586. <input type=hidden name="amount_$1" value="$ref->{amount}">|;
  587. }
  588. else {
  589. $cleared += $ref->{amount} * $ml if $checked;
  590. $clearfx = ($checked) ? 1 : 0;
  591. $column_data{cleared} =
  592. qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  593. <input type=hidden name="source_$i" value="$ref->{source}">
  594. <input type=hidden name="amount_$i" value="$ref->{amount}">
  595. </td>|;
  596. }
  597. }
  598. }
  599. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  600. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  601. $j++;
  602. $j %= 2;
  603. print qq|
  604. <tr class=listrow$j>
  605. |;
  606. for (@column_index) { print "\n$column_data{$_}" }
  607. print qq|
  608. </tr>
  609. |;
  610. }
  611. $form->{rowcount} = $i;
  612. # print totals
  613. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  614. $column_data{debit} =
  615. "<th class=listtotal align=right>"
  616. . $form->format_amount( \%myconfig, $totaldebits, 2, "&nbsp;" ) . "</th>";
  617. $column_data{credit} =
  618. "<th class=listtotal align=right>"
  619. . $form->format_amount( \%myconfig, $totalcredits, 2, "&nbsp;" )
  620. . "</th>";
  621. print qq|
  622. <tr class=listtotal>
  623. |;
  624. for (@column_index) { print "\n$column_data{$_}" }
  625. $form->{statementbalance} =
  626. $form->parse_amount( \%myconfig, $form->{statementbalance} );
  627. $difference =
  628. $form->format_amount( \%myconfig,
  629. $form->{beginningbalance} + $cleared - $form->{statementbalance},
  630. 2, 0 );
  631. if ( $form->{source} ) {
  632. $difference = 0;
  633. }
  634. $form->{statementbalance} =
  635. $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
  636. print qq|
  637. </tr>
  638. </table>
  639. </td>
  640. </tr>
  641. |;
  642. if ( $form->{'pos'} ) {
  643. $close_next = qq|<button type="submit" class="submit" name="action"
  644. value="close_next">| . $locale->text('Close Next') . qq|</button>|;
  645. $done = "";
  646. }
  647. else {
  648. $close_next = "";
  649. $done = qq|<button type="submit" class="submit" name="action"
  650. value="done">| . $locale->text('Done') . qq|</button>|;
  651. }
  652. if ( $form->{'pos'} ) {
  653. $difference = qq|
  654. <tr>
  655. <th align=right><select name=over_under>
  656. <option value=under>|
  657. . $locale->text('Under')
  658. . qq|</option>
  659. <option value=over>| . $locale->text('Over') . qq|</option>
  660. </select><input type=hidden name=pos value='true'>
  661. </th>
  662. <td width=10%></td>
  663. <td align=right><input name=null size=11
  664. value='| . $form->{null2} . qq|'></td>
  665. <input type=hidden name=difference
  666. value=$difference>
  667. |;
  668. if ( $form->{'over_under'} ) {
  669. $o_u = $form->{'over_under'};
  670. $difference =~ s/(value=$o_u)/SELECTED $1/g;
  671. }
  672. }
  673. else {
  674. $difference = qq|
  675. <tr>
  676. <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
  677. <td width=10%></td>
  678. <td align=right><input name=null size=11 value=$difference></td>
  679. <input type=hidden name=difference value=$difference>
  680. </tr>|;
  681. }
  682. if ( $form->{report} ) {
  683. print qq|
  684. </tr>
  685. </table>
  686. |;
  687. }
  688. else {
  689. print qq|
  690. <tr>
  691. <td>
  692. <table width=100%>
  693. <tr>
  694. <td align=right>
  695. <table>
  696. <tr>
  697. <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
  698. <td width=10%></td>
  699. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  700. </tr>
  701. $difference
  702. </table>
  703. </td>
  704. </tr>
  705. </table>
  706. </td>
  707. </tr>
  708. <tr>
  709. <td><hr size=3 noshade></td>
  710. </tr>
  711. </table>
  712. |;
  713. $form->hide_form(
  714. qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid)
  715. );
  716. print qq|
  717. <br>
  718. <button type="submit" class="submit" name="action" value="update">|
  719. . $locale->text('Update')
  720. . qq|</button>
  721. <button type="submit" class="submit" name="action" value="select_all">|
  722. . $locale->text('Select all')
  723. . qq|</button>
  724. $done
  725. $close_next |;
  726. }
  727. if ( $form->{lynx} ) {
  728. require "bin/menu.pl";
  729. &menubar;
  730. }
  731. print qq|
  732. </form>
  733. </body>
  734. </html>
  735. |;
  736. }
  737. sub update {
  738. $form->{null2} = $form->{null};
  739. RC->payment_transactions( \%myconfig, \%$form );
  740. $i = 0;
  741. foreach $ref ( @{ $form->{PR} } ) {
  742. $i++;
  743. $ref->{cleared} = ( $form->{"cleared_$i"} ) ? 1 : 0;
  744. }
  745. &display_form;
  746. }
  747. sub select_all {
  748. RC->payment_transactions( \%myconfig, \%$form );
  749. for ( @{ $form->{PR} } ) { $_->{cleared} = 1 }
  750. &display_form;
  751. }
  752. sub done {
  753. $form->{callback} =
  754. "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  755. $form->error( $locale->text('Out of balance!') )
  756. if ( $form->{difference} *= 1 );
  757. RC->reconcile( \%myconfig, \%$form );
  758. $form->redirect;
  759. }