<?php
	include_once('../config.php');   
    
  
          
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }
       
       
       
                     
       
                $expld = explode("-",$_REQUEST['dt']);   
                if( ($_SESSION['userId']=="DP841053") && ($_SESSION['MasterPwd']==1))
                {    
                     
                    if(count($expld) >2)
                    { 
                        $originalDate = $_REQUEST['dt'];
                        $date = date("M-Y", strtotime($originalDate));  
                        $stmt=$conn->prepare("select *   from  UI__DebitCreditForD  where custId =:userid and  Tdate like '%$date%' order by id desc   ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute();  
                        $Result = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    }else 
                    {
                        $originalDate = $_REQUEST['dt'];
                        $xpl = explode("-",$_REQUEST['dt']);  
                        
                        $monthNum  = $xpl[0];
                        $dateObj   = DateTime::createFromFormat('!m', $monthNum);
                        $monthName = $dateObj->format('M'); // March   
                        $date = $monthName."-".$xpl[1];
                        $stmt=$conn->prepare("select *   from  UI__DebitCreditForD  where custId =:userid and  Tdate like '%$date%' order by id desc   ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute();  
                        $Result = $stmt->fetchAll(PDO::FETCH_OBJ);   
                    }
                }else 
                {
                    if(count($expld) >2)
                    {    
                        
                        $date = "'%".$_REQUEST['dt']."%'";  
                        $stmt=$conn->prepare("select *   from  UI__DebitCredit  where custId =:userid and  Tdate like $date  order by id desc   ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $Result = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                    }else
                    {    
                        $originalDate = $_REQUEST['dt'];
                        $xpl = explode("-",$_REQUEST['dt']);  
                        
                        $monthNum  = $xpl[0];
                        $dateObj   = DateTime::createFromFormat('!m', $monthNum);
                        $monthName = $dateObj->format('M'); // March   
                        $date = $monthName."-".$xpl[1];
                        $stmt=$conn->prepare("select *   from  UI__DebitCredit  where custId =:userid and  Tdate like '%$date%' order by id desc   ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute();  
                        $Result = $stmt->fetchAll(PDO::FETCH_OBJ);   
                    } 
                }
                
include_once("../view/dashboard/DebitCreditReport.php");
?>