From 259a28099fa2f39a4289775d876d5b4fb3d56fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Sat, 7 Dec 2019 12:33:49 +0100 Subject: [PATCH] Various fixes (#3136) --- app/Factory/CompanyFactory.php | 14 ++-- .../Requests/Product/CreateProductRequest.php | 4 +- app/Jobs/Client/StoreClient.php | 11 +-- app/Models/Invoice.php | 72 +++++++++---------- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/app/Factory/CompanyFactory.php b/app/Factory/CompanyFactory.php index b9a1a53467af..334d9e048a96 100644 --- a/app/Factory/CompanyFactory.php +++ b/app/Factory/CompanyFactory.php @@ -19,19 +19,21 @@ class CompanyFactory { use MakesHash; - public static function create(int $account_id) :Company + /** + * @param int $account_id + * @return Company + */ + public function create(int $account_id) :Company { - $company = new Company; -// $company->name = ''; + // $company->name = ''; $company->account_id = $account_id; $company->company_key = $this->createHash(); $company->settings = CompanySettings::defaults(); $company->db = config('database.default'); $company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3']; $company->domain = ''; - + return $company; - } -} \ No newline at end of file +} diff --git a/app/Http/Requests/Product/CreateProductRequest.php b/app/Http/Requests/Product/CreateProductRequest.php index a1080dbad078..455701769461 100644 --- a/app/Http/Requests/Product/CreateProductRequest.php +++ b/app/Http/Requests/Product/CreateProductRequest.php @@ -31,7 +31,7 @@ class CreateProductRequest extends Request { return [ 'product_key' => 'required', - ] + ]; } -} \ No newline at end of file +} diff --git a/app/Jobs/Client/StoreClient.php b/app/Jobs/Client/StoreClient.php index 9e5771e0ed8f..d47165a248d8 100644 --- a/app/Jobs/Client/StoreClient.php +++ b/app/Jobs/Client/StoreClient.php @@ -30,7 +30,8 @@ class StoreClient /** * Create a new job instance. * - * @return void + * @param array $data + * @param Client $client */ public function __construct(array $data, Client $client) @@ -43,10 +44,12 @@ class StoreClient /** * Execute the job. * - * @return void + * @param ClientRepository $client_repo + * @param ClientContactRepository $client_contact_repo + * @return Client|null */ - public function handle(ClientRepository $client_repo, ClientContactRepository $client_contact_repo) : ?Client - + public function handle(ClientRepository $client_repo, ClientContactRepository $client_contact_repo) : ?Client { + $client = $client_repo->save($this->data, $this->client); $contacts = $client_contact_repo->save($data['contacts']), $client); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 9c491703b705..2c9056efbb56 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -41,7 +41,7 @@ class Invoice extends BaseModel use MakesDates; use PresentableTrait; use MakesInvoiceValues; - + protected $presenter = 'App\Models\Presenters\InvoicePresenter'; protected $hidden = [ @@ -109,7 +109,7 @@ class Invoice extends BaseModel const STATUS_UNPAID = -2; const STATUS_REVERSED = -3; - + public function getStatusAttribute() { @@ -125,7 +125,7 @@ class Invoice extends BaseModel return $this->status_id; } - + public function company() { return $this->belongsTo(Company::class); @@ -140,7 +140,7 @@ class Invoice extends BaseModel { return $this->belongsTo(User::class ,'assigned_user_id', 'id')->withTrashed(); } - + public function invitations() { return $this->hasMany(InvoiceInvitation::class); @@ -171,9 +171,9 @@ class Invoice extends BaseModel /* ---------------- */ /** - * If True, prevents an invoice from being + * If True, prevents an invoice from being * modified once it has been marked as sent - * + * * @return boolean isLocked */ public function isLocked() : bool @@ -181,30 +181,30 @@ class Invoice extends BaseModel return $this->client->getSetting('lock_sent_invoices'); } - /** - * Determines if invoice overdue. - * - * @param float $balance The balance - * @param date. $due_date The due date - * - * @return boolean True if overdue, False otherwise. - */ - public static function isOverdue($balance, $due_date) - { - if (! $this->formatValue($balance,2) > 0 || ! $due_date) { - return false; - } - - // it isn't considered overdue until the end of the day - return strtotime($this->createClientDate(date(), $this->client->timezone()->name)) > (strtotime($due_date) + (60 * 60 * 24)); - } +// /** +// * Determines if invoice overdue. +// * +// * @param float $balance The balance +// * @param date. $due_date The due date +// * +// * @return boolean True if overdue, False otherwise. +// */ +// public static function isOverdue($balance, $due_date) +// { +// if (! $this->formatValue($balance,2) > 0 || ! $due_date) { +// return false; +// } +// +// // it isn't considered overdue until the end of the day +// return strtotime($this->createClientDate(date(), $this->client->timezone()->name)) > (strtotime($due_date) + (60 * 60 * 24)); +// } public function markViewed() :void { $this->last_viewed = Carbon::now()->format('Y-m-d H:i'); $this->save(); } - + public function isPayable() : bool { @@ -243,10 +243,10 @@ class Invoice extends BaseModel break; case Invoice::STATUS_UNPAID: return '
'.ctrans('texts.unpaid').'
'; - break; + break; case Invoice::STATUS_REVERSED: return '
'.ctrans('texts.reversed').'
'; - break; + break; default: # code... break; @@ -255,7 +255,7 @@ class Invoice extends BaseModel /** * Returns the template for the invoice - * + * * @return string Either the template view, OR the template HTML string * @todo this needs attention, invoice->settings needs clarification */ @@ -269,7 +269,7 @@ class Invoice extends BaseModel /** * Access the invoice calculator object - * + * * @return object The invoice calculator object getters */ public function calc() @@ -280,7 +280,7 @@ class Invoice extends BaseModel $invoice_calc = new InvoiceSumInclusive($this); else $invoice_calc = new InvoiceSum($this); - + return $invoice_calc->build(); } @@ -307,7 +307,7 @@ class Invoice extends BaseModel CreateInvoicePdf::dispatchNow($this); } - return $storage_path; + return $storage_path; } /** @@ -350,7 +350,7 @@ class Invoice extends BaseModel /** * Clear partial fields - * @return void + * @return void */ public function clearPartial() : void { @@ -365,11 +365,11 @@ class Invoice extends BaseModel public function updateBalance($balance_adjustment) { - if ($this->is_deleted) + if ($this->is_deleted) return; - + $balance_adjustment = floatval($balance_adjustment); - + $this->balance = $this->balance + $balance_adjustment; if($this->balance == 0) { @@ -408,7 +408,7 @@ class Invoice extends BaseModel event(new InvoiceWasMarkedSent($this)); UpdateClientBalance::dispatchNow($this->client, $this->balance); - + $this->save(); } @@ -428,4 +428,4 @@ class Invoice extends BaseModel }); } -} \ No newline at end of file +}