mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-29 01:14:04 +00:00
63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use App\Classes\Modules\Jobs\DataTransferObjects\FixInvoiceV2CommandObject;
|
|
use App\Classes\Modules\Transactions\Processors\CreateShippingInvoiceTransactionDocProcessor;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\CompanyConnection;
|
|
use App\Models\Order;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FixInvoiceV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var FixInvoiceV2CommandObject*/
|
|
private $fixInvoiceV2CommandObject;
|
|
|
|
/**
|
|
* FixInvoiceV2CommandJob constructor.
|
|
* @param FixInvoiceV2CommandObject $fixInvoiceV2CommandObject
|
|
*/
|
|
public function __construct(FixInvoiceV2CommandObject $fixInvoiceV2CommandObject)
|
|
{
|
|
$this->fixInvoiceV2CommandObject = $fixInvoiceV2CommandObject;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Fix invoice.');
|
|
$start = new Carbon();
|
|
|
|
$connection = CompanyConnection::where('invitee_reference', $this->fixInvoiceV2CommandObject->getMarking())->first();
|
|
$company_module_id = $connection->invitee->id;
|
|
|
|
$orders = Order::where('company_module_id', $company_module_id)->get();
|
|
|
|
foreach ($orders as $order){
|
|
$invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get();
|
|
foreach ($invoices as $invoice){
|
|
|
|
dump($invoice->id);
|
|
|
|
// $invoice->documents()->delete();
|
|
$invoice->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->delete();
|
|
|
|
(App()->make(CreateShippingInvoiceTransactionDocProcessor::class))->execute($invoice);
|
|
}
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Fix invoice. ElapsedTime: ' . $elapsedTime . '.');
|
|
}
|
|
}
|