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