<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;
class SaleStockModel extends Model
{
  
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table = "nso007_sale_stock";
    protected $fillable = ['sale_receive'];
	public function itemhouse(){
        return ItemModel::whereIn('id',explode(',',SaleStockDetailModel::where('saledetail_saleid',$this->id)->select(DB::raw('group_concat(saledetail_itemid) As item_id'))->first()->item_id))->select(DB::Raw('group_concat(item_house) As item_name'))->first()->item_name;
    }
    public function itemname(){
        return ItemModel::whereIn('id',explode(',',SaleStockDetailModel::where('saledetail_saleid',$this->id)->select(DB::raw('group_concat(saledetail_itemid) As item_id'))->first()->item_id))->select(DB::Raw('group_concat(item_name) As item_name'))->first()->item_name;
    }
    public function landsize(){
        return ItemModel::whereIn('id',explode(',',SaleStockDetailModel::where('saledetail_saleid',$this->id)->select(DB::raw('group_concat(saledetail_itemid) As item_id'))->first()->item_id))->select(DB::Raw('SUM(item_size_land) As land_size'))->first()->land_size;
    }
    public function housesize(){
        return ItemModel::whereIn('id',explode(',',SaleStockDetailModel::where('saledetail_saleid',$this->id)->select(DB::raw('group_concat(saledetail_itemid) As item_id'))->first()->item_id))->select(DB::Raw('SUM(item_size_house) As house_size'))->first()->house_size;
    }
    public function itemid(){
        return SaleStockDetailModel::select(DB::Raw('group_concat(saledetail_itemid) As ids'))->where('saledetail_saleid',$this->id)->ids;
    }
}