'VATONDEP - calculates VAT already accounted for to Customs & Excise. Basis of
'           adjustment in Sun Acc 6801 to actual.

external   sch scw vloadif() cpath PrintReport() progress() dpath Background()
external   base findpopup() messboxwait() ipath fgp bgp ChooseBranch()
external   vunloadif() progtag() fgi bgi remove() fentrybox() chkdate()
external   messbox() dly_pstgpath

public     ptstr choice sum_date br_name psa dsa $branch

global     p2 p3 p4 p5 p6 x i $shop_name NewIndex() StoreReport()
global     ReturnToMenu() p1 $place clf invdate
global     $dfa1 $ftrappts #ftrappts $fitter $day_1 $popstr df clb $invoice
global     jobdesc ftgcomm ftginstr ftgscrn y z slotrec y1 y2 y3 y4 fmt bot
global     deladdr3 deladdr4 cust_title custcontact offtel hometel $partaddr
global     UninvoicedOrders()


MAIN
single-step off
  messboxwait(" Only use data from month end backup ",0,0,1)
  messboxwait(" Ensure DailyPosting on BACKUP to monthend was done!! ",0,0,1)
  Background()
  file unload all
  p2 = ""   ' p2 = title at top of choice popup ("LABEL")
  p3 = 1    ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p5 = 1    ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p4 = 1

  while true
    x = fentrybox(" Confirm Date for Deposit Summary ",10,"##\/##\/####",today)
    if x = 0
      sum_date = ptstr
      if chkdate(sum_date,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      end if
      exit while
    elseif x = -1
      ReturnToMenu()
    end if
  end while

'   while true
'     $shop_name = ChooseBranch(8,33,1)
'     $branch = upper(left($shop_name,1))  'message "$branch) is:"&str($branch)
'     if $shop_name = -1
'       exit while
'     end if
'     screen shortrestore dsa

    NewIndex()

    UninvoicedOrders()

'   end while
  ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION NewIndex()
  progress(fgp,bgp," Creating new Uninvoiced indicesÿ",0)
  vloadif(dpath|"vod1.vw")
  order change physical
' repaint on
' repaint
' single-step on
  remove($branch|"_vod.idx")
'   progtag(fgi,bgi," Creating index for"&$branch)
'   data query execute "vod1.dfq" index $branch|"_vod.idx"
  data query execute "vod1.dfq" index "vodall.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Inv_Nr]=blank
' and
' not (deleted)
' and
' days([Posted])<=days(sum_date)
' and
' days([Posted])<>blank
' and
' days([Posted])<>0
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No receipts for uninvoiced orders ",0,0,1)
    return (-1)
  end if
  error on
END FUNCTION ' NewIndex()


FUNCTION UninvoicedOrders()
'   progress(15,10," Please wait ... looking for uninvoiced orders ",0)
'   order sort now "uninvd_2.idx" fields "[Posted;Job_Nr;Date_Of_Receipt]" ascending
  order sort now "uninvd_2.idx" fields "[SalesAnalysis;Job_Nr;Date_Of_Receipt]" ascending
  screen clear box 1 1 sch scw 0 0 no-border
  PrintReport("vatondep.dfr","Uninvoiced",p3,p4,p5,p6)
'   p1 = "cshtfr1.dfr"
'   PrintReport(p1,"Uninvoiced",p3,p4,p5,p6)
'   StoreReport(p1,"dep")
' inchar
'   PrintReport("csh_deps.dfr","Uninvoiced",p3,p4,p5,p6)
END FUNCTION ' UninvoicedOrders()


FUNCTION StoreReport(p1,ext)
local dlyrep repdate
 repdate = "0000"
'   dlyrep = dly_pstgpath|"DP"|repdate|"."|ext  '
  dlyrep = "E:\dep0000.997"
  print report execute p1 disk dlyrep detail start 1 end 0 copies 1
END FUNCTION ' StoreReport()

