1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Models/Proposal.php

140 lines
2.9 KiB
PHP
Raw Normal View History

2018-01-30 19:58:55 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait;
/**
* Class ExpenseCategory.
*/
class Proposal extends EntityModel
{
use SoftDeletes;
use PresentableTrait;
/**
* @var array
*/
protected $dates = ['deleted_at'];
2018-02-08 12:41:22 +01:00
/**
* @var string
*/
protected $presenter = 'App\Ninja\Presenters\ProposalPresenter';
2018-01-30 19:58:55 +01:00
/**
* @var array
*/
protected $fillable = [
2018-02-04 17:42:13 +01:00
'private_notes',
2018-02-04 20:34:38 +01:00
'html',
'css',
2018-01-30 19:58:55 +01:00
];
/**
* @var string
*/
//protected $presenter = 'App\Ninja\Presenters\ProjectPresenter';
/**
* @return mixed
*/
public function getEntityType()
{
return ENTITY_PROPOSAL;
}
/**
* @return string
*/
public function getRoute()
{
return "/proposals/{$this->public_id}";
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Models\Account');
}
/**
* @return mixed
*/
2018-02-07 15:16:31 +01:00
public function invoice()
2018-01-30 19:58:55 +01:00
{
return $this->belongsTo('App\Models\Invoice')->withTrashed();
}
2018-02-11 10:14:47 +01:00
/**
* @return mixed
*/
public function invitations()
{
return $this->hasMany('App\Models\ProposalInvitation')->orderBy('proposal_invitations.contact_id');
}
2018-02-07 17:20:53 +01:00
/**
* @return mixed
*/
public function proposal_invitations()
{
return $this->hasMany('App\Models\ProposalInvitation')->orderBy('proposal_invitations.contact_id');
}
2018-02-04 17:42:13 +01:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function proposal_template()
{
return $this->belongsTo('App\Models\ProposalTemplate')->withTrashed();
}
2018-01-30 19:58:55 +01:00
public function getDisplayName()
{
2018-02-08 12:41:22 +01:00
return $this->invoice->invoice_number;
2018-01-30 19:58:55 +01:00
}
2018-03-22 08:31:47 +01:00
public function getLink($forceOnsite = false, $forcePlain = false)
{
$invitation = $this->invitations->first();
return $invitation->getLink('proposal', $forceOnsite, $forcePlain);
}
public function getHeadlessLink()
{
return sprintf('%s?phantomjs=true&phantomjs_secret=%s', $this->getLink(true, true), env('PHANTOMJS_SECRET'));
}
public function getFilename($extension = 'pdf')
{
$entityType = $this->getEntityType();
return trans('texts.proposal') . '_' . $this->invoice->invoice_number . '.' . $extension;
}
2018-04-08 15:55:25 +02:00
/**
* @return string
*/
public function getCustomMessageType()
{
if ($this->invoice->quote_invoice_id) {
return CUSTOM_MESSAGE_APPROVED_PROPOSAL;
} else {
return CUSTOM_MESSAGE_UNAPPROVED_PROPOSAL;
}
}
2018-01-30 19:58:55 +01:00
}
Proposal::creating(function ($project) {
$project->setNullValues();
});
Proposal::updating(function ($project) {
$project->setNullValues();
});