regenerate invoices for 2023

This commit is contained in:
Omair Saleh
2023-08-16 16:47:11 +08:00
parent 4b476d0bf7
commit 2e32ce3059
2 changed files with 46 additions and 6 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
use App\Classes\Modules\Transactions\Processors\GeneratesGroupTransactionsWhiteForm;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class GenerateInvoice implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** @var Booking */
private $booking;
/**
* @param Booking $booking
*/
public function __construct(Booking $booking)
{
$this->booking = $booking;
}
public function handle()
{
$this->booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete();
$this->booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete();
$this->booking->status = ApprovalStatus::APPROVED;
$this->booking->save();
(App()->make(CreateInvoiceTransactionProcessor::class))->execute($this->booking);
}
}
+3 -6
View File
@@ -1,5 +1,6 @@
<?php
use App\Classes\Jobs\GenerateInvoice;
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
use App\Http\Controllers\Accounting\BankStatementController;
use Carbon\Carbon;
@@ -469,12 +470,8 @@ Route::get('/invoice/fix', function(){
$bookings = Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get();
foreach($bookings as $booking){
$booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete();
$booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete();
$booking->status = ApprovalStatus::APPROVED;
$booking->save();
(App()->make(CreateInvoiceTransactionProcessor::class))->execute($booking);
GenerateInvoice::dispatch($booking);
return 'Invoice fixing job dispatched.';
}
})->name('invoice.fix');