customer.php
Lekjew.com
# |
Customer |
Dealer Code |
Dealer Name |
Branch |
Del. Time |
Address |
Province |
Hub |
Latitude |
Longitude |
Route |
Route Group |
# |
Customer |
Dealer Code |
Dealer Name |
Branch |
Del. Time |
Address |
Province |
Hub |
Latitude |
Longitude |
Route |
Route Group |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
customer_data.php
$rowp->CUST_ID
, "CUST_GROUP" => $rowp->CUST_GROUP
, "CUST_CODE" => $rowp->CUST_CODE
, "CUST_NAME" => $rowp->CUST_NAME
, "CUST_BRANCH" => $rowp->CUST_BRANCH
, "CUST_TIME" => $rowp->CUST_TIME
, "CUST_ADDRESS" => $rowp->CUST_ADDRESS
, "CUST_PROVINCE" => $rowp->CUST_PROVINCE
, "CUST_REGION" => $rowp->CUST_REGION
, "CUST_LAT" => $rowp->CUST_LAT
, "CUST_LONG" => $rowp->CUST_LONG
, "CUST_ROUTE" => $rowp->CUST_ROUTE
, "CUST_GROUPROUTE" => $rowp->CUST_GROUPROUTE
);
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
sqlsrv_close($ConnDB);
?>ImportCustomer.php
setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$namedData = array();
for ( $i=2; $i <= $highestRow; $i++) {
$dataRow = $objWorksheet->rangeToArray('A'.$i.':'.$highestColumn.$i, null, true, true, true);
$namedData[$r] = $dataRow[$i];
$r++;
}
try {
foreach ($namedData as $excel ){
$CUST_GROUP = iconv_substr(str_replace("'","", trim($excel["A"])),0,15);
$CUST_CODE = iconv_substr(str_replace("'","", trim($excel["B"])),0,15);
$CUST_NAME = iconv_substr(str_replace("'","", trim($excel["C"])),0,150);
$CUST_BRANCH = iconv_substr(str_replace("'","", trim($excel["D"])),0,100);
$CUST_TIME = date( "H:i" , strtotime(PHPExcel_Style_NumberFormat::toFormattedString(trim($excel["E"]), 'H:i')));
$CUST_ADDRESS = iconv_substr(str_replace("'","", trim($excel["F"])),0,250);
$CUST_PROVINCE = iconv_substr(str_replace("'","", trim($excel["G"])),0,80);
$CUST_REGION = iconv_substr(str_replace("'","", trim($excel["H"])),0,80);
$CUST_LAT = iconv_substr(str_replace("'","", trim($excel["I"])),0,15);
$CUST_LONG = iconv_substr(str_replace("'","", trim($excel["J"])),0,20);
$CUST_ROUTE = iconv_substr(str_replace("'","", trim($excel["K"])),0,100);
$CUST_ROUTE_G = iconv_substr(str_replace("'","", trim($excel["L"])),0,100);
if (in_array( $CUST_ROUTE_G, $ROUTG )!==true && $CUST_ROUTE_G!="") {
$ROUTG[] = $CUST_ROUTE_G;
}
$ROUTG_PRV = $ROUTG[$o-1];
$o++;
$dataexcel[] = array(
"CUST_GROUP" => $CUST_GROUP
, "CUST_CODE" => $CUST_CODE
, "CUST_NAME" => $CUST_NAME
, "CUST_BRANCH" => $CUST_BRANCH
, "CUST_TIME" => $CUST_TIME
, "CUST_ADDRESS" => $CUST_ADDRESS
, "CUST_PROVINCE" => $CUST_PROVINCE
, "CUST_REGION" => $CUST_REGION
, "CUST_LAT" => $CUST_LAT
, "CUST_LONG" => $CUST_LONG
, "CUST_ROUTE" => $CUST_ROUTE
, "CUST_ROUTE_G" => $ROUTG_PRV
);
}
$SQLRUNNING = "SELECT (CASE WHEN max(CUST_ID) is null THEN 1 ELSE max(CUST_ID)+1 END) as RUNNING FROM customer";
$RSR = sqlsrv_query($ConnDB, $SQLRUNNING);
$RS = sqlsrv_fetch_object($RSR);
$CUST_ID = $RS->RUNNING;
for($i=0; $i $ex->getMessage() );
sqlsrv_rollback($ConnDB);
sqlsrv_close($ConnDB);
}
unlink("excelImport/".$fname);
}else{
$result[] = array("ERR" => "Not File" );
}
}else{
$result[] = array("ERR" => "USERNANE or PASSWORD is incorrect");
}
echo json_encode($result, JSON_UNESCAPED_UNICODE);
?>