'MTHLYORD - monthly orders (from VARIATIONS) report

external   vkeybox() sch scw progress() messbox() vloadif() base $menu
external   vunloadif() dpath fentrybox() chkdate() areas greeting cpath
external   PrintReport() popuplist() fgp bgp ChooseBranches() remove()
external   _SWIP_Crystal() Xreppath X_path

public     ptstr indate monthend fullmonth briefmonth enddate
public     choice $shop_name $shop

global     x ReturnToMenu() Report() p1 p2 p3 p4 p5 p6 ChooseDate()
global     s1 s2 s3 s4 s5 s6 s7 $place leftjob SWIP_Print() sw


MAIN
  single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all

  while true
    x = ChooseBranches(8,33,areas)
    if x = -1
      exit while
    end if
    x = ChooseDate()
    if x = -1
      continue while
    end if
    x = Report()
'     exit while
  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 ChooseDate()
local y ld
  while true
    monthend = right(today,7)
    x = fentrybox(" Confirm month for"&$shop_name|"'s report ",7,"*2#\/*4#",monthend)
    if x = 0
      monthend = ptstr
      fullmonth = "01/"|ptstr
      if days(fullmonth)>days(today)
        messbox(" Future date - re-enter ",0,0,1)
        continue while
      end if
      x = chkdate(fullmonth,1)
      if x = 0
        y = len(date3(fullmonth))
        y = y - 8
        briefmonth = monthname(fullmonth)|" '"|right(fullmonth,2)
        exit while
      else
        messbox(" Incorrect date - re-enter ",0,0,1)
      end if
    else
      return (-1)
    end if
    briefmonth = left(date3(fullmonth),3)
  end while
  for ld = 31 to 28 step -1
    enddate = str(ld)|"/"|monthend         'message "last_m_e is:"&str(last_m_e)
    if chkdate(enddate,1) = -1
      continue for
    else
      exit for
    end if
  end for
END FUNCTION 'Date()


FUNCTION Report()
  vloadif(dpath|"ord_rep1.vw")
  order change key "[Var_Nr]"
  progress(fgp,bgp," Creating report for"&$shop_name|" ... please wait ",0)
  data query execute "shops2.dfq" INDEX "first.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³  left[Var_Nr,1]=$shop
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Sales this month at"&$shop_name|" ",0,0,1)
    return (1)
  end if
  data query execute "ord_rep.dfq" INDEX "second.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' º   right(date2([Date]),7) ! monthend                       º
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Orders entered this month at"&$shop_name|" ",0,0,1)
    return (1)
  end if
  order sort execute "ord_rep.dfs" INDEX "sal_rep"
  screen clear box 1 1 sch scw 0 0 no-border
  remove(X_path|"X_mth_o.*")
  data query execute "not_del.dfq" Smart4 X_path|"X_mth_o" fields "[Var_Nr;Date;CustOrd_Name;Amount_Gross;shop;Date_To]"

  vunloadif("X_mth_o.vws")
'   _SWIP_Crystal(Xreppath|"mth_ord1","P",0,1,"")

	sw=_SWIP_Crystal(Xreppath|"mth_ord1","S",0,1,"")		'message "sw is:"&str(sw)
' 	SWIP_Print("mth_ord1","S",0,1,"")

END FUNCTION 'Report()


FUNCTION SWIP_Print(s1,s2,s3,s4,s5)
	_SWIP_Crystal(Xreppath|"mth_ord1","S",0,1,"")
END FUNCTION ' SWIP_Print("mth_ord1","P",0,1,"")


