Commit 1ed88518 authored by Thidaporn Laisan's avatar Thidaporn Laisan
Browse files

update edit exchangerate

parent b5ee13fe
<?php
namespace App\Http\Livewire\Pages\Exchangerate;
use Livewire\Component;
use App\Models\CenterConfExchangerate;
use App\Models\CenterConfExchangerateExport;
class ExchangerateEdit extends Component
{
public $currency, $exdate, $finishdate, $rate, $baht, $exbaht;
public function mount($currency, $exdate)
{
$exchangerate = CenterConfExchangerate::where('currency', $currency)
->where('exdate', $exdate)
->first();
if ($exchangerate) {
$this->currency = $exchangerate->currency;
$this->exdate = $exdate;
$this->finishdate = $exchangerate->finishdate;
$this->rate = $exchangerate->rate;
$this->baht = $exchangerate->baht;
$export = CenterConfExchangerateExport::where('currency', $currency)
->where('exdate', $exdate)
->first();
$this->exbaht = $export ? $export->baht : null;
}
}
public function updateExchangerate()
{
$this->validate([
'currency' => 'required',
'exdate' => 'required',
'finishdate' => 'nullable',
'rate' => 'nullable|numeric',
'baht' => 'nullable|numeric',
'exbaht' => 'nullable|numeric',
]);
CenterConfExchangerate::where('currency', $this->currency)
->where('exdate', $this->exdate)
->update([
'finishdate' => $this->finishdate,
'rate' => $this->rate,
'baht' => $this->baht,
]);
$export = CenterConfExchangerateExport::where('currency', $this->currency)
->where('exdate', $this->exdate)
->first();
if ($export) {
CenterConfExchangerateExport::where('currency', $this->currency)
->where('exdate', $this->exdate)
->update([
'finishdate' => $this->finishdate,
'rate' => $this->rate,
'baht' => $this->exbaht,
]);
} else {
CenterConfExchangerateExport::create([
'currency' => $this->currency,
'exdate' => $this->exdate,
'finishdate' => $this->finishdate,
'rate' => $this->rate,
'baht' => $this->exbaht,
]);
}
$this->emit('showexchangerateListForm');
session()->flash('message', 'Exchangerate updated successfully!');
}
public function render()
{
return view('livewire.pages.exchangerate.exchangerate-edit');
}
public function loadPage($page)
{
$this->action = $page;
}
}
<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">Edit 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="updateExchangerate">
<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">
Update
</button>
</div>
</form>
</div>
</div>
</div>
</div>
......@@ -167,9 +167,9 @@
</div>
@elseif($action === 'add')
<livewire:pages.exchangerate.exchangerate-create />
@elseif($action === 'edit')
@livewire('pages.exchangerate.exchangerate-edit', ['editPid' => $editPid])
@endif
@elseif($action === 'edit')
@livewire('pages.exchangerate.exchangerate-edit', ['currency' => $editCurrency, 'exdate' => $editExdate])
@endif
</main>
@vite(['resources/js/app.js', 'resources/js/sweetalert.js'])
<script src="{{ asset('js/confirmDelete.js') }}"></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