Wednesday, July 4, 2018

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

0 comments:

Post a Comment