<?php
  include_once 'opendb.php';
   $mret="-1";
     
    if (isset($_POST["CompCode"]))
    {
        $coCode=$_POST["CompCode"] ;
        $CoID=0;
        $sql = "SELECT * FROM company WHERE  comp_code like '".$coCode."'";
        $sresult = $conn->query($sql);
        if ($sresult->num_rows > 0 )
        { 
           if($srow = $sresult->fetch_assoc())
            {
                $CoID=$srow["comp_id"];
                mysqli_free_result($sresult);   
            } 
        } 
        else {
                 $mret="invalid co code";
        }
        
        if ( $CoID > 0){
            $cutDate=date('Y-m-d',strtotime('-7 day'));
            $sql = "SELECT count(*) as ocount FROM sale_order WHERE  SYNC_ENTRY_NO = 0 and Entry_date > '$cutDate' and comp_id=$CoID";
            $sresult = $conn->query($sql);
             if($srow = $sresult->fetch_assoc())
            {
                $mret=$srow["ocount"];
                mysqli_free_result($sresult);
            } 
        }
       
    }
    else
    {
        $mret = "company code empty";
    }
    $conn->close();
    echo $mret;
    ?>

