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); // echo "
";
  // print_r($bonus_result);
  // echo "
"; // exit(); // 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 . '
'; $src_name = $path . $file['name']; if (file_exists($src_name)) { //副檔名 $extname = pathinfo($src_name, PATHINFO_EXTENSION); //主檔名 $basename = basename($src_name, '.' . $extname); } } } else { $files = null; } $sql_str = "INSERT INTO contract_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by)"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(":contract_no", $contractno); $stmt->bindParam(":customer", $customer); $stmt->bindParam(":manager", $manager); $stmt->bindParam(":vat", $vat); $stmt->bindParam(":case_name", $case_name); $stmt->bindParam(":linkman", $linkman); $stmt->bindParam(":lm_tel", $lm_tel); $stmt->bindParam(":address", $address); $stmt->bindParam(":salesman", $salesman); $stmt->bindParam(":salesman_name", $salesman_name); $stmt->bindParam(":files_id", $files_id); $stmt->bindParam(":created_at", $created_at); $stmt->bindParam(":created_by", $created_by); // $stmt->bindParam(":qc", $qc); $stmt->execute(); $result = $conn->commit(); if ($result) { header("HTTP/1.1 201 Created"); } } } catch (PDOException $e) { $conn->rollback(); 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(); }