<?php
    $eID=intval($_POST['eID']);
    $scID=SECTION_DEALER;
    $e=$db->get_rowData($general->table(74),'eID',$eID);
    if(!empty($e)){
        $balance=$acc->employeeDueBalance($eID,$scID);
        $eBalance=$acc->headBalance($e['hID']);

        $jArray['eSalary']=(float)$e['eSalary'];;
        $jArray['eBalance']=-$eBalance;
        $jArray['eDue']=$balance;
        $jArray['wtmBlance']=$eBalance+$balance;


    }

    //$q[]='sDsr='.$eID;
    $dRange=date('d-m-Y',strtotime("-30 day")).' to '.date('d-m-Y');
    //$jArray['dRange']=$dRange;
    $general->getFromToFromStringt($dRange,$from,$to);
    $q[]='sDate between '.$from.' and '.$to;
    if(!empty($q)){$sq='where '.implode(' and ',$q);}
    $saleData=[];
    $sales=$db->selectAll($general->table(14),$sq);
    //$jArray['k']=$sales;
    $van=0;
    $tax=0;
    $cost=0;
   
    if(!empty($sales)){
        $oInfo=[

            'van'   => 0,
            'tax'   => 0,
            'cost'  => 0,
            
        ];
        $general->arrayIndexChange($sales,'sID');
        $sIDs=array_keys($sales);
        $otherCosts=$db->selectAllByID($general->table(19),'sID',$sIDs,'',false);
        // $jArray['k']=$otherCosts;
        if(!empty($otherCosts)){
            foreach($otherCosts as $sp){
                if(!isset($saleData[$sp['sID']])){
                    $saleData[$sp['sID']]=$oInfo;
                }
                if($sp['socType']==OTHER_COST_COST){
                    $saleData[$sp['sID']]['cost']+=$sp['scAmount'];
                }
                elseif($sp['socType']==OTHER_COST_VAN_CHARGE){
                    $saleData[$sp['sID']]['van']+=$sp['scAmount'];
                }
                elseif($sp['socType']==OTHER_COST_TAX){
                    $saleData[$sp['sID']]['tax']+=$sp['scAmount'];
                }

            }
        }
        // $jArray['k']=$saleData;

        foreach($saleData as $sID=>$s){
            $ss=$sales[$sID];
            $d=$general->make_date($ss['sDate']);
            $day[$d]=$general->make_date($ss['sDate']);

            if(!isset($empSale[$ss['sDsr']])){       
                $empSale[$ss['sDsr']]=$oInfo;
            }

            $empSale[$ss['sDsr']]['cost']+=$s['cost'];

            $empSale[$ss['sDsr']]['van']+=$s['van'];

            $empSale[$ss['sDsr']]['tax']+=$s['tax'];

        }
        // $jArray['k']=$empSale;
        if(isset($empSale[$eID])){
            $van=(float)$empSale[$eID]['van'];
            $tax=(float)$empSale[$eID]['tax'];
            $cost=(float)$empSale[$eID]['cost'];
            //$jArray['status']=1;
        }

    }
    $jArray['van']=(float)$van;
    $jArray['tax']=(float)$tax;
    $jArray['cost']=(float)$cost;
    $jArray['status']=1;


?>
