"; // print_r($elevators_detail_arr); // echo ""; // exit(); $files = !empty($_FILES['files']) ? $_FILES['files'] : null; $files_id = null; $fail_arr = []; if (empty($contractno)) $fail_arr[] = '合約號為必填'; if (empty($customer)) $fail_arr[] = '客戶名稱為必填'; if (empty($manager)) $fail_arr[] = '負責人為必填'; // if (empty($vat)) $fail_arr[] = '統編/身分證為必填'; if (empty($case_name)) $fail_arr[] = '案名為必填'; if (empty($linkman)) $fail_arr[] = '聯絡人為必填'; if (empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; if (empty($address)) $fail_arr[] = '地址為必填'; if (empty($salesman)) $fail_arr[] = '營業員為必填'; // if (empty($elevators_detail_arr['qc'])) $fail_arr[] = '請選擇QC或官檢'; if (count($fail_arr) > 0) { header("HTTP/1.1 422 Unprocessable Entity"); echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); exit(); } //create facility table $createFacilityNo = new CreateFacilityNo(); $dailyNecessities = [ 'MAE100' => 'X', //小機房客梯 'MAM200' => 'W', //無機房客梯 'MAH100' => 'H', //小電梯 'MAQ100' => 'Z', //強趨梯 'MAF100' => 'F', //貨梯 'MAP100' => 'B', //平台梯 ]; $arr = []; // 建立作番號 foreach ($elevators_detail_arr as $elevator) { // $spec = explode('-', $elevator['item_spec']); $arr[] = $dailyNecessities[$elevator['spec']]; } $facilityno = $createFacilityNo->makeMFacilityNo('M', $arr, intval($elevators_nums)); echo json_encode($facilityno); // $bonus_result = BounsCount($_POST, $conn, $facilityno); // if (!empty($bonus_result) && $bonus_result['status'] == "2") { // $fail_arr[] = '獎金計算錯誤,請再檢查或連繫資訊人員'; // // header("HTTP/1.1 422 Unprocessable Entity"); // echo json_encode($fail_arr, JSON_UNESCAPED_UNICODE); // exit(); // } T8Insert($_POST, $facilityno, $connT8); // exit(); try { $conn->beginTransaction(); //create account table $accounttype = "A"; $accountid = $vat; $pwd = "123"; $name = $customer; $tel = $lm_tel ?? ''; $sql = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address , :creater, :created_at)"; $stmt = $conn->prepare($sql); $stmt->bindParam(':accounttype', $accounttype); $stmt->bindParam(':accountid', $contractno); $stmt->bindParam(':pwd', $pwd); $stmt->bindParam(':name', $customer); $stmt->bindParam(':tel', $tel); $stmt->bindParam(':address', $address); $stmt->bindParam(':creater', $created_by); $stmt->bindParam(':created_at', $created_at); $stmt->execute(); // exit(); //create table Wipwholestatus (作番大日程) foreach ($elevators_detail_arr as $key => $value) { $facilityno = $facilityno[$key]; // 作番 $weight = $value['item_weight']; // 載重 $person = $value['person']; // 人乘 $floor = $value['floor']; // 樓層 $open = $value['item_op']; // 開門方式 $speed = $value['speed']; //速度 $qc = $value['qc']; $facility_kind = $value['spec']; //型號 $contract_arrival_date = $value['contract_arrival_date']; //到工地日期 $site_manager = $value['manage']; $warehouseid = $value['warehouseid']; $sql = "INSERT INTO Wipwholestatus (contract_type,contractno,salesid,custom,accountid,site_manager,warehouseid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,area_no,address,contract_arrival_date,real_contract_arrival_date,qc_official_type,creater,create_at,desin_spec_verify) VALUES ('A',:contractno,:salesid,:custom,:accountid,:site_manager,:warehouseid,:facilityno,:weight,:numberofpassenger,:numberoffloor,:opentype,:speed,:facility_kind,:area_no,:address,:contract_arrival_date,:real_contract_arrival_date,:qc_official_type,:creater,:create_at,1)"; // $sql = "INSERT INTO Wipwholestatus // (contract_type,contractno,salesid,custom,accountid,facilityno,weight,numberofpassenger,numberoffloor,opentype,speed,facility_kind,address,contract_arrival_date,qc_official_type,creater,create_at) VALUES // ('A','$contractno','$salesman','$customer','$customer','$facilityno','$weight','$person','$floor','$open','$speed','$facility_kind','$address','$contract_arrival_date','$qc','$created_by','$created_at')"; $stmt = $conn->prepare($sql); $stmt->bindParam(':contractno', $contractno); $stmt->bindParam(':salesid', $salesman); $stmt->bindParam(':custom', $customer); $stmt->bindParam(':accountid', $customer); $stmt->bindParam(':site_manager', $site_manager); $stmt->bindParam(':warehouseid', $warehouseid); $stmt->bindParam(':facilityno', $facilityno); $stmt->bindParam(':weight', $weight); $stmt->bindParam(':numberofpassenger', $person); $stmt->bindParam(':numberoffloor', $floor); $stmt->bindParam(':opentype', $open); $stmt->bindParam(':speed', $speed); $stmt->bindParam(':facility_kind', $facility_kind); $stmt->bindParam(':area_no', $area_no); $stmt->bindParam(':address', $address); $stmt->bindParam(':contract_arrival_date', $contract_arrival_date); $stmt->bindParam(':real_contract_arrival_date', $contract_arrival_date); $stmt->bindParam(':qc_official_type', $qc); $stmt->bindParam(':creater', $created_by); $stmt->bindParam(':create_at', $created_at); $stmt->execute(); $lastId = $conn->lastInsertId(); // echo "
"; // print_r($lastId); // echo ""; // exit; if (!empty($lastId)) { echo '123'; // 寫入待簽程狀態 A (營業) do_wws_assign1($salesman, $lastId, 'A', $conn); // // 寫入待簽程狀態 G (工務) do_wws_assign1($warehouseid, $lastId, 'G', $conn); } // create table worksite (戰情室) $latitude = $value['latitude']; $longitude = $value['longitude']; $sql = "INSERT INTO worksite (latitude,longitude,facilitynum,facilityno,address,buildcompany,process,status,marchintotime,creater,create_at)VALUES (:latitude,:longitude,'1',:facilityno,:address,:bulidcompany,'進行中','未工勘',:marchintotime,:creater,:create_at)"; $stmt = $conn->prepare($sql); $stmt->bindParam(':latitude', $latitude); $stmt->bindParam(':longitude', $longitude); $stmt->bindParam(':facilityno', $facilityno); $stmt->bindParam(':address', $address); $stmt->bindParam(':bulidcompany', $customer); $stmt->bindParam(':marchintotime', $contract_arrival_date); $stmt->bindParam(':creater', $created_by); $stmt->bindParam(':create_at', $created_at); $stmt->execute(); // create table schedule // $contract_begin_date = ''; // $contract_end_date = ''; // 一年 // $comboNo = new CreateComboNo('em', $contract_begin_date, $contract_end_date); // $comboArr = json_decode($comboNo->getComboNo(), true); // foreach ($comboArr as $combo) { // $sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)'; // $stmt = $conn->prepare($sql_str); // $stmt->bindParam(':contractno', $contractno); // $stmt->bindParam(':facilityno', $facility_no); // $stmt->bindParam(':combono', $combo[0]); // $stmt->bindParam(':repairerid', $repairerid); // $stmt->bindParam(':repairername', $repairername); // $stmt->bindParam(':duedate', $combo[1]); // $stmt->bindParam(':creater', $creater); // $stmt->bindParam(':create_at', $create_at); // $result = $stmt->execute(); // } // } $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(":accountid", $salesman); $stmt->execute(); $saleman = $stmt->fetch(PDO::FETCH_ASSOC); $salesman_name = $saleman['name']; if (!empty($files)) { $englisharr = range('a', 'z'); $files = $_FILES['files']; $newfiles = []; foreach ($files as $file) { $i = 0; //新陣列的索引編號 foreach ($file as $key => $val) { $newfiles[$i]['name'] = $files['name'][$key]; $newfiles[$i]['type'] = $files['type'][$key]; $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; $newfiles[$i]['error'] = $files['error'][$key]; $newfiles[$i]['size'] = $files['size'][$key]; $i++; } //foreach 第2層 end } $max_size = 4096 * 4096; //設定允許上傳檔案容量的最大值(1M) $allow_ext = array('jpeg', 'jpg', 'png', 'JPG', 'JPEG', 'PNG', 'GIF'); //設定允許上傳檔案的類型 $path = '../images/contracts/'; if (!file_exists($path)) { mkdir($path); } $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 $datetime = (string)date('YmdHis'); $files_id = 'm' . $datetime; // 保養=>b + 日期時間 foreach ($newfiles as $key => $file) { $randNum = rand(1000, 9999); $randEnglish = $englisharr[rand(0, 25)]; $file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum . $file['name']; $msg = upload_chk($file, $path, $max_size, $allow_ext, $file_name); if ($msg == 1) { $msg = '檔案傳送成功!'; $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(':files_id', $files_id); $stmt->bindParam(':file_name', $file_name); $stmt->bindParam(':file_mime', $file['type']); $stmt->bindParam(':file_size', $file['size']); $stmt->bindParam(':created_at', $created_at); $stmt->bindParam(':created_by', $created_by); $stmt->execute(); } else { throw new PDOException('檔案上傳失敗:' . $msg); } $msg_result .= '第' . ($key + 1) . '個上傳檔案的結果:' . $msg . '
"; print_r(json_encode($API_body, JSON_UNESCAPED_UNICODE)); echo ""; // $api_url = "https://erp.masada.com.tw:780/twWebAPI/V1/SALSALESORDER/PostERPData"; // $api_url = "http://127.0.0.1:880/twWebAPI/V1/SALSALESORDER/PostERPData"; $api_url = 'http://10.10.145.2:880/twWebAPI/V1/SALSALESORDER/PostERPData'; $result = T8salIncomeApply($API_body, $api_url); echo "
"; print_r($result); echo ""; if (!empty($result) && ($result['Status'] == 'Fails' || $result['Status'] == 'Error')) { echo $result['ErrorMsg']; } } else { echo '資料已新增過,請洽資訊人員'; // exit(); } $connT8->commit(); // } catch (PDOException $e) { // $connT8->rollback(); // header("HTTP/1.1 500 Internal Server Error"); // die('Error!:' . $e->getMessage()); // } } function BounsCount($data, $conn, $facilityno) { try { require_once("../../bonus/elevator_new/elevator_new_deal_bonus.php"); $dailyNecessities = [ 'MAE100' => 'passenger', //小機房 'MAM200' => 'passenger', //無機房 'MAH100' => 'dumbwaiter', //小電梯 'MAQ100' => 'positive_drive', //強趨梯 'MAF100' => 'cargo', //貨梯 'MAP100' => 'flatbase', // 平台踢 ]; $contractType = [ '1' => 'strategy_customer', '2' => 'general_customer' ]; $signing_date = $data['signing_date']; $bonus_v1_0_date = '2024-01-02'; $bonus_v2_0_date = '2024-01-03'; $contract_type = $data['contract_type']; $total = $data['price_total']; $type = $contractType[$contract_type]; //戰略客戶 or 一般客戶 // $elevator_knockdown_price = $data['price_total']; //受價總額 $elevators = json_decode($data['elevators_detail_arr'], true); $contract_no = $data['contractno']; $salesman = $data['salesman']; $manager = $data['manager']; $contract_kind = 1; $create_id = $data['user_id']; $create_at = date("Y-m-d H:i:s"); $status = 1; $result_bonus = []; $result_bonus_arr = []; if ($signing_date <= $bonus_v1_0_date) { $ver = '1.0'; foreach ($elevators as $key => $elevator) { $elevator_knockdown_price = $elevator['elevator_price']; // 單台電梯售價 $elevator_list_price = $elevator['option_other_price'] + $elevator['option_price'] + $elevator['elevator_price']; //牌價 $result_bonus = elevator_new_deal_bonus_v1_0($ver, $type, $elevator_knockdown_price, $salesman, $manager); $facility_no = $facilityno[$key]; $bonus_json = [ 'contract_type' => $type, 'total' => $elevator_list_price, 'fee_per_st' => $elevator_knockdown_price ]; if (!empty($result_bonus)) { if ($result_bonus['result_status'] != "error") { foreach ($result_bonus['bonus_array'] as $i => $result) { $bonus_type = explode('-', $result['bonus_type']); $pay_man_type = $bonus_type[0]; //發放類別 $bonus_kind = $bonus_type[1]; $amount = $result['bonus_amount']; //獎金水庫 $bonus_receiver = $result['bonus_receiver']; //發放人員 $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; $bonus_json['bonus_kind'] = $bonus_kind; $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); $sql = "INSERT INTO bonus (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') "; $stmt = $conn->prepare($sql); $stmt->execute(); } $request = [ "status" => "1", "data" => "Success" ]; return $request; } $request = [ "status" => "2", "data" => "create_bonus_error" ]; return $request; } } } else if ($signing_date >= $bonus_v2_0_date) { $ver = '2.0'; foreach ($elevators as $key => $elevator) { $option_other_price = !empty($elevator['option_other_price']) ? intval($elevator['option_other_price']) : 0; $elevator_type = $dailyNecessities[$elevator['spec']]; $elevator_list_price = $option_other_price + $elevator['option_price'] + $elevator['elevator_price']; $elevator_knockdown_price = $elevator['elevator_price']; $commission_fee = $elevator['commission_fee']; $result_bonus = elevator_new_deal_bonus_v2_0( $ver, $type, $elevator_type, $elevator_list_price, $elevator_knockdown_price, $salesman, $manager ); $facility_no = $facilityno[$key]; $bonus_json = [ 'contract_type' => $type, 'total' => $elevator_list_price, 'fee_per_st' => $elevator_knockdown_price ]; if (!empty($result_bonus)) { if ($result_bonus['result_status'] != "error") { foreach ($result_bonus['bonus_array'] as $i => $result) { $bonus_type = explode('-', $result['bonus_type']); $pay_man_type = $bonus_type[0]; //發放類別 $bonus_kind = $bonus_type[1]; $amount = $result['bonus_amount']; //獎金水庫 $bonus_receiver = $result['bonus_receiver']; //發放人員 $bonus_json['payment_schedul_due'] = $result['payment_schedul_due']; $bonus_json['payment_schedul_regulation'] = $result['payment_schedul_regulation']; $bonus_json['bonus_kind'] = $bonus_kind; $a = json_encode($bonus_json, JSON_UNESCAPED_UNICODE); $sql = "INSERT INTO bonus (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,status,bonus_json,create_id,create_at) VALUES ($pay_man_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$bonus_receiver',$status,'$a','$create_id','$create_at') "; $stmt = $conn->prepare($sql); $stmt->execute(); } } $request = [ "status" => "1", "data" => "Success" ]; } else { $request = [ "status" => "2", "data" => "create_bonus_error" ]; } } } return $request; } catch (PDOException $e) { header("HTTP/1.1 500 Internal Server Error"); die('Error!:' . $e->getMessage()); } } function do_wws_assign1($user_id, $form_id, $flow_code, $conn) { $tds = date("Y-m-d H:i:s"); $sql = "select appwms.nextval('form_key') form_key"; $stmt = $conn->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $form_key = $result['form_key']; $sql = "INSERT INTO flow (system_id, flow_id, form_key, form_id,flow_code) VALUES ('wws', 'wws01', '$form_key', '$form_id','$flow_code');"; $stmt = $conn->prepare($sql); $stmt->execute(); $sql = "INSERT INTO subflow (form_key, seq, current_assigner, create_date) VALUES ('$form_key', '1', '$user_id', '$tds');"; $stmt = $conn->prepare($sql); $stmt->execute(); }