'Generate Bookings E-Invoices', 'message' => sprintf( 'You have successfully submitted %d booking%s for E-Invoices processing.', $this->processedCount, $this->processedCount === 1 ? '' : 's' ), ]; } /** @var RegenerateInvoiceBookingProcessor */ private $regenerateInvoiceBookingProcessor; /** * BatchBookingsGenerateEInvoiceLogic constructor. * @param RegenerateInvoiceBookingProcessor $regenerateInvoiceBookingProcessor */ public function __construct( RegenerateInvoiceBookingProcessor $regenerateInvoiceBookingProcessor ) { $this->regenerateInvoiceBookingProcessor = $regenerateInvoiceBookingProcessor; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request): JsonResponse { $validated = $request->validate([ 'startDate' => 'nullable|date_format:d-m-Y', 'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate', ]); $startDate = null; $endDate = null; if (isset($validated['startDate']) && $validated['startDate']) { $startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay(); } else { $startDate = Carbon::now()->subMonths(1)->startOfDay(); } if (isset($validated['endDate']) && $validated['endDate']) { $endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay(); } else { $endDate = Carbon::now()->endOfDay(); } $startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1); $endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now(); $bookings = Booking::where('status', ApprovalStatus::COMPLETED) // ->whereBetween('created_at', [$startDate, $endDate]) ->whereHas('transactions', function ($query) use ($startDate, $endDate) { $query->payments() ->complete() ->whereBetween('created_at', [$startDate, $endDate]) ->latest('created_at'); }) ->whereHas('attributesKVP', function (Builder $query) { $query->where('key', KVPKey::AUTOCOUNT_DOCNO); }) ->with(['attributesKVP' => function ($query) { $query->where('key', KVPKey::AUTOCOUNT_DOCNO); }]) ->get(); foreach ($bookings as $booking) { //$autocountValue = optional($booking->attributesKVP->first())->value; //Log::info('Booking ID: ' . $booking->marking . ' | AUTOCOUNT_DOCNO: ' . $autocountValue); // $this->regenerateInvoiceBookingProcessor->execute($booking); ProcessBookingForEInvoiceV2CommandJob::dispatch($booking); } $this->processedCount = count($bookings); return $this->resourceResponse(JsonResource::collection(collect([]))); } }