File "report_s.php"

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

Download   Open   Edit   Advanced Editor   Back

<?php
include("db/cn.php");
ob_start();
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'];
}
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>Whole Sale Retail</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">
        <link href="../css/sb-admin-2.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;
		}
		
 #table-container-wrapper {
    max-height: 460px; /* Adjust the maximum height as needed */
    overflow-y: auto; /* Enable vertical scroll when content overflows */
}
  </style>

<?php
ob_start();

$supplier = isset($_POST['supplier']) ? $_POST['supplier'] : '';
$company = isset($_POST['company']) ? $_POST['company'] : '';
$product = isset($_POST['product']) ? $_POST['product'] : '';
$company_category = isset($_POST['company_category']) ? $_POST['company_category'] : '';
$startDate = isset($_POST['startDate']) ? $_POST['startDate'] : '';
$endDate = isset($_POST['endDate']) ? $_POST['endDate'] : '';
$vehicleNo = isset($_POST['vehicleNo']) ? $_POST['vehicleNo'] : '';

// Base SQL query
$sql = "SELECT 
            SUM(product_quantity) AS total_quantity, 
            SUM(product_total) AS total_amount 
        FROM 
            log_user_sales 
        WHERE 1";

// Add filters based on selected options
if (!empty($supplier)) {
    $sql .= " AND supplier_name = '$supplier'";
}

if (!empty($company_category)) {
    $sql .= " AND company = '$company_category'";
}
if (!empty($product)) {
    $sql .= " AND product_name = '$product'";
}

if (!empty($startDate) && !empty($endDate)) {
    $sql .= " AND date_time BETWEEN '$startDate' AND '$endDate'";
}

if (!empty($vehicleNo)) {
    $sql .= " AND customer_type = '$vehicleNo'";
}

// Execute the query
$sum_result = mysqli_query($connection, $sql);
$row = mysqli_fetch_assoc($sum_result);

$total_quantity = isset($row['total_quantity']) ? $row['total_quantity'] : 0;
$total_amount = isset($row['total_amount']) ? $row['total_amount'] : 0;

if ($total_quantity != 0) {
    $final = $total_amount / $total_quantity;
} else {
    $final = "Undefined";
}

// Execute the main query
$sql = "SELECT * FROM log_user_sales WHERE 1 ORDER BY date_time DESC";
if (!empty($supplier)) {
    $sql .= " AND supplier_name = '$supplier'";
}

if (!empty($company_category)) {
    $sql .= " AND company = '$company_category'";
}
if (!empty($product)) {
    $sql .= " AND product_name = '$product'";
}

if (!empty($startDate) && !empty($endDate)) {
    $sql .= " AND date_time BETWEEN '$startDate' AND '$endDate'";
}

if (!empty($vehicleNo)) {
    $sql .= " AND customer_type = '$vehicleNo'";
}

$rec_purchases = mysqli_query($connection, $sql);
ob_end_flush();
    ?>
<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">

                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <!-- Topbar Search -->
                    
  <?php include('common/log.php');  ?>

                    <!-- Topbar Navbar -->
                    
                </nav>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                
        <div class="container mt-5">
    <form method="post">
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label for="vehicleNo">Enter Vehicle No:</label>
                    <input class="form-control" name="vehicleNo" value="<?php echo $vehicleNo; ?>">
                </div>
            </div>
        </div>
                
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label for="startDate">Start Date:</label>
                    <input type="date" class="form-control" name="startDate" value="<?php echo $startDate; ?>">
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label for="endDate">End Date:</label>
                    <input type="date" class="form-control" name="endDate" value="<?php echo $endDate; ?>">
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <br>
                    <button type="submit" class="btn btn-dark " name="filter">Filter</button>
                    <button type="button" class="btn btn-dark" onclick="downloadPDF()">Download PDF</button>
                </div>
            </div>
        </div>
        
        <div class="col-sm-12" id="table-container-wrapper">
            <table  class="table table-stripped table-hover text-center table-sm">
                <thead>
                    <tr class="bg-dark text-white">
                        <th>Date</th>
                        <th>Vehicle No</th>
                        <th>Customer Name</th>
                        <th>Product Name</th>
                        <th>Total Quantity Litre</th>
                        <th>Total Amount</th>
                        
                        <th>R.P Per Litre</th>
                       
                    </tr>
                </thead>
                    
                <tbody>
                    <?php
                    ob_start();
                    while($row = mysqli_fetch_array($rec_purchases)) { ?>
                        <tr>
                            <td><?php echo $row['date_time']; ?></td>
                            <td class="text-capitalize"><?php echo $row['customer_type']; ?></td>
                            <td class="text-capitalize"><?php echo $row['customer_name']; ?></td>
                            <td class="text-capitalize"><?php echo $row['product_name'];?></td>
                            <td><?php echo $row['product_quantity'];?></td>
                            <td>Rs <?php echo $row['product_total']; ?> /-</td>
                            <td><?php
                                $total_quantity2 = $row["product_quantity"];
                                $total_amount2 = $row["product_total"];
                                if ($total_quantity2 != 0) {
                                    $in_tr = $total_amount2 / $total_quantity2;
                                } else {
                                    $in_tr = "Undefined";
                                }
                                echo $in_tr;
                            ?></td>
                           
                        </tr>
                    <?php } 
                    ob_end_flush();
                    ?>
                </tbody>
            </table>
        </div>
        
       <?php
