Beispiel #1
0
def create_health_report(d):
    #db.save_state(d)
    global debug
    stats = {}
    
    total_all_hours = 0.0
    total_staff_hours = 0.0
    total_leave_and_sickness = 0.0
    time_items = d['timeItems']
    las_test = lambda(x): employee['IsStaff'] and (x['JobCode'] == '010400' or x['JobCode'] == '010500')
    #fmt = '{0:4} {1:15} {2:>10} {3:>10} {4:>10}'
    
    output = []
    def add_line(text):
        output.append(text)
    def add_formatted_line(*fields):
        text = []
        for fmt, value in zip('{0:4} {0:15} {0:>10} {0:>10} {0:>10}'.split(' '), fields):
            #pdb.set_trace()
            #print fmt, "---", value
            text.append(fmt.format(value))            
        text = ' '.join(text)
        add_line(text)
    #dir = period.reportdir(d['period'])
    #filename = dir +'\\health.txt' 
    #output = file(filename, "w")

    add_formatted_line('INI', 'NAME', 'LEAV/SICK', 'STAFF', 'ALL')
    for employee_initials, worker_times in common.aggregate(time_items, common.mkKeyFunc('Person')):
        try: employee = d['employees'][employee_initials]
        except KeyError: continue
    
        full_name = employee['PersonNAME']
        time_val = mkKeyFunc('TimeVal')

        #if debug and employee_initials == "AM": pdb.set_trace()
        staff_hours = summate(worker_times, time_val, lambda(x): employee['IsStaff'])
        total_staff_hours += staff_hours
                
        leave_and_sickness = summate(worker_times, time_val, las_test)
        total_leave_and_sickness += leave_and_sickness
        
        all_hours = summate(worker_times, time_val)
        total_all_hours += all_hours
        
        add_formatted_line(employee_initials, full_name, leave_and_sickness, staff_hours, all_hours)

    add_formatted_line('', 'TOTALS' , total_leave_and_sickness, total_staff_hours, total_all_hours)

    add_line('\nHealth & Safety Stats:')
    add_line('Staff hours less leave & sickness: {0} - * this goes into cell I8'.format(total_staff_hours - total_leave_and_sickness))
    add_line('Total all hours: {0}'.format(total_all_hours))

    #output.close()
    
    period.save_report('health.txt', output)
Beispiel #2
0
def create_statements(data):

    # TODO - print a warning if exp_factor > 1.05
    work_codes = set([common.AsAscii(t["JobCode"]) for t in data["timeItems"]])
    the_expenses = data["Expenses"]
    expense_codes = set([e["JobCode"] for e in the_expenses])
    job_codes = list(work_codes.union(expense_codes))
    job_codes.sort()
    if data["auto_invoices"] is None:
        data["auto_invoices"] = {}

    for job_code in job_codes:
        if job_code[0:2] == "01":
            continue
        job = data["jobs"][job_code]

        exps = []
        for exp in the_expenses:
            if exp["JobCode"] <> job_code:
                continue
            item = LineItem()
            item.task = exp["Task"]
            item.desc = "{0} - {1} - {2}".format(exp["Period"], exp["Name"], exp["Desc"])
            item.qty = job["exp_factor"]
            item.price = exp["Amount"]
            exps.append(item)

        times = []
        times1 = filter(lambda x: x["JobCode"] == job_code, data["timeItems"])
        times2 = common.summate_to_dict(times1, lambda x: (x["Task"], x["Person"]), common.mkKeyFunc("TimeVal"))
        keys = times2.keys()
        keys = sorted(keys, key=lambda x: x[0] + " " + x[1])
        for k in keys:
            item = LineItem()
            item.task = k[0]
            initials = k[1]
            item.desc = db.initials_to_name(data, initials)
            item.qty = times2[k]
            item.price = price = data["charges"][(job_code, item.task, initials)]
            times.append(item)

        if len(exps) + len(times) > 0:
            invoice = create_job_statement(job, data["tasks"], exps, times)
            data["auto_invoices"][job_code] = invoice
Beispiel #3
0
def create_timesheets(d):
    title = 'Timesheet: ' + period.mmmmyyyy()
    outdir = period.perioddir() + '\\timesheets'
    for jobKey, job_items in aggregate(d['timeItems'], common.mkKeyFunc('JobCode')):
        #pdb.set_trace()
        CreateJobsheet(jobKey, job_items, d, title, outdir)
Beispiel #4
0
import pdb
import pickle
import pprint

import common
import db

def pic():
    data = db.fetch()
    db.save_state(data)

#pic()

#data = db.load_state()
#pic()
data = db.fetch()    
pp = pprint.PrettyPrinter(indent=4)
for e in sorted(data['employees']):
    print e
    times = filter(lambda x: x['Person'] == e, data['timeItems'])
    aggregates = common.aggregate(times, lambda x: (x['JobCode'], x['Task']))
    for key, vals in aggregates:
        total_times = common.summate(vals, common.mkKeyFunc('TimeVal'))
        print key, " ", total_times
    #pdb.set_trace()
    #pp.pprint(aggregates)
    print
#print data['timeItems']

print "Finished"