main.py :  » Business-Application » OpenRMS » openres-0.2.1 » client » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » OpenRMS 
OpenRMS » openres 0.2.1 » client » main.py
from widgets import *

go_menu = lang.Reservations, lang.Customers, lang.CheckIn, lang.Configuration, lang.Quit

#####  Application Frames Below Here

class resframe(appframe):
  def create_widgets(self):
    self.TitleVar = StringVar(self)
    self.TitleVar.set(lang.UnconfirmedReservations + ':')
    self.create_top_row()
    self.create_select_row()
    self.create_button_set()
  def create_top_row(self):
    self.TopRow = rowframe(self)

    self.AppLabel = unilabel(self.TopRow, self.TitleVar.get()) 
    self.AppLabel.pack(side = 'left')

    self.TRResFrame = Frame(self.TopRow)
    apply_config(self.TRResFrame)

    self.ResEntry = NumberEntry(self.TRResFrame)
    apply_config(self.ResEntry)
    self.ResLabel = unilabel(self.TRResFrame, lang.Res_ID)

    self.ConfEntry = NumberEntry(self.TRResFrame)
    apply_config(self.ConfEntry)
    self.ConfLabel = unilabel(self.TRResFrame, lang.Conf_ID)

    self.Fetch = Button(self.TRResFrame)
    apply_config(self.Fetch)
    self.Fetch['text'] = 'Go'
    self.Fetch['command'] = self.onGoButton

    self.ResLabel.pack(side = 'left')
    self.ResEntry.pack(side = 'left')
    self.ConfLabel.pack(side = 'left')
    self.ConfEntry.pack(side = 'left')
    self.Fetch.pack(side = 'left')
    self.TRResFrame.pack(side = 'right')  

    self.StatLabelRow = rowframe(self)
    self.StatLabel = unilabel(self.StatLabelRow, ' ')
    self.StatLabel.pack(side = 'right')
  def create_select_row(self):
    self.SelectRow = rowframe(self)
    self.ListGrid = grid_listbox(self.SelectRow, 
      [12, 12, 10, 10, 15, 20],
      [lang.DateIn, lang.DateOut, lang.Name, lang.Surname, 
      lang.Phone, lang.Email]
    )
    self.ListGrid.pack(side = 'top')
    _reservation = openrms._reservation
    self.ListGrid.OnDoubleClick = self.GoListEntry

    self.reservations = openrms._reservation.GetUnconfirmed(5)
    for reservation in self.reservations:
      customer = reservation.GetCustomer()
      date_in = format_date(reservation.date_in)
      date_out = format_date(reservation.date_out)
      self.ListGrid.AddRow(reservation.conf, 
        [date_in, date_out, 
        customer.f_name, customer.l_name, 
        customer.FormatPhone(), customer.email])
  def create_button_set(self):
    self.ButtonRow = rowframe(self)

    self.Autobook = Button(self.ButtonRow)
    apply_config(self.Autobook)
    self.Autobook['text'] = lang.Auto
    self.Autobook['command'] = self.onAutoBtn
    self.Autobook.pack(side = 'left')

    self.Confirm = Button(self.ButtonRow)
    apply_config(self.Confirm)
    self.Confirm['text'] = lang.Confirm
    self.Confirm[COMMAND] = self.onConfBtn
    self.Confirm.pack(side = 'left')

    self.Edit = Button(self.ButtonRow)
    apply_config(self.Edit)
    self.Edit['command'] = self.EditBtnCmd
    self.Edit['text'] = lang.Edit
    self.Edit.pack(side = 'left')

    self.Search = Button(self.ButtonRow)
    apply_config(self.Search)
    self.Search['text'] = lang.Search
    self.Search[COMMAND] = self.GoSearch
    self.Search.pack(side = 'left')

    self.Cust_Info = Button(self.ButtonRow)
    apply_config(self.Cust_Info)
    self.Cust_Info['text'] = lang.CustomerInfo
    self.Cust_Info[COMMAND] = self.onCustInfoBtn
    self.Cust_Info.pack(side = 'left')

    self.ButtonRow.pack(side = 'top')

  def EditBtnCmd(self):
    list_entry = self.ListGrid.GetSelectID()
    if int(list_entry):
      self.GoListEntry(list_entry)
  def GoReservation(self, reservation):
    appframe = reseditframe(self.master, reservation)
    self.master.ChangeApp(appframe)

  def GoSearch(self):
    appframe = ressearchframe(self.master)
    self.master.ChangeApp(appframe)

  def onConfBtn(self):
    list_entry = self.ListGrid.GetSelectID()
    for reservation in self.reservations:
      if str(reservation.conf) == str(list_entry):
        reservation.GetReslines()
        for resline in reservation.reslines:
          resline.status = 5
          resline.commit()
    appframe = resframe(self.master)
    self.master.ChangeApp(appframe)

  def onGoButton(self):
    _reservation = openrms._reservation
    res = self.ResEntry.get()
    conf = self.ConfEntry.get()
    if conf == '':
      if res == '':
        return
      else:
        reservation = _reservation.GetByID(res)
    else:
      reservation = _reservation.GetByConfID(conf)
    if reservation == None:
      self.ReservationNotFound()
      self.ResEntry.set('')
      self.ConfEntry.set('')
    else:
      self.GoReservation(reservation)
    return

  def onCustInfoBtn(self):
    list_id = self.ListGrid.GetSelectID()
    reservation = None 
    for res in self.reservations:
      if str(res.conf) == str(list_id):
        reservation = res
    customer = reservation.GetCustomer()
    appframe = custframe(self.master, customer)
    self.master.ChangeApp(appframe)

  def onAutoBtn(self):
    res_iface = openrms._reservation
    res_iface.Autobook()

    appframe = resframe(self.master)
    self.master.ChangeApp(appframe)

  def ReservationNotFound(self):
    self.StatLabel.set(lang.ReservationNotFound)
    self.bell()
  def GoListEntry(self, id):
    _reservation = openrms._reservation
    reservation = _reservation.GetByConfID(id)
    self.GoReservation(reservation)

