summaryrefslogtreecommitdiff
path: root/bin/mozilla/rc.pl
blob: 643d5dc97648588d37920d89153531966f30c0bd (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://sourceforge.net/projects/ledger-smb/
  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->{menubar}) {
  152. require "$form->{path}/menu.pl";
  153. &menubar;
  154. }
  155. print qq|
  156. </body>
  157. </html>
  158. |;
  159. }
  160. sub continue { &{ $form->{nextsub} } };
  161. sub get_payments {
  162. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  163. RC->payment_transactions(\%myconfig, \%$form);
  164. $ml = ($form->{category} eq 'A') ? -1 : 1;
  165. $form->{statementbalance} = $form->{endingbalance} * $ml;
  166. if (! $form->{fx_transaction}) {
  167. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  168. }
  169. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  170. &display_form;
  171. }
  172. sub display_form {
  173. if ($form->{report}) {
  174. @column_index = qw(transdate source name cleared debit credit);
  175. } else {
  176. @column_index = qw(transdate source name cleared debit credit balance);
  177. }
  178. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  179. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  180. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  181. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  182. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  183. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  184. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  185. if ($form->{fromdate}) {
  186. $option .= "\n<br>" if ($option);
  187. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  188. }
  189. if ($form->{todate}) {
  190. $option .= "\n<br>" if ($option);
  191. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  192. }
  193. $form->{title} = "$form->{accno}--$form->{account}";
  194. $form->header;
  195. print qq|
  196. <body>
  197. <form method=post action=$form->{script}>
  198. <table width=100%>
  199. <tr>
  200. <th class=listtop>$form->{title}</th>
  201. </tr>
  202. <tr height="5"></tr>
  203. <tr>
  204. <td>$option</td>
  205. </tr>
  206. <tr>
  207. <td>
  208. <table width=100%>
  209. <tr class=listheading>
  210. |;
  211. for (@column_index) { print "\n$column_header{$_}" }
  212. print qq|
  213. </tr>
  214. |;
  215. $ml = ($form->{category} eq 'A') ? -1 : 1;
  216. $form->{beginningbalance} *= $ml;
  217. $form->{fx_balance} *= $ml;
  218. if (! $form->{fx_transaction}) {
  219. $form->{beginningbalance} -= $form->{fx_balance};
  220. }
  221. $balance = $form->{beginningbalance};
  222. $i = 0;
  223. $j = 0;
  224. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  225. if (! $form->{report}) {
  226. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  227. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  228. print qq|
  229. <tr class=listrow$j>
  230. |;
  231. for (@column_index) { print "\n$column_data{$_}" }
  232. print qq|
  233. </tr>
  234. |;
  235. }
  236. foreach $ref (@{ $form->{PR} }) {
  237. $i++;
  238. if (! $form->{fx_transaction}) {
  239. next if $ref->{fx_transaction};
  240. }
  241. $checked = ($ref->{cleared}) ? "checked" : "";
  242. %temp = ();
  243. if (!$ref->{fx_transaction}) {
  244. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  245. }
  246. $column_data{name} = "<td>";
  247. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  248. $column_data{name} .= "</td>";
  249. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  250. <input type=hidden name="id_$i" value=$ref->{id}>|;
  251. $column_data{debit} = "<td>&nbsp;</td>";
  252. $column_data{credit} = "<td>&nbsp;</td>";
  253. $balance += $ref->{amount} * $ml;
  254. if ($ref->{amount} < 0) {
  255. $totaldebits += $ref->{amount} * -1;
  256. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  257. } else {
  258. $totalcredits += $ref->{amount};
  259. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  260. }
  261. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  262. if ($ref->{fx_transaction}) {
  263. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  264. $cleared += $ref->{amount} * $ml if $clearfx;
  265. } else {
  266. if ($form->{report}) {
  267. if ($ref->{cleared}) {
  268. $column_data{cleared} = qq|<td align=center>*</td>|;
  269. $clearfx = 1;
  270. } else {
  271. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  272. $clearfx = 0;
  273. }
  274. } else {
  275. if ($ref->{oldcleared}) {
  276. $cleared += $ref->{amount} * $ml;
  277. $clearfx = 1;
  278. $column_data{cleared} = qq|<td align=center>*</td>
  279. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  280. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  281. <input type=hidden name="source_$i" value="$ref->{source}">|;
  282. } else {
  283. $cleared += $ref->{amount} * $ml if $checked;
  284. $clearfx = ($checked) ? 1 : 0;
  285. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  286. <input type=hidden name="source_$i" value="$ref->{source}"></td>|;
  287. }
  288. }
  289. }
  290. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  291. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  292. $j++; $j %= 2;
  293. print qq|
  294. <tr class=listrow$j>
  295. |;
  296. for (@column_index) { print "\n$column_data{$_}" }
  297. print qq|
  298. </tr>
  299. |;
  300. }
  301. $form->{rowcount} = $i;
  302. # print totals
  303. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  304. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  305. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  306. print qq|
  307. <tr class=listtotal>
  308. |;
  309. for (@column_index) { print "\n$column_data{$_}" }
  310. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  311. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  312. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  313. print qq|
  314. </tr>
  315. </table>
  316. </td>
  317. </tr>
  318. |;
  319. if ($form->{report}) {
  320. print qq|
  321. </tr>
  322. </table>
  323. |;
  324. } else {
  325. print qq|
  326. <tr>
  327. <td>
  328. <table width=100%>
  329. <tr>
  330. <td align=right>
  331. <table>
  332. <tr>
  333. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  334. <td width=10%></td>
  335. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  336. </tr>
  337. <tr>
  338. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  339. <td width=10%></td>
  340. <td align=right><input name=null size=11 value=$difference></td>
  341. <input type=hidden name=difference value=$difference>
  342. </tr>
  343. </table>
  344. </td>
  345. </tr>
  346. </table>
  347. </td>
  348. </tr>
  349. <tr>
  350. <td><hr size=3 noshade></td>
  351. </tr>
  352. </table>
  353. |;
  354. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  355. print qq|
  356. <br>
  357. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  358. <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|">
  359. <input type=submit class=submit name=action value="|.$locale->text('Done').qq|">|;
  360. }
  361. if ($form->{menubar}) {
  362. require "$form->{path}/menu.pl";
  363. &menubar;
  364. }
  365. print qq|
  366. </form>
  367. </body>
  368. </html>
  369. |;
  370. }
  371. sub update {
  372. RC->payment_transactions(\%myconfig, \%$form);
  373. $i = 0;
  374. foreach $ref (@{ $form->{PR} }) {
  375. $i++;
  376. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  377. }
  378. &display_form;
  379. }
  380. sub select_all {
  381. RC->payment_transactions(\%myconfig, \%$form);
  382. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  383. &display_form;
  384. }
  385. sub done {
  386. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  387. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  388. RC->reconcile(\%myconfig, \%$form);
  389. $form->redirect;
  390. }