<%@language=vbscript%>
<%
Response.Buffer=True
If Session("ID")=0 then
Response.Redirect("http://www.grupo-mim.com")
Response.End
Else
%>
<!--#include file="fpdf.asp"-->
<%
Dim Cn1, Rs1, sql1, Rs2, Sql2, rs3, sql3, rs4, sql4
Dim Empresa, Finicial, Ffinal, Division
Empresa = Request("Empresa")
Ffinal = Request("ffinal")
Finicial = Request("Finicial")
Division = Request("Division")
DiaI = day(Finicial)
MesI = Month(Finicial)
YearI = Year(Finicial)
DiaF = day(Ffinal)
MesF = Month(Ffinal)
Yearf = Year(Ffinal)
Fecha = NOW()
Fecha = Cstr(Fecha)
E1 = Empresa
Set Cn1 = Server.CreateObject( "ADODB.Connection" )
Cn1.Open "DRIVER={SQL Server};SERVER=172.17.0.5;UID=ADMIMSIS;PWD=ST2108GP;Database=" & Empresa &""
set rs1 = server.CreateObject("ADODB.Recordset")
SQL1="SELECT * FROM EMPRESA"
rs1.open sql1,cn1,1,2
B1=rs1("Nombre")
PERIODO = "PERIODO: DEL " & DiaI & " DE "&Ucase(MonthName(MesI))&" "&YearI&" AL "&DiaF&" DE "&Ucase(MonthName(MesF))&" "&YearF&""
set rs2 = server.CreateObject("ADODB.Recordset")
SQL2="Select cvevend, nomvend "&_
"from QrcomisionesTecv2 "&_
"where fecha between '"& Finicial &"' and '"& Ffinal &"' and (divvend='"& Division &"') group by cvevend, nomvend "&_
"order by cvevend asc"
rs2.open sql2,cn1,1,2
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF "L", "mm", "Letter"
pdf.SetPath("fpdf/")
pdf.SetFillColor 13,15,15
pdf.Open()
pdf.LoadModels("ComVenPdf")
pdf.SetLeftMargin(4.0)
Do while Not(RS2.EOF)
pdf.AddPage()
pdf.SetFont "Arial","B",8
FD1 = rs2("cvevend")
FD2 = cstr(rs2("nomvend"))
pdf.Ln(4)
pdf.Cell 1,4,"",0,0,"L",0
pdf.Cell 14,4,Fd1,0,0,"L",0
pdf.Cell 22,4,Fd2,0,0,"L",0
pdf.Ln(6)
set rs3 = server.CreateObject("ADODB.Recordset")
SQL3="Select * from QrcomisionesTecv2 "&_
"where fecha between '"& Finicial &"' and '"& Ffinal &"' and cvevend="& Fd1 &" and (divvend='"& Division &"')"&_
"order by Factura asc"
rs3.open sql3,cn1,1,2
TotalFac = 0
TotalPag = 0
TotalCos = 0
TotalFle = 0
TotalUti = 0
TotalVic = 0
TotalCve = 0
Do while Not(RS3.EOF)
FD3 = Rs3("Factura")
FD4 = cstr(Rs3("Frecxcg"))
FD5 = cstr(Rs3("Fpacxcg"))
FD6 = cstr(Rs3("FechaP"))
FD7 = cstr(Rs3("Diacli"))
FD8 = cstr(Rs3("Atraso"))
FD9 = Rs3("Nomcli")
FD10 = Rs3("Impneto")
FD11 = Rs3("Impneto")
FD12 = Rs3("Cp")
FD13 = Rs3("Flete")
FD14 = cdbl(Rs3("Util"))
FD15 = cdbl(Rs3("Financia"))
Pcom = cdbl(Rs3("Pcomvend"))
If cdbl(FD8) > 45 then
UtilAju = 0
else
UtilAju = cdbl(fd14) - cdbl(fd15)
end if
FD16 = cstr(Rs3("Maniobra"))
Fd17 = cdbl(UtilAju) - cdbl(Fd16)
If cdbl(Fd10)-cdbl(Fd11)<16 then
ComisionA = cdbl(Fd17)*0.12
else
ComisionA = 0
end if
If Fd17 < 12.5 then
Comision = 0
else If cdbl(Fd17) >= 25 then
comision = Pcom
else If cdbl(Fd17) < 25 then
Comision = (cdbl(Fd17)*cdbl(Pcom))/25
else
comision =0
end if
End if
end if
ComisionVen = (cdbl(Fd10) * cdbl(Comision))/100
Fd18 = Rs3("VentasV")
If cdbl(Fd10)-cdbl(Fd11)<21 then
ComisionTV = cdbl(Fd17)*0.008
else
ComisionTV = 0
end if
If Fd17 < 12.5 then
ComisionVic = 0
else If cdbl(ComisionTV)>0.2 then
ComisionVic = 0.2
else if cdbl(Fd10)-cdbl(Fd11)<21 then
ComisionVic = cdbl(Fd17)*0.008
else
ComisionVic =0
end if
End if
end if
ComisionVenVic = (cdbl(Fd18) * cdbl(ComisionVic))/100
ComisionTotal = cdbl(ComisionVen)-cdbl(ComisionVenVic)
pdf.SetFont "Arial","",6
pdf.Cell 1,4,"",0,0,"L",0
pdf.Cell 9,4,Fd3,0,0,"L",0
pdf.Cell 12,4,Fd4,0,0,"L",0
pdf.Cell 12,4,Fd5,0,0,"L",0
pdf.Cell 14,4,Fd6,0,0,"L",0
pdf.Cell 8,4,Fd7,0,0,"L",0
pdf.Cell 1,4,"",0,0,"L",0
pdf.Cell 1,4,Fd8,0,0,"R",0
pdf.Cell 3,4,"",0,0,"L",0
pdf.Cell 28,4,left(Fd9,16),0,0,"L",0
pdf.Cell 10,4,Formatcurrency(Fd10),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd11),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd12),0,0,"R",0
pdf.Cell 13,4,Formatcurrency(Fd13),0,0,"R",0
pdf.Cell 10,4,Formatnumber(Fd14),0,0,"R",0
pdf.Cell 10,4,Formatnumber(Fd15),0,0,"R",0
pdf.Cell 10,4,Formatnumber(UtilAju),0,0,"R",0
pdf.Cell 5,4,"",0,0,"L",0
pdf.Cell 5,4,Fd16,0,0,"L",0
pdf.Cell 10,4,Formatnumber(Fd17),0,0,"R",0
pdf.Cell 10,4,Formatnumber(Comision),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionVen),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd18),0,0,"R",0
pdf.Cell 10,4,Formatnumber(ComisionVic),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionVenVic),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionTotal),0,0,"R",0
pdf.Ln(3)
TotalAtr = cdbl(TotalAtr) + cdbl(Fd8)
TotalFac = cdbl(TotalFac) + cdbl(fd10)
TotalPag = cdbl(TotalPag) + cdbl(fd11)
TotalCos = cdbl(TotalCos) + cdbl(fd12)
TotalFle = cdbl(TotalFle) + cdbl(fd13)
TotalUti = ((cdbl(TotalPag)-(cdbl(TotalCos)+cdbl(TotalFle)))*100)/cdbl(TotalPag)
TotalVic = cdbl(TotalVic) + cdbl(ComisionVenVic)
TotalCve = cdbl(TotalCve) + cdbl(ComisionTotal)
rs3.Movenext
loop
set rs4 = server.CreateObject("ADODB.Recordset")
SQL4="select * from Qrvicdev "&_
"where fecncr between '"& Finicial &"' and '"& Ffinal &"' and cvevend="& Fd1 &" and (divvend='"& Division &"')"&_
"order by numncr asc"
rs4.open sql4,cn1,1,2
TotalFacN = 0
TotalPagN = 0
TotalCosN = 0
TotalFleN = 0
TotalUtiN = 0
TotalVicN = 0
TotalCveN = 0
Do while Not(RS4.EOF)
FD19 = Rs4("Numncr")
FD21 = Rs4("Fecha")
FD22 = Rs4("Fecha")
FD23 = Rs4("Fecha")
FD24 = cstr(Rs4("Diacli"))
FD25 = 0
FD26 = Rs4("Nomcli")
FD27 = Rs4("Total")
FD28 = Rs4("Total")
FD29 = Rs4("Cpromedio")
FD30 = 0
FD31 = cdbl(Rs4("Utilidad"))
FD32 = 0
UtilAjuN = cdbl(fd31)
FD33 = 0
Fd34 = cdbl(UtilAjuN)
Fd35 =cdbl(Rs4("Pcomvend"))
If cdbl(FD27)-cdbl(FD28)<16 then
ComisionAN = cdbl(Fd34)*cdbl(Fd35)
else
ComisionAN = 0
end if
If Fd34 < 12.5 then
ComisionN = 0
else If cdbl(Fd34)>=25 then
comisionN = Fd35
else if cdbl(Fd34)<25 then
ComisionN = (cdbl(Fd34)*cdbl(Pcom))/25
else
comisionN =0
end if
End if
end if
ComisionVenN = ((cdbl(Fd27) * cdbl(ComisionN))/100)
Fd36 = CDBL(Rs4("dEV"))
If cdbl(FD27)-cdbl(FD28)<21 then
ComisionTVN = cdbl(Fd34)*0.008
else
ComisionTVN = 0
end if
If Fd34 < 12.5 then
ComisionVicN = 0
else If cdbl(ComisionTVN)>0.2 then
ComisionVicN = 0.2
else if cdbl(FD27)-cdbl(FD28)<21 then
ComisionVicN = cdbl(Fd34)*0.008
else
ComisionVicN =0
end if
End if
end if
ComisionVenVicN = ((cdbl(Fd36) * cdbl(ComisionVicN))/100)
ComisionTotalN = cdbl(ComisionVenN)-cdbl(ComisionVenVicN)
pdf.SetFont "Arial","",6
pdf.Cell 1,4,"",0,0,"L",0
pdf.Cell 9,4,Fd19,0,0,"L",0
pdf.Cell 12,4,Fd21,0,0,"L",0
pdf.Cell 12,4,Fd22,0,0,"L",0
pdf.Cell 14,4,Fd23,0,0,"L",0
pdf.Cell 8,4,Fd24,0,0,"L",0
pdf.Cell 1,4,"",0,0,"L",0
pdf.Cell 1,4,Fd25,0,0,"R",0
pdf.Cell 3,4,"",0,0,"L",0
pdf.Cell 28,4,left(Fd26,16),0,0,"L",0
pdf.Cell 10,4,Formatcurrency(Fd27),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd28),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd29),0,0,"R",0
pdf.Cell 13,4,Formatcurrency(Fd30),0,0,"R",0
pdf.Cell 10,4,Formatnumber(Fd31),0,0,"R",0
pdf.Cell 10,4,Formatnumber(Fd32),0,0,"R",0
pdf.Cell 10,4,Formatnumber(UtilAjuN),0,0,"R",0
pdf.Cell 5,4,"",0,0,"L",0
pdf.Cell 5,4,Fd33,0,0,"L",0
pdf.Cell 10,4,Formatnumber(Fd34),0,0,"R",0
pdf.Cell 10,4,Formatnumber(ComisionN),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionVenN),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(Fd36),0,0,"R",0
pdf.Cell 10,4,Formatnumber(ComisionVicN),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionVenVicN),0,0,"R",0
pdf.Cell 15,4,Formatcurrency(ComisionTotalN),0,0,"R",0
pdf.Ln(3)
TotalFacN = cdbl(TotalFacN) + cdbl(fd27)
TotalPagN = cdbl(TotalPagN) + cdbl(fd28)
TotalCosN = cdbl(TotalCosN) + cdbl(fd29)
TotalFleN = cdbl(TotalFleN) + cdbl(fd30)
TotalUtiN = ((cdbl(TotalPagN)-(cdbl(TotalCosN)+cdbl(TotalFleN)))*100)/cdbl(TotalPagN)
TotalVicN = cdbl(TotalVicN) + cdbl(ComisionVenVicN)
TotalCveN = cdbl(TotalCveN) + cdbl(ComisionTotalN)
rs4.Movenext
loop
pdf.Ln(2)
pdf.SetFont "Arial","B",6
pdf.Cell 60,4,"",0,0,"L"
pdf.Cell 30,4,"TOTAL",0,0,"L"
pdf.Cell 9,4,Formatcurrency(TotalFac+TotalFacN),0,0,"R"
pdf.Cell 15,4,Formatcurrency(TotalPag+TotalPagN),0,0,"R"
pdf.Cell 15,4,Formatcurrency(TotalCos+TotalCosN),0,0,"R"
pdf.Cell 13,4,Formatcurrency(TotalFle),0,0,"R"
pdf.Cell 10,4,Formatnumber(TotalUti),0,0,"R"
pdf.Cell 105,4,Formatcurrency(TotalVic+TotalVicN),0,0,"R"
pdf.Cell 15,4,Formatcurrency(TotalCve+TotalCveN),0,0,"R"
rs2.Movenext
loop
pdf.Ln(14)
pdf.Output()
End If
%>