class reseditframe(appframe):
  def __init__(self, master, reservation):

    self.class_id = None
    self.rclasses = {}
    self.beds = {}
    self.res_select = False

    self.ResLineList = False
    self.AppTitle = lang.ReservationBy + ":"

    self.reservation = reservation
    _status = openrms._r_status
    self.__statusarray = _status.GetAllArrayName()

    if self.reservation.customer:
      self.customer = self.reservation.GetCustomer()
    else:
      self.customer = None
    appframe.__init__(self, master)
  def create_widgets(self):
    self.CreateTopRow()
    self.MainFrame = rowframe(self)
    self.CreateResPane(self.MainFrame)
    self.CreateClassPane(self.MainFrame)

    self.ResPane.pack(side = 'left')
    self.ClassPane.pack(side = 'left')
    self.MainFrame.pack(side = 'top')
  def CreateTopRow(self):
    self.TopRow = rowframe(self)

    self.AppTitleLabel = unilabel(self.TopRow, self.AppTitle)
    self.AppTitleLabel.pack(side = 'left')

    self.cust_f_nameLabel = unilabel(self.TopRow, 
      self.customer.f_name)
    self.cust_f_nameLabel.pack(side = 'left', padx = 3)

    self.cust_l_nameLabel = unilabel(self.TopRow,
      self.customer.l_name)
    self.cust_l_nameLabel.pack(side = 'left', padx = 3)

    self.CustInfo = Button(self.TopRow)
    apply_config(self.CustInfo)
    self.CustInfo['text'] = lang.CustomerInfo
    self.CustInfo['command'] = self.OnCustInfoBtn
    self.CustInfo.pack(side = 'left')

    self.TopRow.pack(side = 'top')
        
  def CreateResPane(self, master):
    self.ResPane = colframe(master)
    self.ResPane.config(bd = '2', relief = 'groove')

    self.ResSpacer1 = rowframe(self.ResPane)
    self.ResLabel1 = unilabel(self.ResSpacer1, ' ')
    self.ResLabel1.pack(side = 'left')

    self.ResDatesRow = rowframe(self.ResPane)

    self.DateInLabel = unilabel(self.ResDatesRow, lang.DateIn)
    self.DateInLabel.pack(side = 'left')
    self.DateInEntry = DateEntry(self.ResDatesRow,
      self.reservation.date_in, format= config.DateFormat, 
      delimiter = config.DateDelim)
    self.DateInEntry.pack(side = 'left')

    self.DateOutEntry = DateEntry(self.ResDatesRow, 
      self.reservation.date_out, format = config.DateFormat,
      delimiter = config.DateDelim
    )
    self.DateOutEntry.pack(side = 'right')
    self.DateOutLabel = unilabel(self.ResDatesRow, lang.DateOut)
    self.DateOutLabel.pack(side = 'right')

    self.DatesSubRow = rowframe(self.ResPane)
    self.DatesDescLabel = unilabel(self.DatesSubRow, 
      lang.DateDesc)
    self.DatesDescLabel.pack(side = 'left')

    self.ResLineRow = rowframe(self.ResPane)
    self.ShowResLineList()

    self.PriceQtyRow = rowframe(self.ResPane)
    self.PriceLabel = unilabel(self.PriceQtyRow, 
      '%s: ' % lang.Price)
    self.PriceLabel.pack(side = 'left')
    self.PriceEntry = FloatEntry(self.PriceQtyRow)
    self.PriceEntry['width'] = 10
    self.PriceEntry.pack(side = 'left')

    self.QtyLabel = unilabel(self.PriceQtyRow, '  %s: ' % 
          lang.Quantity)
    self.QtyEntry = NumberEntry(self.PriceQtyRow)
    self.QtyEntry['width'] = 3
    self.QtyLabel.pack(side = 'left')
    self.QtyEntry.pack(side = 'left')

    self.TtlLabel = unilabel(self.PriceQtyRow, ' %s: %s' %  
      (lang.Total, ' '))
    self.TtlLabel.pack(side = 'left')

    self.StatClassRow = rowframe(self.ResPane)

    self.StatLabel = unilabel(self.StatClassRow, lang.Status)
    self.StatLabel.pack(side = 'left')

    self.StatMenu = ExtOptionMenu(self.StatClassRow, lang.Status,
      lang.No_Change__)

    stat_iface = openrms._r_status

    self.status_array = stat_iface.GetAllArrayName()
    for status in self.status_array.values():
      self.StatMenu.addOption(status)

    self.StatMenu.pack(side = 'left')
      

    self.ClassChangeButton = Button(self.StatClassRow)
    apply_config(self.ClassChangeButton)
    self.ClassChangeButton['text'] = lang.ChangeClass
    self.ClassChangeButton['command'] = self.OnClassBtn
    self.ClassChangeButton.pack(side = 'right')

    self.BoolRow = rowframe(self.ResPane)
    
    self.WillDgd = Unicheckbutton(self.BoolRow, 
      lang.WillingToDowngrade)
    self.WillDgd.config(padx = 0)
    self.WillDgd.pack(side = 'left')

    self.WillUpgd = Unicheckbutton(self.BoolRow, 
      lang.WillingToUpgrade)
    self.WillUpgd.pack(side = 'right')


    self.ResSpacer2 = rowframe(self.ResPane)
    self.ResLabel2 = unilabel(self.ResSpacer2, ' ')
    self.ResLabel2.pack(side = 'left')

    self.ConfirmChangeRow = rowframe(self.ResPane)

    self.ChangeResButton = Button(self.ConfirmChangeRow)
    apply_config(self.ChangeResButton)
    self.ChangeResButton['text'] = lang.UpdateReservation
    self.ChangeResButton.pack(side = LEFT)
    self.ChangeResButton[COMMAND] = self.OnChangeResBtn

    self.ChangeLineBtn = Button(self.ConfirmChangeRow)
    apply_config(self.ChangeLineBtn)
    self.ChangeLineBtn.config(text = lang.AddLine, 
        command = self.OnLineBtn)
    self.ChangeLineBtn.pack(side = 'left', padx = 3)

    self.ClearBtn = Button(self.ConfirmChangeRow)
    apply_config(self.ClearBtn)
    self.ClearBtn.config(text = lang.Clear, 
      command = self.OnClearBtn)
    self.ClearBtn.pack(side = 'left')

    self.ResTtlLabel = unilabel(self.ConfirmChangeRow, 
      ' %s: %s%s' 
      %  
      (lang.Total, lang.CURRENCYSYM,
        self.reservation.GetTotal()))
    self.ResTtlLabel.pack(side = 'right')


  def ShowResLineList(self):
    if self.ResLineList:
      self.ResLineList.destroy()
    self.ResLineList = grid_listbox(self.ResLineRow, 
        [8, 6, 10, 16],
        [lang.Status, lang.Class, lang.Quantity,
        lang.Price])

    self.ResLineList.OnSelect = self.OnListSelect
    self.ResLineList.pack(side = 'left')
    if bool(self.reservation.reslines) == False:
      self.reservation.GetReslines()
    for resline in self.reservation.reslines:
      self.ResLineList.AddRow(resline.id, 
        [resline.status, resline.class_id, 
          resline.quantity, 
          resline.GetTotalPrice()]
      )

  def CreateClassPane(self, master):
    self.ClassXPane = colframe(master)
    self.ClassXPane.config(relief = 'groove', bd = '2')

    self.ClassPane = rowframe(self.ClassXPane)
    self.ClassLabelRow = rowframe(self.ClassPane)
    self.ClassInfoLbl = unilabel(self.ClassLabelRow, '%s:' %
      lang.RoomClassInfo)
    self.ClassInfoLbl.pack(side = 'left')

    is_true = DBAL.is_true

    self.BoolValRow = rowframe(self.ClassPane)
    smokeval = '%s: ' % lang.Smoking
    self.SmokeLabel = unilabel(self.BoolValRow, smokeval)
    self.C_Smoke = unilabel(self.BoolValRow, ' ')
    self.SmokeLabel.pack(side = 'left')
    self.C_Smoke.pack(side = 'left')

    bathval = "%s: " % lang.PrivateBath
    self.bathLabel = unilabel(self.BoolValRow, bathval)
    self.C_Bath = unilabel(self.BoolValRow, ' ')
    self.bathLabel.pack(side = 'left')
    self.C_Bath.pack(side = 'left')

    bedval = '%s: ' % lang.BedType
    self.BedLabelRow = rowframe(self.ClassPane)
    self.BedTypeLabel = unilabel(self.BedLabelRow, bedval)
    self.C_Bed = unilabel(self.BedLabelRow, ' ')
    self.BedTypeLabel.pack(side = 'left')
    self.C_Bed.pack(side = 'left')

    self.ClassPriceRow = rowframe(self.ClassPane)
    priceval = '%s: ' % lang.Price
    self.ClassPriceLabel = unilabel(self.ClassPriceRow, priceval)
    self.C_Price = unilabel(self.ClassPriceRow, ' ')
    self.ClassPriceLabel.pack(side = 'left')
    self.C_Price.pack(side = 'left')

    self.CPDLRow = rowframe(self.ClassPane)
    self.CDescLbl = unilabel(self.CPDLRow, '%s:' % lang.Description)
    self.CDescLbl.pack(side = 'left')

    self.CPDRow = rowframe(self.ClassPane)
    self.C_Desc = unilabel(self.CPDRow, ' ')
    self.C_Desc.config(wraplength = 250)
    self.C_Desc.pack(side = 'left')

    self.CPPLRow = rowframe(self.ClassPane)
    self.C_P_LBL = unilabel(self.CPPLRow, '%s:' % lang.Prices)

    self.CPPRow = rowframe(self.ClassPane)
    self.C_Price = unilabel(self.CPPRow, ' ')
    self.C_P_LBL.pack(side = 'left')
    self.C_Price.pack(side = 'left')

  def OnListSelect(self, id):
    resline = openrms._resline.GetByID(id)
    self.res_select = id
    self.QtyEntry.set(resline.quantity)
    self.StatMenu.set(self.status_array[resline.status])
    self.TtlLabel.set('%s: %s%.2f' % 
      (lang.Total, lang.CURRENCYSYM, resline.GetTotalPrice()))
    self.WillDgd.set(DBAL.is_true(resline.will_downgrade))
    self.WillUpgd.set(DBAL.is_true(resline.will_upgrade))
    self.UpdateClassPane(resline.class_id)
    self.ChangeLineBtn.config(text = lang.SaveLine)
    self.UpdatePriceLbl(resline)

  def UpdateClassPane(self, id):
    if id == False:
      rclass = openrms._r_class
    elif self.rclasses.keys().count(id):
      rclass = self.rclasses[id]
    else:
      rclass = openrms._r_class.GetByID(id)
      self.rclasses[id] = rclass

    if id:
      rclass.price = '%.2f' % float(rclass.price)
    self.C_Smoke.set(dbbool2yn(rclass.smoking))
    self.C_Bath.set(dbbool2yn(rclass.priv_bath))
    self.C_Price.set(rclass.price)
    self.C_Desc.set(rclass.description)

    if id == False:
      bed = openrms._bed_type
    elif self.beds.keys().count(rclass.bed_type):
      bed = self.beds[rclass.bed_type]
    else:
      bed = openrms._bed_type.GetByID(rclass.bed_type)
      self.beds[bed.id] = bed

    self.C_Bed.set(bed.description)

  def UpdatePriceLbl(self, resline):
    if len(resline.day_price) == 0:
      resline.GetPrices
    pricelbl = ''
    for k, v in resline.day_price.items():
      pricelbl += '%s: %s%.2f\n' % (
        format_date(DateTime.DateTimeFromAbsDays(k)),
        lang.CURRENCYSYM, float(v))
    self.C_Price.set(pricelbl)
  def OnChangeResBtn(self):
    self.reservation.date_in = self.DateInEntry.get()
    self.reservation.date_out = self.DateOutEntry.get()
    self.reservation.commit()
    reservation = self.reservation.GetByConfID(
      self.reservation.conf
    )
    appframe = reseditframe(self.master, reservation)
    self.master.ChangeApp(appframe)

  def OnLineBtn(self):
    if self.res_select == False:
      stat_name = self.StatMenu.get()

      resline = openrms.resline(None, None, 
        self.reservation.conf, self.QtyEntry.get(), 
        1, self.PriceEntry.get(), 0, 0, 0)

      if bool(resline.price) == False:
        resline.price = None
      if bool(resline.quantity) == False:
        resline.quantity = None

      if self.class_id:
        resline.class_id = self.class_id

      resline.will_upgrade = self.WillUpgd.get()
      resline.will_downgrade = self.WillDgd.get()

      for k, v in self.status_array.items():
        if v == stat_name:
          resline.status = k

      if resline.status:
        resline.commit()
        self.UpdatePriceLbl(resline)
      
    else:
      resline = openrms._resline.GetByID(self.res_select)
      resline.price = self.PriceEntry.get()
      resline.quantity = self.QtyEntry.get()

      if bool(resline.price) == False:
        resline.price = None
      if bool(resline.quantity) == False:
        resline.quantity = None

      if self.class_id:
        if self.class_id != resline.class_id:
          resline.class_id = self.class_id
          resline.PriceRecalc()
      resline.will_upgrade = self.WillUpgd.get()
      resline.will_downgrade = self.WillDgd.get()
      stat_name = self.StatMenu.get()
      for k, v in self.status_array.items():
        if v == stat_name:
          resline.status = k
  
      resline.commit()

    self.reservation.GetReslines()
    self.ShowResLineList()

  def OnClearBtn(self):
    self.UpdateClassPane(False)
    self.ChangeLineBtn.config(text = lang.AddLine)
    self.PriceEntry.set('')
    self.QtyEntry.set('')
    self.TtlLabel.set('%s: ' % lang.Total)
    self.StatMenu.set(lang.Status)
    self.WillUpgd.set(0)
    self.WillDgd.set(0)
    self.res_select = False
  def OnClassBtn(self):
    self.MainFrame.pack_forget()
    self.classsearchframe = resclasssearchframe(self)

  def ChangeClass(self, class_id):
    self.class_id = class_id
    self.MainFrame.pack(side = 'top')
    self.UpdateClassPane(class_id)

  def OnCustInfoBtn(self):
    appframe = custframe(self.master, self.customer)
    self.master.ChangeApp(appframe)

