<?php

namespace App;

class PurchaseOrder extends Master
{
  protected $appends = ['status_display'];

  protected $table='purchase_orders';

  protected $fillable = array('folio', 'subtotal', 'total', 'status', 'customer_id', 'created_by_id');

  protected $hidden = ['created_at','updated_at'];

  const PENDING = 1;
  const APPROVED = 2;
  const CANCELLED = 3;
  const PAID = 4;

  public function getStatusDisplayAttribute()
  {
    switch ($this->status) {
      case 1:
      return 'Pendiente';
      case 2:
      return 'Aprobado';
      case 3:
      return 'Cancelado';
      case 4:
      return 'Pagado';
    }
  }

  public function details()
	{
		return $this->hasMany('App\PurchaseOrderDetail');
	}

  public function created_by()
  {
    return $this->belongsTo('App\User', 'created_by_id');
  }

  public function customer()
  {
    return $this->belongsTo('App\Customer');
  }
}
