<link href="<?= $assets ?>plugins/bootstrap-toggle/bootstrap-toggle.min.css" rel="stylesheet">
<script src="<?= $assets ?>plugins/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<link rel="stylesheet" href="<?= $assets ?>dist/css/pages/customers.css">

<section class="content">
		<div class="col-xs-12">
			<div class="row">
				<div class="box" style="border-top: 2.5px solid #9fc10b;">
					<div class="box-body">
						<?php echo form_open("customers/add" . $customer->id, 'id="customer-form"'); ?>
						<div id="alert" class="alert alert-danger text-center" style="display:none;"></div>
						<input type="hidden" name="idclienteedit" value="<?php echo $customer['id']; ?>" id="idclienteedit">
						<div class="col 12"><!-- Numero de documento / Consulta de DNI -->
							<div class="row">
								<div class="col-md-4" id="div-cf1">
									<div class="form-group">
										<label class="control-label" for="cf1"><?= $this->lang->line("ccf1"); ?> *</label>
										<div class="input-group">
											<?= form_input('cf1', set_value('cf1', (isset($form_data['cf1'])?$form_data['cf1']:"")), 'class="form-control" id="cf1" maxlength="15"'); ?>
											<div class="input-group-btn">
												<div id="con-num-doc" class="btn btn-info" tabindex="0" data-toggle="tooltip" title="Consulta numero de documento"><i class="fa fa-search"></i></div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<!-- Radio button para Persona Natura y Juridica -->
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label class="control-label" for="type_persona"><?= $this->lang->line("type_person"); ?> *</label>
										<div class="radio-group">
											<div class="radio-inline">
												<input type="radio" <?= set_radio('person', '1', $customer['person_type'] == 1) ?> checked="true" name="person" id="person-natural" value="1" class="radio-person-type mg">
												<label class="custom-control-label"><?= $this->lang->line("person1"); ?></label>
											</div>
											<div class="radio-inline">
												<input type="radio" <?= set_radio('person', '2', $customer['person_type'] == 2) ?> name="person" id="person-juridica" value="2" class="radio-person-type">
												<label class="custom-control-label"><?= $this->lang->line("person2"); ?></label>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="row">
								<!-- Tipo de documento -->
								<div class="col-md-4" id="div-document_type">
									<div class="form-group" >
										<?= lang('document_type', 'document_type'); ?> *
										<select name="document_type" id="document-type" class="form-control" >
											<option value=""><?= lang("select") . " " . lang("document_type") ?></option> 
										<?php
											foreach ($document_type as $doc_type) { ?>
												<option value="<?= $doc_type->id ?>" <?=($doc_type->id == set_value("document_type",(isset($form_data['document_type'])?$form_data['document_type']:"")))?'selected':''?>><?= $doc_type->document_type; ?></option> 
											<?php }?>
										</select>
									</div>
										<!--<?=form_dropdown('document_type', $ctv1, set_value("document_type",(isset($form_data['document_type'])?$form_data['document_type']:""), $document_type[0]->document_type), 'class="form-control tip select2" id="document-type"  style="width:100%;"'); ?>-->
								</div>

								<!-- Numero de RUC / Consulta de RUC -->
								<div class="col-md-4">
									<div class="form-group" id="div-cf2">
										<label class="control-label" for="cf2"><?= $this->lang->line("ccf2"); ?> </label>
										<div class="input-group">
											<?= form_input('cf2', set_value('cf2',(isset($form_data['cf2'])?$form_data['cf2']:"") ), 'class="form-control" id="cf2" maxlength="11" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\..*)\./g, \'$1\');"'); ?>
											<div class="input-group-btn">
												<div id="con-ruc" class="btn btn-info" tabindex="0" data-toggle="tooltip" title="Consulta de RUC"><i class="fa fa-search"></i></div>
											</div>
										</div>
										<div id="cargando" class="col-md-2" style="display:none;"><img style="width: 30px;height:auto;" src="https://pa1.narvii.com/6558/d6738388bae69543478eb78d0545bf0475ef05a6_hq.gif">
										</div>
									</div>
								</div>
							</div>

							<div class="row">
								<!-- Nombre o razon social-->
								<div class="col-md-6">
									<div class="form-group">
										<label class="control-label" for="code" id="nombre-persona"><?= $this->lang->line("name"); ?> *</label>
										<?= form_input('name', set_value('name',(isset($form_data['name'])?$form_data['name']:"")), 'class="form-control" id="name" maxlength="150"'); ?>
									</div>
								</div>

								<!-- Tipo de cliente -->
								<div class="col-md-6">
									<div class="form-group">
										<?= lang('customers_type', 'customers_type'); ?>
										<?php
										$type_customer_list[0] = lang("select") . " " . lang("customers_type");
										foreach ($customer_type as $cust_type) {
											$type_customer_list[$cust_type['id']] = $cust_type['customers_type'];
										}
										//$type_customer_list[$customer_type['id']] = $customer_type['customers_type'];
										?>
										<?= form_dropdown('customer_type', $type_customer_list, set_value("customer_type",(isset($form_data['customer_type'])?$form_data['customer_type']:""), $customer_type[0]['customers_type']), 'class="form-control tip select2" id="customer_type" style="width:100%;"'); ?>
									</div>
								</div>

							</div>

							<!-- Direccion -->
							<div class="row">
								<div class="col-md-12">
									<div class="row">
										<div class="col-xs-12">
											<div class="form-group">
												<label class="control-label" for="direccion">
													<?= lang("address"); ?>
												</label>
												<?= form_input('direccion', set_value('direccion',(isset($form_data['direccion'])?$form_data['direccion']:"")), 'class="form-control kb-text" id="cdireccion" maxlength="255"'); ?>
											</div>
										</div>
									</div>
								</div>
							</div>

							<div class="row">
								<!-- Telefono -->
								<div class="col-md-6">
									<div class="form-group">
										<label class="control-label" for="phone"><?= $this->lang->line("phone_movil"); ?></label>
										<div class="input-group" style="width: 100%;">
											<select id="codigoPais" name="codigoPais" class="form-control" style="width: 20%; margin-right: 5px;">
												<option value="51"><img src="<?= $assets ?>images/peru.png"/>(PE) +51</option>
											</select>
											<?= form_input('phone', set_value('phone',(isset($form_data['phone'])?preg_replace('/^51/', '',$form_data['phone']):"")), 'class="form-control" style="width: 70%;" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\..*)\./g, \'$1\');" id="phone" maxlength="15"'); ?>
										</div>
									</div>
								</div>

								<!-- Direccion de email -->
								<div class="col-md-6">
									<div class="form-group">
										<label class="control-label" for="email_address"><?= $this->lang->line("email_address"); ?></label>
										<?= form_input('email', set_value('email',(isset($form_data['email'])?$form_data['email']:"")), 'class="form-control" id="email_address" maxlength="100"'); ?>
									</div>
								</div>
							</div>

							<!-- Retainer Porcentage -->
							<?php if ($this->session->userdata('retencion') == 1) { ?>
								<div class="row">
									<div class="col-md-12">
										<div class="form-group row">
											<label class="col-sm-1 col-form-label">
												<?= lang('is_retainer_text', 'is_retainer_text'); ?>
											</label>
											<div class="col-sm-1">
												<input type="checkbox" id="is_retainer_checkbox" name="is_retainer_checkbox" data-offstyle="danger" data-style="slow" data-onstyle="success" data-toggle="toggle" data-on="Si" data-off="No" data-size="mini">
												<input type="hidden" name="is_retainer" id="is_retainer" value="0">
											</div>
											<label class="col-sm-2 col-form-label retainer_percentage pt-1" style="display:none;">
												<?= lang('retainer_percentage', 'retainer_percentage'); ?>
											</label>
											<div class="col-sm-1 retainer_percentage" style="display:none;">
												<input class="form-control" type='text' id='retainer_percentage' name='retainer_percentage' for='0' value='0' oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" maxlength="2" max="99" />
											</div>
										</div>
									</div>
								</div>
							<?php } ?>


							<div class="row">
								<!-- ¿Ya no se usa? -->
								<div class="col-md-12">
									<?php switch ($this->session->userdata('negocio')) {
										case 0: ?>
										<?php break;
										case 1: ?>
											<div class="form-group">
												<label class="control-label" for="custom_field_1"><?= $this->lang->line("digemid"); ?></label>
												<?= form_input('custom_field_1', set_value('custom_field_1'), 'class="form-control" id="custom_field_1"'); ?>
											</div>
									<?php break;
									} ?>
								</div>

								
							</div>
							<div class="row">
								<div class="col-md-12">
									<div class="col-md-12 text-right">
										<?php echo form_submit('add_customer', $this->lang->line("accept"), 'class="btn btn-primary" id="btn-accept"'); ?>
										<a id="btn-cancel" class="btn btn-danger"><?= lang("cancel") ?></a>
									</div>
								</div>
							</div>
						</div>
						
					</div>
					<?php echo form_close(); ?>
				</div>
			</div>
		</div>
</section>

<script src="<?= $assets ?>dist/js/pages/Customers.js"></script>

<script>

  var personValue = <?php echo json_encode(isset($form_data['person']) ? $form_data['person'] : ""); ?>;

  if (personValue == 1) {
    
	$("#person-natural").prop("checked", true);

  }
  if(personValue == 2){

	$("#person-juridica").prop("checked", true);

  }

  

</script>

<script>

	if ($('#person-natural').is(':checked')) {
		$('#document-type option[value="6"]').prop('disabled', true);
		
	}							

	if ($('#person-juridica').is(':checked')) {

		$("#div-document_type *").prop("disabled", true);
		$('#doctypejs').val(6);
		$('#document-type').val(6).trigger('change.select2');

	}

</script>