<div class="table-responsive">
	<table style="margin-bottom:0px;" id="cajachica-transacciones-table-header" class="table table-striped table-hover">
		<thead>
			<tr>
				<th style="width:20%;">Fecha</th>
				<th style="width:40%;">Concepto</th>
				<th style="width:10%;">Ingresos</th>
				<th style="width:10%;">Egresos</th>
				<th style="width:10%;">Saldo</th>
				<th style="width:10%;"></th>
			</tr>
		</thead>
	</table>
</div>
<div style="height:250px; overflow-y:auto;">
	<div class="table-responsive">
		<table id="cajachica-transacciones-table-body" class="table table-striped table-hover">
			<tbody>
				<?php $ingresos=0;$egresos=0;if(isset($transacciones)):foreach($transacciones as $transaccion):?>
				<tr>
					<?php
						if($transaccion->tipo_transaccion==0){
							$ingresos+=$transaccion->monto_transaccion;
						}else{
							$egresos+=$transaccion->monto_transaccion;
						}
					?>
					<td style="width:20%;"><?php echo $transaccion->fecha_transaccion;?></td>
					<td style="width:40%;"><?php echo $transaccion->concepto_transaccion;?></td>
					<td style="width:10%;"><?php echo ($transaccion->tipo_transaccion==0)?"$ ".number_format($transaccion->monto_transaccion,2):"";?></td>
					<td style="width:10%;"><?php echo ($transaccion->tipo_transaccion==1)?"$ ".number_format($transaccion->monto_transaccion,2):"";?></td>
					<td style="width:10%;"><?php echo "$ ".number_format($ingresos-$egresos,2);?></td>
					<td style="width:10%;">
						<button class="btn btn-danger btn-xs transacciones-eliminar-btn" data-id="<?php echo $transaccion->id_transaccion;?>">Eliminar</button>
					</td>
				</tr>
				<?php endforeach;endif;?>
			</tbody>
		 </table>
	</div>
</div>
<div class="row">
	<div class="col-md-9 text-right">
		<h2>Saldo</h2>
	</div>
	<div class="col-md-1 text-right">
		<h2>$</h2>
	</div>
	<div class="col-md-2 text-right">
		<h2><?php echo number_format($ingresos-$egresos,2);?></h2>
	</div>
</div>
<script>
	$(".transacciones-eliminar-btn").click(function(e){
		var $this_=$(this);
		swal({
			title: "Eliminar transaccion",
			text: "&iquest;Desea eliminar esta transaccion?",
			html: true,
			type: "warning",
			confirmButtonColor: "#DD6B55",
			showCancelButton: true,
			cancelButtonText: "Cancelar",
			confirmButtonText: "Si, Eliminar Transaccion",
		},
		function(isconfirm){
			if(isconfirm){
				$.get( "<?php echo base_url();?>transacciones/eliminar_transaccion", {
					id: $this_.data("id")
				}).done(function( data ) {
					$.get('<?php echo base_url();?>transacciones/cargar_transaccionesxcajachica?id='+$("#id_cajachica").val())
					.done(function(data){                
						$('#cajachica-transacciones-wrapper').html(data);
					});
				});
			}
		});
	});
</script>