'FTRUNPYT - marks records in FTR_PAYT.db as unpaid so that account can be reconciled

external  cpath dpath Background() vloadif() vunloadif() bpopdb() popuplist()
external  messboxwait() fgp bgp navrecs() messline() PrintReport() messbox()
external  fentrybox() chkdate() progress() shopmask

public    ptstr dsa ftrcode $nickname ptval $name  jobnr

global    x ChooseFitter() ReturnToMenu() ProcessFitter() ppl ProcessPayment()


MAIN
single-step off
  file unload all
  Background()

  x = ChooseFitter("a")

  ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  Background()
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ChooseFitter(t)
  vloadif(dpath|"ftr_list.vws")
  if t = "v"                           'active fitters
    data query execute "actv_ftr.dfq" index "actv_ftr.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Active]="YES"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  end if
  order sort now dictionary "nickname" fields "[Nickname]" ascending
  while true
    x = bpopdb("ftr_list",5,"","[Nickname]","L8","[Fitter_Name]","L0","[Fitter_Code]",5,35,21,45,"",0)
    if x = -1
      repaint off
      vunloadif("ftr_list.vws")
      return(-1)
    else
      ftrcode   = ptstr                'message "ptstr is:"&str(ptstr)
      $name     = [Fitter_Name]        'message "$name is:"&str($name)
      $nickname = [Nickname]
      while true
        x = fentrybox(" Enter Job Nr ",6,shopmask,"")
        if x = -1
          continue while
        end if
        jobnr = ptstr
        exit while
      end while
      ProcessFitter()
      Background()
      vloadif(dpath|"ftr_list.vws")
    end if
  end while
  repaint off
  screen shortrestore dsa
  vunloadif("ftr_list.vws")
  return (-1)
END FUNCTION  ' ChooseFitter()


FUNCTION ProcessFitter()
local recnr jobseq ord bl m1
'show all PAID records for fitter
  Background()
  progress(15,10," Finding payments for"&$nickname&" on"&jobnr,0)
  vloadif(dpath|"ftr_payt.vws")
  order change key "[Ftr_Code]"
  data query execute "ftrunpyt.dfq" index "ftrupyt1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Ftr_Code]=ftrcode
'   and
'   [JobNr]=jobnr
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No paid records found for"&$nickname,0,0,1)
    vloadif(dpath|"ftr_list.vws")
    return (1)
  end if
  order sort now dictionary "ftrupyt2.idx" fields "[Date_Ftd]" descending
  order change physical

  x = ProcessPayment()
  if x = 1                             'if not printed then remove [Released]

  end if
END FUNCTION ' ProcessFitter()


FUNCTION ProcessPayment()
local y1 y2 y3
  vloadif(dpath|"ftrunpyt.vw")
  order change index "ftrupyt2.idx"
  ptval=0
  y1 = format(" Payments to process for"&$nickname,"M66")
  y3 = format(" ÿÿJob   Address                               Paid    Released","L66")
  y2 = format(" {Enter} views notes - {R}emove/re-instate payment - {Esc} exits ","M66")
  while ptval <> {Esc}
    repaint on
    repaint
    screen print 3 8 fgp bgp y1
    screen print 4 8 fgp bgp y3
    screen print 20 8 fgp bgp y2
    ptval = navrecs()
    if ptval = {Enter}
      if len([Notes])>0
        messboxwait([Notes],0,0,1)
      else
        messboxwait(" No Notes to view ",0,0,1)
      end if
    elseif ptval = {r} or ptval = {R}
      if [Paid]=blank
        x = messbox(" Payment already reversed, mark as PAID? (y/n) ",1,0,1)
        if ptstr == "y"
          lock-record
'             [Released] = [Amount]
            [Paid]     = [Amount]
            [Date_Paid] = "30/11/98"
'           [Address]  = [Delivery_Address_1]
'           [Notes]    = blank
          write-record
          data goto record next
        end if
      else
        x = messbox(" Confirm that you wish to have this `payment' reversed? (y/n) ",1,1,1)
        if ptstr == "y"
          lock-record
            [Released] = [Amount]
            [Paid] = blank
            [Date_Paid] = blank
'           [Address]  = [Delivery_Address_1]
'           [Notes]    = blank
          write-record
          data goto record next
        end if
      end if
    elseif ptval = {Esc}
      repaint off
      order change physical
    end if
  end while
END FUNCTION ' ProcessPayment()
