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