pdf = $pdf; $this->pdfContentService = $pdfContentService; $this->propertyRoomService = $propertyRoomService; $this->mailer = $mailer; } public function pdf(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = json_decode($request->getContent(), 1); $params = current($params); if (isset($params['dataExport']) && $params['dataExport'] == 'json') { $pdfDataRequest = [ 'property_id' => fillOnUndefined($params, 'property_id', null), 'locale' => app('translator')->getLocale() ]; $factSheetDataResponse = $this->pdfContentService->factSheetData($pdfDataRequest); if ($factSheetDataResponse['status'] != 'success') { throw new Exception($factSheetDataResponse['message']); } $factSheetData = $factSheetDataResponse['data']; return apiResponse(1, null, $factSheetData, 200); } if (isset($params['dataExport']) && $params['dataExport'] == 'catalog') { /*$pdfDataRequest = [ 'property_id' => fillOnUndefined($params, 'property_id', null), 'locale' => fillOnUndefined($params, 'language', 'en'), ]; $factSheetDataResponse = $this->pdfContentService->factSheetData($pdfDataRequest); if ($factSheetDataResponse['status'] != 'success') { throw new Exception($factSheetDataResponse['message']); } $pageContent = $factSheetDataResponse['data']; $pdfLanguage = $pdfDataRequest['locale']; app('translator')->setLocale($pdfLanguage); $pdfService = $this->pdf->loadView('pdf.propertyCatalog', compact('pageContent'), [], 'UTF8'); //$pdfService->setOptions(['dpi' => 100, 'isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true]); $hotelName = Str::slug($pageContent['name'], '_', 'en') . '_' . $pdfLanguage; return $pdfService->download($hotelName . '.pdf');*/ dispatch(new PropertyCatalogServiceJob( fillOnUndefined($params, 'property_id', null), fillOnUndefined($params, 'language', app('translator')->getLocale()), fillOnUndefined($params, 'email', null) )); $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => null]; return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } $pdfDataRequest = [ 'property_id' => fillOnUndefined($params, 'property_id', null), 'locale' => app('translator')->getLocale() ]; $pdfDataResponse = $this->pdfContentService->pdfData($pdfDataRequest); if ($pdfDataResponse['status'] != 'success') { throw new Exception($pdfDataResponse['message']); } $pdfData = $pdfDataResponse['data']; $pdfLanguage = upperCase(app('translator')->getLocale()); $logoBase64 = null; if ($pdfData['property_brand']) { if ($pdfData['property_brand']['logo_name']) { $logoFile = Config::get('app.imageUrl') . '/property-photos/' . $pdfData['property_brand']['property_id'] . '/logo/' . $pdfData['property_brand']['logo_name'] . '_250x250.' . $pdfData['property_brand']['logo_file_ext']; $logoBase64 = 'data:image/' . $pdfData['property_brand']['logo_file_ext'] . ';base64,' . base64_encode(file_get_contents($logoFile)); } } $ip = $request->ip(); $pdf = $this->pdf->loadView('pdf.hotelContent', compact('pdfData', 'logoBase64', 'ip'), [], 'UTF8'); $hotelName = Str::slug($pdfData['name'], '_', 'en') . '_' . $pdfLanguage; return $pdf->download($hotelName . '.pdf'); } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (\Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); // return $pdf->stream(); } public function getPropertyPdfInventory(Request $request, $token) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $requestParams = [ 'token' => $token ]; $params = $this->propertyRoomService->getParamsForPdfInvenyory($requestParams); $params = $params['data']; $requestParams = [ 'property_id' => fillOnUndefined($params, 'property_id'), 'channel_id' => fillOnUndefined($params, 'channel_id'), 'start_date' => fillOnUndefined($params, 'start_date'), 'end_date' => fillOnUndefined($params, 'end_date'), ]; $inventoryData = $this->propertyRoomService->getPropertyRoomInventory($requestParams); if ($inventoryData['status'] != 'success') { throw new ApiErrorException($inventoryData['message']); } $data = $inventoryData['data']; foreach ($data as $dataKey => $dataVal) { //room_availability $i = 0; $monthKey = null; foreach ($dataVal['room_availability'] as $key => $val) { $keyArr = explode('-', $key); if ($monthKey != $keyArr[1]) { $monthKey = $keyArr[1]; $i++; } if ($i > 6) { continue; } $data[$dataKey]['monthly_room_availability'][$i][$key] = $val; } //room_stop_sell $i = 0; $monthKey = null; foreach ($dataVal['room_stop_sell'] as $key => $val) { $keyArr = explode('-', $key); if ($monthKey != $keyArr[1]) { $monthKey = $keyArr[1]; $i++; } if ($i > 6) { continue; } $data[$dataKey]['monthly_room_stop_sell'][$i][$key] = $val; } foreach ($dataVal['property_room_rate_mapping'] as $propertyRoomRateMappingKey => $propertyRoomRateMappingVal) { foreach ($propertyRoomRateMappingVal['prices'] as $pricesKey => $pricesVal) { //price $i = 0; $monthKey = null; foreach ($pricesVal['price'] as $key => $val) { $keyArr = explode('-', $key); if ($monthKey != $keyArr[1]) { $monthKey = $keyArr[1]; $i++; } if ($i > 6) { continue; } $data[$dataKey]['property_room_rate_mapping'][$propertyRoomRateMappingKey]['prices'][$pricesKey]['monthly_price'][$i][$key] = $val; } //stop_sell $i = 0; $monthKey = null; foreach ($pricesVal['stop_sell'] as $key => $val) { $keyArr = explode('-', $key); if ($monthKey != $keyArr[1]) { $monthKey = $keyArr[1]; $i++; } if ($i > 6) { continue; } $data[$dataKey]['property_room_rate_mapping'][$propertyRoomRateMappingKey]['prices'][$pricesKey]['monthly_stop_sell'][$i][$key] = $val; } //min_stay $i = 0; $monthKey = null; foreach ($pricesVal['min_stay'] as $key => $val) { $keyArr = explode('-', $key); if ($monthKey != $keyArr[1]) { $monthKey = $keyArr[1]; $i++; } if ($i > 6) { continue; } $data[$dataKey]['property_room_rate_mapping'][$propertyRoomRateMappingKey]['prices'][$pricesKey]['monthly_min_stay'][$i][$key] = $val; } } } } $propertyDataRequest = [ 'property_id' => fillOnUndefined($params, 'property_id', null) ]; $propertyDataResponse = $this->pdfContentService->propertyBaseData($propertyDataRequest); if ($propertyDataResponse['status'] != 'success') { throw new Exception($propertyDataResponse['message']); } $propertyData = $propertyDataResponse['data']; $logoBase64 = null; if ($propertyData['property_brand']) { if ($propertyData['property_brand']['logo_name']) { $logoFile = Config::get('app.imageUrl') . '/property-photos/' . $propertyData['property_brand']['property_id'] . '/logo/' . $propertyData['property_brand']['logo_name'] . '_250x250.' . $propertyData['property_brand']['logo_file_ext']; $logoBase64 = 'data:image/' . $propertyData['property_brand']['logo_file_ext'] . ';base64,' . base64_encode(file_get_contents($logoFile)); } } /*$pdf = $this->pdf->loadView('pdf.inventory', compact('data','propertyData','logoFile','logoBase64'), [], 'UTF8' )->setPaper('a4', 'landscape'); $pdfLanguage = upperCase(app('translator')->getLocale()); $fileName = Str::slug('inventory', '_','en').'_'.$pdfLanguage;*/ return view('pdf.inventory', compact('data', 'propertyData', 'logoFile', 'logoBase64')); /*return $pdf->download($fileName.'.pdf');*/ } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function propertyProductOffer(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = json_decode($request->getContent(), 1); $params = current($params); if (fillOnUndefined($params, 'version') == 'v2') { $offerKey = []; $offerKey[] = $params['propertyName']; $offerKey[] = $params['executiveName']; $offerKey[] = $params['executiveEmail']; $offerKey[] = $params['executivePhone']; $offerKey[] = $params['accountManager']; $offerKey[] = hash('sha256', json_encode($params['detail'], JSON_UNESCAPED_UNICODE)); $offerKey = md5(implode('-', $offerKey)); } else { $offerKey = md5($params['propertyName'] . '-' . $params['executiveName'] . '-' . $params['package'] . '-' . $params['numberOfRooms'] . '-' . $params['promotionCode']); if ($offerKey != fillOnUndefined($params, 'hashKey')) { throw new ApiErrorException('HASH verification error!'); } } $createParam = [ 'offer_key' => $offerKey, 'property_name' => $params['propertyName'], 'executive_name' => $params['executiveName'], 'executive_email' => $params['executiveEmail'], 'executive_phone' => $params['executivePhone'], 'account_manager_name' => fillOnUndefined($params, 'accountManagerName'), 'account_manager_email' => fillOnUndefined($params, 'accountManagerEmail'), 'confirm' => fillOnUndefined($params, 'confirm'), 'offer_date' => Carbon::now()->toDateTimeString(), 'offer_expire_date' => Carbon::now()->addDays(2)->toDateTimeString(), 'package' => $params['package'], 'promotion_code' => $params['promotionCode'], 'detail' => fillOnUndefined($params, 'detail') ? json_encode($params['detail']) : json_encode($params), 'version' => fillOnUndefined($params, 'version', 'v1'), 'ip_address' => $params['ipAddress'], 'status' => 1, 'created_at' => time(), 'updated_at' => time() ]; $propertyProductOfferCheck = PropertyProductOffer::where('offer_key', $offerKey)->first(); if ($propertyProductOfferCheck) { $propertyProductOfferSync = PropertyProductOffer::where('offer_key', $offerKey)->update($createParam); } else { $propertyProductOfferSync = PropertyProductOffer::insert($createParam); } if (!$propertyProductOfferSync) { throw new ApiErrorException('Your offer could not be generated. Please try again.'); } if(fillOnUndefined($params, 'sendEmail')) { $propertyProductOfferMail = ['offerKey' => $offerKey]; $this->mailer->onQueue('propertyProductOfferMail', new PropertyProductOfferMail($propertyProductOfferMail)); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => ['offer_key' => $offerKey]]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); //$response['message'] = $e->getMessage(); $response['message'] = 'Your offer could not be generated. Please try again.'; $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function propertyProductOfferExport(Request $request, $offerKey) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; $package = [ 'LRG' => [ 'commission' => 15, 'minFee' => 2, 'name' => 'Paket A', 'creditRange' => [ '25-50' => [ 'min' => 25, 'max' => 50, 'monthly' => 250, 'annually' => 3000, ], '51-75' => [ 'min' => 51, 'max' => 75, 'monthly' => 500, 'annually' => 6000, ], '76-100' => [ 'min' => 76, 'max' => 100, 'monthly' => 750, 'annually' => 9000, ], '101-150' => [ 'min' => 101, 'max' => 150, 'monthly' => 1000, 'annually' => 12000, ], '151-200' => [ 'min' => 151, 'max' => 200, 'monthly' => 1500, 'annually' => 18000, ], '201-250' => [ 'min' => 201, 'max' => 250, 'monthly' => 2000, 'annually' => 24000, ], '250+' => [ 'min' => 251, 'max' => null, 'monthly' => 2500, 'annually' => 30000, ], ] ], 'MED' => [ 'commission' => 10, 'minFee' => 3, 'name' => 'Paket B', 'creditRange' => [ '25-50' => [ 'min' => 25, 'max' => 50, 'monthly' => 375, 'annually' => 4500, ], '51-75' => [ 'min' => 51, 'max' => 75, 'monthly' => 750, 'annually' => 9000, ], '76-100' => [ 'min' => 76, 'max' => 100, 'monthly' => 1125, 'annually' => 13500, ], '101-150' => [ 'min' => 101, 'max' => 150, 'monthly' => 1500, 'annually' => 18000, ], '151-200' => [ 'min' => 151, 'max' => 200, 'monthly' => 2250, 'annually' => 27000, ], '201-250' => [ 'min' => 201, 'max' => 250, 'monthly' => 3000, 'annually' => 36000, ], '250+' => [ 'min' => 251, 'max' => null, 'monthly' => 3750, 'annually' => 45000, ], ] ], 'SML' => [ 'commission' => 5, 'minFee' => 4, 'name' => 'Paket C', 'creditRange' => [ '25-50' => [ 'min' => 25, 'max' => 50, 'monthly' => 750, 'annually' => 9000, ], '51-75' => [ 'min' => 51, 'max' => 75, 'monthly' => 1500, 'annually' => 18000, ], '76-100' => [ 'min' => 76, 'max' => 100, 'monthly' => 2250, 'annually' => 27000, ], '101-150' => [ 'min' => 101, 'max' => 150, 'monthly' => 3000, 'annually' => 36000, ], '151-200' => [ 'min' => 151, 'max' => 200, 'monthly' => 4500, 'annually' => 54000, ], '201-250' => [ 'min' => 201, 'max' => 250, 'monthly' => 6000, 'annually' => 72000, ], '250+' => [ 'min' => 251, 'max' => null, 'monthly' => 7500, 'annually' => 90000, ], ], ] ]; $campaign = [ 'promotion' => [ 'code' => [/*'ITF2025','ATF2025','TTI2025'*/], 'percentage' => 50 ], 'oneYearAnnually' => [ 'percentage' => 10 ], 'twoYearAnnually' => [ 'percentage' => 20 ] ]; $userListIds = [904, 941, 1485];//22-41 try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $userList = User::whereIn('id', $userListIds)->get()->toArray(); $offerDetail = PropertyProductOffer::where('offer_key', $offerKey)->first(); $offerDetail = $offerDetail ? $offerDetail->toArray() : null; if (empty($offerDetail)) { return redirect()->to(config('app.url')); } $pageContent = [ 'name' => $offerDetail['property_name'], 'executiveName' => $offerDetail['executive_name'], 'executiveEmail' => $offerDetail['executive_email'], 'executivePhone' => $offerDetail['detailArray']['executivePhone'], 'offerTime' => $offerDetail['offer_date'], 'offerExpireTime' => $offerDetail['offer_expire_date'], 'offerTimeFormatted' => $offerDetail['offerTimeFormatted'], 'offerExpireTimeFormatted' => $offerDetail['offerExpireTimeFormatted'], 'numberOfRooms' => $offerDetail['detailArray']['numberOfRooms'], 'package' => $offerDetail['package'], 'promotionCode' => $offerDetail['promotion_code'], ]; $pageContent['package'] = !empty($request->get('package')) ? $request->get('package') : $pageContent['package']; $pageContent['numberOfRooms'] = !empty($request->get('numberOfRooms')) ? $request->get('numberOfRooms') : $pageContent['numberOfRooms']; $creditPackage = []; if ((int)$pageContent['numberOfRooms'] < 25) { $creditPackage = $package[$pageContent['package']]['creditRange']['25-50']; } elseif ((int)$pageContent['numberOfRooms'] > 250) { $creditPackage = $package[$pageContent['package']]['creditRange']['250+']; } else { $creditPackage = collect($package[$pageContent['package']]['creditRange']) ->where('min', '<=', (int)$pageContent['numberOfRooms']) ->where('max', '>=', (int)$pageContent['numberOfRooms']) ->first(); } $pricing = []; $pricing['minFee'] = $package[$pageContent['package']]['minFee']; $pricing['minFeeBeforeDiscount'] = $package[$pageContent['package']]['minFee']; if (in_array($pageContent['promotionCode'], $campaign['promotion']['code'])) { $pricing['minFee'] = (int)($pricing['minFee'] * (1 - ($campaign['promotion']['percentage'] / 100))); } $pricing['commission'] = $package[$pageContent['package']]['commission']; $pricing['minFee'] = $pricing['minFee']; $pricing['minFeeBeforeDiscount'] = $pricing['minFeeBeforeDiscount']; $pricing['monthly']['minFee'] = (int)$pricing['minFee'] * (int)$pageContent['numberOfRooms']; $pricing['monthly']['minFeeBeforePromotion'] = (int)$pricing['minFeeBeforeDiscount'] * (int)$pageContent['numberOfRooms']; $pricing['monthly']['commission'] = $package[$pageContent['package']]['commission']; //$pricing['monthly']['minReservationTotal'] = number_format(((int)$pricing['monthly']['minFee'] * 100) / $package[$pageContent['package']]['commission'], 0, '', '.'); $pricing['monthly']['minReservationTotal'] = number_format(fillOnUndefined($creditPackage, 'monthly', 0), 0, '', '.'); $pricing['annually']['minFee'] = (int)$pricing['monthly']['minFee'] * 12; $pricing['annually']['minFeeBeforePromotion'] = (int)$pricing['monthly']['minFeeBeforePromotion'] * 12; $pricing['annually']['commission'] = $package[$pageContent['package']]['commission']; $pricing['annually']['minFeeDiscount'] = (int)$pricing['annually']['minFee'] * (1 - ($campaign['oneYearAnnually']['percentage'] / 100));//%10 //$pricing['annually']['minReservationTotal'] = number_format(((int)$pricing['annually']['minFeeDiscount'] * 100) / $package[$pageContent['package']]['commission'], 0, '', '.'); $pricing['annually']['minReservationTotal'] = number_format(fillOnUndefined($creditPackage, 'annually', 0), 0, '', '.'); if ($pricing['minFee'] == $pricing['minFeeBeforeDiscount']) { $pricing['monthly']['minFeeBeforePromotion'] = null; $pricing['annually']['minFeeBeforePromotion'] = null; } $pageContent['packageName'] = $package[$pageContent['package']]['name']; $pageContent['pricing'] = $pricing; $accountUserDetail = collect($userList)->where('email', $offerDetail['detailArray']['accountManager'])->first(); $pageContent['accountManagerName'] = fillOnUndefined($accountUserDetail, 'nameSurname'); $pageContent['accountManagerEmail'] = fillOnUndefined($accountUserDetail, 'email'); $pageContent['accountManagerPhone'] = fillOnUndefined($accountUserDetail, 'phone'); $pdfService = $this->pdf->loadView('pdf.propertyProductOffer', compact('pageContent'), [], 'UTF8'); $pdfService->setOptions(['dpi' => 100, 'isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true]); $hotelName = Str::slug($pageContent['name'], '_', 'en'); return $pdfService->stream($hotelName . '.pdf'); } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function propertyProductOfferData(Request $request, $offerKey) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; $userListIds = [904, 941, 1485];//22-41 try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $userList = User::whereIn('id', $userListIds)->get()->toArray(); $offerDetail = PropertyProductOffer::where('offer_key', $offerKey)->first(); $offerDetail = $offerDetail ? $offerDetail->toArray() : null; if (empty($offerDetail)) { return redirect()->to(config('app.url')); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $offerDetail]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } }