summaryrefslogtreecommitdiff
path: root/bin/mozilla/arap.pl
blob: 3e8890f30d59f321dd9d4a569aaf091777f6a8c0 (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. # This program is free software; you can redistribute it and/or modify
  22. # it under the terms of the GNU General Public License as published by
  23. # the Free Software Foundation; either version 2 of the License, or
  24. # (at your option) any later version.
  25. #
  26. # This program is distributed in the hope that it will be useful,
  27. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. # GNU General Public License for more details.
  30. # You should have received a copy of the GNU General Public License
  31. # along with this program; if not, write to the Free Software
  32. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. #======================================================================
  34. #
  35. # common routines for gl, ar, ap, is, ir, oe
  36. #
  37. use LedgerSMB::AA;
  38. # any custom scripts for this one
  39. if (-f "$form->{path}/custom_arap.pl") {
  40. eval { require "$form->{path}/custom_arap.pl"; };
  41. }
  42. if (-f "$form->{path}/$form->{login}_arap.pl") {
  43. eval { require "$form->{path}/$form->{login}_arap.pl"; };
  44. }
  45. 1;
  46. # end of main
  47. sub check_name {
  48. my ($name) = @_;
  49. my ($new_name, $new_id) = split /--/, $form->{$name};
  50. my $rv = 0;
  51. # if we use a selection
  52. if ($form->{"select$name"}) {
  53. if ($form->{"old$name"} ne $form->{$name}) {
  54. # this is needed for is, ir and oe
  55. for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} }
  56. # for credit calculations
  57. $form->{oldinvtotal} = 0;
  58. $form->{oldtotalpaid} = 0;
  59. $form->{calctax} = 1;
  60. $form->{"${name}_id"} = $new_id;
  61. AA->get_name(\%myconfig, \%$form);
  62. $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
  63. $form->{currency} =~ s/ //g;
  64. # put employee together if there is a new employee_id
  65. $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
  66. $rv = 1;
  67. }
  68. } else {
  69. # check name, combine name and id
  70. if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
  71. # this is needed for is, ir and oe
  72. for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} }
  73. # for credit calculations
  74. $form->{oldinvtotal} = 0;
  75. $form->{oldtotalpaid} = 0;
  76. $form->{calctax} = 1;
  77. # return one name or a list of names in $form->{name_list}
  78. if (($rv = $form->get_name(\%myconfig, $name, $form->{transdate})) > 1) {
  79. &select_name($name);
  80. exit;
  81. }
  82. if ($rv == 1) {
  83. # we got one name
  84. $form->{"${name}_id"} = $form->{name_list}[0]->{id};
  85. $form->{$name} = $form->{name_list}[0]->{name};
  86. $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
  87. AA->get_name(\%myconfig, \%$form);
  88. $form->{currency} =~ s/ //g;
  89. # put employee together if there is a new employee_id
  90. $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
  91. } else {
  92. # name is not on file
  93. $msg = ucfirst $name . " not on file!";
  94. $form->error($locale->text($msg));
  95. }
  96. }
  97. }
  98. $rv;
  99. }
  100. # $locale->text('Customer not on file!')
  101. # $locale->text('Vendor not on file!')
  102. sub select_name {
  103. my ($table) = @_;
  104. @column_index = qw(ndx name address);
  105. $label = ucfirst $table;
  106. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  107. $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
  108. $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
  109. # list items with radio button on a form
  110. $form->header;
  111. $title = $locale->text('Select from one of the names below');
  112. print qq|
  113. <body>
  114. <form method=post action=$form->{script}>
  115. <table width=100%>
  116. <tr>
  117. <th class=listtop>$title</th>
  118. </tr>
  119. <tr space=5></tr>
  120. <tr>
  121. <td>
  122. <table width=100%>
  123. <tr class=listheading>|;
  124. for (@column_index) { print "\n$column_data{$_}" }
  125. print qq|
  126. </tr>
  127. |;
  128. @column_index = qw(ndx name address city state zipcode country);
  129. my $i = 0;
  130. foreach $ref (@{ $form->{name_list} }) {
  131. $checked = ($i++) ? "" : "checked";
  132. $ref->{name} = $form->quote($ref->{name});
  133. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  134. $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
  135. $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
  136. for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  137. $j++; $j %= 2;
  138. print qq|
  139. <tr class=listrow$j>|;
  140. for (@column_index) { print "\n$column_data{$_}" }
  141. print qq|
  142. </tr>
  143. <input name="new_id_$i" type=hidden value=$ref->{id}>
  144. |;
  145. }
  146. print qq|
  147. </table>
  148. </td>
  149. </tr>
  150. <tr>
  151. <td><hr size=3 noshade></td>
  152. </tr>
  153. </table>
  154. <input name=lastndx type=hidden value=$i>
  155. |;
  156. # delete variables
  157. for (qw(nextsub name_list)) { delete $form->{$_} }
  158. $form->{action} = "name_selected";
  159. $form->hide_form;
  160. print qq|
  161. <input type=hidden name=nextsub value=name_selected>
  162. <input type=hidden name=vc value=$table>
  163. <br>
  164. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  165. </form>
  166. </body>
  167. </html>
  168. |;
  169. }
  170. sub name_selected {
  171. # replace the variable with the one checked
  172. # index for new item
  173. $i = $form->{ndx};
  174. $form->{$form->{vc}} = $form->{"new_name_$i"};
  175. $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
  176. $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  177. # delete all the new_ variables
  178. for $i (1 .. $form->{lastndx}) {
  179. for (qw(id, name)) { delete $form->{"new_${_}_$i"} }
  180. }
  181. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  182. AA->get_name(\%myconfig, \%$form);
  183. # put employee together if there is a new employee_id
  184. $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
  185. &update(1);
  186. }
  187. sub rebuild_vc {
  188. my ($vc, $ARAP, $transdate, $job) = @_;
  189. ($null, $form->{employee_id}) = split /--/, $form->{employee};
  190. $form->all_vc(\%myconfig, $vc, $ARAP, undef, $transdate, $job);
  191. $form->{"select$vc"} = "";
  192. for (@{ $form->{"all_$vc"} }) { $form->{"select$vc"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  193. $form->{selectprojectnumber} = "";
  194. if (@{ $form->{all_project} }) {
  195. $form->{selectprojectnumber} = "<option>\n";
  196. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  197. }
  198. 1;
  199. }
  200. sub add_transaction {
  201. my ($module) = @_;
  202. delete $form->{script};
  203. $form->{action} = "add";
  204. $form->{type} = "invoice" if $module =~ /(is|ir)/;
  205. $form->{callback} = $form->escape($form->{callback},1);
  206. $argv = "";
  207. for (keys %$form) { $argv .= "$_=$form->{$_}&" }
  208. $form->{callback} = "$module.pl?$argv";
  209. $form->redirect;
  210. }
  211. sub check_project {
  212. for $i (1 .. $form->{rowcount}) {
  213. $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
  214. if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) {
  215. if ($form->{"projectnumber_$i"}) {
  216. # get new project
  217. $form->{projectnumber} = $form->{"projectnumber_$i"};
  218. if (($rows = PE->projects(\%myconfig, $form)) > 1) {
  219. # check form->{project_list} how many there are
  220. $form->{rownumber} = $i;
  221. &select_project;
  222. exit;
  223. }
  224. if ($rows == 1) {
  225. $form->{"project_id_$i"} = $form->{project_list}->[0]->{id};
  226. $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
  227. $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
  228. } else {
  229. # not on file
  230. $form->error($locale->text('Project not on file!'));
  231. }
  232. } else {
  233. $form->{"oldprojectnumber_$i"} = "";
  234. }
  235. }
  236. }
  237. }
  238. sub select_project {
  239. @column_index = qw(ndx projectnumber description);
  240. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  241. $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|;
  242. $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|;
  243. # list items with radio button on a form
  244. $form->header;
  245. $title = $locale->text('Select from one of the projects below');
  246. print qq|
  247. <body>
  248. <form method=post action=$form->{script}>
  249. <input type=hidden name=rownumber value=$form->{rownumber}>
  250. <table width=100%>
  251. <tr>
  252. <th class=listtop>$title</th>
  253. </tr>
  254. <tr space=5></tr>
  255. <tr>
  256. <td>
  257. <table width=100%>
  258. <tr class=listheading>|;
  259. for (@column_index) { print "\n$column_data{$_}" }
  260. print qq|
  261. </tr>
  262. |;
  263. my $i = 0;
  264. foreach $ref (@{ $form->{project_list} }) {
  265. $checked = ($i++) ? "" : "checked";
  266. $ref->{name} = $form->quote($ref->{name});
  267. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  268. $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
  269. $column_data{description} = qq|<td>$ref->{description}</td>|;
  270. $j++; $j %= 2;
  271. print qq|
  272. <tr class=listrow$j>|;
  273. for (@column_index) { print "\n$column_data{$_}" }
  274. print qq|
  275. </tr>
  276. <input name="new_id_$i" type=hidden value=$ref->{id}>
  277. |;
  278. }
  279. print qq|
  280. </table>
  281. </td>
  282. </tr>
  283. <tr>
  284. <td><hr size=3 noshade></td>
  285. </tr>
  286. </table>
  287. <input name=lastndx type=hidden value=$i>
  288. |;
  289. # delete list variable
  290. for (qw(nextsub project_list)) { delete $form->{$_} }
  291. $form->{action} = "project_selected";
  292. $form->hide_form;
  293. print qq|
  294. <input type=hidden name=nextsub value=project_selected>
  295. <br>
  296. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  297. </form>
  298. </body>
  299. </html>
  300. |;
  301. }
  302. sub project_selected {
  303. # replace the variable with the one checked
  304. # index for new item
  305. $i = $form->{ndx};
  306. $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
  307. $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
  308. $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
  309. # delete all the new_ variables
  310. for $i (1 .. $form->{lastndx}) {
  311. for (qw(id projectnumber description)) { delete $form->{"new_${_}_$i"} }
  312. }
  313. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  314. if ($form->{update}) {
  315. &{ $form->{update} };
  316. } else {
  317. &update;
  318. }
  319. }
  320. sub post_as_new {
  321. for (qw(id printed emailed queued)) { delete $form->{$_} }
  322. &post;
  323. }
  324. sub print_and_post_as_new {
  325. for (qw(id printed emailed queued)) { delete $form->{$_} }
  326. &print_and_post;
  327. }
  328. sub repost {
  329. if ($form->{type} =~ /_order/) {
  330. if ($form->{print_and_save}) {
  331. $form->{nextsub} = "print_and_save";
  332. $msg = $locale->text('You are printing and saving an existing order');
  333. } else {
  334. $form->{nextsub} = "save";
  335. $msg = $locale->text('You are saving an existing order');
  336. }
  337. } elsif ($form->{type} =~ /_quotation/) {
  338. if ($form->{print_and_save}) {
  339. $form->{nextsub} = "print_and_save";
  340. $msg = $locale->text('You are printing and saving an existing quotation');
  341. } else {
  342. $form->{nextsub} = "save";
  343. $msg = $locale->text('You are saving an existing quotation');
  344. }
  345. } else {
  346. if ($form->{print_and_post}) {
  347. $form->{nextsub} = "print_and_post";
  348. $msg = $locale->text('You are printing and posting an existing transaction!');
  349. } else {
  350. $form->{nextsub} = "post";
  351. $msg = $locale->text('You are posting an existing transaction!');
  352. }
  353. }
  354. delete $form->{action};
  355. $form->{repost} = 1;
  356. $form->header;
  357. print qq|
  358. <body>
  359. <form method=post action=$form->{script}>
  360. |;
  361. $form->hide_form;
  362. print qq|
  363. <h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
  364. <h4>$msg</h4>
  365. <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
  366. </form>
  367. </body>
  368. </html>
  369. |;
  370. }
  371. sub schedule {
  372. ($form->{recurringreference}, $form->{recurringstartdate}, $form->{recurringrepeat}, $form->{recurringunit}, $form->{recurringhowmany}, $form->{recurringpayment}, $form->{recurringprint}, $form->{recurringemail}, $form->{recurringmessage}) = split /,/, $form->{recurring};
  373. $form->{recurringreference} = $form->quote($form->unescape($form->{recurringreference}));
  374. $form->{recurringmessage} = $form->quote($form->unescape($form->{recurringmessage}));
  375. $form->{recurringstartdate} ||= $form->{transdate};
  376. $recurringpayment = "checked" if $form->{recurringpayment};
  377. if ($form->{paidaccounts}) {
  378. $postpayment = qq|
  379. <tr>
  380. <th align=right nowrap>|.$locale->text('Include Payment').qq|</th>
  381. <td><input name=recurringpayment type=checkbox class=checkbox value=1 $recurringpayment></td>
  382. </tr>
  383. |;
  384. }
  385. if ($form->{recurringnextdate}) {
  386. $nextdate = qq|
  387. <tr>
  388. <th align=right nowrap>|.$locale->text('Next Date').qq|</th>
  389. <td><input name=recurringnextdate size=11 title="($myconfig{'dateformat'})" value=$form->{recurringnextdate}></td>
  390. </tr>
  391. |;
  392. }
  393. @a = split /<option/, $form->unescape($form->{selectformname});
  394. %formname = ();
  395. for ($i = 1; $i <= $#a; $i++) {
  396. $a[$i] =~ /"(.*)"/;
  397. $v = $1;
  398. $a[$i] =~ />(.*)/;
  399. $formname{$v} = $1;
  400. }
  401. for (qw(check receipt)) { delete $formname{$_} }
  402. $selectformat = $form->unescape($form->{selectformat});
  403. if ($form->{type} !~ /transaction/ && %formname) {
  404. $email = qq|
  405. <table>
  406. <tr>
  407. <th colspan=2 class=listheading>|.$locale->text('E-mail').qq|</th>
  408. </tr>
  409. <tr>
  410. <td>
  411. <table>
  412. |;
  413. # formname:format
  414. @p = split /:/, $form->{recurringemail};
  415. %p = ();
  416. for ($i = 0; $i <= $#p; $i += 2) {
  417. $p{$p[$i]}{format} = $p[$i+1];
  418. }
  419. foreach $item (keys %formname) {
  420. $checked = ($p{$item}{format}) ? "checked" : "";
  421. $selectformat =~ s/ selected//;
  422. $p{$item}{format} ||= "pdf";
  423. $selectformat =~ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
  424. $email .= qq|
  425. <tr>
  426. <td><input name="email$item" type=checkbox class=checkbox value=1 $checked></td>
  427. <th align=left>$formname{$item}</th>
  428. <td><select name="emailformat$item">$selectformat</select></td>
  429. </tr>
  430. |;
  431. }
  432. $email .= qq|
  433. </table>
  434. </td>
  435. </tr>
  436. </table>
  437. |;
  438. $message = qq|
  439. <table>
  440. <tr>
  441. <th class=listheading>|.$locale->text('E-mail message').qq|</th>
  442. </tr>
  443. <tr>
  444. <td><textarea name="recurringmessage" rows=10 cols=60 wrap=soft>$form->{recurringmessage}</textarea></td>
  445. </tr>
  446. </table>
  447. |;
  448. }
  449. if (%printer && $latex && %formname) {
  450. $selectprinter = qq|<option>\n|;
  451. for (sort keys %printer) { $selectprinter .= qq|<option value="$_">$_\n| }
  452. # formname:format:printer
  453. @p = split /:/, $form->{recurringprint};
  454. %p = ();
  455. for ($i = 0; $i <= $#p; $i += 3) {
  456. $p{$p[$i]}{formname} = $p[$i];
  457. $p{$p[$i]}{format} = $p[$i+1];
  458. $p{$p[$i]}{printer} = $p[$i+2];
  459. }
  460. $print = qq|
  461. <table>
  462. <tr>
  463. <th colspan=2 class=listheading>|.$locale->text('Print').qq|</th>
  464. </tr>
  465. <tr>
  466. <td>
  467. <table>
  468. |;
  469. $selectformat =~ s/<option.*html//;
  470. foreach $item (keys %formname) {
  471. $selectprinter =~ s/ selected//;
  472. $selectprinter =~ s/(<option value="\Q$p{$item}{printer}\E")/$1 selected/;
  473. $checked = ($p{$item}{formname}) ? "checked" : "";
  474. $selectformat =~ s/ selected//;
  475. $p{$item}{format} ||= "postscript";
  476. $selectformat =~ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
  477. $print .= qq|
  478. <tr>
  479. <td><input name="print$item" type=checkbox class=checkbox value=1 $checked></td>
  480. <th align=left>$formname{$item}</th>
  481. <td><select name="printprinter$item">$selectprinter</select></td>
  482. <td><select name="printformat$item">$selectformat</select></td>
  483. </tr>
  484. |;
  485. }
  486. $print .= qq|
  487. </table>
  488. </td>
  489. </tr>
  490. </table>
  491. |;
  492. }
  493. $selectrepeat = "";
  494. for (1 .. 31) { $selectrepeat .= qq|<option value="$_">$_\n| }
  495. $selectrepeat =~ s/(<option value="$form->{recurringrepeat}")/$1 selected/;
  496. $selectunit = qq|<option value="days">|.$locale->text('Day(s)').qq|
  497. <option value="weeks">|.$locale->text('Week(s)').qq|
  498. <option value="months">|.$locale->text('Month(s)').qq|
  499. <option value="years">|.$locale->text('Year(s)');
  500. if ($form->{recurringunit}) {
  501. $selectunit =~ s/(<option value="$form->{recurringunit}")/$1 selected/;
  502. }
  503. if ($form->{$form->{vc}}) {
  504. $description = $form->{$form->{vc}};
  505. } else {
  506. $description = $form->{description};
  507. }
  508. $repeat = qq|
  509. <table>
  510. <tr>
  511. <th colspan=3 class=listheading>|.$locale->text('Repeat').qq|</th>
  512. </tr>
  513. <tr>
  514. <th align=right nowrap>|.$locale->text('Every').qq|</th>
  515. <td><select name=recurringrepeat>$selectrepeat</td>
  516. <td><select name=recurringunit>$selectunit</td>
  517. </tr>
  518. <tr>
  519. <th align=right nowrap>|.$locale->text('For').qq|</th>
  520. <td><input name=recurringhowmany size=3 value=$form->{recurringhowmany}></td>
  521. <th align=left nowrap>|.$locale->text('time(s)').qq|</th>
  522. </tr>
  523. </table>
  524. |;
  525. $title = $locale->text('Recurring Transaction') ." ". $locale->text('for') ." $description";
  526. $form->header;
  527. print qq|
  528. <body>
  529. <form method=post action=$form->{script}>
  530. <table width=100%>
  531. <tr class=listtop>
  532. <th class=listtop>$title</th>
  533. </tr>
  534. <tr space=5></tr>
  535. <tr>
  536. <td>
  537. <table>
  538. <tr>
  539. <td>
  540. <table>
  541. <tr>
  542. <th align=right nowrap>|.$locale->text('Reference').qq|</th>
  543. <td><input name=recurringreference size=20 value="$form->{recurringreference}"></td>
  544. </tr>
  545. <tr>
  546. <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
  547. <td><input name=recurringstartdate size=11 title="($myconfig{'dateformat'})" value=$form->{recurringstartdate}></td>
  548. </tr>
  549. $nextdate
  550. </table>
  551. </td>
  552. </tr>
  553. </table>
  554. </td>
  555. </tr>
  556. <tr>
  557. <td>
  558. <table>
  559. $postpayment
  560. </table>
  561. </td>
  562. </tr>
  563. <tr>
  564. <td>
  565. <table>
  566. <tr valign=top>
  567. <td>$repeat</td>
  568. <td>$print</td>
  569. </tr>
  570. <tr valign=top>
  571. <td>$email</td>
  572. <td>$message</td>
  573. </tr>
  574. </table>
  575. </td>
  576. </tr>
  577. <tr>
  578. <td><hr size=3 noshade></td>
  579. </tr>
  580. </table>
  581. <br>
  582. |;
  583. # type=submit $locale->text('Save Schedule')
  584. # type=submit $locale->text('Delete Schedule')
  585. %button = ('Save Schedule' => { ndx => 1, key => 'S', value => $locale->text('Save Schedule') },
  586. 'Delete Schedule' => { ndx => 16, key => 'D', value => $locale->text('Delete Schedule') },
  587. );
  588. $form->print_button(\%button, 'Save Schedule');
  589. if ($form->{recurring}) {
  590. $form->print_button(\%button, 'Delete Schedule');
  591. }
  592. # delete variables
  593. for (qw(action recurring)) { delete $form->{$_} }
  594. for (qw(reference startdate nextdate enddate repeat unit howmany payment print email message)) { delete $form->{"recurring$_"} }
  595. $form->hide_form;
  596. print qq|
  597. </form>
  598. </body>
  599. </html>
  600. |;
  601. }
  602. sub save_schedule {
  603. $form->{recurring} = "";
  604. $form->{recurringreference} = $form->escape($form->{recurringreference},1);
  605. $form->{recurringmessage} = $form->escape($form->{recurringmessage},1);
  606. if ($form->{recurringstartdate}) {
  607. for (qw(reference startdate repeat unit howmany payment)) { $form->{recurring} .= qq|$form->{"recurring$_"},| }
  608. }
  609. @a = split /<option/, $form->unescape($form->{selectformname});
  610. @p = ();
  611. for ($i = 1; $i <= $#a; $i++) {
  612. $a[$i] =~ /"(.*)"/;
  613. push @p, $1;
  614. }
  615. $recurringemail = "";
  616. for (@p) { $recurringemail .= qq|$_:$form->{"emailformat$_"}:| if $form->{"email$_"} }
  617. chop $recurringemail;
  618. $recurringprint = "";
  619. for (@p) { $recurringprint .= qq|$_:$form->{"printformat$_"}:$form->{"printprinter$_"}:| if $form->{"print$_"} }
  620. chop $recurringprint;
  621. $form->{recurring} .= qq|$recurringprint,$recurringemail,$form->{recurringmessage}| if $recurringemail || $recurringprint;
  622. $form->save_recurring(undef, \%myconfig) if $form->{id};
  623. if ($form->{recurringid}) {
  624. $form->redirect;
  625. } else {
  626. &update;
  627. }
  628. }
  629. sub delete_schedule {
  630. $form->{recurring} = "";
  631. $form->save_recurring(undef, \%myconfig) if $form->{id};
  632. if ($form->{recurringid}) {
  633. $form->redirect;
  634. } else {
  635. &update;
  636. }
  637. }
  638. sub reprint {
  639. $myconfig{vclimit} = 0;
  640. $pf = "print_form";
  641. for (qw(format formname media message)) { $temp{$_} = $form->{$_} }
  642. if ($form->{module} eq 'oe') {
  643. &order_links;
  644. &prepare_order;
  645. delete $form->{order_details};
  646. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  647. } else {
  648. if ($form->{type} eq 'invoice') {
  649. &invoice_links;
  650. &prepare_invoice;
  651. for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
  652. } else {
  653. &create_links;
  654. $form->{rowcount}--;
  655. for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
  656. for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->format_amount(\%myconfig, $form->{"tax_$_"}, 2) }
  657. $pf = "print_transaction";
  658. }
  659. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  660. }
  661. for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
  662. for (keys %temp) { $form->{$_} = $temp{$_} }
  663. $form->{rowcount}++;
  664. $form->{paidaccounts}++;
  665. delete $form->{paid};
  666. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
  667. $form->{copies} = 1;
  668. &$pf;
  669. if ($form->{media} eq 'email') {
  670. # add email message
  671. $now = scalar localtime;
  672. $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc};
  673. $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc};
  674. $form->{intnotes} .= qq|\n\n| if $form->{intnotes};
  675. $form->{intnotes} .= qq|[email]\n|
  676. .$locale->text('Date').qq|: $now\n|
  677. .$locale->text('To').qq|: $form->{email}\n${cc}${bcc}|
  678. .$locale->text('Subject').qq|: $form->{subject}\n\n|
  679. .$locale->text('Message').qq|: |;
  680. $form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
  681. $form->save_intnotes(\%myconfig, $form->{module});
  682. }
  683. }
  684. sub continue { &{ $form->{nextsub} } };
  685. sub gl_transaction { &add };
  686. sub ar_transaction { &add_transaction(ar) };
  687. sub ap_transaction { &add_transaction(ap) };
  688. sub sales_invoice_ { &add_transaction(is) };
  689. sub vendor_invoice_ { &add_transaction(ir) };