<?php

namespace Tests\Services\OrderService\SyncOrderTest;

use App\Logistic;
use App\Owner;
use App\Services\common\DataHandlerService;
use App\Services\LogisticService;
use App\OracleDOCOrderHeader;
use App\Services\OracleDOCOrderHeaderService;
use App\Services\OrderService;
use App\Services\OwnerService;
use App\Services\ShopService;
use App\Services\WarehouseService;
use App\Shop;
use App\Warehouse;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class SyncOrderTest extends TestCase
{
    /**
     * @var OrderService $service
     * @var OracleDOCOrderHeaderService $orderHeaderService
     * @var DataHandlerService $dataHandlerService
     * @var OwnerService $ownerService
     * @var LogisticService $logisticService
     * @var ShopService $shopService
     * @var WarehouseService $warehouseService
     */
    public $service;
    public $orderHeaderService;
    public $dataHandlerService;
    public $ownerService;
    public $logisticService;
    public $shopService;
    public $warehouseService;
    public function setUp(): void
    {
        parent::setUp();
        $this->service=app(OrderService::class);
        $this->orderHeaderService=app(OracleDOCOrderHeaderService::class);
    }
    public function testCreateOrUpdateOrderInfo()
    {
        $carbon =Carbon::now()->subHours(1);
        $date = '2020-05-18 18:13:50';
        $orderHeader = OracleDOCOrderHeader::query()->selectRaw(implode(',',OracleDOCOrderHeaderService::$columns))
            ->with(['oracleBASCustomer'=>function($query){
                $query->selectRaw('BAS_CUSTOMER.CustomerID,BAS_CUSTOMER.Customer_Type,BAS_CUSTOMER.Descr_C,BAS_CUSTOMER.Active_Flag');
            },'oracleDOCOrderDetails'=>function($query){
                $query->selectRaw('doc_order_details.orderNo,doc_order_details.customerid,doc_order_details.sku,doc_order_details.QtyOrdered');
            }, 'actAllocationDetails'=>function($query){
                $query->selectRaw('ACT_Allocation_Details.AllocationDetailsID,ACT_Allocation_Details.OrderNo,ACT_Allocation_Details.Qty_Each,ACT_Allocation_Details.PickToTraceID,ACT_Allocation_Details.CustomerID,ACT_Allocation_Details.Sku');
            },'oracleBASCode'=>function($query){
                $query->selectRaw('BAS_Codes.CodeID,BAS_Codes.CodeName_C,BAS_Codes.Code');
            }])
//            ->where('DOC_Order_Header.addTime','>=',$startDate)
//            ->where('orderno','SO201112029795')
            ->where('DOC_Order_Header.addTime','>=',$carbon)
            ->get();
        $this->service->syncOrder($orderHeader);
        $order = $this->service->getByWmsOrders($orderHeader);
        $this->assertNotNull($order);
        $this->assertNotNull($orderHeader);
    }
}
