<?php

namespace App\Services;

use App\OracleDOCASNDetail;
use App\Traits\ServiceAppAop;


class OracleDocAsnDetailService
{
    use ServiceAppAop;
    protected $modelClass=OracleDocAsnDetail::class;
    const TABLE = "DOC_ASN_DETAILS";
    public function getLeftJoinBasSku(array $params){
        $query = OracleDOCASNDetail::query();
        foreach ($params as $column => $value){
            if (is_array($value)){
                $query->whereIn(self::TABLE.'.'.$column,$value);
            }
            $query->where(self::TABLE.'.'.$column,$value);
        }
        $query->selectRaw(self::TABLE.".asnno,".self::TABLE.".asnlineno,"
            .self::TABLE.".customerid,".self::TABLE.".sku,".self::TABLE.".expectedqty");
        $query->join('BAS_SKU',function ($join){
            $join->on(self::TABLE.".sku",'=','BAS_SKU.sku')
                ->on(self::TABLE.".customerid",'=',"BAS_SKU.customerid");
        },null,null,'left');
        $query->selectRaw('BAS_SKU.alternate_sku1,BAS_SKU.alternate_sku2');
        return $query->get();
    }

    public function get(array $params, $column = null){
        $query = OracleDOCASNDetail::query();
        if ($column)$query->select($column);
        foreach ($params as $column => $value){
            if (is_array($value)){
                $query->whereIn($column,$value);
            }
            $query->where($column,$value);
        }
        return $query->get();
    }
}
