207 lines
9.8 KiB
PHP
207 lines
9.8 KiB
PHP
<?php
|
|
if(isset($_GET['bill_numbber'])){
|
|
if(isset($_POST['payment_mode'])){
|
|
//echo $_POST['payment_mode'];
|
|
$conn = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$sql = "UPDATE `".SHOP_ID."_bill` SET `payment_mode` = '".$_POST['payment_mode']."' , `total` = '".$_POST['bill_total']."' WHERE `id` = '".$_POST['bill_no']."'";
|
|
if ($conn->query($sql) === TRUE) {
|
|
//echo "Bill Saved!";
|
|
} else {
|
|
echo "Error updating record: " . $conn->error;
|
|
}
|
|
$conn->close();
|
|
}
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill` WHERE `payment_mode` != 0 AND `id`='".$_GET['bill_numbber']."'";
|
|
$result= mysqli_query($link, $query);
|
|
if(mysqli_num_rows($result)<1){
|
|
echo ' <br />
|
|
<h2> Err: No Paid Bill found check the bill number. </h2>
|
|
';
|
|
}
|
|
else {
|
|
if(isset($_POST['return_bill_id'])){
|
|
$total= -1 * abs($_POST['total']);
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="INSERT INTO `".SHOP_ID."_bill` ( `total`,`return_id`,`payment_mode`,`user`)VALUES(?,?,?,?)";
|
|
$payment_mode='99';
|
|
$stmt = $link->prepare($query);
|
|
if($stmt){
|
|
$stmt->bind_param("ssss", $total,$_POST['return_bill_id'],$payment_mode,$_SESSION["id"] ); echo $total,$_POST['return_bill_id'],$_SESSION["id"] ;
|
|
//if(!$stmt->execute()) echo '<div class="alert alert-danger">' . mysqli_error($link) . '</div>';
|
|
if(!$stmt->execute()) echo '<div class="alert alert-danger"> ERR: 8776' . mysqli_error($link) . '</div>';
|
|
}
|
|
else echo mysqli_error($link);
|
|
}
|
|
if(isset($_POST['return_product_id'])){
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="UPDATE `".SHOP_ID."_product` SET `stock` = `stock` +1 WHERE `id`='".$_POST['product_id']."'";
|
|
if($link->query($query) === TRUE){
|
|
$query="UPDATE `".SHOP_ID."_bill_product` SET `returned` = '1' WHERE `id`='".$_POST['return_product_id']."'";
|
|
$result= mysqli_query($link, $query);
|
|
if($result) echo 'Returned!'; else echo 'Err:44889';
|
|
}
|
|
}
|
|
echo '<div id="section-to-print" style="display: flex; flex-direction: column; width: 350px;">
|
|
</div> <table> <tr> <td>SL</td> <td>Product</td> <td>MRP</td> <td>Price</td> <td>Action</td> </tr> ';
|
|
$sl=0;
|
|
$total=0;$total_cost=0;
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill_product` WHERE `bill_id`='".$_GET['bill_numbber']."' ORDER BY `id` DESC";
|
|
$result= mysqli_query($link, $query);
|
|
while ($row= mysqli_fetch_assoc($result)) {
|
|
$sl++;$total=$total+$row['price']; $total_cost=$total_cost+$row['cost'];
|
|
echo '<tr> <td>',$sl,'</td> <td>',$row['product_name'],'</td> <td>',$row['mrp'],'</td> <td>',$row['price'],'</td> <td>';
|
|
if($row['returned']=='1') echo 'Returned'; else echo ' <form method="POST">
|
|
<input type="hidden" name="product_id" value="',$row['product_id'],'" />
|
|
<input type="hidden" name="return_product_id" value="',$row['id'],'" /> <input type="submit" value="Return" /> </form>';
|
|
echo '</td> </tr>';
|
|
}
|
|
echo '</table> <hr /> <br>';
|
|
$tz = 'Asia/Kolkata';$timestamp = time();$dt = new DateTime("now", new DateTimeZone($tz));$dt->setTimestamp($timestamp);
|
|
echo '
|
|
<div id="section-to-print" style="display: flex; flex-direction: column; width: 350px;">
|
|
|
|
Return #'.$_GET['bill_numbber'],' - ',$dt->format('Y/m/d h:i:sa');
|
|
echo ' <table> <tr> <td>SL</td> <td>Product</td> <td>Price</td> </tr> ';
|
|
$sl=0;
|
|
$total_return=0;
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill_product` WHERE `returned`='1' AND `bill_id`='".$_GET['bill_numbber']."' ORDER BY `id` DESC";
|
|
$result= mysqli_query($link, $query);
|
|
while ($row= mysqli_fetch_assoc($result)) {
|
|
$sl++;$total_return=$total_return+$row['price'];
|
|
echo '<tr> <td>',$sl,'</td> <td>',$row['product_name'],'</td> <td>',$row['price'],'</td> </tr>';
|
|
}
|
|
echo '</table> <br /> <span> Total Return:<b> ',$total_return,'</b> </span> <br> <a href="print-bill?bill='.$_GET['bill_numbber'].'"> <button> Submit </button> </a> ';
|
|
if($total_return>0){
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill` WHERE `return_id`='".$_GET['bill_numbber']."'"; //echo $query;
|
|
$result= mysqli_query($link, $query);
|
|
if(mysqli_num_rows($result)>0){
|
|
$row= mysqli_fetch_assoc($result); $newBill_id = $row['id']; $payment_mode= $row['payment_mode'];
|
|
|
|
// Start new bill Section starts
|
|
// if(isset($newBill_id)){
|
|
// echo ' <br /> <form method="POST"> <input type="hidden" name="bill" value="'.$newBill_id.'"> <input type="text" placeholder="bar code" name="code"> </form>';
|
|
// }
|
|
|
|
// Start new bill Section ends
|
|
|
|
|
|
if(isset($_POST['code'])){
|
|
$code = explode('-', $_POST['code']); // get the product id #$code[0]
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_product` WHERE `id`='".$code[0]."'";
|
|
$result= mysqli_query($link, $query);
|
|
if(mysqli_num_rows($result)<1){
|
|
echo ' <br /> <h2> Err: no Product Found </h2> ';
|
|
}
|
|
else {
|
|
$row = $result -> fetch_array(MYSQLI_ASSOC);
|
|
if($row['stock']<1) echo ' <br /> <h2> Err: out of stock </h2> ';
|
|
else {
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$link->set_charset("utf8");
|
|
$query="UPDATE `".SHOP_ID."_product` SET `stock` = `stock` -1 WHERE `id`='".$code[0]."'";
|
|
if($link->query($query) === TRUE){
|
|
$query="INSERT INTO `".SHOP_ID."_bill_product` ( `bill_id`,`product_id`,`mrp`,`price`,`cost`,`product_name`)VALUES(?,?,?,?,?,?)";
|
|
$stmt = $link->prepare($query);
|
|
if($stmt){
|
|
$stmt->bind_param("ssssss", $newBill_id,$code[0],$row['mrp'],$row['price'],$row['cost'],$row['name'] );// echo $row['mrp'],$row['price'];
|
|
//if(!$stmt->execute()) echo '<div class="alert alert-danger">' . mysqli_error($link) . '</div>';
|
|
if(!$stmt->execute()) echo '<div class="alert alert-danger"> ERR: 8776' . mysqli_error($link) . '</div>';
|
|
// else {
|
|
// $last_id = $link->insert_id;
|
|
// echo '<div class="alert alert-success"> '.$last_id .'Bill Started</div> <br>
|
|
// ';
|
|
// }
|
|
}
|
|
else echo mysqli_error($link);
|
|
}
|
|
$link->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
#$tz = 'Asia/Kolkata';$timestamp = time();$dt = new DateTime("now", new DateTimeZone($tz));$dt->setTimestamp($timestamp);
|
|
echo "Bill #: ",$newBill_id,'
|
|
<hr/>
|
|
<table>
|
|
<tr>
|
|
<td>SL</td>
|
|
<td>Product</td>
|
|
<td>Price</td>
|
|
</tr>';
|
|
$sl=0;
|
|
$total=0;
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill_product` WHERE `bill_id`='".$newBill_id."' ".$returned." ORDER BY `id` DESC";
|
|
$result= mysqli_query($link, $query);
|
|
while ($row= mysqli_fetch_assoc($result)) {
|
|
$sl++;$total=$total+$row['price'];
|
|
echo '<tr>
|
|
<td>',$sl,'</td>
|
|
<td><span style="font-size:small;">',$row['product_name'];
|
|
if($row['mrp']> $row['price']) {$discount=$row['mrp']- $row['price']; echo ' <br /> @ ', $row['mrp'], ', Discount: ',$discount;}
|
|
echo ' </span></td> <td>',$row['price'],'</td> </tr>';
|
|
}
|
|
$Payable=$total-$total_return;
|
|
echo '</table> <br /> Total Billed:<b> ',$total,'</b>, Payable:<b> ',$Payable,'</b>';
|
|
|
|
if($payment_mode=='99'){
|
|
echo ' <br /> <form method="POST"> <input type="hidden" name="bill" value="'.$newBill_id.'"> <input type="text" placeholder="bar code" name="code"> </form>';
|
|
if($total<$total_return) echo '<br> Add more item';
|
|
else echo '
|
|
<span> Payment Mode </span>
|
|
<form method="POST">
|
|
<input type="radio" id="Cash" name="payment_mode" value="1">
|
|
<label for="Cash">Cash</label><br>
|
|
<input type="radio" id="Card" name="payment_mode" value="2">
|
|
<label for="Card">Card</label><br>
|
|
<input type="radio" id="UPI" name="payment_mode" value="3">
|
|
<label for="UPI">UPI</label><br>
|
|
<input type="radio" id="Other" name="payment_mode" value="9">
|
|
<label for="Other">Other</label> <br /><br />
|
|
<input type="hidden" name="bill_no" value="'.$newBill_id.'" />
|
|
<input type="hidden" name="bill_total" value="'.$Payable.'" />
|
|
<input type="submit" value="Save" />
|
|
</form>
|
|
';
|
|
} else echo '<br /> <button onclick="window.print()">Print this page</button>';
|
|
|
|
//echo ' <br /> <a href="view-bills?payment=return" > go to return section to print </a>';
|
|
}
|
|
else echo 'Total Return: ',$total_return,' <br /> <form method="POST"> <input type="hidden" name="return_bill_id" value="',$_GET['bill_numbber'],'" />
|
|
<input type="hidden" name="total" value="',$total_return,'" /> <input type="submit" value="Save this return" /> </form> <br>';
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
else echo '
|
|
<form>
|
|
<br>
|
|
<input type="number" name="bill_numbber">
|
|
<input type="submit" value="find">
|
|
</form>
|
|
';
|
|
|
|
echo '</div>';
|
|
?>
|
|
<style>
|
|
@media print {
|
|
body * {
|
|
visibility: hidden;
|
|
}
|
|
#section-to-print, #section-to-print * {
|
|
visibility: visible;
|
|
}
|
|
#section-to-print {
|
|
position: absolute;
|
|
left: 0;
|
|
top: 0;
|
|
}
|
|
}
|
|
</style>
|