class ressearchframe(appframe):
  def create_widgets(self):
    self.rclass = None
    self.ListGrid = None
    status = openrms._r_status
    self.__statusarray = status.GetAllArrayName()

    self.Window = rowframe(self)

    self.TopRow = rowframe(self.Window)

    self.Title = unilabel(self.TopRow, 
        '%s: ' % lang.SearchReservations)
    self.Title.pack(side = 'left')

    self.DateRow = rowframe(self.Window)

    self.FromDatelbl = unilabel(self.DateRow, 
        "%s: " % lang.FromDate)
    self.FromDatelbl.pack(side = 'left')
    self.FromDate = DateEntry(self.DateRow, 
        format = config.DateFormat,
        delimiter = config.DateDelim)
    self.FromDate.pack(side = 'left')

    self.ToDatelbl = unilabel(self.DateRow, "  %s: " % lang.ToDate)
    self.ToDatelbl.pack(side = 'left')
    self.ToDate = DateEntry(self.DateRow, 
        format = config.DateFormat,
        delimiter = config.DateDelim)
    self.ToDate.pack(side = 'left')

    self.DateSearch = Button(self.DateRow)
    apply_config(self.DateSearch)
    self.DateSearch['text'] = lang.SearchByDate
    self.DateSearch['command'] = self.OnDateSearch
    self.DateSearch.pack(side = 'left', padx = '3')
    self.DateSpacer = spacerrow(self.Window)

    self.ClassStatRow = rowframe(self.Window)

    self.StatMenu = ExtOptionMenu(self.ClassStatRow, 
      lang.Status, lang.NA)
    self.StatMenu.pack(side = 'left')
    for k,v in self.__statusarray.items():
      self.StatMenu.addOption(v)

    self.ClassBtn = Button(self.ClassStatRow)
    apply_config(self.ClassBtn)
    self.ClassBtn['text'] = lang.ChangeClass
    self.ClassBtn['command'] = self.OnClassBtn
    self.Classlbl = unilabel(self.ClassStatRow, 
      "%s: %s" % (lang.ClassSelected, self.rclass))
    self.Classlbl.pack(side = 'left', padx = '3')
    self.ClassBtn.pack(side = 'left', padx = '3')

    self.SearchCStat = Button(self.ClassStatRow)
    apply_config(self.SearchCStat)
    self.SearchCStat['text'] = lang.SearchByClassAndStatus
    self.SearchCStat['command'] = self.OnSearchCStat
    self.SearchCStat.pack(side = 'left', padx = '3')
    self.CStatSpacer = spacerrow(self.Window)

    self.CustomerRow = rowframe(self.Window)

    self.NameLbl = unilabel(self.CustomerRow, "%s: " % lang.Name)
    self.NameLbl.pack(side = 'left')
    self.Name = TextEntry(self.CustomerRow)
    self.Name.pack(side = 'left', padx = '3')

    self.SurNameLbl = unilabel(self.CustomerRow, '%s: ' % 
          lang.Surname)
    self.SurNameLbl.pack(side = 'left', padx = '3')
    self.Surname = TextEntry(self.CustomerRow)
    self.Surname.pack(side = 'left', padx = '3')

    self.PhoneLbl = unilabel(self.CustomerRow, '%s: ' % lang.Phone)
    self.PhoneLbl.pack(side = 'left')
    self.Phone = TextEntry(self.CustomerRow)
    self.Phone.pack(side = 'left', padx = '3')

    self.CustSearch = Button(self.CustomerRow)
    apply_config(self.CustSearch)
    self.CustSearch['text'] = lang.Search
    self.CustSearch['command'] = self.OnCustSearch
    self.CustSearch.pack(side = 'left', padx = '3')
    self.CustSpacer = spacerrow(self.Window)

    self.ListGridRow = rowframe(self.Window)
    self.ShowListGrid([])

    self.ButtonRow = rowframe(self.Window)

    self.EditBtn = Button(self.ButtonRow)
    apply_config(self.EditBtn)
    self.EditBtn['text'] = lang.Edit
    self.EditBtn['command'] = self.OnEditBtn
    self.EditBtn.pack(side = 'left')

    self.CustInfo = Button(self.ButtonRow)
    apply_config(self.CustInfo)
    self.CustInfo['text'] = lang.CustomerInfo
    self.CustInfo['command'] = self.OnCustInfo
    self.CustInfo.pack(side = 'left')
  def OnDateSearch(self):
    date_from = self.FromDate.get()
    date_to = self.ToDate.get()
    res_iface = openrms._reservation
    reservations = res_iface.SearchByDateRange(date_from, date_to)
    self.ShowListGrid(reservations)
  def OnClassBtn(self):
    self.Window.pack_forget()
    self.appwindow = resclasssearchframe(self)
  def OnSearchCStat(self):
    reservation_iface = openrms._reservation
    status = None
    stat_label = self.StatMenu.get()
    for k, v in self.__statusarray.items():
      if v == stat_label:
        status = k
    reservations = reservation_iface.SearchByClassAndStatus(
      self.rclass, status
    )
    self.ShowListGrid(reservations)
        
  def OnCustSearch(self):
    customer = openrms.customer(None, self.Name.get(), 
      self.Surname.get(),
      '', '', '', '', '', self.Phone.get(), '')
    customers = customer.search()

    reservations  = []
    res_iface = openrms._reservation

    for cust in customers:
      cust_res = res_iface.GetByCustomerID(cust.id)
      for res in cust_res:
        reservations.append(res)
    self.ShowListGrid(reservations)
      
  def OnEditBtn(self):
    list_entry = self.ListGrid.GetSelectID()
    if int(list_entry):
      self.GoListEntry(list_entry)
  def OnCustInfo(self):
    list_entry = self.ListGrid.GetSelectID()
    res_iface = openrms._reservation

    res = res_iface.GetByConfID(list_entry)
    customer = res.GetCustomer()

    appwindow = custframe(self.master, customer)
    self.master.ChangeApp(appwindow)
  def GoListEntry(self, id):
    res_iface = openrms._reservation
    reservation = res_iface.GetByConfID(id)
    appwindow = reseditframe(self.master, reservation)
    self.master.ChangeApp(appwindow)
  def ShowListGrid(self, reservations):
    if self.ListGrid:
      self.ListGrid.destroy()
    self.ListGrid = grid_listbox(self.ListGridRow, 
      [12, 12, 10, 15, 15, 20],
      [lang.DateIn, lang.DateOut, lang.Name,
      lang.Surname, lang.Phone, lang.Email]
    )
    self.ListGrid.OnDoubleClick = self.GoListEntry

    for res in reservations:
      cust = res.GetCustomer()
      self.ListGrid.AddRow(res.conf, 
        [format_date(res.date_in),
          format_date(res.date_out),
          cust.f_name, cust.l_name, 
          cust.FormatPhone(), cust.email
        ]
      )
  def ChangeClass(self, rclass):
    self.rclass = rclass
    self.Classlbl.set("%s: %s" % (lang.ClassSelected, self.rclass))
    self.Window.pack()

