1#===================================================================== 2# LedgerSMB 3# Small Medium Business Accounting software 4# http://www.ledgersmb.org/ 5# 6# 7# Copyright (C) 2006 8# This work contains copyrighted information from a number of sources all used 9# with permission. 10# 11# This file contains source code included with or based on SQL-Ledger which 12# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed 13# under the GNU General Public License version 2 or, at your option, any later 14# version. For a full list including contact information of contributors, 15# maintainers, and copyright holders, see the CONTRIBUTORS file. 16# 17# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork): 18# Copyright (c) 2001 19# 20# Author: DWS Systems Inc. 21# Web: http://www.sql-ledger.org 22# 23# Contributors: 24# 25#====================================================================== 26# 27# This file has NOT undergone whitespace cleanup. 28# 29#====================================================================== 30# 31# administration 32# 33#====================================================================== 34 35use LedgerSMB::AM; 36use LedgerSMB::CA; 37use LedgerSMB::Form; 38use LedgerSMB::User; 39use LedgerSMB::RP; 40use LedgerSMB::GL; 41 421; 43 44# end of main 45 46sub add { &{"add_$form->{type}"} } 47sub edit { &{"edit_$form->{type}"} } 48sub save { &{"save_$form->{type}"} } 49sub delete { &{"delete_$form->{type}"} } 50 51sub save_as_new { 52 53 delete $form->{id}; 54 55 &save; 56 57} 58 59sub add_account { 60 61 $form->{title} = "Add"; 62 $form->{charttype} = "A"; 63 64 $form->{callback} = 65"$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 66 unless $form->{callback}; 67 68 &account_header; 69 &form_footer; 70 71} 72 73sub edit_account { 74 75 $form->{title} = "Edit"; 76 77 $form->{accno} =~ s/\\'/'/g; 78 $form->{accno} =~ s/\\\\/\\/g; 79 80 AM->get_account( \%myconfig, \%$form ); 81 82 foreach my $item ( split( /:/, $form->{link} ) ) { 83 $form->{$item} = "checked"; 84 } 85 86 &account_header; 87 &form_footer; 88 89} 90 91sub account_header { 92 93 $form->{title} = $locale->text("$form->{title} Account"); 94 95 $checked{ $form->{charttype} } = "checked"; 96 $checked{contra} = "checked" if $form->{contra}; 97 $checked{"$form->{category}_"} = "checked"; 98 99 for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) } 100 101 # this is for our parser only! 102 # type=submit $locale->text('Add Account') 103 # type=submit $locale->text('Edit Account') 104 105 $form->header; 106 107 print qq| 108<body> 109 110<form method=post action=$form->{script}> 111 112<input type=hidden name=id value=$form->{id}> 113<input type=hidden name=type value=account> 114 115<input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}> 116<input type=hidden name=income_accno_id value=$form->{income_accno_id}> 117<input type=hidden name=expense_accno_id value=$form->{expense_accno_id}> 118<input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}> 119<input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}> 120 121<table border=0 width=100%> 122 <tr> 123 <th class=listtop>$form->{title}</th> 124 </tr> 125 <tr height="5"></tr> 126 <tr valign=top> 127 <td> 128 <table> 129 <tr> 130 <th align="right">| . $locale->text('Account Number') . qq|</th> 131 <td><input name=accno size=20 value="$form->{accno}"></td> 132 </tr> 133 <tr> 134 <th align="right">| . $locale->text('Description') . qq|</th> 135 <td><input name=description size=40 value="$form->{description}"></td> 136 </tr> 137 <tr> 138 <th align="right">| . $locale->text('Account Type') . qq|</th> 139 <td> 140 <table> 141 <tr valign=top> 142 <td><input name=category type=radio class=radio value=A $checked{A_}> | 143 . $locale->text('Asset') 144 . qq|\n<br> 145 <input name=category type=radio class=radio value=L $checked{L_}> | 146 . $locale->text('Liability') 147 . qq|\n<br> 148 <input name=category type=radio class=radio value=Q $checked{Q_}> | 149 . $locale->text('Equity') 150 . qq|\n<br> 151 <input name=category type=radio class=radio value=I $checked{I_}> | 152 . $locale->text('Income') 153 . qq|\n<br> 154 <input name=category type=radio class=radio value=E $checked{E_}> | 155 . $locale->text('Expense') 156 . qq|</td> 157 <td> 158 <input name=contra class=checkbox type=checkbox value=1 $checked{contra}> | 159 . $locale->text('Contra') . qq| 160 </td> 161 <td> 162 <input name=charttype type=radio class=radio value="H" $checked{H}> | 163 . $locale->text('Heading') . qq|<br> 164 <input name=charttype type=radio class=radio value="A" $checked{A}> | 165 . $locale->text('Account') 166 . qq|</td> 167 </tr> 168 </table> 169 </td> 170 </tr> 171|; 172 173 if ( $form->{charttype} eq "A" ) { 174 print qq| 175 <tr> 176 <td colspan=2> 177 <table> 178 <tr> 179 <th align=left>| 180 . $locale->text('Is this a summary account to record') 181 . qq|</th> 182 <td> 183 <input name=AR class=checkbox type=checkbox value=AR $form->{AR}> | 184 . $locale->text('AR') 185 . qq| <input name=AP class=checkbox type=checkbox value=AP $form->{AP}> | 186 . $locale->text('AP') 187 . qq| <input name=IC class=checkbox type=checkbox value=IC $form->{IC}> | 188 . $locale->text('Inventory') 189 . qq|</td> 190 </tr> 191 </table> 192 </td> 193 </tr> 194 <tr> 195 <th colspan=2>| . $locale->text('Include in drop-down menus') . qq|</th> 196 </tr> 197 <tr valign=top> 198 <td colspan=2> 199 <table width=100%> 200 <tr> 201 <th align=left>| . $locale->text('Receivables') . qq|</th> 202 <th align=left>| . $locale->text('Payables') . qq|</th> 203 <th align=left>| . $locale->text('Tracking Items') . qq|</th> 204 <th align=left>| . $locale->text('Non-tracking Items') . qq|</th> 205 </tr> 206 <tr> 207 <td> 208 <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}> | 209 . $locale->text('Income') 210 . qq|\n<br> 211 <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}> | 212 . $locale->text('Payment') 213 . qq|\n<br> 214 <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}> | 215 . $locale->text('Tax') . qq| 216 </td> 217 <td> 218 <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}> | 219 . $locale->text('Expense/Asset') 220 . qq|\n<br> 221 <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}> | 222 . $locale->text('Payment') 223 . qq|\n<br> 224 <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}> | 225 . $locale->text('Tax') . qq| 226 </td> 227 <td> 228 <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}> | 229 . $locale->text('Income') 230 . qq|\n<br> 231 <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}> | 232 . $locale->text('COGS') 233 . qq|\n<br> 234 <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}> | 235 . $locale->text('Tax') . qq| 236 </td> 237 <td> 238 <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}> | 239 . $locale->text('Income') 240 . qq|\n<br> 241 <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}> | 242 . $locale->text('Expense') 243 . qq|\n<br> 244 <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}> | 245 . $locale->text('Tax') . qq| 246 </td> 247 </tr> 248 </table> 249 </td> 250 </tr> 251 <tr> 252 </tr> 253|; 254 } 255 256 print qq| 257 <tr> 258 <th align="right">| . $locale->text('GIFI') . qq|</th> 259 <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td> 260 </tr> 261 </table> 262 </td> 263 </tr> 264 <tr> 265 <td><hr size=3 noshade></td> 266 </tr> 267</table> 268|; 269 270} 271 272sub form_footer { 273 274 $form->hide_form(qw(callback path login sessionid)); 275 276 # type=submit $locale->text('Save') 277 # type=submit $locale->text('Save as new') 278 # type=submit $locale->text('Delete') 279 280 %button = (); 281 282 if ( $form->{id} ) { 283 $button{'save'} = 284 { ndx => 3, key => 'S', value => $locale->text('Save') }; 285 $button{'save_as_new'} = 286 { ndx => 7, key => 'N', value => $locale->text('Save as new') }; 287 288 if ( $form->{orphaned} ) { 289 $button{'delete'} = 290 { ndx => 16, key => 'D', value => $locale->text('Delete') }; 291 } 292 } 293 else { 294 $button{'save'} = 295 { ndx => 3, key => 'S', value => $locale->text('Save') }; 296 } 297 298 for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { 299 $form->print_button( \%button, $_ ); 300 } 301 302 if ( $form->{lynx} ) { 303 require "bin/menu.pl"; 304 &menubar; 305 } 306 307 print qq| 308</form> 309 310</body> 311</html> 312|; 313 314} 315 316sub save_account { 317 318 $form->isblank( "accno", $locale->text('Account Number missing!') ); 319 $form->isblank( "category", $locale->text('Account Type missing!') ); 320 321 # check for conflicting accounts 322 if ( $form->{AR} || $form->{AP} || $form->{IC} ) { 323 $a = ""; 324 for (qw(AR AP IC)) { $a .= $form->{$_} } 325 $form->error( 326 $locale->text( 327 'Cannot set account for more than one of AR, AP or IC') 328 ) if length $a > 2; 329 330 for ( 331 qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense) 332 ) 333 { 334 $form->error( 335 "$form->{AR}$form->{AP}$form->{IC} " 336 . $locale->text( 337 'account cannot be set to any other type of account') 338 ) if $form->{$_}; 339 } 340 } 341 342 foreach $item ( "AR", "AP" ) { 343 $i = 0; 344 for ( "${item}_amount", "${item}_paid", "${item}_tax" ) { 345 $i++ if $form->{$_}; 346 } 347 $form->error( 348 $locale->text( 'Cannot set multiple options for [_1]', $item ) ) 349 if $i > 1; 350 } 351 352 if ( AM->save_account( \%myconfig, \%$form ) ) { 353 $form->redirect( $locale->text('Account saved!') ); 354 } 355 else { 356 $form->error( $locale->text('Cannot save account!') ); 357 } 358 359} 360 361sub list_account { 362 363 CA->all_accounts( \%myconfig, \%$form ); 364 365 $form->{title} = $locale->text('Chart of Accounts'); 366 367 # construct callback 368 $callback = 369"$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 370 371 @column_index = qw(accno gifi_accno description debit credit link); 372 373 $column_header{accno} = 374 qq|<th class=listtop>| . $locale->text('Account') . qq|</a></th>|; 375 $column_header{gifi_accno} = 376 qq|<th class=listtop>| . $locale->text('GIFI') . qq|</a></th>|; 377 $column_header{description} = 378 qq|<th class=listtop>| . $locale->text('Description') . qq|</a></th>|; 379 $column_header{debit} = 380 qq|<th class=listtop>| . $locale->text('Debit') . qq|</a></th>|; 381 $column_header{credit} = 382 qq|<th class=listtop>| . $locale->text('Credit') . qq|</a></th>|; 383 $column_header{link} = 384 qq|<th class=listtop>| . $locale->text('Link') . qq|</a></th>|; 385 386 $form->header; 387 $colspan = $#column_index + 1; 388 389 print qq| 390<body> 391 392<table width=100%> 393 <tr> 394 <th class=listtop colspan=$colspan>$form->{title}</th> 395 </tr> 396 <tr height="5"></tr> 397 <tr class="listheading"> 398|; 399 400 for (@column_index) { print "$column_header{$_}\n" } 401 402 print qq| 403</tr> 404|; 405 406 # escape callback 407 $callback = $form->escape($callback); 408 409 foreach $ca ( @{ $form->{CA} } ) { 410 411 $ca->{debit} = " "; 412 $ca->{credit} = " "; 413 414 if ( $ca->{amount} > 0 ) { 415 $ca->{credit} = 416 $form->format_amount( \%myconfig, $ca->{amount}, 2, " " ); 417 } 418 if ( $ca->{amount} < 0 ) { 419 $ca->{debit} = 420 $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " ); 421 } 422 423 $ca->{link} =~ s/:/<br>/og; 424 425 $gifi_accno = $form->escape( $ca->{gifi_accno} ); 426 427 if ( $ca->{charttype} eq "H" ) { 428 print qq|<tr class="listheading">|; 429 430 $column_data{accno} = 431qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|; 432 $column_data{gifi_accno} = 433qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a> </th>|; 434 $column_data{description} = 435 qq|<th class="listheading">$ca->{description} </th>|; 436 $column_data{debit} = qq|<th> </th>|; 437 $column_data{credit} = qq| <th> </th>|; 438 $column_data{link} = qq|<th> </th>|; 439 440 } 441 else { 442 $i++; 443 $i %= 2; 444 print qq| 445<tr valign=top class="listrow$i">|; 446 $column_data{accno} = 447qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|; 448 $column_data{gifi_accno} = 449qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a> </td>|; 450 $column_data{description} = qq|<td>$ca->{description} </td>|; 451 $column_data{debit} = qq|<td align="right">$ca->{debit}</td>|; 452 $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|; 453 $column_data{link} = qq|<td>$ca->{link} </td>|; 454 455 } 456 457 for (@column_index) { print "$column_data{$_}\n" } 458 459 print "</tr>\n"; 460 } 461 462 print qq| 463 <tr><td colspan="$colspan"><hr size="3" noshade /></td></tr> 464</table> 465 466</body> 467</html> 468|; 469 470} 471 472sub delete_account { 473 474 $form->{title} = $locale->text('Delete Account'); 475 476 foreach $id ( 477 qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id) 478 ) 479 { 480 if ( $form->{id} == $form->{$id} ) { 481 $form->error( $locale->text('Cannot delete default account!') ); 482 } 483 } 484 485 if ( AM->delete_account( \%myconfig, \%$form ) ) { 486 $form->redirect( $locale->text('Account deleted!') ); 487 } 488 else { 489 $form->error( $locale->text('Cannot delete account!') ); 490 } 491 492} 493 494sub list_gifi { 495 496 @{ $form->{fields} } = qw(accno description); 497 $form->{table} = "gifi"; 498 499 AM->gifi_accounts( \%myconfig, \%$form ); 500 501 $form->{title} = $locale->text('GIFI'); 502 503 # construct callback 504 $callback = 505"$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 506 507 @column_index = qw(accno description); 508 509 $column_header{accno} = 510 qq|<th class="listheading">| . $locale->text('GIFI') . qq|</a></th>|; 511 $column_header{description} = 512 qq|<th class="listheading">| 513 . $locale->text('Description') 514 . qq|</a></th>|; 515 516 $form->header; 517 $colspan = $#column_index + 1; 518 519 print qq| 520<body> 521 522<table width=100%> 523 <tr> 524 <th class=listtop colspan=$colspan>$form->{title}</th> 525 </tr> 526 <tr height="5"></tr> 527 <tr class="listheading"> 528|; 529 530 for (@column_index) { print "$column_header{$_}\n" } 531 532 print qq| 533</tr> 534|; 535 536 # escape callback 537 $callback = $form->escape($callback); 538 539 foreach $ca ( @{ $form->{ALL} } ) { 540 541 $i++; 542 $i %= 2; 543 544 print qq| 545<tr valign=top class=listrow$i>|; 546 547 $accno = $form->escape( $ca->{accno} ); 548 $column_data{accno} = 549qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|; 550 $column_data{description} = qq|<td>$ca->{description} </td>|; 551 552 for (@column_index) { print "$column_data{$_}\n" } 553 554 print "</tr>\n"; 555 } 556 557 print qq| 558 <tr> 559 <td colspan=$colspan><hr size=3 noshade></td> 560 </tr> 561</table> 562 563</body> 564</html> 565|; 566 567} 568 569sub add_gifi { 570 $form->{title} = "Add"; 571 572 # construct callback 573 $form->{callback} = 574"$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 575 576 $form->{coa} = 1; 577 578 &gifi_header; 579 &gifi_footer; 580 581} 582 583sub edit_gifi { 584 585 $form->{title} = "Edit"; 586 587 AM->get_gifi( \%myconfig, \%$form ); 588 589 $form->error( $locale->text('Account does not exist!') ) 590 unless $form->{accno}; 591 592 &gifi_header; 593 &gifi_footer; 594 595} 596 597sub gifi_header { 598 599 $form->{title} = $locale->text("$form->{title} GIFI"); 600 601 # $locale->text('Add GIFI') 602 # $locale->text('Edit GIFI') 603 604 for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) } 605 606 $form->header; 607 608 print qq| 609<body> 610 611<form method=post action=$form->{script}> 612 613<input type=hidden name=id value="$form->{accno}"> 614<input type=hidden name=type value=gifi> 615 616<table width=100%> 617 <tr> 618 <th class=listtop>$form->{title}</th> 619 </tr> 620 <tr height="5"></tr> 621 <tr> 622 <td> 623 <table> 624 <tr> 625 <th align="right">| . $locale->text('GIFI') . qq|</th> 626 <td><input name=accno size=20 value="$form->{accno}"></td> 627 </tr> 628 <tr> 629 <th align="right">| . $locale->text('Description') . qq|</th> 630 <td><input name=description size=60 value="$form->{description}"></td> 631 </tr> 632 </table> 633 </td> 634 </tr> 635 <tr> 636 <td colspan=2><hr size=3 noshade></td> 637 </tr> 638</table> 639|; 640 641} 642 643sub gifi_footer { 644 645 $form->hide_form(qw(callback path login sessionid)); 646 647 # type=submit $locale->text('Save') 648 # type=submit $locale->text('Copy to COA') 649 # type=submit $locale->text('Delete') 650 651 %button = (); 652 653 $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') }; 654 655 if ( $form->{accno} ) { 656 if ( $form->{orphaned} ) { 657 $button{'delete'} = 658 { ndx => 16, key => 'D', value => $locale->text('Delete') }; 659 } 660 } 661 662 if ( $form->{coa} ) { 663 $button{'copy_to_coa'} = 664 { ndx => 7, key => 'C', value => $locale->text('Copy to COA') }; 665 } 666 667 for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { 668 $form->print_button( \%button, $_ ); 669 } 670 671 if ( $form->{lynx} ) { 672 require "bin/menu.pl"; 673 &menubar; 674 } 675 676 print qq| 677 </form> 678 679</body> 680</html> 681|; 682 683} 684 685sub save_gifi { 686 687 $form->isblank( "accno", $locale->text('GIFI missing!') ); 688 AM->save_gifi( \%myconfig, \%$form ); 689 $form->redirect( $locale->text('GIFI saved!') ); 690 691} 692 693sub copy_to_coa { 694 695 $form->isblank( "accno", $locale->text('GIFI missing!') ); 696 697 AM->save_gifi( \%myconfig, \%$form ); 698 699 delete $form->{id}; 700 $form->{gifi_accno} = $form->{accno}; 701 702 $form->{title} = "Add"; 703 $form->{charttype} = "A"; 704 705 &account_header; 706 &form_footer; 707 708} 709 710sub delete_gifi { 711 712 AM->delete_gifi( \%myconfig, \%$form ); 713 $form->redirect( $locale->text('GIFI deleted!') ); 714 715} 716 717sub add_department { 718 719 $form->{title} = "Add"; 720 $form->{role} = "P"; 721 722 $form->{callback} = 723"$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 724 unless $form->{callback}; 725 726 &department_header; 727 &form_footer; 728 729} 730 731sub edit_department { 732 733 $form->{title} = "Edit"; 734 735 AM->get_department( \%myconfig, \%$form ); 736 737 &department_header; 738 &form_footer; 739 740} 741 742sub list_department { 743 744 AM->departments( \%myconfig, \%$form ); 745 746 $href = 747"$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 748 749 $form->sort_order(); 750 751 $form->{callback} = 752"$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 753 754 $callback = $form->escape( $form->{callback} ); 755 756 $form->{title} = $locale->text('Departments'); 757 758 @column_index = qw(description cost profit); 759 760 $column_header{description} = 761 qq|<th width=90%><a class="listheading" href=$href>| 762 . $locale->text('Description') 763 . qq|</a></th>|; 764 $column_header{cost} = 765 qq|<th class="listheading" nowrap>| 766 . $locale->text('Cost Center') 767 . qq|</th>|; 768 $column_header{profit} = 769 qq|<th class="listheading" nowrap>| 770 . $locale->text('Profit Center') 771 . qq|</th>|; 772 773 $form->header; 774 775 print qq| 776<body> 777 778<table width=100%> 779 <tr> 780 <th class=listtop>$form->{title}</th> 781 </tr> 782 <tr height="5"></tr> 783 <tr> 784 <td> 785 <table width=100%> 786 <tr class="listheading"> 787|; 788 789 for (@column_index) { print "$column_header{$_}\n" } 790 791 print qq| 792 </tr> 793|; 794 795 foreach $ref ( @{ $form->{ALL} } ) { 796 797 $i++; 798 $i %= 2; 799 800 print qq| 801 <tr valign=top class=listrow$i> 802|; 803 804 $costcenter = ( $ref->{role} eq "C" ) ? "*" : " "; 805 $profitcenter = ( $ref->{role} eq "P" ) ? "*" : " "; 806 807 $column_data{description} = 808qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|; 809 $column_data{cost} = qq|<td align=center>$costcenter</td>|; 810 $column_data{profit} = qq|<td align=center>$profitcenter</td>|; 811 812 for (@column_index) { print "$column_data{$_}\n" } 813 814 print qq| 815 </tr> 816|; 817 } 818 819 print qq| 820 </table> 821 </td> 822 </tr> 823 <tr> 824 <td><hr size=3 noshade></td> 825 </tr> 826</table> 827 828<br> 829<form method=post action=$form->{script}> 830|; 831 832 $form->{type} = "department"; 833 834 $form->hide_form(qw(type callback path login sessionid)); 835 836 print qq| 837<button class="submit" type="submit" name="action" value="add_department">| 838 . $locale->text('Add Department') 839 . qq|</button>|; 840 841 if ( $form->{lynx} ) { 842 require "bin/menu.pl"; 843 &menubar; 844 } 845 846 print qq| 847 </form> 848 849 </body> 850 </html> 851|; 852 853} 854 855sub department_header { 856 857 $form->{title} = $locale->text("$form->{title} Department"); 858 859 # $locale->text('Add Department') 860 # $locale->text('Edit Department') 861 862 $form->{description} = $form->quote( $form->{description} ); 863 864 if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { 865 $description = 866qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|; 867 } 868 else { 869 $description = 870 qq|<input name=description size=60 value="$form->{description}">|; 871 } 872 873 $costcenter = "checked" if $form->{role} eq "C"; 874 $profitcenter = "checked" if $form->{role} eq "P"; 875 876 $form->header; 877 878 print qq| 879<body> 880 881<form method=post action=$form->{script}> 882 883<input type=hidden name=id value=$form->{id}> 884<input type=hidden name=type value=department> 885 886<table width=100%> 887 <tr> 888 <th class=listtop colspan=2>$form->{title}</th> 889 </tr> 890 <tr height="5"></tr> 891 <tr> 892 <th align="right">| . $locale->text('Description') . qq|</th> 893 <td>$description</td> 894 </tr> 895 <tr> 896 <td></td> 897 <td><input type=radio style=radio name=role value="C" $costcenter> | 898 . $locale->text('Cost Center') . qq| 899 <input type=radio style=radio name=role value="P" $profitcenter> | 900 . $locale->text('Profit Center') . qq| 901 </td> 902 <tr> 903 <td colspan=2><hr size=3 noshade></td> 904 </tr> 905</table> 906|; 907 908} 909 910sub save_department { 911 912 $form->isblank( "description", $locale->text('Description missing!') ); 913 AM->save_department( \%myconfig, \%$form ); 914 $form->redirect( $locale->text('Department saved!') ); 915 916} 917 918sub delete_department { 919 920 AM->delete_department( \%myconfig, \%$form ); 921 $form->redirect( $locale->text('Department deleted!') ); 922 923} 924 925sub add_business { 926 927 $form->{title} = "Add"; 928 929 $form->{callback} = 930"$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 931 unless $form->{callback}; 932 933 &business_header; 934 &form_footer; 935 936} 937 938sub edit_business { 939 940 $form->{title} = "Edit"; 941 942 AM->get_business( \%myconfig, \%$form ); 943 944 &business_header; 945 946 $form->{orphaned} = 1; 947 &form_footer; 948 949} 950 951sub list_business { 952 953 AM->business( \%myconfig, \%$form ); 954 955 $href = 956"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 957 958 $form->sort_order(); 959 960 $form->{callback} = 961"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 962 963 $callback = $form->escape( $form->{callback} ); 964 965 $form->{title} = $locale->text('Type of Business'); 966 967 @column_index = qw(description discount); 968 969 $column_header{description} = 970 qq|<th width=90%><a class="listheading" href=$href>| 971 . $locale->text('Description') 972 . qq|</a></th>|; 973 $column_header{discount} = 974 qq|<th class="listheading">| . $locale->text('Discount') . qq| %</th>|; 975 976 $form->header; 977 978 print qq| 979<body> 980 981<table width=100%> 982 <tr> 983 <th class=listtop>$form->{title}</th> 984 </tr> 985 <tr height="5"></tr> 986 <tr> 987 <td> 988 <table width=100%> 989 <tr class="listheading"> 990|; 991 992 for (@column_index) { print "$column_header{$_}\n" } 993 994 print qq| 995 </tr> 996|; 997 998 foreach $ref ( @{ $form->{ALL} } ) { 999 1000 $i++; 1001 $i %= 2; 1002 1003 print qq| 1004 <tr valign=top class=listrow$i> 1005|; 1006 1007 $discount = 1008 $form->format_amount( \%myconfig, $ref->{discount} * 100, 2, 1009 " " ); 1010 1011 $column_data{description} = 1012qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|; 1013 $column_data{discount} = qq|<td align="right">$discount</td>|; 1014 1015 for (@column_index) { print "$column_data{$_}\n" } 1016 1017 print qq| 1018 </tr> 1019|; 1020 } 1021 1022 print qq| 1023 </table> 1024 </td> 1025 </tr> 1026 <tr> 1027 <td><hr size=3 noshade></td> 1028 </tr> 1029</table> 1030 1031<br> 1032<form method=post action=$form->{script}> 1033|; 1034 1035 $form->{type} = "business"; 1036 1037 $form->hide_form(qw(type callback path login sessionid)); 1038 1039 print qq| 1040<button class="submit" type="submit" name="action" value="add_business">| 1041 . $locale->text('Add Business') 1042 . qq|</button>|; 1043 1044 if ( $form->{lynx} ) { 1045 require "bin/menu.pl"; 1046 &menubar; 1047 } 1048 1049 print qq| 1050 1051 </form> 1052 1053 </body> 1054 </html> 1055|; 1056 1057} 1058 1059sub business_header { 1060 1061 $form->{title} = $locale->text("$form->{title} Business"); 1062 1063 # $locale->text('Add Business') 1064 # $locale->text('Edit Business') 1065 1066 $form->{description} = $form->quote( $form->{description} ); 1067 $form->{discount} = 1068 $form->format_amount( \%myconfig, $form->{discount} * 100 ); 1069 1070 $form->header; 1071 1072 print qq| 1073<body> 1074 1075<form method=post action=$form->{script}> 1076 1077<input type=hidden name=id value=$form->{id}> 1078<input type=hidden name=type value=business> 1079 1080<table width=100%> 1081 <tr> 1082 <th class=listtop>$form->{title}</th> 1083 </tr> 1084 <tr height="5"></tr> 1085 <tr> 1086 <td> 1087 <table> 1088 <tr> 1089 <th align="right">| . $locale->text('Type of Business') . qq|</th> 1090 <td><input name=description size=30 value="$form->{description}"></td> 1091 <tr> 1092 <tr> 1093 <th align="right">| . $locale->text('Discount') . qq| %</th> 1094 <td><input name=discount size=5 value=$form->{discount}></td> 1095 </tr> 1096 </table> 1097 </td> 1098 </tr> 1099 <tr> 1100 <td><hr size=3 noshade></td> 1101 </tr> 1102</table> 1103|; 1104 1105} 1106 1107sub save_business { 1108 1109 $form->isblank( "description", $locale->text('Description missing!') ); 1110 AM->save_business( \%myconfig, \%$form ); 1111 $form->redirect( $locale->text('Business saved!') ); 1112 1113} 1114 1115sub delete_business { 1116 1117 AM->delete_business( \%myconfig, \%$form ); 1118 $form->redirect( $locale->text('Business deleted!') ); 1119 1120} 1121 1122sub add_sic { 1123 1124 $form->{title} = "Add"; 1125 1126 $form->{callback} = 1127"$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 1128 unless $form->{callback}; 1129 1130 &sic_header; 1131 &form_footer; 1132 1133} 1134 1135sub edit_sic { 1136 1137 $form->{title} = "Edit"; 1138 1139 $form->{code} =~ s/\\'/'/g; 1140 $form->{code} =~ s/\\\\/\\/g; 1141 1142 AM->get_sic( \%myconfig, \%$form ); 1143 $form->{id} = $form->{code}; 1144 1145 &sic_header; 1146 1147 $form->{orphaned} = 1; 1148 &form_footer; 1149 1150} 1151 1152sub list_sic { 1153 1154 AM->sic( \%myconfig, \%$form ); 1155 1156 $href = 1157"$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1158 1159 $form->sort_order(); 1160 1161 $form->{callback} = 1162"$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1163 1164 $callback = $form->escape( $form->{callback} ); 1165 1166 $form->{title} = $locale->text('Standard Industrial Codes'); 1167 1168 @column_index = $form->sort_columns(qw(code description)); 1169 1170 $column_header{code} = 1171 qq|<th><a class="listheading" href=$href&sort=code>| 1172 . $locale->text('Code') 1173 . qq|</a></th>|; 1174 $column_header{description} = 1175 qq|<th><a class="listheading" href=$href&sort=description>| 1176 . $locale->text('Description') 1177 . qq|</a></th>|; 1178 1179 $form->header; 1180 1181 print qq| 1182<body> 1183 1184<table width=100%> 1185 <tr> 1186 <th class=listtop>$form->{title}</th> 1187 </tr> 1188 <tr height="5"></tr> 1189 <tr> 1190 <td> 1191 <table width=100%> 1192 <tr class="listheading"> 1193|; 1194 1195 for (@column_index) { print "$column_header{$_}\n" } 1196 1197 print qq| 1198 </tr> 1199|; 1200 1201 foreach $ref ( @{ $form->{ALL} } ) { 1202 1203 $i++; 1204 $i %= 2; 1205 1206 if ( $ref->{sictype} eq 'H' ) { 1207 print qq| 1208 <tr valign=top class="listheading"> 1209|; 1210 $column_data{code} = 1211qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</th>|; 1212 $column_data{description} = qq|<th>$ref->{description}</th>|; 1213 1214 } 1215 else { 1216 print qq| 1217 <tr valign=top class=listrow$i> 1218|; 1219 1220 $column_data{code} = 1221qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|; 1222 $column_data{description} = qq|<td>$ref->{description}</td>|; 1223 1224 } 1225 1226 for (@column_index) { print "$column_data{$_}\n" } 1227 1228 print qq| 1229 </tr> 1230|; 1231 } 1232 1233 print qq| 1234 </table> 1235 </td> 1236 </tr> 1237 <tr> 1238 <td><hr size=3 noshade></td> 1239 </tr> 1240</table> 1241 1242<br> 1243<form method=post action=$form->{script}> 1244|; 1245 1246 $form->{type} = "sic"; 1247 1248 $form->hide_form(qw(type callback path login sessionid)); 1249 1250 print qq| 1251<button class="submit" type="submit" name="action" value="add_sic">| 1252 . $locale->text('Add SIC') 1253 . qq|</button>|; 1254 1255 if ( $form->{lynx} ) { 1256 require "bin/menu.pl"; 1257 &menubar; 1258 } 1259 1260 print qq| 1261 </form> 1262 1263 </body> 1264 </html> 1265|; 1266 1267} 1268 1269sub sic_header { 1270 1271 $form->{title} = $locale->text("$form->{title} SIC"); 1272 1273 # $locale->text('Add SIC') 1274 # $locale->text('Edit SIC') 1275 1276 for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) } 1277 1278 $checked = ( $form->{sictype} eq 'H' ) ? "checked" : ""; 1279 1280 $form->header; 1281 1282 print qq| 1283<body> 1284 1285<form method=post action=$form->{script}> 1286 1287<input type=hidden name=type value=sic> 1288<input type=hidden name=id value="$form->{code}"> 1289 1290<table width=100%> 1291 <tr> 1292 <th class=listtop colspan=2>$form->{title}</th> 1293 </tr> 1294 <tr height="5"></tr> 1295 <tr> 1296 <th align="right">| . $locale->text('Code') . qq|</th> 1297 <td><input name=code size=10 value="$form->{code}"></td> 1298 <tr> 1299 <tr> 1300 <td></td> 1301 <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> | 1302 . $locale->text('Heading') 1303 . qq|</th> 1304 <tr> 1305 <tr> 1306 <th align="right">| . $locale->text('Description') . qq|</th> 1307 <td><input name=description size=60 value="$form->{description}"></td> 1308 </tr> 1309 <td colspan=2><hr size=3 noshade></td> 1310 </tr> 1311</table> 1312|; 1313 1314} 1315 1316sub save_sic { 1317 1318 $form->isblank( "code", $locale->text('Code missing!') ); 1319 $form->isblank( "description", $locale->text('Description missing!') ); 1320 AM->save_sic( \%myconfig, \%$form ); 1321 $form->redirect( $locale->text('SIC saved!') ); 1322 1323} 1324 1325sub delete_sic { 1326 1327 AM->delete_sic( \%myconfig, \%$form ); 1328 $form->redirect( $locale->text('SIC deleted!') ); 1329 1330} 1331 1332sub add_language { 1333 1334 $form->{title} = "Add"; 1335 1336 $form->{callback} = 1337"$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 1338 unless $form->{callback}; 1339 1340 &language_header; 1341 &form_footer; 1342 1343} 1344 1345sub edit_language { 1346 1347 $form->{title} = "Edit"; 1348 1349 $form->{code} =~ s/\\'/'/g; 1350 $form->{code} =~ s/\\\\/\\/g; 1351 1352 AM->get_language( \%myconfig, \%$form ); 1353 $form->{id} = $form->{code}; 1354 1355 &language_header; 1356 1357 $form->{orphaned} = 1; 1358 &form_footer; 1359 1360} 1361 1362sub list_language { 1363 1364 AM->language( \%myconfig, \%$form ); 1365 1366 $href = 1367"$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1368 1369 $form->sort_order(); 1370 1371 $form->{callback} = 1372"$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1373 1374 $callback = $form->escape( $form->{callback} ); 1375 1376 $form->{title} = $locale->text('Languages'); 1377 1378 @column_index = $form->sort_columns(qw(code description)); 1379 1380 $column_header{code} = 1381 qq|<th><a class="listheading" href=$href&sort=code>| 1382 . $locale->text('Code') 1383 . qq|</a></th>|; 1384 $column_header{description} = 1385 qq|<th><a class="listheading" href=$href&sort=description>| 1386 . $locale->text('Description') 1387 . qq|</a></th>|; 1388 1389 $form->header; 1390 1391 print qq| 1392<body> 1393 1394<table width=100%> 1395 <tr> 1396 <th class=listtop>$form->{title}</th> 1397 </tr> 1398 <tr height="5"></tr> 1399 <tr> 1400 <td> 1401 <table width=100%> 1402 <tr class="listheading"> 1403|; 1404 1405 for (@column_index) { print "$column_header{$_}\n" } 1406 1407 print qq| 1408 </tr> 1409|; 1410 1411 foreach $ref ( @{ $form->{ALL} } ) { 1412 1413 $i++; 1414 $i %= 2; 1415 1416 print qq| 1417 <tr valign=top class=listrow$i> 1418|; 1419 1420 $column_data{code} = 1421qq|<td><a href=$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|; 1422 $column_data{description} = qq|<td>$ref->{description}</td>|; 1423 1424 for (@column_index) { print "$column_data{$_}\n" } 1425 1426 print qq| 1427 </tr> 1428|; 1429 } 1430 1431 print qq| 1432 </table> 1433 </td> 1434 </tr> 1435 <tr> 1436 <td><hr size=3 noshade></td> 1437 </tr> 1438</table> 1439 1440<br> 1441<form method=post action=$form->{script}> 1442|; 1443 1444 $form->{type} = "language"; 1445 1446 $form->hide_form(qw(type callback path login sessionid)); 1447 1448 print qq| 1449<button class="submit" type="submit" name="action" value="add_language">| 1450 . $locale->text('Add Language') 1451 . qq|</button>|; 1452 1453 if ( $form->{lynx} ) { 1454 require "bin/menu.pl"; 1455 &menubar; 1456 } 1457 1458 print qq| 1459 </form> 1460 1461 </body> 1462 </html> 1463|; 1464 1465} 1466 1467sub language_header { 1468 1469 $form->{title} = $locale->text("$form->{title} Language"); 1470 1471 # $locale->text('Add Language') 1472 # $locale->text('Edit Language') 1473 1474 for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) } 1475 1476 $form->header; 1477 1478 print qq| 1479<body> 1480 1481<form method=post action=$form->{script}> 1482 1483<input type=hidden name=type value=language> 1484<input type=hidden name=id value="$form->{code}"> 1485 1486<table width=100%> 1487 <tr> 1488 <th class=listtop colspan=2>$form->{title}</th> 1489 </tr> 1490 <tr height="5"></tr> 1491 <tr> 1492 <th align="right">| . $locale->text('Code') . qq|</th> 1493 <td><input name=code size=10 value="$form->{code}"></td> 1494 <tr> 1495 <tr> 1496 <th align="right">| . $locale->text('Description') . qq|</th> 1497 <td><input name=description size=60 value="$form->{description}"></td> 1498 </tr> 1499 <td colspan=2><hr size=3 noshade></td> 1500 </tr> 1501</table> 1502|; 1503 1504} 1505 1506sub save_language { 1507 1508 $form->isblank( "code", $locale->text('Code missing!') ); 1509 $form->isblank( "description", $locale->text('Description missing!') ); 1510 1511 $form->{code} =~ s/(\.\.|\*)//g; 1512 1513 AM->save_language( \%myconfig, \%$form ); 1514 1515 if ( !-d "$myconfig{templates}/$form->{code}" ) { 1516 1517 umask(002); 1518 1519 if ( mkdir "$myconfig{templates}/$form->{code}", oct("771") ) { 1520 1521 umask(007); 1522 1523 opendir TEMPLATEDIR, "$myconfig{templates}" 1524 or $form->error("$myconfig{templates} : $!"); 1525 @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR; 1526 closedir TEMPLATEDIR; 1527 1528 foreach $file (@templates) { 1529 if ( -f "$myconfig{templates}/$file" ) { 1530 open( TEMP, '<', "$myconfig{templates}/$file" ) 1531 or $form->error("$myconfig{templates}/$file : $!"); 1532 1533 open( NEW, '>', "$myconfig{templates}/$form->{code}/$file" ) 1534 or $form->error( 1535 "$myconfig{templates}/$form->{code}/$file : $!"); 1536 1537 while ( $line = <TEMP> ) { 1538 print NEW $line; 1539 } 1540 close(TEMP); 1541 close(NEW); 1542 } 1543 } 1544 } 1545 else { 1546 $form->error("${templates}/$form->{code} : $!"); 1547 } 1548 } 1549 1550 $form->redirect( $locale->text('Language saved!') ); 1551 1552} 1553 1554sub delete_language { 1555 1556 $form->{title} = $locale->text('Confirm!'); 1557 1558 $form->header; 1559 1560 print qq| 1561<body> 1562 1563<form method=post action=$form->{script}> 1564|; 1565 1566 for (qw(action nextsub)) { delete $form->{$_} } 1567 1568 $form->hide_form; 1569 1570 print qq| 1571<h2 class=confirm>$form->{title}</h2> 1572 1573<h4>| 1574 . $locale->text( 1575'Deleting a language will also delete the templates for the language [_1]', 1576 $form->{invnumber} 1577 ) 1578 . qq|</h4> 1579 1580<input type=hidden name=action value=continue> 1581<input type=hidden name=nextsub value=yes_delete_language> 1582<button name="action" class="submit" type="submit" value="continue">| 1583 . $locale->text('Continue') 1584 . qq|</button> 1585</form> 1586 1587</body> 1588</html> 1589|; 1590 1591} 1592 1593sub yes_delete_language { 1594 1595 AM->delete_language( \%myconfig, \%$form ); 1596 1597 # delete templates 1598 $dir = "$myconfig{templates}/$form->{code}"; 1599 if ( -d $dir ) { 1600 unlink <$dir/*>; 1601 rmdir "$myconfig{templates}/$form->{code}"; 1602 } 1603 $form->redirect( $locale->text('Language deleted!') ); 1604 1605} 1606 1607sub display_stylesheet { 1608 1609 $form->{file} = "css/$myconfig{stylesheet}"; 1610 &display_form; 1611 1612} 1613 1614sub list_templates { 1615 1616 AM->language( \%myconfig, \%$form ); 1617 1618 if ( !@{ $form->{ALL} } ) { 1619 &display_form; 1620 exit; 1621 } 1622 1623 unshift @{ $form->{ALL} }, 1624 { code => '.', description => $locale->text('Default Template') }; 1625 1626 $href = 1627"$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1628 1629 $form->sort_order(); 1630 1631 $form->{callback} = 1632"$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 1633 1634 $callback = $form->escape( $form->{callback} ); 1635 1636 chomp $myconfig{templates}; 1637 $form->{file} =~ s/$myconfig{templates}//; 1638 $form->{file} =~ s/\///; 1639 $form->{title} = $form->{file}; 1640 1641 @column_index = $form->sort_columns(qw(code description)); 1642 1643 $column_header{code} = 1644 qq|<th><a class="listheading" href=$href&sort=code>| 1645 . $locale->text('Code') 1646 . qq|</a></th>|; 1647 $column_header{description} = 1648 qq|<th><a class="listheading" href=$href&sort=description>| 1649 . $locale->text('Description') 1650 . qq|</a></th>|; 1651 1652 $form->header; 1653 1654 print qq| 1655<body> 1656 1657<table width=100%> 1658 <tr> 1659 <th class=listtop>$form->{title}</th> 1660 </tr> 1661 <tr height="5"></tr> 1662 <tr> 1663 <td> 1664 <table width=100%> 1665 <tr class="listheading"> 1666|; 1667 1668 for (@column_index) { print "$column_header{$_}\n" } 1669 1670 print qq| 1671 </tr> 1672|; 1673 1674 foreach $ref ( @{ $form->{ALL} } ) { 1675 1676 $i++; 1677 $i %= 2; 1678 1679 print qq| 1680 <tr valign=top class=listrow$i> 1681|; 1682 1683 $column_data{code} = 1684qq|<td><a href=$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback>$ref->{code}</td>|; 1685 $column_data{description} = qq|<td>$ref->{description}</td>|; 1686 1687 for (@column_index) { print "$column_data{$_}\n" } 1688 1689 print qq| 1690 </tr> 1691|; 1692 } 1693 1694 print qq| 1695 </table> 1696 </td> 1697 </tr> 1698 <tr> 1699 <td><hr size=3 noshade></td> 1700 </tr> 1701</table> 1702 1703<br> 1704<form method=post action=$form->{script}> 1705 1706<input name=callback type=hidden value="$form->{callback}"> 1707 1708<input type=hidden name=type value=language> 1709 1710<input type=hidden name=path value=$form->{path}> 1711<input type=hidden name=login value=$form->{login}> 1712<input type=hidden name=sessionid value=$form->{sessionid}> 1713|; 1714 1715 if ( $form->{lynx} ) { 1716 require "bin/menu.pl"; 1717 &menubar; 1718 } 1719 1720 print qq| 1721 </form> 1722 1723 </body> 1724 </html> 1725|; 1726 1727} 1728 1729sub display_form { 1730 1731 AM->load_template( \%myconfig, \%$form ); 1732 1733 $form->{title} = $form->{file}; 1734 1735 $form->{body} =~ 1736s/<%include (.*?)%>/<a href=$form->{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g; 1737 1738 # if it is anything but html 1739 if ( $form->{file} !~ /\.html$/ ) { 1740 $form->{body} = "<pre>\n$form->{body}\n</pre>"; 1741 } 1742 1743 $form->header; 1744 1745 print qq| 1746<body> 1747 1748$form->{body} 1749 1750<form method=post action=$form->{script}> 1751|; 1752 1753 $form->{type} = "template"; 1754 1755 $form->hide_form(qw(file type path login sessionid)); 1756 1757 print qq| 1758<button name="action" type="submit" class="submit" value="edit">| 1759 . $locale->text('Edit') 1760 . qq|</button>|; 1761 1762 if ( $form->{lynx} ) { 1763 require "bin/menu.pl"; 1764 &menubar; 1765 } 1766 1767 print qq| 1768 </form> 1769 1770</body> 1771</html> 1772|; 1773 1774} 1775 1776sub edit_template { 1777 1778 AM->load_template( \%myconfig, \%$form ); 1779 1780 $form->{title} = $locale->text('Edit Template'); 1781 1782 # convert   to &nbsp; 1783 $form->{body} =~ s/ /&nbsp;/gi; 1784 1785 $form->header; 1786 1787 print qq| 1788<body> 1789 1790<form method=post action=$form->{script}> 1791 1792<input name=file type=hidden value=$form->{file}> 1793<input name=type type=hidden value=template> 1794 1795<input type=hidden name=path value=$form->{path}> 1796<input type=hidden name=login value=$form->{login}> 1797<input type=hidden name=sessionid value=$form->{sessionid}> 1798 1799<input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"> 1800 1801<textarea name=body rows=25 cols=70> 1802$form->{body} 1803</textarea> 1804 1805<br> 1806<button type="submit" class="submit" name="action" value="save">| 1807 . $locale->text('Save') 1808 . qq|</button>|; 1809 1810 if ( $form->{lynx} ) { 1811 require "bin/menu.pl"; 1812 &menubar; 1813 } 1814 1815 print q| 1816 </form> 1817 1818 1819</body> 1820</html> 1821|; 1822 1823} 1824 1825sub save_template { 1826 1827 AM->save_template( \%myconfig, \%$form ); 1828 $form->redirect( $locale->text('Template saved!') ); 1829 1830} 1831 1832sub defaults { 1833 1834 # get defaults for account numbers and last numbers 1835 AM->get_all_defaults( \%$form ); 1836 1837 foreach $key ( keys %{ $form->{accno} } ) { 1838 foreach $accno ( sort keys %{ $form->{accno}{$key} } ) { 1839 $form->{account}{$key} .= 1840 "<option>$accno--$form->{accno}{$key}{$accno}{description}\n"; 1841 $form->{accno}{ $form->{accno}{$key}{$accno}{id} } = $accno; 1842 } 1843 } 1844 1845 for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) { 1846 $form->{account}{$_} =~ 1847s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/; 1848 } 1849 1850 for (qw(accno defaults)) { delete $form->{$_} } 1851 1852 $form->{title} = $locale->text('System Defaults'); 1853 1854 $form->header; 1855 1856 print qq| 1857<body> 1858 1859<form method=post action=$form->{script}> 1860 1861<input type=hidden name=type value=defaults> 1862 1863<table width=100%> 1864 <tr><th class=listtop>$form->{title}</th></tr> 1865 <tr> 1866 <td> 1867 <table> 1868 <tr> 1869 <th align="right">| . $locale->text('Business Number') . qq|</th> 1870 <td><input name=businessnumber size=25 value="$form->{businessnumber}"></td> 1871 </tr> 1872 <tr> 1873 <th align="right">| . $locale->text('Weight Unit') . qq|</th> 1874 <td><input name=weightunit size=5 value="$form->{weightunit}"></td> 1875 </tr> 1876 </table> 1877 </td> 1878 </tr> 1879 <tr> 1880 <th class="listheading">| 1881 . $locale->text('Last Numbers & Default Accounts') 1882 . qq|</th> 1883 </tr> 1884 <tr> 1885 <td> 1886 <table> 1887 <tr> 1888 <th align="right" nowrap>| . $locale->text('Inventory') . qq|</th> 1889 <td><select name=IC>$form->{account}{IC}</select></td> 1890 </tr> 1891 <tr> 1892 <th align="right" nowrap>| . $locale->text('Income') . qq|</th> 1893 <td><select name=IC_income>$form->{account}{IC_income}</select></td> 1894 </tr> 1895 <tr> 1896 <th align="right" nowrap>| . $locale->text('Expense') . qq|</th> 1897 <td><select name=IC_expense>$form->{account}{IC_expense}</select></td> 1898 </tr> 1899 <tr> 1900 <th align="right" nowrap>| 1901 . $locale->text('Foreign Exchange Gain') 1902 . qq|</th> 1903 <td><select name=FX_gain>$form->{account}{FX_gain}</select></td> 1904 </tr> 1905 <tr> 1906 <th align="right" nowrap>| 1907 . $locale->text('Foreign Exchange Loss') 1908 . qq|</th> 1909 <td><select name=FX_loss>$form->{account}{FX_loss}</select></td> 1910 </tr> 1911 </table> 1912 </td> 1913 </tr> 1914 <tr> 1915 <th align=left>| 1916 . $locale->text( 1917'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' 1918 ) 1919 . qq|</th> 1920 </tr> 1921 <tr> 1922 <td> 1923 <input name=curr size=40 value="$form->{curr}"> 1924 </td> 1925 </tr> 1926 <tr> 1927 <td> 1928 <table> 1929 <tr> 1930 <th align="right" nowrap>| . $locale->text('GL Reference Number') . qq|</th> 1931 <td><input name=glnumber size=40 value="$form->{glnumber}"></td> 1932 </tr> 1933 <tr> 1934 <th align="right" nowrap>| 1935 . $locale->text('Sales Invoice/AR Transaction Number') 1936 . qq|</th> 1937 <td><input name=sinumber size=40 value="$form->{sinumber}"></td> 1938 </tr> 1939 <tr> 1940 <th align="right" nowrap>| . $locale->text('Sales Order Number') . qq|</th> 1941 <td><input name=sonumber size=40 value="$form->{sonumber}"></td> 1942 </tr> 1943 <tr> 1944 <th align="right" nowrap>| 1945 . $locale->text('Vendor Invoice/AP Transaction Number') 1946 . qq|</th> 1947 <td><input name=vinumber size=40 value="$form->{vinumber}"></td> 1948 </tr> 1949 <tr> 1950 <th align="right" nowrap>| 1951 . $locale->text('Purchase Order Number') 1952 . qq|</th> 1953 <td><input name=ponumber size=40 value="$form->{ponumber}"></td> 1954 </tr> 1955 <tr> 1956 <th align="right" nowrap>| 1957 . $locale->text('Sales Quotation Number') 1958 . qq|</th> 1959 <td><input name=sqnumber size=40 value="$form->{sqnumber}"></td> 1960 </tr> 1961 <tr> 1962 <th align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th> 1963 <td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td> 1964 </tr> 1965 <tr> 1966 <th align="right" nowrap>| . $locale->text('Part Number') . qq|</th> 1967 <td><input name=partnumber size=40 value="$form->{partnumber}"></td> 1968 </tr> 1969 <tr> 1970 <th align="right" nowrap>| . $locale->text('Job/Project Number') . qq|</th> 1971 <td><input name=projectnumber size=40 value="$form->{projectnumber}"></td> 1972 </tr> 1973 <tr> 1974 <th align="right" nowrap>| . $locale->text('Employee Number') . qq|</th> 1975 <td><input name=employeenumber size=40 value="$form->{employeenumber}"></td> 1976 </tr> 1977 <tr> 1978 <th align="right" nowrap>| . $locale->text('Customer Number') . qq|</th> 1979 <td><input name=customernumber size=40 value="$form->{customernumber}"></td> 1980 </tr> 1981 <tr> 1982 <th align="right" nowrap>| . $locale->text('Vendor Number') . qq|</th> 1983 <td><input name=vendornumber size=40 value="$form->{vendornumber}"></td> 1984 </tr> 1985 </table> 1986 </td> 1987 </tr> 1988 <tr> 1989 <td><hr size=3 noshade></td> 1990 </tr> 1991</table> 1992|; 1993 1994 $form->hide_form(qw(path login sessionid)); 1995 1996 print qq| 1997<button type="submit" class="submit" name="action" value="save">| 1998 . $locale->text('Save') 1999 . qq|</button>|; 2000 2001 if ( $form->{lynx} ) { 2002 require "bin/menu.pl"; 2003 &menubar; 2004 } 2005 2006 print qq| 2007 </form> 2008 2009</body> 2010</html> 2011|; 2012 2013} 2014 2015sub taxes { 2016 2017 # get tax account numbers 2018 AM->taxes( \%myconfig, \%$form ); 2019 2020 $i = 0; 2021 foreach $ref ( @{ $form->{taxrates} } ) { 2022 $i++; 2023 $form->{"taxrate_$i"} = 2024 $form->format_amount( \%myconfig, $ref->{rate} ); 2025 $form->{"taxdescription_$i"} = $ref->{description}; 2026 2027 for (qw(taxnumber validto pass taxmodulename)) { 2028 $form->{"${_}_$i"} = $ref->{$_}; 2029 } 2030 $form->{taxaccounts} .= "$ref->{id}_$i "; 2031 } 2032 chop $form->{taxaccounts}; 2033 2034 &display_taxes; 2035 2036} 2037 2038sub display_taxes { 2039 2040 $form->{title} = $locale->text('Taxes'); 2041 2042 $form->header; 2043 2044 print qq| 2045<body> 2046 2047<form method=post action=$form->{script}> 2048 2049<input type=hidden name=type value=taxes> 2050 2051<table width=100%> 2052 <tr><th class=listtop>$form->{title}</th></tr> 2053 <tr> 2054 <td> 2055 <table> 2056 <tr> 2057 <th></th> 2058 <th>| . $locale->text('Rate') . qq| (%)</th> 2059 <th>| . $locale->text('Number') . qq|</th> 2060 <th>| . $locale->text('Valid To') . qq|</th> 2061 <th>| . $locale->text('Ordering') . qq|</th> 2062 <th>| . $locale->text('Tax Rules') . qq|</th> 2063 </tr> 2064|; 2065 2066 for ( split( / /, $form->{taxaccounts} ) ) { 2067 2068 ( $null, $i ) = split /_/, $_; 2069 2070 $form->{"taxrate_$i"} = 2071 $form->format_amount( \%myconfig, $form->{"taxrate_$i"} ); 2072 2073 $form->hide_form("taxdescription_$i"); 2074 2075 print qq| 2076 <tr> 2077 <th align="right">|; 2078 2079 if ( $form->{"taxdescription_$i"} eq $sametax ) { 2080 print ""; 2081 } 2082 else { 2083 print qq|$form->{"taxdescription_$i"}|; 2084 } 2085 2086 print qq|</th> 2087 <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td> 2088 <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td> 2089 <td><input name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td> 2090 <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td> 2091 <td><select name="taxmodule_id_$i" size=1>|; 2092 foreach my $taxmodule ( sort keys %$form ) { 2093 next if ( $taxmodule !~ /^taxmodule_/ ); 2094 next if ( $taxmodule =~ /^taxmodule_id_/ ); 2095 my $modulenum = $taxmodule; 2096 $modulenum =~ s/^taxmodule_//; 2097 print '<option label="' 2098 . $form->{$taxmodule} 2099 . '" value="' 2100 . $modulenum . '"'; 2101 print " SELECTED " 2102 if $form->{$taxmodule} eq $form->{"taxmodulename_$i"}; 2103 print ">" . $form->{$taxmodule} . "</option>\n"; 2104 } 2105 print qq|</select></td> 2106 </tr> |; 2107 $sametax = $form->{"taxdescription_$i"}; 2108 2109 } 2110 2111 print qq| 2112 </table> 2113 </td> 2114 </tr> 2115 <tr> 2116 <td><hr size=3 noshade></td> 2117 </tr> 2118</table> 2119|; 2120 2121 $form->hide_form(qw(taxaccounts path login sessionid)); 2122 foreach my $taxmodule ( sort keys %$form ) { 2123 next if ( $taxmodule !~ /^taxmodule_/ ); 2124 next if ( $taxmodule =~ /^taxmodule_id_/ ); 2125 $form->hide_form("$taxmodule"); 2126 } 2127 2128 print qq| 2129<button type="submit" class="submit" name="action" value="update">| 2130 . $locale->text('Update') 2131 . qq|</button> 2132<button type="submit" class="submit" name="action" value="save_taxes">| 2133 . $locale->text('Save') 2134 . qq|</button>|; 2135 2136 if ( $form->{lynx} ) { 2137 require "bin/menu.pl"; 2138 &menubar; 2139 } 2140 2141 print qq| 2142 </form> 2143 2144</body> 2145</html> 2146|; 2147 2148} 2149 2150sub update { 2151 2152 @a = split / /, $form->{taxaccounts}; 2153 $ndx = $#a + 1; 2154 2155 foreach $item (@a) { 2156 ( $accno, $i ) = split /_/, $item; 2157 push @t, $accno; 2158 $form->{"taxmodulename_$i"} = 2159 $form->{ "taxmodule_" . $form->{"taxmodule_id_$i"} }; 2160 2161 if ( $form->{"validto_$i"} ) { 2162 $j = $i + 1; 2163 if ( $form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"} ) 2164 { 2165 2166 #insert line 2167 for ( $j = $ndx + 1 ; $j > $i ; $j-- ) { 2168 $k = $j - 1; 2169 for (qw(taxrate taxdescription taxnumber validto)) { 2170 $form->{"${_}_$j"} = $form->{"${_}_$k"}; 2171 } 2172 } 2173 $ndx++; 2174 $k = $i + 1; 2175 for (qw(taxdescription taxnumber)) { 2176 $form->{"${_}_$k"} = $form->{"${_}_$i"}; 2177 } 2178 for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" } 2179 push @t, $accno; 2180 } 2181 } 2182 else { 2183 2184 # remove line 2185 $j = $i + 1; 2186 if ( $form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"} ) 2187 { 2188 for ( $j = $i + 1 ; $j <= $ndx ; $j++ ) { 2189 $k = $j + 1; 2190 for (qw(taxrate taxdescription taxnumber validto)) { 2191 $form->{"${_}_$j"} = $form->{"${_}_$k"}; 2192 } 2193 } 2194 $ndx--; 2195 splice @t, $i - 1, 1; 2196 } 2197 } 2198 2199 } 2200 2201 $i = 1; 2202 $form->{taxaccounts} = ""; 2203 for (@t) { 2204 $form->{taxaccounts} .= "${_}_$i "; 2205 $i++; 2206 } 2207 chop $form->{taxaccounts}; 2208 2209 &display_taxes; 2210 2211} 2212 2213sub config { 2214 2215 foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) 2216 { 2217 $dateformat .= 2218 ( $item eq $myconfig{dateformat} ) 2219 ? "<option selected>$item\n" 2220 : "<option>$item\n"; 2221 } 2222 2223 my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00); 2224 push @formats, '1 000.00'; 2225 foreach $item (@formats) { 2226 $numberformat .= 2227 ( $item eq $myconfig{numberformat} ) 2228 ? "<option selected>$item\n" 2229 : "<option>$item\n"; 2230 } 2231 2232 for (qw(name company address signature)) { 2233 $myconfig{$_} = $form->quote( $myconfig{$_} ); 2234 } 2235 for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g } 2236 2237 %countrycodes = LedgerSMB::User->country_codes; 2238 $countrycodes = ''; 2239 my $selectedcode = 2240 ( $myconfig{countrycode} ) ? $myconfig{countrycode} : 'en'; 2241 2242 foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} } 2243 keys %countrycodes ) 2244 { 2245 $countrycodes .= 2246 ( $selectedcode eq $key ) 2247 ? "<option selected value=$key>$countrycodes{$key}\n" 2248 : "<option value=$key>$countrycodes{$key}\n"; 2249 } 2250 2251 opendir CSS, "css/."; 2252 @all = grep /.*\.css$/, readdir CSS; 2253 closedir CSS; 2254 2255 foreach $item (@all) { 2256 if ( $item eq $myconfig{stylesheet} ) { 2257 $selectstylesheet .= qq|<option selected>$item\n|; 2258 } 2259 else { 2260 $selectstylesheet .= qq|<option>$item\n|; 2261 } 2262 } 2263 $selectstylesheet .= "<option>\n"; 2264 2265 if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) { 2266 $selectprinter = "<option>\n"; 2267 foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) { 2268 if ( $myconfig{printer} eq $item ) { 2269 $selectprinter .= qq|<option value="$item" selected>$item\n|; 2270 } 2271 else { 2272 $selectprinter .= qq|<option value="$item">$item\n|; 2273 } 2274 } 2275 2276 $printer = qq| 2277 <tr> 2278 <th align="right">| . $locale->text('Printer') . qq|</th> 2279 <td><select name=printer>$selectprinter</select></td> 2280 </tr> 2281|; 2282 } 2283 2284 $form->{title} = 2285 $locale->text( 'Edit Preferences for [_1]', $form->{login} ); 2286 2287 $form->header; 2288 2289 print qq| 2290<body> 2291 2292<form method=post action=$form->{script}> 2293 2294<input type=hidden name=type value=preferences> 2295<input type=hidden name=role value="$myconfig{role}"> 2296 2297<table width=100%> 2298 <tr><th class=listtop>$form->{title}</th></tr> 2299 <tr> 2300 <td> 2301 <table width=100%> 2302 <tr valign=top> 2303 <td> 2304 <table> 2305 <tr> 2306 <th align="right">| . $locale->text('Name') . qq|</th> 2307 <td><input name=name size=20 value="$myconfig{name}"></td> 2308 </tr> 2309 <tr> 2310 <th align="right">| . $locale->text('E-mail') . qq|</th> 2311 <td><input name=email size=35 value="$myconfig{email}"></td> 2312 </tr> 2313 <tr valign=top> 2314 <th align="right">| . $locale->text('Signature') . qq|</th> 2315 <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td> 2316 </tr> 2317 <tr> 2318 <th align="right">| . $locale->text('Phone') . qq|</th> 2319 <td><input name=tel size=14 value="$myconfig{tel}"></td> 2320 </tr> 2321 <tr> 2322 <th align="right">| . $locale->text('Fax') . qq|</th> 2323 <td><input name=fax size=14 value="$myconfig{fax}"></td> 2324 </tr> 2325 <tr> 2326 <th align="right">| . $locale->text('Company') . qq|</th> 2327 <td><input name=company size=35 value="$myconfig{company}"></td> 2328 </tr> 2329 <tr valign=top> 2330 <th align="right">| . $locale->text('Address') . qq|</th> 2331 <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td> 2332 </tr> 2333 </table> 2334 </td> 2335 <td> 2336 <table> 2337 <tr> 2338 <th align="right">| . $locale->text('Old Password') . qq|</th> 2339 <td><input type=password name=old_password size=10 value=""></td> 2340 </tr> 2341 <tr> 2342 <th align="right">| . $locale->text('Password') . qq|</th> 2343 <td><input type=password name=new_password size=10 value="$myconfig{password}"></td> 2344 </tr> 2345 <tr> 2346 <th align="right">| . $locale->text('Confirm') . qq|</th> 2347 <td><input type=password name=confirm_password size=10></td> 2348 </tr> 2349 <tr> 2350 <th align="right">| . $locale->text('Date Format') . qq|</th> 2351 <td><select name=dateformat>$dateformat</select></td> 2352 </tr> 2353 <tr> 2354 <th align="right">| . $locale->text('Number Format') . qq|</th> 2355 <td><select name=numberformat>$numberformat</select></td> 2356 </tr> 2357 <tr> 2358 <th align="right">| . $locale->text('Dropdown Limit') . qq|</th> 2359 <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td> 2360 </tr> 2361 <tr> 2362 <th align="right">| . $locale->text('Menu Width') . qq|</th> 2363 <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td> 2364 </tr> 2365 <tr> 2366 <th align="right">| . $locale->text('Language') . qq|</th> 2367 <td><select name=countrycode>$countrycodes</select></td> 2368 </tr> 2369 <tr> 2370 <th align="right">| . $locale->text('Session Timeout') . qq|</th> 2371 <td><input name=timeout size=10 value="$myconfig{timeout}"></td> 2372 </tr> 2373 <tr> 2374 <th align="right">| . $locale->text('Stylesheet') . qq|</th> 2375 <td><select name=usestylesheet>$selectstylesheet</select></td> 2376 </tr> 2377 $printer 2378 </table> 2379 </td> 2380 </tr> 2381 </table> 2382 </td> 2383 <tr> 2384 <td><hr size=3 noshade></td> 2385 </tr> 2386</table> 2387|; 2388 2389 $form->hide_form(qw(path login sessionid)); 2390 2391 print qq| 2392<button type="submit" class="submit" name="action" value="save">| 2393 . $locale->text('Save') 2394 . qq|</button>|; 2395 2396 if ( $form->{lynx} ) { 2397 require "bin/menu.pl"; 2398 &menubar; 2399 } 2400 2401 print qq| 2402 </form> 2403 2404</body> 2405</html> 2406|; 2407 2408} 2409 2410sub save_defaults { 2411 2412 if ( AM->save_defaults( \%myconfig, \%$form ) ) { 2413 $form->redirect( $locale->text('Defaults saved!') ); 2414 } 2415 else { 2416 $form->error( $locale->text('Cannot save defaults!') ); 2417 } 2418 2419} 2420 2421sub save_taxes { 2422 2423 if ( AM->save_taxes( \%myconfig, \%$form ) ) { 2424 $form->redirect( $locale->text('Taxes saved!') ); 2425 } 2426 else { 2427 $form->error( $locale->text('Cannot save taxes!') ); 2428 } 2429 2430} 2431 2432sub save_preferences { 2433 2434 $form->{stylesheet} = $form->{usestylesheet}; 2435 2436 if ( defined $form->{confirm_password} and $form->{confirm_password} ne '') { 2437 $form->error( $locale->text('Password does not match!') ) 2438 if $form->{new_password} ne $form->{confirm_password}; 2439 } 2440 2441 if ( AM->save_preferences( \%myconfig, \%$form ) ) { 2442 $form->info( $locale->text('Preferences saved!') ); 2443 } 2444 else { 2445 $form->error( $locale->text('Cannot save preferences!') ); 2446 } 2447 2448} 2449 2450sub backup { 2451 2452 if ( $form->{media} eq 'email' ) { 2453 $form->error( 2454 $locale->text( 'No email address for [_1]', $myconfig{name} ) ) 2455 unless ( $myconfig{email} ); 2456 } 2457 2458 $SIG{INT} = 'IGNORE'; 2459 AM->backup( 2460 \%myconfig, \%$form, 2461 ${LedgerSMB::Sysconfig::userspath}, 2462 ${LedgerSMB::Sysconfig::gzip} 2463 ); 2464 2465 if ( $form->{media} eq 'email' ) { 2466 $form->redirect( 2467 $locale->text( 'Backup sent to [_1]', $myconfig{email} ) ); 2468 } 2469 2470} 2471 2472sub audit_control { 2473 2474 $form->{title} = $locale->text('Audit Control'); 2475 2476 AM->closedto( \%myconfig, \%$form ); 2477 2478 if ( $form->{revtrans} ) { 2479 $checked{revtransY} = "checked"; 2480 } 2481 else { 2482 $checked{revtransN} = "checked"; 2483 } 2484 2485 if ( $form->{audittrail} ) { 2486 $checked{audittrailY} = "checked"; 2487 } 2488 else { 2489 $checked{audittrailN} = "checked"; 2490 } 2491 2492 $form->header; 2493 2494 print qq| 2495<body> 2496 2497<form method=post action=$form->{script}> 2498 2499<input type=hidden name=path value=$form->{path}> 2500<input type=hidden name=login value=$form->{login}> 2501<input type=hidden name=sessionid value=$form->{sessionid}> 2502 2503<table width=100%> 2504 <tr><th class=listtop>$form->{title}</th></tr> 2505 <tr height="5"></tr> 2506 <tr> 2507 <td> 2508 <table> 2509 <tr> 2510 <th align="right">| 2511 . $locale->text('Enforce transaction reversal for all dates') 2512 . qq|</th> 2513 <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> | 2514 . $locale->text('Yes') 2515 . qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> | 2516 . $locale->text('No') 2517 . qq|</td> 2518 </tr> 2519 <tr> 2520 <th align="right">| . $locale->text('Close Books up to') . qq|</th> 2521 <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td> 2522 </tr> 2523 <tr> 2524 <th align="right">| . $locale->text('Activate Audit trail') . qq|</th> 2525 <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> | 2526 . $locale->text('Yes') 2527 . qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> | 2528 . $locale->text('No') 2529 . qq|</td> 2530 </tr> 2531 <tr> 2532 <th align="right">| . $locale->text('Remove Audit trail up to') . qq|</th> 2533 <td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td> 2534 </tr> 2535 </table> 2536 </td> 2537 </tr> 2538</table> 2539 2540<hr size=3 noshade> 2541 2542<br> 2543<input type=hidden name=nextsub value=doclose> 2544<input type=hidden name=action value=continue> 2545<button type="submit" class="submit" name="action" value="continue">| 2546 . $locale->text('Continue') 2547 . qq|</button> 2548 2549</form> 2550 2551</body> 2552</html> 2553|; 2554 2555} 2556 2557sub doclose { 2558 2559 AM->closebooks( \%myconfig, \%$form ); 2560 2561 if ( $form->{revtrans} ) { 2562 $msg = $locale->text('Transaction reversal enforced for all dates'); 2563 } 2564 else { 2565 2566 if ( $form->{closedto} ) { 2567 $msg = 2568 $locale->text('Transaction reversal enforced up to') . " " 2569 . $locale->date( \%myconfig, $form->{closedto}, 1 ); 2570 } 2571 else { 2572 $msg = $locale->text('Books are open'); 2573 } 2574 } 2575 2576 $msg .= "<p>"; 2577 if ( $form->{audittrail} ) { 2578 $msg .= $locale->text('Audit trail enabled'); 2579 } 2580 else { 2581 $msg .= $locale->text('Audit trail disabled'); 2582 } 2583 2584 $msg .= "<p>"; 2585 if ( $form->{removeaudittrail} ) { 2586 $msg .= 2587 $locale->text('Audit trail removed up to') . " " 2588 . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 ); 2589 } 2590 2591 $form->redirect($msg); 2592 2593} 2594 2595sub add_warehouse { 2596 2597 $form->{title} = "Add"; 2598 2599 $form->{callback} = 2600"$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" 2601 unless $form->{callback}; 2602 2603 &warehouse_header; 2604 &form_footer; 2605 2606} 2607 2608sub edit_warehouse { 2609 2610 $form->{title} = "Edit"; 2611 2612 AM->get_warehouse( \%myconfig, \%$form ); 2613 2614 &warehouse_header; 2615 &form_footer; 2616 2617} 2618 2619sub list_warehouse { 2620 2621 AM->warehouses( \%myconfig, \%$form ); 2622 2623 $href = 2624"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 2625 2626 $form->sort_order(); 2627 2628 $form->{callback} = 2629"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 2630 2631 $callback = $form->escape( $form->{callback} ); 2632 2633 $form->{title} = $locale->text('Warehouses'); 2634 2635 @column_index = qw(description); 2636 2637 $column_header{description} = 2638 qq|<th width=100%><a class="listheading" href=$href>| 2639 . $locale->text('Description') 2640 . qq|</a></th>|; 2641 2642 $form->header; 2643 2644 print qq| 2645<body> 2646 2647<table width=100%> 2648 <tr> 2649 <th class=listtop>$form->{title}</th> 2650 </tr> 2651 <tr height="5"></tr> 2652 <tr> 2653 <td> 2654 <table width=100%> 2655 <tr class="listheading"> 2656|; 2657 2658 for (@column_index) { print "$column_header{$_}\n" } 2659 2660 print qq| 2661 </tr> 2662|; 2663 2664 foreach $ref ( @{ $form->{ALL} } ) { 2665 2666 $i++; 2667 $i %= 2; 2668 2669 print qq| 2670 <tr valign=top class=listrow$i> 2671|; 2672 2673 $column_data{description} = 2674qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|; 2675 2676 for (@column_index) { print "$column_data{$_}\n" } 2677 2678 print qq| 2679 </tr> 2680|; 2681 } 2682 2683 print qq| 2684 </table> 2685 </td> 2686 </tr> 2687 <tr> 2688 <td><hr size=3 noshade></td> 2689 </tr> 2690</table> 2691 2692<br> 2693<form method=post action=$form->{script}> 2694|; 2695 2696 $form->{type} = "warehouse"; 2697 2698 $form->hide_form(qw(type callback path login sessionid)); 2699 2700 print qq| 2701<button class="submit" type="submit" name="action" value="add_warehouse">| 2702 . $locale->text('Add Warehouse') 2703 . qq|</button>|; 2704 2705 if ( $form->{lynx} ) { 2706 require "bin/menu.pl"; 2707 &menubar; 2708 } 2709 2710 print qq| 2711 </form> 2712 2713 </body> 2714 </html> 2715|; 2716 2717} 2718 2719sub warehouse_header { 2720 2721 $form->{title} = $locale->text("$form->{title} Warehouse"); 2722 2723 # $locale->text('Add Warehouse') 2724 # $locale->text('Edit Warehouse') 2725 2726 $form->{description} = $form->quote( $form->{description} ); 2727 2728 if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { 2729 $description = 2730qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|; 2731 } 2732 else { 2733 $description = 2734 qq|<input name=description size=60 value="$form->{description}">|; 2735 } 2736 2737 $form->header; 2738 2739 print qq| 2740<body> 2741 2742<form method=post action=$form->{script}> 2743 2744<input type=hidden name=id value=$form->{id}> 2745<input type=hidden name=type value=warehouse> 2746 2747<table width=100%> 2748 <tr> 2749 <th class=listtop colspan=2>$form->{title}</th> 2750 </tr> 2751 <tr height="5"></tr> 2752 <tr> 2753 <th align="right">| . $locale->text('Description') . qq|</th> 2754 <td>$description</td> 2755 </tr> 2756 <tr> 2757 <td colspan=2><hr size=3 noshade></td> 2758 </tr> 2759</table> 2760|; 2761 2762} 2763 2764sub save_warehouse { 2765 2766 $form->isblank( "description", $locale->text('Description missing!') ); 2767 AM->save_warehouse( \%myconfig, \%$form ); 2768 $form->redirect( $locale->text('Warehouse saved!') ); 2769 2770} 2771 2772sub delete_warehouse { 2773 2774 AM->delete_warehouse( \%myconfig, \%$form ); 2775 $form->redirect( $locale->text('Warehouse deleted!') ); 2776 2777} 2778 2779sub yearend { 2780 2781 AM->earningsaccounts( \%myconfig, \%$form ); 2782 $chart = ""; 2783 for ( @{ $form->{chart} } ) { 2784 $chart .= "<option>$_->{accno}--$_->{description}"; 2785 } 2786 2787 $form->{title} = $locale->text('Yearend'); 2788 $form->header; 2789 2790 print qq| 2791<body> 2792 2793<form method=post action=$form->{script}> 2794 2795<input type=hidden name=decimalplaces value=2> 2796<input type=hidden name=l_accno value=Y> 2797 2798<table width=100%> 2799 <tr> 2800 <th class=listtop>$form->{title}</th> 2801 </tr> 2802 <tr height="5"></tr> 2803 <tr> 2804 <td> 2805 <table> 2806 <tr> 2807 <th align="right">| . $locale->text('Yearend') . qq|</th> 2808 <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td> 2809 </tr> 2810 <tr> 2811 <th align="right">| . $locale->text('Reference') . qq|</th> 2812 <td><input name=reference size=20 value="| 2813 . $locale->text('Yearend') 2814 . qq|"></td> 2815 </tr> 2816 <tr> 2817 <th align="right">| . $locale->text('Description') . qq|</th> 2818 <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td> 2819 </tr> 2820 <tr> 2821 <th align="right">| . $locale->text('Retained Earnings') . qq|</th> 2822 <td><select name=accno>$chart</select></td> 2823 </tr> 2824 <tr> 2825 <th align="right">| . $locale->text('Method') . qq|</th> 2826 <td><input name=method class=radio type=radio value=accrual checked> | 2827 . $locale->text('Accrual') 2828 . qq| <input name=method class=radio type=radio value=cash> | 2829 . $locale->text('Cash') 2830 . qq|</td> 2831 </tr> 2832 </table> 2833 </td> 2834 </tr> 2835</table> 2836 2837<hr size=3 noshade> 2838 2839<input type=hidden name=nextsub value=generate_yearend> 2840|; 2841 2842 $form->hide_form(qw(path login sessionid)); 2843 2844 print qq| 2845<button class="submit" type="submit" name="action" value="continue">| 2846 . $locale->text('Continue') 2847 . qq|</button>|; 2848 2849} 2850 2851sub generate_yearend { 2852 2853 $form->isblank( "todate", $locale->text('Yearend date missing!') ); 2854 2855 RP->yearend_statement( \%myconfig, \%$form ); 2856 2857 $form->{transdate} = $form->{todate}; 2858 2859 $earnings = 0; 2860 2861 $form->{rowcount} = 1; 2862 foreach $key ( keys %{ $form->{I} } ) { 2863 if ( $form->{I}{$key}{charttype} eq "A" ) { 2864 $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this}; 2865 $earnings += $form->{I}{$key}{this}; 2866 $form->{"accno_$form->{rowcount}"} = $key; 2867 $form->{rowcount}++; 2868 $ok = 1; 2869 } 2870 } 2871 2872 foreach $key ( keys %{ $form->{E} } ) { 2873 if ( $form->{E}{$key}{charttype} eq "A" ) { 2874 $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1; 2875 $earnings += $form->{E}{$key}{this}; 2876 $form->{"accno_$form->{rowcount}"} = $key; 2877 $form->{rowcount}++; 2878 $ok = 1; 2879 } 2880 } 2881 if ( $earnings > 0 ) { 2882 $form->{"credit_$form->{rowcount}"} = $earnings; 2883 $form->{"accno_$form->{rowcount}"} = $form->{accno}; 2884 } 2885 else { 2886 $form->{"debit_$form->{rowcount}"} = $earnings * -1; 2887 $form->{"accno_$form->{rowcount}"} = $form->{accno}; 2888 } 2889 2890 if ($ok) { 2891 if ( AM->post_yearend( \%myconfig, \%$form ) ) { 2892 $form->redirect( $locale->text('Yearend posted!') ); 2893 } 2894 else { 2895 $form->error( $locale->text('Yearend posting failed!') ); 2896 } 2897 } 2898 else { 2899 $form->error('Nothing to do!'); 2900 } 2901 2902} 2903 2904sub company_logo { 2905 2906 $myconfig{address} =~ s/\\n/<br>/g; 2907 $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost}; 2908 2909 $form->{stylesheet} = $myconfig{stylesheet}; 2910 2911 $form->{title} = $locale->text('About'); 2912 2913 # create the logo screen 2914 $form->header; 2915 2916 print qq| 2917<body> 2918 2919<pre> 2920 2921</pre> 2922<center> 2923<a href="http://www.ledgersmb.org/" target="_blank"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a> 2924<h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1> 2925 2926<p> 2927| . $locale->text('Company') . qq| : 2928<p> 2929<b> 2930$myconfig{company} 2931<br>$myconfig{address} 2932</b> 2933 2934<p> 2935<table border=0> 2936 <tr> 2937 <th align="right">| . $locale->text('User') . qq|</th> 2938 <td>$myconfig{name}</td> 2939 </tr> 2940 <tr> 2941 <th align="right">| . $locale->text('Dataset') . qq|</th> 2942 <td>$myconfig{dbname}</td> 2943 </tr> 2944 <tr> 2945 <th align="right">| . $locale->text('Database Host') . qq|</th> 2946 <td>$myconfig{dbhost}</td> 2947 </tr> 2948</table> 2949 2950</center> 2951 2952</body> 2953</html> 2954|; 2955 2956} 2957 2958sub recurring_transactions { 2959 2960 # $locale->text('Day') 2961 # $locale->text('Days') 2962 # $locale->text('Month') 2963 # $locale->text('Months') 2964 # $locale->text('Week') 2965 # $locale->text('Weeks') 2966 # $locale->text('Year') 2967 # $locale->text('Years') 2968 2969 $form->{stylesheet} = $myconfig{stylesheet}; 2970 2971 $form->{title} = $locale->text('Recurring Transactions'); 2972 2973 $column_header{id} = ""; 2974 2975 AM->recurring_transactions( \%myconfig, \%$form ); 2976 2977 $href = "$form->{script}?action=recurring_transactions"; 2978 for (qw(direction oldsort path login sessionid)) { 2979 $href .= qq|&$_=$form->{$_}|; 2980 } 2981 2982 $form->sort_order(); 2983 2984 # create the logo screen 2985 $form->header; 2986 2987 @column_index = qw(ndx reference description); 2988 2989 push @column_index, 2990 qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint); 2991 2992 $column_header{reference} = 2993 qq|<th><a class="listheading" href="$href&sort=reference">| 2994 . $locale->text('Reference') 2995 . q|</a></th>|; 2996 $column_header{ndx} = q|<th class="listheading"> </th>|; 2997 $column_header{id} = 2998 q|<th class="listheading">| . $locale->text('ID') . q|</th>|; 2999 $column_header{description} = 3000 q|<th class="listheading">| . $locale->text('Description') . q|</th>|; 3001 $column_header{nextdate} = 3002 qq|<th><a class="listheading" href="$href&sort=nextdate">| 3003 . $locale->text('Next') 3004 . q|</a></th>|; 3005 $column_header{enddate} = 3006 qq|<th><a class="listheading" href="$href&sort=enddate">| 3007 . $locale->text('Ends') 3008 . q|</a></th>|; 3009 $column_header{amount} = 3010 q|<th class="listheading">| . $locale->text('Amount') . q|</th>|; 3011 $column_header{curr} = q|<th class="listheading"> </th>|; 3012 $column_header{repeat} = 3013 q|<th class="listheading">| . $locale->text('Every') . q|</th>|; 3014 $column_header{howmany} = 3015 q|<th class="listheading">| . $locale->text('Times') . q|</th>|; 3016 $column_header{recurringemail} = 3017 q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|; 3018 $column_header{recurringprint} = 3019 q|<th class="listheading">| . $locale->text('Print') . q|</th>|; 3020 3021 print qq| 3022<body> 3023 3024<form method=post action=$form->{script}> 3025 3026<table width=100%> 3027 <tr> 3028 <th class=listtop>$form->{title}</th> 3029 </tr> 3030 <tr height="5"></tr> 3031 <tr> 3032 <td> 3033 <table width=100%> 3034 <tr class="listheading"> 3035|; 3036 3037 for (@column_index) { print "\n$column_header{$_}" } 3038 3039 print qq| 3040 </tr> 3041|; 3042 3043 $i = 1; 3044 $colspan = $#column_index + 1; 3045 3046 %tr = ( 3047 ar => $locale->text('AR'), 3048 ap => $locale->text('AP'), 3049 gl => $locale->text('GL'), 3050 so => $locale->text('Sales Orders'), 3051 po => $locale->text('Purchase Orders'), 3052 ); 3053 3054 %f = &formnames; 3055 3056 foreach $transaction ( sort keys %{ $form->{transactions} } ) { 3057 print qq| 3058 <tr> 3059 <th class="listheading" colspan=$colspan>$tr{$transaction}</th> 3060 </tr> 3061|; 3062 3063 foreach $ref ( @{ $form->{transactions}{$transaction} } ) { 3064 3065 for (@column_index) { 3066 $column_data{$_} = "<td nowrap>$ref->{$_}</td>"; 3067 } 3068 3069 if ( $ref->{repeat} > 1 ) { 3070 $unit = $locale->text( ucfirst $ref->{unit} ); 3071 $repeat = "$ref->{repeat} $unit"; 3072 } 3073 else { 3074 chop $ref->{unit}; 3075 $unit = $locale->text( ucfirst $ref->{unit} ); 3076 $repeat = $unit; 3077 } 3078 3079 $column_data{ndx} = qq|<td></td>|; 3080 3081 if ( !$ref->{expired} ) { 3082 if ( $ref->{overdue} <= 0 ) { 3083 $k++; 3084 $column_data{ndx} = 3085qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|; 3086 } 3087 } 3088 3089 $reference = 3090 ( $ref->{reference} ) 3091 ? $ref->{reference} 3092 : $locale->text('Next Number'); 3093 $column_data{reference} = 3094qq|<td nowrap><a href=$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}>$reference</a></td>|; 3095 3096 $module = "$ref->{module}.pl"; 3097 $type = ""; 3098 if ( $ref->{module} eq 'ar' ) { 3099 $module = "is.pl" if $ref->{invoice}; 3100 $ref->{amount} /= $ref->{exchangerate}; 3101 } 3102 if ( $ref->{module} eq 'ap' ) { 3103 $module = "ir.pl" if $ref->{invoice}; 3104 $ref->{amount} /= $ref->{exchangerate}; 3105 } 3106 if ( $ref->{module} eq 'oe' ) { 3107 $type = 3108 ( $ref->{vc} eq 'customer' ) 3109 ? "sales_order" 3110 : "purchase_order"; 3111 } 3112 3113 $column_data{id} = 3114qq|<td><a href="$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1">$ref->{id}</a></td>|; 3115 3116 $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|; 3117 $column_data{howmany} = 3118 qq|<td align="right" nowrap>| 3119 . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>"; 3120 $column_data{amount} = 3121 qq|<td align="right" nowrap>| 3122 . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>"; 3123 3124 $column_data{recurringemail} = "<td nowrap>"; 3125 @f = split /:/, $ref->{recurringemail}; 3126 for ( 0 .. $#f ) { 3127 $column_data{recurringemail} .= "$f{$f[$_]}<br>"; 3128 } 3129 $column_data{recurringemail} .= "</td>"; 3130 3131 $column_data{recurringprint} = "<td nowrap>"; 3132 @f = split /:/, $ref->{recurringprint}; 3133 for ( 0 .. $#f ) { 3134 $column_data{recurringprint} .= "$f{$f[$_]}<br>"; 3135 } 3136 $column_data{recurringprint} .= "</td>"; 3137 3138 $j++; 3139 $j %= 2; 3140 print qq| 3141 <tr class=listrow$j> 3142|; 3143 3144 for (@column_index) { print "\n$column_data{$_}" } 3145 3146 print qq| 3147 </tr> 3148|; 3149 } 3150 } 3151 3152 print qq| 3153 </tr> 3154 </table> 3155 </td> 3156 </tr> 3157 <tr> 3158 <td><hr size=3 noshade></td> 3159 </tr> 3160</table> 3161 3162<input name=lastndx type=hidden value=$k> 3163|; 3164 3165 $form->hide_form(qw(path login sessionid)); 3166 3167 print qq| 3168<button class="submit" type="submit" name="action" value="process_transactions">| 3169 . $locale->text('Process Transactions') 3170 . qq|</button>| 3171 if $k; 3172 3173 if ( $form->{lynx} ) { 3174 require "bin/menu.pl"; 3175 &menubar; 3176 } 3177 3178 print qq| 3179</form> 3180 3181</body> 3182</html> 3183|; 3184 3185} 3186 3187sub edit_recurring { 3188 3189 %links = ( 3190 ar => 'create_links', 3191 ap => 'create_links', 3192 gl => 'create_links', 3193 is => 'invoice_links', 3194 ir => 'invoice_links', 3195 oe => 'order_links', 3196 ); 3197 %prepare = ( 3198 is => 'prepare_invoice', 3199 ir => 'prepare_invoice', 3200 oe => 'prepare_order', 3201 ); 3202 3203 $form->{callback} = 3204"$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; 3205 3206 $form->{type} = "transaction"; 3207 3208 if ( $form->{module} eq 'ar' ) { 3209 if ( $form->{invoice} ) { 3210 $form->{type} = "invoice"; 3211 $form->{module} = "is"; 3212 } 3213 } 3214 if ( $form->{module} eq 'ap' ) { 3215 if ( $form->{invoice} ) { 3216 $form->{type} = "invoice"; 3217 $form->{module} = "ir"; 3218 } 3219 } 3220 3221 if ( $form->{module} eq 'oe' ) { 3222 %tr = ( 3223 so => sales_order, 3224 po => purchase_order, 3225 ); 3226 3227 $form->{type} = $tr{ $form->{transaction} }; 3228 } 3229 3230 $form->{script} = "$form->{module}.pl"; 3231 do "bin/$form->{script}"; 3232 3233 &{ $links{ $form->{module} } }; 3234 3235 # return if transaction doesn't exist 3236 $form->redirect unless $form->{recurring}; 3237 3238 if ( $prepare{ $form->{module} } ) { 3239 &{ $prepare{ $form->{module} } }; 3240 } 3241 3242 $form->{selectformat} = qq|<option value="html">html\n|; 3243 if ( ${LedgerSMB::Sysconfig::latex} ) { 3244 $form->{selectformat} .= qq| 3245 <option value="postscript">| . $locale->text('Postscript') . qq| 3246 <option value="pdf">| . $locale->text('PDF'); 3247 } 3248 3249 &schedule; 3250 3251} 3252 3253sub process_transactions { 3254 3255 # save variables 3256 my $pt = new Form; 3257 for ( keys %$form ) { $pt->{$_} = $form->{$_} } 3258 3259 my $defaultprinter; 3260 while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) { 3261 if ( $value =~ /lpr/ ) { 3262 $defaultprinter = $key; 3263 last; 3264 } 3265 } 3266 3267 $myconfig{vclimit} = 0; 3268 %f = &formnames; 3269 3270 for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) { 3271 if ( $pt->{"ndx_$i"} ) { 3272 $id = $pt->{"ndx_$i"}; 3273 3274 # process transaction 3275 AM->recurring_details( \%myconfig, \%$pt, $id ); 3276 3277 $header = $form->{header}; 3278 3279 # reset $form 3280 for ( keys %$form ) { delete $form->{$_}; } 3281 for (qw(login path sessionid stylesheet timeout)) { 3282 $form->{$_} = $pt->{$_}; 3283 } 3284 $form->{id} = $id; 3285 $form->{header} = $header; 3286 $form->db_init(\%myconfig); 3287 3288 # post, print, email 3289 if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) { 3290 if ( $pt->{arid} || $pt->{apid} ) { 3291 if ( $pt->{arid} ) { 3292 $form->{script} = 3293 ( $pt->{invoice} ) ? "is.pl" : "ar.pl"; 3294 $form->{ARAP} = "AR"; 3295 $form->{module} = "ar"; 3296 $invfld = "sinumber"; 3297 } 3298 else { 3299 $form->{script} = 3300 ( $pt->{invoice} ) ? "ir.pl" : "ap.pl"; 3301 $form->{ARAP} = "AP"; 3302 $form->{module} = "ap"; 3303 $invfld = "vinumber"; 3304 } 3305 do "bin/$form->{script}"; 3306 3307 if ( $pt->{invoice} ) { 3308 &invoice_links; 3309 &prepare_invoice; 3310 3311 for ( keys %$form ) { 3312 $form->{$_} = $form->unquote( $form->{$_} ); 3313 } 3314 3315 } 3316 else { 3317 &create_links; 3318 3319 $form->{type} = "transaction"; 3320 for ( 1 .. $form->{rowcount} - 1 ) { 3321 $form->{"amount_$_"} = 3322 $form->format_amount( \%myconfig, 3323 $form->{"amount_$_"}, 2 ); 3324 } 3325 for ( 1 .. $form->{paidaccounts} ) { 3326 $form->{"paid_$_"} = 3327 $form->format_amount( \%myconfig, 3328 $form->{"paid_$_"}, 2 ); 3329 } 3330 3331 } 3332 3333 delete $form->{"$form->{ARAP}_links"}; 3334 for (qw(acc_trans invoice_details)) { delete $form->{$_} } 3335 for ( 3336 qw(department employee language month partsgroup project years) 3337 ) 3338 { 3339 delete $form->{"all_$_"}; 3340 } 3341 3342 $form->{invnumber} = $pt->{reference}; 3343 $form->{transdate} = $pt->{nextdate}; 3344 3345 # tax accounts 3346 $form->all_taxaccounts( \%myconfig, undef, 3347 $form->{transdate} ); 3348 3349 # calculate duedate 3350 $form->{duedate} = 3351 $form->add_date( \%myconfig, $form->{transdate}, 3352 $pt->{overdue}, "days" ); 3353 3354 if ( $pt->{payment} ) { 3355 3356 # calculate date paid 3357 for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) { 3358 $form->{"datepaid_$j"} = 3359 $form->add_date( \%myconfig, $form->{transdate}, 3360 $pt->{paid}, "days" ); 3361 3362 ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/, 3363 $form->{"$form->{ARAP}_paid_$j"}; 3364 delete $form->{"cleared_$j"}; 3365 } 3366 3367 $form->{paidaccounts}++; 3368 } 3369 else { 3370 $form->{paidaccounts} = -1; 3371 } 3372 3373 for (qw(id recurring intnotes printed emailed queued)) { 3374 delete $form->{$_}; 3375 } 3376 3377 ( $form->{ $form->{ARAP} } ) = split /--/, 3378 $form->{ $form->{ARAP} }; 3379 3380 $form->{invnumber} = 3381 $form->update_defaults( \%myconfig, "$invfld" ) 3382 unless $form->{invnumber}; 3383 $form->{reference} = $form->{invnumber}; 3384 for (qw(invnumber reference)) { 3385 $form->{$_} = $form->unquote( $form->{$_} ); 3386 } 3387 3388 if ( $pt->{invoice} ) { 3389 if ( $pt->{arid} ) { 3390 $form->info( 3391 "\n" 3392 . $locale->text( 3393 'Posting Sales Invoice [_1]', 3394 $form->{invnumber} 3395 ) 3396 ); 3397 $ok = IS->post_invoice( \%myconfig, \%$form ); 3398 } 3399 else { 3400 $form->info( 3401 "\n" 3402 . $locale->text( 3403 'Posting Vendor Invoice [_1]', 3404 $form->{invnumber} 3405 ) 3406 ); 3407 $ok = IR->post_invoice( \%myconfig, \%$form ); 3408 } 3409 } 3410 else { 3411 if ( $pt->{arid} ) { 3412 $form->info( 3413 "\n" 3414 . $locale->text( 3415 'Posting Transaction [_1]', 3416 $form->{invnumber} 3417 ) 3418 ); 3419 } 3420 else { 3421 $form->info( 3422 "\n" 3423 . $locale->text( 3424 'Posting Transaction [_1]', 3425 $form->{invnumber} 3426 ) 3427 ); 3428 } 3429 3430 $ok = AA->post_transaction( \%myconfig, \%$form ); 3431 3432 } 3433 $form->info( " ..... " . $locale->text('done') ); 3434 3435 # print form 3436 if ( ${LedgerSMB::Sysconfig::latex} && $ok ) { 3437 $ok = &print_recurring( \%$pt, $defaultprinter ); 3438 } 3439 3440 &email_recurring( \%$pt ) if $ok; 3441 3442 } 3443 else { 3444 3445 # order 3446 $form->{script} = "oe.pl"; 3447 $form->{module} = "oe"; 3448 3449 $ordnumber = "ordnumber"; 3450 if ( $pt->{customer_id} ) { 3451 $form->{vc} = "customer"; 3452 $form->{type} = "sales_order"; 3453 $ordfld = "sonumber"; 3454 $flabel = $locale->text('Sales Order'); 3455 } 3456 else { 3457 $form->{vc} = "vendor"; 3458 $form->{type} = "purchase_order"; 3459 $ordfld = "ponumber"; 3460 $flabel = $locale->text('Purchase Order'); 3461 } 3462 require "bin/$form->{script}"; 3463 3464 &order_links; 3465 &prepare_order; 3466 3467 for ( keys %$form ) { 3468 $form->{$_} = $form->unquote( $form->{$_} ); 3469 } 3470 3471 $form->{$ordnumber} = $pt->{reference}; 3472 $form->{transdate} = $pt->{nextdate}; 3473 3474 # calculate reqdate 3475 $form->{reqdate} = 3476 $form->add_date( \%myconfig, $form->{transdate}, 3477 $pt->{req}, "days" ) 3478 if $form->{reqdate}; 3479 3480 for (qw(id recurring intnotes printed emailed queued)) { 3481 delete $form->{$_}; 3482 } 3483 for ( 1 .. $form->{rowcount} ) { 3484 delete $form->{"orderitems_id_$_"}; 3485 } 3486 3487 $form->{$ordnumber} = 3488 $form->update_defaults( \%myconfig, "$ordfld" ) 3489 unless $form->{$ordnumber}; 3490 $form->{reference} = $form->{$ordnumber}; 3491 for ( "$ordnumber", "reference" ) { 3492 $form->{$_} = $form->unquote( $form->{$_} ); 3493 } 3494 $form->{closed} = 0; 3495 3496 $form->info( 3497 "\n" 3498 . $locale->text( 3499 'Saving [_1] [_2]', 3500 $flabel, $form->{$ordnumber} 3501 ) 3502 ); 3503 if ( $ok = OE->save( \%myconfig, \%$form ) ) { 3504 $form->info( " ..... " . $locale->text('done') ); 3505 } 3506 else { 3507 $form->info( " ..... " . $locale->text('failed') ); 3508 } 3509 3510 # print form 3511 if ( ${LedgerSMB::Sysconfig::latex} && $ok ) { 3512 &print_recurring( \%$pt, $defaultprinter ); 3513 } 3514 3515 &email_recurring( \%$pt ); 3516 3517 } 3518 3519 } 3520 else { 3521 3522 # GL transaction 3523 GL->transaction( \%myconfig, \%$form ); 3524 3525 $form->{reference} = $pt->{reference}; 3526 $form->{transdate} = $pt->{nextdate}; 3527 3528 $j = 1; 3529 foreach $ref ( @{ $form->{GL} } ) { 3530 $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}"; 3531 3532 $form->{"projectnumber_$j"} = 3533 "$ref->{projectnumber}--$ref->{project_id}" 3534 if $ref->{project_id}; 3535 $form->{"fx_transaction_$j"} = $ref->{fx_transaction}; 3536 3537 if ( $ref->{amount} < 0 ) { 3538 $form->{"debit_$j"} = $ref->{amount} * -1; 3539 } 3540 else { 3541 $form->{"credit_$j"} = $ref->{amount}; 3542 } 3543 3544 $j++; 3545 } 3546 3547 $form->{rowcount} = $j; 3548 3549 for (qw(id recurring)) { delete $form->{$_} } 3550 $form->info( 3551 "\n" 3552 . $locale->text( 3553 'Posting GL Transaction [_1]', 3554 $form->{reference} 3555 ) 3556 ); 3557 $ok = GL->post_transaction( \%myconfig, \%$form ); 3558 $form->info( " ..... " . $locale->text('done') ); 3559 3560 } 3561 3562 AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok; 3563 3564 } 3565 } 3566 3567 $form->{callback} = 3568"am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}"; 3569 $form->redirect; 3570 3571} 3572 3573sub print_recurring { 3574 my ( $pt, $defaultprinter ) = @_; 3575 use List::Util qw(first); 3576 3577 my %f = &formnames; 3578 my $ok = 1; 3579 3580 if ( $pt->{recurringprint} ) { 3581 my $orig_callback = $form->{callback}; 3582 @f = split /:/, $pt->{recurringprint}; 3583 for ( $j = 0 ; $j <= $#f ; $j += 3 ) { 3584 $media = $f[ $j + 2 ]; 3585 $media ||= $myconfig->{printer} 3586 if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} }; 3587 $media ||= $defaultprinter; 3588 3589 $form->info( "\n" 3590 . $locale->text('Printing') . " " 3591 . $locale->text( $f{ $f[$j] } ) 3592 . " $form->{reference}" ); 3593 3594 $form->error( $locale->text('Invalid redirect') ) 3595 unless first { $_ eq $form->{script} } 3596 @{LedgerSMB::Sysconfig::scripts}; 3597 $form->{callback} = "$form->{script}?action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}"; 3598 $ok = !(main::redirect()); 3599 3600 if ($ok) { 3601 $form->info( " ..... " . $locale->text('done') ); 3602 } 3603 else { 3604 $form->info( " ..... " . $locale->text('failed') ); 3605 last; 3606 } 3607 } 3608 $form->{callback} = $orig_callback; 3609 } 3610 3611 $ok; 3612 3613} 3614 3615sub email_recurring { 3616 my ($pt) = @_; 3617 use List::Util qw(first); 3618 3619 my %f = &formnames; 3620 my $ok = 1; 3621 3622 if ( $pt->{recurringemail} ) { 3623 3624 @f = split /:/, $pt->{recurringemail}; 3625 my $orig_callback = $form->{callback}; 3626 for ( $j = 0 ; $j <= $#f ; $j += 2 ) { 3627 3628 $form->info( "\n" 3629 . $locale->text('Sending') . " " 3630 . $locale->text( $f{ $f[$j] } ) 3631 . " $form->{reference}" ); 3632 3633 # no email, bail out 3634 if ( !$form->{email} ) { 3635 $form->info( 3636 " ..... " . $locale->text('E-mail address missing!') ); 3637 last; 3638 } 3639 3640 $message = $form->escape( $pt->{message}, 1 ); 3641 3642 $form->error( $locale->text('Invalid redirect') ) 3643 unless first { $_ eq $form->{script} } 3644 @{LedgerSMB::Sysconfig::scripts}; 3645 $form->{callback} = "$form->{script}?action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message"; 3646 $ok = !( main::redirect() ); 3647 3648 if ($ok) { 3649 $form->info( " ..... " . $locale->text('done') ); 3650 } 3651 else { 3652 $form->info( " ..... " . $locale->text('failed') ); 3653 last; 3654 } 3655 } 3656 $form->{callback} = $orig_callback; 3657 } 3658 3659 $ok; 3660 3661} 3662 3663sub formnames { 3664 3665 # $locale->text('Transaction') 3666 # $locale->text('Invoice') 3667 # $locale->text('Credit Invoice') 3668 # $locale->text('Debit Invoice') 3669 # $locale->text('Packing List') 3670 # $locale->text('Pick List') 3671 # $locale->text('Sales Order') 3672 # $locale->text('Work Order') 3673 # $locale->text('Purchase Order') 3674 # $locale->text('Bin List') 3675 3676 my %f = ( 3677 transaction => 'Transaction', 3678 invoice => 'Invoice', 3679 credit_invoice => 'Credit Invoice', 3680 debit_invoice => 'Debit Invoice', 3681 packing_list => 'Packing List', 3682 pick_list => 'Pick List', 3683 sales_order => 'Sales Order', 3684 work_order => 'Work Order', 3685 purchase_order => 'Purchase Order', 3686 bin_list => 'Bin List', 3687 ); 3688 3689 %f; 3690 3691} 3692 3693sub continue { &{ $form->{nextsub} } } 3694 3695