ADD NextDeliveryDate to order parameter view.
This commit is contained in:
parent
1e00304eda
commit
1e3c6fd562
@ -19,12 +19,16 @@
|
||||
use App\Models\Test;
|
||||
use App\Repositories\ProductRepository;
|
||||
use App\Repositories\SupplierRepository;
|
||||
use App\Services\DeliveryCalendarService;
|
||||
use App\Services\NextDeliveryDateCalculatorService;
|
||||
use App\Services\WorkCalendarService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\ProfitCenterService;
|
||||
use ArrayObject;
|
||||
use Barryvdh\DomPDF\Facade\Pdf as PDF;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Carbon as ICarbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\App;
|
||||
@ -512,6 +516,8 @@ private function createParameter(Request $request)
|
||||
$CustomNotificationEmailData = $Supplier->contactOrderMail->toArray();
|
||||
}
|
||||
|
||||
$profitCenterId = auth()->user()->profitCenters()->first()->id;
|
||||
|
||||
return view('modules.order.parameter')->with([
|
||||
// 'supplier'=>$ProfitCenter[''],
|
||||
'oneAddress' => $oneAddress,
|
||||
@ -519,7 +525,74 @@ private function createParameter(Request $request)
|
||||
'CustomNotificationEmailData' => $CustomNotificationEmailData,
|
||||
'supplierNote' => $supplierNote,
|
||||
'profitCenterAddress' => $ProfitCenterAddress,
|
||||
'supplierId' => $Order->supplier_id,
|
||||
'profitCenterId' => $profitCenterId,
|
||||
'deliveryCalendarDataUrl' => route('order.deliveryCalendarData'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getDeliveryCalendarData(
|
||||
Request $request,
|
||||
DeliveryCalendarService $deliveryCalendarService,
|
||||
NextDeliveryDateCalculatorService $nextDeliveryCalculator,
|
||||
WorkCalendarService $workCalendarService,
|
||||
): JsonResponse {
|
||||
$supplierId = (int) $request->get('supplierId');
|
||||
$profitCenterId = (int) $request->get('profitCenterId');
|
||||
$orderDateTime = Carbon::parse($request->get('orderDateTime', now()));
|
||||
|
||||
$supplier = Supplier::find($supplierId);
|
||||
$pc = ProfitCenter::find($profitCenterId);
|
||||
|
||||
if (! $supplier || ! $pc) {
|
||||
return response()->json(['error' => 'Érvénytelen szállító vagy profitcenter'], 422);
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Support\Collection $calendarEntries */
|
||||
$calendarEntries = $workCalendarService->getCalendarEntries(
|
||||
ICarbon::today(),
|
||||
ICarbon::today()->addDays(90),
|
||||
);
|
||||
|
||||
$holidays = $calendarEntries
|
||||
->where('type', \App\Enums\WorkDayType::Holiday)
|
||||
->map(fn ($e) => ['date' => ICarbon::parse($e->date)->toDateString(), 'description' => $e->description])
|
||||
->values();
|
||||
|
||||
$workingDays = $calendarEntries
|
||||
->where('type', \App\Enums\WorkDayType::WorkingDay)
|
||||
->map(fn ($e) => ['date' => ICarbon::parse($e->date)->toDateString(), 'description' => $e->description])
|
||||
->values();
|
||||
|
||||
if (! $supplier->hasDeliveryConstraint) {
|
||||
return response()->json([
|
||||
'hasDeliveryConstraint' => false,
|
||||
'availableDates' => [],
|
||||
'nextDeliveryDate' => null,
|
||||
'orderCutOffTime' => null,
|
||||
'deliveryLeadTime' => null,
|
||||
'holidays' => $holidays,
|
||||
'workingDays' => $workingDays,
|
||||
]);
|
||||
}
|
||||
|
||||
$availableDates = $deliveryCalendarService->getAvailableDeliveryDates(
|
||||
$pc,
|
||||
$supplier,
|
||||
ICarbon::today(),
|
||||
ICarbon::today()->addDays(90),
|
||||
)->map(fn (Carbon $d) => $d->format('Y-m-d'))->values();
|
||||
|
||||
$nextDeliveryDate = $nextDeliveryCalculator->calculate($supplierId, $profitCenterId, ICarbon::parse($orderDateTime));
|
||||
|
||||
return response()->json([
|
||||
'hasDeliveryConstraint' => true,
|
||||
'availableDates' => $availableDates,
|
||||
'nextDeliveryDate' => $nextDeliveryDate?->format('Y-m-d'),
|
||||
'orderCutOffTime' => $supplier->orderCutOffTime,
|
||||
'deliveryLeadTime' => $supplier->deliveryLeadTime,
|
||||
'holidays' => $holidays,
|
||||
'workingDays' => $workingDays,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -3,8 +3,8 @@
|
||||
"/js/app.js.map": "/js/app.js.map?id=33d744311c4b662e0040524bcff09d31",
|
||||
"/js/admin.js": "/js/admin.js?id=e7eabc252df1afdcd697202faaf7f371",
|
||||
"/js/admin.js.map": "/js/admin.js.map?id=24864657c7a799f77019f6c1c04bbc79",
|
||||
"/js/module.js": "/js/module.js?id=216a701b8787ea07f66b81683d15976f",
|
||||
"/js/module.js.map": "/js/module.js.map?id=ce0b070e61879f5a38796d2d3dbd42c4",
|
||||
"/js/module.js": "/js/module.js?id=a888d66c1487c4f9e56c8fa60de29ec6",
|
||||
"/js/module.js.map": "/js/module.js.map?id=152ded9708cbf967ac8cda9613614a91",
|
||||
"/js/components.js": "/js/components.js?id=aac1b5221c918d1afb98a34e79620cde",
|
||||
"/js/components.js.map": "/js/components.js.map?id=03868ef122820440c621f29c51b3c467",
|
||||
"/css/app.css": "/css/app.css?id=5d0a6568441f28a5d832021a0501139b",
|
||||
|
||||
@ -714,17 +714,105 @@ window.OrderModule = function () {
|
||||
});
|
||||
|
||||
} else {
|
||||
$(CSSSelectorForm + ' .datePicker').datepicker({
|
||||
// Szállítási korlátozás adatok betöltése (csak ha hasDeliveryConstraint = true)
|
||||
let availableDates = [];
|
||||
let nextDeliveryDate = null;
|
||||
let hasDeliveryConstraint = false;
|
||||
let holidays = [];
|
||||
let workingDays = [];
|
||||
let datepickerInput = $(CSSSelectorForm + ' .datePicker');
|
||||
let calendarUrl = datepickerInput.data('delivery-calendar-url');
|
||||
let supplierId = datepickerInput.data('supplier-id');
|
||||
let profitCenterId = datepickerInput.data('profit-center-id');
|
||||
|
||||
if (calendarUrl && supplierId && profitCenterId) {
|
||||
$.ajax({
|
||||
url: calendarUrl,
|
||||
data: {
|
||||
supplierId: supplierId,
|
||||
profitCenterId: profitCenterId,
|
||||
orderDateTime: new Date().toISOString(),
|
||||
},
|
||||
async: false,
|
||||
success: function (data) {
|
||||
hasDeliveryConstraint = data.hasDeliveryConstraint || false;
|
||||
// Ünnepnapok és áthelyezett munkanapok – mindig betöltjük
|
||||
holidays = (data.holidays || []).map(function(h) { return { date: h.date, description: h.description }; });
|
||||
workingDays = (data.workingDays || []).map(function(w) { return { date: w.date, description: w.description }; });
|
||||
|
||||
if (hasDeliveryConstraint) {
|
||||
availableDates = data.availableDates || [];
|
||||
nextDeliveryDate = data.nextDeliveryDate || null;
|
||||
}
|
||||
// Ha nincs szállítási korlátozás, az availableDates és nextDeliveryDate
|
||||
// üres marad – a datepicker az eredeti módon viselkedik
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (hasDeliveryConstraint && nextDeliveryDate) {
|
||||
// Következő szállítási nap beállítása alapértelmezettként
|
||||
root.setDeliveryDate(nextDeliveryDate);
|
||||
$(CSSSelectorForm + ' .selectedDateText').text(nextDeliveryDate);
|
||||
$(CSSSelectorForm + ' input[name="deliveryDate"]').val(nextDeliveryDate);
|
||||
$('.deliveryDatePlace').text(nextDeliveryDate.replaceAll('-', '.') + '.');
|
||||
}
|
||||
|
||||
// Szín jelmagyarázat megjelenítése csak szállítási korlátozás esetén
|
||||
if (hasDeliveryConstraint) {
|
||||
$('#deliveryDateLegend').show();
|
||||
}
|
||||
|
||||
let datepickerOpts = {
|
||||
dateFormat: 'yy-mm-dd',
|
||||
minDate: new Date(),
|
||||
minDate: (hasDeliveryConstraint && nextDeliveryDate) ? new Date(nextDeliveryDate) : new Date(),
|
||||
onSelect: function (dateText) {
|
||||
$(CSSSelectorForm + ' .selectedDateText').text(dateText);
|
||||
$('.deliveryDatePlace').text(dateText.replaceAll('-', '.') + '.');
|
||||
$(CSSSelectorForm + ' input[name="deliveryDate"]').val(dateText);
|
||||
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// beforeShowDay: mindig aktív ha van munkanaptár adat vagy hasDeliveryConstraint
|
||||
datepickerOpts.beforeShowDay = function (date) {
|
||||
let dateStr = $.datepicker.formatDate('yy-mm-dd', date);
|
||||
|
||||
let holidayEntry = holidays.find(function(h) { return h.date === dateStr; });
|
||||
let workingDayEntry = workingDays.find(function(w) { return w.date === dateStr; });
|
||||
|
||||
let isDelivery = hasDeliveryConstraint && availableDates.includes(dateStr);
|
||||
|
||||
let cssClasses = [];
|
||||
let tooltip = '';
|
||||
let selectable = true;
|
||||
|
||||
if (holidayEntry) {
|
||||
cssClasses.push('work-calendar-holiday');
|
||||
tooltip = 'Ünnepnap' + (holidayEntry.description ? ': ' + holidayEntry.description : '');
|
||||
} else if (workingDayEntry) {
|
||||
cssClasses.push('work-calendar-working-day');
|
||||
tooltip = 'Áthelyezett munkanap' + (workingDayEntry.description ? ': ' + workingDayEntry.description : '');
|
||||
}
|
||||
|
||||
if (hasDeliveryConstraint) {
|
||||
if (isDelivery) {
|
||||
cssClasses.push('delivery-day-available');
|
||||
if (!tooltip) tooltip = 'Szállítási nap';
|
||||
} else {
|
||||
cssClasses.push('delivery-day-unavailable');
|
||||
if (!tooltip) tooltip = 'Nem szállítási nap';
|
||||
selectable = false;
|
||||
}
|
||||
}
|
||||
// Ha ünnepnap és hasDeliveryConstraint nincs bekapcsolva, az ünnepnap is letiltandó
|
||||
if (holidayEntry && !hasDeliveryConstraint) {
|
||||
selectable = false;
|
||||
}
|
||||
|
||||
return [selectable, cssClasses.join(' '), tooltip];
|
||||
};
|
||||
|
||||
$(CSSSelectorForm + ' .datePicker').datepicker(datepickerOpts);
|
||||
}
|
||||
}
|
||||
this.callChangeOrderType=function(){
|
||||
|
||||
@ -35,10 +35,32 @@
|
||||
<div class="form-group row">
|
||||
<label for="remark" class="col-sm-2 col-form-label">Szállítási dátum</label>
|
||||
<div class="col-sm-10">
|
||||
{{-- Szín jelmagyarázat – csak szállítási korlátozás esetén jelenik meg (JS tölti be) --}}
|
||||
<div class="delivery-legend" id="deliveryDateLegend" style="display:none; margin-bottom:8px;">
|
||||
<div class="delivery-legend-item">
|
||||
<span class="delivery-legend-color" style="background-color:#d4edda; border-color:#155724;"></span>
|
||||
<span>Szállítási nap</span>
|
||||
</div>
|
||||
<div class="delivery-legend-item">
|
||||
<span class="delivery-legend-color" style="background-color:#e9ecef; border-color:#999;"></span>
|
||||
<span>Nem szállítási nap</span>
|
||||
</div>
|
||||
<div class="delivery-legend-item">
|
||||
<span class="delivery-legend-color" style="background-color:#f8d7da; border-color:#721c24;"></span>
|
||||
<span>Ünnepnap</span>
|
||||
</div>
|
||||
<div class="delivery-legend-item">
|
||||
<span class="delivery-legend-color" style="background-color:#fff3cd; border-color:#856404;"></span>
|
||||
<span>Áthelyezett munkanap</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group date">
|
||||
<input type="hidden" class="form-control datePicker"
|
||||
value="{{\Illuminate\Support\Carbon::today()->next('Day')->format('Y-m-d')}}"
|
||||
name="deliveryDate" placeholder="Kattintson a dátum kiválasztásához"
|
||||
data-supplier-id="{{ $supplierId ?? '' }}"
|
||||
data-profit-center-id="{{ $profitCenterId ?? '' }}"
|
||||
data-delivery-calendar-url="{{ $deliveryCalendarDataUrl ?? '' }}"
|
||||
required>
|
||||
<span class="input-group-addon datePickerClick">
|
||||
{{--<i class="glyphicon glyphicon-th"></i>--}}
|
||||
@ -104,6 +126,77 @@
|
||||
@endif
|
||||
|
||||
<style>
|
||||
/* Szállítási nap – zöld kiemelés */
|
||||
.ui-datepicker .delivery-day-available a {
|
||||
background-color: #d4edda !important;
|
||||
color: #155724 !important;
|
||||
font-weight: bold;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* Nem szállítási nap – szürke, áthúzott */
|
||||
.ui-datepicker .delivery-day-unavailable {
|
||||
opacity: 0.4;
|
||||
}
|
||||
.ui-datepicker .delivery-day-unavailable a {
|
||||
text-decoration: line-through;
|
||||
cursor: not-allowed !important;
|
||||
color: #999 !important;
|
||||
}
|
||||
|
||||
/* Ünnepnap – piros háttér (td-re is, mert disabled napon nincs <a>) */
|
||||
.ui-datepicker td.work-calendar-holiday,
|
||||
.ui-datepicker td.work-calendar-holiday a,
|
||||
.ui-datepicker td.work-calendar-holiday span {
|
||||
background-color: #f8d7da !important;
|
||||
color: #721c24 !important;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* Áthelyezett munkanap – sárga/narancs háttér */
|
||||
.ui-datepicker td.work-calendar-working-day,
|
||||
.ui-datepicker td.work-calendar-working-day a,
|
||||
.ui-datepicker td.work-calendar-working-day span {
|
||||
background-color: #fff3cd !important;
|
||||
color: #856404 !important;
|
||||
font-style: italic;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* Kombinált: szállítási nap + ünnepnap */
|
||||
.ui-datepicker td.work-calendar-holiday.delivery-day-available a {
|
||||
background-color: #f8d7da !important;
|
||||
border: 2px solid #155724 !important;
|
||||
}
|
||||
|
||||
/* Ünnepnap + nem szállítási nap → áthúzott */
|
||||
.ui-datepicker td.work-calendar-holiday.delivery-day-unavailable a,
|
||||
.ui-datepicker td.work-calendar-holiday.delivery-day-unavailable span {
|
||||
text-decoration: line-through;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* Szín jelmagyarázat */
|
||||
.delivery-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.delivery-legend-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.delivery-legend-color {
|
||||
display: inline-block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.orderParameterForm .selectedDateText{
|
||||
vertical-align: super;
|
||||
padding: 5px;
|
||||
|
||||
@ -90,6 +90,7 @@
|
||||
// csak bemutatora fixalva
|
||||
Route::get('getDataTableContent', [OrderController::class, 'getDataTableContent'])->name('getDataTableContent');
|
||||
Route::get('/{id}/checkReadyToSend', [OrderController::class, 'checkReadyToSend'])->name('checkReadyToSend');
|
||||
Route::get('delivery-calendar-data', [OrderController::class, 'getDeliveryCalendarData'])->name('deliveryCalendarData');
|
||||
Route::resource('/', OrderController::class)->parameters(['' => 'id']);
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user