class resclasssearchframe(appframe):
  def __init__(self, master, reservation = None):
    self.reservation = reservation
    appframe.__init__(self, master)
  def create_widgets(self):
    self.ListGrid = None
    self.CreateClassPane(self)
    if self.reservation:
      self.CreateResPane(self)
  def CreateClassPane(self, master):
    self._ClassPane = rowframe(master)
    self.ClassPane = colframe(self._ClassPane)

    self.SmokeRow = rowframe(self.ClassPane)
    self.SmokeLbl = unilabel(self.SmokeRow, lang.Smoking)
    self.SmokeLbl.pack(side = 'left')
    self.Smokebtns = ynna_radiobutton(self.SmokeRow)
    self.Smokebtns.pack(side = 'right')

    self.BathRow = rowframe(self.ClassPane)
    self.BathLbl = unilabel(self.BathRow, lang.PrivateBath)
    self.BathLbl.pack(side = 'left')
    self.BathBtns = ynna_radiobutton(self.BathRow)
    self.BathBtns.pack(side = 'right')

    self.FeatRow = rowframe(self.ClassPane)
    self.bedarray = openrms._bed_type.ReturnLabelArray()
    labels = []
    for k, item in self.bedarray.items():
      labels.append(item)
    self.BedTypeMenu = ExtOptionMenu(self.FeatRow, lang.BedTypes, 
        lang.NA, labels)
    self.BedTypeMenu.pack(side = 'left')
    self.SearchByFeatures = Button(self.FeatRow)
    apply_config(self.SearchByFeatures)
    self.SearchByFeatures['text'] = lang.FeatureSearch
    self.SearchByFeatures['command'] = self.OnFeatSearch
    self.SearchByFeatures.pack(side = 'left', padx = 3)
    self.FeatSpacer = spacerrow(self.ClassPane)

    self.PriceRow = rowframe(self.ClassPane)
    self.PriceLbl = unilabel(self.PriceRow, lang.Price)
    self.PriceEntry = FloatEntry(self.PriceRow)
    self.PriceEntry['width'] = 10
    self.PriceLbl.pack(side = 'left')
    price_ops = ['=', '<', '>', '<>', '<=', '>=']
    self.PriceOp = ExtOptionMenu(self.PriceRow, '=', price_ops)
    self.PriceOp.pack(side = 'left')
    self.PriceEntry.pack(side = 'left')
    self.PriceSearch = Button(self.PriceRow)
    apply_config(self.PriceSearch)
    self.PriceSearch['text'] = lang.PriceSearch
    self.PriceSearch['command'] = self.OnPriceSearch
    self.PriceSearch.pack(side = 'left')

    self.GridRow = rowframe(self.ClassPane)
    self.ShowListGrid([])

    self.CreateCurClassPane(self._ClassPane)
    
  def CreateCurClassPane(self, master):
    self._CurClassPane = colframe(master)
    self.CurClassPane = rowframe(self._CurClassPane)
    self._CurClassPane.config(relief = 'groove', bd = '2')

    self.CurClassSmokeRow = rowframe(self.CurClassPane)
    self.CurClassSmokelbl = unilabel(self.CurClassSmokeRow,
      "%s: " % lang.Smoking)
    self.CurClassSmoking = unilabel(self.CurClassSmokeRow, ' ')
    self.CurClassSmokelbl.pack(side = 'left')
    self.CurClassSmoking.pack(side = 'left')

    self.CurClassBathRow = rowframe(self.CurClassPane)
    self.CurClassBathlbl = unilabel(self.CurClassBathRow,
      '%s: ' % lang.PrivateBath)
    self.CurClassPrivBath = unilabel(self.CurClassBathRow, ' ')
    self.CurClassBathlbl.pack(side = 'left')
    self.CurClassPrivBath.pack(side = 'left')

    self.CurClassPriceRow = rowframe(self.CurClassPane)
    self.CurClassPricelbl = unilabel(self.CurClassPriceRow, 
      '%s: ' % lang.Price)
    self.CurClassPrice = unilabel(self.CurClassPriceRow, ' ')
    self.CurClassPricelbl.pack(side = 'left')
    self.CurClassPrice.pack(side = 'left')

    self.CurClassDescRow = rowframe(self.CurClassPane)
    self.CurClassDesclbl = unilabel(self.CurClassDescRow, 
      '%s: ' % lang.Description)
    self.CurClassDesclbl.pack(side = 'left')

    self.CurClassDescRow2 = rowframe(self.CurClassPane)
    self.CurClassDescription = unilabel(self.CurClassDescRow2, ' ')
    self.CurClassDescription['wraplength'] = 200
    self.CurClassDescription.pack(side = 'left')

  def CreateResPane(self, master):
    customer = self.reservation.GetCustomer()

    self.ResPane = rowframe(master)
    self.ResPane.config(bd = 2, relief = 'groove')

    self.ResTopRow = rowframe(self.ResPane)
    self.ResTitle = unilabel(self.ResTopRow,
      '%s: ' % lang.ReservationBy)
    self.ResTitle.pack(side = 'left')
    self.ResFName = unilabel(self.ResTopRow,
      '%s ' % customer.f_name)
    self.ResLName = unilabel(self.ResTopRow,
      '%s ' % customer.l_name)
    self.ResFName.pack(side = 'left')
    self.ResLName.pack(side = 'left')

    self.ResDateRow = rowframe(self.ResPane)
    self.ResDateIn = unilabel(self.ResDateRow,
      '%s: %s ' % (lang.DateIn, 
        format_date(self.reservation.date_in)))
    self.ResDateIn.pack(side = 'left')
    self.ResDateOut = unilabel(self.ResDateRow,
      '  %s: %s' % (lang.DateOut,
        format_date(self.reservation.date_out)))
    self.ResDateOut.pack(side = 'left')

    self.ResUpDownGdRow = rowframe(self.ResPane)
    self.WillUpGd = unilabel(self.ResUpDownGdRow,
      '%s: %s' % (lang.WillingToUpgrade, 
      dbbool2yn(self.reservation.will_upgrade)
      )
    )
    self.WillDownGd = unilabel(self.ResUpDownGdRow,
      '   %s: %s' % (lang.WillingToDowngrade, 
      dbbool2yn(self.reservation.will_downgrade)
      )
    )
    self.WillUpGd.pack(side ='left')
    self.WillDownGd.pack(side = 'left')

    self.ResPriceRow = rowframe(self.ResPane)
    self.ResPrice = unilabel(self.ResPriceRow, 
      '%s: %s' % (lang.Price, self.reservation.price))
    self.ResPrice.pack(side = 'left')
  def ShowListGrid(self, class_list):
    if hasattr(self, '_beds') == 0:
      self._beds = {}
    if hasattr(self, '_classes') == 0:
      self._classes = {}

    if self.ListGrid:
      self.ListGrid.destroy()
    self.ListGrid = grid_listbox(self.GridRow,
      [10, 10, 6, 10],
      [lang.Price, lang.Smoking, lang.Bath, lang.Bed])
    self.ListGrid.OnSelect = self.UpdateCurClassPane
    self.ListGrid.OnDoubleClick = self.OnClassUpdate

    for entry in class_list:
      bed_keys = self._beds.keys()
      class_keys = self._classes.keys()

      if class_keys.count(entry.id) == 0:
        self._classes[entry.id] = entry
      if bed_keys.count(entry.bed_type) == 0:
        bed = entry.GetBedType()
        self._beds[bed.id] = bed
      else:
        bed = self._beds[entry.bed_type]

      if DBAL.is_true(entry.smoking):
        Smoking = lang.Y
      else:
        Smoking = lang.N

      if DBAL.is_true(entry.priv_bath):
        Bath = lang.Y
      else:
        Bath = lang.N
      self.ListGrid.AddRow(entry.id,
        [entry.price, Smoking, Bath, bed.label])
        
  def OnPriceSearch(self):
    r_class = openrms.r_class(None, None, None, 
      self.PriceEntry.get(), 
      None, None, None)
    rclass_list = r_class.SearchByPrice(self.PriceOp.get())
    self.ShowListGrid(rclass_list)
  def OnFeatSearch(self):
    BedType = None;
    bed_lbl = self.BedTypeMenu.get()
    for k, v in self.bedarray.items():
      if bed_lbl == v:
        BedType = k
    r_class = openrms.r_class(None, self.Smokebtns.get(), BedType, 
      None, self.BathBtns.get(), None, None)
    rclass_list = r_class.SearchByFeatures()
    self.ShowListGrid(rclass_list)
  def UpdateCurClassPane(self, id):
    r_class = self._classes[int(id)]
    if DBAL.is_true(r_class.smoking):
      smoking = lang.Y
    else:
      smoking = lang.N
    if DBAL.is_true(r_class.priv_bath):
      bath = lang.Y
    else:
      bath = lang.N
    self.CurClassSmoking.set(smoking)
    self.CurClassPrivBath.set(bath)
    self.CurClassPrice.set(r_class.price)
    self.CurClassDescription.set(r_class.description)
  def OnClassUpdate(self, id):
    if self.reservation:
      self.reservation.class_id = id
      self.reservation._InitPrice()
      self.reservation.commit()
      appframe = reseditframe(self.master, self.reservation)
      self.master.ChangeApp(appframe)
    else:
      self.master.ChangeClass(id)
      self.exit()

