$activities * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder withoutTrashed() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() * @mixin \Eloquent */ class PurchaseOrder extends BaseModel { use Filterable; use SoftDeletes; use MakesDates; protected $hidden = [ 'id', 'private_notes', 'user_id', 'vendor_id', 'company_id', ]; 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', 'last_viewed', 'currency_id', ]; protected $casts = [ 'line_items' => 'object', 'backup' => 'object', 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', 'is_amount_discount' => 'bool', 'e_invoice' => 'object', ]; public const STATUS_DRAFT = 1; public const STATUS_SENT = 2; public const STATUS_ACCEPTED = 3; public const STATUS_RECEIVED = 4; public const STATUS_CANCELLED = 5; public static function stringStatus(int $status) { switch ($status) { case self::STATUS_DRAFT: return ctrans('texts.draft'); case self::STATUS_SENT: return ctrans('texts.sent'); case self::STATUS_ACCEPTED: return ctrans('texts.accepted'); case self::STATUS_CANCELLED: return ctrans('texts.cancelled'); default: return ctrans('texts.sent'); } } public static function badgeForStatus(int $status) { switch ($status) { case self::STATUS_DRAFT: return '
'.ctrans('texts.draft').'
'; case self::STATUS_SENT: return '
'.ctrans('texts.sent').'
'; case self::STATUS_ACCEPTED: return '
'.ctrans('texts.accepted').'
'; case self::STATUS_CANCELLED: return '
'.ctrans('texts.cancelled').'
'; default: return '
'.ctrans('texts.sent').'
'; } } public function getEntityType() { return self::class; } public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Vendor::class)->withTrashed(); } public function history(): \Illuminate\Database\Eloquent\Relations\HasManyThrough { return $this->hasManyThrough(Backup::class, Activity::class); } public function activities(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50); } public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Company::class); } public function expense(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Expense::class)->withTrashed(); } public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class)->withTrashed(); } public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Client::class)->withTrashed(); } public function currency(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Currency::class); } public function markInvitationsSent(): void { $this->invitations->each(function ($invitation) { if (! isset($invitation->sent_date)) { $invitation->sent_date = Carbon::now(); $invitation->saveQuietly(); } }); } public function invitations(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(PurchaseOrderInvitation::class); } public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Project::class)->withTrashed(); } public function invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Invoice::class); } /** @return PurchaseOrderService */ public function service(): PurchaseOrderService { return new PurchaseOrderService($this); } public function invoices(): \Illuminate\Database\Eloquent\Relations\BelongsToMany { return $this->belongsToMany(Invoice::class)->using(Paymentable::class); } public function payments(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany(Payment::class, 'paymentable'); } public function documents(): \Illuminate\Database\Eloquent\Relations\MorphMany { return $this->morphMany(Document::class, 'documentable'); } /** * Access the invoice calculator object. * * @return InvoiceSumInclusive | InvoiceSum The invoice calculator object getters */ public function calc(): InvoiceSumInclusive | InvoiceSum { $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(); } public function translate_entity(): string { return ctrans('texts.purchase_order'); } public function typeIdString($id): string { $type = ''; match($id) { '1' => $type = ctrans('texts.product'), '2' => $type = ctrans('texts.service'), '3' => $type = ctrans('texts.gateway_fees'), '4' => $type = ctrans('texts.gateway_fees'), '5' => $type = ctrans('texts.late_fees'), '6' => $type = ctrans('texts.expense'), default => $type = ctrans('texts.product'), }; return $type; } public function taxTypeString($id): string { $tax_type = ''; match(intval($id)) { Product::PRODUCT_TYPE_PHYSICAL => $tax_type = ctrans('texts.physical_goods'), Product::PRODUCT_TYPE_SERVICE => $tax_type = ctrans('texts.services'), Product::PRODUCT_TYPE_DIGITAL => $tax_type = ctrans('texts.digital_products'), Product::PRODUCT_TYPE_SHIPPING => $tax_type = ctrans('texts.shipping'), Product::PRODUCT_TYPE_EXEMPT => $tax_type = ctrans('texts.tax_exempt'), Product::PRODUCT_TYPE_REDUCED_TAX => $tax_type = ctrans('texts.reduced_tax'), Product::PRODUCT_TYPE_OVERRIDE_TAX => $tax_type = ctrans('texts.override_tax'), Product::PRODUCT_TYPE_ZERO_RATED => $tax_type = ctrans('texts.zero_rated'), Product::PRODUCT_TYPE_REVERSE_TAX => $tax_type = ctrans('texts.reverse_tax'), default => $tax_type = ctrans('texts.physical_goods'), }; return $tax_type; } }