Various fixes (#3136)

This commit is contained in:
Benjamin Beganović 2019-12-07 12:33:49 +01:00 committed by David Bomba
parent d07c11ef62
commit 259a28099f
4 changed files with 53 additions and 48 deletions

View File

@ -19,19 +19,21 @@ class CompanyFactory
{ {
use MakesHash; 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 = new Company;
// $company->name = ''; // $company->name = '';
$company->account_id = $account_id; $company->account_id = $account_id;
$company->company_key = $this->createHash(); $company->company_key = $this->createHash();
$company->settings = CompanySettings::defaults(); $company->settings = CompanySettings::defaults();
$company->db = config('database.default'); $company->db = config('database.default');
$company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3']; $company->custom_fields = (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3'];
$company->domain = ''; $company->domain = '';
return $company; return $company;
} }
} }

View File

@ -31,7 +31,7 @@ class CreateProductRequest extends Request
{ {
return [ return [
'product_key' => 'required', 'product_key' => 'required',
] ];
} }
} }

View File

@ -30,7 +30,8 @@ class StoreClient
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @return void * @param array $data
* @param Client $client
*/ */
public function __construct(array $data, Client $client) public function __construct(array $data, Client $client)
@ -43,10 +44,12 @@ class StoreClient
/** /**
* Execute the job. * 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); $client = $client_repo->save($this->data, $this->client);
$contacts = $client_contact_repo->save($data['contacts']), $client); $contacts = $client_contact_repo->save($data['contacts']), $client);

View File

@ -41,7 +41,7 @@ class Invoice extends BaseModel
use MakesDates; use MakesDates;
use PresentableTrait; use PresentableTrait;
use MakesInvoiceValues; use MakesInvoiceValues;
protected $presenter = 'App\Models\Presenters\InvoicePresenter'; protected $presenter = 'App\Models\Presenters\InvoicePresenter';
protected $hidden = [ protected $hidden = [
@ -109,7 +109,7 @@ class Invoice extends BaseModel
const STATUS_UNPAID = -2; const STATUS_UNPAID = -2;
const STATUS_REVERSED = -3; const STATUS_REVERSED = -3;
public function getStatusAttribute() public function getStatusAttribute()
{ {
@ -125,7 +125,7 @@ class Invoice extends BaseModel
return $this->status_id; return $this->status_id;
} }
public function company() public function company()
{ {
return $this->belongsTo(Company::class); return $this->belongsTo(Company::class);
@ -140,7 +140,7 @@ class Invoice extends BaseModel
{ {
return $this->belongsTo(User::class ,'assigned_user_id', 'id')->withTrashed(); return $this->belongsTo(User::class ,'assigned_user_id', 'id')->withTrashed();
} }
public function invitations() public function invitations()
{ {
return $this->hasMany(InvoiceInvitation::class); 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 * modified once it has been marked as sent
* *
* @return boolean isLocked * @return boolean isLocked
*/ */
public function isLocked() : bool public function isLocked() : bool
@ -181,30 +181,30 @@ class Invoice extends BaseModel
return $this->client->getSetting('lock_sent_invoices'); return $this->client->getSetting('lock_sent_invoices');
} }
/** // /**
* Determines if invoice overdue. // * Determines if invoice overdue.
* // *
* @param float $balance The balance // * @param float $balance The balance
* @param date. $due_date The due date // * @param date. $due_date The due date
* // *
* @return boolean True if overdue, False otherwise. // * @return boolean True if overdue, False otherwise.
*/ // */
public static function isOverdue($balance, $due_date) // public static function isOverdue($balance, $due_date)
{ // {
if (! $this->formatValue($balance,2) > 0 || ! $due_date) { // if (! $this->formatValue($balance,2) > 0 || ! $due_date) {
return false; // return false;
} // }
//
// it isn't considered overdue until the end of the day // // 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)); // return strtotime($this->createClientDate(date(), $this->client->timezone()->name)) > (strtotime($due_date) + (60 * 60 * 24));
} // }
public function markViewed() :void public function markViewed() :void
{ {
$this->last_viewed = Carbon::now()->format('Y-m-d H:i'); $this->last_viewed = Carbon::now()->format('Y-m-d H:i');
$this->save(); $this->save();
} }
public function isPayable() : bool public function isPayable() : bool
{ {
@ -243,10 +243,10 @@ class Invoice extends BaseModel
break; break;
case Invoice::STATUS_UNPAID: case Invoice::STATUS_UNPAID:
return '<h5><span class="badge badge-warning">'.ctrans('texts.unpaid').'</span></h5>'; return '<h5><span class="badge badge-warning">'.ctrans('texts.unpaid').'</span></h5>';
break; break;
case Invoice::STATUS_REVERSED: case Invoice::STATUS_REVERSED:
return '<h5><span class="badge badge-info">'.ctrans('texts.reversed').'</span></h5>'; return '<h5><span class="badge badge-info">'.ctrans('texts.reversed').'</span></h5>';
break; break;
default: default:
# code... # code...
break; break;
@ -255,7 +255,7 @@ class Invoice extends BaseModel
/** /**
* Returns the template for the invoice * Returns the template for the invoice
* *
* @return string Either the template view, OR the template HTML string * @return string Either the template view, OR the template HTML string
* @todo this needs attention, invoice->settings needs clarification * @todo this needs attention, invoice->settings needs clarification
*/ */
@ -269,7 +269,7 @@ class Invoice extends BaseModel
/** /**
* Access the invoice calculator object * Access the invoice calculator object
* *
* @return object The invoice calculator object getters * @return object The invoice calculator object getters
*/ */
public function calc() public function calc()
@ -280,7 +280,7 @@ class Invoice extends BaseModel
$invoice_calc = new InvoiceSumInclusive($this); $invoice_calc = new InvoiceSumInclusive($this);
else else
$invoice_calc = new InvoiceSum($this); $invoice_calc = new InvoiceSum($this);
return $invoice_calc->build(); return $invoice_calc->build();
} }
@ -307,7 +307,7 @@ class Invoice extends BaseModel
CreateInvoicePdf::dispatchNow($this); CreateInvoicePdf::dispatchNow($this);
} }
return $storage_path; return $storage_path;
} }
/** /**
@ -350,7 +350,7 @@ class Invoice extends BaseModel
/** /**
* Clear partial fields * Clear partial fields
* @return void * @return void
*/ */
public function clearPartial() : void public function clearPartial() : void
{ {
@ -365,11 +365,11 @@ class Invoice extends BaseModel
public function updateBalance($balance_adjustment) public function updateBalance($balance_adjustment)
{ {
if ($this->is_deleted) if ($this->is_deleted)
return; return;
$balance_adjustment = floatval($balance_adjustment); $balance_adjustment = floatval($balance_adjustment);
$this->balance = $this->balance + $balance_adjustment; $this->balance = $this->balance + $balance_adjustment;
if($this->balance == 0) { if($this->balance == 0) {
@ -408,7 +408,7 @@ class Invoice extends BaseModel
event(new InvoiceWasMarkedSent($this)); event(new InvoiceWasMarkedSent($this));
UpdateClientBalance::dispatchNow($this->client, $this->balance); UpdateClientBalance::dispatchNow($this->client, $this->balance);
$this->save(); $this->save();
} }
@ -428,4 +428,4 @@ class Invoice extends BaseModel
}); });
} }
} }