1#===================================================================== 2# SQL-Ledger 3# Copyright (c) DWS Systems Inc. 4# 5# Author: DWS Systems Inc. 6# Web: http://www.sql-ledger.com 7# 8#====================================================================== 9# 10# common routines for gl, ar, ap, is, ir, oe 11# 12 13use SL::AA; 14 15require "$form->{path}/sr.pl"; 16require "$form->{path}/cm.pl"; 17require "$form->{path}/js.pl"; 18 19# any custom scripts for this one 20if (-f "$form->{path}/custom/arap.pl") { 21 eval { require "$form->{path}/custom/arap.pl"; }; 22} 23if (-f "$form->{path}/custom/$form->{login}/arap.pl") { 24 eval { require "$form->{path}/custom/$form->{login}/arap.pl"; }; 25} 26 27 281; 29# end of main 30 31 32sub check_name { 33 my ($name) = @_; 34 35 my ($new_name, $new_id) = split /--/, $form->{$name}; 36 my $rv = 0; 37 38 # if we use a selection 39 if ($form->{"select$name"}) { 40 if ($form->{"old$name"} ne $form->{$name}) { 41 # this is needed for is, ir and oe 42 for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} } 43 44 for (qw(city state country)) { delete $form->{$_} } 45 46 # for credit calculations 47 $form->{oldinvtotal} = 0; 48 $form->{oldtotalpaid} = 0; 49 $form->{calctax} = 1; 50 51 $form->{"${name}_id"} = $new_id; 52 AA->get_name(\%myconfig, \%$form); 53 54 $form->{"paymentmethod_$form->{paidaccounts}"} = $form->{payment_method}; 55 $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"} = $form->{payment_accno}; 56 57 $form->{$name} = $form->{"old$name"} = "$new_name--$new_id"; 58 $form->{currency} =~ s/ //g; 59 $form->{cashdiscount} *= 100; 60 $form->{cashdiscount} = 0 if $form->{type} =~ /(debit|credit)_/; 61 62 # put employee together if there is a new employee_id 63 $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; 64 65 $rv = 1; 66 } 67 } else { 68 69 my $dosearch; 70 # check name, combine name and id 71 if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) { 72 $form->{searchby} = "name"; 73 $dosearch = 1; 74 } 75 76 if ($form->{"old${name}number"} ne $form->{"${name}number"}) { 77 $form->{searchby} = "$form->{vc}number"; 78 $dosearch = 1; 79 } 80 81 if ($dosearch) { 82 83 # this is needed for is, ir and oe 84 for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} } 85 86 # for credit calculations 87 $form->{oldinvtotal} = 0; 88 $form->{oldtotalpaid} = 0; 89 $form->{calctax} = 1; 90 91 # return one name or a list of names in $form->{name_list} 92 if (($rv = $form->get_name(\%myconfig, $name, $form->{transdate})) > 1) { 93 &select_name($name); 94 exit; 95 } 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->{"${name}number"} = $form->{name_list}[0]->{"${name}number"}; 102 $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|; 103 $form->{"old${name}number"} = $form->{"${name}number"}; 104 105 AA->get_name(\%myconfig, \%$form); 106 107 $form->{"paymentmethod_$form->{paidaccounts}"} = $form->{payment_method}; 108 $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"} = $form->{payment_accno}; 109 110 $form->{currency} =~ s/ //g; 111 # put employee together if there is a new employee_id 112 $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; 113 $form->{cashdiscount} *= 100; 114 $form->{cashdiscount} = 0 if $form->{type} =~ /(debit|credit)_/; 115 116 } else { 117 # name is not on file 118 $msg = ucfirst $name . " not on file!"; 119 $form->error($locale->text($msg)); 120 } 121 } 122 } 123 124 &rebuild_formnames; 125 126 127 $rv; 128 129} 130 131# $locale->text('Customer not on file!') 132# $locale->text('Vendor not on file!') 133 134 135sub select_name { 136 my ($table) = @_; 137 138# $locale->text('Customer Number') 139# $locale->text('Vendor Number') 140# $locale->text('Employee Number') 141 142 @column_index = qw(ndx name number address); 143 144 $label = ucfirst $table; 145 $labelnumber = "$label Number"; 146 147 $column_data{ndx} = qq|<th class=listheading width=1%> </th>|; 148 $column_data{number} = qq|<th class=listheading>|.$locale->text($labelnumber).qq|</th>|; 149 $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|; 150 $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|; 151 152 $form->helpref("list_names", $myconfig{countrycode}); 153 154 # list items with radio button on a form 155 $form->header; 156 157 $title = $locale->text('Select from one of the names below'); 158 159 print qq| 160<body> 161 162<form method=post action=$form->{script}> 163 164<table width=100%> 165 <tr> 166 <th class=listtop>$form->{helpref}$title</a></th> 167 </tr> 168 <tr space=5></tr> 169 <tr> 170 <td> 171 <table width=100%> 172 <tr class=listheading>|; 173 174 for (@column_index) { print "\n$column_data{$_}" } 175 176 print qq| 177 </tr> 178|; 179 180 @column_index = qw(ndx name number address city state zipcode country); 181 182 my $i = 0; 183 foreach $ref (@{ $form->{name_list} }) { 184 $checked = ($i++) ? "" : "checked"; 185 186 $ref->{name} = $form->quote($ref->{name}); 187 188 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; 189 $column_data{number} = qq|<td><input name="new_${table}number_$i" type=hidden value="|.$form->quote($ref->{"${table}number"}).qq|">$ref->{"${table}number"}</td>|; 190 $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="|.$form->quote($ref->{name}).qq|">$ref->{name}</td>|; 191 $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|; 192 for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_} </td>| } 193 194 $j++; $j %= 2; 195 print qq| 196 <tr class=listrow$j>|; 197 198 for (@column_index) { print "\n$column_data{$_}" } 199 200 print qq| 201 </tr> 202 203<input name="new_id_$i" type=hidden value=$ref->{id}> 204 205|; 206 207 } 208 209 print qq| 210 </table> 211 </td> 212 </tr> 213 <tr> 214 <td><hr size=3 noshade></td> 215 </tr> 216</table> 217 218<input name=lastndx type=hidden value=$i> 219 220|; 221 222 # delete variables 223 for (qw(nextsub name_list)) { delete $form->{$_} } 224 225 $form->{action} = "name_selected"; 226 227 $form->hide_form; 228 229 print qq| 230<input type=hidden name=nextsub value=name_selected> 231<input type=hidden name=vc value=$table> 232<br> 233<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> 234</form> 235 236</body> 237</html> 238|; 239 240} 241 242 243 244sub name_selected { 245 246 # replace the variable with the one checked 247 248 # index for new item 249 $i = $form->{ndx}; 250 251 $form->{$form->{vc}} = $form->{"new_name_$i"}; 252 $form->{"$form->{vc}_id"} = $form->{"new_id_$i"}; 253 $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; 254 $form->{"$form->{vc}number"} = $form->{"new_$form->{vc}number_$i"}; 255 $form->{"old$form->{vc}number"} = $form->{"$form->{vc}number"}; 256 257 # delete all the new_ variables 258 for $i (1 .. $form->{lastndx}) { 259 for (qw(id, name)) { delete $form->{"new_${_}_$i"} } 260 delete $form->{"new_$form->{vc}number_$i"}; 261 } 262 263 for (qw(ndx lastndx nextsub)) { delete $form->{$_} } 264 265 AA->get_name(\%myconfig, \%$form); 266 267 $form->{"old$form->{ARAP}"} = $form->{$form->{ARAP}}; 268 269 # put employee together if there is a new employee_id 270 $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; 271 $form->{cashdiscount} *= 100; 272 $form->{cashdiscount} = 0 if $form->{type} =~ /(debit|credit)_/; 273 for (qw(terms discountterms)) { $form->{$_} = "" if ! $form->{$_} } 274 275 $form->{"paymentmethod_$form->{paidaccounts}"} = $form->{payment_method}; 276 $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"} = $form->{payment_accno}; 277 278 &rebuild_formnames; 279 280 &update(1); 281 282} 283 284 285sub rebuild_formnames { 286 287 $form->{selectformname} = $form->unescape($form->{selectformname}); 288 289 if ($form->{remittancevoucher}) { 290 # add remittance voucher to formname 291 if (! ($form->{selectformname} =~ /remittance_voucher/)) { 292 $form->{selectformname} .= qq|\nremittance_voucher--|.$locale->text('Remittance Voucher'); 293 } 294 } else { 295 if ($form->{selectformname} =~ /remittance_voucher/) { 296 $form->{selectformname} =~ s/\nremittance_voucher--.*//s; 297 } 298 } 299 300 $form->{selectformname} = $form->escape($form->{selectformname},1); 301 302} 303 304 305 306sub rebuild_vc { 307 my ($vc, $ARAP, $transdate) = @_; 308 309 (undef, $form->{employee_id}) = split /--/, $form->{employee}; 310 $form->all_vc(\%myconfig, $vc, $ARAP, undef, $transdate); 311 $form->{"select$vc"} = ($form->{generate}) ? "\n" : ""; 312 for (@{ $form->{"all_$vc"} }) { $form->{"select$vc"} .= qq|$_->{name}--$_->{id}\n| } 313 $form->{"select$vc"} = $form->escape($form->{"select$vc"},1); 314 315 $form->{selectprojectnumber} = ""; 316 if (@{ $form->{all_project} }) { 317 $form->{selectprojectnumber} = "\n"; 318 for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|$_->{projectnumber}--$_->{id}\n| } 319 $form->{selectprojectnumber} = $form->escape($form->{selectprojectnumber},1); 320 } 321 322 1; 323 324} 325 326 327sub rebuild_departments { 328 329 $form->all_departments(\%myconfig, undef, $form->{vc}); 330 331 ($subset) = split /--/, $form->{department}; 332 $subset =~ s/:.*//g; 333 334 $form->{selectdepartment} = "\n" if @{ $form->{all_department} }; 335 $form->{olddepartment} = $form->{department}; 336 337 for (@{ $form->{all_department} }) { 338 if ($subset) { 339 if ($_->{description} =~ /:/) { 340 if ($_->{description} =~ /${subset}:/) { 341 $form->{selectdepartment} .= qq|$_->{description}--$_->{id}\n|; 342 } 343 } else { 344 $form->{selectdepartment} .= qq|$_->{description}--$_->{id}\n|; 345 } 346 } else { 347 if ($_->{description} !~ /:/) { 348 $form->{selectdepartment} .= qq|$_->{description}--$_->{id}\n|; 349 } 350 } 351 } 352 353} 354 355 356sub add_transaction { 357 358 $form->{action} = "add"; 359 360 $form->{callback} = $form->escape($form->{callback},1); 361 $argv = ""; 362 for (keys %$form) { $argv .= "$_=$form->{$_}&" } 363 364 $form->{callback} = "$form->{script}?$argv"; 365 366 $form->redirect; 367 368} 369 370 371 372sub check_project { 373 374 for $i (1 .. $form->{rowcount}) { 375 $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"}; 376 if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) { 377 if ($form->{"projectnumber_$i"}) { 378 # get new project 379 $form->{projectnumber} = $form->{"projectnumber_$i"}; 380 if (($rows = PE->projects(\%myconfig, $form)) > 1) { 381 # check form->{project_list} how many there are 382 $form->{rownumber} = $i; 383 &select_project; 384 exit; 385 } 386 387 if ($rows == 1) { 388 $form->{"project_id_$i"} = $form->{project_list}->[0]->{id}; 389 $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber}; 390 $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber}; 391 } else { 392 # not on file 393 $form->error($locale->text('Project not on file!')); 394 } 395 } else { 396 $form->{"oldprojectnumber_$i"} = ""; 397 } 398 } 399 } 400 401} 402 403 404sub select_project { 405 406 @column_index = qw(ndx projectnumber description); 407 408 $column_data{ndx} = qq|<th width=1%> </th>|; 409 $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|; 410 $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|; 411 412 $form->helpref("select_project", $myconfig{countrycode}); 413 414 # list items with radio button on a form 415 $form->header; 416 417 $title = $locale->text('Select from one of the projects below'); 418 419 print qq| 420<body> 421 422<form method=post action=$form->{script}> 423 424<input type=hidden name=rownumber value=$form->{rownumber}> 425 426<table width=100%> 427 <tr> 428 <th class=listtop>$form->{helpref}$title</a></th> 429 </tr> 430 <tr space=5></tr> 431 <tr> 432 <td> 433 <table width=100%> 434 <tr class=listheading>|; 435 436 for (@column_index) { print "\n$column_data{$_}" } 437 438 print qq| 439 </tr> 440|; 441 442 my $i = 0; 443 foreach $ref (@{ $form->{project_list} }) { 444 $checked = ($i++) ? "" : "checked"; 445 446 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; 447 $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="|.$form->quote($ref->{projectnumber}).qq|">$ref->{projectnumber}</td>|; 448 $column_data{description} = qq|<td>$ref->{description}</td>|; 449 450 $j++; $j %= 2; 451 print qq| 452 <tr class=listrow$j>|; 453 454 for (@column_index) { print "\n$column_data{$_}" } 455 456 print qq| 457 </tr> 458 459<input name="new_id_$i" type=hidden value=$ref->{id}> 460 461|; 462 463 } 464 465 print qq| 466 </table> 467 </td> 468 </tr> 469 <tr> 470 <td><hr size=3 noshade></td> 471 </tr> 472</table> 473 474<input name=lastndx type=hidden value=$i> 475 476|; 477 478 # delete list variable 479 for (qw(nextsub project_list)) { delete $form->{$_} } 480 481 $form->{action} = "project_selected"; 482 483 $form->hide_form; 484 485 print qq| 486<input type=hidden name=nextsub value=project_selected> 487<br> 488<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> 489</form> 490 491</body> 492</html> 493|; 494 495} 496 497 498sub project_selected { 499 500 # replace the variable with the one checked 501 502 # index for new item 503 $i = $form->{ndx}; 504 505 $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"}; 506 $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"}; 507 $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"}; 508 509 # delete all the new_ variables 510 for $i (1 .. $form->{lastndx}) { 511 for (qw(id projectnumber description)) { delete $form->{"new_${_}_$i"} } 512 } 513 514 for (qw(ndx lastndx nextsub)) { delete $form->{$_} } 515 516 if ($form->{update}) { 517 &{ $form->{update} }; 518 } else { 519 &update; 520 } 521 522} 523 524 525sub post_as_new { 526 527 for (qw(id printed emailed queued)) { delete $form->{$_} } 528 $form->{postasnew} = 1; 529 if ($form->{lock_sinumber}) { 530 delete $form->{invnumber}; 531 } 532 if ($form->{lock_glnumber}) { 533 delete $form->{reference}; 534 } 535 &post; 536 537} 538 539 540sub print_and_post_as_new { 541 542 for (qw(id printed emailed queued)) { delete $form->{$_} } 543 if ($form->{lock_sinumber}) { 544 delete $form->{invnumber}; 545 } 546 &print_and_post; 547 548} 549 550 551sub repost { 552 553 if ($form->{type} =~ /_order/) { 554 if ($form->{print_and_save}) { 555 $form->{nextsub} = "print_and_save"; 556 $msg = $locale->text('You are printing and saving an existing order'); 557 } else { 558 $form->{nextsub} = "save"; 559 $msg = $locale->text('You are saving an existing order'); 560 } 561 } elsif ($form->{type} =~ /_quotation/) { 562 if ($form->{print_and_save}) { 563 $form->{nextsub} = "print_and_save"; 564 $msg = $locale->text('You are printing and saving an existing quotation'); 565 } else { 566 $form->{nextsub} = "save"; 567 $msg = $locale->text('You are saving an existing quotation'); 568 } 569 } else { 570 if ($form->{print_and_post}) { 571 $form->{nextsub} = "print_and_post"; 572 $msg = $locale->text('You are printing and posting an existing transaction!'); 573 } else { 574 $form->{nextsub} = "post"; 575 $msg = $locale->text('You are posting an existing transaction!'); 576 } 577 } 578 579 delete $form->{action}; 580 $form->{repost} = 1; 581 582 583 $form->header; 584 585 print qq| 586<body> 587 588<form method=post action=$form->{script}> 589|; 590 591 $form->hide_form; 592 593 print qq| 594<h2 class=confirm>|.$locale->text('Warning!').qq|</h2> 595 596<h4>$msg</h4> 597 598<input name=action class=submit type=submit value="|.$locale->text('Continue').qq|"> 599</form> 600 601</body> 602</html> 603|; 604 605} 606 607 608sub schedule { 609 610 ($form->{recurringreference}, $form->{recurringdescription}, $form->{recurringstartdate}, $form->{recurringrepeat}, $form->{recurringunit}, $form->{recurringhowmany}, $form->{recurringpayment}, $form->{recurringprint}, $form->{recurringemail}, $form->{recurringmessage}) = split /,/, $form->{recurring}; 611 612 for (qw(reference description message)) { $form->{"recurring$_"} = $form->quote($form->unescape($form->{"recurring$_"})) } 613 614 $type = $form->{type} || "general_ledger"; 615 if (exists $form->{ARAP}) { 616 $type = lc $form->{ARAP} . "_$form->{type}"; 617 } 618 $form->helpref("recurring_$type", $myconfig{countrycode}); 619 620 $form->{recurringstartdate} ||= $form->{transdate}; 621 $recurringpayment = "checked" if $form->{recurringpayment}; 622 623 if ($form->{paidaccounts}) { 624 $postpayment = qq| 625 <tr> 626 <th align=right nowrap>|.$locale->text('Include Payment').qq|</th> 627 <td><input name=recurringpayment type=checkbox class=checkbox value=1 $recurringpayment></td> 628 </tr> 629|; 630 } 631 632 if ($form->{recurringnextdate}) { 633 $nextdate = qq| 634 <tr> 635 <th align=right nowrap>|.$locale->text('Next Date').qq|</th> 636 <td><input name=recurringnextdate size=11 class=date title="$myconfig{'dateformat'}" value=$form->{recurringnextdate}>|.&js_calendar("main", "recurringnextdate").qq|</td> 637 </tr> 638|; 639 } 640 641 for (split /\r?\n/, $form->unescape($form->{selectformname})) { 642 (@_) = split /--/, $_; 643 $formname{$_[0]} = $_[1]; 644 } 645 for (qw(check receipt)) { delete $formname{$_} } 646 647 $selectformat = qq|html--|.$locale->text('html').qq| 648xml--|.$locale->text('XML').qq| 649txt--|.$locale->text('Text').qq| 650ps--|.$locale->text('Postscript').qq| 651pdf--|.$locale->text('PDF'); 652 653 if ($form->{type} !~ /transaction/ && %formname) { 654 $email = qq| 655 <table> 656 <tr> 657 <th colspan=2 class=listheading>|.$locale->text('E-mail').qq|</th> 658 </tr> 659 660 <tr> 661 <td> 662 <table> 663|; 664 665 # formname:format 666 @p = split /:/, $form->{recurringemail}; 667 %p = (); 668 for ($i = 0; $i <= $#p; $i += 2) { 669 $p{$p[$i]}{format} = $p[$i+1]; 670 } 671 672 foreach $item (keys %formname) { 673 674 $checked = ($p{$item}{format}) ? "checked" : ""; 675 $p{$item}{format} ||= "pdf"; 676 677 $email .= qq| 678 <tr> 679 <td><input name="email$item" type=checkbox class=checkbox value=1 $checked></td> 680 <th align=left>$formname{$item}</th> 681 <td><select name="emailformat$item">| 682 .$form->select_option($selectformat, $p{$item}{format}, undef, 1) 683 .qq|</select> 684 </td> 685 </tr> 686|; 687 } 688 689 $email .= qq| 690 </table> 691 </td> 692 </tr> 693 </table> 694|; 695 696 $message = qq| 697 <table> 698 <tr> 699 <th class=listheading>|.$locale->text('E-mail message').qq|</th> 700 </tr> 701 702 <tr> 703 <td><textarea name="recurringmessage" rows=10 cols=60 wrap=soft>$form->{recurringmessage}</textarea></td> 704 </tr> 705 </table> 706|; 707 708 } 709 710 if ($form->{selectprinter} && $latex && %formname) { 711 $selectprinter = ""; 712 for (split /\n/, $form->unescape($form->{selectprinter})) { $selectprinter .= qq| 713 <option value="$_">$_| } 714 715 # formname:format:printer 716 @p = split /:/, $form->{recurringprint}; 717 718 %p = (); 719 for ($i = 0; $i <= $#p; $i += 3) { 720 $p{$p[$i]}{formname} = $p[$i]; 721 $p{$p[$i]}{format} = $p[$i+1]; 722 $p{$p[$i]}{printer} = $p[$i+2]; 723 } 724 725 $print = qq| 726 <table> 727 <tr> 728 <th colspan=2 class=listheading>|.$locale->text('Print').qq|</th> 729 </tr> 730 731 <tr> 732 <td> 733 <table> 734|; 735 736 foreach $item (keys %formname) { 737 738 $selectprinter =~ s/ selected//; 739 $p{$item}{printer} ||= $myconfig{printer}; 740 $selectprinter =~ s/(<option value="\Q$p{$item}{printer}\E")/$1 selected/; 741 742 $checked = ($p{$item}{formname}) ? "checked" : ""; 743 744 $p{$item}{format} ||= $myconfig{outputformat}; 745 $p{$item}{format} ||= "postscript"; 746 747 $print .= qq| 748 <tr> 749 <td><input name="print$item" type=checkbox class=checkbox value=1 $checked></td> 750 <th align=left>$formname{$item}</th> 751 <td><select name="printprinter$item">$selectprinter</select></td> 752 <td><select name="printformat$item">| 753 .$form->select_option($selectformat, $p{$item}{format}, undef, 1) 754 .qq|</select> 755 </td> 756 </tr> 757|; 758 } 759 760 $print .= qq| 761 </table> 762 </td> 763 </tr> 764 </table> 765|; 766 767 768 } 769 770 $selectrepeat = ""; 771 for (1 .. 31) { $selectrepeat .= qq|<option value="$_">$_\n| } 772 $selectrepeat =~ s/(<option value="$form->{recurringrepeat}")/$1 selected/; 773 774 $selectunit = qq|<option value="days">|.$locale->text('Day(s)').qq| 775 <option value="weeks">|.$locale->text('Week(s)').qq| 776 <option value="months">|.$locale->text('Month(s)').qq| 777 <option value="years">|.$locale->text('Year(s)'); 778 779 if ($form->{recurringunit}) { 780 $selectunit =~ s/(<option value="$form->{recurringunit}")/$1 selected/; 781 } 782 783 if ($form->{$form->{vc}}) { 784 $description = $form->{$form->{vc}}; 785 $description =~ s/--.*//; 786 } else { 787 $description = $form->{description}; 788 } 789 790 $repeat = qq| 791 <table> 792 <tr> 793 <th colspan=3 class=listheading>|.$locale->text('Repeat').qq|</th> 794 </tr> 795 796 <tr> 797 <th align=right nowrap>|.$locale->text('Every').qq|</th> 798 <td><select name=recurringrepeat>$selectrepeat</td> 799 <td><select name=recurringunit>$selectunit</td> 800 </tr> 801 <tr> 802 <th align=right nowrap>|.$locale->text('For').qq|</th> 803 <td><input name=recurringhowmany class="inputright" size=3 value=$form->{recurringhowmany}></td> 804 <th align=left nowrap>|.$locale->text('time(s)').qq|</th> 805 </tr> 806 </table> 807|; 808 809 810 $title = $locale->text('Recurring Transaction') ." ". $locale->text('for') ." $description"; 811 812 if (($rows = $form->numtextrows($form->{recurringdescription}, 60)) > 1) { 813 $description = qq|<textarea name="recurringdescription" rows=$rows cols=35 wrap=soft>$form->{recurringdescription}</textarea>|; 814 } else { 815 $description = qq|<input name=recurringdescription size=60 value="|.$form->quote($form->{recurringdescription}).qq|">|; 816 } 817 818 $form->header; 819 820 &calendar; 821 822 print qq| 823<body> 824 825<form method="post" name="main" action="$form->{script}"> 826 827<table width=100%> 828 <tr class=listtop> 829 <th class=listtop>$form->{helpref}$title</a></th> 830 </tr> 831 <tr space=5></tr> 832 <tr> 833 <td> 834 <table> 835 <tr> 836 <td> 837 <table> 838 <tr> 839 <th align=right nowrap>|.$locale->text('Reference').qq|</th> 840 <td><input name=recurringreference size=20 value="|.$form->quote($form->{recurringreference}).qq|"></td> 841 </tr> 842 <tr> 843 <th align=right nowrap>|.$locale->text('Description').qq|</th> 844 <td>$description</td> 845 </tr> 846 847 <tr> 848 <th align=right nowrap>|.$locale->text('Startdate').qq|</th> 849 <td><input name=recurringstartdate size=11 class=date title="$myconfig{'dateformat'}" value=$form->{recurringstartdate}>|.&js_calendar("main", "recurringstartdate").qq|</td> 850 </tr> 851 $nextdate 852 </table> 853 </td> 854 </tr> 855 </table> 856 </td> 857 </tr> 858 859 <tr> 860 <td> 861 <table> 862 $postpayment 863 </table> 864 </td> 865 </tr> 866 867 <tr> 868 <td> 869 <table> 870 <tr valign=top> 871 <td>$repeat</td> 872 <td>$print</td> 873 </tr> 874 <tr valign=top> 875 <td>$email</td> 876 <td>$message</td> 877 </tr> 878 </table> 879 </td> 880 </tr> 881 <tr> 882 <td><hr size=3 noshade></td> 883 </tr> 884</table> 885 886<br> 887|; 888 889 %button = ('Save Schedule' => { ndx => 1, key => 'S', value => $locale->text('Save Schedule') }, 890 'Delete Schedule' => { ndx => 16, key => 'D', value => $locale->text('Delete Schedule') }, 891 ); 892 893 unless ($form->{recurring}) { 894 delete $button{'Delete Schedule'}; 895 } 896 897 $form->print_button(\%button); 898 899 # delete variables 900 for (qw(action recurring)) { delete $form->{$_} } 901 for (qw(reference description startdate nextdate enddate repeat unit howmany payment print email message)) { delete $form->{"recurring$_"} } 902 903 $form->hide_form; 904 905 print qq| 906 907</form> 908 909</body> 910</html> 911|; 912 913} 914 915 916sub save_schedule { 917 918 $form->{recurring} = ""; 919 920 for (qw(reference description message)) { $form->{"recurring$_"} = $form->escape($form->{"recurring$_"},1) } 921 922 if ($form->{recurringstartdate}) { 923 for (qw(reference description startdate repeat unit howmany payment)) { $form->{recurring} .= qq|$form->{"recurring$_"},| } 924 } 925 926 @p = (); 927 for $item (split /\r?\n/, $form->unescape($form->{selectformname})) { 928 (@f) = split /--/, $item; 929 push @p, $f[0]; 930 } 931 932 $recurringemail = ""; 933 for (@p) { $recurringemail .= qq|$_:$form->{"emailformat$_"}:| if $form->{"email$_"} } 934 chop $recurringemail; 935 936 $recurringprint = ""; 937 for (@p) { $recurringprint .= qq|$_:$form->{"printformat$_"}:$form->{"printprinter$_"}:| if $form->{"print$_"} } 938 chop $recurringprint; 939 940 $form->{recurring} .= qq|$recurringprint,$recurringemail,$form->{recurringmessage}| if $recurringemail || $recurringprint; 941 942 $form->save_recurring(undef, \%myconfig) if $form->{id}; 943 944 if ($form->{recurringid}) { 945 $form->redirect; 946 } else { 947 &update; 948 } 949 950} 951 952 953sub delete_schedule { 954 955 $form->{recurring} = ""; 956 957 $form->save_recurring(undef, \%myconfig) if $form->{id}; 958 959 if ($form->{recurringid}) { 960 $form->redirect; 961 } else { 962 &update; 963 } 964 965} 966 967 968sub reprint { 969 970 $myconfig{vclimit} = 0; 971 $pf = "print_form"; 972 973 for (qw(format formname media message)) { $temp{$_} = $form->{$_} } 974 975 if ($form->{module} eq 'oe') { 976 &order_links; 977 &prepare_order; 978 delete $form->{order_details}; 979 for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) } 980 } else { 981 if ($form->{type} eq 'invoice') { 982 &invoice_links; 983 &prepare_invoice; 984 for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) } 985 } else { 986 &create_links; 987 $form->{rowcount}--; 988 for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, $form->{precision}) } 989 for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->format_amount(\%myconfig, $form->{"tax_$_"}, $form->{precision}) } 990 $pf = "print_transaction"; 991 } 992 for (qw(acc_trans invoice_details)) { delete $form->{$_} } 993 } 994 995 for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} } 996 997 for (keys %temp) { $form->{$_} = $temp{$_} } 998 999 $form->{rowcount}++; 1000 $form->{paidaccounts}++; 1001 1002 delete $form->{paid}; 1003 1004 for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, $form->{precision}) } 1005 $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"} = $form->{payment_accno}; 1006 $form->{"paymentmethod_$form->{paidaccounts}"} = $form->{payment_method}; 1007 1008 $form->{copies} = 1; 1009 1010 &$pf; 1011 1012 if ($form->{media} eq 'email') { 1013 # add email message 1014 $now = scalar localtime; 1015 $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc}; 1016 $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc}; 1017 1018 $form->{intnotes} .= qq|\n\n| if $form->{intnotes}; 1019 $form->{intnotes} .= qq|[email]\n| 1020 .$locale->text('Date').qq|: $now\n| 1021 .$locale->text('To').qq|: $form->{email}\n${cc}${bcc}| 1022 .$locale->text('Subject').qq|: $form->{subject}\n\n| 1023 .$locale->text('Message').qq|: |; 1024 1025 $form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent'); 1026 1027 $form->save_intnotes(\%myconfig, $form->{module}); 1028 } 1029 1030} 1031 1032 1033sub islocked { 1034 1035 print "<p><font color=red>".$locale->text('Locked by').": $form->{haslock}</font>" if $form->{haslock}; 1036 1037} 1038 1039 1040sub continue { &{ $form->{nextsub} } }; 1041sub gl_transaction { &add }; 1042sub ar_transaction { 1043 $form->{script} = "ar.pl"; 1044 $form->{rowcount} = 1; 1045 &add_transaction; 1046} 1047sub ap_transaction { 1048 $form->{script} = "ap.pl"; 1049 $form->{rowcount} = 1; 1050 &add_transaction; 1051}; 1052sub sales_invoice_ { 1053 $form->{script} = "is.pl"; 1054 $form->{type} = "invoice"; 1055 delete $form->{rowcount}; 1056 &add_transaction; 1057} 1058sub credit_invoice_ { 1059 $form->{script} = "is.pl"; 1060 $form->{type} = "credit_invoice"; 1061 delete $form->{rowcount}; 1062 &add_transaction; 1063} 1064sub vendor_invoice_ { 1065 $form->{script} = "ir.pl"; 1066 $form->{type} = "invoice"; 1067 delete $form->{rowcount}; 1068 &add_transaction; 1069} 1070sub debit_invoice_ { 1071 $form->{script} = "ir.pl"; 1072 $form->{type} = "debit_invoice"; 1073 delete $form->{rowcount}; 1074 &add_transaction; 1075} 1076 1077 1078sub preview { 1079 1080 if ($form->{type} eq 'customer') { 1081 if ($form->{type} =~ /(invoice|order)/) { 1082 &validate_items; 1083 } 1084 } 1085 1086 $form->{format} = "pdf"; 1087 $form->{media} = "screen"; 1088 1089 &print; 1090 1091} 1092 1093 1094sub new_number { 1095 1096 $invnumber = "invnumber"; 1097 $numberfld = ($form->{vc} eq 'customer') ? "sinumber" : "vinumber"; 1098 1099 if ($form->{type} =~ /order/) { 1100 $invnumber = "ordnumber"; 1101 $numberfld = ($form->{vc} eq 'customer') ? "sonumber" : "ponumber"; 1102 } elsif ($form->{type} =~ /quotation/) { 1103 $invnumber = "quonumber"; 1104 $numberfld = ($form->{vc} eq 'customer') ? "sqnumber" : "rfqnumber"; 1105 } elsif ($form->{script} eq 'gl.pl') { 1106 $invnumber = "reference"; 1107 $numberfld = "glnumber"; 1108 } elsif ($form->{script} eq 'hr.pl') { 1109 $numberfld = $invnumber = "employeenumber"; 1110 HR->isadmin(\%myconfig, \%$form); 1111 } 1112 1113 $form->{"$invnumber"} = $form->update_defaults(\%myconfig, $numberfld); 1114 1115 &update; 1116 1117} 1118 1119 1120