@extends('adminlte::page')

@section('title', 'Informe Deudas')

@section('content')
    <br>
    <form id="reimprecion_form" method="post" enctype="multipart/form-data">
        @csrf
        <div class="card card-warning" id="my-card">
            <div class="card-header">
                <h3 class="card-title"><strong> Datos de Búsqueda</strong></h3>
            </div>
            <div class="card-body">
                <div class="row">
                    <input name="_token" type="hidden" class="form-control" id="_token" value="{{ csrf_token() }}">
                    <div class="col-sm-3">
                        <div class="form-group">
                            <label>Tipo Documento</label>
                            <select class="form-control" name='tipodoc' id="tipodoc">
                                <option value="D">Deuda</option>
                                <option value="P">Pago</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <label>Numero Documento</label>
                            <input type="text" class="form-control" placeholder="0" name='numerodoc' id="numerodoc">
                        </div>

                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <label></label>
                            <button type="submit" class="btn btn-dark toastrDefaultSuccess m-4"> <i class="fas fa-search">
                                    Generar Documento</i></button>
                        </div>

                    </div>
                </div>

            </div>
        </div>

    </form>
@stop


@section('js')
    <script>
        $("form#reimprecion_form").submit(function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            $.ajax({
                url: '/deudas/ReimpresionDocumento',
                type: 'POST',
                data: formData,
                success: function(data) {
                    if (data.status == 'ok') {
                        if ($('#tipodoc').val() == 'D') {
                            window.open(`/reimprecion/${$('#tipodoc').val()}/${data.iddeuda}`);
                        } else {
                            window.open(`/reimprecion/${$('#tipodoc').val()}/${$('#numerodoc').val()}`);
                        }
                    } else {
                        toastr.error(data.message);
                    }
                },
                cache: false,
                contentType: false,
                processData: false,
            });

        });
    </script>
@stop
