@extends('layouts.app')

@section('title',"Agregar nuevo registro por honorario")

@section('content')
<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">
	<div class="card-body">
		<div class="response-data">
			
		</div>
		<form action="{{ url('rphonorarios') }}" class="form-login" onsubmit="create_contable(this); return false">
			<input type="hidden" name="action" value="add">
			<div class="content-inputs"></div>
			<div class="content-cuentas"></div>
			<div class="content-cuentas-honorarios"></div>
			<div class="content-ccostos-honorarios"></div>
			@csrf
			<div class="content-numbers"></div>
			<div class="row">
				<div class="col-12 text-center text-uppercase ">
					<h3 class="font-weight-light">Nuevo registro</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" name="create_at" placeholder="00/00/0000" aria-describedby="basic-addon1" id="fecha_number" value="{{ Session::get('fecha_compra')}}" onchange="change_number(this); return false">
					</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">
					</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)
								<option value="{{$i->codigo}}" data-id="{{$i->id}}">{{ $i->abrv }} || {{ $i->descripcion }}</option>
							@endforeach
						@endif
					</select>
				</div>
				<div class="col-3 text-left" >
					<div class="input-group ">
						<input type="text" class="form-control identidad_numero" id="input-cont"   name="numero_identidad" placeholder="Numero " aria-describedby="basic-addon1">
					</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')
					  			<option value="{{$t->id}}" data-cambio="{{$t->codsun}}" data-relacional="{{$t->relacional}}" data-descor="{{$t->descor}}">{{$t->descor}}</option>
					  			@endif
					  		@endforeach
					  	@endif
					  </select>
					</div>
				</div>
				<div class="col-2">
					<input type="text" class="form-control"  name="serie" id="docserie" placeholder="example: F0001">
				</div>
				<div class="col-2">
					<input type="text" class="form-control"  name="numero" id="numero_serie">
				</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)
					  			<option value="{{$f->descripcion}}" data-codigo="{{$f->codigo}}">{{$f->descripcion}}</option>
					  		@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)
					  			<option value="{{$t->codsun}}">{{$t->descor}}</option>
					  		@endforeach
					  	@endif
					  </select>
					</div>
				</div>
				<div class="col-2">
					<input type="text" class="form-control"  id="docserie_relacional">
				</div>
				<div class="col-2">
					<input type="text" class="form-control" id="input-cont" id="docnumero_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="<?php echo date('Y-m-d'); ?>" >
					</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" 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">
					</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">
					</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" value="si">Si<br>
					<input type="radio" onchange="percentc(this); return false" name="imp_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>
					  	@if($complet['divisas']->isNotEmpty())
					  		@foreach ($complet['divisas'] as $d)
					  			<option value="{{$d->divisa}}" data-cambio="{{$d->compra}}" data-divisa="{{$d->divisa}}">{{$d->divisa}}</option>
					  		@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="" 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="%">
						</div>
						<div class="col-7">
							<input type="text" name="hvalue" id="rvalue" onkeyup="calcula_valor(this); return false" class="form-control">
						</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">
					</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 text-uppercase" id="input-cont" name="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-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-description="{{ $c->descripcion }}" data-codigo="{{ $c->codigo }}">{{ $c->codigo }} || {{ $c->descripcion }}</option>
									@endif
								@endforeach
							@endif
						</select>
					</div>			
				</div>
			</div>
			<hr>
			<div class="row">
				<div class="col-12 text-center">
					<br>
					<button class="btn btn-primary"><i class="icon-floppy-disk "></i> Guardar</button>
				</div>
			</div>
		</form>
	</div>
</div>
	@section('scripts')
		<script>
			// url para consultas
			const cambiourl = "{{ url('tcambio') }}",tipdocurl = "{{ url('tipdoc') }}",comprasurl = "{{ url('compras') }}";
		</script>
		<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
			cambious();
			change_number();
		</script>
	@endsection
@endsection
