Commit 570d9c08 authored by Thidaporn Laisan's avatar Thidaporn Laisan
Browse files

update list/add exchange rate

parent 8c0e694e
<?php
namespace App\Http\Livewire\Pages\Exchangerate;
use Livewire\Component;
use App\Models\CenterConfExchangerate;
use App\Models\CenterConfExchangerateExport;
use Carbon\Carbon;
class ExchangerateCreate extends Component
{
public $currency, $exdate, $finishdate, $rate, $baht, $exbaht, $pageCode = [];
public $searchByPage = [];
public function mount()
{
// Initial setup if necessary
}
public function addExchangerate()
{
$this->validate([
'currency' => 'required',
'exdate' => 'required',
'finishdate' => 'nullable',
'rate' => 'nullable|numeric',
'baht' => 'nullable|numeric',
'exbaht' => 'nullable|numeric',
]);
//$exdate = Carbon::createFromFormat('m/d/Y', $this->exdate)->format('Y-m-d');
//$finishdate = $this->finishdate ? Carbon::createFromFormat('m/d/Y', $this->finishdate)->format('Y-m-d') : null;
CenterConfExchangerate::create([
'currency' => $this->currency,
'exdate' => $this->exdate,
'finishdate' => $this->finishdate,
'rate' => $this->rate,
'baht' => $this->baht,
]);
CenterConfExchangerateExport::create([
'currency' => $this->currency,
'exdate' => $this->exdate,
'finishdate' => $this->finishdate,
'rate' => $this->rate,
'baht' => $this->exbaht,
]);
$this->reset(['currency', 'exdate', 'finishdate', 'rate', 'baht', 'exbaht']);
$this->emit('showexchangerateListForm');
session()->flash('message', 'Exchangerate added successfully!');
}
public function render()
{
return view('livewire.pages.exchangerate.exchangerate-create');
}
public function loadPage($page)
{
$this->action = $page;
}
}
<?php
namespace App\Http\Livewire\Pages\Exchangerate;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\CenterConfExchangerate;
use App\Models\CenterConfExchangerateExport;
class ExchangerateIndex extends Component
{
use WithPagination;
public $action = 'list';
public $searchBy, $searchByPage, $editCurrency, $editExdate, $deleteCurrency, $deleteExdate, $message, $keyword, $perPage = 20, $searchSelected = 'center_conf_exchangerate.currency';
public $selectedExchangerates = [];
public $deletePid;
protected $listeners = [
'deleteItem',
'deleteSelected',
'showexchangerateListForm',
'loadPage'
];
public function mount()
{
$this->searchBy = [
'center_conf_exchangerate.currency' => 'By Currency',
'center_conf_exchangerate.exdate' => 'By Expired date',
'center_conf_exchangerate.finishdate' => 'By Finish date'
];
$this->showexchangerateListForm();
$this->message = null;
}
public function render()
{
$query = CenterConfExchangerate::select(
'center_conf_exchangerate.currency',
'center_conf_exchangerate.exdate',
'center_conf_exchangerate.finishdate',
'center_conf_exchangerate.rate',
'center_conf_exchangerate.baht',
'center_conf_exchangerate.amenddate',
'center_conf_exchangerate_export.baht as exbaht'
)
->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');
});
if ($this->searchSelected && $this->keyword) {
$query->where($this->searchSelected, 'LIKE', '%' . $this->keyword . '%');
}
$query->orderBy('center_conf_exchangerate.exdate', 'DESC')
->orderBy('center_conf_exchangerate_export.exdate', 'DESC')
->orderBy('center_conf_exchangerate.currency', 'DESC')
->orderBy('center_conf_exchangerate_export.currency', 'DESC');
$results = $query->paginate($this->perPage);
return view('livewire.pages.exchangerate.exchangerate-index', compact('results'));
}
public function search()
{
$this->resetPage();
}
public function showexchangerateListForm()
{
$this->action = 'list';
}
public function showexchangerateAddForm()
{
$this->action = 'add';
}
public function showexchangerateEditForm($currency, $exdate)
{
$this->editCurrency = $currency;
$this->editExdate = $exdate;
$this->action = 'edit';
}
public function deleteExchangerate($currency, $exdate)
{
CenterConfExchangerate::where('currency', $currency)
->where('exdate', $exdate)
->delete();
CenterConfExchangerateExport::where('currency', $currency)
->where('exdate', $exdate)
->delete();
session()->flash('message', 'Exchangerate deleted successfully!');
$this->showexchangerateListForm();
}
public function deleteSelectedExchangerates()
{
foreach ($this->selectedExchangerates as $exchangerate) {
$parts = explode(',', $exchangerate); // แยกค่า currency และ exdate
CenterConfExchangerate::where('currency', $parts[0])
->where('exdate', $parts[1])
->delete();
CenterConfExchangerateExport::where('currency', $parts[0])
->where('exdate', $parts[1])
->delete();
}
session()->flash('message', 'Selected Exchangerates deleted successfully!');
$this->selectedExchangerates = [];
$this->showexchangerateListForm();
}
public function deleteItem($currency, $exdate)
{
$this->deleteExchangerate($currency, $exdate);
}
public function deleteSelected()
{
$this->deleteSelectedExchangerates();
}
public function loadPage($page)
{
$this->action = $page;
}
}
......@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class CenterConfExchangerate extends Model
{
public $timestamps = false;
protected $table = 'center_conf_exchangerate';
protected $fillable = [
'currency',
......
......@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class CenterConfExchangerateExport extends Model
{
public $timestamps = false;
protected $table = 'center_conf_exchangerate_export';
protected $fillable = [
'currency',
......
......@@ -4,6 +4,8 @@
'delete-modal' => 'App\\Http\\Livewire\\DeleteModal',
'main-container' => 'App\\Http\\Livewire\\MainContainer',
'navbar' => 'App\\Http\\Livewire\\Navbar',
'pages.exchangerate.exchangerate-create' => 'App\\Http\\Livewire\\Pages\\Exchangerate\\ExchangerateCreate',
'pages.exchangerate.exchangerate-index' => 'App\\Http\\Livewire\\Pages\\Exchangerate\\ExchangerateIndex',
'pages.parameter.parameter-create' => 'App\\Http\\Livewire\\Pages\\Parameter\\ParameterCreate',
'pages.parameter.parameter-edit' => 'App\\Http\\Livewire\\Pages\\Parameter\\ParameterEdit',
'pages.parameter.parameter-index' => 'App\\Http\\Livewire\\Pages\\Parameter\\ParameterIndex',
......
......@@ -16,6 +16,22 @@ window.confirmDelete = function(pid) {
});
}
window.confirmDelete2 = function(currency, exdate) {
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
Livewire.emit('deleteItem', currency, exdate);
}
});
}
window.confirmDeleteSelected = function() {
Swal.fire({
title: 'Are you sure?',
......
......@@ -17,8 +17,11 @@
<livewire:pages.send-patch.send-patch />
@elseif ($currentContent === 'Patch')
<livewire:pages.patch.patch-index />
@elseif ($currentContent === 'Parameter')
@elseif ($currentContent === 'Parameter')
<livewire:pages.parameter.parameter-index />
@elseif ($currentContent === 'ExchangeRate')
<livewire:pages.exchangerate.exchangerate-index />
@else
@livewire('code-comparer')
@endif
......
......@@ -20,6 +20,10 @@
<li x-data="{ open: false }" wire:click.prevent="loadContent('Parameter')" class="relative">
<a href="#" class="text-gray-700 hover:text-stone-700">Parameter</a>
</li>
<li x-data="{ open: false }" wire:click.prevent="loadContent('ExchangeRate')" class="relative">
<a href="#" class="text-gray-700 hover:text-stone-700">Create Patch Exchange Rate</a>
</li>
<li x-data="{ open: false }" @click.away="open = false" @mouseenter="open = true" class="relative">
<a href="#" class="text-gray-700 hover:text-stone-700">Configuration</a>
<ul x-show="open" @click="open = false" @mouseleave="open = false"
......
<div>
<button type="button" wire:click="$emit('loadPage', 'list')"
class="btn mx-auto m-3 text-white bg-primary px-3 py-2">Back</button>
<div class="max-w-full mx-auto p-6 bg-gray-100">
<div class="w-full px-6 mb-12 flex justify-center">
<div class="p-12 bg-white shadow-md rounded-lg w-1/2">
<h2 class="text-2xl font-bold mb-4">Create Exchangerate</h2>
<div class="mx-auto p-4">
@if (session()->has('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
@endif
<form wire:submit.prevent="addExchangerate">
<div class="mb-4">
<label for="currency" class="block text-sm font-medium text-gray-700">Currency</label>
<input type="text" wire:model.defer="currency" id="currency" class="w-full mt-1 p-2 border border-gray-300 rounded-md">
@error('currency') <span class="text-red-500">{{ $message }}</span> @enderror
</div>
<div class="mb-4">
<label for="exdate" class="block text-gray-700">Expired date</label>
<input type="date" id="exdate" class="w-full mt-1 p-2 border border-gray-300 rounded-md" wire:model.defer="exdate">
<!-- @error('exdate') <span class="text-red-500">{{ $message }}</span> @enderror -->
</div>
<div class="mb-4">
<label for="finishdate" class="block text-gray-700">Finish date</label>
<input type="date" id="finishdate" class="w-full mt-1 p-2 border border-gray-300 rounded-md" wire:model.defer="finishdate">
</div>
<div class="mb-4">
<label for="rate" class="block text-sm font-medium text-gray-700">Rate</label>
<input type="text" wire:model.defer="rate" id="rate" class="w-full mt-1 p-2 border border-gray-300 rounded-md">
</div>
<div class="mb-4">
<label for="baht" class="block text-sm font-medium text-gray-700">Baht</label>
<input type="text" wire:model.defer="baht" id="baht" class="w-full mt-1 p-2 border border-gray-300 rounded-md">
</div>
<div class="mb-4">
<label for="exbaht" class="block text-sm font-medium text-gray-700">Export Baht</label>
<input type="text" wire:model.defer="exbaht" id="exbaht" class="w-full mt-1 p-2 border border-gray-300 rounded-md">
</div>
<div class="flex items-center justify-center">
<button type="submit"
class="bg-primary inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Save
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div wire:loading.remove>
<style>
table {
width: 100%;
table-layout: auto;
}
.table-responsive {
overflow-x: auto;
}
</style>
<main class="m-2">
@if ($action === 'list')
@if ($message)
<div class="alert alert-success">
<div wire:ignore x-data="{ show: true }" x-init="setTimeout(() => show = false, 3000)"
x-show.transition.duration.500ms="show"
class="fixed top-5 right-5 z-50 bg-green-500 text-white py-2 px-4 rounded-md shadow-lg">
{{ $message }}
</div>
</div>
@endif
<div class="grid grid-cols-1 gap-4 sm:gap-5 lg:gap-6">
<div class="pb-4">
<div class="my-3 flex h-8 items-center justify-between px-4 sm:px-5">
<h2 class="font-medium tracking-wide text-slate-700 line-clamp-1 dark:text-navy-100 lg:text-base">
NEW UPDATE EXCHANGERATE MASTERFILE
</h2>
</div>
<div class="flex justify-between">
<div class="px-2 ml-4">
<button type="button" class="py-2 px-3 bg-stone-700 rounded-lg text-white"
wire:click="showexchangerateAddForm">Add</button>
<button type="button" class="py-2 px-3 bg-stone-700 rounded-lg text-white"
onclick="confirmDeleteSelected()">Delete</button>
</div>
<div class="inline-flex flex-initial">
<div x-data="{ isInputActive: true }">
<div class="flex gap-4 px-5 items-center">
<button @click="isInputActive = !isInputActive"
class="btn h-8 w-14 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4.5 w-4.5" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
<span class="w-64" x-show="isInputActive === true">
<input
class="form-input h-9 peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
placeholder="Search Keyword" type="text" wire:model.defer="keyword" />
</span>
<span class="w-52" x-show="isInputActive === true">
<select wire:model.defer="searchSelected"
class="form-select h-9 w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent">
@foreach ($searchBy as $key => $by)
<option value="{{ $key }}">{{ $by }}</option>
@endforeach
</select>
</span>
<button type="button" class="bg-stone-700 text-white px-4 py-2 rounded"
wire:click="search">Search</button>
</div>
</div>
</div>
</div>
<div class="mx-3 mt-3 px-4">
<div class="is-scrollbar-hidden min-w-full table-responsive" x-data="pages.tables.initExample1">
<table class="is-hoverable table w-full text-left">
<thead>
<tr>
<th
class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">
#
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Currency
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Expired date
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Finish date
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Rate
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Baht
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Export Baht
</th>
<th
class="whitespace-nowrap rounded-tr-lg bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Action
</th>
</tr>
</thead>
<tbody>
@foreach ($results as $exc)
<tr class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
<td class="whitespace-nowrap px-4 py-3 sm:px-5">
<label class="inline-flex items-center space-x-2">
<input
class="form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary hover: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" wire:model.defer="selectedExchangerates"
value="{{ $exc->currency }},{{ $exc->exdate }}" />
</label>
</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->currency }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->exdate }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->finishdate }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->rate }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->baht }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $exc->exbaht }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">
<div class="flex justify-center space-x-2">
<a wire:click="showexchangerateEditForm('{{ $exc->currency }}', '{{ $exc->exdate }}')"
class="btn h-8 w-8 p-0 text-info hover:bg-info/20 focus:bg-info/20 active:bg-info/25">
<i class="fa fa-edit"></i>
</a>
<a onclick="confirmDelete2('{{ $exc->currency }}', '{{ $exc->exdate }}')"
class="btn h-8 w-8 p-0 text-danger hover:bg-danger/20 focus:bg-danger/20 active:bg-danger/25">
<i class="fa fa-trash"></i>
</a>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<livewire:delete-modal />
{{ $results->links('livewire.paginate-custom') }}
</div>
</div>
</div>
@elseif($action === 'add')
<livewire:pages.exchangerate.exchangerate-create />
@elseif($action === 'edit')
@livewire('pages.exchangerate.exchangerate-edit', ['editPid' => $editPid])
@endif
</main>
@vite(['resources/js/app.js', 'resources/js/sweetalert.js'])
<script src="{{ asset('js/confirmDelete.js') }}"></script>
</div>
<!-- <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> -->
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