File "assets.php"

Full path: /home/atrmarke/public_html/atrdemolive.site/if/pages/assets.php
File size: 0.02 KB (22.18 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php
ob_start();
include("db/cn.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
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'];
}

@$customer_name = $_GET["asse_head"];

$op = mysqli_query($connection,"select * from asset_opening_amount where asset_name = '$customer_name' ");
$openAmount = 0;
while($open = mysqli_fetch_array($op)){
    $openAmount += $open["open_amount"];
}

$pa = mysqli_query($connection,"select * from asset_p where asset_name = '$customer_name' ");
$pAmount = 0;
while($pur = mysqli_fetch_array($pa)){
    $pAmount += $pur["amount"];
}


if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["creditor_paid"])){
$date_time = date("Y-m-d");
	$cr_name = $_POST["cr_name"];
	@$cr_address = $_POST["cr_address"];
	$amount = $_POST["amount"];
	$paid_by = $_POST["paid_by"];
	 mysqli_query($connection,"insert into asset_paid(cr_name,amount,paid_by,date_time,user_name,user_role,outlet_name,outlet_address)
values('".$cr_name."','".$amount."','".$paid_by."','".$date_time."','".$userName."','".$userRole."','".$outlet_name."','".$outlet_address."')");
 echo "<script type='text/javascript'>window.location.href = 'assets.php?asse_head=$customer_name';</script>";

}

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["creditor_close"])) {
    // Set current date
    $date_time_close = date("Y-m-d");
    // Retrieve values from $_POST
    $creditor_name = $_POST["creditor_name1"];
    $open_amount = $_POST["opening_cash"]; // Corrected variable name
    $credit_sales = $_POST["purchase_cash"];
    $credit_received = $_POST["credit_recieved"] ?? 0;
    $remain_balance = $_POST["closing"]; // Corrected variable name
    $date_time1 = date("Y-m-d");

    // Check if the creditor already has an entry in the database
    $check_sql = "SELECT * FROM asset_closing WHERE asset_name = '$creditor_name'";
    $result = mysqli_query($connection, $check_sql);
    
    if (mysqli_num_rows($result) > 0) {
        // Update existing record
        $sql = "UPDATE asset_closing SET 
                    opening_cash = '$openAmount', 
                    purchase_amount	 = '$credit_sales',  
                    asset_paid1 = '0',
                    remain_balance = '$remain_balance', 
                     date_time = '$date_time1', 
                    user_name = '$userName', 
                    user_role = '$userRole', 
                    outlet_name = '$outlet_name', 
                    outlet_address = '$outlet_address' 
                WHERE asset_name = '$creditor_name'";
    } else {
        // Insert new record
        $sql = "INSERT INTO asset_closing (
                    asset_name, opening_cash, purchase_amount,
                    asset_paid1, remain_balance, date_time, 
                    user_name, user_role, outlet_name, outlet_address
                ) VALUES (
                    '$creditor_name', '$open_amount', '$credit_sales', 
                    '0', '$remain_balance', '$date_time1', 
                    '$userName', '$userRole', '$outlet_name', '$outlet_address'
                )";
    }

    // Execute SQL query
    if (mysqli_query($connection, $sql)) {
       echo "<script type='text/javascript'>window.location.href = 'view_as.php';</script>";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($connection);
    }
}

