Wednesday, July 4, 2018

View Payments (Report)


"Payments" menu is linked to the page payments.php and this is basically a reporting functions. You can view payments in any given date range. CW Calendar javascript plugin also used in this form to select the reporting data range. By default it shows all payments when page loads. We need to stop loading all payments be default because, if there are thousands of payment records it will takes a long time to loads or script crashes (time out or memory crash).

Source code of the payment.php

<?php include("header.php"); ?>
<?php
/*if(privileges('Received Payments') != 'Valid'){
header("Location:main.php");
ob_end_flush();
}*/
?>

<h3>Payments</h3>
<?php
$date_from = '';
$date_to = '';
$cnic = '';
if(isset($_POST['submit'])){
$date_from = $_POST['datefrm'];
$date_to = $_POST['dateto'];
$cnic = $_POST['nic'];
}
// messages
if(isset($error)){
echo "<div class='error'><strong>Error:</strong> {$error}</div>";
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table border="0">
<tr>
<td><strong>Filter: </strong>Date:</td>
<td>
FROM <input type="text" name="datefrm" id="datefrm" value="<?php echo $date_from; ?>" /> <span style="font-size:10px; background-color:#FFFF00; border:1px solid #000; padding:0 2px; cursor:pointer;" onClick="fPopCalendar('datefrm')">Calendar</span> &nbsp; 
TO <input type="text" name="dateto" id="dateto" value="<?php echo $date_to; ?>" /> <span style="font-size:10px; background-color:#FFFF00; border:1px solid #000; padding:0 2px; cursor:pointer;" onClick="fPopCalendar('dateto')">Calendar</span></td>
<td>N.I.C. <input type="text" name="nic" size="15" value="<?php echo $cnic; ?>" /></td>
<td><input style="border:1px solid #0066CC;" class="btn" type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<br />
<table width="100%" style="background-color:#CC0000;" cellpadding="3px" cellspacing="1px">
<tr class="header">
<td>Pay #</td>
<td>Date</td>
<td>Item Name</td>
<td>N.I.C.</td>
<td>Customer</td>
<td>Type</td>
<td>Details</td>
<td>Value Rs.</td>
</tr>

<?php
$sql = "SELECT P_ID, P_Date, P_Value, P_Type, P_Detail, S_Item, Cus_Name, Cus_NIC FROM 
payments, sales, customers WHERE S_ID = P_Sale AND Cus_ID = S_Customer ";

if($date_from != '' && $date_to != ''){
$sql .= "AND P_Date BETWEEN '$date_from' AND '$date_to' ";
}
if($cnic != ''){
$sql .= "AND Cus_NIC = '$cnic' ";
}
$sql .= "ORDER BY S_Date DESC";
if($date_from == '' && $date_to == '' && $cnic == ''){
$sql .= " LIMIT 100";
}

$total_value = 0;
$q = mysql_query($sql);
while($r = mysql_fetch_assoc($q)){
$id = $r['P_ID'];
$pdate = $r['P_Date'];
$value = $r['P_Value'];
$total_value += $value;
$type = $r['P_Type'];
if($type == "I"){
$type = "Installment";
}else if($type == "D"){
$type = "Down Payment";
}else{
$type = "Other Charges";
}
$detail = $r['P_Detail'];
$customer = $r['Cus_Name'];
$nic = $r['Cus_NIC'];
$item = $r['S_Item'];
echo "<tr class='wht'>
<td>{$id}</td>
<td>{$pdate}</td>
<td>{$item}</td>
<td>{$nic}</td>
<td>{$customer}</td>
<td>{$type}</td>
<td>{$detail}</td>
<td><div align='right'>{$value}</div></td>
</tr> \n";
}
echo "<tr class='lblack'>
<td colspan='7'>&nbsp;</td>
<td><div align='right'><strong>".number_format($total_value,2,'.','')."</strong></div></td>
</tr> \n";
?>
</table>

<?php include("footer.php"); ?>

Share:

0 comments:

Post a Comment