Commit fc05fee6 authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

Merge branch 'sprint1' of...

Merge branch 'sprint1' of https://idemo.netbay.co.th/gitlab/sarun.netbay/spnpatch-laravel into sprint1
parents 69ecc25c 4bcd8562
......@@ -25,10 +25,27 @@ class ExchangerateUpload extends Component
'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) {
$resultEEC = $this->sendMasterFileToEcc($filePath);
$absolutePath = Storage::disk('public')->path($temporaryFilePath);
$absolutePath = str_replace('/', '\\', $absolutePath);
$resultEEC = $this->sendMasterFileToEcc($absolutePath);
if ($resultEEC['http_code'] == 200) {
session()->flash('message', 'Send MasterFile To EEC successfully!');
} else {
......@@ -42,10 +59,13 @@ class ExchangerateUpload extends Component
}
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)
{
$url = env('URL_MASTERFILE_EEC');
......@@ -84,7 +104,9 @@ class ExchangerateUpload extends Component
private function processFileForPatch($filePath)
{
$fileContent = Storage::get($filePath);
$fileContent = file_get_contents($filePath);
$lines = explode("\n", $fileContent);
$needChkDup = true;
$array_cur = [];
......@@ -115,26 +137,34 @@ class ExchangerateUpload extends Component
$AMMENDDATE = now()->format('Ymd') + 543;
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->on('center_conf_exchangerate.currency', '=', 'center_conf_exchangerate_export.currency')
->on('center_conf_exchangerate.exdate', '=', 'center_conf_exchangerate_export.exdate')
->on('center_conf_exchangerate.finishdate', '=', 'center_conf_exchangerate_export.finishdate');
})->first();
//DB::enableQueryLog();
$chk = ConfSmartupdate::whereMonth('PDATE', $m2)
->whereYear('PDATE', $y2)
->where('PTYPE', 'UPDATE MASTER NEW')
->exists();
if ($chk) {
//dd(DB::getQueryLog());
if ($chk === true) {
session()->flash('message', 'ไม่สามารถเพิ่ม Patch เดือน '.$m2.' ปี '.$y2.' ได้เนื่องจากได้มีการเพิ่มข้อมูลไว้ในระบบเรียบร้อยแล้ว.');
return;
}
// session()->forget('message');
$needChkDup = false;
}
CenterConfExchangerate::updateOrCreate(
CenterConfExchangerate::updateOrInsert(
[
'currency' => $CUR,
'exdate' => $DATE1,
......@@ -147,7 +177,7 @@ class ExchangerateUpload extends Component
]
);
CenterConfExchangerateExport::updateOrCreate(
CenterConfExchangerateExport::updateOrInsert(
[
'currency' => $CUR,
'exdate' => $DATE1,
......@@ -322,6 +352,7 @@ class ExchangerateUpload extends Component
private function monthToThai($m)
{
$thai_n = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"];
$m = (int) $m;
return $thai_n[$m-1];
}
......
......@@ -10,6 +10,13 @@
</div>
<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="flex items-center mt-2">
<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