2013-11-26 13:45:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Account extends Eloquent
|
|
|
|
{
|
|
|
|
protected $softDelete = true;
|
2013-12-03 23:00:01 +01:00
|
|
|
protected $hidden = array('ip', 'timezone_id', 'created_at', 'updated_at', 'deleted_at', 'key', 'last_login');
|
2013-11-26 13:45:07 +01:00
|
|
|
|
|
|
|
public function users()
|
|
|
|
{
|
|
|
|
return $this->hasMany('User');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clients()
|
|
|
|
{
|
|
|
|
return $this->hasMany('Client');
|
|
|
|
}
|
|
|
|
|
2013-12-01 13:22:08 +01:00
|
|
|
public function invoices()
|
|
|
|
{
|
|
|
|
return $this->hasMany('Invoice');
|
|
|
|
}
|
|
|
|
|
2013-11-26 13:45:07 +01:00
|
|
|
public function account_gateways()
|
|
|
|
{
|
|
|
|
return $this->hasMany('AccountGateway');
|
|
|
|
}
|
|
|
|
|
2013-12-01 21:58:25 +01:00
|
|
|
public function country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Country');
|
2013-12-02 13:22:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function timezone()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Timezone');
|
2013-12-01 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
2013-12-15 13:55:50 +01:00
|
|
|
public function date_format()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('DateFormat');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function datetime_format()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('DatetimeFormat');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-26 13:45:07 +01:00
|
|
|
public function isGatewayConfigured($gatewayId = 0)
|
|
|
|
{
|
|
|
|
if ($gatewayId)
|
|
|
|
{
|
|
|
|
return $this->getGatewayConfig($gatewayId) != false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return count($this->account_gateways) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGatewayConfig($gatewayId)
|
|
|
|
{
|
|
|
|
foreach ($this->account_gateways as $gateway)
|
|
|
|
{
|
|
|
|
if ($gateway->gateway_id == $gatewayId)
|
|
|
|
{
|
|
|
|
return $gateway;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLogoPath()
|
|
|
|
{
|
2013-12-04 17:20:14 +01:00
|
|
|
return 'logo/' . $this->account_key . '.jpg';
|
2013-11-26 13:45:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getLogoWidth()
|
|
|
|
{
|
|
|
|
list($width, $height) = getimagesize($this->getLogoPath());
|
|
|
|
return $width;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLogoHeight()
|
|
|
|
{
|
|
|
|
list($width, $height) = getimagesize($this->getLogoPath());
|
|
|
|
return $height;
|
|
|
|
}
|
2013-12-01 13:22:08 +01:00
|
|
|
|
|
|
|
public function getNextInvoiceNumber()
|
2013-12-10 18:18:35 +01:00
|
|
|
{
|
|
|
|
$order = Invoice::withTrashed()->scope(false, $this->id)->orderBy('invoice_number', 'DESC')->first();
|
2013-12-01 13:22:08 +01:00
|
|
|
|
|
|
|
if ($order)
|
|
|
|
{
|
|
|
|
$number = intval($order->invoice_number) + 1;
|
2013-12-01 21:58:25 +01:00
|
|
|
return str_pad($number, 4, "0", STR_PAD_LEFT);
|
2013-12-01 13:22:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return DEFAULT_INVOICE_NUMBER;
|
|
|
|
}
|
|
|
|
}
|
2013-11-26 13:45:07 +01:00
|
|
|
}
|