<%
Option Explicit
Session.LCID = 2058
'***** SI NO HA INICIADO SESION ***
If Session("Mybussiness") = "" then
Response.redirect("default.asp")
Else
Session.Timeout = 1200
'******* 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="utf-8" />
<TITLE>SISTEMA MIM <%= Session("Mybussiness") %> USUARIO: <%= Session("MyName") %></TITLE>
<link href="css/Modulos.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
Dim Sql11, Sql12, Sql13, Sql14, Sql15, Sql16, Sql17, Sql18, Sql19, Sql20
'***** 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>
<center>
<br>
<B>***** AUTORIZACION DE PEDIDOS *****</B>
<BR><BR>
<%
Dim NumeroPed
Dim ClienteP, SaldoP, LimiteP, DiaCP, SubtotalP, Stacli, TipoCli
Dim Remisionado, DisponibleCred
Dim FDSUCURSAL, FDFAST
Dim Utilidad, UtilidadG, UtilidadT
'******* VARIABLES PARA LA AUTORIZACION *****
Dim PrecioPa, DescuentoP, UnitarioP, CostoP, MarcaP, PrecioListaP
NumeroPed = Request("Numeroped")
FDSUCURSAL = "SIS99999"
FDFAST = "FT55555"
'***** ACTUALIZA LOS SALDOS DE LOS CLIENTES ****
Set Rs12 = server.CreateObject("ADODB.Recordset")
Sql12 = "Update CLIENTES Set SALCLI = 0;"
Cn1.Execute Sql12
Set Rs13 = server.CreateObject("ADODB.Recordset")
Sql13 = "Update CLIENTES " &_
"Set SALCLI = Saldo " &_
"From ASALDOS " &_
"Where Clacli = Cliente;"
Cn1.Execute Sql13
'***** Conexion A la Tabla Encabezado de Pedidos ****
Set Rs14 = Server.CreateObject("ADODB.Recordset")
Sql14="Select sum(totfreme) as Remisionado " &_
"from fremenc, fpedenc " &_
"where Numfpede = "& NumeroPed &" and clifreme = clifpede and (STAFREME = 'A' or stafreme = 'P');"
Rs14.Open Sql14,Cn1,1,2
If Isnull(Rs14("Remisionado")) Then
Remisionado = 0
Else
Remisionado = Rs14("Remisionado")
End If
'***** Conexion A la Tabla Encabezado de Pedidos ****
Set Rs15 = Server.CreateObject("ADODB.Recordset")
Sql15="Select Clifpede, Salcli, Limcli, Diacli, Subfpede, TcaFpede, Stacli, TipoCli " &_
"from Fpedenc, Clientes " &_
"where Numfpede = "& NumeroPed &" and Clifpede = Clacli;"
Rs15.Open Sql15,Cn1,1,2
ClienteP = Rs15("Clifpede")
SaldoP = Rs15("Salcli")
LimiteP = Rs15("Limcli")
DiaCP = Rs15("Diacli")
SubtotalP = Cdbl(Rs15("Subfpede")) * Cdbl(Rs15("Tcafpede"))
Stacli = Rs15("Stacli")
TipoCli = Rs15("TipoCli")
DisponibleCred = Cdbl(LimiteP) - Cdbl(SaldoP) - Cdbl(Remisionado)
'****** CUANDO ES SUCURSAL ******
If TipoCli = "S" then
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "Update Fpedenc " &_
"Set Staimp = 1, Fecimp = GETDATE(), Eautoriza = 9, FDVFPEDE = '"& FDSUCURSAL &"', HFDVFPEDE = GETDATE(), " &_
"FDCFPEDE = '"& FDSUCURSAL &"', HFDCFPEDE = GETDATE(), FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() " &_
"WHERE numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
'***** CUANDO EL CLIENTE ESATA SUSPENDIDO *****
Else If (Stacli = "B" or Stacli = "S" or ISnull(Stacli) or Stacli = "") Then
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "UPDATE fpedenc SET staimp = 1, FECIMP = GETDATE(), Eautoriza = 1, FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() WHERE Numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo s cualquiera")
'**** VERIFICA LOS COSTOS DE FILIALES ***
Else If (Stacli = "A" OR Stacli = "C") and TipoCli = "F" Then
Set Rs16 = server.CreateObject("ADODB.Recordset")
Sql16 ="select Prefpedd, Unifpedd, CPMUL, Marca, Desfpedd, Plainv " &_
"From Fpeddet, Inventarios, Multialmacen " &_
"where Npefpedd = "& NumeroPed &" and almmul = ALMFPEDD and Cveinv = artmul and cveinv = Codfpedd;"
Rs16.Open Sql16, Cn1
If Rs16.EOF Then
UtilidadT = 1
Else
UtilidadG = 0
Do While Not Rs16.EOF
PrecioPa = Rs16("Prefpedd")
DescuentoP = Rs16("Desfpedd")
UnitarioP = Rs16("Unifpedd")
CostoP = Rs16("Cpmul")
PrecioListaP = Rs16("Plainv")
MarcaP = Rs16("Marca")
If (1 - (Cdbl(CostoP) / Cdbl(UnitarioP))) > 0 Then
UtilidadG = UtilidadG + 0
Else
UtilidadG = UtilidadG + 1
End If
Rs16.Movenext
Loop
UtilidadT = UtilidadG + UtilidadT
If Cdbl(UtilidadT) = 0 Then
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "Update Fpedenc " &_
"Set Staimp = 1, Fecimp = GETDATE(), Eautoriza = 9, FDVFPEDE = '"& FDFAST &"', HFDVFPEDE = GETDATE(), " &_
"FDCFPEDE = '"& FDFAST &"', HFDCFPEDE = GETDATE(), FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() " &_
"WHERE numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo f fast track " & UTILIDADT)
Else
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "UPDATE fpedenc SET staimp = 1, FECIMP = GETDATE(), Eautoriza = 1, FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() WHERE Numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo f Cualquier cosa " & UTILIDADT)
End If
End If
'***** CUANDO EL CLIENTE TIPO "P" O TIPO "C" ******
Else If Stacli = "A" and (TipoCli = "C" or TipoCli = "P") Then
Set Rs16 = server.CreateObject("ADODB.Recordset")
Sql16 ="select Prefpedd, Unifpedd, CPMUL, Marca, Desfpedd, Plainv " &_
"From Fpeddet, Inventarios, Multialmacen " &_
"where Npefpedd = "& NumeroPed &" and almmul = ALMFPEDD and Cveinv = artmul and cveinv = Codfpedd;"
Rs16.Open Sql16, Cn1
If Rs16.EOF Then
UtilidadT = 1
Else
UtilidadG = 0
Do While Not Rs16.EOF
PrecioPa = Rs16("Prefpedd")
DescuentoP = Rs16("Desfpedd")
UnitarioP = Rs16("Unifpedd")
CostoP = Rs16("Cpmul")
PrecioListaP = Rs16("Plainv")
MarcaP = Rs16("Marca")
'**** CONDICIONES DE PORCENTAJE DE VENTA *****
If Marcap = "WORCESTER" And Cdbl(DescuentoP) < 20.01 and (1-(Cdbl(CostoP)/Cdbl(UnitarioP))) > .15 Then
UtilidadG = UtilidadG + 0
Else If Marcap = "WORCESTER" And Cdbl(DescuentoP) > 20 or Cdbl(DescuentoP) = 0 and (1-(Cdbl(CostoP)/Cdbl(UnitarioP))) > .15 Then
UtilidadG = UtilidadG + 1
Else If Cdbl(PrecioListaP) = 0 Then
UtilidadG = UtilidadG + 1
Else If Cdbl(DescuentoP) < 10.01 and (1-(Cdbl(CostoP)/Cdbl(UnitarioP))) > .15 Then
UtilidadG = UtilidadG + 0
Else If Cdbl(DescuentoP) > 10 or (1-(Cdbl(CostoP)/Cdbl(UnitarioP))) > .15 Then
UtilidadG = UtilidadG + 1
End If
End If
End If
End If
End If
Rs16.Movenext
Loop
UtilidadT = UtilidadG + UtilidadT
End If
If Stacli = "A" and Cdbl(DiaCP) = 0 and (TipoCli = "P" or TipoCli = "C") Then
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "UPDATE fpedenc SET staimp = 1, FECIMP = GETDATE(), Eautoriza = 1, FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() WHERE numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo A contado cliente p o c")
Else If Stacli = "A" and Cdbl(DisponibleCred) > 0 and Cdbl(SubtotalP) < 50000 and Cdbl(UtilidadT) = 0 and (TipoCli = "P" or TipoCli = "C") Then
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "Update Fpedenc " &_
"Set Staimp = 1, Fecimp = GETDATE(), Eautoriza = 9, FDVFPEDE = '"& FDFAST &"', HFDVFPEDE = GETDATE(), " &_
"FDCFPEDE = '"& FDFAST &"', HFDCFPEDE = GETDATE(), FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() " &_
"WHERE numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo A cliente p o c fast track")
Else
Set Rs20 = Server.CreateObject("ADODB.Recordset")
Sql20 = "UPDATE fpedenc SET staimp = 1, FECIMP = GETDATE(), Eautoriza = 1, FEAFPEDE = GETDATE(), HEAFPEDE = GETDATE() WHERE numfpede = "& NumeroPed &";"
Cn1.Execute Sql20
Response.write("Tipo A cliente p o c Cualquier cosa")
End If
End If
End If
End If
End If
End If
Response.Redirect("fpedesp.asp?Fpednum="& NumeroPed &"&Empresa="& Session("Mybussiness") &"")
%>
</SECTION>
<%
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
%>