summaryrefslogtreecommitdiff
path: root/bin/lynx/rc.pl
blob: e28d6ef6fb0e3a1bc9bb378af0f0f2bc1260e81c (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2006
  4. # This work contains copyrighted information from a number of sources all used
  5. # with permission.
  6. #
  7. # This file contains source code included with or based on SQL-Ledger which
  8. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  9. # under the GNU General Public License version 2 or, at your option, any later
  10. # version. For a full list including contact information of contributors,
  11. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  12. #
  13. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  14. # Copyright (c) 2003
  15. #
  16. # Author: DWS Systems Inc.
  17. # Web: http://www.sql-ledger.org
  18. #
  19. #
  20. #
  21. # Author: DWS Systems Inc.
  22. # Web: http://sourceforge.net/projects/ledger-smb/
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # Account reconciliation module
  40. #
  41. #======================================================================
  42. use SL::RC;
  43. 1;
  44. # end of main
  45. # this is for our long dates
  46. # $locale->text('January')
  47. # $locale->text('February')
  48. # $locale->text('March')
  49. # $locale->text('April')
  50. # $locale->text('May ')
  51. # $locale->text('June')
  52. # $locale->text('July')
  53. # $locale->text('August')
  54. # $locale->text('September')
  55. # $locale->text('October')
  56. # $locale->text('November')
  57. # $locale->text('December')
  58. # this is for our short month
  59. # $locale->text('Jan')
  60. # $locale->text('Feb')
  61. # $locale->text('Mar')
  62. # $locale->text('Apr')
  63. # $locale->text('May')
  64. # $locale->text('Jun')
  65. # $locale->text('Jul')
  66. # $locale->text('Aug')
  67. # $locale->text('Sep')
  68. # $locale->text('Oct')
  69. # $locale->text('Nov')
  70. # $locale->text('Dec')
  71. sub reconciliation {
  72. RC->paymentaccounts(\%myconfig, \%$form);
  73. $selection = "";
  74. for (@{ $form->{PR} }) { $selection .= "<option>$_->{accno}--$_->{description}\n" }
  75. $form->{title} = $locale->text('Reconciliation');
  76. if ($form->{report}) {
  77. $form->{title} = $locale->text('Reconciliation Report');
  78. $cleared = qq|
  79. <input type=hidden name=report value=1>
  80. <tr>
  81. <td align=right><input type=checkbox class=checkbox name=outstanding value=1 checked></td>
  82. <td>|.$locale->text('Outstanding').qq|</td>
  83. <td align=right><input type=checkbox class=checkbox name=cleared value=1></td>
  84. <td>|.$locale->text('Cleared').qq|</td>
  85. </tr>
  86. |;
  87. }
  88. if (@{ $form->{all_years} }) {
  89. # accounting years
  90. $form->{selectaccountingyear} = "<option>\n";
  91. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  92. $form->{selectaccountingmonth} = "<option>\n";
  93. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  94. $selectfrom = qq|
  95. <tr>
  96. <th align=right>|.$locale->text('Period').qq|</th>
  97. <td colspan=3>
  98. <select name=month>$form->{selectaccountingmonth}</select>
  99. <select name=year>$form->{selectaccountingyear}</select>
  100. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  101. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  102. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  103. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  104. </td>
  105. </tr>
  106. |;
  107. }
  108. $form->header;
  109. print qq|
  110. <body>
  111. <form method=post action=$form->{script}>
  112. <table width=100%>
  113. <tr>
  114. <th class=listtop>$form->{title}</th>
  115. </tr>
  116. <tr height="5"></tr>
  117. <tr>
  118. <td>
  119. <table>
  120. <tr>
  121. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  122. <td colspan=3><select name=accno>$selection</select></td>
  123. </tr>
  124. <tr>
  125. <th align=right>|.$locale->text('From').qq|</th>
  126. <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>
  127. </tr>
  128. $selectfrom
  129. $cleared
  130. <tr>
  131. <td></td>
  132. <td colspan=3><input type=radio style=radio name=summary value=1 checked> |.$locale->text('Summary').qq|
  133. <input type=radio style=radio name=summary value=0> |.$locale->text('Detail').qq|</td>
  134. </tr>
  135. <tr>
  136. <td></td>
  137. <td colspan=3><input type=checkbox class=checkbox name=fx_transaction value=1 checked> |.$locale->text('Include Exchange Rate Difference').qq|</td>
  138. </tr>
  139. </table>
  140. </td>
  141. </tr>
  142. <tr>
  143. <td><hr size=3 noshade></td>
  144. </tr>
  145. </table>
  146. <br>
  147. <input type=hidden name=nextsub value=get_payments>
  148. |;
  149. $form->hide_form(qw(path login sessionid));
  150. print qq|
  151. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  152. </form>
  153. |;
  154. if ($form->{menubar}) {
  155. require "$form->{path}/menu.pl";
  156. &menubar;
  157. }
  158. print qq|
  159. </body>
  160. </html>
  161. |;
  162. }
  163. sub continue { &{ $form->{nextsub} } };
  164. sub get_payments {
  165. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  166. RC->payment_transactions(\%myconfig, \%$form);
  167. $ml = ($form->{category} eq 'A') ? -1 : 1;
  168. $form->{statementbalance} = $form->{endingbalance} * $ml;
  169. if (! $form->{fx_transaction}) {
  170. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  171. }
  172. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  173. &display_form;
  174. }
  175. sub display_form {
  176. if ($form->{report}) {
  177. @column_index = qw(transdate source name cleared debit credit);
  178. } else {
  179. @column_index = qw(transdate source name cleared debit credit balance);
  180. }
  181. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  182. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  183. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  184. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  185. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  186. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  187. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  188. if ($form->{fromdate}) {
  189. $option .= "\n<br>" if ($option);
  190. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  191. }
  192. if ($form->{todate}) {
  193. $option .= "\n<br>" if ($option);
  194. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  195. }
  196. $form->{title} = "$form->{accno}--$form->{account}";
  197. $form->header;
  198. print qq|
  199. <body>
  200. <form method=post action=$form->{script}>
  201. <table width=100%>
  202. <tr>
  203. <th class=listtop>$form->{title}</th>
  204. </tr>
  205. <tr height="5"></tr>
  206. <tr>
  207. <td>$option</td>
  208. </tr>
  209. <tr>
  210. <td>
  211. <table width=100%>
  212. <tr class=listheading>
  213. |;
  214. for (@column_index) { print "\n$column_header{$_}" }
  215. print qq|
  216. </tr>
  217. |;
  218. $ml = ($form->{category} eq 'A') ? -1 : 1;
  219. $form->{beginningbalance} *= $ml;
  220. $form->{fx_balance} *= $ml;
  221. if (! $form->{fx_transaction}) {
  222. $form->{beginningbalance} -= $form->{fx_balance};
  223. }
  224. $balance = $form->{beginningbalance};
  225. $i = 0;
  226. $j = 0;
  227. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  228. if (! $form->{report}) {
  229. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  230. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  231. print qq|
  232. <tr class=listrow$j>
  233. |;
  234. for (@column_index) { print "\n$column_data{$_}" }
  235. print qq|
  236. </tr>
  237. |;
  238. }
  239. foreach $ref (@{ $form->{PR} }) {
  240. $i++;
  241. if (! $form->{fx_transaction}) {
  242. next if $ref->{fx_transaction};
  243. }
  244. $checked = ($ref->{cleared}) ? "checked" : "";
  245. %temp = ();
  246. if (!$ref->{fx_transaction}) {
  247. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  248. }
  249. $column_data{name} = "<td>";
  250. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  251. $column_data{name} .= "</td>";
  252. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  253. <input type=hidden name="id_$i" value=$ref->{id}>|;
  254. $column_data{debit} = "<td>&nbsp;</td>";
  255. $column_data{credit} = "<td>&nbsp;</td>";
  256. $balance += $ref->{amount} * $ml;
  257. if ($ref->{amount} < 0) {
  258. $totaldebits += $ref->{amount} * -1;
  259. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  260. } else {
  261. $totalcredits += $ref->{amount};
  262. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  263. }
  264. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  265. if ($ref->{fx_transaction}) {
  266. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  267. $cleared += $ref->{amount} * $ml if $clearfx;
  268. } else {
  269. if ($form->{report}) {
  270. if ($ref->{cleared}) {
  271. $column_data{cleared} = qq|<td align=center>*</td>|;
  272. $clearfx = 1;
  273. } else {
  274. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  275. $clearfx = 0;
  276. }
  277. } else {
  278. if ($ref->{oldcleared}) {
  279. $cleared += $ref->{amount} * $ml;
  280. $clearfx = 1;
  281. $column_data{cleared} = qq|<td align=center>*</td>
  282. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  283. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  284. <input type=hidden name="source_$i" value="$ref->{source}">|;
  285. } else {
  286. $cleared += $ref->{amount} * $ml if $checked;
  287. $clearfx = ($checked) ? 1 : 0;
  288. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  289. <input type=hidden name="source_$i" value="$ref->{source}"></td>|;
  290. }
  291. }
  292. }
  293. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  294. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  295. $j++; $j %= 2;
  296. print qq|
  297. <tr class=listrow$j>
  298. |;
  299. for (@column_index) { print "\n$column_data{$_}" }
  300. print qq|
  301. </tr>
  302. |;
  303. }
  304. $form->{rowcount} = $i;
  305. # print totals
  306. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  307. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  308. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  309. print qq|
  310. <tr class=listtotal>
  311. |;
  312. for (@column_index) { print "\n$column_data{$_}" }
  313. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  314. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  315. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  316. print qq|
  317. </tr>
  318. </table>
  319. </td>
  320. </tr>
  321. |;
  322. if ($form->{report}) {
  323. print qq|
  324. </tr>
  325. </table>
  326. |;
  327. } else {
  328. print qq|
  329. <tr>
  330. <td>
  331. <table width=100%>
  332. <tr>
  333. <td align=right>
  334. <table>
  335. <tr>
  336. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  337. <td width=10%></td>
  338. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  339. </tr>
  340. <tr>
  341. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  342. <td width=10%></td>
  343. <td align=right><input name=null size=11 value=$difference></td>
  344. <input type=hidden name=difference value=$difference>
  345. </tr>
  346. </table>
  347. </td>
  348. </tr>
  349. </table>
  350. </td>
  351. </tr>
  352. <tr>
  353. <td><hr size=3 noshade></td>
  354. </tr>
  355. </table>
  356. |;
  357. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  358. print qq|
  359. <br>
  360. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  361. <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|">
  362. <input type=submit class=submit name=action value="|.$locale->text('Done').qq|">|;
  363. }
  364. if ($form->{menubar}) {
  365. require "$form->{path}/menu.pl";
  366. &menubar;
  367. }
  368. print qq|
  369. </form>
  370. </body>
  371. </html>
  372. |;
  373. }
  374. sub update {
  375. RC->payment_transactions(\%myconfig, \%$form);
  376. $i = 0;
  377. foreach $ref (@{ $form->{PR} }) {
  378. $i++;
  379. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  380. }
  381. &display_form;
  382. }
  383. sub select_all {
  384. RC->payment_transactions(\%myconfig, \%$form);
  385. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  386. &display_form;
  387. }
  388. sub done {
  389. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  390. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  391. RC->reconcile(\%myconfig, \%$form);
  392. $form->redirect;
  393. }