<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
include '../../../config/index.php';
$data = array();

 
$PaidInvoices=0;
$TotalExpenditure=0;
$OverdueInvoices=0;
$OutstandingInvoices=0;
$sql_1 = "SELECT * FROM centerInvoices WHERE center_id='" . $_GET["center_id"] . "' AND Status='Paid'";
$result_1 = mysqli_query($conn, $sql_1);
if (mysqli_num_rows($result_1) > 0) {
    while ($row_1 = mysqli_fetch_assoc($result_1)) {
        $PaidInvoices=$PaidInvoices+$row_1["Price"];
    }
}
 
$invoice_due_date = date(format: 'Y-m-d H:i:s');
$sql_1 = "SELECT * FROM centerInvoices WHERE center_id='" . $_GET["center_id"] . "' AND Status='Unpaid' AND invoice_due_date<'".$invoice_due_date."'";
$result_1 = mysqli_query($conn, $sql_1);
if (mysqli_num_rows($result_1) > 0) {
    while ($row_1 = mysqli_fetch_assoc($result_1)) {
        $invoice_due_date = date(format: 'Y-m-d H:i:s');

      
        // $hourdiff = round((strtotime($invoice_due_date) - strtotime($row_1["invoice_due_date"]))/3600, 1);
        // $OverdueInvoices=$OverdueInvoices+$hourdiff;
         $OverdueInvoices=$OverdueInvoices+$row_1["Price"];
    }
}
 
$sql_1 = "SELECT * FROM centerInvoices WHERE center_id='" . $_GET["center_id"] . "' AND Status='Unpaid'";
$result_1 = mysqli_query($conn, $sql_1);
if (mysqli_num_rows($result_1) > 0) {
    while ($row_1 = mysqli_fetch_assoc($result_1)) {
        $OutstandingInvoices=$OutstandingInvoices+$row_1["Price"];
    }
}
 
 

$curl_post_data = array(
    'PaidInvoices' => $PaidInvoices,
    'OverdueInvoices' => $OverdueInvoices,
    'OutstandingInvoices' => $OutstandingInvoices
);

echo json_encode($curl_post_data);
?>