Wednesday, July 4, 2018

View Sales


There are two pages to view customer sales. Using the search option and selecting a link from sales page. View result of these two options are not the same. In the search option (search.php page) only active sales on the customer are shown and from there only can add payment to a sale. But in the view_sales.php page (select a link from sales.php page), shows all sales of all customers and can edit sales details from there.

Also in view_sales.php page, you can filter sales according to sales status and filter sales by giving a date rage. In the view sales page, you can view daily, weekly, monthly or yearly sales as well as sales on any given date range.

Color code is used to separate sales by it's status. CW calendar plugin used here to select dates using a pop-up calendar.

Source code of the view_sales.php Page:

<?php include("header.php"); ?>
<h3>Sales</h3>
<p><strong>Filter:</strong> <a href="view_sales.php?t=A">Active</a> | <a href="view_sales.php?t=C">Completed</a> | <a href="view_sales.php?t=S">Suspended / Cancelled</a> | <a href="view_sales.php?t=all">All</a></p>
<?php
$date_from = '';
$date_to = '';
if(isset($_POST['submit'])){
$date_from = $_POST['datefrm'];
$date_to = $_POST['dateto'];
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table border="0">
<tr>
<td>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><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>Date</td>
<td>N.I.C</td>
<td>Item Name</td>
<td>Details</td>
<td>Value Rs.</td>
<td>Installments</td>
<td>Interest</td>
<td>Inst. Value Rs.</td>
<td>Status</td>
<td>&nbsp;</td>
</tr>
<?php
$status = $_GET['t'];
$total_value= 0;
if($status != "all"){
if($date_from != '' && $date_to != ''){
$q = mysql_query("SELECT * FROM sales WHERE S_Status = '$status' AND S_Date BETWEEN '$date_from' AND '$date_to' ORDER BY S_Date DESC");
}else{
$q = mysql_query("SELECT * FROM sales WHERE S_Status = '$status' ORDER BY S_Date DESC");
}
}else{
if($date_from != '' && $date_to != ''){
$q = mysql_query("SELECT * FROM sales WHERE S_Date BETWEEN '$date_from' AND '$date_to' ORDER BY S_Date DESC LIMIT 200");
}else{
$q = mysql_query("SELECT * FROM sales ORDER BY S_Date DESC LIMIT 200");
}
}
while($r = mysql_fetch_assoc($q)){
$s_id = $r['S_ID'];
$s_date = $r['S_Date'];
$s_item = $r['S_Item'];
$s_customer = $r['S_Customer'];
$s_details = $r['S_Description'];
$s_value = $r['S_Value'];
$total_value += $s_value;
$s_installments = $r['S_Installments'];
$s_interest = $r['S_Interest'];
$s_ins_value = $r['S_Installment_Value'];
$s_status = $r['S_Status'];
// get the customer nic
$q2 = mysql_query("SELECT Cus_NIC, Cus_Name FROM customers WHERE Cus_ID = '$s_customer'");
$r2 = mysql_fetch_assoc($q2);
$s_nic = $r2['Cus_NIC'];
$s_name = $r2['Cus_Name'];
echo "<tr class='";
if($s_status == "C"){
echo "lgreen";
}else if($s_status == "S"){
echo "lred";
}else{
echo "wht";
}
echo "'>
<td>{$s_date}</td>
<td title = '{$s_name}' onMouseOver=\"this.bgColor='yellow'\"  onMouseOut=\"this.bgColor=''\">{$s_nic}</td>
<td>{$s_item}</td>
<td title='{$s_details}' onMouseOver=\"this.bgColor='yellow'\"  onMouseOut=\"this.bgColor=''\">".substr($s_details,0,20)."...</td>
<td><div align='right'>{$s_value}</div></td>
<td>{$s_installments}</td>
<td>{$s_interest}%</td>
<td><div align='right'>{$s_ins_value}</div></td>
<td>{$s_status}</td>
<td><a href='edit_sale.php?id={$s_id}'>Edit</a></td>
</tr> \n";
}
?>
<tr class="lblack">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><div align="right"><strong>Total Value &nbsp;</strong></div></td>
<td><div align="right"><strong><?php echo number_format($total_value,2,'.',''); ?></strong></div></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

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

0 comments:

Post a Comment