Thursday, July 5, 2018

Download Complete Project Folder (.zip File)


I have uploaded the complete project folder including all php, css and js files and mysql database file. All are included in the ezpay.zip file. You need to setup a local development environment such as WAMP or XAMP to test run the project.

You are free to use the source codes for learning purposes. However if you submit the project as your high school IT project, you should further develop the system as given instructions in this website. There will be bugs, that you will need to fix. Since this is available free to public, you should not use the project as it is - if you do so, you will be caught for plagiarism.

If you plan to use the project in  a real environment -  you would have to do lot more developments. You are free to do upgrades to the system, and if you like to share your developments with others, please email me your changes -  I will publish your work here for other to learn.

However I am not giving the download link here ( I have put it in another post tagged under "Installment Payment System") because if so you will just download and directly use it in your project (I know because I was there too). You are suppose to study and learn the project and do improvements. So keep reading post under "Installment Payment System" and you will find the download link.

Please give your comments and feel free to explore coding and motivate to do improvements and share with others.

Logout from System


This is the most simplest script but the most important script of all. When you login to a system, it is very important to logout from the system to prevent un-authorized access to the system. Logout is a very simple function that it does only destroy created sessions. Without sessions, other users can not login to the system.

logout.php is the page linked with Logout menu. Following the source code for the logout page.







<?php 
    session_start();
    session_unset();
    session_destroy();
    header("Location: index.php");
?>

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"); ?>

Add a New Payment


To add a new payment (Down Payment or Installment) you need to first search the customer by NIC number. In the search result page (search.php) There is a link "Payment" for each sale of the customer. In the new payment page (new_payment.php), all the details (sales details, customer details, previous payment details, remaining payment details) are showing.

Following details need to enter as a new payment:


  • Payment Date
  • Value
  • Payment Type (Down Payment, Installment or Other Charges)
  • Payment details (mode of payment cash, cheque or credit card, etc.)
If you select Installment, the amount must be equal to the installment value defined earlier. There is an option to delete an entered payment. There are lots of functions in this page and maybe the most complex page of the system.

Source code of new payment page:


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

