first commit
This commit is contained in:
122
app/Console/Commands/Jobs/BookingCommissionService.php
Normal file
122
app/Console/Commands/Jobs/BookingCommissionService.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Service\BookingService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
|
||||
class BookingCommissionService extends Command
|
||||
{
|
||||
protected $signature = 'cron:commission-service';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $bookingService;
|
||||
|
||||
public function __construct(
|
||||
BookingService $bookingService
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->bookingService = $bookingService;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
try {
|
||||
|
||||
|
||||
$bookingListParam = [
|
||||
'criteria' => [
|
||||
//['field' => 'id', 'condition' => '=', 'value' => 600],
|
||||
//['field' => 'property_id', 'condition' => '=', 'value' => 313],
|
||||
['field' => 'commission', 'condition' => '=', 'value' => null],
|
||||
['field' => 'commission_rate', 'condition' => '=', 'value' => null]
|
||||
],
|
||||
'with' => ['bookingChannel.propertyChannelCategory', 'bookingProperty'],
|
||||
"take" => 10000,
|
||||
"orderBy" => [
|
||||
["field" => "id", "value" => "ASC"]
|
||||
],
|
||||
];
|
||||
|
||||
$bookingList = $this->bookingService->select($bookingListParam);
|
||||
|
||||
if ($bookingList['status'] != 'success' || ($bookingList['status'] == 'success' && empty($bookingList['data']))) {
|
||||
throw new ApiErrorException('Property list not found!');
|
||||
}
|
||||
|
||||
foreach ($bookingList['data'] as $booking) {
|
||||
|
||||
|
||||
$commission = null;
|
||||
$commissionRate = null;
|
||||
//$booking['booking_property']['commission'] = 15;//TOOD: DEL
|
||||
switch ($booking['booking_channel']['channel_category_id']) {
|
||||
case "3" :
|
||||
|
||||
if (fillOnUndefined($booking['booking_property'], 'commission') && $booking['booking_property']['commission'] > 0) {
|
||||
$commissionRate = $booking['booking_property']['commission'];
|
||||
$commission = moneyDoubleFormatDecimal($booking['booking_property']['commission'] * $booking['total'] / 100);
|
||||
}
|
||||
|
||||
break;
|
||||
case "2" :
|
||||
|
||||
if (fillOnUndefined($booking['booking_property'], 'commission_offline') && $booking['booking_property']['commission_offline'] > 0) {
|
||||
$commissionRate = $booking['booking_property']['commission_offline'];
|
||||
$commission = moneyDoubleFormatDecimal($booking['booking_property']['commission_offline'] * $booking['total'] / 100);
|
||||
}
|
||||
|
||||
break;
|
||||
case "4" :
|
||||
|
||||
if (fillOnUndefined($booking['booking_property'], 'commission_channel') && $booking['booking_property']['commission_channel'] > 0) {
|
||||
$commissionRate = $booking['booking_property']['commission_channel'];
|
||||
$commission = moneyDoubleFormatDecimal($booking['booking_property']['commission_channel'] * $booking['total'] / 100);
|
||||
}
|
||||
|
||||
break;
|
||||
case "7" :
|
||||
|
||||
if (fillOnUndefined($booking['booking_property'], 'commission_wholesaler') && $booking['booking_property']['commission_wholesaler'] > 0) {
|
||||
$commissionRate = $booking['booking_property']['commission_wholesaler'];
|
||||
$commission = moneyDoubleFormatDecimal($booking['booking_property']['commission_wholesaler'] * $booking['total'] / 100);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($commission) && !empty($commissionRate)) {
|
||||
$this->bookingService->update($booking['id'], ['commission' => $commission, 'commission_rate' => $commissionRate]);
|
||||
$this->info(date('Y-m-d H:i:s') . ' Property: ' . $booking['booking_property']['name'] . ' Code: ' . $booking['booking_code'] . ' Commission: ' . $commission . ' Commission Rate: ' . $commissionRate);
|
||||
} else {
|
||||
|
||||
$this->bookingService->update($booking['id'], ['commission' => 0, 'commission_rate' => 0]);
|
||||
$this->error(date('Y-m-d H:i:s') . ' Property: ' . $booking['booking_property']['name'] . ' Code: ' . $booking['booking_code'] . ' Commission: ' . $commission . ' Commission Rate: ' . $commissionRate);
|
||||
}
|
||||
|
||||
//sleep(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (ApiErrorException | Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' ERROR:' . $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
194
app/Console/Commands/Jobs/BookingEngineSearchReportService.php
Normal file
194
app/Console/Commands/Jobs/BookingEngineSearchReportService.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Mail\BookingEngineSearchReportMail;
|
||||
use App\Core\Service\PropertyService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\Country;
|
||||
use App\Models\Language;
|
||||
use App\Models\vwBookingEngineSearch;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Mail\Mailer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BookingEngineSearchReportService extends Command
|
||||
{
|
||||
protected $signature = 'cron:bookingengine-search-report-mail';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertyService;
|
||||
|
||||
public function __construct(
|
||||
Mailer $mailer,
|
||||
PropertyService $propertyService
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->mailer = $mailer;
|
||||
$this->propertyService = $propertyService;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$reportPropertyList = [506, 529, 1606];
|
||||
//506 Green Nature Diamond Hotel
|
||||
//529 Green Nature Resort & Spa Otel
|
||||
//1606 Green Nature Sarıgerme
|
||||
|
||||
$propertyListCriteria = [
|
||||
'criteria' =>
|
||||
[
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'with' => ['propertyBrand', 'propertyUser.user'],
|
||||
'orderBy' => [
|
||||
['field' => 'id', 'value' => 'ASC']
|
||||
],
|
||||
'whereIn' =>
|
||||
[
|
||||
['field' => 'id', 'value' => $reportPropertyList]
|
||||
]
|
||||
];
|
||||
|
||||
$propertyListData = $this->propertyService->select($propertyListCriteria);
|
||||
|
||||
$propertyList = [];
|
||||
if ($propertyListData['status'] == 'success' && !empty($propertyListData['data'])) {
|
||||
$propertyList = $propertyListData['data'];
|
||||
}
|
||||
|
||||
|
||||
$reportData = [];
|
||||
$reportDate = Carbon::now()->subDay()->toDateString();
|
||||
//$reportDate = '2023-02-28';
|
||||
$reportDateFormatted = Carbon::parse($reportDate)->format('d.m.Y');
|
||||
|
||||
$countryList = Country::all()->toArray();
|
||||
$languageList = Language::all()->toArray();
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' Date: ' . $reportDate);
|
||||
|
||||
foreach ($propertyList as $property) {
|
||||
|
||||
$reportData = [];
|
||||
|
||||
$reportData['propertyId'] = $property['id'];
|
||||
$reportData['propertyName'] = $property['name'];
|
||||
$reportData['propertyCountry'] = $property['country'];
|
||||
$reportData['logo'] = $property['property_brand']['logoUrl'];
|
||||
$reportData['date'] = $reportDateFormatted;
|
||||
$reportData['propertyUserEmail'] = collect($property['property_user'])->where('user.email','<>', null)->pluck('user.email')->toArray();
|
||||
|
||||
$searchData = vwBookingEngineSearch::where('property_id', $property['id'])
|
||||
->where('date', $reportDate)
|
||||
->get()->toArray();
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' Property: ' . $reportData['propertyName']);
|
||||
|
||||
if (!empty($searchData)) {
|
||||
|
||||
$reportData['transaction']['search'] = collect($searchData)->count();
|
||||
$reportData['transaction']['roomFound'] = collect($searchData)->where('status', 1)->count();
|
||||
$reportData['transaction']['roomNotFound'] = collect($searchData)->where('status', 0)->count();
|
||||
$reportData['transaction']['preBooking'] = collect($searchData)->where('status', 2)->count();
|
||||
$reportData['transaction']['booking'] = collect($searchData)->where('status', 3)->count();
|
||||
|
||||
|
||||
$countryCodes = collect($searchData)->groupBy('country_code')->keys()->toArray();
|
||||
foreach ($countryCodes as $countryCode) {
|
||||
$countryText = $countryCode;
|
||||
$countryTextCheck = collect($countryList)->where('country_code', mb_strtoupper($countryCode))->first();
|
||||
if (!empty($countryTextCheck)) {
|
||||
$countryText = $countryTextCheck['name'];
|
||||
}
|
||||
$reportData['country'][$countryCode]['text'] = $countryText;
|
||||
$reportData['country'][$countryCode]['search'] = collect($searchData)->where('country_code', $countryCode)->count();
|
||||
$reportData['country'][$countryCode]['roomFound'] = collect($searchData)->where('country_code', $countryCode)->where('status', 1)->count();
|
||||
$reportData['country'][$countryCode]['roomNotFound'] = collect($searchData)->where('country_code', $countryCode)->where('status', 0)->count();
|
||||
$reportData['country'][$countryCode]['preBooking'] = collect($searchData)->where('country_code', $countryCode)->where('status', 2)->count();
|
||||
$reportData['country'][$countryCode]['booking'] = collect($searchData)->where('country_code', $countryCode)->where('status', 3)->count();
|
||||
}
|
||||
|
||||
$reportData['country'] = collect($reportData['country'])->sortByDesc('search')->toArray();
|
||||
|
||||
$languageCodes = collect($searchData)->groupBy('language_code')->keys()->toArray();
|
||||
foreach ($languageCodes as $languageCode) {
|
||||
$languageText = $languageCode;
|
||||
$languageTextCheck = collect($languageList)->where('code', $languageCode)->first();
|
||||
if (!empty($languageTextCheck)) {
|
||||
$languageText = $languageTextCheck['name'];
|
||||
}
|
||||
$reportData['language'][$languageCode]['text'] = $languageText;
|
||||
$reportData['language'][$languageCode]['search'] = collect($searchData)->where('language_code', $languageCode)->count();
|
||||
$reportData['language'][$languageCode]['roomFound'] = collect($searchData)->where('language_code', $languageCode)->where('status', 1)->count();
|
||||
$reportData['language'][$languageCode]['roomNotFound'] = collect($searchData)->where('language_code', $languageCode)->where('status', 0)->count();
|
||||
$reportData['language'][$languageCode]['preBooking'] = collect($searchData)->where('language_code', $languageCode)->where('status', 2)->count();
|
||||
$reportData['language'][$languageCode]['booking'] = collect($searchData)->where('language_code', $languageCode)->where('status', 3)->count();
|
||||
}
|
||||
|
||||
$reportData['language'] = collect($reportData['language'])->sortByDesc('search')->toArray();
|
||||
|
||||
|
||||
$occupancyCodes = collect($searchData)->groupBy('pax')->keys()->toArray();
|
||||
foreach ($occupancyCodes as $occupancyCode) {
|
||||
$reportData['occupancy'][$occupancyCode]['text'] = occupancyCodeFormatted($occupancyCode);
|
||||
$reportData['occupancy'][$occupancyCode]['count'] = collect($searchData)->where('pax', $occupancyCode)->count();
|
||||
}
|
||||
|
||||
$reportData['occupancy'] = collect($reportData['occupancy'])->sortByDesc('count')->toArray();
|
||||
|
||||
//Daily Intensity
|
||||
$dailyIntensity = [];
|
||||
foreach ($searchData as $data) {
|
||||
$checkInDate = $data['checkin_date'];
|
||||
$checkOutDate = $data['checkout_date'];
|
||||
$dateDiff = Carbon::parse($data['checkout_date'])->diffInDays(Carbon::parse($data['checkin_date']));
|
||||
|
||||
for ($i = 0; $i < $dateDiff; $i++) {
|
||||
$date = Carbon::parse($checkInDate)->addDays($i)->toDateString();
|
||||
|
||||
if (!isset($dailyIntensity[$date])) {
|
||||
$dailyIntensity[$date]['text'] = Carbon::parse($date)->format('d.m.Y');
|
||||
$dailyIntensity[$date]['search'] = 0;
|
||||
$dailyIntensity[$date]['roomFound'] = 0;
|
||||
$dailyIntensity[$date]['roomNotFound'] = 0;
|
||||
$dailyIntensity[$date]['preBooking'] = 0;
|
||||
$dailyIntensity[$date]['booking'] = 0;
|
||||
}
|
||||
|
||||
$dailyIntensity[$date]['search']++;
|
||||
$dailyIntensity[$date]['roomFound'] += $data['status'] == 1 ? 1 : 0;
|
||||
$dailyIntensity[$date]['roomNotFound'] += $data['status'] == 0 ? 1 : 0;
|
||||
$dailyIntensity[$date]['preBooking'] += $data['status'] == 2 ? 1 : 0;
|
||||
$dailyIntensity[$date]['booking'] += $data['status'] == 3 ? 1 : 0;
|
||||
|
||||
}
|
||||
}
|
||||
ksort($dailyIntensity);
|
||||
$reportData['dailyIntensity'] = $dailyIntensity;
|
||||
//Daily Intensity
|
||||
|
||||
}
|
||||
|
||||
if (!empty($searchData)) {
|
||||
$this->mailer->onQueue('bookingEngineSearchReportMail', new BookingEngineSearchReportMail($reportData));
|
||||
$this->info(date('Y-m-d H:i:s') . ' Property: ' . $reportData['propertyName'] . ' - SENT MAIL');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
92
app/Console/Commands/Jobs/DataFetch.php
Normal file
92
app/Console/Commands/Jobs/DataFetch.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Models\Property;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class DataFetch extends Command
|
||||
{
|
||||
|
||||
|
||||
protected $signature = 'cron:data-fetch';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$propertyList = Property::whereIn('status', [1, 3])
|
||||
->where('commission', '>', 1)
|
||||
//->where('id', 1456)
|
||||
->with('propertyContractUser')
|
||||
->with('propertyExecutive.executiveType')
|
||||
->with('propertyContact')
|
||||
->with('propertyAdditionalInfos.propertyAdditionalInfoKey')
|
||||
->with('propertyType')
|
||||
->with('propertyStatus')
|
||||
->get();
|
||||
|
||||
$propertyList = $propertyList ? $propertyList->toArray() : null;
|
||||
|
||||
|
||||
$propertyListToExcel = [];
|
||||
foreach ($propertyList as $property) {
|
||||
|
||||
$numberOfRooms = collect($property['property_additional_infos'])->where('additional_info_key_id',3)->first();
|
||||
$numberOfRooms = $numberOfRooms['value'];
|
||||
|
||||
$propertyListToExcel[] = [
|
||||
'contract_user' => $property['property_contract_user']['nameSurname'],
|
||||
'executive_name_surname' => reset($property['property_executive'])['name_surname'],
|
||||
'name' => $property['name'],
|
||||
'phone' => $property['property_contact']['view_full_phone'],
|
||||
'email' => $property['property_contact']['email'],
|
||||
'executive_position' => reset($property['property_executive'])['executive_type']['name'],
|
||||
'executive_phone' => reset($property['property_executive'])['view_full_phone'],
|
||||
'executive_email' => reset($property['property_executive'])['email'],
|
||||
'web' => $property['property_contact']['web'],
|
||||
'address' => $property['property_contact']['address'],
|
||||
'location' => null, //Bölge
|
||||
'number_of_rooms' => $numberOfRooms,
|
||||
'category' => $property['property_type']['name'],
|
||||
'property_pms' => null,
|
||||
'property_cm' => null,
|
||||
'commission' => $property['commission'],
|
||||
'commission_period' => $property['invoice_type'],
|
||||
'contract_start' => Carbon::createFromTimestamp($property['created_at'])->format('d.m.Y'),
|
||||
'contract_finish' => null,
|
||||
'content' => null,
|
||||
'dns' => null,
|
||||
'ssl' => null,
|
||||
'cm' => null,
|
||||
'third_party' => null,
|
||||
'golive' => Carbon::createFromTimestamp($property['created_at'])->format('d.m.Y'),
|
||||
'training' => null,
|
||||
'panel' => null,
|
||||
'official_name' => $property['official_name'],
|
||||
'tax_office' => $property['tax_office'],
|
||||
'tax_number' => $property['tax_number'],
|
||||
'tax_address' => $property['property_contact']['address'],
|
||||
'status' => $property['property_status']['name'],
|
||||
'id' => $property['id'],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$f = fopen("C:\www\api.extranetwork.com\storage/tmp.csv", "w");
|
||||
foreach ($propertyListToExcel as $property) {
|
||||
fputcsv($f, $property);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
97
app/Console/Commands/Jobs/MailJobs.php
Normal file
97
app/Console/Commands/Jobs/MailJobs.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Service\JobsService;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class MailJobs extends Command
|
||||
{
|
||||
/*
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $signature = 'cron:mail-jobs';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mailJobs =
|
||||
[
|
||||
"default",
|
||||
"userCreateMail",
|
||||
"UserForgotPassword",
|
||||
"slackLog",
|
||||
"newBookingMail",
|
||||
"contactFormMail",
|
||||
"manualPaymentMail",
|
||||
"logMail",
|
||||
"inventoryActionMail",
|
||||
"bookingTicketMail",
|
||||
"enwContactFormMail",
|
||||
"trialFirstMail",
|
||||
"trialSecondMail",
|
||||
"cancelBookingMail",
|
||||
"modifiedBookingMail",
|
||||
"inventoryPdfLinkMail",
|
||||
"dailyReportMail",
|
||||
"bookingPaymentDataCode",
|
||||
"bookingPropertyAddonUpdateMail",
|
||||
"offerAcceptMail",
|
||||
"offerPreConfirmCustomerMail",
|
||||
"offerPreConfirmPropertyMail",
|
||||
"bookingEngineSearchReportMail",
|
||||
"channelManagerNotificationMail",
|
||||
"bookingInvoiceUpdateMail",
|
||||
"offerSendMail",
|
||||
"dailyReportSalesMail",
|
||||
"affiliateRequestMail",
|
||||
"propertyProductOfferMail"
|
||||
];
|
||||
protected $description = 'Calls All Mail Jobs';
|
||||
private $jobsService;
|
||||
|
||||
public function __construct(JobsService $jobsService)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->jobsService = $jobsService;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$mailJobsCriteria =
|
||||
[
|
||||
"whereIn" =>
|
||||
[
|
||||
["field" => "queue", "value" => $this->mailJobs]
|
||||
],
|
||||
"orderBy" =>
|
||||
[
|
||||
["field" => "id", "value" => "ASC"]
|
||||
],
|
||||
"take" => 20
|
||||
];
|
||||
|
||||
$mailJobs = $this->jobsService->getJobsList($mailJobsCriteria, ["queue"]);
|
||||
|
||||
foreach ($mailJobs as $perJob) {
|
||||
|
||||
try {
|
||||
Artisan::call("queue:work --queue=" . $perJob["queue"]." --tries=5");
|
||||
} catch (Exception $e) {
|
||||
$message = "Mail Job Fail --- Failed Mail : " . $perJob . " ErrorDetail : " . $e->getLine() . " " . $e->getLine() . " " . $e->getMessage();
|
||||
Log::error($message);
|
||||
continue;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
252
app/Console/Commands/Jobs/PriceComparisonService.php
Normal file
252
app/Console/Commands/Jobs/PriceComparisonService.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\ChannelManagerPropertyMapping;
|
||||
use App\Models\CurrencyRates;
|
||||
use App\Models\PropertyPriceComparison;
|
||||
use App\Models\PropertyRoomRatePrice;
|
||||
use App\Models\vwActiveProperty;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
|
||||
class PriceComparisonService extends Command
|
||||
{
|
||||
protected $signature = 'cron:price-comparison-service';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $bookingService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
//$today = '2025-06-05';
|
||||
$today = Carbon::now()->toDateString();
|
||||
|
||||
$today = Carbon::parse($today)->startOfWeek(Carbon::MONDAY);
|
||||
|
||||
$year = Carbon::parse($today)->format('Y');
|
||||
$week = Carbon::parse($today)->isoWeek();
|
||||
|
||||
$daysCount = [1, 15, 45, 90];
|
||||
$exchangeCurrency = 'EUR';
|
||||
//'BookingEngine'
|
||||
$comparisonChannels = ['Agoda.com', 'etstur.com', 'Booking.com'];
|
||||
|
||||
$exchangeRateUSD = CurrencyRates::where('currency_code', 'USD')->where('exc_currency_code', $exchangeCurrency)->orderBy('date', 'DESC')->first()->toArray();
|
||||
$exchangeRateUSD = $exchangeRateUSD['rate'];
|
||||
|
||||
$competitorPriceAnalysisController = App::make('App\Http\Controllers\V1\CompetitorPriceAnalysisController');
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$queryWeekPrices = [];
|
||||
$queryWeekPricesDaily = [];
|
||||
$queryKeyHash = md5($year . '-' . $week);
|
||||
|
||||
|
||||
$propertyList = vwActiveProperty::where('commission', '>', 1)
|
||||
//->whereIn('id', [1433,1441,1551,1574])
|
||||
->get()->toArray();
|
||||
|
||||
foreach ($propertyList as $property) {
|
||||
|
||||
try {
|
||||
|
||||
$channelManagerProperty = ChannelManagerPropertyMapping::where('channel_manager_id', 12)
|
||||
->where('property_id', $property['id'])->first();
|
||||
$channelManagerProperty = $channelManagerProperty ? $channelManagerProperty->toArray() : null;
|
||||
$channelManagerPropertyId = $channelManagerProperty ? $channelManagerProperty['channel_manager_property_id'] : null;
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' ' . $property['id'] . ' - ' . $property['name']);
|
||||
|
||||
if (empty($channelManagerPropertyId)) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' ' . $property['name'] . ': channelManagerPropertyId!');
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
foreach ($daysCount as $day) {
|
||||
|
||||
|
||||
//Booking Engine
|
||||
$queryDate = Carbon::parse($today)->addDays($day)->toDateString();
|
||||
|
||||
//FIRST Trigger
|
||||
$paramCompetitorPrice = ['date' => $queryDate, 'competitor_property_key' => $channelManagerPropertyId, 'currency' => $exchangeCurrency,];
|
||||
$getPropertyCompetitorPrice = $competitorPriceAnalysisController->getPropertyCompetitorPrice($paramCompetitorPrice);
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' ' . $property['id'] . ' - ' . $queryDate);
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
||||
$bestPriceOfDay = 0;
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']]['BookingEngine'][$day] = [
|
||||
'channel' => 'BookingEngine',
|
||||
'date' => $queryDate,
|
||||
'amount' => null,
|
||||
'currency' => null
|
||||
];
|
||||
|
||||
$propertyPrices = PropertyRoomRatePrice::where('property_id', $property['id'])
|
||||
->where('channel_id', 5)
|
||||
->where('stop_sell', 0)
|
||||
->where('status', 1)
|
||||
->where('amount', '<>', 0)
|
||||
->where('amount', '<>', null)
|
||||
->where('date', $queryDate)
|
||||
->with('roomRateMapping.propertyRoomRate')
|
||||
->get();
|
||||
|
||||
$propertyPrices = $propertyPrices ? $propertyPrices->toArray() : null;
|
||||
|
||||
if (empty($propertyPrices)) {
|
||||
//continue;
|
||||
}
|
||||
|
||||
$bestPrice = collect($propertyPrices)
|
||||
->where('room_rate_mapping.property_room_rate.name', 'Best Available Rate')
|
||||
->sortBy('amount')->first();
|
||||
|
||||
|
||||
|
||||
if (empty($bestPrice)) {
|
||||
//continue;
|
||||
} else {
|
||||
|
||||
|
||||
if ($bestPrice['currency'] != $exchangeCurrency) {
|
||||
$exchangeRate = CurrencyRates::where('currency_code', $bestPrice['currency'])
|
||||
->where('exc_currency_code', $exchangeCurrency)
|
||||
->orderBy('date', 'DESC')->first()->toArray();
|
||||
$exchangeRate = $exchangeRate['rate'];
|
||||
|
||||
$bestPrice['amount'] = $bestPrice['amount'] * $exchangeRate;
|
||||
}
|
||||
|
||||
$bestPrice['amount'] = moneyDoubleFormatDecimal($bestPrice['amount']);
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']]['BookingEngine'][$day] = [
|
||||
'channel' => 'BookingEngine',
|
||||
'date' => $queryDate,
|
||||
'amount' => $bestPrice['amount'],
|
||||
'currency' => $exchangeCurrency,
|
||||
];
|
||||
|
||||
$queryWeekPricesDaily[$queryKeyHash][$property['id']][$day] = $bestPrice['amount'];
|
||||
}
|
||||
//Booking Engine
|
||||
|
||||
|
||||
//OTHER Channels
|
||||
|
||||
$paramCompetitorPrice = ['date' => $queryDate, 'competitor_property_key' => $channelManagerPropertyId, 'currency' => $exchangeCurrency];
|
||||
$getPropertyCompetitorPrice = $competitorPriceAnalysisController->getPropertyCompetitorPrice($paramCompetitorPrice);
|
||||
|
||||
foreach ($comparisonChannels as $comparisonChannel) {
|
||||
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day] = [
|
||||
'channel' => $comparisonChannel,
|
||||
'date' => $queryDate,
|
||||
'amount' => null,
|
||||
'currency' => null
|
||||
];
|
||||
|
||||
if(!isset($queryWeekPricesDaily[$queryKeyHash][$property['id']][$day])) {
|
||||
$queryWeekPricesDaily[$queryKeyHash][$property['id']][$day] = $queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['amount'];
|
||||
}
|
||||
|
||||
if ($getPropertyCompetitorPrice['status'] && !empty($getPropertyCompetitorPrice['data']['all'])) {
|
||||
|
||||
$getPropertyCompetitorPriceChannel = $getPropertyCompetitorPrice['data']['all'];
|
||||
$getPropertyCompetitorPriceChannelCheck = collect($getPropertyCompetitorPriceChannel)->where('provider', $comparisonChannel)->first();
|
||||
|
||||
if ($getPropertyCompetitorPriceChannelCheck) {
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['amount'] = moneyDoubleFormatDecimal($getPropertyCompetitorPriceChannelCheck['amount'] * $exchangeRateUSD);
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['currency'] = 'EUR';
|
||||
|
||||
//BestPriceCheck
|
||||
|
||||
|
||||
if(empty($queryWeekPricesDaily[$queryKeyHash][$property['id']][$day])) {
|
||||
$queryWeekPricesDaily[$queryKeyHash][$property['id']][$day] = $queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['amount'];
|
||||
}elseif ($queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['amount'] < $queryWeekPricesDaily[$queryKeyHash][$property['id']][$day]) {
|
||||
$queryWeekPricesDaily[$queryKeyHash][$property['id']][$day] = $queryWeekPrices[$queryKeyHash][$property['id']][$comparisonChannel][$day]['amount'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//dd($queryWeekPrices[$queryKeyHash][$property['id']],$queryWeekPricesDaily[$queryKeyHash][$property['id']]);
|
||||
|
||||
foreach ($queryWeekPrices[$queryKeyHash][$property['id']] as $channelKey => $channelDays) {
|
||||
foreach ($channelDays as $channelDayKey => $channelDay) {
|
||||
|
||||
//dd($channelDay,$queryWeekPricesDaily[$queryKeyHash][$property['id']][$channelDayKey]);
|
||||
|
||||
|
||||
if ($queryWeekPricesDaily[$queryKeyHash][$property['id']][$channelDayKey] == $channelDay['amount'] && !is_null($channelDay['amount'])) {
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']][$channelKey][$channelDayKey]['bestPrice'] = true;
|
||||
} else {
|
||||
$queryWeekPrices[$queryKeyHash][$property['id']][$channelKey][$channelDayKey]['bestPrice'] = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' ' . $property['id'] . ' - ' . $property['name'] . ' OK!');
|
||||
|
||||
|
||||
$propertyComparisonPrice = [
|
||||
'property_id' => $property['id'],
|
||||
'week_key' => $queryKeyHash,
|
||||
'year' => $year,
|
||||
'week' => $week,
|
||||
'date' => $today,
|
||||
'data' => json_encode($queryWeekPrices[$queryKeyHash][$property['id']]),
|
||||
'status' => 1,
|
||||
'created_at' => Carbon::now()->unix(),
|
||||
'updated_at' => Carbon::now()->unix(),
|
||||
|
||||
];
|
||||
|
||||
$propertyPriceComparisonCheck = PropertyPriceComparison::where('week_key', $queryKeyHash)->where('property_id', $property['id'])->first();
|
||||
|
||||
if ($propertyPriceComparisonCheck) {
|
||||
$propertyPriceComparisonCheck = $propertyPriceComparisonCheck->toArray();
|
||||
$propertyPriceComparison = PropertyPriceComparison::where('id', $propertyPriceComparisonCheck['id'])->update($propertyComparisonPrice);
|
||||
} else {
|
||||
$propertyPriceComparison = PropertyPriceComparison::insert($propertyComparisonPrice);
|
||||
}
|
||||
|
||||
unset($queryWeekPrices[$queryKeyHash]);
|
||||
|
||||
} catch (ApiErrorException|Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' ERROR: L: ' . $e->getLine() . ' - ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
113
app/Console/Commands/Jobs/PropertyCatalogService.php
Normal file
113
app/Console/Commands/Jobs/PropertyCatalogService.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Mail\PropertyCatalogMail;
|
||||
use App\Core\Service\PropertyService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\Country;
|
||||
use App\Models\Language;
|
||||
use App\Models\vwBookingEngineSearch;
|
||||
use Barryvdh\DomPDF\PDF;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Mail\Mailer;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PropertyCatalogService extends Command
|
||||
{
|
||||
protected $signature = 'cron:property-catalog-service {property_id} {language} {--email=}';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertyService;
|
||||
|
||||
public function __construct(
|
||||
PDF $pdf,
|
||||
Mailer $mailer,
|
||||
PropertyService $propertyService
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->pdf = $pdf;
|
||||
$this->mailer = $mailer;
|
||||
$this->propertyService = $propertyService;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$pdfDataRequest = [
|
||||
'property_id' => $this->argument('property_id'),
|
||||
'locale' => $this->argument('language')
|
||||
];
|
||||
|
||||
$pdfContentService = App::make('App\Core\Service\PdfContentService');
|
||||
|
||||
$factSheetDataResponse = $pdfContentService->factSheetData($pdfDataRequest);
|
||||
if ($factSheetDataResponse['status'] != 'success') {
|
||||
throw new Exception($factSheetDataResponse['message']);
|
||||
}
|
||||
|
||||
$pageContent = $factSheetDataResponse['data'];
|
||||
$pdfLanguage = $pdfDataRequest['locale'];
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' PDF');
|
||||
|
||||
app('translator')->setLocale($pdfLanguage);
|
||||
$pdfService = $this->pdf->loadView('pdf.propertyCatalog', compact('pageContent'), [], 'UTF8');
|
||||
$pdfService->setOptions([
|
||||
'dpi' => 100,
|
||||
'isHtml5ParserEnabled' => true,
|
||||
'isRemoteEnabled' => true,
|
||||
'chroot', base_path(),
|
||||
'enable_html5_parser' => true,
|
||||
'enable_css_float' => true
|
||||
]);
|
||||
|
||||
|
||||
$hotelName = Str::slug($pageContent['name'], '_', 'en') . '_' . $pdfLanguage;
|
||||
$pathStorage = Config::get('app.fileSystemDriver') . '/property-catalog/' . $hotelName . '.pdf';
|
||||
|
||||
file_put_contents($pathStorage, $pdfService->output());
|
||||
|
||||
if ($this->option('email')) {
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' E-Mail');
|
||||
|
||||
$languageDetail = Language::where('code', $pdfLanguage)->first();
|
||||
$languageDetail = $languageDetail ? $languageDetail->toArray() : null;
|
||||
|
||||
$mailParams = [
|
||||
'email' => $this->option('email'),
|
||||
'catalogUrl' => Config::get('app.imageUrl') . '/property-catalog/' . $hotelName . '.pdf',
|
||||
'propertyName' => $pageContent['name'],
|
||||
'language' => $pdfLanguage,
|
||||
'languageText' => __($languageDetail['language_key'],[],'tr'),
|
||||
'pathStorage' => $pathStorage
|
||||
];
|
||||
|
||||
|
||||
$this->mailer->send('emails.propertyCatalogMail', ['mailParams' => $mailParams], function ($message) use ($mailParams) {
|
||||
$message->to($mailParams['email'], 'Extranetwork Property Katalog')
|
||||
->bcc(Config::get('app.logMailAddress'))
|
||||
->subject($mailParams['propertyName'] . ' Catalog - ' . $mailParams['languageText'])
|
||||
//->attach($mailParams['pathStorage'])
|
||||
->from(Config::get('app.mailSenderAddress'), 'Extranetwork');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
117
app/Console/Commands/Jobs/PropertyInvoiceService.php
Normal file
117
app/Console/Commands/Jobs/PropertyInvoiceService.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\ChannelManagerPropertyMapping;
|
||||
use App\Models\CurrencyRates;
|
||||
use App\Models\Property;
|
||||
use App\Models\PropertyPriceComparison;
|
||||
use App\Models\PropertyRoomRatePrice;
|
||||
use App\Models\vwActiveProperty;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
|
||||
class PropertyInvoiceService extends Command
|
||||
{
|
||||
protected $signature = 'cron:property-invoice-service';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertyInvoiceService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$propertyInvoiceService = App::make('App\Core\Service\PropertyInvoiceService');
|
||||
|
||||
//BULK
|
||||
/*$firstAllOfYear = '2022-01-01';
|
||||
$lastAllOfYear = '2025-10-01';
|
||||
|
||||
$startDayOfYear = Carbon::parse($firstAllOfYear)->firstOfMonth()->toDateString();
|
||||
$lastDayOfYear = Carbon::parse($lastAllOfYear)->firstOfMonth()->toDateString();
|
||||
|
||||
$diffInPeriod = Carbon::parse($startDayOfYear)->diffInMonths(Carbon::parse($lastDayOfYear));
|
||||
|
||||
$periodList = [];
|
||||
for ($i = 0; $i < $diffInPeriod; $i++) {
|
||||
$periodList[] = Carbon::parse($firstAllOfYear)->addMonths($i)->format('Y-m');
|
||||
}*/
|
||||
//$periodList[] = '2025-09';
|
||||
//BULK
|
||||
|
||||
//$invoiceWithPeriod = $propertyInvoiceService->invoiceWithPeriod(623, '2025-10');
|
||||
//dd($invoiceWithPeriod);
|
||||
//$periodList = ['2025-09'];
|
||||
|
||||
//$lastOfMonth = '2025-10-30';
|
||||
//$dayOfMonth = '2025-10-30';
|
||||
|
||||
//$lastOfMonth = Carbon::now()->lastOfMonth()->format('Y-m-d');
|
||||
//$dayOfMonth = Carbon::now()->format('Y-m-d');
|
||||
|
||||
//if ($lastOfMonth != $dayOfMonth) {
|
||||
//$this->alert(date('Y-m-d H:i:s') . ' : ' . $lastOfMonth . ' - ' . $dayOfMonth);
|
||||
//return false;
|
||||
//}
|
||||
|
||||
|
||||
//$period = Carbon::parse($dayOfMonth)->lastOfMonth()->format('Y-m');
|
||||
//$periodList = [$period];
|
||||
|
||||
$year = Carbon::now()->year;
|
||||
$currentMonth = Carbon::now()->month;
|
||||
$periodList = [];
|
||||
for ($month = $currentMonth; $month <= 12; $month++) {
|
||||
$periodList[] = Carbon::create($year, $month, 1)->format('Y-m');
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$propertyList = Property::where('commission', '>', 1)
|
||||
->whereIn('status', [1,3])
|
||||
//->whereIn('id', [1810])
|
||||
->get()->toArray();
|
||||
|
||||
foreach ($periodList as $period) {
|
||||
|
||||
$this->alert('PERIOD: ' . $period);
|
||||
|
||||
foreach ($propertyList as $property) {
|
||||
|
||||
try {
|
||||
|
||||
$invoiceWithPeriod = $propertyInvoiceService->invoiceWithPeriod($property['id'], $period);
|
||||
|
||||
if ($invoiceWithPeriod['status'] == 'success') {
|
||||
$this->info(date('Y-m-d H:i:s') . ': ' . $period . ' ' . $property['id'] . ' - ' . $property['name'] . ' : ' . $period . ' - ' . $invoiceWithPeriod['data']['total'] . ' ' . $invoiceWithPeriod['data']['currency']);
|
||||
} else {
|
||||
$this->error(date('Y-m-d H:i:s') . ': ' . $period . ' ' . $property['id'] . ' - ' . $invoiceWithPeriod['message']);
|
||||
}
|
||||
|
||||
|
||||
} catch (ApiErrorException | Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' ERROR: L: ' . $e->getLine() . ' - ' . $e->getMessage() . ' - ' . $property['id'] . ' - ' . $property['name']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
124
app/Console/Commands/Jobs/PropertySummaryService.php
Normal file
124
app/Console/Commands/Jobs/PropertySummaryService.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\ChannelManagerPropertyMapping;
|
||||
use App\Models\CurrencyRates;
|
||||
use App\Models\Property;
|
||||
use App\Models\PropertyPriceComparison;
|
||||
use App\Models\PropertyRoomRatePrice;
|
||||
use App\Models\vwActiveProperty;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
|
||||
class PropertySummaryService extends Command
|
||||
{
|
||||
protected $signature = 'cron:property-summary-service';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertySummaryService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$propertySummaryService = App::make('App\Core\Service\PropertySummaryService');
|
||||
|
||||
//BULK
|
||||
/*$firstAllOfYear = '2022-01-01';
|
||||
$lastAllOfYear = '2027-01-01';
|
||||
|
||||
$startDayOfYear = Carbon::parse($firstAllOfYear)->firstOfMonth()->toDateString();
|
||||
$lastDayOfYear = Carbon::parse($lastAllOfYear)->firstOfMonth()->toDateString();
|
||||
|
||||
$diffInPeriod = Carbon::parse($startDayOfYear)->diffInMonths(Carbon::parse($lastDayOfYear));
|
||||
|
||||
$periodList = [];
|
||||
for ($i = 0; $i < $diffInPeriod; $i++) {
|
||||
$periodList[] = Carbon::parse($firstAllOfYear)->addMonths($i)->format('Y-m');
|
||||
}*/
|
||||
//$periodList[] = '2025-09';
|
||||
//BULK
|
||||
|
||||
//$invoiceWithPeriod = $propertyInvoiceService->invoiceWithPeriod(623, '2025-10');
|
||||
//dd($invoiceWithPeriod);
|
||||
//$periodList = ['2025-09'];
|
||||
|
||||
//$lastOfMonth = '2025-10-30';
|
||||
//$dayOfMonth = '2025-10-30';
|
||||
|
||||
//$lastOfMonth = Carbon::now()->lastOfMonth()->format('Y-m-d');
|
||||
//$dayOfMonth = Carbon::now()->format('Y-m-d');
|
||||
|
||||
//if ($lastOfMonth != $dayOfMonth) {
|
||||
//$this->alert(date('Y-m-d H:i:s') . ' : ' . $lastOfMonth . ' - ' . $dayOfMonth);
|
||||
//return false;
|
||||
//}
|
||||
|
||||
|
||||
//$period = Carbon::parse($dayOfMonth)->lastOfMonth()->format('Y-m');
|
||||
//$periodList = [$period];
|
||||
|
||||
$year = Carbon::now()->year;
|
||||
$currentMonth = Carbon::now()->month;
|
||||
$periodList = [];
|
||||
for ($month = $currentMonth; $month <= 12; $month++) {
|
||||
$periodList[] = Carbon::create($year, $month, 1)->format('Y-m');
|
||||
}
|
||||
|
||||
//$periodList = ['2025-03'];
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$propertyList = Property::where('commission', '>', 1)
|
||||
->where('status', 1)
|
||||
//->whereIn('id', [71])
|
||||
->get()->toArray();
|
||||
|
||||
$types[1] = 'Checkout';
|
||||
$types[2] = 'Transaction';
|
||||
foreach ($periodList as $period) {
|
||||
|
||||
$this->alert('PERIOD: ' . $period);
|
||||
|
||||
foreach ($propertyList as $property) {
|
||||
|
||||
try {
|
||||
|
||||
foreach ($types as $typeCode => $type) {
|
||||
|
||||
$invoiceWithPeriod = $propertySummaryService->summaryWithPeriod($property['id'], $period, $typeCode);
|
||||
|
||||
if ($invoiceWithPeriod['status'] == 'success') {
|
||||
$this->info(date('Y-m-d H:i:s') . ': ' . $period . ' ' . $property['id'] . ' - ' . $property['name'] . ' : ' . $type . ' : ' . $period . ' - ' . $invoiceWithPeriod['data']['total'] . ' ' . $invoiceWithPeriod['data']['currency']);
|
||||
} else {
|
||||
$this->error(date('Y-m-d H:i:s') . ': ' . $period . ' ' . $property['id'] . ' - ' . $invoiceWithPeriod['message']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (ApiErrorException | Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' ERROR: L: ' . $e->getLine() . ' - ' . $e->getMessage() . ' - ' . $property['id'] . ' - ' . $property['name']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
386
app/Console/Commands/Jobs/SummaryReportMail.php
Normal file
386
app/Console/Commands/Jobs/SummaryReportMail.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Mail\DailyReportMail;
|
||||
use App\Core\Mail\TrialFirstMail;
|
||||
use App\Core\Mail\TrialSecondMail;
|
||||
use App\Core\Service\CurrencyService;
|
||||
use App\Core\Service\PropertyService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\PropertyInvoice;
|
||||
use App\Models\vwActiveProperty;
|
||||
use App\Models\vwBookingSummary;
|
||||
use App\Models\vwBookingSummaryAll;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Mail\Mailer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SummaryReportMail extends Command
|
||||
{
|
||||
protected $signature = 'cron:summary-report-mail';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertyService;
|
||||
|
||||
public function __construct(
|
||||
Mailer $mailer,
|
||||
PropertyService $propertyService,
|
||||
CurrencyService $currencyService
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->mailer = $mailer;
|
||||
$this->propertyService = $propertyService;
|
||||
$this->currencyService = $currencyService;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$today = Carbon::now()->subDay()->toDateString();
|
||||
|
||||
$report['daily']['data'] = [];
|
||||
$report['daily']['title'] = 'Daily Report';
|
||||
$report['daily']['period'] = Carbon::parse($today)->format('d.m.Y');
|
||||
$daily = vwBookingSummaryAll::where('time', '>', Carbon::parse($today)->toDateString())
|
||||
->where('time', '<', Carbon::parse($today)->addDay()->toDateString())
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
if ($daily) {
|
||||
$dataCollect = collect($daily);
|
||||
$dataCollect = $dataCollect->filter(function ($item) {
|
||||
if ($item['property_id'] == 362) {
|
||||
//Exclude Commission - Barın Hotel, 34 Hotelbeds, 103 World2Meet
|
||||
if (!in_array($item['channel_id'], [34, 103])) {
|
||||
return $item;
|
||||
}
|
||||
} else if ($item['property_id'] == 712) {
|
||||
//Exclude Commission - G Hotels Skopje
|
||||
if (!in_array($item['id'], [18122, 18091, 18090, 18089, 18088, 18087, 18086])) {
|
||||
return $item;
|
||||
}
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
});
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
|
||||
$report['daily']['data'][$currencyCode]['count'] = count($currencyGroup);
|
||||
$report['daily']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
|
||||
$report['daily']['data'][$currencyCode]['commission'] = array_sum(pickItemFromArray('commission', $currencyGroup));
|
||||
}
|
||||
|
||||
$report['daily']['summary'] = ['count' => 0, 'total' => 0, 'commission' => 0];
|
||||
foreach ($report['daily']['data'] as $currentCurrency => $dailyData) {
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currentCurrency, 'EUR');
|
||||
$report['daily']['summary']['count'] += $dailyData['count'];
|
||||
$report['daily']['summary']['total'] += $dailyData['total'] * $lastExchangeRate['data'];
|
||||
$report['daily']['summary']['commission'] += $dailyData['commission'] * $lastExchangeRate['data'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$report['monthly']['data'] = [];
|
||||
$report['monthly']['title'] = 'Monthly Report';
|
||||
$report['monthly']['period'] = Carbon::parse($today)->firstOfMonth()->format('m.Y');
|
||||
$monthly = vwBookingSummaryAll::where('time', '>', Carbon::parse($today)->firstOfMonth()->toDateString())
|
||||
->where('time', '<', Carbon::parse($today)->addMonth()->firstOfMonth()->toDateString())
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
if ($monthly) {
|
||||
$dataCollect = collect($monthly);
|
||||
$dataCollect = $dataCollect->filter(function ($item) {
|
||||
if ($item['property_id'] == 362) {
|
||||
//Exclude Commission - Barın Hotel, 34 Hotelbeds, 103 World2Meet
|
||||
if (!in_array($item['channel_id'], [34, 103])) {
|
||||
return $item;
|
||||
}
|
||||
} else if ($item['property_id'] == 712) {
|
||||
//Exclude Commission - G Hotels Skopje
|
||||
if (!in_array($item['id'], [18122, 18091, 18090, 18089, 18088, 18087, 18086])) {
|
||||
return $item;
|
||||
}
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
});
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
|
||||
$report['monthly']['data'][$currencyCode]['count'] = count($currencyGroup);
|
||||
$report['monthly']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
|
||||
$report['monthly']['data'][$currencyCode]['commission'] = array_sum(pickItemFromArray('commission', $currencyGroup));
|
||||
}
|
||||
|
||||
$report['monthly']['summary'] = ['count' => 0, 'total' => 0, 'commission' => 0];
|
||||
foreach ($report['monthly']['data'] as $currentCurrency => $dailyData) {
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currentCurrency, 'EUR');
|
||||
$report['monthly']['summary']['count'] += $dailyData['count'];
|
||||
$report['monthly']['summary']['total'] += $dailyData['total'] * $lastExchangeRate['data'];
|
||||
$report['monthly']['summary']['commission'] += $dailyData['commission'] * $lastExchangeRate['data'];
|
||||
}
|
||||
|
||||
|
||||
//summaryCheckout
|
||||
$monthlyCheckout = vwBookingSummaryAll::where('checkout_period', Carbon::parse($today)->firstOfMonth()->format('Y-m'))
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
$dataCollect = collect($monthlyCheckout);
|
||||
$dataCollect = $dataCollect->filter(function ($item) {
|
||||
if ($item['property_id'] == 362) {
|
||||
//Exclude Commission - Barın Hotel, 34 Hotelbeds, 103 World2Meet
|
||||
if (!in_array($item['channel_id'], [34, 103])) {
|
||||
return $item;
|
||||
}
|
||||
} else if ($item['property_id'] == 712) {
|
||||
//Exclude Commission - G Hotels Skopje
|
||||
if (!in_array($item['id'], [18122, 18091, 18090, 18089, 18088, 18087, 18086])) {
|
||||
return $item;
|
||||
}
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
});
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
|
||||
$report['monthly']['summaryCheckoutData'][$currencyCode]['count'] = count($currencyGroup);
|
||||
$report['monthly']['summaryCheckoutData'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
|
||||
$report['monthly']['summaryCheckoutData'][$currencyCode]['commission'] = array_sum(pickItemFromArray('commission', $currencyGroup));
|
||||
}
|
||||
|
||||
$report['monthly']['summaryCheckout'] = ['count' => 0, 'total' => 0, 'commission' => 0];
|
||||
foreach ($report['monthly']['summaryCheckoutData'] as $currentCurrency => $dailyData) {
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currentCurrency, 'EUR');
|
||||
$report['monthly']['summaryCheckout']['count'] += $dailyData['count'];
|
||||
$report['monthly']['summaryCheckout']['total'] += $dailyData['total'] * $lastExchangeRate['data'];
|
||||
$report['monthly']['summaryCheckout']['commission'] += $dailyData['commission'] * $lastExchangeRate['data'];
|
||||
}
|
||||
|
||||
$monthlySummary = [];
|
||||
$annuallyMonths = [];
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$annuallyMonths[] = Carbon::parse($today)->firstOfYear()->addMonths($i)->format('Y-m');
|
||||
}
|
||||
|
||||
$vwBookingSummaryTransaction = vwBookingSummaryAll::whereIn('transaction_period',$annuallyMonths)
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
$vwBookingSummaryCheckout = vwBookingSummaryAll::whereIn('checkout_period',$annuallyMonths)
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
|
||||
$vwBookingSummaryTransactionGrouped = collect($vwBookingSummaryTransaction)->groupBy('transaction_period')->toArray();
|
||||
$vwBookingSummaryCheckoutGrouped = collect($vwBookingSummaryCheckout)->groupBy('checkout_period')->toArray();
|
||||
|
||||
|
||||
$monthlySummary['month'] = [];
|
||||
foreach ($annuallyMonths as $annuallyMonth) {
|
||||
//$annuallyMonth = Carbon::parse($annuallyMonth)->format('Y-m');
|
||||
|
||||
$monthlySummary['month'][$annuallyMonth] = $annuallyMonth;
|
||||
|
||||
$monthlySummary['transaction'][$annuallyMonth]['count'] = 0;
|
||||
$monthlySummary['transaction'][$annuallyMonth]['total'] = 0;
|
||||
$monthlySummary['transaction'][$annuallyMonth]['commission'] = 0;
|
||||
if(isset($vwBookingSummaryTransactionGrouped[$annuallyMonth])) {
|
||||
$dataCollectGroupCurrency = collect($vwBookingSummaryTransactionGrouped[$annuallyMonth])->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroupCurrency as $currencyCode => $currencyGroup) {
|
||||
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currencyCode, 'EUR');
|
||||
$monthlySummary['transaction'][$annuallyMonth]['count'] += collect($currencyGroup)->count();
|
||||
$monthlySummary['transaction'][$annuallyMonth]['total'] += collect($currencyGroup)->sum('total') * $lastExchangeRate['data'];
|
||||
$monthlySummary['transaction'][$annuallyMonth]['commission'] += collect($currencyGroup)->sum('commission') * $lastExchangeRate['data'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$monthlySummary['checkout'][$annuallyMonth]['count'] = 0;
|
||||
$monthlySummary['checkout'][$annuallyMonth]['total'] = 0;
|
||||
$monthlySummary['checkout'][$annuallyMonth]['commission'] = 0;
|
||||
if(isset($vwBookingSummaryCheckoutGrouped[$annuallyMonth])) {
|
||||
$dataCollectGroupCurrency = collect($vwBookingSummaryCheckoutGrouped[$annuallyMonth])->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroupCurrency as $currencyCode => $currencyGroup) {
|
||||
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currencyCode, 'EUR');
|
||||
$monthlySummary['checkout'][$annuallyMonth]['count'] += collect($currencyGroup)->count();
|
||||
$monthlySummary['checkout'][$annuallyMonth]['total'] += collect($currencyGroup)->sum('total') * $lastExchangeRate['data'];
|
||||
$monthlySummary['checkout'][$annuallyMonth]['commission'] += collect($currencyGroup)->sum('commission') * $lastExchangeRate['data'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$report['monthlySummary'] = $monthlySummary;
|
||||
|
||||
}
|
||||
|
||||
$report['annually']['data'] = [];
|
||||
$report['annually']['title'] = 'Annually Report';
|
||||
$report['annually']['period'] = Carbon::parse($today)->firstOfYear()->format('Y');
|
||||
$annually = vwBookingSummaryAll::where('time', '>', Carbon::parse($today)->firstOfYear()->toDateString())
|
||||
->where('time', '<', Carbon::parse($today)->addYear()->firstOfYear()->toDateString())
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
if ($annually) {
|
||||
$dataCollect = collect($annually);
|
||||
$dataCollect = $dataCollect->filter(function ($item) {
|
||||
if ($item['property_id'] == 362) {
|
||||
//Exclude Commission - Barın Hotel, 34 Hotelbeds, 103 World2Meet
|
||||
if (!in_array($item['channel_id'], [34, 103])) {
|
||||
return $item;
|
||||
}
|
||||
} else if ($item['property_id'] == 712) {
|
||||
//Exclude Commission - G Hotels Skopje
|
||||
if (!in_array($item['id'], [18122, 18091, 18090, 18089, 18088, 18087, 18086])) {
|
||||
return $item;
|
||||
}
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
});
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
|
||||
$report['annually']['data'][$currencyCode]['count'] = count($currencyGroup);
|
||||
$report['annually']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
|
||||
$report['annually']['data'][$currencyCode]['commission'] = array_sum(pickItemFromArray('commission', $currencyGroup));
|
||||
}
|
||||
|
||||
$report['annually']['summary'] = ['count' => 0, 'total' => 0, 'commission' => 0];
|
||||
foreach ($report['annually']['data'] as $currentCurrency => $dailyData) {
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currentCurrency, 'EUR');
|
||||
$report['annually']['summary']['count'] += $dailyData['count'];
|
||||
$report['annually']['summary']['total'] += $dailyData['total'] * $lastExchangeRate['data'];
|
||||
$report['annually']['summary']['commission'] += $dailyData['commission'] * $lastExchangeRate['data'];
|
||||
}
|
||||
|
||||
|
||||
//summaryCheckout Annually
|
||||
|
||||
$annuallyCheckout = vwBookingSummaryAll::where('checkout_date', '>=', Carbon::parse($today)->firstOfYear()->format('Y-m-d'))
|
||||
->where('checkout_date', '<=', Carbon::parse($today)->endOfYear()->format('Y-m-d'))
|
||||
->where('commission', '>', 0)
|
||||
->get()->toArray();
|
||||
|
||||
$dataCollect = collect($annuallyCheckout);
|
||||
$dataCollect = $dataCollect->filter(function ($item) {
|
||||
if ($item['property_id'] == 362) {
|
||||
//Exclude Commission - Barın Hotel, 34 Hotelbeds, 103 World2Meet
|
||||
if (!in_array($item['channel_id'], [34, 103])) {
|
||||
return $item;
|
||||
}
|
||||
} else if ($item['property_id'] == 712) {
|
||||
//Exclude Commission - G Hotels Skopje
|
||||
if (!in_array($item['id'], [18122, 18091, 18090, 18089, 18088, 18087, 18086])) {
|
||||
return $item;
|
||||
}
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
});
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
|
||||
$report['annually']['summaryCheckoutData'][$currencyCode]['count'] = count($currencyGroup);
|
||||
$report['annually']['summaryCheckoutData'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
|
||||
$report['annually']['summaryCheckoutData'][$currencyCode]['commission'] = array_sum(pickItemFromArray('commission', $currencyGroup));
|
||||
}
|
||||
|
||||
$report['annually']['summaryCheckout'] = ['count' => 0, 'total' => 0, 'commission' => 0];
|
||||
foreach ($report['annually']['summaryCheckoutData'] as $currentCurrency => $dailyData) {
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currentCurrency, 'EUR');
|
||||
$report['annually']['summaryCheckout']['count'] += $dailyData['count'];
|
||||
$report['annually']['summaryCheckout']['total'] += $dailyData['total'] * $lastExchangeRate['data'];
|
||||
$report['annually']['summaryCheckout']['commission'] += $dailyData['commission'] * $lastExchangeRate['data'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Hotel LIST
|
||||
$vwActivePropertySummary = [];
|
||||
$vwActiveProperty = vwActiveProperty::where('commission', '>', 1)->orderByDesc('id')->get()->toArray();
|
||||
$vwActivePropertySummary['count'] = count($vwActiveProperty);
|
||||
$vwActivePropertySummary['groupByMonth'] = collect($vwActiveProperty)->sortByDesc('month')->groupBy('month')->toArray();
|
||||
$vwActivePropertySummary['lastMonth'] = collect($vwActivePropertySummary['groupByMonth'])->take(12)->toArray();
|
||||
|
||||
if ($vwActivePropertySummary['lastMonth']) {
|
||||
foreach ($vwActivePropertySummary['lastMonth'] as $lastMonthKey => $lastMonth) {
|
||||
$vwActivePropertySummary['lastMonth'][$lastMonthKey] = collect($vwActivePropertySummary['lastMonth'][$lastMonthKey])->sortByDesc('id')->toArray();
|
||||
if ($vwActivePropertySummary['lastMonth'][$lastMonthKey]) {
|
||||
$vwActivePropertySummary['lastMonth'][$lastMonthKey] = array_values($vwActivePropertySummary['lastMonth'][$lastMonthKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Hotel LIST
|
||||
|
||||
$report['activeProperty'] = $vwActivePropertySummary;
|
||||
|
||||
//Comparative Summary Data
|
||||
//Carbon::setLocale('tr');
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$months[$month] = Carbon::create(null, $month, 1)->translatedFormat('F');
|
||||
}
|
||||
$report['comparative']['monthList'] = $months;
|
||||
|
||||
$currentYear = Carbon::parse($today)->firstOfYear()->format('Y');
|
||||
$lastYear = Carbon::parse($today)->subYear()->firstOfYear()->format('Y');
|
||||
|
||||
$report['comparative']['yearList'][] = $lastYear;
|
||||
$report['comparative']['yearList'][] = $currentYear;
|
||||
|
||||
$periodList = [];
|
||||
foreach ([$currentYear,$lastYear] as $periodYear) {
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$periodList[] = $periodYear . '-' . str_pad((integer)$month, 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
$propertyInvoice = PropertyInvoice::where('status',1)->whereIn('period', $periodList);
|
||||
$propertyInvoice = $propertyInvoice ? $propertyInvoice->get()->toArray() : [];
|
||||
|
||||
foreach ($propertyInvoice as $invoice) {
|
||||
$periodYear = Carbon::parse($invoice['period'])->format('Y');
|
||||
$periodMonth = (int)Carbon::parse($invoice['period'])->format('m');
|
||||
if(!isset($report['comparative']['data'][$periodYear][$periodMonth])) {
|
||||
$report['comparative']['data'][$periodYear][$periodMonth] = 0;
|
||||
}
|
||||
$report['comparative']['data'][$periodYear][$periodMonth]+=$invoice['total'];
|
||||
}
|
||||
|
||||
$comparativeDiff = [];
|
||||
foreach ($months as $monthKey => $month) {
|
||||
$comparativeDiff[$monthKey]['amount'] = $report['comparative']['data'][$currentYear][$monthKey] - $report['comparative']['data'][$lastYear][$monthKey];
|
||||
}
|
||||
$report['comparative']['diff'] = $comparativeDiff;
|
||||
//Comparative Summary Data
|
||||
|
||||
|
||||
//$json = json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
//file_put_contents(resource_path('data/data.json'), $json);
|
||||
//die();
|
||||
|
||||
$this->mailer->onQueue('dailyReportMail', new DailyReportMail($report));
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
310
app/Console/Commands/Jobs/SummaryReportMailSales.php
Normal file
310
app/Console/Commands/Jobs/SummaryReportMailSales.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Jobs;
|
||||
|
||||
use App\Core\Mail\DailyReportMail;
|
||||
use App\Core\Mail\DailyReportMailSales;
|
||||
use App\Core\Mail\TrialFirstMail;
|
||||
use App\Core\Mail\TrialSecondMail;
|
||||
use App\Core\Service\CurrencyService;
|
||||
use App\Core\Service\PropertyService;
|
||||
use App\Core\Service\UserService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\vwActiveProperty;
|
||||
use App\Models\vwBookingSummary;
|
||||
use App\Models\vwBookingSummaryAll;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Mail\Mailer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SummaryReportMailSales extends Command
|
||||
{
|
||||
protected $signature = 'cron:summary-report-mail-sales';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
private $propertyService;
|
||||
|
||||
public function __construct(
|
||||
Mailer $mailer,
|
||||
PropertyService $propertyService,
|
||||
CurrencyService $currencyService,
|
||||
UserService $userService
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->mailer = $mailer;
|
||||
$this->propertyService = $propertyService;
|
||||
$this->currencyService = $currencyService;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
public function reportCalculate($userId, $contractUserProperty, $type)
|
||||
{
|
||||
|
||||
$today = Carbon::now()->subDay()->toDateString();
|
||||
|
||||
$report = ['data' => null, 'summary' => null];
|
||||
|
||||
|
||||
switch ($type) {
|
||||
|
||||
case 'daily':
|
||||
$vwBookingSummaryAll = vwBookingSummaryAll::where('time', '>', Carbon::parse($today)->toDateString())
|
||||
->where('time', '<', Carbon::parse($today)->addDay()->toDateString())
|
||||
->where('commission', '>', 0)
|
||||
->where('contract_user_id', $userId)
|
||||
->whereIn('property_id', $contractUserProperty)
|
||||
->get()->toArray();
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
|
||||
$monthlySummary = [];
|
||||
$annuallyMonths = [];
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$annuallyMonths[] = Carbon::parse($today)->firstOfYear()->addMonths($i)->format('Y-m');
|
||||
}
|
||||
|
||||
$vwBookingSummaryAll = vwBookingSummaryAll::whereIn('transaction_period', [Carbon::parse($today)->firstOfMonth()->format('Y-m')])
|
||||
->where('commission', '>', 0)
|
||||
->where('contract_user_id', $userId)
|
||||
->whereIn('property_id', $contractUserProperty)
|
||||
->get()->toArray();
|
||||
|
||||
$vwBookingSummaryTransaction = vwBookingSummaryAll::whereIn('transaction_period', $annuallyMonths)
|
||||
->where('commission', '>', 0)
|
||||
->where('contract_user_id', $userId)
|
||||
->whereIn('property_id', $contractUserProperty)
|
||||
->get()->toArray();
|
||||
|
||||
$vwBookingSummaryCheckout = vwBookingSummaryAll::whereIn('checkout_period', $annuallyMonths)
|
||||
->where('commission', '>', 0)
|
||||
->where('contract_user_id', $userId)
|
||||
->whereIn('property_id', $contractUserProperty)
|
||||
->get()->toArray();
|
||||
|
||||
|
||||
$vwBookingSummaryTransactionGrouped = collect($vwBookingSummaryTransaction)->groupBy('transaction_period')->toArray();
|
||||
$vwBookingSummaryCheckoutGrouped = collect($vwBookingSummaryCheckout)->groupBy('checkout_period')->toArray();
|
||||
|
||||
$monthlySummary['month'] = [];
|
||||
foreach ($annuallyMonths as $annuallyMonth) {
|
||||
$annuallyMonth = Carbon::parse($annuallyMonth)->format('Y-m');
|
||||
|
||||
$monthlySummary['month'][$annuallyMonth] = $annuallyMonth;
|
||||
|
||||
$monthlySummary['transaction'][$annuallyMonth]['count'] = 0;
|
||||
$monthlySummary['transaction'][$annuallyMonth]['total'] = 0;
|
||||
$monthlySummary['transaction'][$annuallyMonth]['commission'] = 0;
|
||||
if(isset($vwBookingSummaryTransactionGrouped[$annuallyMonth])) {
|
||||
$dataCollectGroupCurrency = collect($vwBookingSummaryTransactionGrouped[$annuallyMonth])->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroupCurrency as $currencyCode => $currencyGroup) {
|
||||
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currencyCode, 'EUR');
|
||||
$monthlySummary['transaction'][$annuallyMonth]['count'] += collect($currencyGroup)->count();
|
||||
$monthlySummary['transaction'][$annuallyMonth]['total'] += collect($currencyGroup)->sum('total') * $lastExchangeRate['data'];
|
||||
$monthlySummary['transaction'][$annuallyMonth]['commission'] += collect($currencyGroup)->sum('commission') * $lastExchangeRate['data'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$monthlySummary['checkout'][$annuallyMonth]['count'] = 0;
|
||||
$monthlySummary['checkout'][$annuallyMonth]['total'] = 0;
|
||||
$monthlySummary['checkout'][$annuallyMonth]['commission'] = 0;
|
||||
if(isset($vwBookingSummaryCheckoutGrouped[$annuallyMonth])) {
|
||||
$dataCollectGroupCurrency = collect($vwBookingSummaryCheckoutGrouped[$annuallyMonth])->groupBy('currency_code')->toArray();
|
||||
foreach ($dataCollectGroupCurrency as $currencyCode => $currencyGroup) {
|
||||
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currencyCode, 'EUR');
|
||||
$monthlySummary['checkout'][$annuallyMonth]['count'] += collect($currencyGroup)->count();
|
||||
$monthlySummary['checkout'][$annuallyMonth]['total'] += collect($currencyGroup)->sum('total') * $lastExchangeRate['data'];
|
||||
$monthlySummary['checkout'][$annuallyMonth]['commission'] += collect($currencyGroup)->sum('commission') * $lastExchangeRate['data'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$report['monthlySummary'] = $monthlySummary;
|
||||
|
||||
break;
|
||||
|
||||
case 'annually':
|
||||
$vwBookingSummaryAll = vwBookingSummaryAll::where('time', '>', Carbon::parse($today)->firstOfYear()->toDateString())
|
||||
->where('time', '<', Carbon::parse($today)->addYear()->firstOfYear()->toDateString())
|
||||
->where('commission', '>', 0)
|
||||
->where('contract_user_id', $userId)
|
||||
->whereIn('property_id', $contractUserProperty)
|
||||
->get()->toArray();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($vwBookingSummaryAll) {
|
||||
$dataCollect = collect($vwBookingSummaryAll);
|
||||
|
||||
$dataCollectGroup = $dataCollect->groupBy('property_id')->toArray();
|
||||
foreach ($dataCollectGroup as $propertyId => $propertyList) {
|
||||
|
||||
$property = reset($propertyList);
|
||||
$report['data'][$propertyId]['id'] = $property['property_id'];
|
||||
$report['data'][$propertyId]['name'] = $property['property_name'];
|
||||
|
||||
$report['data'][$propertyId]['count'] = 0;
|
||||
$report['data'][$propertyId]['total'] = 0;
|
||||
$report['data'][$propertyId]['commission'] = 0;
|
||||
|
||||
$dataCollectGroupCurrency = collect($propertyList)->groupBy('currency_code')->toArray();
|
||||
|
||||
foreach ($dataCollectGroupCurrency as $currencyCode => $currencyGroup) {
|
||||
|
||||
$lastExchangeRate = $this->currencyService->lastExchangeRate($currencyCode, 'EUR');
|
||||
|
||||
$count = collect($currencyGroup)->count();
|
||||
$total = collect($currencyGroup)->sum('total');
|
||||
$commission = collect($currencyGroup)->sum('commission');
|
||||
|
||||
$report['data'][$propertyId]['count'] += $count;
|
||||
$report['data'][$propertyId]['total'] += $total * $lastExchangeRate['data'];
|
||||
$report['data'][$propertyId]['commission'] += $commission * $lastExchangeRate['data'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$report['data'] = collect($report['data'])->sortByDesc('commission')->toArray();
|
||||
|
||||
$report['summary']['count'] = collect($report['data'])->sum('count');
|
||||
$report['summary']['total'] = collect($report['data'])->sum('total');
|
||||
$report['summary']['commission'] = collect($report['data'])->sum('commission');
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $report;
|
||||
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' START');
|
||||
|
||||
$today = Carbon::now()->subDay()->toDateString();
|
||||
|
||||
$userListIds = [904, 941, 1485];//41, 22, 883
|
||||
|
||||
$userListCriteria = [
|
||||
'criteria' => [
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'whereIn' => [
|
||||
['field' => 'id', 'value' => $userListIds]
|
||||
],
|
||||
'orderBy' => [
|
||||
['field' => 'id', 'value' => 'ASC']
|
||||
]
|
||||
];
|
||||
$userList = $this->userService->select($userListCriteria);
|
||||
|
||||
foreach ($userList['data'] as $user) {
|
||||
|
||||
$contractUserProperty = vwActiveProperty::where('contract_user_id', $user['id'])
|
||||
//->where('month', '>', '2024-10')
|
||||
->get()->toArray();
|
||||
|
||||
$contractUserProperty = $contractUserProperty ? pickItemFromArray('id',$contractUserProperty) : [];
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : '.$user['nameSurname']);
|
||||
|
||||
$report['name'] = $user['nameSurname'];
|
||||
$report['email'] = $user['email'];
|
||||
|
||||
|
||||
//DAILY
|
||||
$report['daily']['data'] = [];
|
||||
$report['daily']['title'] = 'Daily Report';
|
||||
$report['daily']['type'] = 'daily';
|
||||
$report['daily']['period'] = Carbon::parse($today)->format('d.m.Y');
|
||||
|
||||
$reportCalculate = $this->reportCalculate($user['id'], $contractUserProperty, $report['daily']['type']);
|
||||
|
||||
$report['daily']['data'] = $reportCalculate['data'];
|
||||
$report['daily']['summary'] = $reportCalculate['summary'];
|
||||
|
||||
|
||||
|
||||
|
||||
//MONTHLY
|
||||
$report['monthly']['data'] = [];
|
||||
$report['monthly']['title'] = 'Monthly Report';
|
||||
$report['monthly']['type'] = 'monthly';
|
||||
$report['monthly']['period'] = Carbon::parse($today)->firstOfMonth()->format('m.Y');
|
||||
|
||||
$reportCalculate = $this->reportCalculate($user['id'], $contractUserProperty, $report['monthly']['type']);
|
||||
|
||||
$report['monthly']['data'] = $reportCalculate['data'];
|
||||
$report['monthly']['summary'] = $reportCalculate['summary'];
|
||||
$report['monthlySummary'] = $reportCalculate['monthlySummary'];
|
||||
|
||||
|
||||
//ANNUALLY
|
||||
$report['annually']['data'] = [];
|
||||
$report['annually']['title'] = 'Annually Report';
|
||||
$report['annually']['type'] = 'annually';
|
||||
$report['annually']['period'] = Carbon::parse($today)->firstOfYear()->format('Y');
|
||||
|
||||
$reportCalculate = $this->reportCalculate($user['id'], $contractUserProperty, $report['annually']['type']);
|
||||
|
||||
$report['annually']['data'] = $reportCalculate['data'];
|
||||
$report['annually']['summary'] = $reportCalculate['summary'];
|
||||
|
||||
$report['activeProperty'] = vwActiveProperty::where('commission', '>', 1)
|
||||
->where('contract_user_id', $user['id'])
|
||||
->whereIn('id', $contractUserProperty)
|
||||
->orderByDesc('id')
|
||||
->get()->toArray();
|
||||
|
||||
|
||||
//Property Price Comparison
|
||||
$priceComparisonLink = null;
|
||||
$todayComparison = Carbon::now()->toDateString();
|
||||
$firstDayOfWeek = Carbon::parse($todayComparison)->startOfWeek(Carbon::MONDAY);
|
||||
//$firstDayOfWeek = Carbon::parse($today)->startOfWeek(Carbon::MONDAY)->toDateString();
|
||||
|
||||
//if(Carbon::now()->toDateString() == $firstDayOfWeek) {
|
||||
$year = Carbon::parse($firstDayOfWeek)->format('Y');
|
||||
$week = Carbon::parse($firstDayOfWeek)->isoWeek();
|
||||
$queryKeyHash = md5($year . '-' . $week);
|
||||
$priceComparisonLink = config('app.url').'/property-comparison/'.$queryKeyHash.'/'.$user['id'];
|
||||
//}
|
||||
$report['priceComparisonLink'] = $priceComparisonLink;
|
||||
//Property Price Comparison
|
||||
|
||||
|
||||
$this->mailer->onQueue('dailyReportSalesMail', new DailyReportMailSales($report));
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Hotel LIST
|
||||
/*$vwActivePropertySummary = [];
|
||||
$vwActiveProperty = vwActiveProperty::where('commission', '>', 1)->get()->toArray();
|
||||
$vwActivePropertySummary['count'] = count($vwActiveProperty);
|
||||
$vwActivePropertySummary['groupByMonth'] = collect($vwActiveProperty)->sortByDesc('month')->groupBy('month')->toArray();
|
||||
$vwActivePropertySummary['lastMonth'] = collect($vwActivePropertySummary['groupByMonth'])->take(3)->toArray();
|
||||
//Hotel LIST
|
||||
|
||||
$report['activeProperty'] = $vwActivePropertySummary;*/
|
||||
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user