$diesel_q = mysqli_query($connection,"SELECT SUM(product_quantity) AS total_quantity, SUM(total_amount) AS total_amount FROM log_user_sales WHERE product_name = 'diesel'");
$diesel_fetch = mysqli_fetch_array($diesel_q);
$dieselQty = $diesel_fetch["total_quantity"];
$dieselTotal = $diesel_fetch["total_amount"];
	   
	   $oil_q = mysqli_query($connection,"SELECT SUM(product_quantity) AS total_quantity, SUM(total_amount) AS total_amount FROM log_user_sales WHERE product_name = 'Petrol'");
$oil_fetch = mysqli_fetch_array($oil_q);
$oilQty = $oil_fetch["total_quantity"];
$oilTotal = $oil_fetch["total_amount"];
	   
	   
	   ?> 
        
        
        <div class="row">
       
            <div class="col-sm-5">
             <br>
                <table class="table table-bordered text-center">
                     
                     <tr style=" background:#536C40;color:#fff; font-weight:600;">
                     <td colspan="2" >Diesel</td>
                     </tr>
                    
                        <tr>
                            <th>Total Qty Ltr</th>
                            <td style="font-weight:600;"><?php echo number_format(round($dieselQty ,2 ) ,2 ); ?> ~</td>
                        </tr>
                        <tr>
                            <th>Total Amount:</th>
                            <td style="font-weight:600;">Rs <?php echo number_format(round($dieselTotal ,2) ,2); ?> /-</td>
                        </tr>
                        <tr>
                            <th>Weighted Sale Rate:</th>
                            <td style="font-weight:600;">Rs <?php 
							$dsale = $dieselTotal / $dieselQty;
							echo number_format(round($dsale ,2) ,2); ?></td>
                        </tr>
                    
                </table>
            </div>
            <div class="col-sm-1"></div>
            <div class="col-sm-5">
             <br>
            <table class="table table-bordered text-center">
                     
                     <tr style=" background:#536C40;color:#fff; font-weight:600;">
                     <td colspan="2" >Oil</td>
                     </tr>
                    
                        <tr>
                            <th>Total Qty Ltr</th>
                            <td style="font-weight:600;"><?php echo number_format(round((int)$oilQty ,2 ) ,2 ); ?> ~</td>
                        </tr>
                        <tr>
                            <th>Total Amount:</th>
                            <td style="font-weight:600;">Rs <?php echo number_format(round(@$oilTotal ,2) ,2); ?> </td>
                        </tr>
                        <tr>
                            <th>Weighted Sale Rate:</th>
                            <td style="font-weight:600;">Rs <?php 
							$osale = $oilTotal / $oilQty;
							echo number_format(round($osale ,2) ,2); ?></td>
                        </tr>
                    
                </table>
            
            </div>
            <div class="col-sm-1"></div>
        </div>
    </form>
</div>


    
            
                <!-- /.container-fluid -->

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

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

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

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

    <!-- Scroll to Top Button-->
    <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 src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>

<!-- JavaScript for exporting the table data to Excel -->
<script>
    function downloadPDF() {
        const { jsPDF } = window.jspdf;
        const doc = new jsPDF();
        
        // Add logo to the PDF
        const logoUrl = 'img/print_logo1.png'; // Replace with your logo URL or Base64 string
        const logoWidth = 20; // Adjust the width of the logo as needed
        const logoHeight = 20; // Adjust the height of the logo as needed
        const logoX = 97; // X position of the logo
        const logoY = 10; // Y position of the logo
        
        doc.addImage(logoUrl, 'PNG', logoX, logoY, logoWidth, logoHeight);
        
        // Add address text
        const address = "LAARI ADDA MULTAN";
        const addressX = 82;
        const addressY = logoY + logoHeight + 10; // Position the address below the logo
        
        doc.text(address, addressX, addressY);
        
        // Add report title
        const title = "Sale Report";
        const titleX = 14;
        const titleY = addressY + 10; // Position the title below the address
        
        doc.text(title, titleX, titleY);
        
        // Fetch the table data
        const table = document.querySelector("table");
        const rows = Array.from(table.rows);
        
        const tableData = rows.map(row => {
            return Array.from(row.cells).map(cell => cell.textContent);
        });
        
        // Add table to the PDF
        doc.autoTable({
            head: [tableData[0]], // Table headers
            body: tableData.slice(1), // Table data excluding headers
            startY: titleY + 10, // Position the table below the title
            theme: 'grid'
        });
        
        doc.save("Sale_report.pdf");
</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>