'ALT_STAT - change Order_Status] from P V H R to U
'amended 28/06/02 to remove exclusion for Trade orders

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

' x=[Order_Status] 'message "x is:"&str(x)
  if [Order_Status] = "A"             ' "U"pdated
    messboxwait(" Order & Customer details NOT entered - update order first ",0,1,1)
    cancel-record
    return (0)

  elseif [Order_Status] = "U"             ' "U"pdated
    messboxwait(" Order already in UPDATE status ",0,1,1)
    cancel-record
    return (0)

  elseif [Order_Status] = "L"             ' "U"pdated
    messboxwait(" Order currently being despatched - change not permitted ",0,0,1)
    cancel-record
    return (0)

  elseif [Order_Status] = "D"
    messboxwait(" Order completed & despatched - change not permitted ",0,0,1)
    cancel-record
    return (0)

  else                                 ' message "$menu is:"&str($menu)
    messbox(" Confirm change of status to UPDATE? (y/n) ",1,1,1)
    if ptstr == "y"                    ' message "days($orddate) is:"&str(days($orddate))
      #date=days(date2("01/06/96"))    ' message "#date is:"&str(#date)
      if days($orddate) < #date
        if $menu == "boss"
          messbox(" This job is dated before 31st May 1996 - continue? (y/n) ",1,0,1)
          if ptstr =="n"
            cancel-record
            return (0)
          end if
' warn that it is for last year
        else
          messboxwait(" Cannot alter Status for jobs before 31st May 1996 - contact Head Office ",0,0,1)
          cancel-record
          return (0)
        end if
      end if

'       messbox(" Release Order back to Shop? (y/n) ",1,0,1)
'       if ptstr == "n"
'         cancel-record
'         return (0)
'       else
'         messbox(" Checking for booked deliveries ",0,0,1)
'         x = CheckDeliveries()
'         if x = 1
'           cancel-record
'           return (0)
'         end if
'       end if
'       vloadif(dpath|"alt_stat.vw")
        $newstat = "U"
        [Order_Status] = $newstat
        [Updated_By]   = userid
        [Last_Update]  = today
      write-record
'       UpdApptRecs()
      $mess = jobnr&"status changed to UPDATE"
      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 if
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
'     if left(jobnr,1)="T"
'       messboxwait(" Cannot alter status for Trade orders ",0,0,1)
'       continue while
'     end if

'   progress(15,10," Checking for booked deliveries ",0)
'   x = CheckDeliveries()
'   if x = 1
'     messboxwait(" Goods already booked out - Shop must cancel deliveries first ",0,0,1)
'     return (0)
'   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
    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"
'       progress(15,10," Checking for booked deliveries ",0)
'       x = CheckDeliveries()
'       if x = 1
'         messboxwait(" Goods already booked out - Shop must cancel deliveries first ",0,0,1)
'         return (0)
'       end if
'       lock-record
      return (1)
    else
      return (0)
    end if
  end if
end while
END FUNCTION ' CheckJobNr()
