289 lines
12 KiB
PHP
289 lines
12 KiB
PHP
<?php
|
|
function getThisBill($billID){
|
|
$totalTax=0;
|
|
$GSTAmount=0;
|
|
$totalGST=0;
|
|
$totalAmount=0;
|
|
$totalCost=0;
|
|
$billLink = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
|
|
$billQuery = "SELECT * FROM `" . SHOP_ID . "_bill_product` WHERE `bill_id`='" . $billID . "' AND `returned` IS NULL ORDER BY `id` DESC";
|
|
$billResult = mysqli_query($billLink, $billQuery);
|
|
while ($billRow = mysqli_fetch_assoc($billResult)) {
|
|
if ($billRow['price'] <= 1000) {
|
|
$GSTPercentage = 105;
|
|
}
|
|
elseif ($billRow['price'] >= 1000) {
|
|
$GSTPercentage = 112;
|
|
} else {
|
|
//Future Billing Amount Conditions
|
|
}
|
|
$GSTAmount = round($billRow['price'] / $GSTPercentage * 100);
|
|
$totalTax = $billRow['price'] - $GSTAmount;
|
|
$totalGST = $totalGST + $totalTax ;
|
|
|
|
$totalAmount=$totalAmount+$billRow['price'];
|
|
$totalCost=$totalCost+$billRow['cost'];
|
|
}
|
|
// return $totalGST;
|
|
return array($totalGST,$totalCost,$totalAmount);
|
|
}
|
|
|
|
|
|
?>
|
|
<br />
|
|
<table>
|
|
<tr>
|
|
<td style="padding:5px;"> <a href="?payment=1"> Cash </a></td>
|
|
<td style="padding:5px;"> <a href="?payment=2"> Card </a></td>
|
|
<td style="padding:5px;"> <a href="?payment=3"> UPI </a></td>
|
|
<td style="padding:5px;"> <a href="?payment=9"> Other </a></td>
|
|
<td style="padding:5px;"> <a href="?payment=paid"> All Paid </a></td>
|
|
<td style="padding:5px;"> <a href="?payment=0"> Incomplete Bills </a></td>
|
|
</tr>
|
|
</table>
|
|
<br />
|
|
<form method="POST">
|
|
<tabel> <tr>
|
|
<td> Start Date <input type="date" id="start" name="start"> </td> <td> Date Before <input type="date" id="end" name="end"> </td> <td> <input type="submit" value="view"> </td>
|
|
</tr> </table></form>
|
|
<table>
|
|
<tr style="">
|
|
<td style="text-align: center;">SL</td>
|
|
<td style="text-align: center;">Date</td>
|
|
<td style="text-align: center;">Phone</td>
|
|
<td style="text-align: center;">Amount</td>
|
|
<td style="text-align: center;">GST</td>
|
|
<td style="text-align: center;">PAID</td>
|
|
<td style="text-align: center;">Name</td>
|
|
<?php if(isset($_SESSION['email']) && $_SESSION['email'] != 'user@fashionavenue.com'){ echo '<td style="text-align: center;">Action</td>';} ?>
|
|
</tr>
|
|
<?php
|
|
$total=0;
|
|
$total_cost=0;
|
|
$index = 1;
|
|
$totalTax = 0;
|
|
$totalPrice = 0;
|
|
function convertToIndianTimezone($time){
|
|
$date = new DateTime($time, new DateTimeZone('UTC'));
|
|
$date->setTimezone(new DateTimeZone('Asia/Kolkata'));
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
if(isset($_GET['payment'])){
|
|
// echo date('Y-m-d', strtotime(' +1 day'));
|
|
$between="AND `time` between '".date('Y-m-d')."' AND '".date('Y-m-d', strtotime(' +1 day'))."'";
|
|
//echo $_POST['start'],$_POST['end'];
|
|
if(isset($_POST['start'])){
|
|
$between="AND `time` between '".$_POST['start']."' AND '".$_POST['end']."'"; //echo $between;
|
|
}
|
|
if($_GET['payment'] == 'paid') {
|
|
$link = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
|
|
$GSTAmount =0;
|
|
$totalTax =0;
|
|
$totalGSTlistedBills=0;
|
|
$query = "SELECT * FROM `" . SHOP_ID . "_bill` WHERE `payment_mode` != '0' " . $between . " ORDER BY `id` DESC";
|
|
$result = mysqli_query($link, $query);
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
?>
|
|
<tr>
|
|
<td style=""><?php echo $index++; ?></td>
|
|
<td style=""><?php echo convertToIndianTimezone($row['time']); ?></td>
|
|
<td style=""><?php echo $row['cust_phone']; ?></td>
|
|
<td style=""><?php
|
|
// echo $row['total'];
|
|
// $total_cost = $total_cost + $row['cost']; $total = $total + $row['total'];
|
|
$thisBill=getThisBill($row['id']);
|
|
$totalGST=$thisBill[0];
|
|
$totalCost=$thisBill[1];
|
|
$totalAmount=$thisBill[2];
|
|
echo $totalAmount;
|
|
$total_cost = $total_cost + $totalCost; $total = $total + $totalAmount;
|
|
?></td>
|
|
<td style=""><?php $gstForThisBill=$totalGST; echo $gstForThisBill; $totalGSTlistedBills= $totalGSTlistedBills + $gstForThisBill; ?></td>
|
|
<td style=""><?php if($row['payment_mode']=='1') echo 'Cash'; elseif($row['payment_mode']=='2') echo 'Card'; elseif($row['payment_mode']=='3') echo 'UPI'; else echo 'Other'; ?></td>
|
|
<td style=""><?php echo $row['cust_name']; ?></td>
|
|
<td style="">
|
|
<div style="display: flex; flex-direction: row;">
|
|
<?php if(isset($_SESSION['email']) && $_SESSION['email'] != 'user@fashionavenue.com'){ echo '<a href="print-bill?bill='.$row['id'].'" target="_blank"> Print </a> ';} ?>
|
|
<?php if(isset($_SESSION['email']) && $_SESSION['email'] == 'mousumi@fashionavenueonline.com'): ?>
|
|
<button onclick="openModal(event, '<?php echo $row['id']; ?>')">Delete</button>
|
|
<div id="myModal_<?php echo $row['id']; ?>" class="modal" style="display: none;">
|
|
<!-- Modal content -->
|
|
<div class="modal-content">
|
|
<div class="modal-center">
|
|
<span class="close" onclick="closeModal('<?php echo $row['id']; ?>')">×</span>
|
|
<p>Are you sure you want to delete Bill <?php echo $row['id']; ?>?</p>
|
|
<div style="display: flex; flex-direction: row;">
|
|
<form method="POST">
|
|
<input type="hidden" name="delete_bill" value="<?php echo $row['id'] ?>" />
|
|
<input type="submit" value="YES" />
|
|
</form>
|
|
<div>
|
|
<p style="background-color: #3d3d3d; color: #fff; cursor: pointer; margin-top: 0.5px; padding: 3px 6px 3px 6px;" class="" onclick="closeModal('<?php echo $row['id']; ?>')">NO</p>
|
|
</div>
|
|
</div>
|
|
<!-- <a href="/119/view-bills">NO</a> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
}
|
|
elseif($_GET['payment']=='0'){
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill` WHERE `payment_mode`='0' ".$between." ORDER BY `id` DESC";
|
|
$result= mysqli_query($link, $query);
|
|
while ($row= mysqli_fetch_assoc($result)) {
|
|
?>
|
|
<tr>
|
|
<td><?php echo $row['id']; ?></td>
|
|
<td><?php echo $row['time']; ?></td>
|
|
<td><?php echo $row['cust_phone']; ?></td>
|
|
<td><?php echo $row['total']; ?></td>
|
|
<td><?php echo $row['cust_name']; ?></td>
|
|
<td> <a href="create_bill?bill=<?php echo $row['id']; ?>" > Continue </a> </td>
|
|
</tr>
|
|
<?php }
|
|
}
|
|
else{
|
|
$link = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$query="SELECT * FROM `".SHOP_ID."_bill` WHERE `payment_mode`='".$_GET['payment']."' ".$between." ORDER BY `id` DESC";
|
|
$result= mysqli_query($link, $query);
|
|
while ($row= mysqli_fetch_assoc($result)) {
|
|
?>
|
|
<tr>
|
|
<td><?php echo $row['id']; ?></td>
|
|
<td><?php echo $row['time']; ?></td>
|
|
<td><?php echo $row['cust_phone']; ?></td>
|
|
<td><?php echo $row['total']; $total=$total+$row['total'];?></td>
|
|
<td><?php echo $row['cust_name']; ?></td>
|
|
<td> <div style="display: flex; flex-direction: row;">
|
|
<?php if(isset($_SESSION['email']) && $_SESSION['email'] != 'user@fashionavenue.com'){ echo '<a href="print-bill?bill='.$row['id'].'" target="_blank"> Print </a> ';} ?>
|
|
|
|
|
|
<?php if(isset($_SESSION['email']) && $_SESSION['email'] == 'mousumi@fashionavenueonline.com'): ?>
|
|
<button onclick="openModal(event, '<?php echo $row['id']; ?>')">Delete</button>
|
|
<div id="myModal_<?php echo $row['id']; ?>" class="modal" style="display: none;">
|
|
<!-- Modal content -->
|
|
<div class="modal-content">
|
|
<div class="modal-center">
|
|
<span class="close" onclick="closeModal('<?php echo $row['id']; ?>')">×</span>
|
|
<p>Are you sure you want to delete Bill <?php echo $row['id']; ?>?</p>
|
|
<div style="display: flex; flex-direction: row;">
|
|
<form method="POST">
|
|
<input type="hidden" name="delete_bill" value="<?php echo $row['id'] ?>" />
|
|
<input type="submit" value="YES" />
|
|
</form>
|
|
<div>
|
|
<p style="background-color: #3d3d3d; color: #fff; cursor: pointer; margin-top: 0.5px; padding: 3px 6px 3px 6px;" class="" onclick="closeModal('<?php echo $row['id']; ?>')">NO</p>
|
|
</div>
|
|
</div>
|
|
<!-- <a href="/119/view-bills">NO</a> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php }
|
|
}
|
|
}
|
|
|
|
?>
|
|
</table>
|
|
|
|
|
|
<?php
|
|
echo '<h3> Total Bill: ', $total ;
|
|
if(isset($_SESSION['email']) && $_SESSION['email']=='mousumi@fashionavenueonline.com' || $_SESSION['email']=='user@fashionavenue.com'){
|
|
echo ', Cost: ', $total_cost , ', Profit: ', $total-$total_cost,' Total GST: ', $totalGSTlistedBills ;
|
|
}
|
|
echo '</h3>'; ?>
|
|
|
|
|
|
<?php
|
|
if(isset($_POST['delete_bill']) && $_POST['delete_bill']){
|
|
// echo $_POST['delete_bill'];
|
|
$conn = new mysqli(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
|
|
$sql = "DELETE FROM `".SHOP_ID."_bill` WHERE `id` = '".$_POST['delete_bill']."'";
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo 'Bill ID'.$_POST['delete_bill'].' Removed.';
|
|
echo '<script>window.location.href="/119/view-bills?payment=paid";</script>';
|
|
} else { echo "Error deleting record: " . $conn->error; }
|
|
$conn->close();
|
|
// sleep(1);
|
|
}
|
|
?>
|
|
<script>
|
|
// Function to open the modal
|
|
function openModal(event, billId) {
|
|
event.preventDefault(); // Prevent the default action (e.g., form submission or link click)
|
|
var modal = document.getElementById("myModal_" + billId);
|
|
modal.style.display = "block";
|
|
}
|
|
|
|
// Function to close the modal
|
|
function closeModal(billId) {
|
|
var modal = document.getElementById("myModal_" + billId);
|
|
modal.style.display = "none";
|
|
}
|
|
|
|
// Close the modal if clicked outside of it
|
|
window.onclick = function(event) {
|
|
var modals = document.querySelectorAll('.modal');
|
|
modals.forEach(function(modal) {
|
|
if (event.target == modal) {
|
|
modal.style.display = "none";
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<style>
|
|
/* Modal styles */
|
|
.modal {
|
|
display: flex;
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
/* background-color: rgba(0,0,0,0.5); */
|
|
z-index: 9999;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.modal-content {
|
|
|
|
width: 100%;
|
|
}
|
|
|
|
.modal-center {
|
|
max-width: 500px;
|
|
margin: auto; /* Centers horizontally */
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
box-shadow: 0 0 10px rgba(0,0,0,0.3);
|
|
}
|
|
|
|
/* Close button style */
|
|
.close {
|
|
color: #aaa;
|
|
float: right;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.close:hover,
|
|
.close:focus {
|
|
color: black;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|