@extends('layouts.app')

@section('title',"Editar recibo")

@section('content')
	@section('scripts_url')
	<script src="{!! asset('assets/file/js/piexif.min.js') !!}" type="text/javascript"></script>
	<link href="{!! asset('assets/file/css/fileinput.min.css') !!}" rel="stylesheet" type="text/css">
    <script src="{!! asset('assets/file/js/fileinput.min.js') !!}"></script>
	<script>
		// url para consultas
		const cambiourl = "{{ url('tcambio') }}",
			  tipdocurl = "{{ url('tipdoc') }}",
			  url_local = "{{ url('rphonorarios') }}",
			  modalsurl="{{ url('compras/modals')}}";
	</script>
	@endsection
	@if (session('create'))
	    <div class="alert alert-success">
	        {{ session('create') }}
	    </div>
	@endif
<div class="alert alert-secundary p-2 mb-0"><a href="{{ url('rphonorarios') }}"><i class="icon-arrow-left13"></i> Volver al listado de Recibos</a></div>
<div class="card">
	<ul class="nav nav-tabs nav-tabs-highlight">
			<li class="nav-item">
				<a href="#basic-tab1" class="nav-link active" data-toggle="tab">Recibo detalle</a>
			</li>
			<li class="nav-item"><a href="#basic-tab2" class="nav-link" data-toggle="tab">Archivos</a></li>
	</ul>
	<div class="card-body">
		<div class="tab-content">
			<div class="tab-pane fade show active" id="basic-tab1">

				<div class="response-data">
					
				</div>
				<form action="{{ url('rphonorarios/'.$data['cabecera']->id) }}" class="form-login" onsubmit="update_contable(this); return false">
					@csrf
					<input type="hidden" name="action" value="update">
					<input type="hidden" name="id_d" id="id_d" value="{{ $data['cabecera']->id }}">
					<input type="hidden" name="idfile" id="idfile" value="{{ $data['cabecera']->id }}">
					<input type="hidden" name="codigo_num" id="codigo_num" value="{{ $data['cabecera']->codigo_num }}">
					<div class="content-cuentas"></div>
					<div class="row">
						<div class="col-2">
							<a href="#" style="color: black;" data-status="{{(empty($data['cabecera']->status)) ? '0' : $data['cabecera']->status }}" data-id="{{ $data['cabecera']->id }}" id="lock_reg"><i  style="font-size: 26px;" class="{{(empty($data['cabecera']->status) OR $data['cabecera']->status == 0) ? 'icon-unlocked'  : 'icon-lock4' }}"></i></a>
						</div>
						<div class="col-8 text-center text-uppercase ">
							<h3 class="font-weight-light">Editar Recibo</h3>
						</div>
					</div>
					<br>
					<div class="row">
						<div class="col-3">
							<div class="input-group">
								  <div class="input-group-prepend">
								    <span class="input-group-text" id="basic-addon1">Fecha</span>
								  </div>
								  <input type="text" class="form-control fec" id="input-cont"  name="create_at" placeholder="00/00/0000" aria-describedby="basic-addon1" value="{{$data['cabecera']->create_at}}">
							</div>
						</div>
						<div class="col-4" style="position: relative;">
							<div class="input-group ">
							  <div class="input-group-prepend">
							    <span class="input-group-text" id="basic-addon1">Nombre o razon social</span>
							  </div>
							  <input type="text" class="form-control mynombre"  data-tipe="entidad" data-action="{{ url('entidad') }}"  name="nombre" onkeyup="search_razon(this); return false" placeholder="Nombre" aria-describedby="basic-addon1" autocomplete="off" value="{{$data['cabecera']->nombre}}">
							</div>
							<div class="row row-search" >
								<div class="col-4">		
								</div>
								<div class="col-8">
									<div class="content-search entidad-search" >
									</div>
								</div>
							</div>		
						</div>
						<div class="col-2">
							<select name="identidad_document_id" class="form-control"  id="identidad_select" >
								<option value="">Tipo</option>
								@if($complet['identidad']->isNotEmpty())
									@foreach ($complet['identidad'] as $i)
										@if($data['cabecera']->identidad_document_id == $i->codigo)
											<option value="{{$i->codigo}}" data-id="{{$i->id}}" selected="">{{ $i->abrv }} || {{ $i->descripcion }}</option>
										@else
											<option value="{{$i->codigo}}" data-id="{{$i->id}}" >{{ $i->abrv }} || {{ $i->descripcion }}</option>
										@endif
									@endforeach
								@endif
							</select>
						</div>
						<div class="col-3 text-left" >
							<div class="input-group ">
								<input type="text" class="form-control identidad_numero" id="identidad_num"   name="numero_identidad" placeholder="Numero " aria-describedby="basic-addon1" value="{{$data['cabecera']->numero_identidad}}">
							</div>
						</div>
					</div>
					<hr>
					<div class="row">
						<div class="col-3">
							<div class="input-group ">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Documento</span>
							  </div>
							  <select name="tipdocs_id" class="form-control" id="tipdocs_campo" onchange="tipdocs(this); return false">
							  	<option value="">Seleccionar</option>
							  	@if($complet['tipdocs']->isNotEmpty())
							  		@foreach ($complet['tipdocs'] as $t)
							  			@if($t->descor == 'R/H')
								  			@if($t->id == $data['cabecera']->tipdocs_id )
								  				<option value="{{$t->id}}" data-cambio="{{$t->codsun}}" data-descor="{{$t->descor}}" {{ ($t->relacional == 1) ? 'data-relacional="$t->relacional" ' : '' }} selected="selected">{{$t->descor}}</option>
								  			@else
								  				<option value="{{$t->id}}" data-cambio="{{$t->codsun}}"  data-descor="{{$t->descor}}"  {{ ($t->relacional == 1) ? 'data-relacional='.$t->relacional  : '' }} >{{$t->descor}}</option>
								  			@endif
							  			@endif
							  		@endforeach
							  	@endif
							  </select>
							</div>
						</div>
						<div class="col-2">
							<input type="text" class="form-control"  name="serie" id="docserie" value="{{$data['cabecera']->serie}}">
						</div>
						<div class="col-2">
							<input type="text" class="form-control"  name="numero" id="numero_serie" value="{{$data['cabecera']->numero}}">
						</div>
						<div class="col-5">
							<select name="forpags" class="form-control" id="">
							  	<option value="">Forma de pago</option>
							  	@if($complet['forpag']->isNotEmpty())
							  		@foreach ($complet['forpag'] as $f)
							  			@if($f->descripcion == $data['cabecera']->forpags)
							  				<option value="{{$f->descripcion}}" data-codigo="{{$f->codigo}}" selected="selected">{{$f->descripcion}}</option>
							  			@else
							  				<option value="{{$f->descripcion}}" data-codigo="{{$f->codigo}}">{{$f->descripcion}}</option>
							  			@endif
							  		@endforeach
							  	@endif
							</select>
						</div>
					</div>
						<div class="row relacional-content mt-2" style="display: none;">
							<div class="col-3">
								<div class="input-group ">
								  <div class="input-group-prepend">
								    <span class="input-group-text " id="basic-addon1">Relacional</span>
								  </div>
								  <select class="form-control" data-relacion="1"  id="relacional_select" onchange="tipdocs(this); return false">
								  	<option value="">Seleccionar</option>
								  	@if($complet['tipdocs']->isNotEmpty())
								  		@foreach ($complet['tipdocs'] as $t)
								  			@if($t->id == $data['cabecera']->tipdoc_relacional )
								  				<option value="{{$t->codsun}}" selected="">{{$t->descor}}</option>
								  			@else
								  				<option value="{{$t->codsun}}" >{{$t->descor}}</option>

								  			@endif
								  		@endforeach
								  	@endif
								  </select>
								</div>
							</div>
							<div class="col-2">
								<input type="text" class="form-control"  id="docserie_relacional" value="{{$data['cabecera']->serie_relacional}}">
							</div>
							<div class="col-2">
								<input type="text" class="form-control" id="input-cont" id="docnumero_relacional" value="{{$data['cabecera']->numero_relacional}}">
							</div>
						</div>
					
					<hr>
					<div class="row">

						<div class="col-3">
							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Fec emision</span>
							  </div>
							  <input type="text" class="form-control fec" id="emision" onchange="cambious(this); return false" name="fec_emision" placeholder="00/00/0000" value="{{$data['cabecera']->fec_emision}}" >
							</div>			
						</div>
						<div class="col-2">
							<div class="input-group ">
							  <div class="input-group-prepend">
							    <span class="input-group-text" id="basic-addon1">Cambio</span>
							  </div>
							  <input type="text"  name="cambio"  id="cambioinput" value="{{$data['cabecera']->cambio}}" class="form-control divisaval">
							</div>		
						</div>
						<div class="col-2">
							<div class="input-group ">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Dias</span>
							  </div>
							  <input type="text" name="dias" id="input-cont" class="form-control" value="{{$data['cabecera']->dias}}">
							</div>			
						</div>
						<div class="col-3">
							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Fec vencimiento</span>
							  </div>
							  <input type="text" class="form-control fec" id="input-cont" name="fec_vencimiento" placeholder="00/00/0000" value="{{$data['cabecera']->fec_vencimiento}}">
							</div>			
						</div>
					</div>
					<hr>
					<div class="row">
						<div class="col-2">
							<b>Esta operacion se encuentra afecto a la retencion del impuesto de la renta</b>
						</div>
						<div class="col-2">
							<input type="radio" onchange="percentc(this); return false" name="imp_checked" {{ ($data['cabecera']->imp_checked == 'si') ? 'checked' : '' }}  value="si">Si<br>
							<input type="radio" onchange="percentc(this); return false" name="imp_checked" {{ ($data['cabecera']->imp_checked == 'no') ? 'checked' : '' }} value="no">No
						</div>
						<div class="col-2">
							<div class="input-group ">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Moneda</span>
							  </div>
							  <select name="divisa" class="form-control" id="divisa_change" onchange="change_divisa(this); return false" >
							  	<option value=""></option>
							  	<option value="{{ $data['cabecera']->divisa }}"  data-divisa="{{$data['cabecera']->divisa}}" selected="selected">{{$data['cabecera']->divisa}}</option>
							  	@if($complet['divisas']->isNotEmpty())
							  		@foreach ($complet['divisas'] as $d)
							  			@if($d->divisa == $data['cabecera']->divisa)
							  				
							  			@else
							  				<option value="{{$d->divisa}}" data-cambio="{{$d->compra}}" data-divisa="{{$d->divisa}}" >{{$d->divisa}}</option>
							  			@endif
							  		@endforeach
							  	@endif
							  </select>
							</div>			
						</div>

						<div class="col-2">
							<div class="input-group">
		 						<div class="input-group-prepend">
							    	<span class="input-group-text " id="basic-addon1">Honorarios</span>
							  	</div>
								<input type="text" name="honorarios" id="honorario" value="{{$data['cabecera']->honorarios}}" class="form-control" onkeyup="calcula_valor(this); return false">
							</div>
						</div>
						<div class="col-2">
							<div class="row">
								<div class="col-5">
									<input type="text" name="hpertc" id="rpertc" onkeyup="calcula_valor(this); return false" class="form-control" placeholder="%" value="{{$data['cabecera']->hpertc}}">
								</div>
								<div class="col-7">
									<input type="text" name="hvalue" id="rvalue" onkeyup="calcula_valor(this); return false" class="form-control" value="{{$data['cabecera']->hvalue}}">
								</div>
							</div>
						</div>
						<div class="col-2">
							<div class="input-group">
		 						<div class="input-group-prepend">
							    	<span class="input-group-text " id="basic-addon1">Total</span>
							  	</div>
							<input type="number" name="total_h" id="totalh" class="form-control" value="{{$data['cabecera']->total_h}}">
							</div>
						</div>
					</div>
					<hr>
					<div class="row">
						<div class="col-4">
							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Glosa</span>
							  </div>
							  <input type="text" class="form-control"  name="glosa" value="{{$data['cabecera']->glosa}}"  id="glosa_concept">
							</div>			
						</div>
						<div class="col-4">
							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">C.costos</span>
							  </div>
								<select name="ccostos_id" id="ccostos" class="form-control ynamic_selects selectpicker update-picker" data-select="ccostos" onchange="change_cuecc(this); return false">
									<option value="">Centro de costos</option>
									@if($complet['ccostos']->isNotEmpty())
										@foreach ($complet['ccostos'] as $c)
										    @if(strlen($c->codigo) == 4)
											    <option value="{{ $c->id }}" data-description="{{ $c->descripcion }}" {{($data['cabecera']->ccostos_id == $c->id ) ? 'selected' : '' }} data-codigo="{{ $c->codigo }}">{{ $c->codigo }} || {{ $c->descripcion }}</option>
											@endif
										@endforeach
									@endif
								</select>
							</div>			
						</div>
						<div class="col-4">
							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text " id="basic-addon1">Cuenta</span>
							  </div>
							  <select name="plan_cuentas_id" id="cuenta_id"  class="form-control dynamic_selects selectpicker update-picker" data-select="cuentas" data-live-search="true"  required=""  onchange="change_cuecc(this); return false" >
									<option value="">Cuentas contables</option>
									@if($complet['cuentas']->isNotEmpty())
										@foreach ($complet['cuentas'] as $c)
										    @if(strlen($c->codigo) == 7)
											    <option value="{{ $c->id }}" {{($data['cabecera']->plan_cuentas_id == $c->id ) ? 'selected' : '' }} data-description="{{ $c->descripcion }}" data-codigo="{{ $c->codigo }}">{{ $c->codigo }} || {{ $c->descripcion }}</option>
											@endif
										@endforeach
									@endif
								</select>
							</div>			
						</div>
					</div>
					<hr>
					<div class="conten-compra-detalle" >
						<div class="row">
			
							<div class="col-6 ">
								<a href="#" class="btn btn-warning buttons-contables" data-toggle="modal" data-target="#modalFiles">Adicionar Archivos</a>
							</div>
						</div>
						<br/>
						<div class="content-contable">
							<table class="table table-bordered">
								<thead>
									<th>Cuenta</th>
									<th width="20%">Contra cuenta</th>
									<th>Contra cuenta</th>
									<th>Concepto</th>
									<th>Importe US</th>
									<th>Debe</th>
									<th>Haber</th>
								</thead>
								<tbody class="content-lineas-table">
							
									
								</tbody>
							</table>
						</div>
					</div>
					<div class="content-values" >
						<hr>
						<div class="row justify-content-center">
							<div class="col-6">
								<b>Totales:</b>
								<div class="row">
									<div class="col-6">
										<input type="text" class="form-control" id="total_v" value="" >
										<input type="hidden" class="form-control" name="totales" id="total" value="" >
									</div>
									<div class="col-6">
										<input type="text" class="form-control"  id="total_cambio_v"   value="" >
										<input type="hidden" class="form-control" name="total_cambio" id="total_cambio"   value="" >
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-12 text-center">
							<br>
							<button class="btn btn-primary"><i class="icon-rotate-cw2 "></i> Actualizar</button>
						</div>
					</div>
				</form>
				@include('Libros_electronicos.views.utilitarios.files_document',['tipe'=>'rphonorarios'])
			</div>
			<div class="tab-pane fade" id="basic-tab2">
				<div class="row">
					@include('Utilitarios.views.list.listfile')
				</div>
			</div>
		</div>
	</div>
</div>
<div class="response-ajax">
	
</div>
	@section('scripts')
		<script src="{!! asset('assets/views_functions/contable/functions.js') !!}"></script>

		<script src="{!! asset('assets/views_functions/contable/rphonorarios.js') !!}"></script>
		<script>
			//funciones automaticas para  esta vista
			locks_reg();
			document.addEventListener('DOMContentLoaded', function(event) {
				tipdocajax();
				cambious();
				get_lineas();
				change_divisa();
				$(document).on("click",".entidadf",function(e){
					$.ajaxblock();e.preventDefault();e.stopImmediatePropagation();
			    	$(this).attr('disabled', 'true');
					$.ajax({
						url: "{{ url('rphonorarios/modals') }}",
						type: 'POST',
						data: {'action': 'entidad_fac','identidad':"{{ $data['cabecera']->numero_identidad }}",'id_compra':"{{ $data['cabecera']->id }}"},
					})
					.done(function(data) {
						$('.reponse-ajax-relacional').html('').html(data);
						$('#modalEntidad').modal('toggle');
						$('button').removeAttr('disabled');
						$.ajaxunblock();
					})
					return false;
				});
			});
		</script>
	@endsection
@endsection