@extends('layout_forms')
@section('title', 'Registrar Excensiones')
@section('style')
<style type="text/css" media="screen">
    .borde-error{
        border: solid 2px #dc3545 !important;
        border-radius: 5px !important;
        width: 12px;
        height: 12px;
    }
</style>
@stop
@section('content')
<div class="col-sm-12 col-md-10 col-lg-10 col-xl-10">
    <h3 class="text-center titulo">Excensiones</h3>
    <div class="form-group row sin-salto">
        <div class="col-sm-2 col-md-2 col-lg-1 col-xl-1 superior">
            <a class="btn-sm cursor btn-primary" href="{{ route('infoPredio', encrypt($predio->id_unico)) }}" title="Volver"><i class="fa fa-arrow-left"></i></a>
        </div>
        <div class="col-sm-9 col-md-9 col-lg-10 col-xl-10">
            <h6 class="text-center marca-pagina">{{ "Predio: ".$predio->codigo_catastral}}</h6>
        </div>
    </div>
    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 superior2 tamaño-letra scroll_lateral scrollbar-primary">
        <table class="table table-striped table-condensed table-bordered" id="table" data-toggle="dataTable" data-form="deleteForm">
            <thead>
                <tr>
                    <th class="text-center">Resolución</th>
                    <th class="text-center">Fecha</th>
                    <th class="text-center">Año Inicio</th>
                    <th class="text-center">Año Final</th>
                    <th class="text-center">Porcentaje</th>
                    <th style="width: 1%">Imp</th>
                    <th style="width: 1%">Int</th>
                    <th style="width: 1%">CAS</th>
                    <th style="width: 1%">Int.CAS</th>
                    <th style="width: 1%">Desc.</th>
                    <th style="width: 1%">Pap.</th>
                    <th style="width: 1%">Sob.Bom</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <form id="form-table" method="post" accept-charset="utf-8" action="{{ route('GuardarExcesion') }}" novalidate="">
                        <input type="hidden" name="txtPredio" value="{{ encrypt($predio->id_unico) }}">
                        {{ csrf_field() }}
                        <td>
                            <input type="text" name="txtResolucion" id="txtResolucion" class="form-control" placeholder="Resolución" style="width: 75%; font-size: 10px" required="">
                        </td>
                        <td>
                            <input type="text" name="txtFecha" id="txtFecha" class="form-control" placeholder="Fecha" style="width: 75%; font-size: 10px" required="">
                        </td>
                        <td>
                            <input type="text" name="txtAnnoI" id="txtAnnoI" class="form-control anno" placeholder="Año Inicio" title="Año Inicial" style="width: 72%; font-size: 10px">
                        </td>
                        <td>
                            <input type="text" name="txtAnnoF" id="txtAnnoF" class="form-control anno" placeholder="Año Final" title="Año Final" style="width: 70%; font-size: 10px">
                        </td>
                        <td>
                            <input type="text" name="txtPorcentaje" id="txtPorcentaje" class="form-control" placeholder="%" title="Porcentaje a descontar" style="width: 70%; font-size: 10px">
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkImpuesto" class="conceptos" value="1">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkInteres" class="conceptos" value="4">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkCar" class="conceptos" value="3">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkIntCas" class="conceptos" value="8">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkDes" class="conceptos" value="5">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkPapeleria" class="conceptos" value="6">
                            </label>
                        </td>
                        <td class="text-center">
                            <label class="lblCon">
                                <input type="checkbox" name="chkConcepto[]" id="chkSobBom" class="conceptos" value="7">
                            </label>
                        </td>
                        <td class="text-center">
                            <button type="submit" id="submit" class="btn-sin icons cursor fa fa-save"></button>
                        </td>
                    </form>
                </tr>
                @foreach($data as $row)
                    <tr>
                        <td class="text-right">{{ $row->resolucion }}</td>
                        <td class="text-right">{{ $row->fecha }}</td>
                        <td class="text-right">{{ $row->annoinicial }}</td>
                        <td class="text-right">{{ $row->annofinal }}</td>
                        <td class="text-right">{{ $row->porcentajeex }}</td>
                        <td class="text-center">
                            @if(!empty($row->impuesto))
                                <input type="checkbox" name="chkConcepto[]" id="chkImpuesto" value="1" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkImpuesto" value="1">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->interes))
                                <input type="checkbox" name="chkConcepto[]" id="chkInteres" value="4" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkInteres" value="4">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->Cas))
                                <input type="checkbox" name="chkConcepto[]" id="chkCas" value="3" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkCas" value="3">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->intCas))
                                <input type="checkbox" name="chkConcepto[]" id="chkIntCas" value="8" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkIntCas" value="8">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->descuento))
                                <input type="checkbox" name="chkConcepto[]" id="chkDescuento" value="5" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkDescuento" value="5">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->papeleria))
                                <input type="checkbox" name="chkConcepto[]" id="chkPapeleria" value="6" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkPapeleria" value="6">
                            @endif
                        </td>
                        <td class="text-center">
                            @if(!empty($row->SobBom))
                                <input type="checkbox" name="chkConcepto[]" id="chkSobBom" value="7" checked="">
                            @else
                                <input type="checkbox" name="chkConcepto[]" id="chkSobBom" value="7">
                            @endif
                        </td>
                        <td></td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@stop
@section('script')
<script>
    $("#form-table").on('submit',function(e){
        var resolucion = $("#txtResolucion").val();
        var fecha      = $("#txtFecha").val();
        var annoI      = $("#txtAnnoI").val();
        var annoF      = $("#txtAnnoF").val();
        var porcentaje = $("#txtPorcentaje").val();
        var conceptos  = "";
        $(".conceptos").each(function(){
            if($(this).is(':checked')){
                conceptos += $(this).val() + ",";
            }
        });
        conceptos = conceptos.substr(0, conceptos.length - 1);

        if(resolucion.length > 0){
            $("#txtResolucion").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtResolucion").addClass('is-invalid').removeClass('is-valid');
        }

        if(fecha.length > 0){
            $("#txtFecha").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtFecha").addClass('is-invalid').removeClass('is-valid');
        }

        if(annoI.length > 0){
            $("#txtAnnoI").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtAnnoI").addClass('is-invalid').removeClass('is-valid');
        }

        if(annoF.length > 0){
            $("#txtAnnoF").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtAnnoF").addClass('is-invalid').removeClass('is-valid');
        }

        if(porcentaje.length > 0){
            $("#txtPorcentaje").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtPorcentaje").addClass('is-invalid').removeClass('is-valid');
        }

        if(conceptos.length > 0){
            $(".lblCon").removeClass('borde-error');
        }else{
            e.preventDefault();
            $(".lblCon").addClass('borde-error').removeClass('is-valid');
        }
    });
</script>
@stop