<?php
	session_start();
	$ruta="../../../../";
	include_once($ruta."class/credito.php");
	$credito=new credito;
	include_once($ruta."class/grupocredito.php");
	$grupocredito=new grupocredito;
	include_once($ruta."class/creditodetalle.php");
	$creditodetalle=new creditodetalle;
	include_once($ruta."class/creditoahorro.php");
	$creditoahorro=new creditoahorro;

	$fecha=date("Y-m-d");
	extract($_POST);
	$dcred=$credito->muestra($idcreditoAH);
	$saldoAnterior=$dcred['saldoahorro'];
	$saldo=$saldoAnterior-$idmontoAH;


	$vaahorro=array(
		"idcredito"=>"'$idcreditoAH'",
		"codoperacion"=>"'1102'",
		"fecha"=>"'$fecha'",
		"monto"=>"'$idmontoAH'",
		"saldoAnterior"=>"'$saldoAnterior'",
		"saldo"=>"'$saldo'",
		"estado"=>"'1'"
	);	
	;
	if($creditoahorro->insertar($vaahorro))
	{
		$valcredito=array(
			"saldoahorro"=>"'$saldo'"
	 	);
		$credito->actualizar($valcredito,$idcreditoAH);
		//genera movimiento de Otorgacion
		  	?>
				<script type="text/javascript">
				swal({
					title: "Éxito",
					text: "Cobro realizado correctamente",
					type: "success",
					confirmButtonColor: "#28e29e",
					confirmButtonText: "OK",
					closeOnConfirm: false
		          }, function () {
					location.reload();
		          });
				</script>
			<?php
	}else{
		?>
			<script type="text/javascript">
				swal("ERROR","No se registro","error");
			</script>
	   	<?php
	}
	
?>