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