1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/models/Client.php

123 lines
2.1 KiB
PHP
Raw Normal View History

2013-11-26 13:45:07 +01:00
<?php
2013-12-04 17:20:14 +01:00
class Client extends EntityModel
2013-11-26 13:45:07 +01:00
{
2013-12-05 16:23:24 +01:00
protected $hidden = array('id', 'account_id', 'created_at', 'updated_at', 'deleted_at', 'notes', 'last_login');
2013-12-03 23:00:01 +01:00
2013-11-26 13:45:07 +01:00
public static $fieldName = 'Client - Name';
public static $fieldPhone = 'Client - Phone';
public static $fieldAddress1 = 'Client - Street';
public static $fieldAddress2 = 'Client - Apt/Floor';
public static $fieldCity = 'Client - City';
public static $fieldState = 'Client - State';
public static $fieldPostalCode = 'Client - Postal Code';
public static $fieldNotes = 'Client - Notes';
2013-12-01 21:58:25 +01:00
public static $fieldCountry = 'Client - Country';
2013-11-26 13:45:07 +01:00
public function account()
{
return $this->belongsTo('Account');
}
public function invoices()
{
return $this->hasMany('Invoice');
}
2013-12-07 19:45:00 +01:00
public function payments()
{
return $this->hasMany('Payment');
}
2013-11-26 13:45:07 +01:00
public function contacts()
{
return $this->hasMany('Contact');
}
2013-11-29 13:09:21 +01:00
2013-12-01 21:58:25 +01:00
public function country()
{
return $this->belongsTo('Country');
}
public function getName()
{
return $this->name;
}
public function getEntityType()
{
return ENTITY_CLIENT;
}
2013-11-29 13:09:21 +01:00
public function getAddress()
{
$str = '';
if ($this->address1) {
$str .= $this->address1 . '<br/>';
}
if ($this->address2) {
$str .= $this->address2 . '<br/>';
}
if ($this->city) {
$str .= $this->city . ', ';
}
if ($this->state) {
$str .= $this->state . ' ';
}
if ($this->postal_code) {
$str .= $this->postal_code;
}
2013-12-01 21:58:25 +01:00
if ($this->country) {
$str .= '<br/>' . $this->country->name;
}
2013-11-29 13:09:21 +01:00
if ($str)
{
$str = '<p>' . $str . '</p>';
}
return $str;
}
public function getPhone()
{
$str = '';
if ($this->work_phone)
{
2013-12-07 21:33:07 +01:00
$str .= '<i class="fa fa-phone" style="width: 20px"></i>' . Utils::formatPhoneNumber($this->work_phone);
2013-11-29 13:09:21 +01:00
}
return $str;
}
public function getNotes()
{
$str = '';
if ($this->notes)
{
$str .= '<i>' . $this->notes . '</i>';
}
return $str;
}
2013-12-01 08:33:17 +01:00
public function getDateCreated()
2013-12-02 13:22:29 +01:00
{
2013-12-01 08:33:17 +01:00
if ($this->created_at == '0000-00-00 00:00:00')
{
return '---';
}
else
{
return $this->created_at->format('m/d/y h:i a');
}
}
2013-11-26 22:45:10 +01:00
}
Client::created(function($client)
{
Activity::createClient($client);
});