<%
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="ISO-8859-1" />
<TITLE>SISTEMA MIM <%= Session("Mybussiness") %> USUARIO: <%= Session("MyName") %></TITLE>
<link href="css/Modulo5.css" rel="stylesheet" />
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// End -->
</script>
</HEAD>
<BODY>
<%
'***** Variables a la base de datos ****
Dim Cn1
Dim Rs11, Rs12, Rs13, Rs14, Rs15, Rs16
Dim Sql11, Sql12, Sql13, Sql14, Sql15, Sql16
'***** 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
%>
<Header>
<%= Rs11("Nombre") %><br>
<%= Rs11("Direccion") %>, <%= Rs11("colonia") %><br>
<%= Rs11("Poblacion") %>
</header>
<SECTION>
<CENTER>
<Br><Br>
<%
Dim Cn3
Dim Periodo
Periodo = Request("Periodo")
If Isnull(Periodo) Or Periodo = "" Then
Periodo = Year(Date())
Else
Periodo = Periodo
End If
response.write(Periodo)
' ------------ ME CONECTO A LA BASE DE DATOS ----------
Set Cn3 = Server.CreateObject( "ADODB.Connection" )
Cn3.Open "DRIVER={SQL Server};SERVER=172.17.0.5;UID=ADMINDMEX;PWD=IW2BF01;Database=REPORTES"
'--------------- ELIMINO LA TABLA TEMPORAL
Set Rs12 = server.CreateObject("ADODB.Recordset")
Sql12="if exists (select * from dbo.sysobjects where id = object_id(N'" & Session("MyName") & "') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table " & Session("MyName") & ";"
Rs12.open Sql12,Cn3,1,2
Response.Write("<p>Se ha eliminado la Tabla")
'------------ CREO LA NUEVA TABLA TEMPORAL
Set Rs13=server.CreateObject("ADODB.recordset")
Set Rs13=cn3.Execute("CREATE TABLE " & Session("MyName") & "( " &_
"PERIODO INT, " &_
"MES INT, " &_
"CLAVE VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"CLIENTE VARCHAR (200) COLLATE Modern_Spanish_CI_AS NULL, " &_
"CODIGO VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"DESCRIPCION VARCHAR (250) COLLATE Modern_Spanish_CI_AS NULL, " &_
"UDM VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"CANTIDAD DECIMAL (18,2) NULL, " &_
"UNITARIO DECIMAL (18,2) NULL, " &_
"COSTO DECIMAL (18,2) NULL, " &_
"PESO DECIMAL (18,2) NULL, " &_
"LINEA VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"DIVISION VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"VENDEDOR VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL " &_
")" )
Response.Write("<br><br><p>Se ha creado la Tabla EN LA BD REPORTES")
Response.Write("<p>" & Session("MyName"))
Response.Write("<p>" & Periodo)
'//******* INSERTAMOS LO FACTURADO, QUITANDO LO CANCELADO Y PRODUCTOS SERVICIOS *****//
Set Rs14=server.CreateObject("ADODB.recordset")
Sql14="INSERT INTO REPORTES.DBO." & Session("MyName") & " " &_
"(REPORTES.DBO." & Session("MyName") & ".PERIODO, REPORTES.DBO." & Session("MyName") & ".MES, REPORTES.DBO." & Session("MyName") & ".CLAVE, REPORTES.DBO." & Session("MyName") & ".CLIENTE, " &_
"REPORTES.DBO." & Session("MyName") & ".CODIGO, REPORTES.DBO." & Session("MyName") & ".DESCRIPCION, REPORTES.DBO." & Session("MyName") & ".UDM, " &_
"REPORTES.DBO." & Session("MyName") & ".CANTIDAD, REPORTES.DBO." & Session("MyName") & ".UNITARIO, REPORTES.DBO." & Session("MyName") & ".COSTO, REPORTES.DBO." & Session("MyName") & ".PESO, " &_
"REPORTES.DBO." & Session("MyName") & ".LINEA, REPORTES.DBO." & Session("MyName") & ".DIVISION, REPORTES.DBO." & Session("MyName") & ".VENDEDOR) " &_
"SELECT Year(FECFFACE), Month(FECFFACE), Clifface, Nomcli, " &_
"Codffacd, NOMINV, udminv, " &_
"Canffacd, (Uniffacd * Tcaffacd), CPRFFACD, Pesoinv, " &_
"Deslin, DIVVEND, NOMVEND " &_
"From Ffacenc left join Ffacdet on Numfface = Nfaffacd " &_
"Left join Clientes on Clifface = Clacli " &_
"left join vendedores on Vencli = Cvevend " &_
"left join Inventarios on Codffacd = Cveinv " &_
"left join Lineas on Lininv = ClaLin " &_
"where Tipinv = 0 and Year(Fecfface) = "& Periodo &" " &_
"order by clifface;"
Cn1.Execute Sql14
'//******* INSERTAMOS LO FACTURADO, QUITANDO LO CANCELADO Y PRODUCTOS SERVICIOS *****//
Set Rs15=server.CreateObject("ADODB.recordset")
Sql15="INSERT INTO REPORTES.DBO." & Session("MyName") & " " &_
"(REPORTES.DBO." & Session("MyName") & ".PERIODO, REPORTES.DBO." & Session("MyName") & ".MES, REPORTES.DBO." & Session("MyName") & ".CLAVE, REPORTES.DBO." & Session("MyName") & ".CLIENTE, " &_
"REPORTES.DBO." & Session("MyName") & ".CODIGO, REPORTES.DBO." & Session("MyName") & ".DESCRIPCION, REPORTES.DBO." & Session("MyName") & ".UDM, " &_
"REPORTES.DBO." & Session("MyName") & ".CANTIDAD, REPORTES.DBO." & Session("MyName") & ".UNITARIO, REPORTES.DBO." & Session("MyName") & ".COSTO, REPORTES.DBO." & Session("MyName") & ".PESO, " &_
"REPORTES.DBO." & Session("MyName") & ".LINEA, REPORTES.DBO." & Session("MyName") & ".DIVISION, REPORTES.DBO." & Session("MyName") & ".VENDEDOR) " &_
"Select Year(fecfdeve) as Periodo, Month(fecfdeve) as Mes, clifdeve, Nomcli, " &_
"Codfdevd, NOMINV, udminv, " &_
"CanFdevd, (Tcafdevd * UniFdevd * -1), Profdevd * -1, Pesoinv * -1, " &_
"Deslin, DIVVEND, NOMVEND " &_
"From Fdevenc left join Fdevdet on Numfdeve = Numfdevd " &_
"Left join Clientes on Clifdeve = Clacli " &_
"left join vendedores on Vencli = Cvevend " &_
"left join Inventarios on Codfdevd = Cveinv " &_
"left join Lineas on Lininv = ClaLin " &_
"where Tipinv = 0 and Year(fecfdeve) = "& Periodo &" " &_
"order by clifdeve;"
Cn1.Execute Sql15
Set Rs16=server.CreateObject("ADODB.recordset")
Sql16="INSERT INTO REPORTES.DBO." & Session("MyName") & " " &_
"(REPORTES.DBO." & Session("MyName") & ".PERIODO, REPORTES.DBO." & Session("MyName") & ".MES, REPORTES.DBO." & Session("MyName") & ".CLAVE, REPORTES.DBO." & Session("MyName") & ".CLIENTE, " &_
"REPORTES.DBO." & Session("MyName") & ".CODIGO, REPORTES.DBO." & Session("MyName") & ".DESCRIPCION, REPORTES.DBO." & Session("MyName") & ".UDM, " &_
"REPORTES.DBO." & Session("MyName") & ".CANTIDAD, REPORTES.DBO." & Session("MyName") & ".UNITARIO, REPORTES.DBO." & Session("MyName") & ".COSTO, REPORTES.DBO." & Session("MyName") & ".PESO, " &_
"REPORTES.DBO." & Session("MyName") & ".LINEA, REPORTES.DBO." & Session("MyName") & ".DIVISION, REPORTES.DBO." & Session("MyName") & ".VENDEDOR) " &_
"SELECT Year(FACCAN), Month(FACCAN), Clifface, Nomcli, " &_
"Codffacd, NOMINV, udminv, " &_
"Canffacd, (Uniffacd * Tcaffacd *-1), CPRFFACD * -1, Pesoinv, " &_
"Deslin, DIVVEND, NOMVEND " &_
"From Ffacenc left join Ffacdet on Numfface = Nfaffacd " &_
"Left join Clientes on Clifface = Clacli " &_
"left join vendedores on Vencli = Cvevend " &_
"left join Inventarios on Codffacd = Cveinv " &_
"left join Lineas on Lininv = ClaLin " &_
"where Tipinv = 0 and Year(FACCAN) = "& Periodo &" " &_
"order by clifface;"
Cn1.Execute Sql16
Response.redirect("CRMTopProductosGra.asp?Periodo="& Periodo &"")
%>
</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
%>