Wednesday, July 4, 2018

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

0 comments:

Post a Comment