class custframe(appframe):
  def __init__(self, master, customer = None):
    self.customer = customer
    self.SearchList = None

    if self.customer == None:
      self.customer = openrms.customer('','','','','','','',
        '','','')
      self.AppTitle = lang.NewCustomer
    else:
      self.AppTitle = lang.EditCustomer
    appframe.__init__(self, master)
  def create_widgets(self):
    self.TitleRow = rowframe(self)
    self.TitleLbl = unilabel(self.TitleRow, '%s:' % self.AppTitle)
    self.TitleLbl.pack()
    self.CustBlock = rowframe(self)
    self.CreateCustPane()
    self.CreateSearchPane()
    self.CreateDispPane()
  def CreateCustPane(self):
    self.CustPane = colframe(self.CustBlock)
    self.CustPane.config(bd = '2', relief = 'groove')
    Pane = self.CustPane

    self.CustNameRow = rowframe(Pane)

    self.NameLbl = unilabel(self.CustNameRow, "%s: " % lang.Name)
    self.NameLbl.pack(side = 'left')
    self.Name = TextEntry(self.CustNameRow, self.customer.f_name)
    self.Name.pack(side = 'left')

    self.SurnameLbl = unilabel(self.CustNameRow, 
            ' %s: ' % lang.Surname)
    self.Surname = TextEntry(self.CustNameRow, self.customer.l_name)
    self.Surname.pack(side = 'right')
    self.SurnameLbl.pack(side = 'right')
    
    self.AddressBlock = rowframe(Pane)
    Block = self.AddressBlock

    self.AddressCol = colframe(Block)

    self.AddressLblRow = rowframe(self.AddressCol)
    self.AddressLbl = unilabel(self.AddressLblRow, 
          '%s:' % lang.Address)
    self.AddressLbl.pack(side = 'left')

    self.AddressRow = rowframe(self.AddressCol)
    self.Address = Text(self.AddressRow)
    apply_config(self.Address)
    self.Address.config(height = 4, width = 23, wrap = 'word')
    self.Address.insert('1.0', self.customer.address)
    self.Address.pack(side = 'left')

    self.CityCol = colframe(Block)
    self.CityCol.pack_forget()
    self.CityCol.pack(side = 'right')

    self.CityRow = rowframe(self.CityCol)

    self.CityLbl = unilabel(self.CityRow, '%s: ' % lang.City)
    self.City = TextEntry(self.CityRow, self.customer.city)
    self.City.pack(side = 'right')
    self.CityLbl.pack(side = 'right')

    self.StateRow = rowframe(self.CityCol)

    self.StateLbl = unilabel(self.StateRow, 
          '%s: ' % lang.State_Prov)
    self.State = TextEntry(self.StateRow, self.customer.state)
    self.State.pack(side = 'right')
    self.StateLbl.pack(side = 'right')

    self.ZipRow = rowframe(self.CityCol)

    self.ZipLbl = unilabel(self.ZipRow, '%s: ' % lang.Zip_PostC)
    self.Zip = TextEntry(self.ZipRow, self.customer.zip)
    self.Zip.pack(side = 'right')
    self.ZipLbl.pack(side = 'right')

    self.CountryRow = rowframe(self.CityCol)

    self.CountryLbl = unilabel(self.CountryRow, 
            '%s: ' % lang.Country)
    self.Country = TextEntry(self.CountryRow, self.customer.country)
    self.Country.pack(side = 'right')
    self.CountryLbl.pack(side = 'right')

    self.EmailRow = rowframe(Pane)

    self.EmailLbl = unilabel(self.EmailRow, '%s: ' % lang.Email)
    self.Email = TextEntry(self.EmailRow, self.customer.email)
    self.EmailLbl.pack(side = 'left')
    self.Email.pack(side = 'left')

    self.PhoneLbl = unilabel(self.EmailRow, '%s: ' % lang.Phone)
    self.Phone = TextEntry(self.EmailRow, 
          self.customer.FormatPhone())
    self.Phone.pack(side = 'right')
    self.PhoneLbl.pack(side = 'right')

    self.ButtonRow = rowframe(Pane)

    self.SaveBtn = Button(self.ButtonRow)
    apply_config(self.SaveBtn)
    self.SaveBtn.config(text = lang.Save, command = self.OnSaveBtn)
    self.SaveBtn.pack(side = 'left')

    self.SearchBtn = Button(self.ButtonRow)
    apply_config(self.SearchBtn)
    self.SearchBtn.config(text = lang.Search, 
          command = self.OnSearchBtn)
    self.SearchBtn.pack(side = 'left', padx = 3)

    self.ResBtn = Button(self.ButtonRow)
    apply_config(self.ResBtn)
    self.ResBtn.config(text = lang.NewReservation, 
      command = self.OnResBtn)
    self.ResBtn.pack(side = 'left', padx = 3)

  def CreateSearchPane(self):
    self.SearchPane = colframe(self.CustBlock)
    self.CustPane.config(bd = '2', relief = 'groove')

    self.ShowSearchList([])

  def ShowSearchList(self, customers):
    self.customers = customers
    if self.SearchList:
      self.SearchList.destroy()
    self.SearchList = grid_listbox(self.SearchPane,
      [10, 10, 15],
      [lang.Name, lang.Surname, lang.Phone]
    )

    for customer in customers:
      self.SearchList.AddRow(customer.id,
          [customer.f_name, customer.l_name, 
            customer.FormatPhone()]
      )

    self.SearchList.OnSelect = self.OnSLSelect
    self.SearchList.OnDoubleClick = self.GoListEntry

  def CreateDispPane(self):
    self.DispPane = rowframe(self)
    self.DispPane.config(bd = '2', relief = 'groove')

    self.DispBlock = colframe(self.DispPane)
    self.DispBlock.pack_forget()
    self.DispBlock.pack(side = 'right')
    Block = self.DispBlock

    self.DispCol1 = colframe(Block)
    self.DispColspace = colframe(Block)
    self.DispColspace.config(width = 10)
    self.DispCol2 = colframe(Block)

    col1 = self.DispCol1
    col2 = self.DispCol2

    self.DispNameRow = rowframe(col1)
    self.DName = unilabel(self.DispNameRow, ' ')
    self.DName.pack(side = 'left')

    self.DispPhoneRow = rowframe(col1)
    self.DPhone = unilabel(self.DispPhoneRow, ' ')
    self.DPhone.pack(side = 'left')

    self.DispEmailRow = rowframe(col1)
    self.DEmail = unilabel(self.DispEmailRow, ' ')
    self.DEmail.pack(side = 'left')

    self.DispAddrRow = rowframe(col2)
    self.DAddress = unilabel(self.DispAddrRow, ' ')
    self.DAddress.pack(side = 'left')

    self.DispCSZRow = rowframe(col2)
    self.DCSZ = unilabel(self.DispCSZRow, ' ')
    self.DCSZ.pack(side = 'left')

    self.DispCountryRow = rowframe(col2)
    self.DCountry = unilabel(self.DispCountryRow, ' ')
    self.DCountry.pack(side = 'left')

  def OnSaveBtn(self):
    self.GenCustomer()
    self.customer.commit()
    self.TitleLbl.set(lang.RecordSaved)

  def OnSearchBtn(self):
    self.GenCustomer()
    customers = self.customer.search()
    self.ShowSearchList(customers)

  def OnResBtn(self):
    self.OnSaveBtn()
    if self.customer.id:
      today = DateTime.today()
      tomorrow = DateTime.DateTimeFromAbsDays(
          today.absdays + 1
      )
      res = openrms.reservation(None, None, self.customer.id,
        today, tomorrow)
      res.commit()
      appframe = reseditframe(self.master, res)
      self.master.ChangeApp(appframe)  

  def OnSLSelect(self, id):
    for cust in self.customers:
      if str(cust.id) == str(id):
        customer = cust

    self.DName.set('%s %s' % (customer.f_name, customer.l_name))
    self.DEmail.set(customer.email)
    self.DPhone.set(customer.FormatPhone())
    self.DAddress.set(customer.address)
    self.DCSZ.set('%s, %s %s' % (customer.city, customer.state, 
      customer.zip)
    )
    self.DCountry.set(customer.country)

  def GoListEntry(self, id):
    customer = self.customer.GetByID(id)
    appframe = custframe(self.master, customer)
    self.master.ChangeApp(appframe)

  def GenCustomer(self):
    customer = self.customer

    customer.f_name = self.Name.get()
    customer.l_name = self.Surname.get()
    customer.address = string.rstrip(self.Address.get('1.0', 'end'))
    customer.city = self.City.get()
    customer.state = self.State.get()
    customer.zip = self.Zip.get()
    customer.country = self.Country.get()
    customer.email = self.Email.get()
    phone = self.Phone.get()
    customer.SetPhone(self.Phone.get())

