ok

Mini Shell

Direktori : /home2/selectio/public_html/vijay-gases/apis/
Upload File :
Current File : //home2/selectio/public_html/vijay-gases/apis/purchase-update-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']=='update_new_purchase'){
     try{
          /* Purchase Table Inserrted Query Start Here*/
          $purchaseId = $_REQUEST['purchaseId'];
        //   $id = $_POST['id'];
          error_log($purchaseId);
          error_log('hello');
          $count_total_refill_item = count($_POST['sku_no']);
          $count_total_new_item = count($_POST['new_sku_no']);
          
        //   error_log($count_total_refill_item);
        //   error_log($count_total_new_item);
          
         $statement1 = $pdo->prepare("update `tbl_purchase` SET  `purchase_date`=? ,`location_id` =? ,`total_refill_item`=?,`total_new_item`=? ,`total_amount`=? ,`paid_amount`=?, `supplier`=?  WHERE id =? ");
         $result1=$statement1->execute(array($_POST['purchase_date'],$_POST['location'],$count_total_refill_item,$count_total_new_item,$_POST['total_amount'],$_POST['advance_amount'],$_POST['supplier'],$purchaseId));
         $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`, `purchase_price`, `sell_price`) VALUES ('".$_POST['product_id'][$s]."','1','".$newpurchase_id."','".$_POST['purchase_rate'][$s]."','".$_POST['sell_rate'][$s]."')");
                    $result=$statement->execute();
                    
                    // Product Update Query Start Here
                    
                    $statement1 = $pdo->prepare("UPDATE `tbl_product` SET `product_name`='".$_POST['product_name'][$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]."'");
                    $result1=$statement1->execute();
                    
                    
                    // Product Update Query Ends Here
                    
                    
                }
         
         /*   Purchase Item Table Insert Query Is Ends Here */
         
         
         /* Product Table Insert Query Start Here  */
         
         
          for($n=0;$n<count($_POST['new_sku_no']);$n++)
                {
                    $statement2 = $pdo->prepare("INSERT INTO `tbl_product`(`product_name`, `sku`, `purchase_price`, `sell_price`, `default_purchase_location`, `current_stock`,`product_type`) VALUES ('".$_POST['new_product_name'][$n]."','".$_POST['new_sku_no'][$n]."','".$_POST['new_purchse_price'][$n]."','".$_POST['new_sell_price'][$n]."','".$_POST['location']."','1','1')");
                    $result2=$statement2->execute();
                    $new_product_id = $pdo->lastInsertId();
                    
                    $statement3 = $pdo->prepare("INSERT INTO `tbl_purchase_item`(`product_id`, `type`, `purchase_id`, `purchase_price`, `sell_price`) VALUES ('".$new_product_id."','2','".$newpurchase_id."','".$_POST['new_purchse_price'][$n]."','".$_POST['new_sell_price'][$n]."')");
                    $result3=$statement3->execute();
                    
                }
         
         
         /* Product Table Insert Query Ends Here */
         
         
         
        if($result){    
            $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){
        $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`=? WHERE id=?");
         $result = $statement->execute(array($_POST['product_name'],$_POST['sku_no'],$_POST['purchase_price'],$_POST['sell_price'],$_POST['location'],$_POST['stock'],$_POST['status'],$_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);
}



// Product Details Create, Update Ends Here
?>

Zerion Mini Shell 1.0