<?php

namespace App\Listeners;

use App\Events\receiveorderitem;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

use App\Models\POReceives;

use Auth;

class saveItemReceived
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(receiveorderitem $event): void
    {
      //  dd($event);
        $POReceives = new POReceives();
        $POReceives->PurchaseCtrlNum = $event->receivedOrder->OrderCtrlNum;
        $POReceives->Item = $event->receivedOrder->ItemCtrlNum;
        $POReceives->QtyReceived = $event->receivedOrder->ReceivedQty;
        
        $POReceives->store = Auth()->user()->store;
        $POReceives->ApplyDate  = $event->receivedOrder->ApplyDate;
        
        $POReceives->UserId = Auth()->user()->id;
        $POReceives->save();
    }
}
