403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/NAOPOS/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/NAOPOS/api/report.php
<?php

declare(strict_types=1);

require __DIR__ . '/db.php';
require __DIR__ . '/helpers.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    json_response(['error' => 'Method not allowed'], 405);
}

$businessDate = require_business_date($_GET['date'] ?? null);
$pdo = db();

$summaryStmt = $pdo->prepare(
    "SELECT
        COUNT(DISTINCT s.id) AS total_transactions,
        COALESCE(SUM(s.subtotal), 0) AS total_sales,
        COALESCE(SUM(s.tax), 0) AS total_tax,
        COALESCE(SUM(CASE WHEN s.payment_method = 'cash' THEN s.total ELSE 0 END), 0) AS cash_total,
        COALESCE(SUM(CASE WHEN s.payment_method = 'credit' THEN s.total ELSE 0 END), 0) AS credit_total
     FROM sales s
     WHERE s.business_date = :business_date"
);
$summaryStmt->execute(['business_date' => $businessDate]);
$summary = $summaryStmt->fetch() ?: [];

$breakdownStmt = $pdo->prepare(
    "SELECT
        i.report_category,
        COALESCE(SUM(CASE WHEN s.payment_method = 'cash' THEN i.line_total ELSE 0 END), 0) AS cash_sales,
        COALESCE(SUM(CASE WHEN s.payment_method = 'cash' THEN i.tax_amount ELSE 0 END), 0) AS cash_tax,
        COALESCE(SUM(CASE WHEN s.payment_method = 'credit' THEN i.line_total ELSE 0 END), 0) AS credit_sales,
        COALESCE(SUM(CASE WHEN s.payment_method = 'credit' THEN i.tax_amount ELSE 0 END), 0) AS credit_tax,
        COALESCE(SUM(i.line_total), 0) AS total_sales,
        COALESCE(SUM(i.tax_amount), 0) AS total_tax,
        COALESCE(SUM(i.line_total + i.tax_amount), 0) AS grand_total
     FROM sale_items i
     INNER JOIN sales s ON s.id = i.sale_id
     WHERE s.business_date = :business_date
     GROUP BY i.report_category
     ORDER BY grand_total DESC"
);
$breakdownStmt->execute(['business_date' => $businessDate]);
$breakdown = array_map(static function (array $row): array {
    return [
        'category' => $row['report_category'],
        'cashSales' => (float) $row['cash_sales'],
        'cashTax' => (float) $row['cash_tax'],
        'creditSales' => (float) $row['credit_sales'],
        'creditTax' => (float) $row['credit_tax'],
        'totalSales' => (float) $row['total_sales'],
        'totalTax' => (float) $row['total_tax'],
        'grandTotal' => (float) $row['grand_total'],
    ];
}, $breakdownStmt->fetchAll());

json_response([
    'businessDate' => $businessDate,
    'totalTransactions' => (int) ($summary['total_transactions'] ?? 0),
    'totalSales' => (float) ($summary['total_sales'] ?? 0),
    'totalTax' => (float) ($summary['total_tax'] ?? 0),
    'cashTotal' => (float) ($summary['cash_total'] ?? 0),
    'creditTotal' => (float) ($summary['credit_total'] ?? 0),
    'categoryBreakdown' => $breakdown,
]);

Youez - 2016 - github.com/yon3zu
LinuXploit