if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["creditor_open"])){
$date_time32 = date("Y-m-d");
			$creditor = $_POST["creditor_name"];
			$open_amount = $_POST["open_amount"];
			$paid_by1 = 'Cash';
			 mysqli_query($connection,"insert into asset_opening_amount(asset_name,open_amount,paid_by,date_time,login_user,user_role,outlet_name,outlet_address)
			 values('".$creditor."','".$open_amount."','".$paid_by1."','".$date_time32."','".$userName."','".$userRole."','".$outlet_name."','".$outlet_address."');");
			  echo "<script type='text/javascript'>window.location.href = 'assets.php?asse_head=$customer_name';</script>";
}


if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["add_purchase"])){
$date_time321 = date("Y-m-d");
			$creditor11 = $_POST["creditor_name1"];
			$amount11 = $_POST["amount1"];
			$paid_by11 = $_POST["paid_by1"];
			 mysqli_query($connection,"insert into asset_p(asset_name,amount,paid_by,date_time,user_name,user_role,outlet_name,outlet_address)
			 values('".$creditor11."','".$amount11."','".$paid_by11."','".$date_time321."','".$userName."','".$userRole."','".$outlet_name."','".$outlet_address."');");
			  echo "<script type='text/javascript'>window.location.href = 'assets.php?asse_head=$customer_name';</script>";
}

ob_end_flush();
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Assets Ledger Detail</title>

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
   <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@200;300;400;500;600;700&display=swap" rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="../css/sb-admin-2.min.css" rel="stylesheet">
    
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<style>
body {
    font-family: 'Quicksand', sans-serif;
    
}
		    .chart-container {
      position: relative;
      background: rgba(255, 255, 255, 0.9);
      border-radius: 10px;
      padding: 15px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    }

    canvas {
      max-width: 100%;
      height: auto;
    }
.bg-gradient-primary{
    
	background:#0A4657;
	color:#fff;	
	
	}

.btn-primary{
	background:#0A4657;
	color:#fff;
	 border:1px #0A4657 solid;
	
	}  
.btn-primary:hover{
  
  background:#fff;
  border:1px #0A4657 solid;
	color:#0A4657;
	
	}	 
    .chart-container {
      position: relative;
      background: rgba(255, 255, 255, 0.9);
      border-radius: 10px;
      padding: 15px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    }

    canvas {
      max-width: 100%;
      height: auto;
    }
	
	.fa-download:hover{
		color:#953E39;
		}
		
	/* 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;
    }
    .tab-button.active {
        background-color: #0A4657;
		color:#fff;
		font-weight:700;
    }

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

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

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

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                     <?php include('common/log.php');  ?>
                </nav>
<br />
<div class="container">
<div class="row">
<div class="col-sm-6">
<h3 style="color:#212529;font-weight:700;">Assets Detail </h3>
</div>

<div class="col-sm-4">
<a href="view_as.php"><button type="button" class="btn btn-dark"><i class="fa fa-arrow-left"></i></button></a>

            <button type="button" class="btn btn-dark btn-sm" data-toggle="modal" data-target="#addopenPurchaseModal">
              Add Open
            </button>
            <button type="button" class="btn btn-dark btn-sm" data-toggle="modal" data-target="#addopenPurchase1Modal">
              Add Purchase
            </button>
</div>
<div class="col-sm-2 text-center">
    <h6 style="padding:10px; border-radius:7px; text-transform:capitalize; color:#fff;font-size:18px; border:1px solid #0A5064;background:#0A4657; font-weight:600;">
        Assets Name<br><br>
        <?php echo $customer_name; ?></h6>
</div>
</div>
<br />

<div class="container">
<div class="tab-buttons">
    <div class="tab-button active" onclick="openTab(event, 'tab1')">Overview</div>
</div>
<div class="tab-container">
    <div id="tab1" class="tab active">
    <h4>Overview</h4>
    <br />
    <form method="post" action="assets.php?asse_head=<?php echo $customer_name; ?>">
  
    <div class="container ">
        <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 $openAmount; ?>
            <input type="hidden" value="<?php echo $openAmount; ?>" name="opening_cash" />
			</td>
            </tr>
            <tr style="color:;padding:20px;">
            <td style="font-weight:600;">Purchase Amount</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
             <?php echo $pAmount; ?>
            <input type="hidden" value="<?php echo $pAmount; ?>" name="purchase_cash" />
			</td>
            </tr>
            <?php
            $closing = $openAmount + $pAmount;
            ?>
            <tr style="color:;padding:20px;">
            <td style="font-weight:600;">Closing</td>
            <td style="text-align:right; font-size:19px; font-weight:600;">
             <?php echo $closing; ?>
            <input type="hidden" value="<?php echo $closing; ?>" name="closing" />
			</td>
            </tr>
           
           </table>
            <!--<button type="submit" name="creditor_close" class="btn btn-dark">Save</button> -->
            </div>
        </div>
        <br />
    </div>
     </form>
    
</div>
</div>
</div>
</div>
<?php
$cus = mysqli_query($connection,"select *  from credit_note where cr_name = '$customer_name'");
$rc = mysqli_fetch_array($cus);
?>
<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" style="background:#0A4657;">
                            <h5 class="modal-title text-capitalize" id="addPurchaseModalLabel" style=" color:#fff;font-weight:700;">Add Repair</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="assets.php?asse_head=<?php echo $customer_name; ?>" enctype="multipart/form-data">
                            
                                <input type="text" name="cr_name" placeholder="Name" style="background:#0A4657; color:#fff;" value="<?php echo $customer_name; ?>" class="form-control" />
                                <br />
                                <input type="text" name="amount" placeholder="Amount" class="form-control" />
                               <br />
                               <select name="paid_by" class="form-control">
                               <option value="">Select Method </option>
                               <option value="cash" >Cash</option>
                               <option value="bank1">Bank 1</option>
                                    <option value="bank2">Bank 2 </option>
                                    <option value="bank3">Bank 3</option>
                               <option value="other">Other</option>
                               
                               </select>                               
                               <br />
                                <input class="form-control" type="date" name="date_time"  />
                          
                                <br />
                                <button type="submit" name="creditor_paid"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="addopenPurchaseModal" tabindex="-1" role="dialog" 
            aria-labelledby="addPurchaseopenModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" style="background:#0A4657;">
                            <h5 class="modal-title text-capitalize" id="addPurchaseopenModalLabel" style=" color:#fff;font-weight:700;">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="assets.php?asse_head=<?php echo $customer_name; ?>" enctype="multipart/form-data">
                            
                                <input type="hidden" value="<?php echo $customer_name; ?>" name="creditor_name" placeholder="Name" class="form-control" />
                             
                                <input type="text" name="open_amount" placeholder="Amount" class="form-control" />
                               <br />
                               <!-- <input class="form-control" type="date" name="date_time"  />
                                <br />-->
                               
                                <button type="submit" name="creditor_open"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            
             <div class="modal fade" id="addopenPurchase1Modal" tabindex="-1" role="dialog" 
            aria-labelledby="addPurchaseopen1ModalLabel" aria-hidden="true" style="margin-top:80px;">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" style="background:#0A4657;">
                            <h5 class="modal-title text-capitalize" id="addPurchaseopen1ModalLabel" style=" color:#fff;font-weight:700;">Add Purchase</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="assets.php?asse_head=<?php echo $customer_name; ?>" enctype="multipart/form-data">
                            
                                <input type="hidden" value="<?php echo $customer_name; ?>" name="creditor_name1" placeholder="Name" class="form-control" />
                             
                                <input type="text" name="amount1" placeholder="Amount" class="form-control" />
                               <br />
                               <select name="paid_by1" class="form-control">
                               <option value="">Select Method </option>
                               <option value="cash" >Cash</option>
                               <option value="bank1">Bank 1</option>
                                    <option value="bank2">Bank 2 </option>
                                    <option value="bank3">Bank 3</option>
                               <option value="other">Other</option>
                               
                               </select>
                               <br>
                               <!-- <input class="form-control" type="date" name="date_time"  />
                                <br />-->
                               
                                <button type="submit" name="add_purchase"  class="btn btn-dark">Enter</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>



            </div>
            <br><br>
            <!-- End of Main Content -->

            <!-- Footer -->
            <?php include("common/main_ft.php");  ?>
            <!-- End of Footer -->

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="">Logout</a>
                </div>
            </div>
        </div>
    </div>


<script>
 // 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");
    }
  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);
});
 
	</script>
   <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin-2.min.js"></script>

</body>

</html>