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