<?php
if(isset($_POST['state'])){
   require_once('../../assets/config/config.php');
   $obj=new Database();
   if($_POST['state']=='add'){

      $p=$_POST['particular'];
      $desc=$_POST['desc'];
      $amount=$_POST['amount'];
      $date=date("d-M-Y",strtotime($_POST['date']));
      $date1=date("d-M-Y H:i:s");
      $obj->select('setting','*',null,null,null,null);
      $result=$obj->getResult();
      $f_id=$result[0]['f_id']+1;
      $state=$obj->insert('inventory',['particular'=>$p,'description'=>$desc,'amount'=>$amount,'date'=>$date,'create_date'=>$date1,'f_id'=>$f_id]);
      if($state==1)
      {
         $state=$obj->update('setting',['f_id'=>$f_id]);  
         echo $obj->insert('txn_details',['date'=>$date,'f_id'=>$f_id,'debit'=>$amount,'voucher_type'=>$p]);
      }
   }
   if($_POST['state']=='edit'){
      $p=$_POST['particular'];
      $desc=$_POST['desc'];
      $amount=$_POST['amount'];
      $date=date("d-M-Y",strtotime($_POST['date']));
      $id=$_POST['id'];
      $result=$obj->getResult();
      $f_id='f_id="'.$id.'"';
      $state=$obj->update('inventory',['particular'=>$p,'description'=>$desc,'amount'=>$amount,'date'=>$date],$f_id);
      if($state==1)
      { 
         echo $obj->update('txn_details',['date'=>$date,'debit'=>$amount,'voucher_type'=>$p],$f_id);
      }
   }
}
?>