Пример #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)
Пример #2
0
def enumerate_invoices(data):
    mans = data['ManualInvoices']

    job_codes = data['auto_invoices'].keys()
    job_codes.sort()
    autos = []
    for job in job_codes:
        inv = data['auto_invoices'][job]
        inv['JobCode'] = job
        inv['client'] = ''
        inv['irn'] = ''
        inv['desc'] = ''
        autos.append(inv)
    autos = filter(lambda x: x['net'] <> 0.0,  autos)

    the_invoices = mans + autos
    
    # augment vat rates
    jobs = data['jobs']
    for inv in the_invoices:
        job = jobs[inv['JobCode']]
        vatable = job['vatable']
        inv['vat_rate'] = tri(vatable, VAT, 0.0)
    
    net = common.summate(the_invoices, lambda x: x['net'])
    return the_invoices
Пример #3
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"