'ALT_STAT - change Order_Status] from P V H R to U
'amended 28/06/02 to remove exclusion for Trade orders
'amended 28/07/05 only operates on invoiced orders to allow extra req'ns to be entered

external   vloadif() sch scw fentrybox() shopmask dpath messbox() cpath
external   exception() userid vunloadif() messboxwait() $menu progress()

public     ptstr jobnr $dayftr $orddate

global     x CheckJobNr() AltStat() deladdr1 custname $ordstat $mess cat
global     $newstat i #apptnr #date
'      UpdApptRecs()


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
'   messboxwait(" Alteration of Status for jobs before 31st May 1996 is restricted ",0,0,1)
  quiet on
  while true
    x = CheckJobNr()                    ' find Cust_Ord & update - L495
    if x = -1
      exit while
    end if
    x = AltStat()
    if x = -1
      exit while
    elseif x = 0
      continue while
    end if
  end while

  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory

END MAIN


FUNCTION AltStat()
' change Order_Status] from P V H R to U
  lock-record
    messbox(" Allow Shop to add req'ns to invoiced job? (y/n) ",1,1,1)
    if ptstr == "y"                    ' message "days($orddate) is:"&str(days($orddate))
        $newstat = "I"
        [Order_Status] = $newstat
        [Updated_By]   = userid
        [Last_Update]  = today
      write-record
      $mess = jobnr&"req'ns added after invoicing"
      cat = "SUNDRY"
      x = exception(userid,today,time24,cat,$mess)
      vunloadif(dpath|"unread1.vw")
      vloadif(dpath|"alt_stat.vw")
    else
      cancel-record
      return (0)
    end if
    return (1)
END FUNCTION ' AltStat()


FUNCTION CheckJobNr()                   ' finds Job & updates Cust_Ord
' local l1 c3 c2 c1 ques $reqstr
  while true
    repaint off
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ Find Job Nr                                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    x = fentrybox(" Job Nr to alter Status for or {Esc} for Menu ",6,shopmask,"")
    if x = -1
      return (-1)
    else
      jobnr = ptstr
    end if
    vloadif(dpath|"alt_stat.vw")
    order change key "[Job_Nr]"
    data find "[Job_Nr]" equal jobnr options ""   '  find correct JOB
    if cerror
      messbox(" Job Nr NOT found ",0,0,1)
      return (0)
    else
      if days([Invoice_Date])<1          ' NOT Invoiced
        messboxwait(" No need to change status - not yet invoiced ",0,0,1)
        return (-1)
      elseif days([Invoice_Date])>1          ' Invoiced
        deladdr1 = [Delivery_Address_1]
        custname = [CustOrd_Name]
        $ordstat = [Order_Status]
        $orddate = [Date_Of_Order]
        messbox(custname&"@"&deladdr1|"? (y/n) ",1,1,1)
        if ptstr == "y"
          return (1)
        else
          return (0)
        end if
      else
        messboxwait(" ALT_STAT.PF3 line 160 - Inv date not known ",0,0,1)
        return (-1)
      end if
    end if
  end while
END FUNCTION ' CheckJobNr()
