'DLY_CASH - Daily cash receipt report

external   vkeybox() sch scw progress() messbox() vloadif() cpath
'  PrintReport()
external   vunloadif() dpath fentrybox() chkdate() remove() areas greeting
external   base findpopup() messboxwait() $drive Background()
external   X_path _SWIP_Crystal() Xreppath

public     ptstr choice sum_date br_name psa dsa #banking

global     x DailyCash() ReturnToMenu() p1 p2 p3 p4 p5 p6 Place_Paid() $place i


MAIN
single-step off
  	screen clear box 1 1 sch scw 0 0 no-border
  	repaint off
' message "base) is:"&str(base)
  	DailyCash()

  	Background()

  	ReturnToMenu()

END MAIN


FUNCTION DailyCash()     ' show keybox() listing each shop (& ALL)
local br_dir repdate cashrep

	if base="T"
		$place="Trade"
	else
  		x = Place_Paid()
  		if x = -1
    			return (-1)
	  	end if
  	end if
'   	choice = left(br_name,1)             'message "choice is:"&str(choice)
'   	$branch = choice

' message "$branch) is:"&str($branch)


  	br_name = $place
  	choice = left(br_name,1)             'message "choice is:"&str(choice)
  	vloadif(dpath|"cshrcvd1.vw")
  	order change physical
  	if areas ! upper(choice)
    		while true
      		x = fentrybox(" Confirm Date for Cash Summary ",10,"##\/##\/####",today)
      		if x = 0
     	   		sum_date = ptstr
	        		if chkdate(sum_date,1) = -1
          			messbox(" Incorrect date - re-enter ",0,0,1)
          			continue while
        			end if
     	   		exit while
	      	elseif x = -1
        			return (-1)
      		end if
    		end while
    		progress(15,10," Please wait ... preparing report ",0)
    		data query execute "totcash1.dfq" index "totcash2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Banked]=blank and [Branch] = choice
'   and
'   [Abbrv_M] <> "O"
'   and
'   [Method_Of_Payment]<>"PDQ"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    		if cerror
      		messboxwait(" No Cash/cheques to summarise/pay in ",0,0,1)
      		return (1)
    		end if
    		messbox(" Do you want to include CASH in this banking? (y/n) ",1,1,1)
    		if ptstr == "n"
      		data query execute "totcash3.dfq" index "totcash3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Method_Of_Payment]="Cheque"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
      		if cerror
        			messboxwait(" No cheques to pay in ",0,0,1)
        			return (1)
      		end if
    		end if
    		#banking=filesum([Amount_Received],[Abbrv_M]="C") 'message "#banking is:"&str(#banking)
    		order sort execute dictionary "totcash.dfs" index "totcash.idx"

    		while true
      		vunloadif("X_cshrcd.vws")
      		remove(X_path|"X_cshrcd.*")
      		data query execute "not_del.dfq" Smart4 X_path|"X_cshrcd" fields "[Customer_Code|Br_KA]"
      		vunloadif("X_cshrcd.vws")
      		_SWIP_Crystal(Xreppath|"cshrcvd1","S",0,1,"") ' draft report
      		vloadif(dpath|"cshrcvd1.vw")
      		messbox(" Has the draft Cash Summary printed correctly? (y/n) ",1,1,1)
      		if ptstr == "y"                      '  store file & exit
        			for i = 1 to records
          			lock-record                        ' update record with inv nr & date
            				[Banked]=today
          			write-record
          			data goto record next
        			end for
        			_SWIP_Crystal(Xreppath|"cshrcvd2","S",0,2,"")  ' banking report
        			p1 = "totcashb.dfr"              ' banking version - message "p1) is:"&str(p1)
        			repdate = left(sum_date,2)|mid(sum_date,4,2)|right(sum_date,2) 'message "repdate) is:"&str(repdate)
        			br_dir=case br_name ("Sheen","SHEEN")("Raynes","RAYNES")("Fulham","FULHAM")("Putney","PUTNEY")("HeadÿOffice","HEAD") 'message "br_dir is:"&str(br_dir)
'         cashrep = $drive|":\REPORTS\BANKINGS\"|br_dir|"\"|repdate|".BNK" 'message "cashrep) is:"&str(cashrep)
        			cashrep = $drive|"REPORTS\BANKINGS\"|br_dir|"\"|repdate|".BNK" 'message "cashrep) is:"&str(cashrep)
        			print report execute p1 disk cashrep detail start 1 end 0 copies 1
        			exit while
      		else
        			messbox(" Abandon and print later? (y/n) ",1,1,1)
        			if ptstr == "y"                      '  store file & exit
          			return (-1)
        			else
          			continue while
        			end if
      		end if
    		end while
  	else
    		messbox(greeting|", you do not have access rights for this report ",0,0,1)
  	end if
  screen clear box 1 1 sch scw 0 0 no-border
' if shop selection is not included in "areas" on oldpurch.vws refuse access
' if "areas" allow 2 areas, then only one report to be done at any one time (DG excepted)
' print report listing all cash rec'd for selected shop(s)
END FUNCTION ' DailyCash()


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION Place_Paid()
local s1 s2 s3 s4 s5 s6 $locn s7
  	$locn = case base ("R","Raynes")("P","Putney")("S","Sheen")("F","Fulham") else "HeadÿOffice"
  	s1 = "Fulham"
  	s2 = "HeadÿOffice"
  	s3 = "Raynes"
  	s4 = "Sheen"
  	s7 = "Putney"
  	while true
    		x = findpopup(8,60,15,s1&s7&s2&s3&s4,$locn,"Place",1,0)
    		if x = -1
      		return (-1)
    		end if
    		$place = ptstr                     'message "$place is:"&str($place)
    		return (0)
  	end while
END FUNCTION 'Place_Paid()
