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
:
/
home
/
aerosoft
/
public_html
/
InventorySystem
/
Viewing: ledger_v1.php
<?php $page_title = 'Ledger Report'; require_once('includes/load.php'); // Checkin What level user has permission to view this page page_require_level(3); ?> <?php // Initialize variables $start_date = ''; $end_date = ''; $ledger_data = array(); $monthly_summary = array(); // Check if form is submitted if(isset($_POST['generate_report'])){ $req_dates = array('start-date','end-date'); validate_fields($req_dates); if(empty($errors)): $start_date = remove_junk($db->escape($_POST['start-date'])); $end_date = remove_junk($db->escape($_POST['end-date'])); // Get ledger data for the selected date range $ledger_data = get_ledger_data($start_date, $end_date); // Get monthly summary $monthly_summary = get_monthly_summary($start_date, $end_date); else: $session->msg("d", $errors); endif; } // Function to get ledger data function get_ledger_data($start_date, $end_date) { global $db; $sql = "SELECT DATE(s.date) as transaction_date, p.name as product_name, s.qty as quantity, s.price as total_amount, p.buy_price as cost_price, (s.price - (p.buy_price * s.qty)) as profit, 'Sale' as transaction_type FROM sales s JOIN products p ON s.product_id = p.id WHERE DATE(s.date) BETWEEN '{$start_date}' AND '{$end_date}' UNION ALL SELECT DATE(p.date) as transaction_date, p.name as product_name, p.quantity as quantity, (p.buy_price * p.quantity) as total_amount, p.buy_price as cost_price, 0 as profit, 'Purchase' as transaction_type FROM products p WHERE DATE(p.date) BETWEEN '{$start_date}' AND '{$end_date}' ORDER BY transaction_date DESC"; return find_by_sql($sql); } // Function to get monthly summary function get_monthly_summary($start_date, $end_date) { global $db; $sql = "SELECT YEAR(s.date) as year, MONTH(s.date) as month, SUM(s.price) as total_sales, SUM(s.price - (p.buy_price * s.qty)) as total_profit, COUNT(s.id) as transaction_count FROM sales s JOIN products p ON s.product_id = p.id WHERE DATE(s.date) BETWEEN '{$start_date}' AND '{$end_date}' GROUP BY YEAR(s.date), MONTH(s.date) ORDER BY year DESC, month DESC"; return find_by_sql($sql); } // Function to calculate opening balance (you need to define your opening balance logic) function get_opening_balance($date) { global $db; // This is a placeholder - you'll need to implement your actual opening balance logic // For example, you might store opening balances in a separate table $sql = "SELECT COALESCE(SUM(price), 0) as opening_balance FROM sales WHERE DATE(date) < '{$date}'"; $result = find_by_sql($sql); return $result ? $result[0]['opening_balance'] : 0; } // Function to calculate closing balance function get_closing_balance($opening_balance, $sales, $purchases) { return $opening_balance + $sales - $purchases; } ?> <?php include_once('layouts/header.php'); ?> <div class="row"> <div class="col-md-12"> <?php echo display_msg($msg); ?> </div> </div> <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>Ledger Report</span> </strong> </div> <div class="panel-body"> <!-- Date Range Filter Form --> <form class="clearfix" method="post" action="ledger.php"> <div class="form-group"> <label class="form-label">Date Range</label> <div class="input-group"> <input type="date" class="form-control" name="start-date" value="<?php echo isset($start_date) ? $start_date : ''; ?>" placeholder="From Date"> <span class="input-group-addon"><i class="glyphicon glyphicon-menu-right"></i></span> <input type="date" class="form-control" name="end-date" value="<?php echo isset($end_date) ? $end_date : ''; ?>" placeholder="To Date"> </div> </div> <div class="form-group"> <button type="submit" name="generate_report" class="btn btn-primary">Generate Report</button> <?php if(isset($start_date) && isset($end_date)): ?> <a href="ledger_report_process.php?start_date=<?php echo $start_date; ?>&end_date=<?php echo $end_date; ?>" class="btn btn-success" target="_blank"> <span class="glyphicon glyphicon-print"></span> Print Report </a> <?php endif; ?> </div> </form> <!-- Summary Cards --> <?php if(isset($start_date) && isset($end_date) && !empty($ledger_data)): ?> <div class="row"> <div class="col-md-3"> <div class="panel panel-box clearfix"> <div class="panel-icon pull-left bg-green"> <i class="glyphicon glyphicon-calendar"></i> </div> <div class="panel-value pull-right"> <h2 class="margin-top"><?php echo count($ledger_data); ?></h2> <p class="text-muted">Total Transactions</p> </div> </div> </div> <div class="col-md-3"> <div class="panel panel-box clearfix"> <div class="panel-icon pull-left bg-blue"> <i class="glyphicon glyphicon-usd"></i> </div> <div class="panel-value pull-right"> <h2 class="margin-top">₹<?php $total_sales = array_sum(array_map(function($item) { return $item['transaction_type'] == 'Sale' ? $item['total_amount'] : 0; }, $ledger_data)); echo number_format($total_sales, 2); ?></h2> <p class="text-muted">Total Sales</p> </div> </div> </div> <div class="col-md-3"> <div class="panel panel-box clearfix"> <div class="panel-icon pull-left bg-orange"> <i class="glyphicon glyphicon-shopping-cart"></i> </div> <div class="panel-value pull-right"> <h2 class="margin-top">₹<?php $total_purchases = array_sum(array_map(function($item) { return $item['transaction_type'] == 'Purchase' ? $item['total_amount'] : 0; }, $ledger_data)); echo number_format($total_purchases, 2); ?></h2> <p class="text-muted">Total Purchases</p> </div> </div> </div> <div class="col-md-3"> <div class="panel panel-box clearfix"> <div class="panel-icon pull-left bg-red"> <i class="glyphicon glyphicon-stats"></i> </div> <div class="panel-value pull-right"> <h2 class="margin-top">₹<?php $total_profit = array_sum(array_column($ledger_data, 'profit')); echo number_format($total_profit, 2); ?></h2> <p class="text-muted">Total Profit</p> </div> </div> </div> </div> <?php endif; ?> <!-- Monthly Summary Table --> <?php if(!empty($monthly_summary)): ?> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-th-list"></span> <span>Monthly Summary</span> </strong> </div> <div class="panel-body"> <table class="table table-bordered table-striped"> <thead> <tr> <th class="text-center">Month</th> <th class="text-center">Year</th> <th class="text-center">Total Sales</th> <th class="text-center">Total Profit</th> <th class="text-center">Transactions</th> </tr> </thead> <tbody> <?php foreach($monthly_summary as $month): ?> <tr> <td class="text-center"><?php echo DateTime::createFromFormat('!m', $month['month'])->format('F'); ?></td> <td class="text-center"><?php echo $month['year']; ?></td> <td class="text-center">₹<?php echo number_format($month['total_sales'], 2); ?></td> <td class="text-center">₹<?php echo number_format($month['total_profit'], 2); ?></td> <td class="text-center"><?php echo $month['transaction_count']; ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> <?php endif; ?> <!-- Detailed Ledger Table --> <?php if(isset($start_date) && isset($end_date)): ?> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-list-alt"></span> <span>Detailed Ledger (<?php echo $start_date; ?> to <?php echo $end_date; ?>)</span> </strong> </div> <div class="panel-body"> <?php if(!empty($ledger_data)): ?> <table class="table table-bordered table-striped"> <thead> <tr> <th class="text-center">Date</th> <th>Product Name</th> <th class="text-center">Transaction Type</th> <th class="text-center">Quantity</th> <th class="text-center">Amount</th> <th class="text-center">Profit</th> </tr> </thead> <tbody> <?php $running_balance = get_opening_balance($start_date); $opening_displayed = false; ?> <!-- Display Opening Balance --> <tr style="background-color: #f9f9f9;"> <td class="text-center"><strong><?php echo $start_date; ?></strong></td> <td colspan="3"><strong>OPENING BALANCE</strong></td> <td class="text-center"><strong>₹<?php echo number_format($running_balance, 2); ?></strong></td> <td class="text-center">-</td> </tr> <?php foreach($ledger_data as $transaction): ?> <tr> <td class="text-center"><?php echo $transaction['transaction_date']; ?></td> <td><?php echo $transaction['product_name']; ?></td> <td class="text-center"> <span class="label label-<?php echo $transaction['transaction_type'] == 'Sale' ? 'success' : 'info'; ?>"> <?php echo $transaction['transaction_type']; ?> </span> </td> <td class="text-center"><?php echo $transaction['quantity']; ?></td> <td class="text-center"> <?php if($transaction['transaction_type'] == 'Sale'): ?> +₹<?php echo number_format($transaction['total_amount'], 2); ?> <?php $running_balance += $transaction['total_amount']; ?> <?php else: ?> -₹<?php echo number_format($transaction['total_amount'], 2); ?> <?php $running_balance -= $transaction['total_amount']; ?> <?php endif; ?> </td> <td class="text-center"> <?php if($transaction['transaction_type'] == 'Sale'): ?> ₹<?php echo number_format($transaction['profit'], 2); ?> <?php else: ?> - <?php endif; ?> </td> </tr> <?php endforeach; ?> <!-- Display Closing Balance --> <tr style="background-color: #f9f9f9;"> <td class="text-center"><strong><?php echo $end_date; ?></strong></td> <td colspan="3"><strong>CLOSING BALANCE</strong></td> <td class="text-center"><strong>₹<?php echo number_format($running_balance, 2); ?></strong></td> <td class="text-center">-</td> </tr> </tbody> </table> <?php else: ?> <div class="alert alert-info text-center"> <h4>No transactions found for the selected date range.</h4> </div> <?php endif; ?> </div> </div> </div> </div> <?php endif; ?> </div> </div> </div> </div> <?php include_once('layouts/footer.php'); ?>
Coded With 💗 by
HanzOFC