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