<?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/creditomulta.php");
	$creditomulta=new creditomulta;

	$fecha=date("Y-m-d");
	extract($_POST);
	$dcred=$credito->muestra($idcreditoML);
	$saldoAnterior=$dcred['saldoMultas'];
	$saldo=$saldoAnterior+$idmontoML;
	$vaahorro=array(
		"idcredito"=>"'$idcreditoML'",
		"codoperacion"=>"'1201'",
		"fecha"=>"'$fecha'",
		"monto"=>"'$idmontoML'",
		"saldoant"=>"'$saldoAnterior'",
		"saldo"=>"'$saldo'",
		"detalle"=>"'$iddetalleML'"
	);	
	if($creditomulta->insertar($vaahorro))
	{
		$valcredito=array(
			"saldoMultas"=>"'$saldo'"
	 	);
		$credito->actualizar($valcredito,$idcreditoML);
		//genera movimiento de Otorgacion
		  	?>
				<script type="text/javascript">
				swal({
					title: "Éxito",
					text: "Multa Registrado 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
	}
	
?>