ok
Direktori : /proc/self/root/home2/selectio/www/vijay-gases/apis/ |
Current File : //proc/self/root/home2/selectio/www/vijay-gases/apis/cylinder-sale-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_sale'){ try{ $pdo->beginTransaction(); /* Sale Table Inserrted Query Start Here*/ $count_total_collect_item = count($_POST['sku_no']); $count_total_sell_item = count($_POST['return_sku_no']); $cube_rate = $_POST['cube_rate']; $member_id=''; $statement1 = $pdo->prepare("INSERT INTO `tbl_sell`(`sell_date`, `location_id`, `total_refill_item`, `total_new_item`, `total_amount`, `paid_amount`, `inv_no`,`customer_id`,`vechicle_no`,`driver_name`, `cube_rate`) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); $result1=$statement1->execute(array($_POST['sale_date'],$_POST['location'],$count_total_collect_item,$count_total_sell_item,$_POST['total_amount'],$_POST['advance_amount'],$member_id,$_POST['customer'],$_POST['vh_no'],$_POST['d_name'], $cube_rate)); $new_sell_id = $pdo->lastInsertId(); if($result1){ $invoice_id='Vijay-Gas-'.str_pad($new_sell_id, 3, "0", STR_PAD_LEFT); $statement2 = $pdo->prepare("UPDATE tbl_sell SET inv_no = '$invoice_id' WHERE id =$new_sell_id"); $results2=$statement2->execute(); } for($s=0;$s<count($_POST['sku_no']);$s++) { $statement3 = $pdo->prepare("INSERT INTO `tbl_sell_items`(`product_id`, `type`, `sell_id`, `sell_price`) VALUES ('".$_POST['product_id'][$s]."','1','".$new_sell_id."','".$_POST['sell_rate'][$s]."')"); $result3=$statement3->execute(); $statement4 = $pdo->prepare("UPDATE `tbl_product` SET `sku`='".$_POST['sku_no'][$s]."',`current_stock`='".$_POST['quantity'][$s]."',`product_type`='3',`current_location`='".$_POST['location']."',`customer_id`='".$_POST['customer']."' WHERE `id`='".$_POST['product_id'][$s]."'"); $result4=$statement4->execute(); // Product Update Query Ends Here } for($n=0;$n<count($_POST['return_sku_no']);$n++) { $statement5 = $pdo->prepare("INSERT INTO `tbl_sell_items`(`product_id`, `type`, `sell_id`, `sell_price`) VALUES ('".$_POST['return_product_id'][$n]."','2','".$new_sell_id."','".$_POST['return_sell_rate'][$n]."')"); $result5=$statement5->execute(); $statement6 = $pdo->prepare("UPDATE `tbl_product` SET `sku`='".$_POST['return_sku_no'][$n]."',`current_stock`='".$_POST['return_quantity'][$n]."',`product_type`='2',`current_location`='".$_POST['location']."',`customer_id`='".$_POST['customer']."' WHERE `id`='".$_POST['return_product_id'][$n]."'"); $result6=$statement6->execute(); } /* Product Table Insert Query Ends Here */ /* Payment Table Amount Insert Query Start Here */ if(isset($_POST['advance_amount']) && $_POST['advance_amount']!=0){ $statement7 = $pdo->prepare("INSERT INTO `tbl_payment`(`pay_type`, `mode`, `customer_id`, `amount`, `pay_id`, `date`, `type`) VALUES (?,?,?,?,?,?,?)"); $result7=$statement7->execute(array($_POST['pay_type'],$_POST['pay_mode'],$_POST['customer'],$_POST['advance_amount'],$new_sell_id,$_POST['sale_date'],2)); } /* Payment table Amount Insert Query Ends Here */ $pdo->commit(); if($result1){ $return_arr['message']='Sales 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 if(isset($_POST['type']) && $_POST['type']=='add_old_sales'){ try{ $pdo->beginTransaction(); /* Sale Table Inserrted Query Start Here*/ $count_total_collect_item = count($_POST['sku_no']); $count_total_sell_item = count($_POST['return_sku_no']); $cube_rate = $_POST['cube_rate']; $invoice_no = $_POST['invoice_no']; $statement1 = $pdo->prepare("INSERT INTO `tbl_sell`(`sell_date`, `location_id`, `total_refill_item`, `total_new_item`, `total_amount`, `paid_amount`, `inv_no`,`customer_id`,`vechicle_no`,`driver_name`, `cube_rate`, `type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"); $result1=$statement1->execute(array($_POST['sale_date'],$_POST['location'],$count_total_collect_item,$count_total_sell_item,$_POST['total_amount'],$_POST['advance_amount'],$invoice_no,$_POST['customer'],$_POST['vh_no'],$_POST['d_name'], $cube_rate, 2)); $new_sell_id = $pdo->lastInsertId(); /*if($result1){ $invoice_id='Vijay-Gas-'.str_pad($new_sell_id, 3, "0", STR_PAD_LEFT); $statement2 = $pdo->prepare("UPDATE tbl_sell SET inv_no = '$invoice_id' WHERE id =$new_sell_id"); $results2=$statement2->execute(); }*/ // Customer Selling Section Here for($n=0;$n<count($_POST['return_sku_no']);$n++) { $statement5 = $pdo->prepare("INSERT INTO `tbl_sell_items`(`product_id`, `type`, `sell_id`, `sell_price`) VALUES ('".$_POST['return_product_id'][$n]."','2','".$new_sell_id."','".$_POST['return_sell_rate'][$n]."')"); $result5=$statement5->execute(); $statement6 = $pdo->prepare("UPDATE `tbl_product` SET `sku`='".$_POST['return_sku_no'][$n]."',`current_stock`='".$_POST['return_quantity'][$n]."',`product_type`='2',`current_location`='".$_POST['location']."',`customer_id`='".$_POST['customer']."' WHERE `id`='".$_POST['return_product_id'][$n]."'"); $result6=$statement6->execute(); } $pdo->commit(); if($result1){ $return_arr['message']='Sales Old 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); } ?>