<?php
  include_once 'opendb.php';
   $mret="Error";     
    if (isset($_POST["AppID"]) &&  isset($_POST["CompCode"]))
    {
        $coCode=$_POST["CompCode"] ;
        $BeginDate=$_POST["BeginDate"] ;        
        $sql = "SELECT * FROM company WHERE  comp_code like '".$coCode."'";
        $sresult = $conn->query($sql);
        if ($sresult->num_rows > 0 )
        { 
               if($srow = $sresult->fetch_assoc())
                 {
                   
                    if($srow['expiry_date']!=''){
                        $expiry_date = date('Y-m-d', strtotime($srow['expiry_date']));
                        $today=date("Y-m-d");
                        if($expiry_date < $today){
                            $mret= 'company status expired '; 
                             $conn->close();
                             die( $mret);
                        }
                   }
                    if ($srow["inactive"]!=0)
                    {
                       $mret="company status Inactive";                       
                    } 
                    else if ( $srow["begin_date"] == $BeginDate  ) {                       
                        $mret = $srow["comp_id"];                                                                
                        $sresult->free_result();                        
                    } else {
                         $mret="diifferent financial period: provided ". $BeginDate . '  in db :' . $srow["begin_date"]  ;  
                    }                          
                }
        }
        else {
                 $mret = "Invalid co code..!  : ".$coCode;
        }
    }
    else
    {
        $mret = "No Data for app id/company code";
    }
    
    $conn->close();
    echo $mret;
    ?>