class checkinframe(appframe):
  def create_widgets(self):
    self.ResList = None
    self.LineList = None
    self.customers = {}
    self.reservations = {}

    self.CreateTitleRow()
    self.CreateCustRow()
    self.MainWindow = rowframe(self)
    self.CreateResPane()
    self.CreateRoomPane()

  def CreateTitleRow(self):
    self.TitleRow = rowframe(self)
    self.AppTitle = unilabel(self.TitleRow, lang.CheckInForm)
    self.AppTitle.pack(side = 'left')
    self.AppStatus = unilabel (self.TitleRow, ' ')
    self.AppStatus.pack(side = 'right')

  def CreateCustRow(self):
    self.CustRow = rowframe(self)
    self.CustRow.config(bd = 2, relief = 'groove')
    row = self.CustRow
    self.CustNameLbl = unilabel(row, '%s: ' % lang.Name)
    self.CustNameLbl.pack(side = 'left')
    self.CustName = TextEntry(row)
    self.CustName.pack(side = 'left')

    self.CustSurnLbl = unilabel(row, '  %s: ' % lang.Surname)
    self.CustSurnLbl.pack(side = 'left')
    self.CustSurname = TextEntry(row)
    self.CustSurname.pack(side = 'left')

    self.CustPhoneLbl = unilabel(row, '  %s: ' % lang.Phone)
    self.CustPhone = TextEntry(row)
    self.CustPhoneLbl.pack(side = 'left')
    self.CustPhone.pack(side = 'left')

    self.CustGoBtn = Button(row)
    apply_config(self.CustGoBtn)
    self.CustGoBtn.config(
      text = lang.Search, command = self.OnCustBtn
    )
    self.CustGoBtn.pack(side = 'left')

  def OnCustBtn(self):
    self.AppStatus.set(lang.Searching)
    cust = openrms.customer(
        '', self.CustName.get(), self.CustSurname.get(),
        '', '', '', '', '', self.CustPhone.get(), ''
    )
    customers = cust.search()
    reservations = []
    today = DateTime.today()
    if len(customers) == 0:
      self.AppStatus.set("%s!" % lang.NoCustomersFound)
      self.bell()
      return 0

    for customer in customers:
      self.customers[customer.id] = customer
      temp_res = openrms._reservation.GetByCustomerID(
        customer.id
      )
      for res in temp_res:
        if (res.date_in.absdate ==
            today.absdate):
          reservations.append(res)
          self.reservations[str(res.conf)] = res
    self.UpdateResPane(reservations)
    self.AppStatus.set(' ')

  def CreateResPane(self):
    self.ResPane = colframe(self.MainWindow)
    self.ResPane.config(bd = 2, relief = 'groove')
    pane = self.ResPane

    self.ResListRow = rowframe(pane)
    self.ShowResList()
    self.LineListRow = rowframe(pane)
    self.ShowLineList()

    self.ButtonRow = rowframe(pane)
    self.ResEditBtn = Button(self.ButtonRow)
    apply_config(self.ResEditBtn)
    self.ResEditBtn.config(
      text = lang.Edit, command = self.OnResEditBtn
    )
    self.ResEditBtn.pack(side = 'left')

    self.AutoBkBtn = Button(self.ButtonRow)
    apply_config(self.AutoBkBtn)
    self.AutoBkBtn.config(
      text = lang.Auto, command = self.OnAutoBkBtn
    )
    self.AutoBkBtn.pack(side = 'left', padx = 3)

    self.MaxBk = unilabel(self.ButtonRow, '0')
    self.MaxBk.pack(side = 'right')
    self.BkOfLbl = unilabel(self.ButtonRow, ' %s ' % lang.Of)
    self.BkOfLbl.pack(side = 'right')
    self.Bkd = unilabel(self.ButtonRow, '0')
    self.Bkd.pack(side = 'right')
    self.BkdLbl = unilabel(self.ButtonRow, '%s: ' % lang.Booked)
    self.BkdLbl.pack(side = 'right')

  def UpdateResPane(self, reservations):
    self.ShowResList(reservations)
    self.ShowLineList()

  def ShowResList(self, reservations = None):
    if self.ResList:
      self.ResList.destroy()

    self.ResList = grid_listbox(self.ResListRow,
      [12, 15, 15, 15],
      [lang.DateOut, lang.Name, lang.Surname, lang.Phone]
    )
    self.ResList.Listbox.config(height = 4)
    if reservations:
      for res in reservations:
        cust = self.customers[res.customer]
        self.ResList.AddRow(
          res.conf,
          [format_date(res.date_out), cust.f_name,
            cust.l_name,
            cust.FormatPhone()]
        )
    self.ResList.OnSelect = self.OnResListSelect
    self.ResList.pack(side = 'left')

  def OnResListSelect(self, id):
    res = self.reservations[id]
    self.res_id = id
    if bool(res.reslines) == False:
      res.GetReslines()
    self.ShowLineList(res.reslines)

  def ShowLineList(self, reslines = None):
    if self.LineList:
      self.LineList.destroy()
    self.LineList = grid_listbox(self.LineListRow,
      [7, 11, 15, 12, 12],
      [lang.Class, lang.Quantity, lang.Price, lang.Upgrade, 
        lang.Downgrade]
    )
    self.LineList.OnSelect = self.OnLineListSelect
    self.LineList.Listbox.config(height = 4)
    if reslines:
      for resline in reslines:
        self.LineList.AddRow(resline.id, 
          [resline.class_id, resline.quantity, 
            resline.GetTotalPrice(),
            dbbool2yn(resline.will_upgrade),
            dbbool2yn(
              resline.will_downgrade
            )
          ]
        )
    self.LineList.pack(side = 'left')

  def OnLineListSelect(self, id):
    self.sel_line = id
    res = self.reservations[self.res_id]
    for resline in res.reslines:
      if str(resline.id) == str(id):
        line = resline
    avail = openrms._room_assign.GetAvailByClassID(line.class_id)
    self.resline = line 
    booked = openrms._room_assign.GetByResline(line.id)
    self.UpdateRoomPane(avail, booked)
    self.UpdateBkLbl()

  def OnAutoBkBtn(self):
    if hasattr(self, 'res_id'):
      self.reservations[self.res_id].autobook()
    else:
      return 0

  def OnResEditBtn(self):
    appframe = reseditframe(self.reservations[self.res_id])
    self.master.ChangeApp(appframe)

  def CreateRoomPane(self):
    self.RoomPane = colframe(self.MainWindow)
    self.RoomPane.config(bd = 2, relief = 'groove')
    pane = self.RoomPane
    self.AvailListRow = rowframe(pane)
    self.ShowAvailList()

    self.BookListRow = rowframe(pane)
    self.ShowBookList()

    self.RoomBtnRow = rowframe(pane)
    self.CClassBtn = Button(self.RoomBtnRow)
    apply_config(self.CClassBtn)
    self.CClassBtn.config(
      text = lang.ChangeClass, command = self.OnCClassBtn
    )
    self.CClassBtn.pack(side = 'left')

  def UpdateRoomPane(self, avail, booked):
    self.ShowAvailList(avail)
    self.ShowBookList(booked)

  def ShowAvailList(self, avail = []):
    self.avail = avail
    if hasattr(self, 'AvailList'):
      self.AvailList.destroy()
    self.AvailList = grid_listbox(
      self.AvailListRow,
      [22],
      [lang.AvailRoom]
    )
    self.AvailList.OnDoubleClick = self.OnAvailDClick
    self.AvailList.Listbox.config(height = 4)
    if avail:
      for room in avail:
        self.AvailList.AddRow(room, [room])
    self.AvailList.pack(side = 'left')

  def OnAvailDClick(self, id):
    if len(self.book) >= self.resline.quantity:
      self.AppStatus.set(lang.ItemFullyBooked)
      self.bell()
      return 0
    booking = openrms.room_assign(None, self.sel_line, id)
    booking.commit()
    self.BookList.AddRow(id, [id])
    self.avail.remove(id)
    self.ShowAvailList(self.avail)
    self.book.append(booking)
    self.UpdateBkLbl()

  def ShowBookList(self, book = []):
    self.book = book
    if hasattr(self, 'BookList'):
      self.BookList.destroy()
    self.BookList = grid_listbox(
      self.BookListRow,
      [22],
      [lang.BookedRoom]
    )
    self.BookList.OnDoubleClick = self.OnBookListDClick
    self.BookList.Listbox.config(height = 4)
    for assign in book:
      self.BookList.AddRow(assign.room, [assign.room])
    self.BookList.pack(side = 'left')

  def OnBookListDClick(self, id):
    for assign in self.book:
      if assign.room == id:
        self.book.remove(assign)
        self.avail.append(assign.room)
        assign.remove()
    self.ShowAvailList(self.avail)
    self.ShowBookList(self.book)
    self.UpdateBkLbl()

  def UpdateBkLbl(self):
    self.MaxBk.set(self.resline.quantity)
    self.Bkd.set(len(self.book))

  def OnCClassBtn(self):
    self.MainWindow.pack_forget()
    self.ChangeClassFrame = classearchframe(self)

  def ChangeClass(self, class_id):
    self.MainWindow.pack()
    avail = openrms._room_assign.GetAvailByClassID(class_id)
    self.ShowAvailList(avail)

app_dict = {
  lang.Reservations: resframe, 
  lang.Customers: custframe,
  lang.CheckIn: checkinframe,
  lang.Configuration: configframe
}

defaultframe = resframe
openrms.SetConnection(DBAL.connect(config.dsn, config.user, config.password))
app = main_window(app_dict, defaultframe)
app.mainloop()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.