This commit is contained in:
meusinfirmary
2025-06-20 01:17:16 +09:00
parent a4276d9a6a
commit ed42967eef
5 changed files with 350 additions and 235 deletions

View File

@ -370,7 +370,61 @@ class Tracks extends Model
$query .= " ;"; $query .= " ;";
return DB::select($query, $params); // return DB::select($query, $params);
$rawTracks = DB::select($query, $params);
$cleanTracks = self::filterJumps($rawTracks);
if (isset($filter["limit"])) {
return array_slice($cleanTracks, 0, $filter["limit"]);
}
return $cleanTracks;
}
public static function haversineDistance($lat1, $lon1, $lat2, $lon2)
{
$earthRadius = 6371000; // meters
$lat1 = deg2rad($lat1);
$lon1 = deg2rad($lon1);
$lat2 = deg2rad($lat2);
$lon2 = deg2rad($lon2);
$dlat = $lat2 - $lat1;
$dlon = $lon2 - $lon1;
$a = sin($dlat / 2) ** 2 + cos($lat1) * cos($lat2) * sin($dlon / 2) ** 2;
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $earthRadius * $c;
}
public static function filterJumps($points, $maxDistance = 50, $maxTimeGap = 10)
{
$filtered = [];
$last = null;
foreach ($points as $p) {
if (!$last) {
$filtered[] = $p;
$last = $p;
continue;
}
$distance = self::haversineDistance(
$last->latitude,
$last->longitude,
$p->latitude,
$p->longitude
);
$timeGap = $p->lst_loc_crt - $last->lst_loc_crt;
if ($distance <= $maxDistance || $timeGap > $maxTimeGap) {
$filtered[] = $p;
$last = $p;
}
}
return $filtered;
} }
public static function nearestInCircle($lat, $lng, $rad, $filter = []) public static function nearestInCircle($lat, $lng, $rad, $filter = [])

View File

