Function TarifaIncrem()
local cAlias, oDlg, oBrw, nConsumo:=0, oConsumo
local nWd := GetSysMetrics(0) * .90 // .75
local nHt := GetSysMetrics(1) / 1.20 // 2
local aGradBarSel:= { { 1, RGB(252,232,171) , RGB(248,195, 34) } }
local aGradRowSel:= {{1, RGB(108,125, 184), RGB(241,222,088)}}
local nDe,nHasta,nTar
dbCreate("C:\Tarifa",{{"DE", "N", 12,2},;
{"HASTA", "N", 12,2},;
{"TARIFA", "N", 10,2},;
{"CONSUMO","N", 12,2},;
{"VALOR", "N", 12,2}})
dbusearea(.t.,,"C:\Tarifa","Tarifa",.f.)
cAlias:=Alias()
nDe:=1
nHasta:=100
nTar:=0.10
While nHasta <= 1500
(cAlias)->(dbappend())
(cAlias)->de := nDe ; (cAlias)->hasta := nHasta ; (cAlias)->tarifa := nTar
nDe:=nHasta+1
nHasta += 100
nTar += 0.10
Enddo
(cAlias)->(dbappend()) // para poder calcular cuando consumo es mayor a 1500
(cAlias)->de := nDe ; (cAlias)->hasta := 99000000.00 ; (cAlias)->tarifa := nTar
DEFINE DIALOG oDlg SIZE nWd,nHt PIXEL TITLE "RANGOS DE CONSUMO"
nWd /= 2
nHt /= 2
@1,1 XBROWSE oBrw OF oDlg ;
COLUMNS "DE","HASTA","TARIFA","CONSUMO","VALOR";
ALIAS cAlias
WITH OBJECT oBrw
:nTop := 10
:nLeft := 10
:nBottom := :nTop + nHt - 30
:nRight := :nLeft + nWd - 20
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:lColDividerComplete := .t.
:nStyle := nAnd( :nStyle, nNot( WS_BORDER ) )
:nColDividerStyle:=LINESTYLE_LIGHTGRAY
:nRowDividerStyle:=LINESTYLE_LIGHTGRAY
:nHeaderHeight := 30 //altura del header
:nHeadStrAligns := AL_CENTER //texto cabeceras de cols centrado
:bClrSel := {|| { nRGB( 0, 0, 0), aGradRowSel } } // para barra de linea selecc cuando el control no tiene el foco
:bClrSelFocus := { || { CLR_BLACK, aGradBarSel } } // para barra de linea selecc cuando el control tiene el foco
:bClrStd := {|| IF( (cAlias)->Consumo >0, {CLR_BLACK, RGB(238, 238, 238)}, {RGB(120, 120, 120), CLR_WHITE} ) }
:lFooter := .t.
END
WITH OBJECT oBrw:aCols[1]
:nWidth := 80
:nEditType := 1
:cEditPicture := "99,999,999.99"
END
WITH OBJECT oBrw:aCols[2]
:nWidth := 80
:nEditType := 1
:cEditPicture := "99,999,999.99"
END
WITH OBJECT oBrw:aCols[3]
:nWidth := 80
:nEditType := 1
:cEditPicture := "99,999,999.99"
END
WITH OBJECT oBrw:aCols[4]
:nWidth := 80
:nEditType := 0
:cEditPicture := "99,999,999.99"
:lTotal := .t.
:nTotal := 0
:nFooterType := AGGR_TOTAL
END
WITH OBJECT oBrw:aCols[5]
:nWidth := 80
:nEditType := 0
:cEditPicture := "99,999,999.99"
:lTotal := .t.
:nTotal := 0
:nFooterType := AGGR_TOTAL
END
oBrw:CreateFromCode()
oBrw:MakeTotals()
@ nHt-15, 10 SAY "Consumo: " SIZE 50,8 PIXEL OF oDlg
@ nHt-15, 50 GET oConsumo VAR nConsumo SIZE 54,10 PIXEL OF oDlg PICTURE "99,999,999.99" RIGHT;
VALID ( if(ConsumoOK(nConsumo,cAlias), (LiqConsumo(nConsumo,oBrw,cAlias), oBrw:MakeTotals(), .T.) ,.f.) )
@ nHt-15, 124 BUTTON 'Salir' SIZE 35,11 PIXEL OF oDlg ACTION ( oDlg:End() ) CANCEL
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( FitSizes( oBrw, ), oConsumo:SetFocus() )
(cAlias)->(DBCLOSEAREA())
Ferase("C:\"+(cAlias)+".dbf")
RETURN nil
//----------------------------
Function ConsumoOK(nConsumo,cAlias)
(cAlias)->(dbGoBottom())
if nConsumo > (cAlias)->hasta
MsgStop("Consumo digitado sobrepasa al maximo de la tabla.","Alto")
return .f.
endif
Return .t.
//----------------------------
Function LiqConsumo(nConsumoTot,oBrw,cAlias)
local nConsuParc:=0, nSaldo:=nConsumoTot, nHastaAnt:=0
(cAlias)->(DbEval( {|| (cAlias)->Consumo:=0,(cAlias)->Valor:=0} )) //limpiamos por si calc mas de 1 vez
(cAlias)->(dbgotop())
While nSaldo > 0
if nConsumoTot > (cAlias)->Hasta
nConsuParc := (cAlias)->Hasta - nHastaAnt
else
nConsuParc := nSaldo
endif
(cAlias)->Consumo := nConsuParc
(cAlias)->Valor := Round( nConsuParc * (cAlias)->Tarifa, 2)
nHastaAnt:= (cAlias)->Hasta
nSaldo -= nConsuParc
(cAlias)->(dbskip())
enddo
(cAlias)->(dbSkip(-1))
oBrw:Refresh()
oBrw:SetFocus()
return nil