V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home9
/
aerosoft
/
www
/
InventorySystem
/
Viewing: daily_sales.php
<?php // Enable error reporting error_reporting(E_ALL); ini_set('display_errors', 1); $page_title = 'Daily Sales'; require_once('includes/load.php'); // Check if database connection is working if (!isset($db) || !$db) { die("Database connection failed. Please check your configuration."); } page_require_level(3); // Get current store and filter parameters $current_store_id = get_current_store_id(); $current_store_name = get_current_store_name(); $year = isset($_GET['year']) ? $_GET['year'] : date('Y'); $month = isset($_GET['month']) ? $_GET['month'] : date('m'); $sale_type = isset($_GET['sale_type']) ? $_GET['sale_type'] : ''; // Build where conditions $where_conditions = ["s.store_id = '{$current_store_id}'"]; $where_conditions[] = "YEAR(s.date) = '{$year}'"; $where_conditions[] = "MONTH(s.date) = '{$month}'"; if(!empty($sale_type)) { if($sale_type == 'regular') { $where_conditions[] = "s.is_transferred_out = 0"; } elseif($sale_type == 'transferred') { $where_conditions[] = "s.is_transferred_out = 1"; } } $where_clause = implode(' AND ', $where_conditions); // Get daily sales with direct query - FIXED: Using fetch_assoc loop global $db; $sql = "SELECT s.date, p.name, SUM(s.qty) as total_qty, SUM(s.total) as total_sales, SUM(s.profit) as total_profit, SUM(CASE WHEN s.payment_type = 'cash' THEN s.total ELSE 0 END) as cash_sales, SUM(CASE WHEN s.payment_type = 'online' THEN s.total ELSE 0 END) as online_sales, SUM(CASE WHEN s.is_transferred_out = 1 THEN s.total ELSE 0 END) as transferred_sales, SUM(CASE WHEN s.is_transferred_out = 1 THEN s.qty ELSE 0 END) as transferred_qty, COUNT(DISTINCT CASE WHEN s.is_transferred_out = 1 THEN s.id END) as transferred_products_count FROM sales s LEFT JOIN products p ON s.product_id = p.id WHERE {$where_clause} GROUP BY s.date, p.name ORDER BY s.date DESC, total_sales DESC"; $sales_result = $db->query($sql); $sales = []; if($sales_result && $sales_result->num_rows > 0) { while($row = $sales_result->fetch_assoc()) { $sales[] = $row; } } // Get summary for the month $summary_sql = "SELECT COALESCE(SUM(s.total), 0) as total_sales, COALESCE(SUM(s.profit), 0) as total_profit, COALESCE(SUM(CASE WHEN s.payment_type = 'cash' THEN s.total ELSE 0 END), 0) as cash_sales, COALESCE(SUM(CASE WHEN s.payment_type = 'online' THEN s.total ELSE 0 END), 0) as online_sales, COALESCE(SUM(CASE WHEN s.is_transferred_out = 0 THEN s.total ELSE 0 END), 0) as regular_sales, COALESCE(SUM(CASE WHEN s.is_transferred_out = 1 THEN s.total ELSE 0 END), 0) as transferred_sales, COALESCE(SUM(CASE WHEN s.is_transferred_out = 1 THEN s.qty ELSE 0 END), 0) as transferred_qty, COALESCE(COUNT(DISTINCT CASE WHEN s.is_transferred_out = 1 THEN s.id END), 0) as transferred_products_count FROM sales s WHERE {$where_clause}"; $summary_result = $db->query($summary_sql); $summary = [ 'total_sales' => 0, 'total_profit' => 0, 'cash_sales' => 0, 'online_sales' => 0, 'regular_sales' => 0, 'transferred_sales' => 0, 'transferred_qty' => 0, 'transferred_products_count' => 0 ]; if($summary_result && $summary_result->num_rows > 0) { $summary = $summary_result->fetch_assoc(); } // Get total value of transferred products in inventory $transferred_products_sql = "SELECT COALESCE(SUM(sale_price * quantity), 0) as total_transferred_products_value FROM products WHERE store_id = '{$current_store_id}' AND is_transferred = 1"; $transferred_products_result = $db->query($transferred_products_sql); $transferred_products_value = 0; if($transferred_products_result && $transferred_products_result->num_rows > 0) { $transferred_products_value = $transferred_products_result->fetch_assoc()['total_transferred_products_value']; } // Calculate opening balance (you need to implement this based on your business logic) $opening_balance = 0; // Placeholder - implement based on your accounting system $closing_balance = $opening_balance + ($summary['total_sales'] ?? 0); ?> <?php include_once('layouts/header.php'); ?> <div class="row"> <div class="col-md-12"> <?php echo display_msg($msg); ?> </div> </div> <!-- Filters --> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-filter"></span> <span>Daily Sales Filters - <?php echo $current_store_name; ?></span> </strong> </div> <div class="panel-body"> <form method="get" action="daily_sales.php" class="form-inline"> <div class="form-group"> <label for="year">Year:</label> <select class="form-control" id="year" name="year"> <?php for($y = date('Y'); $y >= 2020; $y--): ?> <option value="<?php echo $y; ?>" <?php echo ($y == $year) ? 'selected' : ''; ?>> <?php echo $y; ?> </option> <?php endfor; ?> </select> </div> <div class="form-group" style="margin-left: 10px;"> <label for="month">Month:</label> <select class="form-control" id="month" name="month"> <?php for($m = 1; $m <= 12; $m++): ?> <option value="<?php echo sprintf('%02d', $m); ?>" <?php echo ($m == intval($month)) ? 'selected' : ''; ?>> <?php echo date('F', mktime(0, 0, 0, $m, 1)); ?> </option> <?php endfor; ?> </select> </div> <div class="form-group" style="margin-left: 10px;"> <label for="sale_type">Sale Type:</label> <select class="form-control" id="sale_type" name="sale_type"> <option value="">All Sales</option> <option value="regular" <?php echo ($sale_type == 'regular') ? 'selected' : ''; ?>>Regular Sales</option> <option value="transferred" <?php echo ($sale_type == 'transferred') ? 'selected' : ''; ?>>Transferred Out</option> </select> </div> <button type="submit" class="btn btn-primary" style="margin-left: 10px;"> <span class="glyphicon glyphicon-search"></span> Filter </button> <a href="daily_sales.php" class="btn btn-default" style="margin-left: 10px;"> <span class="glyphicon glyphicon-refresh"></span> Reset </a> </form> </div> </div> </div> </div> <!-- Summary Cards --> <div class="row"> <div class="col-md-2"> <div class="panel panel-primary"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge">₹<?php echo number_format($summary['total_sales'], 2); ?></div> <div>Total Sales</div> </div> </div> </div> </div> </div> <div class="col-md-2"> <div class="panel panel-success"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge">₹<?php echo number_format($summary['regular_sales'], 2); ?></div> <div>Regular Sales</div> </div> </div> </div> </div> </div> <div class="col-md-2"> <div class="panel panel-info"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge">₹<?php echo number_format($summary['transferred_sales'], 2); ?></div> <div>Transferred Out Sales</div> </div> </div> </div> </div> </div> <div class="col-md-2"> <div class="panel panel-warning"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge">₹<?php echo number_format($transferred_products_value, 2); ?></div> <div>Transferred Products Value</div> </div> </div> </div> </div> </div> <div class="col-md-2"> <div class="panel panel-green"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge">₹<?php echo number_format($summary['cash_sales'], 2); ?></div> <div>Cash Payments</div> </div> </div> </div> </div> </div> <div class="col-md-2"> <div class="panel panel-default"> <div class="panel-heading"> <div class="row"> <div class="col-xs-12 text-center"> <div class="huge"><?php echo $summary['transferred_products_count']; ?></div> <div>Transferred Items</div> </div> </div> </div> </div> </div> </div> <!-- Detailed Summary --> <div class="row"> <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-stats"></span> <span>Financial Summary</span> </strong> </div> <div class="panel-body"> <div class="list-group"> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($opening_balance, 2); ?></span> Opening Balance </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($summary['total_sales'], 2); ?></span> Total Revenue </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($closing_balance, 2); ?></span> Closing Balance </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($summary['transferred_sales'], 2); ?></span> Transferred Out Sales Value </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($transferred_products_value, 2); ?></span> Transferred Products Inventory Value </div> <div class="list-group-item"> <span class="badge"><?php echo $summary['transferred_qty']; ?> items</span> Total Transferred Quantity </div> </div> </div> </div> </div> </div> <!-- Daily Sales Table --> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading clearfix"> <strong> <span class="glyphicon glyphicon-th"></span> <span>Daily Sales - <?php echo $current_store_name; ?></span> <small class="text-muted"> (<?php echo date('F Y', strtotime($year . '-' . $month . '-01')); ?>) <?php if(!empty($sale_type)) echo ' - ' . ucfirst($sale_type) . ' Sales'; ?> </small> </strong> </div> <div class="panel-body"> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th class="text-center" style="width: 50px;">#</th> <th>Date</th> <th>Product Name</th> <th class="text-center" style="width: 10%;">Quantity</th> <th class="text-center" style="width: 12%;">Total Sales</th> <th class="text-center" style="width: 12%;">Profit</th> <th class="text-center" style="width: 12%;">Cash</th> <th class="text-center" style="width: 12%;">Online</th> <th class="text-center" style="width: 12%;">Transferred</th> </tr> </thead> <tbody> <?php if(!empty($sales)): ?> <?php $counter = 1; ?> <?php foreach ($sales as $sale): ?> <tr> <td class="text-center"><?php echo $counter++; ?></td> <td><?php echo date('M j, Y', strtotime($sale['date'])); ?></td> <td><?php echo remove_junk($sale['name']); ?></td> <td class="text-center"><?php echo (int)$sale['total_qty']; ?></td> <td class="text-center">₹<?php echo number_format($sale['total_sales'], 2); ?></td> <td class="text-center">₹<?php echo number_format($sale['total_profit'], 2); ?></td> <td class="text-center">₹<?php echo number_format($sale['cash_sales'], 2); ?></td> <td class="text-center">₹<?php echo number_format($sale['online_sales'], 2); ?></td> <td class="text-center">₹<?php echo number_format($sale['transferred_sales'], 2); ?></td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="9" class="text-center">No sales found for the selected criteria.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> </div> <?php include_once('layouts/footer.php'); ?>
Coded With 💗 by
HanzOFC