<?php

namespace Tests\Services\OrderPackageService\SyncPackageByOrderHeadersTest;

use App\Services\OracleDOCOrderHeaderService;
use App\Services\OrderPackageService;
use App\Services\OrderService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class SyncPackageByOrderHeadersTest extends TestCase
{
    /**
     * @var OrderPackageService $service
     * @var OracleDOCOrderHeaderService $orderHeaderService
     * @var OrderService $orderService
     */
    public $service;
    public $orderService;
    public $orderHeaderService;

    public function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderPackageService');
        $this->orderService = app('OrderService');
        $this->orderHeaderService = app('OracleDOCOrderHeaderService');
    }
    public function testSyncPackageByOrderHeaders()
    {
        /**
         * createOrDeletePackageByOrderHeader($orderHeaders)
         */
        $carbon = Carbon::now()->subHours(10);
        $date = '2020-09-18 18:13:50';
        $orderHeaders = $this->orderHeaderService->getWMSOrderOnStartDate($carbon);
        if ($orderHeaders->count() == 0) {
            var_dump('查询数据为空');
            return;
        }
        $this->service->syncPackageByOrderHeaders($orderHeaders);
        $packages = $this->service->getByWmsOrders($orderHeaders);
        $order_nos = array_unique(data_get($orderHeaders, '*.actAllocationDetails.*.picktotraceid'));
        foreach ($order_nos as $order_no) {
            $this->assertNotEmpty($packages->where('logistic_number', $order_no));

        }
    }
}
