-
app/Console/Commands/InvoiceCreate.php
Open in GitHubuse App\Services\InvoiceCreatorService; use Illuminate\Console\Command; class InvoiceCreate extends Command { protected $signature = 'invoice:create'; protected $description = 'Auto Invoice Create'; public function __construct() { parent::__construct(); } public function handle(InvoiceCreatorService $invoiceCreatorService) { $invoiceCreatorService->execute(); } }
-
app/Services/InvoiceCreatorService.php
Open in GitHubuse App\Models\Company; use App\Models\Invoice; use App\Models\Package; use App\Models\PaymentPlan; class InvoiceCreatorService { public function execute() { $invoices = Invoice::where('end_date', '<', now())->get(); foreach ($invoices as $invoice) { $billing = Invoice::where('companyId', $invoice->companyId)->orderBy('id', 'desc')->first(); $company = Company::find($billing->companyId); $paymentPlan = PaymentPlan::find($company->info->planId); $package = Package::where('planId', $company->info->planId)->first(); if ($company->status == 1 && $billing->end_date < now() ) { Invoice::create([ 'price' => $package->price, 'total_amount' => $package->price, 'start_date' => now(), 'end_date' => now()->addMonths($paymentPlan->month), 'companyId' => $billing->companyId, 'packageId' => $package->id, ]); } } } }