EXTERNAL PROC ITPURWITHTAX.SCX

DO FORM "ITPURWITHTAX.SCX" NAME _10L0ODXJY LINKED 

*- [CONVERTER] Begin CLEANUP and other procedures from 2.x Form


procedure initdata

private lnst_rt,lncst_rt
do init_i_bod in auto_lib
sele it_pur
if empt(screen_mod)
    scat memv blank
	store ' ' to mgodown,msupplier,mdebit_ac
	store 0.00 to minsure_am,mcst_amt,mst_amt,m.disc_rs,m.bill_amt
	m.pur_typ = 'OGS'
	m.pay_mode = 'CREDIT'
	= next_no('IT_PUR','INWARD_NO','INWARD_NO',m.inward_no,'0',.T.)
	m.add_by = GcUserName
	m.add_dt = DATE()
else
	sele it_pur
    go it_purrec
    scat memv
	lnst_rt = st_rt
	lncst_rt = cst_rt
    sele tmpissue
    go top
    sele itpurbod
    set orde to bill_no
    if profseek(m.godown_no,'GODOWN','GODOWN_NO')
    	mgodown = godown.godown
    endif
    if seek(m.supplier_n + m.bill_no)
	   scan rest while supplier_n + bill_no = m.supplier_n + m.bill_no
			scat memv fiel item_no,itemmast.item,qty,rate,amount,;
				it_discrt,it_discamt
			if profseek(m.item_no,'ITEMMAST','ITEM_NO')
				m.item = itemmast.item
			endif
			gath memv fiel tmpissue.item_no,tmpissue.item,tmpissue.qty,;
				tmpissue.rate,tmpissue.amount,tmpissue.it_discrt,;
				tmpissue.it_discamt
			skip in tmpissue
	   ends
	endif
	if m.pur_typ = 'LOC'
		m.pur_typ = 'LOCAL'
	endif
	set orde to account_no in ledger
	if seek(m.supplier_n,'LEDGER')
		msupplier = ledger.account
	else
		do err_beep
		do alert with '!!! ERROR !!!;There was problem in getting Supplier Name'
	endif
	if seek(m.pur_ac,'LEDGER')
		mpur_ac = ledger.account
	else
		do err_beep
		do alert with '!!! ERROR !!!;There was problem in getting Purchase A/C'
	endif
	m.st_rt = lnst_rt
	m.cst_rt = lncst_rt
	m.modify_by = gcUserName
	m.modify_dt = DATE()

endif


procedure savedata

if ! empt(screen_mod)
	sele it_pur
	go (it_purrec)
	do del_it_pur in dele_rec
	INSERT INTO history (doc_no,operator,formname,mode,date,time);
		values;	
			(m.bill_no,gcUserName,'SPAREPURCHASE','MODIFY',DATE(),TIME())	
ELSE
	INSERT INTO history (doc_no,operator,formname,mode,date,time);
		values;	
			(m.bill_no,gcUserName,'SPAREPURCHASE','ADD',DATE(),TIME())	
endif

if m.pur_typ = 'LOCAL'
 	do storitpur
else
	PRIVATE lccredit_ac
	lccredit_ac = ' ' 
	IF m.pay_mode = 'CASH'
		lccredit_ac = gcworkcash_ac
	ELSE
		lccredit_ac = m.supplier_n
	ENDIF 
	if add_tran(m.bill_dt,m.pur_ac,lccredit_ac,m.bill_amt,m.bill_no,'','','',m.tran_no,'SP') 
		do storitpur
	else
	  	do err_beep
		do alert with '!!! ERROR !!!;There was problem in storing Financial Info.;So Purchase Bill was not stored'
	endif 
endif


FUNCTION it_body

sele tmpissue
IF ! empt(screen_mod)
	on key labe ctrl+m do modiitrt
ENDIF 
brow fiel sr_no :w= .f. :h='Sr',;
	item_no :v= get_pit(m.insurance,'SCA',iif(msupplier = 'HERO HONDA',.F.,.T.)) :P= '@!' :h='Item No' :13,;
	item :w= .f. :25 :h='Item' ,;
	qty :v= vget_qty() :f :h='Qty',;
	rate :h='Rate' :v= vchk_rate() :F, ;
	it_discrt :h = 'Disc.%' :v= vdisc_rt() :F ,it_discamt :w= .F.,;
	amount :p= '##,##,###.##' :h= 'Amount' :w= ! EMPTY(qty) and EMPTY(rate) :v= chk_amt() ;
	wind it_pur in wind itempur ;
	title '** Item Information **' ;
	noap ;
	noclear
if ! empt(screen_mod)
	on key labe ctrl+m do modi_fld
endif
	
go top
m.total = 0
scan while ! empt(item_no)
	m.total	= m.total + amount
ends
show get m.total
do dispvalue
retu .F.


function vget_qty

if qty < 0
	retu .F.
endif	
repl amount with qty*rate
repl it_discamt with amount*it_discrt/100
repl amount with amount - it_discamt
*!*	keyb '{DNARROW}'
retu .T.

FUNCTION vchk_rate
repl amount with qty*rate 
repl it_discamt with amount*it_discrt/100
repl amount with amount - it_discamt


function vdisc_rt

repl amount with qty*rate 
repl it_discamt with amount*it_discrt/100
repl amount with amount - it_discamt
IF ! EMPT(item_no) AND ! EMPTY(rate) 
	keyb '{DNARROW}'
endif 


function dispvalue
IF gcstaxamtflg <> "Y" THEN
   SHOW GET M.EXCISE_AMT DISA
   SHOW GET M.ST_AMT DISA
   SHOW GET M.CST_AMT DISA
   SHOW GET M.CESS_AMT DISA
ELSE
   SHOW GET M.EXCISE_AMT enab
   SHOW GET M.ST_AMT enab
   SHOW GET M.CST_AMT enab
   SHOW GET M.CESS_AMT enab
   
ENDIF
IF gcstaxamtflg = "Y" then
	IF EMPTY(m.excise_amt)
		m.excise_amt = round((m.total + m.ex_other)*m.excise_rt/100,0)
	ENDIF
ELSE
	m.excise_amt = round((m.total + m.ex_other)*m.excise_rt/100,0)
	IF EMPTY(m.excise_rt)
	    m.excise_amt = 0
	endif

endif	
IF gcstaxamtflg = "Y" then
	IF !EMPTY(m.excise_amt)
		IF EMPTY(m.cess_amt)
		   m.cess_amt = round((m.excise_amt)*m.cess/100,0)
		endif
	ENDIF
ELSE
   IF !EMPTY(excise_amt) 
	   m.cess_amt = round((m.excise_amt)*m.cess/100,0)
   endif 
	IF EMPTY(m.cess)
	    m.cess_amt = 0
	endif
endif
minsure_am = (m.total*m.insurance)/100
IF gcstaxamtflg = "Y" then
	IF EMPTY(m.cst_amt)
		m.cst_amt = ((m.total + minsure_am + m.ex_other + m.excise_amt + m.cess_amt- m.disc_rs)+ m.hand_charg)*m.cst_rt/100
		m.cst_amt = ROUND(m.cst_amt,2)
    endif
ELSE
	m.cst_amt = ((m.total + minsure_am + m.ex_other + m.excise_amt + m.cess_amt- m.disc_rs)+ m.hand_charg)*m.cst_rt/100
	m.cst_amt = ROUND(m.cst_amt,2)
	IF EMPTY(m.cst_rt)
	    m.cst_amt = 0
	endif

ENDIF

if ! empt(m.cst_rt)
	m.st_rt = 0
endif	
IF gcstaxamtflg = "Y" then
	IF EMPTY(m.st_amt)
		m.st_amt = ((m.total + minsure_am + m.ex_other + m.excise_amt + m.cess_amt- m.disc_rs) + m.hand_charg)*m.st_rt/100
		m.st_amt = ROUND(m.st_amt,2)
	ENDIF
ELSE
	m.st_amt = ((m.total + minsure_am + m.ex_other + m.excise_amt + m.cess_amt- m.disc_rs) + m.hand_charg)*m.st_rt/100
	m.st_amt = ROUND(m.st_amt,2)
	IF EMPTY(m.st_rt)
    	m.st_amt = 0
	endif
endif		


if ! empt(m.st_rt)
	m.cst_rt = 0
ENDIF
minsure_am = ROUND(minsure_am,2)
m.bill_amt = m.total + m.ex_other + m.excise_amt + m.cess_amt  - m.disc_rs + m.hand_charg + minsure_am + m.st_amt + m.cst_amt + m.other
m.bill_amt = ROUND(m.bill_amt,2)
show get minsure_am
show get mcst_amt
show get mst_amt
show get m.bill_amt
SHOW get m.excise_amt
SHOW get m.cess_amt


procedure storitpur

private lcgodown_no,ldbill_dt,lcitem_no,lnqty,lcsupp_no,lcbill_no,;
	lnst_rt,llmark_po,lncst_rt

llmark_po = .F.		&& Update Received Qty in P.O. File
IF ! EMPTY(m.p_o_no)
	IF SEEK(m.p_o_no,'MONTHORD','ORDER_NO')
		llmark_po = .T.
	ENDIF 
ENDIF 
ldbill_dt = m.bill_dt
lcsupp_no = m.supplier_n	
lcbill_no = m.bill_no
lnst_rt = m.st_rt
lncst_rt = m.cst_rt
sele tmpissue
DO eff_rate WITH 'PUR'
sele tmpissue
go top
wait wind '!!! WAIT !!! Wait Storing PURCHAE ITEM Info...' nowa
lcgodown_no = m.godown_no

scan while ! empt(item_no)
	scat memv
	m.sr_no = sr_no
	inse into itpurbod from memv
	lcitem_no = item_no
	lnqty = qty
	IF llmark_po 
		IF SEEK(m.p_o_no + lcitem_no,'MONTHBOD','ORDERITEM')
			REPLACE monthbod.received WITH monthbod.received + lnqty
		ENDIF 
	ENDIF 
	do god_tran with ldbill_dt,'P','I',lcgodown_no,lcitem_no,lnqty,lcsupp_no,lcbill_no,m.sr_no
ends
m.godown_no = lcgodown_no
m.st_rt = lnst_rt
m.cst_rt = lncst_rt

wait wind '!!! WAIT !!! Wait Storing BILL Info...' nowa
inse into it_pur from memv
do ok_beep


PROCEDURE chk_amt

IF ! EMPTY(qty) AND EMPTY(rate)
	REPLACE rate WITH amount/qty
ENDIF

procedure modiitrt

private lnrate

lnrate = 0

if alia() <> 'ITEMMAST'
	do err_beep
	do alert with '!!! ERROR !!!;Pressed Key has no meaning here'
	retu .F.
endif
tmp_wind = sys(2015)
defi wind (tmp_wind) from 0,0 to 5,50 doub
acti wind (tmp_wind) 
move wind (tmp_wind) cent
@ 2,2 say 'New Item Purchase Rate : ' get lnrate defa itemmast.rate pict '####.##'
read
rele wind (tmp_wind)
if rloc('ITEMMAST')
	repl itemmast.rate with lnrate
	unlo in itemmast
endif

*- [CONVERTER] End CLEANUP and other procedures from 2.x Form
