ok
Direktori : /proc/self/root/home2/selectio/www/mm-tailor-billing/hrm/apis/ |
Current File : //proc/self/root/home2/selectio/www/mm-tailor-billing/hrm/apis/reports-add.php |
<?php session_start(); include"../config/config.php"; include_once('../config/custom-functions.php'); $fn = new custom_functions; $db = new Database(); if(isset($_POST['type']) && $_POST['type']=='add_new_reports'){ try{ $statements = $pdo->prepare("SELECT * FROM `tbl_products` WHERE status=1"); $results = $statements->execute(); $querys = $statements->fetchAll(PDO::FETCH_ASSOC); $totalDatas = $statements->rowCount(); $pro=""; $ques=""; $update=""; foreach($querys as $res){ $pro.= ", `pro_".$res['id']."`"; $ques.=",?"; $update.= ", `pro_".$res['id']."`=?"; } error_log(count($_POST['user_id'])); for($s=0;$s<count($_POST['user_id']);$s++) { error_log("S Count: ".$s); $values=array(); $ids = $_POST['ids'][$s]; $date = $_POST['date']; $user_id = $_POST['user_id'][$s]; $advance = $_POST['advance'][$s]; $beta = $_POST['beta'][$s]; $grand_total = $_POST['grand_total'][$s]; $product_total = $_POST['product_total'][$s]; $leave = $_POST['leave'][$s]; $pro_count = $_POST['product_count'][$s]; $misc = $_POST['misc'][$s]; $salary = $_POST['salary'][$s]; $ot = $_POST['ot'][$s]; error_log("User Id is: ".$user_id); error_log("Date is: ".$date); error_log("Advance is: ".$advance); error_log("Beta is: ".$beta); error_log("Product Total is: ".$product_total); error_log("Grand Total is: ".$grand_total); error_log("Leave is: ".$leave); $values[]=$misc; $values[]=$salary; $values[]=$ot; $values[]=$user_id; $values[]=$date; $values[]=$advance; $values[]=$beta; $values[]=$product_total; $values[]=$grand_total; $values[]=$leave; for($p=0;$p<$pro_count;$p++){ $product_id = "product_".($p+1); $values[]=$_POST[$product_id][$s]; error_log("Product Id is = $p: ".$_POST[$product_id][$s]); } $statement = $pdo->prepare("SELECT * FROM tbl_reports where user_id='".$user_id."' and date='".$date."'"); $result=$statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); if($totalData>0){ $values[]=$ids; $statement = $pdo->prepare("UPDATE `tbl_reports` SET `misc`=?, `salary`=?, `ot`=?, `user_id`=?, `date`=?, `advance`=?, `beta`=?, `product_total`=?, `grand_total`=?, `leave`=?".$update." WHERE id=?"); $result = $statement->execute($values); $attendance_id = $pdo->lastInsertId(); }else{ $statement = $pdo->prepare("INSERT INTO `tbl_reports`(`misc`, `salary`, `ot`, `user_id`, `date`, `advance`, `beta`, `product_total`, `grand_total`, `leave`".$pro.") VALUES (?,?,?,?,?,?,?,?,?,?".$ques.")"); $result = $statement->execute($values); $attendance_id = $pdo->lastInsertId(); } } if($result){ $return_arr['message']='Attendance Update Successfully...'; $return_arr['status']=200; }else{ $return_arr['message']='Something Went Wrong..'; $return_arr['status']=400; } }catch(Exception $e){ $return_arr['message']="$e"; $return_arr['status']=500; } echo json_encode($return_arr); } ?>