Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarun Mungthanya
SpnPatch-Laravel
Commits
753fe1f8
Commit
753fe1f8
authored
Jul 25, 2024
by
Thidaporn Laisan
Browse files
update dischartport
parent
1ed88518
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/Http/Livewire/Pages/Dischargeport/DischargeportIndex.php
0 → 100644
View file @
753fe1f8
<?php
namespace
App\Http\Livewire\Pages\Dischargeport
;
use
Livewire\Component
;
use
Livewire\WithPagination
;
use
App\Models\MasterDischargePort
;
class
DischargeportIndex
extends
Component
{
use
WithPagination
;
public
$action
=
'list'
;
public
$searchBy
,
$message
,
$keyword
,
$perPage
=
20
,
$searchSelected
=
'isocode'
;
protected
$listeners
=
[
'showdischargeportListForm'
,
'loadPage'
];
public
function
mount
()
{
$this
->
searchBy
=
[
'isocode'
=>
'ISO Code'
,
'portname'
=>
'Port Name'
,
'cntrycode'
=>
'Country Code'
,
'flagstatus'
=>
'Flag Status'
,
'lastupdate'
=>
'Last Update'
];
$this
->
showdischargeportListForm
();
$this
->
message
=
null
;
}
public
function
render
()
{
$query
=
MasterDischargePort
::
select
(
'isocode'
,
'portname'
,
'cntrycode'
,
'startdate'
,
'finishdate'
,
'usrname'
,
'flagstatus'
,
'lastupdate'
);
if
(
$this
->
searchSelected
&&
$this
->
keyword
)
{
$query
->
where
(
$this
->
searchSelected
,
'LIKE'
,
'%'
.
$this
->
keyword
.
'%'
);
}
$results
=
$query
->
paginate
(
$this
->
perPage
);
return
view
(
'livewire.pages.dischargeport.dischargeport-index'
,
[
'results'
=>
$results
,
'action'
=>
$this
->
action
,
]);
}
public
function
search
()
{
$this
->
resetPage
();
}
public
function
showdischargeportListForm
()
{
$this
->
action
=
'list'
;
}
public
function
loadPage
(
$page
)
{
$this
->
action
=
$page
;
}
}
app/Http/Livewire/Pages/Dischargeport/DischargeportUpload.php
0 → 100644
View file @
753fe1f8
<?php
namespace
App\Http\Livewire\Pages\Dischargeport
;
use
Livewire\Component
;
use
Livewire\WithFileUploads
;
use
Illuminate\Support\Facades\DB
;
use
App\Models\MasterDischargePort
;
use
App\Models\MasterDischargePortCompare
;
class
DischargeportUpload
extends
Component
{
use
WithFileUploads
;
public
$file
;
public
function
uploadFile
()
{
$this
->
validate
([
'file'
=>
'required|file|mimes:txt,csv'
,
]);
$filePath
=
$this
->
file
->
getRealPath
();
$file
=
fopen
(
$filePath
,
'r'
);
MasterDischargePortCompare
::
truncate
();
while
((
$line
=
fgets
(
$file
))
!==
false
)
{
$isocode
=
substr
(
$line
,
0
,
5
);
$portname
=
substr
(
$line
,
5
,
100
);
$cntrycode
=
substr
(
$line
,
0
,
2
);
$lastupdate
=
now
();
MasterDischargePortCompare
::
updateOrCreate
(
[
'isocode'
=>
$isocode
],
[
'portname'
=>
htmlspecialchars
(
trim
(
$portname
)),
'cntrycode'
=>
$cntrycode
,
'usrname'
=>
auth
()
->
user
()
->
name
,
'lastupdate'
=>
$lastupdate
,
]
);
}
fclose
(
$file
);
$lastupdate
=
now
();
// update portname
$updatePorts
=
DB
::
table
(
'master_discharge_port_compare as c'
)
->
leftJoin
(
'master_discharge_port as p'
,
'c.isocode'
,
'='
,
'p.isocode'
)
->
whereRaw
(
"REPLACE(REPLACE(REPLACE(TRIM(c.portname),''','\''),'&', '&'),'"', '
\"
') <> p.portname"
)
->
select
(
'c.isocode'
,
'c.portname'
)
->
get
();
foreach
(
$updatePorts
as
$updatePort
)
{
DB
::
table
(
'master_discharge_port'
)
->
where
(
'isocode'
,
$updatePort
->
isocode
)
->
update
([
'portname'
=>
$updatePort
->
portname
,
'lastupdate'
=>
$lastupdate
,
]);
}
// update flag
$updateFlags
=
DB
::
table
(
'master_discharge_port as p'
)
->
leftJoin
(
'master_discharge_port_compare as c'
,
'p.isocode'
,
'='
,
'c.isocode'
)
->
where
(
'p.flagstatus'
,
'Y'
)
->
whereNotNull
(
'c.isocode'
)
->
select
(
'c.isocode'
)
->
get
();
foreach
(
$updateFlags
as
$updateFlag
)
{
DB
::
table
(
'master_discharge_port'
)
->
where
(
'isocode'
,
$updateFlag
->
isocode
)
->
update
([
'flagstatus'
=>
null
,
'lastupdate'
=>
$lastupdate
,
]);
}
// update delete flagstatus (Y is delete)
$isoAll
=
DB
::
table
(
'master_discharge_port'
)
->
whereNotIn
(
'isocode'
,
function
(
$query
)
{
$query
->
select
(
'isocode'
)
->
from
(
'master_discharge_port_compare'
);
})
->
pluck
(
'isocode'
);
if
(
$isoAll
->
isNotEmpty
())
{
DB
::
table
(
'master_discharge_port'
)
->
whereIn
(
'isocode'
,
$isoAll
)
->
update
([
'flagstatus'
=>
'Y'
,
'lastupdate'
=>
$lastupdate
,
]);
}
// INSERT not have
DB
::
table
(
'master_discharge_port'
)
->
insertUsing
([
'isocode'
,
'portname'
,
'cntrycode'
,
'usrname'
,
'lastupdate'
],
function
(
$query
)
{
$query
->
select
(
't2.*'
)
->
from
(
'master_discharge_port_compare as t2'
)
->
leftJoin
(
'master_discharge_port as t1'
,
't1.isocode'
,
'='
,
't2.isocode'
)
->
whereNull
(
't1.isocode'
);
});
DB
::
table
(
'master_discharge_port'
)
->
where
(
function
(
$query
)
{
$query
->
where
(
'usrname'
,
''
)
->
orWhereNotNull
(
'usrname'
);
})
->
update
([
'usrname'
=>
null
]);
session
()
->
flash
(
'message'
,
'Upload File Success'
);
return
redirect
()
->
route
(
'main'
);
}
public
function
render
()
{
return
view
(
'livewire.pages.dischargeport.dischargeport-upload'
);
}
}
app/Http/Livewire/Pages/Exchangerate/ExchangerateIndex.php
View file @
753fe1f8
...
@@ -12,9 +12,8 @@ class ExchangerateIndex extends Component
...
@@ -12,9 +12,8 @@ class ExchangerateIndex extends Component
use
WithPagination
;
use
WithPagination
;
public
$action
=
'list'
;
public
$action
=
'list'
;
public
$searchBy
,
$searchByPage
,
$editCurrency
,
$editExdate
,
$deleteCurrency
,
$deleteExdate
,
$message
,
$keyword
,
$perPage
=
20
,
$searchSelected
=
'center_conf_exchangerate.currency'
;
public
$searchBy
,
$editCurrency
,
$editExdate
,
$deleteCurrency
,
$deleteExdate
,
$message
,
$keyword
,
$perPage
=
20
,
$searchSelected
=
'center_conf_exchangerate.currency'
;
public
$selectedExchangerates
=
[];
public
$selectedExchangerates
=
[];
public
$deletePid
;
protected
$listeners
=
[
protected
$listeners
=
[
'deleteItem'
,
'deleteItem'
,
...
...
resources/views/livewire/main-container.blade.php
View file @
753fe1f8
...
@@ -27,7 +27,9 @@
...
@@ -27,7 +27,9 @@
@elseif ($currentContent === 'Parameter')
@elseif ($currentContent === 'Parameter')
<livewire:pages.parameter.parameter-index
/>
<livewire:pages.parameter.parameter-index
/>
@elseif ($currentContent === 'Exchangerate')
@elseif ($currentContent === 'Exchangerate')
<livewire:pages.exchangerate.exchangerate-index
/>
<livewire:pages.exchangerate.exchangerate-index
/>
@elseif ($currentContent === 'Dischargeport')
<livewire:pages.dischargeport.dischargeport-index
/>
@else
@else
@livewire('code-comparer')
@livewire('code-comparer')
@endif
@endif
...
...
resources/views/livewire/navbar.blade.php
View file @
753fe1f8
...
@@ -41,6 +41,10 @@
...
@@ -41,6 +41,10 @@
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
<a
href=
"#"
>
Create Patch Exchangerate
</a>
<a
href=
"#"
>
Create Patch Exchangerate
</a>
</li>
</li>
<li
x-data=
"{ open: false }"
wire:click.prevent=
"loadContent('Dischargeport')"
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
<a
href=
"#"
>
Create Discharge Port
</a>
</li>
<li
x-data=
"{ open: false, timer: null }"
@
click.away=
"open = false"
@
mouseenter=
"open = true; clearTimeout(timer)"
<li
x-data=
"{ open: false, timer: null }"
@
click.away=
"open = false"
@
mouseenter=
"open = true; clearTimeout(timer)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
...
...
resources/views/livewire/pages/dischargeport/dischargeport-index.blade.php
0 → 100644
View file @
753fe1f8
<div
wire:loading.remove
>
<style>
table
{
width
:
100%
;
table-layout
:
auto
;
}
.table-responsive
{
overflow-x
:
auto
;
}
.form-upload
{
display
:
inline-block
;
margin-left
:
1rem
;
}
.form-upload
input
[
type
=
"file"
]
{
display
:
inline-block
;
margin-right
:
0.5rem
;
padding
:
0.5rem
;
border-radius
:
0.25rem
;
}
.form-upload
label
{
margin-left
:
0.5rem
;
margin-right
:
1rem
;
}
.form-upload
button
{
margin-top
:
0.5rem
;
}
</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"
>
Create Discharge Port
</h2>
</div>
<div
class=
"flex justify-between"
>
<div
class=
"px-2 ml-4"
>
<!-- File Upload Form -->
@livewire('pages.dischargeport.dischargeport-upload')
</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"
>
ISO Code
</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"
>
Port Name
</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"
>
Country Code
</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"
>
Flag Status
</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"
>
Last Update
</th>
</tr>
</thead>
<tbody>
@foreach ($results as $disc)
<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"
>
{{ $disc->isocode }}
</td>
<td
class=
"whitespace-nowrap px-1 py-3 sm:px-2"
>
{{ $disc->portname }}
</td>
<td
class=
"whitespace-nowrap px-1 py-3 sm:px-2"
>
{{ $disc->cntrycode }}
</td>
<td
class=
"whitespace-nowrap px-1 py-3 sm:px-2"
>
{{ $disc->flagstatus }}
</td>
<td
class=
"whitespace-nowrap px-1 py-3 sm:px-2"
>
{{ $disc->lastupdate }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<livewire:delete-modal
/>
{{ $results->links('livewire.paginate-custom') }}
</div>
</div>
</div>
@endif
</main>
</div>
resources/views/livewire/pages/dischargeport/dischargeport-upload.blade.php
0 → 100644
View file @
753fe1f8
<div>
@if (session()->has('message'))
<div
class=
"alert alert-success"
>
{{ session('message') }}
</div>
@endif
<form
wire:submit.prevent=
"uploadFile"
enctype=
"multipart/form-data"
>
<div
class=
"form-upload"
>
<input
type=
"file"
wire:model=
"file"
>
@error('file')
<span
class=
"error"
>
{{ $message }}
</span>
@enderror
<button
type=
"submit"
class=
"py-2 px-3 bg-stone-700 rounded-lg text-white"
>
Upload
</button>
</div>
</form>
</div>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment