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: print_ledger_report.php
<?php $page_title = 'Ledger Report Print'; require_once('includes/load.php'); page_require_level(3); ?> <?php if(isset($_GET['month']) && isset($_GET['year'])){ $month = remove_junk($db->escape($_GET['month'])); $year = remove_junk($db->escape($_GET['year'])); // Get store_id from URL or current session if(isset($_GET['store_id'])) { $store_id = remove_junk($db->escape($_GET['store_id'])); } else { $store_id = get_current_store_id(); } // Get daily summary for the selected month and store $daily_summary = get_daily_summary($year, $month, $store_id); // Calculate monthly totals $monthly_sales = array_sum(array_column($daily_summary, 'sales')); $monthly_purchases = array_sum(array_column($daily_summary, 'purchases')); $net_change = !empty($daily_summary) ? end($daily_summary)['closing'] - $daily_summary[0]['opening'] : 0; } else { die("Month and Year parameters missing."); } // Updated function to accept store_id parameter function get_daily_summary($year, $month, $store_id) { global $db; $days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year); $summary = array(); $first_day = "{$year}-{$month}-01"; $opening_balance = get_opening_balance($first_day, $store_id); $running_balance = $opening_balance; for ($day = 1; $day <= $days_in_month; $day++) { $current_date = "{$year}-{$month}-" . str_pad($day, 2, '0', STR_PAD_LEFT); // Get daily sales total for specific store $sales_sql = "SELECT COALESCE(SUM(price), 0) as daily_sales FROM sales WHERE DATE(date) = '{$current_date}' AND store_id = '{$store_id}'"; $sales_result = find_by_sql($sales_sql); $daily_sales = $sales_result[0]['daily_sales']; // Get daily purchases total for specific store $purchases_sql = "SELECT COALESCE(SUM(buy_price * quantity), 0) as daily_purchases FROM products WHERE DATE(date) = '{$current_date}' AND store_id = '{$store_id}'"; $purchases_result = find_by_sql($purchases_sql); $daily_purchases = $purchases_result[0]['daily_purchases']; $closing_balance = $running_balance + $daily_sales - $daily_purchases; $difference = $closing_balance - $running_balance; $summary[] = array( 'date' => $current_date, 'opening' => $running_balance, 'sales' => $daily_sales, 'purchases' => $daily_purchases, 'closing' => $closing_balance, 'difference' => $difference, 'night_cash' => $closing_balance ); $running_balance = $closing_balance; } return $summary; } // Updated function to accept store_id parameter function get_opening_balance($date, $store_id) { global $db; $sql = "SELECT COALESCE(SUM(price), 0) as opening_balance FROM sales WHERE DATE(date) < '{$date}' AND store_id = '{$store_id}'"; $result = find_by_sql($sql); return $result[0]['opening_balance']; } ?> <!doctype html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Ledger Report - <?php echo DateTime::createFromFormat('!m', $month)->format('F'); ?> <?php echo $year; ?></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/> <style> @import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap'); @media print { html,body{ font-family: "Montserrat", Helvetica, Arial, sans-serif; font-size:12px; margin: 0; padding: 0; }.page-break { page-break-before:always; width: auto; margin: auto; } .no-print { display: none; } } .page-break{ width: 980px; margin: 0 auto; } .report-head{ margin: 40px 0; text-align: center; border-bottom: 2px solid #333; padding-bottom: 20px; } .summary-box { border: 1px solid #ddd; padding: 15px; margin-bottom: 20px; background-color: #f9f9f9; } .table>thead:first-child>tr:first-child>th{ border-top: 2px solid #000; } table thead tr th { text-align: center; border: 1px solid #333; background-color: #f8f8f8; font-weight: bold; } table tbody tr td{ vertical-align: middle; border: 1px solid #333; font-family: "Montserrat", Helvetica, Arial, sans-serif; } .total-row { background-color: #e9ecef !important; font-weight: bold; } .text-right { text-align: right; } .text-center { text-align: center; } p, strong, b, span, label{ font-family: "Montserrat", Helvetica, Arial, sans-serif; } </style> </head> <body> <div class="page-break"> <div class="report-head"> <h1>DAILY LEDGER REPORT</h1> <h3><?php echo DateTime::createFromFormat('!m', $month)->format('F'); ?> <?php echo $year; ?></h3> <p>Store: <?php $store = find_by_id('stores', $store_id); echo $store ? $store['store_name'] : 'Main Store'; ?></p> <p>Generated on: <?php echo date('d-m-Y H:i:s'); ?></p> </div> <!-- Monthly Summary --> <div class="row"> <div class="col-md-12"> <div class="summary-box"> <h3>Monthly Summary</h3> <div class="row"> <div class="col-md-3"> <p><strong>Total Days:</strong> <?php echo count($daily_summary); ?></p> </div> <div class="col-md-3"> <p><strong>Total Sales:</strong> ₹<?php echo number_format($monthly_sales, 2); ?></p> </div> <div class="col-md-3"> <p><strong>Total Purchases:</strong> ₹<?php echo number_format($monthly_purchases, 2); ?></p> </div> <div class="col-md-3"> <p><strong>Net Change:</strong> ₹<?php echo number_format($net_change, 2); ?></p> </div> </div> <div class="row"> <div class="col-md-6"> <p><strong>Opening Balance (01-<?php echo str_pad($month, 2, '0', STR_PAD_LEFT); ?>-<?php echo $year; ?>):</strong> ₹<?php echo !empty($daily_summary) ? number_format($daily_summary[0]['opening'], 2) : '0.00'; ?> </p> </div> <div class="col-md-6"> <p><strong>Closing Balance (<?php echo count($daily_summary); ?>-<?php echo str_pad($month, 2, '0', STR_PAD_LEFT); ?>-<?php echo $year; ?>):</strong> ₹<?php echo !empty($daily_summary) ? number_format(end($daily_summary)['closing'], 2) : '0.00'; ?> </p> </div> </div> </div> </div> </div> <!-- Daily Ledger Table --> <?php if(!empty($daily_summary)): ?> <table class="table table-bordered"> <thead> <tr> <th class="text-center">Date</th> <th class="text-center">OPENING BALANCE</th> <th class="text-center">DAILY SALES</th> <th class="text-center">DAILY PURCHASES</th> <th class="text-center">CLOSING BALANCE</th> <th class="text-center">DIFFERENCE</th> <th class="text-center">NIGHT CASH</th> </tr> </thead> <tbody> <?php foreach($daily_summary as $day): ?> <tr> <td class="text-center"><?php echo date('d-m-Y', strtotime($day['date'])); ?></td> <td class="text-right">₹<?php echo number_format($day['opening'], 2); ?></td> <td class="text-right">₹<?php echo number_format($day['sales'], 2); ?></td> <td class="text-right">₹<?php echo number_format($day['purchases'], 2); ?></td> <td class="text-right">₹<?php echo number_format($day['closing'], 2); ?></td> <td class="text-right">₹<?php echo number_format($day['difference'], 2); ?></td> <td class="text-right">₹<?php echo number_format($day['night_cash'], 2); ?></td> </tr> <?php endforeach; ?> <!-- Monthly Totals Row --> <tr class="total-row"> <td class="text-center"><strong>TOTALS</strong></td> <td class="text-right">-</td> <td class="text-right"><strong>₹<?php echo number_format($monthly_sales, 2); ?></strong></td> <td class="text-right"><strong>₹<?php echo number_format($monthly_purchases, 2); ?></strong></td> <td class="text-right">-</td> <td class="text-right"><strong>₹<?php echo number_format($net_change, 2); ?></strong></td> <td class="text-right">-</td> </tr> </tbody> </table> <!-- Additional Summary --> <div class="row" style="margin-top: 30px;"> <div class="col-md-12"> <div class="summary-box"> <h4>Key Metrics</h4> <div class="row"> <div class="col-md-4"> <p><strong>Average Daily Sales:</strong> ₹<?php echo number_format($monthly_sales / count($daily_summary), 2); ?></p> </div> <div class="col-md-4"> <p><strong>Highest Daily Sales:</strong> ₹<?php echo number_format(max(array_column($daily_summary, 'sales')), 2); ?></p> </div> <div class="col-md-4"> <p><strong>Lowest Daily Sales:</strong> ₹<?php echo number_format(min(array_column($daily_summary, 'sales')), 2); ?></p> </div> </div> <div class="row"> <div class="col-md-6"> <p><strong>Days with Sales:</strong> <?php $days_with_sales = count(array_filter($daily_summary, function($day) { return $day['sales'] > 0; })); echo $days_with_sales . ' out of ' . count($daily_summary); ?> </p> </div> <div class="col-md-6"> <p><strong>Monthly Growth Rate:</strong> <?php if (!empty($daily_summary) && $daily_summary[0]['opening'] > 0) { $growth_rate = ($net_change / $daily_summary[0]['opening']) * 100; echo number_format($growth_rate, 2) . '%'; } else { echo '0%'; } ?> </p> </div> </div> </div> </div> </div> <?php else: ?> <div class="alert alert-info text-center"> <h3>No data available for <?php echo DateTime::createFromFormat('!m', $month)->format('F'); ?> <?php echo $year; ?></h3> </div> <?php endif; ?> <!-- Footer --> <div style="margin-top: 50px; border-top: 1px solid #333; padding-top: 20px;"> <div class="row"> <div class="col-md-6"> <p><strong>Prepared By:</strong> ___________________</p> </div> <div class="col-md-6 text-right"> <p><strong>Authorized Signature:</strong> ___________________</p> </div> </div> </div> </div> <!-- Print Button (visible only when not printing) --> <div class="no-print text-center" style="margin-top: 20px;"> <button onclick="window.print()" class="btn btn-success btn-lg"> <span class="glyphicon glyphicon-print"></span> Print Report </button> <button onclick="window.close()" class="btn btn-default btn-lg"> Close Window </button> </div> </body> </html> <?php if(isset($db)) { $db->db_disconnect(); } ?>
Coded With 💗 by
HanzOFC