<?php
	session_start();
	$ruta="../../../../";
	include_once($ruta."class/creditodetalle.php");
	$creditodetalle=new creditodetalle;
	include_once($ruta."class/dominio.php");
	$dominio=new dominio;
	include_once($ruta."class/credito.php");
	$credito=new credito;
	extract($_POST);
	$fecha=date("Y-m-d");

	switch ($idtipo) {
		case '2':
				$valcreditodet=array(
				//"diasmora"=>"'$iddiasmora'",
				"estadodiasmora"=>"'1'"	//monto combrado		
				//"fechafinmora"=>"'$idfechapago'"
				 	);
				if($creditodetalle->actualizar($valcreditodet,$idcreditodetalle))
				{
					$cred=$credito->muestra($idcredito);
					$nuevomonto=$cred['totalinteresdiapago']+number_format($idtotalmora, 2, '.', '');
					$totaldiasmora=$cred['diasmora']+$iddiasmora;
					//SUMA GENERAL DE COBROS DE DIAS MORA
						$valcredito=array(
						"diasmora"=>"'$totaldiasmora'",
						"totalinteresdiapago"=>"'$nuevomonto'"
						 	);
					   $credito->actualizar($valcredito,$idcredito);
						?>
							<script type="text/javascript">
							swal({
								title: "Exito",
								text: "Cobro realizado correctamente",
								type: "success",
								showCancelButton: false,
								confirmButtonColor: "#28e29e",
								confirmButtonText: "OK",
								closeOnConfirm: false
					          }, function () {
								location.reload();
					          });
							</script>
						<?php
				}else{
					?>
						<script type="text/javascript">
							swal("ERROR","No se registro","error");
						</script>
				   	<?php
				}
			break;
		
		case '3':
				$valcreditodet=array(
				"diasmora"=>"'$iddiasmora'",
				"estadodiasmora"=>"'1'",	//monto combrado		
				"fechafinmora"=>"'$idfechapago'"
			 	);
				if($creditodetalle->actualizar($valcreditodet,$idcreditodetalle))
				{
					$cred=$credito->muestra($idcredito);
					$nuevomonto=$cred['totalinteresdiapago']+number_format($idtotalmora, 2, '.', '');
					$totaldiasmora=$cred['diasmora']+$iddiasmora;
					//SUMA GENERAL DE COBROS DE DIAS MORA
						$valcredito=array(
						"diasmora"=>"'$totaldiasmora'",
						"totalinteresdiapago"=>"'$nuevomonto'"
						 	);
					   $credito->actualizar($valcredito,$idcredito);
						?>
							<script type="text/javascript">
							swal({
								title: "Exito",
								text: "Cobro realizado correctamente",
								type: "success",
								showCancelButton: false,
								confirmButtonColor: "#28e29e",
								confirmButtonText: "OK",
								closeOnConfirm: false
					          }, function () {
								location.reload();
					          });
							</script>
						<?php
				}else{
						?>
							<script type="text/javascript">
								swal("ERROR","No se registro","error");
							</script>
					   	<?php
				}
			break;
	}

	

?>