<%
Option Explicit
%>
<%
Session.LCID = 2058
%>
<!--#include file="User.asp"-->
<!--#include file="general.asp"-->
<html>
<head>
<title>Grupo MIM</title>
<link rel=stylesheet href="vista.css">
</head>
<BODY>
<!--#INCLUDE FILE="BARRA.asp"-->
<div class="normalw" style="position:absolute; top:1px">
<center>
<!--#include file="empresa.asp"--><br>
<hr>
</center>
</div>
<div class="normalw" style="position:absolute; top:1px;">
Bienvenido: <%= nombre %>. <br>
Hora Actual: <%= time %>
</div>
<div class="normalw" style="position:absolute; top:34px; left:1">
<!--#include file="mpro.asp"-->
</div>
<div class="normal" style="position:absolute; top:60px; left:10">
<Center>
<b>Cancelacion de Facturas
<hr>
<%
'****** Variables del Formulario *****
Dim Nfactura
'****** Variables del Recordset ******
Dim Rs11, Sql11, Rs12, Sql12, Rs13, Sql13, Rs14, Sql14, Rs15, Sql15
Dim Rs16, Sql16, Rs17, Sql17, Rs18, Sql18, Rs19, Sql19, Rs20, Sql20
Dim Rs21, Sql21
'***** Declaro Variables del Documento
Dim Saldo, Registro, Rcuenta, Anticipo, Idcxcg, Factual, MonedaF, MonedaA, TcambioA, Vanticipo, TcambioF
Dim DocR, RegR
'***** Vacio el valor de la Variable
Nfactura = Request("Ffacnum")
Factual = Date()
'****** Verifico la Existencia del Documento ******
Set Rs11 = server.CreateObject("ADODB.Recordset")
Sql11="select Numfface, Ranfface, antifface, nfacxcg, totfface, MONFFACE, Tcanti, Regcxcg, movcxcg, salcxcg, idrcxcg from ffacenc, cxcgen where nfacxcg = numfface " &_
"and movcxcg = 1 and numfface = "& Nfactura &";"
Rs11.open Sql11,cn1,1,2
If rs11.EOF then
%>
Lo sentimos No encontramos el documento solicitado.
<br>
<%
Else
While Not Rs11.Eof
Saldo = Cdbl(Rs11("salcxcg")) - Cdbl(Rs11("totfface")) + Cdbl(Rs11("antifface"))
Registro = Rs11("ranfface")
Anticipo = Rs11("antifface")
Idcxcg = Rs11("Idrcxcg")
MonedaF = Rs11("Monfface")
Rcuenta = Rs11("regcxcg")
TcambioF = Rs11("Tcanti")
If Cdbl(Saldo) < - 0.5 Then
%>
No Se Puede cancelar la Factura <%= Rs11("Numfface") %> Debido a que el Saldo Actual
de esta Factura es de <%= Rs11("Salcxcg") %> y el Importe Original fue de <%= (Cdbl(Rs11("Totfface")) - Cdbl(Rs11("Antifface"))) %>
<br>
<%
Else
'***** Si la Factura Tiene Anticipo, Lo regresamos ******
If Registro = 0 Then
Response.Write("No hay Anticipo <br>")
Else
Set Rs12 = server.CreateObject("ADODB.Recordset")
Sql12="Select Moncxcg, Tcacxcg From Cxcgen where Regcxcg = "& Registro &";"
Rs12.open Sql12,cn1,1,2
MonedaA = Rs12("Moncxcg")
TcambioA = Rs12("Tcacxcg")
'********** Determina el Valor del Anticipo
If Cdbl(MonedaF) < Cdbl(MonedaA) Then
Vanticipo = (Cdbl(Anticipo) / Cdbl(TcambioA))
Else If Cdbl(MonedaF) = Cdbl(MonedaA) Then
Vanticipo = Cdbl(Anticipo)
Else If Cdbl(MonedaF) > Cdbl(MonedaA) Then
Vanticipo = (Cdbl(Anticipo) * Cdbl(TcambioF))
End If
End If
End If
Response.write(Vanticipo & "Here")
'*** Actualizamos el Saldo del Anticipo
Set Rs13 = server.CreateObject("ADODB.Recordset")
Sql13="Update Cxcgen Set Salcxcg = Salcxcg - "& VAnticipo &", Imtcxcg = Imtcxcg - ( "& VAnticipo &" * Tcacxcg) Where Regcxcg = "& Registro &";"
Cn1.Execute Sql13
'*** Insertamos el registro de Devolucion del Anticipo ***
Set Rs14 = server.CreateObject("ADODB.Recordset")
Sql14="Insert into cxcdet " &_
"(MOVCXCD, CLICXCD, NFACXCD, REFCXCD, DOCCXCD, FRECXCD, FPACXCD, MONCXCD, TCACXCD, IMPCXCD, IMDCXCD, Idcxcg) " &_
"SELECT 34, Clicxcg, Nfacxcg, Nfacxcg, "& Nfactura &", '"& Factual &"', '"& Factual &"', Moncxcg, Tcacxcg, " &_
"("& VAnticipo &" * Tcacxcg * -1), ("& VAnticipo &" * -1), idrcxcg From cxcgen where Regcxcg = "& Registro &";"
Cn1.Execute Sql14
'*** Quitamos el Anticipo de la Factura ***
Set Rs14 = server.CreateObject("ADODB.Recordset")
Sql14="Insert into cxcdet " &_
"(MOVCXCD, CLICXCD, NFACXCD, REFCXCD, DOCCXCD, FRECXCD, FPACXCD, MONCXCD, TCACXCD, IMPCXCD, IMDCXCD, Idcxcg) " &_
"SELECT 33, Clicxcg, Nfacxcg, Nfacxcg, "& Nfactura &", '"& Factual &"', '"& Factual &"', Moncxcg, Tcacxcg, " &_
"("& VAnticipo &" * Tcacxcg), "& VAnticipo &", '"& Idcxcg &"' From cxcgen where Regcxcg = "& Registro &";"
Cn1.Execute Sql14
'*** Actualizamos el Saldo dela Factura
'Set Rs15 = server.CreateObject("ADODB.Recordset")
'Sql15="Update Cxcgen Set Salcxcg = Salcxcg + "& VAnticipo &", Imtcxcg = Imtcxcg + ( "& VAnticipo &" * Tcacxcg) Where Regcxcg = "& Rcuenta &";"
'Cn1.Execute Sql15
End If
'**** Actualizo el Status de la Factura
Set Rs16 = server.CreateObject("ADODB.Recordset")
Sql16="Update Ffacenc set faccan = '"& Factual &"', stafface = 'C', timfface = 100 where numfface = "& Nfactura &";"
Cn1.Execute Sql16
'**** Actualizo el Saldo del Cliente
set Rs17 = server.CreateObject("ADODB.Recordset")
Sql17="Update Clientes set Salcli = (Salcli - (Totfface * Tcafface)) " &_
"From Ffacenc where Clacli = Clifface and Numfface = "& Nfactura &";"
Cn1.Execute Sql17
Set Rs18 = server.CreateObject("ADODB.Recordset")
Sql18="Update Cxcgen " &_
"set Salcxcg = (Salcxcg - (totfface - Antifface)), " &_
"imtcxcg = (Imtcxcg - ((Totfface - Antifface )* Tcafface)) " &_
"From ffacenc where nfacxcg = numfface " &_
"and movcxcg = 1 and numfface = "& Nfactura &";"
Cn1.Execute Sql18
set rs17 = server.CreateObject("ADODB.Recordset")
Sql17="Insert into cxcdet " &_
"(MOVCXCD, CLICXCD, NFACXCD, REFCXCD, DOCCXCD, FRECXCD, FPACXCD, MONCXCD, TCACXCD, IMPCXCD, IMDCXCD, idcxcg) " &_
"SELECT 22, CLIFFACE, NUMFFACE, NUMFFACE, NUMFFACE, '"& Factual &"', '"& Factual &"', MONFFACE, TCAFFACE, " &_
"(TCAFFACE * TOTFFACE * -1), (TOTFFACE * -1), '"& Idcxcg &"' FROM FFACENC WHERE numfface = "& Nfactura &";"
Cn1.Execute sql17
Set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19="Select nfaffacd, antffacd, rgrffacd from ffacdet where nfaffacd = "& Nfactura &";"
Rs19.open Sql19,cn1,1,2
Do while Not Rs19.Eof
DocR = Rs19("Antffacd")
RegR = Rs19("Rgrffacd")
Set Rs20 = server.CreateObject("ADODB.Recordset")
Sql20="Update Fremenc set Stafreme = 'A' where Numfreme = "& DocR &";"
Cn1.Execute Sql20
Rs19.Movenext
loop
Set Rs21 = server.CreateObject("ADODB.Recordset")
Sql21="Update Fremdet set Csufremd = (Csufremd - Canffacd), Cpefremd = (Cpefremd + Canffacd), sigfremd = null " &_
"From ffacdet where Nfaffacd = "& Nfactura &" and regfremd = RGRFFACD;"
Cn1.Execute Sql21
Response.redirect("ffaccan.asp")
End If
Rs11.Movenext
Wend
End If
%>
<%= Registro %>
</div>
</body>
</html>
<%
End Sub
'Add the chosen course to the cart
Call AddUsuario()
'Display contents of electronic shopping cart
Call DisplayUsuario()
%>