Quantity availability check implemented for default booking
This commit is contained in:
parent
91064cd0bc
commit
53da36dd2c
|
|
@ -17,7 +17,6 @@ class CreateBookingProductAppointmentSlotsTable extends Migration
|
|||
$table->increments('id');
|
||||
$table->integer('duration')->nullable();
|
||||
$table->integer('break_time')->nullable();
|
||||
$table->boolean('slot_has_quantity')->nullable();
|
||||
$table->boolean('same_slot_all_days')->nullable();
|
||||
$table->json('slots')->nullable();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ class CreateBookingProductRentalSlotsTable extends Migration
|
|||
$table->string('renting_type');
|
||||
$table->decimal('daily_price', 12, 4)->default(0)->nullable();
|
||||
$table->decimal('hourly_price', 12, 4)->default(0)->nullable();
|
||||
$table->boolean('slot_has_quantity')->nullable();
|
||||
$table->boolean('same_slot_all_days')->nullable();
|
||||
$table->json('slots')->nullable();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Webkul\BookingProduct\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
use Webkul\BookingProduct\Repositories\BookingProductRepository;
|
||||
use Webkul\BookingProduct\Repositories\BookingProductDefaultSlotRepository;
|
||||
|
|
@ -180,9 +181,9 @@ class Booking
|
|||
|
||||
$currentTime = Carbon::now();
|
||||
|
||||
$availableFrom = Carbon::createFromTimeString($bookingProduct->available_from . " 00:00:01");
|
||||
$availableFrom = Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . " 00:00:01");
|
||||
|
||||
$availableTo = Carbon::createFromTimeString($bookingProduct->available_to . " 23:59:59");
|
||||
$availableTo = Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . " 23:59:59");
|
||||
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$date = clone $currentTime;
|
||||
|
|
@ -259,11 +260,11 @@ class Booking
|
|||
$currentTime = Carbon::now();
|
||||
|
||||
$availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from . " 00:00:00")
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . " 00:00:00")
|
||||
: Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00');
|
||||
|
||||
$availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
|
||||
: Carbon::createFromTimeString('2080-01-01 00:00:00');
|
||||
|
||||
$timeDurations = $bookingProductSlot->same_slot_all_days
|
||||
|
|
@ -331,6 +332,12 @@ class Booking
|
|||
*/
|
||||
public function isItemHaveQuantity($cartItem)
|
||||
{
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartItem->product_id);
|
||||
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartItem) < $cartItem->quantity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -340,9 +347,36 @@ class Booking
|
|||
*/
|
||||
public function isSlotAvailable($cartProducts)
|
||||
{
|
||||
foreach ($cartProducts as $cartProduct) {
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartProduct['product_id']);
|
||||
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartProduct) < $cartProduct['quantity']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return integer
|
||||
*/
|
||||
public function getBookedQuantity($data)
|
||||
{
|
||||
$timestamps = explode('-', $data['additional']['booking']['slot']);
|
||||
|
||||
$result = $this->bookingRepository->getModel()
|
||||
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
|
||||
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
|
||||
->where('bookings.product_id', $data['product_id'])
|
||||
->where('bookings.from', $timestamps[0])
|
||||
->where('bookings.to', $timestamps[1])
|
||||
->first();
|
||||
|
||||
return $result->total_qty_booked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns additional cart item information
|
||||
*
|
||||
|
|
@ -369,11 +403,11 @@ class Booking
|
|||
], [
|
||||
'attribute_name' => 'Rent From',
|
||||
'option_id' => 0,
|
||||
'option_label' => Carbon::createFromTimeString($bookingProduct->available_from)->format('d F, Y'),
|
||||
'option_label' => Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d'))->format('d F, Y'),
|
||||
], [
|
||||
'attribute_name' => 'Rent Till',
|
||||
'option_id' => 0,
|
||||
'option_label' => Carbon::createFromTimeString($bookingProduct->available_to)->format('d F, Y'),
|
||||
'option_label' => Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d'))->format('d F, Y'),
|
||||
]];
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Webkul\BookingProduct\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
|
|
@ -38,11 +37,11 @@ class DefaultSlot extends Booking
|
|||
$currentTime = Carbon::now();
|
||||
|
||||
$availableFrom = ! $bookingProduct->available_from && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . ' 00:00:00')
|
||||
: clone $currentTime;
|
||||
|
||||
$availableTo = ! $bookingProduct->available_from && $bookingProduct->available_to
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
|
||||
: Carbon::createFromTimeString('2080-01-01 00:00:00');
|
||||
|
||||
if ($requestedDate < $currentTime
|
||||
|
|
@ -102,11 +101,11 @@ class DefaultSlot extends Booking
|
|||
$currentTime = Carbon::now();
|
||||
|
||||
$availableFrom = ! $bookingProduct->available_from && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . ' 00:00:00')
|
||||
: clone $currentTime;
|
||||
|
||||
$availableTo = ! $bookingProduct->available_from && $bookingProduct->available_to
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
|
||||
: Carbon::createFromTimeString('2080-01-01 00:00:00');
|
||||
|
||||
$timeDuration = $bookingProductSlot->slots[$requestedDate->format('w')] ?? [];
|
||||
|
|
@ -167,55 +166,4 @@ class DefaultSlot extends Booking
|
|||
|
||||
return $slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CartItem $cartItem
|
||||
* @return bool
|
||||
*/
|
||||
public function isItemHaveQuantity($cartItem)
|
||||
{
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartItem->product_id);
|
||||
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartItem) < $cartItem->quantity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cartProducts
|
||||
* @return bool
|
||||
*/
|
||||
public function isSlotAvailable($cartProducts)
|
||||
{
|
||||
foreach ($cartProducts as $cartProduct) {
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartProduct['product_id']);
|
||||
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartProduct) < $cartProduct['quantity']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return integer
|
||||
*/
|
||||
public function getBookedQuantity($data)
|
||||
{
|
||||
$timestamps = explode('-', $data['additional']['booking']['slot']);
|
||||
|
||||
$result = $this->bookingRepository->getModel()
|
||||
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
|
||||
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
|
||||
->where('bookings.product_id', $data['product_id'])
|
||||
->where('bookings.from', $timestamps[0])
|
||||
->where('bookings.to', $timestamps[1])
|
||||
->first();
|
||||
|
||||
return $result->total_qty_booked;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,9 +20,9 @@ class EventTicket extends Booking
|
|||
*/
|
||||
public function getEventDate($bookingProduct)
|
||||
{
|
||||
$from = Carbon::createFromTimeString($bookingProduct->available_from)->format('d F, Y h:i A');
|
||||
$from = Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d'))->format('d F, Y h:i A');
|
||||
|
||||
$to = Carbon::createFromTimeString($bookingProduct->available_to)->format('d F, Y h:i A');
|
||||
$to = Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d'))->format('d F, Y h:i A');
|
||||
|
||||
return $from . ' - ' . $to;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ class RentalSlot extends Booking
|
|||
$currentTime = Carbon::now();
|
||||
|
||||
$availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . ' 00:00:00')
|
||||
: Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00');
|
||||
|
||||
$availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59')
|
||||
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
|
||||
: Carbon::createFromTimeString('2080-01-01 00:00:00');
|
||||
|
||||
$timeDurations = $bookingProductSlot->same_slot_all_days
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ class BookingProduct extends Model implements BookingProductContract
|
|||
|
||||
protected $with = ['default_slot', 'appointment_slot', 'event_tickets', 'rental_slot', 'table_slot'];
|
||||
|
||||
protected $casts = [
|
||||
'available_from' => 'datetime',
|
||||
'available_to' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Product Default Booking that belong to the product booking.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ class BookingProductAppointmentSlot extends Model implements BookingProductAppoi
|
|||
|
||||
protected $casts = ['slots' => 'array'];
|
||||
|
||||
protected $fillable = ['duration', 'break_time', 'available_every_week', 'slot_has_quantity', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
protected $fillable = ['duration', 'break_time', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
}
|
||||
|
|
@ -11,5 +11,5 @@ class BookingProductRentalSlot extends Model implements BookingProductRentalSlot
|
|||
|
||||
protected $casts = ['slots' => 'array'];
|
||||
|
||||
protected $fillable = ['renting_type', 'daily_price', 'hourly_price', 'available_every_week', 'slot_has_quantity', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
protected $fillable = ['renting_type', 'daily_price', 'hourly_price', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
}
|
||||
|
|
@ -11,5 +11,5 @@ class BookingProductTableSlot extends Model implements BookingProductTableSlotCo
|
|||
|
||||
protected $casts = ['slots' => 'array'];
|
||||
|
||||
protected $fillable = ['price_type', 'guest_limit', 'guest_capacity', 'duration', 'break_time', 'prevent_scheduling_before', 'available_every_week', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
protected $fillable = ['price_type', 'guest_limit', 'guest_capacity', 'duration', 'break_time', 'prevent_scheduling_before', 'same_slot_all_days', 'slots', 'booking_product_id'];
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
<input type="text" name="booking[location]" v-model="booking.location" class="control"/>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('booking[qty]') ? 'has-error' : '']" v-if="booking.type == 'default' || booking.type == 'rental'">
|
||||
<div class="control-group" :class="[errors.has('booking[qty]') ? 'has-error' : '']" v-if="booking.type == 'default' || booking.type == 'appointment' || booking.type == 'rental'">
|
||||
<label class="required">{{ __('bookingproduct::app.admin.catalog.products.qty') }}</label>
|
||||
|
||||
<input type="text" v-validate="'required|numeric|min:0'" name="booking[qty]" v-model="booking.qty" class="control" data-vv-as=""{{ __('bookingproduct::app.admin.catalog.products.qty') }}""/>
|
||||
|
|
|
|||
|
|
@ -25,17 +25,6 @@
|
|||
<span class="control-error" v-if="errors.has('booking[break_time]')">@{{ errors.first('booking[break_time]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('booking[slot_has_quantity]') ? 'has-error' : '']">
|
||||
<label class="required">{{ __('bookingproduct::app.admin.catalog.products.slot-has-quantity') }}</label>
|
||||
|
||||
<select v-validate="'required'" name="booking[slot_has_quantity]" v-model="appointment_booking.slot_has_quantity" class="control" data-vv-as=""{{ __('bookingproduct::app.admin.catalog.products.slot-has-quantity') }}"">
|
||||
<option value="1">{{ __('bookingproduct::app.admin.catalog.products.yes') }}</option>
|
||||
<option value="0">{{ __('bookingproduct::app.admin.catalog.products.no') }}</option>
|
||||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('booking[slot_has_quantity]')">@{{ errors.first('booking[slot_has_quantity]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('booking[same_slot_all_days]') ? 'has-error' : '']">
|
||||
<label class="required">{{ __('bookingproduct::app.admin.catalog.products.same-slot-all-days') }}</label>
|
||||
|
||||
|
|
@ -56,8 +45,7 @@
|
|||
|
||||
<slot-list
|
||||
booking-type="appointment_slot"
|
||||
:same-slot-all-days="appointment_booking.same_slot_all_days"
|
||||
:slot-has-quantity="appointment_booking.slot_has_quantity">
|
||||
:same-slot-all-days="appointment_booking.same_slot_all_days">
|
||||
</slot-list>
|
||||
|
||||
</div>
|
||||
|
|
@ -80,8 +68,6 @@
|
|||
break_time: 15,
|
||||
|
||||
same_slot_all_days: 1,
|
||||
|
||||
slot_has_quantity: 1,
|
||||
|
||||
slots: []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,17 +42,6 @@
|
|||
</div>
|
||||
|
||||
<div v-if="rental_booking.renting_type == 'hourly' || rental_booking.renting_type == 'daily_hourly'">
|
||||
<div class="control-group" :class="[errors.has('booking[slot_has_quantity]') ? 'has-error' : '']">
|
||||
<label class="required">{{ __('bookingproduct::app.admin.catalog.products.slot-has-quantity') }}</label>
|
||||
|
||||
<select v-validate="'required'" name="booking[slot_has_quantity]" v-model="rental_booking.slot_has_quantity" class="control" data-vv-as=""{{ __('bookingproduct::app.admin.catalog.products.slot-has-quantity') }}"">
|
||||
<option value="1">{{ __('bookingproduct::app.admin.catalog.products.yes') }}</option>
|
||||
<option value="0">{{ __('bookingproduct::app.admin.catalog.products.no') }}</option>
|
||||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('booking[slot_has_quantity]')">@{{ errors.first('booking[slot_has_quantity]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('booking[same_slot_all_days]') ? 'has-error' : '']">
|
||||
<label class="required">{{ __('bookingproduct::app.admin.catalog.products.same-slot-all-days') }}</label>
|
||||
|
||||
|
|
@ -73,8 +62,7 @@
|
|||
|
||||
<slot-list
|
||||
booking-type="rental_slot"
|
||||
:same-slot-all-days="rental_booking.same_slot_all_days"
|
||||
:slot-has-quantity="rental_booking.slot_has_quantity">
|
||||
:same-slot-all-days="rental_booking.same_slot_all_days">
|
||||
</slot-list>
|
||||
|
||||
</div>
|
||||
|
|
@ -100,8 +88,6 @@
|
|||
hourly_price: '',
|
||||
|
||||
same_slot_all_days: 1,
|
||||
|
||||
slot_has_quantity: 1,
|
||||
|
||||
slots: []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<tr>
|
||||
<th>{{ __('bookingproduct::app.admin.catalog.products.from') }}</th>
|
||||
<th>{{ __('bookingproduct::app.admin.catalog.products.to') }}</th>
|
||||
<th v-if="parseInt(slotHasQuantity)">{{ __('bookingproduct::app.admin.catalog.products.qty') }}</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -17,7 +16,6 @@
|
|||
:key="index"
|
||||
:slot-item="slot"
|
||||
:control-name="'booking[slots][' + index + ']'"
|
||||
:slot-has-quantity="slotHasQuantity"
|
||||
@onRemoveSlot="removeSlot($event)">
|
||||
</slot-item>
|
||||
</tbody>
|
||||
|
|
@ -46,7 +44,6 @@
|
|||
<tr>
|
||||
<th>{{ __('bookingproduct::app.admin.catalog.products.from') }}</th>
|
||||
<th>{{ __('bookingproduct::app.admin.catalog.products.to') }}</th>
|
||||
<th v-if="parseInt(slotHasQuantity)">{{ __('bookingproduct::app.admin.catalog.products.qty') }}</th>
|
||||
<th class="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -57,7 +54,6 @@
|
|||
:key="dayIndex + '_' + slotIndex"
|
||||
:slot-item="slot"
|
||||
:control-name="'booking[slots][' + dayIndex + '][' + slotIndex + ']'"
|
||||
:slot-has-quantity="slotHasQuantity"
|
||||
@onRemoveSlot="removeSlot($event, dayIndex)"
|
||||
></slot-item>
|
||||
</tbody>
|
||||
|
|
@ -98,16 +94,6 @@
|
|||
</div>
|
||||
</td>
|
||||
|
||||
<td v-if="parseInt(slotHasQuantity)">
|
||||
<div class="control-group" :class="[errors.has(controlName + '[qty]') ? 'has-error' : '']">
|
||||
<input type="text" v-validate="'required|min_value:0'" :name="controlName + '[qty]'" v-model="slotItem.qty" class="control" data-vv-as=""{{ __('bookingproduct::app.admin.catalog.products.qty') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has(controlName + '[qty]')">
|
||||
@{{ errors.first(controlName + '[qty]') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<i class="icon remove-icon" @click="removeSlot()"></i>
|
||||
</td>
|
||||
|
|
@ -119,7 +105,7 @@
|
|||
|
||||
template: '#slot-list-template',
|
||||
|
||||
props: ['bookingType', 'sameSlotAllDays', 'slotHasQuantity'],
|
||||
props: ['bookingType', 'sameSlotAllDays'],
|
||||
|
||||
inject: ['$validator'],
|
||||
|
||||
|
|
@ -162,8 +148,7 @@
|
|||
|
||||
var slot = {
|
||||
'from': '',
|
||||
'to': '',
|
||||
'qty': 0
|
||||
'to': ''
|
||||
};
|
||||
|
||||
this.slots['different_for_week'][dayIndex].push(slot)
|
||||
|
|
@ -172,8 +157,7 @@
|
|||
} else {
|
||||
var slot = {
|
||||
'from': '',
|
||||
'to': '',
|
||||
'qty': 0
|
||||
'to': ''
|
||||
};
|
||||
|
||||
this.slots['same_for_week'].push(slot);
|
||||
|
|
@ -198,7 +182,7 @@
|
|||
|
||||
template: '#slot-item-template',
|
||||
|
||||
props: ['slotItem', 'controlName', 'slotHasQuantity'],
|
||||
props: ['slotItem', 'controlName'],
|
||||
|
||||
inject: ['$validator'],
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue