<?php

namespace App\Http\Controllers;

use App\Http\Controllers\ResponseController;
use App\Http\Controllers\EncryptionController;
use App\Http\Controllers\ResourcesController;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class PartialDeliveriesController extends Controller
{
    private $responseController;
    private $encController;
    private $resourcesController;

    public function __construct(){
        $this->responseController = new ResponseController();
        $this->encController = new EncryptionController();
        $this->resourcesController = new ResourcesController();
    }

    public function getPartialDeliveries($user, $line) {
        DB::beginTransaction();
        try {
            $getPartial = DB::table('S002V01THIOR')
                ->where('HIOR_ESOR', '=', 'Recibido Parcial')
                ->where('HIOR_NULI', '=', $line)
                ->get([
                    'HIOR_IDHO',
                    'HIOR_NUOR',
                    'HIOR_ESOR',
                    'HIOR_DESC',
                    'HIOR_EVID',
                    'HIOR_POEN',
                    'HIOR_ESTA',
                    'HIOR_USRE',
                    'HIOR_FERE',
                    'HIOR_USMO',
                    'HIOR_FEMO',
                ]);
        } catch (\Throwable $th) {
            DB::rollBack();
            return $this->responseController->makeResponse(true, "ERR_PARTIAL_DELIVERIES_REG004: Ocurrió un error al momento de obtener los registros.", $th->getMessage(), 500);
        }
        DB::commit();
        return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getPartial);
    }
}
