def get(req, lag_days): info_by_server = queries.nightly_sales_by_server(label=True, lag_days=lag_days) #server_info = {} #for row in info_by_server: # server_info[row['server'].lower()] = server_inf(**row) return json.dumps(info_by_server)
def index(req, lag=0): results = queries.nightly_sales_by_server(lag_days=lag) seven_day_total = utils.select(''' SELECT sum(total) night, sum(dtotal) lunch FROM nd_tots WHERE dat > now() - INTERVAL '7' DAY''', incursor=None, label=False ) avg = utils.select(''' SELECT sum(total)/2 night, sum(dtotal)/2 lunch FROM nd_tots WHERE dat > now() - INTERVAL '14' DAY;''', incursor=None, label=False ) day_totals = utils.select('''select * from nd_tots order by dat desc''', incursor=None, label=False) grand_total = utils.select(''' SELECT total, dtotal FROM nd_tots WHERE dat = date(now());''', incursor=None, label=False ) html = ( ''' <html> <body> ''' + utils.tohtml( 'Nightly Receipts by Server', ('Server', 'posid', 'ccid', 'Receipts', 'Reciepts', 'Taxable', 'Tabs Closed', 'Date'), results ) + utils.tohtml( "Nightly Total", ('Dinner','Lunch'), grand_total ) + utils.tohtml( "7 day Total", ('Dinner','Lunch'), seven_day_total ) + utils.tohtml( "2 week average", ('Dinner','Lunch'), avg ) + utils.tohtml( "Day Totals", ('Dinner', 'Day', 'Date','Lunch'), day_totals ) + '''</body></html>''' ) return html
import queries import texttab import sys take_name, take_cash, take_credit, take_credit_tips, exit = xrange(5) state = take_name lag_days = (len(sys.argv) > 1 and sys.argv[1]) or 1 info_by_server = queries.nightly_sales_by_server(label=True, lag_days=lag_days) current_server_info = None server_info = {} class server_inf(object): def __init__(self, server, ccid, sales, taxable_sales, **kv): taxable_sales = taxable_sales or 0 self.server = server self.presales = taxable_sales self.sales = sales + taxable_sales * texttab.TAXRATE self.credit = 0 self.credit_tips = 0 self.cash = None self.ccid = str(ccid) def cash_tips(self): if self.credit is not None and self.cash is not None: return self.credit + self.cash - self.sales def all_tips(self):