|
From: <ka...@sp...> - 2001-10-10 06:51:49
|
Hello!
I have been working on customising SQL-ledger to work both as an accounting system and also as a school registration system. I have customised the "Customer" renamed and separated the (Sub search) in ct.pl & CT.pm to (sub s_student) & (sub_vendor) since it is used to search the customer and the vendor.
I was also advised to adjust the link from the menu.pl. However, when i try access the search page and the add page from the menu i get an "Internal server error". The error.log says it was due to a "Premature end of script". I have not managed to locate the script the server is meaning.
I have attached copies of the menu.pl, ct.pl & CT.pm so you can see the adjustments i made. Sir, i will appreciate any advise you can offer. My problem is i am not at all good at perl but i am tying to learn along the way. Otherwise i like the simple structure of SQL-ledger.
Thanks.
Kaziro E
THE MENU.PL, CT.PL & CT.PM FOLLOW BELOW::::
# MENU.PL
#######################################################################
use SL::Form;
$form = new Form;
if ($form->{action}) {
require("$userspath/$form->{login}.conf");
map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset);
$locale = new Locale $myconfig{countrycode}, "menu";
if ($form->{stylesheet}) {
$form->{stylesheet} = qq|<link rel="stylesheet" href="$form->{stylesheet}" type="text/css" title="SQL-Ledger style sheet">|;
}
if ($form->{charset}) {
$form->{charset} = qq|<meta http-equiv="charset" content="$form->{charset}">|;
}
&{ $form->{action} };
} else {
$form->error("action= not defined!");
}
# end of main
sub display {
$form->{title} = "SQL-Ledger, ".$locale->text('Version')." $version";
print qq|Content-type: text/html
<HEAD>
<TITLE>$form->{title}</TITLE>
$form->{charset}
$form->{stylesheet}
</HEAD>
<FRAMESET ROWS="*,35" BORDER="0">
<FRAMESET COLS="155,*" BORDER="0">
<FRAME NAME="acc_menu" SRC="$form->{script}?login=$form->{login}&action=acc_menu&path=$form->{path}">
<FRAME NAME="main_window" SRC="login.pl?login=$form->{login}&action=company_logo&path=$form->{path}">
</FRAMESET>
<FRAME NAME="bottom_menu" SRC="$form->{script}?login=$form->{login}&action=bottom_menu&path=$form->{path}" SCROLL="no">
</FRAMESET>
|;
}
sub acc_menu {
foreach $item (split /;/, $myconfig{acs}) {
$excl{$item} = 1;
}
@menuorder = ('AR--AR', 'AR--Add_Transaction', 'AR--Receipts', 'AR--Reports', 'AR--AR_Aging', 'AR--Add_Customer', 'AR--Search_Customer', 'AR--Customer_Invoice');
$menu{'AR--AR'} = qq|<p><b>|.$locale->text('AR').qq|</b>|;
$menu{'AR--Add_Transaction'} = qq|<li><a href=ar.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Add Transaction').qq|</a>|;
$menu{'AR--Reports'} = qq|<li><a href=ar.pl?path=$form->{path}&action=search&nextsub=ar_transactions&login=$form->{login} target=main_window>|.$locale->text('Reports').qq|</a>|;
$menu{'AR--Add_Customer'} = qq|<li><a href=ct.pl?path=$form->{path}&action=add&db=customer&login=$form->{login} target=main_window>|.$locale->text('Add Student').qq|</a>|;
$menu{'AR--Search_Customer'} = qq|<li><a href=ct.pl?action=s_student&action=search&db=customer&login=$form->{login} target=main_window>|.$locale->text('Search Student').qq|</a>|;
$menu{'AR--Customer_Invoice'} = qq|<li><a href=is.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Student Invoice').qq|</a>|;
$menu{'AR--Receipts'} = qq|<li><a href=ar.pl?path=$form->{path}&action=search&nextsub=receipts&login=$form->{login} target=main_window>|.$locale->text('Receipts').qq|</a>|;
$menu{'AR--AR_Aging'} = qq|<li><a href=rp.pl?path=$form->{path}&action=report&title=AR%20Aging&login=$form->{login} target=main_window>|.$locale->text('AR Aging').qq|</a>|;
push @menuorder, ('AP--AP', 'AP--Add_Transaction', 'AP--Payments', 'AP--Reports', 'AP--AP_Aging', 'AP--Add_Vendor', 'AP--Search_Vendor', 'AP--Vendor_Invoice');
$menu{'AP--AP'} = qq|<p><b>|.$locale->text('AP').qq|</b>|;
$menu{'AP--Add_Transaction'} = qq|<li><a href=ap.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Add Transaction').qq|</a>|;
$menu{'AP--Reports'} = qq|<li><a href=ap.pl?path=$form->{path}&action=search&nextsub=ap_transactions&login=$form->{login} target=main_window>|.$locale->text('Reports').qq|</a>|;
$menu{'AP--Add_Vendor'} = qq|<li><a href=ct.pl?path=$form->{path}&action=add&db=vendor&login=$form->{login} target=main_window>|.$locale->text('Add Vendor').qq|</a>|;
$menu{'AP--Search_Vendor'} = qq|<li><a href=ct.pl?action=s_vendor&action=search&db=vendor&login=$form->{login} target=main_window>|.$locale->text('Search Vendor').qq|</a>|;
$menu{'AP--Vendor_Invoice'} = qq|<li><a href=ir.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Vendor Invoice').qq|</a>|;
$menu{'AP--Payments'} = qq|<li><a href=ap.pl?path=$form->{path}&action=search&nextsub=payments&login=$form->{login} target=main_window>|.$locale->text('Payments').qq|</a>|;
$menu{'AP--AP_Aging'} = qq|<li><a href=rp.pl?path=$form->{path}&action=report&title=AP%20Aging&login=$form->{login} target=main_window>|.$locale->text('AP Aging').qq|</a>|;
push @menuorder, ('General_Ledger--General_Ledger', 'General_Ledger--Add_Transaction', 'General_Ledger--Reports');
$menu{'General_Ledger--General_Ledger'} = qq|<p><b>|.$locale->text('General Ledger').qq|</b>|;
$menu{'General_Ledger--Add_Transaction'} = qq|<li><a href=gl.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Add Transaction').qq|</a>|;
$menu{'General_Ledger--Reports'} = qq|<li><a href=gl.pl?path=$form->{path}&action=search&login=$form->{login} target=main_window>|.$locale->text('Reports').qq|</a>|;
push @menuorder, ('Inventory--Inventory', 'Inventory--Add_Part', 'Inventory--Add_Service', 'Inventory--Add_Assembly', 'Inventory--Reports', 'Inventory--Merchandise_Received', 'Inventory--Stock_Assembly');
$menu{'Inventory--Inventory'} = qq|<p><b>|.$locale->text('Inventory').qq|</b>|;
$menu{'Inventory--Add_Part'} = qq|<li><a href=ic.pl?path=$form->{path}&action=add&item=part&login=$form->{login} target=main_window>|.$locale->text('Add Part').qq|</a>|;
$menu{'Inventory--Add_Service'} = qq|<li><a href=ic.pl?path=$form->{path}&action=add&item=service&login=$form->{login} target=main_window>|.$locale->text('Add Service').qq|</a>|;
$menu{'Inventory--Add_Assembly'} = qq|<li><a href=ic.pl?path=$form->{path}&action=add&item=assembly&login=$form->{login} target=main_window>|.$locale->text('Add Assembly').qq|</a>|;
$menu{'Inventory--Reports'} = qq|<li><a href=ic.pl?path=$form->{path}&action=search&login=$form->{login} target=main_window>|.$locale->text('Reports').qq|</a>|;
$menu{'Inventory--Merchandise_Received'} = qq|<li><a href=ir.pl?path=$form->{path}&action=add&login=$form->{login} target=main_window>|.$locale->text('Merchandise Received').qq|</a>|;
$menu{'Inventory--Stock_Assembly'} = qq|<li><a href=is.pl?path=$form->{path}&action=stock_assembly&login=$form->{login} target=main_window>|.$locale->text('Stock Assembly').qq|</a>|;
push @menuorder, ('Reports--Reports', 'Reports--Chart_of_Accounts', 'Reports--Trial_Balance', 'Reports--Income_Statement', 'Reports--Balance_Sheet');
$menu{'Reports--Reports'} = qq|<p><b>|.$locale->text('Reports').qq|</b>|;
$menu{'Reports--Chart_of_Accounts'} = qq|<li><a href=ca.pl?path=$form->{path}&login=$form->{login} target=main_window>|.$locale->text('Chart of Accounts').qq|</a>|;
$menu{'Reports--Trial_Balance'} = qq|<li><a href=rp.pl?path=$form->{path}&action=report&title=Trial%20Balance&login=$form->{login} target=main_window>|.$locale->text('Trial Balance').qq|</a>|;
$menu{'Reports--Income_Statement'} = qq|<li><a href=rp.pl?path=$form->{path}&action=report&title=Income%20Statement&login=$form->{login} target=main_window>|.$locale->text('Income Statement').qq|</a>|;
$menu{'Reports--Balance_Sheet'} = qq|<li><a href=rp.pl?path=$form->{path}&action=report&title=Balance%20Sheet&login=$form->{login} target=main_window>|.$locale->text('Balance Sheet').qq|</a>|;
$form->{title} = $locale->text('Accounting Menu');
print qq|Content-type: text/html
<head>
<title>$form->{title}</title>
$form->{charset}
$form->{stylesheet}
</head>
<body bgcolor="#FBFFE7">
<font size=-1>
<b>$form->{title}</b>
<p>
|;
map { print $menu{$_} unless $excl{$_} } @menuorder;
}
sub bottom_menu {
print qq'Content-type: text/html
<head>
<title>bottom_menu</title>
$form->{charset}
$form->{stylesheet}
</head>
<body bgcolor="#FBFFE7">
<table width=100% border=0>
<tr>
<td width=30%>
<b>$myconfig{name}</b>
</td>
<td width=60% align=center>|
<a href=$form->{script}?path=$form->{path}&action=acc_menu&login=$form->{login} target=acc_menu>'.$locale->text('Accounting').qq'</a> |
<a href=login.pl?path=$form->{path}&action=company_logo&login=$form->{login} target=main_window>'.$locale->text('Version').qq'</a> |
<a href=mailto:dsimader\@sql-ledger.org?subject=SQL-Ledger%20$version%20/%20Bug%20Report>'.$locale->text('Bug Report').qq'</a> |
</td>
<td width=10% align=right>';
unless ($myconfig{acs} =~ /Setup--Setup/) {
print qq'
<a href=am.pl?path=$form->{path}&action=setup_menu&login=$form->{login} target=acc_menu>'.$locale->text('Setup').qq'</a>';
}
print qq'
</td>
</tr></table>
';
}
#======================================================================
#
# customer/vendor module
#
# CHANGE LOG:
# DS. 2000-07-04 Created
#
#======================================================================
use DBI;
use SL::Form;
use SL::CT;
$form = new Form;
if ($form->{action}) {
require("$userspath/$form->{login}.conf");
$myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset);
$locale = new Locale $myconfig{countrycode}, "ct";
&{ $locale->findsub($form->{action}) };
} else {
$form->error("action= not defined!");
}
# end of main
sub add {
$form->{title} = "Add";
$form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}";
CT->taxaccounts(\%myconfig, \%$form);
&{ "$form->{db}_header" };
&form_footer;
}
sub s_student {
$form->{title} = $locale->text("Search for " . ucfirst $form->{db});
# class=submit type=submit $locale->text('Search for Student')
# class=submit type=submit $locale->text('Search for Vendor')
$form->header;
print qq|
<h2>$form->{title}</h2>
<form method=post action=$form->{script}>
<input type=hidden name=db value=$form->{db}>
<table border=1>
<tr valign=top>
<td>
<table>
<tr>
<th align=right>|.$locale->text('Name').qq|</th><td><input name=name size=35></td>
<th align=right>|.$locale->text('ID number').qq|</th><td><input name=idnumber size=35></td>
<th align=right>|.$locale->text('Date of Birth').qq|</th><td><input name=dob size=35></td>
</tr>
<tr>
<th align=right>|.$locale->text('Class').qq|</th><td><input name=class size=35></td>
<th align=right>|.$locale->text('Club').qq|</th><td><input name=club size=35></td>
<th align=right>|.$locale->text('Society').qq|</th><td><input name=society size=35></td>
</tr>
<tr>
<th align=right>|.$locale->text('Father').qq|</th><td><input name=father size=35></td>
<th align=right>|.$locale->text('Mother').qq|</th><td><input name=mother size=35></td>
</tr>
<tr>
<th align=right>|.$locale->text('Include in Report').qq|</th>
<td>
<input name="l_name" class=checkbox type=checkbox value=Y checked> |.$locale->text('Name').qq|
<input name="l_idnumber" class=checkbox type=checkbox value=Y checked> |.$locale->text('ID no').qq|
<input name="l_address" class=checkbox type=checkbox value=Y> |.$locale->text('Address').qq|
<input name="l_father" class=checkbox type=checkbox value=Y checked> |.$locale->text('Father').qq|
<input name="l_mother" class=checkbox type=checkbox value=Y checked> |.$locale->text('Mother').qq|
<input name="l_phone" class=checkbox type=checkbox value=Y checked> |.$locale->text('Phone [Home]').qq|
<input name="l_cellular" class=checkbox type=checkbox value=Y checked> |.$locale->text('Phone [Cellular]').qq|
<input name="l_fax" class=checkbox type=checkbox value=Y> |.$locale->text('Fax').qq|
<input name="l_email" class=checkbox type=checkbox value=Y checked> |.$locale->text('E-mail').qq|
<input name="l_class" class=checkbox type=checkbox value=Y checked> |.$locale->text('Class').qq|
<input name="l_club" class=checkbox type=checkbox value=Y checked> |.$locale->text('Club').qq|
<input name="l_society" class=checkbox type=checkbox value=Y checked> |.$locale->text('Society').qq|
<input name="l_guardian" class=checkbox type=checkbox value=Y checked> |.$locale->text('Guardian').qq|
<input name="l_guardianphone" class=checkbox type=checkbox value=Y checked> |.$locale->text('Guardian [Tel]').qq|
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
<input type=hidden name=path value=$form->{path}>
<input type=hidden name=login value=$form->{login}>
<input class=submit type=submit name=action value="|.$locale->text('Search for ' . ucfirst $form->{db}).qq|">
</form>
<p>|.$locale->text("To display all $form->{db}s, leave fields blank").qq|
</body>
</html>
|;
}
# $locale->text('To display all customers, leave fields blank')
# $locale->text('To display all 0s, leave fields blank')
sub s_vendor {
$form->{title} = $locale->text("Search for " . ucfirst $form->{db});
# class=submit type=submit $locale->text('Search for Customer')
# class=submit type=submit $locale->text('Search for Vendor')
$form->header;
print qq|
<h2>$form->{title}</h2>
<form method=post action=$form->{script}>
<input type=hidden name=db value=$form->{db}>
<table border=1>
<tr valign=top>
<td>
<table>
<tr>
<th align=right>|.$locale->text('Company').qq|</th><td><input name=name size=35></td>
</tr>
<tr>
<th align=right>|.$locale->text('Contact').qq|</th><td><input name=contact size=35></td>
</tr>
<tr>
<th align=right>|.$locale->text('Include in Report').qq|</th>
<td>
<input name="l_name" class=checkbox type=checkbox value=Y checked> |.$locale->text('Name').qq|
<input name="l_address" class=checkbox type=checkbox value=Y> |.$locale->text('Address').qq|
<input name="l_contact" class=checkbox type=checkbox value=Y checked> |.$locale->text('Contact').qq|
<input name="l_phone" class=checkbox type=checkbox value=Y checked> |.$locale->text('Phone').qq|
<input name="l_fax" class=checkbox type=checkbox value=Y> |.$locale->text('Fax').qq|
<input name="l_email" class=checkbox type=checkbox value=Y checked> |.$locale->text('E-mail').qq|
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
<input type=hidden name=path value=$form->{path}>
<input type=hidden name=login value=$form->{login}>
<input class=submit type=submit name=action value="|.$locale->text('Search for ' . ucfirst $form->{db}).qq|">
</form>
<p>|.$locale->text("To display all $form->{db}s, leave fields blank").qq|
</body>
</html>
|;
}
# $locale->text('To display all customers, leave fields blank')
# $locale->text('To display all vendors, leave fields blank')
sub search_for_vendor {
&search_for_name;
}
sub search_for_name {
CT->search(\%myconfig, \%$form);
$callback = "$form->{script}?action=search_for_name&db=$form->{db}&path=$form->{path}&login=$form->{login}";
$href = "$form->{script}?action=search_for_name&db=$form->{db}&path=$form->{path}&login=$form->{login}&name=" . $form->escape($form->{name}) . "&contact=" . $form->escape($form->{contact});
@columns = $form->sort_columns(qw(name address contact phone fax email));
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->{name}) {
$callback .= "&name=$form->{name}";
}
if ($form->{contact}) {
$callback .= "&contact=$form->{contact}";
}
$callback = $form->escape($callback . "&sort=$form->{sort}");
$column_header{name} = qq|<th><a href=$href&sort=name><font color=ffffff>|.$locale->text('Name').qq|</a></th>|;
$column_header{address} = qq~<th><a href=$href&sort="addr1 || addr2 || addr3"><font color=ffffff>~.$locale->text('Address').qq|</a></th>|;
$column_header{contact} = qq|<th><a href=$href&sort=contact><font color=ffffff>|.$locale->text('Contact').qq|</a></th>|;
$column_header{phone} = qq|<th><a href=$href&sort=phone><font color=ffffff>|.$locale->text('Phone').qq|</a></th>|;
$column_header{fax} = qq|<th><a href=$href&sort=fax><font color=ffffff>|.$locale->text('Fax').qq|</a></th>|;
$column_header{email} = qq|<th><a href=$href&sort=email><font color=ffffff>|.$locale->text('E-mail').qq|</a></th>|;
# $locale->text('Customer List')
# $locale->text('Vendor List')
$form->{title} = $locale->text(ucfirst $form->{db} . " List");
$form->header;
print qq|
<h2>$form->{title}</h2>
<table border=1>
<tr bgcolor=336666>
|;
map { print "$column_header{$_}\n" } @column_index;
print qq|
</tr>
|;
foreach $ref (@{ $form->{CT} }) {
map { $column_data{$_} = "<td> $ref->{$_}</td>" } qw(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}&callback=$callback>$ref->{name}</td>";
$column_data{email} = ($ref->{email}) ? "<td><a href=mailto:$ref->{email}>$ref->{email}</a></td>" : "<td> </td>";
print "<tr>";
map { print "$column_data{$_}\n" } @column_index;
print qq|</tr>|;
}
print qq|
</table>
<p>|.$locale->text("Click on $form->{db} name to edit").qq|
|;
# $locale->text('Click on customer name to edit')
# $locale->text('Click on vendor name to edit')
}
sub search_ for_customer {
&search_for_student;
}
sub search_for_student {
CT->search(\%myconfig, \%$form);
$callback = "$form->{script}?action=search_for_student&db=$form->{db}&path=$form->{path}&login=$form->{login}";
$href = "$form->{script}?action=search_for_student&db=$form->{db}&path=$form->{path}&login=$form->{login}&name=" . $form->escape($form->{name}) . "&idnumber=" . $form->escape($form->{idnumber}) . "&father=" . $form->escape($form->{father}) . "&mother=" . $form->escape($form->{mother}) . "&class=" . $form->escape($form->{class}) . "&club=" . $form->escape($form->{club}) . "&society=" . $form->escape($form->{society}) . "&dob=" . $form->escape($form->{dob}) . "&addr=" . $form->escape($form->{addr}) . "&guardian=" . $form->escape($form->{guardian}) . "&guardianphone=" . $form->escape($form->{guardianphone}) . "&phone=" . $form->escape($form->{phone});
@columns = $form->sort_columns(qw(ID-no name DOB Father Mother Address Phone Class Club Society Guardian Guardian-tel));
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->{name}) {
$callback .= "&name=$form->{name}";
}
if ($form->{father}) {
$callback .= "&contact=$form->{father}";
}
if ($form->{mother}) {
$callback .= "&name=$form->{mother}";
}
if ($form->{idnumber}) {
$callback .= "&contact=$form->{idnumber}";
}
if ($form->{dob}) {
$callback .= "&name=$form->{dob}";
}
if ($form->{class}) {
$callback .= "&contact=$form->{class}";
}
if ($form->{club}) {
$callback .= "&name=$form->{club}";
}
if ($form->{society}) {
$callback .= "&contact=$form->{society}";
}
$callback = $form->escape($callback . "&sort=$form->{sort}");
$column_header{idnumber} = qq|<th><a href=$href&sort=name><font color=ffffff>|.$locale->text('ID-no.').qq|</a></th>|;
$column_header{name} = qq~<th><a href=$href&sort="addr1 || addr2 || addr3"><font color=ffffff>~.$locale->text('Name').qq|</a></th>|;
$column_header{dob} = qq|<th><a href=$href&sort=contact><font color=ffffff>|.$locale->text('DOB').qq|</a></th>|;
$column_header{father} = qq|<th><a href=$href&sort=phone><font color=ffffff>|.$locale->text('Father').qq|</a></th>|;
$column_header{mother} = qq|<th><a href=$href&sort=fax><font color=ffffff>|.$locale->text('Mother').qq|</a></th>|;
$column_header{addr} = qq|<th><a href=$href&sort=email><font color=ffffff>|.$locale->text('Address').qq|</a></th>|;
$column_header{phone} = qq|<th><a href=$href&sort=name><font color=ffffff>|.$locale->text('Phone').qq|</a></th>|;
$column_header{class} = qq~<th><a href=$href&sort="addr1 || addr2 || addr3"><font color=ffffff>~.$locale->text('Class').qq|</a></th>|;
$column_header{club} = qq|<th><a href=$href&sort=contact><font color=ffffff>|.$locale->text('Club').qq|</a></th>|;
$column_header{society} = qq|<th><a href=$href&sort=phone><font color=ffffff>|.$locale->text('Society').qq|</a></th>|;
$column_header{guardian} = qq|<th><a href=$href&sort=fax><font color=ffffff>|.$locale->text('Guardian').qq|</a></th>|;
$column_header{guardianphone} = qq|<th><a href=$href&sort=email><font color=ffffff>|.$locale->text('Guardian-Tel').qq|</a></th>|;
# $locale->text('Customer List')
# $locale->text('Vendor List')
$form->{title} = $locale->text(ucfirst $form->{db} . " List");
$form->header;
print qq|
<h2>$form->{title}</h2>
<table border=1>
<tr bgcolor=336666>
|;
map { print "$column_header{$_}\n" } @column_index;
print qq|
</tr>
|;
foreach $ref (@{ $form->{CT} }) {
map { $column_data{$_} = "<td> $ref->{$_}</td>" } qw(ID-no Name DOB Father Mother Address phone Class Club Society Guardian Guardian-Tel);
$column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{name}</td>";
$column_data{email} = ($ref->{email}) ? "<td><a href=mailto:$ref->{email}>$ref->{email}</a></td>" : "<td> </td>";
print "<tr>";
map { print "$column_data{$_}\n" } @column_index;
print qq|</tr>|;
}
print qq|
</table>
<p>|.$locale->text("Click on $form->{db} name to edit").qq|
|;
# $locale->text('Click on customer name to edit')
# $locale->text('Click on vendor name to edit')
}
sub edit {
CT->get_tuple(\%myconfig, \%$form);
$form->{title} = "Edit";
# format discount
$form->{discount} *= 100;
&{ "$form->{db}_header" };
&form_footer;
}
sub customer_header {
# class=submit type=submit $locale->text('Add Customer')
# class=submit type=submit $locale->text('Edit Customer')
$tax = qq|<tr><th align=right>|.$locale->text('Taxable').qq|</th><td colspan=3>\n|;
foreach $item (split / /, $form->{taxaccounts}) {
if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
$tax .= qq|<input name="tax_$item" value=1 class=checkbox type=checkbox checked> <b>$form->{tax}{$item}{description}</b>\n|;
} else {
$tax .= qq|<input name="tax_$item" value=1 class=checkbox type=checkbox> <b>$form->{tax}{$item}{description}</b>\n|;
}
}
$tax .= qq|</td></tr>|;
$form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
$form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit});
$form->{title} = $locale->text("$form->{title} Customer");
$form->header;
print qq|
<h2>$form->{title}</h2>
<form method=post action=$form->{script}>
<table border=1>
<tr>
<td>
<table border=0>
<tr>
<th colspan=2>|.$locale->text('Student Info').qq|</th>
<th>|.$locale->text('School Info').qq|</th>
</tr>
<tr>
<th align=right>|.$locale->text('Student Name').qq|</th>
<td colspan=2><input name=name size=35 maxsize=35 value="$form->{name}"></td>
<th align=right>|.$locale->text('Class').qq|</th>
<td><input name=class size=35 maxsize=35 value="$form->{class}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('ID Number').qq|</th>
<td colspan=2><input name=idnumber size=35 maxsize=35 value="$form->{idnumber}"></td>
<th align=right>|.$locale->text('Club').qq|</th>
<td><input name=club size=35 maxsize=35 value="$form->{club}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Date of Birth').qq|</th>
<td colspan=2><input name=dob size=35 maxsize=35 value="$form->{dob}"></td>
<th align=right>|.$locale->text('Society').qq|</th>
<td><input name=society size=35 maxsize=35 value="$form->{society}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Home Address').qq|</th>
<td colspan=2><input name=addr size=35 maxsize=35 value="$form->{addr}"></td>
<th align=right>|.$locale->text('?????').qq|</th>
<td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('?????').qq|</th>
<td colspan=2><input name=addr4 size=35 maxsize=35 value="$form->{addr4}"></td>
<th align=right>|.$locale->text('?????').qq|</th>
<td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Parent [Father]').qq|</th>
<td><input name=father size=20 maxsize=35 value="$form->{father}"></td>
<td>
<th align=right>|.$locale->text('Parent [Mother]').qq|</th>
<input name=mother size=20 maxsize=35 value="$form->{mother}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Phone [Home]').qq|</th>
<td><input name=phone size=20 maxsize=20 value="$form->{phone}"></td>
<th align=right>|.$locale->text('Phone [Cellular]').qq|</th>
<td><input name=cellular size=20 maxsize=20 value="$form->{cellular}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Fax').qq|</th>
<td><input name=fax size=20 maxsize=20 value="$form->{fax}"></td>
<th align=right>|.$locale->text('Phone [Work]').qq|</th>
<td><input name=phonework size=20 maxsize=20 value="$form->{phonework}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('E-mail').qq|</th>
<td><input name=email size=25 value="$form->{email}"></td>
<td>
<input name=shiptoemail size=25 value="$form->{shiptoemail}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Guardian').qq|</th>
<td><input name=guardian size=25 value="$form->{guardian}"></td>
<td>
<th align=right>|.$locale->text('Guardian [Phone]').qq|</th>
<input name=guardianphone size=25 value="$form->{guardianphone}"></td>
</tr>
<tr>
<td colspan=4>
<b>|.$locale->text('Terms: Net').qq|</b> <input name=terms size=2 value="$form->{terms}">
<b>|.$locale->text('days').qq|</b> \|
<b>|.$locale->text('Credit Limit').qq|</b>
<input name=creditlimit size=9 value="$form->{creditlimit}">
<b>|.$locale->text('Discount').qq|</b>
<input name=discount size=4 value="$form->{discount}"> <b>%</b>
<b>|.$locale->text('Tax Included').qq|</b>
<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}>
</td>
</tr>
$tax
<tr valign=top>
<th align=right>|.$locale->text('Notes').qq|</th>
<td colspan=2 rowspan=3>
<textarea name=notes rows=3 cols=60>$form->{notes}</textarea>
</td>
</tr>
</table>
</td>
</tr>
|;
}
sub vendor_header {
$form->{title} = $locale->text("$form->{title} Vendor");
$tax = qq|<tr><th align=right>|.$locale->text('Taxable').qq|</th><td colspan=2>\n|;
foreach $item (split / /, $form->{taxaccounts}) {
if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
$tax .= qq|<input name="tax_$item" value=1 class=checkbox type=checkbox checked> <b>$form->{tax}{$item}{description}</b>\n|;
} else {
$tax .= qq|<input name="tax_$item" value=1 class=checkbox type=checkbox> <b>$form->{tax}{$item}{description}</b>\n|;
}
}
$tax .= qq|</td></tr>|;
$form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
$form->header;
# class=submit type=submit $locale->text('Add Vendor')
# class=submit type=submit $locale->text('Edit Vendor')
print qq|
<h2>$form->{title}</h2>
<form method=post action=$form->{script}>
<table border=1>
<tr>
<td>
<table border=0>
<tr>
<td colspan=2>
<input name=idnumber size=35 maxsize=35 value="$form->{idnumber}">
</td>
</tr>
<tr valign=top>
<td colspan=2>
<input name=name size=35 maxsize=35 value="$form->{name}">
</td>
</tr>
<tr>
<td colspan=2>
<input name=dob size=35 maxsize=35 value="$form->{dob}">
</td>
</tr>
<tr>
<td colspan=2>
<input name=addr size=35 maxsize=35 value="$form->{addr}">
</td>
</tr>
<tr>
<td colspan=2>
<input name=class size=35 maxsize=35 value="$form->{class}">
</td>
</tr>
<tr>
<th align=right>|.$locale->text('Father').qq|</th>
<td><input name=father size=20 maxsize=35 value="$form->{father}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Mother').qq|</th>
<td><input name=mother size=20 maxsize=35 value="$form->{mother}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Phone').qq|</th>
<td><input name=phone size=20 maxsize=20 value="$form->{phone}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('Fax').qq|</th>
<td><input name=fax size=20 maxsize=20 value="$form->{fax}"></td>
</tr>
<tr>
<th align=right>|.$locale->text('E-mail').qq|</th>
<td><input name=email size=25 value="$form->{email}"></td>
</tr>
<tr>
<td colspan=2><b>|.$locale->text('Terms: Net').qq|</b>
<input name=terms size=3 value=$form->{terms}> <b>days</b> \|
<b>|.$locale->text('Tax Included').qq|</b>
<input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}>
</td>
</tr>
$tax
<tr valign=top>
<th align=right>|.$locale->text('Notes').qq|</th>
<td colspan=2 rowspan=3>
<textarea name=notes rows=3 cols=60>$form->{notes}</textarea>
</td>
</tr>
</table>
</td>
</tr>
|;
}
sub form_footer {
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=callback value="$form->{callback}">
<input type=hidden name=db value=$form->{db}>
</table>
<input class=submit type=submit name=action value="|.$locale->text('Save ' . ucfirst $form->{db}).qq|">
|;
if ($form->{id}) {
print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete ' . ucfirst $form->{db}).qq|">|;
}
print "</form>";
# class=submit type=submit $locale->text('Save Student')
# class=submit type=submit $locale->text('Delete Student')
# class=submit type=submit $locale->text('Save Vendor')
# class=submit type=submit $locale->text('Delete Vendor')
}
sub delete_customer {
$rc = CT->delete_customer(\%myconfig, \%$form);
if ($rc == -1) {
$form->error($locale->text('Transactions exist, cannot delete student!'));
}
$form->isdeleted($rc);
}
sub save_customer {
$form->isblank("name", $locale->text("Student Name missing!"));
CT->save_customer(\%myconfig, \%$form);
$form->redirect;
}
sub save_vendor {
$form->isblank("name", $locale->text("Vendor Name missing!"));
CT->save_vendor(\%myconfig, \%$form);
$form->redirect;
}
sub delete_vendor {
$rc = CT->delete_vendor(\%myconfig, \%$form);
if ($rc == -1) {
$form->error($locale->text('Transactions exist, cannot delete vendor!'));
}
$form->isdeleted($rc);
}
#======================================================================
#
# backend code for customers and vendors
#
# CHANGE LOG:
# DS. 2000-07-04 Created
#
#======================================================================
package CT;
sub get_tuple {
my ($self, $myconfig, $form) = @_;
my $dbh = $form->dbconnect($myconfig);
my $query = qq|SELECT *
FROM $form->{db}
WHERE id = $form->{id}|;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
my $ref = $sth->fetchrow_hashref;
# copy to $form variables
foreach my $key (keys %$ref) {
$ref->{$key} =~ s/"/"/g;
$form->{$key} = $ref->{$key};
}
$sth->finish;
# get tax labels
$query = qq|SELECT accno, description
FROM chart
WHERE link LIKE '%CT_tax%'
AND chart.id = tax.chart_id
ORDER BY accno|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $taxref = $sth->fetchrow_hashref) {
$form->{taxaccounts} .= "$taxref->{accno} ";
$form->{tax}{$taxref->{accno}}{description} = $taxref->{description};
}
$sth->finish;
chop $form->{taxaccounts};
# get taxes for customer/vendor
$query = qq|SELECT chart_id, accno
FROM $form->{db}tax, chart
WHERE chart_id = chart.id
AND $form->{db}_id = $form->{id}|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $taxref = $sth->fetchrow_hashref) {
$form->{tax}{$taxref->{accno}}{taxable} = 1;
}
$sth->finish;
$dbh->disconnect;
}
sub taxaccounts {
my ($self, $myconfig, $form) = @_;
my $dbh = $form->dbconnect($myconfig);
# get tax labels
my $query = qq|SELECT accno, description
FROM chart
WHERE link LIKE '%CT_tax%'
AND chart.id = tax.chart_id
ORDER BY accno|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $taxref = $sth->fetchrow_hashref) {
$form->{taxaccounts} .= "$taxref->{accno} ";
$form->{tax}{$taxref->{accno}}{description} = $taxref->{description};
}
$sth->finish;
chop $form->{taxaccounts};
$dbh->disconnect;
}
sub delete_customer {
my ($self, $myconfig, $form) = @_;
# connect to database, turn AutoCommit off
my $dbh = $form->dbconnect_noauto($myconfig);
my $query = qq|SELECT id
FROM ar
WHERE customer = $form->{id}|;
my $sth = $dbh->prepare($query) || $form->dberror($query);
$sth->execute;
my ($rc) = $sth->fetchrow_array;
$sth->finish;
if ($rc) {
$dbh->disconnect;
$rc = -1;
} else {
# delete customer
$query = qq|DELETE FROM customer
WHERE id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
$query = qq|DELETE FROM customertax
WHERE customer_id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
# commit and redirect
$rc = $dbh->commit;
$dbh->disconnect;
}
$rc;
}
sub save_customer {
my ($self, $myconfig, $form) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
# escape '
map { $form->{$_} =~ s/'/\\'/g } qw(name idnumber dob addr addr4 father guardian notes class club society shiptoaddr3 shiptoaddr4 mother);
# assign value discount, terms, creditlimit
$form->{discount} /= 100;
$form->{terms} *= 1;
$form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
$form->{taxincluded} = ($form->{taxincluded}) ? TRUE : FALSE;
my $query;
if ($form->{id}) {
$query = qq|DELETE FROM customertax
WHERE customer_id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
} else {
# create unique id
my $uid = time;
$uid .= $form->{login};
$query = qq|INSERT INTO customer (name)
VALUES ('$uid')|;
$dbh->do($query) || $form->dberror($query);
$query = qq|SELECT id FROM customer
WHERE name = '$uid'|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
($form->{id}) = $sth->fetchrow_array;
$sth->finish;
}
$query = qq|UPDATE customer SET
name = '$form->{name}',
idnumber = '$form->{idnumber}',
dob = '$form->{dob}',
addr = '$form->{addr}',
addr4 = '$form->{addr4}',
father = '$form->{father}',
phone = '$form->{phone}',
fax = '$form->{fax}',
email = '$form->{email}',
guardian = '$form->{guardian}',
notes = '$form->{notes}',
discount = $form->{discount},
creditlimit = $form->{creditlimit},
terms = $form->{terms},
class = '$form->{class}',
club = '$form->{club}',
society = '$form->{society}',
shiptoaddr3 = '$form->{shiptoaddr3}',
shiptoaddr4 = '$form->{shiptoaddr4}',
mother = '$form->{mother}',
cellular = '$form->{cellular}',
phonework = '$form->{phonework}',
shiptoemail = '$form->{shiptoemail}',
guardianphone = '$form->{guardianphone}',
taxincluded = $form->{taxincluded}
WHERE id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
# save taxes
foreach $item (split / /, $form->{taxaccounts}) {
if ($form->{"tax_$item"}) {
$query = qq|INSERT INTO customertax (customer_id, chart_id)
VALUES ($form->{id}, (SELECT id
FROM chart
WHERE accno = '$item'))|;
$dbh->do($query) || $form->dberror($query);
}
}
$dbh->disconnect;
}
sub save_vendor {
my ($self, $myconfig, $form) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
# escape '
map { $form->{$_} =~ s/'/\\'/g } qw(name addr1 addr2 addr3 addr4 contact notes);
$form->{terms} *= 1;
$form->{taxincluded} = ($form->{taxincluded}) ? TRUE : FALSE;
my $query;
if ($form->{id}) {
$query = qq|DELETE FROM vendortax
WHERE vendor_id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
} else {
my $uid = time;
$uid .= $form->{login};
$query = qq|INSERT INTO vendor (name)
VALUES ('$uid')|;
$dbh->do($query) || $form->dberror($query);
$query = qq|SELECT id FROM vendor
WHERE name = '$uid'|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
($form->{id}) = $sth->fetchrow_array;
$sth->finish;
}
$query = qq|UPDATE vendor SET
name = '$form->{name}',
addr1 = '$form->{addr1}',
addr2 = '$form->{addr2}',
addr3 = '$form->{addr3}',
addr4 = '$form->{addr4}',
contact = '$form->{contact}',
phone = '$form->{phone}',
fax = '$form->{fax}',
email = '$form->{email}',
notes = '$form->{notes}',
terms = $form->{terms},
taxincluded = $form->{taxincluded}
WHERE id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
# save taxes
foreach $item (split / /, $form->{taxaccounts}) {
if ($form->{"tax_$item"}) {
$query = qq|INSERT INTO vendortax (vendor_id, chart_id)
VALUES ($form->{id}, (SELECT id
FROM chart
WHERE accno = '$item'))|;
$dbh->do($query) || $form->dberror($query);
}
}
$dbh->disconnect;
}
sub delete_vendor {
my ($self, $myconfig, $form) = @_;
# connect to database, turn AutoCommit off
my $dbh = $form->dbconnect_noauto($myconfig);
# check if there are any transactions on file
my $query = qq|SELECT id FROM ap
WHERE vendor = $form->{id}|;
my $sth = $dbh->prepare($query) || $form->dberror($query);
$sth->execute;
my ($rc) = $sth->fetchrow_array;
$sth->finish;
if ($rc) {
$dbh->disconnect;
$rc = -1;
} else {
# delete vendor
$query = qq|DELETE FROM vendor
WHERE id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
$query = qq|DELETE FROM vendortax
WHERE vendor_id = $form->{id}|;
$dbh->do($query) || $form->dberror($query);
# commit and redirect
$rc = $dbh->commit;
$dbh->disconnect;
}
$rc;
}
sub s_student {
my ($self, $myconfig, $form) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
my $where = "TRUE";
if ($form->{name}) {
my $name = lc $form->{name};
$where .= " AND lower(name) LIKE '%$name%'";
}
if ($form->{idnumber}) {
my $contact = lc $form->{idnumber};
$where .= " AND lower(idnumber) LIKE '%$idnumber%'";
}
if ($form->{father}) {
my $name = lc $form->{father};
$where .= " AND lower(father) LIKE '%$father%'";
}
if ($form->{mother}) {
my $contact = lc $form->{mother};
$where .= " AND lower(mother) LIKE '%$mother%'";
}
if ($form->{class}) {
my $name = lc $form->{class};
$where .= " AND lower(class) LIKE '%$class%'";
}
if ($form->{club}) {
my $contact = lc $form->{club};
$where .= " AND lower(club) LIKE '%$club%'";
}
my $query = qq~SELECT id, name, idnumber, dob,
father || ' ' || mother AS parent,
addr, phone, cellular, class, club, society, guardian, terms
FROM $form->{db}
WHERE $where
ORDER BY name~;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $ref = $sth->fetchrow_hashref) {
push @{ $form->{CT} }, $ref;
}
$sth->finish;
$dbh->disconnect;
}
sub s_vendor {
my ($self, $myconfig, $form) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
my $where = "TRUE";
if ($form->{name}) {
my $name = lc $form->{name};
$where .= " AND lower(name) LIKE '%$name%'";
}
if ($form->{contact}) {
my $contact = lc $form->{contact};
$where .= " AND lower(contact) LIKE '%$contact%'";
}
my $query = qq~SELECT id, name,
addr1 || ' ' || addr2 || ' ' || addr3 AS address,
contact, phone, fax, email, terms
FROM $form->{db}
WHERE $where
ORDER BY name~;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $ref = $sth->fetchrow_hashref) {
push @{ $form->{CT} }, $ref;
}
$sth->finish;
$dbh->disconnect;
}
1;
_________________________________________s_p_r_a_y_
Här börjar Internet!
Skaffa gratis e-mail och gratis Internet på http://www.spray.se
Ny chatt på Spray! Fartyget M/S Spray har anlänt till http://www.spray.se/ohoj
|