This was made in vb6, i think the code speaks for himself.
I called this: "Temporal Coding"
Do While Not rstmp.EOF
tmp1 = 0: tmp2 = 0: tmp3 = 0: tmp4 = 0: tmp5 = 0: tmp6 = 0
Call barraProgr(IIf(rstmp.PercentPosition > ProgressBar1.Min, rstmp.PercentPosition, ProgressBar1.Min))
ttLinCod = rstmp.Fields("LINCODIGO")
tmpAdd = Trim(rstmp.Fields("LINDESCRIPCION")) + " (Cod:" + Trim(Str(ttLinCod)) + ")" + Chr(9)
sql = "SELECT Sum(CUOTA.CUOUNIDADES) AS SumaDeCUOUNIDADES, Sum(CUOTA.CUOMONTO) AS SumaDeCUOMONTO"
sql = sql + " FROM CUOTA INNER JOIN PRODUCTO ON CUOTA.PROCODIGO = PRODUCTO.PROCODIGO"
sql = sql + " WHERE CUOTA.VENCODIGO=" & iddUsuario
sql = sql + " AND PRODUCTO.LINCODIGO=" & ttLinCod
sql = sql + " AND CUOTA.CUOPERIODO=" & Format(fchDesdeHasta(0), "yyyymm")
Set rsCuota = dbMain.OpenRecordset(sql, dbOpenSnapshot)
If rsCuota.EOF Or rsCuota.BOF Then
Else
If Not IsNull(rsCuota.Fields("SumaDeCUOUNIDADES")) Then
tmp1 = rsCuota.Fields("SumaDeCUOUNIDADES") '2
tmp2 = rsCuota.Fields("SumaDeCUOMONTO") '3
mTotalesMSF(0) = mTotalesMSF(0) + tmp1
mTotalesMSF(1) = mTotalesMSF(1) + tmp2
End If
End If
tmpAdd = tmpAdd + Format(tmp1, "###,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmp2, "###,##0") + Chr(9)
sql = "SELECT Sum(HISTORIC.HISCANTORDENADA) AS SumaDeHISCANTORDENADA, Sum(HISTORIC.HISMONTO) AS SumaDeHISMONTO"
sql = sql + " FROM ((VENCLI INNER JOIN HISTORIC ON VENCLI.CLICODIGO = HISTORIC.CLICODIGO) INNER JOIN VENLIN ON VENCLI.VENCODIGO = VENLIN.VENCODIGO) INNER JOIN PRODUCTO ON (PRODUCTO.LINCODIGO = VENLIN.LINCODIGO) AND (HISTORIC.PROCODIGO = PRODUCTO.PROCODIGO)"
sql = sql + " WHERE VENCLI.VENCODIGO=" & iddUsuario
sql = sql + " AND VENLIN.LINCODIGO=" & ttLinCod
sql = sql + " AND HISTORIC.HISPERIODOFACT=" & Format(fchDesdeHasta(0), "yyyymm")
Set rsHist = dbMain.OpenRecordset(sql, dbOpenSnapshot)
If rsHist.EOF Or rsHist.BOF Then
Else
If Not IsNull(rsHist.Fields("SumaDeHISCANTORDENADA")) Then
tmp3 = rsHist.Fields("SumaDeHISCANTORDENADA") '4
tmp4 = rsHist.Fields("SumaDeHISMONTO") '5
mTotalesMSF(2) = mTotalesMSF(2) + tmp3
mTotalesMSF(3) = mTotalesMSF(3) + tmp4
End If
End If
tmpAdd = tmpAdd + Format(tmp3, "###,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmp4, "###,##0") + Chr(9)
If Month(CDate(fchDesdeHasta(0))) <> Month(Now) Then GoTo noCalcPed
sql = "SELECT Sum(ITEM.ITECANTAENTREGAR) AS SumaDeITECANTAENTREGAR, Sum([ITEM]![ITECANTAENTREGAR]*[ITEM]![ITEPRECIOUNIT]) AS PrecioTotal"
sql = sql + " FROM (VENLIN INNER JOIN (((ITEM INNER JOIN PEDIDO ON ITEM.PEDCODIGO = PEDIDO.PEDCODIGO) INNER JOIN ESTADO ON ITEM.ESTCODIGO = ESTADO.ESTCODIGO) INNER JOIN VENCLI ON PEDIDO.CLICODIGO = VENCLI.CLICODIGO) ON VENLIN.VENCODIGO = VENCLI.VENCODIGO) INNER JOIN PRODUCTO ON (PRODUCTO.LINCODIGO = VENLIN.LINCODIGO) AND (ITEM.PROCODIGO = PRODUCTO.PROCODIGO)"
sql = sql + " WHERE ESTADO.ESTACTIVO=1 AND VENCLI.VENCODIGO=" & iddUsuario
sql = sql + " AND VENLIN.LINCODIGO=" & ttLinCod
Set rsPed = dbMain.OpenRecordset(sql, dbOpenSnapshot)
If rsPed.EOF Or rsPed.BOF Then
Else
If Not IsNull(rsPed.Fields("SumaDeITECANTAENTREGAR")) Then
tmp5 = rsPed.Fields("SumaDeITECANTAENTREGAR") '4
tmp6 = rsPed.Fields("PrecioTotal") '5
mTotalesMSF(4) = mTotalesMSF(4) + tmp5
mTotalesMSF(5) = mTotalesMSF(5) + tmp6
End If
End If
noCalcPed:
tmpAdd = tmpAdd + Format(tmp5, "###,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmp6, "###,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmp3 + tmp5, "###,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmp4 + tmp6, "###,##0") + Chr(9)
mTotalesMSF(6) = mTotalesMSF(6) + tmp6 + tmp4
If tmp1 = 0 Then
tmpCero = 100
Else
If tmp3 + tmp5 = 0 Then
tmpCero = 0
Else
tmpCero = ((tmp3 + tmp5) / tmp1) * 100
End If
End If
tmpAdd = tmpAdd + Format(tmp3 + tmp5 - tmp1, "#,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmpCero, "#,##0") + "%" + Chr(9)
If tmp2 = 0 Then
tmpCero = 100
Else
If tmp4 + tmp6 = 0 Then
tmpCero = 0
Else
tmpCero = ((tmp4 + tmp6) / tmp2) * 100
End If
End If
tmpAdd = tmpAdd + Format(tmp4 + tmp6 - tmp2, "#,##0") + Chr(9)
tmpAdd = tmpAdd + Format(tmpCero, "#,##0") + "%"
mTotalesMSF(7) = mTotalesMSF(7) + tmp4 + tmp6 - tmp2
If tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6 <> 0 Then msfConsulta.AddItem tmpAdd
rstmp.MoveNext
Loop