<?php

namespace App\Service;
use App\Models\QualityCheck;
use App\Models\QualityCheckItem;
use Log;
use Auth;
use Carbon\Carbon;

class QualityCheckService
{
    public function qualityCheckItem($request,$qualityCheck){

        if(isset($request['items'])){
            
            foreach ($request['items'] as $key => $item) {

                $data=[
                    'item_id','item_name','item_param_id', 'expected_value', 'actual_value',
                    'checked_by','remarks', 'attachments'
                ];
                
                foreach ($data as $key => $value) {
                    if(isset($item[$value]) && $item[$value]!=null && $item[$value]!=''){
                        $obj[$value]=$item[$value];
                    }
                }
                
                $obj['qc_id'] = $qualityCheck['id'];

                $qualityCheckItem=QualityCheckItem::create($obj);

            }
        
            return true;
        }
    }

}