1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/PurchaseOrder.php

497 lines
23 KiB
PHP
Raw Normal View History

2022-05-29 04:05:12 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-05-29 04:05:12 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2022-06-06 14:27:17 +02:00
use App\Helpers\Invoice\InvoiceSum;
use App\Helpers\Invoice\InvoiceSumInclusive;
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
2022-05-29 04:05:12 +02:00
use App\Services\PurchaseOrder\PurchaseOrderService;
2022-06-02 04:41:44 +02:00
use App\Utils\Ninja;
2022-06-13 11:59:24 +02:00
use App\Utils\Traits\MakesDates;
2022-05-29 04:05:12 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
2022-06-02 04:41:44 +02:00
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
2022-05-29 04:05:12 +02:00
2023-03-08 08:33:42 +01:00
/**
* App\Models\PurchaseOrder
*
* @property int $id
* @property int|null $client_id
* @property int $user_id
* @property int|null $assigned_user_id
* @property int $company_id
* @property int $status_id
* @property int|null $project_id
* @property int|null $vendor_id
* @property int|null $recurring_id
* @property int|null $design_id
* @property int|null $invoice_id
* @property string|null $number
* @property float $discount
* @property bool $is_amount_discount
* @property string|null $po_number
* @property string|null $date
* @property string|null $last_sent_date
* @property string|null $due_date
* @property int $is_deleted
* @property object|null $line_items
* @property object|null $backup
* @property string|null $footer
* @property string|null $public_notes
* @property string|null $private_notes
* @property string|null $terms
* @property string|null $tax_name1
* @property string $tax_rate1
* @property string|null $tax_name2
* @property string $tax_rate2
* @property string|null $tax_name3
* @property string $tax_rate3
* @property string $total_taxes
* @property int $uses_inclusive_taxes
* @property string|null $reminder1_sent
* @property string|null $reminder2_sent
* @property string|null $reminder3_sent
* @property string|null $reminder_last_sent
* @property string|null $custom_value1
* @property string|null $custom_value2
* @property string|null $custom_value3
* @property string|null $custom_value4
* @property string|null $next_send_date
* @property string|null $custom_surcharge1
* @property string|null $custom_surcharge2
* @property string|null $custom_surcharge3
* @property string|null $custom_surcharge4
* @property int $custom_surcharge_tax1
* @property int $custom_surcharge_tax2
* @property int $custom_surcharge_tax3
* @property int $custom_surcharge_tax4
* @property string $exchange_rate
* @property string $balance
* @property string|null $partial
* @property string $amount
* @property string $paid_to_date
* @property string|null $partial_due_date
* @property string|null $last_viewed
* @property int|null $deleted_at
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $expense_id
* @property int|null $currency_id
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \App\Models\User|null $assigned_user
* @property-read \App\Models\Client|null $client
* @property-read \App\Models\Company $company
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read int|null $documents_count
* @property-read \App\Models\Expense|null $expense
* @property-read mixed $hashed_id
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read int|null $history_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read int|null $invitations_count
* @property-read \App\Models\Invoice|null $invoice
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read int|null $invoices_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read int|null $payments_count
* @property-read \App\Models\Project|null $project
* @property-read \App\Models\User $user
* @property-read \App\Models\Vendor|null $vendor
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Database\Factories\PurchaseOrderFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereAssignedUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereBackup($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereBalance($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereClientId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCompanyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCurrencyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurcharge1($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurcharge2($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurcharge3($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurcharge4($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurchargeTax1($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurchargeTax2($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurchargeTax3($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomSurchargeTax4($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomValue1($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomValue2($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomValue3($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereCustomValue4($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereDesignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereDiscount($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereDueDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereExchangeRate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereExpenseId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereFooter($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereInvoiceId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereIsAmountDiscount($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereIsDeleted($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereLastSentDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereLastViewed($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereLineItems($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereNextSendDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePaidToDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePartial($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePartialDueDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePoNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePrivateNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereProjectId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder wherePublicNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereRecurringId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereReminder1Sent($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereReminder2Sent($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereReminder3Sent($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereReminderLastSent($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereStatusId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxName1($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxName2($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxName3($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxRate1($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxRate2($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTaxRate3($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTerms($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereTotalTaxes($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereUsesInclusiveTaxes($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder whereVendorId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder withoutTrashed()
2023-03-16 05:20:38 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
2023-03-24 02:12:12 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-27 05:47:01 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
2023-03-29 04:13:50 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
2023-04-10 09:37:40 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
2023-03-29 04:13:50 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
2023-03-29 05:23:06 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
2023-03-27 05:47:01 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-27 22:47:07 +02:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
2023-03-24 02:12:12 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
2023-03-24 08:02:34 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
2023-03-16 05:20:38 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
2023-03-21 12:37:06 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
2023-03-16 05:20:38 +01:00
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
2023-03-08 08:33:42 +01:00
* @mixin \Eloquent
*/
2022-05-29 04:05:12 +02:00
class PurchaseOrder extends BaseModel
{
use Filterable;
use SoftDeletes;
2022-06-13 11:59:24 +02:00
use MakesDates;
2022-05-29 04:05:12 +02:00
protected $fillable = [
'number',
'discount',
'status_id',
'last_sent_date',
'is_deleted',
'po_number',
'date',
'due_date',
'terms',
'public_notes',
'private_notes',
'tax_name1',
'tax_rate1',
'tax_name2',
'tax_rate2',
'tax_name3',
'tax_rate3',
'total_taxes',
'uses_inclusive_taxes',
'is_amount_discount',
'partial',
'recurring_id',
'next_send_date',
'reminder1_sent',
'reminder2_sent',
'reminder3_sent',
'reminder_last_sent',
'partial_due_date',
'project_id',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
'backup',
'footer',
'line_items',
'client_id',
'custom_surcharge1',
'custom_surcharge2',
'custom_surcharge3',
'custom_surcharge4',
'design_id',
'invoice_id',
'assigned_user_id',
'exchange_rate',
'balance',
'partial',
'paid_to_date',
'vendor_id',
2022-11-24 07:23:36 +01:00
'last_viewed',
'currency_id',
2022-05-29 04:05:12 +02:00
];
protected $casts = [
'line_items' => 'object',
'backup' => 'object',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
'is_amount_discount' => 'bool',
];
const STATUS_DRAFT = 1;
const STATUS_SENT = 2;
2022-06-14 14:18:20 +02:00
const STATUS_ACCEPTED = 3;
2022-07-07 03:20:43 +02:00
const STATUS_RECEIVED = 4;
const STATUS_CANCELLED = 5;
2022-05-29 04:05:12 +02:00
2022-06-13 11:59:24 +02:00
public static function stringStatus(int $status)
{
switch ($status) {
case self::STATUS_DRAFT:
return ctrans('texts.draft');
break;
case self::STATUS_SENT:
return ctrans('texts.sent');
break;
2022-06-14 14:18:20 +02:00
case self::STATUS_ACCEPTED:
return ctrans('texts.accepted');
2022-06-13 11:59:24 +02:00
break;
case self::STATUS_CANCELLED:
return ctrans('texts.cancelled');
break;
// code...
break;
}
}
2022-06-13 12:34:40 +02:00
public static function badgeForStatus(int $status)
{
switch ($status) {
case self::STATUS_DRAFT:
return '<h5><span class="badge badge-light">'.ctrans('texts.draft').'</span></h5>';
break;
case self::STATUS_SENT:
return '<h5><span class="badge badge-primary">'.ctrans('texts.sent').'</span></h5>';
break;
2022-06-14 14:18:20 +02:00
case self::STATUS_ACCEPTED:
return '<h5><span class="badge badge-primary">'.ctrans('texts.accepted').'</span></h5>';
2022-06-13 12:34:40 +02:00
break;
case self::STATUS_CANCELLED:
return '<h5><span class="badge badge-secondary">'.ctrans('texts.cancelled').'</span></h5>';
break;
default:
// code...
break;
}
}
2023-02-01 05:00:45 +01:00
public function getEntityType()
{
return self::class;
}
2022-06-13 12:34:40 +02:00
2022-05-29 04:05:12 +02:00
public function assigned_user()
{
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
}
public function vendor()
{
return $this->belongsTo(Vendor::class)->withTrashed();
2022-05-29 04:05:12 +02:00
}
public function history()
{
return $this->hasManyThrough(Backup::class, Activity::class);
}
public function activities()
{
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50);
}
public function company()
{
return $this->belongsTo(Company::class);
}
2022-07-06 11:25:22 +02:00
public function expense()
{
2022-07-07 08:13:37 +02:00
return $this->belongsTo(Expense::class);
2022-07-06 11:25:22 +02:00
}
2022-05-29 04:05:12 +02:00
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
}
public function client()
{
return $this->belongsTo(Client::class)->withTrashed();
}
2022-06-02 04:41:44 +02:00
public function markInvitationsSent()
{
$this->invitations->each(function ($invitation) {
if (! isset($invitation->sent_date)) {
$invitation->sent_date = Carbon::now();
2023-02-01 05:00:45 +01:00
$invitation->saveQuietly();
2022-06-02 04:41:44 +02:00
}
});
}
public function pdf_file_path($invitation = null, string $type = 'path', bool $portal = false)
{
if (! $invitation) {
2023-02-16 02:36:09 +01:00
if ($this->invitations()->exists()) {
2022-06-02 04:41:44 +02:00
$invitation = $this->invitations()->first();
2023-02-16 02:36:09 +01:00
} else {
2022-06-02 04:41:44 +02:00
$this->service()->createInvitations();
$invitation = $this->invitations()->first();
}
}
2022-05-29 04:05:12 +02:00
2023-02-16 02:36:09 +01:00
if (!$invitation) {
2022-06-02 04:41:44 +02:00
throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?');
2023-02-16 02:36:09 +01:00
}
2022-06-02 04:41:44 +02:00
$file_path = $this->vendor->purchase_order_filepath($invitation).$this->numberFormatter().'.pdf';
2022-06-02 04:41:44 +02:00
2023-02-16 02:36:09 +01:00
if (Ninja::isHosted() && $portal && Storage::disk(config('filesystems.default'))->exists($file_path)) {
2022-06-02 04:41:44 +02:00
return Storage::disk(config('filesystems.default'))->{$type}($file_path);
2023-02-16 02:36:09 +01:00
} elseif (Ninja::isHosted() && $portal) {
$file_path = (new CreatePurchaseOrderPdf($invitation, config('filesystems.default')))->handle();
2022-06-02 04:41:44 +02:00
return Storage::disk(config('filesystems.default'))->{$type}($file_path);
}
2023-02-16 02:36:09 +01:00
if (Storage::disk('public')->exists($file_path)) {
2022-06-02 04:41:44 +02:00
return Storage::disk('public')->{$type}($file_path);
2023-02-16 02:36:09 +01:00
}
2022-06-02 04:41:44 +02:00
2022-09-07 06:15:27 +02:00
$file_path = (new CreatePurchaseOrderPdf($invitation))->handle();
2022-06-02 04:41:44 +02:00
return Storage::disk('public')->{$type}($file_path);
}
2022-05-29 04:05:12 +02:00
public function invitations()
{
2022-06-02 04:41:44 +02:00
return $this->hasMany(PurchaseOrderInvitation::class);
2022-05-29 04:05:12 +02:00
}
public function project()
{
return $this->belongsTo(Project::class)->withTrashed();
}
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
/** @return PurchaseOrderService */
public function service() :PurchaseOrderService
2022-05-29 04:05:12 +02:00
{
2022-06-06 14:27:17 +02:00
return new PurchaseOrderService($this);
2022-05-29 04:05:12 +02:00
}
public function invoices()
{
return $this->belongsToMany(Invoice::class)->using(Paymentable::class);
}
public function payments()
{
return $this->morphToMany(Payment::class, 'paymentable');
}
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
2022-06-06 14:27:17 +02:00
public function calc()
{
$purchase_order_calc = null;
if ($this->uses_inclusive_taxes) {
$purchase_order_calc = new InvoiceSumInclusive($this);
} else {
$purchase_order_calc = new InvoiceSum($this);
}
return $purchase_order_calc->build();
}
2022-07-16 08:15:31 +02:00
public function translate_entity()
{
return ctrans('texts.purchase_order');
}
2022-05-29 04:05:12 +02:00
}