'PCSH_PRC - Head Office; produces summaries of unpaid petty cash for each shop;
'           processes list to show it is paid and creates text file for reading
'	    into SUN Accounts


external   vkeybox() sch scw progress() messbox() vloadif() base $menu userid
external   vunloadif() dpath fentrybox() chkdate() areas greeting cpath
external   popuplist() fgp bgp ChooseBranch() remove() Background() vatrate
external   _SWIP_Crystal() Xreppath X_path bpopdb() increment() messboxwait()

public     ptstr ptval
public     $shop_name $shop_init

global     x ReturnToMenu() Report() nr ProcessPayment() i


MAIN
  single-step off
  Background()
  file unload all

  while true
'     x = popuplist(8,33,13,"HeadÿOffice Fulham Sheen Raynes Putney","",1,0)
'     if x = -1
'       ReturnToMenu()
'     end if
'     $shop_init = upper(left(ptstr,1))		'message "$shop_init) is:"&str($shop_init)

$shop_init = "H"

'     $shop_name = ptstr				'message "$shop_name is:"&str($shop_name)
'
    x = Report()			' listing of P/cash NOT re-imbursed
    if x=-1
      continue while
    elseif x=0				' draft correct
      messbox(" Continue and process these payments? (y/n) ",1,1,1)
      if ptstr == "y"
         ProcessPayment()
      else
        continue while
      end if
    end if
  end while

  ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  Background()
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION Report()
  messbox(" List of unpaid petty cash for"&$shop_name&"? (y/n) ",1,1,1)
  if ptstr == "n"
    return (-1)
  else				'message "print list of unpaid items"
    vloadif(dpath|"pcsh_ent.vws")
    data query execute "pcshrep1.dfq" index "pcash1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Shop]=$shop_init
' and
' not (deleted)
' and
' [ProcessDate]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No unpaid Petty Cash items for"&$shop_name,0,0,1)
    else
repaint on
repaint
single-step on
      remove(X_path|"Xpcshlst.*")
      data query execute "not_del.dfq" data-file X_path|"Xpcshlst" fields "[Date;ShopName;Shop;Ref_Nr;Category;SunCode;Narrative;VAT;Gross Amount]"
      vunloadif("Xpcshlst.vws")
      _SWIP_Crystal(Xreppath|"pcsh_lst","P",0,1,"")
    end if
  end if
  return (0)
END FUNCTION 'Report()


FUNCTION ProcessPayment()
'   vloadif(dpath|"pcshproc.vw")		'
  file unload all
  vloadif(dpath|"pcsh_ent.vws")		'
  order change index "pcash1.idx"
'   order change physical
' '   data query execute "pcshrep1.dfq" index "pcash1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Shop]=$shop_init
' and
' not (deleted)
' and
' [ProcessDate]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No unpaid Petty Cash items for"&$shop_name,0,0,1)
    else
    end if

for i=1 to records
lock-record
[ProcessDate]=today
write-record
data goto record next
End for

'   for i = 1 to records
'     lock-record                        ' update record with inv nr & date
'       [ProcessDate]=today
'     write-record
'     data goto record next
'   end for
message "check index"
'print file copy of report - ref nr on report will be shopinit & date (e.g. H040806)
  _SWIP_Crystal(Xreppath|"pcshproc","P",0,1,"")

'create text file for posting in SUN
END FUNCTION 'ProcessPayment()


