File "cashinout.php"

Full path: /home/atrmarke/public_html/atrdemolive.site/bshop/log/cashinout.php
File size: 0.05 KB (49.8 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php
ob_start();
include("../db/cn.php");

 // Check if the user is logged in
if(isset($_SESSION['user_name']) && isset($_SESSION['user_role']) && isset($_SESSION['outlet_name'])
 && isset($_SESSION['outlet_address'])) {
    $userName = $_SESSION['user_name'];
    $userRole = $_SESSION['user_role'];
	$outlet_address = $_SESSION['outlet_address'];
	$outlet_name = $_SESSION['outlet_name'];

        // Display the user's name and role
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['expence_add'])){
	$userName1 = $_SESSION['user_name'];
     $userRole1 = $_SESSION['user_role'];
	@$name_detail = $_POST['desc'];
	@$amount = $_POST["amount"];

	$date_time122 = date("Y-m-d");
	mysqli_query($connection,"insert into 
	incash(name_detail,amount,login_user,user_role,outlet_name,outlet_address,date_time)
	values('".$name_detail."','".$amount."','".$userName1."','".$userRole1."','".$outlet_name."','".$outlet_address."','".$date_time122."')");
	
	}
	
//-----------------------------------------------------------------------------------------
//opening Amount
$date_time = date("Y-m-d");
$record_opening = mysqli_query($connection,"select * from opening_amount where login_user = '$userName' && role = '$userRole' && date_time = '$date_time'");
 $row_amount = mysqli_fetch_array($record_opening);
 @$open_cash = $row_amount["open_cash"];
 //---------------------------------------------------------------
 // sales Sum
$date_time1 = date("Y-m-d");
$rec10 = mysqli_query($connection, "SELECT order_id, discount_amount FROM log_user_sales WHERE login_user = '$userName' AND user_role = '$userRole' AND date_time = '$date_time1' && paid_by ='cash' GROUP BY order_id");

if ($rec10) {
    $total_sales = 0;
    while ($row3 = mysqli_fetch_array($rec10)) {
        @$total_sales += $row3['discount_amount'];
    }
    echo "";
    if (mysqli_num_rows($rec10) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}



$date1= date("Y-m-d");
$rec11 = mysqli_query($connection, "SELECT r_order_id, discount_amount FROM log_user_sales WHERE 
 paid_by = 'cash' && status ='refund' AND date_time = '$date1' GROUP BY r_order_id");

if ($rec11) {
    $re_total_sales = 0;
    while ($rowre = mysqli_fetch_array($rec11)) {
        @$re_total_sales += $rowre['discount_amount'];
    }
    echo "";
    if (mysqli_num_rows($rec11) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//--------------------------------------------------------------------------------



//--------------------------------------------------------------------------------
$date_time12 = date("Y-m-d");
$rec12 = mysqli_query($connection, "SELECT * FROM purchase WHERE login_user = '$userName' AND user_role = '$userRole' AND date_time = '$date_time12' && paid_by ='cash' AND status ='return' GROUP BY r_inv_id ");

if ($rec12) {
    $cash_purchase_return = 0;
    while ($row32 = mysqli_fetch_array($rec12)) {
        @$cash_purchase_return += $row32['discount_amount'];
    }
    echo "";
    if (mysqli_num_rows($rec12) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//--------------------------------------------------------------------------------

$date_time1211 = date("Y-m-d");
$rec12m = mysqli_query($connection, "SELECT * FROM m_order WHERE login_user = '$userName' AND user_role = '$userRole' AND date_time = '$date_time1211' && paid_by ='cash' GROUP BY order_id ");

if ($rec12m) {
    $cash_purchase_m = 0;
    while ($row32m = mysqli_fetch_array($rec12m)) {
        @$cash_purchase_m += $row32m['total_amount'];
    }
    echo "";
    if (mysqli_num_rows($rec12m) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}



//--------------------------------------------------------------------------------
// incash Sum cash expense
$date_time21 = date("Y-m-d");
$cash_out = mysqli_query($connection, "SELECT SUM(amount) AS total_amount FROM incash where date_time = '$date_time21' && login_user = '$userName' && user_role = '$userRole' && date_time = '$date_time21' && paid_by = 'cash' ");
if ($cash_out) {
    $cash_outdata = mysqli_fetch_array($cash_out);
    if ($cash_outdata && isset($cash_outdata['total_amount'])) {
        $totalAmount_cashexpense = $cash_outdata['total_amount'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//-----------------------------------------------------------------------------------------
//credit get cash recieved
		$date_time212 = date("Y-m-d");
$credit_get = mysqli_query($connection, "SELECT SUM(amount) AS total_amounts FROM credit_paid where date_time = '$date_time212' && user_name = '$userName' && user_role = '$userRole' && paid_by = 'cash'");
if ($credit_get) {
    $credit_data = mysqli_fetch_array($credit_get);
    if ($credit_data && isset($credit_data['total_amounts'])) {
        $credit_cashrecievable = $credit_data['total_amounts'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//-----------------------------------------------------------------------------------------

//cash paid // cash paid to supplier
		$date_time2121 = date("Y-m-d");
$cash_paid = mysqli_query($connection, "SELECT SUM(supplier_amount) AS total_amounts FROM supplier_paid  where date_time = '$date_time2121' && status = 'cash'");
if ($credit_get) {
    $cash_paid_data = mysqli_fetch_array($cash_paid);
    if ($cash_paid_data && isset($cash_paid_data['total_amounts'])) {
        $credit_done = $cash_paid_data['total_amounts'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//-----------------------------------------------------------------------------------------

//cash purchase
		
/*$credit_purchase = mysqli_query($connection, "SELECT SUM(total_amount) AS total_amounts FROM purchase where date_time = '$date_time2122' && user_name = '$userName' && user_role = '$userRole' && paid_by = 'cash'" );
if ($credit_purchase) {
    $credit_purchase_data = mysqli_fetch_array($credit_purchase);
    if ($credit_purchase_data && isset($credit_purchase_data['total_amounts'])) {
        $credit_cash_purchase1 = $credit_purchase_data['total_amounts'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}*/
$date_time2122 = date("Y-m-d");
$credit_purchase = mysqli_query($connection, "SELECT * FROM purchase WHERE  date_time = '$date_time2122' && paid_by ='cash' GROUP BY inv_id ");

if ($credit_purchase) {
    $credit_cash_purchase1 = 0;
    while ($row32m = mysqli_fetch_array($credit_purchase)) {
        @$credit_cash_purchase1 += $row32m['discount_amount'];
    }
    echo "";
    if (mysqli_num_rows($credit_purchase) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}

//---------------------------------------------------------------------------------------- if ($rec11) {
    $total_sales_return = 0;
    while ($row31 = mysqli_fetch_array($rec11)) {
        $total_sales_return += $row31['sale_return_cash'];
    }
    
    echo  "Rs ".$total_sales_return;
    
    if (mysqli_num_rows($rec11) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
} 



$date = date("Y-m-d");
$with = mysqli_query($connection, "SELECT * FROM withdraw WHERE  date_time = '$date' AND paid_by = 'cash'  ");

if ($with) {
    $draw = 0;
    while ($rowdraw = mysqli_fetch_array($with)) {
        @$draw += $rowdraw['amount'];
    }
    echo "";
    if (mysqli_num_rows($with) == 0) {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}

//-------------------------------------
// POS cash credit received
$date_21 = date("Y-m-d");

// Prepare and execute the query
$query = "SELECT order_id, cash_amount AS totalamounts 
          FROM log_user_sales 
          WHERE paid_by = 'credit' 
            AND status = '' 
            AND r_order_id = '' 
            AND date_time = ? 
          GROUP BY order_id";
$stmt = $connection->prepare($query);
$stmt->bind_param("s", $date_21);
$stmt->execute();
$result = $stmt->get_result();

$pos_credit = 0;
if ($result) {
    while ($row = $result->fetch_assoc()) {
        if (isset($row['totalamounts'])) {
            $pos_credit += $row['totalamounts'];
        }
    }
    // Output the total or handle it as needed
    echo " ";
} else {
    echo "Error executing query: " . $stmt->error;
}

$stmt->close();
//----------------------------------------
// incash Sum cash form_i
$date_time21a = date("Y-m-d");
$cash_from = mysqli_query($connection, "SELECT SUM(amount_i) AS total_amountq FROM transfer where  from_i = 'cash'  && date_time = '$date_time21a' ");
if ($cash_from) {
    $cash_fromdata = mysqli_fetch_array($cash_from);
    if ($cash_fromdata && isset($cash_fromdata['total_amountq'])) {
        $cash_from_i = $cash_fromdata['total_amountq'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}

// incash Sum cash to_i
$date_time21d = date("Y-m-d");
$cash_to = mysqli_query($connection, "SELECT SUM(amount_i) AS total_amounts FROM transfer where  to_i = 'cash' && date_time = '$date_time21d' ");
if ($cash_to) {
    $cash_todata = mysqli_fetch_array($cash_to);
    if ($cash_todata && isset($cash_todata['total_amounts'])) {
        $cash_to_i = $cash_todata['total_amounts'];
        echo "";
    } else {
        echo "";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}
//-----------------------------------------------------------------------------------------
// Ensure all variables are numeric and default to 0 if not set or empty
@$total_sales = intval($total_sales);
@$credit_cashrecievable = intval($credit_cashrecievable);
@$cash_purchase_return = intval($cash_purchase_return);
@$credit_cash_purchase1 = intval($credit_cash_purchase1);
@$open_cash = intval($open_cash);
@$credit_done = intval($credit_done);
@$cash_purchase_m = intval($cash_purchase_m);
@$totalAmount_cashexpense = intval($totalAmount_cashexpense);
@$draw = intval($draw);
@$total_sales_return = intval($total_sales_return);

// Perform calculations
@$amount_addtion = $total_sales + $credit_cashrecievable ;
@$amount_sub = $credit_cash_purchase1;

$new_final_end = $open_cash + $amount_addtion - $amount_sub - @$cash_from_i;
$new_final_end1 = $new_final_end - $credit_done + $cash_purchase_m + @$cash_to_i + $pos_credit;
$new_final_end2 = $new_final_end1 - $totalAmount_cashexpense  ;
$new_f = $new_final_end2 - $draw - $re_total_sales  ;
$NewF = $new_f - $total_sales_return + (int)$cash_purchase_return;



//-----------------------------------------------------------------------------------------
//opening_amount
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['open_submit'])){
	

	$open_amount = $_POST["open_amount"];
	mysqli_query($connection,"insert into opening_amount(open_cash,login_user,outlet_name,outlet_address,date_time,role)
	values('".$open_amount."','".$userName."','".$outlet_name."','".$outlet_address."','".$date_time2122."','".$userRole."')");

// Redirect to logout.php
echo '<script type="text/javascript">window.location.href="cashinout.php";</script>';
    //header("Location: cashinout.php");
    exit();
}

//----------------------------------------------------------------------------------------

//opening_amount
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['open_cash_amount'])){
	

	$open_amount1 = $_POST["open_amount1"];
	mysqli_query($connection,"insert into cash_opening_amount(open_cash,login_user,outlet_name,outlet_address,date_time,role)
	values('".$open_amount1."','".$userName."','".$outlet_name."','".$outlet_address."','".$date_time2122."','".$userRole."')");

// Redirect to logout.php
echo '<script type="text/javascript">window.location.href="cashinout.php";</script>';
    //header("Location: cashinout.php");
    exit();
}



//closing Drawer
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['closedrawer'])){
    
    $open_cash_f = $_POST["open_cash_f"];
    $sale_cash_f = $_POST["sale_cash_f"];
    $sale_cash_r = $_POST["sale_cash_r"];
    $cash_purchase_f = $_POST["cash_purchase_f"];
    $cash_purchase_r = $_POST["cash_purchase_r"];
    $cash_recieved_f = $_POST["cash_recieved_f"];
    $cash_paid_f = $_POST["cash_paid_f"];
    $cash_expence_f = $_POST["cash_expence_f"];
    $cash_full_f = $_POST["cash_full_f"];
	 $withdraw = $_POST["withdraw"];
    $drawer_amount = $_POST["drawer_amount"];
    $remarks = $_POST["remarks"];
    $user = $userName;
    $role = $userRole;
    $outlet = $outlet_name;
    $address = $outlet_address;
    $date_time = date('Y-m-d');

    $query = "INSERT INTO closing_amount (
        open_cash,
        cash_sales,
        cash_sales_return,
        cash_purchase,
        cash_purchase_return,
        cash_recieved,
        cash_paid,
        cash_expence,
        cash_close,
		cash_draw,
        drawer_amount,
        login_user,
        outlet_name,
        outlet_address,
        role,
        date_time,
        remarks
    ) VALUES (
        '$open_cash_f',
        '$sale_cash_f',
        '$sale_cash_r',
        '$cash_purchase_f',
        '$cash_purchase_r',
        '$cash_recieved_f',
        '$cash_paid_f',
        '$cash_expence_f',
        '$cash_full_f',
		'$withdraw',
        '$drawer_amount',
        '$user',
        '$outlet',
        '$address',
        '$role',
        '$date_time',
        '$remarks'
    )";

    mysqli_query($connection, $query);

    // Redirect to logout.php
    echo '<script type="text/javascript">window.location.href="logout.php";</script>';
    //header("Location: logout.php");
    exit(); // Ensure script execution stops after redirection

}
//-----------------------------------------------------------------------------------------
ob_end_flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Cash ~ IN & OUT ~ </title>
    <!-- Latest compiled and minified CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="css/custom_css.css" />
    <!-- QRCode.js --> 
</head>
<style>
 #table-container-wrapper {
    max-height: 400px; /* Adjust the maximum height as needed */
    overflow-y: auto; /* Enable vertical scroll when content overflows */

}
@media (max-width: 880px) {
    .col-4 {
        width: 33.33% !important;
    }
    .fa-wifi {
        display: none !important;
    }
    .col-6 {
        width: 50% !important;
    }
}

@media (min-width: 880px) {
    .sidebar {
        width: 100%;
        /* Change sidebar width to 100% on mobile */
        max-width: 120px; /* Set maximum width for the sidebar */
    }
}

@media (min-width: 880px) {
    .main-content {
        margin-left: ; /* Width of the sidebar */
    }
}

/* Added new class to control overlay */
.overlay {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 999;
    display: none; /* Initially hidden */
}
    /* Custom styles for sidebar */
    .sidebar {
        width: 100px;
        background: linear-gradient(360deg, #060606, #3C2F23);
        position: fixed;
        bottom: 0;
        top: 60px;
        transition: transform 0.3s ease-in-out;
        transform: translateX(0);
        z-index: 1;
        height: 100%;
        border-radius: 0px;
		   transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
    }

    .sidebar.hide {
        transform: translateX(-100px);
        /* Move sidebar out of the viewport when it is hidden */
    }

    .sidebar .nav-item {
        padding: 10px 0;
        text-align: center;
        position: relative;
        font-size: 12px;
    }

    .sidebar .nav-link {
        color: #fff;
        position: relative;
        /* Ensure icon and text are positioned relative to the nav link */
        z-index: 2;
        /* Ensure the text and icon are above the hover background */
    }

    .sidebar .nav-link i {
        margin-bottom: 5px;
        /* Adjust the margin of the icon */
    }

    /* Custom styles for hover effect */
    .sidebar .nav-item:hover:after {
        background-color: #fff;
        content: '';
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        /* Ensure the hover background is below the text and icon */
    }

    .sidebar .nav-item:hover .nav-link {
        color: #503F2E;
    }

    /* Custom styles for divider */
    .sidebar .nav-item:after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 1px;
        background-color: #fff;
        transition: height 0.3s ease-in-out;
        /* Transition effect for smooth animation */
    }

    /* Custom styles for header */
    .header {
        background: linear-gradient(90deg, #3C2F23, #060606);
        color: #fff;
        padding: 10px;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 2;
        height: 69px;
        box-shadow: #FFF 2px 0px 0px 0px;
        /* Ensure header appears above sidebar */
    }

    .header .navbar-toggler {
        color: #fff;
    }

    .header .navbar-toggler-icon {
        color: #fff;
        /* Set the color of the toggle button to white */
    }

    .header .navbar-toggler.white {
        color: #fff !important;
        /* Ensure the toggle button is white */
    }

    .header .navbar-brand {
        color: #fff;
        /* Set navbar brand text color to white */
    }

    .header .nav-item .nav-link {
        color: #fff;
        /* Set nav link text color to white */
    }

.main-content {
    margin-top: 50px; /* Height of fixed header */
    margin-left: 100px; /* Initially, set margin-left to 0 */
    padding-top: 30px; /* Height of fixed header */
    transition: margin-left 0.3s ease-in-out; /* Add transition for smoother animation */
}


    /* Custom styles for search bar */
    .search-container {
        display: flex;
        align-items: center;
       width:100%;
        margin: 2px auto;
        float:left;
	}

/* Updated hide class to apply to the overlay */
.sidebar.hide, .overlay.hide {
    transform: translateX(-100%);
}

    .search-input {
        width: 100%;
        padding: 10px 30px 10px 10px;
        /* Adjust padding to accommodate the icon */
        border: 1px solid #ccc;
        border-radius: 20px;
        font-size: 16px;
    }

    .search-icon {
        position: relative;
        left: -25px;
        /* Adjust the position of the icon */
        color: #aaa;
    }

    .search-icon i {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
    }

    .btn-dark {
        background: #503F2E;
        color: #fff;
        border: 1px solid #503F2E;
    }

    .btn-dark:hover {
        background: #fff;
        color: #503F2E;
        border: 1px solid #503F2E;
    }

    .bg-dark2 {
        background: #503F2E;
        color: #fff;
    }

    .modal-content {
        animation: modal-animation 0.5s;
    }

    @keyframes modal-animation {
        from {
            opacity: 0;
            transform: scale(0.8);
        }

        to {
            opacity: 1;
            transform: scale(1);
        }
    }
		
		

 /* Basic styling */
    .tab {
        display: none;
        padding: 20px;
    }
    .active {
        display: block;
    }
    .tab-buttons {
        display: flex;
    }
    .tab-button {
        cursor: pointer;
        padding: 10px 10px;
        background-color: #ffff;
        border: 1px solid #0A5064;
        border-radius: 5px 5px 0 0;
        margin-right: 5px;
		color:#212529;
		font-size:13px;
    }
    .tab-button.active {
        background-color: #212529;
		color:#fff;
    }

    /* Background colors for tab content */
    #tab1 {
        background-color: #fff;
		color:#212529;
		padding:20px;
    }
    #tab2 {
        color:#212529;
		background-color: #;
    }
    #tab3 {
		color:#212529;
        background-color: #;
    }
</style>

<body>
<?php  include("common/hd.php");?>
<!-- Sidebar -->
<?php include("common/sd.php"); 

?>

<div class="main-content">

<div class="container-fluid">
<div class="row">
<div class="col-sm-6 text-capitalize">
<h3 style="color:#212529;">Cash Drawer</h3>
</div>
<div class="col-sm-6" >
<br />
<button type="button" class="btn btn-dark btn-sm" data-toggle="modal" data-target="#addOpenModal" >Add Opening Amount</button>&nbsp;&nbsp;  
&nbsp;&nbsp;


   
<!--<a href="pos.php"><button type="button" class="btn btn-dark" ><i class="fa fa-arrow-left"></i></button></a>-->

<span  style=" float:right; margin-top:-7px; padding:11px;background:#524C42; box-shadow: 0px 0px 1px 1px #CECECE; border-radius:5px; 
color:#fff; text-transform:capitalize; font-size:14px;"><?php echo $userName;?></span>



</div>
</div>

</div>
<?php  
?>
<br />
<div class="container">
<div class="tab-buttons">
    <div class="tab-button active" onclick="openTab(event, 'tab1')">Overview</div>
    <div class="tab-button" onclick="openTab(event, 'tab3')">Cash Sales</div>
    <div class="tab-button" onclick="openTab(event, 'tab7')">Cash Sales Return</div>
    <!--<div class="tab-button" onclick="openTab(event, 'tab9')">Cash Sales Adj</div>-->
    <div class="tab-button" onclick="openTab(event, 'tab6')">Cash Purchases</div>
    <div class="tab-button" onclick="openTab(event, 'tab8')">Cash Purchases Return</div>
    <div class="tab-button" onclick="openTab(event, 'tab4')">Cash Recieved</div>
    <div class="tab-button" onclick="openTab(event, 'tab5')">Cash Paid</div>
    <div class="tab-button" onclick="openTab(event, 'tab2')">Cash Expense</div>
    <div class="tab-button" onclick="openTab(event, 'tab10')">Cash Withdraw</div>
    
</div>

<div class="tab-container">
    <div id="tab1" class="tab active">
    <h4>Overview</h4>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <div class="container-fluid">
        <div class="row" style="padding:20px;background:#fff; box-shadow: 0px 0px 5px 2px #CCC; border-radius:10px;">
            <div class="col-sm-12" style="padding:20px;">
            <table class="table table-hover"  >
            <tr style="color:#8A1218;padding:20px;">
            <td style="font-weight:600;">Opening Cash</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($open_cash) ? "Rs ".$open_cash."" : ""; ?>
            <input type="hidden" name="open_cash_f" value="<?php echo $open_cash; ?>">
            </td>
            </tr>
            <tr>
            <td style="font-weight:600;">Cash Sales</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($total_sales) ? "Rs ".$total_sales."" : ""; ?>
            <input type="hidden" name="sale_cash_f" value="<?php echo $total_sales; ?>">
            </td>
            </tr>
            <tr>
            <tr>
            <td style="font-weight:600;">Cash Sales Return</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($re_total_sales) ? "Rs ".$re_total_sales."" : ""; ?>
            <input type="hidden" name="sale_cash_r" value="<?php echo $re_total_sales; ?>">
            </td>
            </tr>
             <tr>
            <!--<tr>
            <td style="font-weight:600;">Cash Sales Adj</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($cash_purchase_m) ? "Rs ".$cash_purchase_m."" : ""; ?></td>
            </tr>-->
            <tr>
            <td style="font-weight:600;">Cash Purchase</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
			<?php echo isset($credit_cash_purchase1) ? "Rs ".$credit_cash_purchase1."" : ""; ?></td>
            <input type="hidden" name="cash_purchase_f" value="<?php echo $credit_cash_purchase1; ?>">
            </tr>
             <tr>
            <td style="font-weight:600;">Cash Purchase Return</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($cash_purchase_return) ? "Rs ".$cash_purchase_return."" : ""; ?> 
            <input type="hidden" name="cash_purchase_r" value="<?php echo $cash_purchase_return ?>">
            </td>
            </tr>
             <tr>
            <td style="font-weight:600;">Cash Recieved</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($credit_cashrecievable) ? "Rs ".$credit_cashrecievable."" : ""; ?>
            <input type="hidden" name="cash_recieved_f" value="<?php echo $credit_cashrecievable; ?>">
            </td>
            </tr>
             <tr>
            <td style="font-weight:600;">POS Credit Recieved</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($pos_credit) ? "Rs ".$pos_credit."" : ""; ?>
            <input type="hidden" name="cash_pos_f" value="<?php echo $pos_credit; ?>">
            </td>
            </tr>
            <tr>
            <td style="font-weight:600;">Cash Paid</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($credit_done) ? "Rs ".$credit_done."" : ""; ?>
            <input type="hidden" name="cash_paid_f" value="<?php echo $credit_done; ?>">
            </td>
            </tr>
            <tr>
            <td style="font-weight:600;">Cash Expense</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($totalAmount_cashexpense) ? "Rs ".$totalAmount_cashexpense."" : ""; ?>
            <input type="hidden" name="cash_expence_f" value="<?php echo $totalAmount_cashexpense; ?>">
            </td>
            </tr>
             
            <tr>
            <td style="font-weight:600;">Cash Withdraw</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
			<?php echo isset($draw) ? "Rs ".$draw."" : ""; ?>
            <input type="hidden" name="withdraw" value="<?php echo $draw; ?>">
            </td>
            </tr>
           <tr>
            <td style="font-weight:600;">Transfer Out</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($cash_from_i) ? "Rs ".$cash_from_i."" : ""; ?>
            <input type="hidden" name="cash_from_f" value="<?php echo $cash_from_i ;?>">
            </td>
            </tr>
             <tr>
            <td style="font-weight:600;">Transfer In</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><?php echo isset($cash_to_i) ? "Rs ".$cash_to_i."" : ""; ?>
            <input type="hidden" name="cash_from_f" value="<?php echo $cash_to_i ;?>">
            </td>
            
             
            <tr>
            <td style="font-weight:600;">Closing Cash</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
			<?php echo isset($NewF) ? "Rs ".$NewF."" : ""; ?>
            <input type="hidden" name="cash_full_f" value="<?php echo $NewF; ?>">
            </td>
            </tr>
            <td style="font-weight:600;">Cash Drawer Amount</td>
            <td style="text-align:right; font-size:19px; font-weight:600;"><input type="text" name="drawer_amount" 
            placeholder="Rs" style="width:220px; height:35px; border:1px solid #999;box-shadow: 0px 0px 4px 1px #CCC; border-radius:5px;"></td>
            </tr>           
            </table>
            </div>
            
            
        </div>
        <br />
        <div class="row">
        
         <div class="col-sm-12">
         
         
         <textarea placeholder="'Remarks:'"  name="remarks"  class="form-control" style="height:150px;"></textarea>
         <br />
         <button class="btn btn-dark" type="submit" name="closedrawer"> <i class="fa fa-cash-register"></i>&nbsp;Close Cash Drawer
         </button>
        
         </div>
         
        </div>
        
    </div>
     </form>
    <p></p>
</div>

    <div id="tab2" class="tab">
        <h4>Cash Expense</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
      </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
                <td>Date</td>
                
                <th>Name</th>
                
                <td>Amount(Rs)</td>
                <td> Paid By</td>
                </tr>
               
               <?php
			   $date_time2111 = date("Y-m-d");
                        $rec2 = mysqli_query($connection,"select * from incash where date_time = '$date_time2111' && paid_by = 'cash'");    
			     while($row2 = mysqli_fetch_array($rec2)){
			   ?>
              <tr>
               <td><?php echo $row2["date_time"]; ?></td>
               
               <td class="text-capitalize" style="font-weight:600;"><?php echo $row2["name_detail"]; ?></td>
               
               <td> <?php echo $row2["amount"]; ?></td>
               <td style="text-transform:capitalize;"><?php echo $row2["login_user"]."";?></td>
               </tr>
              <?php } ?>
               </table>
             </div>
           </div>
          </div>
          
          <div id="tab10" class="tab">
        <h4>Cash Withdraw</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
      </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
                <td>Date</td>
                
                <th>Name</th>
                
                <td>Amount(Rs)</td>
                <td> Paid By</td>
                </tr>
               
               <?php
			   $dateTime = date("Y-m-d");
                        $recw = mysqli_query($connection,"select * from withdraw where date_time = '$dateTime' AND paid_by = 'cash'");    
			     while($roww = mysqli_fetch_array($recw)){
			   ?>
              <tr>
               <td><?php echo $roww["date_time"]; ?></td>
               
               <td class="text-capitalize" style="font-weight:600;"><?php echo $roww["name_detail"]; ?></td>
               
               <td> <?php echo $roww["amount"]; ?></td>
               <td style="text-transform:capitalize;"><?php echo $roww["login_user"]."";?></td>
               </tr>
              <?php } ?>
               </table>
             </div>
           </div>
          </div>
          
          <div id="tab7" class="tab">
        <h4>Cash Sales Return</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
      </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center" >
                <tr style="background:#212529; color:#fff;" >
               <!-- <td>ID</td>-->
                <td>Date</td>
                <td>Order ID</td>
                <td>Sub Total(Rs)</td>
                
                <td>Discount(Rs)</td>
                <td>Amount(Rs)</td>
                </tr>
              <?php
$daTe = date("Y-m-d");
$rec = mysqli_query($connection, "SELECT *, discount_amount
                                   FROM log_user_sales 
                                   WHERE status = 'refund' &&  paid_by = 'cash' AND date_time = '$daTe'
                                   GROUP BY  r_order_id");
// Check if any records were found
if (mysqli_num_rows($rec) > 0) {

    // Loop through results and display them
    while ($row = mysqli_fetch_array($rec)) { ?>
        <tr>
        <td><?php echo $row["date_time"];?></td>
            <td style="font-weight:600;"><?php echo $row["order_id"]; ?></td>
            <td> <?php echo $row["discount_amount"]; ?>.00</td>
            
            <td> <?php echo $row["discounted"]; ?>
</td>            <td> <?php echo $row["discount_amount"]; ?></td>
        </tr>
    <?php }
} else {
    echo "No records found.";
}
?>
              </table>
             </div>
           </div>
          </div>
          
          <!--<div id="tab9" class="tab">
        <h4>Cash Sales Adjustment</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
      </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center" >
                <tr style="background:#212529; color:#fff;" >
               <!-- <td>ID</td>
                <td>Date</td>
                <td>Order ID</td>
                <td>Sub Total</td>
                
                <td>Discount</td>
                <td>Amount</td>
                </tr>
              <?php
$date_time = date("Y-m-d");
$rec = mysqli_query($connection, "SELECT *, SUM(total_amount) AS total_product
                                   FROM m_order
                                   WHERE login_user = '$userName' && user_role = '$userRole' && date_time = '$date_time' 
                                   GROUP BY order_id");
// Check if any records were found
if (mysqli_num_rows($rec) > 0) {
    // Loop through results and display them
    while ($row = mysqli_fetch_array($rec)) { ?>
        <tr>
        <td><?php echo $row["date_time"];?></td>
            <td style="font-weight:600;"><?php echo $row["order_id"]; ?></td>
            <td>Rs <?php echo $row["discount_amount"]; ?>.00</td>
            
            <td>Rs <?php echo $row["discounted"]; ?>
</td>            <td>Rs <?php echo $row["total_amount"]; ?></td>
        </tr>
    <?php }
} else {
    echo "No records found.";
}
?>
              </table>
             </div>
           </div>
          </div>-->
          
          <div id="tab8" class="tab">
        <h4>Cash Purchase Return</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
      </div>
           <br />
           <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
                
                <td>Date</td>
                <th> Invoice ID </th>
                <td>Sub Total(Rs)</td>
                <th> Discount(Rs)</th>
                
               
                <td>Amount(Rs)</td>
      
                </tr>
               
               <?php
			   $date_time11 = date("Y-m-d");
                   $rec5 = mysqli_query($connection,
				   "select *, SUM(net_amount) AS Ne from purchase where login_user = '$userName' && user_role = '$userRole' && outlet_name = '$outlet_name' && outlet_address = '$outlet_address' && date_time = '$date_time11' && paid_by = 'cash' AND status = 'return' GROUP BY r_inv_id");        
			     while($row6 = mysqli_fetch_array($rec5)){
			   ?>
              <tr>
              
               <td><?php echo $row6["date_time"]; ?></td>
               <td><?php echo $row6['r_inv_id'];?></td>
               
              
               
               <td class="text-capitalize"><?php echo $row6["Ne"]; ?></td>
               <td><?php echo $row6["discounted"]; ?></td> 
               
               <td> <?php echo $row6["discount_amount"]; ?></td>
              
             
               </tr>
              <?php } ?>
               </table>
           <br />
             <div class="col-sm-12">
               
             </div>
           </div>
          </div>
          
    </div>
    <div id="tab3" class="tab">
        <h4> Cash Sales</h2>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
        
            </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center" >
                <tr style="background:#212529; color:#fff;" >
               <!-- <td>ID</td>-->
                <td>Date</td>
                <td>Order ID</td>
                <td>Sub Total(Rs)</td>
                
                <td>Discount(Rs)</td>
                <td>Amount(Rs)</td>
                </tr>
              <?php
$date_time = date("Y-m-d");
$rec = mysqli_query($connection, "SELECT SUM(net_amount) AS NetAmouts,order_id,total_amount,discounted,discount_amount,date_time, SUM(net_amount) AS total_product
                                   FROM log_user_sales 
                                   WHERE login_user = '$userName' && user_role = '$userRole' && date_time = '$date_time' && paid_by = 'cash' &&  r_order_id = ''
                                   GROUP BY order_id");
// Check if any records were found
if (mysqli_num_rows($rec) > 0) {
    // Loop through results and display them
    while ($row = mysqli_fetch_array($rec)) { ?>
        <tr>
        <td><?php echo $row["date_time"];?></td>
            <td style="font-weight:600;"><?php echo $row["order_id"]; ?></td>
            <td> <?php echo $row["NetAmouts"]; ?></td>
            
            <td> <?php echo $row["discounted"]; ?>
</td>            <td> <?php echo $row["discount_amount"]; ?></td>
        </tr>
    <?php }
} else {
    echo "";
}
?>
              </table>
             </div>
            
             
           </div>
          </div>
          
          <div id="tab4" class="tab">
        <h4 style="color:#212529;">Cash Recieved</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
    
           </div>
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
            
                <td>Date</td>
                
                <th>Name</th>
              
                <td>Amount(Rs)</td>
                <td>Status</td>
                <td> By</td>
                </tr>
               
               <?php
			   $date_time11 = date("Y-m-d");
                   $rec5 = mysqli_query($connection,
				   "select * from credit_paid where user_name = '$userName' && user_role = '$userRole' && outlet_name = '$outlet_name' && outlet_address = '$outlet_address' && date_time = '$date_time11' && paid_by = 'cash'");        
			     while($row6 = mysqli_fetch_array($rec5)){
			   ?>
              <tr>
              
               <td><?php echo $row6["date_time"]; ?></td>
               
               <td class="text-capitalize" style="font-weight:600;"><?php echo $row6["cr_name"]; ?></td>
               
               <td> <?php echo $row6["amount"]; ?></td>
               <td class="text-capitalize"><?php echo $row6["paid_by"]; ?></td>
               <td class="text-capitalize"><?php echo $row6["user_name"]; ?></td>
             
               </tr>
              <?php } ?>
               </table>
             </div>
           </div>
          </div>
          
          <div id="tab5" class="tab">
        <h4 style="color:#212529;">Cash Paid</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
            
  
            </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
             
                <td>Date</td>
                
                <th>Name</th>
              
                <td>Amount(Rs)</td>
                <td>Status</td>
                <td>By</td>
                </tr>
               
               <?php
			   $date_time11 = date("Y-m-d");
                   $rec51 = mysqli_query($connection,
				   "select * from supplier_paid where date_time = '$date_time11' AND status = 'cash'");        
			     while($row69 = mysqli_fetch_array($rec51)){
			   ?>
              <tr>
              
               <td><?php echo $row69["date_time"]; ?></td>
               
               <td class="text-capitalize" style="font-weight:600;"><?php echo $row69["supplier_name"]; ?></td>
               
               <td> <?php echo $row69["supplier_amount"]; ?></td>
               <td class="text-capitalize"> <?php echo $row69["status"]; ?></td>
               
               <td class="text-capitalize"><?php echo $row69["user_name"];?></td>
             
               </tr>
              <?php } ?>
               </table>
             </div>
           </div>
          </div>
          
          
          <div id="tab6" class="tab">
        <h4 style="color:#212529;">Cash Purchases</h4>
        <div class="container-fluid" id="table-container-wrapper">
           <div class="row">
           
            </div>
           
           <br />
             <div class="col-sm-12">
               <table class="table table-stripped text-center">
                <tr style="background:#212529; color:#fff;">
                
                 <td>Date</td>
                <td>Invoice ID</td>
                <td>Sub Total(Rs)</td>
                
                <td>Discount(Rs)</td>
                <td>Amount(Rs)</td>
      
                </tr>
               
               <?php
			   $date_time11 = date("Y-m-d");
                   $rec5 = mysqli_query($connection,
				   "select *, SUM(net_amount) AS netAmounts from purchase where date_time = '$date_time11' && paid_by = 'cash' && r_inv_id = '' GROUP BY inv_id");        
			     while($row6 = mysqli_fetch_array($rec5)){
			   ?>
               <tr>
        <td><?php echo $row6["date_time"];?></td>
            <td style="font-weight:600;"><?php echo $row6["inv_id"]; ?></td>
            <td> <?php echo $row6["netAmounts"]; ?></td>
            
            <td> <?php echo $row6["discounted"]; ?>
</td>            <td> <?php echo $row6["discount_amount"]; ?></td>
        </tr>
              
              <?php } ?>
               </table>
             </div>
           </div>
          </div>
          
          
    </div>
    
    
   </div> 
    
    
    
</div>
 <!-- Modal HTML -->
        <!-- Modal for adding purchases -->
            <div class="modal fade" id="addPurchaseModal" tabindex="-1" role="dialog" 
            aria-labelledby="addPurchaseModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title text-capitalize" id="addPurchaseModalLabel">Add Cash Expense</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <!-- Form for adding purchase -->
                            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
                            
                                <input type="text" name="desc" placeholder="Description / Name" class="form-control" />
                                <br />
                                <input type="text" name="amount" placeholder="Amount" class="form-control" />
                                <br />
                                <button type="submit"  class="btn btn-dark" name="expence_add">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            
            
            <div class="modal fade" id="addOpenModal" tabindex="-1" role="dialog" 
            aria-labelledby="addOpenModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title text-capitalize" id="addOpenModalLabel">Add Opening Amount</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <!-- Form for adding purchase -->
                            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
                                
                                <input type="text" name="open_amount" placeholder="Amount" class="form-control" />
                                <br />
                                <button type="submit" name="open_submit"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
 

    
    
</div>    
</body>
<!-- JavaScript libraries -->
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Latest compiled and minified Bootstrap JavaScript -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- FileSaver.js -->



<script>
document.addEventListener("DOMContentLoaded", function () {
    var sidebar = document.getElementById("sidebar");
    var overlay = document.createElement("div");
    overlay.classList.add("overlay");
    document.body.appendChild(overlay);

    function toggleSidebar() {
        sidebar.classList.toggle("hide");
        overlay.classList.toggle("hide");

        var mainContent = document.querySelector(".main-content");
        if (sidebar.classList.contains("hide")) {
            mainContent.style.marginLeft = "0";
        } else {
            mainContent.style.marginLeft = "100px"; // Width of the sidebar
        }
    }

    overlay.addEventListener("click", function () {
        toggleSidebar();
    });

    // Add toggle functionality to navbar toggler
    var navbarToggler = document.querySelector(".navbar-toggler");
    navbarToggler.addEventListener("click", function () {
        toggleSidebar();
    });

    // Automatically hide sidebar on all screen sizes
    // sidebar.classList.add("hide");
    // overlay.classList.add("hide");
    
    // Add class to body to prevent scrolling when sidebar is open
    // document.body.classList.add("noscroll");

    // Check if screen size is larger than a certain threshold (e.g., 768px for desktop screens)
    function checkScreenSize() {
        if (window.innerWidth > 768) {
            sidebar.classList.remove("hide");
            overlay.classList.remove("hide");
        } else {
            sidebar.classList.add("hide");
            overlay.classList.add("hide");
        }
    }

    // Check screen size on initial load and whenever the window is resized
    checkScreenSize();
    window.addEventListener("resize", checkScreenSize);
});
 

// Live search functionality
document.getElementById('searchInput').addEventListener('input', function() {
    var filter, table, tr, td, i, txtValue;
    filter = this.value.toUpperCase();
    table = document.getElementById("overviewTable");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[0]; // Change index based on column position
        if (td) {
            txtValue = td.textContent || td.innerText;
            if (txtValue.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
});
    // Function to switch between tabs
    function openTab(evt, tabName) {
        // Get all elements with class="tab" and hide them
        var tabs = document.getElementsByClassName("tab");
        for (var i = 0; i < tabs.length; i++) {
            tabs[i].style.display = "none";
        }

        // Get all elements with class="tab-button" and remove the class "active"
        var tabButtons = document.getElementsByClassName("tab-button");
        for (var i = 0; i < tabButtons.length; i++) {
            tabButtons[i].classList.remove("active");
        }

        // Show the current tab, and add an "active" class to the button that opened the tab
        document.getElementById(tabName).style.display = "block";
        evt.currentTarget.classList.add("active");
    }
</script>


</html>