Commit bb63f795 authored by Thidaporn Laisan's avatar Thidaporn Laisan
Browse files

update create patch

parent e4b91a1c
...@@ -25,10 +25,27 @@ class ExchangerateUpload extends Component ...@@ -25,10 +25,27 @@ class ExchangerateUpload extends Component
'file' => 'required|mimes:csv,txt|max:2048', 'file' => 'required|mimes:csv,txt|max:2048',
]); ]);
$filePath = $this->file->store('uploads'); $temporaryFilePath = 'livewire-tmp/' . $this->file->getFilename();
try {
if (Storage::disk('public')->exists($temporaryFilePath)) {
$absolutePath = Storage::disk('public')->path($temporaryFilePath);
$absolutePath = str_replace('/', '\\', $absolutePath);
$this->processFileForPatch($absolutePath);
session()->flash('message', 'File processed successfully.');
} else {
session()->flash('message', 'Temporary file not found.');
}
} catch (\Exception $e) {
session()->flash('message', 'Error during file processing: ' . $e->getMessage());
}
if ($this->sendToEec) { if ($this->sendToEec) {
$resultEEC = $this->sendMasterFileToEcc($filePath); $absolutePath = Storage::disk('public')->path($temporaryFilePath);
$absolutePath = str_replace('/', '\\', $absolutePath);
$resultEEC = $this->sendMasterFileToEcc($absolutePath);
if ($resultEEC['http_code'] == 200) { if ($resultEEC['http_code'] == 200) {
session()->flash('message', 'Send MasterFile To EEC successfully!'); session()->flash('message', 'Send MasterFile To EEC successfully!');
} else { } else {
...@@ -42,10 +59,13 @@ class ExchangerateUpload extends Component ...@@ -42,10 +59,13 @@ class ExchangerateUpload extends Component
} }
if ($this->createPatch || $this->updatePatch) { if ($this->createPatch || $this->updatePatch) {
$this->processFileForPatch($filePath); $absolutePath = Storage::disk('public')->path($temporaryFilePath);
$absolutePath = str_replace('/', '\\', $absolutePath);
$this->processFileForPatch($absolutePath);
} }
} }
private function sendMasterFileToEcc($filePath) private function sendMasterFileToEcc($filePath)
{ {
$url = env('URL_MASTERFILE_EEC'); $url = env('URL_MASTERFILE_EEC');
...@@ -84,7 +104,9 @@ class ExchangerateUpload extends Component ...@@ -84,7 +104,9 @@ class ExchangerateUpload extends Component
private function processFileForPatch($filePath) private function processFileForPatch($filePath)
{ {
$fileContent = Storage::get($filePath);
$fileContent = file_get_contents($filePath);
$lines = explode("\n", $fileContent); $lines = explode("\n", $fileContent);
$needChkDup = true; $needChkDup = true;
$array_cur = []; $array_cur = [];
...@@ -115,26 +137,34 @@ class ExchangerateUpload extends Component ...@@ -115,26 +137,34 @@ class ExchangerateUpload extends Component
$AMMENDDATE = now()->format('Ymd') + 543; $AMMENDDATE = now()->format('Ymd') + 543;
if ($needChkDup && $this->createPatch) { if ($needChkDup && $this->createPatch) {
$latestRecord = CenterConfExchangerate::selectRaw('MONTH(MAX(exdate)) as month, YEAR(MAX(exdate)) as year') $latestRecord = CenterConfExchangerate::selectRaw('MONTH(MAX(center_conf_exchangerate.exdate)) as month, YEAR(MAX(center_conf_exchangerate.exdate)) as year')
->join('center_conf_exchangerate_export', function($join) { ->join('center_conf_exchangerate_export', function($join) {
$join->on('center_conf_exchangerate.currency', '=', 'center_conf_exchangerate_export.currency') $join->on('center_conf_exchangerate.currency', '=', 'center_conf_exchangerate_export.currency')
->on('center_conf_exchangerate.exdate', '=', 'center_conf_exchangerate_export.exdate') ->on('center_conf_exchangerate.exdate', '=', 'center_conf_exchangerate_export.exdate')
->on('center_conf_exchangerate.finishdate', '=', 'center_conf_exchangerate_export.finishdate'); ->on('center_conf_exchangerate.finishdate', '=', 'center_conf_exchangerate_export.finishdate');
})->first(); })->first();
//DB::enableQueryLog();
$chk = ConfSmartupdate::whereMonth('PDATE', $m2) $chk = ConfSmartupdate::whereMonth('PDATE', $m2)
->whereYear('PDATE', $y2) ->whereYear('PDATE', $y2)
->where('PTYPE', 'UPDATE MASTER NEW') ->where('PTYPE', 'UPDATE MASTER NEW')
->exists(); ->exists();
if ($chk) { //dd(DB::getQueryLog());
if ($chk === true) {
session()->flash('message', 'ไม่สามารถเพิ่ม Patch เดือน '.$m2.' ปี '.$y2.' ได้เนื่องจากได้มีการเพิ่มข้อมูลไว้ในระบบเรียบร้อยแล้ว.'); session()->flash('message', 'ไม่สามารถเพิ่ม Patch เดือน '.$m2.' ปี '.$y2.' ได้เนื่องจากได้มีการเพิ่มข้อมูลไว้ในระบบเรียบร้อยแล้ว.');
return; return;
} }
// session()->forget('message');
$needChkDup = false; $needChkDup = false;
} }
CenterConfExchangerate::updateOrCreate( CenterConfExchangerate::updateOrInsert(
[ [
'currency' => $CUR, 'currency' => $CUR,
'exdate' => $DATE1, 'exdate' => $DATE1,
...@@ -147,7 +177,7 @@ class ExchangerateUpload extends Component ...@@ -147,7 +177,7 @@ class ExchangerateUpload extends Component
] ]
); );
CenterConfExchangerateExport::updateOrCreate( CenterConfExchangerateExport::updateOrInsert(
[ [
'currency' => $CUR, 'currency' => $CUR,
'exdate' => $DATE1, 'exdate' => $DATE1,
...@@ -322,6 +352,7 @@ class ExchangerateUpload extends Component ...@@ -322,6 +352,7 @@ class ExchangerateUpload extends Component
private function monthToThai($m) private function monthToThai($m)
{ {
$thai_n = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"]; $thai_n = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"];
$m = (int) $m;
return $thai_n[$m-1]; return $thai_n[$m-1];
} }
......
...@@ -10,6 +10,13 @@ ...@@ -10,6 +10,13 @@
</div> </div>
<div class="bg-white p-6 rounded-lg shadow-md"> <div class="bg-white p-6 rounded-lg shadow-md">
@if (session()->has('message'))
<div class="mt-4 p-4 bg-green-100 text-green-800 rounded-lg">
{{ session('message') }}
</div>
@endif
<div class="mb-4"> <div class="mb-4">
<div class="flex items-center mt-2"> <div class="flex items-center mt-2">
<label for="upload_file" class="block text-gray-700 font-medium mr-5">Upload File Data</label> <label for="upload_file" class="block text-gray-700 font-medium mr-5">Upload File Data</label>
......
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