<?php


namespace Tests\Services\StoreItemService;


use App\OracleBasCode;
use App\OracleDOCASNHeader;
use App\Owner;
use App\Services\OwnerService;
use App\Services\StoreItemService;
use App\Services\StoreService;
use App\Services\WarehouseService;
use App\Warehouse;
use Tests\TestCase;

class GetByWmsTest extends TestCase
{
    /**
     * @var StoreService $service
     * @var OwnerService $ownerService
     * @var WarehouseService $warehouseService
     *
     */
    public $service;
    public $asnHeaders;
    private $data=[];
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->service=app(StoreItemService::class);
        $this->data['warehouse']  = factory(Warehouse::class)->create(['code'=>'test_wh']);
        $this->data['owner'] = factory(Owner::class)->create(['code'=>'test_owner','name'=>'测试货主']);
        $wmsAsnHeader = factory(OracleDOCASNHeader::class)->make([
            'customerid'=>'test_owner','warehouseid'=>'test_wh','asntype'=>'CSRK','asnstatus'=>'11',
        ]);
        $asnType  = factory(OracleBasCode::class)->make(['codeid'=>'ASN_TYP','code'=>'CSRK','descr_c'=>'测试入库']);
        $asnStatus = factory(OracleBasCode::class)->make(['code'=>'11', 'codeid'=>'ASN_STS', 'codename_c'=>'测试状态']);
        $wmsAsnHeader->setRelation('asnType',$asnType);
        $wmsAsnHeader->setRelation('asnStatus',$asnStatus);
        $this->asnHeaders=collect();
        $this->asnHeaders->add($wmsAsnHeader);
//        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
//        $this->asnHeaders=OracleDOCASNHeader::query()
//            ->with(['asnType', 'asnStatus'])
//            ->where('addTime', '>=',$startDate)
//            ->get();
    }
    public function testGetParamsByAsnHeader()
    {
        if (empty($this->asnHeaders)) return null;
        $asnDetails=$this->service->getAsnDetailsByAsnHerder($this->asnHeaders);
        if(!$asnDetails){
            $storeItems=$this->service->getByWms($asnDetails);
            $this->assertNull($storeItems);
        }else{
            $storeItems=$this->service->getByWms($asnDetails);
            $this->assertNotNull($storeItems);
        }

    }
    public function tearDown(): void
    {
        $this->data['owner']->delete();
        $this->data['warehouse']->delete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