<div style="width:60%; float:left; margin-right:30px;">
<h3>New Payment</h3>
<?php
$s_id = $_GET['sid'];
if(isset($_POST['submit'])){
$p_date = $_POST['date'];
$p_value = $_POST['value'];
$p_type = $_POST['type'];
$p_details = $_POST['details'];
if($p_date == '' || $p_value == '' || $p_type == ''){
$error = "Please enter all required fields.";
}
if(!isset($error)){
mysql_query("INSERT INTO payments (P_Date, P_Sale, P_Value, P_Type, P_Detail) VALUES ('$p_date', '$s_id', '$p_value', '$p_type', '$p_details')"); 
$noerror = "payment record updated.";
}
}
// 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($p_date)){ echo $p_date; }else{ echo $date; } ?>" /></td>
</tr>
<tr>
<td>Value *</td>
<td><input type="text" name="value" size="10" value="<?php if(isset($p_value)){ echo $p_value; } ?>" /></td>
</tr>
<tr>
<td>Type *</td>
<td>
<select name="type" size="1">
<option value="I" <?php if(isset($p_type)){ if($p_type == "I"){ echo "selected"; }}else{ echo "selected"; } ?>>Installment</option>
<option value="D" <?php if(isset($p_type) && $p_type == "D"){ echo "selected"; } ?>>Down Payment</option>
<option value="O" <?php if(isset($p_type) && $p_type == "O"){ echo "selected"; } ?>>Other Charges</option>
</select>
</td>
</tr>
<tr>
<td>Details</td>
<td><textarea name="details" cols="40" rows="4"><?php if(isset($p_details)){ echo $p_details; } ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<div style="width:100%; background-color:#CCFFFF; border:1px solid #3399FF; padding:5px; margin-top:20px;">
<?php
// get customer details
$q = mysql_query("SELECT S_Customer FROM sales WHERE S_ID = '$s_id'");
$r = mysql_fetch_assoc($q);
$c_id = $r['S_Customer'];
$q = mysql_query("SELECT * FROM customers WHERE Cus_ID = '$c_id'");
$r = mysql_fetch_assoc($q);
$c_id = $r['Cus_ID'];
$c_name = $r['Cus_Name'];
$c_nic = $r['Cus_NIC'];
$c_add = $r['Cus_Add'];
$c_tel = $r['Cus_Tel'];
?>
<h3>Customer Details &nbsp; <a class="ong" href="search.php?cid=<?php echo $c_id; ?>">[Edit]</a></h3>
<table width="100%" cellpadding="3px" cellspacing="1px">
<tr class="wht"><td><?php echo $c_name; ?></td></tr>
<tr class="wht"><td><strong>N.I.C.</strong> <?php echo $c_nic; ?></td></tr>
<tr class="wht"><td><?php echo $c_add; ?></td></tr>
<tr class="wht"><td><strong>Telephone:</strong> <?php echo $c_tel; ?></td></tr>
</table>
</div>
</div>
<div style="width:35%; float:left; background-color:#CCFFFF; border:1px solid #3399FF; padding:5px;">
<?php
// get sale details
$q = mysql_query("SELECT * FROM sales WHERE S_ID = '$s_id'");
$r = mysql_fetch_assoc($q);
$s_date = $r['S_Date'];
$s_item = $r['S_Item'];
$s_desc = $r['S_Description'];
$s_value = $r['S_Value'];
$s_ins = $r['S_Installments'];
$s_ins_value = $r['S_Installment_Value'];
$s_int = $r['S_Interest'];
?>
<h3>Sale Details &nbsp; <a class="ong" href="edit_sale.php?id=<?php echo $s_id; ?>">[Edit]</a></h3>
<table width="100%" cellpadding="3px" cellspacing="1px">
<tr class="wht"><td><strong>Sale Date:</strong> <?php echo $s_date; ?></td></tr>
<tr class="wht"><td><?php echo $s_item; ?></td></tr>
<tr class="wht"><td><?php echo $s_desc; ?></td></tr>
<tr class="wht"><td><strong>Value Rs.</strong> <?php echo $s_value; ?></td></tr>
<tr class="wht"><td><strong>No. of Installments</strong> <?php echo $s_ins; ?></td></tr>
<tr class="wht"><td><strong>Installment Value Rs.</strong> <?php echo $s_ins_value; ?></td></tr>
<tr class="wht"><td><strong>Interest:</strong> <?php echo $s_int; ?></td></tr>
</table>
<h3>Previous Payments</h3>
<table width="100%" cellpadding="3px" cellspacing="1px">
<tr class="header"><td>&nbsp;</td><td>Date</td><td>Type</td><td>Amount Rs.</td><td>&nbsp;</td></tr>
<?php
// get pament records
$q = mysql_query("SELECT * FROM payments WHERE P_Sale = '$s_id' ORDER BY P_Date");
$total_paid = 0;
$ins_count = 0;
$n = 1;
while($r = mysql_fetch_assoc($q)){
$p_id = $r['P_ID'];
$p_date = $r['P_Date'];
$p_type = $r['P_Type'];
$p_value = $r['P_Value'];
$total_paid += $p_value;
echo "<tr class='wht'><td>{$n}</td><td>{$p_date}</td><td>";
if($p_type == "D"){
echo "Down Payment";
}else if($p_type == "I"){
echo "Installment";
$ins_count++;
}else{
echo "Other Charges";
}
echo "</td><td><div align='right'>{$p_value}</div></td><td><a href='del_payment.php?sid={$s_id}&id={$p_id}'>x</a></td></tr> \n";
$n++;
}
echo "<tr class='lblack'><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><div align='right'><strong>".number_format($total_paid,2,'.','')."</strong></div></td><td>&nbsp;</td></tr>";
?>
</table>
<h3>Due Payments</h3>
<?php
$total_installments = $s_ins;
$total_paid_installments = $ins_count;
$balance_installments = $total_installments - $total_paid_installments;
$total_balance_value = $balance_installments * $s_ins_value;
?>
<table width="100%" cellpadding="3px" cellspacing="1px">
<tr class="wht"><td><strong>Due Installments:</strong> <?php echo $balance_installments; ?></td></tr>
<tr class="wht"><td><strong>Due Amount Rs.</strong> <?php echo number_format($total_balance_value,2,'.',''); ?></td></tr>
</table>
</div>
<div style="clear:both;"></div>
<?php include("footer.php"); ?>

Edit Sales


We learned about how to create a new sales and view created sales. In this page edit_sales.php you can edit sales details and change sales status. You can not delete a sale from the sales database table, but you can cancel a sale by changing the status.

Edit sale option available only in view sales (view_sales.php) page.

Source code of edit sales page:

<?php include("header.php"); ?>
<div style="width:60%; float:left; margin-right:30px;">
<h3>New Sale</h3>
<?php
$s_id = $_GET['id'];
$q = mysql_query("SELECT * FROM sales WHERE S_ID = '$s_id'");
$r = mysql_fetch_assoc($q);
$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'];
$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 FROM customers WHERE Cus_ID = '$s_customer'");
$r2 = mysql_fetch_assoc($q2);
$s_nic = $r2['Cus_NIC'];

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'];
$s_status = $_POST['status'];

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 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'];
}
}
if(!isset($error)){
mysql_query("UPDATE sales SET S_Date = '$s_date', 
S_Customer = '$s_customer', 
S_Item = '$s_item', 
S_Description = '$s_details', 
S_Value = '$s_value', 
S_Installments = '$s_installments', 
S_Installment_Value = '$s_ins_value', 
S_Interest = '$s_interest', 
S_Status = '$s_status' WHERE S_ID = '$s_id'"); 
$noerror = "Sale updated.";
}
}
// 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>Status</td>
<td>
<select name="status" size="1">
<option value="A" <?php if($s_status == "A"){ echo "selected"; } ?>>Active</option>
<option value="C" <?php if($s_status == "C"){ echo "selected"; } ?>>Completed</option>
<option value="S" <?php if($s_status == "S"){ echo "selected"; } ?>>Suspended / Cencelled</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</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>
<?php include("footer.php"); ?>

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"); ?>

Sales


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>&nbsp;</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>
<?php include("footer.php"); ?>

Download the complete project folder here.