@ -22,8 +22,8 @@
} }
/* .cLogoGroup { /* .cLogoGroup {
display: inherit; display: inherit;
} */ } */
#openLeftSideBar1Mobile { #openLeftSideBar1Mobile {
display: none; display: none;
} }
@ -35,11 +35,11 @@
@media (max-width: 425px) { @media (max-width: 425px) {
/* .cLogoGroup { /* .cLogoGroup {
display: none; display: none;
} }
.cNameGroup { .cNameGroup {
margin-bottom: 0!important; margin-bottom: 0!important;
} */ } */
#openLeftSideBar1 { #openLeftSideBar1 {
display: none !important; display: none !important;
} }
@ -766,13 +766,13 @@
}, },
calcPeriodeDate: function(startDate, endDate) { calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') { if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid'); Helper.toast('Warning', 'just now', 'Start date of the period is not valid');
return { return {
isValid: false isValid: false
}; };
} }
if (endDate.format('YYYY-MM-DD') === 'Invalid date') { if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid'); Helper.toast('Warning', 'just now', 'End date of the period is not valid');
return { return {
isValid: false isValid: false
}; };
@ -781,13 +781,13 @@
const duration = moment.duration(endDate.diff(startDate)); const duration = moment.duration(endDate.diff(startDate));
const diffDays = duration.days(); const diffDays = duration.days();
if (diffDays > 30) { if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan'); Helper.toast('Warning', 'just now', 'Maximum period is 1 month');
return { return {
isValid: false isValid: false
}; };
} }
if (diffDays < 0) { if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid'); Helper.toast('Warning', 'just now', 'Invalid period range');
return { return {
isValid: false isValid: false
}; };
@ -2606,7 +2606,7 @@
let startMarker = Leaflet.addMarkers({ let startMarker = Leaflet.addMarkers({
lat: start.latitude, lat: start.latitude,
lng: start.longitude, lng: start.longitude,
label: `<b>Titik Awal</b><br>${start.nopol1} ${start.nopol2} ${start.nopol3}<br>${moment.unix(start?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof start.lst_speed != 'undefined') ? start.lst_speed : '0'}<br>${Number(start.latitude).toFixed(5)},${Number(start.longitude).toFixed(6)}<br>${decodeURIComponent(start.fulladdress || 'address')}`, label: `<b>Start Poin</b><br>${start.nopol1} ${start.nopol2} ${start.nopol3}<br>${moment.unix(start?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof start.lst_speed != 'undefined') ? start.lst_speed : '0'}<br>${Number(start.latitude).toFixed(5)},${Number(start.longitude).toFixed(6)}<br>${decodeURIComponent(start.fulladdress || 'address')}`,
options: { options: {
icon: Icon.titikAwal(), icon: Icon.titikAwal(),
// rotationAngle: 290 // rotationAngle: 290
@ -2615,7 +2615,7 @@
let finishMarker = Leaflet.addMarkers({ let finishMarker = Leaflet.addMarkers({
lat: finish.latitude, lat: finish.latitude,
lng: finish.longitude, lng: finish.longitude,
label: `<b>Titik Akhir</b><br>${finish.nopol1} ${finish.nopol2} ${finish.nopol3}<br>${moment.unix(finish?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof finish.lst_speed != 'undefined') ? finish.lst_speed : '0'}<br>${Number(finish.latitude).toFixed(5)},${Number(finish.longitude).toFixed(6)}<br>${decodeURIComponent(finish.fulladdress || 'address')}`, label: `<b>End Poin</b><br>${finish.nopol1} ${finish.nopol2} ${finish.nopol3}<br>${moment.unix(finish?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof finish.lst_speed != 'undefined') ? finish.lst_speed : '0'}<br>${Number(finish.latitude).toFixed(5)},${Number(finish.longitude).toFixed(6)}<br>${decodeURIComponent(finish.fulladdress || 'address')}`,
options: { options: {
icon: Icon.titikAkhir() icon: Icon.titikAkhir()
} }

View File

@ -78,8 +78,7 @@
<tr class=""> <tr class="">
<td class="">1</td> <td class="">1</td>
<td class=""> <td class="">
<a href="{{ route('view_keuangan_billing_view') }}" <a href="{{ route('view_keuangan_billing_view') }}" class="">
class="">
<span class="icon ion-eye text-danger fz-16"></span> <span class="icon ion-eye text-danger fz-16"></span>
</a> </a>
</td> </td>
@ -134,7 +133,7 @@
file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}", file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
storage_lara: "{{ asset('storage') }}/", storage_lara: "{{ asset('storage') }}/",
periodeStartDate: '', // unix timestamps periodeStartDate: '', // unix timestamps
periodeEndDate: '', // unix timestamps periodeEndDate: '', // unix timestamps
stts_order: { stts_order: {
wait: "{{ App\Models\Orders::STTS_WAIT }}", wait: "{{ App\Models\Orders::STTS_WAIT }}",
confirm: "{{ App\Models\Orders::STTS_CONFIRM }}", confirm: "{{ App\Models\Orders::STTS_CONFIRM }}",
@ -166,53 +165,73 @@
}; };
const Filter = { const Filter = {
activate: function() { activate: function() {
const startDate = moment().startOf('month'); const startDate = moment().startOf('month');
const endDate = moment().endOf('month'); const endDate = moment().endOf('month');
$('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change');
$('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change');
State.periodeStartDate = startDate.unix(); State.periodeStartDate = startDate.unix();
State.periodeEndDate = endDate.unix(); State.periodeEndDate = endDate.unix();
Filter.evPeriodeDate(); Filter.evPeriodeDate();
}, },
evPeriodeDate: function() { evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) { $('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
$('#filter-endDate').on('change', function(e) { $('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
}, },
calcPeriodeDate: function(startDate, endDate) { calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') { if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid'); Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false }; return {
} isValid: false
if (endDate.format('YYYY-MM-DD') === 'Invalid date') { };
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid'); }
return { isValid: false }; if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
} Helper.toast('Warning', 'just now', 'End date of the period is not valid');
const duration = moment.duration(endDate.diff(startDate)); return {
const diffDays = duration.days(); isValid: false
if (diffDays > 30) { };
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan'); }
return { isValid: false }; const duration = moment.duration(endDate.diff(startDate));
} const diffDays = duration.days();
if (diffDays < 0) { if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid'); Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false }; return {
} isValid: false
return { isValid: true, data: { startDate, endDate } }; };
}, }
} if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return {
isValid: false
};
}
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}
const DTable = { const DTable = {
activate: function() { activate: function() {

View File

@ -19,7 +19,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-4 col-lg-3"> <div class="col-sm-12 col-md-4 col-lg-3">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<h6 class="mb-3">Uang Masuk</h6> <h6 class="mb-3">Uang Masuk</h6>
@ -118,7 +118,7 @@
file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}", file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
storage_lara: "{{ asset('storage') }}/", storage_lara: "{{ asset('storage') }}/",
periodeStartDate: '', // unix timestamps periodeStartDate: '', // unix timestamps
periodeEndDate: '', // unix timestamps periodeEndDate: '', // unix timestamps
stts_order: { stts_order: {
wait: "{{ App\Models\Orders::STTS_WAIT }}", wait: "{{ App\Models\Orders::STTS_WAIT }}",
confirm: "{{ App\Models\Orders::STTS_CONFIRM }}", confirm: "{{ App\Models\Orders::STTS_CONFIRM }}",
@ -176,59 +176,79 @@
}; };
const Filter = { const Filter = {
activate: function() { activate: function() {
const startDate = moment().startOf('month'); const startDate = moment().startOf('month');
const endDate = moment().endOf('month'); const endDate = moment().endOf('month');
$('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change');
$('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change');
State.periodeStartDate = startDate.unix(); State.periodeStartDate = startDate.unix();
State.periodeEndDate = endDate.unix(); State.periodeEndDate = endDate.unix();
Filter.evPeriodeDate(); Filter.evPeriodeDate();
}, },
evPeriodeDate: function() { evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) { $('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
$('#filter-endDate').on('change', function(e) { $('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
}, },
calcPeriodeDate: function(startDate, endDate) { calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') { if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid'); Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false }; return {
} isValid: false
if (endDate.format('YYYY-MM-DD') === 'Invalid date') { };
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid'); }
return { isValid: false }; if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
} Helper.toast('Warning', 'just now', 'End date of the period is not valid');
const duration = moment.duration(endDate.diff(startDate)); return {
const diffDays = duration.days(); isValid: false
if (diffDays > 30) { };
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan'); }
return { isValid: false }; const duration = moment.duration(endDate.diff(startDate));
} const diffDays = duration.days();
if (diffDays < 0) { if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid'); Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false }; return {
} isValid: false
return { isValid: true, data: { startDate, endDate } }; };
}, }
} if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return {
isValid: false
};
}
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}
const DTable = { const DTable = {
table: null, table: null,
activate: function() { activate: function() {
DTable.reload(); DTable.reload();
DTable.eventChildRow(); DTable.eventChildRow();
}, },
reload: function() { reload: function() {
// $('#tLedgerBl').DataTable(); // $('#tLedgerBl').DataTable();
@ -277,19 +297,19 @@
// searchable: true, // searchable: true,
// render: function(data, type, row, meta) { // render: function(data, type, row, meta) {
// let action = ` // let action = `
// <a href="${State.url_view_detail}?code=${row.ord_code}" class=""> // <a href="${State.url_view_detail}?code=${row.ord_code}" class="">
// <span class="icon ion-eye text-danger fz-16"></span> // <span class="icon ion-eye text-danger fz-16"></span>
// </a> // </a>
// `; // `;
// return action; // return action;
// } // }
// }, // },
{ {
"className": 'dt-control', "className": 'dt-control',
"orderable": false, "orderable": false,
"data": null, "data": null,
"defaultContent": '', "defaultContent": '',
}, },
{ {
data: 'ord_code', data: 'ord_code',
className: 'text-start text-nowrap', className: 'text-start text-nowrap',
@ -339,7 +359,7 @@
searchable: true, searchable: true,
render: function(data, type, row, meta) { render: function(data, type, row, meta) {
return (new Intl.NumberFormat('id-ID')).format(data); return (new Intl.NumberFormat('id-ID')).format(data);
// return (new Intl.NumberFormat('id-ID')).format(row.total_in - row.total_out); // return (new Intl.NumberFormat('id-ID')).format(row.total_in - row.total_out);
}, },
}, },
], ],
@ -354,72 +374,74 @@
$('#totAllIn').text((new Intl.NumberFormat('id-ID')).format(total_in)); $('#totAllIn').text((new Intl.NumberFormat('id-ID')).format(total_in));
$('#totAllOut').text((new Intl.NumberFormat('id-ID')).format(total_out)); $('#totAllOut').text((new Intl.NumberFormat('id-ID')).format(total_out));
}, },
eventChildRow: function() { eventChildRow: function() {
$('#tLedgerBl tbody').on('click', 'td.dt-control', function () { $('#tLedgerBl tbody').on('click', 'td.dt-control', function() {
var tr = $(this).closest('tr'); var tr = $(this).closest('tr');
var row = DTable.table.row( tr ); var row = DTable.table.row(tr);
if ( row.child.isShown() ) { if (row.child.isShown()) {
// This row is already open - close it // This row is already open - close it
row.child.hide(); row.child.hide();
tr.removeClass('shown'); tr.removeClass('shown');
} } else {
else { // Open this row
// Open this row row.child(DTable.formatChildRow(row.data())).show();
row.child( DTable.formatChildRow(row.data()) ).show(); tr.addClass('shown');
tr.addClass('shown'); }
} });
} ); },
}, formatChildRow: function(d) {
formatChildRow: function(d) { // `d` is the original data object for the row
// `d` is the original data object for the row // let template = `<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">
// let template = `<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;"> let template = `<table class="table table-bordered table-hover">
let template = `<table class="table table-bordered table-hover"> <thead style="border-style:none;">
<thead style="border-style:none;"> <tr>
<tr> <th>Item</th>
<th>Item</th> <th class="text-end">Jumlah</th>
<th class="text-end">Jumlah</th> <th>Satuan</th>
<th>Satuan</th> <th class="text-center">Invoice (Rp)</th>
<th class="text-center">Invoice (Rp)</th> <th class="text-center">Pembayaran (Rp)</th>
<th class="text-center">Pembayaran (Rp)</th> <th class="text-center">Masuk (Rp)</th>
<th class="text-center">Masuk (Rp)</th> <th class="text-center">Keluar (Rp)</th>
<th class="text-center">Keluar (Rp)</th> <th class="text-center">Balance (Rp)</th>
<th class="text-center">Balance (Rp)</th> </tr>
</tr> </thead>
</thead> <tbody>`
<tbody>` for (let item of d.a_items) {
for (let item of d.a_items) { // perlu diperbaiki cara if di query, jika kalkulasi ke vendor maka is_aprv = , jika ke client is_bill_aprv = 1
// perlu diperbaiki cara if di query, jika kalkulasi ke vendor maka is_aprv = , jika ke client is_bill_aprv = 1 if (item.calc_to_vdr == State.calc_to_vdr.yes && item.is_aprv != State.is_aprv.yes) continue;
if (item.calc_to_vdr == State.calc_to_vdr.yes && item.is_aprv != State.is_aprv.yes) continue; if (item.invc_to_client == State.invc_to_client.yes && item.is_bill_aprv != State.is_aprv.yes) continue;
if (item.invc_to_client == State.invc_to_client.yes && item.is_bill_aprv != State.is_aprv.yes) continue;
let small_desc = '', amt_in = 0, amt_out = 0, amt_bl = 0; let small_desc = '',
if (item.is_bill_paid == State.is_a_item_paid.paid) { amt_in = 0,
amt_in = item.amt_in; amt_out = 0,
small_desc += `<br><small>waktu dibayarkan <span class="text-success">${moment.unix(item.paid_bill_at).format('DD MMM YYYY HH:mm:ss')}</span></small>`; amt_bl = 0;
} if (item.is_bill_paid == State.is_a_item_paid.paid) {
if (item.is_paid == State.is_a_item_paid.paid) { amt_in = item.amt_in;
amt_out = item.amt_out; small_desc += `<br><small>waktu dibayarkan <span class="text-success">${moment.unix(item.paid_bill_at).format('DD MMM YYYY HH:mm:ss')}</span></small>`;
small_desc += `<br><small>waktu keluar <span class="text-danger">${moment.unix(item.paid_at).format('DD MMM YYYY HH:mm:ss')}</span></small>`;
}
if (amt_in != 0 || amt_out != 0) {
amt_bl = item.amt_bl;
}
template += `<tr>
<td>${item.item_desc}${small_desc}</td>
<td class="text-end">${item.unit_qty}</td>
<td>${item.unit_type_name}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(item.amt_in)}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(item.amt_out)}</td>
<td class="text-end text-success">${(new Intl.NumberFormat('id-ID')).format(amt_in)}</td>
<td class="text-end text-danger">${(new Intl.NumberFormat('id-ID')).format(amt_out)}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(amt_bl)}</td>
</tr>`;
} }
template += `</tbody> if (item.is_paid == State.is_a_item_paid.paid) {
</table>`; amt_out = item.amt_out;
small_desc += `<br><small>waktu keluar <span class="text-danger">${moment.unix(item.paid_at).format('DD MMM YYYY HH:mm:ss')}</span></small>`;
}
if (amt_in != 0 || amt_out != 0) {
amt_bl = item.amt_bl;
}
template += `<tr>
<td>${item.item_desc}${small_desc}</td>
<td class="text-end">${item.unit_qty}</td>
<td>${item.unit_type_name}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(item.amt_in)}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(item.amt_out)}</td>
<td class="text-end text-success">${(new Intl.NumberFormat('id-ID')).format(amt_in)}</td>
<td class="text-end text-danger">${(new Intl.NumberFormat('id-ID')).format(amt_out)}</td>
<td class="text-end">${(new Intl.NumberFormat('id-ID')).format(amt_bl)}</td>
</tr>`;
}
template += `</tbody>
</table>`;
return template return template
}, },
}; };
Wrapper.activate(); Wrapper.activate();

View File

@ -122,8 +122,8 @@
const State = { const State = {
file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}", file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
storage_lara: "{{ asset('storage') }}/", storage_lara: "{{ asset('storage') }}/",
periodeStartDate: '', // unix timestamps periodeStartDate: '', // unix timestamps
periodeEndDate: '', // unix timestamps periodeEndDate: '', // unix timestamps
stts_order: { stts_order: {
wait: "{{ App\Models\Orders::STTS_WAIT }}", wait: "{{ App\Models\Orders::STTS_WAIT }}",
confirm: "{{ App\Models\Orders::STTS_CONFIRM }}", confirm: "{{ App\Models\Orders::STTS_CONFIRM }}",
@ -147,7 +147,7 @@
const Wrapper = { const Wrapper = {
activate: function() { activate: function() {
Filter.activate(); Filter.activate();
Wrapper.event(); Wrapper.event();
DTable.activate(); DTable.activate();
}, },
@ -180,54 +180,74 @@
}, },
}; };
const Filter = { const Filter = {
activate: function() { activate: function() {
const startDate = moment().startOf('month'); const startDate = moment().startOf('month');
const endDate = moment().endOf('month'); const endDate = moment().endOf('month');
$('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-startDate').val(startDate.format('YYYY-MM-DD')).trigger('change');
$('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change'); $('#filter-endDate').val(endDate.format('YYYY-MM-DD')).trigger('change');
State.periodeStartDate = startDate.unix(); State.periodeStartDate = startDate.unix();
State.periodeEndDate = endDate.unix(); State.periodeEndDate = endDate.unix();
Filter.evPeriodeDate(); Filter.evPeriodeDate();
}, },
evPeriodeDate: function() { evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) { $('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
$('#filter-endDate').on('change', function(e) { $('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val())) const {
if (!isValid) return false; isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix(); State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix(); State.periodeEndDate = data.endDate.unix();
DTable.reload(); DTable.reload();
}); });
}, },
calcPeriodeDate: function(startDate, endDate) { calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') { if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid'); Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false }; return {
} isValid: false
if (endDate.format('YYYY-MM-DD') === 'Invalid date') { };
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid'); }
return { isValid: false }; if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
} Helper.toast('Warning', 'just now', 'End date of the period is not valid');
const duration = moment.duration(endDate.diff(startDate)); return {
const diffDays = duration.days(); isValid: false
if (diffDays > 30) { };
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan'); }
return { isValid: false }; const duration = moment.duration(endDate.diff(startDate));
} const diffDays = duration.days();
if (diffDays < 0) { if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid'); Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false }; return {
} isValid: false
return { isValid: true, data: { startDate, endDate } }; };
}, }
} if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return {
isValid: false
};
}
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}
const DTable = { const DTable = {
activate: function() { activate: function() {