@ -354,6 +354,8 @@ function T8insert($data, $facilityno)
$contract_end_date = !empty($data['contract_end_date']) ? $data['contract_end_date'] : null;
$contract_end_date = !empty($data['contract_end_date']) ? $data['contract_end_date'] : null;
$num = !empty($data['num']) ? $data['num'] : null; // 電梯數量
$num = !empty($data['num']) ? $data['num'] : null; // 電梯數量
$elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯
$elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯
$area = !empty($_POST['area']) ? $_POST['area'] : null; //縣市 Ex. A->台北 , B-> ..。
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
@ -368,141 +370,143 @@ function T8insert($data, $facilityno)
$createTime = str_replace("-", '', $date);
$createTime = str_replace("-", '', $date);
$beginDate = str_replace("-", '', $contract_begin_date);
$beginDate = str_replace("-", '', $contract_begin_date);
$endDate = str_replace("-", '', $contract_end_date);
$endDate = str_replace("-", '', $contract_end_date);
// if (empty($result)) {
if (empty($result)) {
// 若 客戶資料為空,新增一筆到 comCustomer
// 若 客戶資料為空,新增一筆到 comCustomer
// 新增客戶資料
// 新增客戶資料
$sql = "INSERT INTO comBusinessPartner(BizPartnerId,BizPartnerName,BusinessAttr,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime,BizPartnerTypeId)
$sql = "INSERT INTO comBusinessPartner
VALUES(:BizPartnerId,:BizPartnerName,1,:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime,'10')";
(BizPartnerId,BizPartnerName,BusinessAttr,CountryId,WorkTelNo,BizToDate,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime,BizPartnerTypeId)
$stmt = $connT8->prepare($sql);
VALUES(:BizPartnerId,:BizPartnerName,1,'TW',:WorkTelNo,99999999,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime,'10')";
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerName', $partyA);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':WorkTelNo', $phone);
$stmt->bindParam(':BizPartnerName', $partyA);
$stmt->bindParam(':TaxNo', $vat);
$stmt->bindParam(':WorkTelNo', $phone);
$stmt->bindParam(':EnterpriseName', $customer); //企業名稱
$stmt->bindParam(':TaxNo', $vat);
$stmt->bindParam(':ContactAddress', $partyAaddress);
$stmt->bindParam(':EnterpriseName', $customer); //企業名稱
$stmt->bindParam(':EMail', $email);
$stmt->bindParam(':ContactAddress', $partyAaddress);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':EMail', $email);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$stmt->execute();
$sql = "INSERT INTO comCustomer(OrgId,BizPartnerTypeId,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime)
$sql = "INSERT INTO comCustomer(OrgId,BizPartnerTypeId,Curr Id,BizPartnerId,PersonId,CreatorId,IsInUsed,InvoiceAddress,CreateTime)
VALUES('1000','10',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime)";
VALUES('1000','10','TWD ',:BizPartnerId,:PersonId,:CreatorId,1,:InvoiceAddress,:CreateTime)";
$stmt = $connT8->prepare($sql);
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':InvoiceAddress', $address);
$stmt->bindParam(':InvoiceAddress', $address);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreateTime', $createTime);
$stmt->execute();
$stmt->execute();
} else {
// // 若客戶資料不為空,更新該客戶資訊。
$sql = "UPDATE comCustomer SET
PersonId=:PersonId,
InvoiceAddress=:InvoiceAddress,
LastOperatorId=:LastOperatorId,
LastOperateTime=:LastOperateTime
WHERE BizPartnerId=:BizPartnerId
";
$stmt = $connT8->prepare($sql);
$stmt->bindParam(':PersonId', $salesman);
$stmt->bindParam(':InvoiceAddress', $address);
$stmt->bindParam(':LastOperatorId', $user_id);
$stmt->bindParam(':LastOperateTime', $createTime);
$stmt->bindParam(':BizPartnerId', $contractno);
$stmt->execute();
// $sql = "INSERT INTO comBusinessPartner(BizPartnerId,BizPartnerName,WorkTelNo,TaxNo,EnterpriseName,ContactAddress,EMail,CreatorId,CreateTime)VALUES(:BizPartnerId,:BizPartnerName,:WorkTelNo,:TaxNo,:EnterpriseName,:ContactAddress,:EMail,:CreatorId,:CreateTime)";
$sql = "UPDATE comBusinessPartner SET
// $stmt = $connT8->prepare($sql);
BizPartnerName=:BizPartnerName,
// $stmt->bindParam(':BizPartnerId', $contractno);
WorkTelNo=:WorkTelNo,
// $stmt->bindParam(':BizPartnerName', $partyA);
TaxNo=:TaxNo,
// $stmt->bindParam(':WorkTelNo', $phone);
EnterpriseName=:EnterpriseName,
// $stmt->bindParam(':TaxNo', $vat);
ContactAddress=:ContactAddress,
// $stmt->bindParam(':EnterpriseName', $customer); //企業名稱
EMail=:EMail,
// $stmt->bindParam(':ContactAddress', $partyAaddress);
LastOperatorId=:LastOperatorId,
// $stmt->bindParam(':EMail', $email);
LastOperateTime=:LastOperateTime
// $stmt->bindParam(':CreatorId', $user_id);
WHERE BizPartnerId = :BizPartnerId
// $stmt->bindParam(':CreateTime', $createTime);
";
$stmt = $connT8->prepare($sql);
// $stmt->execute();
$stmt->bindParam(':BizPartnerName', $partyA);
// } else {
$stmt->bindParam(':WorkTelNo', $phone);
// // 若客戶資料不為空,更新該客戶資訊。
$stmt->bindParam(':TaxNo', $vat);
// $sql = "UPDATE comCustomer SET
$stmt->bindParam(':EnterpriseName', $customer);
// PersonId=:PersonId,
$stmt->bindParam(':ContactAddress', $partyAaddress);
// InvoiceAddress=:InvoiceAddress,
$stmt->bindParam(':EMail', $email);
// LastOperatorId=:LastOperatorId,
$stmt->bindParam(':LastOperatorId', $user_id);
// LastOperateTime=:LastOperateTime,
$stmt->bindParam(':LastOperateTime', $createTime);
// WHERE BizPartnerId=:BizPartnerId
$stmt->bindParam(':BizPartnerId', $contractno);
// ";
$stmt->execute();
// $stmt = $connT8->prepare($sql);
}
// $stmt->bindParam(':PersonId', $salesman);
// echo '< pre > ';
// $stmt->bindParam(':InvoiceAddress', $address);
// print_r($elevators['maintainance']);
// $stmt->bindParam(':LastOperatorId', $user_id);
// echo '< / pre > ';
// $stmt->bindParam(':LastOperateTime', $createTime);
foreach ($elevators as $index => $elevator) {
// $stmt->bindParam(':BizPartnerId', $contractno);
$type[] = $elevator['maintainance'];
// $stmt->execute();
if ($type[$index] == 'A') {
$type = 'C3';
} else if ($type[$index] == 'B') {
// $sql = "UPDATE comBusinessPartner SET
$type = 'C4';
// BizPartnerName=:BizPartnerName,
} else if ($type[$index] == 'C') {
// WorkTelNo=:WorkTelNo,
$type = 'C5';
// TaxNo=:TaxNo,
}
// EnterpriseName=:EnterpriseName,
}
// ContractAddress=:ContractAddress,
// echo '< pre > ';
// EMail=:EMail,
// print_r($type);
// LastOperatorId=:LastOperatorId,
// echo '< / pre > ';
// LastOperateTime=:LastOperateTime
// WHERE BizPartnerId = :BizPartnerId
// ";
// $stmt = $connT8->prepare($sql);
// $stmt->bindParam(':BizPartnerName', $partyA);
// $stmt->bindParam(':WorkTelNo', $phone);
// $stmt->bindParam(':TaxNo', $vat);
// $stmt->bindParam(':EnterpriseName', $customer);
// $stmt->bindParam(':ContractAddress', $partyAaddress);
// $stmt->bindParam(':EMail', $email);
// $stmt->bindParam(':LastOperatorId', $user_id);
// $stmt->bindParam(':LastOperateTime', $createTime);
// $stmt->bindParam(':BizPartnerId', $contractno);
// $stmt->execute();
// }
// //新增於 comProject。合約 table
// //新增於 comProject。合約 table
// $sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,ValidityFromDate,ValidityToDate,CreateTime,CreatorId,IsInUsed) VALUES(:ProjectId,:ProjectName,:TypeId,:ValidityFromDate,ValidityToDate,:CreateTime,:CreatorId,1)";
$sql = "INSERT INTO comProject(ProjectId,ProjectName,TypeId,ValidityFromDate,ValidityToDate,CreateTime,CreatorId,IsInUsed)
// $stmt = $connT8->prepare($sql);
VALUES(:ProjectId,:ProjectName,:TypeId,:ValidityFromDate,:ValidityToDate,:CreateTime,:CreatorId,1)";
// $stmt->bindParam(':ProjectId', $contractno);
$stmt = $connT8->prepare($sql);
// $stmt->bindParam(':ProjectName', $customer);
$stmt->bindParam(':ProjectId', $contractno);
// $stmt->bindParam(':TypeId', $elevators['maintainance']);
$stmt->bindParam(':ProjectName', $customer);
// $stmt->bindParam(':ValidityFromDate', $beginDate);
$stmt->bindParam(':TypeId', $type);
// $stmt->bindParam(':ValidityToDate', $endDate);
$stmt->bindParam(':ValidityFromDate', $beginDate);
// $stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':ValidityToDate', $endDate);
// $stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreateTime', $createTime);
// $stmt->execute();
$stmt->bindParam(':CreatorId', $user_id);
$stmt->execute();
// // 新增電梯數
// // 新增電梯數
// foreach ($elevators as $index => $elevator) {
foreach ($elevators as $index => $elevator) {
// echo '< pre > ';
echo '< pre > ';
// print_r($elevator);
print_r($elevator);
// echo '< / pre > ';
echo '< / pre > ';
// if ($elevator['maintainance'] == 'A') {
// $elevator['maintainance'] = 'C3';
$sql = "INSERT INTO comMaterial
// } else if ($elevator['maintainance'] == 'B') {
(MaterialId,MaterialCategoryId,CreatorId,CreateTime)
// $elevator['maintainance'] = 'C4' ;
VALUES (:MaterialId,'E',:CreatorId,:CreateTime)" ;
// } else if ($elevator['maintainance'] == 'C') {
$stmt = $connT8->prepare($sql);
// $elevator['maintainance'] = 'C5' ;
$stmt->bindParam(':MaterialId', $facilityno[$index]) ;
// }
$stmt->bindParam(':CreatorId', $user_id);
// $sql = "INSERT INTO comMaterial(MaterialId,MaterialCategoryId,CreatorId,CreateTime) VALUES (:MaterialId,'E',:CreatorId,:CreateTime)" ;
$stmt->bindParam(':CreateTime', $createTime) ;
// $stmt = $connT8->prepare($sql );
$stmt->execute( );
// $stmt->bindParam(':MaterialId', $facilityno[$index]);
/// 還沒修完
// $stmt->bindParam(':CreatorId', $user_id);
// $stmt->bindParam(':CreateTime', $createTime);
$sql = "INSERT INTO comMaterialGroup
// $stmt->execute();
(MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,UnitId,CreatorId,CreateTime)
// /// 還沒修完
VALUES ('10',:MaterialId,:MaterialName,'E','SET',:CreatorId,:CreateTime)";
$stmt = $connT8->prepare($sql);
// $sql = "INSERT INTO comMaterialGroup(MaterialId,MaterialName,MaterialCategoryId,UnitId,CreatorId,CreateTime) VALUES (:MaterialId,:MaterialName,'E','SET',:CreatorId,:CreateTime)" ;
$stmt->bindParam(':MaterialId', $facilityno[$index]) ;
// $stmt = $connT8->prepare($sql );
$stmt->bindParam(':MaterialName', $customer );
// $stmt->bindParam(':MaterialId', $facilityno[$index] );
$stmt->bindParam(':CreatorId', $user_id );
// $stmt->bindParam(':MaterialName', $customer );
$stmt->bindParam(':CreateTime', $createTime );
// $stmt->bindParam(':CreatorId', $user_id );
$stmt->execute( );
// $stmt->bindParam(':CreateTime', $createTime);
/// 還沒修完
// $stmt->execute();
// /// 還沒修完
$sql = "INSERT INTO comMaterialPurchases
(MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime)
// $sql = "INSERT INTO comMaterialPurchases(MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime) VALUES (:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)";
VALUES (:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)";
// $stmt = $connT8->prepare($sql);
$stmt = $connT8->prepare($sql);
// $stmt->bindParam(':MaterialId', $facilityno[$index]);
$stmt->bindParam(':MaterialId', $facilityno[$index]);
// $stmt->bindParam(':CreatorId', $user_id);
$stmt->bindParam(':CreatorId', $user_id);
// $stmt->bindParam(':CreateTime', $createTime);
$stmt->bindParam(':CreateTime', $createTime);
// $stmt->execute();
$stmt->execute();
}
$connT8->commit();
$connT8->commit();
// }
}
}