Server IP : 162.214.80.37 / Your IP : 216.73.216.83 Web Server : Apache System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : imyrqtmy ( 2189) PHP Version : 8.2.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home2/imyrqtmy/public_html/destinytrafficsolutions/vendor/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php session_start(); include("inc/config.php"); // Get filters $start_date = isset($_GET['start_date']) ? $_GET['start_date'] : ""; $end_date = isset($_GET['end_date']) ? $_GET['end_date'] : ""; // Fetch Invoice Data $invoice_query = "SELECT invoice_number, prices, quantities FROM invoices WHERE status = 'Complete'"; if (!empty($start_date) && !empty($end_date)) { $invoice_query .= " AND invoice_date BETWEEN '$start_date' AND '$end_date'"; } $invoice_run = mysqli_query($conn, $invoice_query); // Fetch Task Data $task_query = "SELECT task_name, SUM(grand_total) as total_cost FROM tasks WHERE 1"; if (!empty($start_date) && !empty($end_date)) { $task_query .= " AND end_datetime BETWEEN '$start_date' AND '$end_date'"; } $task_query .= " GROUP BY task_name"; $task_run = mysqli_query($conn, $task_query); // Calculate Invoice Total $total_invoice_price = 0; $invoice_data = []; while ($row = mysqli_fetch_assoc($invoice_run)) { $prices = json_decode($row['prices'], true); // Try decoding JSON if (!is_array($prices)) { $prices = explode(',', $row['prices']); // If not JSON, assume comma-separated values } $quantities = json_decode($row['quantities'], true); if (!is_array($quantities)) { $quantities = explode(',', $row['quantities']); } $invoice_total = 0; foreach ($prices as $index => $price) { $price = floatval($price); // Convert price to number $quantity = isset($quantities[$index]) ? intval($quantities[$index]) : 1; // Get quantity $invoice_total += $price * $quantity; } $total_invoice_price += $invoice_total; $invoice_data[] = [ 'invoice_number' => $row['invoice_number'], 'total_price' => $invoice_total ]; } // Calculate Task Total $task_total_query = "SELECT SUM(grand_total) as task_total FROM tasks WHERE 1"; if (!empty($start_date) && !empty($end_date)) { $task_total_query .= " AND end_datetime BETWEEN '$start_date' AND '$end_date'"; } $task_total_result = mysqli_query($conn, $task_total_query); $task_total_row = mysqli_fetch_assoc($task_total_result); $total_task_price = $task_total_row['task_total'] ?? 0; // Calculate Profit $profit = $total_invoice_price - $total_task_price; // Calculate Taxes $gst = $total_invoice_price * 0.05; // GST @ 5% $qst = $total_invoice_price * 0.09975; // QST @ 9.975% // Insert Profit Data if (!empty($start_date) && !empty($end_date)) { $insert_profit_query = "INSERT INTO profits (start_date, end_date, total_invoice_price, total_task_price, gst, qst, profit, created_at) VALUES ('$start_date', '$end_date', '$total_invoice_price', '$total_task_price', '$gst', '$qst', '$profit', NOW())"; mysqli_query($conn, $insert_profit_query); } ?> <!DOCTYPE html> <html lang="en"> <?php require "inc/head.php"; ?> <body> <?php require "inc/header.php"; ?> <div class="wrapper"> <?php require "inc/sidebar.php"; ?> <div id="content"> <h3>Profit</h3> <h5 class="text-center">Without Tax <strong>Profit:</strong> <span class="text-primary">$<?php echo number_format($profit, 2); ?></span></h5> <form method="GET"> <div class="row"> <div class="col-md-4"> <label>Start Date:</label> <input type="date" name="start_date" class="form-control" value="<?php echo $start_date; ?>"> </div> <div class="col-md-4"> <label>End Date:</label> <input type="date" name="end_date" class="form-control" value="<?php echo $end_date; ?>"> </div> <div class="col-md-4"> <button type="submit" class="btn btn-primary mt-4">Filter</button> </div> </div> </form> <h4 class="mt-3">Invoices</h4> <table class="table table-bordered"> <thead> <tr> <th>Invoice No</th> <th>Invoice Price</th> </tr> </thead> <tbody> <?php foreach ($invoice_data as $invoice) { ?> <tr> <td><?php echo $invoice['invoice_number']; ?></td> <td>$<?php echo number_format($invoice['total_price'], 2); ?></td> </tr> <?php } ?> <tr> <td class="text-right"><strong>Total Invoice Price:</strong></td> <td><strong>$<?php echo number_format($total_invoice_price, 2); ?></strong></td> </tr> </tbody> </table> <h4 class="mt-3">Tasks</h4> <table class="table table-bordered"> <thead> <tr> <th>Task Name</th> <th>Total Task Cost</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_assoc($task_run)) { ?> <tr> <td><?php echo $row['task_name']; ?></td> <td>$<?php echo number_format($row['total_cost'], 2); ?></td> </tr> <?php } ?> <tr> <td class="text-right"><strong>Total Task Cost:</strong></td> <td><strong>$<?php echo number_format($total_task_price, 2); ?></strong></td> </tr> </tbody> </table> <h4 class="mt-3">Tax Summary</h4> <table class="table table-bordered"> <thead> <tr> <th>Tax Type</th> <th>Tax Rate</th> <th>Tax Amount</th> </tr> </thead> <tbody> <tr> <td>GST</td> <td>5%</td> <td>$<?php echo number_format($gst, 2); ?></td> </tr> <tr> <td>QST</td> <td>9.975%</td> <td>$<?php echo number_format($qst, 2); ?></td> </tr> <tr> <td class="text-right"><strong>Total Tax Amount:</strong></td> <td><strong>$<?php echo number_format($gst + $qst, 2); ?></strong></td> </tr> </tbody> </table> <h4 class="mt-3 text-right"><strong>Profit:</strong> <span class="text-primary">$<?php echo number_format($profit, 2); ?></span></h4> <h4 class="mt-3 text-right"><strong>Total Tax Amount:</strong> <span class="text-primary">$<?php echo number_format($gst + $qst, 2); ?></span></h4> </div> </div> <script src="dist/js/plugins.min.js"></script> <script src="dist/js/common.js"></script> </body> </html>