ok

Mini Shell

Direktori : /home2/selectio/www/vijay-gases/apis/
Upload File :
Current File : /home2/selectio/www/vijay-gases/apis/product-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']=='create_product'){
     try{
    
          //  $pdo->beginTransaction();
    
           for($s=0;$s<count($_POST['cy_no']);$s++){
               
               
                $product_name = $_POST['gas_id'];
                  $sku_no = $_POST['sku_no'];
                  $purchase_price = $_POST['purchase_price'];
                  $sell_price = $_POST['sell_price'];
                  $location_id = $_POST['location_id'];
                  $stock = $_POST['stock'];
                  $current_location = $_POST['location_id'];
                  
                $already_product="";  
               
                $statement1 = $pdo->prepare("SELECT * FROM `tbl_product` WHERE product_name='".$_POST['gas_id']."'and cylinder_no='".$_POST['cy_no'][$s]."'");
                $statement1->execute();
                $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                $totalData = $statement1->rowCount();
                if($totalData!=0){
                    $already_product.=$result1[0]['cylinder_no'].", ";
                }else{
                    $statement = $pdo->prepare("INSERT INTO `tbl_product`(`product_name`, `sku`, `cylinder_no`, `purchase_price`, `sell_price`, `default_purchase_location`, `current_stock`, `product_type`, `current_location`) VALUES ('".$product_name."','".$sku_no."','".$_POST['cy_no'][$s]."','".$purchase_price."','".$sell_price."','".$location_id."','".$stock."','3','".$current_location."')");
                    $result=$statement->execute();
                   
                }
                   
          
               
           }
           
           // $pdo->beginTransaction();
           /*
           
           if($result){*/    
                    $return_arr['message']='Product Details Added Successfully... Old Cylinder '.$already_product;
                    $return_arr['status']=200;
                    echo json_encode($return_arr);
                    return 0;
            /*    } */
                /*else{
                    $return_arr['message']='Something Went Wrong..';
                    $return_arr['status']=400;
                    echo json_encode($return_arr);
                    return 0;
                }*/
        
       /* 
           $statement1 = $pdo->prepare("SELECT * FROM `tbl_product` WHERE product_name='".$_POST['gas_id']."'and cylinder_no='".$_POST['cy_no']."'");
           $statement1->execute();
           $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
           $totalData = $statement1->rowCount();
           if($totalData!=0){
                    $return_arr['message']='This Product Cylinder Number Is Already Exists';
                    $return_arr['status']=400;
                    echo json_encode($return_arr);
                    return 0;
           }else{
               
              $product_name = $_POST['gas_id'];
              $sku_no = $_POST['sku_no'];
              $purchase_price = $_POST['purchase_price'];
              $sell_price = $_POST['sell_price'];
              $location_id = $_POST['location_id'];
              $stock = $_POST['stock'];
              $current_location = $_POST['current_location'];
               
          $statement = $pdo->prepare("INSERT INTO `tbl_product` (`product_name`, `sku`, `cylinder_no`, `purchase_price`, `sell_price`, `default_purchase_location`, `current_stock`, `product_type`, `current_location`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
          $result = $statement->execute(array($_POST['gas_id'], $_POST['sku_no'], $_POST['cy_no'], $_POST['purchase_price'], $_POST['sell_price'], $_POST['location_id'], $_POST['stock'], '3', $_POST['location_id']));
          */
                 /* if($result){    
                    $return_arr['message']='Product Details Added Successfully...';
                    $return_arr['status']=200;
                    echo json_encode($return_arr);
                    return 0;
                } 
                else{
                    $return_arr['message']='Something Went Wrong..';
                    $return_arr['status']=400;
                    echo json_encode($return_arr);
                    return 0;
                }
          */
          
         /*  }*/
        
         
    }catch(PDOException $e){
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}


if(isset($_POST['type']) && $_POST['type']=='update_product'){
     try{
       
         $statement = $pdo->prepare("UPDATE `tbl_product` SET `product_name`=?,`sku`=?,`purchase_price`=?,`sell_price`=?,`default_purchase_location`=?,`current_stock`=?, `status`=?, `cylinder_no`=? WHERE id=?");
         $result = $statement->execute(array($_POST['gas_id'],$_POST['sku_no'],$_POST['purchase_price'],$_POST['sell_price'],$_POST['location'],$_POST['stock'],$_POST['status'],$_POST['cy_no'],$_POST['ids']));
        
        if($result){    
            $return_arr['message']='Product Details Updated Successfully...';
            $return_arr['status']=200;
        } 
        else{
            $return_arr['message']='Something Went Wrong..';
            $return_arr['status']=400;
        }
    }catch(PDOException $e){
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}


if(isset($_POST['type']) && $_POST['type']=='create_multiple_product'){
     try{
    
          //  $pdo->beginTransaction();
    
    $location_id = $_POST['location_id'];
        
        $already_product="";  
        
           for($s=0;$s<count($_POST['cy_no']);$s++){
               
               
                $product_name = $_POST['gas_id'][$s];
                $cylinder_no = $_POST['cy_no'][$s]; 
                $location_id = $_POST['location_id'];
                  
                  
               
                $statement1 = $pdo->prepare("SELECT * FROM `tbl_product` WHERE product_name='".$product_name."'and cylinder_no='".$cylinder_no."'");
                $statement1->execute();
                $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                $totalData = $statement1->rowCount();
                if($totalData!=0){
                    $already_product.=$result1[0]['cylinder_no'].", ";
                }else{
               
                 
               
                   $statement = $pdo->prepare("INSERT INTO `tbl_product`(`product_name`,`cylinder_no`, `default_purchase_location`, `current_location`, `product_type`) VALUES (?,?,?,?,?)");
                   $result=$statement->execute(array($product_name, $cylinder_no, $location_id, $location_id, 3));
                   
                }
                   
          
               
           }  
           
           
           
           if($result){
                    $return_arr['message']='Product Details Added Successfully... Old Cylinder '.$already_product;
                    $return_arr['status']=200;
                    echo json_encode($return_arr);
                    return 0;
           }else{
                    $return_arr['message']='Something Went Wrong';
                    $return_arr['status']=200;
                    echo json_encode($return_arr);
                    return 0;
           }
        
         
    }catch(PDOException $e){
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}

// Product Details Create, Update Ends Here
?>

Zerion Mini Shell 1.0