diff options
Diffstat (limited to 'sql-ledger/bin/mozilla')
25 files changed, 15381 insertions, 2925 deletions
diff --git a/sql-ledger/bin/mozilla/admin.pl b/sql-ledger/bin/mozilla/admin.pl index 39247b541..8a4daba78 100644 --- a/sql-ledger/bin/mozilla/admin.pl +++ b/sql-ledger/bin/mozilla/admin.pl @@ -39,6 +39,11 @@ $locale = new Locale $language, "admin";  eval { require DBI; };  $form->error($locale->text('DBI not installed!')) if ($@); +$form->{stylesheet} = "sql-ledger.css"; +$form->{favicon} = "favicon.ico"; +$form->{timeout} = 600; + +require "$form->{path}/pw.pl";  # customization  if (-f "$form->{path}/custom_$form->{script}") { @@ -47,22 +52,11 @@ if (-f "$form->{path}/custom_$form->{script}") {  } -if (-f "css/sql-ledger.css") { -  $form->{stylesheet} = "sql-ledger.css"; -} - -  if ($form->{action}) {    $subroutine = $locale->findsub($form->{action}); -   -  if ($subroutine eq 'login') { -    if ($form->{rpw}) { -      $form->{rpw} = crypt $form->{rpw}, "ro"; -    } -  } -   -  &check_password; + +  &check_password unless $form->{action} eq 'logout';    &$subroutine; @@ -80,7 +74,7 @@ if ($form->{action}) {  password=  |; -    close(FH); +    close FH;    }    &adminlogin; @@ -94,32 +88,39 @@ password=  sub adminlogin {    $form->{title} = qq|SQL-Ledger $form->{version} |.$locale->text('Administration'); - -  $form->header; -  print qq| -<body class=admin> +  $form->{login} = "root login"; +  $form->header(1); +   +    print qq| +<script language="JavaScript" type="text/javascript"> +<!-- +function sf(){ +  document.admin.password.focus(); +} +// End --> +</script> +<body class=admin onload="sf()">  <div align=center>  <a href="http://www.sql-ledger.org"><img src=sql-ledger.png border=0></a>  <h1 class=login>|.$locale->text('Version').qq| $form->{version}<p>|.$locale->text('Administration').qq|</h1> -<form method=post action="$form->{script}"> +<form method=post action="$form->{script}" name=admin>  <table>    <tr>      <th>|.$locale->text('Password').qq|</th> -    <td><input type=password name=rpw></td> +    <td><input type=password name=password></td>      <td><input type=submit class=submit name=action value="|.$locale->text('Login').qq|"></td>    </tr>  <input type=hidden name=action value=login> -<input type=hidden name=root value="root login">  <input type=hidden name=path value=$form->{path}> +<input type=hidden name=sessionid value=$form->{sessionid}>  </table> -  </form>  <a href=http://www.sql-ledger.org>SQL-Ledger |.$locale->text('website').qq|</a> @@ -133,8 +134,6 @@ sub adminlogin {  } - -  sub login {    &list_users; @@ -142,6 +141,13 @@ sub login {  } +sub logout { + +  $form->{callback} = "$form->{script}?path=$form->{path}&endsession=1"; +  $form->redirect($locale->text('You are logged out')); + +} +  sub add_user { @@ -154,7 +160,9 @@ sub add_user {    if (-f "css/sql-ledger.css") {      $myconfig->{stylesheet} = "sql-ledger.css";    } -  $myconfig->{vclimit} = 200; +  $myconfig->{vclimit} = 1000; +  $myconfig->{menuwidth} = 155; +  $myconfig->{timeout} = 3600;    &form_header;    &form_footer; @@ -183,10 +191,10 @@ sub form_footer {    print qq| -<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"> -<input type=hidden name=root value="$form->{root}"> +<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}"> +  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">  $delete @@ -202,10 +210,17 @@ $delete  sub list_users { -  $form->error("$memberfile : ".$locale->text('locked!')) if (-f "${memberfile}.LCK"); -    open(FH, "$memberfile") or $form->error("$memberfile : $!"); -   + +  $nologin = qq| +<input type=submit class=submit name=action value="|.$locale->text('Lock System').qq|">|; + +  if (-e "$userspath/nologin") { +    $nologin = qq| +<input type=submit class=submit name=action value="|.$locale->text('Unlock System').qq|">|; +  } + +    while (<FH>) {      chop; @@ -223,6 +238,7 @@ sub list_users {    close(FH);  # type=submit $locale->text('Pg Database Administration') +# type=submit $locale->text('PgPP Database Administration')  # type=submit $locale->text('Oracle Database Administration')    foreach $item (User->dbdrivers) { @@ -242,6 +258,7 @@ sub list_users {    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration'); +  $form->{login} = "root login";    $form->header;    print qq| @@ -267,7 +284,7 @@ sub list_users {  |;  foreach $key (sort keys %member) { -  $href = "$script?action=edit&login=$key&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"; +  $href = "$script?action=edit&login=$key&path=$form->{path}&sessionid=$form->{sessionid}";    $href =~ s/ /%20/g;    $member{$key}{templates} =~ s/^$templates\///; @@ -303,13 +320,15 @@ print qq|  </table>  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> -<input type=hidden name=root value="$form->{root}"> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br><input type=submit class=submit name=action value="|.$locale->text('Add User').qq|">  <input type=submit class=submit name=action value="|.$locale->text('Change Admin Password').qq|">  $dbdrivers +$nologin + +<input type=submit class=submit name=action value="|.$locale->text('Logout').qq|">  </form> @@ -317,35 +336,6 @@ $dbdrivers  <br>  |.$locale->text('To add a user to a group edit a name, change the login name and save.  A new user with the same variables will then be saved under the new login name.').qq| -<p> - -<form method=post action=login.pl> - -<table border=0 width=100%> -  <tr class=listheading> -    <th>SQL-Ledger |.$locale->text('Accounting')." ".$locale->text('Login').qq|</th> -  </tr> -  <tr> -    <td> -      <table> -        <tr> -	  <th align=right>|.$locale->text('Name').qq|</th> -	  <td><input class=login name=login></td> -	  <td> </td> -	</tr> -	<tr> -	  <th align=right>|.$locale->text('Password').qq|</th> -	  <td><input class=login type=password name=password></td> -	  <td><input type=submit name=action value="|.$locale->text('Login').qq|"></td> -	</tr> -<input type=hidden name=path value=$form->{path}> -      </table> -    </td> -  </tr> -</table> - -</form> -  </body>  </html>  |; @@ -354,7 +344,6 @@ $dbdrivers -  sub form_header {    # if there is a login, get user @@ -376,17 +365,18 @@ sub form_header {      $dateformat .= ($item eq $myconfig->{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";    } -  foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) { +  foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00)) {      $numberformat .= ($item eq $myconfig->{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";    }    %countrycodes = User->country_codes;    $countrycodes = ""; +      foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {      $countrycodes .= ($myconfig->{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}" : "<option value=$key>$countrycodes{$key}";    } -  $countrycodes = qq|<option value="">American English\n$countrycodes|; +  $countrycodes = qq|<option value="">English\n$countrycodes|;    # is there a templates basedir    if (! -d "$templates") { @@ -398,13 +388,13 @@ sub form_header {    closedir TEMPLATEDIR;    @allhtml = sort grep /\.html/, @all; -  @alldir = grep !/\.(html|tex)$/, @all; +  @alldir = grep !/\.(html|tex|txt)$/, @all;    @allhtml = reverse grep !/Default/, @allhtml;    push @allhtml, 'Default';    @allhtml = reverse @allhtml; -  foreach $item (@alldir) { +  foreach $item (sort @alldir) {      if ($item eq $myconfig->{templates}) {        $usetemplates .= qq|<option selected>$item\n|;      } else { @@ -424,8 +414,42 @@ sub form_header {      }    } +  opendir CSS, "css/."; +  @all = grep /.*\.css$/, readdir CSS; +  closedir CSS; +   +  foreach $item (@all) { +    if ($item eq $myconfig->{stylesheet}) { +      $selectstylesheet .= qq|<option selected>$item\n|; +    } else { +      $selectstylesheet .= qq|<option>$item\n|; +    } +  } +  $selectstylesheet .= "<option>\n"; +   +  if (%printer && $latex) { +    $selectprinter = "<option>\n"; +    foreach $item (sort keys %printer) { +      if ($myconfig->{printer} eq $item) { +	$selectprinter .= qq|<option value="$item" selected>$item\n|; +      } else { +	$selectprinter .= qq|<option value="$item">$item\n|; +      } +    } + +    $printer = qq| +	<tr> +	  <th align=right>|.$locale->text('Printer').qq|</th> +	  <td><select name=printer>$selectprinter</select></td> +	</tr> +|; + +  } +  $user = $form->{login}; +  $form->{login} = "root login";    $form->header; +  $form->{login} = $user;    print qq|  <body class=admin> @@ -444,7 +468,7 @@ sub form_header {  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Password').qq|</th> -	  <td><input type=password name=password size=8 value=$myconfig->{password}></td> +	  <td><input type=password name=new_password size=8 value=$myconfig->{password}></td>  	  <input type=hidden name=old_password value=$myconfig->{password}>  	</tr>  	<tr> @@ -492,6 +516,10 @@ sub form_header {  	  <td><input name=vclimit value="$myconfig->{vclimit}"></td>  	</tr>  	<tr> +	  <th align=right>|.$locale->text('Menu Width').qq|</th> +	  <td><input name=menuwidth value="$myconfig->{menuwidth}"></td> +	</tr> +	<tr>  	  <th align=right>|.$locale->text('Language').qq|</th>  	  <td><select name=countrycode>$countrycodes</select></td>  	</tr> @@ -500,17 +528,15 @@ sub form_header {  	  <td><input name=charset value="$myconfig->{charset}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Stylesheet').qq|</th> -	  <td><input name=userstylesheet value="$myconfig->{stylesheet}"></td> -	</tr> -	<tr> -	  <th align=right>|.$locale->text('Printer').qq|</th> -	  <td><input name=printer size=20 value="$myconfig->{printer}"></td> +	  <th align=right>|.$locale->text('Session Timeout').qq|</th> +	  <td><input name=timeout value="$myconfig->{timeout}"></td>  	</tr> +  	<tr> -	  <th align=right>|.$locale->text('Ship via').qq|</th> -	  <td><input name=shippingpoint size=15 value="$myconfig->{shippingpoint}"></td> +	  <th align=right>|.$locale->text('Stylesheet').qq|</th> +	  <td><select name=userstylesheet>$selectstylesheet</select></td>  	</tr> +	$printer  	<tr>  	  <th align=right>|.$locale->text('Use Templates').qq|</th>  	  <td><select name=usetemplates>$usetemplates</select></td> @@ -550,20 +576,20 @@ sub form_header {  	  <th align=right>|.$locale->text('Driver').qq|</th>  	  <td><input name=dbdriver type=radio class=radio value=$item $checked> $item</td>  	  <th align=right>|.$locale->text('Host').qq|</th> -	  <td><input name="${item}_dbhost" value=$form->{"${item}_dbhost"}></td> +	  <td><input name="${item}_dbhost" size=30 value=$form->{"${item}_dbhost"}></td>  	</tr>  	<tr>|; -    if ($item eq 'Pg') { +    if ($item =~ /Pg/) {        print qq|  	  <th align=right>|.$locale->text('Dataset').qq|</th> -	  <td><input name=Pg_dbname size=10 value=$form->{Pg_dbname}></td> +	  <td><input name="${item}_dbname" size=15 value=$form->{"${item}_dbname"}></td>  	  <th align=right>|.$locale->text('Port').qq|</th> -	  <td><input name=Pg_dbport size=4 value=$form->{Pg_dbport}></td> +	  <td><input name="${item}_dbport" size=4 value=$form->{"${item}_dbport"}></td>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('User').qq|</th> -	  <td><input name="${item}_dbuser" size=10 value=$form->{"${item}_dbuser"}></td> +	  <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>  	  <th align=right>|.$locale->text('Password').qq|</th>  	  <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td>  	</tr>|; @@ -575,11 +601,11 @@ sub form_header {  	  <th align=right>SID</th>  	  <td><input name=Oracle_sid value=$form->{Oracle_sid}></td>  	  <th align=right>|.$locale->text('Port').qq|</th> -	  <td><input name=Oracle_dbport size=4 value=$form->{Oracle_dbport}></td> +	  <td><input name="${item}_dbport size=4 value=$form->{"${item}_dbport"}></td>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Dataset').qq|</th> -	  <td><input name="${item}_dbuser" size=10 value=$form->{"${item}_dbuser"}></td> +	  <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>  	  <th align=right>|.$locale->text('Password').qq|</th>  	  <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td> @@ -612,7 +638,7 @@ sub form_header {    close(FH);    foreach $item (@a) { -    next unless $item =~ /\[/; +    next unless $item =~ /\[\w+/;      next if $item =~ /\#/;      $item =~ s/(\[|\])//g; @@ -630,14 +656,23 @@ sub form_header {    } -  $admincheck = "checked" if $myconfig->{admin}; +  %role = ( 'admin' => $locale->text('Administrator'), +            'user' => $locale->text('User'), +	    'manager' => $locale->text('Manager') + +	   ); +	     +  $selectrole = ""; +  foreach $item (qw(user admin manager)) { +    $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=$item>$role{$item}\n" : "<option value=$item>$role{$item}\n"; +  }    print qq|    <tr class=listheading>      <th colspan=2>|.$locale->text('Access Control').qq|</th>    </tr>    <tr> -    <td><input name=admin type=checkbox class=checkbox value=1 $admincheck> <b>|.$locale->text('Administrator').qq|</b></td> +    <td><select name=role>$selectrole</select></td>    </tr>  |; @@ -695,11 +730,8 @@ sub form_header {     <tr>      <td colspan=2><hr size=3 noshade></td>    </tr> -  <tr> -    <td> -    </td> -  </tr>  </table> +</div>  |;  } @@ -712,6 +744,8 @@ sub save {    # no spaces allowed in login name    ($form->{login}) = split / /, $form->{login}; + +  $form->isblank("login", $locale->text('Login name missing!'));    # check for duplicates    if (!$form->{edit}) { @@ -722,11 +756,6 @@ sub save {      }    } -  # does stylesheet exist -  if ($form->{userstylesheet}) { -    $form->error($locale->text('Stylesheet').": css/$form->{userstylesheet} ".$locale->text('does not exist')) unless (-f "css/$form->{userstylesheet}"); -  } -      # no spaces allowed in directories    ($form->{newtemplates}) = split / /, $form->{newtemplates}; @@ -736,7 +765,6 @@ sub save {      $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};    } -      # is there a basedir    if (! -d "$templates") {      $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist')); @@ -760,38 +788,33 @@ sub save {      }      delete $form->{$item};    } - +      # check which database was filled in +   +  $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"}; +  $form->{dbport} = $form->{"$form->{dbdriver}_dbport"}; +  $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"}; +  $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"}; +  $form->{dbname} = $form->{"$form->{dbdriver}_dbname"}; +     if ($form->{dbdriver} eq 'Oracle') {      $form->{sid} = $form->{Oracle_sid}, ; -    $form->{dbhost} = $form->{Oracle_dbhost}, ; -    $form->{dbport} = $form->{Oracle_dbport}; -    $form->{dbpasswd} = $form->{Oracle_dbpasswd}; -    $form->{dbuser} = $form->{Oracle_dbuser}; -    $form->{dbname} = $form->{Oracle_dbuser};      $form->isblank("dbhost", $locale->text('Hostname missing!'));      $form->isblank("dbport", $locale->text('Port missing!'));      $form->isblank("dbuser", $locale->text('Dataset missing!'));    } -  if ($form->{dbdriver} eq 'Pg') { -    $form->{dbhost} = $form->{Pg_dbhost}; -    $form->{dbport} = $form->{Pg_dbport}; -    $form->{dbpasswd} = $form->{Pg_dbpasswd}; -    $form->{dbuser} = $form->{Pg_dbuser}; -    $form->{dbname} = $form->{Pg_dbname}; -     +  if ($form->{dbdriver} =~ /Pg/) {      $form->isblank("dbname", $locale->text('Dataset missing!'));      $form->isblank("dbuser", $locale->text('Database User missing!'));    } -  # set admin -  $form->{admin} = "" unless $form->{admin}; -      foreach $item (keys %{$form}) {      $myconfig->{$item} = $form->{$item};    } +  $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password}; +    delete $myconfig->{stylesheet};    if ($form->{userstylesheet}) {      $myconfig->{stylesheet} = $form->{userstylesheet}; @@ -808,8 +831,8 @@ sub save {        umask(007);        # copy templates to the directory -      opendir TEMPLATEDIR, "$templates/." or $form-error("$templates : $!"); -      @templates = grep /$form->{mastertemplates}.*?\.(html|tex)$/, readdir TEMPLATEDIR; +      opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!"); +      @templates = grep /$form->{mastertemplates}.*?\.(html|tex|txt)$/, readdir TEMPLATEDIR;        closedir TEMPLATEDIR;        foreach $file (@templates) { @@ -838,11 +861,14 @@ sub delete {    $form->{templates} = ($form->{templates}) ? "$templates/$form->{templates}" : "$templates/$form->{login}"; -  $form->error("$memberfile : ".$locale->text('locked!')) if (-f ${memberfile}.LCK); +  $form->error("$memberfile ".$locale->text('locked!')) if (-f ${memberfile}.LCK);    open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");    close(FH); -  open(CONF, "+<$memberfile") or $form->error("$memberfile : $!"); +  if (! open(CONF, "+<$memberfile")) { +    unlink "${memberfile}.LCK"; +    $form->error("$memberfile : $!"); +  }    @config = <CONF>; @@ -851,6 +877,8 @@ sub delete {    while ($line = shift @config) { +    chop $line; +      if ($line =~ /^\[/) {        last if ($line =~ /\[$form->{login}\]/);        $login = &login_name($line); @@ -860,25 +888,31 @@ sub delete {        $user{$login} = &get_value($line);      } -    print CONF $line; +    print CONF "$line\n";    }    # remove everything up to next login or EOF    # and save template variable    while ($line = shift @config) { -    if ($line =~ /^templates=/) { -      $templatedir = &get_value($line); -    } + +    chop $line; +     +    ($key, $value) = split /=/, $line, 2; +    $myconfig{$key} = $value; +          last if ($line =~ /^\[/);    }    # this one is either the next login or EOF -  print CONF $line; +  print CONF "$line\n";    $login = &login_name($line);    while ($line = shift @config) { + +    chop $line; +      if ($line =~ /^\[/) {        $login = &login_name($line);      } @@ -887,7 +921,7 @@ sub delete {        $user{$login} = &get_value($line);      } -    print CONF $line; +    print CONF "$line\n";    }    close(CONF); @@ -895,9 +929,11 @@ sub delete {    # scan %user for $templatedir    foreach $login (keys %user) { -    last if ($found = ($templatedir eq $user{$login})); +    last if ($found = ($myconfig{templates} eq $user{$login}));    } +  map { $form->{$_} = $myconfig{$_} } keys %myconfig; +      # if found keep directory otherwise delete    if (!$found) {      # delete it if there is a template directory @@ -905,13 +941,16 @@ sub delete {      if (-d "$dir") {        unlink <$dir/*.html>;        unlink <$dir/*.tex>; +      unlink <$dir/*.txt>;        rmdir "$dir";      }    }    # delete config file for user    unlink "$userspath/$form->{login}.conf"; -     + +  User::delete_login("", \%$form); +      $form->redirect($locale->text('User deleted!'));  } @@ -930,10 +969,10 @@ sub login_name {  sub get_value {    my $line = shift; -  my ($null, $value) = split(/=/, $line, 2); +  my ($null, $value) = split /=/, $line, 2;    # remove comments -  $value =~ s/\s#.*//g; +  $value =~ s/^\s*#.*//g;    # remove any trailing whitespace    $value =~ s/^\s*(.*?)\s*$/$1/; @@ -946,22 +985,42 @@ sub get_value {  sub change_admin_password {    $form->{title} = qq|SQL-Ledger |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password'); -   + +  $form->{login} = "root login";    $form->header;    print qq|  <body class=admin> - -<h2>|.$locale->text('Change Admin Password').qq|</h2> -  <form method=post action=$form->{script}> -<b>|.$locale->text('Password').qq|</b> <input type=password name=password size=8> +<table> +  <tr> +  <tr class=listheading> +    <th>|.$locale->text('Change Password').qq|</th> +  </tr> +  <tr size=5></tr> +  <tr> +    <td> +      <table width=100%> +        <tr> +          <th align=right>|.$locale->text('Password').qq|</th> +	  <td><input type=password name=new_password></td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Confirm').qq|</th> +	  <td><input type=password name=confirm_password></td> +	</tr> +      </table> +    </td> +  </tr> -<input type=hidden name=root value="$form->{root}"> +</table> + +<br> +<hr size=3 noshade>  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <p>  <input type=submit class=submit name=action value="|.$locale->text('Change Password').qq|"> @@ -977,12 +1036,14 @@ sub change_admin_password {  sub change_password { -  $root->{password} = $form->{password}; +  $form->error($locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password}; +   +  $root->{password} = $form->{new_password};    $root->{'root login'} = 1;    $root->save_member($memberfile); -  $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$root->{password}"; +  $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";    $form->redirect($locale->text('Password changed!')); @@ -991,11 +1052,26 @@ sub change_password {  sub check_password { -  $root = new User "$memberfile", $form->{root}; +  $root = new User "$memberfile", "root login";    if ($root->{password}) { -    if ($root->{password} ne $form->{rpw}) { -      $form->error($locale->text('Incorrect Password!')); +       +    if ($form->{password}) { +      $form->{callback} .= "&password=$form->{password}" if $form->{callback}; +      $form->{sessionid} = time; +      if ($root->{password} ne crypt $form->{password}, 'ro') { +	&getpassword; +	exit; +      } +    } else { +      if ($ENV{HTTP_USER_AGENT}) { +	$ENV{HTTP_COOKIE} =~ s/;\s*/;/g; +	%cookie = split /[=;]/, $ENV{HTTP_COOKIE}; +	if ((! $cookie{"SQL-Ledger-root login"}) || $cookie{"SQL-Ledger-root login"} ne $form->{sessionid}) { +	  &getpassword(1); +	  exit; +	} +      }      }    } @@ -1010,6 +1086,14 @@ sub pg_database_administration {  } +sub pgpp_database_administration { + +  $form->{dbdriver} = 'PgPP'; +  &dbselect_source; + +} + +  sub oracle_database_administration {    $form->{dbdriver} = 'Oracle'; @@ -1035,6 +1119,8 @@ sub dbdriver_defaults {  			      }                      ); +  $driverdefaults{PgPP} = $driverdefaults{Pg}; +    map { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} } keys %{ $driverdefaults{Pg} };  } @@ -1045,73 +1131,61 @@ sub dbselect_source {    &dbdriver_defaults;    $msg{Pg} = $locale->text('Leave host and port field empty unless you want to make a remote connection.'); +  $msg{PgPP} = $msg{Pg};    $msg{Oracle} = $locale->text('You must enter a host and port for local and remote connections!');   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." / ".$locale->text('Database Administration'); - +  $form->{login} = "root login";    $form->header;    print qq|  <body class=admin> -  <center>  <h2>$form->{title}</h2>  <form method=post action=$form->{script}>  <table> -<tr><td> - -<table> - -  <tr class=listheading> -    <th colspan=4>|.$locale->text('Database').qq|</th> -  </tr> - -<input type=hidden name=dbdriver value=$form->{dbdriver}> - -  <tr><td> -   <table> - -  <tr> - -    <th align=right>|.$locale->text('Host').qq|</th> -    <td><input name=dbhost size=25 value=$form->{dbhost}></td> -    <th align=right>|.$locale->text('Port').qq|</th> -    <td><input name=dbport size=5 value=$form->{dbport}></td> - -  </tr> - -  <tr> - -    <th align=right>|.$locale->text('User').qq|</th> -    <td><input name=dbuser size=10 value=$form->{dbuser}></td> -    <th align=right>|.$locale->text('Password').qq|</th> -    <td><input type=password name=dbpasswd size=10></td> - -  </tr> -      <tr> +    <td> +      <table> +	<tr class=listheading> +	  <th colspan=4>|.$locale->text('Database').qq|</th> +	</tr> +	<input type=hidden name=dbdriver value=$form->{dbdriver}> +	<tr> +	  <td> +	    <table> +	      <tr> +		<th align=right>|.$locale->text('Host').qq|</th> +		<td><input name=dbhost size=25 value=$form->{dbhost}></td> +		<th align=right>|.$locale->text('Port').qq|</th> +		<td><input name=dbport size=5 value=$form->{dbport}></td> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('User').qq|</th> +		<td><input name=dbuser size=10 value=$form->{dbuser}></td> +		<th align=right>|.$locale->text('Password').qq|</th> +		<td><input type=password name=dbpasswd size=10></td> +	      </tr> +	      <tr> + +		<th align=right>$form->{connectstring}</th> +		<td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td> + +	      </tr> +	    </table> +	  </td> +	</tr> +      </table> -    <th align=right>$form->{connectstring}</th> -    <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td> - -  </tr> - -</table> - -</td></tr> -</table> - -<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"> -<input type=hidden name=root value="$form->{root}"> +<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> +<input type=hidden name=sessionid value=$form->{sessionid}> -<hr size=3 noshade>  <br>  <input type=submit class=submit name=action value="|.$locale->text('Create Dataset').qq|"> @@ -1120,7 +1194,8 @@ sub dbselect_source {  </form> -</td></tr> +    </td> +  </tr>  </table>  <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!') @@ -1149,6 +1224,7 @@ sub update_dataset {    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Update Dataset'); +  $form->{login} = "root login";    $form->header;    print qq| @@ -1161,8 +1237,8 @@ sub update_dataset {    foreach $key (sort keys %needsupdate) { -    if ($needsupdate{$key} lt $form->{dbversion}) { -      $upd .= qq|<br><input name="db$key" type=checkbox value=1 checked> $key\n|; +    if ($needsupdate{$key} ne $form->{dbversion}) { +      $upd .= qq|<input name="db$key" type=checkbox value=1 checked> $key\n|;        $form->{dbupdate} .= "db$key ";      }    } @@ -1173,7 +1249,7 @@ sub update_dataset {    if ($form->{dbupdate}) {      print qq| -<table> +<table width=100%>  <form method=post action=$form->{script}>  <input type=hidden name=dbdriver value=$form->{dbdriver}> @@ -1191,19 +1267,23 @@ sub update_dataset {  $upd -</td></tr> -<tr><td> +</td> +</tr> +<tr> +<td>  <input name=dbupdate type=hidden value="$form->{dbupdate}"> -<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"> +<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}"> -<input type=hidden name=root value="$form->{root}">  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=dbupdate> +<hr size=3 noshade> + +<br>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">  </td></tr> @@ -1237,41 +1317,53 @@ sub dbupdate {  sub create_dataset { -  foreach $item (sort User->dbsources(\%$form)) { -    $dbsources .= "[$item] "; -  } +  @dbsources = sort User->dbsources(\%$form); -  opendir SQLDIR, "sql/." or $form-error($!); +  opendir SQLDIR, "sql/." or $form->error($!);    foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {      next if ($item eq 'Default-chart.sql');      $item =~ s/-chart\.sql//; -    push @charts, qq| <input name=chart class=radio type=radio value="$item"> $item|; +    push @charts, qq|<input name=chart class=radio type=radio value="$item">$item|;    }    closedir SQLDIR;    # add Default at beginning -  @charts = (qq|<input name=chart class=radio type=radio value="Default" checked> Default|, @charts); +  unshift @charts, qq|<input name=chart class=radio type=radio value="Default" checked>Default|; -  $selectencoding = qq|<option>  +  $selectencoding = qq|<option>    <option value=SQL_ASCII>ASCII -  <option value=EUC_JP>Japanese Extended UNIX Code -  <option value=EUC_CN>Chinese Extended UNIX Code  -  <option value=EUC_KR>Korean Extended UNIX Code -  <option value=EUC_TW>Taiwan Extended UNIX Code -  <option value=UNICODE>UTF-8 Unicode  +  <option value=EUC_JP>Japanese EUC +  <option value=EUC_CN>Chinese EUC +  <option value=EUC_KR>Korean EUC +  <option value=JOHAB>Korean EUC (Hangle base) +  <option value=EUC_TW>Taiwan EUC +  <option value=UNICODE>Unicode (UTF-8)    <option value=MULE_INTERNAL>Mule internal type -  <option value=LATIN1>ISO 8859-1 -  <option value=LATIN2>ISO 8859-2  -  <option value=LATIN3>ISO 8859-3 -  <option value=LATIN4>ISO 8859-4 -  <option value=LATIN5>ISO 8859-5 -  <option value=KOI8>KOI8-R +  <option value=LATIN1>ISO 8859-1/ECMA 94 (Latin alphabet no. 1) +  <option value=LATIN2>ISO 8859-2/ECMA 94 (Latin alphabet no. 2) +  <option value=LATIN3>ISO 8859-3/ECMA 94 (Latin alphabet no. 3) +  <option value=LATIN4>ISO 8859-4/ECMA 94 (Latin alphabet no. 4) +  <option value=LATIN5>ISO 8859-9/ECMA 128 (Latin alphabet no. 5) +  <option value=LATIN6>ISO 8859-10/ECMA 144 (Latin alphabet no. 6) +  <option value=LATIN7>ISO 8859-13 (Latin alphabet no. 7) +  <option value=LATIN8>ISO 8859-14 (Latin alphabet no. 8) +  <option value=LATIN9>ISO 8859-15 (Latin alphabet no. 9) +  <option value=LATIN10>ISO 8859-16/ASRO SR 14111 (Latin alphabet no. 10) +  <option value=ISO_8859_5>ISO 8859-5/ECMA 113 (Latin/Cyrillic) +  <option value=ISO_8859_6>ISO 8859-6/ECMA 114 (Latin/Arabic) +  <option value=ISO_8859_7>ISO 8859-7/ECMA 118 (Latin/Greek) +  <option value=ISO_8859_8>ISO 8859-8/ECMA 121 (Latin/Hebrew) +  <option value=KOI8>KOI8-R(U)    <option value=WIN>Windows CP1251    <option value=ALT>Windows CP866 +  <option value=WIN1256>Windows CP1256 (Arabic) +  <option value=TCVN>Windows CP1258 (Vietnamese) +  <option value=WIN874>Windows CP874 (Thai)    |;    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset'); +  $form->{login} = "root login";    $form->header;    print qq| @@ -1283,7 +1375,7 @@ sub create_dataset {  <form method=post action=$form->{script}> -<table> +<table width=100%>    <tr class=listheading>      <th colspan=2> </th>    </tr> @@ -1291,8 +1383,13 @@ sub create_dataset {    <tr>      <th align=right nowrap>|.$locale->text('Existing Datasets').qq|</th> -    <td>$dbsources</td> +    <td> +|; +    map { print "[ $_ ] " } @dbsources; +     +    print qq| +    </td>    </tr>    <tr> @@ -1301,7 +1398,7 @@ sub create_dataset {      <td><input name=db></td>    </tr> -   +    <tr>      <th align=right nowrap>|.$locale->text('Multibyte Encoding').qq|</th> @@ -1311,14 +1408,36 @@ sub create_dataset {    <tr> -    <th align=right>|.$locale->text('Create Chart of Accounts').qq|</th> -    <td>@charts</td> +    <th align=right nowrap>|.$locale->text('Create Chart of Accounts').qq|</th> +    <td> +      <table> +|; +  while (@charts) { +    print qq| +        <tr> +|; + +    map { print "<td>$charts[$_]</td>\n" } (0 .. 2); + +    print qq| +        </tr> +|; + +    splice @charts, 0, 3; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td colspan=2> +    <hr size=3 noshade> +    </td>    </tr> +</table> -  <tr><td colspan=2> -<hr size=3 noshade> -<br>  <input type=hidden name=dbdriver value=$form->{dbdriver}>  <input type=hidden name=dbuser value=$form->{dbuser}>  <input type=hidden name=dbhost value=$form->{dbhost}> @@ -1326,22 +1445,19 @@ sub create_dataset {  <input type=hidden name=dbpasswd value=$form->{dbpasswd}>  <input type=hidden name=dbdefault value=$form->{dbdefault}> -<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"> +<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}"> -<input type=hidden name=root value="$form->{root}">  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=rpw value=$form->{rpw}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=dbcreate> +<br>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> -  </td></tr> -</table>  </form> -  </body>  </html>  |; @@ -1357,6 +1473,7 @@ sub dbcreate {    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset'); +  $form->{login} = "root login";    $form->header;    print qq| @@ -1372,9 +1489,8 @@ sub dbcreate {  .qq| -<input type=hidden name=root value="$form->{root}">  <input type=hidden name=path value="$form->{path}"> -<input type=hidden name=rpw value="$form->{rpw}"> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=list_users> @@ -1393,7 +1509,7 @@ sub delete_dataset {    if (@dbsources = User->dbsources_unused(\%$form, $memberfile)) {      foreach $item (sort @dbsources) { -      $dbsources .= qq|<input name=db class=radio type=radio value=$item> $item\n<br>|; +      $dbsources .= qq|<input name=db class=radio type=radio value=$item> $item |;      }    } else {      $form->error($locale->text('Nothing to delete!')); @@ -1401,18 +1517,17 @@ sub delete_dataset {    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset'); +  $form->{login} = "root login";    $form->header;    print qq|  <body class=admin> - -<center>  <h2>$form->{title}</h2>  <form method=post action=$form->{script}> -<table> +<table width=100%>    <tr class=listheading>      <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>    </tr> @@ -1424,9 +1539,7 @@ sub delete_dataset {    </tr>    <tr><td> - -<hr size=3 noshade> -<br> +<p>  <input type=hidden name=dbdriver value=$form->{dbdriver}>  <input type=hidden name=dbuser value=$form->{dbuser}>  <input type=hidden name=dbhost value=$form->{dbhost}> @@ -1434,14 +1547,16 @@ sub delete_dataset {  <input type=hidden name=dbpasswd value=$form->{dbpasswd}>  <input type=hidden name=dbdefault value=$form->{dbdefault}> -<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"> +<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}"> -<input type=hidden name=root value="$form->{root}">  <input type=hidden name=path value="$form->{path}"> -<input type=hidden name=rpw value="$form->{rpw}"> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=dbdelete> +<hr size=3 noshade> + +<br>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">    </td></tr> @@ -1449,11 +1564,6 @@ sub delete_dataset {  </form> -<p>|.$locale->text('Select a Dataset to delete and press "Continue"') - -.qq| - -  </body>  </html>  |; @@ -1471,6 +1581,7 @@ sub dbdelete {    $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset'); +  $form->{login} = "root login";    $form->header;    print qq| @@ -1486,9 +1597,8 @@ $form->{db} |.$locale->text('successfully deleted!')  .qq| -<input type=hidden name=root value="$form->{root}">  <input type=hidden name=path value="$form->{path}"> -<input type=hidden name=rpw value="$form->{rpw}"> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=list_users> @@ -1502,3 +1612,27 @@ $form->{db} |.$locale->text('successfully deleted!')  } + +sub unlock_system { + +  unlink "$userspath/nologin"; +   +  $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}"; + +  $form->redirect($locale->text('Lockfile removed!')); + +} + + +sub lock_system { + +  open(FH, ">$userspath/nologin") or $form->error($locale->text('Cannot create Lock!')); +  close(FH); +   +  $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}"; + +  $form->redirect($locale->text('Lockfile created!')); + +} + + diff --git a/sql-ledger/bin/mozilla/am.pl b/sql-ledger/bin/mozilla/am.pl index 7e36cfdc9..834290343 100644 --- a/sql-ledger/bin/mozilla/am.pl +++ b/sql-ledger/bin/mozilla/am.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -30,6 +30,8 @@ use SL::AM;  use SL::CA;  use SL::Form;  use SL::User; +use SL::RP; +use SL::GL;  1; @@ -37,42 +39,54 @@ use SL::User; -sub add { +sub add { &{ "add_$form->{type}" } }; +sub edit { &{ "edit_$form->{type}" } }; +sub save { &{ "save_$form->{type}" } }; +sub delete { &{ "delete_$form->{type}" } }; + + +sub save_as_new { + +  delete $form->{id}; + +  &save; + +} + +sub add_account { +      $form->{title} = "Add";    $form->{charttype} = "A"; -  $form->{callback} = "$form->{script}?action=list&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; -  &form_header; +  &account_header;    &form_footer;  } -sub edit { +sub edit_account { +      $form->{title} = "Edit"; - -  # if it is a template -  if ($form->{file}) { -    $form->{type} = "template"; -    &edit_template; -    exit; -  } - +   +  $form->{accno} =~ s/\\'/'/g; +  $form->{accno} =~ s/\\\\/\\/g; +     AM->get_account(\%myconfig, \%$form);    foreach my $item (split(/:/, $form->{link})) {      $form->{$item} = "checked";    } -  &form_header; +  &account_header;    &form_footer;  } -sub form_header { +sub account_header {    $form->{title} = $locale->text("$form->{title} Account"); @@ -80,7 +94,7 @@ sub form_header {    $checked{"$form->{category}_"} = "checked";    $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked"; -  $form->{description} =~ s/"/"/g; +  map { $form->{$_} = $form->quote($form->{$_}) } qw(accno description);  # this is for our parser only!  # type=submit $locale->text('Add Account') @@ -102,8 +116,6 @@ sub form_header {  <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>  <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}> -<input type=hidden name=amount value=$form->{amount}> -  <table border=0 width=100%>    <tr>      <th class=listtop>$form->{title}</th> @@ -114,7 +126,7 @@ sub form_header {        <table>  	<tr>  	  <th align=right>|.$locale->text('Account Number').qq|</th> -	  <td><input name=accno size=20 value=$form->{accno}></td> +	  <td><input name=accno size=20 value="$form->{accno}"></td>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Description').qq|</th> @@ -126,11 +138,13 @@ sub form_header {  	    <table>  	      <tr valign=top>  		<td><input name=category type=radio class=radio value=A $checked{A_}> |.$locale->text('Asset').qq|\n<br> +		<input name=category type=radio class=radio value=C $checked{C_}> |.$locale->text('Contra').qq|\n<br>  		<input name=category type=radio class=radio value=L $checked{L_}> |.$locale->text('Liability').qq|\n<br>  		<input name=category type=radio class=radio value=Q $checked{Q_}> |.$locale->text('Equity').qq|\n<br>  		<input name=category type=radio class=radio value=I $checked{I_}> |.$locale->text('Income').qq|\n<br>  		<input name=category type=radio class=radio value=E $checked{E_}> |.$locale->text('Expense')  		.qq|</td> +		<td width=50> </td>  		<td>  		<input name=charttype type=radio class=radio value="H" $checked{H}> |.$locale->text('Heading').qq|<br>  		<input name=charttype type=radio class=radio value="A" $checked{A}> |.$locale->text('Account') @@ -169,31 +183,32 @@ if ($form->{charttype} eq "A") {  		<th align=left>|.$locale->text('Payables').qq|</th>  		<th align=left>|.$locale->text('Parts Inventory').qq|</th>  		<th align=left>|.$locale->text('Service Items').qq|</th> +		<th align=left>|.$locale->text('Labor/Overhead').qq|</th>  	      </tr>  	      <tr>  		<td>  		<input name=AR_amount type=checkbox class=checkbox value=AR_amount $form->{AR_amount}> |.$locale->text('Income').qq|\n<br>  		<input name=AR_paid type=checkbox class=checkbox value=AR_paid $form->{AR_paid}> |.$locale->text('Payment').qq|\n<br> -		<input name=AR_tax type=checkbox class=checkbox value=AR_tax $form->{AR_tax}> |.$locale->text('Tax') -		.qq| +		<input name=AR_tax type=checkbox class=checkbox value=AR_tax $form->{AR_tax}> |.$locale->text('Tax') .qq|  		</td>  		<td>  		<input name=AP_amount type=checkbox class=checkbox value=AP_amount $form->{AP_amount}> |.$locale->text('Expense/Asset').qq|\n<br>  		<input name=AP_paid type=checkbox class=checkbox value=AP_paid $form->{AP_paid}> |.$locale->text('Payment').qq|\n<br> -		<input name=AP_tax type=checkbox class=checkbox value=AP_tax $form->{AP_tax}> |.$locale->text('Tax') -		.qq| +		<input name=AP_tax type=checkbox class=checkbox value=AP_tax $form->{AP_tax}> |.$locale->text('Tax') .qq|  		</td>  		<td> -		<input name=IC_sale type=checkbox class=checkbox value=IC_sale $form->{IC_sale}> |.$locale->text('Sales').qq|\n<br> +		<input name=IC_sale type=checkbox class=checkbox value=IC_sale $form->{IC_sale}> |.$locale->text('Income').qq|\n<br>  		<input name=IC_cogs type=checkbox class=checkbox value=IC_cogs $form->{IC_cogs}> |.$locale->text('COGS').qq|\n<br> -		<input name=IC_taxpart type=checkbox class=checkbox value=IC_taxpart $form->{IC_taxpart}> |.$locale->text('Tax') -		.qq| +		<input name=IC_taxpart type=checkbox class=checkbox value=IC_taxpart $form->{IC_taxpart}> |.$locale->text('Tax') .qq|  		</td>  		<td>  		<input name=IC_income type=checkbox class=checkbox value=IC_income $form->{IC_income}> |.$locale->text('Income').qq|\n<br>  		<input name=IC_expense type=checkbox class=checkbox value=IC_expense $form->{IC_expense}> |.$locale->text('Expense').qq|\n<br> -		<input name=IC_taxservice type=checkbox class=checkbox value=IC_taxservice $form->{IC_taxservice}> |.$locale->text('Tax') -		.qq| +		<input name=IC_taxservice type=checkbox class=checkbox value=IC_taxservice $form->{IC_taxservice}> |.$locale->text('Tax') .qq| +		</td> +		<td> +		<br> +		<input name=IC_cogs type=checkbox class=checkbox value=IC_cogs $form->{IC_cogs}> |.$locale->text('COGS').qq|\n<br>  		</td>  	      </tr>  	    </table> @@ -241,16 +256,27 @@ sub form_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">  |;    if ($form->{id}) { +    print qq| +<input type=submit class=submit name=action value="|.$locale->text('Save as new').qq|"> +|; +  } + +  if ($form->{id} && $form->{orphaned}) {      print qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +	          print qq|  </form> @@ -260,37 +286,57 @@ sub form_footer {  } - -sub save { &{ "save_$form->{type}" } };  sub save_account {    $form->isblank("accno", $locale->text('Account Number missing!'));    $form->isblank("category", $locale->text('Account Type missing!')); +  # check for conflicting accounts +  if ($form->{AR} || $form->{AP} || $form->{IC}) { +    map { $a .= $form->{$_} } qw(AR AP IC); +    $form->error($locale->text('Cannot set account for more than one of AR, AP or IC')) if length $a > 2; + +    map { $form->error("$form->{AR}$form->{AP}$form->{IC} ". $locale->text('account cannot be set to any other type of account')) if $form->{$_} } qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_sale IC_cogs IC_taxpart IC_income IC_expense IC_taxservice); +  } + +  foreach $item ("AR", "AP") { +    $i = 0; +    map { $i++ if $form->{$_} } ("${item}_amount", "${item}_paid", "${item}_tax"); +    $form->error($locale->text('Cannot set multiple options for')." $item") if $i > 1; +  } +   +  $i = 0; +  map { $i++ if $form->{$_} } qw(IC_sale IC_cogs IC_taxpart); +  $form->error($locale->text('Cannot set multiple options for Parts Inventory')) if $i > 1; + +  $i = 0; +  map { $i++ if $form->{$_} } qw(IC_income IC_expense IC_taxservice); +  $form->error($locale->text('Cannot set multiple options for Service Items')) if $i > 1; +      $form->redirect($locale->text('Account saved!')) if (AM->save_account(\%myconfig, \%$form));    $form->error($locale->text('Cannot save account!'));  } -sub list { +sub list_account {    CA->all_accounts(\%myconfig, \%$form);    $form->{title} = $locale->text('Chart of Accounts');    # construct callback -  $callback = "$form->{script}?action=list&path=$form->{path}&login=$form->{login}&password=$form->{password}"; +  $callback = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";    @column_index = qw(accno gifi_accno description debit credit link); -  $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</a></th>|; -  $column_header{gifi_accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</a></th>|; -  $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</a></th>|; -  $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</a></th>|; -  $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</a></th>|; -  $column_header{link} = qq|<th class=listheading>|.$locale->text('Link').qq|</a></th>|; +  $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</a></th>|; +  $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</a></th>|; +  $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</a></th>|; +  $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</a></th>|; +  $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</a></th>|; +  $column_header{link} = qq|<th class=listtop>|.$locale->text('Link').qq|</a></th>|;    $form->header; @@ -299,8 +345,10 @@ sub list {    print qq|  <body> -<table border=0 width=100%> -  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> +<table width=100%> +  <tr> +    <th class=listtop colspan=$colspan>$form->{title}</th> +  </tr>    <tr height=5></tr>    <tr class=listheading>  |; @@ -319,15 +367,10 @@ sub list {      $ca->{debit} = " ";      $ca->{credit} = " "; -    # needed if we can delete an account -    $amount = 0; -      if ($ca->{amount} > 0) { -      $amount = $ca->{amount};        $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");      }      if ($ca->{amount} < 0) { -      $amount = -$ca->{amount};        $ca->{debit} = $form->format_amount(\%myconfig, -$ca->{amount}, 2, " ");      } @@ -336,8 +379,8 @@ sub list {      if ($ca->{charttype} eq "H") {        print qq|<tr class=listheading>|; -      $column_data{accno} = qq|<th><a class=listheading href=$form->{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</a></th>|; -      $column_data{gifi_accno} = qq|<th><a class=listheading href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno}</a> </th>|; +      $column_data{accno} = qq|<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>|; +      $column_data{gifi_accno} = qq|<th class=listheading><a href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{gifi_accno}</a> </th>|;        $column_data{description} = qq|<th class=listheading>$ca->{description} </th>|;        $column_data{debit} = qq|<th> </th>|;        $column_data{credit} = qq| <th> </th>|; @@ -347,8 +390,8 @@ sub list {        $i++; $i %= 2;        print qq|  <tr valign=top class=listrow$i>|; -      $column_data{accno} = qq|<td><a href=$form->{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback&amount=$amount>$ca->{accno}</a></td>|; -      $column_data{gifi_accno} = qq|<td><a href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback&amount=$amount>$ca->{gifi_accno}</a> </td>|; +      $column_data{accno} = qq|<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>|; +      $column_data{gifi_accno} = qq|<td><a href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{gifi_accno}</a> </td>|;        $column_data{description} = qq|<td>$ca->{description} </td>|;        $column_data{debit} = qq|<td align=right>$ca->{debit}</td>|;        $column_data{credit} = qq|<td align=right>$ca->{credit}</td>|; @@ -372,16 +415,10 @@ sub list {  } -sub delete { &{ "delete_$form->{type}" } }; -  sub delete_account {    $form->{title} = $locale->text('Delete Account'); -  if ($form->{amount} != 0) {   -    $form->error($locale->text('Transactions exist; cannot delete account!')); -  } -    foreach $id (qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)) {      if ($form->{id} == $form->{$id}) {        $form->error($locale->text('Cannot delete default account!')); @@ -396,16 +433,15 @@ sub delete_account {  sub list_gifi { -  @{ $form->{fields} } = (accno, description); +  @{ $form->{fields} } = qw(accno description);    $form->{table} = "gifi"; -  $form->{sortorder} = "accno";    AM->gifi_accounts(\%myconfig, \%$form);    $form->{title} = $locale->text('GIFI');    # construct callback -  $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}"; +  $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";    @column_index = qw(accno description); @@ -419,8 +455,10 @@ sub list_gifi {    print qq|  <body> -<table border=0 width=100%> -  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> +<table width=100%> +  <tr> +    <th class=listtop colspan=$colspan>$form->{title}</th> +  </tr>    <tr height="5"></tr>    <tr class=listheading>  |; @@ -441,7 +479,7 @@ sub list_gifi {      print qq|  <tr valign=top class=listrow$i>|; -    $column_data{accno} = qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$ca->{accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</td>|; +    $column_data{accno} = qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$ca->{accno}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|;      $column_data{description} = qq|<td>$ca->{description} </td>|;      map { print "$column_data{$_}\n" } @column_index; @@ -466,7 +504,7 @@ sub add_gifi {    $form->{title} = "Add";    # construct callback -  $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}"; +  $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";    $form->{coa} = 1; @@ -479,8 +517,10 @@ sub add_gifi {  sub edit_gifi {    $form->{title} = "Edit"; - +      AM->get_gifi(\%myconfig, \%$form); + +  $form->error($locale->text('Account does not exist!')) unless $form->{accno};    &gifi_header;    &gifi_footer; @@ -495,7 +535,7 @@ sub gifi_header {  # $locale->text('Add GIFI')  # $locale->text('Edit GIFI') -  $form->{description} =~ s/"/"/g; +  map { $form->{$_} = $form->quote($form->{$_}) } qw(accno description);    $form->header; @@ -504,7 +544,7 @@ sub gifi_header {  <form method=post action=$form->{script}> -<input type=hidden name=id value=$form->{accno}> +<input type=hidden name=id value="$form->{accno}">  <input type=hidden name=type value=gifi>  <table width=100%> @@ -517,7 +557,7 @@ sub gifi_header {        <table>  	<tr>  	  <th align=right>|.$locale->text('GIFI').qq|</th> -	  <td><input name=accno size=20 value=$form->{accno}></td> +	  <td><input name=accno size=20 value="$form->{accno}"></td>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Description').qq|</th> @@ -543,23 +583,27 @@ sub gifi_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> -<br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> -|; +<br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|;    if ($form->{coa}) {      print qq|  <input type=submit class=submit name=action value="|.$locale->text('Copy to COA').qq|">  |; -    if ($form->{accno}) { +    if ($form->{accno} && $form->{orphaned}) {        print qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;      }    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print qq| -</form> +  </form>  </body>  </html> @@ -585,10 +629,11 @@ sub copy_to_coa {    delete $form->{id};    $form->{gifi_accno} = $form->{accno}; +      $form->{title} = "Add";    $form->{charttype} = "A"; -  &form_header; +  &account_header;    &form_footer;  } @@ -602,6 +647,775 @@ sub delete_gifi {  } +sub add_department { + +  $form->{title} = "Add"; +  $form->{role} = "P"; +   +  $form->{callback} = "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &department_header; +  &form_footer; + +} + + +sub edit_department { + +  $form->{title} = "Edit"; + +  AM->get_department(\%myconfig, \%$form); + +  &department_header; +  &form_footer; + +} + + +sub list_department { + +  AM->departments(\%myconfig, \%$form); + +  $href = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $form->sort_order(); +   +  $form->{callback} = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $callback = $form->escape($form->{callback}); +   +  $form->{title} = $locale->text('Departments'); + +  @column_index = qw(description cost profit); + +  $column_header{description} = qq|<th width=90%><a class=listheading href=$href>|.$locale->text('Description').qq|</a></th>|; +  $column_header{cost} = qq|<th class=listheading nowrap>|.$locale->text('Cost Center').qq|</th>|; +  $column_header{profit} = qq|<th class=listheading nowrap>|.$locale->text('Profit Center').qq|</th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{ALL} }) { +     +    $i++; $i %= 2; +     +    print qq| +        <tr valign=top class=listrow$i> +|; + +   $costcenter = ($ref->{role} eq "C") ? "*" : " "; +   $profitcenter = ($ref->{role} eq "P") ? "*" : " "; +    +   $column_data{description} = qq|<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>|; +   $column_data{cost} = qq|<td align=center>$costcenter</td>|; +   $column_data{profit} = qq|<td align=center>$profitcenter</td>|; + +   map { print "$column_data{$_}\n" } @column_index; + +   print qq| +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +  <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=department> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Add Department').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> +   +  </body> +  </html>  +|; +   +} + + +sub department_header { + +  $form->{title} = $locale->text("$form->{title} Department"); + +# $locale->text('Add Department') +# $locale->text('Edit Department') + +  $form->{description} = $form->quote($form->{description}); + +  if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { +    $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|; +  } else { +    $description = qq|<input name=description size=60 value="$form->{description}">|; +  } + +  $costcenter = "checked" if $form->{role} eq "C"; +  $profitcenter = "checked" if $form->{role} eq "P"; +   +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<input type=hidden name=type value=department> + +<table width=100%> +  <tr> +    <th class=listtop colspan=2>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <th align=right>|.$locale->text('Description').qq|</th> +    <td>$description</td> +  </tr> +  <tr> +    <td></td> +    <td><input type=radio style=radio name=role value="C" $costcenter> |.$locale->text('Cost Center').qq| +        <input type=radio style=radio name=role value="P" $profitcenter> |.$locale->text('Profit Center').qq| +    </td> +  <tr> +    <td colspan=2><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub save_department { + +  $form->isblank("description", $locale->text('Description missing!')); +  AM->save_department(\%myconfig, \%$form); +  $form->redirect($locale->text('Department saved!')); + +} + + +sub delete_department { + +  AM->delete_department(\%myconfig, \%$form); +  $form->redirect($locale->text('Department deleted!')); + +} + + +sub add_business { + +  $form->{title} = "Add"; +   +  $form->{callback} = "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &business_header; +  &form_footer; + +} + + +sub edit_business { + +  $form->{title} = "Edit"; + +  AM->get_business(\%myconfig, \%$form); + +  &business_header; + +  $form->{orphaned} = 1; +  &form_footer; + +} + + +sub list_business { + +  AM->business(\%myconfig, \%$form); + +  $href = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $form->sort_order(); +   +  $form->{callback} = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $callback = $form->escape($form->{callback}); +   +  $form->{title} = $locale->text('Type of Business'); + +  @column_index = qw(description discount); + +  $column_header{description} = qq|<th width=90%><a class=listheading href=$href>|.$locale->text('Description').qq|</a></th>|; +  $column_header{discount} = qq|<th class=listheading>|.$locale->text('Discount').qq| %</th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{ALL} }) { +     +    $i++; $i %= 2; +     +    print qq| +        <tr valign=top class=listrow$i> +|; + +   $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100, 2, " "); +    +   $column_data{description} = qq|<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>|; +   $column_data{discount} = qq|<td align=right>$discount</td>|; +    +   map { print "$column_data{$_}\n" } @column_index; + +   print qq| +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +  <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=business> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Add Business').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +   +  </form> +   +  </body> +  </html>  +|; +   +} + + +sub business_header { + +  $form->{title} = $locale->text("$form->{title} Business"); + +# $locale->text('Add Business') +# $locale->text('Edit Business') + +  $form->{description} = $form->quote($form->{description}); +  $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100); + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<input type=hidden name=type value=business> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right>|.$locale->text('Type of Business').qq|</th> +	  <td><input name=description size=30 value="$form->{description}"></td> +	<tr> +	<tr> +	  <th align=right>|.$locale->text('Discount').qq| %</th> +	  <td><input name=discount size=5 value=$form->{discount}></td> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub save_business { + +  $form->isblank("description", $locale->text('Description missing!')); +  AM->save_business(\%myconfig, \%$form); +  $form->redirect($locale->text('Business saved!')); + +} + + +sub delete_business { + +  AM->delete_business(\%myconfig, \%$form); +  $form->redirect($locale->text('Business deleted!')); + +} + + + +sub add_sic { + +  $form->{title} = "Add"; +   +  $form->{callback} = "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &sic_header; +  &form_footer; + +} + + +sub edit_sic { + +  $form->{title} = "Edit"; + +  $form->{code} =~ s/\\'/'/g; +  $form->{code} =~ s/\\\\/\\/g; +   +  AM->get_sic(\%myconfig, \%$form); +  $form->{id} = $form->{code}; + +  &sic_header; + +  $form->{orphaned} = 1; +  &form_footer; + +} + + +sub list_sic { + +  AM->sic(\%myconfig, \%$form); + +  $href = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $form->sort_order(); + +  $form->{callback} = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $callback = $form->escape($form->{callback}); +   +  $form->{title} = $locale->text('Standard Industrial Codes'); + +  @column_index = $form->sort_columns(qw(code description)); + +  $column_header{code} = qq|<th><a class=listheading href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|; +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{ALL} }) { +     +    $i++; $i %= 2; +     +    if ($ref->{sictype} eq 'H') { +      print qq| +        <tr valign=top class=listheading> +|; +      $column_data{code} = qq|<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>|; +      $column_data{description} = qq|<th>$ref->{description}</th>|; +      +    } else { +      print qq| +        <tr valign=top class=listrow$i> +|; + +      $column_data{code} = qq|<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>|; +      $column_data{description} = qq|<td>$ref->{description}</td>|; + +   } +     +   map { print "$column_data{$_}\n" } @column_index; + +   print qq| +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +  <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=sic> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Add SIC').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> +   +  </body> +  </html>  +|; +   +} + + +sub sic_header { + +  $form->{title} = $locale->text("$form->{title} SIC"); + +# $locale->text('Add SIC') +# $locale->text('Edit SIC') + +  map { $form->{$_} = $form->quote($form->{$_}) } qw(code description); + +  $checked = ($form->{sictype} eq 'H') ? "checked" : ""; + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=type value=sic> +<input type=hidden name=id value="$form->{code}"> + +<table width=100%> +  <tr> +    <th class=listtop colspan=2>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <th align=right>|.$locale->text('Code').qq|</th> +    <td><input name=code size=10 value="$form->{code}"></td> +  <tr> +  <tr> +    <td></td> +    <th align=left><input name=sictype type=checkbox style=checkbox value="H" $checked> |.$locale->text('Heading').qq|</th> +  <tr> +  <tr> +    <th align=right>|.$locale->text('Description').qq|</th> +    <td><input name=description size=60 value="$form->{description}"></td> +  </tr> +    <td colspan=2><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub save_sic { + +  $form->isblank("code", $locale->text('Code missing!')); +  $form->isblank("description", $locale->text('Description missing!')); +  AM->save_sic(\%myconfig, \%$form); +  $form->redirect($locale->text('SIC saved!')); + +} + + +sub delete_sic { + +  AM->delete_sic(\%myconfig, \%$form); +  $form->redirect($locale->text('SIC deleted!')); + +} + + +sub add_language { + +  $form->{title} = "Add"; +   +  $form->{callback} = "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &language_header; +  &form_footer; + +} + + +sub edit_language { + +  $form->{title} = "Edit"; + +  $form->{code} =~ s/\\'/'/g; +  $form->{code} =~ s/\\\\/\\/g; +   +  AM->get_language(\%myconfig, \%$form); +  $form->{id} = $form->{code}; + +  &language_header; + +  $form->{orphaned} = 1; +  &form_footer; + +} + + +sub list_language { + +  AM->language(\%myconfig, \%$form); + +  $href = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $form->sort_order(); + +  $form->{callback} = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $callback = $form->escape($form->{callback}); +   +  $form->{title} = $locale->text('Languages'); + +  @column_index = $form->sort_columns(qw(code description)); + +  $column_header{code} = qq|<th><a class=listheading href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|; +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{ALL} }) { +     +    $i++; $i %= 2; + +    print qq| +        <tr valign=top class=listrow$i> +|; + +    $column_data{code} = qq|<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>|; +    $column_data{description} = qq|<td>$ref->{description}</td>|; +     +   map { print "$column_data{$_}\n" } @column_index; + +   print qq| +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +  <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=language> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Add Language').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> +   +  </body> +  </html>  +|; +   +} + + +sub language_header { + +  $form->{title} = $locale->text("$form->{title} Language"); + +# $locale->text('Add Language') +# $locale->text('Edit Language') + +  map { $form->{$_} = $form->quote($form->{$_}) } qw(code description); + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=type value=language> +<input type=hidden name=id value="$form->{code}"> + +<table width=100%> +  <tr> +    <th class=listtop colspan=2>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <th align=right>|.$locale->text('Code').qq|</th> +    <td><input name=code size=10 value="$form->{code}"></td> +  <tr> +  <tr> +    <th align=right>|.$locale->text('Description').qq|</th> +    <td><input name=description size=60 value="$form->{description}"></td> +  </tr> +    <td colspan=2><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub save_language { + +  $form->isblank("code", $locale->text('Code missing!')); +  $form->isblank("description", $locale->text('Description missing!')); +  AM->save_language(\%myconfig, \%$form); +  $form->redirect($locale->text('Language saved!')); + +} + + +sub delete_language { + +  AM->delete_language(\%myconfig, \%$form); +  $form->redirect($locale->text('Language deleted!')); + +} + +  sub display_stylesheet {    $form->{file} = "css/$myconfig{stylesheet}"; @@ -612,7 +1426,7 @@ sub display_stylesheet {  sub display_form { -  $form->{file} =~ s/^(.:)*?\/|\.\.\///g; +  $form->{file} =~ s/^(.:)*?\/|\.\.\///g;     $form->{file} =~ s/^\/*//g;    $form->{file} =~ s/$userspath//; @@ -637,14 +1451,21 @@ $form->{body}  <form method=post action=$form->{script}>  <input name=file type=hidden value=$form->{file}> +<input name=type type=hidden value=template>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> -<input name=action type=submit class=submit value="|.$locale->text('Edit').qq|"> -</form> +<input name=action type=submit class=submit value="|.$locale->text('Edit').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +  print qq| +  </form>  </body>  </html> @@ -674,18 +1495,24 @@ sub edit_template {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> -<input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}"> +<input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}">  <textarea name=body rows=25 cols=70>  $form->{body}  </textarea>  <br> -<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|; -</form> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print q| +  </form>  </body> @@ -703,41 +1530,18 @@ sub save_template {  } -sub config { - +sub defaults { +      # get defaults for account numbers and last numbers    AM->defaultaccounts(\%myconfig, \%$form); -  foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { -    $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n"; -  } - -  foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) { -    $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n"; -  } - -  foreach $item (qw(name company address signature shippingpoint)) { -    $myconfig{$item} =~ s/"/"/g; -  } - -  foreach $item (qw(address signature)) { -    $myconfig{$item} =~ s/\\n/\r\n/g; -  } - -  %countrycodes = User->country_codes; -  $countrycodes = ''; -  foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { -    $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n"; -  } -  $countrycodes = "<option>American English\n$countrycodes"; -    foreach $key (keys %{ $form->{IC} }) {      foreach $accno (sort keys %{ $form->{IC}{$key} }) { -      $myconfig{$key} .= ($form->{IC}{$key}{$accno}{id} == $form->{defaults}{$key}) ? "<option selected>$accno--$form->{IC}{$key}{$accno}{description}\n" : "<option>$accno--$form->{IC}{$key}{$accno}{description}\n"; +      $form->{account}{$key} .= ($form->{IC}{$key}{$accno}{id} == $form->{defaults}{$key}) ? "<option selected>$accno--$form->{IC}{$key}{$accno}{description}\n" : "<option>$accno--$form->{IC}{$key}{$accno}{description}\n";      }    } -   -  $form->{title} = $locale->text('Edit Preferences for').qq| $form->{login}|; + +  $form->{title} = $locale->text('System Defaults');    $form->header; @@ -746,173 +1550,319 @@ sub config {  <form method=post action=$form->{script}> -<input type=hidden name=old_password value=$myconfig{password}> -<input type=hidden name=type value=preferences> +<input type=hidden name=type value=defaults>  <table width=100%>    <tr><th class=listtop>$form->{title}</th></tr>    <tr>      <td>        <table> -        <tr> -	  <th align=right>|.$locale->text('Name').qq|</th> -	  <td><input name=name size=15 value="$myconfig{name}"></td> +	<tr> +	  <th align=right>|.$locale->text('Business Number').qq|</th> +	  <td><input name=businessnumber size=25 value="$form->{defaults}{businessnumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Password').qq|</th> -	  <td><input type=password name=password size=10 value=$myconfig{password}></td> +	  <th align=right>|.$locale->text('Weight Unit').qq|</th> +	  <td><input name=weightunit size=5 value="$form->{defaults}{weightunit}"></td>  	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <th class=listheading>|.$locale->text('Last Numbers & Default Accounts').qq|</th> +  </tr> +  <tr> +    <td> +      <table>  	<tr> -	  <th align=right>|.$locale->text('E-mail').qq|</th> -	  <td><input name=email size=30 value="$myconfig{email}"></td> +	  <th align=right nowrap>|.$locale->text('Inventory Account').qq|</th> +	  <td><select name=inventory_accno>$form->{account}{IC}</select></td>  	</tr> -	<tr valign=top> -	  <th align=right>|.$locale->text('Signature').qq|</th> -	  <td><textarea name=signature rows=3 cols=50>$myconfig{signature}</textarea></td> +	<tr> +	  <th align=right nowrap>|.$locale->text('Income Account').qq|</th> +	  <td><select name=income_accno>$form->{account}{IC_income}</select></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Phone').qq|</th> -	  <td><input name=tel size=14 value="$myconfig{tel}"></td> +	  <th align=right nowrap>|.$locale->text('Expense Account').qq|</th> +	  <td><select name=expense_accno>$form->{account}{IC_expense}</select></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Fax').qq|</th> -	  <td><input name=fax size=14 value="$myconfig{fax}"></td> +	  <th align=right nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th> +	  <td><select name=fxgain_accno>$form->{account}{FX_gain}</select></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Company').qq|</th> -	  <td><input name=company size=30 value="$myconfig{company}"></td> +	  <th align=right nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th> +	  <td><select name=fxloss_accno>$form->{account}{FX_loss}</select></td>  	</tr> -	<tr valign=top> -	  <th align=right>|.$locale->text('Address').qq|</th> -	  <td><textarea name=address rows=4 cols=50>$myconfig{address}</textarea></td> +      </table> +    </td> +  </tr> +  <tr> +    <th align=left>|.$locale->text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies').qq|</th> +  </tr> +  <tr> +    <td> +    <input name=curr size=40 value="$form->{defaults}{curr}"> +    </td> +  </tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right nowrap>|.$locale->text('Sales Invoice Number').qq|</th> +	  <td><input name=sinumber size=40 value="$form->{defaults}{sinumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Date Format').qq|</th> -	  <td><select name=dateformat>$dateformat</select></td> +	  <th align=right nowrap>|.$locale->text('Sales Order Number').qq|</th> +	  <td><input name=sonumber size=40 value="$form->{defaults}{sonumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Number Format').qq|</th> -	  <td><select name=numberformat>$numberformat</select></td> +	  <th align=right nowrap>|.$locale->text('Vendor Invoice Number').qq|</th> +	  <td><input name=vinumber size=40 value="$form->{defaults}{vinumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Dropdown Limit').qq|</th> -	  <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td> +	  <th align=right nowrap>|.$locale->text('Purchase Order Number').qq|</th> +	  <td><input name=ponumber size=40 value="$form->{defaults}{ponumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Language').qq|</th> -	  <td><select name=countrycode>$countrycodes</select></td> +	  <th align=right nowrap>|.$locale->text('Sales Quotation Number').qq|</th> +	  <td><input name=sqnumber size=40 value="$form->{defaults}{sqnumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Character Set').qq|</th> -	  <td><input name=charset size=20 value="$myconfig{charset}"></td> +	  <th align=right nowrap>|.$locale->text('RFQ Number').qq|</th> +	  <td><input name=rfqnumber size=40 value="$form->{defaults}{rfqnumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Stylesheet').qq|</th> -	  <td><input name=stylesheet size=20 value="$myconfig{stylesheet}"></td> +	  <th align=right nowrap>|.$locale->text('Partnumber').qq|</th> +	  <td><input name=partnumber size=40 value="$form->{defaults}{partnumber}"></td>  	</tr> -	<input name=printer type=hidden value="$myconfig{printer}">  	<tr> -	  <th align=right>|.$locale->text('Ship via').qq|</th> -	  <td><input name=shippingpoint size=25 value="$myconfig{shippingpoint}"></td> +	  <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> +	  <td><input name=employeenumber size=40 value="$form->{defaults}{employeenumber}"></td>  	</tr> -	<tr class=listheading> -	  <th colspan=2> </th> +	<tr> +	  <th align=right nowrap>|.$locale->text('Customer Number').qq|</th> +	  <td><input name=customernumber size=40 value="$form->{defaults}{customernumber}"></td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('Business Number').qq|</th> -	  <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td> +	  <th align=right nowrap>|.$locale->text('Vendor Number').qq|</th> +	  <td><input name=vendornumber size=40 value="$form->{defaults}{vendornumber}"></td>  	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <th class=listheading>|.$locale->text('Tax Accounts').qq|</th> +  </tr> +  <tr> +    <td> +      <table>  	<tr> -	  <td colspan=2> -	    <table width=100%> +	  <th></th> +	  <th>|.$locale->text('Rate').qq| (%)</th> +	  <th>|.$locale->text('Number').qq|</th> +	</tr> +|; + +  foreach $accno (sort keys %{ $form->{taxrates} }) { +    $form->{taxrates}{$accno}{rate} = $form->format_amount(\%myconfig, $form->{taxrates}{$accno}{rate}); +     +    print qq| +	<tr> +	  <th align=right>$form->{taxrates}{$accno}{description}</th> +	  <td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td> +	  <td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td> +	</tr> +|; +    $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} "; +  } + +  chop $form->{taxaccounts}; + +  print qq| +      </table> +    </td> +  </tr> +<input name=taxaccounts type=hidden value="$form->{taxaccounts}"> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<br> +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; + + +} + + +sub config { + +  foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { +    $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n"; +  } + +  foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00)) { +    $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n"; +  } + +  map { $myconfig{$_} = $form->quote($myconfig{$_}) } qw(name company address signature); +  map { $myconfig{$_} =~ s/\\n/\r\n/g } qw(address signature); + +  %countrycodes = User->country_codes; +  $countrycodes = ''; +   +  foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { +    $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n"; +  } +  $countrycodes = qq|<option value="">English\n$countrycodes|; + +  opendir CSS, "css/."; +  @all = grep /.*\.css$/, readdir CSS; +  closedir CSS; + +  foreach $item (@all) { +    if ($item eq $myconfig{stylesheet}) { +      $selectstylesheet .= qq|<option selected>$item\n|; +    } else { +      $selectstylesheet .= qq|<option>$item\n|; +    } +  } +  $selectstylesheet .= "<option>\n"; +   +  if (%printer && $latex) { +    $selectprinter = "<option>\n"; +    foreach $item (sort keys %printer) { +      if ($myconfig{printer} eq $item) { +	$selectprinter .= qq|<option value="$item" selected>$item\n|; +      } else { +	$selectprinter .= qq|<option value="$item">$item\n|; +      } +    } + +    $printer = qq| +	      <tr> +		<th align=right>|.$locale->text('Printer').qq|</th> +		<td><select name=printer>$selectprinter</select></td> +	      </tr> +|; +  } +   +  $form->{title} = $locale->text('Edit Preferences for').qq| $form->{login}|; +   +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=old_password value=$myconfig{password}> +<input type=hidden name=type value=preferences> +<input type=hidden name=role value=$myconfig{role}> + +<table width=100%> +  <tr><th class=listtop>$form->{title}</th></tr> +  <tr> +    <td> +      <table width=100%> +        <tr valign=top> +	  <td> +	    <table> +	      <tr> +		<th align=right>|.$locale->text('Name').qq|</th> +		<td><input name=name size=20 value="$myconfig{name}"></td> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('E-mail').qq|</th> +		<td><input name=email size=35 value="$myconfig{email}"></td> +	      </tr> +	      <tr valign=top> +		<th align=right>|.$locale->text('Signature').qq|</th> +		<td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Phone').qq|</th> +		<td><input name=tel size=14 value="$myconfig{tel}"></td> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Fax').qq|</th> +		<td><input name=fax size=14 value="$myconfig{fax}"></td> +	      </tr>  	      <tr> -		<th align=right>|.$locale->text('Year End').qq| (mm/dd)</th> -		<td><input name=yearend size=5 maxsize=5 value=$form->{defaults}{yearend}></td> -		<th align=right>|.$locale->text('Weight Unit').qq|</th> -		<td><input name=weightunit size=5 value="$form->{defaults}{weightunit}"></td> +		<th align=right>|.$locale->text('Company').qq|</th> +		<td><input name=company size=35 value="$myconfig{company}"></td> +	      </tr> +	      <tr valign=top> +		<th align=right>|.$locale->text('Address').qq|</th> +		<td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>  	      </tr>  	    </table>  	  </td> -	</tr> -	<tr class=listheading> -	  <th class=listheading colspan=2>|.$locale->text('Last Numbers & Default Accounts').qq|</th> -	</tr> -	<tr> -	  <td colspan=2> -	    <table width=100%> +	  <td> +	    <table>  	      <tr> -		<th width=1% align=right nowrap>|.$locale->text('Inventory Account').qq|</th> -		<td><select name=inventory_accno>$myconfig{IC}</select></td> +		<th align=right>|.$locale->text('Password').qq|</th> +		<td><input type=password name=new_password size=10 value=$myconfig{password}></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Income Account').qq|</th> -		<td><select name=income_accno>$myconfig{IC_income}</select></td> +		<th align=right>|.$locale->text('Confirm').qq|</th> +		<td><input type=password name=confirm_password size=10></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Expense Account').qq|</th> -		<td><select name=expense_accno>$myconfig{IC_expense}</select></td> +		<th align=right>|.$locale->text('Date Format').qq|</th> +		<td><select name=dateformat>$dateformat</select></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th> -		<td><select name=fxgain_accno>$myconfig{FX_gain}</select></td> +		<th align=right>|.$locale->text('Number Format').qq|</th> +		<td><select name=numberformat>$numberformat</select></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th> -		<td><select name=fxloss_accno>$myconfig{FX_loss}</select></td> +		<th align=right>|.$locale->text('Dropdown Limit').qq|</th> +		<td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>  	      </tr>  	      <tr> -		<td colspan=2>|.$locale->text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies').qq|<br><input name=curr size=40 value="$form->{defaults}{curr}"></td> +		<th align=right>|.$locale->text('Menu Width').qq|</th> +		<td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Last Invoice Number').qq|</th> -		<td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></td> +		<th align=right>|.$locale->text('Language').qq|</th> +		<td><select name=countrycode>$countrycodes</select></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Last Sales Order Number').qq|</th> -		<td><input name=sonumber size=10 value=$form->{defaults}{sonumber}></td> +		<th align=right>|.$locale->text('Character Set').qq|</th> +		<td><input name=charset size=20 value="$myconfig{charset}"></td>  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Last Purchase Order Number').qq|</th> -		<td><input name=ponumber size=10 value=$form->{defaults}{ponumber}></td> +		<th align=right>|.$locale->text('Session Timeout').qq|</th> +		<td><input name=timeout size=10 value="$myconfig{timeout}"></td>  	      </tr> -	    </table> -	  </td> -	</tr> -	<tr class=listheading> -	  <th class=listheading colspan=2>|.$locale->text('Tax Accounts').qq|</th> -	</tr> -	<tr> -	  <td colspan=2> -	    <table>  	      <tr> -		<th> </th> -		<th>|.$locale->text('Rate').qq| (%)</th> -		<th>|.$locale->text('Number').qq|</th> -	      </tr> -|; - -  foreach $accno (sort keys %{ $form->{taxrates} }) { -    print qq| -              <tr> -		<th align=right>$form->{taxrates}{$accno}{description}</th> -		<td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td> -		<td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td> +		<th align=right>|.$locale->text('Stylesheet').qq|</th> +		<td><select name=usestylesheet>$selectstylesheet</select></td>  	      </tr> -|; -    $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} "; -  } - -  chop $form->{taxaccounts}; - -  print qq| -<input name=taxaccounts type=hidden value="$form->{taxaccounts}"> - -            </table> +	      $printer +	    </table>  	  </td>  	</tr>        </table>      </td> -  </tr>    <tr>      <td><hr size=3 noshade></td>    </tr> @@ -920,11 +1870,18 @@ sub config {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br> -<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> -</form> +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form>  </body>  </html> @@ -933,14 +1890,23 @@ sub config {  } +sub save_defaults { + +  $form->redirect($locale->text('Defaults saved!')) if (AM->save_defaults(\%myconfig, \%$form)); +  $form->error($locale->text('Cannot save defaults!')); + +} + +  sub save_preferences { -  # does stylesheet exist -  if ($form->{stylesheet}) { -    $form->error($locale->text('Stylesheet').": css/$form->{stylesheet} ".$locale->text('does not exist')) unless (-f "css/$form->{stylesheet}"); -  }  +  $form->{stylesheet} = $form->{usestylesheet}; + +  if ($form->{new_password} ne $form->{old_password}) { +    $form->error($locale->text('Password does not match!')) if $form->{new_password} ne $form->{confirm_password}; +  } -  $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath)); +  $form->redirect($locale->text('Preferences saved!')) if AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath);    $form->error($locale->text('Cannot save preferences!'));  } @@ -954,8 +1920,9 @@ sub backup {      $form->{OUT} = "$sendmail";    } -   -  AM->backup(\%myconfig, \%$form, $userspath); + +  $SIG{INT} = 'IGNORE'; +  AM->backup(\%myconfig, \%$form, $userspath, $gzip);    if ($form->{media} eq 'email') {      $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|); @@ -972,11 +1939,17 @@ sub audit_control {    AM->closedto(\%myconfig, \%$form);    if ($form->{revtrans}) { -    $checked{Y} = "checked"; +    $checked{revtransY} = "checked";    } else { -    $checked{N} = "checked"; +    $checked{revtransN} = "checked";    } +  if ($form->{audittrail}) { +    $checked{audittrailY} = "checked"; +  } else { +    $checked{audittrailN} = "checked"; +  } +     $form->header;    print qq| @@ -986,7 +1959,7 @@ sub audit_control {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <table width=100%>    <tr><th class=listtop>$form->{title}</th></tr> @@ -995,13 +1968,21 @@ sub audit_control {      <td>        <table>  	<tr> -	  <td>|.$locale->text('Enforce transaction reversal for all dates').qq|</th> -	  <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |.$locale->text('Yes').qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |.$locale->text('No').qq|</td> +	  <th align=right>|.$locale->text('Enforce transaction reversal for all dates').qq|</th> +	  <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |.$locale->text('Yes').qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |.$locale->text('No').qq|</td>  	</tr>  	<tr> -	  <td>|.$locale->text('Close Books up to').qq|</th> +	  <th align=right>|.$locale->text('Close Books up to').qq|</th>  	  <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>  	</tr> +	<tr> +	  <th align=right>|.$locale->text('Activate Audit trails').qq|</th> +	  <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |.$locale->text('Yes').qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |.$locale->text('No').qq|</td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Remove Audit trails up to').qq|</th> +	  <td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td> +	</tr>        </table>      </td>    </tr> @@ -1028,19 +2009,381 @@ sub doclose {    AM->closebooks(\%myconfig, \%$form);    if ($form->{revtrans}) { -    $form->redirect($locale->text('Transaction reversal enforced for all dates')); +    $msg = $locale->text('Transaction reversal enforced for all dates');    } else {      if ($form->{closedto}) { -      $form->redirect($locale->text('Transaction reversal enforced up to') -      ." ".$locale->date(\%myconfig, $form->{closedto}, 1)); +      $msg = $locale->text('Transaction reversal enforced up to') +      ." ".$locale->date(\%myconfig, $form->{closedto}, 1);      } else { -      $form->redirect($locale->text('Books are open')); +      $msg = $locale->text('Books are open');      }    } +  $msg .= "<p>"; +  if ($form->{audittrail}) { +    $msg .= $locale->text('Audit trails enabled'); +  } else { +    $msg .= $locale->text('Audit trails disabled'); +  } + +  $msg .= "<p>"; +  if ($form->{removeaudittrail}) { +    $msg .= $locale->text('Audit trail removed up to') +    ." ".$locale->date(\%myconfig, $form->{removeaudittrail}, 1); +  } +     +  $form->redirect($msg); +   +} + + +sub add_warehouse { + +  $form->{title} = "Add"; +   +  $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &warehouse_header; +  &form_footer; + +} + + +sub edit_warehouse { + +  $form->{title} = "Edit"; + +  AM->get_warehouse(\%myconfig, \%$form); + +  &warehouse_header; +  &form_footer; +  } +sub list_warehouse { + +  AM->warehouses(\%myconfig, \%$form); + +  $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $form->sort_order(); +   +  $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $callback = $form->escape($form->{callback}); +   +  $form->{title} = $locale->text('Warehouses'); + +  @column_index = qw(description); + +  $column_header{description} = qq|<th width=100%><a class=listheading href=$href>|.$locale->text('Description').qq|</a></th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{ALL} }) { +     +    $i++; $i %= 2; +     +    print qq| +        <tr valign=top class=listrow$i> +|; + +   $column_data{description} = qq|<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>|; + +   map { print "$column_data{$_}\n" } @column_index; + +   print qq| +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +  <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=warehouse> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Add Warehouse').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> +   +  </body> +  </html>  +|; +   +} + + + +sub warehouse_header { + +  $form->{title} = $locale->text("$form->{title} Warehouse"); + +# $locale->text('Add Warehouse') +# $locale->text('Edit Warehouse') + +  $form->{description} = $form->quote($form->{description}); + +  if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { +    $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|; +  } else { +    $description = qq|<input name=description size=60 value="$form->{description}">|; +  } + +   +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<input type=hidden name=type value=warehouse> + +<table width=100%> +  <tr> +    <th class=listtop colspan=2>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <th align=right>|.$locale->text('Description').qq|</th> +    <td>$description</td> +  </tr> +  <tr> +    <td colspan=2><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub save_warehouse { + +  $form->isblank("description", $locale->text('Description missing!')); +  AM->save_warehouse(\%myconfig, \%$form); +  $form->redirect($locale->text('Warehouse saved!')); + +} + + +sub delete_warehouse { + +  AM->delete_warehouse(\%myconfig, \%$form); +  $form->redirect($locale->text('Warehouse deleted!')); + +} + + +sub yearend { + +  AM->earningsaccounts(\%myconfig, \%$form); +  map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} }; +   +  $form->{title} = $locale->text('Yearend'); +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=decimalplaces value=2> +<input type=hidden name=l_accno value=Y> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right>|.$locale->text('Yearend').qq|</th> +	  <td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Reference').qq|</th> +	  <td><input name=reference size=20 value="|.$locale->text('Yearend').qq|"></td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Description').qq|</th> +	  <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Retained Earnings').qq|</th> +	  <td><select name=accno>$chart</select></td> +	</tr> +	<tr> +          <th align=right>|.$locale->text('Method').qq|</th> +          <td><input name=method class=radio type=radio value=accrual checked> |.$locale->text('Accrual').qq| <input name=method class=radio type=radio value=cash> |.$locale->text('Cash').qq|</td> +        </tr> +      </table> +    </td> +  </tr> +</table> + +<hr size=3 noshade> + +<input type=hidden name=nextsub value=generate_yearend> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|; + +} + + +sub generate_yearend { + +  $form->isblank("todate", $locale->text('Yearend date missing!')); + +  RP->yearend_statement(\%myconfig, \%$form); +   +  $form->{transdate} = $form->{todate}; + +  $earnings = 0; +   +  $form->{rowcount} = 1; +  foreach $key (keys %{ $form->{I} }) { +    if ($form->{I}{$key}{charttype} eq "A") { +      $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this}; +      $earnings += $form->{I}{$key}{this}; +      $form->{"accno_$form->{rowcount}"} = $key; +      $form->{rowcount}++; +      $ok = 1; +    } +  } + +  foreach $key (keys %{ $form->{E} }) { +    if ($form->{E}{$key}{charttype} eq "A") { +      $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1; +      $earnings += $form->{E}{$key}{this}; +      $form->{"accno_$form->{rowcount}"} = $key; +      $form->{rowcount}++; +      $ok = 1; +    } +  } +  if ($earnings > 0) { +    $form->{"credit_$form->{rowcount}"} = $earnings; +    $form->{"accno_$form->{rowcount}"} = $form->{accno} +  } else { +    $form->{"debit_$form->{rowcount}"} = $earnings * -1; +    $form->{"accno_$form->{rowcount}"} = $form->{accno} +  } +   +  if ($ok) { +    if (AM->post_yearend(\%myconfig, \%$form)) { +      $form->redirect($locale->text('Yearend posted!')); +    } +    $form->error($locale->text('Yearend posting failed!')); +  } else { +    $form->error('Nothing to do!'); +  } +   +} + + + +sub company_logo { +   +  $myconfig{address} =~ s/\\n/<br>/g; +  $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost}; + +  map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet); +   +  $form->{title} = $locale->text('About'); +   +  # create the logo screen +  $form->header; + +  print qq| +<body> + +<pre> + +</pre> +<center> +<a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.gif border=0></a> +<h1 class=login>|.$locale->text('Version').qq| $form->{version}</h1> + +<p> +|.$locale->text('Licensed to').qq| +<p> +<b> +$myconfig{company} +<br>$myconfig{address} +</b> + +<p> +<table border=0> +  <tr> +    <th align=right>|.$locale->text('User').qq|</th> +    <td>$myconfig{name}</td> +  </tr> +  <tr> +    <th align=right>|.$locale->text('Dataset').qq|</th> +    <td>$myconfig{dbname}</td> +  </tr> +  <tr> +    <th align=right>|.$locale->text('Database Host').qq|</th> +    <td>$myconfig{dbhost}</td> +  </tr> +</table> + +</center> + +</body> +</html> +|; + +} +  sub continue { diff --git a/sql-ledger/bin/mozilla/ap.pl b/sql-ledger/bin/mozilla/ap.pl index 269f7cf39..30494b6e6 100644 --- a/sql-ledger/bin/mozilla/ap.pl +++ b/sql-ledger/bin/mozilla/ap.pl @@ -1,11 +1,12 @@  #===================================================================== -# SQL-Ledger Accounting -# Copyright (c) 2001 +# SQL-Ledger, accounting project +# Copyright (C) 2000  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +#  Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -21,7 +22,7 @@  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  #======================================================================  # -# Accounts Payables +# Accounts Payable  #  #====================================================================== @@ -31,6 +32,7 @@ use SL::IR;  use SL::PE;  require "$form->{path}/arap.pl"; +require "$form->{path}/arapprn.pl";  1;  # end of main @@ -69,7 +71,7 @@ sub add {    $form->{title} = "Add"; -  $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};    &create_links;    &display_form; @@ -99,16 +101,12 @@ sub create_links {    $form->create_links("AP", \%myconfig, "vendor"); -  $taxincluded = $form->{taxincluded};    $duedate = $form->{duedate}; -   -  IR->get_vendor(\%myconfig, \%$form); -   -  $form->{duedate} = $duedate; -  $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; -   -  # build the popup menus +  $form->{formname} = "transaction"; +  $form->{format} = "postscript" if $myconfig{printer}; +  $form->{media} = $myconfig{printer}; +      # currencies    @curr = split /:/, $form->{currencies};    chomp $curr[0]; @@ -116,12 +114,40 @@ sub create_links {    map { $form->{selectcurrency} .= "<option>$_\n" } @curr; +  IR->get_vendor(\%myconfig, \%$form); + +  $form->{duedate} = $duedate if $duedate; +  $form->{notes} = $form->{intnotes} if !$form->{id}; + +  $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; +  $form->{oldtransdate} = $form->{transdate}; +      # vendors    if (@{ $form->{all_vendor} }) {      $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|; -    map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} }); +    map { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_vendor} });    } +  # departments +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $form->{employee} = "$form->{employee}--$form->{employee_id}";  +  +  # projects +  if (@{ $form->{all_projects} }) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } (@{ $form->{all_projects} }); +  } + +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  }    # forex    $form->{forex} = $form->{exchangerate}; @@ -132,6 +158,7 @@ sub create_links {      foreach $ref (@{ $form->{AP_links}{$key} }) {        if ($key eq "AP_tax") {  	$form->{"selectAP_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n"; +	$form->{"calctax_$ref->{accno}"} = 1;  	next;        }        $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; @@ -145,6 +172,7 @@ sub create_links {  	$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount};  	$form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};  	$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source}; +	$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};  	$form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate}; @@ -157,16 +185,22 @@ sub create_links {  	if ($key eq "AP_tax") {  	  $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";  	  $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate * -1, 2); -	  $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	  if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { +	    $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	    $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; +	  } else { +	    $totalwithholding += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	    $withholdingrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; +	  } +  	} else {  	  $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);  	  if ($akey eq 'amount') {  	    $form->{"${akey}_$i"} *= -1;  	    $totalamount += $form->{"${akey}_$i"};  	    $form->{rowcount}++; - -	    $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; -	    $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; +	     +	    $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}";  	  }  	  $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";  	} @@ -174,26 +208,52 @@ sub create_links {      }    } -  $form->{taxincluded} = $taxincluded if ($form->{id});    $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};    if ($form->{taxincluded} && $totalamount) {    # add tax to amounts and invtotal      for $i (1 .. $form->{rowcount}) { -      $taxamount = $totaltax * $form->{"amount_$i"} / $totalamount; +      $taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;        $tax = $form->round_amount($taxamount, 2);        $diff += ($taxamount - $tax);        $form->{"amount_$i"} += $tax;      }      $form->{amount_1} += $form->round_amount($diff, 2);    } + +  # check if calculated is equal to stored +  foreach $item (split / /, $form->{taxaccounts}) { +    if ($form->{taxincluded}) { +      if ($form->{"${item}_rate"} > 0) { +	if ($taxrate) { +	  $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $taxrate / (1 + $taxrate), 2) * $form->{"${item}_rate"} / $taxrate; +	} +      } else { +	if ($withholdingrate) { +	  $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"${item}_rate"} / $withholdingrate; +	} +      } +    } else { +      $taxamount = $totalamount * $form->{"${item}_rate"}; +    } +    $taxamount = $form->round_amount($taxamount, 2); + +    $form->{"calctax_$item"} = 0; +    if ($form->{"tax_$item"} == $taxamount) { +      $form->{"calctax_$item"} = 1; +    } +  } -  $form->{invtotal} = $totalamount + $totaltax; +  $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;    $form->{rowcount}++ if $form->{id};    $form->{AP} = $form->{AP_1}; +  $form->{rowcount} = 1 unless $form->{AP_amount_1}; +   +  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); -  $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); +  # readonly +  $form->{readonly} = 1 if $myconfig{acs} =~ /AP--Add Transaction/;  } @@ -201,35 +261,42 @@ sub create_links {  sub form_header {    $title = $form->{title}; -  $form->{title} = $locale->text("$title Accounts Payables Transaction"); +  $form->{title} = $locale->text("$title AP Transaction");    $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; -# type=submit $locale->text('Add Accounts Payables Transaction') -# type=submit $locale->text('Edit Accounts Payables Transaction') +# type=submit $locale->text('Add AP Transaction') +# type=submit $locale->text('Edit AP Transaction')    # set option selected -  foreach $item (qw(AP vendor currency)) { +  foreach $item (qw(AP currency)) {      $form->{"select$item"} =~ s/ selected//;      $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;    } - +  foreach $item (qw(vendor department)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } + +  $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}); +    # format amounts    $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); -   +    $exchangerate = qq|  <input type=hidden name=forex value=$form->{forex}>  |;    if ($form->{currency} ne $form->{defaultcurrency}) {      if ($form->{forex}) {        $exchangerate .= qq| -	      <th align=right>|.$locale->text('Exchangerate').qq|</th> +	      <th align=right>|.$locale->text('Exchange Rate').qq|</th>                <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>  |;      } else {        $exchangerate .= qq| -	     <th align=right>|.$locale->text('Exchangerate').qq|</th> +	     <th align=right>|.$locale->text('Exchange Rate').qq|</th>               <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>  |;      } @@ -251,24 +318,50 @@ sub form_header {    }    $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; -   -  $form->header; +  $department = qq| +              <tr> +	        <th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td colspan=3><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|"> +		</td> +	      </tr> +| if $form->{selectdepartment}; +  $n = ($form->{creditremaining} < 0) ? "0" : "1"; +      $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>| : qq|<input name=vendor value="$form->{vendor}" size=35>|;  + +  $form->header; +     print qq|  <body>  <form method=post action=$form->{script}>  <input type=hidden name=id value=$form->{id}> + +<input type=hidden name=type value="transaction"> +<input type=hidden name=vc value="vendor"> + +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=printed value="$form->{printed}"> +<input type=hidden name=emailed value="$form->{emailed}"> +  <input type=hidden name=sort value=$form->{sort}> +  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=locked value=$form->{locked}> +  <input type=hidden name=title value="$title"> +<input type=hidden name=employee value="$form->{employee}"> + +<input type=hidden name=oldtransdate value=$form->{oldtransdate}> +<input type=hidden name=audittrail value="$form->{audittrail}"> +  <table width=100%> -  <tr class=listtop> +  <tr>      <th class=listtop>$form->{title}</th>    </tr>    <tr height="5"></tr> @@ -281,13 +374,25 @@ sub form_header {  	      <tr>  		<th align=right nowrap>|.$locale->text('Vendor').qq|</th>  		<td colspan=3>$vendor</td> -		<input type=hidden name=selectvendor value="$form->{selectvendor}"> +		<input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|">  		<input type=hidden name=oldvendor value="$form->{oldvendor}">  		<input type=hidden name=vendor_id value="$form->{vendor_id}">  		<input type=hidden name=terms value=$form->{terms}>  	      </tr> -	      $taxincluded -	      </tr> +	      <tr> +	        <td></td> +		<td colspan=3> +		  <table width=100%> +		    <tr> +		      <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th> +		      <td>$form->{creditlimit}</td> +		      <th align=left nowrap>|.$locale->text('Remaining').qq|</th> +		      <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td> +		      <input type=hidden name=creditlimit value=$form->{creditlimit}> +		      <input type=hidden name=creditremaining value=$form->{creditremaining}> +		    </tr> +		  </table> +		</td>  	      <tr>  		<th align=right nowrap>|.$locale->text('Currency').qq|</th>  		<td><select name=currency>$form->{selectcurrency}</select></td> @@ -297,17 +402,19 @@ sub form_header {  		<input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>  		$exchangerate  	      </tr> +	      $department +	      $taxincluded  	    </table>  	  </td>  	  <td align=right>  	    <table>  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -		<td><input name=invnumber size=11 value="$form->{invnumber}"></td> +		<td><input name=invnumber size=20 value="$form->{invnumber}"></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> -		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td> +		<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Date').qq|</th> @@ -324,6 +431,7 @@ sub form_header {      </td>    </tr>    <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}"> +  <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">    <input type=hidden name=rowcount value=$form->{rowcount}>    <tr>      <td> @@ -331,35 +439,40 @@ sub form_header {  |;    $amount = $locale->text('Amount'); -  $project = $locale->text('Project'); -   -  for $i (1 .. $form->{rowcount}) { -    $form->{"selectAP_amount"} =~ s/ selected//; -    $form->{"selectAP_amount"} =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/; +  for $i (1 .. $form->{rowcount}) { +    $selectAP_amount = $form->{selectAP_amount}; +    $selectAP_amount =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/; +     +    $selectprojectnumber = $form->{selectprojectnumber}; +    $selectprojectnumber =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/; +          # format amounts      $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); +    $project = qq| +          <td align=right><select name="projectnumber_$i">$selectprojectnumber</select></td> +| if $form->{selectprojectnumber}; +	        print qq|  	<tr>  	  <th align=right nowrap>$amount</th>  	  <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td> -	  <th>$project</th> -	  <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}"> -	      <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}> -	      <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td> -	  <td width=50%><select name="AP_amount_$i">$form->{selectAP_amount}</select></td> +	  <td></td> +	  <td><select name="AP_amount_$i">$selectAP_amount</select></td> +	  $project  	</tr>  |;      $amount = ""; -    $project = "";    }    $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');    foreach $item (split / /, $form->{taxaccounts}) { +    $form->{"calctax_$item"} = ($form->{"calctax_$item"}) ? "checked" : ""; +          # format and reverse tax      $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);  @@ -367,11 +480,12 @@ sub form_header {          <tr>  	  <th align=right nowrap>${taxlabel}</th>  	  <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td> -	  <td colspan=2></td> +	  <td align=right><input name="calctax_$item" class=checkbox type=checkbox value=1 $form->{"calctax_$item"}></td>  	  <td><select name=AP_tax_$item>$form->{"selectAP_tax_$item"}</select></td>          </tr>  	<input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">  	<input type=hidden name="${item}_description" value="$form->{"${item}_description"}"> +	<input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">  	<input type=hidden name="selectAP_tax_$item" value="$form->{"selectAP_tax_$item"}">  |;    } @@ -382,12 +496,18 @@ sub form_header {          <tr>  	  <th align=right nowrap>|.$locale->text('Total').qq|</th>  	  <td>$form->{invtotal}</td> -	  <td colspan=2></td> +	  <td></td> + +	  <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}> +	  <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}> +	   +	  <input type=hidden name=taxaccounts value="$form->{taxaccounts}"> +	              <td><select name=AP>$form->{selectAP}</select></td>  	  <input type=hidden name=selectAP value="$form->{selectAP}"> -	  <input type=hidden name=taxaccounts value="$form->{taxaccounts}"> +	    	</tr> -	<tr> +	<tr valign=top>  	  <th align=right nowrap>|.$locale->text('Notes').qq|</th>  	  <td colspan=5>$notes</td>  	</tr> @@ -398,15 +518,15 @@ sub form_header {      <td>        <table width=100%>  	<tr class=listheading> -	  <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th> +	  <th class=listheading colspan=6>|.$locale->text('Payments').qq|</th>  	</tr>  |;    if ($form->{currency} eq $form->{defaultcurrency}) { -    @column_index = qw(datepaid source paid AP_paid); +    @column_index = qw(datepaid source memo paid AP_paid);    } else { -    @column_index = qw(datepaid source paid exchangerate AP_paid); +    @column_index = qw(datepaid source memo paid exchangerate AP_paid);    }    $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; @@ -414,6 +534,7 @@ sub form_header {    $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";    $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";    $column_data{source} = "<th>".$locale->text('Source')."</th>"; +  $column_data{memo} = "<th>".$locale->text('Memo')."</th>";    print "          <tr> @@ -449,12 +570,13 @@ sub form_header {  <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>  |; -    $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|; +    $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;      $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;      $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;      $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}></td>|; -    $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|; - +    $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|; +    $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|; +          map { print qq|$column_data{"${_}_$i"}\n| } @column_index;      print " @@ -480,46 +602,57 @@ sub form_header {  sub form_footer { +  &print_options; +      print qq|  <input name=callback type=hidden value="$form->{callback}">  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> -<br> +<p>  |; +      $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -   -  if ($form->{id}) { -    print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> + +  if (! $form->{readonly}) { +     +    if ($form->{id}) { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">  |; -    if (!$form->{revtrans}) {        if (!$form->{locked}) {  	print qq|  	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">  	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|"> -|; +  |;        } -    } -    if ($transdate > $closedto) {        print qq|  <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">  |; -    } -  } else { -    if ($transdate > $closedto) { -      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +    } else { +      if ($transdate > $closedto) { +	print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|; +      }      }    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print "  </form> @@ -539,9 +672,9 @@ sub update {    $form->{invtotal} = 0; -  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}); - -  @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id); +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate); +   +  @flds = qw(amount AP_amount projectnumber);    $count = 0;    for $i (1 .. $form->{rowcount}) {      $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); @@ -559,33 +692,71 @@ sub update {    $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell'))); -  $form->{invdate} = $form->{transdate}; -  &check_name(vendor); +  if (&check_name(vendor)) { +    $form->{notes} = $form->{intnotes} unless $form->{id}; +  } + +  if ($form->{transdate} ne $form->{oldtransdate}) {  +    $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1); +    $form->{oldtransdate} = $form->{transdate}; +  } -  &check_project;  TAXCALC:    # recalculate taxes + +  @taxaccounts = split / /, $form->{taxaccounts}; + +  map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } @taxaccounts; +      if ($form->{taxincluded}) {      $taxrate = 0; +    $withholdingrate = 0; -    map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts}; +    foreach $item (@taxaccounts) { +      $form->{"calctax_$item"} = 1 if $form->{calctax}; +       +      if ($form->{"calctax_$item"}) { +	if ($form->{"${item}_rate"} > 0) { +	  $taxrate += $form->{"${item}_rate"}; +	} else { +	  $withholdingrate += $form->{"${item}_rate"}; +	} +      } +    } -    foreach $item (split / /, $form->{taxaccounts}) { -      $amount = ($form->{invtotal} * (1 - 1 / (1 + $taxrate)) * $form->{"${item}_rate"} / $taxrate) if $taxrate; -      $form->{"tax_$item"} = $form->round_amount($amount, 2); -      $taxdiff += ($amount - $form->{"tax_$item"}); -      if (abs $taxdiff >= 0.005) { -	$form->{"tax_$item"} += $form->round_amount($taxdiff, 2); -	$taxdiff = 0; +    foreach $item (@taxaccounts) { +      if ($form->{"calctax_$item"}) { +	if ($form->{"${item}_rate"} > 0) { +	  if ($taxrate) { +	    $amount = $form->round_amount($form->{invtotal} * $taxrate / (1 + $taxrate), 2) * $form->{"${item}_rate"} / $taxrate; +	    $form->{"tax_$item"} = $form->round_amount($amount, 2); +	    $taxdiff += ($amount - $form->{"tax_$item"}); +	  } +	} else { +	  if ($withholdingrate) { +	    $amount = $form->round_amount($form->{invtotal} * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"${item}_rate"} / $withholdingrate; +	    $form->{"tax_$item"} = $form->round_amount($amount, 2); +	    $taxdiff += ($amount - $form->{"tax_$item"}); +	  } +	} +	 +	if (abs $taxdiff >= 0.005) { +	  $form->{"tax_$item"} += $form->round_amount($taxdiff, 2); +	  $taxdiff = 0; +	}        }        $form->{"selectAP_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;        $totaltax += $form->{"tax_$item"};      }    } else { -    foreach $item (split / /, $form->{taxaccounts}) { -      $form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2); +    foreach $item (@taxaccounts) { +      $form->{"calctax_$item"} = 1 if $form->{calctax}; +       +      if ($form->{"calctax_$item"}) { +	$form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2); +      }        $form->{"selectAP_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;        $totaltax += $form->{"tax_$item"};      } @@ -596,20 +767,25 @@ TAXCALC:    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) {        map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); + +      $totalpaid += $form->{"paid_$i"};        $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell')));      }    } +  $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal}); +  $form->{oldinvtotal} = $form->{invtotal}; +  $form->{oldtotalpaid} = $totalpaid; +      &display_form;  } - +   sub post { -  # check if there is an invoice number, invoice and due date -  $form->isblank("invnumber", $locale->text("Invoice Number missing!")); +  # check if there is a vendor, invoice and due date    $form->isblank("transdate", $locale->text("Invoice Date missing!"));    $form->isblank("duedate", $locale->text("Due Date missing!"));    $form->isblank("vendor", $locale->text('Vendor missing!')); @@ -620,7 +796,7 @@ sub post {    $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); -  $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { @@ -632,7 +808,7 @@ sub post {        if ($form->{currency} ne $form->{defaultcurrency}) {  	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); -	$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); +	$form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));        }      } @@ -646,6 +822,8 @@ sub post {      exit;    } +  $form->{invnumber} = $form->update_defaults(\%myconfig, "vinumber") unless $form->{invnumber}; +    $form->{id} = 0 if $form->{postasnew};    $form->redirect($locale->text('Transaction posted!')) if (AP->post_transaction(\%myconfig, \%$form)); @@ -668,15 +846,15 @@ sub delete {    $form->header; +  delete $form->{header}; +      print qq|  <body>  <form method=post action=$form->{script}>  |; -  foreach $key (keys %$form) { -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|  <h2 class=confirm>$form->{title}</h2> @@ -696,25 +874,92 @@ sub delete {  sub yes { -  $form->redirect($locale->text('Transaction deleted!')) if (AP->delete_transaction(\%myconfig, \%$form)); +  $form->redirect($locale->text('Transaction deleted!')) if (AP->delete_transaction(\%myconfig, \%$form, $spool));    $form->error($locale->text('Cannot delete transaction!'));  }  sub search { -   -  # setup vendor selection -  $form->all_vc(\%myconfig, "vendor"); +  $form->create_links("AP", \%myconfig, "vendor"); + +  $form->{selectAP} = "<option>\n"; +  map { $form->{selectAP} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{AP_links}{AP} }; + +      if (@{ $form->{all_vendor} }) { -    map { $vendor .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_vendor} }; +    map { $vendor .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_vendor} };      $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;    } else {      $vendor = qq|<input name=vendor size=35>|;    } -     -    $form->{title} = $locale->text('AP Transactions'); + +  # departments +  if (@{ $form->{all_departments} }) {  +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $department = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +| if $form->{selectdepartment}; + +  $form->{title} = $locale->text('AP Transactions'); + +  $invnumber = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> +	  <td colspan=3><input name=invnumber size=20></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Order Number').qq|</th> +	  <td colspan=3><input name=ordnumber size=20></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> +	  <td colspan=3><input name=notes size=40></td> +	</tr> +|; + +  $openclosed = qq| +	      <tr> +		<td align=right><input name=open class=checkbox type=checkbox value=Y checked></td> +		<td nowrap>|.$locale->text('Open').qq|</td> +		<td align=right><input name=closed class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Closed').qq|</td> +	      </tr> +|; + +  if ($form->{outstanding}) { +    $form->{title} = $locale->text('AP Outstanding'); +    $invnumber = ""; +    $openclosed = ""; +  } + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr>	 +|;    $form->header; @@ -723,6 +968,9 @@ sub search {  <form method=post action=$form->{script}> +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=outstanding value=$form->{outstanding}> +  <table width=100%>    <tr>      <th class=listtop>$form->{title}</th> @@ -731,29 +979,24 @@ sub search {    <tr>      <td>        <table> +        <tr> +	  <th align=right>|.$locale->text('Account').qq|</th> +	  <td colspan=3><select name=AP>$form->{selectAP}</select></td> +	</tr>  	<tr>  	  <th align=right>|.$locale->text('Vendor').qq|</th>  	  <td colspan=3>$vendor</td>  	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -	  <td colspan=3><input name=invnumber size=20></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Order Number').qq|</th> -	  <td colspan=3><input name=ordnumber size=20></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> -	  <td colspan=3><input name=notes size=40></td> -	</tr> +	$department +	$invnumber  	<tr>  	  <th align=right nowrap>|.$locale->text('From').qq|</th>  	  <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>  	</tr>          <input type=hidden name=sort value=transdate> +	$selectfrom        </table>      </td>    </tr> @@ -764,12 +1007,7 @@ sub search {  	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>  	  <td>  	    <table width=100%> -	      <tr> -		<td align=right><input name=open class=checkbox type=checkbox value=Y checked></td> -		<td nowrap>|.$locale->text('Open').qq|</td> -		<td align=right><input name=closed class=checkbox type=checkbox value=Y></td> -		<td nowrap>|.$locale->text('Closed').qq|</td> -	      </tr> +	      $openclosed  	      <tr>  		<td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('ID').qq|</td> @@ -783,18 +1021,20 @@ sub search {  		<td nowrap>|.$locale->text('Vendor').qq|</td>  		<td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>  		<td nowrap>|.$locale->text('Invoice Date').qq|</td> -		<td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td> -		<td nowrap>|.$locale->text('Amount').qq|</td>  	      </tr>  	      <tr> +		<td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Amount').qq|</td>  		<td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Tax').qq|</td>  		<td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>  		<td nowrap>|.$locale->text('Total').qq|</td> -		<td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td> -		<td nowrap>|.$locale->text('Date Paid').qq|</td> +		<td align=right><input name="l_curr" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Currency').qq|</td>  	      </tr>  	      <tr> +		<td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Date Paid').qq|</td>  		<td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>  		<td nowrap>|.$locale->text('Paid').qq|</td>  		<td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td> @@ -802,11 +1042,13 @@ sub search {  		<td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Amount Due').qq|</td>  	      </tr> -	      <tr> +	      <tr valign=top>  		<td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Notes').qq|</td>  		<td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Employee').qq|</td> +		<td align=right><input name="l_manager" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Manager').qq|</td>  	      </tr>  	      <tr>  		<td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td> @@ -825,9 +1067,10 @@ sub search {  <br>  <input type=hidden name=nextsub value=$form->{nextsub}> +  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">  </form> @@ -841,34 +1084,56 @@ sub search {  sub ap_transactions { -  $form->{vendor} = $form->unescape($form->{vendor}); -  ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor}); +  if ($form->{vendor}) { +    $form->{vendor} = $form->unescape($form->{vendor}); +    ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor}); +  }    AP->ap_transactions(\%myconfig, \%$form); -  $callback = "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}"; -  $href = $callback; -     +  $href = "$form->{script}?action=ap_transactions&direction=$form->{direction}&oldsort=$form->{oldsort}&outstanding=$form->{outstanding}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $form->sort_order(); +   +  $callback = "$form->{script}?action=ap_transactions&direction=$form->{direction}&oldsort=$form->{oldsort}&outstanding=$form->{outstanding}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $callback .= "&title=".$form->escape($form->{title},1); +  $href .= "&title=".$form->escape($form->{title}); + +  if ($form->{AP}) { +    $callback .= "&AP=".$form->escape($form->{AP},1); +    $href .= "&AP=".$form->escape($form->{AP}); +    $form->{AP} =~ s/--/ /; +    $option = $locale->text('Account')." : $form->{AP}"; +  }    if ($form->{vendor}) { -    $callback .= "&vendor=".$form->escape($form->{vendor}); -    $href .= "&vendor=".$form->escape($form->{vendor}); +    $callback .= "&vendor=".$form->escape($form->{vendor},1)."--$form->{vendor_id}"; +    $href .= "&vendor=".$form->escape($form->{vendor})."--$form->{vendor_id}"; +    $option .= "\n<br>" if ($option);      $option .= $locale->text('Vendor')." : $form->{vendor}";    } +  if ($form->{department}) { +    $callback .= "&department=".$form->escape($form->{department},1); +    $href .= "&department=".$form->escape($form->{department}); +    ($department) = split /--/, $form->{department}; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Department')." : $department"; +  }    if ($form->{invnumber}) { -    $callback .= "&invnumber=$form->{invnumber}"; +    $callback .= "&invnumber=".$form->escape($form->{invnumber},1);      $href .= "&invnumber=".$form->escape($form->{invnumber});      $option .= "\n<br>" if ($option);      $option .= $locale->text('Invoice Number')." : $form->{invnumber}";    }    if ($form->{ordnumber}) { -    $callback .= "&ordnumber=$form->{ordnumber}"; +    $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);      $href .= "&ordnumber=".$form->escape($form->{ordnumber});      $option .= "\n<br>" if ($option);      $option .= $locale->text('Order Number')." : $form->{ordnumber}";    }    if ($form->{notes}) { -    $callback .= "¬es=$form->{notes}"; +    $callback .= "¬es=".$form->escape($form->{notes},1);      $href .= "¬es=".$form->escape($form->{notes});      $option .= "\n<br>" if $option;      $option .= $locale->text('Notes')." : $form->{notes}"; @@ -884,7 +1149,7 @@ sub ap_transactions {      $callback .= "&transdateto=$form->{transdateto}";      $href .= "&transdateto=$form->{transdateto}";      $option .= "\n<br>" if ($option); -    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);    }    if ($form->{open}) {      $callback .= "&open=$form->{open}"; @@ -899,11 +1164,15 @@ sub ap_transactions {      $option .= $locale->text('Closed');    } -  @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)); +  @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid due curr datepaid duedate notes employee manager));    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") {        push @column_index, $item; + +      if ($form->{l_curr} && $item =~ /(amount|tax|paid|due)/) { +	push @column_index, "fx_$item"; +      }        # add column to href and callback        $callback .= "&l_$item=Y"; @@ -929,11 +1198,14 @@ sub ap_transactions {    $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;    $column_header{paid} = qq|<th class=listheading>|.$locale->text('Paid').qq|</th>|;    $column_header{datepaid} = qq|<th><a class=listheading href=$href&sort=datepaid>|.$locale->text('Date Paid').qq|</a></th>|; -  $column_header{notes} = qq|<th><a class=listheading>|.$locale->text('Notes').qq|</th>|; +  $column_header{notes} = qq|<th class=listheading>|.$locale->text('Notes').qq|</th>|;    $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Employee')."</th>"; +  $column_header{manager} = "<th><a class=listheading href=$href&sort=manager>".$locale->text('Manager')."</th>"; +  $column_header{curr} = "<th><a class=listheading href=$href&sort=curr>" . $locale->text('Curr') . "</a></th>"; +  map { $column_header{"fx_$_"} = "<th> </th>" } qw(amount tax netamount paid due); -  $form->{title} = $locale->text('AP Transactions'); +  $form->{title} = ($form->{title}) ? $form->{title} : $locale->text('AP Transactions');    $form->header; @@ -964,13 +1236,17 @@ sub ap_transactions {    $form->{callback} = "$callback&sort=$form->{sort}";    $callback = $form->escape($form->{callback}); -  if (@{ $form->{AP} }) { -    $sameitem = $form->{AP}->[0]->{$form->{sort}}; +  # flip direction +  $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC"; +  $href =~ s/&direction=(\w+)&/&direction=$direction&/; + +  if (@{ $form->{transactions} }) { +    $sameitem = $form->{transactions}->[0]->{$form->{sort}};    }    # sums and tax on reports by Antonio Gallardo    # -  foreach $ap (@{ $form->{AP} }) { +  foreach $ap (@{ $form->{transactions} }) {      if ($form->{l_subtotal} eq 'Y') {        if ($sameitem ne $ap->{$form->{sort}}) { @@ -978,22 +1254,37 @@ sub ap_transactions {  	$sameitem = $ap->{$form->{sort}};        }      } + +    if ($form->{l_curr}) { +      map { $ap->{"fx_$_"} = $ap->{$_}/$ap->{exchangerate} } qw(netamount amount paid); +       +      map { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{"fx_$_"}, 2, " ")."</td>" } qw(netamount amount paid); + +      $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{fx_amount} - $ap->{fx_netamount}, 2, " ")."</td>"; +      $column_data{fx_due} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{fx_amount} - $ap->{fx_paid}, 2, " ")."</td>"; + +      $subtotalfxnetamount += $ap->{fx_netamount}; +      $subtotalfxamount += $ap->{fx_amount}; +      $subtotalfxpaid += $ap->{fx_paid}; + +      $totalfxnetamount += $ap->{fx_netamount}; +      $totalfxamount += $ap->{fx_amount}; +      $totalfxpaid += $ap->{fx_paid}; + +    } +     +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{$_}, 2, " ")."</td>" } qw(netamount amount paid); -    $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")."</td>";      $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount}, 2, " ") . "</td>"; -    $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>"; -    $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{paid}, 2, " ")."</td>";      $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid}, 2, " ")."</td>";      $totalnetamount += $ap->{netamount};      $totalamount += $ap->{amount};      $totalpaid += $ap->{paid}; -    $totaldue += ($ap->{amount} - $ap->{paid});      $subtotalnetamount += $ap->{netamount};      $subtotalamount += $ap->{amount};      $subtotalpaid += $ap->{paid}; -    $subtotaldue += ($ap->{amount} - $ap->{paid});      $column_data{transdate} = "<td>$ap->{transdate} </td>";      $column_data{duedate} = "<td>$ap->{duedate} </td>"; @@ -1001,13 +1292,18 @@ sub ap_transactions {      $module = ($ap->{invoice}) ? "ir.pl" : $form->{script}; -    $column_data{invnumber} = qq|<td><a href="$module?action=edit&path=$form->{path}&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|; +    $column_data{invnumber} = qq|<td><a href="$module?action=edit&path=$form->{path}&id=$ap->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ap->{invnumber}</a></td>|;      $column_data{id} = "<td>$ap->{id}</td>";      $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>"; -    $column_data{name} = "<td>$ap->{name}</td>"; + +    $name = $form->escape($ap->{name}); +    $column_data{name} = "<td><a href=$href&vendor=$name--$ap->{vendor_id}&sort=$form->{sort}>$ap->{name}</a></td>"; +      $ap->{notes} =~ s/\r\n/<br>/g;      $column_data{notes} = "<td>$ap->{notes} </td>";      $column_data{employee} = "<td>$ap->{employee} </td>"; +    $column_data{manager} = "<td>$ap->{manager} </td>"; +    $column_data{curr} = "<td>$ap->{curr}</td>";      $i++;      $i %= 2; @@ -1038,10 +1334,30 @@ sub ap_transactions {    $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";    $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>"; -  $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>"; +  $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalpaid, 2, " ")."</th>"; + +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalnetfxamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, " ")."</th>"; +    $column_data{fx_paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxpaid, 2, " ")."</th>"; +    $column_data{fx_due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxpaid, 2, " ")."</th>"; +  }    map { print "$column_data{$_}\n" } @column_index; +  if ($myconfig{acs} !~ /AP--AP/) { +    $i = 1; +    $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |; +    $button{'AP--Add Transaction'}{order} = $i++; +    $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice.').qq|"> |; +    $button{'AP--Vendor Invoice'}{order} = $i++; + +    foreach $item (split /;/, $myconfig{acs}) { +      delete $button{$item}; +    } +  } +    print qq|          </tr>        </table> @@ -1054,18 +1370,29 @@ sub ap_transactions {  <br>  <form method=post action=$form->{script}> -  + +<input type=hidden name=vendor value="$form->{vendor}"> +<input type=hidden name=vendor_id value=$form->{vendor_id}> +<input type=hidden name=vc value=vendor> +  <input name=callback type=hidden value="$form->{callback}">  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> -    -<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; -<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } -</form> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form>  </body>  </html> @@ -1082,12 +1409,22 @@ sub ap_subtotal {    $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";    $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>"; -  $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>"; +  $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalpaid, 2, " ")."</th>"; +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, " ")."</th>"; +    $column_data{fx_paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxpaid, 2, " ")."</th>"; +    $column_data{fx_due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxpaid, 2, " ")."</th>"; +  } +      $subtotalnetamount = 0;    $subtotalamount = 0;    $subtotalpaid = 0; -  $subtotaldue = 0; +   +  $subtotalfxnetamount = 0; +  $subtotalfxamount = 0; +  $subtotalfxpaid = 0;    print "<tr class=listsubtotal>"; @@ -1100,4 +1437,3 @@ sub ap_subtotal {  } - diff --git a/sql-ledger/bin/mozilla/ar.pl b/sql-ledger/bin/mozilla/ar.pl index 341c0380c..8f98981e5 100644 --- a/sql-ledger/bin/mozilla/ar.pl +++ b/sql-ledger/bin/mozilla/ar.pl @@ -1,11 +1,12 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 2001 +# Copyright (c) 2000  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +#  Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -21,7 +22,7 @@  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  #======================================================================  # -# Accounts Receivables +# Accounts Receivable  #  #====================================================================== @@ -31,6 +32,7 @@ use SL::IS;  use SL::PE;  require "$form->{path}/arap.pl"; +require "$form->{path}/arapprn.pl";  1;  # end of main @@ -67,7 +69,7 @@ require "$form->{path}/arap.pl";  sub add {    $form->{title} = "Add"; -  $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};    &create_links;    &display_form; @@ -97,14 +99,11 @@ sub create_links {    $form->create_links("AR", \%myconfig, "customer");    $duedate = $form->{duedate}; -   -  $taxincluded = $form->{taxincluded}; -   -  IS->get_customer(\%myconfig, \%$form); - -  $form->{duedate} = $duedate; -  $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; +  $form->{formname} = "transaction"; +  $form->{format} = "postscript" if $myconfig{printer}; +  $form->{media} = $myconfig{printer}; +      # currencies    @curr = split /:/, $form->{currencies};    chomp $curr[0]; @@ -112,21 +111,56 @@ sub create_links {    map { $form->{selectcurrency} .= "<option>$_\n" } @curr; +  IS->get_customer(\%myconfig, \%$form); + +  $form->{duedate} = $duedate if $duedate; +  $form->{notes} = $form->{intnotes} if !$form->{id}; +   +  $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; +  $form->{oldtransdate} = $form->{transdate}; +    # customers    if (@{ $form->{all_customer} }) {      $form->{customer} = "$form->{customer}--$form->{customer_id}"; -    map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); +    map { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_customer} });    } +  # departments +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}"; +     +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } +   +  $form->{employee} = "$form->{employee}--$form->{employee_id}"; +  # sales staff +  if (@{ $form->{all_employees} }) { +    $form->{selectemployee} = ""; +    map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_employees} }); +  } +   +  # projects +  if (@{ $form->{all_projects} }) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } (@{ $form->{all_projects} }); +  } + +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  } +    # forex    $form->{forex} = $form->{exchangerate};    $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; -   +    foreach $key (keys %{ $form->{AR_links} }) {      foreach $ref (@{ $form->{AR_links}{$key} }) {        if ($key eq 'AR_tax') {  	$form->{"selectAR_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n"; +	$form->{"calctax_$ref->{accno}"} = 1;  	next;        }        $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; @@ -140,6 +174,7 @@ sub create_links {  	$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1;  	$form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};  	$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source}; +	$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};  	$form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate}; @@ -150,18 +185,24 @@ sub create_links {  	$akey =~ s/AR_//;          if ($key eq "AR_tax") { -  	  $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";  	  $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2); -	  $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	   +	  if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { +	    $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	    $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; +	  } else { +	    $totalwithholding += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; +	    $withholdingrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; +	  } +  	} else {  	  $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);  	  if ($akey eq 'amount') {  	    $form->{rowcount}++;  	    $totalamount += $form->{"${akey}_$i"}; -	    $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; -	    $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; +            $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}";  	  }  	  $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";  	} @@ -169,26 +210,54 @@ sub create_links {      }    } -  $form->{taxincluded} = $taxincluded if ($form->{id});    $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};    if ($form->{taxincluded} && $totalamount) { -    # add tax to amounts and invtotal +    # add tax to individual amounts      for $i (1 .. $form->{rowcount}) { -      $taxamount = $totaltax * $form->{"amount_$i"} / $totalamount; +      $taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;        $tax = $form->round_amount($taxamount, 2);        $diff += ($taxamount - $tax);        $form->{"amount_$i"} += $tax;      }      $form->{amount_1} += $form->round_amount($diff, 2);    } +   +  # check if calculated is equal to stored +  # taxincluded is terrible to calculate +  # this works only if all taxes are checked +  foreach $item (split / /, $form->{taxaccounts}) { +    if ($form->{taxincluded}) { +      if ($form->{"${item}_rate"} > 0) { +	if ($taxrate) { +	  $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $taxrate / (1 + $taxrate), 2) * $form->{"${item}_rate"} / $taxrate; +	} +      } else { +	if ($withholdingrate) { +	  $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"${item}_rate"} / $withholdingrate; +	} +      } +    } else { +      $taxamount = $totalamount * $form->{"${item}_rate"}; +    } +    $taxamount = $form->round_amount($taxamount, 2); + +    $form->{"calctax_$item"} = 0; +    if ($form->{"tax_$item"} == $taxamount) { +      $form->{"calctax_$item"} = 1; +    } +  } -  $form->{invtotal} = $totalamount + $totaltax; +  $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;    $form->{rowcount}++ if $form->{id};    $form->{AR} = $form->{AR_1}; +  $form->{rowcount} = 1 unless $form->{AR_amount_1}; -  $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); +  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +  # readonly +  $form->{readonly} = 1 if $myconfig{acs} =~ /AR--Add Transaction/;  } @@ -196,37 +265,42 @@ sub create_links {  sub form_header {    $title = $form->{title}; -  $form->{title} = $locale->text("$title Accounts Receivables Transaction"); +  $form->{title} = $locale->text("$title AR Transaction");    $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; -# $locale->text('Add Accounts Receivables Transaction') -# $locale->text('Edit Accounts Receivables Transaction') +# $locale->text('Add AR Transaction') +# $locale->text('Edit AR Transaction')    # set option selected -  foreach $item (qw(AR customer currency)) { +  foreach $item (qw(AR currency)) {      $form->{"select$item"} =~ s/ selected//; -    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; +    $form->{"select$item"} =~ s/<option>\Q$form->{$item}\E/<option selected>$form->{$item}/;    } +  foreach $item (qw(customer department employee)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } + +  $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}); +      # format amounts    $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); -  $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); -  $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); -    $exchangerate = qq|  <input type=hidden name=forex value=$form->{forex}>  |;    if ($form->{currency} ne $form->{defaultcurrency}) {      if ($form->{forex}) {        $exchangerate .= qq| -	<th align=right>|.$locale->text('Exchangerate').qq|</th> +	<th align=right>|.$locale->text('Exchange Rate').qq|</th>  	<td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>  |;      } else {        $exchangerate .= qq| -        <th align=right>|.$locale->text('Exchangerate').qq|</th> +        <th align=right>|.$locale->text('Exchange Rate').qq|</th>          <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>  |;      } @@ -248,26 +322,60 @@ sub form_header {    }    $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; +  $department = qq| +	      <tr> +		<th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td colspan=3><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|"> +		</td> +	      </tr> +| if $form->{selectdepartment}; -  $form->header; -   -  $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; +  +  $n = ($form->{creditremaining} < 0) ? "0" : "1";    $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>| : qq|<input name=customer value="$form->{customer}" size=35>|; -  + +  $employee = qq| +                <input type=hidden name=employee value="$form->{employee}"> +|; + +  $employee = qq| +	      <tr> +		<th align=right nowrap>|.$locale->text('Salesperson').qq|</th> +		<td><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|.$form->escape($form->{selectemployee},1).qq|"> +	      </tr> +| if $form->{selectemployee}; + +  $form->header; +      print qq|  <body>  <form method=post action=$form->{script}>  <input type=hidden name=id value=$form->{id}> + +<input type=hidden name=type value="transaction"> +<input type=hidden name=vc value="customer"> + +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=printed value="$form->{printed}"> +<input type=hidden name=emailed value="$form->{emailed}"> +  <input type=hidden name=sort value=$form->{sort}> +  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=locked value=$form->{locked}> +  <input type=hidden name=title value="$title"> +<input type=hidden name=oldtransdate value=$form->{oldtransdate}> +<input type=hidden name=audittrail value="$form->{audittrail}"> +  <table width=100%> -  <tr> +  <tr class=listtop>      <th class=listtop>$form->{title}</th>    </tr>    <tr height="5"></tr> @@ -280,7 +388,7 @@ sub form_header {  	      <tr>  		<th align="right" nowrap>|.$locale->text('Customer').qq|</th>  		<td colspan=3>$customer</td> -		<input type=hidden name=selectcustomer value="$form->{selectcustomer}"> +		<input type=hidden name=selectcustomer value="|.$form->escape($form->{selectcustomer},1).qq|">  		<input type=hidden name=oldcustomer value="$form->{oldcustomer}">  		<input type=hidden name=customer_id value="$form->{customer_id}">  		<input type=hidden name=terms value=$form->{terms}> @@ -293,14 +401,13 @@ sub form_header {  		      <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>  		      <td>$form->{creditlimit}</td>  		      <th align=left nowrap>|.$locale->text('Remaining').qq|</th> -		      <td class="plus$n">$form->{creditremaining}</td> +		      <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>  		      <input type=hidden name=creditlimit value=$form->{creditlimit}>  		      <input type=hidden name=creditremaining value=$form->{creditremaining}>  		    </tr>  		  </table>  		</td>  	      </tr> -	      $taxincluded  	      <tr>  		<th align=right>|.$locale->text('Currency').qq|</th>  		<td><select name=currency>$form->{selectcurrency}</select></td> @@ -310,17 +417,20 @@ sub form_header {  		<input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>  		$exchangerate  	      </tr> +	      $department +	      $taxincluded  	    </table>  	  </td>  	  <td align=right>  	    <table> +	      $employee  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -		<td><input name=invnumber size=11 value="$form->{invnumber}"></td> +		<td><input name=invnumber size=20 value="$form->{invnumber}"></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> -		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td> +		<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Date').qq|</th> @@ -341,45 +451,52 @@ sub form_header {        <table width=100%>  <input type=hidden name=selectAR_amount value="$form->{selectAR_amount}"> +<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">  <input type=hidden name=rowcount value=$form->{rowcount}>  |;    $amount = $locale->text('Amount'); -  $project = $locale->text('Project');    for $i (1 .. $form->{rowcount}) { + +    $selectAR_amount = $form->{selectAR_amount}; +    $selectAR_amount =~ s/option>\Q$form->{"AR_amount_$i"}\E/option selected>$form->{"AR_amount_$i"}/; -    $form->{"selectAR_amount"} =~ s/ selected//; -    $form->{"selectAR_amount"} =~ s/option>\Q$form->{"AR_amount_$i"}\E/option selected>$form->{"AR_amount_$i"}/; +    $selectprojectnumber = $form->{selectprojectnumber}; +    $selectprojectnumber =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;      # format amounts      $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); +    $project = qq| +	  <td align=right><select name="projectnumber_$i">$selectprojectnumber</select></td> +| if $form->{selectprojectnumber}; +	        print qq|  	<tr>  	  <th align=right>$amount</th>  	  <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td> -	  <th>$project</th> -	  <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}"> -	      <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}> -	      <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td> -	  <td width=50%><select name="AR_amount_$i">$form->{"selectAR_amount"}</select></td> +	  <td></td> +	  <td><select name="AR_amount_$i">$selectAR_amount</select></td> +	  $project  	</tr>  |;      $amount = ""; -    $project = "";    } +    $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');    foreach $item (split / /, $form->{taxaccounts}) { +    $form->{"calctax_$item"} = ($form->{"calctax_$item"}) ? "checked" : ""; +      $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);      print qq|          <tr>  	  <th align=right nowrap>$taxlabel</th>  	  <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td> -	  <td colspan=2></td> +	  <td align=right><input name="calctax_$item" class=checkbox type=checkbox value=1 $form->{"calctax_$item"}></td>  	  <td><select name="AR_tax_$item">$form->{"selectAR_tax_$item"}</select></td>  	</tr>  	<input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}"> @@ -396,18 +513,18 @@ sub form_header {  	  <th align=right>|.$locale->text('Total').qq|</th>  	  <th align=left>$form->{invtotal}</th> +	  <td></td>  	  <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>  	  <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>  	  <input type=hidden name=taxaccounts value="$form->{taxaccounts}"> -	  <td colspan=2></td>  	  <td><select name=AR>$form->{selectAR}</select></td>            <input type=hidden name=selectAR value="$form->{selectAR}">          </tr> -        <tr> +        <tr valign=top>  	  <th align=right>|.$locale->text('Notes').qq|</th>  	  <td colspan=4>$notes</td>  	</tr> @@ -417,16 +534,15 @@ sub form_header {    <tr>      <td>        <table width=100%> -	<tr> -	  <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th> +	<tr class=listheading> +	  <th colspan=6 class=listheading>|.$locale->text('Payments').qq|</th>  	</tr>  |; -    if ($form->{currency} eq $form->{defaultcurrency}) { -    @column_index = qw(datepaid source paid AR_paid); +    @column_index = qw(datepaid source memo paid AR_paid);    } else { -    @column_index = qw(datepaid source paid exchangerate AR_paid); +    @column_index = qw(datepaid source memo paid exchangerate AR_paid);    }    $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; @@ -434,6 +550,7 @@ sub form_header {    $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";    $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";    $column_data{source} = "<th>".$locale->text('Source')."</th>"; +  $column_data{memo} = "<th>".$locale->text('Memo')."</th>";    print "          <tr> @@ -443,6 +560,7 @@ sub form_header {          </tr>  "; +    $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});    for $i (1 .. $form->{paidaccounts}) {      print " @@ -469,13 +587,14 @@ sub form_header {  <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>  |; -    $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|; -    $column_data{"AR_paid_$i"} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|; -    $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|; -    $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|; -    $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|; +    $column_data{paid} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|; +    $column_data{AR_paid} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|; +    $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|; +    $column_data{datepaid} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|; +    $column_data{source} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|; +    $column_data{memo} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|; -    map { print qq|$column_data{"${_}_$i"}\n| } @column_index; +    map { print qq|$column_data{$_}\n| } @column_index;      print "          </tr> @@ -500,13 +619,15 @@ sub form_header {  sub form_footer { +  &print_options; +      print qq|  <input name=callback type=hidden value="$form->{callback}">  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  |; @@ -514,33 +635,40 @@ sub form_footer {    $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  if ($form->{id}) { +  if (! $form->{readonly}) { +    if ($form->{id}) {        print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">  |; -    if (!$form->{revtrans}) {        if (!$form->{locked}) {  	print qq|  	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">  	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">  |;        } -    } -    if ($transdate > $closedto) {        print qq|  <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">  |; -    } -  } else { -    if ($transdate > $closedto) { -      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +    } else { +      if ($transdate > $closedto) { +	print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|; +      }      }    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print "  </form> @@ -560,9 +688,9 @@ sub update {    $form->{invtotal} = 0; -  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate); -  @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); +  @flds = qw(amount AR_amount projectnumber);    $count = 0;    @a = ();    for $i (1 .. $form->{rowcount}) { @@ -584,33 +712,72 @@ sub update {    $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy'))); -  $form->{invdate} = $form->{transdate}; -  &check_name(customer); +  if (&check_name(customer)) { +    $form->{notes} = $form->{intnotes} unless $form->{id}; +  } -  &check_project; +  if ($form->{transdate} ne $form->{oldtransdate}) { +    $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1); +    $form->{oldtransdate} = $form->{transdate}; +  } +    TAXCALC:    # recalculate taxes + +  @taxaccounts = split / /, $form->{taxaccounts}; +   +  map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } @taxaccounts; +      if ($form->{taxincluded}) {      $taxrate = 0; +    $withholdingrate = 0; + +    foreach $item (@taxaccounts) { +      $form->{"calctax_$item"} = 1 if $form->{calctax}; +       +      if ($form->{"calctax_$item"}) { +	if ($form->{"${item}_rate"} > 0) { +	  $taxrate += $form->{"${item}_rate"}; +	} else { +	  $withholdingrate += $form->{"${item}_rate"}; +	} +      } +    } + +    foreach $item (@taxaccounts) { -    map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts}; +      if ($form->{"calctax_$item"}) { +	if ($form->{"${item}_rate"} > 0) { +	  if ($taxrate) { +	    $amount = $form->round_amount($form->{invtotal} * $taxrate / (1 + $taxrate), 2) * $form->{"${item}_rate"} / $taxrate; +	    $form->{"tax_$item"} = $form->round_amount($amount, 2); +	    $taxdiff += ($amount - $form->{"tax_$item"}); +	  } +	} else { +	  if ($withholdingrate) { +	    $amount = $form->round_amount($form->{invtotal} * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"${item}_rate"} / $withholdingrate; +	    $form->{"tax_$item"} = $form->round_amount($amount, 2); +	    $taxdiff += ($amount - $form->{"tax_$item"}); +	  } +	} -    foreach $item (split / /, $form->{taxaccounts}) { -      $amount = ($form->{invtotal} * (1 - 1 / (1 + $taxrate)) * $form->{"${item}_rate"} / $taxrate) if $taxrate; -      $form->{"tax_$item"} = $form->round_amount($amount, 2); -      $taxdiff += ($amount - $form->{"tax_$item"}); -      if (abs $taxdiff >= 0.005) { -	$form->{"tax_$item"} += $form->round_amount($taxdiff, 2); -	$taxdiff = 0; +	if (abs($taxdiff) >= 0.005) { +	  $form->{"tax_$item"} += $form->round_amount($taxdiff, 2); +	  $taxdiff = 0; +	}        }        $form->{"selectAR_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;        $totaltax += $form->{"tax_$item"};      }    } else { -    foreach $item (split / /, $form->{taxaccounts}) { -      $form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2); +    foreach $item (@taxaccounts) { +      $form->{"calctax_$item"} = 1 if $form->{calctax}; +       +      if ($form->{"calctax_$item"}) { +	$form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2); +      }        $form->{"selectAR_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;        $totaltax += $form->{"tax_$item"};      } @@ -640,7 +807,6 @@ TAXCALC:  sub post {    # check if there is an invoice number, invoice and due date -  $form->isblank("invnumber", $locale->text('Invoice Number missing!'));    $form->isblank("transdate", $locale->text('Invoice Date missing!'));    $form->isblank("duedate", $locale->text('Due Date missing!'));    $form->isblank("customer", $locale->text('Customer missing!')); @@ -650,7 +816,7 @@ sub post {    $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); -  $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { @@ -662,7 +828,7 @@ sub post {        if ($form->{currency} ne $form->{defaultcurrency}) {  	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); -	$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); +	$form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));        }      }    } @@ -674,6 +840,8 @@ sub post {      exit;    } +  $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber") unless $form->{invnumber}; +    $form->{id} = 0 if $form->{postasnew};    $form->redirect($locale->text('Transaction posted!')) if (AR->post_transaction(\%myconfig, \%$form)); @@ -696,15 +864,15 @@ sub delete {    $form->header; +  delete $form->{header}; +    print qq|  <body>  <form method=post action=$form->{script}>  |; -  foreach $key (keys %$form) { -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|  <h2 class=confirm>$form->{title}</h2> @@ -724,7 +892,7 @@ sub delete {  sub yes { -  $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form)); +  $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form, $spool));    $form->error($locale->text('Cannot delete transaction!'));  } @@ -732,17 +900,85 @@ sub yes {  sub search { -  # setup customer selection -  $form->all_vc(\%myconfig, "customer"); - +  $form->create_links("AR", \%myconfig, "customer"); +   +  $form->{selectAR} = "<option>\n"; +  map { $form->{selectAR} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{AR_links}{AR} }; +      if (@{ $form->{all_customer} }) {  -    map { $customer .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_customer} }; +    map { $customer .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_customer} };      $customer = qq|<select name=customer><option>\n$customer</select>|;    } else {      $customer = qq|<input name=customer size=35>|;    } -     + +  # departments  +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $department = qq|  +        <tr>  +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +| if $form->{selectdepartment}; + +    $form->{title} = $locale->text('AR Transactions'); + +  $invnumber = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> +	  <td colspan=3><input name=invnumber size=20></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Order Number').qq|</th> +	  <td colspan=3><input name=ordnumber size=20></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> +	  <td colspan=3><input name=notes size=40></td> +	</tr> +|; + +  $openclosed = qq| +	      <tr> +		<td align=right><input name=open class=checkbox type=checkbox value=Y checked></td> +		<td nowrap>|.$locale->text('Open').qq|</td> +		<td align=right><input name=closed class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Closed').qq|</td> +	      </tr> +|; + +  if ($form->{outstanding}) { +    $form->{title} = $locale->text('AR Outstanding'); +    $invnumber = ""; +    $openclosed = ""; +  } + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; +    $form->header; @@ -751,35 +987,37 @@ sub search {  <form method=post action=$form->{script}> +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=outstanding value=$form->{outstanding}> +  <table width=100%>    <tr><th class=listtop>$form->{title}</th></tr>    <tr height="5"></tr>    <tr>      <td>        <table> +        <tr> +	  <th align=right>|.$locale->text('Account').qq|</th> +	  <td colspan=3><select name=AR>$form->{selectAR}</select></td> +	</tr>  	<tr>  	  <th align=right>|.$locale->text('Customer').qq|</th>  	  <td colspan=3>$customer</td>  	</tr> +	$department +	$invnumber  	<tr> -	  <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -	  <td colspan=3><input name=invnumber size=20></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Order Number').qq|</th> -	  <td colspan=3><input name=ordnumber size=20></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> -	  <td colspan=3><input name=notes size=40></td> +	  <th align=right>|.$locale->text('Ship via').qq|</th> +	  <td colspan=3><input name=shipvia size=40></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('From').qq|</th>  	  <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>  	</tr>  	<input type=hidden name=sort value=transdate> +	$selectfrom        </table>      </td>    </tr> @@ -790,12 +1028,7 @@ sub search {  	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>  	  <td>  	    <table width=100%> -	      <tr> -		<td align=right><input name=open class=checkbox type=checkbox value=Y checked></td> -		<td nowrap>|.$locale->text('Open').qq|</td> -		<td align=right><input name=closed class=checkbox type=checkbox value=Y></td> -		<td nowrap>|.$locale->text('Closed').qq|</td> -	      </tr> +	      $openclosed  	      <tr>  		<td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('ID').qq|</td> @@ -809,12 +1042,20 @@ sub search {  	      <tr>  		<td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>  		<td nowrap>|.$locale->text('Customer').qq|</td> +		<td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Salesperson').qq|</td> +		<td align=right><input name="l_manager" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Manager').qq|</td> +	      </tr> +	      <tr>  		<td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Amount').qq|</td>  		<td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Tax').qq|</td>  		<td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>  		<td nowrap>|.$locale->text('Total').qq|</td> +		<td align=right><input name="l_curr" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Currency').qq|</td>  	      </tr>  	      <tr>  		<td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td> @@ -826,12 +1067,14 @@ sub search {  		<td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Amount Due').qq|</td>  	      </tr> -	      <tr> +	      <tr valign=top>  		<td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Notes').qq|</td> -		<td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td> -		<td nowrap>|.$locale->text('Salesperson').qq|</td> +		<td align=right><input name="l_till" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Till').qq|</td>  		<td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td> +		<td nowrap>|.$locale->text('Shipping Point').qq|</td> +		<td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>  		<td nowrap>|.$locale->text('Ship via').qq|</td>  	      </tr>  	      <tr> @@ -853,7 +1096,7 @@ sub search {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> @@ -869,33 +1112,57 @@ sub search {  sub ar_transactions { -  $form->{customer} = $form->unescape($form->{customer}); -  ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); - +  if ($form->{customer}) { +    $form->{customer} = $form->unescape($form->{customer}); +    ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); +  } +      AR->ar_transactions(\%myconfig, \%$form); -  $callback = "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}"; -  $href = $callback; +  $href = "$form->{script}?action=ar_transactions&direction=$form->{direction}&oldsort=$form->{oldsort}&till=$form->{till}&outstanding=$form->{outstanding}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $href .= "&title=".$form->escape($form->{title}); + +  $form->sort_order(); +   +  $callback = "$form->{script}?action=ar_transactions&direction=$form->{direction}&oldsort=$form->{oldsort}&till=$form->{till}&outstanding=$form->{outstanding}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $callback .= "&title=".$form->escape($form->{title},1); +  if ($form->{AR}) { +    $callback .= "&AR=".$form->escape($form->{AR},1); +    $href .= "&AR=".$form->escape($form->{AR}); +    $form->{AR} =~ s/--/ /; +    $option = $locale->text('Account')." : $form->{AR}"; +  } +      if ($form->{customer}) { -    $callback .= "&customer=".$form->escape($form->{customer}); -    $href .= "&customer=".$form->escape($form->{customer}); -    $option = $locale->text('Customer')." : $form->{customer}"; +    $callback .= "&customer=".$form->escape($form->{customer},1)."--$form->{customer_id}"; +    $href .= "&customer=".$form->escape($form->{customer})."--$form->{customer_id}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Customer')." : $form->{customer}"; +  } +  if ($form->{department}) { +    $callback .= "&department=".$form->escape($form->{department},1); +    $href .= "&department=".$form->escape($form->{department}); +    ($department) = split /--/, $form->{department}; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Department')." : $department";    }    if ($form->{invnumber}) { -    $callback .= "&invnumber=$form->{invnumber}"; +    $callback .= "&invnumber=".$form->escape($form->{invnumber},1);      $href .= "&invnumber=".$form->escape($form->{invnumber});      $option .= "\n<br>" if ($option);      $option .= $locale->text('Invoice Number')." : $form->{invnumber}";    }    if ($form->{ordnumber}) { -    $callback .= "&ordnumber=$form->{ordnumber}"; +    $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);      $href .= "&ordnumber=".$form->escape($form->{ordnumber});      $option .= "\n<br>" if ($option);      $option .= $locale->text('Order Number')." : $form->{ordnumber}";    }    if ($form->{notes}) { -    $callback .= "¬es=$form->{notes}"; +    $callback .= "¬es=".$form->escape($form->{notes},1);      $href .= "¬es=".$form->escape($form->{notes});      $option .= "\n<br>" if $option;      $option .= $locale->text('Notes')." : $form->{notes}"; @@ -911,7 +1178,7 @@ sub ar_transactions {      $callback .= "&transdateto=$form->{transdateto}";      $href .= "&transdateto=$form->{transdateto}";      $option .= "\n<br>" if ($option); -    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);    }    if ($form->{open}) {      $callback .= "&open=$form->{open}"; @@ -926,25 +1193,31 @@ sub ar_transactions {      $option .= $locale->text('Closed');    } -  @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint)); +  @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia));    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") {        push @column_index, $item; +      if ($form->{l_curr} && $item =~ /(amount|tax|paid|due)/) { +	push @column_index, "fx_$item"; +      } +	        # add column to href and callback        $callback .= "&l_$item=Y";        $href .= "&l_$item=Y";      }    } +     +    if ($form->{l_subtotal} eq 'Y') {      $callback .= "&l_subtotal=Y";      $href .= "&l_subtotal=Y";    } -  $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>"; +  $column_header{id} = "<th><a class=listheading href=$href&sort=id}>".$locale->text('ID')."</a></th>";    $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";    $column_header{duedate} = "<th><a class=listheading href=$href&sort=duedate>".$locale->text('Due Date')."</a></th>";    $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>"; @@ -957,12 +1230,17 @@ sub ar_transactions {    $column_header{datepaid} = "<th><a class=listheading href=$href&sort=datepaid>" . $locale->text('Date Paid') . "</a></th>";    $column_header{due} = "<th class=listheading>" . $locale->text('Amount Due') . "</th>";    $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>"; -  $column_header{employee} = "<th class=listheading><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</th>"; - -  $column_header{shippingpoint} = "<th class=listheading><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Ship via') . "</a></th>"; +  $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</th>"; +  $column_header{manager} = "<th><a class=listheading href=$href&sort=manager>".$locale->text('Manager')."</th>"; +  $column_header{till} = "<th class=listheading><a class=listheading href=$href&sort=till>".$locale->text('Till')."</th>"; +  $column_header{shippingpoint} = "<th><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Shipping Point') . "</a></th>"; +  $column_header{shipvia} = "<th><a class=listheading href=$href&sort=shipvia>" . $locale->text('Ship via') . "</a></th>"; -  $form->{title} = $locale->text('AR Transactions'); +  $column_header{curr} = "<th><a class=listheading href=$href&sort=curr>" . $locale->text('Curr') . "</a></th>"; +  map { $column_header{"fx_$_"} = "<th> </th>" } qw(amount tax netamount paid due); + +  $form->{title} = ($form->{title}) ? $form->{title} : $locale->text('AR Transactions');    $form->header; @@ -996,35 +1274,55 @@ sub ar_transactions {    # escape callback for href    $callback = $form->escape($callback); -  if (@{ $form->{AR} }) { -    $sameitem = $form->{AR}->[0]->{$form->{sort}}; +  # flip direction +  $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC"; +  $href =~ s/&direction=(\w+)&/&direction=$direction&/; +   +  if (@{ $form->{transactions} }) { +    $sameitem = $form->{transactions}->[0]->{$form->{sort}};    }    # sums and tax on reports by Antonio Gallardo    # -  foreach $ar (@{ $form->{AR} }) { +  foreach $ar (@{ $form->{transactions} }) {      if ($form->{l_subtotal} eq 'Y') {        if ($sameitem ne $ar->{$form->{sort}}) {  	&ar_subtotal;        }      } + +    if ($form->{l_curr}) { +      map { $ar->{"fx_$_"} = $ar->{$_}/$ar->{exchangerate} } qw(netamount amount paid); + +      map { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{"fx_$_"}, 2, " ")."</td>" } qw(netamount amount paid); +       +      $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{fx_amount} - $ar->{fx_netamount}, 2, " ")."</td>"; +      $column_data{fx_due} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{fx_amount} - $ar->{fx_paid}, 2, " ")."</td>"; + +      $subtotalfxnetamount += $ar->{fx_netamount}; +      $subtotalfxamount += $ar->{fx_amount}; +      $subtotalfxpaid += $ar->{fx_paid}; +       +      $totalfxnetamount += $ar->{fx_netamount}; +      $totalfxamount += $ar->{fx_amount}; +      $totalfxpaid += $ar->{fx_paid}; +       +    } +     +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{$_}, 2, " ")."</td>" } qw(netamount amount paid); -    $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")."</td>";      $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount}, 2, " ")."</td>"; -    $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount}, 2, " ")."</td>"; -    $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{paid}, 2, " ")."</td>";      $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid}, 2, " ")."</td>"; +          $subtotalnetamount += $ar->{netamount};      $subtotalamount += $ar->{amount};      $subtotalpaid += $ar->{paid}; -    $subtotaldue += $ar->{amount} - $ar->{paid};      $totalnetamount += $ar->{netamount};      $totalamount += $ar->{amount};      $totalpaid += $ar->{paid}; -    $totaldue += ($ar->{amount} - $ar->{paid});      $column_data{transdate} = "<td>$ar->{transdate} </td>";      $column_data{id} = "<td>$ar->{id}</td>"; @@ -1032,15 +1330,24 @@ sub ar_transactions {      $column_data{duedate} = "<td>$ar->{duedate} </td>";      $module = ($ar->{invoice}) ? "is.pl" : $form->{script}; +    $module = ($ar->{till}) ? "ps.pl" : $module; -    $column_data{invnumber} = "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>"; +    $column_data{invnumber} = "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ar->{invnumber}</a></td>";      $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>"; -    $column_data{name} = "<td>$ar->{name}</td>"; +     + +    $name = $form->escape($ar->{name}); +    $column_data{name} = "<td><a href=$href&customer=$name--$ar->{customer_id}&sort=$form->{sort}>$ar->{name}</a></td>"; +          $ar->{notes} =~ s/\r\n/<br>/g;      $column_data{notes} = "<td>$ar->{notes} </td>";      $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>"; +    $column_data{shipvia} = "<td>$ar->{shipvia} </td>";      $column_data{employee} = "<td>$ar->{employee} </td>"; - +    $column_data{manager} = "<td>$ar->{manager} </td>"; +    $column_data{till} = "<td>$ar->{till} </td>"; +    $column_data{curr} = "<td>$ar->{curr}</td>"; +          $i++; $i %= 2;      print "          <tr class=listrow$i> @@ -1070,10 +1377,30 @@ sub ar_transactions {    $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";    $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>"; -  $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>"; +  $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalpaid, 2, " ")."</th>"; + +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, " ")."</th>"; +    $column_data{fx_paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxpaid, 2, " ")."</th>"; +    $column_data{fx_due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxpaid, 2, " ")."</th>"; +  }    map { print "\n$column_data{$_}" } @column_index; +  if ($myconfig{acs} !~ /AR--AR/) { +    $i = 1; +    $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |; +    $button{'AR--Add Transaction'}{order} = $i++; +    $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice.').qq|"> |; +    $button{'AR--Sales Invoice'}{order} = $i++; + +    foreach $item (split /;/, $myconfig{acs}) { +      delete $button{$item}; +    } +  } +    print qq|  	</tr>        </table> @@ -1089,13 +1416,27 @@ sub ar_transactions {  <input name=callback type=hidden value="$form->{callback}"> +<input type=hidden name=customer value="$form->{customer}"> +<input type=hidden name=customer_id value=$form->{customer_id}> +<input type=hidden name=vc value=customer> +  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  if (! $form->{till}) { +    foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +      print $item->{code}; +    } +  } -<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +  print qq|  </form>  </body> @@ -1112,12 +1453,22 @@ sub ar_subtotal {    $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";    $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>"; -  $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>"; +  $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalpaid, 2, " ")."</th>"; + +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, " ")."</th>"; +    $column_data{fx_paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxpaid, 2, " ")."</th>"; +    $column_data{fx_due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxmount - $subtotalfxpaid, 2, " ")."</th>"; +  }    $subtotalnetamount = 0;    $subtotalamount = 0;    $subtotalpaid = 0; -  $subtotaldue = 0; +   +  $subtotalfxnetamount = 0; +  $subtotalfxamount = 0; +  $subtotalfxpaid = 0;    $sameitem = $ar->{$form->{sort}}; diff --git a/sql-ledger/bin/mozilla/arap.pl b/sql-ledger/bin/mozilla/arap.pl index fecd9260f..224ea402b 100644 --- a/sql-ledger/bin/mozilla/arap.pl +++ b/sql-ledger/bin/mozilla/arap.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 2002 +# Copyright (c) 2003  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -38,7 +38,7 @@ if (-f "$form->{path}/$form->{login}_arap.pl") {  sub check_name { -  my ($name) = @_; +  my ($name, $msg) = @_;    my ($new_name, $new_id) = split /--/, $form->{$name};    my $i = 0; @@ -48,17 +48,21 @@ sub check_name {      if ($form->{"old$name"} ne $form->{$name}) {        # this is needed for is, ir and oe        map { delete $form->{"${_}_rate"} } (split / /, $form->{taxaccounts}); -       +        # for credit calculations        $form->{oldinvtotal} = 0;        $form->{oldtotalpaid} = 0; +      $form->{calctax} = 1;        $form->{"${name}_id"} = $new_id; -      $form->{"old$name"} = "$new_name--$new_id"; -        IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');        IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor'); +      $form->{$name} = $form->{"old$name"} = "$new_name--$new_id"; + +      # put employee together if there is a new employee_id +      $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; +        $i = 1;      }    } else { @@ -71,6 +75,7 @@ sub check_name {        # for credit calculations        $form->{oldinvtotal} = 0;        $form->{oldtotalpaid} = 0; +      $form->{calctax} = 1;        # return one name or a list of names in $form->{name_list}        if (($i = $form->get_name(\%myconfig, $name)) > 1) { @@ -87,9 +92,12 @@ sub check_name {  	IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');  	IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor'); +	# put employee together if there is a new employee_id +	$form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; +        } else { -	# name is not on file -	$msg = ucfirst $name . " not on file!"; +	# name is not on file or no outstanding invoice +	$msg = ucfirst $name . " not on file!" unless $msg;  	$form->error($locale->text($msg));        }      } @@ -111,8 +119,8 @@ sub select_name {    $label = ucfirst $table;    $column_data{ndx} = qq|<th> </th>|; -  $column_data{name} = qq|<th>|.$locale->text($label).qq|</th>|; -  $column_data{address} = qq|<th>|.$locale->text('Address').qq|</th>|; +  $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|; +  $column_data{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|;    # list items with radio button on a form    $form->header; @@ -144,11 +152,11 @@ sub select_name {    foreach $ref (@{ $form->{name_list} }) {      $checked = ($i++) ? "" : "checked"; -    $ref->{name} =~ s/"/"/g; +    $ref->{name} = $form->quote($ref->{name});     $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;     $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|; -   $column_data{address} = qq|<td>$ref->{address}</td>|; +   $column_data{address} = qq|<td>$ref->{address1} $ref->{address2} $ref->{city} $ref->{state} $ref->{zipcode} $ref->{country}</td>|;      $j++; $j %= 2;      print qq| @@ -178,15 +186,10 @@ sub select_name {  |; -  # delete action variable -  delete $form->{action}; -  delete $form->{name_list}; -     -  # save all other form variables -  foreach $key (keys %${form}) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input name=$key type=hidden value="$form->{$key}">\n|; -  } +  # delete variables +  map { delete $form->{$_} } qw(action name_list header); +   +  $form->hide_form();    print qq|  <input type=hidden name=nextsub value=name_selected> @@ -225,6 +228,9 @@ sub name_selected {    IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');    IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor'); +  # put employee together if there is a new employee_id +  $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id}; +    &update(1);  } @@ -240,8 +246,10 @@ sub add_transaction {    $form->{callback} = $form->escape($form->{callback},1);    map { $argv .= "$_=$form->{$_}&" } keys %$form; -  exec ("perl", "$module.pl", $argv); +  $form->{callback} = "$module.pl?$argv"; +  $form->redirect; +    } @@ -269,6 +277,8 @@ sub check_project {  	  # not on file  	  $form->error($locale->text('Project not on file!'));  	} +      } else { +	$form->{"oldprojectnumber_$i"} = "";        }      }    } @@ -316,7 +326,7 @@ sub select_project {    foreach $ref (@{ $form->{project_list} }) {      $checked = ($i++) ? "" : "checked"; -    $ref->{name} =~ s/"/"/g; +    $ref->{name} = $form->quote($ref->{name});     $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;     $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|; @@ -351,14 +361,9 @@ sub select_project {  |;    # delete action variable -  delete $form->{action}; -  delete $form->{project_list}; -     -  # save all other form variables -  foreach $key (keys %${form}) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input name=$key type=hidden value="$form->{$key}">\n|; -  } +  map { delete $form->{$_} } qw(action project_list header); +   +  $form->hide_form();    print qq|  <input type=hidden name=nextsub value=project_selected> @@ -392,7 +397,11 @@ sub project_selected {    map { delete $form->{$_} } qw(ndx lastndx nextsub); -  &update; +  if ($form->{update}) { +    &{ $form->{update} }; +  } else { +    &update; +  }  } @@ -401,6 +410,6 @@ sub continue { &{ $form->{nextsub} } };  sub gl_transaction { &add };  sub ar_transaction { &add_transaction(ar) };  sub ap_transaction { &add_transaction(ap) }; -sub sales_invoice { &add_transaction(is) }; -sub vendor_invoice { &add_transaction(ir) }; +sub sales_invoice_ { &add_transaction(is) }; +sub vendor_invoice_ { &add_transaction(ir) }; diff --git a/sql-ledger/bin/mozilla/arapprn.pl b/sql-ledger/bin/mozilla/arapprn.pl new file mode 100644 index 000000000..eea82c7e6 --- /dev/null +++ b/sql-ledger/bin/mozilla/arapprn.pl @@ -0,0 +1,660 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2003 +# +#  Author: Dieter Simader +#   Email: dsimader@sql-ledger.org +#     Web: http://www.sql-ledger.org +#  +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#====================================================================== +#  +# +# printing routines for ar, ap +# + +# any custom scripts for this one +if (-f "$form->{path}/custom_arapprn.pl") { +    eval { require "$form->{path}/custom_arapprn.pl"; }; +} +if (-f "$form->{path}/$form->{login}_arapprn.pl") { +    eval { require "$form->{path}/$form->{login}_arapprn.pl"; }; +} + + +1; +# end of main + + +sub print { +   +  if ($form->{AP}) { +    $form->{vc} = "vendor"; +    $form->{ARAP} = "AP"; +    $invfld = "vinumber"; +  } +  if ($form->{AR}) { +    $form->{vc} = "customer"; +    $form->{ARAP} = "AR"; +    $invfld = "sinumber"; +  } +   +  if ($form->{media} !~ /screen/) { +    $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/; +  } + +  if ($form->{media} eq 'screen' && $form->{formname} =~ /(check|receipt)/) { +    $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/; +  } +   +  if (! $form->{invnumber}) { +    $form->{invnumber} = $form->update_defaults(\%myconfig, $invfld); +    if ($form->{media} eq 'screen') { +      if ($form->{media} eq 'screen') { +	&update; +	exit; +      } +    } +  } + +  if ($form->{formname} =~ /(check|receipt)/) { +    if ($form->{media} ne 'screen') { +      map { delete $form->{$_} } qw(action header); +      $form->{invtotal} = $form->{oldinvtotal}; +       +      foreach $key (keys %$form) { +	$form->{$key} =~ s/&/%26/g; +	$form->{previousform} .= qq|$key=$form->{$key}&|; +      } +      chop $form->{previousform}; +      $form->{previousform} = $form->escape($form->{previousform}, 1); +    } + +    if ($form->{paidaccounts} > 1) { +      if ($form->{"paid_$form->{paidaccounts}"}) { +	&update; +	exit; +      } elsif ($form->{paidaccounts} > 2) { +	# select payment +	&select_payment; +	exit; +      } +    } else { +      $form->error($locale->text('Nothing to print!')); +    } +     +  } + +  &{ "print_$form->{formname}" }(1); + +} + + +sub print_check { +  my ($i) = @_; +   +  $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form"; + +  if ($form->{"paid_$i"}) { +    @a = (); +     +    if (exists $form->{longformat}) { +      $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat}); +    } + +    push @a, "source_$i", "memo_$i"; +    $form->format_string(@a); +  } + +  $form->{amount} = $form->{"paid_$i"}; +  map { $form->{$_} = $form->{"${_}_$i"} } qw(datepaid source memo); + +   +  &{ "$form->{vc}_details" }; +  @a = qw(name address1 address2 city state zipcode country); +  +  foreach $item (qw(invnumber ordnumber)) { +    $temp{$item} = $form->{$item}; +    delete $form->{$item}; +    push(@{ $form->{$item} }, $temp{$item}); +  } +  push(@{ $form->{invdate} }, $form->{transdate}); +  push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2)); +  push(@{ $form->{paid} }, $form->{"paid_$i"}); + +  use SL::CP; +  if ($form->{language_code}) { +    $c = new CP $form->{language_code}; +  } else { +    $c = new CP $myconfig->{countrycode}; +  }  +  $c->init; +  ($whole, $form->{decimal}) = split /\./, $form->{amount}; +  $form->{decimal} .= "00"; +  $form->{decimal} = substr($form->{decimal}, 0, 2); +  $form->{text_amount} = $c->num2text($whole);  +   +  ($form->{employee}) = split /--/, $form->{employee}; + +  $form->{notes} =~ s/^\s+//g; +  push @a, "notes"; + +  map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax businessnumber)); +  push @a, qw(company address tel fax businessnumber); +   +  $form->format_string(@a); + +  $form->{templates} = "$myconfig{templates}"; +  $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html"; + +  if ($form->{format} =~ /(postscript|pdf)/) { +    $form->{IN} =~ s/html$/tex/; +  } + +  if ($form->{media} !~ /(screen|queue)/) { +    $form->{OUT} = "| $printer{$form->{media}}"; +     +    $reference = $form->{invnumber}; +     +    if ($form->{formname} =~ /(check|receipt)/) { +      $form->{rowcount} = 1; +      $form->{"id_1"} = $form->{id}; +      $form->{"checked_1"} = 1; +      $form->{account} = $form->{"$form->{ARAP}_paid_$i"}; +      $reference = $form->{"source_$i"}; +    } +       +    if ($form->{printed} !~ /$form->{formname}/) { + +      $form->{printed} .= " $form->{formname}"; +      $form->{printed} =~ s/^ //; + +      $form->update_status(\%myconfig); +    } + +    %audittrail = ( tablename   => lc $form->{ARAP}, +                    reference   => $reference, +		    formname    => $form->{formname}, +		    action      => 'printed', +		    id          => $form->{id} ); +     +    %status = (); +    map { $status{$_} = $form->{$_} } qw(printed queued audittrail); +     +    $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); + +  } + +  if ($form->{media} eq 'queue') { +    %queued = split / /, $form->{queued}; +     +    $reference = $form->{invnumber}; +  +    if ($form->{formname} =~ /(check|receipt)/) { +      $form->{rowcount} = 1; +      $form->{"id_1"} = $form->{id}; +      $form->{"checked_1"} = 1; +      $form->{account} = $form->{"$form->{ARAP}_paid_$i"}; +      $reference = $form->{"source_$i"}; +    } +  +    if ($filename = $queued{$form->{formname}}) { +      $form->{queued} =~ s/$form->{formname} $filename//; +      unlink "$spool/$filename"; +      $filename =~ s/\..*$//g; +    } else { +      $filename = time; +      $filename .= $$; +    } + +    $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf'; +    $form->{OUT} = ">$spool/$filename"; + +    $form->{queued} .= " $form->{formname} $filename"; +    $form->{queued} =~ s/^ //; + +    # save status +    $form->update_status(\%myconfig); + +    %audittrail = ( tablename   => lc $form->{ARAP}, +                    reference   => $reference, +		    formname    => $form->{formname}, +		    action      => 'queued', +		    id          => $form->{id} ); + +    %status = (); +    map { $status{$_} = $form->{$_} } qw(printed queued audittrail); + +    $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); + +  } + +  $form->{fileid} = $invnumber; +  $form->{fileid} =~ s/(\s|\W)+//g; + +  $form->parse_template(\%myconfig, $userspath); + +  if ($form->{previousform}) { +   +    $previousform = $form->unescape($form->{previousform}); + +    map { delete $form->{$_} } keys %$form; + +    foreach $item (split /&/, $previousform) { +      ($key, $value) = split /=/, $item, 2; +      $value =~ s/%26/&/g; +      $form->{$key} = $value; +    } + +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + +    map { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) } (1 .. $form->{rowcount}); +    map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } split / /, $form->{taxaccounts}; + +    for $i (1 .. $form->{paidaccounts}) { +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); +    } + +    map { $form->{$_} = $status{$_} } qw(printed queued audittrail); + +    &{ "$display_form" }; +     +  } + +} + + +sub print_receipt { &print_check; } + + +sub print_transaction { +  +  $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form"; +  +  if ($form->{media} !~ /screen/) { +    $old_form = new Form; +    map { $old_form->{$_} = $form->{$_} } keys %$form; +  } +  +  &{ "$form->{vc}_details" }; +  @a = qw(name address1 address2 city state zipcode country); +   +   +  $form->{invtotal} = 0; +  foreach $i (1 .. $form->{rowcount} - 1) { +    ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"}; +    ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"}; +     +    $form->format_string(qw(tempaccno tempaccount tempprojectnumber)); +     +    push(@{ $form->{accno} }, $form->{tempaccno}); +    push(@{ $form->{account} }, $form->{tempaccount}); +    push(@{ $form->{projectnumber} }, $form->{tempprojectnumber}); + +    push(@{ $form->{amount} }, $form->{"amount_$i"}); + +    $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"}); +     +  } + +  foreach $accno (split / /, $form->{taxaccounts}) { +    if ($form->{"tax_$accno"}) { +      $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"}); +      push(@{ $form->{tax} }, $form->{"tax_$accno"}); +      push(@{ $form->{taxdescription} }, $form->{"${accno}_description"}); +      push(@{ $form->{taxrate} }, $form->{"${accno}_rate"} * 100); +      push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"}); +    } +  } +     +  +  push @a, $form->{ARAP}; +  $form->format_string(@a); +   +  $form->{paid} = 0; +  for $i (1 .. $form->{paidaccounts} - 1) { + +    if ($form->{"paid_$i"}) { +    @a = (); +    $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"}); +     +    if (exists $form->{longformat}) { +      $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat}); +    } + +    push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i"; +    $form->format_string(@a); +     +    ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"}; +     +    push(@{ $form->{payment} }, $form->{"paid_$i"}); +    push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"}); +    push(@{ $form->{paymentaccount} }, $account); +    push(@{ $form->{paymentsource} }, $form->{"source_$i"}); +    push(@{ $form->{paymentmemo} }, $form->{"memo_$i"}); +    } +     +  } + + +  $form->{invtotal} = $form->{subtotal} + $tax; +  $form->{total} = $form->{invtotal} - $form->{paid}; +   +  use SL::CP; +  if ($form->{language_code}) { +    $c = new CP $form->{language_code}; +  } else { +    $c = new CP $myconfig->{countrycode}; +  }  +  $c->init; +  ($whole, $form->{decimal}) = split /\./, $form->{invtotal}; +  $form->{decimal} .= "00"; +  $form->{decimal} = substr($form->{decimal}, 0, 2); +  $form->{text_amount} = $c->num2text($whole);  +   +  map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) } qw(invtotal subtotal paid total); +   +  ($form->{employee}) = split /--/, $form->{employee}; + +  if (exists $form->{longformat}) { +    map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) } ("duedate", "transdate"); +  } + +  $form->{notes} =~ s/^\s+//g; + +  push @a, ("invnumber", "transdate", "duedate", "notes"); + +  map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax businessnumber)); +  push @a, qw(company address tel fax businessnumber); +   +  $form->format_string(@a); + +  $form->{invdate} = $form->{transdate}; + +  $form->{templates} = "$myconfig{templates}"; +  $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html"; + +  if ($form->{format} =~ /(postscript|pdf)/) { +    $form->{IN} =~ s/html$/tex/; +  } + +  if ($form->{media} !~ /(screen|queue)/) { +    $form->{OUT} = "| $printer{$form->{media}}"; +     +    if ($form->{printed} !~ /$form->{formname}/) { + +      $form->{printed} .= " $form->{formname}"; +      $form->{printed} =~ s/^ //; + +      $form->update_status(\%myconfig); +    } + +    $old_form->{printed} = $form->{printed}; +     +    %audittrail = ( tablename   => lc $form->{ARAP}, +                    reference   => $form->{"invnumber"}, +		    formname    => $form->{formname}, +		    action      => 'printed', +		    id          => $form->{id} ); +     +    $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); + +  } + +  if ($form->{media} eq 'queue') { +    %queued = split / /, $form->{queued}; + +    if ($filename = $queued{$form->{formname}}) { +      $form->{queued} =~ s/$form->{formname} $filename//; +      unlink "$spool/$filename"; +      $filename =~ s/\..*$//g; +    } else { +      $filename = time; +      $filename .= $$; +    } + +    $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf'; +    $form->{OUT} = ">$spool/$filename"; + +    $form->{queued} .= " $form->{formname} $filename"; +    $form->{queued} =~ s/^ //; + +    # save status +    $form->update_status(\%myconfig); + +    $old_form->{queued} = $form->{queued}; + +    %audittrail = ( tablename   => lc $form->{ARAP}, +                    reference   => $form->{invnumber}, +		    formname    => $form->{formname}, +		    action      => 'queued', +		    id          => $form->{id} ); +    $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); + +  } + +  $form->{fileid} = $form->{invnumber}; +  $form->{fileid} =~ s/(\s|\W)+//g; + +  $form->parse_template(\%myconfig, $userspath); + +  if ($old_form) { +    $old_form->{invnumber} = $form->{invnumber}; +    $old_form->{invtotal} = $form->{invtotal}; + +    map { delete $form->{$_} } keys %$form; +    map { $form->{$_} = $old_form->{$_} } keys %$old_form; + +    if (! $form->{printandpost}) { +      map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + +      map { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) } (1 .. $form->{rowcount}); +      map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } split / /, $form->{taxaccounts}; + +      for $i (1 .. $form->{paidaccounts}) { +	map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); +      } +    } +     +    &{ "$display_form" }; + +  } +} + + +sub vendor_details { IR->vendor_details(\%myconfig, \%$form) }; +sub customer_details { IS->customer_details(\%myconfig, \%$form) }; + + +sub select_payment { + +  @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid"); + +  # list payments with radio button on a form +  $form->header; + +  $title = $locale->text('Select payment'); + +  $column_data{ndx} = qq|<th width=1%> </th>|; +  $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|; +  $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|; +  $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|; +  $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|; +  $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> +  <tr> +    <th class=listtop>$title</th> +  </tr> +  <tr space=5></tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; + +  map { print "\n$column_data{$_}" } @column_index; +   +  print qq| +	</tr> +|; + +  foreach $i (1 .. $form->{paidaccounts} - 1) { +   $checked = ($i == 1) ? "checked" : ""; + +   map { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| } @column_index; +   $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; +   $column_data{paid} = qq|<td align=right>$form->{"paid_$i"}</td>|; +     +    $j++; $j %= 2; +    print qq| +	<tr class=listrow$j>|; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +	</tr> +|; + +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +  $form->{nextsub} = "payment_selected"; + +  $form->hide_form(); +   +  print qq| + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; +   +} + +sub payment_selected { + +  &{ "print_$form->{formname}" }($form->{ndx}); + +} + + +sub print_options { + +  $form->{PD}{$form->{formname}} = "selected"; +  $form->{DF}{$form->{format}} = "selected"; + +  if ($form->{selectlanguage}) { +    $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"}); +    $form->{"selectlanguage"} =~ s/ selected//; +    $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/; +    $lang = qq|<select name=language_code>$form->{selectlanguage}</select> +    <input type=hidden name=selectlanguage value="|. +    $form->escape($form->{selectlanguage},1).qq|">|; +  } +   +  $type = qq|<select name=formname> +          <option value=transaction $form->{PD}{transaction}>|.$locale->text('Transaction'); + +  if ($form->{AR}) { +    $type .= qq| +          <option value=receipt $form->{PD}{receipt}>|.$locale->text('Receipt').qq|</select>|; +  } + +  if ($form->{AP}) { +    $type .= qq| +          <option value=check $form->{PD}{check}>|.$locale->text('Check').qq|</select>|; +  } +	   +  $media = qq|<select name=media> +          <option value=screen>|.$locale->text('Screen'); + +  if (%printer && $latex) { +    map { $media .= qq|  +          <option value="$_">$_| } sort keys %printer; +  } + +  $format = qq|<select name=format> +            <option value=html $form->{DF}{html}>html|; +	     +  if ($latex) { +# disable for now +#    $media .= qq| +#          <option value="queue">|.$locale->text('Queue'); +    $format .= qq| +            <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq| +	    <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF'); +  } + +  $format .= qq|</select>|; +  $media .= qq|</select>|; +  $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; + +  print qq| +  <table width=100%> +    <tr> +      <td> +  $type +  $lang +  $format +  $media +     </td> +     <td align=right> +  |; + +  if ($form->{printed} =~ /$form->{formname}/) { +    print $locale->text('Printed').qq|<br>|; +  } + +  if ($form->{queued} =~ /$form->{formname}/) { +    print $locale->text('Queued'); +  } + +  print qq| +      </td> +    </tr> +  </table> +|; + +} + + +sub print_and_post { + +  $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/; +  $form->error($locale->text('Select Printer or Queue!')) if $form->{media} eq 'screen'; + +  $form->{printandpost} = 1; +  $form->{display_form} = "post"; +  &print; + +} + diff --git a/sql-ledger/bin/mozilla/bp.pl b/sql-ledger/bin/mozilla/bp.pl new file mode 100644 index 000000000..9d0cea480 --- /dev/null +++ b/sql-ledger/bin/mozilla/bp.pl @@ -0,0 +1,567 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2003 +# +#  Author: Dieter Simader +#   Email: dsimader@sql-ledger.org +#     Web: http://www.sql-ledger.org +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#====================================================================== +# +# Batch printing +# +#====================================================================== + + +use SL::BP; + +1; +# end of main + + +sub search { + +# $locale->text('Sales Invoices') +# $locale->text('Packing Lists') +# $locale->text('Pick Lists') +# $locale->text('Sales Orders') +# $locale->text('Work Orders') +# $locale->text('Purchase Orders') +# $locale->text('Bin Lists') +# $locale->text('Quotations') +# $locale->text('RFQs') +# $locale->text('Checks') +# $locale->text('Receipts') + +  # setup customer/vendor selection +  BP->get_vc(\%myconfig, \%$form); +   +  if (@{ $form->{"all_$form->{vc}"} }) {  +    map { $name .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; +    $name = qq|<select name=$form->{vc}><option>\n$name</select>|; +  } else { +    $name = qq|<input name=$form->{vc} size=35>|; +  } + +# $locale->text('Customer') +# $locale->text('Vendor') + +  %label = ( invoice => { title => 'Sales Invoices', name => 'Customer' }, +             packing_list => { title => 'Packing Lists', name => 'Customer' }, +             pick_list => { title => 'Pick Lists', name => 'Customer' }, +             sales_order => { title => 'Sales Orders', name => 'Customer' }, +             work_order => { title => 'Work Orders', name => 'Customer' }, +             purchase_order => { title => 'Purchase Orders', name => 'Vendor' }, +             bin_list => { title => 'Bin Lists', name => 'Vendor' }, +             sales_quotation => { title => 'Quotations', name => 'Customer' }, +             request_quotation => { title => 'RFQs', name => 'Vendor' }, +             check => { title => 'Checks', name => 'Vendor' }, +             receipt => { title => 'Receipts', name => 'Customer' } +	   ); + +  $label{invoice}{invnumber} = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> +	  <td colspan=3><input name=invnumber size=20></td> +	</tr> +|; +  $label{invoice}{ordnumber} = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Order Number').qq|</th> +	  <td colspan=3><input name=ordnumber size=20></td> +	</tr> +|; +  $label{sales_quotation}{quonumber} = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th> +	  <td colspan=3><input name=quonumber size=20></td> +	</tr> +|; + +  $label{check}{chknumber} = qq| +  	<tr> +	  <th align=right nowrap>|.$locale->text('Reference').qq|</th> +	  <td colspan=3><input name=chknumber size=20></td> +	</tr> +|; + +  $label{packing_list}{invnumber} = $label{invoice}{invnumber}; +  $label{packing_list}{ordnumber} = $label{invoice}{ordnumber}; +  $label{pick_list}{invnumber} = $label{invoice}{invnumber}; +  $label{pick_list}{ordnumber} = $label{invoice}{ordnumber}; +  $label{sales_order}{ordnumber} = $label{invoice}{ordnumber}; +  $label{work_order}{ordnumber} = $label{invoice}{ordnumber}; +  $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber}; +  $label{bin_list}{ordnumber} = $label{invoice}{ordnumber}; +  $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber}; +  $label{receipt}{rctnumber} = $label{check}{chknumber}; +   +  # do one call to text +  $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title}); + +  if ($form->{type} =~ /(check|receipt)/) { +    if (BP->payment_accounts(\%myconfig, \%$form)) { +      $account = qq| +        <tr> +      	  <th align=right>|.$locale->text('Account').qq|</th> +|; + +      if ($form->{accounts}) { +	$account .= qq| +	  <td colspan=3><select name=account> +|; +	foreach $ref (@{ $form->{accounts} }) { +	  $account .= qq| +          <option>$ref->{accno}--$ref->{description} +|; +	} + +	$account .= qq| +          </select> +|; +      } else { +	$account .= qq| +	  <td colspan=3><input name=account></td> +|; + +      } +       +      $account .= qq| +	</tr> +|; + +    } +  } + + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +   +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=vc value=$form->{vc}> +<input type=hidden name=type value=$form->{type}> +<input type=hidden name=title value="$form->{title}"> + +<table width=100%> +  <tr><th class=listtop>$form->{title}</th></tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th> +	  <td colspan=3>$name</td> +	</tr> +	$account +	$label{$form->{type}}{invnumber} +	$label{$form->{type}}{ordnumber} +	$label{$form->{type}}{quonumber} +	$label{$form->{type}}{chknumber} +	$label{$form->{type}}{rctnumber} +	<tr> +	  <th align=right nowrap>|.$locale->text('From').qq|</th> +	  <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> +	  <th align=right>|.$locale->text('To').qq|</th> +	  <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> +	</tr> +	<input type=hidden name=sort value=transdate> +	$selectfrom +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<input type=hidden name=nextsub value=list_spool> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + + +sub remove { +   +  $selected = 0; +   +  for $i (1 .. $form->{rowcount}) { +    if ($form->{"checked_$i"}) { +      $selected = 1; +      last; +    } +  } + +  $form->error('Nothing selected!') unless $selected; +  +  $form->{title} = $locale->text('Confirm!'); +   +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> +|; + +  map { delete $form->{$_} } qw(action header); +   +  foreach $key (keys %$form) { +    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; +  } + +  print qq| +<h2 class=confirm>$form->{title}</h2> + +<h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4> + +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub yes { + +  $form->info($locale->text('Removing marked entries from queue ...')); +  $form->{callback} .= "&header=1" if $form->{callback}; + +  $form->redirect($locale->text('Removed spoolfiles!')) if (BP->delete_spool(\%myconfig, \%$form, $spool)); +  $form->error($locale->text('Cannot remove files!')); + +} + + +sub print { + +  if ($form->{callback}) { +    map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} } (1 .. $form->{rowcount}); +    $form->{callback} .= "&header=1"; +  } + +  for $i (1 .. $form->{rowcount}) { +    if ($form->{"checked_$i"}) { +      $form->{OUT} = "| $printer{$form->{media}}"; +      $form->info($locale->text('Printing ... ')); + +      if (BP->print_spool(\%myconfig, \%$form, $spool)) { +	print $locale->text('done'); +	$form->redirect($locale->text('Marked entries printed!')); +      } +      exit; +    } +  } + +  $form->error('Nothing selected!'); + +} + + +sub list_spool { + +  $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}}); +  ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}}); + +  BP->get_spoolfiles(\%myconfig, \%$form); + +  $title = $form->escape($form->{title}); +  $href = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title"; +  +  $form->sort_order(); +   +  $title = $form->escape($form->{title},1); +  $callback = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title"; + +  if ($form->{$form->{vc}}) { +    $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1); +    $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}}); +    $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor'); +    $option .= " : $form->{$form->{vc}}"; +  } +  if ($form->{account}) { +    $callback .= "&account=".$form->escape($form->{account},1); +    $href .= "&account=".$form->escape($form->{account}); +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Account')." : $form->{account}"; +  } +  if ($form->{invnumber}) { +    $callback .= "&invnumber=".$form->escape($form->{invnumber},1); +    $href .= "&invnumber=".$form->escape($form->{invnumber}); +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Invoice Number')." : $form->{invnumber}"; +  } +  if ($form->{ordnumber}) { +    $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1); +    $href .= "&ordnumber=".$form->escape($form->{ordnumber}); +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Order Number')." : $form->{ordnumber}"; +  } +  if ($form->{quonumber}) { +    $callback .= "&quonumber=".$form->escape($form->{quonumber},1); +    $href .= "&quonumber=".$form->escape($form->{quonumber}); +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Quotation Number')." : $form->{quonumber}"; +  } +  +  if ($form->{transdatefrom}) { +    $callback .= "&transdatefrom=$form->{transdatefrom}"; +    $href .= "&transdatefrom=$form->{transdatefrom}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); +  } +  if ($form->{transdateto}) { +    $callback .= "&transdateto=$form->{transdateto}"; +    $href .= "&transdateto=$form->{transdateto}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +  } + +  $name = ucfirst $form->{vc}; +   +  @columns = qw(transdate); +  if ($form->{type} =~ /(invoice|check|receipt)/) { +    push @columns, "invnumber"; +  } +  if ($form->{type} =~ /(packing|pick)_list/) { +    push @columns, "invnumber"; +  } +  if ($form->{type} =~ /_(order|list)$/) { +    push @columns, "ordnumber"; +  } +  if ($form->{type} =~ /_quotation$/) { +    push @columns, "quonumber"; +  } + +  push @columns, (name, spoolfile); +  @column_index = $form->sort_columns(@columns); +  unshift @column_index, "checked"; + +  $column_header{checked} = "<th class=listheading> </th>"; +  $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>"; +  $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>"; +  $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>"; +  $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>"; +  $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>"; +  $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>"; + + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|; + +  map { print "\n$column_header{$_}" } @column_index; + +  print qq| +	</tr> +|; + + +  # add sort and escape callback, this one we use for the add sub +  $form->{callback} = $callback .= "&sort=$form->{sort}"; + +  # escape callback for href +  $callback = $form->escape($callback); +   +  $i = 0; +   +  foreach $ref (@{ $form->{SPOOL} }) { + +    $i++; +    +    $form->{"checked_$i"} = "checked" if $form->{"checked_$i"}; +     +    # this is for audittrail +    $form->{module} = $ref->{module}; +     +    if ($ref->{invoice}) { +      $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir"; +    } +    $module = "$ref->{module}.pl"; +     +    $column_data{transdate} = "<td>$ref->{transdate} </td>"; + +    if ($spoolfile eq $ref->{spoolfile}) { +      $column_data{checked} = qq|<td></td>|; +    } else { +      $column_data{checked} = qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|; +    } +     +    if ($ref->{module} eq 'oe') { +      $column_data{invnumber} = qq|<td> </td>|; +      $column_data{ordnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td> +      <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|; +       +      $column_data{quonumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td> +    <input type=hidden name="reference_$i" value="$ref->{quonumber}">|; +  +    } else { +      $column_data{ordnumber} = qq|<td>$ref->{ordnumber}</td>|; +      $column_data{quonumber} = qq|<td>$ref->{quonumber}</td>|; +      $column_data{invnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td> +    <input type=hidden name="reference_$i" value="$ref->{invnumber}">|; +    } +     +    +    $column_data{name} = "<td>$ref->{name}</td>"; +    $column_data{spoolfile} = qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td> + +|; + +    $spoolfile = $ref->{spoolfile}; +     +    $j++; $j %= 2; +    print " +        <tr class=listrow$j> +"; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +<input type=hidden name="id_$i" value=$ref->{id}> +<input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}> + +        </tr> +|; + +  } + +  print qq| +<input type=hidden name=rowcount value=$i> + +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=vc value="$form->{vc}"> +<input type=hidden name=type value="$form->{type}"> +<input type=hidden name=sort value="$form->{sort}"> +<input type=hidden name=module value=$form->{module}> + +<input type=hidden name=account value="$form->{account}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  if (%printer && $latex) { +    foreach $key (sort keys %printer) { +      print qq| +<input name=media type=radio class=radio value="$key" |; +      print qq|checked| if $key eq $myconfig{printer}; +      print qq|>$key|; +    } +     +    print qq| +<p> +<input class=submit type=submit name=action value="|.$locale->text('Select all').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Remove').qq|"> +|; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +</form> + +</body> +</html> +|; + +} + + +sub select_all { + +  map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount}); +  &list_spool; +   +} + + +sub continue { &{ $form->{nextsub} } }; + diff --git a/sql-ledger/bin/mozilla/ca.pl b/sql-ledger/bin/mozilla/ca.pl index ed3100573..9ee602e74 100644 --- a/sql-ledger/bin/mozilla/ca.pl +++ b/sql-ledger/bin/mozilla/ca.pl @@ -6,6 +6,7 @@  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +#  Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -26,7 +27,6 @@  #   #====================================================================== -  use SL::CA;  1; @@ -67,11 +67,11 @@ sub chart_of_accounts {    @column_index = qw(accno gifi_accno description debit credit); -  $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>\n|; -  $column_header{gifi_accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>\n|; -  $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>\n|; -  $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>\n|; -  $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>\n|; +  $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</th>\n|; +  $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</th>\n|; +  $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</th>\n|; +  $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</th>\n|; +  $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</th>\n|;    $form->{title} = $locale->text('Chart of Accounts'); @@ -83,8 +83,8 @@ sub chart_of_accounts {    print qq|  <body> -<table width=100%> -  <tr><th class=listtop colspan=$colspan>$form->{title}</font></th></tr> +<table border=0 width=100%> +  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>    <tr height="5"></tr>    <tr class=listheading>|; @@ -100,12 +100,12 @@ sub chart_of_accounts {      $description = $form->escape($ca->{description});      $gifi_description = $form->escape($ca->{gifi_description}); -    $href = qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|; +    $href = qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;      if ($ca->{charttype} eq "H") {        print qq|<tr class=listheading>|;        map { $column_data{$_} = "<th class=listheading>$ca->{$_}</th>"; } qw(accno description); -      $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno} </font></th>"; +      $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno} </th>";      } else {        $i++; $i %= 2;        print qq|<tr class=listrow$i>|; @@ -129,8 +129,8 @@ sub chart_of_accounts {    map { $column_data{$_} = "<td> </td>"; } qw(accno gifi_accno description); -  $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</font></th>"; -  $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</font></th>"; +  $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</th>"; +  $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</th>";    print "<tr class=listtotal>"; @@ -158,10 +158,46 @@ sub list {    } else {      $form->{title} .= " - ".$locale->text('Account')." $form->{accno}";    } -   + +  # get departments +  $form->all_departments(\%myconfig); +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $department = qq| +        <tr> +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +| if $form->{selectdepartment}; + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +    $form->header; -  map { $form->{$_} =~ s/"/"/g; } qw(description gifi_description); +  map { $form->{$_} = $form->quote($form->{$_}) } qw(description gifi_description);    print qq|  <body> @@ -177,17 +213,19 @@ sub list {  <input type=hidden name=gifi_description value="$form->{gifi_description}">  <table border=0 width=100%> -  <tr><th class=listtop>$form->{title}</font></th></tr> +  <tr><th class=listtop>$form->{title}</th></tr>    <tr height="5"></tr    <tr valign=top>      <td>        <table> +        $department  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectfrom  	<tr>  	  <th align=right>|.$locale->text('Include in Report').qq|</th>  	  <td colspan=3> @@ -201,7 +239,7 @@ sub list {  <input type=hidden name=login value=$form->{login}>  <input type=hidden name=path value=$form->{path}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br><input class=submit type=submit name=action value="|.$locale->text('List Transactions').qq|">  </form> @@ -216,25 +254,41 @@ sub list {  sub list_transactions {    CA->all_transactions(\%myconfig, \%$form); - +      $description = $form->escape($form->{description});    $gifi_description = $form->escape($form->{gifi_description}); +  $department = $form->escape($form->{department}); +  $projectnumber = $form->escape($form->{projectnumber}); +  $title = $form->escape($form->{title});    # construct href -  $href = "$form->{script}?path=$form->{path}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}"; +  $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&title=$title"; +  $form->sort_order(); +   +  $description = $form->escape($form->{description},1); +  $gifi_description = $form->escape($form->{gifi_description},1); +  $department = $form->escape($form->{department},1); +  $projectnumber = $form->escape($form->{projectnumber},1); +  $title = $form->escape($form->{title},1); +     # construct callback -  $callback = "rp.pl?path=$form->{path}&action=generate_trial_balance&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&accounttype=$form->{accounttype}"; +  $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&title=$title";    # figure out which column comes first    $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;    $column_header{reference} = qq|<th><a class=listheading href=$href&sort=reference>|.$locale->text('Reference').qq|</a></th>|;    $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; +  $column_header{cleared} = qq|<th class=listheading>|.$locale->text('R').qq|</th>|;    $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;    $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;    $column_header{balance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;    @column_index = $form->sort_columns(qw(transdate reference description debit credit)); + +  if ($form->{link} =~ /_paid/) { +    @column_index = $form->sort_columns(qw(transdate reference description cleared debit credit)); +  }    if ($form->{accounttype} eq 'gifi') {      map { $form->{$_} = $form->{"gifi_$_"} } qw(accno description); @@ -246,8 +300,16 @@ sub list_transactions {    $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account');    $form->{title} .= " $form->{accno} - $form->{description}"; -  -  + +  if ($form->{department}) { +    ($department) = split /--/, $form->{department}; +    $options = $locale->text('Department')." : $department<br>"; +  } +  if ($form->{projectnumber}) { +    ($projectnumber) = split /--/, $form->{projectnumber}; +    $options .= $locale->text('Project Number')." : $projectnumber<br>"; +  } +    if ($form->{fromdate} || $form->{todate}) {      if ($form->{fromdate}) {        $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); @@ -261,6 +323,7 @@ sub list_transactions {      $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig),1);    } +  $options .= $form->{period};    $form->header; @@ -269,11 +332,11 @@ sub list_transactions {  <table width=100%>    <tr> -    <th class=listtop>$form->{title}</font></th> +    <th class=listtop>$form->{title}</th>    </tr>    <tr height="5"></tr>    <tr> -    <td>$form->{period}</td> +    <td>$options</td>    </tr>    <tr>      <td> @@ -320,7 +383,7 @@ print qq|      }      # construct link to source -    $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{reference}</a>"; +    $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{reference}</a>";      $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>"; @@ -337,7 +400,9 @@ print qq|      $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;      $column_data{reference} = qq|<td>$href</td>|; -    $column_data{description} = qq|<td>$ca->{description}</td>|; +    $column_data{description} = qq|<td>$ca->{description} </td>|; +     +    $column_data{cleared} = ($ca->{cleared}) ? qq|<td>*</td>| : qq|<td> </td>|;      $i++; $i %= 2;      print qq| @@ -360,9 +425,9 @@ print qq|    map { $column_data{$_} = "<td> </td>" } @column_index; -  $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</font></th>"; -  $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</font></th>"; -  $column_data{balance} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</font></th>"; +  $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>"; +  $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>"; +  $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";    print qq|  	<tr class=listtotal> @@ -391,8 +456,8 @@ sub ca_subtotal {    map { $column_data{$_} = "<td> </td>" } @column_index; -  $column_data{debit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldebit, 2, " ") . "</font></th>"; -  $column_data{credit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalcredit, 2, " ") . "</font></th>"; +  $column_data{debit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotaldebit, 2, " ") . "</th>"; +  $column_data{credit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotalcredit, 2, " ") . "</th>";    $subtotaldebit = 0;    $subtotalcredit = 0; diff --git a/sql-ledger/bin/mozilla/cp.pl b/sql-ledger/bin/mozilla/cp.pl index 911b70105..8aefa0ccd 100644 --- a/sql-ledger/bin/mozilla/cp.pl +++ b/sql-ledger/bin/mozilla/cp.pl @@ -6,6 +6,7 @@  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +# Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -27,6 +28,7 @@  use SL::CP; +use SL::OP;  use SL::IS;  use SL::IR; @@ -38,30 +40,64 @@ require "$form->{path}/arap.pl";  sub payment { +  $form->{callback} = "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&all_vc=$form->{all_vc}&type=$form->{type}"; +   +  $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP"; +  $form->{arap} = lc $form->{ARAP}; +    # setup customer/vendor selection for open invoices -  CP->get_openvc(\%myconfig, \%$form); +  if ($form->{all_vc}) { +    $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}); +  } else { +    CP->get_openvc(\%myconfig, \%$form); +  } +  $form->{"select$form->{vc}"} = ""; +      if ($form->{"all_$form->{vc}"}) { -    map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; +    $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id}; +    map { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} }; +  } + +  # departments +  if (@{ $form->{all_departments} }) {  +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department}; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });    } -  $form->{arap} = ($form->{vc} eq 'customer') ? "AR" : "AP"; +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  }    CP->paymentaccounts(\%myconfig, \%$form); -  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR} }; +  $form->{selectaccount} = ""; +  $form->{"select$form->{ARAP}"} = ""; + +  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR}{"$form->{ARAP}_paid"} }; +  map { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR}{$form->{ARAP}} };    # currencies    @curr = split /:/, $form->{currencies};    chomp $curr[0]; -  $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} = $curr[0]; +  $form->{defaultcurrency} = $curr[0]; +  $form->{selectcurrency} = "";    map { $form->{selectcurrency} .= "<option>$_\n" } @curr; -  $form->{media} = "screen"; +  $form->{oldcurrency} = $form->{currency}; + +  if ($form->{currency} ne $form->{defaultcurrency}) { +    $form->{forex} = $form->{exchangerate} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, ($form->{vc} eq 'customer') ? "buy" : "sell"); +  } +   +  $form->{media} = $myconfig{printer}; +  $form->{format} = "pdf" unless $myconfig{printer};    &form_header; -  &list_invoices;    &form_footer;  } @@ -72,63 +108,100 @@ sub form_header {    $vclabel = ucfirst $form->{vc};    $vclabel = $locale->text($vclabel); - -  if ($form->{vc} eq 'customer') { +   +  if ($form->{type} eq 'receipt') {      $form->{title} = $locale->text('Receipt'); -    $rclabel = $locale->text('Reference'); -    $form->{type} = 'receipt'; -  } else { +  } +  if ($form->{type} eq 'check') {      $form->{title} = $locale->text('Payment'); -    $rclabel = $locale->text('Check'); -    $form->{type} = 'check';    } +  # $locale->text('Customer')  # $locale->text('Vendor')    if ($form->{$form->{vc}} eq "") { -    map { $form->{"addr$_"} = "" } (1 .. 4); +    map { $form->{$_} = "" } qw(address1 address2 city zipcode state country);    } +  $exchangerate = "";    if ($form->{currency} ne $form->{defaultcurrency}) {      $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});      if ($form->{forex}) {        $exchangerate = qq|   	      <tr> -		<th align=right nowrap>|.$locale->text('Exchangerate').qq|</th> +		<th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>  		<td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>  	      </tr>  |;      } else {        $exchangerate = qq|   	      <tr> -		<th align=right nowrap>|.$locale->text('Exchangerate').qq|</th> +		<th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>  		<td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>  	      </tr>  |;      }    } + +  foreach $item ($form->{vc}, department) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } -  foreach $item ($form->{vc}, account, currency) { +  foreach $item (account, currency, $form->{ARAP}) {      $form->{"select$item"} =~ s/ selected//;      $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;    }    $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>| : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|; +  if ($form->{all_vc}) { +    $allvc = "checked"; +    $form->{openinvoices} = ""; +  } else { +    $allvc = ""; +    $form->{openinvoices} = 1; +  } +   +# $locale->text('AR') +# $locale->text('AP') + +  $department = qq| +              <tr> +	        <th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|"> +		<input type=hidden name=olddepartment value="$form->{department}"> + +	      </td> +	    </tr> +| if $form->{selectdepartment}; +    $form->header; +  $arap = lc $form->{ARAP}; +    print qq|  <body>  <form method=post action=$form->{script}> +<!-- <input type=hidden name=id value=1> --> +  <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=vc value=$form->{vc}>  <input type=hidden name=type value=$form->{type}> - -<table border=0 width=100%> +<input type=hidden name=formname value=$form->{type}> +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=arap value=$arap> +<input type=hidden name=ARAP value=$form->{ARAP}> +<input type=hidden name=openinvoices value=$form->{openinvoices}> +<input type=hidden name=title value="$form->{title}"> + +<table width=100%>    <tr>      <th class=listtop>$form->{title}</th>    </tr> @@ -140,39 +213,63 @@ sub form_header {  	  <td>  	    <table>  	      <tr> +	        <td align=right> +		<input name=all_vc type=checkbox style=checkbox value=Y $allvc> +		<input type=hidden name="oldall_vc" value="$form->{all_vc}"></td> +		<th align=left>|.$locale->text('All').qq|</th> +	      </tr> +	      <tr>  		<th align=right>$vclabel</th>  		<td>$vc</td> -                <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}"> +                <input type=hidden name="select$form->{vc}" value="|.$form->escape($form->{"select$form->{vc}"},1).qq|">                  <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>  		<input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">  	      </tr>  	      <tr valign=top>  		<th align=right nowrap>|.$locale->text('Address').qq|</th> -		<td> +		<td colspan=2>  		  <table>  		    <tr> -		      <td>$form->{addr1}</td> +		      <td>$form->{address1}</td>  		    </tr>  		    <tr> -		      <td>$form->{addr2}</td> +		      <td>$form->{address2}</td>  		    </tr> -		    <tr> -		      <td>$form->{addr3}</td> +		      <td>$form->{city}</td> +		    </tr> +		    </tr> +		      <td>$form->{state}</td> +		    </tr> +		    </tr> +		      <td>$form->{zipcode}</td>  		    </tr>  		    <tr> -		      <td>$form->{addr4}</td> +		      <td>$form->{country}</td>  		    </tr>  		  </table>  		</td> -		<input type=hidden name=addr1 value="$form->{addr1}"> -		<input type=hidden name=addr2 value="$form->{addr2}"> -		<input type=hidden name=addr3 value="$form->{addr3}"> -		<input type=hidden name=addr4 value="$form->{addr4}"> +		<input type=hidden name=address1 value="$form->{address1}"> +		<input type=hidden name=address2 value="$form->{address2}"> +		<input type=hidden name=city value="$form->{city}"> +		<input type=hidden name=state value="$form->{state}"> +		<input type=hidden name=zipcode value="$form->{zipcode}"> +		<input type=hidden name=country value="$form->{country}"> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Memo').qq|</th> +		<td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>  	      </tr>  	    </table>  	  </td>  	  <td align=right>  	    <table> +	      $department +	      <tr> +	        <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th> +		<td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select> +		</td> +		<input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}"> +	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Account').qq|</th>  		<td colspan=3><select name=account>$form->{selectaccount}</select> @@ -191,21 +288,13 @@ sub form_header {  	      </tr>  	      $exchangerate  	      <tr> -		<th align=right nowrap>$rclabel</th> +		<th align=right nowrap>|.$locale->text('Source').qq|</th>  		<td colspan=3><input name=source value="$form->{source}" size=10></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Amount').qq|</th>  		<td colspan=3><input name=amount size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, 2).qq|></td>  	      </tr> -	      <tr> -		<th align=right nowrap>|.$locale->text('From').qq|</th> -		<td><input name=transdatefrom size=11 title="$myconfig{dateformat}" value=$form->{transdatefrom}></td> -		<th align=right nowrap>|.$locale->text('to').qq|</th> -		<td><input name=transdateto size=11 title="$myconfig{dateformat}" value=$form->{transdateto}></td> -		<input type=hidden name=oldtransdatefrom value=$form->{oldtransdatefrom}> -		<input type=hidden name=oldtransdateto value=$form->{oldtransdateto}> -	      </tr>  	    </table>  	  </td>  	</tr> @@ -219,9 +308,11 @@ sub form_header {  sub list_invoices { -  @column_index = qw(invnumber transdate amount due paid selectpaid); +  @column_index = qw(invnumber transdate amount due checked paid);    $colspan = $#column_index + 1; + +  $invoice = $locale->text('Invoices');    print qq|    <input type=hidden name=column_index value="id @column_index"> @@ -229,16 +320,16 @@ sub list_invoices {      <td>        <table width=100%>  	<tr> -	  <th class=listheading colspan=$colspan>|.$locale->text('Invoices').qq|</th> +	  <th class=listheading colspan=$colspan>$invoice</th>  	</tr>  |;    $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";    $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";    $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>"; -  $column_data{due} = qq|<th nowrap>|.$locale->text('Due')."</th>"; -  $column_data{paid} = qq|<th nowrap>|.$locale->text('Applied')."</th>"; -  $column_data{selectpaid} = qq|<th nowrap>|.$locale->text('Paid in full')."</th>"; +  $column_data{due} = qq|<th nowrap>|.$locale->text('Amount Due')."</th>"; +  $column_data{paid} = qq|<th nowrap>|.$locale->text('Amount')."</th>"; +  $column_data{checked} = qq|<th nowrap>|.$locale->text('Select')."</th>";    print qq|          <tr> @@ -250,7 +341,6 @@ sub list_invoices {    for $i (1 .. $form->{rowcount}) { -    $form->{"selectpaid_$i"} = "checked" if $form->{"selectpaid_$i"};      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid);      $totalamount += $form->{"amount_$i"}; @@ -269,13 +359,10 @@ sub list_invoices {      $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>        <input type=hidden name="due_$i" value=$form->{"due_$i"}>|; -    $column_data{paid} = qq|<td align=right width=15%>|; -    if ($form->{"selectpaid_$i"}) { -      $column_data{paid} .= qq|<input type=hidden name="paid_$i" value=$form->{"paid_$i"}>$form->{"paid_$i"}</td>|; -    } else { -      $column_data{paid} .= qq|<input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|; -    } -    $column_data{selectpaid} = qq|<td align=center width=10%><input name="selectpaid_$i" type=checkbox class=checkbox $form->{"selectpaid_$i"}></td>|; +    $column_data{paid} = qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|; + +    $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : ""; +    $column_data{checked} = qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;      $j++; $j %= 2;      print qq| @@ -289,9 +376,9 @@ sub list_invoices {    map { $column_data{$_} = "<td> </td>" } @column_index; -  $column_data{amount} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, " ").qq|</th>|; -  $column_data{due} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, " ").qq|</th>|; -  $column_data{paid} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, " ").qq|</th>|; +  $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, " ").qq|</th>|; +  $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, " ").qq|</th>|; +  $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, " ").qq|</th>|;    print qq|          <tr class=listtotal> @@ -309,18 +396,45 @@ sub list_invoices {  sub form_footer { -  $form->{OP}{$form->{media}} = "checked"; +  $form->{DF}{$form->{format}} = "selected"; + +  if ($form->{selectlanguage}) { +    $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"}); +    $form->{"selectlanguage"} =~ s/ selected//; +    $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/; +    $lang = qq|<select name=language_code>$form->{selectlanguage}</select> +    <input type=hidden name=selectlanguage value="|. +    $form->escape($form->{selectlanguage},1).qq|">|; +  } +  $media = qq| +          <option value=screen>|.$locale->text('Screen') if $latex; + +  if (%printer && $latex) { +    map { $media .= qq|  +          <option value="$_">$_| } sort keys %printer; +  } +  if ($latex) { +    $media .= qq| +          <option value=queue>|.$locale->text('Queue'); +    $format .= qq| +            <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq| +	    <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF'); +  } +   +          print qq|    <tr>      <td><hr size=3 noshade></td>    </tr>  </table> + +<input type=hidden name=callback value="$form->{callback}">  <input type=hidden name=rowcount value=$form->{rowcount}>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> @@ -328,18 +442,24 @@ sub form_footer {    if ($latex) {      print qq| -<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> -<input class=radio type=radio name=media value=screen $form->{OP}{screen}> |.$locale->text('Screen'); - -    if ($myconfig{printer}) { -      print qq| -<input class=radio type=radio name=media value=printer $form->{OP}{printer}> |.$locale->text('Printer'); -    } +<input class=submit type=submit name=action value="|.$locale->text('Print').qq|">|;    } +  $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; +    print qq| +  $lang +<select name=format>$format</select> +<select name=media>$media</select> +|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } -</form> +  print qq| +  </form>  </body>  </html> @@ -351,15 +471,60 @@ sub form_footer {  sub update {    my ($new_name_selected) = @_; -  # get customer and invoices -  $updated = &check_name($form->{vc}); +  if ($form->{vc} eq 'customer') { +    $buysell = "buy"; +  } else { +    $buysell = "sell"; +  } + +  # get customer +  $updated = &check_name($form->{vc}, $locale->text('Nothing outstanding for ') . $form->{customer}); -  $updated = 1 if (($form->{oldtransdatefrom} ne $form->{transdatefrom}) || ($form->{oldtransdateto} ne $form->{transdateto})); -  $form->{oldtransdatefrom} = $form->{transdatefrom}; -  $form->{oldtransdateto} = $form->{transdateto}; +  if ($form->{department} ne $form->{olddepartment}) { +    $updated = 1; +  } +  # if we switched to all_vc +  if ($form->{all_vc} ne $form->{oldall_vc}) { + +    $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1; +     +    $form->{"select$form->{vc}"} = ""; + +    if ($form->{all_vc}) { +      $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}); +       +      if ($form->{"all_$form->{vc}"}) { +	map { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} }; +      } +       +    } else { +      CP->get_openvc(\%myconfig, \%$form); +       +      if ($form->{"all_$form->{vc}"}) { +	$newvc = qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|; +	map { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} }; + + +	# if the name is not the same +	if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) { +	  $form->{$form->{vc}} = $newvc; +	  &check_name($form->{vc}, $locale->text('Nothing outstanding for ') . $form->{customer}); +	} +      } +    } + +    if (@{ $form->{all_languages} }) { +      $form->{selectlanguage} = "<option>\n"; +      map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +    } + +  } +    if ($new_name_selected || $updated) {      CP->get_openinvoices(\%myconfig, \%$form); +    ($newvc) = split /--/, $form->{$form->{vc}}; +    $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;;      $updated = 1;    } @@ -371,15 +536,16 @@ sub update {      }    } -  # check currency -  $buysell = ($form->{vc} eq 'customer') ? "buy" : "sell";    $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));    $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount}); -   + +    if ($updated) {      $form->{rowcount} = 0; + +    $form->{queued} = "";      $i = 0;      foreach $ref (@{ $form->{PR} }) { @@ -389,11 +555,12 @@ sub update {        $form->{"transdate_$i"} = $ref->{transdate};        $ref->{exchangerate} = 1 unless $ref->{exchangerate};        $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate}; -      $form->{"due_$i"} = $form->round_amount(($ref->{amount} - $ref->{paid}) / $ref->{exchangerate}, 2); -      $amount = $form->round_amount($amount - $form->{"due_$i"}, 2); -      $form->{"selectpaid_$i"} = 1 if $amount > 0; +      $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate}; +      $form->{"checked_$i"} = ""; +      $form->{"paid_$i"} = ""; -      map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid); +      # need to format +      map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due);      }      $form->{rowcount} = $i; @@ -405,14 +572,15 @@ sub update {      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid); -    if ($form->{"selectpaid_$i"}) { -      $amount -= $form->{"due_$i"}; -       -      if ($amount < 0) { -	$form->{"selectpaid_$i"} = 0; -      } else { +    if ($form->{"checked_$i"}) { +      # calculate paid_$i +      if (!$form->{"paid_$i"}) {  	$form->{"paid_$i"} = $form->{"due_$i"};        } +       +      $amount -= $form->{"paid_$i"}; +    } else { +      $form->{"paid_$i"} = "";      }      map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid); @@ -429,9 +597,24 @@ sub update {  sub post {    &check_form; +   +  if ($form->{currency} ne $form->{defaultcurrency}) { +    $form->error($locale->text('Exchange rate missing!')) unless $form->{exchangerate}; +  } + +  $msg1 = "$form->{title} posted!"; +  $msg2 = "Cannot post $form->{title}!"; + +# $locale->text('Payment posted!') +# $locale->text('Receipt posted!') +# $locale->text('Cannot post Payment!') +# $locale->text('Cannot post Receipt!') + -  $form->redirect($locale->text('Payment posted!')) if (CP->process_payment(\%myconfig, \%$form)); -  $form->error($locale->text('Cannot post payment!')); +  $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2); + +  $form->redirect($locale->text($msg1)) if (CP->process_payment(\%myconfig, \%$form)); +  $form->error($locale->text($msg2));  } @@ -443,43 +626,52 @@ sub print {    ($whole, $form->{decimal}) = split /\./, $form->{amount};    $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2); -  $m = "*" x (24 - length $form->{amount}); -  $form->{amount} = $locale->text($form->{currency})."$m$form->{amount}";    $form->{decimal} .= "00";    $form->{decimal} = substr($form->{decimal}, 0, 2); -  $check = new CP $myconfig{countrycode}; +  $countrycode = ($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode}; +  $check = new CP $countrycode;    $check->init;    $form->{text_amount} = $check->num2text($whole);    &{ "$form->{vc}_details" }; -  $form->{format} = ($form->{media} eq 'screen') ? "pdf" : "postscript";    $form->{templates} = "$myconfig{templates}"; -  $form->{IN} = "$form->{type}.tex"; -  $form->{OUT} = "| $myconfig{printer}" if ($form->{media} eq 'printer'); +  $form->{IN} = "$form->{formname}.tex"; + +  if ($form->{media} !~ /(screen|queue)/) { +    $form->{OUT} = "| $printer{$form->{media}}"; +  } +  if ($form->{media} eq 'queue') { +    %queued = split / /, $form->{queued}; +     +    if ($filename = $queued{$form->{formname}}) { +      unlink "$spool/$filename"; +      $filename =~ s/\..*$//g; +    } else { +      $filename = time; +      $filename .= $$; +    } +    $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf'; +    $form->{queued} = "$form->{formname} $filename"; +    $form->{OUT} = ">$spool/$filename"; + +    $form->update_status(\%myconfig); + +  } +    $form->{company} = $myconfig{company};    $form->{address} = $myconfig{address}; -  -  @a = qw(name invnumber company address text_amount addr1 addr2 addr3 addr4); + +  @a = qw(name company address text_amount address1 address2 city state zipcode country memo);    $form->format_string(@a);    $form->parse_template(\%myconfig, $userspath); -  $form->{callback} = ""; - -  $label = uc $form->{type}; +  &update if $form->{media} ne 'screen'; -# $locale->text('Check printed!') -# $locale->text('Check printing failed!') -# $locale->text('Receipt printed!') -# $locale->text('Receipt printing failed!') - -  $form->redirect($locale->text("$label printed!")); -  $form->error($locale->text("$label printing failed!")); -    } @@ -489,10 +681,7 @@ sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };  sub check_form { -  # construct callback -  $form->{callback} = "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}"; - -  $form->redirect unless $form->{rowcount}; +  &check_name($form->{vc}, $locale->text('Nothing outstanding for ') . $form->{customer});    if ($form->{currency} ne $form->{oldcurrency}) {      &update; @@ -500,17 +689,22 @@ sub check_form {    }    $form->error($locale->text('Date missing!')) unless $form->{datepaid}; -  $form->error($locale->text('Amount missing!')) unless $form->{amount};    $closedto = $form->datetonum($form->{closedto}, \%myconfig);    $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);    $form->error($locale->text('Cannot process payment for a closed period!')) if ($datepaid <= $closedto); -  $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount}); +  # this is just to format the year +  $form->{datepaid} = $locale->date(\%myconfig, $form->{datepaid}); +   +  $amount = $form->parse_amount(\%myconfig, $form->{amount}); +  $form->{amount} = $amount; +      for $i (1 .. $form->{rowcount}) { -    $totalpaid += $form->parse_amount(\%myconfig, $form->{"paid_$i"});      if ($form->{"paid_$i"}) { +      $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"}); +              push(@{ $form->{paid} }, $form->{"paid_$i"});        push(@{ $form->{due} }, $form->{"due_$i"});        push(@{ $form->{invnumber} }, $form->{"invnumber_$i"}); @@ -518,11 +712,13 @@ sub check_form {      }    } -  $totalpaid = $form->round_amount($totalpaid, 2); - -  $form->error($locale->text('Nothing applied!')) unless $totalpaid; -  $form->error($locale->text('Amount does not equal applied!')) if ($form->{amount} != $totalpaid); - +  if ($form->round_amount($amount, 2) != 0) { +    push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2)); +    push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0")); +    push(@{ $form->{invnumber} }, ($form->{ARAP} eq 'AR') ? $locale->text('Deposit') : $locale->text('Prepayment')); +    push(@{ $form->{invdate} }, $form->{datepaid}); +  } +     } diff --git a/sql-ledger/bin/mozilla/ct.pl b/sql-ledger/bin/mozilla/ct.pl index 3dbb5656a..988422b9d 100644 --- a/sql-ledger/bin/mozilla/ct.pl +++ b/sql-ledger/bin/mozilla/ct.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -26,9 +26,6 @@  #  #====================================================================== -# $locale->text('Customers') -# $locale->text('Vendors') -  use SL::CT;  1; @@ -39,10 +36,12 @@ use SL::CT;  sub add {    $form->{title} = "Add"; +# $locale->text('Add Customer') +# $locale->text('Add Vendor') -  $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; -  CT->taxaccounts(\%myconfig, \%$form); +  CT->create_links(\%myconfig, \%$form);    &form_header;    &form_footer; @@ -50,10 +49,316 @@ sub add {  } +sub history { + +# $locale->text('Customer History') +# $locale->text('Vendor History') + +  $history = 1; +  $label = ucfirst $form->{db}; +  $label .= " History"; + +  if ($form->{db} eq 'customer') { +    $invlabel = $locale->text('Sales Invoices'); +    $ordlabel = $locale->text('Sales Orders'); +    $quolabel = $locale->text('Quotations'); +  } else { +    $invlabel = $locale->text('Vendor Invoices'); +    $ordlabel = $locale->text('Purchase Orders'); +    $quolabel = $locale->text('Request for Quotations'); +  } +   +  $form->{title} = $locale->text($label); +   +  $form->{nextsub} = "list_history"; + +  $transactions = qq| + 	<tr> +	  <td></td> +	  <td> +	    <table> +	      <tr> +	        <td> +		  <table> +		    <tr> +		      <td><input name=type type=radio class=radio value=invoice checked> $invlabel</td> +		    </tr> +		    <tr> +		      <td><input name=type type=radio class=radio value=order> $ordlabel</td> +		    </tr> +		    <tr> +		      <td><input name="type" type=radio class=radio value=quotation> $quolabel</td> +		    </tr> +		  </table> +		</td> +		<td> +		  <table> +		    <tr> +		      <th>|.$locale->text('From').qq|</th> +		      <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> +		      <th>|.$locale->text('To').qq|</th> +		      <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> +		    </tr> +		    <tr> +		      <td></td> +		      <td colspan=3> +	              <input name="open" type=checkbox class=checkbox value=Y checked> |.$locale->text('Open').qq| +	              <input name="closed" type=checkbox class=checkbox value=Y checked> |.$locale->text('Closed').qq| +		      </td> +		    </tr> +		  </table> +		</td> +	      </tr> + 	    </table> +	  </td> +	</tr> +|; + +  $include = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> +	  <td> +	    <table> +	      <tr> +		<td><input name=history type=radio class=radio value=summary checked> |.$locale->text('Summary').qq|</td> +		<td><input name=history type=radio class=radio value=detail> |.$locale->text('Detail').qq| +		</td> +	      </tr> +	      <tr> +		<td> +		<input name="l_partnumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Part Number').qq| +		</td> +		<td> +		<input name="l_description" type=checkbox class=checkbox value=Y checked> |.$locale->text('Description').qq| +		</td> +		<td> +		<input name="l_sellprice" type=checkbox class=checkbox value=Y checked> |.$locale->text('Sell Price').qq| +		</td> +		<td> +		<input name="l_curr" type=checkbox class=checkbox value=Y> |.$locale->text('Currency').qq| +		</td> +	      </tr> +	      <tr> +		<td> +		<input name="l_qty" type=checkbox class=checkbox value=Y> |.$locale->text('Qty').qq| +		</td> +		<td> +		<input name="l_unit" type=checkbox class=checkbox value=Y> |.$locale->text('Unit').qq| +		</td> +		<td> +		<input name="l_discount" type=checkbox class=checkbox value=Y> |.$locale->text('Discount').qq| +		</td> +	      <tr> +	      </tr> +		<td> +		<input name="l_deliverydate" type=checkbox class=checkbox value=Y> |.$locale->text('Delivery Date').qq| +		</td> +		<td> +		<input name="l_projectnumber" type=checkbox class=checkbox value=Y> |.$locale->text('Project Number').qq| +		</td> +		<td> +		<input name="l_serialnumber" type=checkbox class=checkbox value=Y> |.$locale->text('Serial Number').qq| +		</td> +	      </tr> +	    </table> +	  </td> +	</tr> +|; + +  &search_name; + +} + + +sub transactions { + +  if ($form->{db} eq 'customer') { +    $translabel = $locale->text('AR Transactions'); +    $invlabel = $locale->text('Sales Invoices'); +    $ordlabel = $locale->text('Sales Orders'); +    $quolabel = $locale->text('Quotations'); +  } else { +    $translabel = $locale->text('AP Transactions'); +    $invlabel = $locale->text('Vendor Invoices'); +    $ordlabel = $locale->text('Purchase Orders'); +    $quolabel = $locale->text('Request for Quotations'); +  } + +  +  $transactions = qq| + 	<tr> +	  <td></td> +	  <td> +	    <table> +	      <tr> +	        <td> +		  <table> +		    <tr> +		      <td><input name="l_transnumber" type=checkbox class=checkbox value=Y> $translabel</td> +		    </tr> +		    <tr> +		      <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> $invlabel</td> +		    </tr> +		    <tr> +		      <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> $ordlabel</td> +		    </tr> +		    <tr> +		      <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> $quolabel</td> +		    </tr> +		  </table> +		</td> +		<td> +		  <table> +		    <tr> +		      <th>|.$locale->text('From').qq|</th> +		      <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> +		      <th>|.$locale->text('To').qq|</th> +		      <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> +		    </tr> +		    <tr> +		      <td></td> +		      <td colspan=3> +	              <input name="open" type=checkbox class=checkbox value=Y checked> |.$locale->text('Open').qq| +	              <input name="closed" type=checkbox class=checkbox value=Y checked> |.$locale->text('Closed').qq| +		      </td> +		    </tr> +		    <tr> +		      <td></td> +		      <td colspan=3> +	              <input name="l_amount" type=checkbox class=checkbox value=Y checked> |.$locale->text('Amount').qq| +	              <input name="l_tax" type=checkbox class=checkbox value=Y checked> |.$locale->text('Tax').qq| +	              <input name="l_total" type=checkbox class=checkbox value=Y checked> |.$locale->text('Total').qq| +	              <input name="l_subtotal" type=checkbox class=checkbox value=Y> |.$locale->text('Subtotal').qq| +		      </td> +		    </tr> +		  </table> +		</td> +	      </tr> + 	    </table> +	  </td> +	</tr> +|; + +} + + +sub include_in_report { +   +  $label = ucfirst $form->{db}; +   +  if ($myconfig{role} =~ /(admin|manager)/) { +    $bcc = qq| +		<td><input name="l_bcc" type=checkbox class=checkbox value=Y> |.$locale->text('Bcc').qq|</td> +|; +  } + +  if ($form->{db} eq 'customer') { +    $employee = qq| +		<td><input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Salesperson').qq|</td> +|; + +    $pricegroup = qq| +		<td><input name="l_pricegroup" type=checkbox class=checkbox value=Y> |.$locale->text('Pricegroup').qq|</td> +|; + +  } else { +    $employee = qq| +		<td><input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Employee').qq|</td> +|; +  } + +  $employee .= qq| +                <td><input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager').qq|</td> +|; +     +  $include = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> +	  <td> +	    <table> +	      <tr> +	        <td><input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID').qq|</td> +		<td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |.$locale->text($label . ' Number').qq|</td> +		<td><input name="l_name" type=checkbox class=checkbox value=Y $form->{l_name}> |.$locale->text('Company Name').qq|</td> +		<td><input name="l_contact" type=checkbox class=checkbox value=Y $form->{l_contact}> |.$locale->text('Contact').qq|</td> +		<td><input name="l_email" type=checkbox class=checkbox value=Y $form->{l_email}> |.$locale->text('E-mail').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|</td> +		<td><input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City').qq|</td> +		<td><input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province').qq|</td> +		<td><input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code').qq|</td> +		<td><input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_phone" type=checkbox class=checkbox value=Y $form->{l_phone}> |.$locale->text('Phone').qq|</td> +		<td><input name="l_fax" type=checkbox class=checkbox value=Y> |.$locale->text('Fax').qq|</td> +		<td><input name="l_cc" type=checkbox class=checkbox value=Y> |.$locale->text('Cc').qq|</td> +		$bcc +		<td><input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes').qq|</td> +		<td><input name="l_discount" type=checkbox class=checkbox value=Y> |.$locale->text('Discount').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |.$locale->text('Tax Number').qq|</td> +		$gifi +		<td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |.$locale->text('SIC').qq|</td> +		<td><input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN').qq|</td> +		<td><input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC').qq|</td> +	      </tr> +	      <tr> +		$employee +		<td><input name="l_business" type=checkbox class=checkbox value=Y> |.$locale->text('Type of Business').qq|</td> +		$pricegroup +		<td><input name="l_language" type=checkbox class=checkbox value=Y> |.$locale->text('Language').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_startdate" type=checkbox class=checkbox value=Y> |.$locale->text('Startdate').qq|</td> +		<td><input name="l_enddate" type=checkbox class=checkbox value=Y> |.$locale->text('Enddate').qq|</td> +	      </tr> +	    </table> +	  </td> +	</tr> +|; + +} + +  sub search { +# $locale->text('Customers') +# $locale->text('Vendors') + +  $form->{title} = $locale->text('Search') unless $form->{title}; +   +  map { $form->{"l_$_"} = 'checked' } qw(name contact phone email); + +  $form->{nextsub} = "list_names"; + +  $orphan = qq| +	<tr> +	  <td></td> +	  <td><input name=status class=radio type=radio value=all checked> |.$locale->text('All').qq| +	  <input name=status class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq|</td> +	</tr> +|; + +  if ($form->{db} eq 'vendor') { +    $gifi = qq| +		<td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |.$locale->text('GIFI').qq|</td> +|; +  } +  +  &transactions; +  &include_in_report; +  &search_name; + +} + + +sub search_name { +    $label = ucfirst $form->{db}; -  $form->{title} = $locale->text($label."s"); +      $form->header; @@ -73,52 +378,65 @@ sub search {      <td>        <table>  	<tr> -	  <th align=right nowrap>|.$locale->text('Number').qq|</th> -	  <td><input name=$form->{db}number size=35></td> +	  <th align=right nowrap>|.$locale->text($label . ' Number').qq|</th> +	  <td><input name=$form->{db}number size=32></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Name').qq|</th> -	  <td><input name=name size=35></td> +	  <th align=right nowrap>|.$locale->text('Company Name').qq|</th> +	  <td><input name=name size=64></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Contact').qq|</th> -	  <td><input name=contact size=35></td> +	  <th align=right nowrap>|.$locale->text('Address').qq|</th> +	  <td><input name=address size=64></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('E-mail').qq|</th> -	  <td><input name=email size=35></td> +	  <th align=right nowrap>|.$locale->text('City').qq|</th> +	  <td><input name=city size=32></td>  	</tr>  	<tr> -	  <td></td> -	  <td><input name=status class=radio type=radio value=all checked> |.$locale->text('All').qq| -	  <input name=status class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq|</td> +	  <th align=right nowrap>|.$locale->text('State/Province').qq|</th> +	  <td><input name=state size=32></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> -	  <td> -	  <input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |.$locale->text('Number').qq| -	  <input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Name').qq| -	  <input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|<br> -	  <input name="l_contact" type=checkbox class=checkbox value=Y checked> |.$locale->text('Contact').qq| -	  <input name="l_phone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Phone').qq| -	  <input name="l_fax" type=checkbox class=checkbox value=Y> |.$locale->text('Fax').qq| -	  <input name="l_email" type=checkbox class=checkbox value=Y checked> |.$locale->text('E-mail').qq| -	  <input name="l_cc" type=checkbox class=checkbox value=Y> |.$locale->text('Cc').qq| -	  </td> +	  <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> +	  <td><input name=zipcode size=10></td>  	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Country').qq|</th> +	  <td><input name=country size=32></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Contact').qq|</th> +	  <td><input name=contact size=64></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('E-mail').qq|</th> +	  <td><input name=email size=32></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> +	  <td><input name=notes size=64></td> +	</tr> + +        $invnumber +	$orphan +	$transactions +	$include +        </table>      </td>    </tr> +    <tr>      <td><hr size=3 noshade></td>    </tr>  </table> -<input type=hidden name=nextsub value=list_names> +<input type=hidden name=nextsub value=$form->{nextsub}>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> @@ -131,13 +449,44 @@ sub search {  sub list_names { -   +    CT->search(\%myconfig, \%$form); -  $callback = "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}"; -  $href = $callback; +  $href = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}"; +   +  $form->sort_order(); +   +  $callback = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}"; -  @columns = $form->sort_columns(name, "$form->{db}number", address, contact, phone, fax, email, cc); +  @columns = $form->sort_columns(id, name, "$form->{db}number", address, +                                 city, state, zipcode, country, contact, +				 phone, fax, email, cc, bcc, employee, +				 manager, notes, discount, +				 taxnumber, gifi_accno, sic_code, business, +				 pricegroup, language, iban, bic, +				 startdate, enddate, +				 invnumber, invamount, invtax, invtotal, +				 ordnumber, ordamount, ordtax, ordtotal, +				 quonumber, quoamount, quotax, quototal); + +  foreach $item (qw(inv ord quo)) { +    if ($form->{"l_${item}number"}) { +      map { $form->{"l_$item$_"} = $form->{"l_$_"} } qw(amount tax total); +      $removeemployee = 1; +      $openclosed = 1; +    } +  } +  $form->{open} = $form->{closed} = "" if !$openclosed; + +  if ($form->{l_transnumber}) { +    map { $form->{"l_inv$_"} = $form->{"l_$_"} } qw(amount tax total); +    $removeemployee = 1; +  } + +  if ($removeemployee) { +    @columns = grep !/(employee|manager)/, @columns; +  } +    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") { @@ -149,6 +498,14 @@ sub list_names {      }    } +  foreach $item (qw(amount tax total transnumber)) { +    if ($form->{"l_$item"} eq "Y") {  +      $callback .= "&l_$item=Y";  +      $href .= "&l_$item=Y";  +    } +  } + +    if ($form->{status} eq 'all') {      $option = $locale->text('All');    } @@ -156,40 +513,153 @@ sub list_names {      $option .= $locale->text('Orphaned');    }    if ($form->{name}) { -    $callback .= "&name=$form->{name}"; +    $callback .= "&name=".$form->escape($form->{name},1);      $href .= "&name=".$form->escape($form->{name});      $option .= "\n<br>".$locale->text('Name')." : $form->{name}";    } +  if ($form->{address}) { +    $callback .= "&address=".$form->escape($form->{address},1); +    $href .= "&address=".$form->escape($form->{address}); +    $option .= "\n<br>".$locale->text('Address')." : $form->{address}"; +  } +  if ($form->{city}) { +    $callback .= "&city=".$form->escape($form->{city},1); +    $href .= "&city=".$form->escape($form->{city}); +    $option .= "\n<br>".$locale->text('City')." : $form->{city}"; +  } +  if ($form->{state}) { +    $callback .= "&state=".$form->escape($form->{state},1); +    $href .= "&state=".$form->escape($form->{state}); +    $option .= "\n<br>".$locale->text('State')." : $form->{state}"; +  } +  if ($form->{zipcode}) { +    $callback .= "&zipcode=".$form->escape($form->{zipcode},1); +    $href .= "&zipcode=".$form->escape($form->{zipcode}); +    $option .= "\n<br>".$locale->text('Zip/Postal Code')." : $form->{zipcode}"; +  } +  if ($form->{country}) { +    $callback .= "&country=".$form->escape($form->{country},1); +    $href .= "&country=".$form->escape($form->{country}); +    $option .= "\n<br>".$locale->text('Country')." : $form->{country}"; +  }    if ($form->{contact}) { -    $callback .= "&contact=$form->{contact}"; +    $callback .= "&contact=".$form->escape($form->{contact},1);      $href .= "&contact=".$form->escape($form->{contact});      $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";    } +  if ($form->{notes}) { +    $callback .= "¬es=".$form->escape($form->{notes},1); +    $href .= "¬es=".$form->escape($form->{notes}); +    $option .= "\n<br>".$locale->text('Notes')." : $form->{notes}"; +  }    if ($form->{"$form->{db}number"}) { -    $callback .= qq|&$form->{db}number=$form->{"$form->{db}number"}|; +    $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1);      $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});      $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;    }    if ($form->{email}) { -    $callback .= "&email=$form->{email}"; +    $callback .= "&email=".$form->escape($form->{email},1);      $href .= "&email=".$form->escape($form->{email});      $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";    } +  if ($form->{transdatefrom}) { +    $callback .= "&transdatefrom=$form->{transdatefrom}"; +    $href .= "&transdatefrom=$form->{transdatefrom}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); +  } +  if ($form->{transdateto}) { +    $callback .= "&transdateto=$form->{transdateto}"; +    $href .= "&transdateto=$form->{transdateto}"; +    if ($form->{transdatefrom}) { +      $option .= " "; +    } else { +      $option .= "\n<br>" if ($option); +    } +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +  } +  if ($form->{open}) { +    $callback .= "&open=$form->{open}"; +    $href .= "&open=$form->{open}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Open'); +  } +  if ($form->{closed}) { +    $callback .= "&closed=$form->{closed}"; +    $href .= "&closed=$form->{closed}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Closed'); +  } +      $form->{callback} = "$callback&sort=$form->{sort}";    $callback = $form->escape($form->{callback}); +  $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;    $column_header{"$form->{db}number"} = qq|<th><a class=listheading href=$href&sort=$form->{db}number>|.$locale->text('Number').qq|</a></th>|;    $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|; -  $column_header{address} = qq|<th><a class=listheading href=$href&sort=address>|.$locale->text('Address').qq|</a></th>|; +  $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|; +  $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|; +  $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|; +  $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|; +  $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;    $column_header{contact} = qq|<th><a class=listheading href=$href&sort=contact>|.$locale->text('Contact').qq|</a></th>|;    $column_header{phone} = qq|<th><a class=listheading href=$href&sort=phone>|.$locale->text('Phone').qq|</a></th>|;    $column_header{fax} = qq|<th><a class=listheading href=$href&sort=fax>|.$locale->text('Fax').qq|</a></th>|;    $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;    $column_header{cc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Cc').qq|</a></th>|; +  $column_header{bcc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Bcc').qq|</a></th>|; +  $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|; +  $column_header{discount} = qq|<th class=listheading>%</th>|; -  $label = ucfirst $form->{db}."s"; -  $form->{title} = $locale->text($label); +  $column_header{taxnumber} = qq|<th><a class=listheading href=$href&sort=taxnumber>|.$locale->text('Tax Number').qq|</a></th>|; +  $column_header{gifi_accno} = qq|<th><a class=listheading href=$href&sort=gifi_accno>|.$locale->text('GIFI').qq|</a></th>|; +  $column_header{sic_code} = qq|<th><a class=listheading href=$href&sort=sic_code>|.$locale->text('SIC').qq|</a></th>|; +  $column_header{business} = qq|<th><a class=listheading href=$href&sort=business>|.$locale->text('Type of Business').qq|</a></th>|; +  $column_header{iban} = qq|<th class=listheading>|.$locale->text('IBAN').qq|</th>|; +  $column_header{bic} = qq|<th class=listheading>|.$locale->text('BIC').qq|</th>|; +  $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|; +  $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|; +   +  $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|; +  $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|; +  $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|; + +  if ($form->{db} eq 'customer') { +    $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Salesperson').qq|</a></th>|; +  } else { +    $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|; +  } +  $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|; + +  $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup>|.$locale->text('Pricegroup').qq|</a></th>|; +  $column_header{language} = qq|<th><a class=listheading href=$href&sort=language>|.$locale->text('Language').qq|</a></th>|; +   + +  $amount = $locale->text('Amount'); +  $tax = $locale->text('Tax'); +  $total = $locale->text('Total'); +   +  $column_header{invamount} = qq|<th class=listheading>$amount</th>|; +  $column_header{ordamount} = qq|<th class=listheading>$amount</th>|; +  $column_header{quoamount} = qq|<th class=listheading>$amount</th>|; +   +  $column_header{invtax} = qq|<th class=listheading>$tax</th>|; +  $column_header{ordtax} = qq|<th class=listheading>$tax</th>|; +  $column_header{quotax} = qq|<th class=listheading>$tax</th>|; +   +  $column_header{invtotal} = qq|<th class=listheading>$total</th>|; +  $column_header{ordtotal} = qq|<th class=listheading>$total</th>|; +  $column_header{quototal} = qq|<th class=listheading>$total</th>|; +  + +  if ($form->{status}) { +    $label = ucfirst $form->{db}."s"; +    $form->{title} = $locale->text($label); +  } else { +    $label = ucfirst $form->{db}; +    $form->{title} = $locale->text($label ." Transactions"); +  }    $form->header; @@ -211,20 +681,97 @@ sub list_names {  |;    map { print "$column_header{$_}\n" } @column_index; -   +    print qq|          </tr>  |; +  $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order'; +  $quotationtype = ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation'; +  $subtotal = 0; +    foreach $ref (@{ $form->{CT} }) { -    map { $column_data{$_} = "<td>$ref->{$_} </td>" } ("$form->{db}number", address, contact, phone, fax); -     -    $column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}&callback=$callback>$ref->{name} </td>"; +    if ("$ref->{$form->{sort}}$ref->{id}" ne $sameitem && $form->{l_subtotal}) { +      # print subtotal +      if ($subtotal) { +	map { $column_data{$_} = "<td> </td>" } @column_index; +	&list_subtotal; +      } +    } + +    if ("$ref->{$form->{sort}}$ref->{id}" eq $sameitem && $form->{sort} eq 'name') { +      map { $column_data{$_} = "<td> </td>" } @column_index; +    } else { +       +      map { $column_data{$_} = "<td>$ref->{$_} </td>" } @column_index; +      $column_data{$form->{sort}} = "<td> </td>" if $ref->{$form->{sort}} eq $sameitem && $form->{l_subtotal}; +       +      $column_data{address} = "<td>$ref->{address1} $ref->{address2} </td>"; +      $column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name} </td>"; + +      $email = ""; +      if ($form->{sort} =~ /(email|cc)/) { +	if ("$ref->{$form->{sort}}$ref->{id}" ne $sameitem) { +	  $email = 1; +	} +      } else { +	$email = 1; +      } +       +      if ($email) { +      foreach $item (qw(email cc bcc)) { +	if ($ref->{$item}) { +	  $email = $ref->{$item}; +	  $email =~ s/</\</; +	  $email =~ s/>/\>/; +	   +	  $column_data{$item} = qq|<td><a href="mailto:$ref->{$item}">$email</a></td>|; +	} +      } +      } +    } -    $column_data{email} = ($ref->{email}) ? qq|<td><a href="mailto:$ref->{email}">$ref->{email}</a></td>| : "<td> </td>"; -    $column_data{cc} = ($ref->{cc}) ? qq|<td><a href="mailto:$ref->{cc}">$ref->{cc}</a></td>| : "<td> </td>"; +    if ($ref->{formtype} eq 'invoice') { +      $column_data{invnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber} </td>"; +       +      $column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, " ")."</td>"; +      $column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, " ")."</td>"; +      $column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, " ")."</td>"; + +      $invamountsubtotal += $ref->{netamount}; +      $invtaxsubtotal += ($ref->{amount} - $ref->{netamount}); +      $invtotalsubtotal += $ref->{amount}; +    } +      +    if ($ref->{formtype} eq 'order') { +      $column_data{ordnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber} </td>"; +       +      $column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, " ")."</td>"; +      $column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, " ")."</td>"; +      $column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, " ")."</td>"; + +      $ordamountsubtotal += $ref->{netamount}; +      $ordtaxsubtotal += ($ref->{amount} - $ref->{netamount}); +      $ordtotalsubtotal += $ref->{amount}; +    } + +    if ($ref->{formtype} eq 'quotation') { +      $column_data{quonumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber} </td>"; +       +      $column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, " ")."</td>"; +      $column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, " ")."</td>"; +      $column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, " ")."</td>"; + +      $quoamountsubtotal += $ref->{netamount}; +      $quotaxsubtotal += ($ref->{amount} - $ref->{netamount}); +      $quototalsubtotal += $ref->{amount}; +    } +    if ($form->{l_discount}) { +      $column_data{discount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{discount} * 100, "", " ")."</td>"; +    } +         $i++; $i %= 2;      print "          <tr class=listrow$i> @@ -236,8 +783,34 @@ sub list_names {          </tr>  |; +    $sameitem = "$ref->{$form->{sort}}$ref->{id}"; +    $subtotal = 1; +    } +  if ($form->{l_subtotal}) { +    map { $column_data{$_} = "<td> </td>" } @column_index; +    &list_subtotal; +  } +   +  $i = 1; +  if ($myconfig{acs} !~ /AR--AR/) { +    if ($form->{db} eq 'customer') { +      $button{'AR--Customers-Add Customer'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Customer').qq|"> |; +      $button{'AR--Customers--Add Customer'}{order} = $i++; +    } +  } +  if ($myconfig{acs} !~ /AP--AP/) { +    if ($form->{db} eq 'vendor') { +      $button{'AP--Vendors--Add Vendor'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Vendor').qq|"> |; +      $button{'AP--Vendors--Add Vendor'}{order} = $i++; +    } +  } +   +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +      print qq|        </table>      </td> @@ -255,11 +828,320 @@ sub list_names {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; -<input class=submit type=submit name=action value="|.$locale->text('Add').qq|"> +  if ($form->{status}) { +    foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +      print $item->{code}; +    } +  } -</form> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; +  +} + + +sub list_subtotal { + +	$column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $invamountsubtotal, 2, " ")."</td>"; +	$column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $invtaxsubtotal, 2, " ")."</td>"; +	$column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $invtotalsubtotal, 2, " ")."</td>"; + +	$invamountsubtotal = 0; +	$invtaxsubtotal = 0; +	$invtotalsubtotal = 0; + +	$column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ordamountsubtotal, 2, " ")."</td>"; +	$column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ordtaxsubtotal, 2, " ")."</td>"; +	$column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ordtotalsubtotal, 2, " ")."</td>"; + +	$ordamountsubtotal = 0; +	$ordtaxsubtotal = 0; +	$ordtotalsubtotal = 0; + +	$column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $quoamountsubtotal, 2, " ")."</td>"; +	$column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $quotaxsubtotal, 2, " ")."</td>"; +	$column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $quototalsubtotal, 2, " ")."</td>"; + +	$quoamountsubtotal = 0; +	$quotaxsubtotal = 0; +	$quototalsubtotal = 0; +	 +	print " +        <tr class=listsubtotal> +"; +	map { print "$column_data{$_}\n" } @column_index; + +	print qq| +        </tr> +|; +  + +} + + +sub list_history { +   +  CT->get_history(\%myconfig, \%$form); +   +  $href = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}"; + +  $form->sort_order(); +   +  $callback = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}"; +   +  $form->{l_fxsellprice} = $form->{l_curr}; +  @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, fxsellprice, curr, discount, deliverydate, projectnumber, serialnumber); + +  if ($form->{history} eq 'summary') { +    @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, curr); +  } + +  foreach $item (@columns) { +    if ($form->{"l_$item"} eq "Y") { +      push @column_index, $item; + +      # add column to href and callback +      $callback .= "&l_$item=Y"; +      $href .= "&l_$item=Y"; +    } +  } +   +  if ($form->{history} eq 'detail') { +    $option = $locale->text('Detail'); +  } +  if ($form->{history} eq 'summary') { +    $option .= $locale->text('Summary'); +  } +  if ($form->{name}) { +    $callback .= "&name=".$form->escape($form->{name},1); +    $href .= "&name=".$form->escape($form->{name}); +    $option .= "\n<br>".$locale->text('Name')." : $form->{name}"; +  } +  if ($form->{contact}) { +    $callback .= "&contact=".$form->escape($form->{contact},1); +    $href .= "&contact=".$form->escape($form->{contact}); +    $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}"; +  } +  if ($form->{"$form->{db}number"}) { +    $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1); +    $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"}); +    $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|; +  } +  if ($form->{email}) { +    $callback .= "&email=".$form->escape($form->{email},1); +    $href .= "&email=".$form->escape($form->{email}); +    $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}"; +  } +  if ($form->{transdatefrom}) { +    $callback .= "&transdatefrom=$form->{transdatefrom}"; +    $href .= "&transdatefrom=$form->{transdatefrom}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); +  } +  if ($form->{transdateto}) { +    $callback .= "&transdateto=$form->{transdateto}"; +    $href .= "&transdateto=$form->{transdateto}"; +    if ($form->{transdatefrom}) { +      $option .= " "; +    } else { +      $option .= "\n<br>" if ($option); +    } +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +  } +  if ($form->{open}) { +    $callback .= "&open=$form->{open}"; +    $href .= "&open=$form->{open}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Open'); +  } +  if ($form->{closed}) { +    $callback .= "&closed=$form->{closed}"; +    $href .= "&closed=$form->{closed}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Closed'); +  } + + +  $form->{callback} = "$callback&sort=$form->{sort}"; +  $callback = $form->escape($form->{callback}); + +  $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|; +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; + +  if ($form->{history} eq 'summary') { +    $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|; +  } else { +    $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|; +  } +  $column_header{fxsellprice} = qq|<th> </th>|; +   +  $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|; +  $column_header{discount} = qq|<th class=listheading>|.$locale->text('Discount').qq|</th>|; +  $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|; +  $column_header{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|; +  $column_header{deliverydate} = qq|<th><a class=listheading href=$href&sort=deliverydate>|.$locale->text('Delivery Date').qq|</a></th>|; +  $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Project Number').qq|</a></th>|; +  $column_header{serialnumber} = qq|<th><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|; +   + +# $locale->text('Customer History') +# $locale->text('Vendor History') + +  $label = ucfirst $form->{db}; +  $form->{title} = $locale->text($label." History"); + +  $colspan = $#column_index + 1; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; + +  print qq| +        </tr> +|; + + +  $module = 'oe'; +  if ($form->{db} eq 'customer') { +    $invlabel = $locale->text('Sales Invoice'); +    $ordlabel = $locale->text('Sales Order'); +    $quolabel = $locale->text('Quotation'); +     +    $ordertype = 'sales_order'; +    $quotationtype = 'sales_quotation'; +    if ($form->{type} eq 'invoice') { +      $module = 'is'; +    } +  } else { +    $invlabel = $locale->text('Vendor Invoice'); +    $ordlabel = $locale->text('Purchase Order'); +    $quolabel = $locale->text('RFQ'); +     +    $ordertype = 'purchase_order'; +    $quotationtype = 'request_quotation'; +    if ($form->{type} eq 'invoice') { +      $module = 'ir'; +    } +  } +     +   +  foreach $ref (@{ $form->{CT} }) { + +    if ($ref->{id} ne $sameid) { +      # print the header +      print qq| +        <tr class=listheading> +	  <th colspan=$colspan><a class=listheading href=$form->{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{name} $ref->{address}</a></th> +	</tr> +|; +    } + +    if ($form->{type} ne 'invoice') { +      $ref->{fxsellprice} = $ref->{sellprice}; +      $ref->{sellprice} *= $ref->{exchangerate}; +    } +	 +    if ($form->{history} eq 'detail' and $ref->{invid} ne $sameinvid) { +      # print inv, ord, quo number +      $i++; $i %= 2; +       +      print qq| +	  <tr class=listrow$i> +|; + +      if ($form->{type} eq 'invoice') { +	print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}</a></th>|; +      } +        +      if ($form->{type} eq 'order') { +	print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}</a></th>|; +      } + +      if ($form->{type} eq 'quotation') { +	print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}</a></th>|; +      } + +      print qq| +          </tr> +|; +    } + +    map { $column_data{$_} = "<td>$ref->{$_} </td>" } @column_index; + +    if ($form->{l_curr}) { +      $column_data{fxsellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{fxsellprice}, 2)."</td>"; +    } +    $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2)."</td>"; +       +    $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty})."</td>"; +    $column_data{discount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{discount} * 100, "", " ")."</td>"; +    $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|; +     +    +    $i++; $i %= 2; +    print qq| +        <tr class=listrow$i> +|; + +    map { print "$column_data{$_}\n" } @column_index; + +    print qq| +        </tr> +|; +     +    $sameid = $ref->{id}; +    $sameinvid = $ref->{invid}; + +  } + +  +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form>  </body>  </html> @@ -268,15 +1150,15 @@ sub list_names {  } +  sub edit {  # $locale->text('Edit Customer')  # $locale->text('Edit Vendor') -  CT->get_tuple(\%myconfig, \%$form); +  CT->create_links(\%myconfig, \%$form); -  # format " into " -  map { $form->{$_} =~ s/"/"/g } keys %$form; +  map { $form->{$_} = $form->quote($form->{$_}) } keys %$form;    $form->{title} = "Edit"; @@ -291,53 +1173,139 @@ sub edit {  sub form_header { +  $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; +  $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0); +   +  if ($myconfig{role} =~ /(admin|manager)/) { +    $bcc = qq| +        <tr> +	  <th align=right nowrap>|.$locale->text('Bcc').qq|</th> +	  <td><input name=bcc size=35 value="$form->{bcc}"></td> +	</tr> +|; +  } +   +  # currencies +  map { $form->{selectcurrency} .= "<option>$_\n" } split /:/, $form->{currencies}; +  $form->{selectcurrency} =~ s/option>($form->{curr})/option selected>$1/; +      foreach $item (split / /, $form->{taxaccounts}) { -    if (($form->{tax}{$item}{taxable}) || !($form->{id})) { +    if ($form->{tax}{$item}{taxable}) {        $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked> <b>$form->{tax}{$item}{description}</b>|;      } else {        $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox> <b>$form->{tax}{$item}{description}</b>|;      }    } -  $tax = qq| -  <tr> -    <td> -      <table> -        <tr> +  if ($taxable) { +    $tax = qq| +	<tr>  	  <th align=right>|.$locale->text('Taxable').qq|</th> -	  <td>$taxable</td> +	  <td colspan=5> +	    <table> +	      <tr> +		<td>$taxable</td> +		<td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td> +		<th align=left>|.$locale->text('Tax Included').qq|</th> +	      </tr> +	    </table> +	  </td>  	</tr> -      </table> -    </td> -  </tr>  |; +  } -  $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; -  $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0); +  $typeofbusiness = qq| +          <th></th> +	  <td></td> +|; + +  if (@{ $form->{all_business} }) { +    $form->{selectbusiness} = qq|<option>\n|; +    map { $form->{selectbusiness} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_business} }; + +    $form->{selectbusiness} =~ s/(<option value="\Q$form->{business}--$form->{business_id}\E")>/$1 selected>/; + +    $typeofbusiness = qq| + 	  <th align=right>|.$locale->text('Type of Business').qq|</th> +	  <td><select name=business>$form->{selectbusiness}</select></td> +|; + + +  } + +  $pricegroup = qq| +          <th></th> +	  <td></td> +|; + +  if (@{ $form->{all_pricegroup} } && $form->{db} eq 'customer') { +    $form->{selectpricegroup} = qq|<option>\n|; +    map { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| } @{ $form->{all_pricegroup} }; +     +    $form->{selectpricegroup} =~ s/(<option value="\Q$form->{pricegroup}--$form->{pricegroup_id}\E")/$1 selected/; + +    $pricegroup = qq| + 	  <th align=right>|.$locale->text('Pricegroup').qq|</th> +	  <td><select name=pricegroup>$form->{selectpricegroup}</select></td> +|; +  } -  if ($myconfig{admin}) { -    $bcc = qq| -        <tr> -	  <th align=right nowrap>|.$locale->text('Bcc').qq|</th> -	  <td><input name=bcc size=35 value="$form->{bcc}"></td> -	</tr> +  $lang = qq| +          <th></th> +	  <td></td> +|; + +  if (@{ $form->{all_language} }) { +    $form->{selectlanguage} = qq|<option>\n|; +    map { $form->{selectlanguage} .= qq|<option value="$_->{description}--$_->{code}">$_->{description}\n| } @{ $form->{all_language} }; +     +    $form->{selectlanguage} =~ s/(<option value="\Q$form->{language}--$form->{language_code}\E")/$1 selected/; + +    $lang = qq| + 	  <th align=right>|.$locale->text('Language').qq|</th> +	  <td><select name=language>$form->{selectlanguage}</select></td>  |;    } + +  +  $employeelabel = $locale->text('Salesperson'); +  $form->{selectemployee} = qq|<option>\n|; +  map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_employee} }; -  $label = ucfirst $form->{db}; -  $form->{title} = $locale->text("$form->{title} $label"); +  $form->{selectemployee} =~ s/(<option value="\Q$form->{employee}--$form->{employee_id}\E")/$1 selected/; +   +  if ($form->{db} eq 'vendor') { +    $gifi = qq| +    	  <th align=right>|.$locale->text('Sub-contract GIFI').qq|</th> +	  <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td> +|; +    $employeelabel = $locale->text('Employee'); +  } -  if ($form->{db} eq 'customer') { -    $creditlimit = qq| -	  <th align=right>|.$locale->text('Credit Limit').qq|</th> -	  <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td> -	  <th align=right>|.$locale->text('Discount').qq|</th> -	  <td><input name=discount size=4 value="$form->{discount}"></td> -	  <th>%</th> + +  if (@{ $form->{all_employee} }) { +    $employee = qq| +	        <th align=right>$employeelabel</th>|; +		 +    if ($myconfig{role} ne 'user' || !$form->{id}) { +      $employee .= qq| +		<td><select name=employee>$form->{selectemployee}</select></td>  |; +    } else { +      $employee .= qq| +                <td>$form->{employee}</td> +		<input type=hidden name=employee value="$form->{employee}--$form->{employee_id}">|; +    }    } + +# $locale->text('Customer Number') +# $locale->text('Vendor Number') + +  $label = ucfirst $form->{db}; +  $form->{title} = $locale->text("$form->{title} $label"); +     $form->header;    print qq| @@ -349,92 +1317,170 @@ sub form_header {    <tr>      <th class=listtop>$form->{title}</th>    </tr> +  <tr height="5"></tr>    <tr>      <td>        <table width=100%> -	<tr class=listheading> -	  <th class=listheading colspan=2 width=50%"> </th> -	  <th class=listheading width=50%">|.$locale->text('Ship to').qq|</th> -	</tr> -	<tr height="5"></tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Number').qq|</th> -	  <td><input name="$form->{db}number" size=35 maxsize=35 value="$form->{"$form->{db}number"}"></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Name').qq|</th> -	  <td><input name=name size=35 maxsize=35 value="$form->{name}"></td> -	  <td><input name=shiptoname size=35 maxsize=35 value="$form->{shiptoname}"></td> -	</tr> -	<tr> -	  <th align=right nowrap>|.$locale->text('Address').qq|</th> -	  <td><input name=addr1 size=35 maxsize=35 value="$form->{addr1}"></td> -	  <td><input name=shiptoaddr1 size=35 maxsize=35 value="$form->{shiptoaddr1}"></td> -	</tr> -	<tr> -	  <th></th> -	  <td><input name=addr2 size=35 maxsize=35 value="$form->{addr2}"></td> -	  <td><input name=shiptoaddr2 size=35 maxsize=35 value="$form->{shiptoaddr2}"></td> -	</tr> -	<tr> -	  <th></th> -	  <td><input name=addr3 size=35 maxsize=35 value="$form->{addr3}"></td> -	  <td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td> -	</tr> -	<tr> -	  <th></th> -	  <td><input name=addr4 size=35 maxsize=35 value="$form->{addr4}"></td> -	  <td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></td> +        <tr valign=top> +	  <td width=50%> +	    <table width=100%> +	      <tr class=listheading> +		<th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th> +	      <tr> +		<th align=right nowrap>|.$locale->text($label .' Number').qq|</th> +		<td><input name="$form->{db}number" size=35 maxlength=32 value="$form->{"$form->{db}number"}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Company Name').qq|</th> +		<td><input name=name size=35 maxlength=64 value="$form->{name}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Address').qq|</th> +		<td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td> +	      </tr> +	      <tr> +		<th></th> +		<td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('City').qq|</th> +		<td><input name=city size=35 maxlength=32 value="$form->{city}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('State/Province').qq|</th> +		<td><input name=state size=35 maxlength=32 value="$form->{state}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> +		<td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Country').qq|</th> +		<td><input name=country size=35 maxlength=32 value="$form->{country}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Contact').qq|</th> +		<td><input name=contact size=35 maxlength=64 value="$form->{contact}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Phone').qq|</th> +		<td><input name=phone size=20 maxlength=20 value="$form->{phone}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Fax').qq|</th> +		<td><input name=fax size=20 maxlength=20 value="$form->{fax}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('E-mail').qq|</th> +		<td><input name=email size=35 value="$form->{email}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Cc').qq|</th> +		<td><input name=cc size=35 value="$form->{cc}"></td> +	      </tr> +	      $bcc +	    </table> +	  </td> +	  <td width=50%> +	    <table width=100%> +	      <tr> +		<th class=listheading colspan=2>|.$locale->text('Shipping Address').qq|</th> +	      </tr> +	      <tr> +		<td><input name=none size=35 value=|. ("=" x 35) .qq|></td> +	      </tr> +	      <tr> +		<td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptophone size=20 maxlength=20 value="$form->{shiptophone}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptofax size=20 maxlength=20 value="$form->{shiptofax}"></td> +	      </tr> +	      <tr> +		<td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td> +	      </tr> +	    </table> +	  </td>  	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td> +      <table> +	$tax  	<tr> -	  <th align=right nowrap>|.$locale->text('Contact').qq|</th> -	  <td><input name=contact size=35 maxsize=35 value="$form->{contact}"></td> -	  <td><input name=shiptocontact size=35 maxsize=35 value="$form->{shiptocontact}"></td> +	  <th align=right>|.$locale->text('Startdate').qq|</th> +	  <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td> +	  <th align=right>|.$locale->text('Enddate').qq|</th> +	  <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Phone').qq|</th> -	  <td><input name=phone size=20 maxsize=20 value="$form->{phone}"></td> -	  <td><input name=shiptophone size=20 maxsize=20 value="$form->{shiptophone}"></td> +	  <th align=right>|.$locale->text('Credit Limit').qq|</th> +	  <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td> +	  <th align=right>|.$locale->text('Terms').qq|</th> +	  <td><input name=terms size=2 value="$form->{terms}"> <b>|.$locale->text('days').qq|</b></td> +	  <th align=right>|.$locale->text('Discount').qq|</th> +	  <td><input name=discount size=4 value="$form->{discount}"> +	  <b>%</b></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Fax').qq|</th> -	  <td><input name=fax size=20 maxsize=20 value="$form->{fax}"></td> -	  <td><input name=shiptofax size=20 maxsize=20 value="$form->{shiptofax}"></td> +	  <th align=right>|.$locale->text('Tax Number / SSN').qq|</th> +	  <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td> +	  $gifi +	  <th align=right>|.$locale->text('SIC').qq|</th> +	  <td><input name=sic size=6 maxlength=6 value="$form->{sic}"></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('E-mail').qq|</th> -	  <td><input name=email size=35 value="$form->{email}"></td> -	  <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td> +	  $typeofbusiness +	  <th align=right>|.$locale->text('BIC').qq|</th> +	  <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td> +	  <th align=right>|.$locale->text('IBAN').qq|</th> +	  <td><input name=iban size=24 maxlength=34 value="$form->{iban}"></td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Cc').qq|</th> -	  <td><input name=cc size=35 value="$form->{cc}"></td> +	  $pricegroup +	  $lang +	  <th>|.$locale->text('Currency').qq|</th> +	  <td><select name=curr>$form->{selectcurrency}</select></td>  	</tr> -        $bcc -      </table> -    </td> -  </tr> -  <tr> -    <td> -      <table width=100%> -	<tr> -	  <th align=right>|.$locale->text('Terms: Net').qq|</th> -	  <td><input name=terms size=2 value="$form->{terms}"></td> -	  <th>|.$locale->text('days').qq|</th> -	  $creditlimit -	  <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td> -	  <th align=left>|.$locale->text('Tax Included').qq|</th> +	<tr valign=top> +	  $employee +	  <td colspan=4> +	    <table> +	      <tr valign=top> +		<th align=left nowrap>|.$locale->text('Notes').qq|</th> +		<td><textarea name=notes rows=3 cols=40 wrap=soft>$form->{notes}</textarea></td> +	      </tr> +	    </table> +	  </td>  	</tr>        </table>      </td>    </tr> -  $tax -  <tr> -    <th align=left nowrap>|.$locale->text('Notes').qq|</th> -  </tr> -  <tr> -    <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td> -  </tr>    <tr>      <td><hr size=3 noshade></td>    </tr> @@ -447,28 +1493,86 @@ sub form_header {  sub form_footer { -  $label = ucfirst $form->{db}; +  $i = 1; +  if ($form->{db} eq 'customer') { +    if ($myconfig{acs} !~ /AR--AR/) { +      $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |; +      $button{'AR--Add Transaction'}{order} = $i++; +      $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> |; +      $button{'AR--Sales Invoice'}{order} = $i++; +    } +    if ($myconfig{acs} !~ /Order Entry--Order Entry/) { +      $button{'Order Entry--Sales Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|"> |; +      $button{'Order Entry--Sales Order'}{order} = $i++; +    } +    if ($myconfig{acs} !~ /Quotations--Quotations/) { +      $button{'Quotations--Quotation'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|"> |; +      $button{'Quotations--Quotation'}{order} = $i++; +    } +  } +  if ($form->{db} eq 'vendor') { +    if ($myconfig{acs} !~ /AP--AP/) { +      $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |; +      $button{'AP--Add Transaction'}{order} = $i++; +      $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> |; +      $button{'AP--Vendor Invoice'}{order} = $i++; +    } +    if ($myconfig{acs} !~ /Order Entry--Order Entry/) { +      $button{'Order Entry--Purchase Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|"> |; +      $button{'Order Entry--Purchase Order'}{order} = $i++; +    } +    if ($myconfig{acs} !~ /Quotations--Quotations/) { +      $button{'Quotations--RFQ'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('RFQ').qq|"> |; +      $button{'Quotations--RFQ'}{order} = $i++; +    } +  } +  if ($myconfig{acs} !~ /Goods & Services--Goods & Services/) { +    $myconfig{acs} =~ s/(Goods & Services--Add )(Service|Assembly).*;/$1--Add Part/g; +    $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Pricelist').qq|"> |; +    $button{'Goods & Services--Add Part'}{order} = $i++; +  } +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +     print qq|  <input name=id type=hidden value=$form->{id}>  <input name=taxaccounts type=hidden value="$form->{taxaccounts}">  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=callback value="$form->{callback}">  <input type=hidden name=db value=$form->{db}>  <br> +|; +  if ($form->{db} eq 'customer') { +    $item = 'AR--Customers--Add Customer'; +  }  +  if ($form->{db} eq 'vendor') { +    $item = 'AP--Vendors--Add Vendor'; +  }  +   +  if ($myconfig{acs} !~ /$item/) { +    print qq|  <input class=submit type=submit name=action value="|.$locale->text("Save").qq|"> -<input class=submit type=submit name=action value="|.$locale->text("Invoice").qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Order').qq|">  |; +    if ($form->{id} && $form->{status} eq 'orphaned') { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|; +    } +  } -  if ($form->{id} && $form->{status} eq 'orphaned') { -    print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|; +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } +   +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar;    }    print qq| @@ -482,150 +1586,742 @@ sub form_footer {  } -sub invoice { &{ "$form->{db}_invoice" } }; +sub pricelist { -sub customer_invoice { +  $form->isblank("name", $locale->text('Name missing!')); -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_customer(\%myconfig, \%$form); +  CT->pricelist(\%myconfig, \%$form); + +  foreach $ref (@{ $form->{"all_partspricelist"} }) { +    $i++; +    map { $form->{"${_}_$i"} = $ref->{$_} } keys %$ref; +  } +  $form->{rowcount} = $i; + +  # currencies +  @curr = split /:/, $form->{currencies}; +  map { $form->{selectcurrency} .= "<option>$_\n" } @curr; -  delete $form->{script}; +  if (@ { $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    foreach $ref (@ { $form->{all_partsgroup} }) { +      $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|; +    } +  } + +  map { delete $form->{$_} } ("currencies", "all_partsgroup", "all_partspricelist"); + +  foreach $i (1 .. $form->{rowcount}) { +     +    if ($form->{db} eq 'customer') { +       +      $form->{"pricebreak_$i"} = $form->format_amount(\%myconfig, $form->{"pricebreak_$i"}); + +      ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); +      $dec = length $dec; +      $decimalplaces = ($dec > 2) ? $dec : 2; +       +      $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); +       +    } +     +    if ($form->{db} eq 'vendor') { +       +      $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{"leadtime_$i"}); +      ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/); +      $dec = length $dec; +      $decimalplaces = ($dec > 2) ? $dec : 2; +       +      $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); +       +    } +  } + +  $form->{rowcount}++; +  &{ "$form->{db}_pricelist" }; + +} -  $form->{action} = "add"; -  $form->{callback} = $form->escape($form->{callback},1); -  $form->{customer} = $form->{name}; -  $form->{customer_id} = $form->{id}; -  $form->{vc} = 'customer'; +sub customer_pricelist { -  delete $form->{id}; +  @flds = qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto); -  map { $argv .= "$_=$form->{$_}&" } keys %$form; +  $form->{rowcount}--; -  exec ("perl", "is.pl", $argv); +  # remove empty rows +  if ($form->{rowcount}) { + +    foreach $i (1 .. $form->{rowcount}) { + +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(pricebreak sellprice); +       +      ($a, $b) = split /\./, $form->{"pricebreak_$i"}; +      $a = length $a; +      $b = length $b; +      $whole = ($whole > $a) ? $whole : $a; +      $dec = ($dec > $b) ? $dec : $b; +    } +    $pad1 = '0' x $whole; +    $pad2 = '0' x $dec; + +    foreach $i (1 .. $form->{rowcount}) { +      ($a, $b) = split /\./, $form->{"pricebreak_$i"}; +       +      $a = substr("$pad1$a", -$whole); +      $b = substr("$b$pad2", 0, $dec); +      $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i; +    } +     +    $i = 1; +    map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx; +       +    foreach $i (1 .. $form->{rowcount}) { +      if ($form->{"partnumber_$i"} && $form->{"sellprice_$i"}) { +	if ($form->{"id_$i"} eq $sameid) { +	  $j = $i + 1; +	  next if ($form->{"id_$j"} eq $sameid && !$form->{"pricebreak_$i"}); +	} +	 +	push @a, {}; +	$j = $#a; + +	map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +	$count++; +      } +      $sameid = $form->{"id_$i"}; +    } +    +    $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); +    $form->{rowcount} = $count; +  } + +  $form->{rowcount}++; + +  &pricelist_header; +  $form->hide_form(); +  &pricelist_footer; +    } -sub vendor_invoice { +sub vendor_pricelist { -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_vendor(\%myconfig, \%$form); +  @flds = qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime); + +  $form->{rowcount}--; -  delete $form->{script}; +  # remove empty rows +  if ($form->{rowcount}) { + +    foreach $i (1 .. $form->{rowcount}) { + +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(leadtime lastcost); +      $var = ($form->{"partnumber_$i"}) ? $form->{"sku_$i"} : qq|_$form->{"sku_$i"}|; +      $ndx{$var} = $i; +       +    } + +    $i = 1; +    map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx; +       +    foreach $i (1 .. $form->{rowcount}) { +      if ($form->{"sku_$i"}) { +	push @a, {}; +	$j = $#a; + +	map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +	$count++; +      } +    } +    +    $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); +    $form->{rowcount} = $count; + +  } + +  $form->{rowcount}++; + +  &pricelist_header; +  $form->hide_form(); +  &pricelist_footer; -  $form->{action} = "add"; -  $form->{callback} = $form->escape($form->{callback},1); +} -  $form->{vendor} = $form->{name}; -  $form->{vendor_id} = $form->{id}; -  $form->{vc} = 'vendor'; + + +sub pricelist_header { -  delete $form->{id}; +  $form->{title} = $form->{name}; +  +  $form->header; + +  print qq| +<body> + +<form method=post action="$form->{script}"> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +|; + +  if ($form->{db} eq 'customer') { +    @column_index = qw(partnumber description); +    push @column_index, "partsgroup" if $form->{selectpartsgroup}; +    push @column_index, qw(pricebreak sellprice curr validfrom validto); + +    $column_header{pricebreak} = qq|<th class=listheading nowrap>|.$locale->text('Break').qq|</th>|; +    $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|; +    $column_header{validfrom} = qq|<th class=listheading nowrap>|.$locale->text('From').qq|</th>|; +    $column_header{validto} = qq|<th class=listheading nowrap>|.$locale->text('To').qq|</th>|; +  } + +  if ($form->{db} eq 'vendor') { +    @column_index = qw(sku partnumber description); +    push @column_index, "partsgroup" if $form->{selectpartsgroup}; +    push @column_index, qw(lastcost curr leadtime); + + +    $column_header{sku} = qq|<th class=listheading nowrap>|.$locale->text('SKU').qq|</th>|; +    $column_header{leadtime} = qq|<th class=listheading nowrap>|.$locale->text('Leadtime').qq|</th>|; +    $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|; +  } + +  $column_header{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|; +  $column_header{description} = qq|<th class=listheading nowrap width=80%>|.$locale->text('Description').qq|</th>|; +  $column_header{partsgroup} = qq|<th class=listheading nowrap>|.$locale->text('Group').qq|</th>|; +  $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|; -  map { $argv .= "$_=$form->{$_}&" } keys %$form; +  print qq| +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "\n$column_header{$_}" } @column_index; -  exec ("perl", "ir.pl", $argv); +  print qq| +       </tr> +|; + +  $sameid = ""; +  foreach $i (1 .. $form->{rowcount}) { +     +    $selectcurrency = $form->{selectcurrency}; +    $selectcurrency =~ s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/; + +    if ($form->{selectpartsgroup}) { +      if ($i < $form->{rowcount}) { +	($partsgroup) = split /--/, $form->{"partsgroup_$i"}; +	$column_data{partsgroup} = qq|<td>$partsgroup</td> +	<input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|; +      } +    } + + +    if ($i < $form->{rowcount}) { +       +      if ($form->{"id_$i"} eq $sameid) { +	map { $column_data{$_} = qq|<td> </td> +	<input type=hidden name="${_}_$i" value="|.$form->quote($form->{"${_}_$i"}).qq|">| } qw(partnumber description partsgroup); +       +      } else { +	 +	$column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|; +	$column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|; + +	$column_data{description} = qq|<td>$form->{"description_$i"} </td> +	<input type=hidden name="description_$i" value="|.$form->quote($form->{"description_$i"}).qq|">|; +       +      } + +      $column_data{partnumber} .= qq| +        <input type=hidden name="id_$i" value="$form->{"id_$i"}">|; +  +    } else { +    +      if ($form->{db} eq 'customer') { +	$column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|; +      } else { +	$column_data{partnumber} = qq|<td> </td>|; +      } + +      $column_data{partnumber} .= qq| +        <input type=hidden name="id_$i" value="$form->{"id_$i"}">|; +       +      $column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|; +      $column_data{description} = qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|; +       +      if ($form->{selectpartsgroup}) { +	$column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectpartsgroup}</select></td>|; +      } +       +    } + + +    if ($form->{db} eq 'customer') { +      ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); +      $dec = length $dec; +      $decimalplaces = ($dec > 2) ? $dec : 2; +       +      $column_data{pricebreak} = qq|<td align=right><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>|; +      $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|; +       +      $column_data{validfrom} = qq|<td><input name="validfrom_$i" size=11 value=$form->{"validfrom_$i"}></td>|; +      $column_data{validto} = qq|<td><input name="validto_$i" size=11 value=$form->{"validto_$i"}></td>|; +    } +     +    if ($form->{db} eq 'vendor') { +      ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/); +      $dec = length $dec; +      $decimalplaces = ($dec > 2) ? $dec : 2; +       +      $column_data{leadtime} = qq|<td align=right><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|></td>|; +      $column_data{lastcost} = qq|<td align=right><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces).qq|></td>|; +    } +       + +    $column_data{curr} = qq|<td><select name="curr_$i">$selectcurrency</select></td>|; + +     +    print qq|<tr valign=top>|; +     +    map { print "\n$column_data{$_}" } @column_index; + +    print qq|</tr>|; + +    $sameid = $form->{"id_$i"}; + +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +  # delete variables +  foreach $i (1 .. $form->{rowcount}) { +    map { delete $form->{"${_}_$i"} } (@column_index, "id"); +  } +  map { delete $form->{$_} } qw(title titlebar script none header action);  } -sub order { &{ "$form->{db}_order" } }; +sub pricelist_footer { +   +  print qq| +    <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +    <input class=submit type=submit name=action value="|.$locale->text('Save Pricelist').qq|">|; +     +  print qq| +</form> -sub customer_order { +<a name="end"></a> +   +  </body> +  </html> +|;   -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_customer(\%myconfig, \%$form); +} + + +sub update { +   +  $i = $form->{rowcount}; +  $additem = 0; + +  if ($form->{db} eq 'customer') { +    $additem = 1 if ! (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")); +  } +  if ($form->{db} eq 'vendor') { +    if (! (($form->{"sku_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq ""))) { +      $additem = 1; +      $form->{"partnumber_$i"} = $form->{"sku_$i"}; +    } +  } + +  if ($additem) { + +    CT->retrieve_item(\%myconfig, \%$form); + +    $rows = scalar @{ $form->{item_list} }; + +    if ($rows > 0) { +       +      if ($rows > 1) { +	 +	&select_item; +	exit; +	 +      } else { +	 +	$sellprice = $form->{"sellprice_$i"}; +	$pricebreak = $form->{"pricebreak_$i"}; +	$lastcost = $form->{"lastcost_$i"}; +	 +	map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description); +	map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + +        if ($form->{db} eq 'customer') { +	   +	  if ($sellprice) { +	    $form->{"sellprice_$i"} = $sellprice; +	  } +	   +	  ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); +	  $dec = length $dec; +	  $decimalplaces = ($dec > 2) ? $dec : 2; +	       +	  $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); +	   +	  $form->{"pricebreak_$i"} = $pricebreak; +	   +	} else { + +          foreach $j (1 .. $form->{rowcount}) { +	    if ($form->{"sku_$j"} eq $form->{"partnumber_$i"}) { +	      $form->error($locale->text('Item already on pricelist!')); +	    } +	  } + +	  if ($lastcost) { +	    $form->{"lastcost_$i"} = $lastcost; +	  } +	    +	  ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/); +	  $dec = length $dec; +	  $decimalplaces = ($dec > 2) ? $dec : 2; +	       +	  $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); + +	  $form->{"sku_$i"} = $form->{"partnumber_$i"}; +	  delete $form->{"partnumber_$i"}; +	   +	} + +	$form->{rowcount}++; + +      } +	 +    } else { + +      $form->error($locale->text('Item not on file!')); +       +    } +  } + +  &{ "$form->{db}_pricelist" }; -  delete $form->{script}; +} + + + +sub select_item { + +  @column_index = qw(ndx partnumber description partsgroup unit sellprice lastcost); + +  $column_data{ndx} = qq|<th> </th>|; +  $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|; +  $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|; +  $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|; +  $column_data{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|; +  $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|; +  $column_data{lastcost} = qq|<th class=listheading>|.$locale->text('Cost').qq|</th>|; -  $form->{action} = "add"; -  $form->{callback} = $form->escape($form->{callback},1); +  $form->header; +   +  $title = $locale->text('Select from one of the items below'); +   +  print qq| +<body> + +<form method=post action="$form->{script}"> + +<table width=100%> +  <tr> +    <th class=listtop>$title</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading>|; + +  map { print "\n$column_data{$_}" } @column_index; + +  print qq| +        </tr> +|; + +  my $i = 0; +  foreach $ref (@{ $form->{item_list} }) { +    $checked = ($i++) ? "" : "checked"; + +    map { $ref->{$_} = $form->quote($ref->{$_}) } qw(partnumber description unit); +     +    $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; + +    map { $column_data{$_} = qq|<td>$ref->{$_} </td>| } qw(partnumber description partsgroup unit); + +    $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ").qq|</td>|; +    $column_data{lastcost} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{lastcost}, 2, " ").qq|</td>|; + +    $j++; $j %= 2; + +    print qq| +        <tr class=listrow$j>|; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +        </tr> + +<input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}"> +<input name="new_description_$i" type=hidden value="$ref->{description}"> +<input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}"> +<input name="new_partsgroup_id_$i" type=hidden value="$ref->{partsgroup_id}"> +<input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}> +<input name="new_lastcost_$i" type=hidden value=$ref->{lastcost}> +<input name="new_unit_$i" type=hidden value="$ref->{unit}"> + +<input name="new_id_$i" type=hidden value=$ref->{id}> + +|; + +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<input name=lastndx type=hidden value=$i> + +|; + +  # delete action variable +  map { delete $form->{$_} } qw(action item_list header); + +  $form->hide_form(); + +  print qq| +<input type=hidden name=nextsub value=item_selected> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; +} + + + +sub item_selected { + +  # replace the last row with the checked row +  $i = $form->{rowcount}; + +  # index for new item +  $j = $form->{ndx}; + +  @new = qw(id partnumber description unit); +  push @new, "sellprice" if ! $form->{"sellprice_$i"}; +  push @new, "lastcost" if ! $form->{"lastcost_$i"}; -  $form->{customer} = $form->{name}; -  $form->{customer_id} = $form->{id}; -  $form->{vc} = 'customer'; +  map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } @new; + +  $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|; -  $form->{type} = 'sales_order'; +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice lastcost); -  delete $form->{id}; +  push @new, qw(partsgroup partsgroup_id); -  map { $argv .= "$_=$form->{$_}&" } keys %$form; +  # delete all the new_ variables +  for $i (1 .. $form->{lastndx}) { +    map { delete $form->{"new_${_}_$i"} } @new; +  } -  exec ("perl", "oe.pl", $argv); +  map { delete $form->{$_} } qw(ndx lastndx nextsub); + +  # format amounts +  map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(sellprice lastcost); +   +  foreach $j (1 .. $form->{rowcount}) { +    if ($form->{"sku_$j"} eq $form->{"partnumber_$i"}) { +      $form->error($locale->text('Item already on pricelist!')); +    } +  } +   +  $form->{"sku_$i"} = $form->{"partnumber_$i"}; +  delete $form->{"partnumber_$i"} if $form->{db} eq 'vendor'; + +  $form->{rowcount}++; +  &{ "$form->{db}_pricelist" };  } -sub vendor_order { -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_vendor(\%myconfig, \%$form); +     +sub save_pricelist { +  +  &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form); + +  $rc = CT->save_pricelist(\%myconfig, \%$form); + +  $form->{callback} = "$form->{script}?action=edit&db=$form->{db}&id=$form->{id}&login=$form->{login}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $form->redirect if $rc; +  $form->error($locale->text('Could not save pricelist!')); + +} + + + +sub add_transaction { -  delete $form->{script}; +  $form->isblank("name", $locale->text("Name missing!")); + +  &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form); -  $form->{action} = "add";    $form->{callback} = $form->escape($form->{callback},1); +  $name = $form->escape($form->{name},1); + +  $form->{callback} = "$form->{script}?login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}"; + +  $form->redirect; -  $form->{vendor} = $form->{name}; -  $form->{vendor_id} = $form->{id}; -  $form->{vc} = 'vendor'; +} -  $form->{type} = 'purchase_order'; +sub ap_transaction { -  delete $form->{id}; +  $form->{script} = "ap.pl"; +  $form->{type} = "ap_transaction"; +  &add_transaction; + +} -  map { $argv .= "$_=$form->{$_}&" } keys %$form; -   -  exec ("perl", "oe.pl", $argv); + +sub ar_transaction { + +  $form->{script} = "ar.pl"; +  $form->{type} = "ar_transaction"; +  &add_transaction;  } -sub save { &{ "save_$form->{db}" } }; +sub sales_invoice { -sub save_customer { +  $form->{script} = "is.pl"; +  $form->{type} = "invoice"; +  &add_transaction; +   +} -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_customer(\%myconfig, \%$form); -  $form->redirect($locale->text('Customer saved!')); + +sub vendor_invoice { + +  $form->{script} = "ir.pl"; +  $form->{type} = "invoice"; +  &add_transaction;  } -sub save_vendor { +sub rfq { -  $form->isblank("name", $locale->text("Name missing!")); -  CT->save_vendor(\%myconfig, \%$form); -  $form->redirect($locale->text('Vendor saved!')); +  $form->{script} = "oe.pl"; +  $form->{type} = "request_quotation"; +  &add_transaction; + +} + + +sub quotation { +  $form->{script} = "oe.pl"; +  $form->{type} = "sales_quotation"; +  &add_transaction; +  } -sub delete { &{ "delete_$form->{db}" } }; +sub sales_order { +   +  $form->{script} = "oe.pl"; +  $form->{type} = "sales_order"; +  &add_transaction; + +} -sub delete_customer { -  $rc = CT->delete_customer(\%myconfig, \%$form); +sub purchase_order { + +  $form->{script} = "oe.pl"; +  $form->{type} = "purchase_order"; +  &add_transaction; -  $form->error($locale->text('Transactions exist, cannot delete customer!')) if ($rc == -1); -  $form->redirect($locale->text('Customer deleted!')) if $rc; -  $form->error($locale->text('Cannot delete customer!')); +} + +sub save { + +# $locale->text('Customer saved!') +# $locale->text('Vendor saved!') + +  $msg = ucfirst $form->{db}; +  $msg .= " saved!"; +   +  $form->isblank("name", $locale->text("Name missing!")); +  &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form); +   +  $form->redirect($locale->text($msg)); +    } -sub delete_vendor { +sub delete { -  $rc = CT->delete_vendor(\%myconfig, \%$form); +# $locale->text('Customer deleted!') +# $locale->text('Cannot delete customer!') +# $locale->text('Vendor deleted!') +# $locale->text('Cannot delete vendor!') + +  CT->delete(\%myconfig, \%$form); +   +  $msg = ucfirst $form->{db}; +  $msg .= " deleted!"; +  $form->redirect($locale->text($msg)); -  $form->error($locale->text('Transactions exist, cannot delete vendor!')) if ($rc == -1); -  $form->redirect($locale->text('Vendor deleted!')) if $rc; -  $form->error($locale->text('Cannot delete vendor!')); +  $msg = "Cannot delete $form->{db}"; +  $form->error($locale->text($msg));  }  sub continue { &{ $form->{nextsub} } }; +sub add_customer { &add }; +sub add_vendor { &add }; diff --git a/sql-ledger/bin/mozilla/gl.pl b/sql-ledger/bin/mozilla/gl.pl index 0d2dd4628..5b29dc6ee 100644 --- a/sql-ledger/bin/mozilla/gl.pl +++ b/sql-ledger/bin/mozilla/gl.pl @@ -1,11 +1,12 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +# Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -68,15 +69,29 @@ sub add {    $form->{title} = "Add"; -  $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};    # we use this only to set a default date    GL->transaction(\%myconfig, \%$form); -  map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} }; -  $form->{chart} = $chart; +  map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{all_accno} }; + +  if ($form->{all_projects}) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; +  } + -  $form->{rowcount} = 4; +  $form->{rowcount} = ($form->{transfer}) ? 2 : 9; + +  # departments +  $form->all_departments(\%myconfig); +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } +     &display_form;  } @@ -86,10 +101,30 @@ sub edit {    GL->transaction(\%myconfig, \%$form); -  map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} }; -  $form->{chart} = $chart; +  map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{all_accno} }; +   +  # projects +  if ($form->{all_projects}) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; +  } + +   +  # departments +  $form->all_departments(\%myconfig); +  if (@{ $form->{all_departments} }) { -  $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); +    $form->{department} = "$form->{department}--$form->{department_id}"; + +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } +  +  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +  # readonly +  $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;     $form->{title} = "Edit"; @@ -97,22 +132,25 @@ sub edit {    $i = 1;    foreach $ref (@{ $form->{GL} }) { -    $form->{"accno_$i"} = $ref->{accno}; -    $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = $ref->{projectnumber}; -    $form->{"project_id_$i"} = $ref->{project_id}; +    $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}"; + +    $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}"; +    $form->{"fx_transaction_$i"} = $ref->{fx_transaction};      if ($ref->{amount} < 0) {        $form->{totaldebit} -= $ref->{amount}; -      $form->{"debit_$i"} = $form->format_amount(\%myconfig, $ref->{amount} * -1, 2); +      $form->{"debit_$i"} = $ref->{amount} * -1;      } else {        $form->{totalcredit} += $ref->{amount}; -      $form->{"credit_$i"} = ($ref->{amount} > 0) ? $form->format_amount(\%myconfig, $ref->{amount}, 2) : ""; +      $form->{"credit_$i"} = $ref->{amount};      } -    &form_row($i++); +    $i++;    } -  &form_row($i); +  $form->{rowcount} = $i; +   +  &display_rows;    &form_footer; @@ -124,8 +162,45 @@ sub search {    $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports'); -  $form->header; +  $form->all_departments(\%myconfig); +  # departments +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  +    $department = qq| +  	<tr> +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +|; +  } + + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +  $form->header; +    print qq|  <body> @@ -147,6 +222,7 @@ sub search {  	  <th align=right>|.$locale->text('Source').qq|</th>  	  <td><input name=source size=20></td>  	</tr> +	$department  	<tr>  	  <th align=right>|.$locale->text('Description').qq|</th>  	  <td colspan=3><input name=description size=40></td> @@ -158,9 +234,16 @@ sub search {  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectfrom +	<tr> +	  <th align=right>|.$locale->text('Amount').qq| >=</th> +	  <td><input name=amountfrom size=11></td> +	  <th align=right>|.$locale->text('Amount').qq| <=</th> +	  <td><input name=amountto size=11></td> +	</tr>  	<tr>  	  <th align=right>|.$locale->text('Include in Report').qq|</th>  	  <td colspan=3> @@ -169,6 +252,7 @@ sub search {  		<td>  		  <input name="category" class=radio type=radio value=X checked> |.$locale->text('All').qq|  		  <input name="category" class=radio type=radio value=A> |.$locale->text('Asset').qq| +		  <input name="category" class=radio type=radio value=C> |.$locale->text('Contra').qq|  		  <input name="category" class=radio type=radio value=L> |.$locale->text('Liability').qq|  		  <input name="category" class=radio type=radio value=Q> |.$locale->text('Equity').qq|  		  <input name="category" class=radio type=radio value=I> |.$locale->text('Income').qq| @@ -221,7 +305,7 @@ sub search {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> @@ -235,11 +319,18 @@ sub search {  sub generate_report { +  $form->{sort} = "transdate" unless $form->{sort}; +    GL->all_transactions(\%myconfig, \%$form); -  $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}"; -  +  $href = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  $form->sort_order(); + +  $callback = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +      %acctype = ( 'A' => $locale->text('Asset'), +               'C' => $locale->text('Contra'),                 'L' => $locale->text('Liability'),  	       'Q' => $locale->text('Equity'),  	       'I' => $locale->text('Income'), @@ -254,60 +345,98 @@ sub generate_report {      $form->{title} .= " : ".$locale->text($acctype{$form->{category}});    }    if ($form->{accno}) { -    $callback .= "&accno=$form->{accno}"; +    $href .= "&accno=".$form->escape($form->{accno}); +    $callback .= "&accno=".$form->escape($form->{accno},1);      $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";    }    if ($form->{gifi_accno}) { -    $callback .= "&gifi_accno=$form->{gifi_accno}"; +    $href .= "&gifi_accno=".$form->escape($form->{gifi_accno}); +    $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);      $option .= "\n<br>" if $option;      $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";    }    if ($form->{source}) { -    $callback .= "&source=".$form->escape($form->{source}); +    $href .= "&source=".$form->escape($form->{source}); +    $callback .= "&source=".$form->escape($form->{source},1);      $option .= "\n<br>" if $option;      $option .= $locale->text('Source')." : $form->{source}";    }    if ($form->{reference}) { -    $callback .= "&reference=".$form->escape($form->{reference}); +    $href .= "&reference=".$form->escape($form->{reference}); +    $callback .= "&reference=".$form->escape($form->{reference},1);      $option .= "\n<br>" if $option;      $option .= $locale->text('Reference')." : $form->{reference}";    } +  if ($form->{department}) { +    $href .= "&department=".$form->escape($form->{department}); +    $callback .= "&department=".$form->escape($form->{department},1); +    ($department) = split /--/, $form->{department}; +    $option .= "\n<br>" if $option; +    $option .= $locale->text('Department')." : $department"; +  } +    if ($form->{description}) { -    $callback .= "&description=".$form->escape($form->{description}); +    $href .= "&description=".$form->escape($form->{description}); +    $callback .= "&description=".$form->escape($form->{description},1);      $option .= "\n<br>" if $option;      $option .= $locale->text('Description')." : $form->{description}";    }    if ($form->{notes}) { -    $callback .= "¬es=".$form->escape($form->{notes}); +    $href .= "¬es=".$form->escape($form->{notes}); +    $callback .= "¬es=".$form->escape($form->{notes},1);      $option .= "\n<br>" if $option;      $option .= $locale->text('Notes')." : $form->{notes}";    }    if ($form->{datefrom}) { +    $href .= "&datefrom=$form->{datefrom}";      $callback .= "&datefrom=$form->{datefrom}";      $option .= "\n<br>" if $option;      $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);    }    if ($form->{dateto}) { +    $href .= "&dateto=$form->{dateto}";      $callback .= "&dateto=$form->{dateto}";      if ($form->{datefrom}) {        $option .= " ";      } else {        $option .= "\n<br>" if $option;      } -    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{dateto}, 1); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{dateto}, 1); +  } +   +  if ($form->{amountfrom}) { +    $href .= "&amountfrom=$form->{amountfrom}"; +    $callback .= "&amountfrom=$form->{amountfrom}"; +    $option .= "\n<br>" if $option; +    $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2); +  } +  if ($form->{amountto}) { +    $href .= "&amountto=$form->{amountto}"; +    $callback .= "&amountto=$form->{amountto}"; +    if ($form->{amountfrom}) { +      $option .= " <= "; +    } else { +      $option .= "\n<br>" if $option; +      $option .= $locale->text('Amount')." <= "; +    } +    $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);    }    @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno)); +  if ($form->{link} =~ /_paid/) { +    @columns = $form->sort_columns(qw(transdate id reference description notes source cleared debit credit accno gifi_accno)); +    $form->{l_cleared} = "Y"; +  } +    if ($form->{accno} || $form->{gifi_accno}) {      @columns = grep !/(accno|gifi_accno)/, @columns;      push @columns, "balance";      $form->{l_balance} = "Y";    } -  $href = "$callback&sort=$form->{sort}";        # needed for accno    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") { @@ -327,17 +456,18 @@ sub generate_report {    $callback .= "&category=$form->{category}";    $href .= "&category=$form->{category}"; -  $column_header{id} = "<th><a class=listheading href=$callback&sort=id>".$locale->text('ID')."</a></th>"; -  $column_header{transdate} = "<th><a class=listheading href=$callback&sort=transdate>".$locale->text('Date')."</a></th>"; -  $column_header{reference} = "<th><a class=listheading href=$callback&sort=reference>".$locale->text('Reference')."</a></th>"; -  $column_header{source} = "<th><a class=listheading href=$callback&sort=source>".$locale->text('Source')."</a></th>"; -  $column_header{description} = "<th><a class=listheading href=$callback&sort=description>".$locale->text('Description')."</a></th>"; +  $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>"; +  $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>"; +  $column_header{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</a></th>"; +  $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>"; +  $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";    $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";    $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";    $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>"; -  $column_header{accno} = "<th><a class=listheading href=$callback&sort=accno>".$locale->text('Account')."</a></th>"; -  $column_header{gifi_accno} = "<th><a class=listheading href=$callback&sort=gifi_accno>".$locale->text('GIFI')."</a></th>"; -  $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</th>"; +  $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Account')."</a></th>"; +  $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>"; +  $column_header{balance} = "<th>".$locale->text('Balance')."</th>"; +  $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;    $form->header; @@ -388,6 +518,11 @@ print "          </tr>  |;    } + +  # reverse href +  $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC"; +  $form->sort_order(); +  $href =~ s/direction=$form->{direction}/direction=$direction/;    foreach $ref (@{ $form->{GL} }) { @@ -411,7 +546,7 @@ print "      $column_data{id} = "<td>$ref->{id}</td>";      $column_data{transdate} = "<td>$ref->{transdate}</td>"; -    $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>"; +    $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}</td>";      $column_data{description} = "<td>$ref->{description} </td>";      $column_data{source} = "<td>$ref->{source} </td>";      $column_data{notes} = "<td>$ref->{notes} </td>"; @@ -420,6 +555,7 @@ print "      $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";      $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";      $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>"; +    $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td> </td>";      $i++; $i %= 2;      print " @@ -435,9 +571,9 @@ print "    map { $column_data{$_} = "<td> </td>" } @column_index; -  $column_data{debit} = "<th align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>"; -  $column_data{credit} = "<th align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>"; -  $column_data{balance} = "<th align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>"; +  $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>"; +  $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>"; +  $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";    print qq|  	<tr class=listtotal> @@ -445,6 +581,28 @@ print "    map { print "$column_data{$_}\n" } @column_index; +  $i = 1; +  if ($myconfig{acs} !~ /GL--GL/) { +    $button{'GL--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> |; +    $button{'GL--Add Transaction'}{order} = $i++; +  } +  if ($myconfig{acs} !~ /AR--AR/) { +    $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |; +    $button{'AR--Add Transaction'}{order} = $i++; +    $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice ').qq|"> |; +    $button{'AR--Sales Invoice'}{order} = $i++; +  } +  if ($myconfig{acs} !~ /AP--AP/) { +    $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |; +    $button{'AP--Add Transaction'}{order} = $i++; +    $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice ').qq|"> |; +    $button{'AP--Vendor Invoice'}{order} = $i++; +  } + +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +      print qq|          </tr>        </table> @@ -463,13 +621,19 @@ print "  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; -<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq|  </form> @@ -485,9 +649,10 @@ sub gl_subtotal {    $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");    $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " "); -  map { $column_data{$_} = "<td> </td>" } qw(transdate id reference source description accno); -  $column_data{debit} = "<th class=listsubtotal align=right>$subtotaldebit</td>"; -  $column_data{credit} = "<th class=listsubtotal align=right>$subtotalcredit</td>"; +  map { $column_data{$_} = "<td> </td>" } @column_index; + +  $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</td>"; +  $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</td>";    print "<tr class=listsubtotal>"; @@ -506,12 +671,13 @@ sub update {    @a = ();    $count = 0; -  @flds = (qw(accno debit credit projectnumber project_id)); +  @flds = qw(accno debit credit projectnumber);    for $i (1 .. $form->{rowcount}) {      unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {        # take accno apart        ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"}); +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(debit credit);        push @a, {};        $j = $#a; @@ -521,6 +687,7 @@ sub update {      }    } +    for $i (1 .. $count) {      $j = $i - 1;      map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds; @@ -530,9 +697,7 @@ sub update {      map { delete $form->{"${_}_$i"} } @flds;    } -  $form->{rowcount} = $count; - -  &check_project; +  $form->{rowcount} = $count + 1;    &display_form; @@ -542,40 +707,66 @@ sub update {  sub display_form {    &form_header; +  &display_rows; +  &form_footer; -  $form->{rowcount}++; +} + + +sub display_rows { + +  $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}); +      $form->{totaldebit} = 0;    $form->{totalcredit} = 0; -   +    for $i (1 .. $form->{rowcount}) { -    $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"}); -    $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"}); -    &form_row($i); -  } - -  &form_footer; +    $form->{totaldebit} += $form->{"debit_$i"}; +    $form->{totalcredit} += $form->{"credit_$i"}; -} +    map { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" } qw(debit credit); +    $selectaccno = $form->{selectaccno}; +    $selectaccno =~ s/option>\Q$form->{"accno_$i"}\E/option selected>$form->{"accno_$i"}/; -sub form_row { -  my $i = shift; -   -  my $chart = $form->{chart}; -  $chart =~ s/<option>$form->{"accno_$i"}/<option selected>$form->{"accno_$i"}/; +    if ($form->{selectprojectnumber}) { +      $selectprojectnumber = $form->{selectprojectnumber}; +      $selectprojectnumber =~ s/(<option value="$form->{"projectnumber_$i"}")/$1 selected/; +       +      $project = qq| +  <td><select name="projectnumber_$i">$selectprojectnumber</select></td>|; +    } +     -  print qq|<tr> -  <td><select name="accno_$i">$chart</select></td> +    if ($form->{transfer}) { +      $form->{"fx_transaction_$i"} = ($form->{"fx_transaction_$i"}) ? "checked" : ""; +      $fx_transaction = qq| +  <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1 $form->{"fx_transaction_$i"}></td> +|; +    } else { +      $fx_transaction = qq| +    <input type=hidden name="fx_transaction_$i" value=$form->{"fx_transaction_$i"}> +|; +    } +     + +    print qq|<tr> +  <td><select name="accno_$i">$selectaccno</select></td> +  $fx_transaction    <td><input name="debit_$i" size=12 value=$form->{"debit_$i"}></td>    <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td> -  <td><input name="projectnumber_$i" size=12 value="$form->{"projectnumber_$i"}"> -      <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}> -      <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td> +  $project  </tr> -<input type=hidden name=rowcount value=$i>  |; +  } + + +  print qq| +<input type=hidden name=rowcount value=$form->{rowcount}> +<input type=hidden name=selectaccno value="$form->{selectaccno}"> +<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;  } @@ -583,12 +774,23 @@ sub form_row {  sub form_header {    $title = $form->{title}; -  $form->{title} = $locale->text("$title General Ledger Transaction"); -   +  if ($form->{transfer}) { +    $form->{title} = $locale->text("$title Cash Transfer Transaction"); +  } else { +    $form->{title} = $locale->text("$title General Ledger Transaction"); +  } +     +# $locale->text('Add Cash Transfer Transaction') +# $locale->text('Edit Cash Transfer Transaction')  # $locale->text('Add General Ledger Transaction')  # $locale->text('Edit General Ledger Transaction') +   + +  $form->{selectdepartment} = $form->unescape($form->{selectdepartment}); +  $form->{selectdepartment} =~ s/ selected//; +  $form->{selectdepartment} =~ s/(<option value="\Q$form->{department}\E")/$1 selected/; -  map { $form->{$_} =~ s/"/"/g } qw(reference description chart); +  map { $form->{$_} = $form->quote($form->{$_}) } qw(reference description notes);    if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {      $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|; @@ -601,7 +803,25 @@ sub form_header {    } else {      $notes = qq|<input name=notes size=50 value="$form->{notes}">|;    } +   +  $department = qq| +        <tr> +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td><select name=department>$form->{selectdepartment}</select></td> +	  <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|"> +	</tr> +| if $form->{selectdepartment}; +  $project = qq|  +	  <th class=listheading>|.$locale->text('Project').qq|</th> +| if $form->{selectprojectnumber}; + +  if ($form->{transfer}) { +    $fx_transaction = qq| +	  <th class=listheading>|.$locale->text('FX').qq|</th> +|; +  } +      $form->header;    print qq| @@ -611,7 +831,10 @@ sub form_header {  <input name=id type=hidden value=$form->{id}> -<input name=chart type=hidden value="$form->{chart}"> +<input type=hidden name=transfer value=$form->{transfer}> + +<input type=hidden name=selectaccno value="$form->{selectaccno}"> +  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=locked value=$form->{locked}>  <input type=hidden name=title value="$title"> @@ -627,22 +850,17 @@ sub form_header {  	<tr>  	  <th align=right>|.$locale->text('Reference').qq|</th>  	  <td><input name=reference size=20 value="$form->{reference}"></td> -	  <td align=right> -	    <table> -	      <tr> -		<th align=right>|.$locale->text('Date').qq|</th> -		<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td> -	      </tr> -	    </table> -	  </td> +	  <th align=right>|.$locale->text('Date').qq|</th> +	  <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>  	</tr> +	$department  	<tr>  	  <th align=right>|.$locale->text('Description').qq|</th> -	  <td colspan=2>$description</td> +	  <td colspan=3>$description</td>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Notes').qq|</th> -	  <td colspan=2>$notes</td> +	  <td colspan=3>$notes</td>  	</tr>        </table>      </td> @@ -652,9 +870,10 @@ sub form_header {        <table width=100%>  	<tr class=listheading>  	  <th class=listheading>|.$locale->text('Account').qq|</th> +	  $fx_transaction  	  <th class=listheading>|.$locale->text('Debit').qq|</th>  	  <th class=listheading>|.$locale->text('Credit').qq|</th> -	  <th class=listheading>|.$locale->text('Project').qq|</th> +	  $project  	</tr>  |; @@ -668,13 +887,25 @@ sub form_footer {    $decimalplaces = ($dec > 2) ? $dec : 2;    map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, " ") } qw(totaldebit totalcredit); -   + + +  $project = qq| +	  <th> </th> +| if $form->{selectprojectnumber}; + +  if ($form->{transfer}) { +    $fx_transaction = qq| +	  <th> </th> +|; +  } +        print qq|          <tr class=listtotal>  	  <th> </th> +	  $fx_transaction  	  <th class=listtotal align=right>$form->{totaldebit}</th>  	  <th class=listtotal align=right>$form->{totalcredit}</th> -	  <th> </th> +	  $project          </tr>        </table>      </td> @@ -686,7 +917,7 @@ sub form_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input name=callback type=hidden value="$form->{callback}"> @@ -696,33 +927,38 @@ sub form_footer {    $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  if ($form->{id}) { -    print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +  if (! $form->{readonly}) { +     +    if ($form->{id}) { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">  |; -    if (!$form->{revtrans}) {        if (!$form->{locked}) {  	print qq|  	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">  	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">  |;        } -    } -    if ($transdate > $closedto) {        print qq| -      <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">  |; -    } -     -  } else { -    if ($transdate > $closedto) { -      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +       +    } else { +      if ($transdate > $closedto) { +	print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +      }      }    } -  print "</form> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +   +  print " +  </form>  </body>  </html> @@ -741,12 +977,8 @@ sub delete {  <form method=post action=$form->{script}>  |; -  map { $form->{$_} =~ s/"/"/g } qw(reference description chart); - -  foreach $key (keys %$form) { -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } - +  $form->hide_form(); +      print qq|  <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2> @@ -776,22 +1008,24 @@ sub post {    $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  # check project -  &check_project; -  # this is just for the wise guys    $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); -   -  if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) { -    $errno *= -1; -    $err[1] = $locale->text('Cannot have a value in both Debit and Credit!'); -    $err[2] = $locale->text('Debit and credit out of balance!'); -    $err[3] = $locale->text('Cannot post a transaction without a value!'); + +  # add up debits and credits +  if (!$form->{adjustment}) { +    for $i (1 .. $form->{rowcount}) { +      $debit += $form->parse_amount(\%myconfig, $form->{"debit_$i"}); +      $credit += $form->parse_amount(\%myconfig, $form->{"credit_$i"}); +    } -    $form->error($err[$errno]); +    if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) { +      &post_adjustment; +      exit; +    }    } -     -  $form->redirect($locale->text('Transaction posted!')); + +  $form->redirect($locale->text('Transaction posted!')) if GL->post_transaction(\%myconfig, \%$form); +  $form->error($locale->text('Cannot post transaction!'));  } @@ -804,3 +1038,29 @@ sub post_as_new {  } +sub post_adjustment { + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=adjustment value=1> +|; + +  $form->hide_form(); +   +  print qq| +<h2 class=confirm>|.$locale->text('Warning!').qq|</h2> + +<h4>|.$locale->text('Out of balance transaction!').qq|</h4> + +<input name=action class=submit type=submit value="|.$locale->text('Post').qq|"> +</form> +|; + +} + + diff --git a/sql-ledger/bin/mozilla/hr.pl b/sql-ledger/bin/mozilla/hr.pl new file mode 100644 index 000000000..497daa1f7 --- /dev/null +++ b/sql-ledger/bin/mozilla/hr.pl @@ -0,0 +1,1217 @@ +#===================================================================== +# SQL-Ledger, Accounting +# Copyright (c) 2004 +# +#  Author: Dieter Simader +#   Email: dsimader@sql-ledger.org +#     Web: http://www.sql-ledger.org +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#====================================================================== +# +# payroll module +# +#====================================================================== + +use SL::HR; +use SL::User; + +1; +# end of main + + + +sub add { + +  $label = "Add ".ucfirst $form->{db}; +  $form->{title} = $locale->text($label); + +  $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  &{ "$form->{db}_links" }; +   +} + + +sub search { &{ "search_$form->{db}" } }; +   + +sub search_employee { + +  $form->{title} = $locale->text('Employees'); + +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr valign=top> +    <td> +      <table> +	<tr> +	  <th align=right nowrap>|.$locale->text('Employee Number').qq|</th> +	  <td colspan=3><input name=employeenumber size=20></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Employee Name').qq|</th> +	  <td colspan=3><input name=name size=35></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Startdate').qq|</th> +	  <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td> +	  <th>|.$locale->text('Enddate').qq|</th> +	  <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td> +	</tr> +	<tr valign=top> +	  <th align=right nowrap>|.$locale->text('Notes').qq|</th> +	  <td colspan=3><input name=notes size=40></td> +	</tr> +	<tr> +	  <td></td> +	  <td colspan=3><input name=status class=radio type=radio value=all checked> |.$locale->text('All').qq| +	  <input name=status class=radio type=radio value=sales> |.$locale->text('Sales').qq| +	  <input name=status class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq|</td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> +	  <td colspan=3> +	    <table> +	      <tr> +	        <td><input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID').qq|</td> +		<td><input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Number').qq|</td> +		<td><input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Name').qq|</td> +		<td><input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|</td> +		<td><input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province').qq|</td> +		<td><input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code').qq|</td> +		<td><input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country').qq|</td> +		<td><input name="l_workphone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Phone').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_homephone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Phone').qq|</td> +		<td><input name="l_startdate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Startdate').qq|</td> +		<td><input name="l_enddate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Enddate').qq|</td> +		<td><input name="l_sales" type=checkbox class=checkbox value=Y> |.$locale->text('Sales').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager').qq|</td> +		<td><input name="l_role" type=checkbox class=checkbox value=Y checked> |.$locale->text('Role').qq|</td> +		<td><input name="l_login" type=checkbox class=checkbox value=Y checked> |.$locale->text('Login').qq|</td> +		<td><input name="l_email" type=checkbox class=checkbox value=Y> |.$locale->text('E-mail').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_ssn" type=checkbox class=checkbox value=Y> |.$locale->text('SSN').qq|</td> +		<td><input name="l_dob" type=checkbox class=checkbox value=Y> |.$locale->text('DOB').qq|</td> +		<td><input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN').qq|</td> +		<td><input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC').qq|</td> +		<td><input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes').qq|</td> +	      </tr> +	    </table> +	  </td> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<input type=hidden name=nextsub value=list_employees> +<input type=hidden name=db value=$form->{db}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<br> +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; +} + + +sub list_employees { + +  HR->employees(\%myconfig, \%$form); +   +  $href = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; +   +  $form->sort_order(); + +  $callback = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; +   +  @columns = $form->sort_columns(qw(id employeenumber name address city state zipcode country workphone homephone email startdate enddate ssn dob iban bic sales role manager login notes)); + +  foreach $item (@columns) { +    if ($form->{"l_$item"} eq "Y") { +      push @column_index, $item; + +      # add column to href and callback +      $callback .= "&l_$item=Y"; +      $href .= "&l_$item=Y"; +    } +  } + +  %role = ( user	=> $locale->text('User'), +            supervisor	=> $locale->text('Supervisor'), +	    manager	=> $locale->text('Manager'), +            admin	=> $locale->text('Administrator') +	  ); +   +  $option = $locale->text('All'); + +  if ($form->{status} eq 'sales') { +    $option = $locale->text('Sales'); +  } +  if ($form->{status} eq 'orphaned') { +    $option = $locale->text('Orphaned'); +  } +  if ($form->{employeenumber}) { +    $callback .= "&employeenumber=".$form->escape($form->{employeenumber},1); +    $href .= "&employeenumber=".$form->escape($form->{employeenumber}); +    $option .= "\n<br>".$locale->text('Employee Number')." : $form->{employeenumber}"; +  } +  if ($form->{name}) { +    $callback .= "&name=".$form->escape($form->{name},1); +    $href .= "&name=".$form->escape($form->{name}); +    $option .= "\n<br>".$locale->text('Employee Name')." : $form->{name}"; +  } +  if ($form->{startdate}) { +    $callback .= "&startdate=$form->{startdate}"; +    $href .= "&startdate=$form->{startdate}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Startdate')." ".$locale->date(\%myconfig, $form->{startdate}, 1); +  } +  if ($form->{enddate}) { +    $callback .= "&enddate=$form->{enddate}"; +    $href .= "&enddate=$form->{enddate}"; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Enddate')." ".$locale->date(\%myconfig, $form->{enddate}, 1); +  } +  if ($form->{notes}) { +    $callback .= "¬es=".$form->escape($form->{notes},1); +    $href .= "¬es=".$form->escape($form->{notes}); +    $option .= "\n<br>" if $option; +    $option .= $locale->text('Notes')." : $form->{notes}"; +  } + +  $form->{callback} = "$callback&sort=$form->{sort}"; +  $callback = $form->escape($form->{callback}); + +  $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|; +  $column_header{employeenumber} = qq|<th><a class=listheading href=$href&sort=employeenumber>|.$locale->text('Number').qq|</a></th>|; +  $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|; +  $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|; +  $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</a></th>|; +  $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|; +  $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|; +  $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|; +  $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|; +  $column_header{workphone} = qq|<th><a class=listheading href=$href&sort=workphone>|.$locale->text('Work Phone').qq|</a></th>|; +  $column_header{homephone} = qq|<th><a class=listheading href=$href&sort=homephone>|.$locale->text('Home Phone').qq|</a></th>|; +   +  $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|; +  $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|; +  $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|; +  $column_header{role} = qq|<th><a class=listheading href=$href&sort=role>|.$locale->text('Role').qq|</a></th>|; +  $column_header{login} = qq|<th><a class=listheading href=$href&sort=login>|.$locale->text('Login').qq|</a></th>|; +   +  $column_header{sales} = qq|<th class=listheading>|.$locale->text('S').qq|</th>|; +  $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|; +  $column_header{ssn} = qq|<th><a class=listheading href=$href&sort=ssn>|.$locale->text('SSN').qq|</a></th>|; +  $column_header{dob} = qq|<th><a class=listheading href=$href&sort=dob>|.$locale->text('DOB').qq|</a></th>|; +  $column_header{iban} = qq|<th><a class=listheading href=$href&sort=iban>|.$locale->text('IBAN').qq|</a></th>|; +  $column_header{bic} = qq|<th><a class=listheading href=$href&sort=bic>|.$locale->text('BIC').qq|</a></th>|; +   +  $form->{title} = $locale->text('Employees'); + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; +   +  print qq| +        </tr> +|; + +  foreach $ref (@{ $form->{all_employee} }) { + +    map { $column_data{$_} = "<td>$ref->{$_} </td>" } @column_index; +     +    $column_data{sales} = ($ref->{sales}) ? "<td>x</td>" : "<td> </td>"; +    $column_data{role} = qq|<td>$role{"$ref->{role}"} </td>|; +    $column_date{address} = qq|$ref->{address1} $ref->{address2}|; + +    $column_data{name} = "<td><a href=$form->{script}?action=edit&db=employee&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name} </td>"; + +    if ($ref->{email}) { +      $email = $ref->{email}; +      $email =~ s/</\</; +      $email =~ s/>/\>/; +       +      $column_data{email} = qq|<td><a href="mailto:$ref->{email}">$email</a></td>|; +    } + +    $i++; $i %= 2; +    print " +        <tr class=listrow$i> +"; + +    map { print "$column_data{$_}\n" } @column_index; + +    print qq| +        </tr> +|; +     +  } + +  $i = 1; +  $button{'HR--Employees--Add Employee'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Employee').qq|"> |; +  $button{'HR--Employees--Add Employee'}{order} = $i++; + +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=db value=$form->{db}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; +  +} + + +sub edit { + +# $locale->text('Edit Employee') +# $locale->text('Edit Deduction') + +  $label = ucfirst $form->{db}; +  $form->{title} = "Edit $label"; + +  &{ "$form->{db}_links" }; +   +} + + +sub employee_links { + +#$form->{deductions} = 1; +  HR->get_employee(\%myconfig, \%$form); + +  map { $form->{$_} = $form->quote($form->{$_}) } keys %$form; + +  if ($form->{all_deduction}) { +    $form->{selectdeduction} = "<option>\n"; +    map { $form->{selectdeduction} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_deduction} }; +  } + +  $form->{manager} = "$form->{manager}--$form->{managerid}"; + +  if ($form->{all_manager}) { +    $form->{selectmanager} = "<option>\n"; +    map { $form->{selectmanager} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_manager} }; +  } + +  %role = ( user	=> $locale->text('User'), +            supervisor	=> $locale->text('Supervisor'), +	    manager	=> $locale->text('Manager'), +            admin	=> $locale->text('Administrator') +	  ); +   +  $form->{selectrole} = "<option>\n"; +  map { $form->{selectrole} .= "<option value=$_>$role{$_}\n" } qw(user supervisor manager admin); + +  $i = 1; +  foreach $ref (@{ $form->{all_employeededuction} }) { +    $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}"; +    map { $form->{"${_}_$i"} = $ref->{$_} } qw(before after rate); +    $i++; +  } +  $form->{deduction_rows} = $i - 1; + +  &employee_header; +  &employee_footer; + +} + + +sub employee_header { + +  $sales = qq|<input type=hidden name=sales value=$form->{sales}>|; +  $form->{sales} = ($form->{sales}) ? "checked" : ""; + +  $form->{selectrole} =~ s/ selected//; +  $form->{selectrole} =~ s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/; + +  $form->{selectdeduction} = $form->unescape($form->{selectdeduction}); +   +  $form->{selectmanager} = $form->unescape($form->{selectmanager}); +  $form->{selectmanager} =~ s/ selected//; +  $form->{selectmanager} =~ s/(<option value="\Q$form->{manager}\E")/$1 selected/; + +  $sales = qq| +<input type=hidden name=role value=$form->{role}> +<input type=hidden name=manager value=$form->{manager}> +|; + +  if ($myconfig{role} ne 'user') { +    $sales = qq| +        <tr> +	  <th align=right>|.$locale->text('Sales').qq|</th> +	  <td><input name=sales class=checkbox type=checkbox value=1 $form->{sales}></td> +	</tr> +        <tr> +	  <th align=right>|.$locale->text('Role').qq|</th> +	  <td><select name=role>$form->{selectrole}</select></td> +	</tr> +|; + +    if ($form->{selectmanager}) { +      $sales .= qq| +        <tr> +	  <th align=right>|.$locale->text('Manager').qq|</th> +	  <td><select name=manager>$form->{selectmanager}</select></td> +	</tr> +|; +    } +  } +   +  $form->{deduction_rows}++; +   +  for ($i = 1; $i <= $form->{deduction_rows}; $i++) { +    $form->{"selectdeduction_$i"} = $form->{selectdeduction}; +    if ($form->{"deduction_$i"}) { +      $form->{"selectdeduction_$i"} =~ s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/; +    } +  } + +  $form->{selectdeduction} = $form->escape($form->{selectdeduction},1); +  $form->{selectmanager} = $form->escape($form->{selectmanager},1); + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=selectdeduction value="$form->{selectdeduction}"> +<input type=hidden name=deduction_rows value=$form->{deduction_rows}> + +<input type=hidden name=selectmanager value="$form->{selectmanager}"> +<input type=hidden name=selectrole value="$form->{selectrole}"> + +<input type=hidden name=status value=$form->{status}> + +<input type=hidden name=title value="$form->{title}"> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +        <tr valign=top> +	  <td> +	    <table> +	      <tr> +		<th align=right nowrap>|.$locale->text('Number').qq|</th> +		<td><input name=employeenumber size=32 maxlength=32 value="$form->{employeenumber}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Name').qq|</th> +		<td><input name=name size=35 maxlength=64 value="$form->{name}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Address').qq|</th> +		<td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td> +	      </tr> +	      <tr> +		<th></th> +		<td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('City').qq|</th> +		<td><input name=city size=35 maxlength=32 value="$form->{city}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('State/Province').qq|</th> +		<td><input name=state size=35 maxlength=32 value="$form->{state}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> +		<td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Country').qq|</th> +		<td><input name=country size=35 maxlength=32 value="$form->{country}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('E-mail').qq|</th> +		<td><input name=email size=35 value="$form->{email}"></td> +	      </tr> +	      <tr> +	      $sales +	    </table> +	  </td> +	  <td> +	    <table> +	      <tr> +		<th align=right nowrap>|.$locale->text('Work Phone').qq|</th> +		<td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Home Phone').qq|</th> +		<td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Startdate').qq|</th> +		<td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Enddate').qq|</th> +		<td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td> +	      </tr> + +	      <tr> +		<th align=right nowrap>|.$locale->text('SSN').qq|</th> +		<td><input name=ssn size=20 maxlength=20 value="$form->{ssn}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('DOB').qq|</th> +		<td><input name=dob size=11 title="$myconfig{dateformat}" value=$form->{dob}></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('IBAN').qq|</th> +		<td><input name=iban size=34 maxlength=34 value="$form->{iban}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('BIC').qq|</th> +		<td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td> +	      </tr> +	    </table> +	  </td> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <th align=left nowrap>|.$locale->text('Notes').qq|</th> +  </tr> +  <tr> +    <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td> +  </tr> +|; + +    if ($form->{selectdeduction}) { + +      print qq| +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +	  <th class=listheading>|.$locale->text('Payroll Deduction').qq|</th> +	  <th class=listheading colspan=3>|.$locale->text('Allowances').qq|</th> +	</tr> + +        <tr class=listheading> +	  <th></th> +	  <th class=listheading>|.$locale->text('Before Deduction').qq|</th> +	  <th class=listheading>|.$locale->text('After Deduction').qq|</th> +	  <th class=listheading>|.$locale->text('Rate').qq|</th> +	</tr> +|; + +    for ($i = 1; $i <= $form->{deduction_rows}; $i++) { +      print qq| +        <tr> +	  <td><select name="deduction_$i">$form->{"selectdeduction_$i"}</select></td> +	  <td><input name="before_$i" value=|.$form->format_amount(\%myconfig, $form->{"before_$i"}, 2).qq|></td> +	  <td><input name="after_$i" value=|.$form->format_amount(\%myconfig, $form->{"after_$i"}, 2).qq|></td> +	  <td><input name="rate_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td> +	</tr> +|; +    } +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + + +sub employee_footer { + +  print qq| +<input name=id type=hidden value=$form->{id}> + +<input type=hidden name=db value=$form->{db}> +<input type=hidden name=employeelogin value=$form->{employeelogin}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input type=hidden name=callback value="$form->{callback}"> + +<br> + +<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Save').qq|"> +|; + +  if ($form->{id}) { +    print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|; +    if ($form->{status} eq 'orphaned') { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|; +    } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  +  </form> + +</body> +</html> +|; + +} + + +sub save { &{ "save_$form->{db}" } }; + + +sub save_employee { + +  $form->isblank("name", $locale->text("Name missing!")); +  HR->save_employee(\%myconfig, \%$form); + +  # if it is a login change memberfile and .conf +  if ($form->{employeelogin}) { +    $user = new User $memberfile, $form->{employeelogin}; + +    map { $user->{$_} = $form->{$_} } qw(name email role); +    map { $user->{"old_$_"} = $user->{$_} } qw(dbpassword password); +     +    $user->save_member($memberfile, $userspath) if $user->{login}; +  } +   +  $form->redirect($locale->text('Employee saved!')); +   +} + + +sub delete { &{ "delete_$form->{db}" } }; + + +sub delete_employee { + +  HR->delete_employee(\%myconfig, \%$form); +  $form->redirect($locale->text('Employee deleted!')); +   +} + + +sub continue { &{ $form->{nextsub} } }; + +sub add_employee { &add }; +sub add_deduction { &add }; + + +sub search_deduction { + +  HR->deductions(\%myconfig, \%$form); +   +  $href = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; + +  $form->sort_order(); + +  $callback = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; +   +  @column_index = $form->sort_columns(qw(description rate amount above below employeepays employerpays ap_accno expense_accno)); + +  +  $form->{callback} = $callback; +  $callback = $form->escape($form->{callback}); + +  $column_header{description} = qq|<th class=listheading href=$href>|.$locale->text('Description').qq|</th>|; +  $column_header{rate} = qq|<th class=listheading nowrap>|.$locale->text('Rate').qq|<br>%</th>|; +  $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|; +  $column_header{above} = qq|<th class=listheading>|.$locale->text('Above').qq|</th>|; +  $column_header{below} = qq|<th class=listheading>|.$locale->text('Below').qq|</th>|; +  $column_header{employerpays} = qq|<th class=listheading>|.$locale->text('Employer').qq|</th>|; +  $column_header{employeepays} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|; +   +  $column_header{ap_accno} = qq|<th class=listheading>|.$locale->text('AP').qq|</th>|; +  $column_header{expense_accno} = qq|<th class=listheading>|.$locale->text('Expense').qq|</th>|; +   +  $form->{title} = $locale->text('Deductions'); + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; +   +  print qq| +        </tr> +|; + +   +  foreach $ref (@{ $form->{all_deduction} }) { + +    $rate = $form->format_amount(\%myconfig, $ref->{rate} * 100, "", " "); +     +    $column_data{rate} = "<td align=right>$rate</td>"; + +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, " ")."</td>" } qw(amount below above); +       +    map { $column_data{$_} = "<td>$ref->{$_} </td>" } qw(ap_accno expense_accno); +     +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, "", " ")."</td>" } qw(employerpays employeepays); +     +    if ($ref->{description} ne $sameitem) { +      $column_data{description} = "<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</a></td>"; +    } else { +      $column_data{description} = "<td> </td>"; +    } + +    $i++; $i %= 2; +    print " +        <tr class=listrow$i> +"; + +    map { print "$column_data{$_}\n" } @column_index; + +    print qq| +        </tr> +|; + +    $sameitem = $ref->{description}; +     +  } + +  $i = 1; +  $button{'HR--Deductions--Add Deduction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Deduction').qq|"> |; +  $button{'HR--Deductions--Add Deduction'}{order} = $i++; + +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input type=hidden name=db value=$form->{db}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; +  +} + + +sub deduction_links { +   +  HR->get_deduction(\%myconfig, \%$form); + +  $i = 1; +  foreach $ref (@{ $form->{deductionrate} }) { +    map { $form->{"${_}_$i"} = $ref->{$_} } keys %$ref; +    $i++; +  } +  $form->{rate_rows} = $i - 1; +   +  $i = 1; +  foreach $ref (@{ $form->{deductionbase} }) { +    $form->{"base_$i"} = "$ref->{description}--$ref->{id}"; +    $form->{"maximum_$i"} = $ref->{maximum}; +    $i++; +  } +  $form->{base_rows} = $i - 1; + +  $i = 1; +  foreach $ref (@{ $form->{deductionafter} }) { +    $form->{"after_$i"} = "$ref->{description}--$ref->{id}"; +    $i++; +  } +  $form->{after_rows} = $i - 1; +   +  $form->{employeepays} = 1; +   +  $selectaccount = "<option>\n"; +  map { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{ap_accounts} }; + +  $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|; +  $form->{selectap} = $selectaccount; + +  $selectaccount = "<option>\n"; +  map { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{expense_accounts} }; + +  $form->{expense_accno} = qq|$form->{expense_accno}--$form->{expense_description}|; +  $form->{selectexpense} = $selectaccount; + +  map { $form->{"rate_$_"} *= 100 } (1 .. $form->{rate_rows}); + +  $form->{selectbase} = "<option>\n"; +  map { $form->{selectbase} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_deduction} }; +   +  &deduction_header; +  &deduction_footer; +   +} + + +sub deduction_header { + +  $selectap = $form->{selectap}; +  $selectap =~ s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/; +  $selectexpense = $form->{selectexpense}; +  $selectexpense =~ s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/; + + +  $form->{rate_rows}++; +  $form->{base_rows}++; +  $form->{after_rows}++; + +  $form->{selectbase} = $form->unescape($form->{selectbase}); +   +  for ($i = 1; $i <= $form->{base_rows}; $i++) { +    $form->{"selectbase_$i"} = $form->{selectbase}; +    if ($form->{"base_$i"}) { +      $form->{"selectbase_$i"} =~ s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/; +    } +  } +  for ($i = 1; $i <= $form->{after_rows}; $i++) { +    $form->{"selectafter_$i"} = $form->{selectbase}; +    if ($form->{"after_$i"}) { +      $form->{"selectafter_$i"} =~ s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/; +    } +  } +  + +  $form->header; + +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=title value="$form->{title}"> + +<input type=hidden name=selectap value="$form->{selectap}"> +<input type=hidden name=selectexpense value="$form->{selectexpense}"> +<input type=hidden name=selectbase value="|.$form->escape($form->{selectbase},1).qq|"> + +<input type=hidden name=rate_rows value=$form->{rate_rows}> +<input type=hidden name=base_rows value=$form->{base_rows}> +<input type=hidden name=after_rows value=$form->{after_rows}> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right nowrap>|.$locale->text('Description').qq|</th> +	  <td><input name=description size=35 value="$form->{description}"></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('AP').qq|</th> +	  <td><select name=ap_accno>$selectap</select></td> +	  <th align=right nowrap>|.$locale->text('Employee pays').qq| x</th> +	  <td><input name=employeepays size=4 value=|.$form->format_amount(\%myconfig, $form->{employeepays}).qq|></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Expense').qq|</th> +	  <td><select name=expense_accno>$selectexpense</select></td> +	  <th align=right nowrap>|.$locale->text('Employer pays').qq| x</th> +	  <td><input name=employerpays size=4 value=|.$form->format_amount(\%myconfig, $form->{employerpays}).qq|></td> +	</tr> +	<tr> +	  <td></td> +	  <td></td> +	  <th align=right nowrap>|.$locale->text('Excempt age <').qq|</th> +	  <td><input name=fromage size=4 value=|.$form->format_amount(\%myconfig, $form->{fromage}).qq|></td> +	  <th align=right nowrap>|.$locale->text('>').qq|</th> +	  <td><input name=toage size=4 value=|.$form->format_amount(\%myconfig, $form->{toage}).qq|> +        </tr> +	<tr> +	  <td></td> +	  <td> +	    <table> +	      <tr class=listheading> +	        <th class=listheading>|.$locale->text('Rate').qq| %</th> +		<th class=listheading>|.$locale->text('Amount').qq|</th> +		<th class=listheading>|.$locale->text('Above').qq|</th> +		<th class=listheading>|.$locale->text('Below').qq|</th> +	      </tr> +|; + +  for ($i = 1; $i <= $form->{rate_rows}; $i++) { +    print qq| +	      <tr> +		<td><input name="rate_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td> +		<td><input name="amount_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"amount_$i"}, 2).qq|></td> +		<td><input name="above_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}, 2).qq|></td> +		<td><input name="below_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"below_$i"}, 2).qq|></td> +	      </tr> +|; +  } + +  print qq| +	    </table> +	  </td> +	</tr> +      </table> +    </td> +  </tr> +|; +   +  print qq| +  <tr> +    <td> +      <table> +|; + +  $basedon = $locale->text('Based on'); +  $maximum = $locale->text('Maximum'); +   +  for ($i = 1; $i <= $form->{base_rows}; $i++) { +    print qq| +	<tr> +	  <th>$basedon</th> +	  <td><select name="base_$i">$form->{"selectbase_$i"}</select></td> +	  <th>$maximum</th> +	  <td><input name="maximum_$i" value=|.$form->format_amount(\%myconfig, $form->{"maximum_$i"}, 2).qq|></td> +	</tr> +|; +    $basedon = ""; +    $maximum = ""; +  } + +  $deductafter = $locale->text('Deduct after'); +   +  for ($i = 1; $i <= $form->{after_rows}; $i++) { +    print qq| +	<tr> +	  <th>$deductafter</th> +	  <td><select name="after_$i">$form->{"selectafter_$i"}</select></td> +	</tr> +|; +    $deductafter = ""; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + + +sub deduction_footer { + +  print qq| +<input name=id type=hidden value=$form->{id}> + +<input type=hidden name=db value=$form->{db}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input type=hidden name=callback value="$form->{callback}"> + +<br> + +<input class=submit type=submit name=action value="|.$locale->text("Update").qq|"> +<input class=submit type=submit name=action value="|.$locale->text("Save").qq|"> +|; + +  if ($form->{id}) { +    print qq|<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">\n|; +     +    if ($form->{status} eq 'orphaned') { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|; +    } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  +  </form> + +</body> +</html> +|; + +} + + +sub update { &{ "update_$form->{db}" }; } +sub save { &{ "save_$form->{db}" } }; + + +sub update_deduction { + +  # if rate or amount is blank remove row +  @flds = qw(rate amount above below); +  $count = 0; +  @a = (); +  for $i (1 .. $form->{rate_rows}) { +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } @flds; +    if ($form->{"rate_$i"} || $form->{"amount_$i"}) { +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +  $form->redo_rows(\@flds, \@a, $count, $form->{rate_rows}); +  $form->{rate_rows} = $count; + + +  @flds = qw(base maximum); +  $count = 0; +  @a = (); +  for $i (1 .. $form->{"base_rows"}) { +    $form->{"maximum_$i"} = $form->parse_amount(\%myconfig, $form->{"maximum_$i"}); +    if ($form->{"base_$i"}) { +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +  $form->redo_rows(\@flds, \@a, $count, $form->{"base_rows"}); +  $form->{"base_rows"} = $count; + + +  @flds = qw(after); +  $count = 0; +  @a = (); +  for $i (1 .. $form->{"after_rows"}) { +    if ($form->{"after_$i"}) { +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +  $form->redo_rows(\@flds, \@a, $count, $form->{"after_rows"}); +  $form->{"after_rows"} = $count; + +  &deduction_header; +  &deduction_footer; + +} + + +sub update_employee { + +  # if rate or amount is blank remove row +  @flds = qw(before after); +  $count = 0; +  @a = (); +  for $i (1 .. $form->{deduction_rows}) { +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } @flds; +    if ($form->{"deduction_$i"}) { +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +  $form->redo_rows(\@flds, \@a, $count, $form->{deduction_rows}); +  $form->{deduction_rows} = $count; + +  &employee_header; +  &employee_footer; + +} +  + +sub save_as_new { + +  $form->{id} = 0; +  delete $form->{employeelogin}; + +  &save; + +} + + +sub save_deduction { + +  $form->isblank("description", $locale->text("Description missing!")); + +  unless ($form->{"rate_1"} || $form->{"amount_1"}) { +    $form->isblank("rate_1", $locale->text("Rate missing!")) unless $form->{"amount_1"}; +    $form->isblank("amount_1", $locale->text("Amount missing!")); +  } +   +  HR->save_deduction(\%myconfig, \%$form); +  $form->redirect($locale->text('Deduction saved!')); +   +} + + +sub delete_deduction { + +  HR->delete_deduction(\%myconfig, \%$form); +  $form->redirect($locale->text('Deduction deleted!')); +   +} + + diff --git a/sql-ledger/bin/mozilla/ic.pl b/sql-ledger/bin/mozilla/ic.pl index 797daee01..f643c1301 100644 --- a/sql-ledger/bin/mozilla/ic.pl +++ b/sql-ledger/bin/mozilla/ic.pl @@ -6,6 +6,7 @@  #   Email: dsimader@sql-ledger.org  #     Web: http://www.sql-ledger.org  # +# Contributors:  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -37,14 +38,28 @@ require "$form->{path}/io.pl";  sub add { -  $form->{title} = $locale->text('Add ' . ucfirst $form->{item}); +  %label = ( part	=> 'Part', +             service	=> 'Service', +	     assembly	=> 'Assembly', +	     labor	=> 'Labor/Overhead' ); -  $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +# $locale->text('Add Part') +# $locale->text('Add Service') +# $locale->text('Add Assembly') +# $locale->text('Add Labor/Overhead') -  $form->{unit} = ($form->{item} eq 'service') ? $locale->text('hr') : $locale->text('ea'); +  $label = "Add $label{$form->{item}}"; +  $form->{title} = $locale->text($label); + +  $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + +  $form->{orphaned} = 1; + +  if ($form->{previousform}) { +    $form->{callback} = ""; +  }    &link_part; -      &display_form;  } @@ -52,13 +67,55 @@ sub add {  sub search { -  $form->{title} = (ucfirst $form->{searchitems})."s"; -  $form->{title} = $locale->text($form->{title}); -   -# $locale->text('Parts') -# $locale->text('Services') +  $form->get_partsgroup(\%myconfig, { all => 0, searchitems => $form->{searchitems}}); + +  IC->get_warehouses(\%myconfig, \%$form) unless $form->{searchitems} =~ /(service|labor)/; + +  if (@{ $form->{all_partsgroup} }) { +    $partsgroup = qq|<option>\n|; + +    map { $partsgroup .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };  + +    $partsgroup = qq|  +        <th align=right nowrap>|.$locale->text('Group').qq|</th> +	<td><select name=partsgroup>$partsgroup</select></td> +|; +  } + +  $l_listprice = qq| +                <td><input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price').qq|</td> +|; +  $l_sellprice = qq| +		<td><input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price').qq|</td> +|; +  $l_lastcost = qq| +		<td><input name=l_lastcost class=checkbox type=checkbox value=Y> |.$locale->text('Cost').qq|</td> +|; +  $l_linetotal = qq| +		<td><input name=l_linetotal class=checkbox type=checkbox value=Y checked> |.$locale->text('Line Total').qq|</td> +|; +  $l_curr = qq| +		<td><input name=l_curr class=checkbox type=checkbox value=Y> |.$locale->text('Currency').qq|</td> +|; -  unless ($form->{searchitems} eq 'service') { +  $accrual = qq| +		    <tr> +		      <td colspan=4><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq| +		       <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td> +		    </tr> +|; + +  $serialnumber = qq| +          <th align=right nowrap>|.$locale->text('Serial Number').qq|</th> +          <td><input name=serialnumber size=20></td> +|; + +  $l_serialnumber = qq| +        <td><input name=l_serialnumber class=checkbox type=checkbox value=Y> |.$locale->text('Serial Number').qq|</td> +|; + + +  if ($form->{searchitems} =~ /(part|assembly)/) {      $onhand = qq|              <input name=itemstatus class=radio type=radio value=onhand> |.$locale->text('On Hand').qq| @@ -67,23 +124,71 @@ sub search {      $makemodel = qq|          <tr> -          <th width="1%" align=right nowrap>|.$locale->text('Make').qq|</th> +          <th align=right nowrap>|.$locale->text('Make').qq|</th>            <td><input name=make size=20></td> -          <th width="1%" align=right nowrap>|.$locale->text('Model').qq|</th> +          <th align=right nowrap>|.$locale->text('Model').qq|</th>            <td><input name=model size=20></td>          </tr>  |; + +    $l_makemodel = qq| +        <td><input name=l_make class=checkbox type=checkbox value=Y> |.$locale->text('Make').qq|</td> +        <td><input name=l_model class=checkbox type=checkbox value=Y> |.$locale->text('Model').qq|</td> +|; + +    $l_bin = qq| +		<td><input name=l_bin class=checkbox type=checkbox value=Y> |.$locale->text('Bin').qq|</td>|; + +    $l_rop = qq| +		<td><input name=l_rop class=checkbox type=checkbox value=Y> |.$locale->text('ROP').qq|</td>|; + + +    $l_weight = qq| +		<td><input name=l_weight class=checkbox type=checkbox value=Y> |.$locale->text('Weight').qq|</td>|; + + +    if (@{ $form->{all_warehouses} }) { +      $selectwarehouse = "<option>\n"; + +      map { $selectwarehouse .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} }); +       +      $warehouse = qq| +          <th align=right nowrap>|.$locale->text('Warehouse').qq|</th> +          <td><select name=warehouse>$selectwarehouse</select></td> +|; + +      $l_warehouse = qq| +        <td><input name=l_warehouse class=checkbox type=checkbox value=Y> |.$locale->text('Warehouse').qq|</td> +|; + + +      $drawing = qq| +        <tr> +          <th align=right nowrap>|.$locale->text('Drawing').qq|</th> +          <td><input name=drawing size=20></td> +          <th align=right nowrap>|.$locale->text('Microfiche').qq|</th> +          <td><input name=microfiche size=20></td> +        </tr> +|; + +      $l_drawing = qq| +	      <tr> +                <td><input name=l_image class=checkbox type=checkbox value=Y> |.$locale->text('Image').qq|</td> +		<td><input name=l_drawing class=checkbox type=checkbox value=Y> |.$locale->text('Drawing').qq|</td> +		<td><input name=l_microfiche class=checkbox type=checkbox value=Y> |.$locale->text('Microfiche').qq|</td> +	      </tr> +|; + +    }    }    if ($form->{searchitems} eq 'assembly') { - -    $form->{title} = $locale->text('Assemblies'); -     +       $toplevel = qq|          <tr>  	  <td></td>            <td colspan=3> -	  <input name=none class=radio type=radio value=1 checked> |.$locale->text('Top Level').qq| +	  <input name=null class=radio type=radio value=1 checked> |.$locale->text('Top Level').qq|  	  <input name=bom class=checkbox type=checkbox value=1> |.$locale->text('Individual Items').qq|            </td>          </tr> @@ -99,30 +204,64 @@ sub search {  		  <table>  		    <tr>  		      <td><input name=sold class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('Sold').qq|</td> +		      <td nowrap>|.$locale->text('Sales Invoices').qq|</td>  		    </tr>  		    <tr>  		      <td colspan=2><hr size=1 noshade></td>  		    </tr>  		    <tr>  		      <td><input name=ordered class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('Ordered').qq|</td> +		      <td nowrap>|.$locale->text('Sales Orders').qq|</td> +		    </tr> +		    <tr> +		      <td colspan=4><hr size=1 noshade></td> +		    </tr> +		    <tr> +		      <td><input name=quoted class=checkbox type=checkbox value=1></td> +		      <td nowrap>|.$locale->text('Quotations').qq|</td>  		    </tr>  		  </table>  		</td>  		<td width=5%> </td> -		<th>|.$locale->text('From').qq|</th> -		<td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> -		<th>|.$locale->text('to').qq|</th> -		<td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> - -		<td><input name=closed class=checkbox type=checkbox value=1> |.$locale->text('Closed').qq|</td> +		<td> +		  <table> +		    $accrual +		    <tr> +		      <th>|.$locale->text('From').qq|</th> +		      <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> +		      <th>|.$locale->text('To').qq|</th> +		      <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> +		    </tr> +		    <tr> +		      <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq| +		      <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|</td> +		    </tr> +		  </table> +		</td>  	      </tr>  	    </table>  	  </td>  	</tr>  |; +  } elsif ($form->{searchitems} eq 'component') { + +    $warehouse = ""; +    $serialnumber = ""; +    $l_serialnumber = ""; +    $l_warehouse = ""; +   +  } elsif ($form->{searchitems} eq 'labor') { + +    $warehouse = ""; +    $serialnumber = ""; +    $l_serialnumber = ""; +    $l_sellprice = qq| +		<td><input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Amount').qq|</td> +|; +    $l_listprice = ""; +    $l_lastcost = ""; +        } else {       $bought = qq| @@ -135,31 +274,43 @@ sub search {  		  <table>  		    <tr>  		      <td><input name=bought class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('Bought').qq|</td> +		      <td nowrap>|.$locale->text('Vendor Invoices').qq|</td>  		      <td><input name=sold class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('Sold').qq|</td> +		      <td nowrap>|.$locale->text('Sales Invoices').qq|</td>  		    </tr>  		    <tr>  		      <td colspan=4><hr size=1 noshade></td>  		    </tr>  		    <tr>  		      <td><input name=onorder class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('On Order').qq|</td> +		      <td nowrap>|.$locale->text('Purchase Orders').qq|</td>  		      <td><input name=ordered class=checkbox type=checkbox value=1></td> -		      <td nowrap>|.$locale->text('Ordered').qq|</td> +		      <td nowrap>|.$locale->text('Sales Orders').qq|</td> +		    </tr> +		    <tr> +		      <td colspan=4><hr size=1 noshade></td> +		    </tr> +		    <tr> +		      <td><input name=rfq class=checkbox type=checkbox value=1></td> +		      <td nowrap>|.$locale->text('RFQ').qq|</td> +		      <td><input name=quoted class=checkbox type=checkbox value=1></td> +		      <td nowrap>|.$locale->text('Quotations').qq|</td>  		    </tr>  		  </table>  		</td>  		<td width=5%> </td>  		<td>  		  <table> +		    $accrual  		    <tr>  		      <th>|.$locale->text('From').qq|</th>  		      <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> -		      <th>|.$locale->text('to').qq|</th> +		      <th>|.$locale->text('To').qq|</th>  		      <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> - -		      <td><input name=closed class=checkbox type=checkbox value=1> |.$locale->text('Closed').qq|</td> +		    </tr> +		    <tr> +		      <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq| +		      <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|</td>  		    </tr>  		  </table>  		</td> @@ -170,7 +321,23 @@ sub search {  |;    } +  %title = ( all	=> 'Items', +             part	=> 'Parts', +	     labor	=> 'Labor/Overhead', +	     service	=> 'Services', +	     assembly	=> 'Assemblies', +	     component	=> 'Components' +	   ); +# $locale->text('Items') +# $locale->text('Parts') +# $locale->text('Labor/Overhead') +# $locale->text('Services') +# $locale->text('Assemblies') +# $locale->text('Components') +   +  $form->{title} = $locale->text($title{$form->{searchitems}}); +       $form->header;    print qq| @@ -188,22 +355,22 @@ sub search {      <td>        <table>          <tr> -          <th width=1% align=right nowrap>|.$locale->text('Number').qq|</th> +          <th align=right nowrap>|.$locale->text('Number').qq|</th>            <td><input name=partnumber size=20></td> -          <th align=right nowrap>|.$locale->text('Description').qq|</th> -          <td><input name=description size=40></td>          </tr>          <tr> -          <th align=right nowrap>|.$locale->text('Group').qq|</th> -          <td><input name=partsgroup size=20></td> +          <th align=right nowrap>|.$locale->text('Description').qq|</th> +          <td colspan=3><input name=description size=40></td>          </tr> +	<tr> +	  $warehouse +	</tr> +	<tr> +	  $partsgroup +	  $serialnumber +	</tr>  	$makemodel -        <tr> -          <th align=right nowrap>|.$locale->text('Drawing').qq|</th> -          <td><input name=drawing size=20></td> -          <th align=right nowrap>|.$locale->text('Microfiche').qq|</th> -          <td><input name=microfiche size=20></td> -        </tr> +	$drawing  	$toplevel          <tr>            <td></td> @@ -228,25 +395,27 @@ sub search {                <tr>                  <td><input name=l_partnumber class=checkbox type=checkbox value=Y checked> |.$locale->text('Number').qq|</td>  		<td><input name=l_description class=checkbox type=checkbox value=Y checked> |.$locale->text('Description').qq|</td> +		$l_serialnumber  		<td><input name=l_unit class=checkbox type=checkbox value=Y checked> |.$locale->text('Unit of measure').qq|</td> +                <td><input name=l_priceupdate class=checkbox type=checkbox value=Y> |.$locale->text('Updated').qq|</td> +		<td><input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group').qq|</td>  	      </tr>  	      <tr> -                <td><input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price').qq|</td> -		<td><input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price').qq|</td> -		<td><input name=l_lastcost class=checkbox type=checkbox value=Y> |.$locale->text('Last Cost').qq|</td> -		<td><input name=l_linetotal class=checkbox type=checkbox value=Y checked> |.$locale->text('Line Total').qq|</td> +	        $l_listprice +		$l_sellprice +		$l_lastcost +		$l_linetotal +		$l_curr  	      </tr>  	      <tr> -                <td><input name=l_priceupdate class=checkbox type=checkbox value=Y> |.$locale->text('Updated').qq|</td> -		<td><input name=l_bin class=checkbox type=checkbox value=Y> |.$locale->text('Bin').qq|</td> -		<td><input name=l_rop class=checkbox type=checkbox value=Y> |.$locale->text('ROP').qq|</td> -		<td><input name=l_weight class=checkbox type=checkbox value=Y> |.$locale->text('Weight').qq|</td> +		$l_bin +		$l_rop +		$l_weight                </tr> +	        $l_drawing  	      <tr> -                <td><input name=l_image class=checkbox type=checkbox value=Y> |.$locale->text('Image').qq|</td> -		<td><input name=l_drawing class=checkbox type=checkbox value=Y> |.$locale->text('Drawing').qq|</td> -		<td><input name=l_microfiche class=checkbox type=checkbox value=Y> |.$locale->text('Microfiche').qq|</td> -		<td><input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group').qq|</td> +		$l_makemodel +		$l_warehouse                </tr>  	      <tr>                  <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> @@ -264,7 +433,7 @@ sub search {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> @@ -289,18 +458,47 @@ sub generate_report {      }    } -  $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title=".$form->escape($form->{title},1); +  $warehouse = $form->escape($form->{warehouse},1); +  $partsgroup = $form->escape($form->{partsgroup},1); +  $title = $form->escape($form->{title},1); +   +  $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&warehouse=$warehouse&partsgroup=$partsgroup&title=$title&method=$form->{method}"; -  IC->all_parts(\%myconfig, \%$form); +  # if we have a serialnumber limit search +  if ($form->{serialnumber} || $form->{l_serialnumber}) { +    $form->{l_serialnumber} = "Y"; +    unless ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { +      if ($form->{searchitems} eq 'assembly') { +	$form->{sold} = $form->{ordered} = 1; +      } else { +	$form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1; +      } +    } +  } +     if ($form->{itemstatus} eq 'active') {      $option .= $locale->text('Active')." : ";    }    if ($form->{itemstatus} eq 'obsolete') { +    $form->{onhand} = $form->{short} = 0; +    $form->{warehouse} = ""; +    $form->{l_warehouse} = 0; +      $option .= $locale->text('Obsolete')." : ";    }    if ($form->{itemstatus} eq 'orphaned') { +    $form->{onhand} = $form->{short} = 0; +    $form->{bought} = $form->{sold} = 0; +    $form->{onorder} = $form->{ordered} = 0; +    $form->{rfq} = $form->{quoted} = 0; + +    $form->{warehouse} = ""; +    $form->{l_warehouse} = 0; + +    $form->{transdatefrom} = $form->{transdateto} = ""; +          $option .= $locale->text('Orphaned')." : ";    }    if ($form->{itemstatus} eq 'onhand') { @@ -310,87 +508,130 @@ sub generate_report {    if ($form->{itemstatus} eq 'short') {      $option .= $locale->text('Short')." : ";      $form->{l_onhand} = "Y"; +    $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor'; +     +    $form->{warehouse} = ""; +    $form->{l_warehouse} = 0;    }    if ($form->{onorder}) {      $form->{l_ordnumber} = "Y";      $callback .= "&onorder=$form->{onorder}"; -    $option .= $locale->text('On Order')." : "; +    $option .= $locale->text('Purchase Order')." : ";    }    if ($form->{ordered}) {      $form->{l_ordnumber} = "Y";      $callback .= "&ordered=$form->{ordered}"; -    $option .= $locale->text('Ordered')." : "; +    $option .= $locale->text('Sales Order')." : "; +  } +  if ($form->{rfq}) { +    $form->{l_quonumber} = "Y"; +    $callback .= "&rfq=$form->{rfq}"; +    $option .= $locale->text('RFQ')." : ";    } -  if ($form->{closed}) { -    $callback .= "&closed=$form->{closed}"; -    $option .= $locale->text('Closed')." : "; +  if ($form->{quoted}) { +    $form->{l_quonumber} = "Y"; +    $callback .= ""ed=$form->{quoted}"; +    $option .= $locale->text('Quotation')." : ";    }    if ($form->{bought}) {      $form->{l_invnumber} = "Y";      $callback .= "&bought=$form->{bought}"; -    $option .= $locale->text('Bought')." : "; +    $option .= $locale->text('Vendor Invoice')." : ";    }    if ($form->{sold}) {      $form->{l_invnumber} = "Y";      $callback .= "&sold=$form->{sold}"; -    $option .= $locale->text('Sold')." : "; +    $option .= $locale->text('Sales Invoice')." : "; +  } +  if ($form->{sold} || $form->{bought}) { +    $label = ucfirst $form->{method}; +    $option .= $locale->text($label) ." : ";    } -  if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { + +  if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) { +     +    # warehouse stuff is meaningless +    $form->{warehouse} = ""; +    $form->{l_warehouse} = 0;      $form->{l_lastcost} = ""; +    $form->{l_name} = "Y"; +    $form->{l_employee} = "Y"; + +      +    if ($form->{open}) { +      $callback .= "&open=$form->{open}"; +      $option .= $locale->text('Open'); +    } +    if ($form->{closed}) { +      $callback .= "&closed=$form->{closed}"; +      if ($form->{open}) { +	$option .= " : ".$locale->text('Closed'); +      } else { +	$option .= $locale->text('Closed'); +      } +    } +      if ($form->{transdatefrom}) {        $callback .= "&transdatefrom=$form->{transdatefrom}";        $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);      }      if ($form->{transdateto}) {        $callback .= "&transdateto=$form->{transdateto}"; -      $option .= "\n<br>".$locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +      $option .= "\n<br>".$locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);      }    } +  if ($form->{warehouse}) { +    ($warehouse) = split /--/, $form->{warehouse}; +    $option .= "<br>".$locale->text('Warehouse')." : $warehouse"; +    $form->{l_warehouse} = 0; +  } +     $option .= "<br>";    if ($form->{partnumber}) { -    $callback .= "&partnumber=$form->{partnumber}"; +    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);      $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;    } +  if ($form->{partsgroup}) { +    ($partsgroup) = split /--/, $form->{partsgroup}; +    $option .= $locale->text('Group').qq| : $partsgroup<br>|; +  } +  if ($form->{serialnumber}) { +    $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1); +    $option .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|; +  }    if ($form->{description}) { -    $callback .= "&description=$form->{description}"; +    $callback .= "&description=".$form->escape($form->{description},1); +    $description = $form->{description}; +    $description =~ s/
/<br>/g;      $option .= $locale->text('Description').qq| : $form->{description}<br>|;    }    if ($form->{make}) { -    $callback .= "&make=$form->{make}"; +    $callback .= "&make=".$form->escape($form->{make},1);      $option .= $locale->text('Make').qq| : $form->{make}<br>|;    }    if ($form->{model}) { -    $callback .= "&model=$form->{model}"; +    $callback .= "&model=".$form->escape($form->{model},1);      $option .= $locale->text('Model').qq| : $form->{model}<br>|;    }    if ($form->{drawing}) { -    $callback .= "&drawing=$form->{drawing}"; +    $callback .= "&drawing=".$form->escape($form->{drawing},1);      $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;    }    if ($form->{microfiche}) { -    $callback .= "µfiche=$form->{microfiche}"; +    $callback .= "µfiche=".$form->escape($form->{microfiche},1);      $option .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;    } -  if ($form->{partsgroup}) { -    $callback .= "&partsgroup=$form->{partsgroup}"; -    $option .= $locale->text('Group').qq| : $form->{partsgroup}<br>|; -  } - -  @columns = $form->sort_columns(qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber)); +   +  @columns = $form->sort_columns(qw(partnumber description assemblypartnumber partsgroup make model bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost curr priceupdate weight image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse));    if ($form->{l_linetotal}) {      $form->{l_onhand} = "Y";      $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice}; -    if ($form->{l_lastcost}) { -      $form->{l_linetotallastcost} = "Y"; -      if (($form->{searchitems} eq 'assembly') && !$form->{bom}) { -	$form->{l_linetotallastcost} = ""; -      } -    } +    $form->{l_linetotallastcost} = "Y" if $form->{l_lastcost};      $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};    } @@ -400,7 +641,8 @@ sub generate_report {      $form->{l_onhand} = "";      # qty is irrelevant unless bought or sold -    if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { +    if ($form->{bought} || $form->{sold} || $form->{onorder} || +        $form->{ordered} || $form->{rfq} || $form->{quoted}) {        $form->{l_onhand} = "Y";      } else {        $form->{l_linetotalsellprice} = ""; @@ -408,7 +650,6 @@ sub generate_report {      }    } -  $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") { @@ -422,50 +663,135 @@ sub generate_report {    if ($form->{l_subtotal} eq 'Y') {      $callback .= "&l_subtotal=Y";    } + + +  IC->all_parts(\%myconfig, \%$form); + +  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}"; +   +  $href = $callback; +   +  $form->sort_order(); +   +  $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/; + + +  if ($form->{searchitems} eq 'assembly' && $form->{l_partnumber}) { +    # replace partnumber with partnumber_ +    $ndx = 0; +    foreach $item (@column_index) { +      $ndx++; +      last if $item eq 'partnumber'; +    } + +    splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol}); +    $colspan = $form->{pncol} + 1; +  } + +  if ($form->{searchitems} eq 'component') { +    if ($form->{l_partnumber}) { +      # splice it in after the partnumber +      $ndx = 0; +      foreach $item (@column_index) { +	$ndx++; +	last if $item eq 'partnumber'; +      } +       +      @a = splice @column_index, 0, $ndx; +      unshift @column_index, "assemblypartnumber"; +      unshift @column_index, @a; +    } +  } -  $column_header{partnumber} = qq|<th nowrap><a class=listheading href=$callback&sort=partnumber>|.$locale->text('Number').qq|</a></th>|; -  $column_header{description} = qq|<th nowrap><a class=listheading href=$callback&sort=description>|.$locale->text('Description').qq|</a></th>|; -  $column_header{partsgroup} = qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|; -  $column_header{bin} = qq|<th><a class=listheading href=$callback&sort=bin>|.$locale->text('Bin').qq|</a></th>|; -  $column_header{priceupdate} = qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|.$locale->text('Updated').qq|</a></th>|; +  $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|; +  $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; +  $column_header{partsgroup} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|; +  $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</a></th>|; +  $column_header{priceupdate} = qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>|.$locale->text('Updated').qq|</a></th>|;    $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;    $column_header{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;    $column_header{listprice} = qq|<th class=listheading nowrap>|.$locale->text('List Price').qq|</th>|; -  $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Last Cost').qq|</th>|; +  $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|;    $column_header{rop} = qq|<th class=listheading nowrap>|.$locale->text('ROP').qq|</th>|;    $column_header{weight} = qq|<th class=listheading nowrap>|.$locale->text('Weight').qq|</th>|; + +  $column_header{make} = qq|<th nowrap><a class=listheading href=$href&sort=make>|.$locale->text('Make').qq|</a></th>|; +  $column_header{model} = qq|<th nowrap><a class=listheading href=$href&sort=model>|.$locale->text('Model').qq|</a></th>|; -  $column_header{invnumber} = qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|.$locale->text('Invoice Number').qq|</a></th>|; -  $column_header{ordnumber} = qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|.$locale->text('Order Number').qq|</a></th>|; +  $column_header{invnumber} = qq|<th nowrap><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice Number').qq|</a></th>|; +  $column_header{ordnumber} = qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order Number').qq|</a></th>|; +  $column_header{quonumber} = qq|<th nowrap><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|; +   +  $column_header{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|; +   +  $column_header{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|; +   +  $column_header{sellprice} = qq|<th class=listheading nowrap>|; +  $column_header{sellprice} .= ($form->{searchitems} ne 'labor') ? $locale->text('Sell Price') : $locale->text('Amount'); +  $column_header{sellprice} .= qq|</th>|; -  $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;    $column_header{linetotalsellprice} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;    $column_header{linetotallastcost} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;    $column_header{linetotallistprice} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|; +  $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|; +      $column_header{image} = qq|<th class=listheading nowrap>|.$locale->text('Image').qq|</a></th>|; -  $column_header{drawing} = qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|.$locale->text('Drawing').qq|</a></th>|; -  $column_header{microfiche} = qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|.$locale->text('Microfiche').qq|</a></th>|; +  $column_header{drawing} = qq|<th nowrap><a class=listheading href=$href&sort=drawing>|.$locale->text('Drawing').qq|</a></th>|; +  $column_header{microfiche} = qq|<th nowrap><a class=listheading href=$href&sort=microfiche>|.$locale->text('Microfiche').qq|</a></th>|; +   +  $column_header{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|; +   +  $column_header{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|.$locale->text('Assembly').qq|</a></th>|; +   +  $column_header{warehouse} = qq|<th nowrap class=listheading>|.$locale->text('Warehouse').qq|</th>|; +    $form->header; -  $colspan = $#column_index + 1; + +  $i = 1; +  if ($form->{searchitems} eq 'part') { +    $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Part').qq|"> |; +    $button{'Goods & Services--Add Part'}{order} = $i++; +  } +  if ($form->{searchitems} eq 'service') { +    $button{'Goods & Services--Add Service'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Service').qq|"> |; +    $button{'Goods & Services--Add Service'}{order} = $i++; +  } +  if ($form->{searchitems} eq 'assembly') {   +    $button{'Goods & Services--Add Assembly'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Assembly').qq|"> |; +    $button{'Goods & Services--Add Assembly'}{order} = $i++; +  } +  if ($form->{searchitems} eq 'labor') {   +    $button{'Goods & Services--Add Labor/Overhead'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Labor/Overhead').qq|"> |; +    $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++; +  } + +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  }    print qq|  <body>  <table width=100%> -<tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> -<tr height="5"></tr> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> -<tr><td colspan=$colspan>$option</td></tr> +  <tr><td>$option</td></tr> -  <tr class=listheading> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading>  |;    map { print "\n$column_header{$_}" } @column_index;    print qq| -  </tr> +        </tr>    |; @@ -479,6 +805,7 @@ sub generate_report {      $sameitem = $form->{parts}->[0]->{$form->{sort}};    } +    foreach $ref (@{ $form->{parts} }) {      if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) { @@ -489,30 +816,51 @@ sub generate_report {      }      $ref->{exchangerate} = 1 unless $ref->{exchangerate}; -    $ref->{sellprice} *= $ref->{exchangerate}; -    $ref->{listprice} *= $ref->{exchangerate}; -    $ref->{lastcost} *= $ref->{exchangerate}; +    $ref->{discount} *= 1; +    $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount}); +    if ($form->{l_curr}) { +      if ($ref->{module} ne 'oe') { +	map { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) } qw(sellprice listprice lastcost); +      } +    } else { +      if ($ref->{module} eq 'oe') { +	map { $ref->{$_} = $form->round_amount($ref->{$_} * $ref->{exchangerate}, 2) } qw(sellprice listprice lastcost); +      } +    } -    $align = "left"; +    # use this for assemblies      $onhand = $ref->{onhand}; +    $ref->{description} =~ s/
/<br>/g; +     +    map { $column_data{"partnumber_$_"} = "<td> </td>" } (1 .. $form->{pncol}); + +    $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>"; +     +    $column_data{assemblypartnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{assemblypartnumber} </a></td>"; +          if ($ref->{assemblyitem}) { -      $align = "right";        $onhand = 0 if ($form->{sold}); +       +      $column_data{partnumber} = "<td> </td>"; +       +      $column_data{"partnumber_$ref->{stagger}"} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>"; +      } +     +    map { $column_data{$_} = "<td>$ref->{$_} </td>" } qw(description partsgroup employee curr); -    $column_data{partnumber} = "<td align=$align><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partnumber} </a></td>"; -    $column_data{description} = "<td>$ref->{description} </td>"; -    $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>"; -    -    $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $onhand, '', " ")."</td>"; -    $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ") . "</td>"; -    $column_data{listprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{listprice}, 2, " ") . "</td>"; -    $column_data{lastcost} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{lastcost}, 2, " ") . "</td>"; +    $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', " ")."</td>"; + +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, " ") . "</td>" } qw(sellprice listprice lastcost);      $column_data{linetotalsellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2, " ")."</td>";      $column_data{linetotallastcost} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2, " ")."</td>";      $column_data{linetotallistprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2, " ")."</td>"; + +    if ($ref->{assemblyitem} && $ref->{stagger} > 1) { +      map { $column_data{$_} = "<td> </td>" } qw(linetotalsellprice linetotallastcost linetotallistprice); +    }      if (!$ref->{assemblyitem}) {        $totalsellprice += $onhand * $ref->{sellprice}; @@ -531,13 +879,23 @@ sub generate_report {      $column_data{bin} = "<td>$ref->{bin} </td>";      $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>"; -    $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber} </a></td>" : "<td>$ref->{invnumber} </td>"; -    $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber} </a></td>" : "<td>$ref->{ordnumber} </td>"; +    $ref->{module} = 'ps' if $ref->{till}; +    $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber} </a></td>" : "<td>$ref->{invnumber} </td>"; +    $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber} </a></td>" : "<td>$ref->{ordnumber} </td>"; +    $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber} </a></td>" : "<td>$ref->{quonumber} </td>"; + +    $column_data{name} = "<td>$ref->{name} </td>";      $column_data{image} = ($ref->{image}) ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>" : "<td> </td>";      $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td> </td>";      $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td> </td>"; +    $column_data{make} = "<td>$ref->{make} </td>"; +    $column_data{model} = "<td>$ref->{model} </td>"; +     +    $column_data{serialnumber} = "<td>$ref->{serialnumber} </td>"; +    $column_data{warehouse} = "<td>$ref->{warehouse} </td>"; +          $i++; $i %= 2;      print "<tr class=listrow$i>"; @@ -569,12 +927,14 @@ sub generate_report {    }    print qq| -  <tr><td colspan=$colspan><hr size=3 noshade></td></tr> +      </table> +    </td> +  </tr> +  <tr><td><hr size=3 noshade></td></tr>  </table>  |; - - +     print qq|  <br> @@ -587,11 +947,20 @@ sub generate_report {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; -<input class=submit type=submit name=action value="|.$locale->text('Add').qq|"> +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } -</form> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form>  </body>  </html> @@ -607,9 +976,10 @@ sub parts_subtotal {    $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});    $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, '', " ")."</th>"; -  $column_data{sellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, " ")."</th>"; -  $column_data{listprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, " ")."</th>"; -  $column_data{lastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, " ")."</th>"; + +  $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, " ")."</th>"; +  $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, " ")."</th>"; +  $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, " ")."</th>";    $subtotalonhand = 0;    $subtotalsellprice = 0; @@ -629,14 +999,28 @@ sub parts_subtotal {  sub edit { +   + %label = ( part	=> 'Part', +            service	=> 'Service', +            assembly	=> 'Assembly', +	    labor	=> 'Labor/Overhead' ); + +# $locale->text('Edit Part') +# $locale->text('Edit Service') +# $locale->text('Edit Assembly') +# $locale->text('Edit Labor/Overhead')    IC->get_part(\%myconfig, \%$form); -  $form->{title} = $locale->text('Edit '.ucfirst $form->{item}); +  $label = "Edit $label{$form->{item}}"; +  $form->{title} = $locale->text($label);    &link_part; -  &display_form; + +  $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform}; +  &display_form; +  } @@ -645,10 +1029,26 @@ sub link_part {    IC->create_links("IC", \%myconfig, \%$form); +  # currencies  +  map { $form->{selectcurrency} .= "<option>$_\n" } split /:/, $form->{currencies}; +      # parts and assemblies have the same links    $item = $form->{item}; +   +  # readonly +  if ($form->{item} eq 'part') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/; +  } +  if ($form->{item} eq 'service') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/; +  }    if ($form->{item} eq 'assembly') {      $item = 'part'; +    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/; +  } +  if ($form->{item} eq 'labor') { +    $item = 'labor'; +    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;    }    # build the popup menus @@ -681,7 +1081,7 @@ sub link_part {    }    chop $form->{taxaccounts}; -  if (($form->{item} eq "part") || ($form->{item} eq "assembly")) { +  if ($form->{item} !~ /service/) {      $form->{selectIC_income} = $form->{selectIC_sale};      $form->{selectIC_expense} = $form->{selectIC_cogs};      $form->{IC_income} = $form->{IC_sale}; @@ -691,6 +1091,82 @@ sub link_part {    delete $form->{IC_links};    delete $form->{amount}; +  $form->get_partsgroup(\%myconfig, {all => 1}); +  $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}"; +   +  if (@{ $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = qq|<option>\n|; + +    map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} }; +  } + +  if ($form->{item} eq 'assembly') { + +    foreach $i (1 .. $form->{assembly_rows}) { +      if ($form->{"partsgroup_id_$i"}) { +	$form->{"partsgroup_$i"} = qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|; +      } +    } +     +    $form->get_partsgroup(\%myconfig); + +    if (@{ $form->{all_partsgroup} }) { +      $form->{selectassemblypartsgroup} = qq|<option>\n|; + +      map { $form->{selectassemblypartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} }; +    } +  } +   +  # setup make and models +  $i = 1; +  foreach $ref (@{ $form->{makemodels} }) { +    map { $form->{"${_}_$i"} = $ref->{$_} } qw(make model); +    $i++; +  } +  $form->{makemodel_rows} = $i - 1; + +   +  # setup vendors +  if (@{ $form->{all_vendor} }) { +    $form->{selectvendor} = "<option>\n"; +    map { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_vendor} }; +  } + +  # vendor matrix +  $i = 1; +  foreach $ref (@{ $form->{vendormatrix} }) { +    $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|; + +    map { $form->{"${_}_$i"} = $ref->{$_} } qw(partnumber lastcost leadtime vendorcurr); +    $i++; +  } +  $form->{vendor_rows} = $i - 1; +   +  # setup customers and groups +  if (@{ $form->{all_customer} }) { +    $form->{selectcustomer} = "<option>\n"; +    map { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_customer} }; +  } + +  if (@{ $form->{all_pricegroup} }) { +    $form->{selectpricegroup} = "<option>\n"; +    map { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| } @{ $form->{all_pricegroup} }; +  } + +  $i = 1; +  # customer matrix +  foreach $ref (@{ $form->{customermatrix} }) { + +    $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid}; +    $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid}; + +    map { $form->{"${_}_$i"} = $ref->{$_} } qw(validfrom validto pricebreak customerprice customercurr); + +    $i++; +     +  } +  $form->{customer_rows} = $i - 1; +  } @@ -701,8 +1177,13 @@ sub form_header {    $dec = length $dec;    my $decimalplaces = ($dec > 2) ? $dec : 2; +  if ($form->{lastcost} > 0) { +    $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1); +    $form->{markup} = $form->format_amount(\%myconfig, $markup, 1); +  } +      map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)} qw(listprice sellprice); - +      ($dec) = ($form->{lastcost} =~ /\.(\d+)/);    $dec = length $dec;    my $decimalplaces = ($dec > 2) ? $dec : 2; @@ -710,12 +1191,9 @@ sub form_header {    $form->{lastcost} = $form->format_amount(\%myconfig, $form->{lastcost}, $decimalplaces);    map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) } qw(weight rop stock); - -  foreach $item (qw(partnumber description unit notes)) { -    $form->{$item} =~ s/"/"/g; -  } - +  map { $form->{$_} = $form->quote($form->{$_}) } qw(partnumber description unit notes); +    if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {      $rows = 2;    } @@ -736,16 +1214,26 @@ sub form_header {    # set option    foreach $item (qw(IC IC_income IC_expense)) {      if ($form->{$item}) { -      if ($form->{id} && $form->{orphaned}) { +      if ($form->{orphaned}) {  	$form->{"select$item"} =~ s/ selected//;  	$form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; -        } else {  	$form->{"select$item"} = qq|<option selected>$form->{$item}|;        }      }    } +  if ($form->{selectpartsgroup}) { +    $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup}); + +    $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|; +     +    $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/; + +    $partsgroup .= qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|; +    $group = $locale->text('Group'); +  } +    # tax fields    foreach $item (split / /, $form->{taxaccounts}) {      $tax .= qq| @@ -755,24 +1243,40 @@ sub form_header {    }    $form->{obsolete} = "checked" if $form->{obsolete}; +   +  $sellprice = qq| +	      <tr> +		<th align="right" nowrap="true">|.$locale->text('List Price').qq|</th> +		<td><input name=listprice size=11 value=$form->{listprice}></td> +	      </tr> +	      <tr> +		<th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th> +		<td><input name=sellprice size=11 value=$form->{sellprice}></td> +	      </tr> +|;    $lastcost = qq|   	      <tr> -                <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th> +                <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th>                  <td><input name=lastcost size=11 value=$form->{lastcost}></td>                </tr> +	      <tr> +	        <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th> +		<td><input name=markup size=5 value=$form->{markup}></td> +		<input type=hidden name=oldmarkup value=$markup> +	      </tr>  |;    if ($form->{item} eq "part") {      $linkaccounts = qq|  	      <tr> -		<th width="1%" align=right>|.$locale->text('Inventory').qq|</th> +		<th align=right>|.$locale->text('Inventory').qq|</th>  		<td><select name=IC>$form->{selectIC}</select></td>  		<input name=selectIC type=hidden value="$form->{selectIC}">  	      </tr>  	      <tr> -		<th align=right>|.$locale->text('Sales').qq|</th> +		<th align=right>|.$locale->text('Income').qq|</th>  		<td><select name=IC_income>$form->{selectIC_income}</select></td>  		<input name=selectIC_income type=hidden value="$form->{selectIC_income}">  	      </tr> @@ -817,11 +1321,28 @@ sub form_header {    if ($form->{item} eq "assembly") { -    $lastcost = ""; -     +    $lastcost = qq| +              <tr> +	        <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th>  +		<td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td> +	      </tr> +	      <tr> +	        <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th> +		<td><input name=markup size=5 value=$form->{markup}></td> +		<input type=hidden name=oldmarkup value=$markup> +	      </tr> +|; +      $linkaccounts = qq| +<!--  	      <tr> -		<th width="1%" align=right>|.$locale->text('Sales').qq|</th> +		<th align=right>|.$locale->text('Inventory').qq|</th> +		<td><select name=IC>$form->{selectIC}</select></td> +		<input name=selectIC type=hidden value="$form->{selectIC}"> +	      </tr> +--> +	      <tr> +		<th align=right>|.$locale->text('Income').qq|</th>  		<td><select name=IC_income>$form->{selectIC_income}</select></td>  		<input name=selectIC_income type=hidden value="$form->{selectIC_income}">  	      </tr> @@ -856,8 +1377,7 @@ sub form_header {  		</td>  	      </tr>  |; - -    +        } @@ -865,7 +1385,7 @@ sub form_header {      $linkaccounts = qq|  	      <tr> -		<th width="1%" align=right>|.$locale->text('Income').qq|</th> +		<th align=right>|.$locale->text('Income').qq|</th>  		<td><select name=IC_income>$form->{selectIC_income}</select></td>  		<input name=selectIC_income type=hidden value="$form->{selectIC_income}">  	      </tr> @@ -887,25 +1407,49 @@ sub form_header {    } +  if ($form->{item} eq "labor") { +    $lastcost = ""; +    $sellprice = qq| +	      <tr> +		<th align="right" nowrap="true">|.$locale->text('Amount').qq|</th> +		<td><input name=sellprice size=11 value=$form->{sellprice}></td> +	      </tr> +|; -  if ($form->{item} ne 'service') { -    $color = ($form->{onhand} > 0) ? "green" : "red"; +    $linkaccounts = qq| +	      <tr> +		<th align=right>|.$locale->text('Labor/Overhead').qq|</th> +		<td><select name=IC>$form->{selectIC}</select></td> +		<input name=selectIC type=hidden value="$form->{selectIC}"> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Expense').qq|</th> +		<td><select name=IC_expense>$form->{selectIC_expense}</select></td> +		<input name=selectIC_expense type=hidden value="$form->{selectIC_expense}"> +	      </tr> +|; +   +  } + + +  if ($form->{item} =~ /(part|assembly)/) { +    $n = ($form->{onhand} > 0) ? "1" : "0";      $rop = qq|  	      <tr>  		<th align="right" nowrap>|.$locale->text('On Hand').qq|</th> -		<th align=left nowrap> |.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th> +		<th align=left nowrap class="plus$n"> |.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>  	      </tr>  |;      if ($form->{item} eq 'assembly') {        $rop .= qq| -	      <tr> -		<th align="right" nowrap>|.$locale->text('Stock').qq|</th> +              <tr> +	        <th align="right" nowrap>|.$locale->text('Stock').qq|</th>  		<td><input name=stock size=10 value=$form->{stock}></td>  	      </tr>  |;      } -   +      $rop .= qq|  	      <tr>  		<th align="right" nowrap="true">|.$locale->text('ROP').qq|</th> @@ -923,17 +1467,16 @@ sub form_header {      $imagelinks = qq|    <tr>      <td> -      <table> +      <table width=100%>          <tr> -	  <th width=1% align=right nowrap>|.$locale->text('Image').qq|</th> -	  <td width=70%><input name=image size=40 value="$form->{image}"></td> - +	  <th align=right nowrap>|.$locale->text('Image').qq|</th> +	  <td><input name=image size=40 value="$form->{image}"></td> +	  <th align=right nowrap>|.$locale->text('Microfiche').qq|</th> +	  <td><input name=microfiche size=20 value="$form->{microfiche}"></td>  	</tr>  	<tr> -	  <th width=1% align=right nowrap>|.$locale->text('Drawing').qq|</th> -	  <td width=70%><input name=drawing size=40 value="$form->{drawing}"></td> -	  <th width=1% align=right nowrap>|.$locale->text('Microfiche').qq|</th> -	  <td width=30%><input name=microfiche size=20 value="$form->{microfiche}"></td> +	  <th align=right nowrap>|.$locale->text('Drawing').qq|</th> +	  <td><input name=drawing size=40 value="$form->{drawing}"></td>  	</tr>        </table>      </td> @@ -952,11 +1495,6 @@ sub form_header {    } - -# type=submit $locale->text('Add Part') -# type=submit $locale->text('Add Service') -# type=submit $locale->text('Add Assembly') -  # type=submit $locale->text('Edit Part')  # type=submit $locale->text('Edit Service')  # type=submit $locale->text('Edit Assembly') @@ -967,20 +1505,23 @@ sub form_header {    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end"> -<input name=id type=hidden value=$form->{id}> -<input name=item type=hidden value=$form->{item}> -<input name=title type=hidden value="$form->{title}"> -<input name=makemodel type=hidden value="$form->{makemodel}"> -<input name=alternate type=hidden value="$form->{alternate}"> -<input name=onhand type=hidden value=$form->{onhand}> -<input name=orphaned type=hidden value=$form->{orphaned}> -<input name=taxaccounts type=hidden value="$form->{taxaccounts}"> -<input name=rowcount type=hidden value=$form->{rowcount}> +<input type=hidden name=id value=$form->{id}> +<input type=hidden name=item value=$form->{item}> +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=makemodel value="$form->{makemodel}"> +<input type=hidden name=alternate value="$form->{alternate}"> +<input type=hidden name=onhand value=$form->{onhand}> +<input type=hidden name=orphaned value=$form->{orphaned}> +<input type=hidden name=taxaccounts value="$form->{taxaccounts}"> +<input type=hidden name=rowcount value=$form->{rowcount}> +<input type=hidden name=baseassembly value=$form->{baseassembly}>  <table width="100%"> -  <tr><th class=listtop>$form->{title}</th></tr> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr>    <tr height="5"></tr>    <tr>      <td> @@ -988,14 +1529,13 @@ sub form_header {          <tr valign=top>            <th align=left>|.$locale->text('Number').qq|</th>            <th align=left>|.$locale->text('Description').qq|</th> - 	  <th align=left>|.$locale->text('Group').qq|</th> +	  <th align=left>$group</th>  	</tr>  	<tr valign=top>            <td><input name=partnumber value="$form->{partnumber}" size=20></td>            <td>$description</td> -	  <td><input name=partsgroup size=20 value="$form->{partsgroup}"></td> -	  <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}"> -        </tr> +	  <td>$partsgroup</td> +	</tr>        </table>      </td>    </tr> @@ -1025,18 +1565,11 @@ sub form_header {  		<th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>  		<td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>      	      </tr> -	      <tr> -		<th align="right" nowrap="true">|.$locale->text('List Price').qq|</th> -		<td><input name=listprice size=11 value=$form->{listprice}></td> -	      </tr> -	      <tr> -		<th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th> -		<td><input name=sellprice size=11 value=$form->{sellprice}></td> -	      </tr> +	      $sellprice  	      $lastcost  	      <tr>  		<th align="right" nowrap="true">|.$locale->text('Unit').qq|</th> -		<td><input name=unit size=5 maxsize=5 value="$form->{unit}"></td> +		<td><input name=unit size=5 value="$form->{unit}"></td>  	      </tr>  	      $weight  	      $rop @@ -1055,67 +1588,68 @@ sub form_header {  sub form_footer { -  if ($form->{item} eq "assembly") { - -    print qq| -	<tr> -	  <td> -            <table width="100%"> -              <tr> -                <th colspan=2 align=right>|.$locale->text('Total').qq| </th> -                <th width="1%" align=right>|.$form->format_amount(\%myconfig, $form->{assemblytotal}, 2).qq|</th> -              </tr> -            </table> -          </td> -        </tr> -        <input type=hidden name=assembly_rows value=$form->{assembly_rows}> -|; -  } -    print qq| -      <input type=hidden name=path value=$form->{path}> -      <input type=hidden name=login value=$form->{login}> -      <input type=hidden name=password value=$form->{password}> -      <input type=hidden name=callback value="$form->{callback}"> -      <input type=hidden name=previous_form value="$form->{previous_form}">    <tr>      <td><hr size=3 noshade></td>    </tr>  </table> -<br> -<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +<input type=hidden name=customer_rows value=$form->{customer_rows}>  |; -  if ($form->{item} ne "service") { + +  if ($form->{item} =~ /(part|assembly)/) {      print qq|        <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}> -    |; +|; +  } +   +  if ($form->{item} =~ /(part|service)/) { +    print qq| +      <input type=hidden name=vendor_rows value=$form->{vendor_rows}> +|;    } -  print qq| + +  if (! $form->{readonly}) { +    print qq| +      <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">        <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">|; -  if ($form->{id}) { +    if ($form->{id}) { -    if (! $form->{previous_form}) { -      print qq| -      <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">|; -    } -     -    if ($form->{orphaned}) { -      if (! $form->{previous_form}) { +      if (!$form->{isassemblyitem}) { +	print qq| +	<input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">|; +      } + +      if ($form->{orphaned}) {  	print qq| -      <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|; +	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|;        }      } +  } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar;    } +  &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly'; +    print qq| +  <input type=hidden name=path value=$form->{path}> +  <input type=hidden name=login value=$form->{login}> +  <input type=hidden name=sessionid value=$form->{sessionid}> +  <input type=hidden name=callback value="$form->{callback}"> +  <input type=hidden name=previousform value="$form->{previousform}"> +  <input type=hidden name=isassemblyitem value=$form->{isassemblyitem}> +  </form> +<a name="end"></a> +  </body>  </html>  |; @@ -1127,8 +1661,7 @@ sub form_footer {  sub makemodel_row {    my ($numrows) = @_; -  $form->{"make_$i"} =~ s/"/"/g; -  $form->{"model_$i"} =~ s/"/"/g; +  map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(make model);    print qq|    <tr> @@ -1143,8 +1676,8 @@ sub makemodel_row {    for $i (1 .. $numrows) {      print qq|  	<tr> -	  <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td> -	  <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td> +	  <td><input name="make_$i" size=30 value="$form->{"make_$i"}"></td> +	  <td><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>  	</tr>  |;    } @@ -1158,49 +1691,225 @@ sub makemodel_row {  } -sub assembly_row { +sub vendor_row {    my ($numrows) = @_; -  @column_index = qw(runningnumber qty unit bom partnumber description partsgroup total); +  $form->{selectvendor} = $form->unescape($form->{selectvendor}); +  print qq| +  <input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|"> -  if ($form->{previous_form}) { -    $nochange = 1; -    @column_index = qw(qty unit bom partnumber description partsgroup total); -  } else { -    # change callback -    $form->{old_callback} = $form->{callback}; -    $callback = $form->{callback}; -    $form->{callback} = "$form->{script}?action=display_form"; +  <tr> +    <td> +      <table width=100%> +	<tr> +	  <th class="listheading">|.$locale->text('Vendor').qq|</th> +	  <th class="listheading">|.$locale->text('Number').qq|</th> +	  <th class="listheading">|.$locale->text('Cost').qq|</th> +	  <th class="listheading">|.$locale->text('Curr').qq|</th> +	  <th class="listheading">|.$locale->text('Leadtime').qq|</th> +	</tr> +|; -    # delete action -    delete $form->{action}; +  for $i (1 .. $numrows) { +     +    $form->{selectcurrency} =~ s/ selected//; +    +    if ($i == $numrows) { +      +      $vendor = qq| +          <td><input name="vendor_$i" size=35 value="$form->{"vendor_$i"}"></td> +|; +  +      if ($form->{selectvendor}) { +	$vendor = qq| +	  <td width=99%><select name="vendor_$i">$form->{selectvendor}</select></td> +|; +      } +    +    } else { +       +      $form->{selectcurrency} =~ s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/; +  +      ($vendor) = split /--/, $form->{"vendor_$i"}; +      $vendor = qq| +          <td>$vendor +	  <input type=hidden name="vendor_$i" value="$form->{"vendor_$i"}"> +	  </td> +|; -    $previous_form = ""; -    # save form variables in a previous_form variable -    foreach $key (sort keys %$form) { -      # escape ampersands -      $form->{$key} =~ s/&/%26/g; -      $previous_form .= qq|$key=$form->{$key}&|;      } -    chop $previous_form; -    $previous_form = $form->escape($form->escape($previous_form, 1)); -    $form->{callback} = $callback; +    +    print qq| +	<tr> +	  $vendor +	  <td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td> +	  <td><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2).qq|></td> +	  <td><select name="vendorcurr_$i">$form->{selectcurrency}</select></td> +	  <td nowrap><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|> <b>|.$locale->text('days').qq|</b></td> +	</tr> +|; +       +  } + +  print qq| +      </table> +    </td> +  </tr> +|; + +} + + +sub customer_row { +  my ($numrows) = @_; + +  if ($form->{selectpricegroup}) { +    $pricegroup = qq| +          <th class="listheading">|.$locale->text('Pricegroup').qq| +          </th> +|; +  } + +  $form->{selectcustomer} = $form->unescape($form->{selectcustomer}); +  $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup}); +   +  print qq| +  <input type=hidden name=selectcurrency value="$form->{selectcurrency}"> +  <input type=hidden name=selectcustomer value="|.$form->escape($form->{selectcustomer},1).qq|"> +  <input type=hidden name=selectpricegroup value="|.$form->escape($form->{selectpricegroup},1).qq|"> +   +  <tr> +    <td> +      <table width=100%> +	<tr> +	  <th class="listheading">|.$locale->text('Customer').qq|</th> +	  $pricegroup +	  <th class="listheading">|.$locale->text('Break').qq|</th> +	  <th class="listheading">|.$locale->text('Sell Price').qq|</th> +	  <th class="listheading">|.$locale->text('Curr').qq|</th> +	  <th class="listheading">|.$locale->text('From').qq|</th> +	  <th class="listheading">|.$locale->text('To').qq|</th> +	</tr> +|; + +  for $i (1 .. $numrows) { +     +    $form->{selectcurrency} =~ s/ selected//; +    $form->{selectcurrency} =~ s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/; +     +    if ($i == $numrows) { +      $customer = qq| +          <td><input name="customer_$i" size=35 value="$form->{"customer_$i"}"></td> +	  |; +   +      if ($form->{selectcustomer}) { +	$customer = qq| +	  <td><select name="customer_$i">$form->{selectcustomer}</select></td> +|; +      } + +      if ($form->{selectpricegroup}) { +	$pricegroup = qq| +	  <td><select name="pricegroup_$i">$form->{selectpricegroup}</select></td> +|; +      } + +    } else { +      ($customer) = split /--/, $form->{"customer_$i"}; +      $customer = qq| +          <td>$customer</td> +	  <input type=hidden name="customer_$i" value="$form->{"customer_$i"}"> +	  |; + +      if ($form->{selectpricegroup}) { +	($pricegroup) = split /--/, $form->{"pricegroup_$i"}; +	$pricegroup = qq| +	  <td>$pricegroup</td> +	  <input type=hidden name="pricegroup_$i" value="$form->{"pricegroup_$i"}"> +|; +      } +    } +     -    $form->{assemblytotal} = 0; -    $form->{weight} = 0; +    print qq| +	<tr> +	  $customer +	  $pricegroup + +	  <td><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td> +	  <td><input name="customerprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"customerprice_$i"}, 2).qq|></td> +	  <td><select name="customercurr_$i">$form->{selectcurrency}</select></td> +	  <td><input name="validfrom_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validfrom_$i"}"></td> +	  <td><input name="validto_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validto_$i"}"></td> +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +|; +} + + + +sub assembly_row { +  my ($numrows) = @_; + +  @column_index = qw(runningnumber qty unit bom adj partnumber description listprice sellprice lastcost); +   +  if ($form->{selectassemblypartsgroup}) { +    $form->{selectassemblypartsgroup} = $form->unescape($form->{selectassemblypartsgroup}); +    @column_index = qw(runningnumber qty unit bom adj partnumber description partsgroup listprice sellprice lastcost); +  } +   +  delete $form->{previousform}; + +  # change callback +  $form->{old_callback} = $form->{callback}; +  $callback = $form->{callback}; +  $form->{callback} = "$form->{script}?action=display_form"; + +  # delete action +  map { delete $form->{$_} } qw(action header); + +  $form->{baseassembly} = 0; +  $previousform = ""; +  # save form variables in a previousform variable +  foreach $key (sort keys %$form) { +    # escape ampersands +    $form->{$key} =~ s/&/%26/g; +    $previousform .= qq|$key=$form->{$key}&|;    } +  chop $previousform; +  $form->{previousform} = $form->escape($previousform, 1); + +  $form->{sellprice} = 0; +  $form->{listprice} = 0; +  $form->{lastcost} = 0; +  $form->{weight} = 0; + +  $form->{callback} = $callback; +    $column_header{runningnumber} = qq|<th nowrap width=5%>|.$locale->text('No.').qq|</th>|;    $column_header{qty} = qq|<th align=left nowrap width=10%>|.$locale->text('Qty').qq|</th>|;    $column_header{unit} = qq|<th align=left nowrap width=5%>|.$locale->text('Unit').qq|</th>|;    $column_header{partnumber} = qq|<th align=left nowrap width=20%>|.$locale->text('Number').qq|</th>|;    $column_header{description} = qq|<th nowrap width=50%>|.$locale->text('Description').qq|</th>|; -  $column_header{total} = qq|<th align=right nowrap>|.$locale->text('Extended').qq|</th>|; +  $column_header{sellprice} = qq|<th align=right nowrap>|.$locale->text('Sell').qq|</th>|; +  $column_header{listprice} = qq|<th align=right nowrap>|.$locale->text('List').qq|</th>|; +  $column_header{lastcost} = qq|<th align=right nowrap>|.$locale->text('Cost').qq|</th>|;    $column_header{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|; +  $column_header{adj} = qq|<th>|.$locale->text('A').qq|</th>|;    $column_header{partsgroup} = qq|<th>|.$locale->text('Group').qq|</th>|;    print qq| +  <p> + +  <table width=100%>    <tr class=listheading>      <th class=listheading>|.$locale->text('Individual Items').qq|</th>    </tr> @@ -1216,61 +1925,58 @@ sub assembly_row {          </tr>  |; +    for $i (1 .. $numrows) { -    $form->{"partnumber_$i"} =~ s/"/"/g; +    $form->{"partnumber_$i"} = $form->quote($form->{"partnumber_$i"}); -    $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2); -    $form->{assemblytotal} += $linetotal; +    $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2); +    $form->{sellprice} += $linetotalsellprice; +    $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, 2); +    $form->{listprice} += $linetotallistprice; + +    $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, 2); +    $form->{lastcost} += $linetotallastcost; + +      $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); -    $linetotal = $form->format_amount(\%myconfig, $linetotal, 2); +    $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, 2); +    $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, 2); +    $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, 2); -    if (($i >= 1) && ($i == $numrows)) { +    if ($i == $numrows) { -      if ($nochange) { -	map { $column_data{$_} = qq|<td></td>| } qw(qty unit partnumber description bom partsgroup); -      } else { -	 -	map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom); -	 -	$column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|; -	$column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|; -	$column_data{description} = qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|; -	$column_data{partsgroup} = qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|; -	 -      } +      map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom adj); + +      $column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|; +      $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|; +      $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|; +      $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectassemblypartsgroup}</select></td>|;      } else { -      if ($form->{previous_form}) { -	$column_data{partnumber} = qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|; -	$column_data{qty} = qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|; - -        $column_data{bom} = qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|; -	$column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " "; -	$column_data{bom} .= qq|</td>|; - -	$column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|; +      $column_data{partnumber} = qq|<td><input class=submit type=submit name=action value=" $form->{"partnumber_$i"}"></td> +      <input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">|; -      } else { -	$href = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&password=$form->{password}&rowcount=$i&previous_form=$previous_form|; -	$column_data{partnumber} = qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|; -	$column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value="$i"}"></td>|; -	$column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|; - -	$form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : ""; -	$column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|; +      $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|; +      $column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|; -	$column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|; +      map { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? "checked" : "" } qw(bom adj); +      $column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|; +      $column_data{adj} = qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|; -      } +      ($partsgroup) = split /--/, $form->{"partsgroup_$i"}; +      $column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;        $column_data{unit} = qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;        $column_data{description} = qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|; +            } -    $column_data{total} = qq|<td align=right>$linetotal</td>|; +    $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|; +    $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|; +    $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;      print qq|          <tr>|; @@ -1281,22 +1987,62 @@ sub assembly_row {          </tr>    <input type=hidden name="id_$i" value=$form->{"id_$i"}>    <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}> +  <input type=hidden name="listprice_$i" value=$form->{"listprice_$i"}> +  <input type=hidden name="lastcost_$i" value=$form->{"lastcost_$i"}>    <input type=hidden name="weight_$i" value=$form->{"weight_$i"}> +  <input type=hidden name="assembly_$i" value=$form->{"assembly_$i"}>  |;    } +  map { $column_data{$_} = "<td> </td>" } @column_index; + +  $column_data{sellprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{sellprice}, 2)."</th>"; +  $column_data{listprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{listprice}, 2)."</th>"; +  $column_data{lastcost} = "<th align=right>".$form->format_amount(\%myconfig, $form->{lastcost}, 2)."</th>"; +      print qq| +        <tr>|; + +  map { print "\n$column_data{$_}" } @column_index; +     +  print qq| +        </tr>        </table>      </td>    </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +  </table> +  <input type=hidden name=assembly_rows value=$form->{assembly_rows}> +  <input type=hidden name=nextsub value=edit_assemblyitem> +  <input type=hidden name=selectassemblypartsgroup value="|.$form->escape($form->{selectassemblypartsgroup},1).qq|">  |;  } +sub edit_assemblyitem { + +  $pn = substr($form->{action}, 1); + +  for ($i = 1; $i < $form->{assembly_rows}; $i++) { +    last if $form->{"partnumber_$i"} eq $pn; +  } + +  $form->error($local->text('unexpected error!')) unless $i; +   +  $form->{baseassembly} = ($form->{baseassembly}) ? $form->{baseassembly} : $form->{"assembly_$i"}; + +  $form->{callback} = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&rowcount=$i&baseassembly=$form->{baseassembly}&isassemblyitem=1&previousform=$form->{previousform}|; + +  $form->redirect; +   +} + +  sub update { -     if ($form->{item} eq "assembly") {      $i = $form->{assembly_rows}; @@ -1314,14 +2060,21 @@ sub update {        if ($rows) {  	$form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); +	$form->{"adj_$i"} = 1;  	if ($rows > 1) {  	  $form->{makemodel_rows}--; +	  $form->{customer_rows}--;  	  &select_item;  	  exit;  	} else { -	  map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit partsgroup); +	  map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);  	  map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + +	  if ($form->{item_list}[0]{partsgroup_id}) { +	    $form->{"partsgroup_$i"} = qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|; +	  } +	    	  $form->{"runningnumber_$i"} = $form->{assembly_rows};  	  $form->{assembly_rows}++; @@ -1338,26 +2091,252 @@ sub update {        }      } -  } + +  } else { -  if ($form->{item} eq "part") {      &check_form; +    } -  if ($form->{item} eq 'service') { -    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice); +} + + +sub check_vendor { +   +  @flds = qw(vendor partnumber lastcost leadtime); +  @a = ();  +  $count = 0;  + +  map { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) } qw(lastcost leadtime); +   +  for $i (1 .. $form->{vendor_rows} - 1) { +     +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(lastcost leadtime); -    &form_header; -    &form_footer; +    if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) { + +      push @a, {}; +      $j = $#a;  +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; + +    }     } +   +  $i = $form->{vendor_rows}; +   +  if (!$form->{selectvendor}) { + +    if ($form->{"vendor_$i"}) { +      ($form->{vendor}) = split /--/, $form->{"vendor_$i"}; +      if (($j = $form->get_name(\%myconfig, vendor)) > 1) { +	&select_name(vendor, $i); +	exit; +      } + +      if ($j == 1) { +	# we got one name +	$form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|; +      } else { +	# name is not on file +	$form->error(qq|$form->{"vendor_$i"} : |.$locale->text('Vendor not on file!')); +      } +    } +  } + +  if ($form->{"vendor_$i"}) { +    push @a, {}; +    $j = $#a;  +    map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +    $count++; +  } + +  $form->redo_rows(\@flds, \@a, $count, $form->{vendor_rows}); +  $form->{vendor_rows} = $count;  } -sub save { +sub check_customer { +   +  @flds = qw(customer validfrom validto pricebreak customerprice pricegroup); +  @a = ();  +  $count = 0; + +  map { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) } qw(customerprice pricebreak); + +  for $i (1 .. $form->{customer_rows} - 1) { + +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(customerprice pricebreak); +     +    if ($form->{"customerprice_$i"}) { +      if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) { +	 +	push @a, {}; +	$j = $#a;  +	map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +	$count++; +	 +      } +    } +  } + +  $i = $form->{customer_rows}; + +  if (!$form->{selectcustomer}) { + +    if ($form->{"customer_$i"}) { +      ($form->{customer}) = split /--/, $form->{"customer_$i"}; + +      if (($j = $form->get_name(\%myconfig, customer)) > 1) { +	&select_name(customer, $i); +	exit; +      } + +      if ($j == 1) { +	# we got one name +	$form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|; +      } else { +	# name is not on file +	$form->error(qq|$form->{customer} : |.$locale->text('Customer not on file!')); +      } +    } +  } + +  if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) { +    push @a, {}; +    $j = $#a;  +    map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +    $count++; +  } + +  $form->redo_rows(\@flds, \@a, $count, $form->{customer_rows}); +  $form->{customer_rows} = $count; + +} + + + +sub select_name { +  my ($table, $vr) = @_; +   +  @column_index = qw(ndx name address); + +  $label = ucfirst $table; +  $column_data{ndx} = qq|<th> </th>|; +  $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|; +  $column_data{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|; +   +  # list items with radio button on a form +  $form->header; + +  $title = $locale->text('Select from one of the names below'); + +  print qq| +<body> + +<form method=post action="$form->{script}#end"> + +<input type=hidden name=vr value=$vr> + +<table width=100%> +  <tr> +    <th class=listtop>$title</th> +  </tr> +  <tr space=5></tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; + +  map { print "\n$column_data{$_}" } @column_index; +   +  print qq| +	</tr> +|; + +  my $i = 0; +  foreach $ref (@{ $form->{name_list} }) { +    $checked = ($i++) ? "" : "checked"; + +    $ref->{name} = $form->quote($ref->{name}); +     +   $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; +   $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|; +   $column_data{address} = qq|<td>$ref->{address1} $ref->{address2} $ref->{city} $ref->{state} $ref->{zipcode} $ref->{country}</td>|; +     +    $j++; $j %= 2; +    print qq| +	<tr class=listrow$j>|; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +	</tr> + +<input name="new_id_$i" type=hidden value=$ref->{id}> + +|; + +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<input name=lastndx type=hidden value=$i> + +|; + +  # delete variables +  map { delete $form->{$_} } qw(action name_list header); + +  $form->hide_form(); +   +  print qq| +<input type=hidden name=nextsub value=name_selected> + +<input type=hidden name=vc value=$table> +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub name_selected { + +  # replace the variable with the one checked + +  # index for new item +  $i = $form->{ndx}; +   +  $form->{"$form->{vc}_$form->{vr}"} = qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|; +  $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"}; + +  # delete all the new_ variables +  for $i (1 .. $form->{lastndx}) { +    map { delete $form->{"new_${_}_$i"} } (id, name); +  } +   +  map { delete $form->{$_} } qw(ndx lastndx nextsub); + +  &update; + +} + -  # check if there is a part number -  $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Number missing!")); +sub save {    if ($form->{obsolete}) {      $form->error($locale->text("Inventory quantity must be zero before you can set this $form->{item} obsolete!")) if ($form->{onhand}); @@ -1366,62 +2345,103 @@ sub save {  # expand dynamic strings  # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')  # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!') -# $locale->text('Part Number missing!') -# $locale->text('Service Number missing!') -# $locale->text('Assembly Number missing!') + +  $olditem = $form->{id};    # save part    $rc = IC->save(\%myconfig, \%$form);    $parts_id = $form->{id}; -   +    # load previous variables -  if ($form->{previous_form}) { -    # save the new form variables before splitting previous_form +  if ($form->{previousform} && !$form->{callback}) { +    # save the new form variables before splitting previousform      map { $newform{$_} = $form->{$_} } keys %$form; -    $previous_form = $form->unescape($form->{previous_form}); +    $previousform = $form->unescape($form->{previousform}); +    $baseassembly = $form->{baseassembly};      # don't trample on previous variables      map { delete $form->{$_} } keys %newform;      # now take it apart and restore original values -    foreach $item (split /&/, $previous_form) { +    foreach $item (split /&/, $previousform) {        ($key, $value) = split /=/, $item, 2;        $value =~ s/%26/&/g;        $form->{$key} = $value;      } +      if ($form->{item} eq 'assembly') { -      # undo formatting -      map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice weight); -      $form->{assembly_rows}--; +      if ($baseassembly) { +	#redo the assembly +	$previousform =~ /\&id=(\d+)/; +	$form->{id} = $1; +	 +	# restore original callback +	$form->{callback} = $form->unescape($form->{old_callback}); + +	&edit; +	exit; +      } +	 +      # undo number formatting +      map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(weight listprice sellprice lastcost rop); + +      $form->{assembly_rows}-- if $olditem;        $i = $newform{rowcount};        $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); +      ($dec) = ($form->{listprice} =~ /\.(\d+)/); +      $dec = length $dec; +      $dec1 = ($dec > 2) ? $dec : 2; +  +      ($dec) = ($form->{sellprice} =~ /\.(\d+)/); +      $dec = length $dec; +      $dec2 = ($dec > 2) ? $dec : 2; +      +      ($dec) = ($form->{lastcost} =~ /\.(\d+)/); +      $dec = length $dec; +      $dec3 = ($dec > 2) ? $dec : 2; + +      $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};        $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"}; +      $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};        $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"}; -       +        # change/add values for assembly item -      map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno partsgroup); +      map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice lastcost inventory_accno income_accno expense_accno); -      # undo string formatting -      map { $form->{"${_}_$i"} =~ s/''/'/g } qw(partnumber description unit bin); +      $form->{listprice} += $form->{"listprice_$i"} * $form->{"qty_$i"}; +      $form->{listprice} = $form->round_amount($form->{listprice}, $dec1); + +      $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"}; +      $form->{sellprice} = $form->round_amount($form->{sellprice}, $dec2); -      $form->{sellprice} += $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2); +      $form->{lastcost} += $form->{"lastcost_$i"} * $form->{"qty_$i"}; +      $form->{lastcost} = $form->round_amount($form->{lastcost}, $dec3); +        $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"}; +      $form->{"adj_$i"} = 1 if !$olditem; + +      $form->{customer_rows}--; +            } else {        # set values for last invoice/order item        $i = $form->{rowcount};        $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); -      map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice); +      map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice partsgroup);        $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});        if ($form->{exchangerate} != 0) { -	$form->{"sellprice_$i"} /= $form->{exchangerate}; +	($dec) = ($newform{sellprice} =~ /\.(\d+)/); +	$dec = length $dec; +	$decimalplaces = ($dec > 2) ? $dec : 2; +	 +	$form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, $decimalplaces);        }        map { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) } split / /, $newform{taxaccounts}; @@ -1431,7 +2451,7 @@ sub save {        $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};        map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});        map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded}; -       +        $form->{creditremaining} -= $amount;      } @@ -1493,19 +2513,25 @@ sub stock_assembly {  <form method=post action=$form->{script}>  <table width="100%"> -  <tr><th class=listtop>$form->{title}</th></tr> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr>    <tr height="5"></tr>    <tr valign=top>      <td> -      <table width="100%"> +      <table>          <tr> -          <th width="1%" align="right" nowrap="true">|.$locale->text('Number').qq|</th> -          <td width="40%"><input name=partnumber size=20></td> +          <th align="right" nowrap="true">|.$locale->text('Number').qq|</th> +          <td><input name=partnumber size=20></td>            <td> </td>          </tr>          <tr>            <th align="right" nowrap="true">|.$locale->text('Description').qq|</th> -          <td colspan="2"><input name=description size=40></td> +          <td><input name=description size=40></td> +        </tr> +        <tr> +          <td></td> +	  <td><input name=checkinventory class=checkbox type=checkbox value=1> |.$locale->text('Check Inventory').qq|</td>          </tr>        </table>      </td> @@ -1513,9 +2539,11 @@ sub stock_assembly {    <tr><td><hr size=3 noshade></td></tr>  </table> +<input type=hidden name=sort value=partnumber> +  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=list_assemblies> @@ -1536,22 +2564,36 @@ sub list_assemblies {    IC->retrieve_assemblies(\%myconfig, \%$form); -  $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|; -  $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|; -  $column_header{bin} = qq|<th class=listheading>|.$locale->text('Bin').qq|</th>|; +  $callback = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}"; +   +  $form->sort_order(); +  $href = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}"; +   +  if ($form->{partnumber}) { +    $callback .= "&partnumber=".$form->escape($form->{partnumber},1); +    $href .= "&partnumber=".$form->escape($form->{partnumber}); +    $form->{sort} = "partnumber" unless $form->{sort}; +  } +  if ($form->{description}) { +    $callback .= "&description=".$form->escape($form->{description},1); +    $href .= "&description=".$form->escape($form->{description}); +    $form->{sort} = "description" unless $form->{sort}; +  } +  +  $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|; +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|; +  $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;    $column_header{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;    $column_header{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;    $column_header{stock} = qq|<th class=listheading>|.$locale->text('Add').qq|</th>|; -  @column_index = (qw(partnumber description bin onhand rop stock)); +  @column_index = $form->sort_columns(qw(partnumber description bin onhand rop stock));    $form->{title} = $locale->text('Stock Assembly'); -  $form->{callback} = "$form->{script}?action=stock_assembly&path=$form->{path}&login=$form->{login}&password=$form->{password}";    $form->header; -  $colspan = $#column_index + 1;    print qq|  <body> @@ -1559,30 +2601,42 @@ sub list_assemblies {  <form method=post action=$form->{script}>  <table width=100%> -  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr>    <tr size=5></tr> -  <tr class=listheading>|; +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|;    map { print "\n$column_header{$_}" } @column_index;    print qq| -  </tr> +	</tr>  |; +  # add sort and escape callback +  $form->{callback} = $callback .= "&sort=$form->{sort}"; + +  # escape callback for href +  $callback = $form->escape($callback); + +    $i = 1;    foreach $ref (@{ $form->{assembly_items} }) { -    map { $ref->{$_} =~ s/"/"/g } qw(partnumber description); +    map { $ref->{$_} = $form->quote($ref->{$_}) } qw(partnumber description); -    # figure out how many to stock -    $form->{"qty_$i"} = $form->format_amount(\%myconfig, $ref->{rop} - $ref->{onhand}); - -    $column_data{partnumber} = qq|<td width=20%>$ref->{partnumber}</td>|; +    $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>"; +          $column_data{description} = qq|<td width=50%>$ref->{description} </td>|;      $column_data{bin} = qq|<td>$ref->{bin} </td>|; -    $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', " ").qq|</td>|; +    $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, "", " ").qq|</td>|;      $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, '', " ").qq|</td>|; -    $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10 value=$form->{"qty_$i"}></td>|; +    $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10 value=|.$form->format_amount(\%myconfig, $ref->{stock}).qq|></td> +    <input type=hidden name="stock_$i" value=$ref->{stock}>|;      $j++; $j %= 2;      print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|; @@ -1590,7 +2644,7 @@ sub list_assemblies {      map { print "\n$column_data{$_}" } @column_index;      print qq| -    </tr> +	</tr>  |;      $i++; @@ -1599,15 +2653,19 @@ sub list_assemblies {    $i--;    print qq| +      </td> +    </table>    <tr> -    <td colspan=6><hr size=3 noshade> +    <td><hr size=3 noshade>    </tr>  </table> +  <input name=rowcount type=hidden value="$i"> +<input type=hidden name=checkinventory value=$form->{checkinventory}>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input name=callback type=hidden value="$form->{callback}"> @@ -1627,6 +2685,11 @@ sub list_assemblies {  sub restock_assemblies { + +  if ($form->{checkinventory}) { +    map { $form->error($locale->text('Quantity exceeds available units to stock!')) if $form->parse_amount($myconfig, $form->{"qty_$_"}) > $form->{"stock_$_"} }(1 .. $form->{rowcount}); +  } +    $form->redirect($locale->text('Assemblies restocked!')) if (IC->restock_assemblies(\%myconfig, \%$form));    $form->error($locale->text('Cannot stock assemblies!')); @@ -1635,4 +2698,9 @@ sub restock_assemblies {  sub continue { &{ $form->{nextsub} } }; +sub add_part { &add }; +sub add_service { &add }; +sub add_assembly { &add }; +sub add_labor_overhead { &add }; + diff --git a/sql-ledger/bin/mozilla/io.pl b/sql-ledger/bin/mozilla/io.pl index 751d9a2ed..22228a9f8 100644 --- a/sql-ledger/bin/mozilla/io.pl +++ b/sql-ledger/bin/mozilla/io.pl @@ -1,6 +1,6 @@  ######################################################################  # SQL-Ledger, Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2002  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -19,7 +19,6 @@  # You should have received a copy of the GNU General Public License  # along with this program; if not, write to the Free Software  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -#  #######################################################################  #  # common routines used in is, ir, oe @@ -71,35 +70,46 @@ if (-f "$form->{path}/$form->{login}_io.pl") {  sub display_row {    my $numrows = shift; -  @column_index = (partnumber, description, qty); -   +  @column_index = qw(runningnumber partnumber description qty); +    if ($form->{type} eq "sales_order") { -    if ($form->{id}) { -      push @column_index, "ship"; -      $column_data{ship} = qq|<th class=listheading align=left width="auto">|.$locale->text('Ship').qq|</th>|; -    } +    push @column_index, "ship"; +    $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;    }    if ($form->{type} eq "purchase_order") { -    if ($form->{id}) { -      push @column_index, "ship"; -      $column_data{ship} = qq|<th class=listheading align=left width="auto">|.$locale->text('Recd').qq|</th>|; -    } +    push @column_index, "ship"; +    $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;    } -   -  push @column_index, qw(unit sellprice); -   -  if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') { -    push @column_index, qw(discount); + +  foreach $item (qw(projectnumber partsgroup)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"};    } -   -  push @column_index, "linetotal"; +       +  if ($form->{language_code} ne $form->{oldlanguage_code}) { +    # rebuild partsgroup +    $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} }); +    if (@ { $form->{all_partsgroup} }) { +      $form->{selectpartsgroup} = "<option>\n"; +      foreach $ref (@ { $form->{all_partsgroup} }) { +	if ($ref->{translation}) { +	  $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|; +	} else { +	  $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|; +	} +      } +    } +    $form->{oldlanguage_code} = $form->{language_code}; +  } +       + +  push @column_index, qw(unit sellprice discount linetotal);    my $colspan = $#column_index + 1; -         $form->{invsubtotal} = 0;    map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); +  $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('No.').qq|</th>|;    $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;    $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;    $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|; @@ -122,45 +132,81 @@ sub display_row {  |; +  $deliverydate = $locale->text('Delivery Date'); +  $serialnumber = $locale->text('Serial No.');    $projectnumber = $locale->text('Project'); -  $runningnumber = $locale->text('No.'); -  $partsgroup = $locale->text('Group'); +  $group = $locale->text('Group'); +  $sku = $locale->text('SKU'); + +  $delvar = 'deliverydate'; -  if ($form->{type} =~ /_order/) { +  if ($form->{type} =~ /_(order|quotation)$/) {      $reqdate = $locale->text('Required by'); -    $delvar = "reqdate"; -  } else { -    $deliverydate = $locale->text('Delivery Date'); -    $delvar = "deliverydate"; +    $delvar = 'reqdate';    } -   -   + +  $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate}); +  $exchangerate = ($exchangerate) ? $exchangerate : 1; +    for $i (1 .. $numrows) {      # undo formatting      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship discount sellprice); - +          ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);      $dec = length $dec;      $decimalplaces = ($dec > 2) ? $dec : 2; + +    if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) { +      # check for a pricematrix +      @a = split / /, $form->{"pricematrix_$i"}; +      if ((scalar @a) > 2 || $form->{currency} ne $form->{oldcurrency}) { +	foreach $item (@a) { +	  ($q, $p) = split /:/, $item; +	  if ($p != 0 && $form->{"qty_$i"} > $q) { +	    $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces); +	  } +	} +      } +    }      $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);      $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);      $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2); -    # convert " to " -    map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); +    map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit); +     +    $skunumber = qq| +                <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"}); + +     +    if ($form->{selectpartsgroup}) { +      if ($i < $numrows) { +	$partsgroup = qq| +	      <p><b>$group</b> +	      <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|; +	($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"}; +	$partsgroup .= $form->{"partsgroup_$i"}; +	$partsgroup = "" unless $form->{"partsgroup_$i"}; +      } +    } -    $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>|; +    $delivery = qq| +	  <b>${$delvar}</b> +	  <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"> +|; + +    $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|; +    $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}">$skunumber</td>|; -    if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) { -      $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=30 wrap=soft>$form->{"description_$i"}</textarea></td>|; +    if (($rows = $form->numtextrows($form->{"description_$i"}, 25, 6)) > 1) { +      $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=25 wrap=soft>$form->{"description_$i"}</textarea>$partsgroup</td>|;      } else { -      $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|; +      $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}">$partsgroup</td>|;      }      $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;      $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|; -    $column_data{unit} = qq|<td><input name="unit_$i" size=5 maxsize=5 value="$form->{"unit_$i"}"></td>|; +    $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;      $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;      $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;      $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|; @@ -174,44 +220,66 @@ sub display_row {      print qq|          </tr> +<input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}> +  <input type=hidden name="id_$i" value=$form->{"id_$i"}>  <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>  <input type=hidden name="bin_$i" value="$form->{"bin_$i"}"> +<input type=hidden name="weight_$i" value="$form->{"weight_$i"}">  <input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}>  <input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}>  <input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}">  <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">  <input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}"> +<input type=hidden name="pricematrix_$i" value="$form->{"pricematrix_$i"}"> +<input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}"> +<input type=hidden name="sku_$i" value="$form->{"sku_$i"}">  |; +    $form->{selectprojectnumber} =~ s/ selected//; +    $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/; + +    $project = qq| +                <b>$projectnumber</b> +		<select name="projectnumber_$i">$form->{selectprojectnumber}</select> +| if $form->{selectprojectnumber}; + +    $serial = qq| +                <b>$serialnumber</b> <input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}">| if $form->{type} !~ /_quotation/; +		 +    $partsgroup = ""; +    if ($i == $numrows) { +      if ($form->{selectpartsgroup}) { +	$partsgroup = qq| +	        <b>$group</b> +		<select name="partsgroup_$i">$form->{selectpartsgroup}</select> +|; +      } + +      $serial = ""; +      $project = ""; +      $delivery = "" +    } + +	      # print second row      print qq|          <tr>  	  <td colspan=$colspan> -	    <table> -	      <tr> -                <th>$runningnumber</th> -		<td><input name="runningnumber_$i" size=3 value=$i></td> -		<td width=20></td> -	        <th>$partsgroup</th> -		<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"> -	        <th>${$delvar}</th> -		<td><input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td> -	        <th>$projectnumber</th> -		<td><input name="projectnumber_$i" size=10 value="$form->{"projectnumber_$i"}"> -		    <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"> -		    <input type=hidden name="project_id_$i" value="$form->{"project_id_$i"}"></td> -	      </tr> -	    </table> +	  $delivery +	  $serial +	  $project +	  $partsgroup  	  </td>  	</tr>  	<tr>  	  <td colspan=$colspan><hr size=1 noshade></td>  	</tr>  |; -   +    $skunumber = ""; +          map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"});      $form->{invsubtotal} += $linetotal; @@ -223,65 +291,101 @@ sub display_row {    </tr>  |; +  print qq| + +<input type=hidden name=oldcurrency value=$form->{currency}> +<input type=hidden name=audittrail value="$form->{audittrail}"> + +<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|"> +<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|"> +|; +   }  sub select_item { -   -  @column_index = qw(ndx partnumber description onhand sellprice); + +  if ($form->{vc} eq "vendor") { +    @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice); +  } else { +    @column_index = qw(ndx partnumber description partsgroup onhand sellprice); +  }    $column_data{ndx} = qq|<th> </th>|;    $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|; +  $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;    $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|; +  $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;    $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;    $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|; -   +  $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; +    # list items with radio button on a form    $form->header;    $title = $locale->text('Select from one of the items below'); -  $colspan = $#column_index + 1;    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end">  <table width=100%>    <tr> -    <th class=listtop colspan=$colspan>$title</th> +    <th class=listtop>$title</th>    </tr>    <tr height="5"></tr> -  <tr class=listheading>|; +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading>|;    map { print "\n$column_data{$_}" } @column_index; -  print qq|</tr>|; +  print qq| +        </tr> +|;    my $i = 0;    foreach $ref (@{ $form->{item_list} }) {      $checked = ($i++) ? "" : "checked"; -    map { $ref->{$_} =~ s/"/"/g } qw(partnumber description unit); +    map { $ref->{$_} = $form->quote($ref->{$_}) } qw(sku partnumber description unit); + +    $ref->{sellprice} = $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);      $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; -    $column_data{partnumber} = qq|<td><input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">$ref->{partnumber}</td>|; -    $column_data{description} = qq|<td><input name="new_description_$i" type=hidden value="$ref->{description}">$ref->{description}</td>|; -    $column_data{sellprice} = qq|<td align=right><input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ").qq|</td>|; -    $column_data{onhand} = qq|<td align=right><input name="new_onhand_$i" type=hidden value=$ref->{onhand}>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', " ").qq|</td>|; +    $column_data{partnumber} = qq|<td>$ref->{partnumber}</td>|; +    $column_data{sku} = qq|<td>$ref->{sku}</td>|; +    $column_data{description} = qq|<td>$ref->{description}</td>|; +    $column_data{partsgroup} = qq|<td>$ref->{partsgroup}</td>|; +    $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, " ").qq|</td>|; +    $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', " ").qq|</td>|;      $j++; $j %= 2;      print qq| -<tr class=listrow$j>|; +        <tr class=listrow$j>|;      map { print "\n$column_data{$_}" } @column_index;      print qq| -</tr> +        </tr> +<input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}"> +<input name="new_sku_$i" type=hidden value="$ref->{sku}"> +<input name="new_description_$i" type=hidden value="$ref->{description}"> +<input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}"> +<input name="new_partsgroup_id_$i" type=hidden value="$ref->{partsgroup_id}">  <input name="new_bin_$i" type=hidden value="$ref->{bin}"> +<input name="new_weight_$i" type=hidden value=$ref->{weight}> +<input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>  <input name="new_listprice_$i" type=hidden value=$ref->{listprice}> +<input name="new_lastcost_$i" type=hidden value=$ref->{lastcost}> +<input name="new_onhand_$i" type=hidden value=$ref->{onhand}>  <input name="new_inventory_accno_$i" type=hidden value=$ref->{inventory_accno}>  <input name="new_income_accno_$i" type=hidden value=$ref->{income_accno}>  <input name="new_expense_accno_$i" type=hidden value=$ref->{expense_accno}> @@ -289,7 +393,7 @@ sub select_item {  <input name="new_weight_$i" type=hidden value="$ref->{weight}">  <input name="new_assembly_$i" type=hidden value="$ref->{assembly}">  <input name="new_taxaccounts_$i" type=hidden value="$ref->{taxaccounts}"> -<input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}"> +<input name="new_pricematrix_$i" type=hidden value="$ref->{pricematrix}">  <input name="new_id_$i" type=hidden value=$ref->{id}> @@ -298,7 +402,12 @@ sub select_item {    }    print qq| -<tr><td colspan=8><hr size=3 noshade></td></tr> +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr>  </table>  <input name=lastndx type=hidden value=$i> @@ -306,15 +415,10 @@ sub select_item {  |;    # delete action variable -  delete $form->{action}; -  delete $form->{item_list}; -     -  # save all other form variables -  foreach $key (keys %${form}) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input name=$key type=hidden value="$form->{$key}">\n|; -  } +  map { delete $form->{$_} } qw(action item_list header); +  $form->hide_form(); +      print qq|  <input type=hidden name=nextsub value=item_selected> @@ -342,7 +446,9 @@ sub item_selected {    # if there was a price entered, override it    $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); -  map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber description sellprice listprice inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts partsgroup); +  map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(id partnumber sku description sellprice listprice lastcost inventory_accno income_accno expense_accno bin unit weight assembly taxaccounts pricematrix); + +  $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);    $dec = length $dec; @@ -358,7 +464,12 @@ sub item_selected {      }    } -  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice weight); +  if (($form->{exchangerate} * 1) != 0) { +    map { $form->{"${_}_$i"} /= $form->{exchangerate} } qw(listprice lastcost); +  } +   +  # this is for the assembly +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice weight);    $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});    $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"}); @@ -373,25 +484,25 @@ sub item_selected {    # delete all the new_ variables    for $i (1 .. $form->{lastndx}) { -    map { delete $form->{"new_${_}_$i"} } qw(partnumber description sellprice bin listprice inventory_accno income_accno expense_accno unit assembly taxaccounts id); +    map { delete $form->{"new_${_}_$i"} } qw(partnumber sku description sellprice bin listprice lastcost inventory_accno income_accno expense_accno unit assembly taxaccounts id pricematrix weight);    }    map { delete $form->{$_} } qw(ndx lastndx nextsub); -  if ($form->{item} eq 'assembly') { -    map { $form->{"qty_$_"} = $form->parse_amount(\%myconfig, $form->{"qty_$_"}) } (1 .. $i); -  } else { -    # format amounts for invoice / order -    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice); -  } +  # format amounts +  map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost) if $form->{item} ne 'assembly';    &display_form; -   +  }  sub new_item { +  if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) { +    $form->error($locale->text('Translation not on file!')); +  } +      # change callback    $form->{old_callback} = $form->escape($form->{callback},1);    $form->{callback} = $form->escape("$form->{script}?action=display_form",1); @@ -399,27 +510,31 @@ sub new_item {    # delete action    delete $form->{action}; -  # save all other form variables in a previous_form variable -  foreach $key (keys %$form) { -    # escape ampersands -    $form->{$key} =~ s/&/%26/g; -    $previous_form .= qq|$key=$form->{$key}&|; +  # save all other form variables in a previousform variable +  if (!$form->{previousform}) { +    foreach $key (keys %$form) { +      # escape ampersands +      $form->{$key} =~ s/&/%26/g; +      $form->{previousform} .= qq|$key=$form->{$key}&|; +    } +    chop $form->{previousform}; +    $form->{previousform} = $form->escape($form->{previousform}, 1);    } -  chop $previous_form; -  $previous_form = $form->escape($previous_form, 1);    $i = $form->{rowcount}; -  map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description); +  map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber description);    $form->header;    print qq|  <body> -<h4 class=error>|.$locale->text('Item not on file!').qq| +<h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|; -<p> -|.$locale->text('What type of item is this?').qq|</h4> +  if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) { + +    print qq| +<h4>|.$locale->text('What type of item is this?').qq|</h4>  <form method=post action=ic.pl> @@ -430,21 +545,24 @@ sub new_item {    <input class=radio type=radio name=item value=service> |.$locale->text('Service')  .qq| -<input type=hidden name=previous_form value="$previous_form"> +<input type=hidden name=previousform value="$form->{previousform}">  <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">  <input type=hidden name=description value="$form->{"description_$i"}">  <input type=hidden name=rowcount value=$form->{rowcount}>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=hidden name=nextsub value=add>  <p>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">  </form> +|; +  } +  print qq|  </body>  </html>  |; @@ -455,26 +573,40 @@ sub new_item {  sub display_form { +  # if we have a display_form +  if ($form->{display_form}) { +    &{ "$form->{display_form}" }; +    exit; +  } +      &form_header;    $numrows = ++$form->{rowcount};    $subroutine = "display_row";    if ($form->{item} eq 'part') { -    $numrows = ++$form->{makemodel_rows}; -    $subroutine = "makemodel_row"; +    # create makemodel rows +    &makemodel_row(++$form->{makemodel_rows}); + +    &vendor_row(++$form->{vendor_rows}); +     +    $numrows = ++$form->{customer_rows}; +    $subroutine = "customer_row";    }    if ($form->{item} eq 'assembly') { -    $numrows = ++$form->{makemodel_rows}; -    $subroutine = "makemodel_row"; -        # create makemodel rows -    &{ $subroutine }($numrows); - -    $numrows = ++$form->{assembly_rows}; -    $subroutine = "assembly_row"; +    &makemodel_row(++$form->{makemodel_rows}); +     +    $numrows = ++$form->{customer_rows}; +    $subroutine = "customer_row";    }    if ($form->{item} eq 'service') { +    &vendor_row(++$form->{vendor_rows}); +     +    $numrows = ++$form->{customer_rows}; +    $subroutine = "customer_row"; +  } +  if ($form->{item} eq 'labor') {      $numrows = 0;    } @@ -491,17 +623,23 @@ sub check_form {    my @a = ();    my $count = 0; -  my @flds = (qw(id partnumber description qty sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber project_id oldprojectnumber runningnumber partsgroup)); +  my $i; +  my $j; +  my @flds = qw(id partnumber sku description qty ship sellprice unit discount inventory_accno income_accno expense_accno listprice taxaccounts bin assembly weight projectnumber runningnumber serialnumber partsgroup reqdate pricematrix);    # remove any makes or model rows    if ($form->{item} eq 'part') { -    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop); +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop markup); -    @flds = (make, model); -    for my $i (1 .. ($form->{makemodel_rows})) { +    &calc_markup; +     +    @flds = qw(make model); +    $count = 0; +    @a = (); +    for $i (1 .. $form->{makemodel_rows}) {        if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {  	push @a, {}; -	my $j = $#a; +	$j = $#a;  	map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;  	$count++; @@ -511,13 +649,30 @@ sub check_form {      $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});      $form->{makemodel_rows} = $count; -  } elsif ($form->{item} eq 'assembly') { +    &check_vendor; +    &check_customer; +     +  } elsif ($form->{item} eq 'service') { +     +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice lastcost markup); +     +    &calc_markup; +    &check_vendor; +    &check_customer; +  } elsif ($form->{item} eq 'assembly') { +      $form->{sellprice} = 0;      $form->{weight} = 0; -    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice rop); +    $form->{lastcost} = 0; +    $form->{listprice} = 0; +     +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(rop stock markup); -    @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup); +    +    @flds = qw(id qty unit bom adj partnumber description sellprice listprice weight runningnumber partsgroup); +    $count = 0; +    @a = ();      for my $i (1 .. ($form->{assembly_rows} - 1)) {        if ($form->{"qty_$i"}) { @@ -528,13 +683,18 @@ sub check_form {  	map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; -	$form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"}); -	$form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"}); +        map { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) } qw(sellprice listprice weight lastcost); +	  	$count++;        }      } -    $form->{sellprice} = $form->round_amount($form->{sellprice}, 2); +    if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) { +      $form->{sellprice} = 0; +      &calc_markup; +    } +  +    map { $form->{$_} = $form->round_amount($form->{$_}, 2) } qw(sellprice lastcost listprice);      $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});      $form->{assembly_rows} = $count; @@ -556,11 +716,15 @@ sub check_form {      $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});      $form->{makemodel_rows} = $count; +    &check_customer; +      } else {      # this section applies to invoices and orders      # remove any empty numbers +    $count = 0; +    @a = ();      if ($form->{rowcount}) {        for my $i (1 .. $form->{rowcount} - 1) {  	if ($form->{"partnumber_$i"}) { @@ -585,6 +749,28 @@ sub check_form {  } +sub calc_markup { + +  if ($form->{markup}) { +    if ($form->{markup} != $form->{oldmarkup}) { +      if ($form->{lastcost}) { +	$form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100); +	$form->{sellprice} = $form->round_amount($form->{sellprice}, 2); +      } else { +	$form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100); +	$form->{lastcost} = $form->round_amount($form->{lastcost}, 2); +      } +    } +  } else { +    if ($form->{lastcost}) { +      $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1); +    } +    $form->{markup} = "" if $form->{markup} == 0; +  } + +} + +  sub invoicetotal {    $form->{oldinvtotal} = 0; @@ -631,60 +817,100 @@ sub validate_items {  } -sub order { -  $form->{ordnumber} = $form->{invnumber}; +sub purchase_order { +   +  $form->{title} = $locale->text('Add Purchase Order'); +  $form->{vc} = 'vendor'; +  $form->{type} = 'purchase_order'; +  $buysell = 'sell'; -  $form->{id} = ''; +  &create_form; -  if ($form->{script} eq 'ir.pl') { -    $form->{title} = $locale->text('Add Purchase Order'); -    $form->{vc} = 'vendor'; -    $form->{type} = 'purchase_order'; -    $buysell = 'sell'; -  } -  if ($form->{script} eq 'is.pl') { -    $form->{title} = $locale->text('Add Sales Order'); -    $form->{vc} = 'customer'; -    $form->{type} = 'sales_order'; -    $buysell = 'buy'; -  } +} + +  +sub sales_order { + +  $form->{title} = $locale->text('Add Sales Order'); +  $form->{vc} = 'customer'; +  $form->{type} = 'sales_order'; +  $buysell = 'buy'; + +  &create_form; + +} + + +sub rfq { +   +  $form->{title} = $locale->text('Add Request for Quotation'); +  $form->{vc} = 'vendor'; +  $form->{type} = 'request_quotation'; +  $buysell = 'sell'; +  +  &create_form; +   +} + + +sub quotation { + +  $form->{title} = $locale->text('Add Quotation'); +  $form->{vc} = 'customer'; +  $form->{type} = 'sales_quotation'; +  $buysell = 'buy'; + +  &create_form; + +} + + +sub create_form { + +  map { delete $form->{$_} } qw(id printed emailed queued); +     $form->{script} = 'oe.pl';    $form->{shipto} = 1; -   -  $form->{rowcount}--; + +  $form->{rowcount}-- if $form->{rowcount};    require "$form->{path}/$form->{script}";    map { $form->{"select$_"} = "" } ($form->{vc}, currency); -  $currency = $form->{currency}; -   +  map { $temp{$_} = $form->{$_} } qw(currency employee department intnotes notes language_code); +    &order_links; -  $form->{currency} = $currency; +  map { $form->{$_} = $temp{$_} if $temp{$_} } keys %temp; +    $form->{exchangerate} = "";    $form->{forex} = ""; -  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{orddate}, $buysell)));  +  if ($form->{currency} ne $form->{defaultcurrency}) { +    $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell))); +  }    &prepare_order; +    &display_form;  } -sub e_mail { +sub e_mail { -  if ($myconfig{admin}) { +  $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|; +  if ($myconfig{role} =~ /(admin|manager)/) {      $bcc = qq|   	  <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>  	  <td><input name=bcc size=30 value="$form->{bcc}"></td>  |;    } -  if ($form->{type} eq 'packing_list') { +  if ($form->{formname} =~ /(pick|packing|bin)_list/) {      $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};    } @@ -692,15 +918,12 @@ sub e_mail {    $name =~ s/--.*//g;    $title = $locale->text('E-mail')." $name"; -  $form->{oldmedia} = $form->{media}; -  $form->{media} = "email"; -      $form->header;    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end">  <table width=100%>    <tr class=listtop> @@ -711,7 +934,7 @@ sub e_mail {      <td>        <table width=100%>  	<tr> -	  <th align=right nowrap>|.$locale->text('To').qq|</th> +	  <th align=right nowrap>|.$locale->text('E-mail').qq|</th>  	  <td><input name=email size=30 value="$form->{email}"></td>  	  <th align=right nowrap>|.$locale->text('Cc').qq|</th>  	  <td><input name=cc size=30 value="$form->{cc}"></td> @@ -740,15 +963,15 @@ sub e_mail {      <td>  |; +  $form->{oldmedia} = $form->{media}; +  $form->{media} = "email"; +  $form->{format} = "pdf"; +      &print_options; -  map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format); +  map { delete $form->{$_} } qw(action email cc bcc subject message formname sendmode format header); -  # save all other variables -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|      </td> @@ -774,8 +997,10 @@ sub e_mail {  sub send_email {    $old_form = new Form; +      map { $old_form->{$_} = $form->{$_} } keys %$form; -  $old_form->{media} = $form->{oldmedia}; +  $old_form->{media} = $old_form->{oldmedia}; +      &print_form($old_form);  } @@ -785,232 +1010,482 @@ sub send_email {  sub print_options {    $form->{sendmode} = "attachment"; -  $form->{copies} = 3 unless $form->{copies}; +  $form->{copies} = 1 unless $form->{copies}; -  $form->{PD}{$form->{type}} = "checked"; -  $form->{DF}{$form->{format}} = "checked"; -  $form->{OP}{$form->{media}} = "checked"; -  $form->{SM}{$form->{sendmode}} = "checked"; +  $form->{PD}{$form->{formname}} = "selected"; +  $form->{DF}{$form->{format}} = "selected"; +  $form->{SM}{$form->{sendmode}} = "selected"; -  if ($form->{type} =~ /_order/) { -    $order = qq| -	  <td align=right><input class=radio type=radio name=type value="$`_order" $form->{PD}{"$`_order"}></td><td>|.$locale->text('Order').qq|</td> -|; -  } else { -    $invoice = qq| -	  <td align=right><input class=radio type=radio name=type value=invoice $form->{PD}{invoice}></td><td>|.$locale->text('Invoice').qq|</td> -	  <td align=right><input class=radio type=radio name=type value=packing_list $form->{PD}{packing_list}></td><td>|.$locale->text('Packing List').qq|</td> -|; +  if ($form->{selectlanguage}) { +    $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"}); +    $form->{"selectlanguage"} =~ s/ selected//; +    $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/; +    $lang = qq|<td><select name=language_code>$form->{selectlanguage}</select></td> +    <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}> +    <input type=hidden name=selectlanguage value="|. +    $form->escape($form->{selectlanguage},1).qq|">|;    } - +   +  if ($form->{type} eq 'purchase_order') { +    $type = qq|<td><select name=formname> +	    <option value=purchase_order $form->{PD}{purchase_order}>|.$locale->text('Purchase Order').qq| +	    <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List').qq|</select></td>|; +  } +   +  if ($form->{type} eq 'sales_order') { +    $type = qq|<td><select name=formname> +	    <option value=sales_order $form->{PD}{sales_order}>|.$locale->text('Sales Order').qq| +	    <option value=work_order $form->{PD}{work_order}>|.$locale->text('Work Order').qq| +	    <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq| +	    <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|; +  } +   +  if ($form->{type} =~ /_quotation$/) { +    $type = qq|<td><select name=formname> +	    <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|.$locale->text('Quotation').qq|</select></td>|; +  } +   +  if ($form->{type} eq 'invoice') { +    $type = qq|<td><select name=formname> +	    <option value=invoice $form->{PD}{invoice}>|.$locale->text('Invoice').qq| +	    <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq| +	    <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|; +  } +   +  if ($form->{type} eq 'ship_order') { +    $type = qq|<td><select name=formname> +	    <option value=pick_list $form->{PD}{pick_list}>|.$locale->text('Pick List').qq| +	    <option value=packing_list $form->{PD}{packing_list}>|.$locale->text('Packing List').qq|</select></td>|; +  } +   +  if ($form->{type} eq 'receive_order') { +    $type = qq|<td><select name=formname> +	    <option value=bin_list $form->{PD}{bin_list}>|.$locale->text('Bin List').qq|</select></td>|; +  } +     if ($form->{media} eq 'email') { -    $email = qq| -	<td align=center><input class=radio type=radio name=sendmode value=attachment $form->{SM}{attachment}> |.$locale->text('Attachment') -	.qq| <input class=radio type=radio name=sendmode value=inline $form->{SM}{inline}> |.$locale->text('In-line').qq|</td> -|; +    $media = qq|<td><select name=sendmode> +	    <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq| +	    <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select></td>|;    } else { -    $screen = qq| -	<td align=right><input class=radio type=radio name=media value=screen $form->{OP}{screen}></td> -	<td>|.$locale->text('Screen').qq|</td> -|; +    $media = qq|<td><select name=media> +	    <option value=screen>|.$locale->text('Screen'); +    if (%printer && $latex) { +      map { $media .= qq| +            <option value="$_">$_| } sort keys %printer; +    } +    if ($latex) { +      $media .= qq| +            <option value="queue">|.$locale->text('Queue'); +    } +    $media .= qq|</select></td>|; + +    # set option selected +    $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; +     } -  print qq| -<table width=100%> -  <tr valign=top> -    $invoice -    $order -    <td align=right><input class=radio type=radio name=format value=html $form->{DF}{html}></td> -    <td>html</td> -|; +  $format = qq|<td><select name=format> +            <option value=html $form->{DF}{html}>html|; + +#	    <option value=txt $form->{DF}{txt}>txt|;    if ($latex) { -      print qq| -    <td align=right><input class=radio type=radio name=format value=postscript $form->{DF}{postscript}></td> -    <td>|.$locale->text('Postscript').qq|</td> -    <td align=right><input class=radio type=radio name=format value=pdf $form->{DF}{pdf}></td> -    <td>|.$locale->text('PDF').qq|</td> -|; +    $format .= qq| +            <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq| +	    <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');    } +  $format .= qq|</select></td>|;    print qq| -    $screen +<table width=100% cellspacing=0 cellpadding=0> +  <tr> +    <td> +      <table> +	<tr> +	  $type +	  $lang +	  $format +	  $media  |; -  if ($screen) { -    if ($myconfig{printer} && $latex) { -      print qq| -    <td align=right><input class=radio type=radio name=media value=printer $form->{OP}{printer}></td> -    <td>|.$locale->text('Printer') -    .qq| (|.$locale->text('Copies') -    .qq| <input name=copies size=2 value=$form->{copies}>)</td> +  if (%printer && $latex && $form->{media} ne 'email') { +    print qq| +	  <td>|.$locale->text('Copies').qq| +	  <input name=copies size=2 value=$form->{copies}></td>  |; -    }    } +  $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber}; +  $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup}; + +  print qq| +          <td>|.$locale->text('Group Items').qq|</td> +          <td> +	  <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}> +	  |.$locale->text('Project').qq| +	  <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}> +	  |.$locale->text('Group').qq| +	  </td> +        </tr> +      </table> +    </td> +    <td align=right> +|; + +  if ($form->{printed} =~ /$form->{formname}/) { +    print $locale->text('Printed').qq|<br>|; +  } +   +  if ($form->{emailed} =~ /$form->{formname}/) { +    print $locale->text('E-mailed').qq|<br>|; +  } -  $form->{groupitems} = "checked" if $form->{groupitems}; +  if ($form->{queued} =~ /$form->{formname}/) { +    print $locale->text('Queued'); +  }    print qq| -    $email -    <td align=right><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td> -    <td>|.$locale->text('Group Items').qq|</td> +    </td>    </tr>  </table>  |; +  } +  sub print { -   +    # if this goes to the printer pass through -  if ($form->{media} eq 'printer') { -    $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/); +  if ($form->{media} !~ /(screen|email)/) { +    $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);      $old_form = new Form;      map { $old_form->{$_} = $form->{$_} } keys %$form; +        } - +       &print_form($old_form);  }  sub print_form { -  my $old_form = shift; -   +  my ($old_form) = @_; +    $inv = "inv";    $due = "due"; -  if ($form->{type} eq "invoice") { +  $numberfld = "sinumber"; + +  $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form"; + +  if ($form->{formname} eq "invoice") {      $form->{label} = $locale->text('Invoice');    } -  if ($form->{type} eq "packing_list") { -    $form->{label} = $locale->text('Packing List'); -  } -  if ($form->{type} eq 'sales_order') { +  if ($form->{formname} eq 'sales_order') {      $inv = "ord";      $due = "req";      $form->{label} = $locale->text('Sales Order'); +    $numberfld = "sonumber"; +    $order = 1;    } -  if ($form->{type} eq 'purchase_order') { +  if ($form->{formname} eq 'work_order') { +    $inv = "ord"; +    $due = "req"; +    $form->{label} = $locale->text('Work Order'); +    $numberfld = "sonumber"; +    $order = 1; +  } +  if ($form->{formname} eq 'packing_list') { +    # we use the same packing list as from an invoice +    $form->{label} = $locale->text('Packing List'); + +    if ($form->{type} ne 'invoice') { +      $inv = "ord"; +      $due = "req"; +      $numberfld = "sonumber"; +      $order = 1; +    } +  } +  if ($form->{formname} eq 'pick_list') { +    $form->{label} = $locale->text('Pick List'); +    if ($form->{type} ne 'invoice') { +      $inv = "ord"; +      $due = "req"; +      $order = 1; +      $numberfld = "sonumber"; +    } +  } +  if ($form->{formname} eq 'purchase_order') {      $inv = "ord";      $due = "req";      $form->{label} = $locale->text('Purchase Order'); +    $numberfld = "ponumber"; +    $order = 1; +  } +  if ($form->{formname} eq 'bin_list') { +    $inv = "ord"; +    $due = "req"; +    $form->{label} = $locale->text('Bin List'); +    $numberfld = "ponumber"; +    $order = 1; +  } +  if ($form->{formname} eq 'sales_quotation') { +    $inv = "quo"; +    $due = "req"; +    $form->{label} = $locale->text('Quotation'); +    $numberfld = "sqnumber"; +    $order = 1; +  } +  if ($form->{formname} eq 'request_quotation') { +    $inv = "quo"; +    $due = "req"; +    $form->{label} = $locale->text('Quotation'); +    $numberfld = "rfqnumber"; +    $order = 1;    } +   +  $form->{"${inv}date"} = $form->{transdate};    $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email'); -  $form->isblank("${inv}number", $locale->text($form->{label} .' Number missing!'));    $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!')); +  # get next number +  if (! $form->{"${inv}number"}) { +    $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld); +    if ($form->{media} eq 'screen') { +      &update; +      exit; +    } +  } + +  # $locale->text('Invoice Number missing!')  # $locale->text('Invoice Date missing!')  # $locale->text('Packing List Number missing!')  # $locale->text('Packing List Date missing!')  # $locale->text('Order Number missing!')  # $locale->text('Order Date missing!') +# $locale->text('Quotation Number missing!') +# $locale->text('Quotation Date missing!')    &validate_items;    &{ "$form->{vc}_details" };    @a = (); -  map { push @a, ("partnumber_$_", "description_$_") } (1 .. $form->{rowcount}); +  foreach $i (1 .. $form->{rowcount}) { +    push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i"); +  }    map { push @a, "${_}_description" } split / /, $form->{taxaccounts}; -  $form->format_string(@a); +  $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP"; +  push @a, $ARAP; +      # format payment dates -  map { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}) } (1 .. $form->{paidaccounts}); +  for $i (1 .. $form->{paidaccounts} - 1) { +    if (exists $form->{longformat}) { +      $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat}); +    } +     +    push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i"; +  } +   +  $form->format_string(@a); -  # create the form variables for the invoice, packing list or order -  if ($form->{type} =~ /order$/) { +  ($form->{employee}) = split /--/, $form->{employee}; +  ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse}; +   +  # this is a label for the subtotals +  $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription}; +  delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal}; + +  # create the form variables +  if ($order) {      OE->order_details(\%myconfig, \%$form);    } else {      IS->invoice_details(\%myconfig, \%$form);    } -  $form->{"${inv}date"} = $locale->date(\%myconfig, $form->{"${inv}date"}, 1); -  $form->{"${due}date"} = $locale->date(\%myconfig, $form->{"${due}date"}, 1); -   +  if (exists $form->{longformat}) { +    map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) } ("${inv}date", "${due}date", "shippingdate", "transdate"); +  } -  @a = qw(name addr1 addr2 addr3 addr4); +  @a = qw(name address1 address2 city state zipcode country); -  $fillshipto = 1; +  $shipto = 1;    # if there is no shipto fill it in from billto    foreach $item (@a) {      if ($form->{"shipto$item"}) { -      $fillshipto = 0; +      $shipto = 0;        last;      }    } -  if ($fillshipto) { -    if ($form->{type} eq 'purchase_order') { +  if ($shipto) { +    if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {  	$form->{shiptoname} = $myconfig{company}; -	$form->{shiptoaddr1} = $myconfig{address}; +	$form->{shiptoaddress1} = $myconfig{address};      } else { -      map { $form->{"shipto$_"} = $form->{$_} } @a; +      if ($form->{formname} !~ /bin_list/) { +	map { $form->{"shipto$_"} = $form->{$_} } @a; +      }      }    }    $form->{notes} =~ s/^\s+//g;    # some of the stuff could have umlauts so we translate them -  push @a, qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shippingpoint company address signature notes); +  push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes employee warehouse); -  push @a, ("${inv}date", "${due}date"); +  push @a, ("${inv}number", "${inv}date", "${due}date", "email", "cc", "bcc"); +  map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax signature businessnumber)); +  map { $form->{"user$_"} = $myconfig{$_} } qw(name email); +  push @a, qw(company address tel fax signature businessnumber username useremail); +    $form->format_string(@a);    $form->{templates} = "$myconfig{templates}"; -  $form->{IN} = "$form->{type}.html"; +  $form->{IN} = "$form->{formname}.$form->{format}"; -  if ($form->{format} eq 'postscript') { -    $form->{postscript} = 1; -    $form->{IN} =~ s/html$/tex/; -  } -  if ($form->{format} eq 'pdf') { -    $form->{pdf} = 1; -    $form->{IN} =~ s/html$/tex/; +  if ($form->{format} =~ /(postscript|pdf)/) { +    $form->{IN} =~ s/$&$/tex/;    } -  $form->format_string(email, shiptoemail, cc, bcc) if $form->{format} =~ /(pdf|postscript)/; -   -  if ($form->{media} eq 'printer') { -    $form->{OUT} = "| $myconfig{printer}"; +  $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt'; + +  if ($form->{media} !~ /(screen|queue|email)/) { +    $form->{OUT} = "| $printer{$form->{media}}"; +     +    if ($form->{printed} !~ /$form->{formname}/) { +     +      $form->{printed} .= " $form->{formname}"; +      $form->{printed} =~ s/^ //; + +      $form->update_status(\%myconfig); +    } + +    $old_form->{printed} = $form->{printed}; + +    %audittrail = ( tablename	=> ($order) ? 'oe' : lc $ARAP, +                    reference	=> $form->{"${inv}number"}, +		    formname	=> $form->{formname}, +		    action	=> 'printed', +		    id		=> $form->{id} ); +  +    $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); +        } +    if ($form->{media} eq 'email') {      $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject}; -     + +    $form->{plainpaper} = 1;      $form->{OUT} = "$sendmail"; + +    if ($form->{emailed} !~ /$form->{formname}/) { +      $form->{emailed} .= " $form->{formname}"; +      $form->{emailed} =~ s/^ //; + +      # save status +      $form->update_status(\%myconfig); +    } + +    $now = scalar localtime; +    $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc}; +    $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc}; +     +    $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes}; +    $old_form->{intnotes} .= qq|[email] +|.$locale->text('Date').qq|: $now +|.$locale->text('To').qq|: $form->{email} +$cc${bcc}|.$locale->text('Subject').qq|: $form->{subject}\n|; + +    $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |; +    $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent'); + +    $old_form->{message} = $form->{message}; +    $old_form->{emailed} = $form->{emailed}; + +    $old_form->{format} = "postscript" if $myconfig{printer}; +    $old_form->{media} = $myconfig{printer}; + +    $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP); +     +    %audittrail = ( tablename	=> ($order) ? 'oe' : lc $ARAP, +                    reference	=> $form->{"${inv}number"}, +		    formname	=> $form->{formname}, +		    action	=> 'emailed', +		    id		=> $form->{id} ); +  +    $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); +  } + + +  if ($form->{media} eq 'queue') { +    %queued = split / /, $form->{queued}; +     +    if ($filename = $queued{$form->{formname}}) { +      $form->{queued} =~ s/$form->{formname} $filename//; +      unlink "$spool/$filename"; +      $filename =~ s/\..*$//g; +    } else { +      $filename = time; +      $filename .= $$; +    } + +    $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf'; +    $form->{OUT} = ">$spool/$filename"; + +    $form->{queued} .= " $form->{formname} $filename"; +    $form->{queued} =~ s/^ //; + +    # save status +    $form->update_status(\%myconfig); + +    $old_form->{queued} = $form->{queued}; +     +    %audittrail = ( tablename	=> ($order) ? 'oe' : lc $ARAP, +                    reference	=> $form->{"${inv}number"}, +		    formname	=> $form->{formname}, +		    action	=> 'queued', +		    id		=> $form->{id} ); +  +    $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail); +        } -   -  $form->parse_template(\%myconfig, $userspath); -  $form->{callback} = ""; +  $form->{fileid} = $form->{"${inv}number"}; +  $form->{fileid} =~ s/(\s|\W)+//g; +  $form->parse_template(\%myconfig, $userspath); +    # if we got back here restore the previous form -  if ($form->{media} =~ /(printer|email)/) { -    if ($old_form) { -      # restore and display form -      map { $form->{$_} = $old_form->{$_} } keys %$old_form; -      $form->{rowcount}--; -      map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); - -      for $i (1 .. $form->{paidaccounts}) { -	map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); -      } -       -      &display_form; -      exit; +  if ($old_form) { +     +    $old_form->{"${inv}number"} = $form->{"${inv}number"}; +     +    # restore and display form +    map { $form->{$_} = $old_form->{$_} } keys %$old_form; +    delete $form->{pre}; +     +    $form->{rowcount}--; + +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); +     +    for $i (1 .. $form->{paidaccounts}) { +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);      } -    $msg = ($form->{media} eq 'printer') ? $locale->text('sent to printer') : $locale->text('emailed to')." $form->{email}"; -    $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|); +    &{ "$display_form" }; +    }  } @@ -1033,6 +1508,8 @@ sub vendor_details {  sub post_as_new {    $form->{postasnew} = 1; +  map { delete $form->{$_} } qw(printed emailed queued); +      &post;  } @@ -1042,14 +1519,18 @@ sub ship_to {    $title = $form->{title};    $form->{title} = $locale->text('Ship to'); -   -  $form->{rowcount}--;    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);    # get details for name    &{ "$form->{vc}_details" }; +  $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number'); + +  $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form"; + +  $form->{rowcount}--; +    $form->header;    print qq| @@ -1062,53 +1543,63 @@ sub ship_to {      <td>        <table>  	<tr class=listheading> -	  <th class=listheading colspan=2 width=50%>|.$locale->text('To').qq|</th> -	  <th class=listheading width=50%>|.$locale->text('Ship to').qq|</th> +	  <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th> +	  <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>  	</tr>  	<tr height="5"></tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Number').qq|</th> +	  <th align=right nowrap>$number</th>  	  <td>$form->{"$form->{vc}number"}</td>  	</tr>  	<tr> -	  <th align=right nowrap>|.$locale->text('Name').qq|</th> +	  <th align=right nowrap>|.$locale->text('Company Name').qq|</th>  	  <td>$form->{name}</td> -	  <td><input name=shiptoname size=35 maxsize=35 value="$form->{shiptoname}"></td> +	  <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('Address').qq|</th> -	  <td>$form->{addr1}</td> -	  <td><input name=shiptoaddr1 size=35 maxsize=35 value="$form->{shiptoaddr1}"></td> +	  <td>$form->{address1}</td> +	  <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>  	</tr>  	<tr>  	  <th></th> -	  <td>$form->{addr2}</td> -	  <td><input name=shiptoaddr2 size=35 maxsize=35 value="$form->{shiptoaddr2}"></td> +	  <td>$form->{address2}</td> +	  <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>  	</tr>  	<tr> -	  <th></th> -	  <td>$form->{addr3}</td> -	  <td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td> +	  <th align=right nowrap>|.$locale->text('City').qq|</th> +	  <td>$form->{city}</td> +	  <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>  	</tr>  	<tr> -	  <th></th> -	  <td>$form->{addr4}</td> -	  <td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></td> +	  <th align=right nowrap>|.$locale->text('State/Province').qq|</th> +	  <td>$form->{state}</td> +	  <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th> +	  <td>$form->{zipcode}</td> +	  <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Country').qq|</th> +	  <td>$form->{country}</td> +	  <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('Contact').qq|</th>  	  <td>$form->{contact}</td> -	  <td><input name=shiptocontact size=35 maxsize=35 value="$form->{shiptocontact}"></td> +	  <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('Phone').qq|</th>  	  <td>$form->{"$form->{vc}phone"}</td> -	  <td><input name=shiptophone size=20 maxsize=20 value="$form->{shiptophone}"></td> +	  <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('Fax').qq|</th>  	  <td>$form->{"$form->{vc}fax"}</td> -	  <td><input name=shiptofax size=20 maxsize=20 value="$form->{shiptofax}"></td> +	  <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>  	</tr>  	<tr>  	  <th align=right nowrap>|.$locale->text('E-mail').qq|</th> @@ -1119,21 +1610,18 @@ sub ship_to {      </td>    </tr>  </table> + +<input type=hidden name=nextsub value=$nextsub>  |;    # delete shipto -  map { delete $form->{$_} } qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact shiptophone shiptofax shiptoemail); +  map { delete $form->{$_} } qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);    $form->{title} = $title; -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq| -<input type=hidden name=nextsub value=display_form> -  <hr size=3 noshade>  <br> diff --git a/sql-ledger/bin/mozilla/ir.pl b/sql-ledger/bin/mozilla/ir.pl index ec7d18cf0..080ac2415 100644 --- a/sql-ledger/bin/mozilla/ir.pl +++ b/sql-ledger/bin/mozilla/ir.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger, Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -41,6 +41,7 @@ sub add {    $form->{title} = $locale->text('Add Vendor Invoice'); +  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};    &invoice_links;    &prepare_invoice;    &display_form; @@ -60,13 +61,12 @@ sub edit {  sub invoice_links { +   +  $form->{vc} = "vendor";    # create links    $form->create_links("AP", \%myconfig, "vendor"); - -  IR->get_vendor(\%myconfig, \%$form); -  IR->retrieve_invoice(\%myconfig, \%$form); - +      # currencies    @curr = split /:/, $form->{currencies};    chomp $curr[0]; @@ -74,14 +74,56 @@ sub invoice_links {    map { $form->{selectcurrency} .= "<option>$_\n" } @curr; +  if ($form->{all_vendor}) { +    unless ($form->{vendor_id}) { +      $form->{vendor_id} = $form->{all_vendor}->[0]->{id}; +    } +  } + +  IR->get_vendor(\%myconfig, \%$form); +  delete $form->{notes}; +  IR->retrieve_invoice(\%myconfig, \%$form); + +  $form->{oldlanguage_code} = $form->{language_code}; + +  $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} }); +  if (@ { $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    foreach $ref (@ { $form->{all_partsgroup} }) { +      if ($ref->{translation}) { +	$form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|; +      } else { +        $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|; +      } +    } +  } + +  if (@{ $form->{all_projects} }) {  +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; +  } +    $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; +  $form->{oldtransdate} = $form->{transdate};    # vendors -  if (@{ $form->{all_vendor} }) { +  if ($form->{all_vendor}) {      $form->{vendor} = "$form->{vendor}--$form->{vendor_id}"; -    map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} }); +    map { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_vendor} }); +  } + +  # departments +  if ($form->{all_departments}) { +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });    } +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  }    # forex    $form->{forex} = $form->{exchangerate}; @@ -101,18 +143,23 @@ sub invoice_links {  	$form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};  	$form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};  	$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source}; +	$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo}; +  	$form->{paidaccounts} = $i;        }      } else {        $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";      } +        }    $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});    $form->{AP} = $form->{AP_1} unless $form->{id}; -  $form->{locked} = ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); +  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +  $form->{readonly} = 1 if $myconfig{acs} =~ /AP--Vendor Invoice/;  } @@ -120,13 +167,21 @@ sub invoice_links {  sub prepare_invoice { +  $form->{type} = "invoice"; +  $form->{oldcurrency} = $form->{currency}; +    if ($form->{id}) { -    map { $form->{$_} =~ s/"/"/g } qw(invnumber ordnumber); +    map { $form->{$_} = $form->quote($form->{$_}) } qw(invnumber ordnumber quonumber);      foreach $ref (@{ $form->{invoice_details} }) {        $i++;        map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + +      $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}|; +      $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}|; + +      $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);        ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);        $dec = length $dec; @@ -134,6 +189,9 @@ sub prepare_invoice {        $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);        $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); +      $form->{"oldqty_$i"} = $form->{"qty_$i"}; + +      map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit);        $form->{rowcount} = $i;      } @@ -146,24 +204,48 @@ sub prepare_invoice {  sub form_header {    # set option selected -  foreach $item (qw(AP vendor currency)) { +  foreach $item (qw(AP currency)) {      $form->{"select$item"} =~ s/ selected//;      $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;    } +  foreach $item (qw(vendor department)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } + +  if ($form->{selectlanguage}) { +    $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"}); +    $form->{"selectlanguage"} =~ s/ selected//; +    $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/; + +    $lang = qq| +	      <tr> +		<th align=right nowrap>|.$locale->text('Language').qq|</th> +		<td><select name=language_code>$form->{selectlanguage}</select></td> +		<input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}> +                <input type=hidden name="selectlanguage" value="|. +		$form->escape($form->{selectlanguage},1).qq|"> +	      </tr> +|; + +  } +   +    $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});    $exchangerate = "";    if ($form->{currency} ne $form->{defaultcurrency}) {      if ($form->{forex}) {        $exchangerate .= qq| -      <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th> -      <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td> +                <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th> +                <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>  |;      } else {        $exchangerate .= qq| -      <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th> -      <td><input name=exchangerate size=10 value=$form->{exchangerate}></td> +                <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th> +                <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>  |;      }    } @@ -171,23 +253,50 @@ sub form_header {  <input type=hidden name=forex value=$form->{forex}>  |; -  $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">| : qq|<input name=vendor value="$form->{vendor}" size=35>|; +  if ($form->{selectvendor}) { +    $vendor = qq|<select name=vendor>$form->{selectvendor}</select> +                 <input type=hidden name="selectvendor" value="|. +		 $form->escape($form->{selectvendor},1).qq|">|; +  } else { +    $vendor = qq|<input name=vendor value="$form->{vendor}" size=35>|; +  } +  $department = qq| +              <tr> +	      <th align="right" nowrap>|.$locale->text('Department').qq|</th> +	      <td colspan=3><select name=department>$form->{selectdepartment}</select> +	      <input type=hidden name=selectdepartment value="|. +	      $form->escape($form->{selectdepartment},1).qq|"> +	      </td> +	    </tr> +| if $form->{selectdepartment}; + +  $n = ($form->{creditremaining} < 0) ? "0" : "1"; +    $form->header;    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end">  <input type=hidden name=id value=$form->{id}>  <input type=hidden name=title value="$form->{title}">  <input type=hidden name=vc value="vendor"> +<input type=hidden name=type value=$form->{type}> + +<input type=hidden name=terms value=$form->{terms}> + +<input type=hidden name=creditlimit value=$form->{creditlimit}> +<input type=hidden name=creditremaining value=$form->{creditremaining}>  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=locked value=$form->{locked}> +<input type=hidden name=shipped value=$form->{shipped}> + +<input type=hidden name=oldtransdate value=$form->{oldtransdate}>  <table width=100%>    <tr class=listtop> @@ -201,11 +310,6 @@ sub form_header {  	  <td>  	    <table>  	      <tr> -		<th align=right>|.$locale->text('Record in').qq|</th> -		<td colspan=3><select name=AP>$form->{selectAP}</select></td> -		<input type=hidden name=selectAP value="$form->{selectAP}"> -	      </tr> -	      <tr>  		<th align=right nowrap>|.$locale->text('Vendor').qq|</th>  		<td colspan=3>$vendor</td> @@ -214,6 +318,25 @@ sub form_header {  	      </tr>  	      <tr> +	        <td></td> +		<td colspan=3> +		  <table> +		    <tr> +		      <th nowrap>|.$locale->text('Credit Limit').qq|</th> +		      <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td> +		      <td width=20%></td> +		      <th nowrap>|.$locale->text('Remaining').qq|</th> +		      <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td> +		    </tr> +		  </table> +		</td> +	      <tr> +		<th align=right>|.$locale->text('Record in').qq|</th> +		<td colspan=3><select name=AP>$form->{selectAP}</select></td> +		<input type=hidden name=selectAP value="$form->{selectAP}"> +	      </tr> +              $department +	      <tr>  		<th align=right nowrap>|.$locale->text('Currency').qq|</th>  		<td><select name=currency>$form->{selectcurrency}</select></td>  		$exchangerate @@ -224,20 +347,22 @@ sub form_header {  	    <table>  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -		<td><input name=invnumber size=11 value="$form->{invnumber}"></td> +		<td><input name=invnumber size=20 value="$form->{invnumber}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> +		<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td> +<input type=hidden name=quonumber value="$form->{quonumber}">  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Date').qq|</th> -		<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td> +		<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>  	      </tr>  	      <tr>  		<th align=right nowrap>|.$locale->text('Due Date').qq|</th>  		<td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>  	      </tr> -	      <tr> -		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> -		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td> -	      </tr> +	      $lang  	    </table>  	  </td>  	</tr> @@ -270,16 +395,22 @@ sub form_footer {    $form->{invtotal} = $form->{invsubtotal}; -  if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { +  if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {      $rows = 2;    } -  $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; - - +  if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { +    $introws = 2; +  } +  $rows = ($rows > $introws) ? $rows : $introws; +  $notes = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|; +  $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|; +      $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + +  $taxincluded = "";    if ($form->{taxaccounts}) {      $taxincluded = qq| -		<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br> +		<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b>  |;    } @@ -315,22 +446,25 @@ sub form_footer {    print qq|    <tr> -    <td colspan=$colspan> -      <table cellspacing="0"> +    <td> +      <table width=100%>  	<tr valign=bottom>  	  <td>  	    <table>  	      <tr>  		<th align=left>|.$locale->text('Notes').qq|</th> +		<th align=left>|.$locale->text('Internal Notes').qq|</th>  	      </tr> -	      <tr> +	      <tr valign=top>  		<td>$notes</td> +		<td>$intnotes</td>  	      </tr>  	    </table>  	  </td> -	  <td colspan=2 align=right width=100%> +	  <td align=right>  	    $taxincluded -	    <table width=100%> +	    <br> +	    <table>  	      $subtotal  	      $tax  	      <tr> @@ -344,17 +478,17 @@ sub form_footer {      </td>    </tr>    <tr> -    <td colspan=$colspan> +    <td>        <table width=100%>          <tr> -	  <th colspan=5 class=listheading>|.$locale->text('Payments').qq|</th> +	  <th colspan=6 class=listheading>|.$locale->text('Payments').qq|</th>  	</tr>  |;      if ($form->{currency} eq $form->{defaultcurrency}) { -      @column_index = qw(datepaid source paid AP_paid); +      @column_index = qw(datepaid source memo paid AP_paid);      } else { -      @column_index = qw(datepaid source paid exchangerate AP_paid); +      @column_index = qw(datepaid source memo paid exchangerate AP_paid);      }      $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; @@ -362,6 +496,7 @@ sub form_footer {      $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";      $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";      $column_data{source} = "<th>".$locale->text('Source')."</th>"; +    $column_data{memo} = "<th>".$locale->text('Memo')."</th>";      print qq|  	<tr> @@ -401,7 +536,8 @@ sub form_footer {        $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;        $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;        $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|; -      $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|; +      $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|; +      $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;        map { print qq|$column_data{"${_}_$i"}\n| } @column_index; @@ -423,36 +559,39 @@ sub form_footer {  <br>  |; -  $invdate = $form->datetonum($form->{invdate}, \%myconfig); +  $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  if ($form->{id}) { -    print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +  if (! $form->{readonly}) { +    if ($form->{id}) { +      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">  |; -    if (!$form->{revtrans}) {        if (!$form->{locked}) {  	print qq|  	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">  	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">  |;        } -    } -    if ($invdate > $closedto) {        print qq| -      <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Order').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|">  |; -    } -  } else { -    if ($invdate > $closedto) { -      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +    } else { +      if ($transdate > $closedto) { +	print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +      }      }    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print qq|  <input type=hidden name=rowcount value=$form->{rowcount}> @@ -461,10 +600,12 @@ print qq|  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  </form> +<a name="end"></a> +  </body>  </html>  |; @@ -475,32 +616,46 @@ print qq|  sub update { -  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}); +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate);    &check_name(vendor); -  &check_project; +  if ($form->{transdate} ne $form->{oldtransdate}) { +    $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1); +    $form->{oldtransdate} = $form->{transdate}; +  } -  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell'))); -   + +  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell'))); +  $j = 1;    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { -      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); +      map { $form->{"${_}_$j"} = $form->{"${_}_$i"} } qw(datepaid source memo); +      map { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); -      $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'))); +      $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, 'sell'))); +      map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex) if $j != $i; +    } else { +      map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex);      } +    $form->{paidaccounts} = $j;    }    $i = $form->{rowcount};    $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; +  foreach $item (qw(partsgroup projectnumber)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"}; +  } +      if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {      &check_form;    } else { +    $form->{transdate} = $form->{oldtransdate};      IR->retrieve_item(\%myconfig, \%$form);      my $rows = scalar @{ $form->{item_list} }; @@ -517,7 +672,7 @@ sub update {          # override sellprice if there is one entered  	$sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); -	map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit); +	map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);  	map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; @@ -550,7 +705,7 @@ sub update {  	&display_form;        } else { -	$form->{"id_$i"}		= 0; +	$form->{"id_$i"}	= 0;  	$form->{"unit_$i"}	= $locale->text('ea');  	&new_item; @@ -564,8 +719,7 @@ sub update {  sub post { -  $form->isblank("invnumber", $locale->text('Invoice Number missing!')); -  $form->isblank("invdate", $locale->text('Invoice Date missing!')); +  $form->isblank("transdate", $locale->text('Invoice Date missing!'));    $form->isblank("vendor", $locale->text('Vendor missing!'));    # if the vendor changed get new values @@ -577,11 +731,11 @@ sub post {    &validate_items;    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  $invdate = $form->datetonum($form->{invdate}, \%myconfig); +  $transdate = $form->datetonum($form->{transdate}, \%myconfig); -  $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); +  $form->error($locale->text('Cannot post invoice for a closed period!')) if ($transdate <= $closedto); -  $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { @@ -592,8 +746,8 @@ sub post {        $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);        if ($form->{currency} ne $form->{defaultcurrency}) { -	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); -	$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); +	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); +	$form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));        }      }    } @@ -604,7 +758,9 @@ sub post {    $form->{id} = 0 if $form->{postasnew}; -  $form->redirect($locale->text('Invoice posted!')) if (IR->post_invoice(\%myconfig, \%$form)); +  $form->{invnumber} = $form->update_defaults(\%myconfig, "vinumber") unless $form->{invnumber}; + +  $form->redirect($locale->text('Invoice')." $form->{invnumber} ".$locale->text('posted!')) if (IR->post_invoice(\%myconfig, \%$form));    $form->error($locale->text('Cannot post invoice!'));  } @@ -622,12 +778,9 @@ sub delete {  |;    # delete action variable -  delete $form->{action}; +  map { delete $form->{$_} } qw(action header); -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|  <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2> diff --git a/sql-ledger/bin/mozilla/is.pl b/sql-ledger/bin/mozilla/is.pl index cca5813e8..605380d5d 100644 --- a/sql-ledger/bin/mozilla/is.pl +++ b/sql-ledger/bin/mozilla/is.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -29,8 +29,8 @@  use SL::IS;  use SL::PE; -require "$form->{path}/io.pl";  require "$form->{path}/arap.pl"; +require "$form->{path}/io.pl";  1; @@ -42,6 +42,8 @@ sub add {    $form->{title} = $locale->text('Add Sales Invoice'); +  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback}; +    &invoice_links;    &prepare_invoice;    &display_form; @@ -62,12 +64,11 @@ sub edit {  sub invoice_links { +  $form->{vc} = 'customer'; +    # create links    $form->create_links("AR", \%myconfig, "customer"); -  IS->get_customer(\%myconfig, \%$form); -  IS->retrieve_invoice(\%myconfig, \%$form); -    # currencies    @curr = split /:/, $form->{currencies};    chomp $curr[0]; @@ -75,19 +76,68 @@ sub invoice_links {    map { $form->{selectcurrency} .= "<option>$_\n" } @curr; +  if ($form->{all_customer}) { +    unless ($form->{customer_id}) { +      $form->{customer_id} = $form->{all_customer}->[0]->{id}; +    } +  } + +  IS->get_customer(\%myconfig, \%$form); +  delete $form->{notes}; +  IS->retrieve_invoice(\%myconfig, \%$form); + +  $form->{oldlanguage_code} = $form->{language_code}; +   +  $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} }); +  if (@{ $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    foreach $ref (@ { $form->{all_partsgroup} }) { +      if ($ref->{translation}) { +	$form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|; +      } else { +	$form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|; +      } +    } +  } +   +  if (@{ $form->{all_projects} }) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; +  } +    $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; +  $form->{oldtransdate} = $form->{transdate}; -  if (@{ $form->{all_customer} }) { -    $form->{customer} = qq|$form->{customer}--$form->{customer_id}|; -    map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); +  if ($form->{all_customer}) { +    $form->{customer} = "$form->{customer}--$form->{customer_id}"; +    map { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_customer} });    } +  # departments +  if ($form->{all_departments}) { +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } +   +  $form->{employee} = "$form->{employee}--$form->{employee_id}"; +  # sales staff +  if ($form->{all_employees}) { +    $form->{selectemployee} = ""; +    map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_employees} }); +  } +   +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  } +      # forex    $form->{forex} = $form->{exchangerate};    $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; - +      foreach $key (keys %{ $form->{AR_links} }) { -          foreach $ref (@{ $form->{AR_links}{$key} }) {        $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";      } @@ -100,18 +150,23 @@ sub invoice_links {  	$form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};  	$form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};  	$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source}; +	$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo}; +	  	$form->{paidaccounts} = $i;        }      } else {        $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";      } +        }    $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});    $form->{AR} = $form->{AR_1} unless $form->{id}; +   +  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); -  $form->{locked} = ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); +  $form->{readonly} = 1 if $myconfig{acs} =~ /AR--Sales Invoice/;  } @@ -119,26 +174,34 @@ sub invoice_links {  sub prepare_invoice {    $form->{type} = "invoice"; -  $form->{format} = "html"; -  $form->{media} = "screen"; +  $form->{formname} = "invoice"; +  $form->{format} = "postscript" if $myconfig{printer}; +  $form->{media} = $myconfig{printer}; +   +  $form->{oldcurrency} = $form->{currency};    if ($form->{id}) { -    map { $form->{$_} =~ s/"/"/g } qw(invnumber ordnumber shippingpoint notes); +    map { $form->{$_} = $form->quote($form->{$_}) } qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);      foreach $ref (@{ $form->{invoice_details} } ) {        $i++;        map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + +      $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}|; +      $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}|; +        $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);        ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);        $dec = length $dec;        $decimalplaces = ($dec > 2) ? $dec : 2; -       +        $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);        $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); +      $form->{"oldqty_$i"} = $form->{"qty_$i"}; -      map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); +      map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit);        $form->{rowcount} = $i;      }    } @@ -149,42 +212,73 @@ sub prepare_invoice {  sub form_header { -    # set option selected -  foreach $item (qw(AR customer currency)) { +  foreach $item (qw(AR currency)) {      $form->{"select$item"} =~ s/ selected//;      $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;    } +   +  foreach $item (qw(customer department employee)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  }    $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); -  $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); -  $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - -   +     $exchangerate = "";    if ($form->{currency} ne $form->{defaultcurrency}) {      if ($form->{forex}) { -      $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|; +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;      } else { -      $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|; +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;      }    }    $exchangerate .= qq|  <input type=hidden name=forex value=$form->{forex}>  |; -  $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">| : qq|<input name=customer value="$form->{customer}" size=35>|; +  if ($form->{selectcustomer}) { +    $customer = qq|<select name=customer>$form->{selectcustomer}</select> +                   <input type=hidden name="selectcustomer" value="|. +		   $form->escape($form->{selectcustomer},1).qq|">|; +  } else { +    $customer = qq|<input name=customer value="$form->{customer}" size=35>|; +  } -  $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; +  $department = qq| +              <tr> +	        <th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td colspan=3><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="|. +		$form->escape($form->{selectdepartment},1).qq|"> +		</td> +	      </tr> +| if $form->{selectdepartment}; + + +  $n = ($form->{creditremaining} < 0) ? "0" : "1"; + + +  if ($form->{business}) { +    $business = qq| +	      <tr> +		<th align=right>|.$locale->text('Business').qq|</th> +		<td>$form->{business}</td> +		<th align=right>|.$locale->text('Trade Discount').qq|</th> +		<td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td> +	      </tr> +|; +  } + -      $form->header;    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end">  <input type=hidden name=id value=$form->{id}> @@ -192,20 +286,33 @@ sub form_header {  <input type=hidden name=media value=$form->{media}>  <input type=hidden name=format value=$form->{format}> +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=printed value="$form->{printed}"> +<input type=hidden name=emailed value="$form->{emailed}"> +  <input type=hidden name=title value="$form->{title}"> -<input type=hidden name=vc value="customer"> -<input type=hidden name=employee value="$form->{employee}"> +<input type=hidden name=vc value=$form->{vc}> + +<input type=hidden name=terms value=$form->{terms}>  <input type=hidden name=discount value=$form->{discount}>  <input type=hidden name=creditlimit value=$form->{creditlimit}>  <input type=hidden name=creditremaining value=$form->{creditremaining}> +<input type=hidden name=tradediscount value=$form->{tradediscount}> +<input type=hidden name=business value="$form->{business}"> +  <input type=hidden name=closedto value=$form->{closedto}>  <input type=hidden name=locked value=$form->{locked}> +<input type=hidden name=shipped value=$form->{shipped}> + +<input type=hidden name=oldtransdate value=$form->{oldtransdate}> + +  <table width=100%>    <tr class=listtop> -    <th class=listtop>$form->{title}</font></th> +    <th class=listtop>$form->{title}</th>    </tr>    <tr height="5"></tr>    <tr> @@ -215,11 +322,6 @@ sub form_header {  	  <td>  	    <table>  	      <tr> -		<th align=right nowrap>|.$locale->text('Record in').qq|</th> -		<td colspan=3><select name=AR>$form->{selectAR}</select></td> -		<input type=hidden name=selectAR value="$form->{selectAR}"> -	      </tr> -	      <tr>  		<th align=right nowrap>|.$locale->text('Customer').qq|</th>  		<td colspan=3>$customer</td>  		<input type=hidden name=customer_id value=$form->{customer_id}> @@ -228,16 +330,24 @@ sub form_header {  	      <tr>  		<td></td>  		<td colspan=3> -		  <table width=100%> +		  <table>  		    <tr> -		      <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th> -		      <td>$form->{creditlimit}</td> -		      <th align=left nowrap>|.$locale->text('Remaining').qq|</th> -		      <td class="plus$n">$form->{creditremaining}</font></td> +		      <th nowrap>|.$locale->text('Credit Limit').qq|</th> +		      <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td> +		      <td width=20%></td> +		      <th nowrap>|.$locale->text('Remaining').qq|</th> +		      <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>  		    </tr>  		  </table>  		</td>  	      </tr> +	      $business +	      <tr> +		<th align=right nowrap>|.$locale->text('Record in').qq|</th> +		<td colspan=3><select name=AR>$form->{selectAR}</select></td> +		<input type=hidden name=selectAR value="$form->{selectAR}"> +	      </tr> +	      $department  	      <tr>  		<th align=right nowrap>|.$locale->text('Currency').qq|</th>  		<td><select name=currency>$form->{selectcurrency}</select></td> @@ -248,29 +358,40 @@ sub form_header {  		$exchangerate  	      </tr>  	      <tr> -		<th align=right nowrap>|.$locale->text('Ship via').qq|</th> +		<th align=right nowrap>|.$locale->text('Shipping Point').qq|</th>  		<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>  	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Ship via').qq|</th> +		<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td> +	      </tr>  	    </table>  	  </td>  	  <td align=right>  	    <table>  	      <tr> +	        <th align=right nowrap>|.$locale->text('Salesperson').qq|</th> +		<td><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|. +		$form->escape($form->{selectemployee},1).qq|"> +	      </tr> +	      <tr>  		<th align=right nowrap>|.$locale->text('Invoice Number').qq|</th> -		<td><input name=invnumber size=11 value="$form->{invnumber}"></td> +		<td><input name=invnumber size=20 value="$form->{invnumber}"></td> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> +		<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td> +<input type=hidden name=quonumber value="$form->{quonumber}">  	      </tr>  	      <tr>  		<th align=right>|.$locale->text('Invoice Date').qq|</th> -		<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td> +		<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>  	      </tr>  	      <tr>  		<th align=right>|.$locale->text('Due Date').qq|</th>  		<td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>  	      </tr> -	      <tr> -		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> -		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td> -	      </tr>  	    </table>  	  </td>  	</tr> @@ -284,10 +405,12 @@ sub form_header {  <!-- shipto are in hidden variables -->  <input type=hidden name=shiptoname value="$form->{shiptoname}"> -<input type=hidden name=shiptoaddr1 value="$form->{shiptoaddr1}"> -<input type=hidden name=shiptoaddr2 value="$form->{shiptoaddr2}"> -<input type=hidden name=shiptoaddr3 value="$form->{shiptoaddr3}"> -<input type=hidden name=shiptoaddr4 value="$form->{shiptoaddr4}"> +<input type=hidden name=shiptoaddress1 value="$form->{shiptoaddress1}"> +<input type=hidden name=shiptoaddress2 value="$form->{shiptoaddress2}"> +<input type=hidden name=shiptocity value="$form->{shiptocity}"> +<input type=hidden name=shiptostate value="$form->{shiptostate}"> +<input type=hidden name=shiptozipcode value="$form->{shiptozipcode}"> +<input type=hidden name=shiptocountry value="$form->{shiptocountry}">  <input type=hidden name=shiptocontact value="$form->{shiptocontact}">  <input type=hidden name=shiptophone value="$form->{shiptophone}">  <input type=hidden name=shiptofax value="$form->{shiptofax}"> @@ -319,20 +442,29 @@ sub form_footer {    $form->{invtotal} = $form->{invsubtotal}; -  if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { +  if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {      $rows = 2;    } -  $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; - +  if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { +    $introws = 2; +  } +  $rows = ($rows > $introws) ? $rows : $introws; +  $notes = qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|; +  $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;    $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; +  $taxincluded = "";    if ($form->{taxaccounts}) {      $taxincluded = qq| -		<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br> +              <tr height="5"></tr> +              <tr> +	        <td align=right> +	        <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|.$locale->text('Tax Included').qq|</th> +	     </tr>  |;    } -   +    if (!$form->{taxincluded}) {      foreach $item (split / /, $form->{taxaccounts}) { @@ -373,21 +505,23 @@ sub form_footer {  	    <table>  	      <tr>  		<th align=left>|.$locale->text('Notes').qq|</th> +		<th align=left>|.$locale->text('Internal Notes').qq|</th>  	      </tr> -	      <tr> +	      <tr valign=top>  		<td>$notes</td> +		<td>$intnotes</td>  	      </tr>  	    </table>  	  </td> -	  <td align=right width=100%> -	    $taxincluded -	    <table width=100%> +	  <td align=right> +	    <table>  	      $subtotal  	      $tax  	      <tr>  		<th align=right>|.$locale->text('Total').qq|</th>  		<td align=right>$form->{invtotal}</td>  	      </tr> +	      $taxincluded  	    </table>  	  </td>  	</tr> @@ -398,15 +532,15 @@ sub form_footer {      <td>        <table width=100%>  	<tr class=listheading> -	  <th class=listheading colspan=5>|.$locale->text('Payments') -	  .qq|</font></th> +	  <th colspan=6 class=listheading>|.$locale->text('Payments') +	  .qq|</th>  	</tr>  |;    if ($form->{currency} eq $form->{defaultcurrency}) { -    @column_index = qw(datepaid source paid AR_paid); +    @column_index = qw(datepaid source memo paid AR_paid);    } else { -    @column_index = qw(datepaid source paid exchangerate AR_paid); +    @column_index = qw(datepaid source memo paid exchangerate AR_paid);    }    $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; @@ -414,6 +548,7 @@ sub form_footer {    $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";    $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";    $column_data{source} = "<th>".$locale->text('Source')."</th>"; +  $column_data{memo} = "<th>".$locale->text('Memo')."</th>";    print "  	<tr> @@ -455,6 +590,7 @@ sub form_footer {      $column_data{"AR_paid_$i"} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;      $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;      $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|; +    $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;      map { print qq|$column_data{"${_}_$i"}\n| } @column_index;      print " @@ -470,6 +606,9 @@ sub form_footer {      </td>    </tr>    <tr> +    <td><hr size=3 noshade></td> +  </tr> +  <tr>      <td>  |; @@ -478,50 +617,67 @@ sub form_footer {    print qq|      </td>    </tr> -  <tr> -    <td><hr size=3 noshade></td> -  </tr>  </table> +<br>  |; -  $invdate = $form->datetonum($form->{invdate}, \%myconfig); +  $transdate = $form->datetonum($form->{transdate}, \%myconfig);    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  -  if ($form->{id}) { -    print qq| -    <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -    <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|"> -    <input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> -    <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|"> + +  if (! $form->{readonly}) { +     +    if ($form->{id}) { +       +      print qq| +      <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">  |; -    if (!$form->{revtrans}) { -      if (!$form->{locked}) { -	print qq| -	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|"> +        if (! $form->{locked}) { +	  print qq| +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; + +	  if ($latex) { +	    print qq| +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|; +	  } + +	  print qq|  	<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">  |; -      } -    } +	} -    if ($invdate > $closedto) { -      print qq| +	print qq|        <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Order').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|">  |; -    } -  } else { -    if ($invdate > $closedto) { -      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|"> -      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; +    } else { + +      if ($transdate > $closedto) { +	print qq| +        <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|"> +	<input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; + +	if ($latex) { +	  print qq| +	<input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|; +	} +      }      }    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print qq|  <input type=hidden name=rowcount value=$form->{rowcount}> @@ -530,10 +686,12 @@ sub form_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  </form> +<a name="end"></a> +  </body>  </html>  |; @@ -543,25 +701,40 @@ sub form_footer {  sub update { -  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate);    &check_name(customer); -  &check_project; +  if ($form->{transdate} ne $form->{oldtransdate}) { +    $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1); +    $form->{oldtransdate} = $form->{transdate}; +  } -  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy'))); +  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy'))); + +  $j = 1;    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { -      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); +      map { $form->{"${_}_$j"} = $form->{"${_}_$i"} } qw(datepaid source memo); +      map { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); -      $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'))); +      $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, 'buy'))); +      map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex) if $j != $i; +      $j++; +    } else { +      map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex);      } +    $form->{paidaccounts} = $j;    }    $i = $form->{rowcount};    $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; +  foreach $item (qw(partsgroup projectnumber)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"}; +  } +        # if last row empty, check the form otherwise retrieve new item    if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { @@ -576,7 +749,7 @@ sub update {      $form->{"discount_$i"}	= $form->format_amount(\%myconfig, $form->{discount} * 100); -    if ($rows) { +    if ($rows > 0) {        $form->{"qty_$i"}		= ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;        if ($rows > 1) { @@ -588,9 +761,11 @@ sub update {          $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); -	map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit); +	map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);  	map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; +	$form->{"discount_$i"} = $form->{discount} * 100; +	  	$s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};  	($dec) = ($s =~ /\.(\d+)/);  	$dec = length $dec; @@ -600,10 +775,11 @@ sub update {  	  $form->{"sellprice_$i"} = $sellprice;  	} else {  	  # if there is an exchange rate adjust sellprice +	  $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});  	  $form->{"sellprice_$i"} /= $exchangerate;  	} -	$form->{"listprice_$i"} /= $exchangerate; +	map { $form->{"${_}_$i"} /= $exchangerate } qw(listprice lastcost);          $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);  	map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); @@ -612,11 +788,9 @@ sub update {          $form->{creditremaining} -= $amount; - -	map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice); +	map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost);  	$form->{"qty_$i"} =  $form->format_amount(\%myconfig, $form->{"qty_$i"}); -        }        &display_form; @@ -630,12 +804,12 @@ sub update {  	$form->{"discount_$i"} = "";  	&display_form;        } else { - +	  	$form->{"id_$i"}          = 0;  	$form->{"unit_$i"}        = $locale->text('ea');  	&new_item; - +	        }      }    } @@ -645,8 +819,7 @@ sub update {  sub post { -  $form->isblank("invnumber", $locale->text('Invoice Number missing!')); -  $form->isblank("invdate", $locale->text('Invoice Date missing!')); +  $form->isblank("transdate", $locale->text('Invoice Date missing!'));    $form->isblank("customer", $locale->text('Customer missing!'));    # if oldcustomer ne customer redo form @@ -654,15 +827,15 @@ sub post {      &update;      exit;    } -   +    &validate_items;    $closedto = $form->datetonum($form->{closedto}, \%myconfig); -  $invdate = $form->datetonum($form->{invdate}, \%myconfig); +  $transdate = $form->datetonum($form->{transdate}, \%myconfig); -  $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); +  $form->error($locale->text('Cannot post invoice for a closed period!')) if ($transdate <= $closedto); -  $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});    for $i (1 .. $form->{paidaccounts}) {      if ($form->{"paid_$i"}) { @@ -673,13 +846,13 @@ sub post {        $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);        if ($form->{currency} ne $form->{defaultcurrency}) { -	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); -	$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); +	$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); +	$form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));        }      }    } -       +      ($form->{AR}) = split /--/, $form->{AR};    ($form->{AR_paid}) = split /--/, $form->{AR_paid}; @@ -687,12 +860,28 @@ sub post {    $form->{id} = 0 if $form->{postasnew}; +  $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber") unless $form->{invnumber}; +    $form->redirect($locale->text('Invoice posted!')) if (IS->post_invoice(\%myconfig, \%$form));    $form->error($locale->text('Cannot post invoice!'));  } +sub print_and_post { + +  $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/; +  $form->error($locale->text('Select Printer or Queue!')) if $form->{media} eq 'screen'; + +  $old_form = new Form; +  $form->{display_form} = "post"; +  map { $old_form->{$_} = $form->{$_} } keys %$form; +  $old_form->{rowcount}++; + +  &print_form($old_form); + +} +  sub delete { @@ -706,15 +895,12 @@ sub delete {  |;    # delete action variable -  delete $form->{action}; +  map { delete $form->{$_} } qw(action header); -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq| -<h2 class=confirm>|.$locale->text('Confirm!').qq|</font></h2> +<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>  <h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}  </h4> @@ -731,9 +917,16 @@ sub delete {  sub yes { -  $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form)); +  $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form, $spool));    $form->error($locale->text('Cannot delete invoice!'));  } +sub redirect { + +  $form->redirect; +  $form->error($locale->text('Invoice processed!')); + +} + diff --git a/sql-ledger/bin/mozilla/login.pl b/sql-ledger/bin/mozilla/login.pl index 3c36564fd..1cf1f729f 100644 --- a/sql-ledger/bin/mozilla/login.pl +++ b/sql-ledger/bin/mozilla/login.pl @@ -1,6 +1,6 @@  ######################################################################  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2000  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -19,6 +19,10 @@  # You should have received a copy of the GNU General Public License  # along with this program; if not, write to the Free Software  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +###################################################################### +# +# login frontend +#  ####################################################################### @@ -58,6 +62,97 @@ if ($form->{action}) {  sub login_screen { + +  $form->{stylesheet} = "sql-ledger.css"; +  $form->{favicon} = "sql-ledger.ico"; + +  $form->{endsession} = 1; +  $form->header(1); + +  if ($form->{login}) { +   $sf = qq|function sf() { document.login.password.focus(); }|; +  } else { +   $sf = qq|function sf() { document.login.login.focus(); }|; +  } + +  if ($form->{jsc} && -d 'bin/js') { +  print qq| +<script language="JavaScript" type="text/javascript"> +<!-- +var agt = navigator.userAgent.toLowerCase(); +var is_major = parseInt(navigator.appVersion); +var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) +           && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) +	   && (agt.indexOf('webtv') == -1)); +var is_nav4lo = (is_nav && (is_major <= 4)); + +function jsp() { +  if (is_nav4lo) +    document.login.path.value = "bin/mozilla" +  else +    document.login.path.value = "bin/js" +} +$sf +// End --> +</script> +|; +  } + +  print qq| + +<body class=login onload="jsp(); sf()"> + +<pre> + +</pre> + +<center> +<table class=login border=3 cellpadding=20> +  <tr> +    <td class=login align=center><a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.gif border=0></a> +<h1 class=login align=center>|.$locale->text('Version').qq| $form->{version} +</h1> + +<p> + +<form method=post action=$form->{script} name=login> + +      <table width=100%> +	<tr> +	  <td align=center> +	    <table> +	      <tr> +		<th align=right>|.$locale->text('Name').qq|</th> +		<td><input class=login name=login size=30 value=$form->{login}></td> +	      </tr>  +	      <tr> +		<th align=right>|.$locale->text('Password').qq|</th> +		<td><input class=login type=password name=password size=30></td> +	      </tr> +	      <input type=hidden name=path value=$form->{path}> +	    </table> + +	    <br> +	    <input type=submit name=action value="|.$locale->text('Login').qq|"> +	  </td> +	</tr> +      </table> + +</form> + +    </td> +  </tr> +</table> +   +</body> +</html> +|; + +} + + +sub selectdataset { +  my ($login) = @_;    if (-f "css/sql-ledger.css") {      $form->{stylesheet} = "sql-ledger.css"; @@ -75,7 +170,7 @@ sub login_screen {  <center>  <table class=login border=3 cellpadding=20>    <tr> -    <td class=login align=center><a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.png border=0></a> +    <td class=login align=center><a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.gif border=0></a>  <h1 class=login align=center>|.$locale->text('Version').qq| $form->{version}  </h1> @@ -83,24 +178,39 @@ sub login_screen {  <form method=post action=$form->{script}> +<input type=hidden name=beenthere value=1> +        <table width=100%>  	<tr>  	  <td align=center>  	    <table>  	      <tr>  		<th align=right>|.$locale->text('Name').qq|</th> -		<td><input class=login name=login size=30></td> +		<td>$form->{login}</td>  	      </tr>   	      <tr>  		<th align=right>|.$locale->text('Password').qq|</th> -		<td><input class=login type=password name=password size=30></td> +		<td><input class=login type=password name=password size=30 value=$form->{password}></td>  	      </tr>  	      <input type=hidden name=path value=$form->{path}> +	      <tr> +		<th align=right>|.$locale->text('Company').qq|</th> +		<td>|; +		 +		$checked = "checked"; +		foreach $login (sort { $login{$a} cmp $login{$b} } keys %{ $login }) { +		  print qq| +		  <br><input class=login type=radio name=login value=$login $checked>$login{$login} +		  |; +		  $checked = ""; +		} + +		print qq| +		  </td> +	      </tr>  	    </table> -  	    <br>  	    <input type=submit name=action value="|.$locale->text('Login').qq|"> -  	  </td>  	</tr>        </table> @@ -115,103 +225,101 @@ sub login_screen {  </html>  |; +  }  sub login { +  $form->{stylesheet} = "sql-ledger.css"; +  $form->{favicon} = "sql-ledger.ico"; +      $form->error($locale->text('You did not enter a name!')) unless ($form->{login}); +  if (! $form->{beenthere}) { +    open(FH, "$memberfile") or $form->error("$memberfile : $!"); +    @a = <FH>; +    close(FH); + +    @login = grep { s/\[(.*)\]/$1/ } @a; +    @company = grep { s/company=(.*)/$1/ } @a; +    shift @login; + +    for ($i = 0; $i <= $#login; $i++) { +      chop $login[$i]; +      if (($form->{login} eq $login[$i]) || ($login[$i] =~ /$form->{login}@/)) { +	chop $company[$i]; +	$login{$login[$i]} = $company[$i]; +      } +    } + +    if (keys %login > 1) { +      &selectdataset(\%login); +      exit; +    } +  } + +    $user = new User $memberfile, $form->{login};    # if we get an error back, bale out    if (($errno = $user->login(\%$form, $userspath)) <= -1) { +      $errno *= -1;      $err[1] = $locale->text('Incorrect Password!');      $err[2] = $locale->text('Incorrect Dataset version!');      $err[3] = qq|$form->{login} |.$locale->text('is not a member!'); +    $err[4] = $locale->text('Dataset is newer than version!'); -    $form->error($err[$errno]); -  } -   -  # made it this far, execute the menu -  $argv = "login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display"; +    if ($errno == 5) { +      # upgrade dataset and log in again +      open FH, ">$userspath/nologin" or $form->error($!); -  exec ("perl", "menu.pl", $argv); +      map { $form->{$_} = $user->{$_} } qw(dbname dbhost dbport dbdriver dbuser dbpasswd); -} +      $form->{dbpasswd} = unpack 'u', $form->{dbpasswd}; +       +      $form->{dbupdate} = "db$user->{dbname}"; +      $form->{$form->{dbupdate}} = 1; +      $form->header; +      print $locale->text('Upgrading to Version')." $form->{version} ... "; +      # required for Oracle +      $form->{dbdefault} = $sid; -sub logout { +      $user->dbupdate(\%$form); -  unlink "$userspath/$form->{login}.conf"; -   -  # remove the callback to display the message -  $form->{callback} = "login.pl?path=$form->{path}&action=&login="; -  $form->redirect($locale->text('You are logged out!')); +      # remove lock file +      unlink "$userspath/nologin"; -} +      print $locale->text('done'); +      print "<p><a href=menu.pl?login=$form->{login}&sessionid=$form->{sessionid}&path=$form->{path}&action=display>".$locale->text('Continue')."</a>"; +      exit; +    } -sub company_logo { -   -  require "$userspath/$form->{login}.conf"; -  $locale = new Locale $myconfig{countrycode}, "login" unless ($language eq $myconfig{countrycode}); - -  $myconfig{address} =~ s/\\n/<br>/g; -  $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost}; - -  map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet); -   -  $form->{title} = $locale->text('About'); -   -  -  # create the logo screen -  $form->header unless $form->{noheader}; +    $form->error($err[$errno]); +  } -  print qq| -<body> -<pre> +  # made it this far, execute the menu +  $form->{callback} = "menu.pl?login=$form->{login}&path=$form->{path}&action=display"; -</pre> -<center> -<a href="http://www.sql-ledger.org" target=_top><img src=sql-ledger.png border=0></a> -<h1 class=login>|.$locale->text('Version').qq| $form->{version}</h1> +  $form->redirect; +   +} -<p> -|.$locale->text('Licensed to').qq| -<p> -<b> -$myconfig{company} -<br>$myconfig{address} -</b> -<p> -<table> -  <tr> -    <th align=right>|.$locale->text('User').qq|</th> -    <td>$myconfig{name}</td> -  </tr> -  <tr> -    <th align=right>|.$locale->text('Dataset').qq|</th> -    <td>$myconfig{dbname}</td> -  </tr> -  <tr> -    <th align=right>|.$locale->text('Database Host').qq|</th> -    <td>$myconfig{dbhost}</td> -  </tr> -</table> -</center> +sub logout { -</body> -</html> -|; +  $jsc = $form->{path} =~ /js/; +  $form->{callback} = "$form->{script}?path=$form->{path}&login=$form->{login}&jsc=$jsc"; +   +  $form->redirect;  } - diff --git a/sql-ledger/bin/mozilla/menu.pl b/sql-ledger/bin/mozilla/menu.pl index 67c18bd54..fab2905e0 100644 --- a/sql-ledger/bin/mozilla/menu.pl +++ b/sql-ledger/bin/mozilla/menu.pl @@ -1,6 +1,6 @@  ######################################################################  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -24,8 +24,6 @@  #  # two frame layout with refractured menu  # -# CHANGE LOG: -#   DS. 2002-03-25  Created  #######################################################################  $menufile = "menu.ini"; @@ -38,16 +36,17 @@ use SL::Menu;  sub display { -  $framesize = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "135"; +  $menuwidth = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "155"; +  $menuwidth = $myconfig{menuwidth} if $myconfig{menuwidth}; -  $form->header; +  $form->header(1);    print qq| -<FRAMESET COLS="$framesize,*" BORDER="1"> +<FRAMESET COLS="$menuwidth,*" BORDER="1"> -  <FRAME NAME="acc_menu" SRC="$form->{script}?login=$form->{login}&password=$form->{password}&action=acc_menu&path=$form->{path}"> -  <FRAME NAME="main_window" SRC="login.pl?login=$form->{login}&password=$form->{password}&action=company_logo&path=$form->{path}"> +  <FRAME NAME="acc_menu" SRC="$form->{script}?login=$form->{login}&sessionid=$form->{sessionid}&action=acc_menu&path=$form->{path}"> +  <FRAME NAME="main_window" SRC="am.pl?login=$form->{login}&sessionid=$form->{sessionid}&action=company_logo&path=$form->{path}">  </FRAMESET> @@ -99,14 +98,15 @@ sub section_menu {      $label =~ s/.*--//g;      $label = $locale->text($label); -    $label =~ s/ / /g; +    $label =~ s/ / /g if $label !~ /<img /i;      $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};      if ($menu->{$item}{submenu}) { +        $menu->{$item}{$item} = !$form->{$item}; -      if ($form->{level} && $item =~ /^$form->{level}/) { +      if ($form->{level} && $item =~ $form->{level}) {          # expand menu  	print qq|<br>\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|; @@ -119,42 +119,40 @@ sub section_menu {  	print qq|<br>\n|;        } else { -	 +  	print qq|<br>\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label ...</a>|;          # remove same level items  	map { shift @menuorder } grep /^$item/, @menuorder;        } -      } else {        if ($menu->{$item}{module}) { -	if ($form->{$item} && $form->{level} eq $item) { -	  $menu->{$item}{$item} = !$form->{$item}; -	  print qq|<br>\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|; -	   -	  # remove same level items -	  map { shift @menuorder } grep /^$item/, @menuorder; -	   -	  §ion_menu($menu, $item); - -	} else { -	  print qq|<br>\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|; -	} + +	print qq|<br>\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|;        } else { -	 -	print qq|<br><b>$label</b>|; + +        $form->{tag}++; +	print qq|<a name="id$form->{tag}"></a> +	<p><b>$label</b>|;  	§ion_menu($menu, $item);  	print qq|<br>\n|; -	 +        }      }    }  } +sub menubar { + +  1; + +} + + diff --git a/sql-ledger/bin/mozilla/oe.pl b/sql-ledger/bin/mozilla/oe.pl index 6a8326ff2..1c494c11f 100644 --- a/sql-ledger/bin/mozilla/oe.pl +++ b/sql-ledger/bin/mozilla/oe.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger, Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -22,6 +22,7 @@  #======================================================================  #  # Order entry module +# Quotation module  #  #====================================================================== @@ -31,8 +32,9 @@ use SL::IR;  use SL::IS;  use SL::PE; -require "$form->{path}/io.pl";  require "$form->{path}/arap.pl"; +require "$form->{path}/io.pl"; +  1;  # end of main @@ -48,6 +50,16 @@ sub add {      $form->{title} = $locale->text('Add Sales Order');      $form->{vc} = 'customer';    } +  if ($form->{type} eq 'request_quotation') { +    $form->{title} = $locale->text('Add Request for Quotation'); +    $form->{vc} = 'vendor'; +  } +  if ($form->{type} eq 'sales_quotation') { +    $form->{title} = $locale->text('Add Quotation'); +    $form->{vc} = 'customer'; +  } + +  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};    &order_links;    &prepare_order; @@ -57,61 +69,122 @@ sub add {  sub edit { - -  if ($form->{type} eq 'purchase_order') { +   +  if ($form->{type} =~ /(purchase_order|bin_list)/) {      $form->{title} = $locale->text('Edit Purchase Order');      $form->{vc} = 'vendor'; +    $form->{type} = 'purchase_order';    } -  if ($form->{type} eq 'sales_order') { +  if ($form->{type} =~ /((sales|work)_order|(packing|pick)_list)/) {      $form->{title} = $locale->text('Edit Sales Order');      $form->{vc} = 'customer'; +    $form->{type} = 'sales_order';    } -   +  if ($form->{type} eq 'request_quotation') { +    $form->{title} = $locale->text('Edit Request for Quotation'); +    $form->{vc} = 'vendor'; +  } +  if ($form->{type} eq 'sales_quotation') { +    $form->{title} = $locale->text('Edit Quotation'); +    $form->{vc} = 'customer'; +  } +    &order_links;    &prepare_order; -    &display_form; - +    } +  sub order_links { +   +  # get customer/vendor +  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); +   +  $form->get_partsgroup(\%myconfig); +  if (@{ $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };  +  } -  # get vendors / customers -  $form->all_vc(\%myconfig, $form->{vc}); +  # retrieve order/quotation +  OE->retrieve(\%myconfig, \%$form); +   +  # currencies +  @curr = split /:/, $form->{currencies}; +  chomp $curr[0]; +  $form->{defaultcurrency} = $curr[0]; +  $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; +   +  map { $form->{selectcurrency} .= "<option>$_\n" } @curr; -  # retrieve order -  OE->retrieve_order(\%myconfig, \%$form); +  $form->{oldlanguage_code} = $form->{language_code}; -  $taxincluded = $form->{taxincluded}; +  $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} }); +   +  if (@{ $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    foreach $ref (@ { $form->{all_partsgroup} }) { +      if ($ref->{translation}) { +	$form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|; +      } else { +	$form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|; +      } +    } +  } + +  if (@{ $form->{all_projects} }) { +    $form->{selectprojectnumber} = "<option>\n"; +    map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; +  } +     $form->{shipto} = 1 if $form->{id}; +  if (@{ $form->{"all_$form->{vc}"} }) { +    unless ($form->{"$form->{vc}_id"}) { +      $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id}; +    } +  } +      # get customer / vendor -  if ($form->{type} eq 'purchase_order') { +  if ($form->{type} =~ /(purchase_order|request_quotation|receive_order)/ ) {      IR->get_vendor(\%myconfig, \%$form);    } -  if ($form->{type} eq 'sales_order') { +  if ($form->{type} =~ /(sales|ship)_(order|quotation)/) {      IS->get_customer(\%myconfig, \%$form);    }    ($form->{$form->{vc}}) = split /--/, $form->{$form->{vc}};    $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; -  # build the popup menus +  # build selection list    if (@{ $form->{"all_$form->{vc}"} }) {      $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; -    map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{"all_$form->{vc}"} }); +    map { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{"all_$form->{vc}"} });    } -  # currencies -  @curr = split /:/, $form->{currencies}; -  chomp $curr[0]; -  $form->{defaultcurrency} = $curr[0]; -   -  map { $form->{selectcurrency} .= "<option>$_\n" } @curr; +  # departments +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; +    $form->{department} = "$form->{department}--$form->{department_id}"; -  $form->{taxincluded} = $taxincluded if ($form->{id}); +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $form->{employee} = "$form->{employee}--$form->{employee_id}"; + +  # sales staff +  if (@{ $form->{all_employees} }) { +    $form->{selectemployee} = ""; +    map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_employees} }); +  } +  if (@{ $form->{all_languages} }) { +    $form->{selectlanguage} = "<option>\n"; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} }; +  } +      # forex    $form->{forex} = $form->{exchangerate}; @@ -120,16 +193,22 @@ sub order_links {  sub prepare_order { -  $form->{format} = "html"; -  $form->{media} = "screen"; -   +  $form->{format} = "postscript" if $myconfig{printer}; +  $form->{media} = $myconfig{printer}; +  $form->{formname} = $form->{type}; +  $form->{oldcurrency} = $form->{currency}; +     if ($form->{id}) { -    map { $form->{$_} =~ s/"/"/g } qw(invnumber shippingpoint notes shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact); +    map { $form->{$_} = $form->quote($form->{$_}) } qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact); -    foreach $ref (@{ $form->{order_details} } ) { +    foreach $ref (@{ $form->{form_details} } ) {        $i++;        map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + +      $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}|; +      $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}|; +        $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);        ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); @@ -138,12 +217,26 @@ sub prepare_order {        $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);        $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); +      $form->{"oldqty_$i"} = $form->{"qty_$i"}; -      map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); +      map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit);        $form->{rowcount} = $i;      }    } +  if ($form->{type} eq 'sales_quotation') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/; +  } +  if ($form->{type} eq 'request_quotation') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/; +  } +  if ($form->{type} eq 'sales_order') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Sales Order/; +  } +  if ($form->{type} eq 'purchase_order') { +    $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Purchase Order/; +  } +  } @@ -155,40 +248,36 @@ sub form_header {    if ($form->{id}) {      $openclosed = qq|        <tr> -        <td colspan=2 align=center> -	  <table> -	    <tr> -	      <th nowrap><input name=closed type=radio class=radio value=0 $checkedopen> |.$locale->text('Open').qq|</th> -	      <th nowrap><input name=closed type=radio class=radio value=1 $checkedclosed> |.$locale->text('Closed').qq|</th> -	    </tr> -	  </table> -	</td> +	<th nowrap align=right><input name=closed type=radio class=radio value=0 $checkedopen> |.$locale->text('Open').qq|</th> +	<th nowrap align=left><input name=closed type=radio class=radio value=1 $checkedclosed> |.$locale->text('Closed').qq|</th>        </tr>  |;    }    # set option selected -  foreach $item ($form->{vc}, currency) { +  $form->{selectcurrency} =~ s/ selected//; +  $form->{selectcurrency} =~ s/option>\Q$form->{currency}\E/option selected>$form->{currency}/;  +   +  foreach $item ($form->{vc}, department, employee) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"});      $form->{"select$item"} =~ s/ selected//; -    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/;    } +      $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); -  $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); -  $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); -      $exchangerate = qq|  <input type=hidden name=forex value=$form->{forex}>  |;    if ($form->{currency} ne $form->{defaultcurrency}) {      if ($form->{forex}) { -      $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td>$form->{exchangerate}</td> +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}</td>        <input type=hidden name=exchangerate value=$form->{exchangerate}>  |;      } else { -      $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|; +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;      }    } @@ -196,45 +285,160 @@ sub form_header {    $vclabel = ucfirst $form->{vc};    $vclabel = $locale->text($vclabel); -  if ($form->{type} eq 'sales_order') { +  $terms = qq| +                    <tr> +		      <th align=right nowrap>|.$locale->text('Terms').qq|</th> +		      <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |.$locale->text('days').qq|</td> +                    </tr> +|; + + +  if ($form->{business}) { +    $business = qq| +	      <tr> +		<th align=right>|.$locale->text('Business').qq|</th> +		<td>$form->{business}</td> +		<th align=right>|.$locale->text('Trade Discount').qq|</th> +		<td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td> +	      </tr> +|; +  } + +  if ($form->{type} !~ /_quotation$/) { +    $ordnumber = qq| +	      <tr> +		<th width=70% align=right nowrap>|.$locale->text('Order Number').qq|</th> +                <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td> +		<input type=hidden name=quonumber value="$form->{quonumber}"> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Order Date').qq|</th> +		<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td> +	      </tr> +	      <tr> +		<th align=right nowrap=true>|.$locale->text('Required by').qq|</th> +		<td><input name=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td> +	      </tr> +|; -    $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; +    $n = ($form->{creditremaining} < 0) ? "0" : "1";      $creditremaining = qq|  	      <tr>  		<td></td>  		<td colspan=3> -		  <table width=100%> +		  <table>  		    <tr> -		      <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th> -		      <td>$form->{creditlimit}</td> -		      <th align=left nowrap>|.$locale->text('Remaining').qq|</th> -		      <td class="plus$n">$form->{creditremaining}</td> +		      <th nowrap>|.$locale->text('Credit Limit').qq|</th> +		      <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td> +		      <td width=20%></td> +		      <th nowrap>|.$locale->text('Remaining').qq|</th> +		      <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>  		    </tr>  		  </table>  		</td>  	      </tr>  |; +  } else { +    $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by'); +    if ($form->{type} eq 'sales_quotation') { +      $ordnumber = qq| +	      <tr> +		<th width=70% align=right nowrap>|.$locale->text('Quotation Number').qq|</th> +		<td><input name=quonumber size=20 value="$form->{quonumber}"></td> +		<input type=hidden name=ordnumber value="$form->{ordnumber}"> +	      </tr> +|; +    } else { +      $ordnumber = qq| +	      <tr> +		<th width=70% align=right nowrap>|.$locale->text('RFQ Number').qq|</th> +		<td><input name=quonumber size=20 value="$form->{quonumber}"></td> +		<input type=hidden name=ordnumber value="$form->{ordnumber}"> +	      </tr> +|; + +      $terms = ""; +    } +      + +    $ordnumber .= qq| +	      <tr> +		<th align=right nowrap>|.$locale->text('Quotation Date').qq|</th> +		<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td> +	      </tr> +	      <tr> +		<th align=right nowrap=true>$reqlabel</th> +		<td><input name=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td> +	      </tr> +|; +    } -  $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">| : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|; +  if ($form->{"select$form->{vc}"}) { +    $vc = qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select> +             <input type=hidden name="select$form->{vc}" value="| +	     .$form->escape($form->{"select$form->{vc}"},1).qq|">|; +  } else { +    $vc = qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|; +  } + +  $department = qq| +              <tr> +	        <th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td colspan=3><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="| +		.$form->escape($form->{selectdepartment},1).qq|"> +		</td> +	      </tr> +| if $form->{selectdepartment}; + +  $employee = qq| +              <input type=hidden name=employee value="$form->{employee}"> +|; +  if ($form->{type} eq 'sales_order') { +    if ($form->{selectemployee}) { +      $employee = qq| + 	      <tr> +	        <th align=right nowrap>|.$locale->text('Salesperson').qq|</th> +		<td><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|. +		$form->escape($form->{selectemployee},1).qq|" +	      </tr> +|; +    } +  } else { +      $employee = qq| + 	      <tr> +	        <th align=right nowrap>|.$locale->text('Employee').qq|</th> +		<td><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|. +		$form->escape($form->{selectemployee},1).qq|" +	      </tr> +|; +  } +      $form->header;    print qq|  <body> -<form method=post action=$form->{script}> +<form method=post action="$form->{script}#end">  <input type=hidden name=id value=$form->{id}>  <input type=hidden name=type value=$form->{type}> +<input type=hidden name=formname value=$form->{formname}>  <input type=hidden name=media value=$form->{media}>  <input type=hidden name=format value=$form->{format}> +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=printed value="$form->{printed}"> +<input type=hidden name=emailed value="$form->{emailed}"> +  <input type=hidden name=vc value=$form->{vc}> -<input type=hidden name=employee value="$form->{employee}">  <input type=hidden name=title value="$form->{title}"> @@ -242,8 +446,12 @@ sub form_header {  <input type=hidden name=creditlimit value=$form->{creditlimit}>  <input type=hidden name=creditremaining value=$form->{creditremaining}> +<input type=hidden name=tradediscount value=$form->{tradediscount}> +<input type=hidden name=business value="$form->{business}"> + +  <table width=100%> -  <tr> +  <tr class=listtop>      <th class=listtop>$form->{title}</th>    </tr>    <tr height="5"></tr> @@ -252,7 +460,7 @@ sub form_header {        <table width="100%">          <tr valign=top>  	  <td> -	    <table> +	    <table width=100%>  	      <tr>  		<th align=right>$vclabel</th>  		<td colspan=3>$vc</td> @@ -260,6 +468,8 @@ sub form_header {  		<input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">  	      </tr>  	      $creditremaining +	      $business +	      $department  	      <tr>  		<th align=right>|.$locale->text('Currency').qq|</th>  		<td><select name=currency>$form->{selectcurrency}</select></td> @@ -268,30 +478,21 @@ sub form_header {  		$exchangerate  	      </tr>  	      <tr> -		<th align=right>|.$locale->text('Ship via').qq|</th> +		<th align=right>|.$locale->text('Shipping Point').qq|</th>  		<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>  	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Ship via').qq|</th> +		<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td> +	      </tr>  	    </table>  	  </td>  	  <td align=right> -	    <table width=100%> +	    <table>  	      $openclosed -	      <tr> -		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> -		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td> -	      </tr> -	      <tr> -		<th align=right nowrap>|.$locale->text('Order Date').qq|</th> -		<td><input name=orddate size=11 title="$myconfig{dateformat}" value=$form->{orddate}></td> -	      </tr> -	      <tr> -		<th align=right nowrap=true>|.$locale->text('Required by').qq|</th> -		<td><input name=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td> -	      </tr> -	      <tr> -		<th align=right nowrap>|.$locale->text('Terms: Net').qq|</th> -		<td nowrap=true><input name=terms size="3" maxlength="3" value=$form->{terms}> |.$locale->text('days').qq|</td> -	      </tr> +	      $employee +	      $ordnumber +	      $terms  	    </table>  	  </td>  	</tr> @@ -302,10 +503,12 @@ sub form_header {  <!-- shipto are in hidden variables -->  <input type=hidden name=shiptoname value="$form->{shiptoname}"> -<input type=hidden name=shiptoaddr1 value="$form->{shiptoaddr1}"> -<input type=hidden name=shiptoaddr2 value="$form->{shiptoaddr2}"> -<input type=hidden name=shiptoaddr3 value="$form->{shiptoaddr3}"> -<input type=hidden name=shiptoaddr4 value="$form->{shiptoaddr4}"> +<input type=hidden name=shiptoaddress1 value="$form->{shiptoaddress1}"> +<input type=hidden name=shiptoaddress2 value="$form->{shiptoaddress2}"> +<input type=hidden name=shiptocity value="$form->{shiptocity}"> +<input type=hidden name=shiptostate value="$form->{shiptostate}"> +<input type=hidden name=shiptozipcode value="$form->{shiptozipcode}"> +<input type=hidden name=shiptocountry value="$form->{shiptocountry}">  <input type=hidden name=shiptocontact value="$form->{shiptocontact}">  <input type=hidden name=shiptophone value="$form->{shiptophone}">  <input type=hidden name=shiptofax value="$form->{shiptofax}"> @@ -338,16 +541,28 @@ sub form_footer {    $form->{invtotal} = $form->{invsubtotal}; -  if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { +  if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {      $rows = 2;    } -  $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; +  if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { +    $introws = 2; +  } +  $rows = ($rows > $introws) ? $rows : $introws; +  $notes = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|; +  $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|; + -  $taxincluded = "";    $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + +  $taxincluded = "";    if ($form->{taxaccounts}) {      $taxincluded = qq| -		<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br> +            <tr height="5"></tr> +            <tr> +	      <td align=right> +	      <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td> +	      <th align=left>|.$locale->text('Tax Included').qq|</th> +	    </tr>  |;    } @@ -381,30 +596,33 @@ sub form_footer {    $form->{oldinvtotal} = $form->{invtotal};    $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); +    print qq|    <tr>      <td>        <table width=100%> -	<tr valign=bottom> +	<tr valign=top>  	  <td>  	    <table>  	      <tr>  		<th align=left>|.$locale->text('Notes').qq|</th> +		<th align=left>|.$locale->text('Internal Notes').qq|</th>  	      </tr> -	      <tr> +	      <tr valign=top>  		<td>$notes</td> +		<td>$intnotes</td>  	      </tr>  	    </table>  	  </td> -	  <td align=right width=100%> -	    $taxincluded -	    <table width=100%> +	  <td align=right> +	    <table>  	      $subtotal  	      $tax  	      <tr>  		<th align=right>|.$locale->text('Total').qq|</th>  		<td align=right>$form->{invtotal}</td>  	      </tr> +	      $taxincluded  	    </table>  	  </td>  	</tr> @@ -414,6 +632,9 @@ sub form_footer {  <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>  <input type=hidden name=oldtotalpaid value=$totalpaid>    <tr> +    <td><hr size=3 noshade></td> +  </tr> +  <tr>      <td>  |; @@ -422,12 +643,13 @@ sub form_footer {    print qq|      </td>    </tr> -  <tr> -    <td><hr size=3 noshade></td> -  </tr>  </table>  <br> +|; + +  if (! $form->{readonly}) { +    print qq|  <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">  <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">  <input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> @@ -435,13 +657,68 @@ sub form_footer {  <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">  |; +    if ($latex) { +      print qq| +<input class=submit type=submit name=action value="|.$locale->text('Print and Save').qq|">|; +    } +          if ($form->{id}) {        print qq|  <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|"> -<input class=submit type=submit name=action value="|.$locale->text('Invoice').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|; + +      if ($form->{type} =~ /sales_/) { +	if ($myconfig{acs} !~ /AP--Sales Invoice/) { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> +|; +	} +      } else { +	if ($myconfig{acs} !~ /AR--Vendor Invoice/) { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> +|; +	} +      } +	 +      if ($form->{type} eq 'sales_order') { +        if ($myconfig{acs} !~ /Quotations--RFQ/) { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|"> +|; +	} +      } +       +      if ($form->{type} eq 'purchase_order') { +	if ($myconfig{acs} !~ /Quotations--RFQ/) { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('RFQ').qq|"> +|; +	} +      } +       +      if ($form->{type} eq 'sales_quotation') { +	if ($myconfig{acs} !~ /Order Entry--Sales Order/) { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|"> +|; +	} +      } +       +      if ($myconfig{acs} !~ /Order Entry--Purchase Order/) { +	if ($form->{type} eq 'request_quotation') { +	  print qq| +<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|">  |; +	} +      }      } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  }    print qq|  @@ -451,10 +728,12 @@ sub form_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  </form> +<a name=end></a> +  </body>  </html>  |; @@ -464,40 +743,45 @@ sub form_footer {  sub update { -  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); +  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate);    &check_name($form->{vc}); -  &check_project;    $buysell = 'buy';    $buysell = 'sell' if ($form->{vc} eq 'vendor'); -  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{orddate}, $buysell))); +  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell))); -    my $i = $form->{rowcount};    $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; +  foreach $item (qw(partsgroup projectnumber)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"}; +  } +    if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {      $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});      &check_form; - +        } else { -    -    if ($form->{type} eq 'purchase_order') { + +    if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {        IR->retrieve_item(\%myconfig, \%$form);      } -    if ($form->{type} eq 'sales_order') { +    if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {        IS->retrieve_item(\%myconfig, \%$form);      } -    my $rows = scalar @{ $form->{item_list} }; -     +    $rows = scalar @{ $form->{item_list} }; +      $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);      if ($rows) { -      $form->{"qty_$i"}                     = 1 unless ($form->{"qty_$i"}); +      $form->{"qty_$i"}		= 1; +      if ($form->{type} !~ /_quotation/) { +	$form->{"reqdate_$i"}	= $form->{reqdate} unless $form->{"reqdate_$i"}; +      }        if ($rows > 1) { @@ -508,7 +792,7 @@ sub update {  	$sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); -	map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit); +	map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);  	map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };  	$s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; @@ -520,10 +804,13 @@ sub update {          if ($sellprice) {  	  $form->{"sellprice_$i"} = $sellprice;  	} else { -	  # if there is an exchange rate adjust sellprice +	  # if there is an exchange rate adjust prices +	  $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});  	  $form->{"sellprice_$i"} /= $exchangerate;  	} +	map { $form->{"${_}_$i"} /= $exchangerate } qw(listprice lastcost); +  	$amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);  	map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});  	map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"}); @@ -531,7 +818,8 @@ sub update {  	$form->{creditremaining} -= $amount; -	$form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); +	map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost); +	  	$form->{"qty_$i"} =  $form->format_amount(\%myconfig, $form->{"qty_$i"});        } @@ -540,21 +828,23 @@ sub update {      } else {        # ok, so this is a new part        # ask if it is a part or service item -       +        if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {  	$form->{rowcount}--;  	$form->{"discount_$i"} = "";  	&display_form;        } else { -	 -	$form->{"id_$i"}		= 0; +		 +	$form->{"id_$i"}	= 0;  	$form->{"unit_$i"}	= $locale->text('ea'); +	$form->{"reqdate_$i"}	= $form->{reqdate} if $form->{type} !~ /_quotation/;  	&new_item;        }      }    } +  } @@ -564,16 +854,79 @@ sub search {    if ($form->{type} eq 'purchase_order') {      $form->{title} = $locale->text('Purchase Orders');      $form->{vc} = 'vendor'; +    $ordlabel = $locale->text('Order Number'); +    $ordnumber = 'ordnumber'; +    $employee = $locale->text('Employee'); +  } +  if ($form->{type} eq 'request_quotation') { +    $form->{title} = $locale->text('Request for Quotations'); +    $form->{vc} = 'vendor'; +    $ordlabel = $locale->text('RFQ Number'); +    $ordnumber = 'quonumber'; +    $employee = $locale->text('Employee'); +  } +  if ($form->{type} eq 'receive_order') { +    $form->{title} = $locale->text('Receive Merchandise'); +    $form->{vc} = 'vendor'; +    $ordlabel = $locale->text('Order Number'); +    $ordnumber = 'ordnumber'; +    $employee = $locale->text('Employee');    }    if ($form->{type} eq 'sales_order') {      $form->{title} = $locale->text('Sales Orders');      $form->{vc} = 'customer'; +    $ordlabel = $locale->text('Order Number'); +    $ordnumber = 'ordnumber'; +    $employee = $locale->text('Salesperson'); +  } +  if ($form->{type} eq 'ship_order') { +    $form->{title} = $locale->text('Ship Merchandise'); +    $form->{vc} = 'customer'; +    $ordlabel = $locale->text('Order Number'); +    $ordnumber = 'ordnumber'; +    $employee = $locale->text('Salesperson'); + +  } +   +  if ($form->{type} eq 'sales_quotation') { +    $form->{title} = $locale->text('Quotations'); +    $form->{vc} = 'customer'; +    $ordlabel = $locale->text('Quotation Number'); +    $ordnumber = 'quonumber'; +    $employee = $locale->text('Employee'); +  } + +  $manager = qq| +	        <td><input name="l_manager" class=checkbox type=checkbox value=Y> |.$locale->text('Manager').qq|</td>|; + +  if ($form->{type} =~ /(ship|receive)_order/) { +    OE->get_warehouses(\%myconfig, \%$form); + +    $manager = ""; + +    # warehouse +    if (@{ $form->{all_warehouses} }) { +      $form->{selectwarehouse} = "<option>\n"; +      $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|; + +      map { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} }); + +      $warehouse = qq| +	      <tr> +		<th align=right>|.$locale->text('Warehouse').qq|</th> +		<td><select name=warehouse>$form->{selectwarehouse}</select></td> +		<input type=hidden name=selectwarehouse value="|. +		$form->escape($form->{selectwarehouse},1).qq|"> +	      </tr> +|; + +    }    }    # setup vendor / customer selection -  $form->all_vc(\%myconfig, "$form->{vc}"); +  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); -  map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; +  map { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} };    $vclabel = ucfirst $form->{vc};    $vclabel = $locale->text($vclabel); @@ -583,6 +936,56 @@ sub search {    $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|; +  # departments   +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } + +  $department = qq|   +        <tr>   +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +| if $form->{selectdepartment};  + +  if ($form->{type} !~ /(ship|receive)_order/) { +    $openclosed = qq| +	      <tr> +	        <td><input name="open" class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|</td> +	        <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |.$locale->text('Closed').qq|</td> +	      </tr> +|; +  } else { +     +     $openclosed = qq| +	        <input type=hidden name="open" value=1> +|; +  } + +   +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +    $form->header;    print qq| @@ -602,36 +1005,47 @@ sub search {            <th align=right>$vclabel</th>            <td colspan=3>$vc</td>          </tr> +	$warehouse +	$department          <tr> -          <th align=right>|.$locale->text('Order Number').qq|</th> -          <td colspan=3><input name=ordnumber size=20></td> +          <th align=right>$ordlabel</th> +          <td colspan=3><input name="$ordnumber" size=20></td> +        </tr> +        <tr> +          <th align=right>|.$locale->text('Ship via').qq|</th> +          <td colspan=3><input name="shipvia" size=40></td>          </tr>          <tr>            <th align=right>|.$locale->text('From').qq|</th>            <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td> -          <th align=right>|.$locale->text('to').qq|</th> +          <th align=right>|.$locale->text('To').qq|</th>            <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>          </tr>          <input type=hidden name=sort value=transdate> +	$selectfrom          <tr>            <th align=right>|.$locale->text('Include in Report').qq|</th>            <td colspan=3>  	    <table> +	      $openclosed  	      <tr> -	        <td><input name="open" class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|</td> -	        <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |.$locale->text('Closed').qq|</td> -	      </tr> -	      <tr> -		<td><input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID').qq|</td> -		<td><input name="l_ordnumber" class=checkbox type=checkbox value=Y checked> |.$locale->text('Order Number').qq|</td> -		<td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Order Date').qq|</td> +		<td><input name="l_id" class=checkbox type=checkbox value=Y> +		|.$locale->text('ID').qq|</td> +		<td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td> +		<td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date').qq|</td>  		<td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Required by').qq|</td>  	      </tr>  	      <tr>  	        <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td> +	        <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td> +		$manager +		<td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |.$locale->text('Ship via').qq|</td> +	      </tr> +	      <tr>  		<td><input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount').qq|</td>  		<td><input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax').qq|</td>  		<td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total').qq|</td> +		<td><input name="l_curr" class=checkbox type=checkbox value=Y checked> |.$locale->text('Currency').qq|</td>  	      </tr>  	      <tr>  	        <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> @@ -646,10 +1060,12 @@ sub search {  </table>  <br> -<input type=hidden name=nextsub value=orders> +<input type=hidden name=nextsub value=transactions> +  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +  <input type=hidden name=vc value=$form->{vc}>  <input type=hidden name=type value=$form->{type}> @@ -663,29 +1079,47 @@ sub search {  } -sub orders { +sub transactions { -  $name = $form->{$form->{vc}}; -      # split vendor / customer    ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}}); +  $ordnumber = ($form->{type} =~ /_order/) ? 'ordnumber' : 'quonumber'; +      OE->transactions(\%myconfig, \%$form); +  $number = $form->escape($form->{$ordnumber}); +  $name = $form->escape($form->{$form->{vc}}); +  $department = $form->escape($form->{department}); +  $warehouse = $form->escape($form->{warehouse}); +  $shipvia = $form->escape($form->{shipvia}); +      # construct href -  $href = "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&ordnumber=" . $form->escape($form->{ordnumber}) . "&$form->{vc}=" . $form->escape($form->{$form->{vc}}); +  $href = qq|$form->{script}?oldsort=$form->{oldsort}&direction=$form->{direction}&path=$form->{path}&action=transactions&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name--$form->{"$form->{vc}_id"}&department=$department&warehouse=$warehouse&shipvia=$shipvia|;    # construct callback -  $name =~ s/&/_/g; -  $callback = "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&ordnumber=$form->{ordnumber}&$form->{vc}=$name"; +  $number = $form->escape($form->{$ordnumber},1); +  $name = $form->escape($form->{$form->{vc}},1); +  $department = $form->escape($form->{department},1); +  $warehouse = $form->escape($form->{warehouse},1); +  $shipvia = $form->escape($form->{shipvia},1); +   +  # flip direction +  $form->sort_order(); +     +  $callback = qq|$form->{script}?oldsort=$form->{oldsort}&direction=$form->{direction}&path=$form->{path}&action=transactions&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name--$form->{"$form->{vc}_id"}&department=$department&warehouse=$warehouse&shipvia=$shipvia|; -  @columns = $form->sort_columns(qw(transdate reqdate id ordnumber name netamount tax amount curr open closed)); +  @columns = $form->sort_columns("transdate", "reqdate", "id", "$ordnumber", "name", "netamount", "tax", "amount", "curr", "employee", "manager", "shipvia", "open", "closed");    $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed}) ;    foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") {        push @column_index, $item; + +      if ($form->{l_curr} && $item =~ /(amount|tax)/) { +	push @column_index, "fx_$item"; +      }        # add column to href and callback        $callback .= "&l_$item=Y"; @@ -699,74 +1133,151 @@ sub orders {    } +  $i = 1;     if ($form->{vc} eq 'vendor') { -    $form->{title} = $locale->text('Purchase Orders'); +    if ($form->{type} eq 'receive_order') { +      $form->{title} = $locale->text('Receive Merchandise'); +    } elsif ($form->{type} eq 'purchase_order') { +      $form->{title} = $locale->text('Purchase Orders'); + +      if ($myconfig{acs} !~ /Order Entry--Order Entry/) { +	$button{'Order Entry--Purchase Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|"> |; +	$button{'Order Entry--Sales Order'}{order} = $i++; +      } + +    } else { +      $form->{title} = $locale->text('Request for Quotations'); + +      if ($myconfig{acs} !~ /Quotations--Quotations/) { +	$button{'Quotations--RFQ'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('RFQ ').qq|"> |; +	$button{'Quotations--RFQ'}{order} = $i++; +      } +       +    }      $name = $locale->text('Vendor'); +    $employee = $locale->text('Employee');    }    if ($form->{vc} eq 'customer') { -    $form->{title} = $locale->text('Sales Orders'); +    if ($form->{type} eq 'sales_order') { +      $form->{title} = $locale->text('Sales Orders'); +      $employee = $locale->text('Salesperson'); + +      if ($myconfig{acs} !~ /Order Entry--Order Entry/) { +	$button{'Order Entry--Sales Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|"> |; +	$button{'Order Entry--Sales Order'}{order} = $i++; +      } + +    } elsif ($form->{type} eq 'ship_order') { +      $form->{title} = $locale->text('Ship Merchandise'); +      $employee = $locale->text('Salesperson'); +    } else { +      $form->{title} = $locale->text('Quotations'); +      $employee = $locale->text('Employee'); + +      if ($myconfig{acs} !~ /Quotations--Quotations/) { +	$button{'Quotations--Quotation'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Quotation ').qq|"> |; +	$button{'Quotations--Quotation'}{order} = $i++; +      } +       +    }      $name = $locale->text('Customer');    } -  + +  foreach $item (split /;/, $myconfig{acs}) { +    delete $button{$item}; +  } +    $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;    $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;    $column_header{reqdate} = qq|<th><a class=listheading href=$href&sort=reqdate>|.$locale->text('Required by').qq|</a></th>|;    $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|; +  $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;    $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;    $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;    $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;    $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|; -  $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|; +  $column_header{curr} = qq|<th><a class=listheading href=$href&sort=curr>|.$locale->text('Curr').qq|</a></th>|; +  $column_header{shipvia} = qq|<th><a class=listheading href=$href&sort=shipvia>|.$locale->text('Ship via').qq|</a></th>|;    $column_header{open} = qq|<th class=listheading>|.$locale->text('O').qq|</th>|;    $column_header{closed} = qq|<th class=listheading>|.$locale->text('C').qq|</th>|; -  if ($form->{open}) { -    $option = $locale->text('Open'); -  } -  if ($form->{closed}) { -    $option .= " : " if $form->{open}; -    $option .= $locale->text('Closed'); -  } +  $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|; +  $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|; + +  map { $column_header{"fx_$_"} = "<th> </th>" } qw(amount tax netamount); +      if ($form->{$form->{vc}}) { -    $option .= "\n<br>"; -    $option .= ucfirst $form->{vc}; +    $option = $locale->text(ucfirst $form->{vc});      $option .= " : $form->{$form->{vc}}";    } +  if ($form->{warehouse}) { +    ($warehouse) = split /--/, $form->{warehouse}; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Warehouse'); +    $option .= " : $warehouse"; +  } +  if ($form->{department}) { +    $option .= "\n<br>" if ($option); +    ($department) = split /--/, $form->{department}; +    $option .= $locale->text('Department')." : $department"; +  }    if ($form->{transdatefrom}) {      $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);    }    if ($form->{transdateto}) { -    $option .= "\n<br>".$locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +    $option .= "\n<br>".$locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); +  } +  if ($form->{open}) { +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Open'); +  } +  if ($form->{closed}) { +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Closed');    }    $form->header; -  $colspan = $#column_index + 1; -    print qq|  <body>  <table width=100%> -  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr>    <tr height="5"></tr>    <tr> -    <td colspan=$colspan>$option</td> +    <td>$option</td>    </tr> -  <tr class=listheading>|; +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; -map { print "\n$column_header{$_}" } @column_index; +  map { print "\n$column_header{$_}" } @column_index; -print qq| -  </tr> +  print qq| +	</tr>  |;    # add sort and escape callback -  $callback = $form->escape($callback . "&sort=$form->{sort}"); +  $callback .= "&sort=$form->{sort}"; +  $form->{callback} = $callback; +  $callback = $form->escape($callback); + +  # flip direction +  $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC"; +  $href =~ s/&direction=(\w+)&/&direction=$direction&/;    if (@{ $form->{OE} }) {      $sameitem = $form->{OE}->[0]->{$form->{sort}};    } +  $action = "edit"; +  $action = "ship_receive" if ($form->{type} =~ /(ship|receive)_order/); + +  $warehouse = $form->escape($form->{warehouse}); +    foreach $oe (@{ $form->{OE} }) {      if ($form->{l_subtotal} eq 'Y') { @@ -776,11 +1287,23 @@ print qq|        }      } -    map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount)); +    if ($form->{l_curr}) { +      map { $oe->{"fx_$_"} = $oe->{$_} } (qw(netamount amount)); +      $oe->{fx_tax} = $oe->{fx_amount} - $oe->{fx_netamount}; +      map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount)); + +      map { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{"fx_$_"}, 2, " ")."</td>" } qw(netamount amount); +      $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{fx_amount} - $oe->{fx_netamount}, 2, " ")."</td>";  +       +      $totalfxnetamount += $oe->{fx_netamount};  +      $totalfxamount += $oe->{fx_amount}; + +      $subtotalfxnetamount += $oe->{fx_netamount}; +      $subtotalfxamount += $oe->{fx_amount}; +    } -    $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")."</td>"; +    map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{$_}, 2, " ")."</td>" } qw(netamount amount);      $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount}, 2, " ")."</td>"; -    $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount}, 2, " ")."</td>";      $totalnetamount += $oe->{netamount};      $totalamount += $oe->{amount}; @@ -788,28 +1311,34 @@ print qq|      $subtotalnetamount += $oe->{netamount};      $subtotalamount += $oe->{amount}; +      $column_data{id} = "<td>$oe->{id}</td>";      $column_data{transdate} = "<td>$oe->{transdate} </td>";      $column_data{reqdate} = "<td>$oe->{reqdate} </td>"; -    $column_data{ordnumber} = "<td><a href=oe.pl?path=$form->{path}&action=edit&type=$form->{type}&id=$oe->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$oe->{ordnumber}</a></td>"; -    $column_data{name} = "<td>$oe->{name}</td>"; +    $column_data{$ordnumber} = "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$oe->{$ordnumber}</a></td>"; + +    $name = $form->escape($oe->{name}); +    $column_data{name} = qq|<td><a href=$href&$form->{vc}=$name--$oe->{"$form->{vc}_id"}&sort=$form->{sort}>$oe->{name}</a></td>|; + +    map { $column_data{$_} = "<td>$oe->{$_} </td>" } qw(employee manager shipvia curr);      if ($oe->{closed}) { -      $column_data{closed} = "<td align=center>X</td>"; +      $column_data{closed} = "<td align=center>*</td>";        $column_data{open} = "<td> </td>";      } else {        $column_data{closed} = "<td> </td>"; -      $column_data{open} = "<td align=center>X</td>"; +      $column_data{open} = "<td align=center>*</td>";      }      $i++; $i %= 2; -    print "<tr class=listrow$i>"; +    print " +        <tr class=listrow$i>";      map { print "\n$column_data{$_}" } @column_index;      print qq| -    </tr> +	</tr>  |;    } @@ -819,7 +1348,8 @@ print qq|    }    # print totals -  print qq|<tr class=listtotal>|; +  print qq| +        <tr class=listtotal>|;    map { $column_data{$_} = "<td> </td>" } @column_index; @@ -827,11 +1357,22 @@ print qq|    $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>"; -  map { print "\n$column_data{$_}" } @column_index; +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, " ")."</th>"; +  } +  map { print "\n$column_data{$_}" } @column_index; +     print qq| +        </tr> +      </td> +    </table> +  </tr> +  <tr> +    <td><hr size=3 noshade></td>    </tr> -  <tr><td colspan=8><hr size=3 noshade></td></tr>  </table>  <br> @@ -840,14 +1381,28 @@ print qq|  <input name=callback type=hidden value="$form->{callback}">  <input type=hidden name=type value=$form->{type}> + +<input type=hidden name=$form->{vc} value="$form->{$form->{vc}}"> +<input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>  <input type=hidden name=vc value=$form->{vc}>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  if ($form->{type} !~ /(ship|receive)_order/) { +    foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +      print $item->{code}; +    } +  } -<input class=submit type=submit name=action value=|.$locale->text('Add').qq| +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +  print qq|  </form>  </body> @@ -866,15 +1421,26 @@ sub subtotal {    $column_data{tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";    $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>"; +  if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) { +    $column_data{fx_netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, " ")."</th>"; +    $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, " ")."</th>"; +  } +    $subtotalnetamount = 0;    $subtotalamount = 0; +   +  $subtotalfxnetamount = 0; +  $subtotalfxamount = 0; -  print "<tr class=listsubtotal>"; +  print " +        <tr class=listsubtotal> +";    map { print "\n$column_data{$_}" } @column_index;    print qq| -  </tr> +        </tr>  |;  } @@ -882,8 +1448,11 @@ sub subtotal {  sub save { -  $form->isblank("ordnumber", $locale->text('Order Number missing!')); -  $form->isblank("orddate", $locale->text('Order Date missing!')); +  if ($form->{type} =~ /_order$/) { +    $form->isblank("transdate", $locale->text('Order Date missing!')); +  } else { +    $form->isblank("transdate", $locale->text('Quotation Date missing!')); +  }    $msg = ucfirst $form->{vc};    $form->isblank($form->{vc}, $locale->text($msg . " missing!")); @@ -891,7 +1460,7 @@ sub save {  # $locale->text('Customer missing!');  # $locale->text('Vendor missing!'); -  $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});    &validate_items; @@ -902,22 +1471,77 @@ sub save {    } -  # this is for the notes section for the [email] Subject -  $form->{label} = ($form->{type} eq 'sales_order') ? $locale->text('Sales Order') : $locale->text('Purchase Order'); +  # this is for the internal notes section for the [email] Subject +  if ($form->{type} =~ /_order$/) { +    if ($form->{type} eq 'sales_order') { +      $form->{label} = $locale->text('Sales Order'); + +      $numberfld = "sonumber"; +      $ordnumber = "ordnumber"; +    } else { +      $form->{label} = $locale->text('Purchase Order'); +       +      $numberfld = "ponumber"; +      $ordnumber = "ordnumber"; +    } + +    $err = $locale->text('Cannot save order!'); +     +  } else { +    if ($form->{type} eq 'sales_quotation') { +      $form->{label} = $locale->text('Quotation'); +       +      $numberfld = "sqnumber"; +      $ordnumber = "quonumber"; +    } else { +      $form->{label} = $locale->text('Request for Quotation'); + +      $numberfld = "rfqnumber"; +      $ordnumber = "quonumber"; +    } +       +    $err = $locale->text('Cannot save quotation!'); +  +  } -  $form->{id} = 0 if $form->{saveasnew}; -   -  $form->redirect($locale->text('Order saved!')) if (OE->save_order(\%myconfig, \%$form)); -  $form->error($locale->text('Cannot save order!')); +  $form->{id} = 0 if $form->{saveasnew}; +  +  $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld) unless $form->{$ordnumber}; + +  $form->redirect($locale->text('Order saved!')) if (OE->save(\%myconfig, \%$form));  +  $form->error($err); +  } +sub print_and_save { + +  $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/; +  $form->error($locale->text('Select Printer or Queue!')) if $form->{media} eq 'screen'; + +  $old_form = new Form; +  $form->{display_form} = "save"; +  map { $old_form->{$_} = $form->{$_} } keys %$form; +  $old_form->{rowcount}++; + +  &print_form($old_form); + +} +  sub delete {    $form->header; +  if ($form->{type} =~ /_order$/) { +    $msg = $locale->text('Are you sure you want to delete Order Number'); +    $ordnumber = 'ordnumber'; +  } else { +    $msg = $locale->text('Are you sure you want to delete Quotation Number'); +    $ordnumber = 'quonumber'; +  } +      print qq|  <body> @@ -925,19 +1549,14 @@ sub delete {  |;    # delete action variable -  delete $form->{action}; +  map { delete $form->{$_} } qw(action header); -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|  <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2> -<h4>| -  .$locale->text('Are you sure you want to delete Order Number').qq| $form->{ordnumber} -</h4> +<h4>$msg $form->{$ordnumber}</h4>  <p>  <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">  </form> @@ -953,17 +1572,34 @@ sub delete {  sub yes { -  $form->redirect($locale->text('Order deleted!')) if (OE->delete_order(\%myconfig, \%$form)); -  $form->error($locale->text('Cannot delete order!')); +  if ($form->{type} =~ /_order$/) { +    $msg = $locale->text('Order deleted!'); +    $err = $locale->text('Cannot delete order!'); +  } else { +    $msg = $locale->text('Quotation deleted!'); +    $err = $locale->text('Cannot delete quotation!'); +  } +     +  $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool)); +  $form->error($err);  } +sub vendor_invoice { &invoice }; +sub sales_invoice { &invoice }; +  sub invoice { -  $form->isblank("ordnumber", $locale->text('Order Number missing!')); -  $form->isblank("orddate", $locale->text('Order Date missing!')); +  if ($form->{type} =~ /_order$/) { +    $form->isblank("ordnumber", $locale->text('Order Number missing!')); +    $form->isblank("transdate", $locale->text('Order Date missing!')); +  } else { +    $form->isblank("quonumber", $locale->text('Quotation Number missing!')); +    $form->isblank("transdate", $locale->text('Quotation Date missing!')); +    $form->{ordnumber} = ""; +  }    # if the name changed get new values    if (&check_name($form->{vc})) { @@ -971,35 +1607,55 @@ sub invoice {      exit;    } + +  if ($form->{type} =~ /_order/ && $form->{currency} ne $form->{defaultcurrency}) { +    # check if we need a new exchangerate +    $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell"; +     +    $orddate = $form->current_date(\%myconfig); +    $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell); + +    if (!$exchangerate) { +      &backorder_exchangerate($orddate, $buysell); +      exit; +    } +  } + + +  # close orders/quotations    $form->{closed} = 1; -  OE->save_order(\%myconfig, \%$form); + +  OE->save(\%myconfig, \%$form); -  $form->{orddate} = $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig); -  $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1); +  $form->{transdate} = $form->current_date(\%myconfig); +  $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1);    $form->{id} = '';    $form->{closed} = 0;    $form->{rowcount}--;    $form->{shipto} = 1; -  &create_backorder; -  if ($form->{type} eq 'purchase_order') { +  if ($form->{type} =~ /_order$/) { +    $form->{exchangerate} = $exchangerate; +    &create_backorder; +  } + + +  if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {      $form->{title} = $locale->text('Add Vendor Invoice');      $form->{script} = 'ir.pl';      $script = "ir";      $buysell = 'sell';    } -  if ($form->{type} eq 'sales_order') { +  if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {      $form->{title} = $locale->text('Add Sales Invoice');      $form->{script} = 'is.pl';      $script = "is";      $buysell = 'buy';    } -   -  # bo creates the id, reset it -  map { $form->{$_} = "" } qw(id subject message cc bcc); +  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);    $form->{$form->{vc}} =~ s/--.*//g;    $form->{type} = "invoice"; @@ -1008,56 +1664,152 @@ sub invoice {    require "$form->{path}/$form->{script}"; -  map { $form->{"select$_"} = "" } ($form->{vc}, currency); +  # customized scripts +  if (-f "$form->{path}/custom_$form->{script}") { +    eval { require "$form->{path}/custom_$form->{script}"; }; +  } + +  # customized scripts for login +  if (-f "$form->{path}/$form->{login}_$form->{script}") { +    eval { require "$form->{path}/$form->{login}_$form->{script}"; }; +  } -  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(creditlimit creditremaining); +  map { $form->{"select$_"} = "" } ($form->{vc}, currency); +  map { $temp{$_} = $form->{$_} } qw(currency oldcurrency employee department intnotes notes); -  $currency = $form->{currency};    &invoice_links; -  $form->{currency} = $currency; +  $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal}); + +  &prepare_invoice; +   +  map { $form->{$_} = $temp{$_} } keys %temp; +      $form->{exchangerate} = "";    $form->{forex} = ""; -  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell))); +  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell))); -  $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal}); +  for $i (1 .. $form->{rowcount}) { +    $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}; +    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty sellprice discount); +  } -  &prepare_invoice; +  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued audittrail); -  # format amounts -  for $i (1 .. $form->{rowcount}) { -    $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"}); +  &display_form; -    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); -    $dec = length $dec; -    $decimalplaces = ($dec > 2) ? $dec : 2; +} -    $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); -    $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); -    map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); -  } -  &display_form; +sub backorder_exchangerate { +  my ($orddate, $buysell) = @_; + +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> +|; + +  # delete action variable +  map { delete $form->{$_} } qw(action header exchangerate); + +  $form->hide_form(); + +  $form->{title} = $locale->text('Add Exchange Rate'); +   +  print qq| + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input type=hidden name=exchangeratedate value=$orddate> +<input type=hidden name=buysell value=$buysell> + +<table width=100%> +  <tr><th class=listtop>$form->{title}</th></tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +        <tr> +	  <th align=right>|.$locale->text('Currency').qq|</th> +	  <td>$form->{currency}</td> +	</tr> +	<tr> +	  <th align=right>|.$locale->text('Date').qq|</th> +	  <td>$orddate</td> +	</tr> +        <tr> +	  <th align=right>|.$locale->text('Exchange Rate').qq|</th> +	  <td><input name=exchangerate size=11></td> +        </tr> +      </table> +    </td> +  </tr> +</table> + +<hr size=3 noshade> + +<br> +<input type=hidden name=nextsub value=save_exchangerate> + +<input name=action class=submit type=submit value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; +  } -sub create_backorder { +sub save_exchangerate { + +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')); +  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}); +  $form->save_exchangerate(\%myconfig, $form->{currency}, $form->{exchangeratedate}, $form->{exchangerate}, $form->{buysell}); +   +  &invoice; + +} + +sub create_backorder { +   +  $form->{shipped} = 1; +     # figure out if we need to create a backorder    # items aren't saved if qty != 0 +  $dec1 = $dec2 = 0;    for $i (1 .. $form->{rowcount}) { -    $totalqty += $qty = $form->parse_amount($myconfig, $form->{"qty_$i"}); -    $totalship += $ship = $form->parse_amount($myconfig, $form->{"ship_$i"}); +    ($dec) = ($form->{"qty_$i"} =~ /\.(\d+)/); +    $dec = length $dec; +    $dec1 = ($dec > $dec1) ? $dec : $dec1; +     +    ($dec) = ($form->{"ship_$i"} =~ /\.(\d+)/); +    $dec = length $dec; +    $dec2 = ($dec > $dec2) ? $dec : $dec2; +     +    $totalqty += $qty = $form->{"qty_$i"}; +    $totalship += $ship = $form->{"ship_$i"};      $form->{"qty_$i"} = $qty - $ship;    } +  $totalqty = $form->round_amount($totalqty, $dec1); +  $totalship = $form->round_amount($totalship, $dec2); +    if ($totalship == 0) {      map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});      $form->{ordtotal} = 0; +    $form->{shipped} = 0;      return;    } @@ -1067,23 +1819,29 @@ sub create_backorder {      return;    } -  @flds = (qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts)); +  @flds = qw(partnumber sku description qty oldqty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup reqdate pricematrix); -  OE->save_order(\%myconfig, \%$form); -   +  for $i (1 .. $form->{rowcount}) { +    map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty sellprice discount); +     +    $form->{"oldship_$i"} = $form->{"ship_$i"}; +    $form->{"ship_$i"} = 0; +  } + +  # clear flags +  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued audittrail); + +  OE->save(\%myconfig, \%$form); +     # rebuild rows for invoice    @a = ();    $count = 0;    for $i (1 .. $form->{rowcount}) { +    $form->{"qty_$i"} = $form->{"oldship_$i"}; +    $form->{"oldqty_$i"} = $form->{"qty_$i"}; -    # reformat values if there was a backorder quantity -    if ($form->{"qty_$i"}) { -      $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"}); -      $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}); -    } - -    $form->{"qty_$i"} = $form->{"ship_$i"}; +    $form->{"orderitems_id_$i"} = "";      if ($form->{"qty_$i"}) {        push @a, {}; @@ -1095,7 +1853,7 @@ sub create_backorder {    $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});    $form->{rowcount} = $count; -   +  } @@ -1104,8 +1862,609 @@ sub save_as_new {    $form->{saveasnew} = 1;    $form->{closed} = 0; +  map { delete $form->{$_} } qw(printed emailed queued); +    &save;  } +sub ship_receive { + +  &order_links; +   +  &prepare_order; + +  OE->get_warehouses(\%myconfig, \%$form); + +  # warehouse +  if (@{ $form->{all_warehouses} }) { +    $form->{selectwarehouse} = "<option>\n"; + +    map { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} }); + +    if ($form->{warehouse}) { +      $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|; +      $form->{warehouse} =~ s/--.*//; +      $form->{selectwarehouse} .= $form->{warehouse}; +    } +  } + +  $form->{shippingdate} = $form->current_date(\%myconfig); +  $form->{"$form->{vc}"} =~ s/--.*//; +  $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|; + +  @flds = (); +  @a = (); +  $count = 0; +  foreach $key (keys %$form) { +    if ($key =~ /_1$/) { +      $key =~ s/_1//; +      push @flds, $key; +    } +  } +   +  for $i (1 .. $form->{rowcount}) { +    # undo formatting from prepare_order +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty ship); +    $n = ($form->{"qty_$i"} -= $form->{"ship_$i"}); +    if (abs($n) > 0 && ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"})) { +      $form->{"ship_$i"} = ""; +      $form->{"serialnumber_$i"} = ""; + +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +   +  $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); +  $form->{rowcount} = $count; +   +  &display_ship_receive; +   +} + + +sub display_ship_receive { +   +  $vclabel = ucfirst $form->{vc}; +  $vclabel = $locale->text($vclabel); + +  $form->{rowcount}++; + +  if ($form->{vc} eq 'customer') { +    $form->{title} = $locale->text('Ship Merchandise'); +    $shipped = $locale->text('Shipping Date'); +  } else { +    $form->{title} = $locale->text('Receive Merchandise'); +    $shipped = $locale->text('Date Received'); +  } +   +  # set option selected +  foreach $item (warehouse, employee) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } + + +  $warehouse = qq| +	      <tr> +		<th align=right>|.$locale->text('Warehouse').qq|</th> +		<td><select name=warehouse>$form->{selectwarehouse}</select></td> +		<input type=hidden name=selectwarehouse value="|. +		$form->escape($form->{selectwarehouse},1).qq|"> +	      </tr> +| if $form->{selectwarehouse}; + +  $employee = qq| + 	      <tr> +	        <th align=right nowrap>|.$locale->text('Contact').qq|</th> +		<td><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|. +		$form->escape($form->{selectemployee},1).qq|"> +	      </tr> +|; + + +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> + +<input type=hidden name=display_form value=display_ship_receive> + +<input type=hidden name=type value=$form->{type}> +<input type=hidden name=media value=$form->{media}> +<input type=hidden name=format value=$form->{format}> + +<input type=hidden name=queued value="$form->{queued}"> +<input type=hidden name=printed value="$form->{printed}"> +<input type=hidden name=emailed value="$form->{emailed}"> + +<input type=hidden name=vc value=$form->{vc}> +<input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}"> + +<table width=100%> +  <tr class=listtop> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width="100%"> +        <tr valign=top> +	  <td> +	    <table width=100%> +	      <tr> +		<th align=right>$vclabel</th> +		<td colspan=3>$form->{$form->{vc}}</td> +		<input type=hidden name=$form->{vc} value="$form->{$form->{vc}}"> +		<input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}> +	      </tr> +	      $department +	      <tr> +		<th align=right>|.$locale->text('Shipping Point').qq|</th> +		<td colspan=3> +		<input name=shippingpoint size=35 value="$form->{shippingpoint}"> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Ship via').qq|</th> +		<td colspan=3> +		<input name=shipvia size=35 value="$form->{shipvia}"> +	      </tr> +	      $warehouse +	    </table> +	  </td> +	  <td align=right> +	    <table> +	      $employee +	      <tr> +		<th align=right nowrap>|.$locale->text('Order Number').qq|</th> +		<td>$form->{ordnumber}</td> +		<input type=hidden name=ordnumber value="$form->{ordnumber}"> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Order Date').qq|</th> +		<td>$form->{transdate}</td> +		<input type=hidden name=transdate value=$form->{transdate}> +	      </tr> +	      <tr> +		<th align=right nowrap>$shipped</th> +		<td><input name=shippingdate size=11 value=$form->{shippingdate}></td> +	      </tr> +	    </table> +	  </td> +	</tr> +      </table> +    </td> +  </tr> + +<!-- shipto are in hidden variables --> + +<input type=hidden name=shiptoname value="$form->{shiptoname}"> +<input type=hidden name=shiptoaddress1 value="$form->{shiptoaddress1}"> +<input type=hidden name=shiptoaddress2 value="$form->{shiptoaddress2}"> +<input type=hidden name=shiptocity value="$form->{shiptocity}"> +<input type=hidden name=shiptostate value="$form->{shiptostate}"> +<input type=hidden name=shiptozipcode value="$form->{shiptozipcode}"> +<input type=hidden name=shiptocountry value="$form->{shiptocountry}"> +<input type=hidden name=shiptocontact value="$form->{shiptocontact}"> +<input type=hidden name=shiptophone value="$form->{shiptophone}"> +<input type=hidden name=shiptofax value="$form->{shiptofax}"> +<input type=hidden name=shiptoemail value="$form->{shiptoemail}"> + +<!-- email variables --> +<input type=hidden name=message value="$form->{message}">  +<input type=hidden name=email value="$form->{email}"> +<input type=hidden name=subject value="$form->{subject}"> +<input type=hidden name=cc value="$form->{cc}"> +<input type=hidden name=bcc value="$form->{bcc}"> + +|; + +  @column_index = qw(partnumber); +   +  if ($form->{type} eq "ship_order") { +    $column_data{ship} = qq|<th class=listheading>|.$locale->text('Ship').qq|</th>|; +  } +  if ($form->{type} eq "receive_order") { +      $column_data{ship} = qq|<th class=listheading>|.$locale->text('Recd').qq|</th>|; +      $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|; +      push @column_index, "sku"; +  } +  push @column_index, qw(description qty ship unit bin serialnumber); + +  my $colspan = $#column_index + 1; +  +  $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|; +  $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|; +  $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|; +  $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|; +  $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|; +  $column_data{serialnumber} = qq|<th class=listheading nowrap>|.$locale->text('Serial No.').qq|</th>|; +   +  print qq| +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; + +  map { print "\n$column_data{$_}" } @column_index; + +  print qq| +        </tr> +|; +   +   +  for $i (1 .. $form->{rowcount} - 1) { +     +    # undo formatting +    $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"}); + +    map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit bin serialnumber); + +    $description = $form->{"description_$i"}; +    $description =~ s/
/<br>/g; +     +    $column_data{partnumber} = qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|; +    $column_data{sku} = qq|<td>$form->{"sku_$i"}<input type=hidden name="sku_$i" value="$form->{"sku_$i"}"></td>|; +    $column_data{description} = qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|; +    $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|; +    $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|; +    $column_data{unit} = qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|; +    $column_data{bin} = qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|; +     +    $column_data{serialnumber} = qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|; +     +    print qq| +        <tr valign=top>|; + +    map { print "\n$column_data{$_}" } @column_index; +   +    print qq| +        </tr> + +<input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}> +<input type=hidden name="id_$i" value=$form->{"id_$i"}> +<input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}"> +<input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}"> + +|; + +  } +  +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +  <tr> +    <td> +|; + +  $form->{copies} = 1; +   +  &print_options; + +  print qq| +    </td> +  </tr> +</table> +<br> +<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +|; + +  if ($form->{type} eq 'ship_order') { +    print qq| +<input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|"> +|; +  } +   +  print qq| + +<input class=submit type=submit name=action value="|.$locale->text('Done').qq|"> +|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +   +<input type=hidden name=rowcount value=$form->{rowcount}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +</form> + +</body> +</html> +|; + + +} + + +sub done { + +  if ($form->{type} eq 'ship_order') { +    $form->isblank("shippingdate", $locale->text('Shipping Date missing!')); +  } else { +    $form->isblank("shippingdate", $locale->text('Date received missing!')); +  } +   +  $total = 0; +  map { $total += $form->{"ship_$_"} = $form->parse_amount(\%myconfig, $form->{"ship_$_"}) } (1 .. $form->{rowcount} - 1); +   +  $form->error($locale->text('Nothing entered!')) unless $total; +   +  $form->redirect($locale->text('Inventory saved!')) if OE->save_inventory(\%myconfig, \%$form); +  $form->error($locale->text('Could not save!')); + +} + + +sub search_transfer { +   +  OE->get_warehouses(\%myconfig, \%$form); + +  # warehouse +  if (@{ $form->{all_warehouses} }) { +    $form->{selectwarehouse} = "<option>\n"; +    $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|; + +    map { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} }); +  } else { +    $form->error($locale->text('Nothing to transfer!')); +  } +   +  $form->get_partsgroup(\%myconfig, { all => 0, searchitems => 'part'}); +  if (@{ $form->{all_partsgroup} }) { +    $form->{selectpartsgroup} = "<option>\n"; +    map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };  +  } +   +  $form->{title} = $locale->text('Transfer Inventory'); +  +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +        <tr> +          <th align=right nowrap>|.$locale->text('Transfer to').qq|</th> +          <td><select name=warehouse>$form->{selectwarehouse}</select></td> +        </tr> +	<tr> +	  <th align="right" nowrap="true">|.$locale->text('Part Number').qq|</th> +	  <td><input name=partnumber size=20></td> +	</tr> +	<tr> +	  <th align="right" nowrap="true">|.$locale->text('Description').qq|</th> +	  <td><input name=description size=40></td> +	</tr> +	<tr> +	  <th align=right nowrap>|.$locale->text('Group').qq|</th> +	  <td><select name=partsgroup><select>$form->{selectpartsgroup}</select></td> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<input type=hidden name=sort value=partnumber> +<input type=hidden name=nextsub value=list_transfer> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub list_transfer { + +  OE->get_inventory(\%myconfig, \%$form); +   +  $partnumber = $form->escape($form->{partnumber}); +  $warehouse = $form->escape($form->{warehouse}); +  $description = $form->escape($form->{description}); +  $partsgroup = $form->escape($form->{partsgroup}); +   +  # construct href +  $href = "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&sessionid=$form->{sessionid}"; + +  # construct callback +  $partnumber = $form->escape($form->{partnumber},1); +  $warehouse = $form->escape($form->{warehouse},1); +  $description = $form->escape($form->{description},1); +  $partsgroup = $form->escape($form->{partsgroup},1); +  +  $callback = "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&sessionid=$form->{sessionid}"; + +  @column_index = $form->sort_columns(qw(partnumber description partsgroup make model warehouse qty transfer)); + + +  $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|; +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; +  $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|; +  $column_header{warehouse} = qq|<th><a class=listheading href=$href&sort=warehouse>|.$locale->text('From').qq|</a></th>|; +  $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</a></th>|; +  $column_header{transfer} = qq|<th class=listheading>|.$locale->text('Transfer').qq|</a></th>|; + +   +  $option = $locale->text('Transfer to'); +   +  ($warehouse, $warehouse_id) = split /--/, $form->{warehouse}; +   +  if ($form->{warehouse}) { +    $option .= " : $warehouse"; +  } +  if ($form->{partnumber}) { +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Part Number')." : $form->{partnumber}"; +  } +  if ($form->{description}) { +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Description')." : $form->{description}"; +  } +  if ($form->{partsgroup}) { +    ($partsgroup) = split /--/, $form->{partsgroup}; +    $option .= "\n<br>" if ($option); +    $option .= $locale->text('Group')." : $partsgroup"; +  } + +  $form->{title} = $locale->text('Transfer Inventory'); +   +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=warehouse_id value=$warehouse_id> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; + +map { print "\n$column_header{$_}" } @column_index; + +print qq| +	</tr> +|; + + +  if (@{ $form->{all_inventory} }) { +    $sameitem = $form->{all_inventory}->[0]->{$form->{sort}}; +  } + +  $i = 0; +  foreach $ref (@{ $form->{all_inventory} }) { + +    $i++; + +    $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|; +    $column_data{description} = "<td>$ref->{description} </td>"; +    $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>"; +    $column_data{warehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse} </td>|; +    $column_data{qty} = qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|.$form->format_amount(\%myconfig, $ref->{qty}).qq|</td>|; +    $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|; + +    $j++; $j %= 2; +    print " +        <tr class=listrow$j>"; +     +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +	</tr> +|; + +  } +   +  print qq| +      </table> +    </td> +  </tr> +   +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> + +<input name=callback type=hidden value="$callback"> + +<input type=hidden name=rowcount value=$i> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input class=submit type=submit name=action value="|.$locale->text('Transfer').qq|">|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +</form> + +</body> +</html> +|; + + +} + + +sub transfer { + +  $form->redirect($locale->text('Inventory transferred!')) if OE->transfer(\%myconfig, \%$form); +  $form->error($locale->text('Could not transfer Inventory!')); + +} + + +sub rfq_ { &add }; +sub quotation_ { &add }; + + +sub redirect { +    +  $form->redirect;  +  $form->error($locale->text('Order processed!')); +         +} + diff --git a/sql-ledger/bin/mozilla/pe.pl b/sql-ledger/bin/mozilla/pe.pl index d8706d413..841c3fef2 100644 --- a/sql-ledger/bin/mozilla/pe.pl +++ b/sql-ledger/bin/mozilla/pe.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2002  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -23,6 +23,7 @@  #  # project administration  # partsgroup administration +# translation maintainance  #  #====================================================================== @@ -39,10 +40,10 @@ sub add {    $form->{title} = "Add";    # construct callback -  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; +  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; -  &{ "form_$form->{type}_header" }; -  &{ "form_$form->{type}_footer" }; +  &{ "$form->{type}_header" }; +  &{ "$form->{type}_footer" };  } @@ -51,15 +52,9 @@ sub edit {    $form->{title} = "Edit"; -  if ($form->{type} eq 'project') { -    PE->get_project(\%myconfig, \%$form); -  } -  if ($form->{type} eq 'partsgroup') { -    PE->get_partsgroup(\%myconfig, \%$form); -  } - -  &{ "form_$form->{type}_header" }; -  &{ "form_$form->{type}_footer" }; +  &{ "PE::get_$form->{type}" }("", \%myconfig, \%$form); +  &{ "$form->{type}_header" }; +  &{ "$form->{type}_footer" };  } @@ -96,6 +91,20 @@ sub search {  |;    } +  if ($form->{type} eq 'pricegroup') { +    $report = "pricegroup_report"; +    $sort = 'pricegroup'; +    $form->{title} = $locale->text('Pricegroups'); +     +    $number = qq| +	<tr> +	  <th align=right width=1%>|.$locale->text('Pricegroup').qq|</th> +	  <td><input name=pricegroup size=20></td> +	</tr> +|; + +  } +    $form->header; @@ -133,7 +142,7 @@ sub search {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> @@ -152,8 +161,11 @@ sub project_report {    map { $form->{$_} = $form->unescape($form->{$_}) } (projectnumber, description);    PE->projects(\%myconfig, \%$form); -  $callback = "$form->{script}?action=project_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}"; -  $href = $callback; +  $href = "$form->{script}?action=project_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; + +  $form->sort_order(); +   +  $callback = "$form->{script}?action=project_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";    if ($form->{status} eq 'all') {      $option = $locale->text('All'); @@ -219,7 +231,7 @@ sub project_report {          <tr valign=top class=listrow$i>  |; -    $column_data{projectnumber} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{projectnumber}</td>|; +    $column_data{projectnumber} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{projectnumber}</td>|;      $column_data{description} = qq|<td>$ref->{description} </td>|;      map { print "$column_data{$_}\n" } @column_index; @@ -229,6 +241,16 @@ sub project_report {  ";    } +  $i = 1; +  if ($myconfig{acs} !~ /Projects--Projects/) { +    $button{'Projects--Add Project'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Project').qq|"> |; +    $button{'Projects--Add Project'}{order} = $i++; + +    foreach $item (split /;/, $myconfig{acs}) { +      delete $button{$item}; +    } +  } +     print qq|        </table>      </td> @@ -247,10 +269,21 @@ sub project_report {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; -<input class=submit type=submit name=action value="|.$locale->text('Add').qq|"> +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } +   +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +  print qq| +  </form> +    </body>  </html>  |; @@ -258,14 +291,14 @@ sub project_report {  } -sub form_project_header { +sub project_header {    $form->{title} = $locale->text("$form->{title} Project");  # $locale->text('Add Project')  # $locale->text('Edit Project') -  $form->{description} =~ s/"/"/g; +  $form->{description} = $form->quote($form->{description});    if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {      $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|; @@ -311,7 +344,7 @@ sub form_project_header {  } -sub form_project_footer { +sub project_footer {    print qq| @@ -319,14 +352,24 @@ sub form_project_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> - -<br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +<input type=hidden name=sessionid value=$form->{sessionid}> +<br>  |; -  if ($form->{id} && $form->{orphaned}) { +  if ($myconfig{acs} !~ /Projects--Add Project/) {      print qq| +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +|; + +    if ($form->{id} && $form->{orphaned}) { +      print qq|  <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|; +    } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar;    }    print qq| @@ -351,19 +394,38 @@ sub save {      PE->save_partsgroup(\%myconfig, \%$form);      $form->redirect($locale->text('Group saved!'));    } +  if ($form->{type} eq 'pricegroup') { +    $form->isblank("pricegroup", $locale->text('Pricegroup missing!')); +    PE->save_pricegroup(\%myconfig, \%$form); +    $form->redirect($locale->text('Pricegroup saved!')); +  } +  if ($form->{translation}) { +    PE->save_translation(\%myconfig, \%$form); +    $form->redirect($locale->text('Translations saved!')); +  }  }  sub delete { -  PE->delete_tuple(\%myconfig, \%$form); +  if ($form->{translation}) { +    PE->delete_translation(\%myconfig, \%$form); +    $form->redirect($locale->text('Translation deleted!')); + +  } else { -  if ($form->{type} eq 'project') {  -    $form->redirect($locale->text('Project deleted!')); -  } -  if ($form->{type} eq 'partsgroup') { -    $form->redirect($locale->text('Group deleted!')); +    PE->delete_tuple(\%myconfig, \%$form); +     +    if ($form->{type} eq 'project') {  +      $form->redirect($locale->text('Project deleted!')); +    } +    if ($form->{type} eq 'partsgroup') { +      $form->redirect($locale->text('Group deleted!')); +    } +    if ($form->{type} eq 'pricegroup') { +      $form->redirect($locale->text('Pricegroup deleted!')); +    }    }  } @@ -377,7 +439,11 @@ sub partsgroup_report {    map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);    PE->partsgroups(\%myconfig, \%$form); -  $callback = "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}"; +  $href = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; +   +  $form->sort_order(); + +  $callback = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";    if ($form->{status} eq 'all') {      $option = $locale->text('All'); @@ -391,9 +457,9 @@ sub partsgroup_report {    } -  @column_index = (partsgroup); +  @column_index = $form->sort_columns(qw(partsgroup)); -  $column_header{partsgroup} = qq|<th class=listheading width=90%>|.$locale->text('Group').qq|</th>|; +  $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|.$locale->text('Group').qq|</a></th>|;    $form->{title} = $locale->text('Groups'); @@ -436,15 +502,23 @@ sub partsgroup_report {          <tr valign=top class=listrow$i>  |; - -    $column_data{partsgroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partsgroup}</td>|; -     +    $column_data{partsgroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|;      map { print "$column_data{$_}\n" } @column_index;      print "          </tr>  ";    } + +  $i = 1; +  if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) { +    $button{'Goods & Services--Add Group'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Group').qq|"> |; +    $button{'Goods & Services--Add Group'}{order} = $i++; + +    foreach $item (split /;/, $myconfig{acs}) { +      delete $button{$item}; +    } +  }    print qq|        </table> @@ -464,9 +538,20 @@ sub partsgroup_report {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } -<input class=submit type=submit name=action value="|.$locale->text('Add').qq|"> +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form>  </body>  </html> @@ -475,14 +560,13 @@ sub partsgroup_report {  } -sub form_partsgroup_header { +sub partsgroup_header {    $form->{title} = $locale->text("$form->{title} Group"); -# $locale->text('Add Group')  # $locale->text('Edit Group') -  $form->{partsgroup} =~ s/"/"/g; +  $form->{partsgroup} = $form->quote($form->{partsgroup});    $form->header; @@ -505,6 +589,7 @@ sub form_partsgroup_header {        <table width=100%>  	<tr>  	  <th align=right>|.$locale->text('Group').qq|</th> +            <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>  	</tr>        </table> @@ -519,7 +604,7 @@ sub form_partsgroup_header {  } -sub form_partsgroup_footer { +sub partsgroup_footer {    print qq| @@ -527,14 +612,232 @@ sub form_partsgroup_footer {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}> +<br> +|; -<br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +  if ($myconfig{acs} !~ /Goods \& Services--Add Group/) { +    print qq| +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">  |; -  if ($form->{id} && $form->{orphaned}) { +    if ($form->{id} && $form->{orphaned}) { +      print qq| +<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|; +    } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +</form> + +</body> +</html> +|; + +} + + +sub pricegroup_report { + +  map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup); +  PE->pricegroups(\%myconfig, \%$form); + +  $href = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; +   +  $form->sort_order(); + +  $callback = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}"; +   +  if ($form->{status} eq 'all') { +    $option = $locale->text('All'); +  } +  if ($form->{status} eq 'orphaned') { +    $option .= $locale->text('Orphaned'); +  } +  if ($form->{pricegroup}) { +    $callback .= "&pricegroup=$form->{pricegroup}"; +    $option .= "\n<br>".$locale->text('Pricegroup')." : $form->{pricegroup}"; +  } +    + +  @column_index = $form->sort_columns(qw(pricegroup)); + +  $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|.$locale->text('Pricegroup').qq|</th>|; + +  $form->{title} = $locale->text('Pricegroups'); + +  $form->header; +  +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td>$option</td> +  </tr> +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading> +|; + +  map { print "$column_header{$_}\n" } @column_index; +   +  print qq| +        </tr> +|; + +  # escape callback +  $form->{callback} = $callback; + +  # escape callback for href +  $callback = $form->escape($callback); +   +  foreach $ref (@{ $form->{item_list} }) { +     +    $i++; $i %= 2; +     +    print qq| +        <tr valign=top class=listrow$i> +|; +     +    $column_data{pricegroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|; +    map { print "$column_data{$_}\n" } @column_index; +     +    print " +        </tr> +"; +  } + +  $i = 1; +  if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) { +    $button{'Goods & Services--Add Pricegroup'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Pricegroup').qq|"> |; +    $button{'Goods & Services--Add Pricegroup'}{order} = $i++; + +    foreach $item (split /;/, $myconfig{acs}) { +      delete $button{$item}; +    } +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=type value=$form->{type}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  foreach $item (sort { $a->{order} <=> $b->{order} } %button) { +    print $item->{code}; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; + +} + + +sub pricegroup_header { + +  $form->{title} = $locale->text("$form->{title} Pricegroup"); +   +# $locale->text('Edit Pricegroup') + +  $form->{pricegroup} = $form->quote($form->{pricegroup}); + +   +  $form->header; + +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<input type=hidden name=type value=$form->{type}> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +	<tr> +	  <th align=right>|.$locale->text('Pricegroup').qq|</th> + +          <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td colspan=2><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub pricegroup_footer { + +  print qq| + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +<br> +|; + +  if ($myconfig{acs} !~ /Goods \& Services--Add Pricegroup/) {      print qq| +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +|; + +    if ($form->{id} && $form->{orphaned}) { +      print qq|  <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|; +    } +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar;    }    print qq| @@ -547,3 +850,387 @@ sub form_partsgroup_footer {  } +sub translation { + +  if ($form->{translation} eq 'description') { +    $form->{title} = $locale->text('Description Translations'); +    $sort = qq|<input type=hidden name=sort value=partnumber>|; +    $form->{number} = "partnumber"; +    $number = qq| +        <tr> +          <th align=right nowrap>|.$locale->text('Number').qq|</th> +          <td><input name=partnumber size=20></td> +        </tr> +|; +  } + +  if ($form->{translation} eq 'partsgroup') { +    $form->{title} = $locale->text('Group Translations'); +    $sort = qq|<input type=hidden name=sort value=partsgroup>|; +  } +   +  if ($form->{translation} eq 'project') { +    $form->{title} = $locale->text('Project Description Translations'); +    $form->{number} = "projectnumber"; +    $sort = qq|<input type=hidden name=sort value=projectnumber>|; +    $number = qq| +        <tr> +          <th align=right nowrap>|.$locale->text('Project Number').qq|</th> +          <td><input name=projectnumber size=20></td> +        </tr> +|; +  } + + +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=translation value=$form->{translation}> +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=number value=$form->{number}> + +<table width="100%"> +  <tr><th class=listtop>$form->{title}</th></tr> +  <tr height="5"></tr> +  <tr valign=top> +    <td> +      <table> +        $number +        <tr> +          <th align=right nowrap>|.$locale->text('Description').qq|</th> +          <td colspan=3><input name=description size=40></td> +        </tr> +      </table> +    </td> +  </tr> +  <tr><td><hr size=3 noshade></td></tr> +</table> + +<input type=hidden name=nextsub value=list_translations> +$sort + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub list_translations { + +  $title = $form->escape($form->{title},1); +   +  $callback = "$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title"; + +  if ($form->{"$form->{number}"}) { +    $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|; +    $option .= $locale->text('Number').qq| : $form->{"$form->{number}"}<br>|; +  } +  if ($form->{description}) { +    $callback .= "&description=$form->{description}"; +    $description = $form->{description}; +    $description =~ s/
/<br>/g; +    $option .= $locale->text('Description').qq| : $form->{description}<br>|; +  } + +  if ($form->{translation} eq 'partsgroup') { +    @column_index = qw(description language translation); +    $form->{sort} = ""; +  } else { +    @column_index = $form->sort_columns("$form->{number}", "description", "language", "translation"); +  } + +  &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form); + +  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}"; +   +  $href = $callback; +   +  $form->sort_order(); +   +  $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/; + +  $column_header{"$form->{number}"} = qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|.$locale->text('Number').qq|</a></th>|; +  $column_header{description} = qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; +  $column_header{language} = qq|<th nowrap class=listheading>|.$locale->text('Language').qq|</a></th>|; +  $column_header{translation} = qq|<th nowrap width=40% class=listheading>|.$locale->text('Translation').qq|</a></th>|; + +  $form->header; + +  print qq| +<body> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> + +  <tr><td>$option</td></tr> + +  <tr> +    <td> +      <table width=100%> +        <tr class=listheading> +|; + +  map { print "\n$column_header{$_}" } @column_index; +   +  print qq| +        </tr> +  |; + + +  # add order to callback +  $form->{callback} = $callback .= "&sort=$form->{sort}"; + +  # escape callback for href +  $callback = $form->escape($callback); + +  if (@{ $form->{translations} }) { +    $sameitem = $form->{translations}->[0]->{$form->{sort}}; +  } + +  foreach $ref (@{ $form->{translations} }) { +   +    $ref->{description} =~ s/
/<br>/g; +     +    map { $column_data{$_} = "<td>$ref->{$_} </td>" } @column_index; +     +    $column_data{description} = "<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description} </a></td>"; +     +    $i++; $i %= 2; +    print "<tr class=listrow$i>"; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +    </tr> +|; + +  } +   +  print qq| +      </table> +    </td> +  </tr> +  <tr><td><hr size=3 noshade></td></tr> +</table> + +|; +  +  print qq| + +<br> + +<form method=post action=$form->{script}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> +|; + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| +  </form> + +</body> +</html> +|; + +} + + +sub edit_translation { + +  &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form); + +  $form->error($locale->text('Languages not defined!')) unless $form->{all_language}; + +  $form->{selectlanguage} = qq|<option>\n|; +  map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_language} }; + +  $form->{"$form->{number}"} = $form->{translations}->[0]->{"$form->{number}"}; +  $form->{description} = $form->{translations}->[0]->{description}; +  $form->{description} =~ s/
/<br>/g; + +  shift @{ $form->{translations} }; + +  $i = 1; +  foreach $row (@{ $form->{translations} }) { +    $form->{"language_code_$i"} = $row->{code}; +    $form->{"translation_$i"} = $row->{translation}; +    $i++; +  } +  $form->{translation_rows} = $i - 1; +     +  $form->{title} = $locale->text('Edit Description Translations'); +   +  &translation_header; +  &translation_footer; + +} + + +sub translation_header { + +  $form->{translation_rows}++; + +  $form->{selectlanguage} = $form->unescape($form->{selectlanguage}); +  for ($i = 1; $i <= $form->{translation_rows}; $i++) { +    $form->{"selectlanguage_$i"} = $form->{selectlanguage}; +    if ($form->{"language_code_$i"}) { +      $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/; +    } +  } +   +  $form->{selectlanguage} = $form->escape($form->{selectlanguage},1); + +  $form->header; +  +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input name=id type=hidden value=$form->{id}> +<input name=trans_id type=hidden value=$form->{trans_id}> + +<input type=hidden name=selectlanguage value="$form->{selectlanguage}"> +<input type=hidden name=translation_rows value=$form->{translation_rows}> + +<input type=hidden name=number value=$form->{number}> +<input type=hidden name=$form->{number} value="|.$form->quote($form->{"$form->{number}"}).qq|"> +<input type=hidden name=description value="|.$form->quote($form->{description}).qq|"> + +<input type=hidden name=translation value=$form->{translation}> +<input type=hidden name=title value="$form->{title}"> + +<table width="100%"> +  <tr><th class=listtop>$form->{title}</th></tr> +  <tr height="5"></tr> +  <tr valign=top> +    <td> +      <table width=100%> +        <tr> +          <td align=left>$form->{"$form->{number}"}</th> +	  <td align=left>$form->{description}</th> +        </tr> +        <tr> +	<tr> +	  <th class=listheading>|.$locale->text('Language').qq|</th> +	  <th class=listheading>|.$locale->text('Translation').qq|</th> +	</tr> +|; + +  for ($i = 1; $i <= $form->{translation_rows}; $i++) { +     +    if (($rows = $form->numtextrows($form->{"translation_$i"}, 40)) > 1) { +      $translation = qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|; +    } else { +      $translation = qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|; +    } +    +    print qq| +	<tr valign=top> +	  <td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td> +	  <td>$translation</td> +	</tr> +|; +  } + +  print qq| +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +} + + +sub translation_footer { + +  print qq| +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input type=hidden name=callback value="$form->{callback}"> + +<br> + +<input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Save').qq|"> +|; + +  if ($form->{trans_id}) { +    print qq| +<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|"> +|; +  } + +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq| + +  </form> + +</body> +</html> +|; + +} + + +sub update { + +  @flds = qw(language translation); +  $count = 0; +  @a = (); +  for $i (1 .. $form->{translation_rows}) { +    if ($form->{"language_code_$i"} ne "") { +      push @a, {}; +      $j = $#a; + +      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; +      $count++; +    } +  } +  $form->redo_rows(\@flds, \@a, $count, $form->{translation_rows}); +  $form->{translation_rows} = $count; + +  &translation_header; +  &translation_footer; + +} + +     +sub add_group { &add }; +sub add_project { &add }; +sub add_pricegroup { &add }; + diff --git a/sql-ledger/bin/mozilla/pos.pl b/sql-ledger/bin/mozilla/pos.pl new file mode 100644 index 000000000..e9416f63b --- /dev/null +++ b/sql-ledger/bin/mozilla/pos.pl @@ -0,0 +1,878 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2003 +# +#  Author: Dieter Simader +#   Email: dsimader@sql-ledger.org +#     Web: http://www.sql-ledger.org +# +# Contributors: Steve Doerr <sdoerr907@everestkc.net> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#===================================================================== +# +# POS +# +#===================================================================== + + +1; +# end + + +sub add { + +  $form->{title} = $locale->text('Add POS Invoice'); + +  $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; +   +  &invoice_links; + +  $form->{type} =  "pos_invoice"; +  $form->{format} = "txt"; +  $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen"; +  $form->{rowcount} = 0; + +  $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0; + +  $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; +  $form->{till} = $4; + +  map { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n" } @{ $form->{all_partsgroup} }; + +  &display_form; + +} + + +sub openinvoices { + +  $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; +  $form->{till} = $4; +   +  $form->{sort} = 'transdate'; + +  map { $form->{$_} = 'Y' } qw(open l_invnumber l_transdate l_name l_amount l_curr l_till l_subtotal); + +  if ($myconfig{role} ne 'user') { +    $form->{l_employee} = 'Y'; +  } + +  $form->{title} = $locale->text('Open'); +  &ar_transactions; +   +} + + +sub edit { + +  $form->{title} = $locale->text('Edit POS Invoice'); + +  $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; +   +  &invoice_links; +  &prepare_invoice; + +  $form->{type} =  "pos_invoice"; +  $form->{format} = "txt"; +  $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen"; + +  $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0; + +  map { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n" } @{ $form->{all_partsgroup} }; +   +  &display_form; + +} + + +sub form_header { + +  # set option selected +  foreach $item (qw(AR currency)) { +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; +  } + +  foreach $item (qw(customer department employee)) { +    $form->{"select$item"} = $form->unescape($form->{"select$item"}); +    $form->{"select$item"} =~ s/ selected//; +    $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/; +  } +     +  $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + +  if ($form->{oldtotalpaid} > $form->{oldinvtotal}) { +    $adj = $form->{oldtotalpaid} - $form->{oldinvtotal}; +  } +  $form->{creditremaining} = $form->{creditremaining} - $adj + $form->{oldchange}; +   +  $exchangerate = ""; +  if ($form->{currency} ne $form->{defaultcurrency}) { +    if ($form->{forex}) { +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|; +    } else { +      $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|; +    } +  } +  $exchangerate .= qq| +<input type=hidden name=forex value=$form->{forex}> +|; + +  if ($form->{selectcustomer}) { +    $customer = qq|<select name=customer>$form->{selectcustomer}</select> +                   <input type=hidden name="selectcustomer" value="|. +		   $form->escape($form->{selectcustomer},1).qq|">|; +  } else { +    $customer = qq|<input name=customer value="$form->{customer}" size=35>|; +  } +   +  $department = qq| +              <tr> +	        <th align="right" nowrap>|.$locale->text('Department').qq|</th> +		<td colspan=3><select name=department>$form->{selectdepartment}</select> +		<input type=hidden name=selectdepartment value="|. +		$form->escape($form->{selectdepartment},1).qq|"> +		</td> +	      </tr> +| if $form->{selectdepartment}; +	 +  $n = ($form->{creditremaining} < 0) ? "0" : "1"; + +  if ($form->{selectlanguage}) { +    if ($form->{language_code} ne $form->{oldlanguage_code}) { +      # rebuild partsgroup +      $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} }); +      $form->{partsgroup} = ""; +      map { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n" } @{ $form->{all_partsgroup} }; +      $form->{oldlanguage_code} = $form->{language_code}; +    } + +       +    $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"}); +    $form->{"selectlanguage"} =~ s/ selected//; +    $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;  +    $lang = qq| +	      <tr> +                <th align=right>|.$locale->text('Language').qq|</th> +		<td colspan=3><select name=language_code>$form->{selectlanguage}</select></td> +	      </tr> +    <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}> +    <input type=hidden name=selectlanguage value="|. +    $form->escape($form->{selectlanguage},1).qq|">|; +  } +  + +  $form->header; + +  +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> + +<input type=hidden name=till value=$form->{till}> + +<input type=hidden name=type value=$form->{type}> +<input type=hidden name=media value=$form->{media}> +<input type=hidden name=format value=$form->{format}> + +<input type=hidden name=printed value="$form->{printed}"> + +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=vc value="customer"> + +<input type=hidden name=discount value=$form->{discount}> +<input type=hidden name=creditlimit value=$form->{creditlimit}> +<input type=hidden name=creditremaining value=$form->{creditremaining}> + +<input type=hidden name=closedto value=$form->{closedto}> +<input type=hidden name=locked value=$form->{locked}> + + +<table width=100%> +  <tr class=listtop> +    <th class=listtop>$form->{title}</font></th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table width=100%> +	<tr valign=top> +	  <td> +	    <table> +	      <tr> +		<th align=right nowrap>|.$locale->text('Customer').qq|</th> +		<td>$customer</td> +		<input type=hidden name=customer_id value=$form->{customer_id}> +		<input type=hidden name=oldcustomer value="$form->{oldcustomer}">  +	      </tr> +	      <tr> +	        <td></td> +		<td colspan=3> +		  <table> +		    <tr> +		      <th nowrap>|.$locale->text('Credit Limit').qq|</th> +		      <td>$form->{creditlimit}</td> +		      <th nowrap>|.$locale->text('Remaining').qq|</th> +		      <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</font></td> +		    </tr> +		  </table> +		</td> +	      </tr> +	      $discount +	      <tr> +		<th align=right nowrap>|.$locale->text('Record in').qq|</th> +		<td><select name=AR>$form->{selectAR}</select></td> +		<input type=hidden name=selectAR value="$form->{selectAR}"> +	      </tr> +	      $department +	    </table> +	  </td> +	  <td> +	    <table> +	      <tr> +	        <th align=right nowrap>|.$locale->text('Salesperson').qq|</th> +		<td colspan=3><select name=employee>$form->{selectemployee}</select></td> +		<input type=hidden name=selectemployee value="|. +		$form->escape($form->{selectemployee},1).qq|"> +	      </tr> +	      <tr> +		<th align=right nowrap>|.$locale->text('Currency').qq|</th> +		<td><select name=currency>$form->{selectcurrency}</select></td> +		<input type=hidden name=selectcurrency value="$form->{selectcurrency}"> +		<input type=hidden name=defaultcurrency value=$form->{defaultcurrency}> +		<input type=hidden name=fxgain_accno value=$form->{fxgain_accno}> +		<input type=hidden name=fxloss_accno value=$form->{fxloss_accno}> +		$exchangerate +	      </tr> +	      $lang +	    </table> +	  </td> +	<input type=hidden name=invnumber value=$form->{invnumber}> +	<input type=hidden name=transdate value=$form->{transdate}> +	<input type=hidden name=duedate value=$form->{duedate}> +	</tr> +      </table> +    </td> +  </tr> +  <tr> +    <td> +    </td> +  </tr> + + +<input type=hidden name=taxaccounts value="$form->{taxaccounts}"> +|; + +  foreach $item (split / /, $form->{taxaccounts}) { +    print qq| +<input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}"> +<input type=hidden name="${item}_description" value="$form->{"${item}_description"}"> +<input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}"> +|; +  } + +} + + + +sub form_footer { + +  $form->{invtotal} = $form->{invsubtotal}; +   +  foreach $item (split / /, $form->{taxaccounts}) { +    if ($form->{"${item}_base"}) { +      $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2); +      $form->{invtotal} += $form->{"${item}_total"}; +      $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2, 0); +       +      $tax .= qq| +	    <tr> +	      <th align=right>$form->{"${item}_description"}</th> +	      <td align=right>$form->{"${item}_total"}</td> +	    </tr> +|; +    } +  } + + + +  $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); + +  $subtotal = qq| +	      <tr> +		<th align=right>|.$locale->text('Subtotal').qq|</th> +		<td align=right>$form->{invsubtotal}</td> +	      </tr> +|; + + +  $totalpaid = 0; +   +  $form->{paidaccounts} = 1; +  $i = 1; +   +  $form->{"selectAR_paid_$i"} = $form->{selectAR_paid}; +  $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; +   +  # format amounts +  $totalpaid += $form->{"paid_$i"}; +  $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); +  $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); +   +  $form->{change} = 0; +  if ($totalpaid > $form->{invtotal}) { +    $form->{change} = $totalpaid - $form->{invtotal}; +  } +  $form->{oldchange} = $form->{change}; +  $form->{change} = $form->format_amount(\%myconfig, $form->{change}, 2, 0); +  $form->{totalpaid} = $form->format_amount(\%myconfig, $totalpaid, 2); + +  +  $form->{oldinvtotal} = $form->{invtotal}; +  $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); +   +  +  print qq| + +<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate"}> +<input type=hidden name="forex_$i" value=$form->{"forex_$i"}> + +  <tr> +    <td> +      <table width=100%> +	<tr valign=bottom> +	  <td> +	    <table> +	      <tr> +	        <td></td> +                <th>|.$locale->text('Paid').qq|</th> +		<th>|.$locale->text('Source').qq|</th> +		<th>|.$locale->text('Memo').qq|</th> +		<th>|.$locale->text('Account').qq|</th> +	      </tr> +	      <tr> +	        <td></td> +		<td><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td> +		<td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td> +		<td><input name="memo_$i" size=10 value="$form->{"memo_$i"}"></td> +	        <td><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td> +	      </tr> +	      <tr> +		<th align=right>|.$locale->text('Change').qq|</th> +		<th>$form->{change}</th> +	      </tr> +	    </table> +	  </td> +	  <td align=right> +	    <table> +	      $subtotal +	      $tax +	      <tr> +		<th align=right>|.$locale->text('Total').qq|</th> +		<td align=right>$form->{invtotal}</td> +	      </tr> +	      $taxincluded +	    </table> +	  </td> +	</tr> +      </table> +    </td> +  </tr> +  +<input type=hidden name=paidaccounts value=$form->{paidaccounts}> +<input type=hidden name=selectAR_paid value="$form->{selectAR_paid}"> +<input type=hidden name=oldinvtotal value=$form->{oldinvtotal}> +<input type=hidden name=oldtotalpaid value=$totalpaid> + +<input type=hidden name=change value=$form->{change}> +<input type=hidden name=oldchange value=$form->{oldchange}> + +<input type=hidden name=datepaid value=$form->{transdate}> +<input type=hidden name=invtotal value=$form->{invtotal}> + +<tr> +  <td> +|; + +  &print_options; + +  print qq| +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> +|; + +  $transdate = $form->datetonum($form->{transdate}, \%myconfig); +  $closedto = $form->datetonum($form->{closedto}, \%myconfig); +  +  if (! $form->{readonly}) { +    if ($transdate > $closedto) { +      print qq| +      <input class=submit type=submit name=action value="|.$locale->text('Update').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('Print').qq|"> +      <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|; + +      if ($form->{id}) { +	print qq| +      <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|; +      } +     + +      print "<p>\n"; +     +      if ($form->{partsgroup}) { +	print qq| +<input type=hidden name=nextsub value=lookup_partsgroup> +<input type=hidden name=partsgroup value="$form->{partsgroup}">|; + +	foreach $item (split /\n/, $form->{partsgroup}) { +	  $item =~ s/
//; +	  ($partsgroup, $translation) = split /--/, $item; +	  $item = ($translation) ? $translation : $partsgroup; +	  print qq| <input class=submit type=submit name=action value=".$item">\n|; +	} +      } +    } +  } +   +  print qq| + +<input type=hidden name=rowcount value=$form->{rowcount}> + +<input name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +</form> + +</body> +</html> +|; + +} + + +sub post { + +  $form->isblank("customer", $locale->text('Customer missing!')); + +  # if oldcustomer ne customer redo form +  $customer = $form->{customer}; +  $customer =~ s/--.*//g; +  $customer .= "--$form->{customer_id}"; +  if ($customer ne $form->{oldcustomer}) { +    &update; +    exit; +  } +   +  &validate_items; + +  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); +   +  $paid = $form->parse_amount(\%myconfig, $form->{"paid_1"}); +  $total = $form->parse_amount(\%myconfig, $form->{invtotal}); +   +  $form->{"paid_1"} = $form->{invtotal} if $paid > $total; +   +  ($form->{AR}) = split /--/, $form->{AR}; + +  $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber") unless $form->{invnumber}; +   +  $form->redirect($locale->text('Posted!')) if (IS->post_invoice(\%myconfig, \%$form)); +  $form->error($locale->text('Cannot post transaction!')); +   +} + + +sub display_row { +  my $numrows = shift; + +  @column_index = qw(partnumber description partsgroup qty unit sellprice discount linetotal); +     +  $form->{invsubtotal} = 0; + +  map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); +   +  $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|; +  $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|; +  $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|; +  $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|; +  $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|; +  $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|; +  $column_data{discount} = qq|<th class=listheading nowrap>%</th>|; +   +  print qq| +  <tr> +    <td> +      <table width=100%> +	<tr class=listheading>|; + +  map { print "\n$column_data{$_}" } @column_index; + +  print qq| +        </tr> +|; + +  $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate}); +  $exchangerate = ($exchangerate) ? $exchangerate : 1; +   +  for $i (1 .. $numrows) { +    # undo formatting +    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty discount sellprice); + +    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); +    $dec = length $dec; +    $decimalplaces = ($dec > 2) ? $dec : 2; + +    if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) { +# check for a pricematrix +      foreach $item (split / /, $form->{"pricematrix_$i"}) { +	($q, $p) = split /:/, $item; +	if ($p && $form->{"qty_$i"} > $q) { +	  $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces); +	} +      } +    } +     +    if ($i < $numrows) { +      if ($form->{"discount_$i"} != $form->{discount} * 100) { +	$form->{"discount_$i"} = $form->{discount} * 100; +      } +    } +     +    $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces); +    $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces); +    $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2); + +    map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description partsgroup unit); +     +    $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>|; + +    if (($rows = $form->numtextrows($form->{"description_$i"}, 25, 6)) > 1) { +      $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=25 wrap=soft>$form->{"description_$i"}</textarea></td>|; +    } else { +      $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|; +    } + +    $column_data{partsgroup} = qq|<input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|; + +    $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|; +    $column_data{unit} = qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|; +    $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|; +    $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|; +     + +    $discount = $form->format_amount(\%myconfig, $form->{"discount_$i"}); +    $column_data{discount} = qq|<td align=right>$discount</td> +    <input type=hidden name="discount_$i" value=$discount>|; +     +    print qq| +        <tr valign=top>|; + +    map { print "\n$column_data{$_}" } @column_index; +   +    print qq| +        </tr> + +<input type=hidden name="id_$i" value=$form->{"id_$i"}> +<input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}> +<input type=hidden name="income_accno_$i" value=$form->{"income_accno_$i"}> +<input type=hidden name="expense_accno_$i" value=$form->{"expense_accno_$i"}> +<input type=hidden name="listprice_$i" value="$form->{"listprice_$i"}"> +<input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}"> +<input type=hidden name="taxaccounts_$i" value="$form->{"taxaccounts_$i"}"> +<input type=hidden name="pricematrix_$i" value="$form->{"pricematrix_$i"}"> +<input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}"> +<input type=hidden name="sku_$i" value="$form->{"sku_$i"}"> + +|; + +    map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"}); +   +    $form->{invsubtotal} += $linetotal; +  } + +  print qq| +      </table> +    </td> +  </tr> + +<input type=hidden name=oldcurrency value=$form->{currency}> + +|; + +} + + +sub print { +   +  $paid = $form->parse_amount(\%myconfig, $form->{"paid_1"}); +  $total = $form->parse_amount(\%myconfig, $form->{invtotal}); + +  $form->{change} = 0; +  if ($paid > $total) { +    $form->{paid} = $total - $paid; +    $form->{"paid_1"} = $form->format_amount(\%myconfig, $paid, 2, 0); +    $form->{change} = $form->format_amount(\%myconfig, $paid - $total, 2, 0); +  } + +  $old_form = new Form; +  map { $old_form->{$_} = $form->{$_} } keys %$form; +   +  map { $form->{$_} =~ s/--.*//g } qw(employee department); +  $form->{invdate} = $form->{transdate}; +  $form->{invtime} = scalar localtime; + +  &print_form($old_form); + +} + + +sub print_form { +  my $old_form = shift; +   +  # if oldcustomer ne customer redo form +  $customer = $form->{customer}; +  $customer =~ s/--.*//g; +  $customer .= "--$form->{customer_id}"; +  if ($customer ne $form->{oldcustomer}) { +    &update; +    exit; +  } +  +  +  &validate_items; + +  &{ "$form->{vc}_details" }; + +  @a = (); +  map { push @a, ("partnumber_$_", "description_$_") } (1 .. $form->{rowcount}); +  map { push @a, "${_}_description" } split / /, $form->{taxaccounts}; +  $form->format_string(@a); + +  # format payment dates +  map { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}) } (1 .. $form->{paidaccounts}); +   +  IS->invoice_details(\%myconfig, \%$form); + +  map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax businessnumber)); +  $form->{username} = $myconfig{name}; +  map { $form->{$_} =~ s/\\n/ /g } qw(company address); + +  $form->{templates} = "$myconfig{templates}"; +  $form->{IN} = "$form->{type}.$form->{format}"; + +  if ($form->{media} !~ /screen/) { +    $form->{OUT} = "| $printer{$form->{media}}"; +  } + +  $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100); +   +  $form->{rowcount}--; +  $form->{pre} = "<body bgcolor=#ffffff>\n<pre>"; +  delete $form->{stylesheet}; +   +  $form->parse_template(\%myconfig, $userspath); + +  if ($form->{printed} !~ /$form->{formname}/) { +    $form->{printed} .= " $form->{formname}"; +    $form->{printed} =~ s/^ //; +     +    $form->update_status(\%myconfig); +  } +  $old_form->{printed} = $form->{printed}; +   +  # if we got back here restore the previous form +  if ($form->{media} !~ /screen/) { +    # restore and display form +    map { $form->{$_} = $old_form->{$_} } keys %$old_form; +    map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate); + +    $form->{rowcount}--; +    for $i (1 .. $form->{paidaccounts}) { +      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); +    } + +    delete $form->{pre}; + +    &display_form; +    exit; +  } + +} + + +sub lookup_partsgroup { + +  $form->{action} =~ s/
//; +  $form->{action} = substr($form->{action}, 1); + +  if ($form->{language_code}) { +    # get english +    foreach $item (split /\n/, $form->{partsgroup}) { +      if ($item =~ /$form->{action}/) { +	($partsgroup, $translation) = split /--/, $item; +	$form->{action} = $partsgroup; +	last; +      } +    } +  } +   +  $form->{"partsgroup_$form->{rowcount}"} = $form->{action}; +  +  &update; + +} + + + +sub print_options { + +  $form->{PD}{$form->{type}} = "checked"; +   +  print qq| +<input type=hidden name=format value=$form->{format}> +<input type=hidden name=formname value=$form->{type}> + +<table width=100%> +  <tr> +|; + +  +  $media = qq| +    <td><input class=radio type=radio name=media value="screen"></td> +    <td>|.$locale->text('Screen').qq|</td>|; + +  if (%printer) { +    map { $media .= qq| +    <td><input class=radio type=radio name=media value="$_"></td> +    <td nowrap>$_</td> +| } keys %printer; +  } + +  $media =~ s/(value="\Q$form->{media}\E")/$1 checked/; + +  print qq| +  $media +   +  <td width=99%> </td>|; +   +  if ($form->{printed} =~ /$form->{type}/) { +    print qq| +    <th>\||.$locale->text('Printed').qq|\|</th>|; +  } +   +  print qq| +  </tr> +</table> +|; + +} + + +sub receipts { + +  $form->{title} = $locale->text('Receipts'); + +  $form->{db} = 'ar'; +  RP->paymentaccounts(\%myconfig, \%$form); +   +  map { $paymentaccounts .= "$_->{accno} " } @{ $form->{PR} }; + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +  $form->header; +   +  print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=title value="$form->{title}"> +<input type=hidden name=paymentaccounts value="$paymentaccounts"> + +<input type=hidden name=till value=1> +<input type=hidden name=subtotal value=1> + +<table width=100%> +  <tr> +    <th class=listtop>$form->{title}</th> +  </tr> +  <tr height="5"></tr> +  <tr> +    <td> +      <table> +       +        <input type=hidden name=nextsub value=list_payments> +	 +        <tr> +	  <th align=right>|.$locale->text('From').qq|</th> +	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> +	  <th align=right>|.$locale->text('To').qq|</th> +	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td> +	</tr> +	$selectfrom +	  <input type=hidden name=sort value=transdate> +	  <input type=hidden name=db value=$form->{db}> +      </table> +    </td> +  </tr> +  <tr> +    <td><hr size=3 noshade></td> +  </tr> +</table> + +<br> +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=sessionid value=$form->{sessionid}> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + diff --git a/sql-ledger/bin/mozilla/ps.pl b/sql-ledger/bin/mozilla/ps.pl new file mode 100644 index 000000000..81ffaa465 --- /dev/null +++ b/sql-ledger/bin/mozilla/ps.pl @@ -0,0 +1,42 @@ +# point of sale script + +use SL::AR; +use SL::IS; +use SL::RP; + +require "$form->{path}/ar.pl"; +require "$form->{path}/is.pl"; +require "$form->{path}/rp.pl"; +require "$form->{path}/pos.pl"; + +# customizations +if (-f "$form->{path}/custom_ar.pl") { +  eval { require "$form->{path}/custom_ar.pl"; }; +} +if (-f "$form->{path}/$form->{login}_ar.pl") { +  eval { require "$form->{path}/$form->{login}_ar.pl"; }; +} + +if (-f "$form->{path}/custom_is.pl") { +  eval { require "$form->{path}/custom_is.pl"; }; +} +if (-f "$form->{path}/$form->{login}_is.pl") { +  eval { require "$form->{path}/$form->{login}_is.pl"; }; +} + +if (-f "$form->{path}/custom_rp.pl") { +  eval { require "$form->{path}/custom_rp.pl"; }; +} +if (-f "$form->{path}/$form->{login}_rp.pl") { +  eval { require "$form->{path}/$form->{login}_rp.pl"; }; +} + +if (-f "$form->{path}/custom_pos.pl") { +  eval { require "$form->{path}/custom_pos.pl"; }; +} +if (-f "$form->{path}/$form->{login}_pos.pl") { +  eval { require "$form->{path}/$form->{login}_pos.pl"; }; +} + +1; +# end diff --git a/sql-ledger/bin/mozilla/pw.pl b/sql-ledger/bin/mozilla/pw.pl new file mode 100644 index 000000000..6f7319004 --- /dev/null +++ b/sql-ledger/bin/mozilla/pw.pl @@ -0,0 +1,73 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2004 +# +#  Author: Dieter Simader +#     Web: http://www.sql-ledger.org +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#====================================================================== + + +1; +# end of main + + +sub getpassword { +  my ($s) = @_; + +  $form->{endsession} = 1; +  $form->header; + +  $sessionexpired = qq|<b><font color=red><blink>|.$locale->text('Session expired!').qq|</blink></font></b><p>| if $s; +   +  print qq| +<script language="JavaScript" type="text/javascript"> +<!-- +function sf(){ +    document.pw.password.focus(); +} +// End --> +</script> + +<body onload="sf()"> + +  $sessionexpired + +<form method=post action=$form->{script} name=pw> + +<table> +  <tr> +    <th align=right>|.$locale->text('Password').qq|</th> +    <td><input type=password name=password size=30></td> +    <td><input type=submit value="|.$locale->text('Continue').qq|"></td> +  </tr> +</table> + +|; + +  map { delete $form->{$_} } qw(header script endsession password); +  $form->hide_form; +   +  print qq| +</form> + +</body> +</html> +|; + +} + + diff --git a/sql-ledger/bin/mozilla/rc.pl b/sql-ledger/bin/mozilla/rc.pl index cf2bc235b..ee6d86781 100644 --- a/sql-ledger/bin/mozilla/rc.pl +++ b/sql-ledger/bin/mozilla/rc.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 2002 +# Copyright (c) 2003  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -25,13 +25,39 @@  #  #====================================================================== -  use SL::RC; -  1;  # end of main +# this is for our long dates +# $locale->text('January') +# $locale->text('February') +# $locale->text('March') +# $locale->text('April') +# $locale->text('May ') +# $locale->text('June') +# $locale->text('July') +# $locale->text('August') +# $locale->text('September') +# $locale->text('October') +# $locale->text('November') +# $locale->text('December') + +# this is for our short month +# $locale->text('Jan') +# $locale->text('Feb') +# $locale->text('Mar') +# $locale->text('Apr') +# $locale->text('May') +# $locale->text('Jun') +# $locale->text('Jul') +# $locale->text('Aug') +# $locale->text('Sep') +# $locale->text('Oct') +# $locale->text('Nov') +# $locale->text('Dec') +  sub reconciliation { @@ -42,6 +68,42 @@ sub reconciliation {    $form->{title} = $locale->text('Reconciliation'); +  if ($form->{report}) { +    $form->{title} = $locale->text('Reconciliation Report'); +    $cleared = qq| +        <input type=hidden name=report value=1> +        <tr> +	  <td align=right><input type=checkbox style=checkbox name=outstanding value=1 checked></td> +	  <td>|.$locale->text('Outstanding').qq|</td> +	  <td align=right><input type=checkbox style=checkbox name=cleared value=1></td> +	  <td>|.$locale->text('Cleared').qq|</td> +	</tr> +|; + +  } + + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	<th align=right>|.$locale->text('Period').qq|</th> +	<td colspan=3> +	<select name=month>$form->{selectaccountingmonth}</select> +	<select name=year>$form->{selectaccountingyear}</select> +	<input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	<input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	<input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	<input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	</td> +      </tr> +|; + +    $form->header;    print qq| @@ -65,9 +127,21 @@ sub reconciliation {  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectfrom +	$cleared +        <tr> +	  <td align=right><input type=radio style=radio name=summary value=1 checked></td> +	  <td>|.$locale->text('Summary').qq|</td> +	  <td align=right><input type=radio style=radio name=summary value=0></td> +	  <td>|.$locale->text('Detail').qq|</td> +	</tr> +	<tr> +	  <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td> +	  <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td> +	</tr>        </table>      </td>    </tr> @@ -81,7 +155,7 @@ sub reconciliation {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> @@ -102,7 +176,15 @@ sub get_payments {    ($form->{accno}, $form->{account}) = split /--/, $form->{accno};    RC->payment_transactions(\%myconfig, \%$form); -  +   +  $ml = ($form->{category} eq 'A') ? -1 : 1; +  $form->{statementbalance} = $form->{endingbalance} * $ml; +  if (! $form->{fx_transaction}) { +    $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml; +  } +   +  $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0); +      &display_form;  } @@ -110,15 +192,24 @@ sub get_payments {  sub display_form { -  @column_index = qw(cleared transdate source name credit debit balance); +  if ($form->{report}) { +    @column_index = qw(transdate source name cleared credit debit); +  } else { +    @column_index = qw(transdate source name cleared credit debit balance); +  } -  $column_header{cleared} = "<th class=listheading> </th>"; +  $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;    $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";    $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";    $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>"; -  $column_header{debit} = "<th class=listheading>".$locale->text('Deposit')."</a></th>"; -  $column_header{credit} = "<th class=listheading>".$locale->text('Payment')."</a></th>"; +  if ($form->{category} eq 'A') { +    $column_header{debit} = "<th class=listheading>".$locale->text('Deposit')."</a></th>"; +    $column_header{credit} = "<th class=listheading>".$locale->text('Payment')."</a></th>"; +  } else { +    $column_header{debit} = "<th class=listheading>".$locale->text('Decrease')."</a></th>"; +    $column_header{credit} = "<th class=listheading>".$locale->text('Increase')."</a></th>"; +  }    $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>"; @@ -128,7 +219,7 @@ sub display_form {    }    if ($form->{todate}) {      $option .= "\n<br>" if ($option); -    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{todate}, 1); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{todate}, 1);    }    $form->{title} = "$form->{accno}--$form->{account}"; @@ -151,7 +242,7 @@ sub display_form {    <tr>      <td>        <table width=100%> -	<tr> +	<tr class=listheading>  |;    map { print "\n$column_header{$_}" } @column_index; @@ -160,64 +251,110 @@ sub display_form {          </tr>  |; -  $form->{beginningbalance} *= -1; -  $clearedbalance = $balance = $form->{beginningbalance}; +  $ml = ($form->{category} eq 'A') ? -1 : 1; +  $form->{beginningbalance} *= $ml; +  $form->{fx_balance} *= $ml; +   +  if (! $form->{fx_transaction}) { +    $form->{beginningbalance} -= $form->{fx_balance}; +  } +  $balance = $form->{beginningbalance}; +      $i = 0; -  $id = 0; +  $j = 0; +   +  map { $column_data{$_} = "<td> </td>" } qw(cleared transdate source debit credit); -  map { $column_data{$_} = "<td> </td>" } qw(cleared transdate source name debit credit); +  if (! $form->{report}) { +  $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;    $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>"; -  $j = 0;    print qq| -        <tr class=listrow$j> +	<tr class=listrow$j>  |;    map { print "\n$column_data{$_}" } @column_index;    print qq| -        </tr> +	</tr>  |; -   +  } +    foreach $ref (@{ $form->{PR} }) { -    $balance += $ref->{amount} * -1; -    $cleared += $ref->{amount} * -1 if $ref->{cleared}; +    $i++; + +    if (! $form->{fx_transaction}) { +      next if $ref->{fx_transaction}; +    } -    $column_data{name} = "<td>$ref->{name} </td>"; -    $column_data{source} = qq|<td>$ref->{source} </a> -    </td>|; -    $column_data{transdate} = "<td>$ref->{transdate} </td>"; +    $checked = ($ref->{cleared}) ? "checked" : ""; +     +    $column_data{name} = "<td>"; +    map { $column_data{name} .= "$_<br>" } @{ $ref->{name} }; +    $column_data{name} .= "</td>"; +    $column_data{source} = qq|<td>$ref->{source} </td> +    <input type=hidden name="id_$i" value=$ref->{id}>|;      $column_data{debit} = "<td> </td>";      $column_data{credit} = "<td> </td>"; +    $balance += $ref->{amount} * $ml; +      if ($ref->{amount} < 0) { +              $totaldebits += $ref->{amount} * -1; +        $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, " ")."</td>"; +            } else { +              $totalcredits += $ref->{amount}; +        $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, " ")."</td>"; +            }      $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";      if ($ref->{fx_transaction}) { -      $i++ unless $id == $ref->{id}; -      $fx_transaction = 1; -      $fx += $ref->{amount} * -1; -      $column_data{cleared} = qq|<td align=center>  -      <input type=hidden name="fxoid_$i" value=$ref->{oid}> -      </td>|; + +      $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td> </td>|; +      $cleared += $ref->{amount} * $ml if $clearfx; +            } else { -      $i++ unless ($fx_transaction && $id == $ref->{id}); -      $fx_transaction = 0; -      $column_data{cleared} = qq|<td> -      <input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}> -      <input type=hidden name="oid_$i" value=$ref->{oid}> -      </td>|; +       +      if ($form->{report}) { +	 +	if ($ref->{cleared}) { +	  $column_data{cleared} = qq|<td align=center>*</td>|; +	  $clearfx = 1; +	} else { +	  $column_data{cleared} = qq|<td> </td>|; +	  $clearfx = 0; +	} +	 +      } else { + +	if ($ref->{oldcleared}) { +	  $cleared += $ref->{amount} * $ml; +	  $clearfx = 1; +	  $column_data{cleared} = qq|<td align=center>*</td> +	  <input type=hidden name="cleared_$i" value=$ref->{cleared}> +	  <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}> +	  <input type=hidden name="source_$i" value="$ref->{source}">|; +	} else { +	  $cleared += $ref->{amount} * $ml if $checked; +	  $clearfx = ($checked) ? 1 : 0; +	  $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked> +	  <input type=hidden name="source_$i" value="$ref->{source}"></td>|; +	} +	 +      }      } -    $id = $ref->{id}; +     +    $column_data{transdate} = qq|<td>$ref->{transdate} </td> +    <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;      $j++; $j %= 2;      print qq| @@ -232,6 +369,8 @@ sub display_form {    } +  $form->{rowcount} = $i; +      # print totals    map { $column_data{$_} = "<td> </td>" } @column_index; @@ -243,44 +382,34 @@ sub display_form {  |;    map { print "\n$column_data{$_}" } @column_index; - +     $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance}); -  $difference = $form->format_amount(\%myconfig, $form->{statementbalance} - $clearedbalance - $cleared, 2, 0); -   +  $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);    $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0); -  $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0); -   -  if ($fx) { -    $fx = $form->format_amount(\%myconfig, $fx, 2, 0); -    $exchdiff = qq| -		<th align=right nowrap>|.$locale->text('Exchangerate Difference').qq|</th> -		<td width=10%></td> -		<td align=right>$fx</td> -|; -  } -    print qq|  	</tr>        </table>      </td>    </tr> +|; + +   +  if ($form->{report}) { + +    print qq| +    </tr> +  </table> +|; + +  } else { +     +    print qq| +       <tr>      <td>        <table width=100%> -        <tr valign=top> -	  <td> -	    <table> -	      <tr> -		<th align=right nowrap>|.$locale->text('Cleared Balance').qq|</th> -		<td width=10%></td> -		<td align=right>$clearedbalance</td> -	      </tr> -	      <tr> -		$exchdiff -	      </tr> -	    </table> -	  </td> +        <tr>  	  <td align=right>  	    <table>  	      <tr> @@ -291,7 +420,7 @@ sub display_form {  	      <tr>  		<th align=right nowrap>|.$locale->text('Difference').qq|</th>  		<td width=10%></td> -		<td align=right><input name=none size=11 value=$difference></td> +		<td align=right><input name=null size=11 value=$difference></td>  		<input type=hidden name=difference value=$difference>  	      </tr>  	    </table> @@ -305,8 +434,11 @@ sub display_form {    </tr>  </table> -<input type=hidden name=rowcount value=$i> -<input type=hidden name=accno value=$form->{accno}> +<input type=hidden name=fx_transaction value=$form->{fx_transaction}> +<input type=hidden name=summary value=$form->{summary}> + +<input type=hidden name=rowcount value=$form->{rowcount}> +<input type=hidden name=accno value="$form->{accno}">  <input type=hidden name=account value="$form->{account}">  <input type=hidden name=fromdate value=$form->{fromdate}> @@ -314,13 +446,20 @@ sub display_form {  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">  <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|"> -<input type=submit class=submit name=action value="|.$locale->text('Done').qq|"> +<input type=submit class=submit name=action value="|.$locale->text('Done').qq|">|; +  } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } + +  print qq|  </form>  </body> @@ -334,11 +473,10 @@ sub update {    RC->payment_transactions(\%myconfig, \%$form); +  $i = 0;    foreach $ref (@{ $form->{PR} }) { -    if (!$ref->{fx_transaction}) { -      $i++; -      $ref->{cleared} = "checked" if $form->{"cleared_$i"}; -    } +    $i++; +    $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;    }    &display_form; @@ -350,7 +488,7 @@ sub select_all {    RC->payment_transactions(\%myconfig, \%$form); -  map { $_->{cleared} = "checked" unless $_->{fx_transaction} } @{ $form->{PR} }; +  map { $_->{cleared} = 1 } @{ $form->{PR} };    &display_form; @@ -359,7 +497,7 @@ sub select_all {  sub done { -  $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&password=$form->{password}"; +  $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";    $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1); diff --git a/sql-ledger/bin/mozilla/rp.pl b/sql-ledger/bin/mozilla/rp.pl index 41cff8cf0..795ed3711 100644 --- a/sql-ledger/bin/mozilla/rp.pl +++ b/sql-ledger/bin/mozilla/rp.pl @@ -1,6 +1,6 @@  #=====================================================================  # SQL-Ledger Accounting -# Copyright (c) 1998-2002 +# Copyright (c) 2001  #  #  Author: Dieter Simader  #   Email: dsimader@sql-ledger.org @@ -27,7 +27,9 @@  #   #====================================================================== +require "$form->{path}/arap.pl"; +use SL::PE;  use SL::RP;  1; @@ -70,25 +72,29 @@ use SL::RP;  # $locale->text('Tax paid')  # $locale->text('Receipts')  # $locale->text('Payments') +# $locale->text('Project Transactions') +# $locale->text('Non-taxable Sales') +# $locale->text('Non-taxable Purchases')  sub report { -  %title = ( 'balance_sheet'	=> 'Balance Sheet', -             'income_statement'	=> 'Income Statement', -             'trial_balance'	=> 'Trial Balance', -	     'ar_aging'		=> 'AR Aging', -	     'ap_aging'		=> 'AP Aging', -	     'tax_collected'	=> 'Tax collected', -	     'tax_paid'		=> 'Tax paid', -	     'receipts'		=> 'Receipts', -	     'payments'		=> 'Payments', +  %title = ( balance_sheet	=> 'Balance Sheet', +             income_statement	=> 'Income Statement', +             trial_balance	=> 'Trial Balance', +	     ar_aging		=> 'AR Aging', +	     ap_aging		=> 'AP Aging', +	     tax_collected	=> 'Tax collected', +	     tax_paid		=> 'Tax paid', +	     nontaxable_sales	=> 'Non-taxable Sales', +	     nontaxable_purchases => 'Non-taxable Purchases', +	     receipts		=> 'Receipts', +	     payments		=> 'Payments', +	     projects		=> 'Project Transactions',  	   );    $form->{title} = $locale->text($title{$form->{report}}); -   -  $form->header; -   +    $gifi = qq|  <tr>    <th align=right>|.$locale->text('Accounts').qq|</th> @@ -98,7 +104,79 @@ sub report {    </td>  </tr>  |; +   +  # get departments +  $form->all_departments(\%myconfig); +  if (@{ $form->{all_departments} }) { +    $form->{selectdepartment} = "<option>\n"; + +    map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} }); +  } +  +  $department = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Department').qq|</th> +	  <td colspan=3><select name=department>$form->{selectdepartment}</select></td> +	</tr> +| if $form->{selectdepartment}; + +  # accounting years +  $form->{selectaccountingyear} = "<option>\n"; +  map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} }; + +  $form->{selectaccountingmonth} = "<option>\n"; +  map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} }; + +  $selectfrom = qq| +        <tr> +	  <th align=right>|.$locale->text('Period').qq|</th> +	  <td colspan=3> +	  <select name=month>$form->{selectaccountingmonth}</select> +	  <select name=year>$form->{selectaccountingyear}</select> +	  <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	  <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	  <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	  <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	  </td> +	</tr> +|; + +  $selectto = qq| +        <tr> +	  <th align=right></th> +	  <td> +	  <select name=month>$form->{selectaccountingmonth}</select> +	  <select name=year>$form->{selectaccountingyear}</select> +	  </td> +	</tr> +|; + + +  $summary = qq| +	<tr> +	  <th></th> +	  <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq| +	  <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq| +	  </td> +	</tr> +|; + +  # get projects +  $form->all_projects(\%myconfig); +  if (@{ $form->{all_projects} }) { +    $form->{selectproject} = "<option>\n"; +    map { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} }; + +    $project = qq| +	<tr> +	  <th align=right nowrap>|.$locale->text('Project').qq|</th> +	  <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td> +	</tr>|; +  } +  +  $form->header; +     print qq|  <body> @@ -114,29 +192,74 @@ sub report {    <tr>      <td>        <table> +      $department +|; + +  if ($form->{report} eq "projects") { +    print qq| +        $project +        <input type=hidden name=nextsub value=generate_projects> +        <tr> +	  <th align=right>|.$locale->text('From').qq|</th> +	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> +	  <th align=right>|.$locale->text('To').qq|</th> +	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td> +	</tr> +	$selectfrom +      </table> +    </td> +  </tr> +  <tr> +    <td> +      <table> +	<tr> +	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> +	  <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq| +	  <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> +	</tr>  |; +  }    if ($form->{report} eq "income_statement") {      print qq| +	$project          <input type=hidden name=nextsub value=generate_income_statement>  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +        <tr> +	  <th align=right>|.$locale->text('Period').qq|</th> +	  <td colspan=3> +	  <select name=frommonth>$form->{selectaccountingmonth}</select> +	  <select name=fromyear>$form->{selectaccountingyear}</select> +	  <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq| +	  <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq| +	  <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq| +	  <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq| +	  </td> +	</tr>  	<tr> -	  <th colspan=4>|.$locale->text('Compare to').qq|</th> +	  <th align=right>|.$locale->text('Compare to').qq|</th>  	</tr>  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>  	</tr> +        <tr> +	  <th align=right>|.$locale->text('Period').qq|</th> +	  <td> +	  <select name=comparemonth>$form->{selectaccountingmonth}</select> +	  <select name=compareyear>$form->{selectaccountingyear}</select> +	  </td> +	</tr>  	<tr>  	  <th align=right>|.$locale->text('Decimalplaces').qq|</th> -	  <td><input name=decimalplaces size=3 maxsize=1></td> +	  <td><input name=decimalplaces size=3 value=2></td>  	</tr>        </table>      </td> @@ -145,9 +268,16 @@ sub report {      <td>        <table>  	<tr> +	  <th align=right>|.$locale->text('Method').qq|</th> +	  <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq| +	   <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td> +	</tr> + +	<tr>  	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> -	  <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|</td> -	  <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> +	  <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq| +	  <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq| +	  <input name=l_accno class=checkbox type=checkbox value=Y> |.$locale->text('Account Number').qq|</td>  	</tr>  |;    } @@ -159,12 +289,23 @@ sub report {  	<tr>  	  <th align=right>|.$locale->text('as at').qq|</th>  	  <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td> +	  <td> +	  <select name=asofmonth>$form->{selectaccountingmonth}</select> +	  <select name=asofyear>$form->{selectaccountingyear}</select> +	  </td> +	</tr> +  	  <th align=right nowrap>|.$locale->text('Compare to').qq|</th>  	  <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td> +	  <td> +	  <select name=compareasofmonth>$form->{selectaccountingmonth}</select> +	  <select name=compareasofyear>$form->{selectaccountingyear}</select> +	  </td> +  	</tr>  	<tr>  	  <th align=right>|.$locale->text('Decimalplaces').qq|</th> -	  <td><input name=decimalplaces size=3 maxsize=1></td> +	  <td><input name=decimalplaces size=3 value=2></td>  	</tr>        </table>      </td> @@ -173,9 +314,16 @@ sub report {      <td>        <table>  	<tr> +	  <th align=right>|.$locale->text('Method').qq|</th> +	  <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq| +	   <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td> +	</tr> + +	<tr>  	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> -	  <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|</td> -	  <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> +	  <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq| +	  <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq| +	  <input name=l_accno class=checkbox type=checkbox value=Y> |.$locale->text('Account Number').qq|</td>  	</tr>  |;    } @@ -187,9 +335,10 @@ sub report {          <tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectfrom        </table>      </td>    </tr> @@ -199,16 +348,17 @@ sub report {  	<tr>  	  <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>  	  <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq| -	  <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> +	  <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq| +	  <input name=all_accounts class=checkbox type=checkbox value=Y> |.$locale->text('All Accounts').qq|</td>  	</tr>  |;    } -  if (($form->{report} eq "tax_paid") || ($form->{report} eq "tax_collected")) { +  if ($form->{report} =~ /^tax_/) {      $gifi = ""; -    $form->{db} = ($form->{report} eq "tax_collected") ? "ar" : "ap"; +    $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";      RP->get_taxaccounts(\%myconfig, \%$form); @@ -217,27 +367,26 @@ sub report {  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> -	<tr> -	  <th align=right>|.$locale->text('Cash based').qq|</th> -	  <td><input name=cashbased class=checkbox type=checkbox value=Y></td> -	</tr> +	$selectfrom +	$summary  	<tr>  	  <th align=right>|.$locale->text('Report for').qq|</th> -	  <td> +	  <td colspan=3>  |;    $checked = "checked"; -  foreach $item (@{ $form->{taxaccounts} }) { -    ($accno, $description) = split /--/, $item; +  foreach $ref (@{ $form->{taxaccounts} }) { -    print qq|<input name=accno class=radio type=radio value=$accno $checked> $description +    print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description} -    <input name="${accno}_description" type=hidden value="$description">|; +    <input name="$ref->{accno}_description" type=hidden value="$ref->{description}"> +    <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;      $checked = ""; +    }    print qq| @@ -253,15 +402,15 @@ sub report {      print qq|          <tr>  	  <th align=right>|.$locale->text('GIFI').qq|</th> -	  <td> +	  <td colspan=3>  |; -    foreach $item (@{ $form->{gifi_taxaccounts} }) { -      ($accno, $description) = split /--/, $item; +    foreach $ref (@{ $form->{gifi_taxaccounts} }) { -      print qq|<input name=accno class=radio type=radio value="gifi_$accno" $checked> $description +      print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}"> $ref->{description} -      <input name="gifi_${accno}_description" type=hidden value="$description">|; +      <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}"> +      <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;      } @@ -273,6 +422,11 @@ sub report {  print qq| +	<tr> +	  <th align=right>|.$locale->text('Method').qq|</th> +	  <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq| +	   <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td> +	</tr>        </table>      </td>    </tr> @@ -293,24 +447,96 @@ print qq|  	      </tr>  	      <tr>  		<td><input name="l_name" class=checkbox type=checkbox value=Y checked></td> -		<td>|; +|;    if ($form->{db} eq 'ar') { -    print $locale->text('Customer'); +    print qq|<td>|.$locale->text('Customer').qq|</td>|;    }    if ($form->{db} eq 'ap') { -    print $locale->text('Vendor'); +    print qq|<td>|.$locale->text('Vendor').qq|</td>|;    } -  print qq|</td> -                <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td> +  print qq| +  	        <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td> +		<td>|.$locale->text('Description').qq|</td> +		<td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>  		<td>|.$locale->text('Amount').qq|</td> +		  		<td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>  		<td>|.$locale->text('Tax').qq|</td> -		<td><input name="l_amount" class=checkbox type=checkbox value=Y></td> +		 +                <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>  		<td>|.$locale->text('Total').qq|</td>  	      </tr>  	      <tr> +	      </tr> +	      <tr> +	        <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td> +		<td>|.$locale->text('Subtotal').qq|</td> +	      </tr> +	    </table> +	  </td> +	</tr> +|; + +  } + +   +  if ($form->{report} =~ /^nontaxable_/) { +    $gifi = ""; + +    $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap"; +     +    print qq| +        <input type=hidden name=nextsub value=generate_tax_report> + +        <input type=hidden name=db value=$form->{db}> +        <input type=hidden name=sort value=transdate> +        <input type=hidden name=report value=$form->{report}> + +	<tr> +	  <th align=right>|.$locale->text('From').qq|</th> +	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> +	  <th align=right>|.$locale->text('To').qq|</th> +	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td> +	</tr> +	$selectfrom +	$summary +	<tr> +	  <th align=right>|.$locale->text('Method').qq|</th> +	  <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq| +	   <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td> +	</tr> +        <tr> +	  <th align=right>|.$locale->text('Include in Report').qq|</th> +	  <td colspan=3> +	    <table> +	      <tr> +		<td><input name="l_id" class=checkbox type=checkbox value=Y></td> +		<td>|.$locale->text('ID').qq|</td> +		<td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td> +		<td>|.$locale->text('Invoice').qq|</td> +		<td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td> +		<td>|.$locale->text('Date').qq|</td> +	      </tr> +	      <tr> +		<td><input name="l_name" class=checkbox type=checkbox value=Y checked></td> +|; +		 +  if ($form->{db} eq 'ar') { +    print qq|<td>|.$locale->text('Customer').qq|</td>|; +  } +  if ($form->{db} eq 'ap') { +    print qq|<td>|.$locale->text('Vendor').qq|</td>|; +  } +   +  print qq| +	        <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td> +		<td>|.$locale->text('Description').qq|</td> +                <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td> +		<td>|.$locale->text('Amount').qq|</td> +	      </tr> +	      <tr>  	        <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>  		<td>|.$locale->text('Subtotal').qq|</td>  	      </tr> @@ -336,37 +562,41 @@ print qq|      $nextsub = "generate_$form->{report}";      # setup vc selection -    $form->all_vc(\%myconfig, $form->{vc}); +    $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP"); -    map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; +    map { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} };      $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|; +    $postscript = "postscript" if $myconfig{printer}; +      print qq|  	<tr>  	  <th align=right>|.$locale->text($label).qq|</th>  	  <td>$vc</td>  	</tr>  	<tr> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectto          <input type=hidden name=type value=statement> -        <input type=hidden name=format value=html> -	<input type=hidden name=media value=screen> +        <input type=hidden name=format value=$postscript> +	<input type=hidden name=media value="$myconfig{printer}">  	<input type=hidden name=nextsub value=$nextsub>  	<input type=hidden name=action value=$nextsub> +	$summary  |;    }  # above action can be removed if there is more than one input field -  if (($form->{report} eq "receipts") || ($form->{report} eq "payments")) { +  if ($form->{report} =~ /(receipts|payments)$/) {      $gifi = ""; -    $form->{db} = ($form->{report} eq "receipts") ? "ar" : "ap"; +    $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";      RP->paymentaccounts(\%myconfig, \%$form); @@ -386,12 +616,34 @@ print qq|  	    <input type=hidden name=paymentaccounts value="$paymentaccounts">  	  </td>  	</tr> +        <tr> +	  <th align=right nowrap>|.$locale->text('Description').qq|</th> +          <td colspan=3><input name=description size=35></td> +	</tr> +        <tr> +	  <th align=right nowrap>|.$locale->text('Source').qq|</th> +          <td colspan=3><input name=source></td> +	</tr> +        <tr> +	  <th align=right nowrap>|.$locale->text('Memo').qq|</th> +          <td colspan=3><input name=memo size=30></td> +	</tr>  	<tr>  	  <th align=right>|.$locale->text('From').qq|</th>  	  <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td> -	  <th align=right>|.$locale->text('to').qq|</th> +	  <th align=right>|.$locale->text('To').qq|</th>  	  <td><input name=todate size=11 title="$myconfig{dateformat}"></td>  	</tr> +	$selectfrom +        <tr> +	  <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td> +	  <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td> +	</tr> +        <tr> +	  <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td> +	  <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th> +	</tr> +	    	  <input type=hidden name=db value=$form->{db}>  	  <input type=hidden name=sort value=transdate>  |; @@ -414,7 +666,7 @@ $gifi  <br>  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> @@ -436,10 +688,12 @@ sub generate_income_statement {    $form->{bold} = "<b>";    $form->{endbold} = "</b>";    $form->{br} = "<br>"; - +      RP->income_statement(\%myconfig, \%$form); - +  ($form->{department}) = split /--/, $form->{department}; +  ($form->{projectnumber}) = split /--/, $form->{projectnumber}; +      $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);    $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate}; @@ -451,27 +705,26 @@ sub generate_income_statement {      }      $longtodate = $locale->date(\%myconfig, $form->{todate}, 1); -    $shorttodate = $locale->date(\%myconfig, $form->{todate}); +    $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);      $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); -    $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}); +    $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);      $form->{this_period} = "$shortfromdate<br>\n$shorttodate"; -    $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('to').qq| $longtodate|; +    $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;    }    if ($form->{comparefromdate} || $form->{comparetodate}) {      $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1); -    $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}); +    $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);      $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1); -    $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}); +    $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);      $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate"; -    $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('to').qq| $longcomparetodate|; +    $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;    } -     # setup variables for the form    @a = qw(company address businessnumber);    map { $form->{$_} = $myconfig{$_} } @a; @@ -492,18 +745,20 @@ sub generate_balance_sheet {    $form->{bold} = "<b>";    $form->{endbold} = "</b>";    $form->{br} = "<br>"; - +      RP->balance_sheet(\%myconfig, \%$form);    $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1); -  # define Retained Earnings account +  ($form->{department}) = split /--/, $form->{department}; +   +  # define Current Earnings account    $padding = ($form->{l_heading}) ? $form->{padding} : ""; -  push(@{$form->{equity_account}}, $padding.$locale->text('Retained Earnings')); +  push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings')); -  $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}); -  $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}); +  $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0); +  $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);    $form->{IN} = "balance_sheet.html"; @@ -518,6 +773,17 @@ sub generate_balance_sheet {  } +sub generate_projects { + +  $form->{nextsub} = "generate_projects"; +  $form->{title} = $locale->text('Project Transactions'); +  RP->trial_balance(\%myconfig, \%$form); +   +  &list_accounts; + +} + +  # Antonio Gallardo  #  # D.S. Feb 16, 2001 @@ -527,7 +793,7 @@ sub generate_balance_sheet {  sub generate_trial_balance {    # get for each account initial balance, debits and credits -  RP->trial_balance_details(\%myconfig, \%$form); +  RP->trial_balance(\%myconfig, \%$form);    $form->{nextsub} = "generate_trial_balance";    $form->{title} = $locale->text('Trial Balance'); @@ -540,11 +806,17 @@ sub list_accounts {    $title = $form->escape($form->{title}); +  if ($form->{department}) { +    ($department) = split /--/, $form->{department}; +    $options = $locale->text('Department')." : $department<br>"; +    $department = $form->escape($form->{department}); +  }    if ($form->{projectnumber}) { -    $options .= $locale->text('Project Number')." : $form->{projectnumber}<br>"; +    ($projectnumber) = split /--/, $form->{projectnumber}; +    $options .= $locale->text('Project Number')." : $projectnumber<br>";      $projectnumber = $form->escape($form->{projectnumber});    } -  +    # if there are any dates    if ($form->{fromdate} || $form->{todate}) {      if ($form->{fromdate}) { @@ -557,8 +829,8 @@ sub list_accounts {      $form->{period} = "$fromdate - $todate";    } else {      $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1); +    } -      $options .= $form->{period};    @column_index = qw(accno description begbalance debit credit endbalance); @@ -607,7 +879,7 @@ sub list_accounts {      $description = $form->escape($ref->{description}); -    $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|; +    $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;      if ($form->{accounttype} eq 'gifi') {        $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description"; @@ -624,29 +896,33 @@ sub list_accounts {      $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, " ");      $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, " "); -    next if ($ref->{debit} == 0 && $ref->{credit} == 0); -     +       if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) { -      map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance); - -      $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " "); -      $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " "); -      $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " "); -      $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " "); -      $column_data{description} = "<th>$subtotaldescription</th>"; -      $column_data{begbalance} = "<th align=right>$subtotalbegbalance</th>"; -      $column_data{endbalance} = "<th align=right>$subtotalendbalance</th>"; -      $column_data{debit} = "<th align=right>$subtotaldebit</th>"; -      $column_data{credit} = "<th align=right>$subtotalcredit</th>"; -       -      print qq| -	<tr class=listsubtotal> + +      if ($subtotal) { + +	map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance); + +	$subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " "); +	$subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " "); +	$subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " "); +	$subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " "); +	 +	$column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>"; +	$column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>"; +	$column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>"; +	$column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>"; +	$column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>"; +	 +	print qq| +	  <tr class=listsubtotal>  |; -      map { print "$column_data{$_}\n" } @column_index; -       -      print qq| -        </tr> +	map { print "$column_data{$_}\n" } @column_index; +	 +	print qq| +	  </tr>  |; +      }      }      if ($ref->{charttype} eq "H") { @@ -657,7 +933,20 @@ sub list_accounts {        $subtotalbegbalance = 0;        $subtotalendbalance = 0; -      next unless $form->{l_heading}; +      if ($form->{l_heading}) { +	if (! $form->{all_accounts}) { +	  if (($subtotaldebit + $subtotalcredit) == 0) { +	    $subtotal = 0; +	    next; +	  } +	} +      } else { +	$subtotal = 0; +	if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) { +	  $subtotal = 1; +	} +	next; +      }        map { $column_data{$_} = "<th> </th>" } qw(accno debit credit begbalance endbalance);        $column_data{description} = "<th class=listheading>$ref->{description}</th>"; @@ -674,11 +963,13 @@ sub list_accounts {        $totaldebit += $ref->{debit};        $totalcredit += $ref->{credit}; -      $subtotalbegbalance += $ref->{balance} * $ml; -      $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml; +      $cml = ($ref->{category} eq 'C') ? -1 : 1; +      $subtotalbegbalance += $ref->{balance} * $ml * $cml; +      $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;      } -     +  +         if ($ref->{charttype} eq "H") {        print qq|        <tr class=listheading> @@ -706,19 +997,19 @@ sub list_accounts {      $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");      $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");      $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " "); -    $column_data{description} = "<th>$subdescription</th>"; -    $column_data{begbalance} = "<th align=right>$subtotalbegbalance</th>"; -    $column_data{endbalance} = "<th align=right>$subtotalendbalance</th>"; -    $column_data{debit} = "<th align=right>$subtotaldebit</th>"; -    $column_data{credit} = "<th align=right>$subtotalcredit</th>"; +    $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>"; +    $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>"; +    $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>"; +    $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>"; +    $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";      print qq| -      <tr class=listsubtotal> +    <tr class=listsubtotal>  |;      map { print "$column_data{$_}\n" } @column_index;      print qq| -      </tr> +    </tr>  |;    } @@ -753,18 +1044,21 @@ sub list_accounts {  } -  sub generate_ar_aging {    # split customer    ($form->{customer}) = split(/--/, $form->{customer}); +  $customer = $form->escape($form->{customer},1); +  $title = $form->escape($form->{title},1); +  $media = $form->escape($form->{media},1);    $form->{ct} = "customer";    $form->{arap} = "ar"; -  $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&customer=|.$form->escape($form->{customer}); -    RP->aging(\%myconfig, \%$form); + +  $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|; +      &aging;  } @@ -774,13 +1068,17 @@ sub generate_ap_aging {    # split vendor    ($form->{vendor}) = split(/--/, $form->{vendor}); +  $vendor = $form->escape($form->{vendor},1); +  $title = $form->escape($form->{title},1); +  $media = $form->escape($form->{media},1);    $form->{ct} = "vendor";    $form->{arap} = "ap"; -  $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&vendor=|.$form->escape($form->{vendor}); -    RP->aging(\%myconfig, \%$form); + +  $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|; +    &aging;  } @@ -788,22 +1086,43 @@ sub generate_ap_aging {  sub aging { -    $form->header; - -  $column_header{statement} = qq|<th class=listheading> </th>|; -  $column_header{ct} = qq|<th class=listheading>|.$locale->text(ucfirst $form->{ct}).qq|</th>|; +   +  $column_header{statement} = qq|<th class=listheading width=1%> </th>|; +  $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|; +  $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;    $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|; -  $column_header{transdate} = qq|<th class=listheading>|.$locale->text('Date').qq|</th>|; -  $column_header{duedate} = qq|<th class=listheading>|.$locale->text('Due').qq|</th>|; -  $column_header{c0} = qq|<th class=listheading>|.$locale->text('Current').qq|</th>|; -  $column_header{c30} = qq|<th class=listheading>30</th>|; -  $column_header{c60} = qq|<th class=listheading>60</th>|; -  $column_header{c90} = qq|<th class=listheading>90</th>|; +  $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|; +  $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|; +  $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|; +  $column_header{c0} = qq|<th class=listheading width=10%>|.$locale->text('Current').qq|</th>|; +  $column_header{c30} = qq|<th class=listheading width=10%>30</th>|; +  $column_header{c60} = qq|<th class=listheading width=10%>60</th>|; +  $column_header{c90} = qq|<th class=listheading width=10%>90</th>|; -  @column_index = (qw(statement ct invnumber transdate duedate c0 c30 c60 c90)); +  @column_index = qw(statement ct); + +  if (@{ $form->{all_language} } && $form->{arap} eq 'ar') { +    push @column_index, "language"; +    $form->{selectlanguage} = qq|<option>\n|; +    map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_language} }; +  } +  if ($form->{summary}) { +    push @column_index, qw(c0 c30 c60 c90); +  } else { +    push @column_index, qw(invnumber ordnumber transdate duedate c0 c30 c60 c90); +  } + +  if ($form->{department}) { +      $option .= "\n<br>" if $option; +      ($department) = split /--/, $form->{department}; +      $option .= $locale->text('Department')." : $department"; +      $department = $form->escape($form->{department},1); +      $form->{callback} .= "&department=$department"; +  } +        if ($form->{arap} eq 'ar') {      if ($form->{customer}) {        $option .= "\n<br>" if $option; @@ -817,10 +1136,10 @@ sub aging {        $option .= $form->{vendor};      }    } -   +    $todate = $locale->date(\%myconfig, $form->{todate}, 1);    $option .= "\n<br>" if $option; -  $option .= $locale->text('for Period')." ".$locale->text('to')." $todate"; +  $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";    print qq|  <body> @@ -849,58 +1168,33 @@ sub aging {    $ctid = 0; -  $subtotal = 0;    $i = 0; +  $k = 0; +  $l = $#{ $form->{AG} };    foreach $ref (@{ $form->{AG} }) { +    $k++; +          if ($ctid != $ref->{ctid}) {        $i++; -      if ($subtotal) { -	$c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " "); -	$c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " "); -	$c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " "); -	$c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " "); -      } +      $column_data{ct} = qq|<td>$ref->{name}</td>|; -      $column_data{ct} = qq|<th> </th>|; -      $column_data{invnumber} = qq|<th> </th>|; -      $column_data{transdate} = qq|<th> </th>|; -      $column_data{duedate} = qq|<th> </th>|; -      $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|; -      $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|; -      $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|; -      $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|; -      -      if ($subtotal) { -	# print subtotals -	print qq| -	<tr class=listsubtotal> -|; - -	map { print "$column_data{$_}\n" } @column_index; - -	$column_data{statement} = qq|<td> </td>|; - -	print qq| -        </tr> -|; +      if ($form->{selectlanguage}) { +	$form->{"selectlanguage_$i"} = $form->{selectlanguage}; +	$form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/; +	$column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;        } -    -      $subtotal = 1; - -      $c0subtotal = 0; -      $c30subtotal = 0; -      $c60subtotal = 0; -      $c90subtotal = 0; - -      $column_data{ct} = qq|<td>$ref->{name}</td>|; +              $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>        <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>        </td>|; +      } +	     +    $ctid = $ref->{ctid};      $c0subtotal += $ref->{c0};      $c30subtotal += $ref->{c30}; @@ -916,73 +1210,103 @@ sub aging {      $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, " ");      $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, " ");      $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, " "); -  -    $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|.$form->escape($form->{callback}); + +    $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});      $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|; -    $column_data{transdate} = qq|<td>$ref->{transdate}</td>|; -    $column_data{duedate} = qq|<td>$ref->{duedate} </td>|; -    $column_data{c0} = qq|<td align=right>$ref->{c0}</td>|; -    $column_data{c30} = qq|<td align=right>$ref->{c30}</td>|; -    $column_data{c60} = qq|<td align=right>$ref->{c60}</td>|; -    $column_data{c90} = qq|<td align=right>$ref->{c90}</td>|; +    map { $column_data{$_} = qq|<td>$ref->{$_}</td>| } qw(ordnumber transdate duedate); +    map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(c0 c30 c60 c90); -    $j++; $j %= 2; -    print qq| -	<tr class=listrow$j> +    if (!$form->{summary}) { + +      $j++; $j %= 2; +      print qq| +        <tr class=listrow$j>  |; -    map { print "$column_data{$_}\n" } @column_index; +      map { print "$column_data{$_}\n" } @column_index; -    print qq| +      print qq|          </tr>  |; -  -    $column_data{ct} = qq|<td> </td>|; -    $column_data{statement} = qq|<td> </td>|; -    $ctid = $ref->{ctid}; +      map { $column_data{$_} = qq|<td> </td>| } qw(ct statement language); +       +    } +    +    # print subtotal +    $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0; +    if ($ctid != $nextid) { + +      $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " "); +      $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " "); +      $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " "); +      $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " "); +       +      if ($form->{summary}) { +	$column_data{c0} = qq|<td align=right>$c0subtotal</th>|; +	$column_data{c30} = qq|<td align=right>$c30subtotal</th>|; +	$column_data{c60} = qq|<td align=right>$c60subtotal</th>|; +	$column_data{c90} = qq|<td align=right>$c90subtotal</th>|; -  } -   -  # print subtotals -  $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " "); -  $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " "); -  $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " "); -  $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " "); -   -  print qq| -        <tr class=listsubtotal> +	$j++; $j %= 2; +	print qq| +	<tr class=listrow$j>  |; -  map { $column_data{$_} = qq|<th> </th>| } @column_index; +        map { print "$column_data{$_}\n" } @column_index; + +	print qq| +	</tr> +|; -  $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|; -  $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|; -  $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|; -  $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|; +      } else { -  map { print "$column_data{$_}\n" } @column_index; -  +	map { $column_data{$_} = qq|<th> </th>| } @column_index; + +	$column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|; +	$column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|; +	$column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|; +	$column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|; + +        # print subtotals +        print qq| +	<tr class=listsubtotal> +|; +        map { print "$column_data{$_}\n" } @column_index; + +	print qq| +	</tr> +|; + +      } +       +      $c0subtotal = 0; +      $c30subtotal = 0; +      $c60subtotal = 0; +      $c90subtotal = 0; +       +    } +  }    print qq|          </tr>          <tr class=listtotal>  |; +  map { $column_data{$_} = qq|<th> </th>| } @column_index; +    $c0total = $form->format_amount(\%myconfig, $c0total, 2, " ");    $c30total = $form->format_amount(\%myconfig, $c30total, 2, " ");    $c60total = $form->format_amount(\%myconfig, $c60total, 2, " ");    $c90total = $form->format_amount(\%myconfig, $c90total, 2, " "); -  $column_data{c0} = qq|<th class=listtotal align=right>$c0total</th>|; -  $column_data{c30} = qq|<th class=listtotal align=right>$c30total</th>|; -  $column_data{c60} = qq|<th class=listtotal align=right>$c60total</th>|; -  $column_data{c90} = qq|<th class=listtotal align=right>$c90total</th>|; +  $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|; +  $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|; +  $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|; +  $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|; -     map { print "$column_data{$_}\n" } @column_index; -    print qq|            <input type=hidden name=rowcount value=$i> @@ -1010,14 +1334,19 @@ sub aging {  <input type=hidden name=todate value=$form->{todate}>  <input type=hidden name=title value="$form->{title}"> +<input type=hidden name=summary value=$form->{summary}> + +<input type=hidden name=callback value=$form->{callback}>  <input type=hidden name=arap value=$form->{arap}>  <input type=hidden name=ct value=$form->{ct}>  <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}"> +<input type=hidden name=department value="$form->{department}"> +  <input type=hidden name=path value=$form->{path}>  <input type=hidden name=login value=$form->{login}> -<input type=hidden name=password value=$form->{password}> +<input type=hidden name=sessionid value=$form->{sessionid}>  <br>  <input class=submit type=submit name=action value="|.$locale->text('Select all').qq|"> @@ -1026,6 +1355,11 @@ sub aging {  |;    } +  if ($form->{menubar}) { +    require "$form->{path}/menu.pl"; +    &menubar; +  } +    print qq|  </form> @@ -1050,60 +1384,59 @@ sub select_all {  sub print_options {    $form->{sendmode} = "attachment"; -  $form->{copies} = 2 unless $form->{copies}; +  $form->{copies} = 1 unless $form->{copies}; -  $form->{PD}{$form->{type}} = "checked"; -  $form->{DF}{$form->{format}} = "checked"; -  $form->{OP}{$form->{media}} = "checked"; -  $form->{SM}{$form->{sendmode}} = "checked"; +  $form->{PD}{$form->{type}} = "selected"; +  $form->{DF}{$form->{format}} = "selected"; +  $form->{SM}{$form->{sendmode}} = "selected"; +  $format = qq| +            <option value=html $form->{PD}{format}>html|; +	     +  $type = qq| +	    <option value=statement $form->{PD}{statement}>|.$locale->text('Statement'); +      if ($form->{media} eq 'email') { -    $email = qq| -	<td><input class=radio type=radio name=sendmode value=attachment $form->{SM}{attachment}> |.$locale->text('Attachment') -	.qq| <input class=radio type=radio name=sendmode value=inline $form->{SM}{inline}> |.$locale->text('In-line').qq|</td> -|; +    $media = qq| +            <td><select name=sendmode> +	    <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq| +	    <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');    } else { -    $screen = qq| -	<td><input class=radio type=radio name=media value=screen $form->{OP}{screen}></td> -	<td>|.$locale->text('Screen').qq|</td> -|; +    $media = qq| +            <td><select name=media> +	    <option value=screen>|.$locale->text('Screen'); +    if (%printer && $latex) { +      map { $media .= qq| +            <option value="$_">$_| } keys %printer; +    }    } -  print qq| -<table width=100%> -  <tr valign=top> -    <td><input class=radio type=radio name=type value=statement $form->{PD}{statement}></td><td>|.$locale->text('Statement').qq|</td> -    <td><input class=radio type=radio name=format value=html $form->{DF}{html}></td> -    <td>html</td> -|; +  $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/; +  $media .= qq|</select></td>|;    if ($latex) { -      print qq| -    <td><input class=radio type=radio name=format value=postscript $form->{DF}{postscript}></td> -    <td>|.$locale->text('Postscript').qq|</td> -    <td><input class=radio type=radio name=format value=pdf $form->{DF}{pdf}></td> -    <td>|.$locale->text('PDF').qq|</td> -|; +    $format .= qq| +            <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq| +	    <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');    }    print qq| -    $screen +<table> +  <tr> +    <td><select name=type>$type</select></td> +    <td><select name=format>$format</select></td> +    $media  |; -  if ($screen) { -    if ($myconfig{printer} && $latex) { -      print qq| -    <td><input class=radio type=radio name=media value=printer $form->{OP}{printer}></td> -    <td>|.$locale->text('Printer') -    .qq| (|.$locale->text('Copies') -    .qq| <input name=copies size=2 value=$form->{copies}>)</td> +  if (%printer && $latex && $form->{media} ne 'email') { +    print qq| +      <td>|.$locale->text('Copies').qq| +      <input name=copies size=2 value=$form->{copies}></td>  |; -    }    } - +      print qq| -    $email    </tr>  </table>  |; @@ -1125,7 +1458,7 @@ sub e_mail {    $form->error($locale->text('Nothing selected!')) unless $selected; -  if ($myconfig{admin}) { +  if ($myconfig{role} =~ /(admin|manager)/) {      $bcc = qq|            <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>  	  <td><input name=bcc size=30 value="$form->{bcc}"></td> @@ -1145,7 +1478,7 @@ sub e_mail {  <table width=100%>    <tr class=listtop> -    <th class=listtop>$title</th> +    <th>$title</th>    </tr>    <tr height="5"></tr>    <tr> @@ -1183,13 +1516,9 @@ sub e_mail {    &print_options; -  map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format); +  map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format header); -  # save all other variables -  foreach $key (keys %$form) { -    $form->{$key} =~ s/"/"/g; -    print qq|<input type=hidden name=$key value="$form->{$key}">\n|; -  } +  $form->hide_form();    print qq|      </td> @@ -1217,6 +1546,7 @@ sub send_email {    $form->{OUT} = "$sendmail";    $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject}; +  $form->isblank("email", $locale->text('E-mail address missing!'));    RP->aging(\%myconfig, \%$form); @@ -1231,14 +1561,15 @@ sub send_email {  sub print { -   -  if ($form->{media} eq 'printer') { + +  if ($form->{media} !~ /(screen|email)/) {      $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);    }    for $i (1 .. $form->{rowcount}) {      if ($form->{"statement_$i"}) {        $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"}; +      $language_code = $form->{"language_code_$i"};        $selected = 1;        last;      } @@ -1247,18 +1578,20 @@ sub print {    $form->error($locale->text('Nothing selected!')) unless $selected; -  if ($form->{media} eq 'printer') { -    $form->{OUT} = "| $myconfig{printer}"; +  if ($form->{media} !~ /(screen|email)/) { +    $form->{OUT} = "| $printer{$form->{media}}";      $form->{"$form->{ct}_id"} = ""; +    $SIG{INT} = 'IGNORE';    } else {      $form->{"statement_1"} = 1; +    $form->{"language_code_1"} = $language_code;    } -   +    RP->aging(\%myconfig, \%$form);    &print_form; -  $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} eq 'printer'); +  $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);  } @@ -1268,7 +1601,7 @@ sub print_form {    $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);    $form->{templates} = "$myconfig{templates}"; -  +    # setup variables for the form    @a = qw(company address businessnumber tel fax);    map { $form->{$_} = $myconfig{$_} } @a; @@ -1277,14 +1610,16 @@ sub print_form {    $form->{IN} = "$form->{type}.html";    if ($form->{format} eq 'postscript') { -    $form->{postscript} = 1;      $form->{IN} =~ s/html$/tex/;    }    if ($form->{format} eq 'pdf') { -    $form->{pdf} = 1;      $form->{IN} =~ s/html$/tex/;    } +  @a = qw(name address1 address2 city state zipcode country contact); +  push @a, "$form->{ct}phone", "$form->{ct}fax"; +  push @a, 'email' if ! $form->{media} eq 'email'; +    $i = 0;    while (@{ $form->{AG} }) { @@ -1297,14 +1632,14 @@ sub print_form {        if ($form->{"statement_$i"}) { -	@a = (name, addr1, addr2, addr3, addr4, contact, "$form->{ct}phone", "$form->{ct}fax");  	map { $form->{$_} = $ref->{$_} } @a;  	$form->format_string(@a);  	$form->{$form->{ct}} = $form->{name};  	$form->{"$form->{ct}_id"} = $ref->{ctid}; +	$form->{language_code} = $form->{"language_code_$i"}; -	map { $form->{$_} = () } qw(invnumber invdate duedate); +	map { $form->{$_} = () } qw(invnumber ordnumber notes invdate duedate);  	$form->{total} = 0;  	foreach $item (qw(c0 c30 c60 c90)) {  	  $form->{$item} = (); @@ -1312,10 +1647,10 @@ sub print_form {  	}  	&statement_details($ref); -	 +          while ($ref) { -          if (scalar (@{ $form->{AG} }) > 0) { +	  if (scalar (@{ $form->{AG} }) > 0) {  	    # one or more left to go  	    if ($ctid == $form->{AG}->[0]->{ctid}) {  	      $ref = shift @{ $form->{AG} }; @@ -1345,13 +1680,15 @@ sub print_form {  sub statement_details {    my ($ref) = @_; -   -  push @{ $form->{invnumber} }, $ref->{invnumber}; -  push @{ $form->{invdate} }, $ref->{transdate}; -  push @{ $form->{duedate} }, $ref->{duedate}; + +  $ref->{invdate} = $ref->{transdate}; +  my @a = qw(invnumber ordnumber notes invdate duedate); +  map { $form->{"${_}_1"} = $ref->{$_} } @a; +  $form->format_string(qw(invnumber_1 ordnumber_1 notes_1)); +  map { push @{ $form->{$_} }, $form->{"${_}_1"} } @a;    foreach $item (qw(c0 c30 c60 c90)) { -    $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2); +    eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };      $form->{"${item}total"} += $ref->{$item};      $form->{total} += $ref->{$item};      push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2); @@ -1366,16 +1703,42 @@ sub generate_tax_report {    $descvar = "$form->{accno}_description";    $description = $form->escape($form->{$descvar}); +  $ratevar = "$form->{accno}_rate"; +  $taxrate = $form->{"$form->{accno}_rate"}; +   +  if ($form->{accno} =~ /^gifi_/) { +    $descvar = "gifi_$form->{accno}_description"; +    $description = $form->escape($form->{$descvar}); +    $ratevar = "gifi_$form->{accno}_rate"; +    $taxrate = $form->{"gifi_$form->{accno}_rate"}; +  } +   +  $department = $form->escape($form->{department});    # construct href -  $href = "$form->{script}?path=$form->{path}&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&accno=$form->{accno}&$descvar=$description"; +  $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";    # construct callback -  $callback = $href; +  $description = $form->escape($form->{$descvar},1); +  $department = $form->escape($form->{department},1); -  -  @columns = $form->sort_columns(qw(id transdate invnumber name netamount tax amount)); +  $form->sort_order(); + +  $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}"; +  $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/); + +  $title = $form->escape($form->{title}); +  $href .= "&title=$title"; +  $title = $form->escape($form->{title},1); +  $callback .= "&title=$title"; +   +  $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |; + +  @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total)); + +  $form->{"l_description"} = "" if $form->{summary}; +      foreach $item (@columns) {      if ($form->{"l_$item"} eq "Y") {        push @column_index, $item; @@ -1386,12 +1749,18 @@ sub generate_tax_report {      }    } +    if ($form->{l_subtotal} eq 'Y') {      $callback .= "&l_subtotal=Y";      $href .= "&l_subtotal=Y";    } +  if ($form->{department}) { +    ($department) = split /--/, $form->{department}; +    $option = $locale->text('Department')." : $department"; +  } +      # if there are any dates    if ($form->{fromdate} || $form->{todate}) {      if ($form->{fromdate}) { @@ -1406,30 +1775,32 @@ sub generate_tax_report {      $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);    } -  $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/); -  $form->{title} = qq|$form->{"$form->{accno}_description"} |; +    if ($form->{db} eq 'ar') { -    $form->{title} .= $locale->text('collected on sales');      $name = $locale->text('Customer');      $invoice = 'is.pl';      $arap = 'ar.pl';    }    if ($form->{db} eq 'ap') { -    $form->{title} .= $locale->text('paid on purchases');      $name = $locale->text('Vendor');      $invoice = 'ir.pl';      $arap = 'ap.pl';    } +  $option .= "<br>" if $option; +  $option .= "$form->{period}"; +      $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;    $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;    $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;    $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;    $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|; -  $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|; +  $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;    $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|; +   +  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;    $form->header; @@ -1443,7 +1814,7 @@ sub generate_tax_report {    </tr>    <tr height="5"></tr>    <tr> -    <td>$form->{period}</td> +    <td>$option</td>    </tr>    <tr>      <td> @@ -1467,6 +1838,7 @@ sub generate_tax_report {    foreach $ref (@{ $form->{TR} }) {      $module = ($ref->{invoice}) ? $invoice : $arap; +    $module = 'ps.pl' if $ref->{till};      if ($form->{l_subtotal} eq 'Y') {        if ($sameitem ne $ref->{$form->{sort}}) { @@ -1477,19 +1849,19 @@ sub generate_tax_report {      $totalnetamount += $ref->{netamount};      $totaltax += $ref->{tax}; -    $ref->{amount} = $ref->{netamount} + $ref->{tax}; +    $ref->{total} = $ref->{netamount} + $ref->{tax};      $subtotalnetamount += $ref->{netamount};      $subtotaltax += $ref->{tax}; -    map { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); } qw(netamount tax amount); +    map { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); } qw(netamount tax total);      $column_data{id} = qq|<td>$ref->{id}</td>|; -    $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>|; -    $column_data{transdate} = qq|<td>$ref->{transdate}</td>|; -    $column_data{name} = qq|<td>$ref->{name} </td>|; +    $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|; + +    map { $column_data{$_} = qq|<td>$ref->{$_}</td>| } qw(id transdate name partnumber description); -    map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(netamount tax amount); +    map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(netamount tax total);      $i++; $i %= 2;      print qq| @@ -1522,7 +1894,7 @@ sub generate_tax_report {    $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;    $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|; -  $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|; +  $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;    map { print "$column_data{$_}\n" } @column_index; @@ -1548,13 +1920,13 @@ sub tax_subtotal {    map { $column_data{$_} = "<td> </td>" } @column_index; +  $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");    $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");    $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " "); -  $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");    $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";    $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>"; -  $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>"; +  $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";    $subtotalnetamount = 0;    $subtotaltax = 0; @@ -1574,31 +1946,58 @@ sub tax_subtotal {  sub list_payments { +    if ($form->{account}) {      ($form->{paymentaccounts}) = split /--/, $form->{account};    } +  if ($form->{department}) { +    ($department, $form->{department_id}) = split /--/, $form->{department}; +    $option = $locale->text('Department')." : $department"; +  }    RP->payments(\%myconfig, \%$form); -  @columns = $form->sort_columns(qw(transdate invnumber name paid source)); +  @columns = $form->sort_columns(qw(transdate name paid source memo)); +  if ($form->{till}) { +    @columns = $form->sort_columns(qw(transdate name paid curr source till)); +    if ($myconfig{role} ne 'user') { +      @columns = $form->sort_columns(qw(transdate name paid curr source till employee)); +    } +  } +      # construct href -  $href = "$form->{script}?path=$form->{path}&action=list_payments&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&title=".$form->escape($form->{title})."&account=".$form->escape($form->{account}); - +  $account = $form->escape($form->{account}); +  $title = $form->escape($form->{title}); +  $department = $form->escape($form->{department});    $form->{paymentaccounts} =~ s/ /%20/g; -  $href .= "&paymentaccounts=$form->{paymentaccounts}"; - +  $source = $form->escape($form->{source}); +  $memo = $form->escape($form->{memo}); +   +  $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_cubtotal}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&source=$source&memo=$memo";    # construct callback -  $form->{callback} = "$href&sort=$form->{sort}"; +  $account = $form->escape($form->{account},1); +  $title = $form->escape($form->{title},1); +  $department = $form->escape($form->{department},1); +  $source = $form->escape($form->{source},1); +  $memo = $form->escape($form->{memo},1); +   +  $form->sort_order(); + +  $form->{callback} = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&source=$source&memo=$memo&sort=$form->{sort}";    $callback = $form->escape($form->{callback});    $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>"; -  $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";    $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";    $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>"; +  $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";    $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>"; +  $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>"; + +  $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>"; +  $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";    if ($form->{fromdate}) { @@ -1607,7 +2006,7 @@ sub list_payments {    }    if ($form->{todate}) {      $option .= "\n<br>" if ($option); -    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{todate}, 1); +    $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{todate}, 1);    }    @column_index = @columns; @@ -1641,28 +2040,40 @@ sub list_payments {    foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) { +    next unless @{ $form->{$ref->{id}} }; +      print qq|          <tr>  	  <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>  	</tr>  |; -   + +    if (@{ $form->{$ref->{id}} }) { +      $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}}; +    } +          foreach $payment (@{ $form->{$ref->{id}} }) { + +      if ($form->{l_subtotal}) { +	if ($payment->{$form->{sort}} ne $sameitem) { +	  # print subtotal +	  &payment_subtotal; +	} +      } -      $module = $payment->{module}; -      $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar'); -      $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap'); -       -      $href = qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|; -     +      next if ($form->{till} && ! $payment->{till});        $column_data{name} = "<td>$payment->{name} </td>"; -      $column_data{invnumber} = qq|<td><a href=$href>$payment->{invnumber}</a></td>|;        $column_data{transdate} = "<td>$payment->{transdate} </td>";        $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, " ")."</td>"; +      $column_data{curr} = "<td>$payment->{curr}</td>";        $column_data{source} = "<td>$payment->{source} </td>"; +      $column_data{memo} = "<td>$payment->{memo} </td>"; +      $column_data{employee} = "<td>$payment->{employee} </td>"; +      $column_data{till} = "<td>$payment->{till} </td>";        $subtotalpaid += $payment->{paid}; +      $accounttotalpaid += $payment->{paid};        $totalpaid += $payment->{paid};        $i++; $i %= 2; @@ -1676,15 +2087,19 @@ sub list_payments {          </tr>  |; +      $sameitem = $payment->{$form->{sort}}; +            } -    # print subtotals +    &payment_subtotal if $form->{l_subtotal}; +     +    # print account totals      map { $column_data{$_} = "<td> </td>" } @column_index; -    $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>"; +    $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, " ")."</th>";      print qq| -	<tr class=listsubtotal> +	<tr class=listtotal>  |;      map { print "\n$column_data{$_}" } @column_index; @@ -1693,7 +2108,7 @@ sub list_payments {          </tr>  |; -    $subtotalpaid = 0; +    $accounttotalpaid = 0;    } @@ -1727,4 +2142,26 @@ sub list_payments {  } +sub payment_subtotal { + +  if ($subtotalpaid != 0) { +    map { $column_data{$_} = "<td> </td>" } @column_index; + +    $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>"; + +    print qq| +  <tr class=listsubtotal> +|; + +    map { print "\n$column_data{$_}" } @column_index; + +    print qq| +  </tr> +|; +  } + +  $subtotalpaid = 0; + +} +  | 
