<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$today=date("Y-m-d");
include("db_connect.php");
include("db_functions.php");
$db=new DB_Functions();
$dc = new DB_Connect();         
$link1 = $dc->connect();
$uid = $_REQUEST['uid']; 

$a=array();
$b=array();

$sql="select sum(collect_amt) as amt from collect_data where status='Approved' and collect_date<'".$today."' and collect_by='".$uid."'";
$rs=mysqli_query($link1,$sql) or die(mysqli_error($link1));
$row=mysqli_fetch_assoc($rs);

$opening=$row['amt'];

$sql_t="select sum(collect_amt) as amt from collect_data where status='Approved' and collect_date='".$today."' and collect_by='".$uid."'";
$rs_t=mysqli_query($link1,$sql_t) or die(mysqli_error($link1));
$row_t=mysqli_fetch_assoc($rs_t);

if($row_t['amt']!=''){
$today_collection=$row_t['amt'];
}else{
    $today_collection="0";   
}

$endamt=$opening+$today_collection;

$a['opening']=$opening;
$a['today_collection']=$today_collection;
$a['total_collection']=$endamt;

   
   echo json_encode($a);
?>