Mr. Marco, thanks for the test...
it's work when you have big size databases more than 50000 records
I'm sorry this my Indonesian language , look at the remarks
Code: Select all
function HitungStock() // <-- final stock count for drug expiration dates
local oDlgStock,nBanyak := obat->(lastrec()), nPos := 0
MemoryFlush()
define dialog oDlgStock from 1,1 to 40,350 pixel style nOR( WS_CAPTION ) title "Menghitung Kartu Stock"
@ 2, 2 PROGRESS oPrg;
SIZE 170, 15 of oDlgStock pixel
activate dialog oDlgStock centered nowait
nBanyak := edaw->(lastrec())
oPrg:SetPos( 0 )
oPrg:SetRange( 0, nBanyak )
edaw->(ordScope(0,nil))
edaw->(ordScope(1,nil))
edaw->(dbGotop())
do while !edaw->(eof())
oPrg:SetPos( ++nPos )
oPrg:Refresh()
if empty(edaw->tglawal)
edaw->(dbDelete())
endif
edaw->(dbSkip())
enddo
nBanyak := obat->(lastrec())
oPrg:SetPos( 0 )
oPrg:SetRange( 0, nBanyak ) // <-- nBanyak more than 50000 records
nPos := 0
obat->(dbGotop())
do while !obat->(eof()) // <-- more than 50000 records
MemoryFlush()
SysRefresh()
oPrg:SetPos( ++nPos )
oPrg:Refresh()
edaw->(ordScope(0,nil))
edaw->(ordScope(1,nil))
edaw->(ordSetFocus("kode"))
edaw->(ordScope(0,obat->kode))
edaw->(ordScope(1,obat->kode))
edaw->(dbGotop())
dbSelectArea("fifom")
zap
dbSelectArea("fifok")
zap
do while !edaw->(eof()) // <-- more than 50000 records <-- final stock count for drug expiration dates
if edaw->sts == "001" .or. edaw->sts == "002" .or. edaw->sts == "004" // barang masuk
if !empty(edaw->tgled)
fifom->(dbAppend())
fifom->kode := edaw->kode
fifom->qty := edaw->qty
fifom->keluar := 0
fifom->sisa := edaw->qty
fifom->nama := edaw->nama
fifom->satuan := edaw->satuan
fifom->harga := edaw->harga
fifom->tgled := edaw->tgled
fifom->cnobat := edaw->cnobat
endif
endif
if edaw->sts == "003" .or. edaw->sts == "005" // barang keluar
fifok->(dbAppend())
fifok->kode := edaw->kode
fifok->qty := edaw->qty
fifok->keluar := edaw->keluar
fifok->sisa := edaw->sisa
fifok->harga := edaw->harga
fifok->tglawal := edaw->tglawal
endif
edaw->(dbSkip())
enddo
fifok->(dbGotop())
do while !fifok->(eof())
nQty := fifok->qty
fifom->(dbGotop())
do while !fifom->(eof())
if fifom->sisa >= nQty
fifom->keluar += nQty
fifom->sisa := fifom->qty - fifom->keluar
exit
else
fifom->keluar += fifom->sisa
nQty -= fifom->sisa
fifom->sisa := 0
endif
fifom->(dbSkip())
enddo
fifok->(dbSkip())
enddo
fifom->(dbGotop())
do while !fifom->(eof())
if fifom->sisa # 0
edsisa->(dbAppend())
edsisa->kode := fifom->kode
edsisa->qty := fifom->qty
edsisa->keluar := fifom->keluar
edsisa->sisa := fifom->sisa
edsisa->nama := fifom->nama
edsisa->satuan := fifom->satuan
edsisa->harga := fifom->harga
edsisa->jumlah := fifom->harga * fifom->jumlah
edsisa->tgled := fifom->tgled
edsisa->cnobat := fifom->cnobat
obat->(ordSetFocus("kode"))
obat->(dbGotop())
if obat->(dbSeek(fifom->kode))
edsisa->kdjenis := obat->kdjenis
edsisa->jenis := obat->jenis
edsisa->kdkel := obat->kdkel
edsisa->ktkel := obat->ktkel
endif
endif
fifom->(dbSkip())
enddo
nAwal := nMasuk := nKeluar := 0
edaw->(dbGotop())
do while !edaw->(eof())
if edaw->sts == "001"
nAwal += edaw->qty
endif
if edaw->sts == "002" .or. edaw->sts == "004"
nMasuk += edaw->qty
endif
if edaw->sts == "003" .or. edaw->sts == "005"
nKeluar += edaw->qty
endif
edaw->(dbSkip())
enddo
if obat->(rlock())
obat->awal := nAwal
obat->masuk := nMasuk
obat->keluar := nKeluar
obat->sisa := (nAwal + nMasuk) - nKeluar
endif
obat->(dbUnlock())
obat->(dbSkip())
enddo
MemoryFlush()
oDlgStock:End()
return nil
That's all
Regards
Fafi