<?php

namespace App\Inventory;
use App\Inventory\BillOfQuantity;
use App\Inventory\BOQItems;
use App\User;
use App\Inventory\PurchaseOrder;
use App\Branch;

use Illuminate\Database\Eloquent\Model;

class ProjectStock extends Model
{
   private $generic_condition;

   public function __construct()
    {

       $this->setCondition(['is_recycle' => '0']);
    }

    public function setCondition($condition = [])
    {
        $this->generic_condition = $condition;
    }

    public function getCondition()
    {
        return $this->generic_condition;
    }

    //
    public function transferStock($object)
      {

          return \DB::transaction(function () use ($object)  {


            $stock                    = new 	ProjectStock;
            $stock->to_branch_id      = $object['to_branch_id'];
            $stock->from_branch_id    = $object['from_branch_id'];
            $stock->stock_in_qty      = $object['stock_out_qty'];;
            $stock->stock_out_qty     = $object['stock_out_qty'];
            $stock->item_id     = $object['item_id'];
            $stock->remarks     = $object['remarks'];

            $stock->save();


            return with($stock);
          });
      }


      public function from_branch()
      {
          return $this->belongsTo(Branch::class,'from_branch_id');
      }

      public function to_branch()
      {
          return $this->belongsTo(Branch::class,'to_branch_id');
      }









}
