From 62f587d7e669755638579c78e6c8e25765c53ca5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 5 Mar 2022 11:05:35 +1100 Subject: [PATCH] Fix invoice generation and other minor cosmetic items --- app/Console/Commands/InvoiceEmail.php | 12 ++---------- app/Console/Commands/InvoiceGenerate.php | 18 +++++------------- app/Models/Account.php | 5 +++++ app/Models/Rtm.php | 2 -- app/Models/Service.php | 2 +- resources/views/email/user/invoice.blade.php | 2 +- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/Console/Commands/InvoiceEmail.php b/app/Console/Commands/InvoiceEmail.php index 10ad69a..48e4a83 100644 --- a/app/Console/Commands/InvoiceEmail.php +++ b/app/Console/Commands/InvoiceEmail.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; use Illuminate\Console\Command; @@ -23,16 +24,6 @@ class InvoiceEmail extends Command */ protected $description = 'Email Invoices to be client'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @@ -41,6 +32,7 @@ class InvoiceEmail extends Command public function handle() { $o = Invoice::findOrFail($this->argument('id')); + Config::set('site',$o->account->site); Mail::to($o->account->user->email)->send(new \App\Mail\InvoiceEmail($o)); diff --git a/app/Console/Commands/InvoiceGenerate.php b/app/Console/Commands/InvoiceGenerate.php index 7a9fb18..db62232 100644 --- a/app/Console/Commands/InvoiceGenerate.php +++ b/app/Console/Commands/InvoiceGenerate.php @@ -2,10 +2,10 @@ namespace App\Console\Commands; -use App\Models\Account; -use App\Models\Invoice; -use Carbon\Carbon; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Config; + +use App\Models\{Account,Invoice}; class InvoiceGenerate extends Command { @@ -23,16 +23,6 @@ class InvoiceGenerate extends Command */ protected $description = 'Generate Invoices to be Sent'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @@ -46,6 +36,8 @@ class InvoiceGenerate extends Command $accounts = Account::active()->get(); foreach ($accounts as $o) { + Config::set('site',$o->site); + $io = new Invoice; $io->account_id = $o->id; diff --git a/app/Models/Account.php b/app/Models/Account.php index 5ffcbe9..ef238aa 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -91,6 +91,11 @@ class Account extends Model implements IDs return $active ? $query->active() : $query; } + public function site() + { + return $this->belongsTo(Site::class); + } + public function taxes() { return $this->hasMany(Tax::class,'country_id','country_id'); diff --git a/app/Models/Rtm.php b/app/Models/Rtm.php index d57ddb9..53d9d21 100644 --- a/app/Models/Rtm.php +++ b/app/Models/Rtm.php @@ -8,6 +8,4 @@ class Rtm extends Model { protected $table = 'ab_rtm'; public $timestamps = FALSE; - - } \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index 2875b55..5779f4f 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -618,7 +618,7 @@ class Service extends Model implements IDs // Two Yearly case 5: - if (!$this->product->price_recur_strict) + if (! $this->product->price_recur_strict) $date = $this->getInvoiceNextAttribute()->addYear(2)->subDay(); else { $date = $this->getInvoiceNextAttribute()->addYear(2)->subDay()->endOfYear(); diff --git a/resources/views/email/user/invoice.blade.php b/resources/views/email/user/invoice.blade.php index 7c3f481..07cb466 100644 --- a/resources/views/email/user/invoice.blade.php +++ b/resources/views/email/user/invoice.blade.php @@ -7,7 +7,7 @@ A new invoice has been generated on your account. A summary of that invoice is b | # | ID | Name | Amount | | -: | - |:-----| ------:| @foreach ($invoice->products() as $po) -| {{ $po->count }} | {{ $po->product_id }} | {{ $po->name($invoice->account->user->language) }} | ${{ number_format($invoice->items->filter(function($item) use ($po) {return $item->product_id == $po->id; })->sum('total'),$invoice->currency()->rounding) }} | +| {{ $po->count }} | {{ $po->product_id }} | {{ $po->name }} | ${{ number_format($invoice->items->filter(function($item) use ($po) {return $item->product_id == $po->id; })->sum('total'),$invoice->currency()->rounding) }} | @endforeach ||| Sub Total | ${{ $invoice->sub_total }} | ||| Tax | ${{ $invoice->tax_total }} |