From f6c9088e16c4c083174dd1130ae58d213923cdef Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 15 Jul 2003 11:45:14 +0000 Subject: import of sql-ledger 2.0.8 --- sql-ledger/bin/mozilla/am.pl | 1051 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1051 insertions(+) create mode 100644 sql-ledger/bin/mozilla/am.pl (limited to 'sql-ledger/bin/mozilla/am.pl') 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| + + +
{script}> + +{id}> + + +{inventory_accno_id}> +{income_accno_id}> +{expense_accno_id}> +{fxgain_accno_id}> +{fxloss_accno_id}> + +{amount}> + + + + + + + + + + + + +
$form->{title}
+ + + + + + + + + + + + + +|; + + +if ($form->{charttype} eq "A") { + print qq| + + + + + + + + + + + + +|; +} + +print qq| + + + + +
|.$locale->text('Account Number').qq|{accno}>
|.$locale->text('Description').qq|
|.$locale->text('Account Type').qq| + + + + + +
 |.$locale->text('Asset').qq|\n
+  |.$locale->text('Liability').qq|\n
+  |.$locale->text('Equity').qq|\n
+  |.$locale->text('Income').qq|\n
+  |.$locale->text('Expense') + .qq|
+  |.$locale->text('Heading').qq|
+  |.$locale->text('Account') + .qq|
+
+ + + + + +
|.$locale->text('Is this a summary account to record').qq| + {AR}> |.$locale->text('AR') + .qq| {AP}> |.$locale->text('AP') + .qq| {IC}> |.$locale->text('Inventory') + .qq|
+
|.$locale->text('Include in drop-down menus').qq|
+ + + + + + + + + + + + + +
|.$locale->text('Receivables').qq||.$locale->text('Payables').qq||.$locale->text('Parts Inventory').qq||.$locale->text('Service Items').qq|
+ {AR_amount}> |.$locale->text('Income').qq|\n
+ {AR_paid}> |.$locale->text('Payment').qq|\n
+ {AR_tax}> |.$locale->text('Tax') + .qq| +
+ {AP_amount}> |.$locale->text('Expense/Asset').qq|\n
+ {AP_paid}> |.$locale->text('Payment').qq|\n
+ {AP_tax}> |.$locale->text('Tax') + .qq| +
+ {IC_sale}> |.$locale->text('Sales').qq|\n
+ {IC_cogs}> |.$locale->text('COGS').qq|\n
+ {IC_taxpart}> |.$locale->text('Tax') + .qq| +
+ {IC_income}> |.$locale->text('Income').qq|\n
+ {IC_expense}> |.$locale->text('Expense').qq|\n
+ {IC_taxservice}> |.$locale->text('Tax') + .qq| +
+
+ + + + + +
|.$locale->text('Include this account on the customer/vendor forms to flag customer/vendor as taxable?').qq| + {CT_tax}> |.$locale->text('Yes').qq|  +  |.$locale->text('No') + .qq| +
+
|.$locale->text('GIFI').qq|{gifi_accno}>
+

+|; + +} + + +sub form_footer { + + print qq| + + + +{path}> +{login}> +{password}> + +
+ +|; + + if ($form->{id}) { + print qq||; + } + + print qq| +
+ + + +|; + +} + + +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||.$locale->text('Account').qq||; + $column_header{gifi_accno} = qq||.$locale->text('GIFI').qq||; + $column_header{description} = qq||.$locale->text('Description').qq||; + $column_header{debit} = qq||.$locale->text('Debit').qq||; + $column_header{credit} = qq||.$locale->text('Credit').qq||; + $column_header{link} = qq||.$locale->text('Link').qq||; + + + $form->header; + $colspan = $#column_index + 1; + + print qq| + + + + + + +|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| + +|; + + # 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/:/
/og; + + if ($ca->{charttype} eq "H") { + print qq||; + + $column_data{accno} = qq||; + $column_data{gifi_accno} = qq||; + $column_data{description} = qq||; + $column_data{debit} = qq||; + $column_data{credit} = qq| |; + $column_data{link} = qq||; + + } else { + $i++; $i %= 2; + print qq| +|; + $column_data{accno} = qq||; + $column_data{gifi_accno} = qq||; + $column_data{description} = qq||; + $column_data{debit} = qq||; + $column_data{credit} = qq||; + $column_data{link} = qq||; + + } + + map { print "$column_data{$_}\n" } @column_index; + + print "\n"; + } + + print qq| + +
$form->{title}
{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno} $ca->{description}    
{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback&amount=$amount>$ca->{accno}{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback&amount=$amount>$ca->{gifi_accno} $ca->{description} $ca->{debit}$ca->{credit}$ca->{link} 

+ + + +|; + +} + + +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||.$locale->text('GIFI').qq||; + $column_header{description} = qq||.$locale->text('Description').qq||; + + + $form->header; + $colspan = $#column_index + 1; + + print qq| + + + + + + +|; + + map { print "$column_header{$_}\n" } @column_index; + + print qq| + +|; + + # escape callback + $callback = $form->escape($callback); + + foreach $ca (@{ $form->{ALL} }) { + + $i++; $i %= 2; + + print qq| +|; + + $column_data{accno} = qq||; + $column_data{description} = qq||; + + map { print "$column_data{$_}\n" } @column_index; + + print "\n"; + } + + print qq| + + + +
$form->{title}
{script}?action=edit_gifi&coa=1&accno=$ca->{accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}$ca->{description} 

+ + + +|; + +} + + +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| + + +
{script}> + +{accno}> + + + + + + + + + + + + + +
$form->{title}
+ + + + + + + + + +
|.$locale->text('GIFI').qq|{accno}>
|.$locale->text('Description').qq|
+

+|; + +} + + +sub gifi_footer { + + print qq| + + + +{path}> +{login}> +{password}> + +
+|; + + if ($form->{coa}) { + print qq| + +|; + + if ($form->{accno}) { + print qq||; + } + } + + print qq| +
+ + + +|; + +} + + +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} = "
\n$form->{body}\n
"; + } + + $form->header; + + print qq| + + +$form->{body} + +
{script}> + +{file}> + +{path}> +{login}> +{password}> + + +
+ + + + +|; + +} + + +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| + + +
{script}> + +{file}> + + +{path}> +{login}> +{password}> + + + + + +
+ + +
+ + + + +|; + +} + + +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}) ? "