<%
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"-->
<center>
<!--#include file="empresa.asp"--><br>
<hr>
<b>***** Cancelacion de Recepcion *****
<br>
<%
Dim Rs11, Rs12, Rs13, Rs14, Rs15, Rs16, Rs17, Rs18, Rs19, Rs20, Rs21, Rs22, Rs23, Rs24
Dim Sql11, Sql12, Sql13, Sql14, Sql15, Sql16, Sql17, Sql18, Sql19, Sql20, Sql21, Sql22, Sql23, Sql24
Dim Rs25, Rs26, Rs27, Rs28, Rs29, Rs30, Rs31, Rs32, Rs33, Rs34, Rs35, Rs36, Rs37, Rs38, Rs39, Rs40
Dim Sql25, Sql26, Sql27, Sql28, Sql29, Sql30, Sql31, Sql32, Sql33, Sql34, Sql35, Sql36, Sql37, Sql38, Sql39, Sql40
Dim Numrec, GeneraC, ExisteC, CantiC, GeneraCT
Dim RegistroR, AlmacenR, CodigoR, CantidadR
Dim CantidadU, RestanteU, RegistroU
Dim RegistroRe, CantidadRe, CantidadUc, RestanteUc, RegistroUC,TotalG
Dim FechaC, Saldo
Dim Supplier, Impesos, Regant, Idcxpg
Numrec = Request("Numrec")
FechaC = date()
'***** RECORDSET PARA SABER SI LA ENTRADA ESTA ACTIVA *****
Set Rs11 = Server.CreateObject("ADODB.Recordset")
Sql11="SELECT NUMRENC, STARENC, SubRenc, Totrenc, salcxpg, Vflete, TcaRenc " &_
"FROM CRECENC, cxpgen " &_
"WHERE Numrenc= Nrecxpg and NUMRENC = "& Numrec &";"
Rs11.Open Sql11,Cn1,1,2
TotalG = (Cdbl(Rs11("Subrenc")) - Cdbl(Rs11("Vflete"))) * 1.16
Impesos = Cdbl(TotalG) * Cdbl(Rs11("TcaRenc"))
Idcxpg = 1 & "-" & Numrec
Saldo = Cdbl(Rs11("salcxpg")) - Cdbl(TotalG)
If Rs11.Eof Then
%>
<BR>
***** NO EXISTE LA RECEPCION <%= Numrec %> *****
<BR><BR>
<a href="#" title="Cerrar" onclick="window.close()"><<< CERRAR >>></a>
<%
'**** ELSE DEL RECORDSET 11 ****
Else
'**** CONDICIONAL PARA SABER SI YA ESTA CANCELADO EL DOCUMENTO *****
If Rs11("STARENC") = 2 Then
%>
<BR>
***** LA RECEPCION <%= Numrec %> YA SE ENCUENTRA CANCELADA *****
<BR><BR>
<a href="#" title="Cerrar" onclick="window.close()"><<< CERRAR >>></a>
<%
'**** ELSE DEL RECORDSET 11 ****
Else
'**** CONDICIONAL PARA SABER SI YA ESTA CANCELADO EL DOCUMENTO *****
If Rs11("STARENC") = 2 Then
%>
<BR>
No Se Puede cancelar el documento <%= Rs11("NUMRENC") %> Debido a que el Saldo Actual
es de <%= Rs11("salcxpg") %> y el Importe Original fue de <%= Cdbl(Rs11("Totrenc")) %>
<BR><BR>
<a href="#" title="Cerrar" onclick="window.close()"><<< CERRAR >>></a>
<br>
<%
'***** ELSE CUANDO EL DOCUMENTO NO ESTA CANCELADO *****
Else
Set Rs12 = Server.CreateObject("ADODB.Recordset")
Sql12="select codrdet, sum(Crerdet) as Cantidad, EXIRMUL " &_
"from crecdet, MULTIALMACEN " &_
"where numrdet = "& Numrec &" AND ALMRDET = ALMMUL AND CODRDET = ARTMUL " &_
"group by CODRDET, EXIRMUL " &_
"order by CODRDET;"
Rs12.Open Sql12,Cn1,1,2
'****** CONDICIONAL SI LA RECEPCION NO TIENE PARTIDAD *****
If Rs12.Eof Then
%>
<BR>
***** LA RECEPCION <%= Numrec %> NO TIENE PARTIDAS POR CANCELAR *****
<BR><BR>
<a href="#" title="Cerrar" onclick="window.close()"><<< CERRAR >>></a>
<br>
<%
'******* CUANDO SI HAY PARTIDAS *****
Else
GeneraC = 0
Do While Not Rs12.Eof
ExisteC = Rs12("Exirmul")
CantiC = Rs12("Cantidad")
If Cdbl(ExisteC) < Cdbl(CantiC) Then
GeneraC = Cdbl(GeneraC) - 1
Else If Cdbl(ExisteC) = Cdbl(CantiC) Then
GeneraC = Cdbl(GeneraC) + 0
Else If Cdbl(ExisteC) > Cdbl(CantiC) Then
GeneraC = Cdbl(GeneraC) + 0
End If
End If
End If
Rs12.Movenext
Loop
GeneraCT = GeneraC
If Cdbl(GeneraCT) < 0 Then
%>
<BR>
***** SIN EXISTENCIAS SUFICIENTES PARA PROCESAR LA CANCELACION DE LA RECEPCION <%= Numrec %> *****
<BR><BR>
<a href="#" title="Cerrar" onclick="window.close()"><<< CERRAR >>></a>
<br>
<%
Else
'//****** EMPIEZO EL PROCESO PARA GENERAR LAS CAPAS UEPS DE LA CANCELACION DE LA RECEPCION ******//
Set Rs13 = Server.CreateObject("ADODB.Recordset")
Sql13="Select Regrdet, numrdet, Secrdet, Almrdet, Codrdet, Crerdet, Exirmul " &_
"From crecdet, Multialmacen " &_
"Where numrdet = "& Numrec &" and Almrdet = Almmul and Codrdet = Artmul " &_
"Order by Secrdet;"
Rs13.Open Sql13,Cn1,1,2
'****************** BUCLE DE LOS REGISTROS *******
Do While Not Rs13.Eof
RegistroR = Rs13("Regrdet")
CantidadR = Rs13("Crerdet")
Set Rs14 = Server.CreateObject("ADODB.Recordset")
Sql14="Select Regueps, Almueps, Codueps, Canueps, Punueps " &_
"From Ueps, crecdet " &_
"Where Regrdet = "& RegistroR &" and ALMRDET = Almueps and CODRDET = Codueps " &_
"Order by regueps desc;"
Rs14.Open Sql14,Cn1,1,2
Do While Not Rs14.Eof
RegistroU = Rs14("Regueps")
CantidadU = Rs14("Canueps")
RestanteU = CantidadR
'****************** UEPS *****
If Cdbl(CantidadR) < Cdbl(CantidadU) And Cdbl(CantidadR) > 0 Then
Set Rs15 = Server.CreateObject("ADODB.Recordset")
Sql15="update Ueps " &_
"Set Canueps = (Canueps - "& CantidadR &") " &_
"where Regueps = "& RegistroU &";"
Cn1.Execute Sql15
Set Rs16 = Server.CreateObject("ADODB.Recordset")
Sql16="Delete from Ueps " &_
"where Canueps = 0;"
Cn1.Execute Sql16
CantidadR = 0
Else If Cdbl(CantidadR) = Cdbl(CantidadU) And Cdbl(CantidadR) > 0 Then
Set Rs15 = Server.CreateObject("ADODB.Recordset")
Sql15="update Ueps " &_
"Set Canueps = (Canueps - "& CantidadR &") " &_
"where Regueps = "& RegistroU &";"
Cn1.Execute Sql15
Set Rs16 = Server.CreateObject("ADODB.Recordset")
Sql16="Delete from Ueps " &_
"where Canueps = 0;"
Cn1.Execute Sql16
CantidadR = 0
Else If Cdbl(CantidadR) > Cdbl(CantidadU) And Cdbl(CantidadR) > 0 Then
Set Rs15 = Server.CreateObject("ADODB.Recordset")
Sql15="update Ueps " &_
"Set Canueps = (Canueps - "& CantidadU &") " &_
"where Regueps = "& RegistroU &";"
Cn1.Execute Sql15
Set Rs16 = Server.CreateObject("ADODB.Recordset")
Sql16="Delete from Ueps " &_
"where Canueps = 0;"
Cn1.Execute Sql16
CantidadR = Cdbl(CantidadR) - Cdbl(CantidadU)
End If
End If
End If
Rs14.Movenext
Loop
Rs13.Movenext
Loop
'************* EMPIEZA EL RECORDSET DEL UEPSC *******
Set Rs17 = Server.CreateObject("ADODB.Recordset")
Sql17="Select REGRDET, NUMRDET, SECRDET, ALMRDET, CODRDET, CRERDET, Exirmul " &_
"From CRecDet, Multialmacen " &_
"Where NUMRDET = "& Numrec &" and ALMRDET = Almmul and CODRDET = Artmul " &_
"Order by SECRDET;"
Rs17.Open Sql17,Cn1,1,2
Do While Not Rs17.Eof
RegistroRe = Rs17("REGRDET")
CantidadRe = Rs17("CRERDET")
Set Rs18 = Server.CreateObject("ADODB.Recordset")
Sql18="Select Reguepsc, Almuepsc, Coduepsc, Canuepsc, Punuepsc " &_
"From Uepsc, crecdet " &_
"Where REGRDET = "& RegistroRe &" and ALMRDET = Almuepsc and codrdet = Coduepsc " &_
"Order by reguepsc desc;"
Rs18.Open Sql18,Cn1,1,2
Do While Not Rs18.Eof
RegistroUc = Rs18("Reguepsc")
CantidadUc = Rs18("Canuepsc")
RestanteUc = CantidadRe
If Cdbl(CantidadRe) < Cdbl(CantidadUc) and Cdbl(CantidadRe) > 0 Then
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv, Pedimento, YEARP, ADUANAP, PATENTEP, PEDIMENTOP) " &_
"Select 57, numrdet, '"& FechaC &"', almrdet, codrdet, "& CantidadRe &", (Exirmul - "& CantidadRe &"), (punrdet * Tcardet), " &_
"Punuepsc, 0, Monrdet, tcardet, prorenc, 0, '', '"& Nombre &"', " &_
"cpmul, Uepsc.Pedimento, Uepsc.yearp, Uepsc.Aduanap, Uepsc.patentep, Uepsc.pedimentop " &_
"from Crecdet, crecenc, Multialmacen, Uepsc " &_
"Where Numrdet = numrenc and Regrdet = "& RegistroRe &" and Almrdet = Almmul and Codrdet = Artmul " &_
"and Reguepsc = "& RegistroUc &";"
Cn1.Execute Sql19
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20="Update Multialmacen " &_
"Set Exirmul = (exirmul - "& CantidadRe &"), Eximul = (eximul - "& CantidadRe &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and almmul = almuepsc and Coduepsc = Artmul;"
Cn1.Execute Sql20
Set Rs21 = Server.CreateObject("ADODB.Recordset")
Sql21="Update Inventarios " &_
"Set Exirinv = (exirinv - "& CantidadRe &"), Exiinv = (exiinv - "& CantidadRe &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and Coduepsc = Cveinv;"
Cn1.Execute Sql21
Set Rs22 = Server.CreateObject("ADODB.Recordset")
Sql22="update UepsC " &_
"Set Canuepsc = (Canuepsc - "& CantidadRe &") " &_
"where Reguepsc = "& RegistroUC &";"
Cn1.Execute Sql22
Set Rs23 = Server.CreateObject("ADODB.Recordset")
Sql23="Delete from Uepsc " &_
"where Canuepsc = 0;"
Cn1.Execute Sql23
CantidadRe = 0
Else If Cdbl(CantidadRe) = Cdbl(CantidadUc) and Cdbl(CantidadRe) > 0 Then
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv, Pedimento, YEARP, ADUANAP, PATENTEP, PEDIMENTOP) " &_
"Select 57, numrdet, '"& FechaC &"', almrdet, codrdet, "& CantidadRe &", (Exirmul - "& CantidadRe &"), (punrdet * Tcardet), " &_
"Punuepsc, 0, Monrdet, tcardet, prorenc, 0, '', '"& Nombre &"', " &_
"cpmul, Uepsc.Pedimento, Uepsc.yearp, Uepsc.Aduanap, Uepsc.patentep, Uepsc.pedimentop " &_
"from Crecdet, crecenc, Multialmacen, Uepsc " &_
"Where Numrdet = numrenc and Regrdet = "& RegistroRe &" and Almrdet = Almmul and Codrdet = Artmul " &_
"and Reguepsc = "& RegistroUc &";"
Cn1.Execute Sql19
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20="Update Multialmacen " &_
"Set Exirmul = (exirmul - "& CantidadRe &"), Eximul = (eximul - "& CantidadRe &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and almmul = almuepsc and Coduepsc = Artmul;"
Cn1.Execute Sql20
Set Rs21 = Server.CreateObject("ADODB.Recordset")
Sql21="Update Inventarios " &_
"Set Exirinv = (exirinv - "& CantidadRe &"), Exiinv = (exiinv - "& CantidadRe &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and Coduepsc = Cveinv;"
Cn1.Execute Sql21
Set Rs22 = Server.CreateObject("ADODB.Recordset")
Sql22="update UepsC " &_
"Set Canuepsc = (Canuepsc - "& CantidadRe &") " &_
"where Reguepsc = "& RegistroUC &";"
Cn1.Execute Sql22
Set Rs23 = Server.CreateObject("ADODB.Recordset")
Sql23="Delete from Uepsc " &_
"where Canuepsc = 0;"
Cn1.Execute Sql23
CantidadRe = 0
Else If Cdbl(CantidadRe) > Cdbl(CantidadUc) and Cdbl(CantidadRe) > 0 Then
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv, Pedimento, YEARP, ADUANAP, PATENTEP, PEDIMENTOP) " &_
"Select 57, numrdet, '"& FechaC &"', almrdet, codrdet, "& CantidadUc &", (Exirmul - "& CantidadUc &"), (punrdet * Tcardet), " &_
"Punuepsc, 0, Monrdet, tcardet, prorenc, 0, '', '"& Nombre &"', " &_
"cpmul, Uepsc.Pedimento, Uepsc.yearp, Uepsc.Aduanap, Uepsc.patentep, Uepsc.pedimentop " &_
"from Crecdet, crecenc, Multialmacen, Uepsc " &_
"Where Numrdet = numrenc and Regrdet = "& RegistroRe &" and Almrdet = Almmul and Codrdet = Artmul " &_
"and Reguepsc = "& RegistroUc &";"
Cn1.Execute Sql19
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20="Update Multialmacen " &_
"Set Exirmul = (exirmul - "& CantidadUc &"), Eximul = (eximul - "& CantidadUc &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and almmul = almuepsc and Coduepsc = Artmul;"
Cn1.Execute Sql20
Set Rs21 = Server.CreateObject("ADODB.Recordset")
Sql21="Update Inventarios " &_
"Set Exirinv = (exirinv - "& CantidadUc &"), Exiinv = (exiinv - "& CantidadUc &") " &_
"From Uepsc where Reguepsc = "& RegistroUC &" and Coduepsc = Cveinv;"
Cn1.Execute Sql21
Set Rs22 = Server.CreateObject("ADODB.Recordset")
Sql22="update UepsC " &_
"Set Canuepsc = (Canuepsc - "& CantidadUc &") " &_
"where Reguepsc = "& RegistroUC &";"
Cn1.Execute Sql22
Set Rs23 = Server.CreateObject("ADODB.Recordset")
Sql23="Delete from Uepsc " &_
"where Canuepsc = 0;"
Cn1.Execute Sql23
CantidadRe = Cdbl(CantidadRe) - Cdbl(CantidadUc)
End If
End If
End If
Rs18.Movenext
Loop
Rs17.Movenext
Loop
Set Rs24 = Server.CreateObject("ADODB.Recordset")
Sql24="Update Crecenc " &_
"Set Starenc = 2 " &_
"Where Numrenc = "& Numrec &";"
Cn1.Execute Sql24
Set Rs25 = server.CreateObject("ADODB.Recordset")
Sql25 ="UPDATE MULTIALMACEN SET DESMUL = NOMINV FROM INVENTARIOS WHERE CVEINV = ARTMUL AND ALMMUL = 1;"
cn1.execute Sql25
Set Rs26 = server.CreateObject("ADODB.Recordset")
sql26 ="update multialmacen set desmul = nominv from inventarios where artmul = cveinv and almmul = 1 and embdire is null;"
cn1.execute Sql26
Set Rs27 = server.CreateObject("ADODB.Recordset")
sql27="update multialmacen set embdire = 0 where embdire is null;"
cn1.execute Sql27
Set Rs28 = server.CreateObject("ADODB.Recordset")
sql28="UPDATE MULTIALMACEN SET CAPMUL = 0 WHERE ALMMUL = 1;"
cn1.execute Sql28
Set Rs29 = server.CreateObject("ADODB.Recordset")
sql29="UPDATE MULTIALMACEN SET CAPMUL = CANTIDAD FROM APARTADOSB WHERE ARTMUL = CODIGO AND ALMMUL = 1;"
cn1.execute Sql29
Set Rs30 = server.CreateObject("ADODB.Recordset")
sql30="UPDATE MULTIALMACEN SET EMBDIRE = 0 WHERE ALMMUL = 1;"
cn1.execute Sql30
Set Rs31 = server.CreateObject("ADODB.Recordset")
sql31="UPDATE MULTIALMACEN SET EMBDIRE = CANTIDAD FROM APARTADOSD WHERE ARTMUL = CODIGO AND ALMMUL = 1;"
cn1.execute Sql31
Set Rs32 = server.CreateObject("ADODB.Recordset")
Sql32="UPDATE MULTIALMACEN SET RSEM = 0;"
Cn1.Execute Sql32
Set Rs33 = server.CreateObject("ADODB.Recordset")
Sql33="UPDATE MULTIALMACEN " &_
"SET RSEM = CANTIDAD " &_
"FROM ARSE " &_
"WHERE ALMMUL = Almacen AND ARTMUL = codigo;"
Cn1.Execute Sql33
Set Rs34 = server.CreateObject("ADODB.Recordset")
Sql34="Update corddet set nreord = null, Cpeord = (CPEORD + CRERDET), CSUORD = (CSUORD - CRERDET)" &_
"FROM CRECDET WHERE PANRDET = REGORD AND Numrdet = '"& Numrec &"';"
Cn1.Execute Sql34
Set Rs35 = server.CreateObject("ADODB.Recordset")
Sql35="select regrenc, numrenc, prorenc, monrenc, tcarenc, subrenc, ivtrenc, totrenc, starenc, reggas," &_
"cveprv, salprv from crecenc, proveedores where cveprv = prorenc and numrenc = "& Numrec &";"
Rs35.open Sql35,cn1,1,2
Do while not Rs35.EOF
Supplier = Rs35("cveprv")
'Impesos = Formatnumber(Rs35("totrenc")) * Formatnumber(Rs35("tcarenc"))
Regant = Rs35("reggas")
Set Rs36 = server.CreateObject("ADODB.Recordset")
Sql36="Update crecenc set starenc =2 where numrenc = "& Numrec &";"
Cn1.Execute Sql36
Set Rs37 = server.CreateObject("ADODB.Recordset")
Sql37="Update proveedores set salprv = (Salprv - "& Impesos &") from crecenc where cveprv = prorenc " &_
"and numrenc = '"& Numrec &"';"
Cn1.Execute Sql37
Set Rs38 = server.CreateObject("ADODB.Recordset")
Sql38="Update cxpgen set salcxpg = 0, Imtcxpg=0, Pagcxpg = Impcxpg where prvcxpg = '"& Supplier &"' " &_
"and nrecxpg = "& Numrec &";"
Cn1.Execute Sql38
Set Rs39 = server.CreateObject("ADODB.Recordset")
Sql39="Insert into cxpdet (Movcxpd, Prvcxpd, Nrecxpd, Refcxpd, doccxpd, Frecxpd, fpacxpd, moncxpd, tcacxpd, impcxpd, imdcxpd, idrcxpd) " &_
"select 9, prorenc, numrenc, refrenc, numrenc, '"& FechaC &"', '"& FechaC &"', monrenc, tcarenc, " &_
""& Impesos &", "& TotalG &", '"& Idcxpg &"' from crecenc where numrenc = "& Numrec &";"
Cn1.Execute Sql39
Set Rs40 = server.CreateObject("ADODB.Recordset")
Sql40="Update cordgim set staordg = 0 where regordg = "& Regant &";"
Cn1.Execute Sql40
Rs35.MoveNext
Loop
Response.Redirect("Recesp.asp?numrec="& Numrec &"&Empresa="& Negocio &"")
%>
<%
End If
End If
'**** END DEL DOCUMENTO *****
End If
End If
%>
<%
'***** END DEL RECORDSET 11 ****
End If
%>
</center>
</body>
</html>
<%
End Sub
'Add the chosen course to the cart
Call AddUsuario()
'Display contents of electronic shopping cart
Call DisplayUsuario()
%>