'CNTRAFTG - enter/amend contra charges for Ftr_Payt's

external  dpath Background() vloadif() fentrybox() popuplist() shopmask
external  cpath bpopdb() vunloadif()  messboxwait() navrecs() messline()
external  entryline()

public    ptstr jobnr dsa ftrcode ptval

global    x Fitters() ReturnToMenu() ChooseFitter() y3 y4 y5 $name $nickname
global    ContraEntry()


MAIN
single-step off
  Background()
  file unload all

' choose fitter/job
  while true
'     x = popuplist(10,33,13,"Fitter Job˙Nr","Enter By",1,0)
'     if x = -1
'       exit while
'     end if
'     if ptstr = "Fitter"

    Fitters()
    if x = -1
      exit while
    end if

'     else
'       while true
'         x = fentrybox(" Enter Job Nr ",6,shopmask,"")
'         if x = -1
'           exit while
'         end if
'         jobnr = ptstr
'         Process(1)
'
' '         exit while
'       end while
'
' '     end if
  end while

  ReturnToMenu()

END MAIN


FUNCTION Fitters()
local ppl
  while true
    x = popuplist(10,31,13,"Active˙fitters ˙All˙Fitters˙","Select by",1,0)
    if x = 0
      ppl = ptstr
      while true
        if ppl = "Active˙fitters"
          x = ChooseFitter("v")
          if x = -1
            exit while
          end if
        else
          x = ChooseFitter("a")
          if x = -1
            exit while
          end if
        end if
      end while
    else
      return(1)
    end if
  end while
END FUNCTION ' Fitters()


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)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  else
    data query execute "not_del.dfq" index "actv_ftr.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' 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]
      ContraEntry()
      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 ContraEntry()
local ftgdate j q d a r $reas
'enter reason and amount - enter as negative amount and release for payment
'   ftrcode = [Ftr_Code]
'   ftgdate = [FtdDate]
'   j       = [JobNr]
'   q       = [Address]
'   d       = [Desc]

'reason
  while true
    x = fentrybox(" Enter reason for contra ",20,"","")
    if x = -1
      continue while
    elseif ptstr = ""
      continue while
    else
      $reas = ptstr
      exit while
    end if
  end while

'date
  while true
    x = fentrybox(" Date of contra ",10,"##\/##\/####",today)
    if x = -1
      continue while
    elseif x = 0
      exit while
    end if
  end while
  ftgdate = ptstr

'enter amount
  while true
    x = fentrybox(" Enter amount of contra ",8,"*8{[-1234567890.]}","")
    if x = 0
      if ptstr = ""
        continue while
      end if
      a = value(ptstr)
      exit while
    end if
  end while


'   while true
    x = fentrybox(" Enter Job Nr (if applicable) ",6,shopmask,"")
    if x = -1
      jobnr = "Y99999"
'       exit while
    else
      jobnr = ptstr
    end if
'     exit while
'   end while

  vloadif(dpath|"ftr_payt.vws")
  data enter lock
    [Ftr_Code] = ftrcode
    [Date_Ftd] = ftgdate
    [Amount]   = -a
    [Released] = -a
    [Action]   = "N"
    [JobNr]    = jobnr
'     [ReqRef]   = r
    [Notes]    = $reas
'     [Address]  = q
'     [Desc] = d
  write-record
END FUNCTION ' ContraEntry()

