Example #1
0
def load_db_config(cfg):
  
  supercats = utils.select('''select distinct supercategory as name from sku 
    where bin is not null and bin != '0' and active=True and supercategory is not null
    order by id''')
  for supercat in supercats:
    cfg['menu']['categories'].append(supercat)
    supercat['subcategories'] = []
    for cat in utils.select('''select distinct category as name from sku where supercategory = %s 
      and bin is not null and bin != '0' and active = True and category is not null order by bin''', 
        args = (supercat['name'])):
      supercat['subcategories'].append(cat)
      cat['items'] = []
      for item in utils.select('''select * from sku where supercategory = %s and category = %s
      and bin is not null and bin != '0' and active=True
      order by bin, name''', args = (supercat['name'], cat['name'])):
        cat['items'].append(item)
        if winecats.match(cat['name']):
          item['name'] = item['bin'] + ' ' + item['name']
          my_logger.info('name: modified ' + item['name'])
          if item['qtprice'] > 0: 
            my_logger.info('qt: added ' + item['name'])
            qtitem = item.copy()
            qtitem['fraction'] = .25
            qtitem['retail_price'] = item['qtprice']
            qtitem['name'] = 'qt: '+item['name']
            cat['items'].append(qtitem)
Example #2
0
def index(req, table, shouldPrint, serverpin, close=True):
  my_logger.info(req.get_remote_host()+': server %s closed tab %s'%(serverpin, table))

  cursor = utils.get_cursor()

  shouldPrint = (shouldPrint == 'true')

  receipt_text, gift_certs = texttab.get_tab_text(table, serverpin, cursor)

  if close:
    cursor.execute('''
      UPDATE order_group
      SET is_open = FALSE, closedby = %(serverpin)s, updated = now()
      WHERE is_open = TRUE
      AND table_id = "%(table)s"
    ''' % locals())

  cursor.close()

  if shouldPrint:
    recfile = tempfile.NamedTemporaryFile(delete=False)
    recfile.write(receipt_text.encode('latin1', 'replace'))
    filename = recfile.name
    recfile.close()

    subprocess.call(['enscript', '--font=Courier-Bold@11/16', '-B', '-MEnv10', filename])
    os.remove(filename)

  for cert in gift_certs:
    cert.print_out()

  return json.dumps(None)
Example #3
0
def index(req, table, shouldPrint, serverpin, close=True):
  my_logger.info(req.get_remote_host()+': server %s closed tab %s'%(serverpin, table))

  cursor = utils.get_cursor()

  shouldPrint = (shouldPrint == 'true')

  receipt_text, gift_certs = texttab.get_tab_text(table, serverpin, cursor)

  if close:
    cursor.execute('''
      UPDATE order_group
      SET is_open = FALSE, closedby = %s, updated = now()
      WHERE is_open = TRUE
      AND table_id = %s
    ''', args=[serverpin, table])

  cursor.close()

  if shouldPrint:
    utils.print_slip(receipt_text)

  for cert in gift_certs:
    if shouldPrint or cert.is_gift():
      cert.print_out()

  return json.dumps(None)
Example #4
0
def delivered(req, item_id):
    my_logger.info(req.get_remote_host() + ': delivered on ' + str(item_id))

    utils.execute('''
      UPDATE order_item oi
      set oi.is_delivered = NOT oi.is_delivered, oi.is_held = FALSE, oi.updated = NOW()
      where oi.id = %(item_id)s
    ''' % locals())

    return json.dumps(None);
Example #5
0
def comped(req, item_id):
    my_logger.info(req.get_remote_host() + ': comped on ' + str(item_id))

    utils.execute('''
      UPDATE order_item oi
      set oi.is_comped = NOT oi.is_comped
      where oi.id = %(item_id)s
    ''' % locals())
    
    return json.dumps(None);
Example #6
0
def synchronize(req, crud_commands):
    my_logger.info(req.get_remote_host()+': '+crud_commands)

    crud_commands = json.loads(crud_commands)
    for command in crud_commands:
      if command['command'] == 'add_item':
        add_item(**command)
      if command['command'] == 'cancel_item':
        cancel_item(**command)
      if command['command'] == 'set_status':
        set_status(**command)

    return json.dumps(queries.get_active_items(), encoding='latin-1')
Example #7
0
def get_session_id(req):
    #client will use this to create unique ids for order_item commands it sends to server for DB insertion

    my_logger.info(req.get_remote_host()+': get_session_id called')
    cursor = utils.get_cursor()

    cursor.execute("insert into client_session values (null, null);");
    session_id = cursor.connection.insert_id()
    my_logger.info(req.get_remote_host()+': generated session id: %s'%session_id)

    cursor.close()

    return json.dumps(session_id)
Example #8
0
def execute(sql, incursor=None, args= None):
  
  my_logger.info(sql + repr(args))

  if not incursor:
    conn = MySQLdb.connect (host = "localhost",
                          user = "******",
                          passwd = "pos",
                          db = "pos",
                          charset = "utf8")

    cursor = conn.cursor()
  else:
    cursor = incursor

  cursor.execute(sql, args)

  if not incursor:
    cursor.close()
    conn.close()
Example #9
0
def go(query):
    my_logger.info('inventory')
    queryfunction = getattr(inventory, 'get_'+query)
    winelist = queryfunction(None)
    winelist = json.loads(winelist) #convert from json format to python native
    # winelist = utils.select('''
    #  select category, bin as binnum, name, round(estimated_units_remaining,2) est_count 
    #  from sku_inv where bin !=0 and category != 'House Cocktails' order by category, bin;
    #'''
    #, label=True)

    inventory_text = '';
    catname = None;
    for rec in winelist:
      # check if we are in a new category
      if catname != rec['category']:
          # if we just finished a previous category, insert a
          # page-break
        if catname is not None:
          inventory_text += ''
Example #10
0
def cellar_list(req = None):
    my_logger.info('cellar list')
    cellarlist = utils.select('''
      select bin as binnum, name, round(estimated_units_remaining) est_count, byline, listprice
      from winelist_inv where bin !=0 and cellar_listorder != 0 and cellar_listorder is not null
      order by cellar_listorder;
    '''
    , label=True)

    outfile = tempfile.NamedTemporaryFile(delete=False)
    filename = outfile.name
    for rec in cellarlist:
      outfile.write(
        rec['name'][:TEXTWIDTH].encode('latin1', 'replace') + '\n' + 
        'bin '+str(rec['binnum']) + ', ' +
        str(int(rec['est_count'])) + ' bottles' + ',  $' + str(rec['listprice']) + '\n\n'
      )

    outfile.close()
    subprocess.call(['enscript', '--font=Courier-Bold@11/16', '-B', '-MReceiptRoll', filename])
    #subprocess.call(['cat', filename])
    os.remove(filename)
    return  json.dumps(None)