This system search a customer by NIC number field in the customers database table. Customer search box is displayed in all pages except users. In all other pages, it is only the form with action location as search.php and the search query and display of search result is handled by the search.php page.
Source code of the search form
<form method="post" action="search.php">
N.I.C. <input type="text" name="nic" size="20" />
<input type="submit" name="submit" value="Search" />
</form>
When click on the search button it post the input value to the search.php page. There are two methods a form can send data "POST" and "GET". We uses POST method because posted data is invisible to the users and more secure than GET method. If you uses GET method, posted data is visible to the users in the URL. Most of the time in system developments, preferred method of a form is POST method.
Inline CSS styles used to show different colors according to customer's status. Red for black listed customers, Gray color for suspended customer.
Source code of "Search.php" page
<?php include("header.php"); ?>
<?php
if(isset($_GET['cid'])){
$cid = $_GET['cid'];
}
if(isset($_POST['submit'])){
$cnic = $_POST['nic'];
if($cnic == ''){
header("Location: customers.php");
ob_end_flush(0);
}
}
if(!isset($cid) && !isset($cnic)){
header("Location: customers.php");
ob_end_flush(0);
}
?>
<h3>Customer Details</h3>
<?php
// get customer details
if(isset($cnic)){
$q = mysql_query("SELECT * FROM customers WHERE Cus_NIC = '$cnic'");
}else{
$q = mysql_query("SELECT * FROM customers WHERE Cus_ID = '$cid'");
}
$r = mysql_fetch_assoc($q);
$c_id = $r['Cus_ID'];
$c_date = $r['Cus_Date'];
$c_name = $r['Cus_Name'];
$c_nic = $r['Cus_NIC'];
$c_add = $r['Cus_Add'];
$c_tel = $r['Cus_Tel'];
$c_sex = $r['Cus_Sex'];
$c_email = $r['Cus_Email'];
$c_status = $r['Cus_Status'];
if($c_status == "S"){
$status = "Suspended";
}else if($c_status == "B"){
$status = "Black Listed";
}else{
$status = "Active";
}
?>
<span style="float:right; background-color:#33CC99; border:1px solid #00CCCC; padding:3px 5px;"><a href="edit_customer.php?id=<?php echo $c_id; ?>" class="wht">Edit Customer Details</a></span>
<table width="100%" cellpadding="3px" cellspacing="1px" style="background-color:#00CCCC;">
<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>
<tr class="wht"><td><strong>Email:</strong> <?php echo $c_email; ?></td></tr>
<tr class="wht"><td><strong>Sex:</strong> <?php echo $c_sex; ?></td></tr>
<tr class="
<?php
if($c_status == "B"){
echo "lred";
}else if($c_status == "S"){
echo "lblack";
}else{
echo "wht";
}
?>
"><td><strong>Status:</strong> <?php echo $status; ?></td></tr>
</table>
<h3>Sales</h3>
<table width="100%" style="background-color:#CC0000;" cellpadding="3px" cellspacing="1px">
<tr class="header">
<td>Date</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> </td>
</tr>
<?php
$total_value= 0;
$q = mysql_query("SELECT * FROM sales WHERE S_Customer = '$c_id' ORDER BY S_Date DESC");
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'];
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>{$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='new_payment.php?sid={$s_id}'>Payments</a></td>
</tr> \n";
}
?>
<tr class="lblack">
<td> </td>
<td> </td>
<td><div align="right"><strong>Total Value </strong></div></td>
<td><div align="right"><strong><?php echo number_format($total_value,2,'.',''); ?></strong></div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<?php include("footer.php"); ?>
0 comments:
Post a Comment