This is the main function of the system - selling products. Since this system is intended to handle only installment payments, this system doesn't maintain an inventory. Product inventory will be an useful add-on for the system and if you want to improve the system it is good to develop an inventory and stock management part for this system.
When selling a product, following details need to feed to the system.
- Date of selling
- Customer's NIC number
- Product name
- Product description
- Item value
- Number of installments
- Total interest in percentage
- Value of an installment - This amount need to be calculated separately. It is up to you to improve these functions, if you are going to submit this as your project.
After posting the form - PHP script validate data for integrity. If customer NIC is not found in the customers table, error message displays. Other details also validated upon submission of the form.
There are lots of improvements need in this page and there are plenty of room for you to do additional developments here.
There are links to select and view sales according to the status of the sale.
- All sales
- Active sales
- Completed sales
- Cancelled / Suspended sales
Viewing of sales are handled by the view_sales.php page and we will discuss it in the next post.
Source Code for the Sales.php page
<?php include("header.php"); ?>
<div style="width:60%; float:left; margin-right:30px;">
<h3>New Sale</h3>
<?php
if(isset($_POST['submit'])){
$s_date = $_POST['date'];
$s_item = $_POST['item'];
$s_nic = $_POST['nic'];
$s_details = $_POST['details'];
$s_value = $_POST['value'];
$s_installments = $_POST['ins'];
$s_interest = $_POST['interest'];
$s_ins_value = $_POST['ivalue'];
if($s_date == '' || $s_item == '' || $s_nic == '' || $s_value == '' || $s_installments == '' || $s_interest == '' || $s_ins_value == ''){
$error = "Please enter all required fields.";
}
if(!isset($error)){
// no form errors. validate customer nic
$q = mysql_query("SELECT Cus_ID, Cus_Status FROM customers WHERE Cus_NIC = '$s_nic'");
if(mysql_num_rows($q) == 0){
$error = "Customer not found!";
}else{
$r = mysql_fetch_assoc($q);
$s_customer = $r['Cus_ID'];
$c_status = $r['Cus_Status'];
// validate status
if($c_status != "A"){
$error = "This customer is Black Listed or Suspended. Can not create new sale.";
}
}
}
if(!isset($error)){
mysql_query("INSERT INTO sales (S_Date, S_Customer, S_Item, S_Description, S_Value, S_Installments, S_Installment_Value, S_Interest) VALUES
('$s_date', '$s_customer', '$s_item', '$s_details', '$s_value', '$s_installments', '$s_ins_value', '$s_interest')");
$noerror = "Sale created.";
}
}
// messages
if(isset($error)){
echo "<div class='error'><strong>Error:</strong> {$error}</div>";
}
if(isset($noerror)){
echo "<div class='noerror'><strong>Success:</strong> {$noerror}</div>";
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table border="0">
<tr>
<td>Date *</td>
<td><input type="text" name="date" size="15" value="<?php if(isset($s_date)){ echo $s_date; }else{ echo $date; } ?>" /></td>
</tr>
<tr>
<td>Customer N.I.C. *</td>
<td><input type="text" name="nic" size="20" value="<?php if(isset($s_nic)){ echo $s_nic; } ?>" /></td>
</tr>
<tr>
<td>Item Name *</td>
<td><input type="text" name="item" size="50" value="<?php if(isset($s_item)){ echo $s_item; } ?>" /></td>
</tr>
<tr>
<td>Item Details</td>
<td><textarea name="details" cols="40" rows="4"><?php if(isset($s_details)){ echo $s_details; } ?></textarea></td>
</tr>
<tr>
<td>Item Value Rs. *</td>
<td><input type="text" name="value" size="12" value="<?php if(isset($s_value)){ echo $s_value; } ?>" /></td>
</tr>
<tr>
<td>No. of Installments *</td>
<td><input type="text" name="ins" size="10" value="<?php if(isset($s_installments)){ echo $s_installments; } ?>" /></td>
</tr>
<tr>
<td>Interest % *</td>
<td><input type="text" name="interest" size="10" value="<?php if(isset($s_interest)){ echo $s_interest; } ?>" /></td>
</tr>
<tr>
<td>Installment Value Rs. *</td>
<td><input type="text" name="ivalue" size="12" value="<?php if(isset($s_ins_value)){ echo $s_ins_value; } ?>" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<div style="width:36%; float:left;">
<h3>Search</h3>
<form method="post" action="search.php">
N.I.C. <input type="text" name="nic" size="20" /> <input type="submit" name="submit" value="Search" />
</form>
<h3>View Sales</h3>
<ul>
<li><a href="view_sales.php?t=all">All Sales</a></li><br />
<li><a href="view_sales.php?t=A">Active Sales</a></li><br />
<li><a href="view_sales.php?t=C">Completed Sales</a></li><br />
<li><a href="view_sales.php?t=S">Suspended / Cancelled Sales</a></li><br />
</ul>
</div>
<div style="clear:both;"></div>
0 comments:
Post a Comment