diff options
author | ivan <ivan> | 2003-07-15 11:45:14 +0000 |
---|---|---|
committer | ivan <ivan> | 2003-07-15 11:45:14 +0000 |
commit | f6c9088e16c4c083174dd1130ae58d213923cdef (patch) | |
tree | 7398c7087b03c412658679bf25a68700191bd1a8 /sql-ledger/bin/mozilla |
import of sql-ledger 2.0.8SQL_LEDGER_2_0_8
Diffstat (limited to 'sql-ledger/bin/mozilla')
-rw-r--r-- | sql-ledger/bin/mozilla/admin.pl | 1504 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/am.pl | 1051 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ap.pl | 1103 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ar.pl | 1135 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/arap.pl | 406 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ca.pl | 413 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/cp.pl | 528 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ct.pl | 631 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/gl.pl | 806 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ic.pl | 1638 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/io.pl | 1149 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/ir.pl | 653 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/is.pl | 739 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/login.pl | 217 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/menu.pl | 160 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/oe.pl | 1111 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/pe.pl | 549 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/rc.pl | 371 | ||||
-rw-r--r-- | sql-ledger/bin/mozilla/rp.pl | 1730 |
19 files changed, 15894 insertions, 0 deletions
diff --git a/sql-ledger/bin/mozilla/admin.pl b/sql-ledger/bin/mozilla/admin.pl new file mode 100644 index 000000000..39247b541 --- /dev/null +++ b/sql-ledger/bin/mozilla/admin.pl @@ -0,0 +1,1504 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2002 +# +# 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. +#====================================================================== +# +# setup module +# add/edit/delete users +# +#====================================================================== + +$menufile = "menu.ini"; + +use SL::Form; +use SL::User; + + +$form = new Form; + +$locale = new Locale $language, "admin"; + +eval { require DBI; }; +$form->error($locale->text('DBI not installed!')) if ($@); + + +# customization +if (-f "$form->{path}/custom_$form->{script}") { + eval { require "$form->{path}/custom_$form->{script}"; }; + $form->error($@) if ($@); +} + + +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; + + &$subroutine; + +} else { + + # if there are no drivers bail out + $form->error($locale->text('No Database Drivers available!')) unless (User->dbdrivers); + + # create memberfile + if (! -f $memberfile) { + open(FH, ">$memberfile") or $form->error("$memberfile : $!"); + print FH qq|# SQL-Ledger Accounting members + +[root login] +password= + +|; + close(FH); + } + + &adminlogin; + +} + +1; +# end + + +sub adminlogin { + + $form->{title} = qq|SQL-Ledger $form->{version} |.$locale->text('Administration'); + + $form->header; + + print qq| +<body class=admin> + + +<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}"> + +<table> + <tr> + <th>|.$locale->text('Password').qq|</th> + <td><input type=password name=rpw></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}> +</table> + + +</form> + +<a href=http://www.sql-ledger.org>SQL-Ledger |.$locale->text('website').qq|</a> + +</div> + +</body> +</html> +|; + +} + + + + +sub login { + + &list_users; + +} + + + +sub add_user { + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User'); + + $form->{Oracle_sid} = $sid; + $form->{Oracle_dbport} = '1521'; + $form->{Oracle_dbhost} = `hostname`; + + if (-f "css/sql-ledger.css") { + $myconfig->{stylesheet} = "sql-ledger.css"; + } + $myconfig->{vclimit} = 200; + + &form_header; + &form_footer; + +} + + + +sub edit { + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User'); + $form->{edit} = 1; + + &form_header; + &form_footer; + +} + + +sub form_footer { + + if ($form->{edit}) { + $delete = qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|"> +<input type=hidden name=edit value=1>|; + } + + 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 type=hidden name=path value=$form->{path}> +<input type=hidden name=rpw value=$form->{rpw}> + +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +$delete + +</form> + +</body> +</html> +|; + +} + + +sub list_users { + + $form->error("$memberfile : ".$locale->text('locked!')) if (-f "${memberfile}.LCK"); + + open(FH, "$memberfile") or $form->error("$memberfile : $!"); + + while (<FH>) { + chop; + + if (/^\[.*\]/) { + $login = $_; + $login =~ s/(\[|\])//g; + } + + if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) { + chop ($var = $&); + ($null, $member{$login}{$var}) = split /=/, $_, 2; + } + } + + close(FH); + +# type=submit $locale->text('Pg Database Administration') +# type=submit $locale->text('Oracle Database Administration') + + foreach $item (User->dbdrivers) { + $dbdrivers .= qq|<input name=action type=submit class=submit value="|.$locale->text("$item Database Administration").qq|">|; + } + + + $column_header{login} = qq|<th>|.$locale->text('Login').qq|</th>|; + $column_header{name} = qq|<th>|.$locale->text('Name').qq|</th>|; + $column_header{company} = qq|<th>|.$locale->text('Company').qq|</th>|; + $column_header{dbdriver} = qq|<th>|.$locale->text('Driver').qq|</th>|; + $column_header{dbhost} = qq|<th>|.$locale->text('Host').qq|</th>|; + $column_header{dataset} = qq|<th>|.$locale->text('Dataset').qq|</th>|; + $column_header{templates} = qq|<th>|.$locale->text('Templates').qq|</th>|; + + @column_index = qw(login name company dbdriver dbhost dataset templates); + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration'); + + $form->header; + + print qq| +<body class=admin> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr> + <tr class=listheading> + <th>$form->{title}</th> + </tr> + <tr size=5></tr> + <tr> + <td> + <table width=100%> + <tr class=listheading>|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| + </tr> +|; + +foreach $key (sort keys %member) { + $href = "$script?action=edit&login=$key&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}"; + $href =~ s/ /%20/g; + + $member{$key}{templates} =~ s/^$templates\///; + $member{$key}{dbhost} = $locale->text('localhost') unless $member{$key}{dbhost}; + $member{$key}{dbname} = $member{$key}{dbuser} if ($member{$key}{dbdriver} eq 'Oracle'); + + $column_data{login} = qq|<td><a href=$href>$key</a></td>|; + $column_data{name} = qq|<td>$member{$key}{name}</td>|; + $column_data{company} = qq|<td>$member{$key}{company}</td>|; + $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|; + $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|; + $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|; + $column_data{templates} = qq|<td>$member{$key}{templates}</td>|; + + $i++; $i %= 2; + print qq| + <tr class=listrow$i>|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr>|; +} + + +print qq| + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</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}"> + +<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 + +</form> + +|.$locale->text('Click on login name to edit!').qq| +<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> +|; + +} + + + + +sub form_header { + + # if there is a login, get user + if ($form->{login}) { + # get user + $myconfig = new User "$memberfile", "$form->{login}"; + + $myconfig->{signature} =~ s/\\n/\r\n/g; + $myconfig->{address} =~ s/\\n/\r\n/g; + + # strip basedir from templates directory + $myconfig->{templates} =~ s/^$templates\///; + + $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd}; + } + + + 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"; + } + + + %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|; + + # is there a templates basedir + if (! -d "$templates") { + $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist')); + } + + opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!"); + @all = grep !/^\.\.?$/, readdir TEMPLATEDIR; + closedir TEMPLATEDIR; + + @allhtml = sort grep /\.html/, @all; + @alldir = grep !/\.(html|tex)$/, @all; + + @allhtml = reverse grep !/Default/, @allhtml; + push @allhtml, 'Default'; + @allhtml = reverse @allhtml; + + foreach $item (@alldir) { + if ($item eq $myconfig->{templates}) { + $usetemplates .= qq|<option selected>$item\n|; + } else { + $usetemplates .= qq|<option>$item\n|; + } + } + + $lastitem = $allhtml[0]; + $lastitem =~ s/-.*//g; + $mastertemplates = qq|<option>$lastitem\n|; + foreach $item (@allhtml) { + $item =~ s/-.*//g; + + if ($item ne $lastitem) { + $mastertemplates .= qq|<option>$item\n|; + $lastitem = $item; + } + } + + + $form->header; + + print qq| +<body class=admin> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr class=listheading><th colspan=2>$form->{title}</th></tr> + <tr size=5></tr> + <tr valign=top> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Login').qq|</th> + <td><input name=login value="$myconfig->{login}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Password').qq|</th> + <td><input type=password name=password size=8 value=$myconfig->{password}></td> + <input type=hidden name=old_password value=$myconfig->{password}> + </tr> + <tr> + <th align=right>|.$locale->text('Name').qq|</th> + <td><input name=name size=15 value="$myconfig->{name}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('E-mail').qq|</th> + <td><input name=email size=30 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('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> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Date Format').qq|</th> + <td><select name=dateformat>$dateformat</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Number Format').qq|</th> + <td><select name=numberformat>$numberformat</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Dropdown Limit').qq|</th> + <td><input name=vclimit value="$myconfig->{vclimit}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Language').qq|</th> + <td><select name=countrycode>$countrycodes</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Character Set').qq|</th> + <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> + </tr> + <tr> + <th align=right>|.$locale->text('Ship via').qq|</th> + <td><input name=shippingpoint size=15 value="$myconfig->{shippingpoint}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Use Templates').qq|</th> + <td><select name=usetemplates>$usetemplates</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('New Templates').qq|</th> + <td><input name=newtemplates></td> + </tr> + <tr> + <th align=right>|.$locale->text('Setup Templates').qq|</th> + <td><select name=mastertemplates>$mastertemplates</select></td> + </tr> + <input type=hidden name=templates value=$myconfig->{templates}> + </table> + </td> + </tr> + <tr class=listheading> + <th colspan=2>|.$locale->text('Database').qq|</th> + </tr>|; + + # list section for database drivers + foreach $item (User->dbdrivers) { + + print qq| + <tr> + <td colspan=2> + <table> + <tr>|; + + $checked = ""; + if ($myconfig->{dbdriver} eq $item) { + map { $form->{"${item}_$_"} = $myconfig->{$_} } qw(dbhost dbport dbuser dbpasswd dbname sid); + $checked = "checked"; + } + + print qq| + <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> + </tr> + <tr>|; + + if ($item eq 'Pg') { + print qq| + <th align=right>|.$locale->text('Dataset').qq|</th> + <td><input name=Pg_dbname size=10 value=$form->{Pg_dbname}></td> + <th align=right>|.$locale->text('Port').qq|</th> + <td><input name=Pg_dbport size=4 value=$form->{Pg_dbport}></td> + </tr> + <tr> + <th align=right>|.$locale->text('User').qq|</th> + <td><input name="${item}_dbuser" size=10 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>|; + + } + + if ($item eq 'Oracle') { + print qq| + <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> + </tr> + <tr> + <th align=right>|.$locale->text('Dataset').qq|</th> + <td><input name="${item}_dbuser" size=10 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>|; + } + + + print qq| + <input type=hidden name=old_dbpasswd value=$myconfig->{dbpasswd}> + </table> + </td> + </tr> + <tr> + <td colspan=2><hr size=2 noshade></td> + </tr> +|; + + } + + + # access control + open(FH, $menufile) or $form->error("$menufile : $!"); + # scan for first menu level + @a = <FH>; + close(FH); + + if (open(FH, "custom_$menufile")) { + push @a, <FH>; + } + close(FH); + + foreach $item (@a) { + next unless $item =~ /\[/; + next if $item =~ /\#/; + + $item =~ s/(\[|\])//g; + chop $item; + + if ($item =~ /--/) { + ($level, $menuitem) = split /--/, $item, 2; + } else { + $level = $item; + $menuitem = $item; + push @acsorder, $item; + } + + push @{ $acs{$level} }, $menuitem; + + } + + $admincheck = "checked" if $myconfig->{admin}; + + 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> + </tr> +|; + + foreach $item (split /;/, $myconfig->{acs}) { + ($key, $value) = split /--/, $item, 2; + $excl{$key}{$value} = 1; + } + + foreach $key (@acsorder) { + + $checked = "checked"; + if ($form->{login}) { + $checked = ($excl{$key}{$key}) ? "" : "checked"; + } + + # can't have variable names with spaces + # the 1 is for apache 2 + $item = $form->escape("${key}--$key", 1); + + $acsheading = $key; + $acsheading =~ s/ / /g; + + $acsheading = qq| + <th align=left><input name="$item" class=checkbox type=checkbox value=1 $checked> $acsheading</th>\n|; + $menuitems .= "$item;"; + $acsdata = " + <td>"; + + foreach $item (@{ $acs{$key} }) { + next if ($key eq $item); + + $checked = "checked"; + if ($form->{login}) { + $checked = ($excl{$key}{$item}) ? "" : "checked"; + } + + $acsitem = $form->escape("${key}--$item", 1); + + $acsdata .= qq| + <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked> $item|; + $menuitems .= "$acsitem;"; + } + + $acsdata .= " + </td>"; + + print qq| + <tr valign=top>$acsheading $acsdata + </tr> +|; + } + + print qq|<input type=hidden name=acs value="$menuitems"> + + <tr> + <td colspan=2><hr size=3 noshade></td> + </tr> + <tr> + <td> + </td> + </tr> +</table> +|; + +} + + +sub save { + + # no driver checked + $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver}; + + # no spaces allowed in login name + ($form->{login}) = split / /, $form->{login}; + + # check for duplicates + if (!$form->{edit}) { + $temp = new User "$memberfile", "$form->{login}"; + + if ($temp->{login}) { + $form->error("$form->{login} ".$locale->text('is already a member!')); + } + } + + # 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}; + + if ($form->{newtemplates}) { + $form->{templates} = $form->{newtemplates}; + } else { + $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')); + } + + # add base directory to $form->{templates} + $form->{templates} = "$templates/$form->{templates}"; + + + $myconfig = new User "$memberfile", "$form->{login}"; + + # redo acs variable and delete all the acs codes + @acs = split /;/, $form->{acs}; + + $form->{acs} = ""; + foreach $item (@acs) { + $item = $form->escape($item, 1); + + if (!$form->{$item}) { + $form->{acs} .= $form->unescape($form->unescape($item)).";"; + } + delete $form->{$item}; + } + + # check which database was filled in + 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}; + + $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}; + } + + delete $myconfig->{stylesheet}; + if ($form->{userstylesheet}) { + $myconfig->{stylesheet} = $form->{userstylesheet}; + } + + $myconfig->save_member($memberfile, $userspath); + + # create user template directory and copy master files + if (! -d "$form->{templates}") { + umask(002); + + if (mkdir "$form->{templates}", oct("771")) { + + umask(007); + + # copy templates to the directory + opendir TEMPLATEDIR, "$templates/." or $form-error("$templates : $!"); + @templates = grep /$form->{mastertemplates}.*?\.(html|tex)$/, readdir TEMPLATEDIR; + closedir TEMPLATEDIR; + + foreach $file (@templates) { + open(TEMP, "$templates/$file") or $form->error("$templates/$file : $!"); + + $file =~ s/$form->{mastertemplates}-//; + open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!"); + + while ($line = <TEMP>) { + print NEW $line; + } + close(TEMP); + close(NEW); + } + } else { + $form->error("$!: $form->{templates}"); + } + } + + $form->redirect($locale->text('User saved!')); + +} + + +sub delete { + + $form->{templates} = ($form->{templates}) ? "$templates/$form->{templates}" : "$templates/$form->{login}"; + + $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 : $!"); + + @config = <CONF>; + + seek(CONF, 0, 0); + truncate(CONF, 0); + + while ($line = shift @config) { + + if ($line =~ /^\[/) { + last if ($line =~ /\[$form->{login}\]/); + $login = &login_name($line); + } + + if ($line =~ /^templates=/) { + $user{$login} = &get_value($line); + } + + print CONF $line; + } + + # remove everything up to next login or EOF + # and save template variable + while ($line = shift @config) { + if ($line =~ /^templates=/) { + $templatedir = &get_value($line); + } + last if ($line =~ /^\[/); + } + + # this one is either the next login or EOF + print CONF $line; + + $login = &login_name($line); + + + while ($line = shift @config) { + if ($line =~ /^\[/) { + $login = &login_name($line); + } + + if ($line =~ /^templates=/) { + $user{$login} = &get_value($line); + } + + print CONF $line; + } + + close(CONF); + unlink "${memberfile}.LCK"; + + # scan %user for $templatedir + foreach $login (keys %user) { + last if ($found = ($templatedir eq $user{$login})); + } + + # if found keep directory otherwise delete + if (!$found) { + # delete it if there is a template directory + $dir = "$form->{templates}"; + if (-d "$dir") { + unlink <$dir/*.html>; + unlink <$dir/*.tex>; + rmdir "$dir"; + } + } + + # delete config file for user + unlink "$userspath/$form->{login}.conf"; + + $form->redirect($locale->text('User deleted!')); + +} + + +sub login_name { + my $login = shift; + + $login =~ s/\[\]//g; + return ($login) ? $login : undef; + +} + + + +sub get_value { + my $line = shift; + + my ($null, $value) = split(/=/, $line, 2); + + # remove comments + $value =~ s/\s#.*//g; + + # remove any trailing whitespace + $value =~ s/^\s*(.*?)\s*$/$1/; + + $value; +} + + + +sub change_admin_password { + + $form->{title} = qq|SQL-Ledger |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password'); + + $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> + +<input type=hidden name=root value="$form->{root}"> +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=rpw value=$form->{rpw}> + +<p> +<input type=submit class=submit name=action value="|.$locale->text('Change Password').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub change_password { + + $root->{password} = $form->{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->redirect($locale->text('Password changed!')); + +} + + +sub check_password { + + $root = new User "$memberfile", $form->{root}; + + if ($root->{password}) { + if ($root->{password} ne $form->{rpw}) { + $form->error($locale->text('Incorrect Password!')); + } + } + +} + + +sub pg_database_administration { + + $form->{dbdriver} = 'Pg'; + &dbselect_source; + +} + + +sub oracle_database_administration { + + $form->{dbdriver} = 'Oracle'; + &dbselect_source; + +} + + +sub dbdriver_defaults { + + # load some defaults for the selected driver + %driverdefaults = ( 'Pg' => { dbport => '', + dbuser => 'sql-ledger', + dbdefault => 'template1', + dbhost => '', + connectstring => $locale->text('Connect to') + }, + 'Oracle' => { dbport => '1521', + dbuser => 'oralin', + dbdefault => $sid, + dbhost => `hostname`, + connectstring => 'SID' + } + ); + + map { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} } keys %{ $driverdefaults{Pg} }; + +} + + +sub dbselect_source { + + &dbdriver_defaults; + + $msg{Pg} = $locale->text('Leave host and port field empty unless you want to make a remote connection.'); + $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->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> + + <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 type=hidden name=path value=$form->{path}> +<input type=hidden name=rpw value=$form->{rpw}> + +<hr size=3 noshade> +<br> + +<input type=submit class=submit name=action value="|.$locale->text('Create Dataset').qq|"> +<input type=submit class=submit name=action value="|.$locale->text('Update Dataset').qq|"> +<input type=submit class=submit name=action value="|.$locale->text('Delete Dataset').qq|"> + +</form> + +</td></tr> +</table> + +<p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!') + +.qq| +<br>$msg{$form->{dbdriver}} + + +</body> +</html> +|; + +} + + +sub continue { + + &{ $form->{nextsub} }; + +} + + +sub update_dataset { + + %needsupdate = User->dbneedsupdate(\%$form); + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Update Dataset'); + + $form->header; + + print qq| +<body class=admin> + + +<center> +<h2>$form->{title}</h2> +|; + + + 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|; + $form->{dbupdate} .= "db$key "; + } + } + + chop $form->{dbupdate}; + + + if ($form->{dbupdate}) { + + print qq| +<table> +<form method=post action=$form->{script}> + +<input type=hidden name=dbdriver value=$form->{dbdriver}> +<input type=hidden name=dbhost value=$form->{dbhost}> +<input type=hidden name=dbport value=$form->{dbport}> +<input type=hidden name=dbuser value=$form->{dbuser}> +<input type=hidden name=dbpasswd value=$form->{dbpasswd}> +<input type=hidden name=dbdefault value=$form->{dbdefault}> + +<tr class=listheading> + <th>|.$locale->text('The following Datasets need to be updated').qq|</th> +</tr> +<tr> +<td> + +$upd + +</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 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=nextsub value=dbupdate> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + +</td></tr> +</table> +</form> +|; + + } else { + + print $locale->text('All Datasets up to date!'); + + } + + print qq| + +</body> +</html> +|; + +} + + +sub dbupdate { + + User->dbupdate(\%$form); + + $form->redirect($locale->text('Dataset updated!')); + +} + + +sub create_dataset { + + foreach $item (sort User->dbsources(\%$form)) { + $dbsources .= "[$item] "; + } + + 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|; + } + closedir SQLDIR; + + # add Default at beginning + @charts = (qq|<input name=chart class=radio type=radio value="Default" checked> Default|, @charts); + + $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=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=WIN>Windows CP1251 + <option value=ALT>Windows CP866 + |; + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset'); + + $form->header; + + print qq| +<body class=admin> + + +<center> +<h2>$form->{title}</h2> + +<form method=post action=$form->{script}> + +<table> + <tr class=listheading> + <th colspan=2> </th> + </tr> + + <tr> + + <th align=right nowrap>|.$locale->text('Existing Datasets').qq|</th> + <td>$dbsources</td> + + </tr> + + <tr> + + <th align=right nowrap>|.$locale->text('Create Dataset').qq|</th> + <td><input name=db></td> + + </tr> + + <tr> + + <th align=right nowrap>|.$locale->text('Multibyte Encoding').qq|</th> + <td><select name=encoding>$selectencoding</select></td> + + </tr> + + <tr> + + <th align=right>|.$locale->text('Create Chart of Accounts').qq|</th> + <td>@charts</td> + + </tr> + + <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}> +<input type=hidden name=dbport value=$form->{dbport}> +<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 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=nextsub value=dbcreate> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + + </td></tr> +</table> + +</form> + + +</body> +</html> +|; + +} + + +sub dbcreate { + + $form->isblank("db", $locale->text('Dataset missing!')); + + User->dbcreate(\%$form); + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset'); + + $form->header; + + print qq| +<body class=admin> + + +<center> +<h2>$form->{title}</h2> + +<form method=post action=$form->{script}>| + +.$locale->text('Dataset')." $form->{db} ".$locale->text('successfully created!') + +.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=nextsub value=list_users> + +<p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + + +</body> +</html> +|; + +} + + +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>|; + } + } else { + $form->error($locale->text('Nothing to delete!')); + } + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset'); + + $form->header; + + print qq| +<body class=admin> + + +<center> +<h2>$form->{title}</h2> + +<form method=post action=$form->{script}> + +<table> + <tr class=listheading> + <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th> + </tr> + + <tr> + <td> + $dbsources + </td> + </tr> + + <tr><td> + +<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}> +<input type=hidden name=dbport value=$form->{dbport}> +<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 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=nextsub value=dbdelete> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + + </td></tr> +</table> + +</form> + +<p>|.$locale->text('Select a Dataset to delete and press "Continue"') + +.qq| + + +</body> +</html> +|; + +} + + +sub dbdelete { + + if (!$form->{db}) { + $form->error($locale->text('No Dataset selected!')); + } + + User->dbdelete(\%$form); + + $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset'); + + $form->header; + + print qq| +<body class=admin> + + +<center> +<h2>$form->{title}</h2> + +<form method=post action=$form->{script}> + +$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=nextsub value=list_users> + +<p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + + +</body> +</html> +|; + +} + diff --git a/sql-ledger/bin/mozilla/am.pl b/sql-ledger/bin/mozilla/am.pl new file mode 100644 index 000000000..7e36cfdc9 --- /dev/null +++ b/sql-ledger/bin/mozilla/am.pl @@ -0,0 +1,1051 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# administration +# +#====================================================================== + + +use SL::AM; +use SL::CA; +use SL::Form; +use SL::User; + + +1; +# end of main + + + +sub add { + + $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_header; + &form_footer; + +} + + +sub edit { + $form->{title} = "Edit"; + + # if it is a template + if ($form->{file}) { + $form->{type} = "template"; + &edit_template; + exit; + } + + AM->get_account(\%myconfig, \%$form); + + foreach my $item (split(/:/, $form->{link})) { + $form->{$item} = "checked"; + } + + &form_header; + &form_footer; + +} + + +sub form_header { + + $form->{title} = $locale->text("$form->{title} Account"); + + $checked{$form->{charttype}} = "checked"; + $checked{"$form->{category}_"} = "checked"; + $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked"; + + $form->{description} =~ s/"/"/g; + +# this is for our parser only! +# type=submit $locale->text('Add Account') +# type=submit $locale->text('Edit Account') + + $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=account> + +<input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}> +<input type=hidden name=income_accno_id value=$form->{income_accno_id}> +<input type=hidden name=expense_accno_id value=$form->{expense_accno_id}> +<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> + </tr> + <tr height="5"></tr> + <tr valign=top> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Account Number').qq|</th> + <td><input name=accno size=20 value=$form->{accno}></td> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td><input name=description size=40 value="$form->{description}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Account Type').qq|</th> + <td> + <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=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> + <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') + .qq|</td> + </tr> + </table> + </td> + </tr> +|; + + +if ($form->{charttype} eq "A") { + print qq| + <tr> + <td colspan=2> + <table> + <tr> + <th align=left>|.$locale->text('Is this a summary account to record').qq|</th> + <td> + <input name=AR type=checkbox class=checkbox value=AR $form->{AR}> |.$locale->text('AR') + .qq| <input name=AP type=checkbox class=checkbox value=AP $form->{AP}> |.$locale->text('AP') + .qq| <input name=IC type=checkbox class=checkbox value=IC $form->{IC}> |.$locale->text('Inventory') + .qq|</td> + </tr> + </table> + </td> + </tr> + <tr> + <th colspan=2>|.$locale->text('Include in drop-down menus').qq|</th> + </tr> + <tr valign=top> + <td colspan=2> + <table width=100%> + <tr> + <th align=left>|.$locale->text('Receivables').qq|</th> + <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> + </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| + </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| + </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_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| + </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| + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan=2> + <table> + <tr> + <th align=left>|.$locale->text('Include this account on the customer/vendor forms to flag customer/vendor as taxable?').qq|</th> + <td> + <input name=CT_tax type=radio class=radio value=CT_tax $form->{CT_tax}> |.$locale->text('Yes').qq| + <input name=CT_tax type=radio class=radio value="" $checked{CT_tax}> |.$locale->text('No') + .qq| + </td> + </tr> + </table> + </td> + </tr> +|; +} + +print qq| + <tr> + <th align=right>|.$locale->text('GIFI').qq|</th> + <td><input name=gifi_accno size=9 value=$form->{gifi_accno}></td> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub form_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=password value=$form->{password}> + +<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('Delete').qq|">|; + } + + print qq| +</form> + +</body> +</html> +|; + +} + + +sub save { &{ "save_$form->{type}" } }; + +sub save_account { + + $form->isblank("accno", $locale->text('Account Number missing!')); + $form->isblank("category", $locale->text('Account Type missing!')); + + $form->redirect($locale->text('Account saved!')) if (AM->save_account(\%myconfig, \%$form)); + $form->error($locale->text('Cannot save account!')); + +} + + +sub list { + + 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}"; + + @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>|; + + + $form->header; + $colspan = $#column_index + 1; + + print qq| +<body> + +<table border=0 width=100%> + <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> + <tr height=5></tr> + <tr class=listheading> +|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| +</tr> +|; + + # escape callback + $callback = $form->escape($callback); + + foreach $ca (@{ $form->{CA} }) { + + $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, " "); + } + + $ca->{link} =~ s/:/<br>/og; + + 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{description} = qq|<th class=listheading>$ca->{description} </th>|; + $column_data{debit} = qq|<th> </th>|; + $column_data{credit} = qq| <th> </th>|; + $column_data{link} = qq|<th> </th>|; + + } else { + $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{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>|; + $column_data{link} = qq|<td>$ca->{link} </td>|; + + } + + map { print "$column_data{$_}\n" } @column_index; + + print "</tr>\n"; + } + + print qq| + <tr><td colspan=$colspan><hr size=3 noshade></td></tr> +</table> + +</body> +</html> +|; + +} + + +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!')); + } + } + + $form->redirect($locale->text('Account deleted!')) if (AM->delete_account(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete account!')); + +} + + +sub list_gifi { + + @{ $form->{fields} } = (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}"; + + @column_index = qw(accno description); + + $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</a></th>|; + $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</a></th>|; + + + $form->header; + $colspan = $#column_index + 1; + + print qq| +<body> + +<table border=0 width=100%> + <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> + <tr height="5"></tr> + <tr class=listheading> +|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| +</tr> +|; + + # escape callback + $callback = $form->escape($callback); + + foreach $ca (@{ $form->{ALL} }) { + + $i++; $i %= 2; + + 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{description} = qq|<td>$ca->{description} </td>|; + + map { print "$column_data{$_}\n" } @column_index; + + print "</tr>\n"; + } + + print qq| + <tr> + <td colspan=$colspan><hr size=3 noshade></td> + </tr> +</table> + +</body> +</html> +|; + +} + + +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->{coa} = 1; + + &gifi_header; + &gifi_footer; + +} + + +sub edit_gifi { + + $form->{title} = "Edit"; + + AM->get_gifi(\%myconfig, \%$form); + + &gifi_header; + &gifi_footer; + +} + + +sub gifi_header { + + $form->{title} = $locale->text("$form->{title} GIFI"); + +# $locale->text('Add GIFI') +# $locale->text('Edit GIFI') + + $form->{description} =~ s/"/"/g; + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{accno}> +<input type=hidden name=type value=gifi> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table> + <tr> + <th align=right>|.$locale->text('GIFI').qq|</th> + <td><input name=accno size=20 value=$form->{accno}></td> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td><input name=description size=60 value="$form->{description}"></td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan=2><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub gifi_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=password value=$form->{password}> + +<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}) { + print qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|; + } + } + + print qq| +</form> + +</body> +</html> +|; + +} + + +sub save_gifi { + + $form->isblank("accno", $locale->text('GIFI missing!')); + AM->save_gifi(\%myconfig, \%$form); + $form->redirect($locale->text('GIFI saved!')); + +} + + +sub copy_to_coa { + + $form->isblank("accno", $locale->text('GIFI missing!')); + + AM->save_gifi(\%myconfig, \%$form); + + delete $form->{id}; + $form->{gifi_accno} = $form->{accno}; + $form->{title} = "Add"; + $form->{charttype} = "A"; + + &form_header; + &form_footer; + +} + + +sub delete_gifi { + + AM->delete_gifi(\%myconfig, \%$form); + $form->redirect($locale->text('GIFI deleted!')); + +} + + +sub display_stylesheet { + + $form->{file} = "css/$myconfig{stylesheet}"; + &display_form; + +} + + +sub display_form { + + $form->{file} =~ s/^(.:)*?\/|\.\.\///g; + $form->{file} =~ s/^\/*//g; + $form->{file} =~ s/$userspath//; + + $form->error("$!: $form->{file}") unless -f $form->{file}; + + AM->load_template(\%$form); + + $form->{title} = $form->{file}; + + # if it is anything but html + if ($form->{file} !~ /\.html$/) { + $form->{body} = "<pre>\n$form->{body}\n</pre>"; + } + + $form->header; + + print qq| +<body> + +$form->{body} + +<form method=post action=$form->{script}> + +<input name=file type=hidden value=$form->{file}> + +<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 name=action type=submit class=submit value="|.$locale->text('Edit').qq|"> +</form> + + +</body> +</html> +|; + +} + + +sub edit_template { + + AM->load_template(\%$form); + + $form->{title} = $locale->text('Edit Template'); + # convert   to &nbsp; + $form->{body} =~ s/ /&nbsp;/gi; + + + $form->header; + + print qq| +<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 name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}"> + +<textarea name=body rows=25 cols=70> +$form->{body} +</textarea> + +<br> +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> + +</form> + + +</body> +</html> +|; + +} + + +sub save_template { + + AM->save_template(\%$form); + $form->redirect($locale->text('Template saved!')); + +} + + +sub config { + + # 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->{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> + +<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> + <tr> + <th align=right>|.$locale->text('Password').qq|</th> + <td><input type=password name=password size=10 value=$myconfig{password}></td> + </tr> + <tr> + <th align=right>|.$locale->text('E-mail').qq|</th> + <td><input name=email size=30 value="$myconfig{email}"></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> + <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('Company').qq|</th> + <td><input name=company size=30 value="$myconfig{company}"></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> + </tr> + <tr> + <th align=right>|.$locale->text('Date Format').qq|</th> + <td><select name=dateformat>$dateformat</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Number Format').qq|</th> + <td><select name=numberformat>$numberformat</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Dropdown Limit').qq|</th> + <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Language').qq|</th> + <td><select name=countrycode>$countrycodes</select></td> + </tr> + <tr> + <th align=right>|.$locale->text('Character Set').qq|</th> + <td><input name=charset size=20 value="$myconfig{charset}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Stylesheet').qq|</th> + <td><input name=stylesheet size=20 value="$myconfig{stylesheet}"></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> + </tr> + <tr class=listheading> + <th colspan=2> </th> + </tr> + <tr> + <th align=right>|.$locale->text('Business Number').qq|</th> + <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td> + </tr> + <tr> + <td colspan=2> + <table width=100%> + <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> + </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%> + <tr> + <th width=1% align=right nowrap>|.$locale->text('Inventory Account').qq|</th> + <td><select name=inventory_accno>$myconfig{IC}</select></td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Income Account').qq|</th> + <td><select name=income_accno>$myconfig{IC_income}</select></td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Expense Account').qq|</th> + <td><select name=expense_accno>$myconfig{IC_expense}</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> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th> + <td><select name=fxloss_accno>$myconfig{FX_loss}</select></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> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Last Invoice Number').qq|</th> + <td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></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> + </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> + </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> + </tr> +|; + $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} "; + } + + chop $form->{taxaccounts}; + + print qq| +<input name=taxaccounts type=hidden value="$form->{taxaccounts}"> + + </table> + </td> + </tr> + </table> + </td> + </tr> + <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=password value=$form->{password}> + +<br> +<input type=submit class=submit name=action value="|.$locale->text('Save').qq|"> +</form> + +</body> +</html> +|; + +} + + +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->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath)); + $form->error($locale->text('Cannot save preferences!')); + +} + + +sub backup { + + if ($form->{media} eq 'email') { + $form->error($locale->text('No email address for')." $myconfig{name}") unless ($myconfig{email}); + + $form->{OUT} = "$sendmail"; + + } + + AM->backup(\%myconfig, \%$form, $userspath); + + if ($form->{media} eq 'email') { + $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|); + } + +} + + + +sub audit_control { + + $form->{title} = $locale->text('Audit Control'); + + AM->closedto(\%myconfig, \%$form); + + if ($form->{revtrans}) { + $checked{Y} = "checked"; + } else { + $checked{N} = "checked"; + } + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=password value=$form->{password}> + +<table width=100%> + <tr><th class=listtop>$form->{title}</th></tr> + <tr height="5"></tr> + <tr> + <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> + </tr> + <tr> + <td>|.$locale->text('Close Books up to').qq|</th> + <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td> + </tr> + </table> + </td> + </tr> +</table> + +<hr size=3 noshade> + +<br> +<input type=hidden name=nextsub value=doclose> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub doclose { + + AM->closebooks(\%myconfig, \%$form); + + if ($form->{revtrans}) { + $form->redirect($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)); + } else { + $form->redirect($locale->text('Books are open')); + } + } + +} + + + +sub continue { + + &{ $form->{nextsub} }; + +} + + diff --git a/sql-ledger/bin/mozilla/ap.pl b/sql-ledger/bin/mozilla/ap.pl new file mode 100644 index 000000000..269f7cf39 --- /dev/null +++ b/sql-ledger/bin/mozilla/ap.pl @@ -0,0 +1,1103 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2001 +# +# 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. +#====================================================================== +# +# Accounts Payables +# +#====================================================================== + + +use SL::AP; +use SL::IR; +use SL::PE; + +require "$form->{path}/arap.pl"; + +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 add { + + $form->{title} = "Add"; + + $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + + &create_links; + &display_form; + +} + + +sub edit { + + $form->{title} = "Edit"; + + &create_links; + &display_form; + +} + + +sub display_form { + + &form_header; + &form_footer; + +} + + +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 + + # currencies + @curr = split /:/, $form->{currencies}; + chomp $curr[0]; + $form->{defaultcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + # vendors + if (@{ $form->{all_vendor} }) { + $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|; + map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} }); + } + + + # forex + $form->{forex} = $form->{exchangerate}; + $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + foreach $key (keys %{ $form->{AP_links} }) { + + foreach $ref (@{ $form->{AP_links}{$key} }) { + if ($key eq "AP_tax") { + $form->{"selectAP_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n"; + next; + } + $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; + } + + # if there is a value we have an old entry + for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + + if ($key eq "AP_paid") { + $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + $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->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate}; + + $form->{paidaccounts}++; + } else { + + $akey = $key; + $akey =~ s/AP_//; + + 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}"}; + } 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->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + } + } + } + } + + $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; + $tax = $form->round_amount($taxamount, 2); + $diff += ($taxamount - $tax); + $form->{"amount_$i"} += $tax; + } + $form->{amount_1} += $form->round_amount($diff, 2); + } + + $form->{invtotal} = $totalamount + $totaltax; + $form->{rowcount}++ if $form->{id}; + + $form->{AP} = $form->{AP_1}; + + $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +} + + +sub form_header { + + $title = $form->{title}; + $form->{title} = $locale->text("$title Accounts Payables Transaction"); + + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + +# type=submit $locale->text('Add Accounts Payables Transaction') +# type=submit $locale->text('Edit Accounts Payables Transaction') + + # set option selected + foreach $item (qw(AP vendor currency)) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + } + + + # 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> + <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td> +|; + } else { + $exchangerate .= qq| + <th align=right>|.$locale->text('Exchangerate').qq|</th> + <td><input name=exchangerate size=10 value=$form->{exchangerate}></td> +|; + } + } + + $taxincluded = ""; + if ($form->{taxaccounts}) { + $taxincluded = qq| + <tr> + <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td> + <th align=left nowrap>|.$locale->text('Tax Included').qq|</th> + </tr> +|; + } + + + if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { + $rows = 2; + } + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + + + $form->header; + + $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>| : qq|<input name=vendor value="$form->{vendor}" size=35>|; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<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"> + +<table width=100%> + <tr class=listtop> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr valign=top> + <td> + <table width=100%> + <tr valign=top> + <td> + <table> + <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=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> + <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> + </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> + </tr> + <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('Invoice Date').qq|</th> + <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> + </table> + </td> + </tr> + </table> + </td> + </tr> + <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}"> + <input type=hidden name=rowcount value=$form->{rowcount}> + <tr> + <td> + <table width=100%> +|; + + $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"}/; + + # format amounts + $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); + + 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> + </tr> +|; + $amount = ""; + $project = ""; + } + + $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax'); + + foreach $item (split / /, $form->{taxaccounts}) { + + # format and reverse tax + $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><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="selectAP_tax_$item" value="$form->{"selectAP_tax_$item"}"> +|; + } + + $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); + + print qq| + <tr> + <th align=right nowrap>|.$locale->text('Total').qq|</th> + <td>$form->{invtotal}</td> + <td colspan=2></td> + <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> + <th align=right nowrap>|.$locale->text('Notes').qq|</th> + <td colspan=5>$notes</td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr class=listheading> + <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th> + </tr> +|; + + + if ($form->{currency} eq $form->{defaultcurrency}) { + @column_index = qw(datepaid source paid AP_paid); + } else { + @column_index = qw(datepaid source paid exchangerate AP_paid); + } + + $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; + $column_data{paid} = "<th>".$locale->text('Amount')."</th>"; + $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>"; + + print " + <tr> +"; + map { print "$column_data{$_}\n" } @column_index; + print " + </tr> +"; + + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); + for $i (1 .. $form->{paidaccounts}) { + print " + <tr> +"; + + $form->{"selectAP_paid_$i"} = $form->{selectAP_paid}; + $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/; + + # format amounts + $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + + $exchangerate = qq| |; + if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{"forex_$i"}) { + $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } else { + $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|; + } + } + + $exchangerate .= qq| +<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{"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>|; + + map { print qq|$column_data{"${_}_$i"}\n| } @column_index; + + print " + </tr> +"; + } + + print qq| + <input type=hidden name=paidaccounts value=$form->{paidaccounts}> + <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}"> + + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub form_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=password value=$form->{password}> + +<br> +|; + + $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->{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|"> +|; + } + + } 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> + +</body> +</html> +"; + +} + + +sub update { + my $display = shift; + + if ($display) { + goto TAXCALC; + } + + $form->{invtotal} = 0; + + $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}); + + @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id); + $count = 0; + for $i (1 .. $form->{rowcount}) { + $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); + if ($form->{"amount_$i"}) { + push @a, {}; + my $j = $#a; + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); + $form->{rowcount} = $count + 1; + + map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount}); + + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell'))); + + $form->{invdate} = $form->{transdate}; + &check_name(vendor); + + &check_project; + + +TAXCALC: + # recalculate taxes + if ($form->{taxincluded}) { + $taxrate = 0; + + map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts}; + + 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; + } + $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); + $form->{"selectAP_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|; + $totaltax += $form->{"tax_$item"}; + } + } + + $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + map { $form->{"${_}_$i"} = $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'))); + } + } + + &display_form; + +} + + +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("vendor", $locale->text('Vendor missing!')); + + + $closedto = $form->datetonum($form->{closedto}, \%myconfig); + $transdate = $form->datetonum($form->{transdate}, \%myconfig); + + $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}); + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + + $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 ($transdate == $datepaid); + $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); + } + + } + } + + + # if old vendor ne vendor redo form + ($vendor) = split /--/, $form->{vendor}; + if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") { + &update; + exit; + } + + $form->{id} = 0 if $form->{postasnew}; + + $form->redirect($locale->text('Transaction posted!')) if (AP->post_transaction(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post transaction!')); + +} + + +sub post_as_new { + + $form->{postasnew} = 1; + &post; + +} + + +sub delete { + + $form->{title} = $locale->text('Confirm!'); + + $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|; + } + + print qq| +<h2 class=confirm>$form->{title}</h2> + +<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4> + +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub yes { + + $form->redirect($locale->text('Transaction deleted!')) if (AP->delete_transaction(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete transaction!')); + +} + + +sub search { + + # setup vendor selection + $form->all_vc(\%myconfig, "vendor"); + + if (@{ $form->{all_vendor} }) { + map { $vendor .= "<option>$_->{name}--$_->{id}\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'); + + $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>|.$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> + <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> + </table> + </td> + </tr> + <tr> + <td> + <table> + <tr> + <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> + <tr> + <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('ID').qq|</td> + <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td> + <td nowrap>|.$locale->text('Invoice Number').qq|</td> + <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Order Number').qq|</td> + </tr> + <tr> + <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td> + <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_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> + </tr> + <tr> + <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> + <td nowrap>|.$locale->text('Due Date').qq|</td> + <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Amount Due').qq|</td> + </tr> + <tr> + <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> + </tr> + <tr> + <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<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 class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub ap_transactions { + + $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; + + + if ($form->{vendor}) { + $callback .= "&vendor=".$form->escape($form->{vendor}); + $href .= "&vendor=".$form->escape($form->{vendor}); + $option .= $locale->text('Vendor')." : $form->{vendor}"; + } + if ($form->{invnumber}) { + $callback .= "&invnumber=$form->{invnumber}"; + $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}"; + $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}"; + $href .= "¬es=".$form->escape($form->{notes}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Notes')." : $form->{notes}"; + } + + 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); + } + 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'); + } + + @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)); + + 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->{l_subtotal} eq 'Y') { + $callback .= "&l_subtotal=Y"; + $href .= "&l_subtotal=Y"; + } + + + $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{duedate} = qq|<th><a class=listheading href=$href&sort=duedate>|.$locale->text('Due Date').qq|</a></th>|; + $column_header{due} = qq|<th class=listheading>|.$locale->text('Amount Due').qq|</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{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Vendor').qq|</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{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{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Employee')."</th>"; + + + $form->{title} = $locale->text('AP Transactions'); + + $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 sort and escape callback + $form->{callback} = "$callback&sort=$form->{sort}"; + $callback = $form->escape($form->{callback}); + + if (@{ $form->{AP} }) { + $sameitem = $form->{AP}->[0]->{$form->{sort}}; + } + + # sums and tax on reports by Antonio Gallardo + # + foreach $ap (@{ $form->{AP} }) { + + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $ap->{$form->{sort}}) { + &ap_subtotal; + $sameitem = $ap->{$form->{sort}}; + } + } + + $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>"; + $column_data{datepaid} = "<td>$ap->{datepaid} </td>"; + + $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{id} = "<td>$ap->{id}</td>"; + $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>"; + $column_data{name} = "<td>$ap->{name}</td>"; + $ap->{notes} =~ s/\r\n/<br>/g; + $column_data{notes} = "<td>$ap->{notes} </td>"; + $column_data{employee} = "<td>$ap->{employee} </td>"; + + $i++; + $i %= 2; + print " + <tr class=listrow$i > +"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + } + + if ($form->{l_subtotal} eq 'Y') { + &ap_subtotal; + } + + # print totals + print qq| + <tr class=listtotal> +|; + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>"; + $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>"; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> + </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=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 class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub ap_subtotal { + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>"; + $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>"; + + $subtotalnetamount = 0; + $subtotalamount = 0; + $subtotalpaid = 0; + $subtotaldue = 0; + + print "<tr class=listsubtotal>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + +} + + + diff --git a/sql-ledger/bin/mozilla/ar.pl b/sql-ledger/bin/mozilla/ar.pl new file mode 100644 index 000000000..341c0380c --- /dev/null +++ b/sql-ledger/bin/mozilla/ar.pl @@ -0,0 +1,1135 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2001 +# +# 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. +#====================================================================== +# +# Accounts Receivables +# +#====================================================================== + + +use SL::AR; +use SL::IS; +use SL::PE; + +require "$form->{path}/arap.pl"; + +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 add { + + $form->{title} = "Add"; + $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + + &create_links; + &display_form; + +} + + +sub edit { + + $form->{title} = "Edit"; + + &create_links; + &display_form; + +} + + +sub display_form { + + &form_header; + &form_footer; + +} + + +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}"; + + # currencies + @curr = split /:/, $form->{currencies}; + chomp $curr[0]; + $form->{defaultcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + # customers + if (@{ $form->{all_customer} }) { + $form->{customer} = "$form->{customer}--$form->{customer_id}"; + map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); + } + + # 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"; + next; + } + $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; + } + + # if there is a value we have an old entry + for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + if ($key eq "AR_paid") { + $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + # reverse paid + $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->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate}; + + $form->{paidaccounts}++; + } else { + + $akey = $key; + $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}"}; + } 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->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + } + } + } + } + + $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; + $tax = $form->round_amount($taxamount, 2); + $diff += ($taxamount - $tax); + $form->{"amount_$i"} += $tax; + } + $form->{amount_1} += $form->round_amount($diff, 2); + } + + $form->{invtotal} = $totalamount + $totaltax; + $form->{rowcount}++ if $form->{id}; + + $form->{AR} = $form->{AR_1}; + + $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +} + + +sub form_header { + + $title = $form->{title}; + $form->{title} = $locale->text("$title Accounts Receivables Transaction"); + + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + +# $locale->text('Add Accounts Receivables Transaction') +# $locale->text('Edit Accounts Receivables Transaction') + + # set option selected + foreach $item (qw(AR customer currency)) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + } + + # 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> + <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td> +|; + } else { + $exchangerate .= qq| + <th align=right>|.$locale->text('Exchangerate').qq|</th> + <td><input name=exchangerate size=10 value=$form->{exchangerate}></td> +|; + } + } + + $taxincluded = ""; + if ($form->{taxaccounts}) { + $taxincluded = qq| + <tr> + <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td> + <th align=left nowrap>|.$locale->text('Tax Included').qq|</th> + </tr> +|; + } + + + if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { + $rows = 2; + } + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + + + $form->header; + + $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + + $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>| : qq|<input name=customer value="$form->{customer}" size=35>|; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=id value=$form->{id}> +<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"> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr valign=top> + <td> + <table width=100%> + <tr valign=top> + <td> + <table> + <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=oldcustomer value="$form->{oldcustomer}"> + <input type=hidden name=customer_id value="$form->{customer_id}"> + <input type=hidden name=terms value=$form->{terms}> + </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->{creditremaining}</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> + <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> + </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> + </tr> + <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('Invoice Date').qq|</th> + <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> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + +<input type=hidden name=selectAR_amount value="$form->{selectAR_amount}"> +<input type=hidden name=rowcount value=$form->{rowcount}> +|; + + $amount = $locale->text('Amount'); + $project = $locale->text('Project'); + + for $i (1 .. $form->{rowcount}) { + + $form->{"selectAR_amount"} =~ s/ selected//; + $form->{"selectAR_amount"} =~ s/option>\Q$form->{"AR_amount_$i"}\E/option selected>$form->{"AR_amount_$i"}/; + + # format amounts + $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); + + 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> + </tr> +|; + $amount = ""; + $project = ""; + } + + $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax'); + + foreach $item (split / /, $form->{taxaccounts}) { + + $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><select name="AR_tax_$item">$form->{"selectAR_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="selectAR_tax_$item" value="$form->{"selectAR_tax_$item"}"> +|; + + } + + $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); + + print qq| + <tr> + + <th align=right>|.$locale->text('Total').qq|</th> + <th align=left>$form->{invtotal}</th> + + <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> + <th align=right>|.$locale->text('Notes').qq|</th> + <td colspan=4>$notes</td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr> + <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th> + </tr> +|; + + + if ($form->{currency} eq $form->{defaultcurrency}) { + @column_index = qw(datepaid source paid AR_paid); + } else { + @column_index = qw(datepaid source paid exchangerate AR_paid); + } + + $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; + $column_data{paid} = "<th>".$locale->text('Amount')."</th>"; + $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>"; + + print " + <tr> +"; + map { print "$column_data{$_}\n" } @column_index; + print " + </tr> +"; + + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); + for $i (1 .. $form->{paidaccounts}) { + print " + <tr> +"; + + $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 + $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + + $exchangerate = qq| |; + if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{"forex_$i"}) { + $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } else { + $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|; + } + } + + $exchangerate .= qq| +<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>|; + + map { print qq|$column_data{"${_}_$i"}\n| } @column_index; + + print " + </tr> +"; + } + + print qq| +<input type=hidden name=paidaccounts value=$form->{paidaccounts}> +<input type=hidden name=selectAR_paid value="$form->{selectAR_paid}"> + + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub form_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=password value=$form->{password}> + +<br> +|; + + $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->{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|"> +|; + } + + } 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> + +</body> +</html> +"; + +} + + +sub update { + my $display = shift; + + if ($display) { + goto TAXCALC; + } + + $form->{invtotal} = 0; + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + + @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); + $count = 0; + @a = (); + for $i (1 .. $form->{rowcount}) { + $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); + if ($form->{"amount_$i"}) { + push @a, {}; + $j = $#a; + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); + $form->{rowcount} = $count + 1; + + map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount}); + + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy'))); + + + $form->{invdate} = $form->{transdate}; + &check_name(customer); + + &check_project; + + +TAXCALC: + # recalculate taxes + if ($form->{taxincluded}) { + $taxrate = 0; + + map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts}; + + 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; + } + $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); + $form->{"selectAR_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|; + $totaltax += $form->{"tax_$item"}; + } + } + + $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; + + 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"}, 'buy'))); + } + } + + $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!')); + $form->isblank("transdate", $locale->text('Invoice Date missing!')); + $form->isblank("duedate", $locale->text('Due Date missing!')); + $form->isblank("customer", $locale->text('Customer missing!')); + + $closedto = $form->datetonum($form->{closedto}, \%myconfig); + $transdate = $form->datetonum($form->{transdate}, \%myconfig); + + $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}); + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + + $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 ($transdate == $datepaid); + $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); + } + } + } + + # if oldcustomer ne customer redo form + ($customer) = split /--/, $form->{customer}; + if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { + &update; + exit; + } + + $form->{id} = 0 if $form->{postasnew}; + + $form->redirect($locale->text('Transaction posted!')) if (AR->post_transaction(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post transaction!')); + +} + + +sub post_as_new { + + $form->{postasnew} = 1; + &post; + +} + + +sub delete { + + $form->{title} = $locale->text('Confirm!'); + + $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|; + } + + print qq| +<h2 class=confirm>$form->{title}</h2> + +<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4> + +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub yes { + + $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete transaction!')); + +} + + +sub search { + + # setup customer selection + $form->all_vc(\%myconfig, "customer"); + + if (@{ $form->{all_customer} }) { + map { $customer .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_customer} }; + $customer = qq|<select name=customer><option>\n$customer</select>|; + } else { + $customer = qq|<input name=customer size=35>|; + } + + $form->{title} = $locale->text('AR Transactions'); + + $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>|.$locale->text('Customer').qq|</th> + <td colspan=3>$customer</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> + <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> + </table> + </td> + </tr> + <tr> + <td> + <table> + <tr> + <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> + <tr> + <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('ID').qq|</td> + <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td> + <td nowrap>|.$locale->text('Invoice Number').qq|</td> + <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Order Number').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> + </tr> + <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_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> + </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> + <td nowrap>|.$locale->text('Due Date').qq|</td> + <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Amount Due').qq|</td> + </tr> + <tr> + <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_shippingpoint" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Ship via').qq|</td> + </tr> + <tr> + <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td> + <td nowrap>|.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<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}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub ar_transactions { + + $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; + + if ($form->{customer}) { + $callback .= "&customer=".$form->escape($form->{customer}); + $href .= "&customer=".$form->escape($form->{customer}); + $option = $locale->text('Customer')." : $form->{customer}"; + } + if ($form->{invnumber}) { + $callback .= "&invnumber=$form->{invnumber}"; + $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}"; + $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}"; + $href .= "¬es=".$form->escape($form->{notes}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Notes')." : $form->{notes}"; + } + + 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); + } + 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'); + } + + @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint)); + + 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->{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{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>"; + $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>"; + $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Customer')."</a></th>"; + $column_header{netamount} = "<th class=listheading>" . $locale->text('Amount') . "</th>"; + $column_header{tax} = "<th class=listheading>" . $locale->text('Tax') . "</th>"; + $column_header{amount} = "<th class=listheading>" . $locale->text('Total') . "</th>"; + $column_header{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>"; + $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>"; + + + $form->{title} = $locale->text('AR Transactions'); + + $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 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); + + if (@{ $form->{AR} }) { + $sameitem = $form->{AR}->[0]->{$form->{sort}}; + } + + # sums and tax on reports by Antonio Gallardo + # + foreach $ar (@{ $form->{AR} }) { + + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $ar->{$form->{sort}}) { + &ar_subtotal; + } + } + + $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>"; + $column_data{datepaid} = "<td>$ar->{datepaid} </td>"; + $column_data{duedate} = "<td>$ar->{duedate} </td>"; + + $module = ($ar->{invoice}) ? "is.pl" : $form->{script}; + + $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{ordnumber} = "<td>$ar->{ordnumber} </td>"; + $column_data{name} = "<td>$ar->{name}</td>"; + $ar->{notes} =~ s/\r\n/<br>/g; + $column_data{notes} = "<td>$ar->{notes} </td>"; + $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>"; + $column_data{employee} = "<td>$ar->{employee} </td>"; + + $i++; $i %= 2; + print " + <tr class=listrow$i> +"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + + } + + if ($form->{l_subtotal} eq 'Y') { + &ar_subtotal; + } + + # print totals + print qq| + <tr class=listtotal> +|; + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>"; + $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>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> + </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=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('AR Transaction').qq|"> +<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub ar_subtotal { + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $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>"; + + $subtotalnetamount = 0; + $subtotalamount = 0; + $subtotalpaid = 0; + $subtotaldue = 0; + + $sameitem = $ar->{$form->{sort}}; + + print "<tr class=listsubtotal>"; + + map { print "\n$column_data{$_}" } @column_index; + +print " +</tr> +"; + +} + + + diff --git a/sql-ledger/bin/mozilla/arap.pl b/sql-ledger/bin/mozilla/arap.pl new file mode 100644 index 000000000..fecd9260f --- /dev/null +++ b/sql-ledger/bin/mozilla/arap.pl @@ -0,0 +1,406 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2002 +# +# 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. +#====================================================================== +# +# common routines for gl, ar, ap, is, ir, oe +# + +# any custom scripts for this one +if (-f "$form->{path}/custom_arap.pl") { + eval { require "$form->{path}/custom_arap.pl"; }; +} +if (-f "$form->{path}/$form->{login}_arap.pl") { + eval { require "$form->{path}/$form->{login}_arap.pl"; }; +} + + +1; +# end of main + + +sub check_name { + my ($name) = @_; + + my ($new_name, $new_id) = split /--/, $form->{$name}; + my $i = 0; + + # if we use a selection + if ($form->{"select$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->{"${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'); + + $i = 1; + } + } else { + + # check name, combine name and id + if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) { + # this is needed for is, ir and oe + map { delete $form->{"${_}_rate"} } (split / /, $form->{taxaccounts}); + + # for credit calculations + $form->{oldinvtotal} = 0; + $form->{oldtotalpaid} = 0; + + # return one name or a list of names in $form->{name_list} + if (($i = $form->get_name(\%myconfig, $name)) > 1) { + &select_name($name); + exit; + } + + if ($i == 1) { + # we got one name + $form->{"${name}_id"} = $form->{name_list}[0]->{id}; + $form->{$name} = $form->{name_list}[0]->{name}; + $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|; + + IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer'); + IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor'); + + } else { + # name is not on file + $msg = ucfirst $name . " not on file!"; + $form->error($locale->text($msg)); + } + } + } + + $i; + +} + +# $locale->text('Customer not on file!') +# $locale->text('Vendor not on file!') + + + +sub select_name { + my ($table) = @_; + + @column_index = qw(ndx name address); + + $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>|; + + # 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}> + +<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} =~ s/"/"/g; + + $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>|; + + $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 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|; + } + + 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->{"new_name_$i"}; + $form->{"$form->{vc}_id"} = $form->{"new_id_$i"}; + $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; + + # delete all the new_ variables + for $i (1 .. $form->{lastndx}) { + map { delete $form->{"new_${_}_$i"} } (id, name); + } + + map { delete $form->{$_} } qw(ndx lastndx nextsub); + + IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer'); + IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor'); + + &update(1); + +} + + +sub add_transaction { + my ($module) = @_; + + delete $form->{script}; + $form->{action} = "add"; + $form->{type} = "invoice" if $module =~ /(is|ir)/; + + $form->{callback} = $form->escape($form->{callback},1); + map { $argv .= "$_=$form->{$_}&" } keys %$form; + + exec ("perl", "$module.pl", $argv); + +} + + + +sub check_project { + + for $i (1 .. $form->{rowcount}) { + $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"}; + if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) { + if ($form->{"projectnumber_$i"}) { + # get new project + $form->{projectnumber} = $form->{"projectnumber_$i"}; + if (($rows = PE->projects(\%myconfig, $form)) > 1) { + # check form->{project_list} how many there are + $form->{rownumber} = $i; + &select_project; + exit; + } + + if ($rows == 1) { + $form->{"project_id_$i"} = $form->{project_list}->[0]->{id}; + $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber}; + $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber}; + } else { + # not on file + $form->error($locale->text('Project not on file!')); + } + } + } + } + +} + + +sub select_project { + + @column_index = qw(ndx projectnumber description); + + $column_data{ndx} = qq|<th> </th>|; + $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|; + $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|; + + # list items with radio button on a form + $form->header; + + $title = $locale->text('Select from one of the projects below'); + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=rownumber value=$form->{rownumber}> + +<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->{project_list} }) { + $checked = ($i++) ? "" : "checked"; + + $ref->{name} =~ s/"/"/g; + + $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>|; + $column_data{description} = qq|<td>$ref->{description}</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 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|; + } + + print qq| +<input type=hidden name=nextsub value=project_selected> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub project_selected { + + # replace the variable with the one checked + + # index for new item + $i = $form->{ndx}; + + $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"}; + $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"}; + $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"}; + + # delete all the new_ variables + for $i (1 .. $form->{lastndx}) { + map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description); + } + + map { delete $form->{$_} } qw(ndx lastndx nextsub); + + &update; + +} + + +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) }; + diff --git a/sql-ledger/bin/mozilla/ca.pl b/sql-ledger/bin/mozilla/ca.pl new file mode 100644 index 000000000..ed3100573 --- /dev/null +++ b/sql-ledger/bin/mozilla/ca.pl @@ -0,0 +1,413 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (C) 2001 +# +# 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. +#====================================================================== +# +# module for Chart of Accounts, Income Statement and Balance Sheet +# search and edit transactions posted by the GL, AR and AP +# +#====================================================================== + + +use SL::CA; + +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 chart_of_accounts { + + CA->all_accounts(\%myconfig, \%$form); + + @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|; + + + $form->{title} = $locale->text('Chart of Accounts'); + + $colspan = $#column_index + 1; + + $form->header; + + print qq| +<body> + +<table width=100%> + <tr><th class=listtop colspan=$colspan>$form->{title}</font></th></tr> + <tr height="5"></tr> + <tr class=listheading>|; + + map { print $column_header{$_} } @column_index; + + print qq| + </tr> +|; + + + foreach $ca (@{ $form->{CA} }) { + + $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|; + + 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>"; + } else { + $i++; $i %= 2; + print qq|<tr class=listrow$i>|; + $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>"; + $column_data{gifi_accno} = "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a> </td>"; + $column_data{description} = "<td>$ca->{description}</td>"; + } + + $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>\n"; + $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>\n"; + + $totaldebit += $ca->{debit}; + $totalcredit += $ca->{credit}; + + map { print $column_data{$_} } @column_index; + + print qq| +</tr> +|; + } + + 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>"; + + print "<tr class=listtotal>"; + + map { print $column_data{$_} } @column_index; + + print qq| +</tr> +<tr> + <td colspan=$colspan><hr size=3 noshade></td> +</tr> +</table> + +</body> +</html> +|; + +} + + +sub list { + + $form->{title} = $locale->text('List Transactions'); + if ($form->{accounttype} eq 'gifi') { + $form->{title} .= " - ".$locale->text('GIFI')." $form->{gifi_accno}"; + } else { + $form->{title} .= " - ".$locale->text('Account')." $form->{accno}"; + } + + $form->header; + + map { $form->{$_} =~ s/"/"/g; } qw(description gifi_description); + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=accno value=$form->{accno}> +<input type=hidden name=description value="$form->{description}"> +<input type=hidden name=sort value=transdate> + +<input type=hidden name=accounttype value=$form->{accounttype}> +<input type=hidden name=gifi_accno value=$form->{gifi_accno}> +<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 height="5"></tr + <tr valign=top> + <td> + <table> + <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> + <td><input name=todate size=11 title="$myconfig{dateformat}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Include in Report').qq|</th> + <td colspan=3> + <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </td> + </tr> + <tr><td><hr size=3 noshade></td></tr> +</table> + +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=path value=$form->{path}> +<input type=hidden name=password value=$form->{password}> + +<br><input class=submit type=submit name=action value="|.$locale->text('List Transactions').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub list_transactions { + + CA->all_transactions(\%myconfig, \%$form); + + $description = $form->escape($form->{description}); + $gifi_description = $form->escape($form->{gifi_description}); + + # 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}"; + + # 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}"; + + # 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{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->{accounttype} eq 'gifi') { + map { $form->{$_} = $form->{"gifi_$_"} } qw(accno description); + } + if ($form->{accno}) { + push @column_index, "balance"; + } + + $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account'); + + $form->{title} .= " $form->{accno} - $form->{description}"; + + + if ($form->{fromdate} || $form->{todate}) { + if ($form->{fromdate}) { + $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); + } + if ($form->{todate}) { + $todate = $locale->date(\%myconfig, $form->{todate}, 1); + } + + $form->{period} = "$fromdate - $todate"; + } else { + $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig),1); + } + + + $form->header; + + print qq| +<body> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</font></th> + </tr> + <tr height="5"></tr> + <tr> + <td>$form->{period}</td> + </tr> + <tr> + <td> + <table width=100%> + <tr class=listheading> +|; + +map { print "$column_header{$_}\n" } @column_index; + +print qq| + </tr> +|; + + # add sort to callback + $callback = $form->escape($callback . "&sort=$form->{sort}"); + + if (@{ $form->{CA} }) { + $sameitem = $form->{CA}->[0]->{$form->{sort}}; + } + + $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1; + if ($form->{accno} && $form->{balance}) { + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>"; + + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + map { print $column_data{$_} } @column_index; + print qq| + </tr> +|; + } + + foreach $ca (@{ $form->{CA} }) { + + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $ca->{$form->{sort}}) { + &ca_subtotal; + } + } + + # 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>"; + + + $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, " ")."</td>"; + $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, " ")."</td>"; + + $form->{balance} += $ca->{amount}; + $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>"; + + $subtotaldebit += $ca->{debit}; + $subtotalcredit += $ca->{credit}; + + $totaldebit += $ca->{debit}; + $totalcredit += $ca->{credit}; + + $column_data{transdate} = qq|<td>$ca->{transdate}</td>|; + $column_data{reference} = qq|<td>$href</td>|; + $column_data{description} = qq|<td>$ca->{description}</td>|; + + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + + map { print $column_data{$_} } @column_index; + + print qq| + </tr> +|; + + } + + + if ($form->{l_subtotal} eq 'Y') { + &ca_subtotal; + } + + + 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>"; + + print qq| + <tr class=listtotal> +|; + + map { print $column_data{$_} } @column_index; + + print qq| + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +</body> +</html> +|; + +} + + +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>"; + + $subtotaldebit = 0; + $subtotalcredit = 0; + + $sameitem = $ca->{$form->{sort}}; + + print qq| + <tr class=listsubtotal> +|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + +} + diff --git a/sql-ledger/bin/mozilla/cp.pl b/sql-ledger/bin/mozilla/cp.pl new file mode 100644 index 000000000..911b70105 --- /dev/null +++ b/sql-ledger/bin/mozilla/cp.pl @@ -0,0 +1,528 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2002 +# +# 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. +#====================================================================== +# +# Payment module +# +#====================================================================== + + +use SL::CP; +use SL::IS; +use SL::IR; + +require "$form->{path}/arap.pl"; + +1; +# end of main + + +sub payment { + + # setup customer/vendor selection for open invoices + CP->get_openvc(\%myconfig, \%$form); + + if ($form->{"all_$form->{vc}"}) { + map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; + } + + $form->{arap} = ($form->{vc} eq 'customer') ? "AR" : "AP"; + + CP->paymentaccounts(\%myconfig, \%$form); + + map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR} }; + + # currencies + @curr = split /:/, $form->{currencies}; + chomp $curr[0]; + $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + $form->{media} = "screen"; + + &form_header; + &list_invoices; + &form_footer; + +} + + + +sub form_header { + + $vclabel = ucfirst $form->{vc}; + $vclabel = $locale->text($vclabel); + + if ($form->{vc} eq 'customer') { + $form->{title} = $locale->text('Receipt'); + $rclabel = $locale->text('Reference'); + $form->{type} = 'receipt'; + } else { + $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); + } + + 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> + <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> + <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td> + </tr> +|; + } + } + + foreach $item ($form->{vc}, account, currency) { + $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}}">|; + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<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%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table width=100%> + <tr valign=top> + <td> + <table> + <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="$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> + <table> + <tr> + <td>$form->{addr1}</td> + </tr> + <tr> + <td>$form->{addr2}</td> + </tr> + <tr> + <td>$form->{addr3}</td> + </tr> + <tr> + <td>$form->{addr4}</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}"> + </tr> + </table> + </td> + <td align=right> + <table> + <tr> + <th align=right nowrap>|.$locale->text('Account').qq|</th> + <td colspan=3><select name=account>$form->{selectaccount}</select> + <input type=hidden name=selectaccount value="$form->{selectaccount}"> + </td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Date').qq|</th> + <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td> + </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=oldcurrency value=$form->{oldcurrency}> + </tr> + $exchangerate + <tr> + <th align=right nowrap>$rclabel</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> + </table> + </td> + </tr> +|; + +} + + +sub list_invoices { + + @column_index = qw(invnumber transdate amount due paid selectpaid); + + $colspan = $#column_index + 1; + + print qq| + <input type=hidden name=column_index value="id @column_index"> + <tr> + <td> + <table width=100%> + <tr> + <th class=listheading colspan=$colspan>|.$locale->text('Invoices').qq|</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>"; + + print qq| + <tr> +|; + map { print "$column_data{$_}\n" } @column_index; + print qq| + </tr> +|; + + 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"}; + $totaldue += $form->{"due_$i"}; + $totalpaid += $form->{"paid_$i"}; + + map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid); + + $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td> + <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}"> + <input type=hidden name="id_$i" value=$form->{"id_$i"}>|; + $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td> + <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|; + $column_data{amount} = qq|<td align=right width=15%>$form->{"amount_$i"}</td> + <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|; + $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>|; + + $j++; $j %= 2; + print qq| + <tr class=listrow$j> +|; + map { print "$column_data{$_}\n" } @column_index; + print qq| + </tr> +|; + } + + 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>|; + + print qq| + <tr class=listtotal> +|; + map { print "$column_data{$_}\n" } @column_index; + print qq| + </tr> + </table> + </td> + </tr> +|; + +} + + +sub form_footer { + + $form->{OP}{$form->{media}} = "checked"; + + print qq| + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +<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}> + +<br> +<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 ($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'); + } + } + + print qq| + +</form> + +</body> +</html> +|; + +} + + +sub update { + my ($new_name_selected) = @_; + + # get customer and invoices + $updated = &check_name($form->{vc}); + + $updated = 1 if (($form->{oldtransdatefrom} ne $form->{transdatefrom}) || ($form->{oldtransdateto} ne $form->{transdateto})); + $form->{oldtransdatefrom} = $form->{transdatefrom}; + $form->{oldtransdateto} = $form->{transdateto}; + + if ($new_name_selected || $updated) { + CP->get_openinvoices(\%myconfig, \%$form); + $updated = 1; + } + + if ($form->{currency} ne $form->{oldcurrency}) { + $form->{oldcurrency} = $form->{currency}; + if (!$updated) { + CP->get_openinvoices(\%myconfig, \%$form); + $updated = 1; + } + } + + # 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; + + $i = 0; + foreach $ref (@{ $form->{PR} }) { + $i++; + $form->{"id_$i"} = $ref->{id}; + $form->{"invnumber_$i"} = $ref->{invnumber}; + $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; + + map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid); + + } + $form->{rowcount} = $i; + } + + # recalculate + $amount = $form->{amount}; + for $i (1 .. $form->{rowcount}) { + + 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 { + $form->{"paid_$i"} = $form->{"due_$i"}; + } + } + + map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid); + + } + + &form_header; + &list_invoices; + &form_footer; + +} + + +sub post { + + &check_form; + + $form->redirect($locale->text('Payment posted!')) if (CP->process_payment(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post payment!')); + +} + + +sub print { + + &check_form; + + ($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}; + $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->{company} = $myconfig{company}; + $form->{address} = $myconfig{address}; + + @a = qw(name invnumber company address text_amount addr1 addr2 addr3 addr4); + $form->format_string(@a); + + $form->parse_template(\%myconfig, $userspath); + + $form->{callback} = ""; + + $label = uc $form->{type}; + +# $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!")); + +} + + +sub customer_details { IS->customer_details(\%myconfig, \%$form) }; +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}; + + if ($form->{currency} ne $form->{oldcurrency}) { + &update; + exit; + } + + $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}); + for $i (1 .. $form->{rowcount}) { + $totalpaid += $form->parse_amount(\%myconfig, $form->{"paid_$i"}); + if ($form->{"paid_$i"}) { + push(@{ $form->{paid} }, $form->{"paid_$i"}); + push(@{ $form->{due} }, $form->{"due_$i"}); + push(@{ $form->{invnumber} }, $form->{"invnumber_$i"}); + push(@{ $form->{invdate} }, $form->{"transdate_$i"}); + } + } + + $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); + +} + + diff --git a/sql-ledger/bin/mozilla/ct.pl b/sql-ledger/bin/mozilla/ct.pl new file mode 100644 index 000000000..3dbb5656a --- /dev/null +++ b/sql-ledger/bin/mozilla/ct.pl @@ -0,0 +1,631 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# Author: Dieter Simader +# Email: dsimader@sql-ledger.org +# Web: http://www.sql-ledger.org +# +# Contributors: Reed White <alta@alta-research.com> +# +# 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. +#====================================================================== +# +# customer/vendor module +# +#====================================================================== + +# $locale->text('Customers') +# $locale->text('Vendors') + +use SL::CT; + +1; +# end of main + + + +sub add { + + $form->{title} = "Add"; + + $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + + CT->taxaccounts(\%myconfig, \%$form); + + &form_header; + &form_footer; + +} + + +sub search { + + $label = ucfirst $form->{db}; + $form->{title} = $locale->text($label."s"); + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=db value=$form->{db}> + +<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('Number').qq|</th> + <td><input name=$form->{db}number size=35></td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Name').qq|</th> + <td><input name=name size=35></td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Contact').qq|</th> + <td><input name=contact size=35></td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('E-mail').qq|</th> + <td><input name=email size=35></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> + </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> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=nextsub value=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}> + +<br> +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; +} + + +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; + + @columns = $form->sort_columns(name, "$form->{db}number", address, contact, phone, fax, email, cc); + + 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->{status} eq 'all') { + $option = $locale->text('All'); + } + if ($form->{status} eq 'orphaned') { + $option .= $locale->text('Orphaned'); + } + if ($form->{name}) { + $callback .= "&name=$form->{name}"; + $href .= "&name=".$form->escape($form->{name}); + $option .= "\n<br>".$locale->text('Name')." : $form->{name}"; + } + if ($form->{contact}) { + $callback .= "&contact=$form->{contact}"; + $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->{"$form->{db}number"}|; + $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}"; + $href .= "&email=".$form->escape($form->{email}); + $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}"; + } + + $form->{callback} = "$callback&sort=$form->{sort}"; + $callback = $form->escape($form->{callback}); + + $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{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>|; + + $label = ucfirst $form->{db}."s"; + $form->{title} = $locale->text($label); + + $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->{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>"; + + $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>"; + + $i++; $i %= 2; + print " + <tr class=listrow$i> +"; + + 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 name=db type=hidden value=$form->{db}> + +<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('Add').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub edit { + +# $locale->text('Edit Customer') +# $locale->text('Edit Vendor') + + CT->get_tuple(\%myconfig, \%$form); + + # format " into " + map { $form->{$_} =~ s/"/"/g } keys %$form; + + $form->{title} = "Edit"; + + # format discount + $form->{discount} *= 100; + + &form_header; + &form_footer; + +} + + +sub form_header { + + foreach $item (split / /, $form->{taxaccounts}) { + if (($form->{tax}{$item}{taxable}) || !($form->{id})) { + $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> + <th align=right>|.$locale->text('Taxable').qq|</th> + <td>$taxable</td> + </tr> + </table> + </td> + </tr> +|; + + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0); + + 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> +|; + } + + + $label = ucfirst $form->{db}; + $form->{title} = $locale->text("$form->{title} $label"); + + 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> +|; + } + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </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> + <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> + </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> + </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> + </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> + </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> + </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> + </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> +</table> +|; + +} + + + +sub form_footer { + + $label = ucfirst $form->{db}; + + 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=callback value="$form->{callback}"> +<input type=hidden name=db value=$form->{db}> + +<br> + +<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|; + } + + print qq| + + </form> + +</body> +</html> +|; + +} + + +sub invoice { &{ "$form->{db}_invoice" } }; + +sub customer_invoice { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_customer(\%myconfig, \%$form); + + delete $form->{script}; + + $form->{action} = "add"; + $form->{callback} = $form->escape($form->{callback},1); + + $form->{customer} = $form->{name}; + $form->{customer_id} = $form->{id}; + $form->{vc} = 'customer'; + + delete $form->{id}; + + map { $argv .= "$_=$form->{$_}&" } keys %$form; + + exec ("perl", "is.pl", $argv); + +} + + +sub vendor_invoice { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_vendor(\%myconfig, \%$form); + + delete $form->{script}; + + $form->{action} = "add"; + $form->{callback} = $form->escape($form->{callback},1); + + $form->{vendor} = $form->{name}; + $form->{vendor_id} = $form->{id}; + $form->{vc} = 'vendor'; + + delete $form->{id}; + + map { $argv .= "$_=$form->{$_}&" } keys %$form; + + exec ("perl", "ir.pl", $argv); + +} + + +sub order { &{ "$form->{db}_order" } }; + +sub customer_order { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_customer(\%myconfig, \%$form); + + delete $form->{script}; + + $form->{action} = "add"; + $form->{callback} = $form->escape($form->{callback},1); + + $form->{customer} = $form->{name}; + $form->{customer_id} = $form->{id}; + $form->{vc} = 'customer'; + + $form->{type} = 'sales_order'; + + delete $form->{id}; + + map { $argv .= "$_=$form->{$_}&" } keys %$form; + + exec ("perl", "oe.pl", $argv); + +} + + +sub vendor_order { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_vendor(\%myconfig, \%$form); + + delete $form->{script}; + + $form->{action} = "add"; + $form->{callback} = $form->escape($form->{callback},1); + + $form->{vendor} = $form->{name}; + $form->{vendor_id} = $form->{id}; + $form->{vc} = 'vendor'; + + $form->{type} = 'purchase_order'; + + delete $form->{id}; + + map { $argv .= "$_=$form->{$_}&" } keys %$form; + + exec ("perl", "oe.pl", $argv); + +} + + +sub save { &{ "save_$form->{db}" } }; + +sub save_customer { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_customer(\%myconfig, \%$form); + $form->redirect($locale->text('Customer saved!')); + +} + + +sub save_vendor { + + $form->isblank("name", $locale->text("Name missing!")); + CT->save_vendor(\%myconfig, \%$form); + $form->redirect($locale->text('Vendor saved!')); + +} + + +sub delete { &{ "delete_$form->{db}" } }; + +sub delete_customer { + + $rc = CT->delete_customer(\%myconfig, \%$form); + + $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 delete_vendor { + + $rc = CT->delete_vendor(\%myconfig, \%$form); + + $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!')); + +} + + +sub continue { &{ $form->{nextsub} } }; + + diff --git a/sql-ledger/bin/mozilla/gl.pl b/sql-ledger/bin/mozilla/gl.pl new file mode 100644 index 000000000..0d2dd4628 --- /dev/null +++ b/sql-ledger/bin/mozilla/gl.pl @@ -0,0 +1,806 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# Genereal Ledger +# +#====================================================================== + + +use SL::GL; +use SL::PE; + +require "$form->{path}/arap.pl"; + +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 add { + + $form->{title} = "Add"; + + $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" 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; + + $form->{rowcount} = 4; + &display_form; + +} + + +sub edit { + + GL->transaction(\%myconfig, \%$form); + + map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} }; + $form->{chart} = $chart; + + $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + + $form->{title} = "Edit"; + + &form_header; + + $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}; + + if ($ref->{amount} < 0) { + $form->{totaldebit} -= $ref->{amount}; + $form->{"debit_$i"} = $form->format_amount(\%myconfig, $ref->{amount} * -1, 2); + } else { + $form->{totalcredit} += $ref->{amount}; + $form->{"credit_$i"} = ($ref->{amount} > 0) ? $form->format_amount(\%myconfig, $ref->{amount}, 2) : ""; + } + + &form_row($i++); + } + + &form_row($i); + + &form_footer; + +} + + + +sub search { + + $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports'); + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=sort value=transdate> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Reference').qq|</th> + <td><input name=reference size=20></td> + <th align=right>|.$locale->text('Source').qq|</th> + <td><input name=source size=20></td> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td colspan=3><input name=description size=40></td> + </tr> + <tr> + <th align=right>|.$locale->text('Notes').qq|</th> + <td colspan=3><input name=notes size=40></td> + </tr> + <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> + <td><input name=dateto size=11 title="$myconfig{dateformat}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Include in Report').qq|</th> + <td colspan=3> + <table> + <tr> + <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=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| + <input name="category" class=radio type=radio value=E> |.$locale->text('Expense').qq| + </td> + </tr> + <tr> + <table> + <tr> + <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td> + <td>|.$locale->text('ID').qq|</td> + <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Date').qq|</td> + <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Reference').qq|</td> + <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Description').qq|</td> + <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td> + <td>|.$locale->text('Notes').qq|</td> + </tr> + <tr> + <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Debit').qq|</td> + <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Credit').qq|</td> + <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Source').qq|</td> + <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td> + <td>|.$locale->text('Account').qq|</td> + <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td> + <td>|.$locale->text('GIFI').qq|</td> + </tr> + <tr> + <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td> + <td>|.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </tr> + </table> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=nextsub value=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}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; +} + + +sub generate_report { + + GL->all_transactions(\%myconfig, \%$form); + + $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + + %acctype = ( 'A' => $locale->text('Asset'), + 'L' => $locale->text('Liability'), + 'Q' => $locale->text('Equity'), + 'I' => $locale->text('Income'), + 'E' => $locale->text('Expense'), + ); + + $form->{title} = $locale->text('General Ledger'); + + $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1; + + unless ($form->{category} eq 'X') { + $form->{title} .= " : ".$locale->text($acctype{$form->{category}}); + } + if ($form->{accno}) { + $callback .= "&accno=$form->{accno}"; + $option = $locale->text('Account')." : $form->{accno} $form->{account_description}"; + } + if ($form->{gifi_accno}) { + $callback .= "&gifi_accno=$form->{gifi_accno}"; + $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}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Source')." : $form->{source}"; + } + if ($form->{reference}) { + $callback .= "&reference=".$form->escape($form->{reference}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Reference')." : $form->{reference}"; + } + if ($form->{description}) { + $callback .= "&description=".$form->escape($form->{description}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Description')." : $form->{description}"; + } + if ($form->{notes}) { + $callback .= "¬es=".$form->escape($form->{notes}); + $option .= "\n<br>" if $option; + $option .= $locale->text('Notes')." : $form->{notes}"; + } + + if ($form->{datefrom}) { + $callback .= "&datefrom=$form->{datefrom}"; + $option .= "\n<br>" if $option; + $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1); + } + if ($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); + } + + + @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno)); + + 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") { + push @column_index, $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"; + } + + $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{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>"; + + $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 " + </tr> +"; + + # add sort to callback + $form->{callback} = "$callback&sort=$form->{sort}"; + $callback = $form->escape($form->{callback}); + + # initial item for subtotals + if (@{ $form->{GL} }) { + $sameitem = $form->{GL}->[0]->{$form->{sort}}; + } + + if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) { + + map { $column_data{$_} = "<td> </td>" } @column_index; + $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>"; + + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + } + + foreach $ref (@{ $form->{GL} }) { + + # if item ne sort print subtotal + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $ref->{$form->{sort}}) { + &gl_subtotal; + } + } + + $form->{balance} += $ref->{amount}; + + $subtotaldebit += $ref->{debit}; + $subtotalcredit += $ref->{credit}; + + $totaldebit += $ref->{debit}; + $totalcredit += $ref->{credit}; + + $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " "); + $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " "); + + $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{description} = "<td>$ref->{description} </td>"; + $column_data{source} = "<td>$ref->{source} </td>"; + $column_data{notes} = "<td>$ref->{notes} </td>"; + $column_data{debit} = "<td align=right>$ref->{debit}</td>"; + $column_data{credit} = "<td align=right>$ref->{credit}</td>"; + $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>"; + + $i++; $i %= 2; + print " + <tr class=listrow$i>"; + map { print "$column_data{$_}\n" } @column_index; + print "</tr>"; + + } + + + &gl_subtotal if ($form->{l_subtotal} eq 'Y'); + + + 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>"; + + print qq| + <tr class=listtotal> +|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> + </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=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('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|"> + +</form> + +</body> +</html> +|; + +} + + +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>"; + + + print "<tr class=listsubtotal>"; + map { print "$column_data{$_}\n" } @column_index; + print "</tr>"; + + $subtotaldebit = 0; + $subtotalcredit = 0; + + $sameitem = $ref->{$form->{sort}}; + +} + + +sub update { + + @a = (); + $count = 0; + @flds = (qw(accno debit credit projectnumber project_id)); + + for $i (1 .. $form->{rowcount}) { + unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) { + # take accno apart + ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"}); + + push @a, {}; + $j = $#a; + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + for $i (1 .. $count) { + $j = $i - 1; + map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds; + } + + for $i ($count + 1 .. $form->{rowcount}) { + map { delete $form->{"${_}_$i"} } @flds; + } + + $form->{rowcount} = $count; + + &check_project; + + &display_form; + +} + + +sub display_form { + + &form_header; + + $form->{rowcount}++; + $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; + +} + + +sub form_row { + my $i = shift; + + my $chart = $form->{chart}; + $chart =~ s/<option>$form->{"accno_$i"}/<option selected>$form->{"accno_$i"}/; + + print qq|<tr> + <td><select name="accno_$i">$chart</select></td> + <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> +</tr> +<input type=hidden name=rowcount value=$i> + +|; + +} + + +sub form_header { + + $title = $form->{title}; + $form->{title} = $locale->text("$title General Ledger Transaction"); + +# $locale->text('Add General Ledger Transaction') +# $locale->text('Edit General Ledger Transaction') + + map { $form->{$_} =~ s/"/"/g } qw(reference description chart); + + if (($rows = $form->numtextrows($form->{description}, 50)) > 1) { + $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|; + } else { + $description = qq|<input name=description size=50 value="$form->{description}">|; + } + + if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) { + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + } else { + $notes = qq|<input name=notes size=50 value="$form->{notes}">|; + } + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input name=id type=hidden value=$form->{id}> + +<input name=chart type=hidden value="$form->{chart}"> +<input type=hidden name=closedto value=$form->{closedto}> +<input type=hidden name=locked value=$form->{locked}> +<input type=hidden name=title value="$title"> + +<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('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> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td colspan=2>$description</td> + </tr> + <tr> + <th align=right>|.$locale->text('Notes').qq|</th> + <td colspan=2>$notes</td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr class=listheading> + <th class=listheading>|.$locale->text('Account').qq|</th> + <th class=listheading>|.$locale->text('Debit').qq|</th> + <th class=listheading>|.$locale->text('Credit').qq|</th> + <th class=listheading>|.$locale->text('Project').qq|</th> + </tr> +|; + +} + + +sub form_footer { + + ($dec) = ($form->{totaldebit} =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, " ") } qw(totaldebit totalcredit); + + print qq| + <tr class=listtotal> + <th> </th> + <th class=listtotal align=right>$form->{totaldebit}</th> + <th class=listtotal align=right>$form->{totalcredit}</th> + <th> </th> + </tr> + </table> + </td> + </tr> + <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=password value=$form->{password}> + +<input name=callback type=hidden value="$form->{callback}"> + +<br> +|; + + $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->{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|"> +|; + } + + } 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> + +</body> +</html> +"; + +} + + +sub delete { + + $form->header; + + print qq| +<body> + +<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|; + } + + print qq| +<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2> + +<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4> + +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> +|; + +} + + +sub yes { + + $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete transaction!')); + +} + + +sub post { + + # check if there is something in reference and date + $form->isblank("reference", $locale->text('Reference missing!')); + $form->isblank("transdate", $locale->text('Transaction Date missing!')); + + $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!'); + + $form->error($err[$errno]); + } + + $form->redirect($locale->text('Transaction posted!')); + +} + + +sub post_as_new { + + $form->{id} = 0; + &post; + +} + + diff --git a/sql-ledger/bin/mozilla/ic.pl b/sql-ledger/bin/mozilla/ic.pl new file mode 100644 index 000000000..797daee01 --- /dev/null +++ b/sql-ledger/bin/mozilla/ic.pl @@ -0,0 +1,1638 @@ +#===================================================================== +# SQL-Ledger, Accounting +# Copyright (c) 2001 +# +# 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. +#====================================================================== +# +# Inventory Control module +# +#====================================================================== + + +use SL::IC; + +require "$form->{path}/io.pl"; + +1; +# end of main + + + +sub add { + + $form->{title} = $locale->text('Add ' . ucfirst $form->{item}); + + $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + + $form->{unit} = ($form->{item} eq 'service') ? $locale->text('hr') : $locale->text('ea'); + + &link_part; + + &display_form; + +} + + +sub search { + + $form->{title} = (ucfirst $form->{searchitems})."s"; + $form->{title} = $locale->text($form->{title}); + +# $locale->text('Parts') +# $locale->text('Services') + + unless ($form->{searchitems} eq 'service') { + + $onhand = qq| + <input name=itemstatus class=radio type=radio value=onhand> |.$locale->text('On Hand').qq| + <input name=itemstatus class=radio type=radio value=short> |.$locale->text('Short').qq| +|; + + $makemodel = qq| + <tr> + <th width="1%" 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> + <td><input name=model size=20></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=bom class=checkbox type=checkbox value=1> |.$locale->text('Individual Items').qq| + </td> + </tr> +|; + + $bought = qq| + <tr> + <td></td> + <td colspan=3> + <table> + <tr> + <td> + <table> + <tr> + <td><input name=sold class=checkbox type=checkbox value=1></td> + <td nowrap>|.$locale->text('Sold').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> + </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> + </tr> + </table> + </td> + </tr> +|; + + } else { + + $bought = qq| + <tr> + <td></td> + <td colspan=3> + <table> + <tr> + <td> + <table> + <tr> + <td><input name=bought class=checkbox type=checkbox value=1></td> + <td nowrap>|.$locale->text('Bought').qq|</td> + <td><input name=sold class=checkbox type=checkbox value=1></td> + <td nowrap>|.$locale->text('Sold').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><input name=ordered class=checkbox type=checkbox value=1></td> + <td nowrap>|.$locale->text('Ordered').qq|</td> + </tr> + </table> + </td> + <td width=5%> </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> + + <td><input name=closed class=checkbox type=checkbox value=1> |.$locale->text('Closed').qq|</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> +|; + } + + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=searchitems value=$form->{searchitems}> +<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> + <tr> + <th width=1% 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> + </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> + $toplevel + <tr> + <td></td> + <td colspan=3> + <input name=itemstatus class=radio type=radio value=active checked> |.$locale->text('Active').qq| + $onhand + <input name=itemstatus class=radio type=radio value=obsolete> |.$locale->text('Obsolete').qq| + <input name=itemstatus class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq| + </td> + </tr> + $bought + <tr> + <td></td> + <td colspan=3> + <hr size=1 noshade> + </td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Include in Report').qq|</th> + <td colspan=3> + <table> + <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> + <td><input name=l_unit class=checkbox type=checkbox value=Y checked> |.$locale->text('Unit of measure').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> + </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> + </tr> + <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> + </tr> + <tr> + <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr><td colspan=4><hr size=3 noshade></td></tr> +</table> + +<input type=hidden name=nextsub value=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}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub generate_report { + + # setup $form->{sort} + unless ($form->{sort}) { + if ($form->{description} && !($form->{partnumber})) { + $form->{sort} = "description"; + } else { + $form->{sort} = "partnumber"; + } + } + + $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); + + IC->all_parts(\%myconfig, \%$form); + + + if ($form->{itemstatus} eq 'active') { + $option .= $locale->text('Active')." : "; + } + if ($form->{itemstatus} eq 'obsolete') { + $option .= $locale->text('Obsolete')." : "; + } + if ($form->{itemstatus} eq 'orphaned') { + $option .= $locale->text('Orphaned')." : "; + } + if ($form->{itemstatus} eq 'onhand') { + $option .= $locale->text('On Hand')." : "; + $form->{l_onhand} = "Y"; + } + if ($form->{itemstatus} eq 'short') { + $option .= $locale->text('Short')." : "; + $form->{l_onhand} = "Y"; + } + if ($form->{onorder}) { + $form->{l_ordnumber} = "Y"; + $callback .= "&onorder=$form->{onorder}"; + $option .= $locale->text('On Order')." : "; + } + if ($form->{ordered}) { + $form->{l_ordnumber} = "Y"; + $callback .= "&ordered=$form->{ordered}"; + $option .= $locale->text('Ordered')." : "; + } + if ($form->{closed}) { + $callback .= "&closed=$form->{closed}"; + $option .= $locale->text('Closed')." : "; + } + if ($form->{bought}) { + $form->{l_invnumber} = "Y"; + $callback .= "&bought=$form->{bought}"; + $option .= $locale->text('Bought')." : "; + } + if ($form->{sold}) { + $form->{l_invnumber} = "Y"; + $callback .= "&sold=$form->{sold}"; + $option .= $locale->text('Sold')." : "; + } + if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { + + $form->{l_lastcost} = ""; + 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 .= "<br>"; + + if ($form->{partnumber}) { + $callback .= "&partnumber=$form->{partnumber}"; + $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|; + } + if ($form->{description}) { + $callback .= "&description=$form->{description}"; + $option .= $locale->text('Description').qq| : $form->{description}<br>|; + } + if ($form->{make}) { + $callback .= "&make=$form->{make}"; + $option .= $locale->text('Make').qq| : $form->{make}<br>|; + } + if ($form->{model}) { + $callback .= "&model=$form->{model}"; + $option .= $locale->text('Model').qq| : $form->{model}<br>|; + } + if ($form->{drawing}) { + $callback .= "&drawing=$form->{drawing}"; + $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|; + } + if ($form->{microfiche}) { + $callback .= "µfiche=$form->{microfiche}"; + $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)); + + 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_linetotallistprice} = "Y" if $form->{l_listprice}; + } + + if ($form->{searchitems} eq 'service') { + # remove bin, weight and rop from list + map { $form->{"l_$_"} = "" } qw(bin weight rop); + + $form->{l_onhand} = ""; + # qty is irrelevant unless bought or sold + if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { + $form->{l_onhand} = "Y"; + } else { + $form->{l_linetotalsellprice} = ""; + $form->{l_linetotallastcost} = ""; + } + } + + $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom}); + + foreach $item (@columns) { + if ($form->{"l_$item"} eq "Y") { + push @column_index, $item; + + # add column to callback + $callback .= "&l_$item=Y"; + } + } + + if ($form->{l_subtotal} eq 'Y') { + $callback .= "&l_subtotal=Y"; + } + + $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{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{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{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{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{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>|; + + $form->header; + $colspan = $#column_index + 1; + + print qq| +<body> + +<table width=100%> +<tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> +<tr height="5"></tr> + +<tr><td colspan=$colspan>$option</td></tr> + + <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->{parts} }) { + $sameitem = $form->{parts}->[0]->{$form->{sort}}; + } + + foreach $ref (@{ $form->{parts} }) { + + if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) { + if ($sameitem ne $ref->{$form->{sort}}) { + &parts_subtotal; + $sameitem = $ref->{$form->{sort}}; + } + } + + $ref->{exchangerate} = 1 unless $ref->{exchangerate}; + $ref->{sellprice} *= $ref->{exchangerate}; + $ref->{listprice} *= $ref->{exchangerate}; + $ref->{lastcost} *= $ref->{exchangerate}; + + $align = "left"; + $onhand = $ref->{onhand}; + + if ($ref->{assemblyitem}) { + $align = "right"; + $onhand = 0 if ($form->{sold}); + } + + $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{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}) { + $totalsellprice += $onhand * $ref->{sellprice}; + $totallastcost += $onhand * $ref->{lastcost}; + $totallistprice += $onhand * $ref->{listprice}; + + $subtotalonhand += $onhand; + $subtotalsellprice += $onhand * $ref->{sellprice}; + $subtotallastcost += $onhand * $ref->{lastcost}; + $subtotallistprice += $onhand * $ref->{listprice}; + } + + $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, '', " ")."</td>"; + $column_data{weight} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{weight}, '', " ")."</td>"; + $column_data{unit} = "<td>$ref->{unit} </td>"; + $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>"; + + $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>"; + + $i++; $i %= 2; + print "<tr class=listrow$i>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + } + + + if ($form->{l_subtotal} eq 'Y') { + &parts_subtotal; + } + + if ($form->{"l_linetotal"}) { + map { $column_data{$_} = "<td> </td>" } @column_index; + $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, 2, " ")."</th>"; + $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, 2, " ")."</th>"; + $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, 2, " ")."</th>"; + + print "<tr class=listtotal>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq|</tr> + |; + } + + print qq| + <tr><td colspan=$colspan><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=item value=$form->{searchitems}> + +<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('Add').qq|"> + +</form> + +</body> +</html> +|; + +} + + + +sub parts_subtotal { + + map { $column_data{$_} = "<td> </td>" } @column_index; + $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>"; + + $subtotalonhand = 0; + $subtotalsellprice = 0; + $subtotallistprice = 0; + $subtotallastcost = 0; + + print "<tr class=listsubtotal>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + +} + + + +sub edit { + + IC->get_part(\%myconfig, \%$form); + + $form->{title} = $locale->text('Edit '.ucfirst $form->{item}); + + &link_part; + &display_form; + +} + + + +sub link_part { + + IC->create_links("IC", \%myconfig, \%$form); + + # parts and assemblies have the same links + $item = $form->{item}; + if ($form->{item} eq 'assembly') { + $item = 'part'; + } + + # build the popup menus + $form->{taxaccounts} = ""; + foreach $key (keys %{ $form->{IC_links} }) { + foreach $ref (@{ $form->{IC_links}{$key} }) { + # if this is a tax field + if ($key =~ /IC_tax/) { + if ($key =~ /$item/) { + $form->{taxaccounts} .= "$ref->{accno} "; + $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}"; + + if ($form->{id}) { + if ($form->{amount}{$ref->{accno}}) { + $form->{"IC_tax_$ref->{accno}"} = "checked"; + } + } else { + $form->{"IC_tax_$ref->{accno}"} = "checked"; + } + } + } else { + + $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; + if ($form->{amount}{$key} eq $ref->{accno}) { + $form->{$key} = "$ref->{accno}--$ref->{description}"; + } + + } + } + } + chop $form->{taxaccounts}; + + if (($form->{item} eq "part") || ($form->{item} eq "assembly")) { + $form->{selectIC_income} = $form->{selectIC_sale}; + $form->{selectIC_expense} = $form->{selectIC_cogs}; + $form->{IC_income} = $form->{IC_sale}; + $form->{IC_expense} = $form->{IC_cogs}; + } + + delete $form->{IC_links}; + delete $form->{amount}; + +} + + + +sub form_header { + + ($dec) = ($form->{sellprice} =~ /\.(\d+)/); + $dec = length $dec; + my $decimalplaces = ($dec > 2) ? $dec : 2; + + map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)} qw(listprice sellprice); + + ($dec) = ($form->{lastcost} =~ /\.(\d+)/); + $dec = length $dec; + my $decimalplaces = ($dec > 2) ? $dec : 2; + + $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; + } + + + if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) { + $rows = 2; + } + + $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|; + + if (($rows = $form->numtextrows($form->{description}, 40)) > 1) { + $description = qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|; + } else { + $description = qq|<input name=description size=40 value="$form->{description}">|; + } + + foreach $item (split / /, $form->{taxaccounts}) { + $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : ""; + } + + + # set option + foreach $item (qw(IC IC_income IC_expense)) { + if ($form->{$item}) { + if ($form->{id} && $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}|; + } + } + } + + # tax fields + foreach $item (split / /, $form->{taxaccounts}) { + $tax .= qq| + <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}> <b>$form->{"IC_tax_${item}_description"}</b> + <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}"> +|; + } + + $form->{obsolete} = "checked" if $form->{obsolete}; + + $lastcost = qq| + <tr> + <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th> + <td><input name=lastcost size=11 value=$form->{lastcost}></td> + </tr> +|; + + if ($form->{item} eq "part") { + + $linkaccounts = qq| + <tr> + <th width="1%" 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> + <td><select name=IC_income>$form->{selectIC_income}</select></td> + <input name=selectIC_income type=hidden value="$form->{selectIC_income}"> + </tr> + <tr> + <th align=right>|.$locale->text('COGS').qq|</th> + <td><select name=IC_expense>$form->{selectIC_expense}</select></td> + <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}"> + </tr> +|; + + if ($tax) { + $linkaccounts .= qq| + <tr> + <th align=right>|.$locale->text('Tax').qq|</th> + <td>$tax</td> + </tr> +|; + } + + $weight = qq| + <tr> + <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th> + <td> + <table> + <tr> + <td> + <input name=weight size=10 value=$form->{weight}> + </td> + <th> + + $form->{weightunit} + <input type=hidden name=weightunit value=$form->{weightunit}> + </th> + </tr> + </table> + </td> + </tr> +|; + + } + + + if ($form->{item} eq "assembly") { + + $lastcost = ""; + + $linkaccounts = qq| + <tr> + <th width="1%" align=right>|.$locale->text('Sales').qq|</th> + <td><select name=IC_income>$form->{selectIC_income}</select></td> + <input name=selectIC_income type=hidden value="$form->{selectIC_income}"> + </tr> +|; + + if ($tax) { + $linkaccounts .= qq| + <tr> + <th align=right>|.$locale->text('Tax').qq|</th> + <td>$tax</td> + </tr> +|; + } + + $weight = qq| + <tr> + <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th> + <td> + <table> + <tr> + <td> + $form->{weight} + <input type=hidden name=weight value=$form->{weight}> + </td> + <th> + + $form->{weightunit} + <input type=hidden name=weightunit value=$form->{weightunit}> + </th> + </tr> + </table> + </td> + </tr> +|; + + + } + + + if ($form->{item} eq "service") { + + $linkaccounts = qq| + <tr> + <th width="1%" 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> + <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 ($tax) { + $linkaccounts .= qq| + <tr> + <th align=right>|.$locale->text('Tax').qq|</th> + <td>$tax</td> + </tr> +|; + } + + } + + + if ($form->{item} ne 'service') { + $color = ($form->{onhand} > 0) ? "green" : "red"; + $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> + </tr> +|; + + if ($form->{item} eq 'assembly') { + $rop .= qq| + <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> + <td><input name=rop size=10 value=$form->{rop}></td> + </tr> +|; + + $bin = qq| + <tr> + <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th> + <td><input name=bin size=10 value=$form->{bin}></td> + </tr> +|; + + $imagelinks = qq| + <tr> + <td> + <table> + <tr> + <th width=1% align=right nowrap>|.$locale->text('Image').qq|</th> + <td width=70%><input name=image size=40 value="$form->{image}"></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> + </tr> + </table> + </td> + </tr> +|; + + } + + if ($form->{id}) { + $obsolete = qq| + <tr> + <th align="right" nowrap="true">|.$locale->text('Obsolete').qq|</th> + <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td> + </tr> +|; + } + + + +# 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') + + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<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}> + +<table width="100%"> + <tr><th class=listtop>$form->{title}</th></tr> + <tr height="5"></tr> + <tr> + <td> + <table width="100%"> + <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> + </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> + </table> + </td> + </tr> + <tr> + <td> + <table width="100%" height="100%"> + <tr valign=top> + <td width=70%> + <table width="100%" height="100%"> + <tr class="listheading"> + <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th> + </tr> + $linkaccounts + <tr> + <th align="left">|.$locale->text('Notes').qq|</th> + </tr> + <tr> + <td colspan=2> + $notes + </td> + </tr> + </table> + </td> + <td width="30%"> + <table width="100%"> + <tr> + <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> + $lastcost + <tr> + <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th> + <td><input name=unit size=5 maxsize=5 value="$form->{unit}"></td> + </tr> + $weight + $rop + $bin + $obsolete + </table> + </td> + </tr> + </table> + </td> + </tr> + $imagelinks +|; +} + + +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|"> +|; + + if ($form->{item} ne "service") { + print qq| + <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}> + |; + } + + print qq| + <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">|; + + 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}) { + print qq| + <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|; + } + } + + } + + print qq| + +</form> + +</body> +</html> +|; + +} + + + +sub makemodel_row { + my ($numrows) = @_; + + $form->{"make_$i"} =~ s/"/"/g; + $form->{"model_$i"} =~ s/"/"/g; + + print qq| + <tr> + <td> + <table width=100%> + <tr> + <th class="listheading">|.$locale->text('Make').qq|</th> + <th class="listheading">|.$locale->text('Model').qq|</th> + </tr> +|; + + 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> + </tr> +|; + } + + print qq| + </table> + </td> + </tr> +|; + +} + + +sub assembly_row { + my ($numrows) = @_; + + @column_index = qw(runningnumber qty unit bom partnumber description partsgroup total); + + 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"; + + # delete action + delete $form->{action}; + + $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; + + $form->{assemblytotal} = 0; + $form->{weight} = 0; + + } + + $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{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|; + $column_header{partsgroup} = qq|<th>|.$locale->text('Group').qq|</th>|; + + print qq| + <tr class=listheading> + <th class=listheading>|.$locale->text('Individual Items').qq|</th> + </tr> + <tr> + <td> + <table width=100%> + <tr> +|; + + map { print "\n$column_header{$_}" } @column_index; + + print qq| + </tr> +|; + + for $i (1 .. $numrows) { + $form->{"partnumber_$i"} =~ s/"/"/g; + + $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2); + $form->{assemblytotal} += $linetotal; + + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + + $linetotal = $form->format_amount(\%myconfig, $linetotal, 2); + + if (($i >= 1) && ($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>|; + + } + + } 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>|; + + } 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{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</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>|; + + print qq| + <tr>|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </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="weight_$i" value=$form->{"weight_$i"}> +|; + } + + print qq| + </table> + </td> + </tr> +|; + +} + + +sub update { + + + if ($form->{item} eq "assembly") { + + $i = $form->{assembly_rows}; + + # if last row is empty check the form otherwise retrieve item + if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { + + &check_form; + + } else { + + IC->assembly_item(\%myconfig, \%$form); + + $rows = scalar @{ $form->{item_list} }; + + if ($rows) { + $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); + + if ($rows > 1) { + $form->{makemodel_rows}--; + &select_item; + exit; + } else { + map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit partsgroup); + map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + $form->{"runningnumber_$i"} = $form->{assembly_rows}; + $form->{assembly_rows}++; + + &check_form; + + } + + } else { + + $form->{rowcount} = $i; + $form->{assembly_rows}++; + + &new_item; + + } + } + } + + if ($form->{item} eq "part") { + &check_form; + } + + if ($form->{item} eq 'service') { + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice); + + &form_header; + &form_footer; + } + +} + + +sub save { + + # check if there is a part number + $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Number missing!")); + + if ($form->{obsolete}) { + $form->error($locale->text("Inventory quantity must be zero before you can set this $form->{item} obsolete!")) if ($form->{onhand}); + } + +# 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!') + + # 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 + map { $newform{$_} = $form->{$_} } keys %$form; + + $previous_form = $form->unescape($form->{previous_form}); + + # don't trample on previous variables + map { delete $form->{$_} } keys %newform; + + # now take it apart and restore original values + foreach $item (split /&/, $previous_form) { + ($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}--; + $i = $newform{rowcount}; + $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); + + $form->{sellprice} -= $form->{"sellprice_$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); + + # undo string formatting + map { $form->{"${_}_$i"} =~ s/''/'/g } qw(partnumber description unit bin); + + $form->{sellprice} += $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2); + $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"}; + + } 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); + $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id}); + + if ($form->{exchangerate} != 0) { + $form->{"sellprice_$i"} /= $form->{exchangerate}; + } + + map { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) } split / /, $newform{taxaccounts}; + chop $form->{"taxaccounts_$i"}; + + # credit remaining calculation + $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; + + } + + $form->{"id_$i"} = $parts_id; + delete $form->{action}; + + # restore original callback + $callback = $form->unescape($form->{callback}); + $form->{callback} = $form->unescape($form->{old_callback}); + delete $form->{old_callback}; + + $form->{makemodel_rows}--; + + # put callback together + foreach $key (keys %$form) { + # do single escape for Apache 2.0 + $value = $form->escape($form->{$key}, 1); + $callback .= qq|&$key=$value|; + } + $form->{callback} = $callback; + } + + # redirect + $form->redirect; + +} + + +sub save_as_new { + + $form->{id} = 0; + &save; + +} + + +sub delete { + + $rc = IC->delete(\%myconfig, \%$form); + + # redirect + $form->redirect($locale->text('Item deleted!')) if ($rc > 0); + $form->error($locale->text('Cannot delete item!')); + +} + + + +sub stock_assembly { + + $form->{title} = $locale->text('Stock Assembly'); + + $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 width="100%"> + <tr> + <th width="1%" align="right" nowrap="true">|.$locale->text('Number').qq|</th> + <td width="40%"><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> + </tr> + </table> + </td> + </tr> + <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=password value=$form->{password}> + +<input type=hidden name=nextsub value=list_assemblies> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + + + +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>|; + $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)); + + $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> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> + <tr size=5></tr> + <tr class=listheading>|; + + map { print "\n$column_header{$_}" } @column_index; + + print qq| + </tr> +|; + + $i = 1; + foreach $ref (@{ $form->{assembly_items} }) { + + map { $ref->{$_} =~ s/"/"/g } 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{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{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>|; + + $j++; $j %= 2; + print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + $i++; + + } + + $i--; + print qq| + <tr> + <td colspan=6><hr size=3 noshade> + </tr> +</table> +<input name=rowcount type=hidden value="$i"> + +<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 name=callback type=hidden value="$form->{callback}"> + +<input type=hidden name=nextsub value=restock_assemblies> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub restock_assemblies { + + $form->redirect($locale->text('Assemblies restocked!')) if (IC->restock_assemblies(\%myconfig, \%$form)); + $form->error($locale->text('Cannot stock assemblies!')); + +} + + +sub continue { &{ $form->{nextsub} } }; + + diff --git a/sql-ledger/bin/mozilla/io.pl b/sql-ledger/bin/mozilla/io.pl new file mode 100644 index 000000000..751d9a2ed --- /dev/null +++ b/sql-ledger/bin/mozilla/io.pl @@ -0,0 +1,1149 @@ +###################################################################### +# SQL-Ledger, Accounting +# Copyright (c) 1998-2002 +# +# 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. +# +####################################################################### +# +# common routines used in is, ir, oe +# +####################################################################### + +# any custom scripts for this one +if (-f "$form->{path}/custom_io.pl") { + eval { require "$form->{path}/custom_io.pl"; }; +} +if (-f "$form->{path}/$form->{login}_io.pl") { + eval { require "$form->{path}/$form->{login}_io.pl"; }; +} + + +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 display_row { + my $numrows = shift; + + @column_index = (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>|; + } + } + 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, qw(unit sellprice); + + if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') { + push @column_index, qw(discount); + } + + push @column_index, "linetotal"; + + my $colspan = $#column_index + 1; + + + $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{discount} = qq|<th class=listheading>%</th>|; + $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|; + $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|; + + print qq| + <tr> + <td> + <table width=100%> + <tr class=listheading>|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + + $projectnumber = $locale->text('Project'); + $runningnumber = $locale->text('No.'); + $partsgroup = $locale->text('Group'); + + if ($form->{type} =~ /_order/) { + $reqdate = $locale->text('Required by'); + $delvar = "reqdate"; + } else { + $deliverydate = $locale->text('Delivery Date'); + $delvar = "deliverydate"; + } + + + 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; + + $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); + + $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></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>|; + } else { + $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></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{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>|; + $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|; + + 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="bin_$i" value="$form->{"bin_$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"}"> + +|; + + # 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> + </td> + </tr> + <tr> + <td colspan=$colspan><hr size=1 noshade></td> + </tr> +|; + + + map { $form->{"${_}_base"} += $linetotal } (split / /, $form->{"taxaccounts_$i"}); + + $form->{invsubtotal} += $linetotal; + } + + print qq| + </table> + </td> + </tr> +|; + +} + + +sub select_item { + + @column_index = qw(ndx partnumber description onhand sellprice); + + $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{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|; + $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|; + + + # 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}> + +<table width=100%> + <tr> + <th class=listtop colspan=$colspan>$title</th> + </tr> + <tr height="5"></tr> + <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->{$_} =~ s/"/"/g } qw(partnumber description unit); + + $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>|; + + $j++; $j %= 2; + print qq| +<tr class=listrow$j>|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| +</tr> + +<input name="new_bin_$i" type=hidden value="$ref->{bin}"> +<input name="new_listprice_$i" type=hidden value=$ref->{listprice}> +<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}> +<input name="new_unit_$i" type=hidden value="$ref->{unit}"> +<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_id_$i" type=hidden value=$ref->{id}> + +|; + + } + + print qq| +<tr><td colspan=8><hr size=3 noshade></td></tr> +</table> + +<input name=lastndx type=hidden value=$i> + +|; + + # 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|; + } + + 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}; + $i = $form->{assembly_rows} if ($form->{item} eq 'assembly'); + + # index for new item + $j = $form->{ndx}; + + # 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); + + ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + # if there is an exchange rate adjust sellprice + if (($form->{exchangerate} * 1) != 0) { + $form->{"sellprice_$i"} /= $form->{exchangerate}; + $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces); + } + } + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice weight); + + $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"}); + $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"}); + + $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; + + $form->{"runningnumber_$i"} = $i; + + # 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->{$_} } 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); + } + + &display_form; + +} + + +sub new_item { + + # change callback + $form->{old_callback} = $form->escape($form->{callback},1); + $form->{callback} = $form->escape("$form->{script}?action=display_form",1); + + # 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}&|; + } + chop $previous_form; + $previous_form = $form->escape($previous_form, 1); + + $i = $form->{rowcount}; + map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description); + + $form->header; + + print qq| +<body> + +<h4 class=error>|.$locale->text('Item not on file!').qq| + +<p> +|.$locale->text('What type of item is this?').qq|</h4> + +<form method=post action=ic.pl> + +<p> + + <input class=radio type=radio name=item value=part checked> |.$locale->text('Part') +.qq|<br> + <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=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=nextsub value=add> + +<p> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + + +sub display_form { + + &form_header; + + $numrows = ++$form->{rowcount}; + $subroutine = "display_row"; + + if ($form->{item} eq 'part') { + $numrows = ++$form->{makemodel_rows}; + $subroutine = "makemodel_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"; + } + if ($form->{item} eq 'service') { + $numrows = 0; + } + + # create rows + &{ $subroutine }($numrows) if $numrows; + + &form_footer; + +} + + + +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)); + + # remove any makes or model rows + if ($form->{item} eq 'part') { + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost weight rop); + + @flds = (make, model); + for my $i (1 .. ($form->{makemodel_rows})) { + if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) { + push @a, {}; + my $j = $#a; + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows}); + $form->{makemodel_rows} = $count; + + } elsif ($form->{item} eq 'assembly') { + + $form->{sellprice} = 0; + $form->{weight} = 0; + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice rop); + + @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup); + + for my $i (1 .. ($form->{assembly_rows} - 1)) { + if ($form->{"qty_$i"}) { + push @a, {}; + my $j = $#a; + + $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"}); + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + + $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"}); + $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"}); + $count++; + } + } + + $form->{sellprice} = $form->round_amount($form->{sellprice}, 2); + + $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows}); + $form->{assembly_rows} = $count; + + $count = 0; + @flds = qw(make model); + @a = (); + + for my $i (1 .. ($form->{makemodel_rows})) { + if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) { + push @a, {}; + my $j = $#a; + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows}); + $form->{makemodel_rows} = $count; + + } else { + + # this section applies to invoices and orders + # remove any empty numbers + + if ($form->{rowcount}) { + for my $i (1 .. $form->{rowcount} - 1) { + if ($form->{"partnumber_$i"}) { + push @a, {}; + my $j = $#a; + + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); + $form->{rowcount} = $count; + + $form->{creditremaining} -= &invoicetotal; + + } + } + + &display_form; + +} + + +sub invoicetotal { + + $form->{oldinvtotal} = 0; + # add all parts and deduct paid + map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts}; + + my ($amount, $sellprice, $discount, $qty); + + for my $i (1 .. $form->{rowcount}) { + $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); + $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"}); + $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"}); + + $amount = $sellprice * (1 - $discount / 100) * $qty; + map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"}); + $form->{oldinvtotal} += $amount; + } + + map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded}; + + $form->{oldtotalpaid} = 0; + for $i (1 .. $form->{paidaccounts}) { + $form->{oldtotalpaid} += $form->{"paid_$i"}; + } + + # return total + ($form->{oldinvtotal} - $form->{oldtotalpaid}); + +} + + +sub validate_items { + + # check if items are valid + if ($form->{rowcount} == 1) { + &update; + exit; + } + + for $i (1 .. $form->{rowcount} - 1) { + $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i"); + } + +} + + +sub order { + + $form->{ordnumber} = $form->{invnumber}; + + $form->{id} = ''; + + 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'; + } + $form->{script} = 'oe.pl'; + + $form->{shipto} = 1; + + $form->{rowcount}--; + + require "$form->{path}/$form->{script}"; + + map { $form->{"select$_"} = "" } ($form->{vc}, currency); + + $currency = $form->{currency}; + + &order_links; + + $form->{currency} = $currency; + $form->{exchangerate} = ""; + $form->{forex} = ""; + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{orddate}, $buysell))); + + &prepare_order; + &display_form; + +} + + +sub e_mail { + + + if ($myconfig{admin}) { + $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') { + $form->{email} = $form->{shiptoemail} if $form->{shiptoemail}; + } + + $name = $form->{$form->{vc}}; + $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}> + +<table width=100%> + <tr class=listtop> + <th class=listtop>$title</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table width=100%> + <tr> + <th align=right nowrap>|.$locale->text('To').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> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Subject').qq|</th> + <td><input name=subject size=30 value="$form->{subject}"></td> + $bcc + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr> + <th align=left nowrap>|.$locale->text('Message').qq|</th> + </tr> + <tr> + <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td> + </tr> + </table> + </td> + </tr> + <tr> + <td> +|; + + &print_options; + + map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format); + + # save all other variables + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + print qq| + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=nextsub value=send_email> + +<br> +<input name=action class=submit type=submit value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub send_email { + + $old_form = new Form; + map { $old_form->{$_} = $form->{$_} } keys %$form; + $old_form->{media} = $form->{oldmedia}; + &print_form($old_form); + +} + + + +sub print_options { + + $form->{sendmode} = "attachment"; + $form->{copies} = 3 unless $form->{copies}; + + $form->{PD}{$form->{type}} = "checked"; + $form->{DF}{$form->{format}} = "checked"; + $form->{OP}{$form->{media}} = "checked"; + $form->{SM}{$form->{sendmode}} = "checked"; + + 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->{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> +|; + } 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> +|; + } + + 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> +|; + + 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> +|; + } + + print qq| + $screen +|; + + 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> +|; + } + } + + + $form->{groupitems} = "checked" if $form->{groupitems}; + + print qq| + $email + <td align=right><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td> + <td>|.$locale->text('Group Items').qq|</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)/); + + $old_form = new Form; + map { $old_form->{$_} = $form->{$_} } keys %$form; + } + + &print_form($old_form); + +} + + +sub print_form { + my $old_form = shift; + + $inv = "inv"; + $due = "due"; + + if ($form->{type} 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') { + $inv = "ord"; + $due = "req"; + $form->{label} = $locale->text('Sales Order'); + } + if ($form->{type} eq 'purchase_order') { + $inv = "ord"; + $due = "req"; + $form->{label} = $locale->text('Purchase Order'); + } + + $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!')); + +# $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!') + + &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}); + + # create the form variables for the invoice, packing list or order + if ($form->{type} =~ /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); + + + @a = qw(name addr1 addr2 addr3 addr4); + + $fillshipto = 1; + # if there is no shipto fill it in from billto + foreach $item (@a) { + if ($form->{"shipto$item"}) { + $fillshipto = 0; + last; + } + } + + if ($fillshipto) { + if ($form->{type} eq 'purchase_order') { + $form->{shiptoname} = $myconfig{company}; + $form->{shiptoaddr1} = $myconfig{address}; + } else { + 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, ("${inv}date", "${due}date"); + + $form->format_string(@a); + + + $form->{templates} = "$myconfig{templates}"; + $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/; + } + + $form->format_string(email, shiptoemail, cc, bcc) if $form->{format} =~ /(pdf|postscript)/; + + if ($form->{media} eq 'printer') { + $form->{OUT} = "| $myconfig{printer}"; + } + + if ($form->{media} eq 'email') { + $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject}; + + $form->{OUT} = "$sendmail"; + } + + + $form->parse_template(\%myconfig, $userspath); + + $form->{callback} = ""; + + # 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; + } + + $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|); + } + +} + + +sub customer_details { + + IS->customer_details(\%myconfig, \%$form); + +} + + +sub vendor_details { + + IR->vendor_details(\%myconfig, \%$form); + +} + + +sub post_as_new { + + $form->{postasnew} = 1; + &post; + +} + + +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" }; + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr> + <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> + </tr> + <tr height="5"></tr> + <tr> + <th align=right nowrap>|.$locale->text('Number').qq|</th> + <td>$form->{"$form->{vc}number"}</td> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Name').qq|</th> + <td>$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>$form->{addr1}</td> + <td><input name=shiptoaddr1 size=35 maxsize=35 value="$form->{shiptoaddr1}"></td> + </tr> + <tr> + <th></th> + <td>$form->{addr2}</td> + <td><input name=shiptoaddr2 size=35 maxsize=35 value="$form->{shiptoaddr2}"></td> + </tr> + <tr> + <th></th> + <td>$form->{addr3}</td> + <td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td> + </tr> + <tr> + <th></th> + <td>$form->{addr4}</td> + <td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></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> + </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> + </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> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('E-mail').qq|</th> + <td>$form->{email}</td> + <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td> + </tr> + </table> + </td> + </tr> +</table> +|; + + # delete shipto + map { delete $form->{$_} } qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact shiptophone shiptofax shiptoemail); + $form->{title} = $title; + + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + print qq| + +<input type=hidden name=nextsub value=display_form> + +<hr size=3 noshade> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + diff --git a/sql-ledger/bin/mozilla/ir.pl b/sql-ledger/bin/mozilla/ir.pl new file mode 100644 index 000000000..ec7d18cf0 --- /dev/null +++ b/sql-ledger/bin/mozilla/ir.pl @@ -0,0 +1,653 @@ +#===================================================================== +# SQL-Ledger, Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# Inventory received module +# +#====================================================================== + + +use SL::IR; +use SL::PE; + +require "$form->{path}/io.pl"; +require "$form->{path}/arap.pl"; + +1; +# end of main + + + +sub add { + + $form->{title} = $locale->text('Add Vendor Invoice'); + + &invoice_links; + &prepare_invoice; + &display_form; + +} + + +sub edit { + + $form->{title} = $locale->text('Edit Vendor Invoice'); + + &invoice_links; + &prepare_invoice; + &display_form; + +} + + +sub invoice_links { + + # 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]; + $form->{defaultcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; + + # vendors + if (@{ $form->{all_vendor} }) { + $form->{vendor} = "$form->{vendor}--$form->{vendor_id}"; + map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} }); + } + + + # forex + $form->{forex} = $form->{exchangerate}; + $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + foreach $key (keys %{ $form->{AP_links} }) { + + foreach $ref (@{ $form->{AP_links}{$key} }) { + $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n"; + } + + if ($key eq "AP_paid") { + for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + # reverse paid + $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount}; + $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->{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)); + +} + + + +sub prepare_invoice { + + if ($form->{id}) { + + map { $form->{$_} =~ s/"/"/g } qw(invnumber ordnumber); + + foreach $ref (@{ $form->{invoice_details} }) { + $i++; + map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + + ($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->{rowcount} = $i; + } + } + +} + + + +sub form_header { + + # set option selected + foreach $item (qw(AP vendor currency)) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + } + + $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> +|; + } else { + $exchangerate .= qq| + <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th> + <td><input name=exchangerate size=10 value=$form->{exchangerate}></td> +|; + } + } + $exchangerate .= qq| +<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>|; + + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<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=closedto value=$form->{closedto}> +<input type=hidden name=locked value=$form->{locked}> + + +<table width=100%> + <tr class=listtop> + <th>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table width=100%> + <tr valign=top> + <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> + + <input type=hidden name=vendor_id value=$form->{vendor_id}> + <input type=hidden name=oldvendor value="$form->{oldvendor}"> + + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Currency').qq|</th> + <td><select name=currency>$form->{selectcurrency}</select></td> + $exchangerate + </tr> + </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> + </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> + </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> + </table> + </td> + </tr> + </table> + </td> + </tr> +<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}> + +<input type=hidden name=taxpart value="$form->{taxpart}"> +<input type=hidden name=taxservice value="$form->{taxservice}"> + +<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"}"> +|; + } + +} + + + +sub form_footer { + + $form->{invtotal} = $form->{invsubtotal}; + + if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { + $rows = 2; + } + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + + + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + 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> +|; + } + + if (!$form->{taxincluded}) { + + foreach $item (split / /, $form->{taxaccounts}) { + if ($form->{"${item}_base"}) { + $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2); + $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); + + $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> +|; + + } + + + $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); + + print qq| + <tr> + <td colspan=$colspan> + <table cellspacing="0"> + <tr valign=bottom> + <td> + <table> + <tr> + <th align=left>|.$locale->text('Notes').qq|</th> + </tr> + <tr> + <td>$notes</td> + </tr> + </table> + </td> + <td colspan=2 align=right width=100%> + $taxincluded + <table width=100%> + $subtotal + $tax + <tr> + <th align=right>|.$locale->text('Total').qq|</th> + <td align=right>$form->{invtotal}</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan=$colspan> + <table width=100%> + <tr> + <th colspan=5 class=listheading>|.$locale->text('Payments').qq|</th> + </tr> +|; + + if ($form->{currency} eq $form->{defaultcurrency}) { + @column_index = qw(datepaid source paid AP_paid); + } else { + @column_index = qw(datepaid source paid exchangerate AP_paid); + } + + $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; + $column_data{paid} = "<th>".$locale->text('Amount')."</th>"; + $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>"; + + print qq| + <tr> +|; + map { print "$column_data{$_}\n" } @column_index; + print qq| + </tr> +|; + + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); + for $i (1 .. $form->{paidaccounts}) { + + print qq| + <tr> +|; + + $form->{"selectAP_paid_$i"} = $form->{selectAP_paid}; + $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/; + + # format amounts + $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + + $exchangerate = qq| |; + if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{"forex_$i"}) { + $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } else { + $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|; + } + } + $exchangerate .= qq| +<input type=hidden name="forex_$i" value=$form->{"forex_$i"}> +|; + + $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|; + $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>|; + + map { print qq|$column_data{"${_}_$i"}\n| } @column_index; + + print qq| + </tr> +|; + } + + print qq| + <input type=hidden name=paidaccounts value=$form->{paidaccounts}> + <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}"> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +<br> +|; + + $invdate = $form->datetonum($form->{invdate}, \%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->{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|"> +|; + } + + } 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|">|; + } + } + +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=password value=$form->{password}> + +</form> + +</body> +</html> +|; + +} + + + +sub update { + + $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}); + + &check_name(vendor); + + &check_project; + + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell'))); + + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + map { $form->{"${_}_$i"} = $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'))); + } + } + + $i = $form->{rowcount}; + $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { + + &check_form; + + } else { + + IR->retrieve_item(\%myconfig, \%$form); + + my $rows = scalar @{ $form->{item_list} }; + + if ($rows) { + $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"}); + + if ($rows > 1) { + + &select_item; + exit; + + } else { + # 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->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + + $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; + + ($dec) = ($s =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + # if there is an exchange rate adjust sellprice + $form->{"sellprice_$i"} /= $exchangerate; + } + + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + } + + &display_form; + + } 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->{"unit_$i"} = $locale->text('ea'); + + &new_item; + + } + } + } +} + + + +sub post { + + $form->isblank("invnumber", $locale->text('Invoice Number missing!')); + $form->isblank("invdate", $locale->text('Invoice Date missing!')); + $form->isblank("vendor", $locale->text('Vendor missing!')); + + # if the vendor changed get new values + if (&check_name(vendor)) { + &update; + exit; + } + + &validate_items; + + $closedto = $form->datetonum($form->{closedto}, \%myconfig); + $invdate = $form->datetonum($form->{invdate}, \%myconfig); + + $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); + + $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + + $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->{AP}) = split /--/, $form->{AP}; + ($form->{AP_paid}) = split /--/, $form->{AP_paid}; + + $form->{id} = 0 if $form->{postasnew}; + + $form->redirect($locale->text('Invoice posted!')) if (IR->post_invoice(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post invoice!')); + +} + + + +sub delete { + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> +|; + + # delete action variable + delete $form->{action}; + + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + print qq| +<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2> + +<h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}</h4> +<p> +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> +|; + + +} + + + +sub yes { + + $form->redirect($locale->text('Invoice deleted!')) if (IR->delete_invoice(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete invoice!')); + +} + + diff --git a/sql-ledger/bin/mozilla/is.pl b/sql-ledger/bin/mozilla/is.pl new file mode 100644 index 000000000..cca5813e8 --- /dev/null +++ b/sql-ledger/bin/mozilla/is.pl @@ -0,0 +1,739 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# Inventory invoicing module +# +#====================================================================== + + +use SL::IS; +use SL::PE; + +require "$form->{path}/io.pl"; +require "$form->{path}/arap.pl"; + + +1; +# end of main + + + +sub add { + + $form->{title} = $locale->text('Add Sales Invoice'); + + &invoice_links; + &prepare_invoice; + &display_form; + +} + + +sub edit { + + $form->{title} = $locale->text('Edit Sales Invoice'); + + &invoice_links; + &prepare_invoice; + &display_form; + +} + + +sub invoice_links { + + # 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]; + $form->{defaultcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; + + if (@{ $form->{all_customer} }) { + $form->{customer} = qq|$form->{customer}--$form->{customer_id}|; + map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); + } + + # 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"; + } + + if ($key eq "AR_paid") { + for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + # reverse paid + $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1; + $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->{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->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + +} + + +sub prepare_invoice { + + $form->{type} = "invoice"; + $form->{format} = "html"; + $form->{media} = "screen"; + + if ($form->{id}) { + + map { $form->{$_} =~ s/"/"/g } qw(invnumber ordnumber shippingpoint notes); + + foreach $ref (@{ $form->{invoice_details} } ) { + $i++; + map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + $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"}); + + map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); + $form->{rowcount} = $i; + } + } + +} + + + +sub form_header { + + + # set option selected + foreach $item (qw(AR customer currency)) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + } + + $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>|; + } else { + $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').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>|; + + $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + + + $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}> +<input type=hidden name=media value=$form->{media}> +<input type=hidden name=format value=$form->{format}> + +<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=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('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}> + <input type=hidden name=oldcustomer value="$form->{oldcustomer}"> + </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->{creditremaining}</font></td> + </tr> + </table> + </td> + </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> + <tr> + <th align=right nowrap>|.$locale->text('Ship via').qq|</th> + <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td> + </tr> + </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> + </tr> + <tr> + <th align=right>|.$locale->text('Invoice Date').qq|</th> + <td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></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> + </table> + </td> + </tr> + <tr> + <td> + </td> + </tr> +<!-- 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=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}"> + +<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}; + + if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { + $rows = 2; + } + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + + + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + + 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> +|; + } + + if (!$form->{taxincluded}) { + + 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); + + $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> +|; + + } + + $form->{oldinvtotal} = $form->{invtotal}; + $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); + + print qq| + <tr> + <td> + <table width=100%> + <tr valign=bottom> + <td> + <table> + <tr> + <th align=left>|.$locale->text('Notes').qq|</th> + </tr> + <tr> + <td>$notes</td> + </tr> + </table> + </td> + <td align=right width=100%> + $taxincluded + <table width=100%> + $subtotal + $tax + <tr> + <th align=right>|.$locale->text('Total').qq|</th> + <td align=right>$form->{invtotal}</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr class=listheading> + <th class=listheading colspan=5>|.$locale->text('Payments') + .qq|</font></th> + </tr> +|; + + if ($form->{currency} eq $form->{defaultcurrency}) { + @column_index = qw(datepaid source paid AR_paid); + } else { + @column_index = qw(datepaid source paid exchangerate AR_paid); + } + + $column_data{datepaid} = "<th>".$locale->text('Date')."</th>"; + $column_data{paid} = "<th>".$locale->text('Amount')."</th>"; + $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>"; + + print " + <tr> +"; + map { print "$column_data{$_}\n" } @column_index; + print " + </tr> +"; + + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); + for $i (1 .. $form->{paidaccounts}) { + + print " + <tr>\n"; + + $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"}); + + $exchangerate = qq| |; + if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{"forex_$i"}) { + $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } else { + $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|; + } + } + + $exchangerate .= qq| +<input type=hidden name="forex_$i" value=$form->{"forex_$i"}> +|; + + $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|; + $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|; + $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>|; + + map { print qq|$column_data{"${_}_$i"}\n| } @column_index; + print " + </tr>\n"; + } + + print qq| +<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> + </table> + </td> + </tr> + <tr> + <td> +|; + + &print_options; + + print qq| + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +|; + + + $invdate = $form->datetonum($form->{invdate}, \%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->{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|"> +|; + } + + } 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|">|; + } + } + + 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=password value=$form->{password}> + +</form> + +</body> +</html> +|; + +} + + +sub update { + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + + &check_name(customer); + + &check_project; + + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy'))); + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + map { $form->{"${_}_$i"} = $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'))); + } + } + + $i = $form->{rowcount}; + $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + # if last row empty, check the form otherwise retrieve new item + if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { + + $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); + &check_form; + + } else { + + IS->retrieve_item(\%myconfig, \%$form); + + $rows = scalar @{ $form->{item_list} }; + + $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100); + + if ($rows) { + $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1; + + if ($rows > 1) { + + &select_item; + exit; + + } else { + + $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); + + map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit); + map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + + $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; + ($dec) = ($s =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + # if there is an exchange rate adjust sellprice + $form->{"sellprice_$i"} /= $exchangerate; + } + + $form->{"listprice_$i"} /= $exchangerate; + + $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"}); + map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded}; + + $form->{creditremaining} -= $amount; + + + map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice); + + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + + } + + &display_form; + + } 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->{"unit_$i"} = $locale->text('ea'); + + &new_item; + + } + } + } +} + + + +sub post { + + $form->isblank("invnumber", $locale->text('Invoice Number missing!')); + $form->isblank("invdate", $locale->text('Invoice Date missing!')); + $form->isblank("customer", $locale->text('Customer missing!')); + + # if oldcustomer ne customer redo form + if (&check_name(customer)) { + &update; + exit; + } + + &validate_items; + + $closedto = $form->datetonum($form->{closedto}, \%myconfig); + $invdate = $form->datetonum($form->{invdate}, \%myconfig); + + $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); + + $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); + + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + + $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->{AR}) = split /--/, $form->{AR}; + ($form->{AR_paid}) = split /--/, $form->{AR_paid}; + + $form->{label} = $locale->text('Invoice'); + + $form->{id} = 0 if $form->{postasnew}; + + $form->redirect($locale->text('Invoice posted!')) if (IS->post_invoice(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post invoice!')); + +} + + + + +sub delete { + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> +|; + + # delete action variable + delete $form->{action}; + + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + print qq| +<h2 class=confirm>|.$locale->text('Confirm!').qq|</font></h2> + +<h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber} +</h4> + +<p> +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> +|; + + +} + + + +sub yes { + + $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete invoice!')); + +} + + diff --git a/sql-ledger/bin/mozilla/login.pl b/sql-ledger/bin/mozilla/login.pl new file mode 100644 index 000000000..3c36564fd --- /dev/null +++ b/sql-ledger/bin/mozilla/login.pl @@ -0,0 +1,217 @@ +###################################################################### +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# 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. +####################################################################### + + +use DBI; +use SL::User; +use SL::Form; + + +$form = new Form; + +$locale = new Locale $language, "login"; + +# customization +if (-f "$form->{path}/custom_$form->{script}") { + eval { require "$form->{path}/custom_$form->{script}"; }; + $form->error($@) if ($@); +} + +# per login customization +if (-f "$form->{path}/$form->{login}_$form->{script}") { + eval { require "$form->{path}/$form->{login}_$form->{script}"; }; + $form->error($@) if ($@); +} + +# window title bar, user info +$form->{titlebar} = "SQL-Ledger ".$locale->text('Version'). " $form->{version}"; + +if ($form->{action}) { + $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}"; + &{ $locale->findsub($form->{action}) }; +} else { + &login_screen; +} + + +1; + + +sub login_screen { + + if (-f "css/sql-ledger.css") { + $form->{stylesheet} = "sql-ledger.css"; + } + + $form->header; + + print qq| +<body class=login> + +<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.png border=0></a> +<h1 class=login align=center>|.$locale->text('Version').qq| $form->{version} +</h1> + +<p> + +<form method=post action=$form->{script}> + + <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> + </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 login { + + $form->error($locale->text('You did not enter a name!')) unless ($form->{login}); + + $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!'); + + $form->error($err[$errno]); + } + + # made it this far, execute the menu + $argv = "login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display"; + + exec ("perl", "menu.pl", $argv); + +} + + + +sub logout { + + 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!')); + +} + + + +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}; + + print qq| +<body> + +<pre> + +</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> + +<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> + +</body> +</html> +|; + +} + + + diff --git a/sql-ledger/bin/mozilla/menu.pl b/sql-ledger/bin/mozilla/menu.pl new file mode 100644 index 000000000..67c18bd54 --- /dev/null +++ b/sql-ledger/bin/mozilla/menu.pl @@ -0,0 +1,160 @@ +###################################################################### +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# Author: Dieter Simader +# Email: dsimader@sql-ledger.org +# Web: http://www.sql-ledger.org +# +# Contributors: Christopher Browne +# +# 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. +####################################################################### +# +# two frame layout with refractured menu +# +# CHANGE LOG: +# DS. 2002-03-25 Created +####################################################################### + +$menufile = "menu.ini"; +use SL::Menu; + + +1; +# end of main + + +sub display { + + $framesize = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "135"; + + $form->header; + + print qq| + +<FRAMESET COLS="$framesize,*" 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}"> + +</FRAMESET> + +</BODY> +</HTML> +|; + +} + + + +sub acc_menu { + + my $menu = new Menu "$menufile"; + $menu = new Menu "custom_$menufile" if (-f "custom_$menufile"); + $menu = new Menu "$form->{login}_$menufile" if (-f "$form->{login}_$menufile"); + + $form->{title} = $locale->text('Accounting Menu'); + + $form->header; + + print qq| +<body class=menu> + +|; + + §ion_menu($menu); + + print qq| +</body> +</html> +|; + +} + + +sub section_menu { + my ($menu, $level) = @_; + + # build tiered menus + my @menuorder = $menu->access_control(\%myconfig, $level); + + while (@menuorder) { + $item = shift @menuorder; + $label = $item; + $label =~ s/$level--//g; + + my $spacer = " " x (($item =~ s/--/--/g) * 2); + + $label =~ s/.*--//g; + $label = $locale->text($label); + $label =~ s/ / /g; + + $menu->{$item}{target} = "main_window" unless $menu->{$item}{target}; + + if ($menu->{$item}{submenu}) { + $menu->{$item}{$item} = !$form->{$item}; + + if ($form->{level} && $item =~ /^$form->{level}/) { + + # expand menu + 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); + + 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>|; + } + + } else { + + print qq|<br><b>$label</b>|; + + §ion_menu($menu, $item); + + print qq|<br>\n|; + + } + } + } +} + + diff --git a/sql-ledger/bin/mozilla/oe.pl b/sql-ledger/bin/mozilla/oe.pl new file mode 100644 index 000000000..6a8326ff2 --- /dev/null +++ b/sql-ledger/bin/mozilla/oe.pl @@ -0,0 +1,1111 @@ +#===================================================================== +# SQL-Ledger, Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# Order entry module +# +#====================================================================== + + +use SL::OE; +use SL::IR; +use SL::IS; +use SL::PE; + +require "$form->{path}/io.pl"; +require "$form->{path}/arap.pl"; + +1; +# end of main + + +sub add { + + if ($form->{type} eq 'purchase_order') { + $form->{title} = $locale->text('Add Purchase Order'); + $form->{vc} = 'vendor'; + } + if ($form->{type} eq 'sales_order') { + $form->{title} = $locale->text('Add Sales Order'); + $form->{vc} = 'customer'; + } + + &order_links; + &prepare_order; + &display_form; + +} + + +sub edit { + + if ($form->{type} eq 'purchase_order') { + $form->{title} = $locale->text('Edit Purchase Order'); + $form->{vc} = 'vendor'; + } + if ($form->{type} eq 'sales_order') { + $form->{title} = $locale->text('Edit Sales Order'); + $form->{vc} = 'customer'; + } + + &order_links; + &prepare_order; + + &display_form; + +} + + +sub order_links { + + # get vendors / customers + $form->all_vc(\%myconfig, $form->{vc}); + + # retrieve order + OE->retrieve_order(\%myconfig, \%$form); + + $taxincluded = $form->{taxincluded}; + $form->{shipto} = 1 if $form->{id}; + + # get customer / vendor + if ($form->{type} eq 'purchase_order') { + IR->get_vendor(\%myconfig, \%$form); + } + if ($form->{type} eq 'sales_order') { + 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 + 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}"} }); + } + + # currencies + @curr = split /:/, $form->{currencies}; + chomp $curr[0]; + $form->{defaultcurrency} = $curr[0]; + + map { $form->{selectcurrency} .= "<option>$_\n" } @curr; + + $form->{taxincluded} = $taxincluded if ($form->{id}); + + # forex + $form->{forex} = $form->{exchangerate}; + +} + + +sub prepare_order { + + $form->{format} = "html"; + $form->{media} = "screen"; + + if ($form->{id}) { + + map { $form->{$_} =~ s/"/"/g } qw(invnumber shippingpoint notes shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact); + + foreach $ref (@{ $form->{order_details} } ) { + $i++; + map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref }; + $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"}); + + map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); + $form->{rowcount} = $i; + } + } + +} + + +sub form_header { + + $checkedopen = ($form->{closed}) ? "" : "checked"; + $checkedclosed = ($form->{closed}) ? "checked" : ""; + + 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> + </tr> +|; + } + + # set option selected + foreach $item ($form->{vc}, currency) { + $form->{"select$item"} =~ s/ selected//; + $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + } + + $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> + <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>|; + } + } + + + $vclabel = ucfirst $form->{vc}; + $vclabel = $locale->text($vclabel); + + if ($form->{type} eq 'sales_order') { + + $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; + + $creditremaining = qq| + <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->{creditremaining}</td> + </tr> + </table> + </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>|; + + + $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}> +<input type=hidden name=media value=$form->{media}> +<input type=hidden name=format value=$form->{format}> + +<input type=hidden name=vc value=$form->{vc}> +<input type=hidden name=employee value="$form->{employee}"> + +<input type=hidden name=title value="$form->{title}"> + +<input type=hidden name=discount value=$form->{discount}> +<input type=hidden name=creditlimit value=$form->{creditlimit}> +<input type=hidden name=creditremaining value=$form->{creditremaining}> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table width="100%"> + <tr valign=top> + <td> + <table> + <tr> + <th align=right>$vclabel</th> + <td colspan=3>$vc</td> + <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> + $creditremaining + <tr> + <th align=right>|.$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}> + $exchangerate + </tr> + <tr> + <th align=right>|.$locale->text('Ship via').qq|</th> + <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td> + </tr> + </table> + </td> + <td align=right> + <table width=100%> + $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> + </table> + </td> + </tr> + </table> + </td> + </tr> + +<!-- 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=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}"> + +<input type=hidden name=taxpart value="$form->{taxpart}"> +<input type=hidden name=taxservice value="$form->{taxservice}"> + +<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"}"> +|; + } + +} + + +sub form_footer { + + $form->{invtotal} = $form->{invsubtotal}; + + if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) { + $rows = 2; + } + $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|; + + $taxincluded = ""; + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + 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> +|; + } + + if (!$form->{taxincluded}) { + + foreach $item (split / /, $form->{taxaccounts}) { + if ($form->{"${item}_base"}) { + $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2); + $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); + + $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> +|; + + } + + $form->{oldinvtotal} = $form->{invtotal}; + $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); + + print qq| + <tr> + <td> + <table width=100%> + <tr valign=bottom> + <td> + <table> + <tr> + <th align=left>|.$locale->text('Notes').qq|</th> + </tr> + <tr> + <td>$notes</td> + </tr> + </table> + </td> + <td align=right width=100%> + $taxincluded + <table width=100%> + $subtotal + $tax + <tr> + <th align=right>|.$locale->text('Total').qq|</th> + <td align=right>$form->{invtotal}</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> +<input type=hidden name=oldinvtotal value=$form->{oldinvtotal}> +<input type=hidden name=oldtotalpaid value=$totalpaid> + <tr> + <td> +|; + + &print_options; + + print qq| + </td> + </tr> + <tr> + <td><hr size=3 noshade></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('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('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|"> +|; + } + + 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=password value=$form->{password}> + +</form> + +</body> +</html> +|; + +} + + +sub update { + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + + &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))); + + + my $i = $form->{rowcount}; + $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; + + 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') { + IR->retrieve_item(\%myconfig, \%$form); + } + if ($form->{type} eq 'sales_order') { + IS->retrieve_item(\%myconfig, \%$form); + } + + my $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"}); + + if ($rows > 1) { + + &select_item; + exit; + + } else { + + $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); + + map { $form->{item_list}[$i]{$_} =~ s/"/"/g } qw(partnumber description unit); + map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + + $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; + + ($dec) = ($s =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + # if there is an exchange rate adjust sellprice + $form->{"sellprice_$i"} /= $exchangerate; + } + + $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"}); + map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded}; + + $form->{creditremaining} -= $amount; + + $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + } + + &display_form; + + } 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->{"unit_$i"} = $locale->text('ea'); + + &new_item; + + } + } + } +} + + + +sub search { + + if ($form->{type} eq 'purchase_order') { + $form->{title} = $locale->text('Purchase Orders'); + $form->{vc} = 'vendor'; + } + if ($form->{type} eq 'sales_order') { + $form->{title} = $locale->text('Sales Orders'); + $form->{vc} = 'customer'; + } + + # setup vendor / customer selection + $form->all_vc(\%myconfig, "$form->{vc}"); + + map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; + + $vclabel = ucfirst $form->{vc}; + $vclabel = $locale->text($vclabel); + +# $locale->text('Vendor') +# $locale->text('Customer') + + $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|; + + $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>$vclabel</th> + <td colspan=3>$vc</td> + </tr> + <tr> + <th align=right>|.$locale->text('Order Number').qq|</th> + <td colspan=3><input name=ordnumber size=20></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> + <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td> + </tr> + <input type=hidden name=sort value=transdate> + <tr> + <th align=right>|.$locale->text('Include in Report').qq|</th> + <td colspan=3> + <table> + <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_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_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> + </tr> + <tr> + <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr><td colspan=4><hr size=3 noshade></td></tr> +</table> + +<br> +<input type=hidden name=nextsub value=orders> +<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=vc value=$form->{vc}> +<input type=hidden name=type value=$form->{type}> + +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub orders { + + $name = $form->{$form->{vc}}; + + # split vendor / customer + ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}}); + + OE->transactions(\%myconfig, \%$form); + + # 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}}); + + # 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"; + + @columns = $form->sort_columns(qw(transdate reqdate id ordnumber name netamount tax amount curr 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; + + # 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"; + } + + + if ($form->{vc} eq 'vendor') { + $form->{title} = $locale->text('Purchase Orders'); + $name = $locale->text('Vendor'); + } + if ($form->{vc} eq 'customer') { + $form->{title} = $locale->text('Sales Orders'); + $name = $locale->text('Customer'); + } + + $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{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{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'); + } + if ($form->{$form->{vc}}) { + $option .= "\n<br>"; + $option .= ucfirst $form->{vc}; + $option .= " : $form->{$form->{vc}}"; + } + 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); + } + + $form->header; + + $colspan = $#column_index + 1; + + print qq| +<body> + +<table width=100%> + <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr> + <tr height="5"></tr> + <tr> + <td colspan=$colspan>$option</td> + </tr> + <tr class=listheading>|; + +map { print "\n$column_header{$_}" } @column_index; + +print qq| + </tr> +|; + + # add sort and escape callback + $callback = $form->escape($callback . "&sort=$form->{sort}"); + + if (@{ $form->{OE} }) { + $sameitem = $form->{OE}->[0]->{$form->{sort}}; + } + + foreach $oe (@{ $form->{OE} }) { + + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $oe->{$form->{sort}}) { + &subtotal; + $sameitem = $oe->{$form->{sort}}; + } + } + + map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount)); + + $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")."</td>"; + $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}; + + $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>"; + + if ($oe->{closed}) { + $column_data{closed} = "<td align=center>X</td>"; + $column_data{open} = "<td> </td>"; + } else { + $column_data{closed} = "<td> </td>"; + $column_data{open} = "<td align=center>X</td>"; + } + + $i++; $i %= 2; + print "<tr class=listrow$i>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + } + + if ($form->{l_subtotal} eq 'Y') { + &subtotal; + } + + # print totals + print qq|<tr class=listtotal>|; + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>"; + $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; + + print qq| + </tr> + <tr><td colspan=8><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=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 class=submit type=submit name=action value=|.$locale->text('Add').qq| + +</form> + +</body> +</html> +|; + +} + + + +sub subtotal { + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>"; + $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>"; + + $subtotalnetamount = 0; + $subtotalamount = 0; + + print "<tr class=listsubtotal>"; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + +} + + +sub save { + + $form->isblank("ordnumber", $locale->text('Order Number missing!')); + $form->isblank("orddate", $locale->text('Order Date missing!')); + + $msg = ucfirst $form->{vc}; + $form->isblank($form->{vc}, $locale->text($msg . " missing!")); + +# $locale->text('Customer missing!'); +# $locale->text('Vendor missing!'); + + $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); + + &validate_items; + + # if the name changed get new values + if (&check_name($form->{vc})) { + &update; + exit; + } + + + # 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'); + + $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!')); + +} + + + +sub delete { + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> +|; + + # delete action variable + delete $form->{action}; + + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + 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> +<p> +<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|"> +</form> + +</body> +</html> +|; + + +} + + + +sub yes { + + $form->redirect($locale->text('Order deleted!')) if (OE->delete_order(\%myconfig, \%$form)); + $form->error($locale->text('Cannot delete order!')); + +} + + +sub invoice { + + $form->isblank("ordnumber", $locale->text('Order Number missing!')); + $form->isblank("orddate", $locale->text('Order Date missing!')); + + + # if the name changed get new values + if (&check_name($form->{vc})) { + &update; + exit; + } + + $form->{closed} = 1; + OE->save_order(\%myconfig, \%$form); + + $form->{orddate} = $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig); + $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1); + + $form->{id} = ''; + $form->{closed} = 0; + $form->{rowcount}--; + $form->{shipto} = 1; + + &create_backorder; + + if ($form->{type} eq 'purchase_order') { + $form->{title} = $locale->text('Add Vendor Invoice'); + $form->{script} = 'ir.pl'; + $script = "ir"; + $buysell = 'sell'; + } + if ($form->{type} eq 'sales_order') { + $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); + $form->{$form->{vc}} =~ s/--.*//g; + $form->{type} = "invoice"; + + # locale messages + $locale = new Locale "$myconfig{countrycode}", "$script"; + + require "$form->{path}/$form->{script}"; + + map { $form->{"select$_"} = "" } ($form->{vc}, currency); + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(creditlimit creditremaining); + + $currency = $form->{currency}; + &invoice_links; + + $form->{currency} = $currency; + $form->{exchangerate} = ""; + $form->{forex} = ""; + $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell))); + + $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal}); + + &prepare_invoice; + + # format amounts + for $i (1 .. $form->{rowcount}) { + $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$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); + $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); + + map { $form->{"${_}_$i"} =~ s/"/"/g } qw(partnumber description unit); + } + + &display_form; + +} + + +sub create_backorder { + + # figure out if we need to create a backorder + # items aren't saved if qty != 0 + + for $i (1 .. $form->{rowcount}) { + $totalqty += $qty = $form->parse_amount($myconfig, $form->{"qty_$i"}); + $totalship += $ship = $form->parse_amount($myconfig, $form->{"ship_$i"}); + + $form->{"qty_$i"} = $qty - $ship; + } + + if ($totalship == 0) { + map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount}); + $form->{ordtotal} = 0; + return; + } + + if ($totalqty == $totalship) { + map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount}); + $form->{ordtotal} = 0; + return; + } + + @flds = (qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts)); + + OE->save_order(\%myconfig, \%$form); + + # rebuild rows for invoice + @a = (); + $count = 0; + + for $i (1 .. $form->{rowcount}) { + + # 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"}; + + if ($form->{"qty_$i"}) { + push @a, {}; + $j = $#a; + map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; + $count++; + } + } + + $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); + $form->{rowcount} = $count; + +} + + + +sub save_as_new { + + $form->{saveasnew} = 1; + $form->{closed} = 0; + &save; + +} + + diff --git a/sql-ledger/bin/mozilla/pe.pl b/sql-ledger/bin/mozilla/pe.pl new file mode 100644 index 000000000..d8706d413 --- /dev/null +++ b/sql-ledger/bin/mozilla/pe.pl @@ -0,0 +1,549 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# 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. +#====================================================================== +# +# project administration +# partsgroup administration +# +#====================================================================== + + +use SL::PE; + +1; +# end of main + + + +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_$form->{type}_header" }; + &{ "form_$form->{type}_footer" }; + +} + + +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" }; + +} + + +sub search { + + if ($form->{type} eq 'project') { + $report = "project_report"; + $sort = 'projectnumber'; + $form->{title} = $locale->text('Projects'); + + $number = qq| + <tr> + <th align=right width=1%>|.$locale->text('Number').qq|</th> + <td><input name=projectnumber size=20></td> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td><input name=description size=60></td> + </tr> +|; + + } + if ($form->{type} eq 'partsgroup') { + $report = "partsgroup_report"; + $sort = 'partsgroup'; + $form->{title} = $locale->text('Groups'); + + $number = qq| + <tr> + <th align=right width=1%>|.$locale->text('Group').qq|</th> + <td><input name=partsgroup size=20></td> + </tr> +|; + + } + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<input type=hidden name=sort value=$sort> +<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%> + $number + <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> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=nextsub value=$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}> + +<br> +<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + + +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; + + if ($form->{status} eq 'all') { + $option = $locale->text('All'); + } + if ($form->{status} eq 'orphaned') { + $option .= $locale->text('Orphaned'); + } + if ($form->{projectnumber}) { + $href .= "&projectnumber=".$form->escape($form->{projectnumber}); + $callback .= "&projectnumber=$form->{projectnumber}"; + $option .= "\n<br>".$locale->text('Project')." : $form->{projectnumber}"; + } + if ($form->{description}) { + $href .= "&description=".$form->escape($form->{description}); + $callback .= "&description=$form->{description}"; + $option .= "\n<br>".$locale->text('Description')." : $form->{description}"; + } + + + @column_index = $form->sort_columns(qw(projectnumber description)); + + $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|; + $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|; + + $form->{title} = $locale->text('Projects'); + + $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 .= "&sort=$form->{sort}"; + + # escape callback for href + $callback = $form->escape($callback); + + foreach $ref (@{ $form->{project_list} }) { + + $i++; $i %= 2; + + print qq| + <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{description} = qq|<td>$ref->{description} </td>|; + + map { print "$column_data{$_}\n" } @column_index; + + print " + </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=$form->{type}> + +<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('Add').qq|"> + +</body> +</html> +|; + +} + + +sub form_project_header { + + $form->{title} = $locale->text("$form->{title} Project"); + +# $locale->text('Add Project') +# $locale->text('Edit Project') + + $form->{description} =~ s/"/"/g; + + 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>|; + } 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=project> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Number').qq|</th> + <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Description').qq|</th> + <td>$description</td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan=2><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub form_project_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=password value=$form->{password}> + +<br><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|">|; + } + + print qq| +</form> + +</body> +</html> +|; + +} + + +sub save { + + if ($form->{type} eq 'project') { + $form->isblank("projectnumber", $locale->text('Project Number missing!')); + PE->save_project(\%myconfig, \%$form); + $form->redirect($locale->text('Project saved!')); + } + if ($form->{type} eq 'partsgroup') { + $form->isblank("partsgroup", $locale->text('Group missing!')); + PE->save_partsgroup(\%myconfig, \%$form); + $form->redirect($locale->text('Group saved!')); + } + +} + + +sub delete { + + 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!')); + } + +} + + +sub continue { &{ $form->{nextsub} } }; + + +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}"; + + if ($form->{status} eq 'all') { + $option = $locale->text('All'); + } + if ($form->{status} eq 'orphaned') { + $option .= $locale->text('Orphaned'); + } + if ($form->{partsgroup}) { + $callback .= "&partsgroup=$form->{partsgroup}"; + $option .= "\n<br>".$locale->text('Group')." : $form->{partsgroup}"; + } + + + @column_index = (partsgroup); + + $column_header{partsgroup} = qq|<th class=listheading width=90%>|.$locale->text('Group').qq|</th>|; + + $form->{title} = $locale->text('Groups'); + + $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{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>|; + + map { print "$column_data{$_}\n" } @column_index; + + print " + </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=$form->{type}> + +<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('Add').qq|"> + +</body> +</html> +|; + +} + + +sub form_partsgroup_header { + + $form->{title} = $locale->text("$form->{title} Group"); + +# $locale->text('Add Group') +# $locale->text('Edit Group') + + $form->{partsgroup} =~ s/"/"/g; + + + $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('Group').qq|</th> + <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan=2><hr size=3 noshade></td> + </tr> +</table> +|; + +} + + +sub form_partsgroup_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=password value=$form->{password}> + +<br><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|">|; + } + + print qq| +</form> + +</body> +</html> +|; + +} + + diff --git a/sql-ledger/bin/mozilla/rc.pl b/sql-ledger/bin/mozilla/rc.pl new file mode 100644 index 000000000..cf2bc235b --- /dev/null +++ b/sql-ledger/bin/mozilla/rc.pl @@ -0,0 +1,371 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 2002 +# +# 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. +#====================================================================== +# +# Account reconciliation module +# +#====================================================================== + + +use SL::RC; + + +1; +# end of main + + +sub reconciliation { + + RC->paymentaccounts(\%myconfig, \%$form); + + $selection = ""; + map { $selection .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR} }; + + $form->{title} = $locale->text('Reconciliation'); + + $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('Account').qq|</th> + <td colspan=3><select name=accno>$selection</select> + </td> + </tr> + <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> + <td><input name=todate size=11 title="$myconfig{dateformat}"></td> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<br> +<input type=hidden name=nextsub value=get_payments> + +<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=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub continue { &{ $form->{nextsub} } }; + + +sub get_payments { + + ($form->{accno}, $form->{account}) = split /--/, $form->{accno}; + + RC->payment_transactions(\%myconfig, \%$form); + + &display_form; + +} + + +sub display_form { + + @column_index = qw(cleared transdate source name credit debit balance); + + $column_header{cleared} = "<th class=listheading> </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>"; + + $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>"; + + if ($form->{fromdate}) { + $option .= "\n<br>" if ($option); + $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{fromdate}, 1); + } + if ($form->{todate}) { + $option .= "\n<br>" if ($option); + $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{todate}, 1); + } + + $form->{title} = "$form->{accno}--$form->{account}"; + + $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> +|; + + map { print "\n$column_header{$_}" } @column_index; + + print qq| + </tr> +|; + + $form->{beginningbalance} *= -1; + $clearedbalance = $balance = $form->{beginningbalance}; + $i = 0; + $id = 0; + + map { $column_data{$_} = "<td> </td>" } qw(cleared transdate source name debit credit); + $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>"; + $j = 0; + print qq| + <tr class=listrow$j> +|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + + foreach $ref (@{ $form->{PR} }) { + + $balance += $ref->{amount} * -1; + $cleared += $ref->{amount} * -1 if $ref->{cleared}; + + $column_data{name} = "<td>$ref->{name} </td>"; + $column_data{source} = qq|<td>$ref->{source} </a> + </td>|; + $column_data{transdate} = "<td>$ref->{transdate} </td>"; + + $column_data{debit} = "<td> </td>"; + $column_data{credit} = "<td> </td>"; + + 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>|; + } 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>|; + } + $id = $ref->{id}; + + $j++; $j %= 2; + print qq| + <tr class=listrow$j> +|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + } + + # print totals + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, " ")."</th>"; + $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, " ")."</th>"; + + print qq| + <tr class=listtotal> +|; + + 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); + + $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> + <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> + <td align=right> + <table> + <tr> + <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th> + <td width=10%></td> + <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td> + </tr> + <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> + <input type=hidden name=difference value=$difference> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=rowcount value=$i> +<input type=hidden name=accno value=$form->{accno}> +<input type=hidden name=account value="$form->{account}"> + +<input type=hidden name=fromdate value=$form->{fromdate}> +<input type=hidden name=todate value=$form->{todate}> + +<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('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|"> + +</form> + +</body> +</html> +|; + +} + + +sub update { + + RC->payment_transactions(\%myconfig, \%$form); + + foreach $ref (@{ $form->{PR} }) { + if (!$ref->{fx_transaction}) { + $i++; + $ref->{cleared} = "checked" if $form->{"cleared_$i"}; + } + } + + &display_form; + +} + + +sub select_all { + + RC->payment_transactions(\%myconfig, \%$form); + + map { $_->{cleared} = "checked" unless $_->{fx_transaction} } @{ $form->{PR} }; + + &display_form; + +} + + +sub done { + + $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&password=$form->{password}"; + + $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1); + + RC->reconcile(\%myconfig, \%$form); + $form->redirect; + +} + + diff --git a/sql-ledger/bin/mozilla/rp.pl b/sql-ledger/bin/mozilla/rp.pl new file mode 100644 index 000000000..41cff8cf0 --- /dev/null +++ b/sql-ledger/bin/mozilla/rp.pl @@ -0,0 +1,1730 @@ +#===================================================================== +# SQL-Ledger Accounting +# Copyright (c) 1998-2002 +# +# Author: Dieter Simader +# Email: dsimader@sql-ledger.org +# Web: http://www.sql-ledger.org +# +# Contributors: Antonio Gallardo <agssa@ibw.com.ni> +# Benjamin Lee <benjaminlee@consultant.com> +# +# 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. +#====================================================================== +# +# module for preparing Income Statement and Balance Sheet +# +#====================================================================== + + +use SL::RP; + +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') + +# $locale->text('Balance Sheet') +# $locale->text('Income Statement') +# $locale->text('Trial Balance') +# $locale->text('AR Aging') +# $locale->text('AP Aging') +# $locale->text('Tax collected') +# $locale->text('Tax paid') +# $locale->text('Receipts') +# $locale->text('Payments') + + +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', + ); + + $form->{title} = $locale->text($title{$form->{report}}); + + $form->header; + + $gifi = qq| +<tr> + <th align=right>|.$locale->text('Accounts').qq|</th> + <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq| + + <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq| + </td> +</tr> +|; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<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> +|; + + if ($form->{report} eq "income_statement") { + print qq| + <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> + <td><input name=todate size=11 title="$myconfig{dateformat}"></td> + </tr> + <tr> + <th colspan=4>|.$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> + <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Decimalplaces').qq|</th> + <td><input name=decimalplaces size=3 maxsize=1></td> + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table> + <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> + </tr> +|; + } + + + if ($form->{report} eq "balance_sheet") { + print qq| + <input type=hidden name=nextsub value=generate_balance_sheet> + <tr> + <th align=right>|.$locale->text('as at').qq|</th> + <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td> + <th align=right nowrap>|.$locale->text('Compare to').qq|</th> + <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td> + </tr> + <tr> + <th align=right>|.$locale->text('Decimalplaces').qq|</th> + <td><input name=decimalplaces size=3 maxsize=1></td> + </tr> + </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|</td> + <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td> + </tr> +|; + } + + + if ($form->{report} eq "trial_balance") { + print qq| + <input type=hidden name=nextsub value=generate_trial_balance> + <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> + </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 "tax_paid") || ($form->{report} eq "tax_collected")) { + $gifi = ""; + + $form->{db} = ($form->{report} eq "tax_collected") ? "ar" : "ap"; + + RP->get_taxaccounts(\%myconfig, \%$form); + + print qq| + <input type=hidden name=nextsub value=generate_tax_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> + <tr> + <th align=right>|.$locale->text('Cash based').qq|</th> + <td><input name=cashbased class=checkbox type=checkbox value=Y></td> + </tr> + <tr> + <th align=right>|.$locale->text('Report for').qq|</th> + <td> +|; + + $checked = "checked"; + foreach $item (@{ $form->{taxaccounts} }) { + ($accno, $description) = split /--/, $item; + + print qq|<input name=accno class=radio type=radio value=$accno $checked> $description + + <input name="${accno}_description" type=hidden value="$description">|; + + $checked = ""; + } + + print qq| + <input type=hidden name=db value=$form->{db}> + <input type=hidden name=sort value=transdate> + + </td> + </tr> +|; + + + if (@{ $form->{gifi_taxaccounts} }) { + print qq| + <tr> + <th align=right>|.$locale->text('GIFI').qq|</th> + <td> +|; + + foreach $item (@{ $form->{gifi_taxaccounts} }) { + ($accno, $description) = split /--/, $item; + + print qq|<input name=accno class=radio type=radio value="gifi_$accno" $checked> $description + + <input name="gifi_${accno}_description" type=hidden value="$description">|; + + } + + print qq| + </td> + </tr> +|; + } + + +print qq| + </table> + </td> + </tr> + <tr> + <td> + <table> + <tr> + <th align=right>|.$locale->text('Include in Report').qq|</th> + <td> + <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> + <td>|; + + if ($form->{db} eq 'ar') { + print $locale->text('Customer'); + } + if ($form->{db} eq 'ap') { + print $locale->text('Vendor'); + } + + print 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>|.$locale->text('Total').qq|</td> + </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} eq "ar_aging") || ($form->{report} eq "ap_aging")) { + $gifi = ""; + + if ($form->{report} eq 'ar_aging') { + $label = $locale->text('Customer'); + $form->{vc} = 'customer'; + } else { + $label = $locale->text('Vendor'); + $form->{vc} = 'vendor'; + } + + $nextsub = "generate_$form->{report}"; + + # setup vc selection + $form->all_vc(\%myconfig, $form->{vc}); + + map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} }; + + $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|; + + print qq| + <tr> + <th align=right>|.$locale->text($label).qq|</th> + <td>$vc</td> + </tr> + <tr> + <th align=right>|.$locale->text('to').qq|</th> + <td><input name=todate size=11 title="$myconfig{dateformat}"></td> + </tr> + <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=nextsub value=$nextsub> + <input type=hidden name=action value=$nextsub> +|; + } + +# above action can be removed if there is more than one input field + + + if (($form->{report} eq "receipts") || ($form->{report} eq "payments")) { + $gifi = ""; + + $form->{db} = ($form->{report} eq "receipts") ? "ar" : "ap"; + + RP->paymentaccounts(\%myconfig, \%$form); + + $selection = "<option>\n"; + foreach $ref (@{ $form->{PR} }) { + $paymentaccounts .= "$ref->{accno} "; + $selection .= "<option>$ref->{accno}--$ref->{description}\n"; + } + + chop $paymentaccounts; + + print qq| + <input type=hidden name=nextsub value=list_payments> + <tr> + <th align=right nowrap>|.$locale->text('Account').qq|</th> + <td colspan=3><select name=account>$selection</select> + <input type=hidden name=paymentaccounts value="$paymentaccounts"> + </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> + <td><input name=todate size=11 title="$myconfig{dateformat}"></td> + </tr> + <input type=hidden name=db value=$form->{db}> + <input type=hidden name=sort value=transdate> +|; + + } + + + print qq| + +$gifi + + </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=password value=$form->{password}> + +<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|"> + +</form> + +</body> +</html> +|; + +} + + +sub continue { &{$form->{nextsub}} }; + + +sub generate_income_statement { + + $form->{padding} = " "; + $form->{bold} = "<b>"; + $form->{endbold} = "</b>"; + $form->{br} = "<br>"; + + RP->income_statement(\%myconfig, \%$form); + + + $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1); + $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate}; + + # if there are any dates construct a where + if ($form->{fromdate} || $form->{todate}) { + + unless ($form->{todate}) { + $form->{todate} = $form->current_date(\%myconfig); + } + + $longtodate = $locale->date(\%myconfig, $form->{todate}, 1); + $shorttodate = $locale->date(\%myconfig, $form->{todate}); + + $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); + $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}); + + $form->{this_period} = "$shortfromdate<br>\n$shorttodate"; + $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}); + + $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1); + $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}); + + $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate"; + $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('to').qq| $longcomparetodate|; + } + + + # setup variables for the form + @a = qw(company address businessnumber); + map { $form->{$_} = $myconfig{$_} } @a; + $form->{address} =~ s/\\n/<br>/g; + + $form->{templates} = $myconfig{templates}; + + $form->{IN} = "income_statement.html"; + + $form->parse_template; + +} + + +sub generate_balance_sheet { + + $form->{padding} = " "; + $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 + $padding = ($form->{l_heading}) ? $form->{padding} : ""; + push(@{$form->{equity_account}}, $padding.$locale->text('Retained Earnings')); + + $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}); + $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}); + + $form->{IN} = "balance_sheet.html"; + + # setup company variables for the form + map { $form->{$_} = $myconfig{$_} } (qw(company address businessnumber nativecurr)); + $form->{address} =~ s/\\n/<br>/g; + + $form->{templates} = $myconfig{templates}; + + $form->parse_template; + +} + + +# Antonio Gallardo +# +# D.S. Feb 16, 2001 +# included links to display transactions for period entered +# added headers and subtotals +# +sub generate_trial_balance { + + # get for each account initial balance, debits and credits + RP->trial_balance_details(\%myconfig, \%$form); + + $form->{nextsub} = "generate_trial_balance"; + $form->{title} = $locale->text('Trial Balance'); + &list_accounts; + +} + + +sub list_accounts { + + $title = $form->escape($form->{title}); + + if ($form->{projectnumber}) { + $options .= $locale->text('Project Number')." : $form->{projectnumber}<br>"; + $projectnumber = $form->escape($form->{projectnumber}); + } + + # if there are any dates + if ($form->{fromdate} || $form->{todate}) { + if ($form->{fromdate}) { + $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); + } + if ($form->{todate}) { + $todate = $locale->date(\%myconfig, $form->{todate}, 1); + } + + $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); + + $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|; + $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').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{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|; + $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|; + + + if ($form->{accounttype} eq 'gifi') { + $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|; + } + + + $form->header; + + print qq| +<body> + +<table width=100%> + <tr> + <th class=listtop>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td>$options</td> + </tr> + <tr> + <td> + <table width=100%> + <tr>|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| + </tr> +|; + + + + # sort the whole thing by account numbers and display + foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) { + + $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}|; + + if ($form->{accounttype} eq 'gifi') { + $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description"; + $na = $locale->text('N/A'); + map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno}; + } else { + $href .= "&accno=$ref->{accno}&description=$description"; + } + + $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1; + + $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, " "); + $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, " "); + $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> +|; + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + } + + if ($ref->{charttype} eq "H") { + $subtotal = 1; + $subtotaldescription = $ref->{description}; + $subtotaldebit = $ref->{debit}; + $subtotalcredit = $ref->{credit}; + $subtotalbegbalance = 0; + $subtotalendbalance = 0; + + next unless $form->{l_heading}; + + map { $column_data{$_} = "<th> </th>" } qw(accno debit credit begbalance endbalance); + $column_data{description} = "<th class=listheading>$ref->{description}</th>"; + } + + if ($ref->{charttype} eq "A") { + $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>"; + $column_data{description} = "<td>$ref->{description}</td>"; + $column_data{debit} = "<td align=right>$debit</td>"; + $column_data{credit} = "<td align=right>$credit</td>"; + $column_data{begbalance} = "<td align=right>$begbalance</td>"; + $column_data{endbalance} = "<td align=right>$endbalance</td>"; + + $totaldebit += $ref->{debit}; + $totalcredit += $ref->{credit}; + + $subtotalbegbalance += $ref->{balance} * $ml; + $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml; + + } + + if ($ref->{charttype} eq "H") { + print qq| + <tr class=listheading> +|; + } + if ($ref->{charttype} eq "A") { + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + } + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + } + + + # print last subtotal + if ($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>$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>"; + + print qq| + <tr class=listsubtotal> +|; + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + } + + $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, " "); + $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, " "); + + map { $column_data{$_} = "<th> </th>" } qw(accno description begbalance endbalance); + + $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|; + $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|; + + print qq| + <tr class=listtotal> +|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +</body> +</html> +|; + +} + + + +sub generate_ar_aging { + + # split customer + ($form->{customer}) = split(/--/, $form->{customer}); + + $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); + &aging; + +} + + +sub generate_ap_aging { + + # split vendor + ($form->{vendor}) = split(/--/, $form->{vendor}); + + $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); + &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{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_index = (qw(statement ct invnumber transdate duedate c0 c30 c60 c90)); + + + if ($form->{arap} eq 'ar') { + if ($form->{customer}) { + $option .= "\n<br>" if $option; + $option .= $form->{customer}; + } + } + if ($form->{arap} eq 'ap') { + shift @column_index; + if ($form->{vendor}) { + $option .= "\n<br>" if $option; + $option .= $form->{vendor}; + } + } + + $todate = $locale->date(\%myconfig, $form->{todate}, 1); + $option .= "\n<br>" if $option; + $option .= $locale->text('for Period')." ".$locale->text('to')." $todate"; + + 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 "$column_header{$_}\n" } @column_index; + + print qq| + </tr> +|; + + + $ctid = 0; + $subtotal = 0; + $i = 0; + + foreach $ref (@{ $form->{AG} }) { + + 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|<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> +|; + } + + $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>|; + } + + $c0subtotal += $ref->{c0}; + $c30subtotal += $ref->{c30}; + $c60subtotal += $ref->{c60}; + $c90subtotal += $ref->{c90}; + + $c0total += $ref->{c0}; + $c30total += $ref->{c30}; + $c60total += $ref->{c60}; + $c90total += $ref->{c90}; + + $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, " "); + $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}); + + $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>|; + + $j++; $j %= 2; + print qq| + <tr class=listrow$j> +|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + + $column_data{ct} = qq|<td> </td>|; + $column_data{statement} = qq|<td> </td>|; + + $ctid = $ref->{ctid}; + + } + + # 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> +|; + + 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>|; + + map { print "$column_data{$_}\n" } @column_index; + + + print qq| + </tr> + <tr class=listtotal> +|; + + $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>|; + + + map { print "$column_data{$_}\n" } @column_index; + + + print qq| + <input type=hidden name=rowcount value=$i> + </tr> + </table> + </td> + </tr> + <tr> + <td> +|; + + &print_options if ($form->{arap} eq 'ar'); + + print qq| + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> +|; + + if ($form->{arap} eq 'ar') { + print qq| +<input type=hidden name=todate value=$form->{todate}> + +<input type=hidden name=title value="$form->{title}"> + +<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=path value=$form->{path}> +<input type=hidden name=login value=$form->{login}> +<input type=hidden name=password value=$form->{password}> + +<br> +<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('E-mail').qq|"> +|; + } + + print qq| +</form> + +</body> +</html> +|; + +} + + +sub select_all { + + RP->aging(\%myconfig, \%$form); + + map { $_->{checked} = "checked" } @{ $form->{AG} }; + + &aging; + +} + + +sub print_options { + + $form->{sendmode} = "attachment"; + $form->{copies} = 2 unless $form->{copies}; + + $form->{PD}{$form->{type}} = "checked"; + $form->{DF}{$form->{format}} = "checked"; + $form->{OP}{$form->{media}} = "checked"; + $form->{SM}{$form->{sendmode}} = "checked"; + + + 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> +|; + } else { + $screen = qq| + <td><input class=radio type=radio name=media value=screen $form->{OP}{screen}></td> + <td>|.$locale->text('Screen').qq|</td> +|; + } + + 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> +|; + + 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> +|; + } + + print qq| + $screen +|; + + 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> +|; + } + } + + print qq| + $email + </tr> +</table> +|; + +} + + +sub e_mail { + + # get name and email addresses + for $i (1 .. $form->{rowcount}) { + if ($form->{"statement_$i"}) { + $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"}; + RP->get_customer(\%myconfig, \%$form); + $selected = 1; + last; + } + } + + $form->error($locale->text('Nothing selected!')) unless $selected; + + if ($myconfig{admin}) { + $bcc = qq| + <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th> + <td><input name=bcc size=30 value="$form->{bcc}"></td> +|; + } + + $title = $locale->text('E-mail Statement to')." $form->{$form->{ct}}"; + + $form->{media} = "email"; + + $form->header; + + print qq| +<body> + +<form method=post action=$form->{script}> + +<table width=100%> + <tr class=listtop> + <th class=listtop>$title</th> + </tr> + <tr height="5"></tr> + <tr> + <td> + <table width=100%> + <tr> + <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> + </tr> + <tr> + <th align=right nowrap>|.$locale->text('Subject').qq|</th> + <td><input name=subject size=30 value="$form->{subject}"></td> + $bcc + </tr> + </table> + </td> + </tr> + <tr> + <td> + <table width=100%> + <tr> + <th align=left nowrap>|.$locale->text('Message').qq|</th> + </tr> + <tr> + <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td> + </tr> + </table> + </td> + </tr> + <tr> + <td> +|; + + &print_options; + + map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format); + + # save all other variables + foreach $key (keys %$form) { + $form->{$key} =~ s/"/"/g; + print qq|<input type=hidden name=$key value="$form->{$key}">\n|; + } + + print qq| + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +<input type=hidden name=nextsub value=send_email> + +<br> +<input name=action class=submit type=submit value="|.$locale->text('Continue').qq|"> +</form> + +</body> +</html> +|; + +} + + +sub send_email { + + $form->{OUT} = "$sendmail"; + + $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject}; + + RP->aging(\%myconfig, \%$form); + + $form->{"statement_1"} = 1; + + &print_form; + + $form->redirect($locale->text('Statement sent to')." $form->{$form->{ct}}"); + +} + + + +sub print { + + if ($form->{media} eq 'printer') { + $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"}; + $selected = 1; + last; + } + } + + $form->error($locale->text('Nothing selected!')) unless $selected; + + + if ($form->{media} eq 'printer') { + $form->{OUT} = "| $myconfig{printer}"; + $form->{"$form->{ct}_id"} = ""; + } else { + $form->{"statement_1"} = 1; + } + + RP->aging(\%myconfig, \%$form); + + &print_form; + + $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} eq 'printer'); + +} + + +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; + $form->format_string(@a); + + $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/; + } + + $i = 0; + while (@{ $form->{AG} }) { + + $ref = shift @{ $form->{AG} }; + + if ($ctid != $ref->{ctid}) { + + $ctid = $ref->{ctid}; + $i++; + + 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}; + + map { $form->{$_} = () } qw(invnumber invdate duedate); + $form->{total} = 0; + foreach $item (qw(c0 c30 c60 c90)) { + $form->{$item} = (); + $form->{"${item}total"} = 0; + } + + &statement_details($ref); + + while ($ref) { + + if (scalar (@{ $form->{AG} }) > 0) { + # one or more left to go + if ($ctid == $form->{AG}->[0]->{ctid}) { + $ref = shift @{ $form->{AG} }; + &statement_details($ref); + # any more? + $ref = scalar (@{ $form->{AG} }); + } else { + $ref = 0; + } + } else { + # set initial ref to 0 + $ref = 0; + } + + } + + map { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) } (c0, c30, c60, c90, ""); + + $form->parse_template(\%myconfig, $userspath); + + } + } + } + +} + + +sub statement_details { + my ($ref) = @_; + + push @{ $form->{invnumber} }, $ref->{invnumber}; + push @{ $form->{invdate} }, $ref->{transdate}; + push @{ $form->{duedate} }, $ref->{duedate}; + + foreach $item (qw(c0 c30 c60 c90)) { + $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); + } + +} + + +sub generate_tax_report { + + RP->tax_report(\%myconfig, \%$form); + + $descvar = "$form->{accno}_description"; + $description = $form->escape($form->{$descvar}); + + # 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"; + + # construct callback + $callback = $href; + + + @columns = $form->sort_columns(qw(id transdate invnumber name netamount tax amount)); + + 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->{l_subtotal} eq 'Y') { + $callback .= "&l_subtotal=Y"; + $href .= "&l_subtotal=Y"; + } + + + # if there are any dates + if ($form->{fromdate} || $form->{todate}) { + if ($form->{fromdate}) { + $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1); + } + if ($form->{todate}) { + $todate = $locale->date(\%myconfig, $form->{todate}, 1); + } + + $form->{period} = "$fromdate - $todate"; + } else { + $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'; + } + + + $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{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|; + + + $form->header; + + print qq| +<body> + +<table width=100%> + <tr> + <th class=listtop colspan=$colspan>$form->{title}</th> + </tr> + <tr height="5"></tr> + <tr> + <td>$form->{period}</td> + </tr> + <tr> + <td> + <table width=100%> + <tr class=listheading> +|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| + </tr> +|; + + # add sort and escape callback + $callback = $form->escape($callback . "&sort=$form->{sort}"); + + if (@{ $form->{TR} }) { + $sameitem = $form->{TR}->[0]->{$form->{sort}}; + } + + foreach $ref (@{ $form->{TR} }) { + + $module = ($ref->{invoice}) ? $invoice : $arap; + + if ($form->{l_subtotal} eq 'Y') { + if ($sameitem ne $ref->{$form->{sort}}) { + &tax_subtotal; + $sameitem = $ref->{$form->{sort}}; + } + } + + $totalnetamount += $ref->{netamount}; + $totaltax += $ref->{tax}; + $ref->{amount} = $ref->{netamount} + $ref->{tax}; + + $subtotalnetamount += $ref->{netamount}; + $subtotaltax += $ref->{tax}; + + map { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); } qw(netamount tax amount); + + $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>|; + + map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(netamount tax amount); + + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + + map { print "$column_data{$_}\n" } @column_index; + + print qq| + </tr> +|; + + } + + if ($form->{l_subtotal} eq 'Y') { + &tax_subtotal; + } + + + map { $column_data{$_} = qq|<th> </th>| } @column_index; + + print qq| + </tr> + <tr class=listtotal> +|; + + $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " "); + $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " "); + $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " "); + + $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>|; + + map { print "$column_data{$_}\n" } @column_index; + + + print qq| + </tr> + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +</body> +</html> +|; + +} + + +sub tax_subtotal { + + map { $column_data{$_} = "<td> </td>" } @column_index; + + $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>"; + + $subtotalnetamount = 0; + $subtotaltax = 0; + + print qq| + <tr class=listsubtotal> +|; + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + +} + + + +sub list_payments { + + if ($form->{account}) { + ($form->{paymentaccounts}) = split /--/, $form->{account}; + } + + RP->payments(\%myconfig, \%$form); + + @columns = $form->sort_columns(qw(transdate invnumber name paid source)); + + # 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}); + + $form->{paymentaccounts} =~ s/ /%20/g; + $href .= "&paymentaccounts=$form->{paymentaccounts}"; + + + # construct callback + $form->{callback} = "$href&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{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>"; + + + if ($form->{fromdate}) { + $option .= "\n<br>" if ($option); + $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{fromdate}, 1); + } + if ($form->{todate}) { + $option .= "\n<br>" if ($option); + $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{todate}, 1); + } + + @column_index = @columns; + $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 "\n$column_header{$_}" } @column_index; + + print qq| + </tr> +|; + + + foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) { + + print qq| + <tr> + <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th> + </tr> +|; + + foreach $payment (@{ $form->{$ref->{id}} }) { + + $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|; + + + $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{source} = "<td>$payment->{source} </td>"; + + $subtotalpaid += $payment->{paid}; + $totalpaid += $payment->{paid}; + + $i++; $i %= 2; + print qq| + <tr class=listrow$i> +|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> +|; + + } + + # print subtotals + 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; + + } + + + # print total + map { $column_data{$_} = "<td> </td>" } @column_index; + + $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>"; + + print qq| + <tr class=listtotal> +|; + + map { print "\n$column_data{$_}" } @column_index; + + print qq| + </tr> + + </table> + </td> + </tr> + <tr> + <td><hr size=3 noshade></td> + </tr> +</table> + +</body> +</html> +|; + +} + + + |