Exemple #1
0
 public static function checkVouchersToCreate()
 {
     $voucherTasks = VoucherTask::builder()->get();
     if (count($voucherTasks) > 0) {
         // block enter to routine just finish this loop
         $bookingVouchersBulkCreate = Preference::getValue('bookingVouchersBulkCreate', 11, '0');
         // Comprobación para casos de errores o caídas del servidor, y no dejen bloquedo el envío de emails a la cola de proceso
         // si en 10 minutos no se ha liberado la variable, damos por hecho que se ha bloqueado y la liberamos
         $update = \DateTime::createFromFormat('Y-m-d H:i:s', $bookingVouchersBulkCreate->updated_at);
         if ($bookingVouchersBulkCreate->value_018 == '1' && date('U') - $update->getTimestamp() > 600) {
             Preference::setValue('emailServiceSendingEmailsToQueue', 11, '0');
         }
         // en el caso que el estado de envio esté activo, eso siginifica que hay una petición trabajando y enviando
         // a la tabla de cola de envíos los contactos, cuando termine de hacerlo cambiaremos el estado de envío de emails
         // para poder aceptar más peticiones, de esa manera nos aseguramos que no hayan
         // varias peticiones concurrentes insertando mails.
         if ($bookingVouchersBulkCreate->value_018 == '1') {
             exit;
         } else {
             Preference::setValue('bookingVouchersBulkCreate', 11, '1');
         }
         $limitVouchers = (int) Preference::getValue('bookingNVouchersToCreate', 11)->value_018;
         $voucherTask = $voucherTasks->first();
         // set limit to create vouchers
         if ($voucherTask->vouchers_to_create_227 <= $limitVouchers) {
             $limit = $voucherTask->vouchers_to_create_227;
         } else {
             $limit = $limitVouchers;
         }
         $voucher = Voucher::builder()->find($voucherTask->voucher_id_227);
         $vouchers = [];
         for ($i = 0; $i < $limit; $i++) {
             $vouchers[] = ['date_226' => $voucher->date_226, 'date_text_226' => $voucher->date_text_226, 'code_prefix_226' => $voucher->code_prefix_226, 'campaign_id_226' => $voucher->campaign_id_226, 'customer_id_226' => $voucher->customer_id_226, 'customer_name_226' => $voucher->customer_name_226, 'bearer_226' => $voucher->bearer_226, 'invoice_id_226' => $voucher->invoice_id_226, 'invoice_code_226' => $voucher->invoice_code_226, 'invoice_customer_id_226' => $voucher->invoice_customer_id_226, 'invoice_customer_name_226' => $voucher->invoice_customer_name_226, 'product_id_226' => $voucher->product_id_226, 'name_226' => $voucher->name_226, 'description_226' => $voucher->description_226, 'price_226' => $voucher->price_226, 'expire_date_226' => $voucher->expire_date_226, 'expire_date_text_226' => $voucher->expire_date_text_226, 'active_226' => $voucher->active_226];
         }
         // insert n vouchers
         Voucher::insert($vouchers);
         if ($voucherTask->vouchers_to_create_227 <= $limitVouchers) {
             // get user to send email
             $user = $voucherTask->getUser;
             // destroy task
             VoucherTask::destroy($voucherTask->id_227);
             // send email to user
             $dataMessage = ['emailTo' => $user->email_010, 'nameTo' => $user->name_010 . ' ' . $user->surname_010, 'subject' => trans('booking::pulsar.bulk_vouchers_create', ['totalVouchers' => $voucherTask->total_vouchers_227, 'id' => $voucherTask->id_227]), 'totalVouchers' => $voucherTask->total_vouchers_227, 'voucher' => $voucher];
             Mail::send('booking::emails.bulk_vouchers_notification', $dataMessage, function ($m) use($dataMessage) {
                 $m->to($dataMessage['emailTo'], $dataMessage['nameTo'])->subject($dataMessage['subject']);
             });
         } else {
             VoucherTask::where('id_227', $voucherTask->id_227)->update(['vouchers_to_create_227' => $voucherTask->vouchers_to_create_227 - $limit]);
         }
         // unblock loop
         Preference::setValue('bookingVouchersBulkCreate', 11, '0');
     }
 }
 private function setVouchersToReset($vouchers)
 {
     if ($vouchers->count() > 0) {
         Voucher::whereIn('id_226', $vouchers)->update(['has_used_226' => false, 'used_date_226' => null, 'used_date_text_226' => null, 'booking_id_226' => null, 'place_id_226' => null, 'object_id_226' => null, 'cost_226' => null]);
     }
 }
 public function updateCustomRecord($parameters)
 {
     Voucher::where('id_226', $parameters['id'])->update(['code_prefix_226' => $this->request->has('codePrefix') ? $this->request->input('codePrefix') : null, 'campaign_id_226' => $this->request->input('campaign'), 'customer_id_226' => $this->request->input('customerId'), 'customer_name_226' => $this->request->input('customer'), 'bearer_226' => $this->request->has('bearer') ? $this->request->input('bearer') : null, 'invoice_id_226' => $this->request->has('invoiceId') ? $this->request->input('invoiceId') : null, 'invoice_code_226' => $this->request->has('invoiceCode') ? $this->request->input('invoiceCode') : null, 'invoice_customer_id_226' => $this->request->has('invoiceCustomerId') ? $this->request->input('invoiceCustomerId') : null, 'invoice_customer_name_226' => $this->request->has('invoiceCustomerName') ? $this->request->input('invoiceCustomerName') : null, 'product_id_226' => $this->request->input('product'), 'name_226' => $this->request->has('name') ? $this->request->input('name') : null, 'description_226' => $this->request->has('description') ? $this->request->input('description') : null, 'price_226' => $this->request->input('price'), 'expire_date_226' => $this->request->has('expireDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('expireDate'))->getTimestamp() : null, 'expire_date_text_226' => $this->request->has('expireDate') ? $this->request->input('expireDate') : null, 'active_226' => $this->request->has('active'), 'has_used_226' => $this->request->has('usedDate'), 'used_date_226' => $this->request->has('usedDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('usedDate'))->getTimestamp() : null, 'used_date_text_226' => $this->request->has('usedDate') ? $this->request->input('usedDate') : null, 'place_id_226' => $this->request->has('place') ? $this->request->input('place') : null, 'object_id_226' => $this->request->has('object') ? $this->request->input('object') : null, 'cost_226' => $this->request->has('cost') ? $this->request->input('cost') : null, 'paid_226' => $this->request->has('payoutDate'), 'place_payout_date_226' => $this->request->has('payoutDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('payoutDate'))->getTimestamp() : null, 'place_payout_date_text_226' => $this->request->has('payoutDate') ? $this->request->input('payoutDate') : null]);
 }
 private function sendEmails(Booking $booking)
 {
     // objects from place
     if (isset($booking->place_id_225)) {
         $result = collect(config('booking.models'))->where('id', $booking->place_id_225);
         if (count($result) === 0) {
             return response()->json(['status' => 'error', 'code' => 404, 'message' => 'Records not found']);
         }
         // model constructor
         $model = App::make($result->first()->model);
         // use sofa to get lang from lang table of object query
         $establishment = $model->builder()->where('lang_id', base_lang()->id_001)->where('id', $booking->object_id_225)->first();
         $attachment = Attachment::builder()->where('lang_id_016', base_lang()->id_001)->where('resource_id_016', 'hotels-hotel')->where('object_id_016', $establishment->id)->where('family_id_016', 1)->orderBy('sorting', 'asc')->first();
         //****************************
         // get values to Master Card
         //****************************
         $customFields = CustomField::where('group_id_026', 4)->get();
         if (isset($customFields) && $customFields->where('name_026', 'master_card_feature')->count() > 0) {
             $masterCardFeatures = $customFields->where('name_026', 'master_card_feature')->first()->getResults()->where('object_id_028', $establishment->id_170)->where('lang_id_028', 'es')->get()->first();
         } else {
             $masterCardFeatures = null;
         }
         // get vouchers
         $vouchers = Voucher::builder()->whereIn('id_226', json_decode($booking->data_225))->get();
         // status confirmed
         if ($booking->status_225 == 1) {
             Mail::to('*****@*****.**')->bcc('*****@*****.**')->cc('*****@*****.**')->send(new BookingEmail('booking::emails.customer_booking_notification', trans('booking::pulsar.subject_customer_booking_email', ['bookingId' => $booking->id_225 . '/' . date('Y')]), $booking, $establishment, $vouchers, $attachment, $masterCardFeatures));
             Mail::to('*****@*****.**')->bcc('*****@*****.**')->cc('*****@*****.**')->send(new BookingEmail('booking::emails.hotel_booking_notification', trans('booking::pulsar.subject_hotel_booking_email', ['bookingId' => $booking->id_225 . '/' . date('Y')]), $booking, $establishment, $vouchers, $attachment, $masterCardFeatures));
         } elseif ($booking->status_225 == 3) {
             Mail::to('*****@*****.**')->bcc('*****@*****.**')->cc('*****@*****.**')->send(new BookingEmail('booking::emails.customer_cancel_booking_notification', trans('booking::pulsar.subject_customer_cancel_booking_email', ['bookingId' => $booking->id_225 . '/' . date('Y')]), $booking, $establishment, $vouchers, $attachment, $masterCardFeatures));
             Mail::to('*****@*****.**')->bcc('*****@*****.**')->cc('*****@*****.**')->send(new BookingEmail('booking::emails.hotel_cancel_booking_notification', trans('booking::pulsar.subject_hotel_cancel_booking_email', ['bookingId' => $booking->id_225 . '/' . date('Y')]), $booking, $establishment, $vouchers, $attachment, $masterCardFeatures));
         }
     }
 }