<%
Option Explicit
Session.LCID = 2058
'***** SI NO HA INICIADO SESION ***
If Session("Mybussiness") = "" then
Response.redirect("default.asp")
Else
'******* EN CASO DE ERROR ****
Err.Clear
On Error Resume Next
'*** REMPLAZA
Function Sanea(Texto)
Sanea = Replace(Texto, "'", "''")
End Function
%>
<!DOCTYPE html>
<HTML>
<HEAD>
<meta charset="ISO-8859-1" />
<TITLE>SISTEMA MIM <%= Session("Mybussiness") %> USUARIO: <%= Session("MyName") %></TITLE>
<link href="css/GestorC.css" rel="stylesheet" />
<link href="css/Buscador.css" rel="stylesheet" />
</HEAD>
<BODY>
<%
'***** Variables a la base de datos ****
Dim Cn1
Dim Rs11, Rs12, Rs13, Rs14, Rs15, Rs16, Rs17, Rs18, Rs19, Rs20, Rs21, Rs22, Rs23
Dim Sql11, Sql12, Sql13, Sql14, Sql15, Sql16, Sql17, Sql18, Sql19, Sql20, Sql21, Sql22, Sql23
'***** Conexion a la Base de Datos
Set Cn1 = Server.CreateObject( "ADODB.Connection" )
Cn1.Open "DRIVER={SQL Server};SERVER=172.17.0.5;UID="& Session("MyName") &";PWD="& Session("MyPass") &";Database="& Session("Mybussiness") &""
'***** Conexion A la Tabla Empresa ****
Set Rs11 = Server.CreateObject("ADODB.Recordset")
Sql11="Select * from Empresa;"
Rs11.Open Sql11,Cn1,1,2
%>
<SECTION Class="HeaderGes">
<div Id="DivHeadGes">
<%= Rs11("Nombre") %><br>
<%= Rs11("Direccion") %>, <%= Rs11("colonia") %><br>
<%= Rs11("Poblacion") %>
</div>
</SECTION>
<SECTION>
<!---menu --->
<br><br><br><br>
</SECTION>
<SECTION>
<%
Dim ImporteA, TcambioA, MonedaD, Factura, Documento, Vpago, Pago, Moneda, SAldoR, FechaP, Tpago, Observaciones, Ipesos, ValorC, ValorO, Clacli, Pergan, ImporteO
Dim FechaC, Tdestino, Ncobranza, Mpago, ImporteP, FacturaA, TcambioD
Factura = Request("Factura")
FacturaA = Request("FacturaA")
Documento = Session.sessionid
ImporteA = Request("ImporteA")
ImporteP = Request("ImporteP")
TcambioA = Request("TcambioA")
TcambioD = Request("TcambioD")
MonedaD = Request("MonedaD")
Vpago = Request("Vpago")
FechaP = Request("FechaP")
Tpago = Request("Tpago")
Observaciones = Request("Observaciones")
Tdestino = Request("Tdestino")
FechaC = Date()
Mpago = Request("Mpago")
Clacli = Request("Clacli")
Set Rs12 = server.CreateObject("ADODB.Recordset")
Sql12 = "Select * from Cobdtem, Cxcgen where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and Clicobtem='"& Clacli &"' order by RegCobtem;"
Rs12.open Sql12,Cn1,1,2
Pergan=cdbl(Rs12("PerganCobtem"))
'************************ GENERA EL MOVIMIENTO A CXCDET ************
Set Rs13 = server.CreateObject("ADODB.Recordset")
Sql13 = "Insert into Cxcdet (Movcxcd, Clicxcd, nfacxcd, refcxcd, doccxcd, Frecxcd, Fpacxcd, moncxcd, tcacxcd, "&_
"impcxcd, imdcxcd, tcdcxcd, idcxcg) " &_
"Select "& Tpago &", Clicobtem, FacCobtem, "& Factura &", "& Factura &", '"& FechaP &"', '"& FechaP &"', "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then MonSaCobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then MonSaCobtem end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then Tcasacobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then TcaACobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then Tcasacobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then Tcasacobtem end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then (-1 * ImpaCobtem) "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then (-1 * ImpaCobtem * TcaACobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then (-1 * ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then (-1 * ImpaCobtem * TcaSaCobtem) end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then (-1 * ImpaCobtem) / TcaSaCobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then (-1 * ImpaCobtem ) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then (-1 * ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then (-1 * ImpaCobtem) end, Tcacxcg, idrcxcg "&_
"from cxcgen, Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql13
'************************ GENERA EL MOVIMIENTO A COBRANZA ************
Set Rs14 = server.CreateObject("ADODB.Recordset")
Sql14 = "Select Cobranza From Consecutivos;"
Rs14.Open Sql14,cn1,1,2
Ncobranza = Rs14("Cobranza") + 1
Set Rs15 = server.CreateObject("ADODB.Recordset")
Sql15 = "Update Consecutivos Set Cobranza = "& Ncobranza &";"
Cn1.Execute Sql15
Set Rs16 = server.CreateObject("ADODB.Recordset")
Sql16 = "Insert Into Cobranza (CliCob, FecCob, Capcob, FolCob, TipCob, DocCob, ImpCob, Obscob, TpaCob, MonCob, "&_
"TcaCob, Descob, UsrCob) " &_
"Select Clicobtem, '"& FechaP &"', '"& FechaC &"', "& Ncobranza &", "& Tpago &", FacCobtem, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then (ImpaCobtem) "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then (ImpaCobtem * Tcasacobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then (ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then (ImpaCobtem * Tcasacobtem) end, '"& Sanea(Observaciones) &"', 3, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then MonSaCobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then MonSaCobtem end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then Tcasacobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then TcaACobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then Tcasacobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then Tcasacobtem end, "& TDestino &", '"& Session("MyName") &"' " &_
"from cxcgen, Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql16
'************************ ACTUALIZA EL SALDO DE CXCGEN ************
Set Rs17 = server.CreateObject("ADODB.Recordset")
Sql17= "Update cxcgen Set Salcxcg = (Salcxcg - ImpaCobtem), imtcxcg = (imtcxcg - (ImpaCobtem * Tcacxcg)), Pagcxcg = (Pagcxcg + ImpaCobtem) " &_
"from Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql17
Set Rs18 = server.CreateObject("ADODB.Recordset")
Sql18 = "Insert into Cxcdet (Movcxcd, Clicxcd, nfacxcd, refcxcd, doccxcd, Frecxcd, Fpacxcd, moncxcd, tcacxcd, "&_
"impcxcd, imdcxcd, tcdcxcd, idcxcg) " &_
"Select case when PerganCobtem < 0 Then 23 Else 24 End, clicxcg, nfacxcg, doccxcg, doccxcg, '"& FechaP &"', '"& FechaP &"', "& MonedaD &", tcaACobtem, "&_
"PerganCobtem,0 , Tcacxcg, idrcxcg " &_
"from cxcgen, Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and PerganCobtem <>0 and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql18
Set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Insert Into Cobranza " &_
"(CliCob, FecCob, Capcob, FolCob, TipCob, DocCob, ImpCob, Obscob, TpaCob, MonCob, TcaCob, Descob, UsrCob) " &_
"Select Clicxcg, '"& FechaP &"', '"& FechaC &"', "& Ncobranza &", case when PerganCobtem < 0 Then 23 Else 24 End, nfacxcg, PerganCobtem, '"& Sanea(Observaciones) &"', " &_
"3, "& MonedaD &", tcaACobtem, "& TDestino &", '"& Session("MyName") &"' " &_
"from cxcgen, Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and PerganCobtem <>0 and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql19
'************************ ACTUALIZA EL SALDO DE CXCGEN ************
'Set Rs20 = server.CreateObject("ADODB.Recordset")
'Sql20= "Update cxcgen " &_
'"Set imtcxcg = (imtcxcg + PerganCobtem) from cxcgen, Cobdtem where nfacxcg = FacCobtem and SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
'Cn1.Execute Sql20
Set Rs21 = server.CreateObject("ADODB.Recordset")
Sql21 = "Insert into Cxcdet (Movcxcd, Clicxcd, nfacxcd, refcxcd, doccxcd, Frecxcd, Fpacxcd, moncxcd, tcacxcd, "&_
"impcxcd, imdcxcd, tcdcxcd, idcxcg) " &_
"Select 26, Clicobtem, "& Factura &", FacCobtem, FacCobtem, '"& FechaP &"', '"& FechaP &"', "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then MonSaCobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then MonSaCobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then MonSaCobtem end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then Tcasacobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then TcaACobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then Tcasacobtem "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then Tcasacobtem end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then (ImpaCobtem) "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then (ImpaCobtem * TcaACobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then (ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then (ImpaCobtem * TcaSaCobtem) end, "&_
"case when moncobtem <> MonSaCobtem and monsacobtem = 2 then (ImpaCobtem) / TcaSaCobtem "&_
"when moncobtem <> MonSaCobtem and monsacobtem = 1 then (ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 1 then (ImpaCobtem) "&_
"when moncobtem = MonSaCobtem and monsacobtem = 2 then (ImpaCobtem) end, Tcacxcg, idrcxcg "&_
"from cxcgen, Cobdtem where nfacxcg = DocsCobtem and clicobtem=Clicxcg and SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql21
Set Rs22 = server.CreateObject("ADODB.Recordset")
Sql22= "Update cxcgen Set Salcxcg = "& Vpago &", imtcxcg = "& Vpago &" * Tcacxcg, Pagcxcg = Impcxcg - "& Vpago &" " &_
"from cxcgen where nfacxcg = "& Factura &" and clicxcg = '"& Clacli &"' ;"
Cn1.Execute Sql22
If MonedaD = 1 and TcambioA > 1 then
Tcambioa = 1/TcambioA
else
TcambioA = TcambioD
End if
ImporteP = (-1 * cdbl(ImporteA)) + cdbl(Vpago)
If Mpago = "PUE" Then
Set Rs23 = server.CreateObject("ADODB.Recordset")
Sql23= "Delete Cobdtem where SesCobtem = "& Documento &" and Clicobtem = '"& Clacli &"' and DocsCobtem = "& Factura &";"
Cn1.Execute Sql23
Response.Redirect("CxcApli.asp")
else
Response.Redirect("CxcAplocpInsert.asp?Clacli="& Clacli &"&MonedaD="&MonedaD&"&TcambioA="&TcambioA&"&FechaP="&FechaP&"&Tpago="&Tpago&"&Mpago="&Mpago&"&Tdestino="&Tdestino&"&ImporteP="&ImporteP&"&Factura="&Factura&"")
End If
Response.write(Clacli)
Response.write(ImporteA)
%>
<%
If Err.Number <> 0 Then
%>
<br><br>
Número de Error: <%= Err.Number %><BR>
Descripción: <%= Err.Description %><BR>
Origen: <%= Err.Source %><BR>
Linea: <%= Err.Line %><BR>
<br>
<%
Else
'****** FIN DE LOS ERRORES ***
End If
%>
</BODY>
</HTML>
<%
'FIN DE SESION
End If
%>