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