ok

Mini Shell

Direktori : /proc/self/root/home2/selectio/www/vijay-gases/apis/
Upload File :
Current File : //proc/self/root/home2/selectio/www/vijay-gases/apis/purchase-add-api.php

<?php 
ob_start();
session_start();
include "../config/config.php";
$session_id = $_SESSION['vijay_gases']['id'];


// Product Details Create, Update Starts Here 

if(isset($_POST['type']) && $_POST['type']=='add_new_purchase'){
     try{
         
          $pdo->beginTransaction();
          /* Purchase Table Inserrted Query Start Here*/
          
          $count_total_refill_item = count($_POST['sku_no']);
         
         $statement1 = $pdo->prepare("INSERT INTO `tbl_purchase`(`purchase_date`, `location_id`, `total_refill_item`, `total_new_item`, `total_amount`, `paid_amount`, `supplier`, `total_purchase_qty`, `pay_description`, `vehicle_no`,`before_total_amount`,`gst`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
         $result1=$statement1->execute(array($_POST['purchase_date'],$_POST['location'],$count_total_refill_item,0,$_POST['total_amount'],$_POST['advance_amount'],$_POST['supplier'],$_POST['pro_qty'],$_POST['payment_condition'],$_POST['vehicle_no'],$_POST['total_sell_rate'],$_POST['gst_percentage']));
         $newpurchase_id = $pdo->lastInsertId();
         /* Purchase Table Inserrted Query Ends Here*/
         
         
         /*  Purchase Item Table Insert Query Is Start Here*/
         
                for($s=0;$s<count($_POST['sku_no']);$s++)
                {
                    
                    
               // $rs="INSERT INTO `tbl_purchase_item`(`product_id`, `type`, `purchase_id`, `purchase_price`, `sell_price`) VALUES ('".$_POST['product_id'][$s]."','1','".$newpurchase_id."','".$_POST['purchase_rate'][$s]."','".$_POST['sell_rate'][$s]."')";
                
               // error_log('Check Query:'.$rs);
                
                    $statement = $pdo->prepare("INSERT INTO `tbl_purchase_item`(`product_id`, `type`, `purchase_id`, `cylinder_no`) VALUES ('".$_POST['product_id'][$s]."','1','".$newpurchase_id."','".$_POST['cylinder_no'][$s]."')");
                    $result=$statement->execute();
                    
                    // Product Update Query Start Here
                    
                   // $up ="UPDATE `tbl_product` SET `product_name`='".$_POST['product_name'][$s]."',`cylinder_no`='".$_POST['cylinder_no'][$s]."', `sku`='".$_POST['sku_no'][$s]."', `purchase_price`='".$_POST['purchase_rate'][$s]."',`sell_price`='".$_POST['sell_rate'][$s]."',`default_purchase_location`='".$_POST['location']."',`current_stock`='".$_POST['quantity'][$s]."',`product_type`='1' WHERE `id`='".$_POST['product_id'][$s]."'";
                   // error_log("Update The Product Table Query =====".$up);
                   
                   
                    $statement1 = $pdo->prepare("UPDATE `tbl_product` SET `cylinder_no`='".$_POST['cylinder_no'][$s]."', `sku`='".$_POST['sku_no'][$s]."',`current_stock`='".$_POST['quantity'][$s]."',`product_type`='1',`customer_id`='0',`current_location`='".$_POST['location']."' WHERE `id`='".$_POST['product_id'][$s]."'");
                    $result1=$statement1->execute();
                    
                    
                    // Product Update Query Ends Here
                    
                    
                }
         
         /*   Purchase Item Table Insert Query Is Ends Here */
         
         
         
         
         /*   Payment Table Amount Insert Query Start Here  */
         
         
         if(isset($_POST['advance_amount']) && $_POST['advance_amount']!=0){
             
             $statement1 = $pdo->prepare("INSERT INTO `tbl_payment`(`pay_type`, `mode`, `customer_id`, `amount`, `pay_id`, `date`, `type`) VALUES (?,?,?,?,?,?,?)");
             $result1=$statement1->execute(array($_POST['pay_type'],$_POST['pay_mode'],$_POST['supplier'],$_POST['advance_amount'],$newpurchase_id,$_POST['purchase_date'],1));
            
         }
         
         
        
         /*   Payment Table Amount Insert Query Ends Here */
        $pdo->commit();  
         
        if($result1){    
            $return_arr['message']='Purchase Cylinder Added Successfully...';
            $return_arr['status']=200;
        } 
        else{
            $return_arr['message']='Something Went Wrong..';
            $return_arr['status']=400;
        }
         
    }catch(PDOException $e){
        
        $pdo->rollBack();
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}

// Product Details Create, Update Ends Here
?>

Zerion Mini Shell 1.0