diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php index d3a8db3ba..51ee81434 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php @@ -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(); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php index b9e4b4be1..38d383770 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php @@ -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(); diff --git a/packages/Webkul/BookingProduct/src/Helpers/Booking.php b/packages/Webkul/BookingProduct/src/Helpers/Booking.php index 58fe2933b..781ece211 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/Booking.php +++ b/packages/Webkul/BookingProduct/src/Helpers/Booking.php @@ -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; diff --git a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php index 446dfb549..3dba01805 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php @@ -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; - } } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php b/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php index ae544eced..e6a073b44 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php +++ b/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php @@ -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; } diff --git a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php index 6fd8a31cc..dc88ffc34 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php @@ -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 diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProduct.php b/packages/Webkul/BookingProduct/src/Models/BookingProduct.php index 514b0f150..c5bb16a8e 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProduct.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProduct.php @@ -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. */ diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductAppointmentSlot.php b/packages/Webkul/BookingProduct/src/Models/BookingProductAppointmentSlot.php index 1766d3bbf..d1e2efcce 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProductAppointmentSlot.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProductAppointmentSlot.php @@ -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']; } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductRentalSlot.php b/packages/Webkul/BookingProduct/src/Models/BookingProductRentalSlot.php index 050c87b5b..fa7405b81 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProductRentalSlot.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProductRentalSlot.php @@ -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']; } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductTableSlot.php b/packages/Webkul/BookingProduct/src/Models/BookingProductTableSlot.php index f6a56a8cb..668c86e1b 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProductTableSlot.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProductTableSlot.php @@ -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']; } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php index 9bba4fef1..71df0d525 100644 --- a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php +++ b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php @@ -37,7 +37,7 @@ -