CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Existing Database, Need to Insert Blank Invoice

 



2oldchap
New User

Sep 8, 2010, 9:10 PM

Post #1 of 1 (1416 views)
Existing Database, Need to Insert Blank Invoice Can't Post

I have an existing form to Find an invoice (FindInvoice). is for a pos and it has 5 registers. Would like to be able to select the register, then I would like to be able to insert a blank invoice for a day or a range of days with the new form (CreateInvoice)

*******FindInvoice********

#!/usr/bin/perl -I../../lib

use pos;

$rn = $q->param('Reg') || 0;
$un = $q->param('User') || 0;
$xx = $q->param('Type');
$yy = $q->param('Return') || 0;
$date = parseDate($q->param('date'));

$N = nRegs;

print p_header('Find Invoice');

unless ($date) {
print <<__EOT;
<form method=post action='FindInvoice'>
<table width='100%'>
<tr><td>Date:</td>
<td><input type=text name='date' id='date' size='16' value='' onblur='parseDate("date")' />
<input type=button value='...' onclick="calendar('date');"></td>
<td></td><td></td><td><input type=submit></td></tr>
<tr><td>Register:</td>
<td><select name='Reg'><option value='0'>All Registers
__EOT
for ($i = 1; $i <= $N; $i++) {print "<option value='$i'>Register $i\n";}
print <<__EOT;
</select></td><td>Payment Type:</td>
<td><select name='Type'><option value='-1'>All
__EOT
for ($i = 0; $i <= 8; $i++) {print "<option value='$i'>$PP[$i]\n";}
print <<__EOT;
</select></td><td></tr>
<tr><td>Cashier:</td>
<td><select name='User'><option value='0'>All Cashiers
__EOT
$sth = $conn->prepare('select id,name from users order by name');
$sth->execute();
while (@r = $sth->fetchrow_array()) {print "<option value='$r[0]'>$r[1]\n";}
print <<__EOT;
</select></td><td>Only with Returned Items?</td>
<td><input type=checkbox name='Return' value='1'></td><td></td></tr>
</table>
</form>
__EOT
} else {
$sth = $conn->prepare('select id,name from users order by name');
$sth->execute();
while (@r = $sth->fetchrow_array()) {$users{$r[0]} = $r[1];}

print "<h3>Search Results</h3>\n<p>For Invoices made on $date by "
. ($un == 0? "any cashier": $users{$un}) . " at "
. ($rn == 0? "any register": "register $rn") . " having "
. ($xx == -1? "any": $PP[$xx]) . " payment"
. ($yy == 1? " (Only invoices with returns shown)": "") . <<__EOT;
.</p>
<table width='100%' class='sales'>
<tr><th>#</th><th>Time</th><th>Cashier</th><th>Register</th>
<th>Payment Type</th><th>Total</th></tr>
__EOT

$sth = $conn->prepare(<<__EOSQL);
select id,cast(datetime as time),userid,station
from invoices
where datetime between '$date 00:00:00' and '$date 23:59:59'
order by id
__EOSQL
$sth->execute();

$count = 0;
while (@r = $sth->fetchrow_array()) {
next if (($un > 0) && ($un != $r[2]));
next if (($rn > 0) && ($rn != $r[3]));
if ($xx >= 0) {
$ssth = $conn->prepare("select id from payments where id=$r[0] and paymenttype=$xx");
$ssth->execute();
next if (! $ssth->fetchrow_array());
}
if ($yy > 0) {
$ssth = $conn->prepare("select * from invoicelines where invoice=$r[0] and qty<0");
$ssth->execute();
next if (! $ssth->fetchrow_array());
}

$payments = '';
$ssth = $conn->prepare(<<__EOSQL);
select distinct paymenttype from payments where id=$r[0] order by paymenttype
__EOSQL
$ssth->execute();
while (@rr = $ssth->fetchrow_array()) {$payments .= "$PP[$rr[0]]. ";}

$ssth = $conn->prepare("select sum(amount) from payments where id=$r[0]");
$ssth->execute();
$total = FormatCent(($ssth->fetchrow_array())[0]);

print <<__EOT;
<tr class='${\(++$count % 2? 'odd': 'even')}'><td>$r[0]</td>
<td>$r[1]</td><td>$users{$r[2]}</td><td>$r[3]</td><td>$payments </td>
<td class='right'>$total Edit</td></tr>
__EOT
}
print "</tr></table>\n<p>$count invoices found</p>";
}

print p_footer;

*********End FindInvoice **********


***********Invoice Header Information **************

Invoice Fields
id integer
datetime timestamp
station integer
userid integer
customer character(8)


*********End Invoice Header Information ***********

Not sure how to do this. Any help would be very much appreciated.

Thank you for your help

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives