@extends('layouts.app')
@section('content')
    <div class="container">
        @if(count($errors) > 0)
        <div class="alert alert-danger" role="alert">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
        @endif

        <p>
            <h4 style="float: right"><b>Rebajar Material de Almacen</b></h4>
        </p><br><br>

        <form action="{{ url('/Rebajes') }}" method="post" class="form-horizontal">
            {{ csrf_field() }}
            <div class="form-row">
                
                <div class="col-md-4 mb-3">
                    <label class="control-label" for="id_material">{{ 'Material' }}</label>
                    <select class="form-control {{ $errors->has('id_material')?'is-invalid':'' }}" name="id_material" id="id_material">
                        <option value="">{{ '-- Seleccione el Material' }}</option>
                        @foreach ($materiales as $material)
                            <option value="{{ $material['id_material'] }}">{{ $material['nombre'] }}</option>
                        @endforeach
                    </select>
                    {!! $errors->first('id_material', '<div class="invalid-feedback">:message</div>') !!}
                </div>

                <div class="col-md-3 mb-3">
                    <label class="control-label" for="id_personal">{{ 'Responsable:' }}</label>
                    <select class="form-control {{ $errors->has('id_personal')?'is-invalid':'' }}" name="id_personal" id="id_personal">
                        <option value="">{{ '-- Seleccionar Responsable --' }}</option>
                        @foreach ($personales as $personal)
                            <option value="{{ $personal['id_personal'] }}">{{ $personal['apellidos'] }} RUT: {{ $personal['rut'] }}</option>
                        @endforeach
                    </select>
                    {!! $errors->first('id_personal', '<div class="invalid-feedback">:message</div>') !!}
                </div>

                <div class="col-md-4 mb-3">
                    <label class="control-label" for="cantidad_rebaje">{{ 'Cantidad de Rebaje' }}</label>
                    <input class="form-control {{ $errors->has('cantidad_rebaje')?'is-invalid':'' }}" type="number" name="cantidad_rebaje" id="cantidad_rebaje" min="1" max="100">
                    {!! $errors->first('cantidad_rebaje', '<div class="invalid-feedback">:message</div>') !!}
                </div>

                <div class="col-md-3 mb-3">
                    <label class="control-label" for="motivo_rebaje">{{ 'Motivo de Rebaje' }}</label>
                    <select class="form-control {{ $errors->has('motivo_rebaje')?'is-invalid':'' }}" name="motivo_rebaje" id="motivo_rebaje">
                        <option value="">{{ '-- Seleccionar Motivo --' }}</option>
                        <option value="Robo">{{ 'Robo' }}</option>
                        <option value="Extravio">{{ 'Extravío' }}</option>
                        <option value="Material con Defecto">{{ 'Material con Defecto' }}</option>
                    </select>
                    {!! $errors->first('motivo_rebaje', '<div class="invalid-feedback">:message</div>') !!}
                </div>

                <div class="col-md-4 mb-3">
                    <label class="control-label" for="fecha_rebaje">{{ 'Fecha de Rebaje' }}</label>
                    <input class="form-control {{ $errors->has('fecha_rebaje')?'is-invalid':'' }}" type="date" name="fecha_rebaje" id="fecha_rebaje">
                    {!! $errors->first('fecha_rebaje', '<div class="invalid-feedback">:message</div>') !!}
                </div>
            </div>

            <div style="float: right">
                <a href="{{ url('/Rebajes') }}" class="btn btn-primary">Cancelar</a>
                <input type="submit" value="Agregar" class="btn btn-success">
            </div>
        </form>
    </div>
@endsection