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