118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?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');
|
|
|
|
|
|
}
|
|
}
|