Commit 6499b290 authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

issue truncate gen patch

parent 948018da
......@@ -40,10 +40,10 @@ class MasterFileController extends Controller
$filePath = $file->getRealPath();
if (isset($request->truncateGoods) && ($request->format_file_id == 196)) {
$truncateGoods = true;
if (isset($request->truncate) && (($request->format_file_id == 32) || ($request->format_file_id == 63) || ($request->format_file_id == 196))) {
$truncate = true;
} else {
$truncateGoods = false;
$truncate = false;
}
......@@ -59,7 +59,7 @@ class MasterFileController extends Controller
if ($request->createPatch) {
$sqlPackAll = $this->readTxt($filePath, $formatData, $fileFormat, $request->limit, $request->noLimit);
$this->processPatches($sqlPackAll, $fileFormat, $request->genWithSmartUpdate, $request->noLimit, $truncateGoods);
$this->processPatches($sqlPackAll, $fileFormat, $request->genWithSmartUpdate, $request->noLimit, $truncate);
$message .= 'Patch master file created successfully. ';
}
......@@ -108,7 +108,7 @@ class MasterFileController extends Controller
]);
}
function processPatches($sqlPackAll, $fileFormat, $genSpnSmartUpdateDecode, $noLimit, $truncateGoods)
function processPatches($sqlPackAll, $fileFormat, $genSpnSmartUpdateDecode, $noLimit, $truncate)
{
$uid = auth()->user()->id;
$pLevel = "Critical";
......@@ -129,7 +129,7 @@ class MasterFileController extends Controller
$patchCode = '';
if ($truncateGoods && $part == 1) {
if ($truncate && $part == 1 && $fileFormat->formatservice_ID == 196) {
$patchCode .= '$sql = "truncate table master_permissiongoods";
exec_query($sql);
if ($DBTYPE == "MSSQL") {
......@@ -145,8 +145,13 @@ class MasterFileController extends Controller
}
}
';
}else if ($truncate && $part == 1 && $fileFormat->formatservice_ID == 32) {
$patchCode .= '$sql="truncate table master_country";exec_query($sql);';
}else if ($truncate && $part == 1 && $fileFormat->formatservice_ID == 63) {
$patchCode .= '$sql="truncate table master_container_type";exec_query($sql);';
}
$ALL64 = base64_encode(gzcompress(var_export($sqlPack, true)));
......@@ -201,7 +206,7 @@ class MasterFileController extends Controller
$patchCode .= 'unset($update);' . "\n";
$patchCode .= 'unset($select);' . "\n";
$patchCode .= 'unset($select2);' . "\n";
$patchCode .= '$PRINT_ .= date("h:i:s")." Process ' . ($i__ + 1) . ' / ' . $countSql . ' Successful Update $succ data(s) (Added = $succ2) from $CountSQL_.</br>";' . "\n";
$patchCode .= '$PRINT_ = "";$PRINT_ .= date("h:i:s")." Process ' . ($i__ + 1) . ' / ' . $countSql . ' Successful Update $succ data(s) (Added = $succ2) from $CountSQL_.</br>";' . "\n";
return $patchCode;
}
......@@ -269,12 +274,11 @@ class MasterFileController extends Controller
{
$X = 0;
$Y = 0;
$Z = 0;
$primaryKeyConditions = [];
$insertFields = [];
$insertValues = [];
foreach ($formatData['primary_key'] as $keyIndex => $primaryKey) {
$fieldFormat = $formatData['format'][$keyIndex];
$type = $this->getFieldType($fieldFormat['TYPE']);
......@@ -310,7 +314,7 @@ class MasterFileController extends Controller
$insert = "INSERT INTO " . $formatData['database'] . " (" . implode(',', $insertFields) . ") VALUES (" . implode(',', $insertValues) . ")";
$update = $this->generateUpdateQuery($formatData['format'], $line, $X, $formatData['primary_key']);
$update = $this->generateUpdateQuery($formatData['format'], $line, $Z, $formatData['primary_key']);
return [
'insert' => $insert,
......@@ -353,7 +357,7 @@ class MasterFileController extends Controller
private function generateUpdateQuery($formatData, $text, &$Z, $primaryKeys)
{
$update = "";
foreach ($formatData as $index => $fieldFormat) {
$type = $fieldFormat['TYPE'];
......@@ -361,8 +365,11 @@ class MasterFileController extends Controller
$type = str_replace('DE', '', $type);
$type = (int) $type + 1;
}
$type = (int) filter_var($type, FILTER_SANITIZE_NUMBER_INT);
$fieldValue = substr($text, $Z, $type);
$Z += $type;
if (isset($fieldFormat['format'])) {
......@@ -375,9 +382,10 @@ class MasterFileController extends Controller
if ($update != "") {
$update .= ", ";
}
Log::info( "`" . $fieldFormat['FILD'] . "` = '" . str_replace("'", "''", trim($fieldValue)) . "'");
$update .= "`" . $fieldFormat['FILD'] . "` = '" . str_replace("'", "''", trim($fieldValue)) . "'";
}
}
return $update;
......
......@@ -17,12 +17,12 @@
@endphp
<div class="bg-main-container" x-data="{
notLimit: false,
permissionGoods: false,
truncateCheckBox: false,
checkSelect(event) {
if (event.target.value == 196) {
this.permissionGoods = true
if (event.target.value == 196 || event.target.value == 32 || event.target.value == 63) {
this.truncateCheckBox = true
} else {
this.permissionGoods = false
this.truncateCheckBox = false
}
}
}">
......@@ -108,12 +108,12 @@
</div>
</div>
<div class="mb-4" x-show="permissionGoods">
<div class="mb-4" x-show="truncateCheckBox">
<label class="inline-flex items-center">
<input name="truncateGoods"
<input name="truncate"
class="form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary focus:border-primary dark:bg-navy-900 dark:border-navy-500 dark:checked:bg-accent dark:checked:border-accent dark:hover:border-accent dark:focus:border-accent"
type="checkbox" value="checked" x-bind:checked="permissionGoods">
<span class="ml-2 text-red-500">Truncate Table "master_permissiongoods"</span>
type="checkbox" value="checked" x-bind:checked="truncateCheckBox">
<span class="ml-2 text-red-500">Truncate Table </span>
</label>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment