do set_menu
private mwpr_mon,i,tot_monuw,tot_monpw,month_no,mcwarranty,tot_month,tmp_dbf
private mtot_serve,mlabour_amt,mspare_amt,mds_amt,mtot_free,muwarranty,mpwarranty,mpservice,mmajor,mminor,moil_amt
private ytot_serve,ylabour_amt,yspare_amt,yds_amt,ytot_free,yuwarranty,ypwarranty,ypservice,ymajor,yminor,yoil_amt
private apr_uw,may_uw,june_uw,july_uw,aug_uw,sep_uw,oct_uw,nov_uw,dec_uw,jan_uw,feb_uw,mar_uw
private apr_pw,may_pw,june_pw,july_pw,aug_pw,sep_pw,oct_pw,nov_pw,dec_pw,jan_pw,feb_pw,mar_pw
store 0 to apr_pw,may_pw,june_pw,july_pw,aug_pw,sep_pw,oct_pw,nov_pw,dec_pw,jan_pw,feb_pw,mar_pw
store 0 to apr_uw,may_uw,june_uw,july_uw,aug_uw,sep_uw,oct_uw,nov_uw,dec_uw,jan_uw,feb_uw,mar_uw
store 0 to tot_month,mcwarranty
tmp_dbf = sys(2015)
private myear,mmonth
myear = 0
mmonth = cmont(date())
mwpr_mon = mont(date())
store 0 to mout_labour,maccessory,month_no
dime monuw(12),monpw(12)
store 0 to tot_monuw,tot_monpw
for i = 1 to 12
	monuw(i) = 0
	monpw(i) = 0
endf

= get_pnam('MONTHLY WORKSHOP PERFORMANCE REPORT')
use (year_path) + 'MWPRHIST' in 0
sele mwprhist
scat memv blank
do mwpr.spr

upto_date = gomo(ctod('01/' + ltrim(str(month_no)) + '/' + ltrim(str(myear))),1) - 1
set talk on
wait wind '!!! WAIT !!! Calculating Company Warranty Detail .. ' nowa
sele sum(spare_rt*qty) as cwarranty ;
	from job_mast,issue,issuebod ;
	where job_mast.jobcard_no = issue.jobcard_no ;
		and issue.issue_no = issuebod.issue_no ;
		and issuebod.warranty = 'C' ;
		and year(job_dt) = myear and month(job_dt) = month_no ;
	into cursor query
mcwarranty = cwarranty
use in query
wait wind '!!! WAIT !!! Gathering Data for PERFORMANCE ....' nowa
sele year(job_dt) as year,mont(job_dt) as month, ;
	count(DISTINCT job_dt) as days, ;
	0000 as tot_serve, ;
	sum(tot_labour) as labour_amt , ;
	sum(iif(servicetyp <> 'D',tot_spares,0000000.00)) as spare_amt, ;
    sum(iif(servicetyp = 'D',tot_spares,0000000.00)) as ds_amt, ;
    sum(iif(servicetyp = 'F',1,0000)) as tot_free,;
    sum(iif(category = 'W',1,0000)) as uwarranty,;
    sum(iif(inli(servicetyp,'R','P') and category = 'W',1,0000)) as pwarranty ,;
    sum(iif(inli(servicetyp,'R','P'),1,0000)) as pservice ,;
    sum(iif(inli(category,'E','A'),1,0000)) as major ,;
    sum(iif(servicetyp = 'M',1,0000)) as minor, ;
    sum(tot_oil) as oil_amt ;
	where betw(job_dt,mstart_dt,upto_date) ;
	group by 1,2 ;
	from job_mast ;
	into dbf (tmp_dbf)
use
use (tmp_dbf) in 0 alia del	
set talk off
tot_month = recc('DEL')
sele del
repl all tot_serve with tot_free + uwarranty + pwarranty + pservice + major + minor
loca for month = month_no
if foun()
	mtot_serve = tot_serve
	mlabour_amt = labour_amt
	mspare_amt = spare_amt
	mds_amt = ds_amt
	mtot_free = tot_free
	muwarranty = uwarranty 
	mpwarranty = pwarranty
	mpservice = pservice
	mmajor = major
	mminor = minor
	moil_amt = oil_amt
	sum tot_serve to ytot_serve
	sum labour_amt to ylabour_amt
	sum spare_amt to yspare_amt
	sum ds_amt to yds_amt
	sum tot_free to ytot_free
	sum uwarranty  to yuwarranty
	sum pwarranty to ypwarranty 
	sum pservice to ypservice 
	sum major to ymajor
	sum minor to yminor
	sum oil_amt to yoil_amt
	scan
		do case
			case month = 4
				apr_uw = tot_free + uwarranty + pwarranty
				apr_pw = pservice + major + minor
			case month = 5
				may_uw = tot_free + uwarranty + pwarranty
				may_pw = pservice + major + minor
			case month = 6
				june_uw = tot_free + uwarranty + pwarranty
				june_pw = pservice + major + minor
			case month = 7
				july_uw = tot_free + uwarranty + pwarranty
				july_pw = pservice + major + minor
			case month = 8
				aug_uw = tot_free + uwarranty + pwarranty
				aug_pw = pservice + major + minor
			case month = 9
				sep_uw = tot_free + uwarranty + pwarranty
				sep_pw = pservice + major + minor
			case month = 10
				oct_uw = tot_free + uwarranty + pwarranty
				oct_pw = pservice + major + minor
			case month = 11
				nov_uw = tot_free + uwarranty + pwarranty
				nov_pw = pservice + major + minor
			case month = 12
				dec_uw = tot_free + uwarranty + pwarranty
				dec_pw = pservice + major + minor
			case month = 1
				jan_uw = tot_free + uwarranty + pwarranty
				jan_pw = pservice + major + minor
			case month = 2
				feb_uw = tot_free + uwarranty + pwarranty
				feb_pw = pservice + major + minor
			case month = 3
				mar_uw = tot_free + uwarranty + pwarranty
				mar_pw = pservice + major + minor
		endc
		tot_monuw = tot_monuw + tot_free + uwarranty + pwarranty
		tot_monpw = tot_monpw + pservice + major + minor
	ends
do prinrepo with 'WMWPR','MWPR','month = month_no','','' 
	
*	repo form mwpr for month = month_no to (out_file) noco
*	do out_repo
else
	do err_beep
	do alert with '!!! No Transaction for Month Found ...'
endif
sele mwprhist
set orde to month_yr in mwprhist
m.year = ltrim(str(myear))
m.month = mmonth
if seek(ALLTRIM(mmonth)+ltrim(str(myear)))
	private resp
	resp = 1
	do alert with 'Do you want to Store MWPR Data ?',1,'\<Yes;\<No',resp
	if resp = 1
		gath memv
	endif
else
	inse into mwprhist from memv
endif
use in mwprhist
use in del
tmp_dbf = tmp_dbf + '.DBF'
dele file (tmp_dbf)
do cls_menu