<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$zroot = $_SESSION["zdbroot"];
$tdate = date('Y-m-d');
$fseries = $_SESSION["series_" . $dbname];

// $year = $_REQUEST['year'];
// echo ($year);
$ctr = 0;
$rows = array();
if ($_REQUEST['year'] != '') {
    $month = $_REQUEST['month'];
    $year = $_REQUEST['year'];

    $ndays = cal_days_in_month(CAL_GREGORIAN, $month, $year); // 31

    for ($i = 1; $i <= $ndays; $i++) {

        $day = $day + 1;
        $vouchdt = date("Y-m-d", strtotime($year.'-'.$month.'-'.$i));

        $getsale = mysqli_query($conn, "SELECT SUM(netamt) as snetamt from salemain  where vouchdt='$vouchdt' and series = '$fseries' ") or die(mysqli_error($conn));
        $sale = mysqli_fetch_array($getsale);
        $saleamt = $sale['snetamt'];

        if($saleamt == ''){
            $saleamt = 0;
        }

        $rows[] = ['day' => $day,
                   'saleamt' => $saleamt,];
        $ctr++;
}
}

header("Content-type: application\json");
echo json_encode($rows);
