Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

app/Console/Commands/InvoiceCreate.php

Open in GitHub
use 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 GitHub
use 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,
]);
}
}
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.