def create_insertion(jcode): d = ordereddict.OrderedDict(map(lambda x: [x, 0.0], get_keys())) d['InvDate'] = datetime.date.today().strftime('%d/%m/%Y') d['InvBillingPeriod'] = period.mmmmyyyy() d['InvJobCode'] = str(jcode) d['InvComments'] = "PMS " + common.get_timestamp() return d
def zap_entries(): 'Remove all recorded invoices for the period PER' fmt = "DELETE FROM tblInvoice WHERE InvBillingPeriod='{0}'" #print "zap_entries" sql = fmt.format(period.mmmmyyyy()) #print sql db.ExecuteSql(sql)
def GetInvoices(): sql = "SELECT * FROM tblInvoice WHERE InvBillingPeriod='" + period.mmmmyyyy() + "'" fields = 'InvDate,InvBillingPeriod,InvBIA,InvUBI,InvWIP,InvAccrual,InvInvoice,' fields += 'Inv3rdParty,InvTime,InvJobCode,InvComments,InvPODatabaseCosts,' fields += 'InvCapital,InvStock' recs = fetch_and_dictify(sql, fields) return recs
def create_job_statement(job, all_tasks, exps, times): title = "Work Statement: {0}".format(period.mmmmyyyy()) out = rtf.Rtf() out.addTitle(title) AddTopInfo(out, job) tasks = map(lambda o: getattr(o, "task"), times + exps) tasks = common.unique(tasks) tasks.sort() if tasks[0] == "" and len(tasks) > 1: tasks = tasks[1:] + [tasks[0]] # rotate unassigned to end # distribute invoice items into sections job_code = job["job"] sections = [] # a list of Section classes totalWork = 0.0 totalExpenses = 0.0 for task_key in tasks: # work out heading if len(task_key) == 0: heading = "Expenses not categorised to a specific task" else: desc = all_tasks[(job_code, task_key)]["TaskDes"] heading = "Task {0}: {1}".format(task_key, desc) out.add(heading) amount_work, num_times = ProcessSubsection(out, times, task_key, "Work subtotal") totalWork += amount_work amount_expenses, num_expenses = ProcessSubsection(out, exps, task_key, "Expenses subtotal") totalExpenses += amount_expenses if num_times > 0 and num_expenses > 0: subtotal(out, "Task subtotal", amount_work + amount_expenses) out.para() # output grand summary out.add("Overall summary") subtotal(out, "Work total", totalWork) subtotal(out, "Expenses total", totalExpenses) net = totalWork + totalExpenses subtotal(out, "Net total", net) out.annotation(job) outdir = period.perioddir() + "\\statements" outfile = job_code + ".rtf" out.save(outdir, outfile) # remember what we have produced for the invoice summaries if job["Weird"] or job["WIP"]: billed = 0.0 else: billed = net invoice = {"work": totalWork, "expenses": totalExpenses, "net": billed} return invoice
def setup_insertions(tasks): invBillingPeriod = period.mmmmyyyy() #recs = db.GetTasks() activeJobs = set([key[0] for key in tasks.keys()]) ignoreJobs = set(['010500', '010400', '010300', '010200', '3. Sundry', '404550']) jobsToCreate = activeJobs - ignoreJobs insertions = {} for jcode in jobsToCreate: insertions[jcode] = create_insertion(jcode) return insertions
def GetTimeitems(): tbl_billing = GetTblBilling() sql = 'SELECT * FROM tblTimeItems WHERE TimeVal<>0 AND LEN(JobCode) > 0 ORDER BY JobCode, Task, Person, DateVal' fields = 'DateVal,JobCode,Person,Task,TimeVal,WorkDone' recs = fetch_and_dictify(sql, fields) # filter by period #global tbl_billing per = common.find(period.mmmmyyyy(), tbl_billing, key = lambda x: x[0]) start = per[1] end = per[2] def within(x): return x['DateVal'] >= start and x['DateVal'] <= end recs = filter(within, recs) return recs
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)