<%
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
Dim Sql11, Sql12, Sql13, Sql14
'***** 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, Clave
Clave = Request("Clave")
Periodo = Request("Periodo")
If Isnull(Periodo) Or Periodo = "" Then
Periodo = Year(Date())
Else
Periodo = Periodo
End If
' ------------ 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, " &_
"DOCUMENTO INT, " &_
"CLAVE VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"PROVEEDOR VARCHAR (200) COLLATE Modern_Spanish_CI_AS NULL, " &_
"CODIGO VARCHAR (50) COLLATE Modern_Spanish_CI_AS NULL, " &_
"DESCRIPCION VARCHAR (200) 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, " &_
"PESO DECIMAL (18,2) NULL, " &_
"CLAVELIN INT, " &_
"LINEA 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 LAS COMPRAS QUITANDO LAS CANCELADAS Y 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") & ".DOCUMENTO, REPORTES.DBO." & Session("MyName") & ".CLAVE, REPORTES.DBO." & Session("MyName") & ".PROVEEDOR, " &_
"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") & ".PESO, " &_
"REPORTES.DBO." & Session("MyName") & ".CLAVELIN, REPORTES.DBO." & Session("MyName") & ".LINEA) " &_
"SELECT Year(FECRENC), Month(FECRENC), Numrenc, Prorenc, Nomprv, " &_
"Codrdet, NOMINV, udminv, " &_
"Crerdet, (punrdet * Tcarenc), Pesoinv, " &_
"LinInv, Deslin " &_
"From Crecenc left join Crecdet on Numrenc = Numrdet " &_
"Left join Proveedores on Prorenc = Cveprv " &_
"left join Inventarios on Codrdet = Cveinv " &_
"left join Lineas on Lininv = ClaLin " &_
"where Starenc = 0 and Tipinv = 0 and Year(FECRENC) = "& Periodo &" and Cveprv = '"& Clave &"' " &_
"order by Prorenc;"
Cn1.Execute Sql14
'//******* INSERTAMOS LAS DEVOLUCIONES A PROVEEDOR *****//
Sql14="INSERT INTO REPORTES.DBO." & Session("MyName") & " " &_
"(REPORTES.DBO." & Session("MyName") & ".PERIODO, REPORTES.DBO." & Session("MyName") & ".MES, " &_
"REPORTES.DBO." & Session("MyName") & ".DOCUMENTO, REPORTES.DBO." & Session("MyName") & ".CLAVE, REPORTES.DBO." & Session("MyName") & ".PROVEEDOR, " &_
"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") & ".PESO, " &_
"REPORTES.DBO." & Session("MyName") & ".CLAVELIN, REPORTES.DBO." & Session("MyName") & ".LINEA) " &_
"SELECT Year(Fecrencd), Month(Fecrencd), Numrencd, Prorencd, Nomprv, " &_
"Codrdevd, NOMINV, udminv, " &_
"Crerdevd, (punrdevd * Tcarencd * -1), (Pesoinv * -1), " &_
"LinInv, Deslin " &_
"From CRecEncd left join CRecDevd on Numrencd = Numrdevd " &_
"Left join Proveedores on Prorencd = Cveprv " &_
"left join Inventarios on Codrdevd = Cveinv " &_
"left join Lineas on Lininv = ClaLin " &_
"where Tipinv = 0 and Year(Fecrencd) = "& Periodo &" and Cveprv = '"& Clave &"' " &_
"order by Prorencd;"
Cn1.Execute Sql14
Response.redirect("CRMProveeGra.asp?Periodo="& Periodo &"&Clave="& Clave &"")
%>
</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
%>