<?php

namespace Tests\Services\OrderIssueService\OrderIssueTagTest;

use App\OracleDOCOrderHeader;
use App\Order;
use App\OrderIssue;
use App\OrderPackage;
use App\Services\OrderIssueService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class OrderIssueTagTest extends TestCase
{
    /** @var OrderIssueService $service */
    public $service;
    public function setUp(): void
    {
        $this->service = app(OrderIssueService::class);
        parent::setUp();
    }

    public function testOrderIssueTag()
    {
        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('AddTime')->first();
        $orderNos = OracleDOCOrderHeader::query()
            ->where('AddTime','>=',$orderHeader->addtime)
            ->where('sostatus',99)
            ->get()
            ->map(function($orderHeader){
                return $orderHeader->orderno;
            });
        $orderNo_arr = collect($orderNos)->chunk(5)->toArray();
        $orderNos  = $orderNo_arr[0];
        $this->assertNotNull($orderNos);
        $arr = [];
        $arr['orderNos'] = $orderNos;
        $arr['typeId'] = 0;
        $arr['result_explain'] = '';
        $this->service->orderIssueTag($arr);
        $orderIssue = OrderIssue::query()->whereHas('order',function($query)use($orderNos){
            $query->whereIn('code',$orderNos);
        })->get();
        $this->assertEquals($orderIssue->count(),count($orderNos));
    }
}
