<%
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>
Devolucion de Material
<hr>
<%
Dim Entrada, Folio, Docu, Factual
Dim Almacen, Codigo, Csol, Csolo
Dim Uepscan, CostoUeps, UepsIndex, CanCap, CanRem, NewUeps
Dim UepscanC, CostoUepsC, UepsIndexC, CanCapC, CanRemC, NewUepsC
Dim ImporteD, IvaEnc, IvaDev, TotalD
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, Rs22, Sql22, Rs23, Sql23, Rs24, Sql24, Rs25, Sql25
Dim Rs26, Sql26, Rs27, Sql27, Rs28, Sql28, Rs29, Sql29, Rs30, sql30
Dim Rsa, Sqla, Rsb, Sqlb
Entrada = Request("Entrada")
Docu = Session.SessionID
Factual = Date()
'*************** OBTENGO EL FOLIO DE LA DEVOLUCION **********
Set Rs11 = server.CreateObject("ADODB.Recordset")
Sql11="Select DevInt from consecutivos;"
Rs11.open sql11,cn1,1,2
Folio = Rs11("DevInt") + 1
'************* CHECO SI TENGO PARTIDAS EN EL TEMPORAL DE DEVOLUCION ***********
Set Rs12 = server.CreateObject("ADODB.Recordset")
Sql12="Select * from CrecdevT where Doctrecd = "& Docu &";"
Rs12.open sql12,cn1,1,2
If Rs12.EOF then
%>
No hay partidas a Devolver<br>
<a href="javascript:history.back(2)">Regresar</a>
<%
Else
While (Not Rs12.Eof)
Almacen = Rs12("Almtrecd")
Codigo = Rs12("Codtrecd")
Csol = Rs12("Cretrecd")
Csolo = Rs12("Cretrecd")
'*******************************COSTEO PARA UEPS ***************************
Response.write("Estoy aqui")
set rs13 = server.CreateObject("ADODB.Recordset")
sql13="Select * from Ueps " &_
"where almueps = "& Almacen &" and CodUeps = '"& Codigo &"' order by regueps desc;"
rs13.open sql13,cn1,1,2
While (Not Rs13.Eof)
Uepscan = rs13("canueps")
Costoueps = rs13("punueps")
UepsIndex = rs13("regueps")
'*********************** PRIMER IF SI LO SOLICITADO ES MENOR A LA CAPA UEPS *********************************
If Cdbl(Csol) < Cdbl(Uepscan) and Cdbl(Csol) > 0 then
CanCap = Cdbl(Csol)
CanRem = Cdbl(CanRem) + Cdbl(Csol)
NewUeps = Cdbl(UepsCan) - Cdbl(Cancap)
set rs14 = server.CreateObject("ADODB.Recordset")
sql14 = "Update ueps set canueps = "& Newueps &" where almueps = "& Almacen &" and codueps = '"& codigo &"' " &_
"and regueps = "& UepsIndex &";"
Cn1.Execute sql14
set Rsa = server.CreateObject("ADODB.Recordset")
Sqla = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqla
Csol = 0
Response.Write("UEPS 1 <br>")
'--------------- SEGUNDO IF SI LO SOLICITADO ES IGUAL A LA CAPA UEPS ----------------
Else If Cdbl(Csol) = Cdbl(Uepscan) and Cdbl(Csol) > 0 then
Cancap = Cdbl(Csol)
Canrem = Cdbl(Canrem) + Cdbl(Csol)
NewUeps = 0
set rs14 = server.CreateObject("ADODB.Recordset")
sql14 = "Update ueps set canueps = "& Newueps &" where almueps = "& Almacen &" and codueps = '"& codigo &"' " &_
"and regueps = "& UepsIndex &";"
Cn1.Execute sql14
set Rsa = server.CreateObject("ADODB.Recordset")
Sqla = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqla
Csol = 0
Response.Write("UEPS 2 <br>")
'--------------- TERCER IF SI LO SOLICITADO ES MAYOR A LA CAPA UEPS ----------------
Else If Cdbl(Csol) > Cdbl(Uepscan) and Cdbl(Csol) > 0 then
Cancap = Cdbl(Uepscan)
Canrem = Cdbl(Canrem) + Cdbl(UepsCan)
NewUeps = 0
set rs14 = server.CreateObject("ADODB.Recordset")
sql14 = "Update ueps set canueps = "& Newueps &" where almueps = "& Almacen &" and codueps = '"& codigo &"' " &_
"and regueps = "& UepsIndex &";"
Cn1.Execute sql14
set Rsa = server.CreateObject("ADODB.Recordset")
Sqla = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqla
Csol = Cdbl(Csol) - Cdbl(Uepscan)
Response.Write("UEPS 3 <br>")
End If
End If
End If
RS13.MoveNext
Wend
'******************************* COSTEO CONTABILIDAD *****************************************
set Rs15 = server.CreateObject("ADODB.Recordset")
Sql15="Select * from UepsC " &_
"where almuepsC = "& Almacen &" and CodUepsC = '"& Codigo &"' order by reguepsc desc;"
rs15.open sql15,cn1,1,2
While (Not Rs15.Eof)
UepscanC = rs15("canuepsC")
CostouepsC = rs15("punuepsC")
UepsIndexC = rs15("reguepsC")
'*********************** PRIMER IF SI LO SOLICITADO ES MENOR A LA CAPA UEPS *********************************
If Cdbl(Csolo) < Cdbl(UepscanC) and Cdbl(Csolo) > 0 then
CanCapC = Cdbl(Csolo)
CanRemC = Cdbl(CanRemC) + Cdbl(Csolo)
NewUepsC = Cdbl(UepsCanC) - Cdbl(CancapC)
set rs16 = server.CreateObject("ADODB.Recordset")
sql16 = "Update uepsc set canuepsc = "& Newuepsc &" where almuepsc = "& Almacen &" and coduepsc = '"& codigo &"' " &_
"and reguepsc = "& UepsIndexc &";"
Cn1.Execute sql16
set rs17 = server.CreateObject("ADODB.Recordset")
sql17 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv) " &_
"Select 80, "& Folio &", '"& Factual &"', "& Almacen &", '"& Codigo &"', "& CancapC &", (Exirmul - "& Cancapc &"), 0, " &_
""& CostoUepsC &", 0, 1, 1, '000000', 0, 'Devolucion a Proveedor', '"& Nombre &"', " &_
"cpmul from multialmacen where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
cn1.Execute sql17
set Rs18 = server.CreateObject("ADODB.Recordset")
Sql18 = "Update multialmacen set eximul = (Eximul - "& CancapC &"), exirmul = (Exirmul - "& CancapC &"), Capmul = (Capmul - "& CancapC &"), " &_
"fuvmul = '"& Factual &"' " &_
"where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
Cn1.Execute Sql18
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Update Inventarios set exiinv = (Exiinv - "& CancapC &"), exirinv = (Exirinv - "& CanCapC &") " &_
"where CveInv = '"& Codigo &"';"
Cn1.Execute Sql19
set Rsb = server.CreateObject("ADODB.Recordset")
Sqlb = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqlb
Csolo = 0
Response.Write("UEPSc 1 <br>")
'--------------- SEGUNDO IF SI LO SOLICITADO ES IGUAL A LA CAPA UEPS ----------------
Else If Cdbl(Csolo) = Cdbl(Uepscanc) and Cdbl(Csolo) > 0 then
CancapC = Cdbl(Csolo)
CanremC = Cdbl(CanremC) + Cdbl(Csolo)
NewUepsC = 0
set rs16 = server.CreateObject("ADODB.Recordset")
sql16 = "Update uepsc set canuepsc = "& Newuepsc &" where almuepsc = "& Almacen &" and coduepsc = '"& codigo &"' " &_
"and reguepsc = "& UepsIndexc &";"
Cn1.Execute sql16
set rs17 = server.CreateObject("ADODB.Recordset")
sql17 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv) " &_
"Select 80, "& Folio &", '"& Factual &"', "& Almacen &", '"& Codigo &"', "& CancapC &", (Exirmul - "& Cancapc &"), 0, " &_
""& CostoUepsC &", 0, 1, 1, '000000', 0, 'Devolucion a Proveedor', '"& Nombre &"', " &_
"cpmul from multialmacen where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
cn1.Execute sql17
set Rs18 = server.CreateObject("ADODB.Recordset")
Sql18 = "Update multialmacen set eximul = (Eximul - "& CancapC &"), exirmul = (Exirmul - "& CancapC &"), Capmul = (Capmul - "& CancapC &"), " &_
"fuvmul = '"& Factual &"' " &_
"where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
Cn1.Execute Sql18
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Update Inventarios set exiinv = (Exiinv - "& CancapC &"), exirinv = (Exirinv - "& CanCapC &") " &_
"where CveInv = '"& Codigo &"';"
Cn1.Execute Sql19
set Rsb = server.CreateObject("ADODB.Recordset")
Sqlb = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqlb
Csolo = 0
Response.Write("UEPS 2 <br>")
'--------------- TERCER IF SI LO SOLICITADO ES MAYOR A LA CAPA UEPS ----------------
Else If Cdbl(Csolo) > Cdbl(Uepscanc) and Cdbl(Csolo) > 0 then
Cancapc = Cdbl(Uepscanc)
Canremc = Cdbl(Canremc) + Cdbl(UepsCanc)
NewUepsc = 0
set rs16 = server.CreateObject("ADODB.Recordset")
sql16 = "Update uepsc set canuepsc = "& Newuepsc &" where almuepsc = "& Almacen &" and coduepsc = '"& codigo &"' " &_
"and reguepsc = "& UepsIndexc &";"
Cn1.Execute sql16
set rs17 = server.CreateObject("ADODB.Recordset")
sql17 = "Insert into movinv (tmominv, docminv, fecminv, almminv, codminv, canminv, Eximinv, prvminv, ucominv, " &_
"pgaminv, monminv, tcaminv, cprminv, venminv, obsminv, usrminv, CpMinv) " &_
"Select 80, "& Folio &", '"& Factual &"', "& Almacen &", '"& Codigo &"', "& UepscanC &", (Exirmul - "& Uepscanc &"), 0, " &_
""& CostoUepsC &", 0, 1, 1, '000000', 0, 'Devolucion a Proveedor', '"& Nombre &"', " &_
"cpmul from multialmacen where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
cn1.Execute sql17
set Rs18 = server.CreateObject("ADODB.Recordset")
Sql18 = "Update multialmacen set eximul = (Eximul - "& UepscanC &"), exirmul = (Exirmul - "& UepscanC &"), " &_
"fuvmul = '"& Factual &"' " &_
"where almmul = "& Almacen &" and artmul = '"& Codigo &"';"
Cn1.Execute Sql18
set Rs19 = server.CreateObject("ADODB.Recordset")
Sql19 = "Update Inventarios set exiinv = (Exiinv - "& Uepscanc &"), exirinv = (Exirinv - "& UepscanC &") " &_
"where CveInv = '"& Codigo &"';"
Cn1.Execute Sql19
set Rsb = server.CreateObject("ADODB.Recordset")
Sqlb = "Delete from ueps where Canueps = 0;"
Cn1.Execute Sqlb
Csolo = Cdbl(Csolo) - Cdbl(Uepscanc)
Response.Write("UEPS 3 <br>")
End If
End If
End If
RS15.MoveNext
Wend
RS12.MoveNext
Wend
'***************** INSERTO LAS PARTIDAS EN EL DETALLE DE LA DEVOLUCION *******
set Rs20 = server.CreateObject("ADODB.Recordset")
Sql20 = "Insert Into CRecdidet " &_
"(Numrdevd, secrdevd, panrdevd, almrdevd, codrdevd, crerdevd, punrdevd, monrdevd, tcardevd, pinrdevd, ppirdevd, obsrdevd) " &_
"Select "& Folio &", SecRdet, regrdet, almrdet, codrdet, cretrecd, puntrecd, monrdet, tcardet, 0, 0, 'Devolucion de la Entrada: "& Entrada &"' " &_
"From Crecdet, Crecdevt " &_
"where Numrdet = "& Entrada &" and pantrecd = regrdet;"
Cn1.Execute Sql20
Set Rs21 = server.CreateObject("ADODB.Recordset")
Sql21="select Sum(crerdevd * punrdevd) as Importe " &_
"from CRecdidet " &_
"where Numrdevd = "& Folio &" " &_
"group by Numrdevd;"
Rs21.open sql21,cn1,1,2
ImporteD = Rs21("Importe")
Set Rs22 = server.CreateObject("ADODB.Recordset")
Sql22="Select Ivarenc from Crecenc where Numrenc = "& Entrada &";"
Rs22.open sql22,cn1,1,2
IvaEnc = Rs22("Ivarenc")
IvaDev = (Cdbl(ImporteD) * Cdbl(IvaEnc) / 100)
TotalD = (Cdbl(ImporteD) + Cdbl(Ivadev))
Response.write(ImporteD)
set Rs23 = server.CreateObject("ADODB.Recordset")
Sql23 = "Insert Into CRecdienc " &_
"(Numrencd, fecrencd, prorencd, ivarencd, fparencd, Refrencd, Monrencd, tcarencd, subrencd, ivtrencd, totrencd, starencd, usurencd) " &_
"Select "& Folio &", '"& Factual &"', prorenc, ivarenc, '"& Factual &"', numrenc, Monrenc, tcarenc, "& ImporteD &", " &_
""& IvaDev &", "& TotalD &", 'A', '"& Nombre &"'" &_
"From Crecenc " &_
"where Numrenc = "& Entrada &";"
Cn1.Execute Sql23
set Rs24 = server.CreateObject("ADODB.Recordset")
Sql24 = "Delete Crecdevt where Doctrecd = "& Docu &";"
Cn1.Execute Sql24
set Rs25 = server.CreateObject("ADODB.Recordset")
Sql25 = "Update Consecutivos set DevEnt = "& Folio &";"
Cn1.Execute Sql25
set Rs26 = server.CreateObject("ADODB.Recordset")
Sql26 = "update cxpgen " &_
"set salcxpg = salcxpg - "& TotalD &", Imtcxpg = (Imtcxpg - ("& TotalD &" * Tcarenc)) " &_
"From crecenc " &_
"where numrenc = "& Entrada &" and prvcxpg = prorenc " &_
"and numrenc = nrecxpg;"
Cn1.Execute Sql26
set Rs27 = server.CreateObject("ADODB.Recordset")
Sql27 = "update proveedores set salprv = (salprv - ("& TotalD &" * Tcarenc))" &_
"from proveedores, crecenc " &_
"where numrenc = "& Entrada &" and cveprv = prorenc;"
Cn1.Execute Sql27
set Rs28 = server.CreateObject("ADODB.Recordset")
Sql28 = "Insert into Cxpdet " &_
"(Movcxpd, Prvcxpd, Nrecxpd, Refcxpd, Doccxpd, Frecxpd, Fpacxpd, Moncxpd, Tcacxpd, impcxpd, imdcxpd) " &_
"Select 30, Prorenc, Numrenc , Numrenc, "& Folio &", '"& Factual &"', '"& Factual &"', monrenc, tcarenc, (-1*("& TotalD &" * Tcarenc)), (-1*("& TotalD &"))" &_
"from crecenc " &_
"where numrenc = "& Entrada &";"
Cn1.Execute Sql28
Response.Redirect("DevInesp.asp?Folio="& Folio &"&Empresa="& Negocio &"")
%>
<br>
Enlace documento
<%
End If
%>
</div>
</body>
</html>
<%
End Sub
'Add the chosen course to the cart
Call AddUsuario()
'Display contents of electronic shopping cart
Call DisplayUsuario()
%>