<?php $this->load->view("partial/header"); ?>
	<?php echo form_open_multipart('locations/dian_save/'.$location_info->location_id,array('id'=>'dian_form','class'=>'form-horizontal','autocomplete'=> 'off')); ?>
		<div class="row" id="form">
			
			<div class="col-md-12">				
				<div class="panel panel-piluku">
					<div class="panel-heading">
		                <h3 class="panel-title">
		                    <i class="ion-edit"></i> 
		                    <?php echo lang("locations_resolution_information"); ?>
	    					<small>(<?php echo lang('common_fields_required_message'); ?>)</small>
		                </h3>
			        </div>

					<div class="panel-body">

						<div class="form-group">
							<?php echo form_label(lang('locations_name').':', 'name',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label')); ?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php echo form_input(array(
									'class'=>'form-control form-inps',
									'name'=>'name',
									'id'=>'name',
									'value'=>$location_info->name,
									'disabled'=>'true')
								);?>
							</div>
						</div>
			
					<div class="form-group">	
						<?php echo form_label(lang('common_company').':', 'company',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
						<div class="col-sm-9 col-md-9 col-lg-10 input-field">
							<?php echo form_input(array(
								'class'=>'form-control form-inps',
							'name'=>'company',
							'id'=>'company',
							'disabled' => 'true',
							'value'=>$location_info->company));?>
						</div>
					</div>
					<?php echo form_hidden('location_id', @$location_info->location_id); ?>
					<?php echo form_hidden('id', @$dian_info->id); ?>
					<div class="form-group">	
						<?php echo form_label(lang('DIAN_cia_NIT').':', 'cia_nit',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
						<div class="col-sm-9 col-md-9 col-lg-10 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'cia_nit',
							'id'=>'cia_nit',
							'value'=>$dian_info->cia_nit));?>
						</div>
					</div>					
					
					<div class="form-group">	
						<?php echo form_label(lang('DIAN_usuarioId').':', 'dian_user',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
						<div class="col-sm-4 col-md-4 col-lg-4 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'dian_user',
							'id'=>'dian_user',
							'value'=>$dian_info->dian_user));?>
						</div>

						<?php echo form_label(lang('DIAN_password').':', 'dian_password',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
						<div class="col-sm-3 col-md-3 col-lg-3 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'dian_password',
							'id'=>'dian_password',
							'value'=>$dian_info->dian_password));?>
						</div>
					</div>
					
					<div class="form-group">	
						<?php echo form_label(lang('invoice_auth').':', 'invoice_auth',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
						<?php echo form_input(array(
							'class'=>'validate form-control form-inps',
							'name'=>'invoice_auth',
							'id'=>'invoice_auth',
							'value'=>$dian_info->invoice_auth));?>
						</div>
	
						<?php echo form_label(lang('DIAN_startdate').':', 'startdate',array('class'=>'col-sm-2 col-md-2 col-lg-2 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'form-control form-inps',
							'type' => 'date',
							'name'=>'startdate',
							'id'=>'startdate',
							'value'=>$dian_info->startdate));?>
						</div>

						<?php echo form_label(lang('DIAN_enddate').':', 'enddate',array('class'=>'col-sm-1 col-md-1 col-lg-1 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'form-control form-inps',
							'type' => 'date',
							'name'=>'enddate',
							'id'=>'enddate',
							'value'=>$dian_info->enddate));?>
						</div>
					</div>

					<div class="form-group">	
						<?php echo form_label(lang('DIAN_Prefix').':', 'prefix',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label required')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'prefix',
							'placeholder' => 'SETT',
							'id'=>'prefix',
							'value'=>$dian_info->prefix));?>
						</div>

						<?php echo form_label(lang('DIAN_from').':', 'inv_from',array('class'=>'col-sm-1 col-md-1 col-lg-1 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'form-control form-inps',
							'name'=>'inv_from',
							'id'=>'inv_from',
							'placeholder' => '0',
							'type' => 'number',
							'min' => 0,
							'value'=>$dian_info->inv_from));?>
						</div>

						<?php echo form_label(lang('DIAN_to').':', 'inv_to',array('class'=>'col-sm-1 col-md-1 col-lg-1 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'form-control form-inps',
							'name'=>'inv_to',
							'id'=>'inv_to',
							'placeholder' => '0',
							'type' => 'number',
							'min' => '0',
							'value'=>$dian_info->inv_to));?>
						</div>
					</div>					

					<div class="form-group">
						<?php echo form_label(lang('DIAN_tax_scheme').':', 'tax_scheme',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_dropdown(array(
							'class'=>'form-control form-inps',
							'name'=>'tax_scheme',
							'options' => ['01' => 'IVA', 'ZZ' => 'No Aplica' ],
							'id'=>'tax_scheme',
							'selected'=>'01'));?>
						</div>

						<?php echo form_label(lang('DIAN_profile').':', 'profile',array('class'=>'col-sm-2 col-md-2 col-lg-2 control-label ')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_dropdown(array(
							'class'=>'form-control form-inps',
							'name'=>'profile',
							'options' => [1 => 'Producción', 2 => 'Prueba' ],
							'id'=>'profile',
							'selected'=>$dian_info->profile));?>
						</div>

						<?php echo form_label(lang('DIAN_VigenciaTicket').':', 'vigencia_ticket',array('class'=>'col-sm-2 col-md-2 col-lg-2 control-label ')); ?>
						<div class="col-sm-1 col-md-1 col-lg-1 input-field">
							<?php echo form_dropdown(array(
								'class'=>'form-control form-inps',
							'options' => [1 => 'Un Mes' ],
							'name'=>'vigencia_ticket',
							'id'=>'vigencia_ticket',
							'selected'=>1));?>
						</div>
					</div>
					<div class="form-group">
						<?php echo form_label(lang('DIAN_Prefix_nc').':', 'prefix_nc',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'prefix_nc',
							'placeholder' => 'NC',
							'id'=>'prefix_nc',
							'value'=>$dian_info->prefix_nc));?>
						</div>	
						<?php echo form_label(lang('DIAN_formato_ID').':', 'prefix',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'formato_id',
							'id'=>'formato_id',
							'value'=>$dian_info->formato_id));?>
						</div>
						<?php echo form_label(lang('DIAN_pto_venta').':', 'prefix',array('class'=>'col-sm-2 col-md-2 col-lg-2 control-label')); ?>
						<div class="col-sm-2 col-md-2 col-lg-2 input-field">
							<?php echo form_input(array(
								'class'=>'validate form-control form-inps',
							'name'=>'pto_venta',
							'id'=>'pto_venta',
							'value'=>$dian_info->pto_venta));?>
						</div>
					</div>
					<div class="form-group">
						<?php echo form_label(lang('DIAN_url_prba').':', 'url_prba',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
						<div class="col-sm-9 col-md-9 col-lg-10 input-field">
							<?php echo form_input(array(
								'class'=>' form-control form-inps',
							'name'=>'url_prba',
							'id'=>'url_prba',
							'placeholder' => 'Url de pruebas',
							'type' => 'text',
							'value'=>$dian_info->url_prba));?>
						</div>
					</div>
					<div class="form-group">
						<?php echo form_label(lang('DIAN_url_prod').':', 'url_prod',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
						<div class="col-sm-9 col-md-9 col-lg-10 input-field">
							<?php echo form_input(array(
								'class'=>' form-control form-inps',
							'name'=>'url_prod',
							'id'=>'url_prod',
							'placeholder' => 'Url de producción',
							'type' => 'text',
							'value'=>$dian_info->url_prod));?>
						</div>
					</div>
					<div class="form-group">
						<?php echo form_label(lang('DIAN_invoice').':', 'url_prod',array('class'=>'col-sm-3 col-md-3 col-lg-2 control-label ')); ?>
						<div class="col-sm-9 col-md-9 col-lg-10 input-field">
							<?php echo form_dropdown(array(
							'class'=>'form-control form-inps',
							'name'=>'dian_invoice',
							'options' => [0 => 'Utilizar el recibo del sistema por defecto', 1 => 'Salida en PDF del recibo de la DIAN' ],
							'id'=>'dian_invoice',
							'selected'=> $dian_info->dian_invoice));?>
						</div>
					</div>
					<?php echo form_hidden('redirect', $redirect); ?>

					<div class="form-actions pull-right">
						<?php
						echo form_submit(array(
							'name'=>'submitf',
							'id'=>'submitf',
							'value'=>lang('common_save'),
							'class'=>'submit_button floating-button btn btn-lg btn-primary')
						);
						?>
					</div>
					</div>
				</div>
			</div>
		</div>
	<?php echo form_close(); ?>
	

<script type='text/javascript'>
	var submitting = false;
	var add_register_index = 0;
		//validation and submit handling
		$(document).ready(function()
		{			
			//Turn on Credit card processing if we type in IP Tran
			var submitting = false;
			$('#dian_form').validate({
				submitHandler:function(form)
				{
					if (submitting) return;
					submitting = true;
					$('#grid-loader').show();
					$(form).ajaxSubmit({
					success:function(response)
					{
						//Don't let the registers be double submitted, so we change the name
						$(".registers_to_add").attr('name', 'registers_added[]');
						
						$('#grid-loader').hide();
						submitting = false;						
						show_feedback(response.success ? 'success' : 'error', response.message,response.success ? <?php echo json_encode(lang('common_success')); ?> +' #' + response.location_id : <?php echo json_encode(lang('common_error')); ?>);
						
						
						if(response.redirect==2 && response.success)
						{
							window.location.href = '<?php echo site_url('locations'); ?>';
						}
						else
						{
							$("html, body").animate({ scrollTop: 0 }, "slow");
							$(".form-group").removeClass('has-success has-error');
						}
										
					},
					<?php if(!$location_info->location_id) { ?>
					resetForm: true,
					<?php } ?>
					dataType:'json'
				});

				},
				ignore: '',
				errorClass: "text-danger",
				errorElement: "p",
				errorPlacement: function(error, element) {
				    error.insertBefore(element);
				},
					highlight:function(element, errorClass, validClass) {
						$(element).parents('.form-group').removeClass('has-success').addClass('has-error');
					},
					unhighlight: function(element, errorClass, validClass) {
						$(element).parents('.form-group').removeClass('has-error').addClass('has-success');
					},
				rules:
				{
					cia_nit:
					{
						required:true,
					},
					dian_user:
					{
						required:true
					},
					dian_password:
					{
						required:true
					},
					invoice_auth:
					{
						required:true
					},
					prefix:
					{
						required: true
					}
					
		   		},
				messages:
				{
					cia_nit:
					{
						required:<?php echo json_encode(lang('DIAN_cia_NIT_required')); ?>,
					},
					dian_user:
					{
						required:<?php echo json_encode(lang('DIAN_usuarioId_required')); ?>
					},
					dian_password:
					{
						required:<?php echo json_encode(lang('DIAN_password_required')); ?>
					},
					invoice_auth:
					{
						required:<?php echo json_encode(lang('invoice_auth_required')); ?>,
					},
					prefix:
					{
						required:<?php echo json_encode(lang('DIAN_Prefix_required')); ?>
					}
					
				}
			});
			
		});
	
</script>
<?php $this->load->view('partial/footer'); ?>