11 changed files with 365 additions and 17 deletions
@ -0,0 +1,204 @@ |
|||
<?php |
|||
require_once('./conn.php'); |
|||
require 'vendor/autoload.php'; |
|||
ini_set('date.timezone', 'Asia/Taipei'); |
|||
|
|||
$id = $_GET['miid']; |
|||
|
|||
use PhpOffice\PhpSpreadsheet\IOFactory; |
|||
|
|||
// 指定要讀取的 Excel 文件 |
|||
$filePath = './mi/mi' . $id . '.xlsx'; |
|||
|
|||
|
|||
try { |
|||
$spreadsheet = IOFactory::load($filePath); |
|||
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) { |
|||
die('Error loading file: ' . $e->getMessage()); |
|||
} |
|||
|
|||
// 獲取活動工作表 |
|||
$sheet = $spreadsheet->getActiveSheet(); |
|||
|
|||
$create_at = date('Y-m-d H:i:s'); |
|||
|
|||
$sql_str = "INSERT INTO elevator_mi_option (elevator_type, model_no, min_weight, max_weight, min_speed, max_speed, min_floors, max_floors, base_floor, purchase_cost, material_plus, design_hour, export_fee, equip_profit, customs_shipping, unloading, transport_site, install_price, install_plus, install_coef, trial_price, trial_plus, trial_coef, free1y, crane, wooden_box, consume, consumables, quotation_no, create_at) |
|||
VALUES (:elevator_type, :model_no, :min_weight, :max_weight, :min_speed, :max_speed, :min_floors, :max_floors, :base_floor, :purchase_cost, :material_plus, :design_hour, :export_fee, :equip_profit, :customs_shipping, :unloading, :transport_site, :install_price, :install_plus, :install_coef, :trial_price, :trial_plus, :trial_coef, :free1y, :crane, :wooden_box, :consume, :consumables, :quotation_no, :create_at)"; |
|||
|
|||
foreach ($sheet->getRowIterator() as $key => $row) { |
|||
// 獲得單元格迭代器 |
|||
$cellIterator = $row->getCellIterator(); |
|||
$cellIterator->setIterateOnlyExistingCells(false); // This loops through all cells, |
|||
// even if a cell value is not set. |
|||
// By default, only cells that have a value set will be iterated. |
|||
foreach ($cellIterator as $idx => $cell) { |
|||
if ($cell !== null) { |
|||
// 打印單元格數據 |
|||
// echo $cell->getValue() . '///'; |
|||
} |
|||
if($idx == "A"){ |
|||
$elevator_type = $cell->getValue(); |
|||
echo $elevator_type; |
|||
//電梯機種 |
|||
} |
|||
elseif ($idx == 'B') { |
|||
$model_no = $cell->getValue(); |
|||
echo $model_no; |
|||
//產品型號 |
|||
} elseif ($idx == 'C') { |
|||
$min_weight = $cell->getValue(); |
|||
echo $min_weight; |
|||
//最低載重 |
|||
} elseif ($idx == 'D') { |
|||
$max_weight = $cell->getValue(); |
|||
$max_weight = $min_weight; |
|||
echo $max_weight; |
|||
//最高載重 |
|||
} elseif ($idx == 'E') { |
|||
$min_speed = $cell->getValue(); |
|||
echo $min_speed; |
|||
//最低速度 |
|||
} elseif ($idx == 'F') { |
|||
$max_speed = $cell->getValue(); |
|||
$max_speed = $min_speed; |
|||
echo $max_speed; |
|||
//最高速度 |
|||
} elseif ($idx == 'G') { |
|||
$min_floors = '2'; |
|||
echo $min_floors; |
|||
//樓層開始 |
|||
} elseif ($idx == 'H') { |
|||
$max_floors = $cell->getValue(); |
|||
$max_floors = (int)$min_speed / 3; |
|||
echo $max_floors; |
|||
//樓層結束 |
|||
}elseif ($idx == 'I') { |
|||
$base_floor = $cell->getValue(); |
|||
echo $base_floor; |
|||
//基準層 |
|||
}elseif ($idx == 'J') { |
|||
$purchase_cost = $cell->getValue(); |
|||
echo $purchase_cost; |
|||
//基準採購成本 |
|||
}elseif ($idx == 'K') { |
|||
$material_plus = $cell->getValue(); |
|||
echo $material_plus; |
|||
//+1停材料費 |
|||
}elseif ($idx == 'L') { |
|||
$design_hour = $cell->getValue(); |
|||
echo $design_hour; |
|||
//設計人工(小時) |
|||
}elseif ($idx == 'M') { |
|||
$export_fee = $cell->getValue(); |
|||
echo $export_fee; |
|||
//出口費用 |
|||
}elseif ($idx == 'N') { |
|||
$equip_profit = $cell->getValue(); |
|||
echo $equip_profit; |
|||
//利潤 |
|||
}elseif ($idx == 'O') { |
|||
$customs_shipping = $cell->getValue(); |
|||
echo $customs_shipping; |
|||
//報關+運輸 |
|||
}elseif ($idx == 'P') { |
|||
$unloading = $cell->getValue(); |
|||
echo $unloading; |
|||
//工廠卸貨 |
|||
}elseif ($idx == 'Q') { |
|||
$transport_site = $cell->getValue(); |
|||
echo $transport_site; |
|||
//運輸至工地 |
|||
}elseif ($idx == 'R') { |
|||
$install_price = $cell->getValue(); |
|||
echo $install_price; |
|||
//安裝基價 |
|||
}elseif ($idx == 'S') { |
|||
$install_plus = $cell->getValue(); |
|||
echo $install_plus; |
|||
//+1停安裝費 |
|||
}elseif ($idx == 'T') { |
|||
$install_coef = $cell->getValue(); |
|||
echo $install_coef; |
|||
//+1停安裝係數 |
|||
}elseif ($idx == 'U') { |
|||
$trial_price = $cell->getValue(); |
|||
echo $trial_price; |
|||
//試車費用 |
|||
}elseif ($idx == 'V') { |
|||
$trial_plus = $cell->getValue(); |
|||
echo $trial_plus; |
|||
//+1停試車價 |
|||
}elseif ($idx == 'W') { |
|||
$trial_coef = $cell->getValue(); |
|||
echo $trial_coef; |
|||
//+1停試車係數 |
|||
}elseif ($idx == 'X') { |
|||
$free1y = $cell->getValue(); |
|||
echo $free1y; |
|||
//一年免保費 |
|||
}elseif ($idx == 'Y') { |
|||
$crane = $cell->getValue(); |
|||
echo $crane; |
|||
//卸貨起吊費 |
|||
}elseif ($idx == 'Z') { |
|||
$wooden_box = $cell->getValue(); |
|||
echo $wooden_box; |
|||
//木箱清運 |
|||
}elseif ($idx == 'AA') { |
|||
$consume = $cell->getValue(); |
|||
echo $consume; |
|||
//工具消耗 |
|||
}elseif ($idx == 'AB') { |
|||
$consumables = $cell->getValue(); |
|||
echo $consumables; |
|||
//耗材 |
|||
} |
|||
} |
|||
echo "<br>"; // 換行,以分隔不同的行 |
|||
|
|||
$status = "Y"; |
|||
|
|||
if (isset($_GET['miid'])) { |
|||
try { |
|||
$quotation_no = 'Q2401002'; |
|||
//VALUES (:elevator_type, :model_no, :min_weight, :max_weight, :min_speed, :max_speed, :min_floors, :max_floors, :base_floor, :purchase_cost, :material_plus, :design_hour, :export_fee, :equip_profit, :customs_shipping, :unloading, :transport_site, :install_price, :install_plus, :install_coef, :trial_price, :trial_plus, :trial_coef, :free1y, :crane, :wooden_box, :consume, :consumables, :option_price, :quotation_no, :create_at)"; |
|||
$stmt = $conn->prepare($sql_str); |
|||
$stmt->bindParam(':elevator_type', $elevator_type); |
|||
$stmt->bindParam(':model_no', $model_no); |
|||
$stmt->bindParam(':min_weight', $min_weight); |
|||
$stmt->bindParam(':max_weight', $max_weight); |
|||
$stmt->bindParam(':min_speed', $min_speed); |
|||
$stmt->bindParam(':max_speed', $max_speed); |
|||
$stmt->bindParam(':min_floors', $min_floors); |
|||
$stmt->bindParam(':max_floors', $max_floors); |
|||
$stmt->bindParam(':base_floor', $base_floor); |
|||
$stmt->bindParam(':purchase_cost', $purchase_cost); |
|||
$stmt->bindParam(':material_plus', $material_plus); |
|||
$stmt->bindParam(':design_hour', $design_hour); |
|||
$stmt->bindParam(':export_fee', $export_fee); |
|||
$stmt->bindParam(':equip_profit', $equip_profit); |
|||
$stmt->bindParam(':customs_shipping', $customs_shipping); |
|||
$stmt->bindParam(':unloading', $unloading); |
|||
$stmt->bindParam(':transport_site', $transport_site); |
|||
$stmt->bindParam(':install_price', $install_price); |
|||
$stmt->bindParam(':install_plus', $install_plus); |
|||
$stmt->bindParam(':install_coef', $install_coef); |
|||
$stmt->bindParam(':trial_price', $trial_price); |
|||
$stmt->bindParam(':trial_plus', $trial_plus); |
|||
$stmt->bindParam(':trial_coef', $trial_coef); |
|||
$stmt->bindParam(':free1y', $free1y); |
|||
$stmt->bindParam(':crane', $crane); |
|||
$stmt->bindParam(':wooden_box', $wooden_box); |
|||
$stmt->bindParam(':consume', $consume); |
|||
$stmt->bindParam(':consumables', $consumables); |
|||
$stmt->bindParam(':quotation_no', $quotation_no); |
|||
$stmt->bindParam(':create_at', $create_at); |
|||
// 遍歷當前行的每一個單元格 |
|||
$stmt->execute(); |
|||
|
|||
} catch (PDOException $e) { |
|||
echo $e->getMessage(); |
|||
die('Error!:' . $e->getMessage()); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,68 @@ |
|||
<?php |
|||
include "../header.php"; |
|||
|
|||
$id = $_GET['id']; |
|||
|
|||
function getMI($id){ |
|||
$specarr = []; |
|||
$elno = []; |
|||
require_once("./conn.php"); |
|||
$sql_str = "SELECT * FROM pricereview_item WHERE mid = :id"; |
|||
$stmt = $conn->prepare($sql_str); |
|||
$stmt->bindParam(':id', $id); |
|||
$stmt->execute(); |
|||
$price_items = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|||
foreach($price_items as $item){ |
|||
if($item['item_group'] == "A"){ |
|||
$openfn = trim(explode("-", $item['item_spec'])[2]); |
|||
$openname = ""; |
|||
$speed = ""; |
|||
if(str_contains($openfn, "2U")){ |
|||
$speed = str_replace("2U", "", $openfn); |
|||
$openname = "2U"; |
|||
}elseif(str_contains($openfn, "4PCO")){ |
|||
$speed = str_replace("4PCO","", $openfn); |
|||
$openname = "4PCO"; |
|||
}elseif(str_contains($openfn, "6PCO")){ |
|||
$speed = str_replace("6PCO","", $openfn); |
|||
$openname = "6PCO"; |
|||
}elseif(str_contains($openfn, "2S")){ |
|||
$speed = str_replace("2S","", $openfn); |
|||
$openname = "2S"; |
|||
}elseif(str_contains($openfn, "CO")){ |
|||
$speed = str_replace("CO","", $openfn); |
|||
$openname = "CO"; |
|||
}else{ |
|||
|
|||
} |
|||
|
|||
// specarr[] = [trim(explode("-", $item['item_spec'])[0]), explode("*", explode("-", $item['item_spec'])[1])[1]]; |
|||
$specarr[] = [trim(explode("-", $item['item_spec'])[0]), explode("*", trim(explode("-", $item['item_spec'])[1]))[0], explode("*", trim(explode("-", $item['item_spec'])[1]))[1], $openname, $speed, $item['item_weight']]; |
|||
|
|||
$elno[] = trim("'".explode("-", $item['item_spec'])[0]. "'"); |
|||
} |
|||
} |
|||
$quotation_no = "Q2401002"; |
|||
$jsonel = implode(",", $elno); |
|||
$sql_str = "SELECT * FROM elevator_mi_option WHERE elevator_type IN ($jsonel) AND quotation_no = :quotation_no"; |
|||
$stmt = $conn->prepare($sql_str); |
|||
$stmt->bindParam(':quotation_no', $quotation_no); |
|||
$stmt->execute(); |
|||
$output_el_options = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|||
|
|||
$el_options = []; |
|||
|
|||
foreach($output_el_options as $el){ |
|||
foreach($specarr as $spec){ |
|||
if($el['min_weight'] == $spec['5'] && $el['min_speed'] == $spec['4']){ |
|||
$el_options[] = $el; |
|||
} |
|||
} |
|||
} |
|||
print_r($el_options); |
|||
} |
|||
getMI($id); |
|||
|
|||
?> |
|||
|
|||
|
Loading…
Reference in new issue