<div class="row">
	<span style="display:block;text-align:center;">La compra que desea anular se registro al cr&eacute;dito. &iquest;Que desea hacer con este saldo?</span>
	<h4>Seleccione una acci&oacute;n:</h4>
	<div class="form-group">
		<div class="col-md-6">
			<div class="radio i-checks crediaccion"><label> <input type="radio" id="crediaccion-ninguna" value="0" name="crediaccion"> <i></i> No realizar ninguna acci&oacute;n sobre cr&eacute;ditos</label></div>
		</div>
		<div class="col-md-6">
			<div class="radio i-checks crediaccion"><label> <input type="radio" id="crediaccion-abonar" value="1" name="crediaccion" data-display="#creditos-cliente-list"> <i></i>Abonar un cr&eacute;dito existente </label></div>
		</div>
		<div class="clearfix"></div>
	</div>
	
	<div class="row">
		<div class="m-l-md m-r-md" id="creditos-proveedor-select-list-wrapper" style="height:200px;overflow:hidden;border:solid 1px #F1F1F1;">
			
			<div class="table-responsive" style="display:none;" id="creditos-cliente-list">
				<table class="table table-striped">
					<thead>
						<tr>
							<th></th>
							<th>ID</th>
							<th>Monto</th>
							<th>Saldo</th>
							<th>Final</th>
							<th>Estado</th>
						</tr>
					</thead>
					<tbody>
						
						<?php if(count($creditos)>0): foreach($creditos as $credito):?>
						<tr data-deuda="<?php echo $credito->id_deuda;?>">
							<td><div class="radio i-checks creditoradio"><input type="radio" value="option1" name="deuda"></div></td>
							<td><?php echo $credito->id_deuda;?></td>
							<td><?php echo $credito->monto_deuda;?></td>
							<td><?php echo $credito->saldo_deuda;?></td>
							<td><?php echo $credito->finalizacion_deuda;?></td>
							<td>
								<?php switch($credito->estado_deuda):
								case 0:?>
								<span class="label label-info">Activo</span>
								<?php break; case 1:?>
								<span class="label">Liquidado</span>
								<?php break; endswitch;?>
							</td>
						</tr>
						<?php endforeach;
						else:?>
							<tr>
								<td colspan="6"><small style="display:block;" class="text-center">No se han encontrados cr&eacute;ditos para este cliente.</small></td>
							</tr>
						<?php endif;?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="form-group text-center m-t-md">
		<button type="button"  id="cancel-credit-btn" class="btn btn-danger btn-rounded" onclick="$('#guardar-devolucion-btn').removeAttr('disabled');Custombox.close();">Cancelar</button>
		<button type="button" id="selcredit-btn" class="btn btn-info btn-rounded">Aceptar</button>
	</div>
</div>
<script>
	$(document).ready(function(){
		$("#creditos-proveedor-select-list-wrapper").slimScroll({
			height: '200px'
		});
		$('.i-checks').iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green'
		});
		$('.crediaccion input:radio').on('ifChecked', function(event){
			$('#creditos-proveedor-select-list-wrapper > div').hide();
			$($(this).attr('data-display')).show();
			$(".creditoradio input:radio").attr('checked', false);
			$('.creditoradio input:radio').iCheck('update');
		});
		$("#selcredit-btn").click(function(){
			if($('#crediaccion-ninguna').is(':checked') || $('#crediaccion-abonar').is(':checked')){
					if($('#crediaccion-ninguna').is(':checked')){
						$("#nueva-salida-anulacion-compra-credito").val("ninguna");
						salidas.guardarAnularCompra(jQuery.Event("click",{target:$('#nueva-salida-anulacion-compra-anular-btn')}));
						Custombox.close();
					}else if($('#crediaccion-abonar').is(':checked')){
						if ($("input[name='deuda']:checked").val()) {
							var selRadio=$("input[name='deuda']:checked"); 
							var CreditoID=selRadio.closest('tr').attr('data-deuda');
							$("#nueva-salida-anulacion-compra-credito").val(CreditoID);
							salidas.guardarAnularCompra(jQuery.Event("click",{target:$('#nueva-salida-anulacion-compra-anular-btn')}));
							Custombox.close();
						}
						else {
							 toastr.options = {
								"closeButton": true,
								"progressBar": true,
								"positionClass": "toast-top-right"
							}
							toastr.error('Seleccione un cr&eacute;dito de la lista para continuar...');
						}
					}
			}else{
				toastr.options = {
					"closeButton": true,
					"progressBar": true,
					"positionClass": "toast-top-right"
				}
				toastr.error('Seleccione una acci&oacute;n para registrar el abono de esta devoluci&oacute;n');
			}
		});
	});
</script>