summaryrefslogtreecommitdiff
path: root/bin/mozilla/cp.pl
blob: 8848c9cb2e0856ae0309b84f9a89fb2fcc3ab103 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # See COPYRIGHT file for copyright information
  6. #======================================================================
  7. #
  8. # This file has NOT undergone whitespace cleanup.
  9. #
  10. #======================================================================
  11. #
  12. # Payment module
  13. #
  14. #======================================================================
  15. use LedgerSMB::CP;
  16. use LedgerSMB::OP;
  17. use LedgerSMB::IS;
  18. use LedgerSMB::IR;
  19. require "$form->{path}/arap.pl";
  20. 1;
  21. # end of main
  22. sub payment {
  23. if ($form->{type} eq 'receipt') {
  24. $form->{ARAP} = "AR";
  25. $form->{arap} = "ar";
  26. $form->{vc} = "customer";
  27. $form->{formname} = "receipt";
  28. }
  29. if ($form->{type} eq 'check') {
  30. $form->{ARAP} = "AP";
  31. $form->{arap} = "ap";
  32. $form->{vc} = "vendor";
  33. $form->{formname} = "check";
  34. }
  35. $form->{payment} = "payment";
  36. $form->{callback} = "$form->{script}?action=payment&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&all_vc=$form->{all_vc}&type=$form->{type}";
  37. # setup customer/vendor selection for open invoices
  38. if ($form->{all_vc}) {
  39. $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}, undef, $form->{datepaid});
  40. } else {
  41. CP->get_openvc(\%myconfig, \%$form);
  42. if ($myconfig{vclimit} > 0) {
  43. $form->{"all_$form->{vc}"} = $form->{name_list};
  44. }
  45. }
  46. $form->{"select$form->{vc}"} = "";
  47. if (@{ $form->{"all_$form->{vc}"} }) {
  48. $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
  49. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  50. }
  51. # departments
  52. if (@{ $form->{all_department} }) {
  53. $form->{selectdepartment} = "<option>\n";
  54. $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department};
  55. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  56. }
  57. if (@{ $form->{all_language} }) {
  58. $form->{selectlanguage} = "<option>\n";
  59. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  60. }
  61. CP->paymentaccounts(\%myconfig, \%$form);
  62. $form->{selectaccount} = "";
  63. $form->{"select$form->{ARAP}"} = "";
  64. for (@{ $form->{PR}{"$form->{ARAP}_paid"} }) { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
  65. for (@{ $form->{PR}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
  66. # currencies
  67. @curr = split /:/, $form->{currencies};
  68. $form->{defaultcurrency} = $curr[0];
  69. chomp $form->{defaultcurrency};
  70. $form->{selectcurrency} = "";
  71. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  72. $form->{currency} = $form->{defaultcurrency};
  73. $form->{oldcurrency} = $form->{currency};
  74. if ($form->{currency} ne $form->{defaultcurrency}) {
  75. $form->{forex} = $form->{exchangerate} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, ($form->{vc} eq 'customer') ? "buy" : "sell");
  76. }
  77. $form->{olddatepaid} = $form->{datepaid};
  78. $form->{media} = $myconfig{printer};
  79. $form->{format} = "pdf" unless $myconfig{printer};
  80. &payment_header;
  81. &payment_footer;
  82. }
  83. sub payments {
  84. if ($form->{type} eq 'receipt') {
  85. $form->{ARAP} = "AR";
  86. $form->{arap} = "ar";
  87. $form->{vc} = "customer";
  88. $form->{formname} = "receipt";
  89. }
  90. if ($form->{type} eq 'check') {
  91. $form->{ARAP} = "AP";
  92. $form->{arap} = "ap";
  93. $form->{vc} = "vendor";
  94. $form->{formname} = "check";
  95. }
  96. $form->{payment} = "payments";
  97. $form->{callback} = "$form->{script}?action=$form->{action}";
  98. for (qw(path login sessionid type)) { $form->{callback} .= "&$_=$form->{$_}" }
  99. CP->paymentaccounts(\%myconfig, \%$form);
  100. if (@{ $form->{all_language} }) {
  101. $form->{selectlanguage} = "<option>\n";
  102. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  103. }
  104. # departments
  105. if (@{ $form->{all_department} }) {
  106. $form->{selectdepartment} = "<option>\n";
  107. $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department};
  108. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  109. }
  110. $form->{selectaccount} = "";
  111. $form->{"select$form->{ARAP}"} = "";
  112. for (@{ $form->{PR}{"$form->{ARAP}_paid"} }) { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
  113. for (@{ $form->{PR}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
  114. # currencies
  115. @curr = split /:/, $form->{currencies};
  116. $form->{defaultcurrency} = $curr[0];
  117. chomp $form->{defaultcurrency};
  118. $form->{selectcurrency} = "";
  119. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  120. $form->{oldcurrency} = $form->{currency} = $form->{defaultcurrency};
  121. $form->{oldduedateto} = $form->{datepaid};
  122. $form->{media} = $myconfig{printer};
  123. $form->{format} = "pdf" unless $myconfig{printer};
  124. &payments_header;
  125. &invoices_due;
  126. &payments_footer;
  127. }
  128. sub payments_header {
  129. if ($form->{type} eq 'receipt') {
  130. $form->{title} = $locale->text('Receipts');
  131. }
  132. if ($form->{type} eq 'check') {
  133. $form->{title} = $locale->text('Payments');
  134. }
  135. for ("department") {
  136. $form->{"select$_"} = $form->unescape($form->{"select$_"});
  137. $form->{"select$_"} =~ s/ selected//;
  138. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  139. }
  140. for ("account", "currency", "$form->{ARAP}") {
  141. $form->{"select$_"} =~ s/ selected//;
  142. $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
  143. }
  144. if ($form->{defaultcurrency}) {
  145. $exchangerate = qq|
  146. <tr>
  147. <th align=right nowrap>|.$locale->text('Currency').qq|</th>
  148. <td><select name=currency>$form->{selectcurrency}</select></td>
  149. <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
  150. <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
  151. </tr>
  152. |;
  153. }
  154. if ($form->{currency} ne $form->{defaultcurrency}) {
  155. $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
  156. if ($form->{forex}) {
  157. $exchangerate .= qq|
  158. <tr>
  159. <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
  160. <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
  161. </tr>
  162. |;
  163. } else {
  164. $exchangerate .= qq|
  165. <tr>
  166. <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
  167. <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
  168. </tr>
  169. |;
  170. }
  171. }
  172. $department = qq|
  173. <tr>
  174. <th align="right" nowrap>|.$locale->text('Department').qq|</th>
  175. <td><select name=department>$form->{selectdepartment}</select>
  176. <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
  177. </td>
  178. </tr>
  179. | if $form->{selectdepartment};
  180. $form->header;
  181. print qq|
  182. <body>
  183. <form method=post action=$form->{script}>
  184. |;
  185. $form->hide_form(qw(defaultcurrency closedto vc type formname arap ARAP title oldduedatefrom oldduedateto payment olddepartment));
  186. print qq|
  187. <table width=100%>
  188. <tr>
  189. <th class=listtop>$form->{title}</th>
  190. </tr>
  191. <tr height="5"></tr>
  192. <tr>
  193. <td>
  194. <table width=100%>
  195. <tr valign=top>
  196. <td>
  197. <table>
  198. <tr>
  199. <th align=right>|.$locale->text('Due Date').qq|&nbsp;|.$locale->text('From').qq|</th>
  200. <td><input name=duedatefrom value="$form->{duedatefrom}" title="$myconfig{dateformat}" size=11></td>
  201. <th align=right>|.$locale->text('To').qq|</th>
  202. <td><input name=duedateto value="$form->{duedateto}" title="$myconfig{dateformat}" size=11></td>
  203. </tr>
  204. </table>
  205. </td>
  206. </td>
  207. <td align=right>
  208. <table>
  209. $department
  210. <tr>
  211. <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th>
  212. <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
  213. </td>
  214. <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
  215. </tr>
  216. <tr>
  217. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  218. <td colspan=3><select name=account>$form->{selectaccount}</select>
  219. <input type=hidden name=selectaccount value="$form->{selectaccount}">
  220. </td>
  221. </tr>
  222. <tr>
  223. <th align=right nowrap>|.$locale->text('Date').qq|</th>
  224. <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
  225. </tr>
  226. $exchangerate
  227. </table>
  228. </td>
  229. </tr>
  230. </table>
  231. </td>
  232. </tr>
  233. |;
  234. }
  235. sub invoices_due {
  236. @column_index = qw(name invnumber transdate amount due checked paid memo source);
  237. push @column_index, "language" if $form->{selectlanguage};
  238. $colspan = $#column_index + 1;
  239. $invoice = $locale->text('Invoices');
  240. $vclabel = ucfirst $form->{vc};
  241. $vclabel = $locale->text($vclabel);
  242. print qq|
  243. <input type=hidden name=column_index value="id @column_index">
  244. <tr>
  245. <td>
  246. <table width=100%>
  247. <tr>
  248. <th class=listheading colspan=$colspan>$invoice</th>
  249. </tr>
  250. |;
  251. $column_data{name} = qq|<th nowrap>$vclabel</th>|;
  252. $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";
  253. $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";
  254. $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
  255. $column_data{due} = qq|<th nowrap>|.$locale->text('Amount Due')."</th>";
  256. $column_data{paid} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
  257. $column_data{checked} = qq|<th nowrap>|.$locale->text('Select')."</th>";
  258. $column_data{memo} = qq|<th nowrap>|.$locale->text('Memo')."</th>";
  259. $column_data{source} = qq|<th nowrap>|.$locale->text('Source')."</th>";
  260. $column_data{language} = qq|<th nowrap>|.$locale->text('Language')."</th>";
  261. print qq|
  262. <tr>
  263. |;
  264. for (@column_index) { print "$column_data{$_}\n" }
  265. print qq|
  266. </tr>
  267. |;
  268. $form->{selectlanguage} = $form->unescape($form->{selectlanguage});
  269. for $i (1 .. $form->{rowcount}) {
  270. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  271. $totalamount += $form->{"amount_$i"};
  272. $totaldue += $form->{"due_$i"};
  273. $totalpaid += $form->{"paid_$i"};
  274. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  275. $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
  276. <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
  277. <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
  278. $column_data{transdate} = qq|<td>$form->{"transdate_$i"}</td>
  279. <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
  280. $column_data{amount} = qq|<td align=right>$form->{"amount_$i"}</td>
  281. <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
  282. $column_data{due} = qq|<td align=right>$form->{"due_$i"}</td>
  283. <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
  284. $column_data{paid} = qq|<td align=right><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
  285. if ($same_id eq $form->{"$form->{vc}_id_$i"}) {
  286. for (qw(name memo source language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
  287. } else {
  288. $column_data{name} = qq|<td>$form->{"name_$i"}</td>|;
  289. $column_data{memo} = qq|<td align=right><input name="memo_$i" size=10 value="$form->{"memo_$i"}"></td>|;
  290. $column_data{source} = qq|<td align=right><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  291. if ($form->{selectlanguage}) {
  292. $selectlanguage = $form->{selectlanguage};
  293. $selectlanguage =~ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
  294. $column_data{language} = qq|<td><select name="language_code_$i">$selectlanguage</select></td>|;
  295. }
  296. }
  297. $column_data{name} .= qq|
  298. <input type=hidden name="name_$i" value="$form->{"name_$i"}">
  299. <input type=hidden name="$form->{vc}_id_$i" value="$form->{"$form->{vc}_id_$i"}">|;
  300. $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
  301. $column_data{checked} = qq|<td align=center><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
  302. $j++; $j %= 2;
  303. print qq|
  304. <tr class=listrow$j>
  305. |;
  306. for (@column_index) { print "$column_data{$_}\n" }
  307. print qq|
  308. </tr>
  309. |;
  310. $same_id = $form->{"$form->{vc}_id_$i"};
  311. }
  312. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  313. $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;").qq|</th>|;
  314. $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;").qq|</th>|;
  315. $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;").qq|</th>|;
  316. print qq|
  317. <tr class=listtotal>
  318. |;
  319. for (@column_index) { print "$column_data{$_}\n" }
  320. print qq|
  321. </tr>
  322. </table>
  323. </td>
  324. </tr>
  325. <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">
  326. |;
  327. }
  328. sub payments_footer {
  329. $form->{DF}{$form->{format}} = "selected";
  330. $transdate = $form->datetonum(\%myconfig, $form->{datepaid});
  331. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  332. if ($latex) {
  333. $media = qq|<select name=media>
  334. <option value=screen>|.$locale->text('Screen');
  335. if (%printer) {
  336. for (sort keys %printer) { $media .= qq|
  337. <option value="$_">$_| }
  338. }
  339. $media .= qq|</select>|;
  340. $format = qq|<select name=format>
  341. <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
  342. <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|</select>|;
  343. }
  344. print qq|
  345. <tr>
  346. <td><hr size=3 noshade></td>
  347. </tr>
  348. </table>
  349. |;
  350. # type=submit $locale->text('Update')
  351. # type=submit $locale->text('Post')
  352. # type=submit $locale->text('Print')
  353. # type=submit $locale->text('Select all')
  354. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  355. 'Select all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
  356. 'Print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
  357. 'Post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
  358. );
  359. if (! $latex) {
  360. delete $button{'Print'};
  361. }
  362. if ($transdate <= $closedto) {
  363. for ('Post', 'Print') { delete $button{$_} }
  364. $media = $format = "";
  365. }
  366. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  367. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  368. print qq|
  369. $format
  370. $media
  371. |;
  372. $form->hide_form(qw(callback rowcount path login sessionid));
  373. if ($form->{menubar}) {
  374. require "$form->{path}/menu.pl";
  375. &menubar;
  376. }
  377. print qq|
  378. </form>
  379. </body>
  380. </html>
  381. |;
  382. }
  383. sub select_all {
  384. for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
  385. &{"update_$form->{payment}"}
  386. }
  387. sub update {
  388. my ($new_name_selected) = @_;
  389. &{"update_$form->{payment}"};
  390. }
  391. sub update_payments {
  392. if ($form->{ARAP} eq 'AR') {
  393. $buysell = "buy";
  394. } else {
  395. $buysell = "sell";
  396. }
  397. if (($form->{oldduedatefrom} ne $form->{duedatefrom}) || ($form->{oldduedateto} ne $form->{duedateto}) || ($form->{department} ne $form->{olddepartment})) {
  398. CP->get_openinvoices(\%myconfig, \%$form);
  399. $form->{redo} = 1;
  400. }
  401. if ($form->{currency} ne $form->{oldcurrency}) {
  402. $form->{oldcurrency} = $form->{currency};
  403. if (!$form->{redo}) {
  404. CP->get_openinvoices(\%myconfig, \%$form);
  405. $form->{redo} = 1;
  406. }
  407. }
  408. for (qw(duedatefrom duedateto department)) { $form->{"old$_"} = $form->{$_} }
  409. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
  410. if ($form->{redo}) {
  411. $form->{rowcount} = 0;
  412. $i = 0;
  413. foreach $ref (@{ $form->{PR} }) {
  414. $i++;
  415. for (qw(id name invnumber transdate)) { $form->{"${_}_$i"} = $ref->{$_} }
  416. $form->{"$form->{vc}_id_$i"} = $ref->{"$form->{vc}_id"};
  417. $ref->{exchangerate} = 1 unless $ref->{exchangerate};
  418. $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
  419. $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
  420. $form->{"checked_$i"} = "";
  421. $form->{"paid_$i"} = "";
  422. # need to format
  423. for (qw(amount due)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  424. }
  425. $form->{rowcount} = $i;
  426. }
  427. $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
  428. # recalculate
  429. $amount = 0;
  430. for $i (1 .. $form->{rowcount}) {
  431. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  432. if ($form->{"checked_$i"}) {
  433. # calculate paid_$i
  434. if (!$form->{"paid_$i"}) {
  435. $form->{"paid_$i"} = $form->{"due_$i"};
  436. }
  437. $amount += $form->{"paid_$i"};
  438. $form->{redo} = 1;
  439. } else {
  440. $form->{"paid_$i"} = "";
  441. }
  442. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  443. }
  444. $form->{amount} += ($amount - $form->{oldamount}) if $form->{redo};
  445. &payments_header;
  446. &invoices_due;
  447. &payments_footer;
  448. }
  449. sub update_payment {
  450. if ($form->{vc} eq 'customer') {
  451. $buysell = "buy";
  452. } else {
  453. $buysell = "sell";
  454. }
  455. $department = $form->{department};
  456. # get customer/vendor
  457. &check_openvc;
  458. $form->{department} = $department;
  459. if ($form->{datepaid} ne $form->{olddatepaid}) {
  460. $form->{olddatepaid} = $form->{datepaid};
  461. $form->{oldall_vc} = !$form->{oldall_vc} if $form->{all_vc};
  462. }
  463. if ($form->{department} ne $form->{olddepartment}) {
  464. $form->{olddepartment} = $form->{department};
  465. $form->{redo} = 1;
  466. }
  467. # if we switched to all_vc
  468. if ($form->{all_vc} ne $form->{oldall_vc}) {
  469. if ($form->{"select$form->{vc}"}) {
  470. $form->{redo} = ($form->{"old$name"} ne $form->{$name});
  471. } else {
  472. $form->{redo} = ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|);
  473. }
  474. $form->{"select$form->{vc}"} = "";
  475. if ($form->{all_vc}) {
  476. $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}, undef, $form->{datepaid});
  477. if (@{ $form->{"all_$form->{vc}"} }) {
  478. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  479. }
  480. } else {
  481. if (($myconfig{vclimit} * 1) > 0) {
  482. $form->{$form->{vc}} = "";
  483. }
  484. CP->get_openvc(\%myconfig, \%$form);
  485. if (($myconfig{vclimit} * 1) > 0) {
  486. $form->{"all_$form->{vc}"} = $form->{name_list};
  487. }
  488. if (@{ $form->{"all_$form->{vc}"} }) {
  489. $newvc = qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
  490. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  491. # if the name is not the same
  492. if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
  493. $form->{$form->{vc}} = $newvc;
  494. &check_openvc;
  495. }
  496. }
  497. }
  498. if (@{ $form->{all_language} }) {
  499. $form->{selectlanguage} = "<option>\n";
  500. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  501. }
  502. }
  503. if ($new_name_selected || $form->{redo}) {
  504. CP->get_openinvoices(\%myconfig, \%$form);
  505. ($newvc) = split /--/, $form->{$form->{vc}};
  506. $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;;
  507. $form->{redo} = 1;
  508. }
  509. if ($form->{currency} ne $form->{oldcurrency}) {
  510. $form->{oldcurrency} = $form->{currency};
  511. if (!$form->{redo}) {
  512. CP->get_openinvoices(\%myconfig, \%$form);
  513. $form->{redo} = 1;
  514. }
  515. }
  516. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
  517. if ($form->{redo}) {
  518. $form->{rowcount} = 0;
  519. $i = 0;
  520. foreach $ref (@{ $form->{PR} }) {
  521. $i++;
  522. $form->{"id_$i"} = $ref->{id};
  523. $form->{"invnumber_$i"} = $ref->{invnumber};
  524. $form->{"transdate_$i"} = $ref->{transdate};
  525. $ref->{exchangerate} = 1 unless $ref->{exchangerate};
  526. $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
  527. $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
  528. $form->{"checked_$i"} = "";
  529. $form->{"paid_$i"} = "";
  530. # need to format
  531. for (qw(amount due)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  532. }
  533. $form->{rowcount} = $i;
  534. }
  535. $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
  536. # recalculate
  537. $amount = 0;
  538. for $i (1 .. $form->{rowcount}) {
  539. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  540. if ($form->{"checked_$i"}) {
  541. # calculate paid_$i
  542. if (!$form->{"paid_$i"}) {
  543. $form->{"paid_$i"} = $form->{"due_$i"};
  544. }
  545. $amount += $form->{"paid_$i"};
  546. $form->{redo} = 1;
  547. } else {
  548. $form->{"paid_$i"} = "";
  549. }
  550. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  551. }
  552. $form->{amount} += ($amount - $form->{oldamount}) if $form->{redo};
  553. &payment_header;
  554. &list_invoices;
  555. &payment_footer;
  556. }
  557. sub payment_header {
  558. $vclabel = ucfirst $form->{vc};
  559. $vclabel = $locale->text($vclabel);
  560. if ($form->{type} eq 'receipt') {
  561. $form->{title} = $locale->text('Receipt');
  562. }
  563. if ($form->{type} eq 'check') {
  564. $form->{title} = $locale->text('Payment');
  565. }
  566. # $locale->text('Customer')
  567. # $locale->text('Vendor')
  568. if ($form->{$form->{vc}} eq "") {
  569. for (qw(address1 address2 city zipcode state country)) { $form->{$_} = "" }
  570. }
  571. for ("$form->{vc}", "department") {
  572. $form->{"select$_"} = $form->unescape($form->{"select$_"});
  573. $form->{"select$_"} =~ s/ selected//;
  574. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  575. }
  576. for ("account", "currency", "$form->{ARAP}") {
  577. $form->{"select$_"} =~ s/ selected//;
  578. $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
  579. }
  580. if ($form->{defaultcurrency}) {
  581. $exchangerate = qq|
  582. <tr>
  583. <th align=right nowrap>|.$locale->text('Currency').qq|</th>
  584. <td><select name=currency>$form->{selectcurrency}</select></td>
  585. <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
  586. <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
  587. </tr>
  588. |;
  589. }
  590. if ($form->{currency} ne $form->{defaultcurrency}) {
  591. $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
  592. if ($form->{forex}) {
  593. $exchangerate .= qq|
  594. <tr>
  595. <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
  596. <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
  597. </tr>
  598. |;
  599. } else {
  600. $exchangerate .= qq|
  601. <tr>
  602. <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
  603. <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
  604. </tr>
  605. |;
  606. }
  607. }
  608. $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>| : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
  609. if ($form->{all_vc}) {
  610. $allvc = "checked";
  611. } else {
  612. $allvc = "";
  613. }
  614. # $locale->text('AR')
  615. # $locale->text('AP')
  616. $department = qq|
  617. <tr>
  618. <th align="right" nowrap>|.$locale->text('Department').qq|</th>
  619. <td><select name=department>$form->{selectdepartment}</select>
  620. <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
  621. </td>
  622. </tr>
  623. | if $form->{selectdepartment};
  624. $form->header;
  625. print qq|
  626. <body>
  627. <form method=post action=$form->{script}>
  628. |;
  629. $form->hide_form(qw(defaultcurrency closedto vc type ARAP arap title formname payment olddepartment));
  630. print qq|
  631. <table width=100%>
  632. <tr>
  633. <th class=listtop>$form->{title}</th>
  634. </tr>
  635. <tr height="5"></tr>
  636. <tr>
  637. <td>
  638. <table width=100%>
  639. <tr valign=top>
  640. <td>
  641. <table>
  642. <tr>
  643. <td align=right>
  644. <input name=all_vc type=checkbox class=checkbox value=Y $allvc>
  645. <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
  646. <th align=left>|.$locale->text('All').qq|</th>
  647. </tr>
  648. <tr>
  649. <th align=right>$vclabel</th>
  650. <td>$vc</td>
  651. <input type=hidden name="select$form->{vc}" value="|.$form->escape($form->{"select$form->{vc}"},1).qq|">
  652. <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
  653. <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
  654. </tr>
  655. <tr valign=top>
  656. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  657. <td colspan=2>
  658. <table>
  659. <tr>
  660. <td>$form->{address1}</td>
  661. </tr>
  662. <tr>
  663. <td>$form->{address2}</td>
  664. </tr>
  665. <td>$form->{city}</td>
  666. </tr>
  667. </tr>
  668. <td>$form->{state}</td>
  669. </tr>
  670. </tr>
  671. <td>$form->{zipcode}</td>
  672. </tr>
  673. <tr>
  674. <td>$form->{country}</td>
  675. </tr>
  676. </table>
  677. </td>
  678. <input type=hidden name=address1 value="$form->{address1}">
  679. <input type=hidden name=address2 value="$form->{address2}">
  680. <input type=hidden name=city value="$form->{city}">
  681. <input type=hidden name=state value="$form->{state}">
  682. <input type=hidden name=zipcode value="$form->{zipcode}">
  683. <input type=hidden name=country value="$form->{country}">
  684. </tr>
  685. <tr>
  686. <th align=right>|.$locale->text('Memo').qq|</th>
  687. <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
  688. </tr>
  689. </table>
  690. </td>
  691. <td align=right>
  692. <table>
  693. $department
  694. <tr>
  695. <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th>
  696. <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
  697. </td>
  698. <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
  699. </tr>
  700. <tr>
  701. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  702. <td colspan=3><select name=account>$form->{selectaccount}</select>
  703. <input type=hidden name=selectaccount value="$form->{selectaccount}">
  704. </td>
  705. </tr>
  706. <tr>
  707. <th align=right nowrap>|.$locale->text('Date').qq|</th>
  708. <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
  709. <input type=hidden name=olddatepaid value=$form->{olddatepaid}>
  710. </tr>
  711. $exchangerate
  712. <tr>
  713. <th align=right nowrap>|.$locale->text('Source').qq|</th>
  714. <td colspan=3><input name=source value="$form->{source}" size=10></td>
  715. </tr>
  716. <tr>
  717. <th align=right nowrap>|.$locale->text('Amount').qq|</th>
  718. <td colspan=3><input name=amount size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, 2).qq|></td>
  719. <input type=hidden name=oldamount value=$form->{amount}>
  720. </tr>
  721. </table>
  722. </td>
  723. </tr>
  724. </table>
  725. </td>
  726. </tr>
  727. |;
  728. }
  729. sub list_invoices {
  730. @column_index = qw(invnumber transdate amount due checked paid);
  731. $colspan = $#column_index + 1;
  732. $invoice = $locale->text('Invoices');
  733. print qq|
  734. <input type=hidden name=column_index value="id @column_index">
  735. <tr>
  736. <td>
  737. <table width=100%>
  738. <tr>
  739. <th class=listheading colspan=$colspan>$invoice</th>
  740. </tr>
  741. |;
  742. $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";
  743. $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";
  744. $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
  745. $column_data{due} = qq|<th nowrap>|.$locale->text('Amount Due')."</th>";
  746. $column_data{paid} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
  747. $column_data{checked} = qq|<th nowrap>|.$locale->text('Select')."</th>";
  748. print qq|
  749. <tr>
  750. |;
  751. for (@column_index) { print "$column_data{$_}\n" }
  752. print qq|
  753. </tr>
  754. |;
  755. for $i (1 .. $form->{rowcount}) {
  756. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  757. $totalamount += $form->{"amount_$i"};
  758. $totaldue += $form->{"due_$i"};
  759. $totalpaid += $form->{"paid_$i"};
  760. for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  761. $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
  762. <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
  763. <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
  764. $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
  765. <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
  766. $column_data{amount} = qq|<td align=right width=15%>$form->{"amount_$i"}</td>
  767. <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
  768. $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
  769. <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
  770. $column_data{paid} = qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
  771. $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
  772. $column_data{checked} = qq|<td align=center width=10%><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
  773. $j++; $j %= 2;
  774. print qq|
  775. <tr class=listrow$j>
  776. |;
  777. for (@column_index) { print "$column_data{$_}\n" }
  778. print qq|
  779. </tr>
  780. |;
  781. }
  782. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  783. $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;").qq|</th>|;
  784. $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;").qq|</th>|;
  785. $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;").qq|</th>|;
  786. print qq|
  787. <tr class=listtotal>
  788. |;
  789. for (@column_index) { print "$column_data{$_}\n" }
  790. print qq|
  791. </tr>
  792. </table>
  793. </td>
  794. </tr>
  795. |;
  796. }
  797. sub payment_footer {
  798. $form->{DF}{$form->{format}} = "selected";
  799. $transdate = $form->datetonum(\%myconfig, $form->{datepaid});
  800. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  801. if ($latex) {
  802. if ($form->{selectlanguage}) {
  803. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  804. $form->{"selectlanguage"} =~ s/ selected//;
  805. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  806. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  807. <input type=hidden name=selectlanguage value="|.
  808. $form->escape($form->{selectlanguage},1).qq|">|;
  809. }
  810. $media = qq|<select name=media>
  811. <option value=screen>|.$locale->text('Screen');
  812. if (%printer) {
  813. for (sort keys %printer) { $media .= qq|
  814. <option value="$_">$_| }
  815. }
  816. $media .= qq|</select>|;
  817. $format = qq|<select name=format>
  818. <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
  819. <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|</select>|;
  820. }
  821. print qq|
  822. <tr>
  823. <td><hr size=3 noshade></td>
  824. </tr>
  825. </table>
  826. |;
  827. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  828. 'Select all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
  829. 'Print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
  830. 'Post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
  831. );
  832. if (! $latex) {
  833. delete $button{'Print'};
  834. }
  835. if ($transdate <= $closedto) {
  836. for ('Post', 'Print') { delete $button{$_} }
  837. $media = $format = "";
  838. }
  839. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  840. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  841. print qq|
  842. $lang
  843. $format
  844. $media
  845. |;
  846. $form->hide_form(qw(callback rowcount path login sessionid));
  847. if ($form->{menubar}) {
  848. require "$form->{path}/menu.pl";
  849. &menubar;
  850. }
  851. print qq|
  852. </form>
  853. </body>
  854. </html>
  855. |;
  856. }
  857. sub post { &{"post_$form->{payment}"} }
  858. sub post_payments {
  859. if ($form->{currency} ne $form->{defaultcurrency}) {
  860. $form->error($locale->text('Exchange rate missing!')) unless $form->{exchangerate};
  861. }
  862. if (CP->post_payments(\%myconfig, \%$form)) {
  863. $form->redirect($locale->text('Payments posted!'));
  864. } else {
  865. $form->error($locale->text('Posting failed!'));
  866. }
  867. }
  868. sub post_payment {
  869. &check_form;
  870. if ($form->{currency} ne $form->{defaultcurrency}) {
  871. $form->error($locale->text('Exchange rate missing!')) unless $form->{exchangerate};
  872. }
  873. $msg1 = "$form->{title} posted!";
  874. $msg2 = "Cannot post $form->{title}!";
  875. # $locale->text('Payment posted!')
  876. # $locale->text('Receipt posted!')
  877. # $locale->text('Cannot post Payment!')
  878. # $locale->text('Cannot post Receipt!')
  879. $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
  880. $source = $form->{source};
  881. $source =~ s/(\d+)/$1 + 1/e;
  882. if ($form->{callback}) {
  883. $form->{callback} .= "&source=$source";
  884. }
  885. if (CP->post_payment(\%myconfig, \%$form)) {
  886. $form->redirect($locale->text($msg1));
  887. } else {
  888. $form->error($locale->text($msg2));
  889. }
  890. }
  891. sub print {
  892. &{ "print_$form->{payment}" };
  893. &update if $form->{media} ne 'screen';
  894. }
  895. sub print_payments {
  896. $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
  897. $SIG{INT} = 'IGNORE';
  898. for (qw(company address)) { $form->{$_} = $myconfig{$_} }
  899. $form->{address} =~ s/\\n/\n/g;
  900. %oldform = ();
  901. for (keys %$form) { $oldform{$_} = $form->{$_} };
  902. @a = qw(name company address text_amount text_decimal address1 address2 city state zipcode country memo);
  903. for (@a) { $temp{$_} = $form->{$_} }
  904. $form->format_string(@a);
  905. $ok = 0;
  906. $j = 0;
  907. $temp{rowcount} = $form->{rowcount};
  908. for $i (1 .. $temp{rowcount}) {
  909. if ($form->{"$form->{vc}_id_$i"} ne $form->{"$form->{vc}_id"}) {
  910. $form->{rowcount} = $j;
  911. for (1 .. $j) { $form->{"id_$_"} = $temp{"id_$_"} }
  912. &print_form if $ok;
  913. $ok = 0;
  914. $j = 0;
  915. $form->{amount} = 0;
  916. for (qw(invnumber invdate due paid)) { @{ $form->{$_} } = () }
  917. for (qw(language_code source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  918. }
  919. if ($form->{"checked_$i"}) {
  920. $j++;
  921. $ok = 1;
  922. $temp{"id_$j"} = $form->{"id_$i"};
  923. $form->{"invdate_$i"} = $form->{"transdate_$i"};
  924. for (qw(invnumber invdate due paid)) { push @{ $form->{$_} }, $form->{"${_}_$i"} }
  925. $form->{amount} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
  926. $form->{"$form->{vc}_id"} = $form->{"$form->{vc}_id_$i"};
  927. }
  928. }
  929. $form->{rowcount} = $j;
  930. for (1 .. $j) { $form->{"id_$_"} = $temp{"id_$_"} }
  931. &print_form if $ok;
  932. for (keys %oldform) { $form->{$_} = $oldform{$_} }
  933. }
  934. sub print_form {
  935. $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
  936. $c->init;
  937. ($whole, $form->{decimal}) = split /\./, $form->{amount};
  938. $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
  939. $form->{decimal} .= "00";
  940. $form->{decimal} = substr($form->{decimal}, 0, 2);
  941. $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
  942. $form->{text_amount} = $c->num2text($whole);
  943. $form->{integer_amount} = $form->format_amount($myconfig, $whole);
  944. $datepaid = $form->datetonum(\%myconfig, $form->{datepaid});
  945. ($form->{yyyy}, $form->{mm}, $form->{dd}) = $datepaid =~ /(....)(..)(..)/;
  946. &{ "$form->{vc}_details" };
  947. $form->{templates} = "$myconfig{templates}";
  948. $form->{IN} = "$form->{formname}.tex";
  949. if ($form->{media} ne 'screen') {
  950. $form->{OUT} = "| $printer{$form->{media}}";
  951. }
  952. $form->parse_template(\%myconfig, $userspath);
  953. }
  954. sub print_payment {
  955. &check_form;
  956. for (qw(company address)) { $form->{$_} = $myconfig{$_} }
  957. $form->{address} =~ s/\\n/\n/g;
  958. @a = qw(name company address text_amount text_decimal address1 address2 city state zipcode country memo);
  959. %temp = ();
  960. for (@a) { $temp{$_} = $form->{$_} }
  961. $form->format_string(@a);
  962. &print_form;
  963. for (keys %temp) { $form->{$_} = $temp{$_} }
  964. }
  965. sub customer_details { IS->customer_details(\%myconfig, \%$form) };
  966. sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
  967. sub check_form {
  968. &check_openvc;
  969. if ($form->{currency} ne $form->{oldcurrency}) {
  970. &update;
  971. exit;
  972. }
  973. $form->error($locale->text('Date missing!')) unless $form->{datepaid};
  974. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  975. $datepaid = $form->datetonum(\%myconfig, $form->{datepaid});
  976. $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
  977. # this is just to format the year
  978. $form->{datepaid} = $locale->date(\%myconfig, $form->{datepaid});
  979. $amount = $form->parse_amount(\%myconfig, $form->{amount});
  980. $form->{amount} = $amount;
  981. for $i (1 .. $form->{rowcount}) {
  982. if ($form->{"paid_$i"}) {
  983. $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
  984. push(@{ $form->{paid} }, $form->{"paid_$i"});
  985. push(@{ $form->{due} }, $form->{"due_$i"});
  986. push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
  987. push(@{ $form->{invdate} }, $form->{"transdate_$i"});
  988. }
  989. }
  990. if ($form->round_amount($amount, 2) != 0) {
  991. push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
  992. push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
  993. push(@{ $form->{invnumber} }, ($form->{ARAP} eq 'AR') ? $locale->text('Deposit') : $locale->text('Prepayment'));
  994. push(@{ $form->{invdate} }, $form->{datepaid});
  995. }
  996. }
  997. sub check_openvc {
  998. $name = $form->{vc};
  999. ($new_name, $new_id) = split /--/, $form->{$name};
  1000. if ($form->{all_vc}) {
  1001. if ($form->{"select$name"}) {
  1002. $ok = ($form->{"old$name"} ne $form->{$name});
  1003. } else {
  1004. $ok = ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|);
  1005. }
  1006. if ($ok) {
  1007. $form->{redo} = 1;
  1008. if ($form->{"select$name"}) {
  1009. $form->{"${name}_id"} = $new_id;
  1010. AA->get_name(\%myconfig, \%$form);
  1011. $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
  1012. } else {
  1013. &check_name($form->{vc});
  1014. }
  1015. }
  1016. } else {
  1017. # if we use a selection
  1018. if ($form->{"select$name"}) {
  1019. if ($form->{"old$name"} ne $form->{$name}) {
  1020. $form->{"${name}_id"} = $new_id;
  1021. AA->get_name(\%myconfig, \%$form);
  1022. $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
  1023. $form->{redo} = 1;
  1024. }
  1025. } else {
  1026. # check name, combine name and id
  1027. if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
  1028. # return one name or a list of names in $form->{name_list}
  1029. if (($rv = CP->get_openvc(\%myconfig, \%$form)) > 1) {
  1030. $form->{redo} = 1;
  1031. &select_name($name);
  1032. exit;
  1033. }
  1034. if ($rv == 1) {
  1035. # we got one name
  1036. $form->{"${name}_id"} = $form->{name_list}[0]->{id};
  1037. $form->{$name} = $form->{name_list}[0]->{name};
  1038. $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
  1039. AA->get_name(\%myconfig, \%$form);
  1040. } else {
  1041. # nothing open
  1042. $form->error($locale->text('Nothing open!'));
  1043. }
  1044. $form->{redo} = 1;
  1045. }
  1046. }
  1047. }
  1048. }