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