class bk3010(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.mainProcess() if "wait" in self.opts: self.df.mstFrame.wait_window() else: self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["bkmmst", "bkmcon", "bkmtrn"], prog=self.__class__.__name__) if self.sql.error: return mc = GetCtl(self.opts["mf"]) bkmctl = mc.getCtl("bkmctl", self.opts["conum"]) if not bkmctl: return self.fromad = bkmctl["cbk_emadd"] t = time.localtime() self.sysdtw = ((t[0] * 10000) + (t[1] * 100) + t[2]) return True def mainProcess(self): tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]), "Deposits Due") r1s = (("No","N"), ("Yes","Y")) r2s = (("Arrival","A"), ("Due","D")) fld = ( (("T",0,0,0),("IRB",r1s),0,"Expired Only","", "N","Y",self.doExpired,None,None,None), (("T",0,1,0),("IRB",r2s),0,"Order","", "A","Y",self.doOrder,None,None,None)) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) if "args" in self.opts: tops = self.opts["args"] else: tops = False self.df = TartanDialog(self.opts["mf"], tops=tops, title=tit, eflds=fld, tend=tnd, txit=txt, view=("Y","V"), mail=("Y","N")) def doExpired(self, frt, pag, r, c, p, i, w): self.expired = w def doOrder(self, frt, pag, r, c, p, i, w): self.order = w def doEnd(self): self.df.closeProcess() tab = ["bkmmst"] col = [ "bkm_number", "bkm_group", "bkm_ccode", "bkm_arrive", "bkm_depart", "bkm_stddep", "bkm_stddte", "bkm_grpdep", "bkm_grpdte", "bkm_state"] whr = [ ("bkm_cono", "=", self.opts["conum"]), ("bkm_state", "in", ("C", "Q"))] if self.order == "A": odr = "bkm_arrive, bkm_ccode" else: odr = "bkm_stddte, bkm_grpdte, bkm_ccode" recs = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr) self.fpdf = MyFpdf(name=self.__class__.__name__, head=80, auto=True) self.fpdf.header = self.pageHeading self.fpdf.add_page() newrec = [] for rec in recs: if not rec[5] and not rec[7]: continue num = CCD(rec[0], "UI", 6) trn = self.sql.getRec("bkmtrn", where=[("bkt_cono", "=", self.opts["conum"]), ("bkt_number", "=", num.work)]) inv = False bal = 0.0 for tr in trn: typ = tr[self.sql.bkmtrn_col.index("bkt_type")] amt = tr[self.sql.bkmtrn_col.index("bkt_tramt")] bal = float(ASD(bal) + ASD(amt)) if typ == 2: inv = True if inv: continue dp1 = float(ASD(rec[5]) + ASD(bal)) dt1 = rec[6] if dp1 > 0: dp2 = rec[7] dt2 = rec[8] elif rec[7]: dp2 = float(ASD(rec[7]) + ASD(dp1)) dt2 = rec[8] dp1 = 0 else: dp1 = 0 dp2 = 0 dt2 = 0 if self.expired == "Y": if dp1 and dt1 > self.sysdtw: continue if not dp1 and dp2 and dt2 > self.sysdtw: continue elif dp1 <= 0 and dp2 <= 0: continue if dp1 and dp1 > 0: b = CCD(dt1, "D1", 10).disp if dp2: b = "%s\n%s" % (b, CCD(dt2, "D1", 10).disp) elif dp2 and dp2 > 0: b = CCD(dt2, "D1", 10).disp else: continue con = self.sql.getRec("bkmcon", where=[("bkc_cono", "=", self.opts["conum"]), ("bkc_ccode", "=", rec[2])], limit=1) snam = con[self.sql.bkmcon_col.index("bkc_sname")] fnam = con[self.sql.bkmcon_col.index("bkc_names")] if fnam: c = "%s %s" % (fnam.split()[0], snam) else: c = snam l = 8 if rec[1]: c = "%s\n%s" % (c, rec[1]) l = 16 d = CCD(rec[3], "D1", 10).disp e = CCD(rec[4], "D1", 10).disp if dp1: f = CCD(dp1, "UD", 10.2).disp if dp2: f = "%s\n%s" % (f, CCD(dp2, "UD", 10.2).disp) l = 16 else: f = CCD(dp2, "UD", 10.2).disp newrec.append([num.disp, b, c, d, e, f]) if newrec: if self.order == "D": newrec = sorted(newrec, key=itemgetter(1)) for rec in newrec: if self.fpdf.get_y() + l > 260: self.fpdf.add_page() self.printLine(rec[0], rec[1], rec[2], rec[3], rec[4], rec[5]) if self.fpdf.page: pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], header=self.head, pdfnam=pdfnam, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) if "wait" not in self.opts: self.opts["mf"].closeLoop() def pageHeading(self): cd1 = "%-30s" % self.opts["conam"] self.fpdf.drawText(cd1, x=7, font=["courier", "B", 24]) self.fpdf.drawText(font=["courier", "B", 14]) if self.expired == "N": cd2 = "Deposits Due Report" else: cd2 = "Deposits Expired Report" self.head = "%s - %s" % (cd1, cd2) self.fpdf.drawText(cd2, x=7, font=["courier", "B", 16]) self.fpdf.drawText(font=["courier", "B", 14]) self.printLine("Number", " Due-Date ", "%-20s" % "Name & Group", " Arrive ", " Depart ", " Amount", fill=1) def printLine(self, a, b, c, d, e, f, fill=0): ft = ["courier", "B", 13] self.fpdf.set_font(ft[0], ft[1], ft[2]) c, cq = self.getLines(c, self.fpdf.get_string_width("X"*21)) f, fq = self.getLines(f, self.fpdf.get_string_width("X"*11)) if cq > fq: ch = 8 h = cq * 8 fh = int(h / fq) elif fq > cq: fh = 8 h = fq * 8 ch = int(h / cq) else: h = cq * 8 ch = fh = 8 if cq > 1 or fq > 1: ctyp = "M" else: ctyp = "S" # Booking number x = 7 y = self.fpdf.get_y() w = self.fpdf.get_string_width("X"*7) self.fpdf.drawText(a, x=x, y=y, w=w, h=h, border="TLB", fill=fill, ctyp=ctyp, font=ft) # Name and group x += w w = self.fpdf.get_string_width("X"*21) self.fpdf.drawText(c, x=x, y=y, w=w, h=ch, border="TLB", fill=fill, ctyp=ctyp, font=ft) # Arrival date x += w w = self.fpdf.get_string_width("X"*11) self.fpdf.drawText(d, x=x, y=y, w=w, h=h, border="TLB", fill=fill, ctyp=ctyp, font=ft) # Departure date x += w w = self.fpdf.get_string_width("X"*11) self.fpdf.drawText(e, x=x, y=y, w=w, h=h, border="TLB", fill=fill, ctyp=ctyp, font=ft) # Deposit due date x += w w = self.fpdf.get_string_width("X"*11) self.fpdf.drawText(b, x=x, y=y, w=0, h=fh, border="TLB", fill=fill, ctyp=ctyp, font=ft) # Deposit amount x += w w = self.fpdf.get_string_width("X"*11) self.fpdf.drawText(f, x=x, y=y, w=w, h=fh, border="TLRB", fill=fill, ctyp=ctyp, font=ft) def getLines(self, t, w): tmp = t.split("\n") nam = self.fpdf.multi_cell(w, 8, tmp[0], split_only=True) t = nam[0] q = 1 for n in nam[1:]: t = "%s\n%s" % (t, n) q += 1 if len(tmp) > 1: nam = self.fpdf.multi_cell(w, 8, tmp[1], split_only=True) for n in nam: t = "%s\n%s" % (t, n) q += 1 return t, q def doExit(self): self.df.closeProcess() if "wait" not in self.opts: self.opts["mf"].closeLoop()
class bk3030(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.mainProcess() if "wait" in self.opts: self.df.mstFrame.wait_window() else: self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, tables=["bkmmst", "bkmcon", "bkmrtt", "bkmtrn", "bkmunm", "ctlmst", "ctlvtf", "gentrn", "tplmst"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) ctl = gc.getCtl("ctlmst", self.opts["conum"]) if not ctl: return for col in ( "ctm_name", "ctm_add1", "ctm_add2", "ctm_add3", "ctm_pcode", "ctm_regno", "ctm_taxno", "ctm_taxdf", "ctm_tel", "ctm_fax", "ctm_b_name", "ctm_b_ibt", "ctm_b_acno", "ctm_logo"): setattr(self, col, ctl[col]) if self.ctm_logo and "LETTERHEAD" in os.environ: self.ctm_logo = os.environ["LETTERHEAD"] if not self.ctm_logo or not os.path.exists(self.ctm_logo): self.ctm_logo = None bkmctl = gc.getCtl("bkmctl", self.opts["conum"]) if not bkmctl: return self.glint = bkmctl["cbk_glint"] self.tplnam = bkmctl["cbk_invtpl"] self.fromad = bkmctl["cbk_emadd"] if self.glint == "Y": ctlctl = gc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return ctls = ["vat_ctl", "bkm_ctl"] if gc.chkRec(self.opts["conum"], ctlctl, ctls): return self.vatctl = ctlctl["vat_ctl"] self.bkmctl = ctlctl["bkm_ctl"] t = time.localtime() self.sysdtw = ((t[0] * 10000) + (t[1] * 100) + t[2]) return True def mainProcess(self): self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]), "Booking Arrivals Listing (%s)" % self.__class__.__name__) tpm = { "stype": "R", "tables": ("tplmst",), "cols": ( ("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0, "Title", "Y")), "where": [ ("tpm_type", "=", "I"), ("tpm_system", "=", "BKM")], "order": "tpm_tname"} r1s = (("Weekdays","D"), ("Weekend","E"), ("Range", "R")) r2s = (("Yes","Y"), ("No","N")) fld = ( (("T",0,0,0),("IRB",r1s),0,"Period","", "D","Y",self.doPeriod,None,None,None), (("T",0,1,0),"ID1",10,"Starting Date","", 0,"N",self.doStartDate,None,None,("efld",)), (("T",0,2,0),"ID1",10,"Ending Date","", 0,"N",self.doEndDate,None,None,("efld",)), (("T",0,3,0),("IRB",r2s),0,"Include Queries","", "N","Y",self.doQuery,None,None,None), (("T",0,4,0),("IRB",r2s),0,"Housekeeping Report","", "Y","Y",self.doHkRpt,None,None,None), (("T",0,5,0),("IRB",r2s),0,"Generate Invoices","", "Y","Y",self.doGenInv,None,None,None), (("T",0,6,0),("IRB",r2s),0,"Print Invoices","", "Y","Y",self.doPrtInv,None,None,None), (("T",0,7,0),"INA",20,"Template Name","", self.tplnam,"N",self.doTplNam,tpm,None,None)) tnd = ((self.doEnd,"y"), ) txt = (self.doExit, ) if "args" in self.opts: tops = self.opts["args"] else: tops = False self.df = TartanDialog(self.opts["mf"], tops=tops, title=self.tit, eflds=fld, tend=tnd, txit=txt, view=("N","P"), mail=("Y","N")) def doPeriod(self, frt, pag, r, c, p, i, w): self.period = w if self.period in ("D", "E"): self.start = self.getStart() self.df.loadEntry(frt, pag, p+1, data=self.start) def doStartDate(self, frt, pag, r, c, p, i, w): self.start = w if self.period in ("D", "E"): if self.getStart(self.start): return "Invalid Start Date" if self.period == "D": self.end = projectDate(self.start, 3) else: self.end = projectDate(self.start, 2) self.df.loadEntry(frt, pag, p+1, data=self.end) return "sk1" def getStart(self, date=None): if self.period == "D": chk = 0 else: chk = 4 if date: year = int(date / 10000) month = int(date / 100) % 100 day = date % 100 if datetime.date(year, month, day).weekday() != chk: return True else: date = projectDate(self.sysdtw, -1) dte = 99 while dte != chk: date = projectDate(date, 1) year = int(date / 10000) month = int(date / 100) % 100 day = date % 100 dte = datetime.date(year, month, day).weekday() return date def doEndDate(self, frt, pag, r, c, p, i, w): if w < self.start: return "Invalid End Date, Before Start Date" days = dateDiff(self.start, w, ptype="days") if days > 7: return "Range More Than 7 Days" self.end = w def doQuery(self, frt, pag, r, c, p, i, w): self.query = w def doHkRpt(self, frt, pag, r, c, p, i, w): self.house = w def doGenInv(self, frt, pag, r, c, p, i, w): self.geninv = w if self.geninv == "N": self.prtinv = "N" self.df.loadEntry(frt, pag, p+1, data=self.prtinv) return "sk2" def doPrtInv(self, frt, pag, r, c, p, i, w): self.prtinv = w if self.prtinv == "N": return "sk1" def doTplNam(self, frt, pag, r, c, p, i, w): acc = self.sql.getRec("tplmst", where=[("tpm_tname", "=", w), ("tpm_type", "=", "I"), ("tpm_system", "=", "BKM")], limit=1) if not acc: return "Invalid Template Name" self.tname = w def doEnd(self): self.df.closeProcess() # Headings and Mail subject self.cdes = "%-30s" % self.opts["conam"] start = self.getDate(self.start) end = self.getDate(projectDate(self.end, 1)) if self.period == "D": self.hdes = "Arrivals for Weekdays %s to %s" % (start, end) elif self.period == "E": self.hdes = "Arrivals for Weekend %s to %s" % (start, end) else: self.hdes = "Arrivals for Period %s to %s" % (start, end) self.fpdf = MyFpdf(name=self.__class__.__name__, head=80, auto=True) self.fpdf.header = self.pageHeading self.rtyp = "A" self.doArrival() if self.house == "Y": self.rtyp = "H" self.hdes = self.hdes.replace("Arrivals", "Units") if self.fpdf.page: self.fpdf.add_page() self.doHKeeping() if self.fpdf.page: pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") subj = "%s - %s" % (self.cdes, self.hdes) doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=subj, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) if self.prtinv == "Y" and self.docs: # Print Invoice self.docs.sort() PrintBookingInvoice(self.opts["mf"], self.opts["conum"], self.opts["conam"], "I", self.docs, tname=self.tname, repprt=self.df.repprt, repeml=self.df.repeml) # Print Statement self.book.sort() callModule(self.opts["mf"], None, "bk3070", coy=(self.opts["conum"], self.opts["conam"]), args=[self.book, self.df.repprt, self.df.repeml]) if "wait" not in self.opts: self.opts["mf"].closeLoop() def doArrival(self): state = ["C", "S"] if self.query == "Y": state.append("Q") recs = self.sql.getRec("bkmmst", where=[("bkm_cono", "=", self.opts["conum"]), ("bkm_state", "in", tuple(state))], order="bkm_ccode") self.book = [] self.docs = [] last = 0 for rec in recs: number = rec[self.sql.bkmmst_col.index("bkm_number")] ccode = rec[self.sql.bkmmst_col.index("bkm_ccode")] btype = rec[self.sql.bkmmst_col.index("bkm_btype")] arrive = rec[self.sql.bkmmst_col.index("bkm_arrive")] depart = rec[self.sql.bkmmst_col.index("bkm_depart")] if btype == "A": if depart <= self.start or arrive > self.end: continue elif depart < self.start or arrive > self.end: continue if self.geninv == "Y": self.doRaiseInvoice(number, arrive) con = self.sql.getRec("bkmcon", where=[("bkc_cono", "=", self.opts["conum"]), ("bkc_ccode", "=", ccode)], limit=1) sname = con[self.sql.bkmcon_col.index("bkc_sname")].strip() names = con[self.sql.bkmcon_col.index("bkc_names")].strip() if names: name = "%s %s (%s)" % (names.split()[0], sname, number) else: name = "%s (%s)" % (sname, number) bal = self.sql.getRec("bkmtrn", cols=["sum(bkt_tramt)"], where=[("bkt_cono", "=", self.opts["conum"]), ("bkt_number", "=", number)], limit=1) rtts = self.sql.getRec("bkmrtt", cols=["brt_udesc", "brt_uroom", "sum(brt_quant)"], where=[("brt_cono", "=", self.opts["conum"]), ("brt_number", "=", number)], group="brt_utype, brt_ucode, brt_udesc, brt_uroom", order="brt_utype, brt_ucode, brt_uroom") if not rtts: continue units = [] unt = None for rtt in rtts: if rtt[1]: if not unt: unt = ["%s - R%s" % (rtt[0], rtt[1]), rtt[2]] else: unt = ["%s & R%s" % (unt[0], rtt[1]), rtt[2]] else: unt = (rtt[0], rtt[2]) units.append(unt) namq = len(wrap(name, break_long_words=False, width=25)) untq = 0 for unit in units: untq += len(wrap(unit[0], break_long_words=False, width=25)) if namq and untq > namq: hh = [(untq * 8.0) / namq, 8, untq * 8] elif untq and namq > untq: hh = [8, (namq * 8.0) / untq, namq * 8] elif namq: hh = [8, 8, namq * 8] else: hh = [8, 8, untq * 8] if not self.fpdf.page or self.fpdf.get_y() + hh[0] > 280: self.fpdf.add_page() oldnm = None for unit in units: if name == oldnm: name = "" else: oldnm = name if arrive >= self.start: yr = int(arrive / 10000) mt = int(arrive / 100) % 100 dy = arrive % 100 d = datetime.date(yr, mt, dy) arr = d.strftime("%a") else: arr = "<--" if btype == "A": td = projectDate(depart, -1) else: td = depart if td <= self.end: yr = int(depart / 10000) mt = int(depart / 100) % 100 dy = depart % 100 e = datetime.date(yr, mt, dy) dep = e.strftime("%a") else: dep = "-->" if last != number and bal[0]: amt = CCD(bal[0], "SD", 13.2).disp else: amt = CCD(0, "SD", 13.2).disp self.printLine(name, unit[0], unit[1], arr, dep, amt, hh) last = number self.opts["mf"].dbm.commitDbase() def doHKeeping(self): recs = self.sql.getRec("bkmunm", cols=["bum_btyp", "bum_code", "bum_desc"], where=[("bum_cono", "=", self.opts["conum"]), ("bum_room", "<>", 999)], order="bum_btyp, bum_code") for rec in recs: col = ["bkm_number", "bkm_btype", "bkm_group", "bkc_sname", "bkc_names", "bkm_arrive", "bkm_depart", "sum(brt_quant)"] state = ["C", "S"] if self.query == "Y": state.append("Q") bks = self.sql.getRec(tables=["bkmmst", "bkmrtt", "bkmcon"], cols=col, where=[("bkm_cono", "=", self.opts["conum"]), ("bkm_state", "in", tuple(state)), ("brt_cono=bkm_cono",), ("brt_number=bkm_number",), ("brt_utype", "=", rec[0]), ("brt_ucode", "=", rec[1]), ("bkc_cono=bkm_cono",), ("bkc_ccode=bkm_ccode",)], order="bkm_arrive, bkc_sname") qty = "" arr = "" dep = "" amt = "" totq = 0 lines = [] hh = [8, 8, 8] for bk in bks: number = bk[0] btype = bk[1] if bk[2]: name = bk[2] elif bk[4]: name = "%s %s" % (bk[4].split()[0], bk[3]) else: name = bk[3] name = "%s\n(%s)" % (name.strip(), number) arrive = bk[5] depart = bk[6] if btype == "A": if depart <= self.start or arrive > self.end: continue elif depart < self.start or arrive > self.end: continue if arrive >= self.start: yr = int(arrive / 10000) mt = int(arrive / 100) % 100 dy = arrive % 100 dt = datetime.date(yr, mt, dy) arrive = dt.strftime("%a") else: arrive = "<--" if btype == "A": td = projectDate(depart, -1) else: td = depart if td <= self.end: yr = int(depart / 10000) mt = int(depart / 100) % 100 dy = depart % 100 dt = datetime.date(yr, mt, dy) depart = dt.strftime("%a") else: depart = "-->" rms = self.sql.getRec("bkmrtt", cols=["brt_uroom"], where=[ ("brt_cono", "=", self.opts["conum"]), ("brt_number", "=", number), ("brt_utype", "=", rec[0]), ("brt_ucode", "=", rec[1])], order="brt_uroom") rm = False for r in rms: if not r[0]: continue if not rm: name = "%s - R%s" % (name, r[0]) rm = True else: name = "%s & R%s" % (name, r[0]) quant = bk[7] bal = self.sql.getRec("bkmtrn", cols=["sum(bkt_tramt)"], where=[("bkt_cono", "=", self.opts["conum"]), ("bkt_number", "=", number)], limit=1) namq = len(wrap(name, break_long_words=False, width=25)) totq += namq hh[2] = namq * 8 qty = CCD(quant, "UI", 3).disp arr = CCD(arrive, "NA", 3).disp dep = CCD(depart, "NA", 3).disp amt = CCD(bal[0], "SD", 13.2).disp lines.append([name, qty, arr, dep, amt, copyList(hh)]) if not self.fpdf.page or self.fpdf.get_y() + (totq * 8) > 280: self.fpdf.add_page() untq = len(wrap(rec[2], break_long_words=False, width=25)) if not lines: hh[1] = hh[2] = 8.0 * untq self.y = self.fpdf.get_y() self.printLine(rec[2], "", "", "", "", "", hh) self.fpdf.set_y(self.y) self.printLine(None, "", "", "", "", "", hh) else: if untq > totq: hh[1] = hh[2] = (untq * 8.0) / totq elif totq > untq: hh[0] = (totq * 8.0) / untq else: hh[2] = totq * 8 self.y = self.fpdf.get_y() self.printLine(rec[2], "", "", "", "", "", hh) self.fpdf.set_y(self.y) for l in lines: self.printLine(None, l[0], l[1], l[2], l[3], l[4], l[5]) def doRaiseInvoice(self, number, trdt): # Raise the Invoice incamt = 0 vatamt = 0 curdt = int(trdt / 100) batno = "B%s" % curdt gls = {} recs = self.sql.getRec("bkmrtt", where=[("brt_cono", "=", self.opts["conum"]), ("brt_number", "=", number), ("brt_invno", "=", 0)]) if not recs: return invno = self.getRef(number) self.docs.append(invno) if number not in self.book: self.book.append(number) for rec in recs: utyp = rec[self.sql.bkmrtt_col.index("brt_utype")] ucod = rec[self.sql.bkmrtt_col.index("brt_ucode")] rcod = rec[self.sql.bkmrtt_col.index("brt_rcode")] rbas = rec[self.sql.bkmrtt_col.index("brt_rbase")] quan = rec[self.sql.bkmrtt_col.index("brt_quant")] rate = rec[self.sql.bkmrtt_col.index("brt_arate")] days = rec[self.sql.bkmrtt_col.index("brt_bdays")] umst = self.sql.getRec("bkmunm", where=[("bum_cono", "=", self.opts["conum"]), ("bum_btyp", "=", utyp), ("bum_code", "=", ucod)], limit=1) vatc = umst[self.sql.bkmunm_col.index("bum_vatc")] if not vatc: vatc = self.ctm_taxdf vrte = getVatRate(self.sql, self.opts["conum"], vatc, trdt) if vrte is None: vrte = 0.0 if rbas == "A": inca = quan * days * rate elif rbas == "B": inca = quan * rate elif rbas == "C": inca = days * rate else: inca = rate vata = round(inca * vrte / (100 + vrte), 2) exca = float(ASD(inca) - ASD(vata)) incamt = float(ASD(incamt) + ASD(inca)) vatamt = float(ASD(vatamt) - ASD(vata)) if self.glint == "Y": slsa = umst[self.sql.bkmunm_col.index("bum_slsa")] if slsa not in gls: gls[slsa] = [0, 0, vatc] gls[slsa][0] = float(ASD(gls[slsa][0]) - ASD(exca)) gls[slsa][1] = float(ASD(gls[slsa][1]) - ASD(vata)) data = [self.opts["conum"], number, 2, invno, batno, trdt, inca, vata, curdt, "Booking %s-%s Raised" % (utyp, ucod), vatc, "", self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("bkmtrn", data=data) self.sql.updRec("bkmrtt", cols=["brt_invno", "brt_invdt", "brt_vrate"], data=[invno, trdt, vrte], where=[("brt_cono", "=", self.opts["conum"]), ("brt_number", "=", number), ("brt_utype", "=", utyp), ("brt_ucode", "=", ucod), ("brt_rcode", "=", rcod)]) if vata: exc = float(ASD(0) - ASD(exca)) vat = float(ASD(0) - ASD(vata)) data = [self.opts["conum"], vatc, "O", curdt, "B", 1, batno, invno, trdt, number, "Booking %s" % number, exc, vat, 0, self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("ctlvtf", data=data) if self.glint == "Y": data = [self.opts["conum"], self.bkmctl, curdt, trdt, 1, invno, batno, incamt, 0, "Booking %s" % number, "", "", 0, self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("gentrn", data=data) for acc in gls: data = [self.opts["conum"], acc, curdt, trdt, 1, invno, batno, gls[acc][0], gls[acc][1], "Booking %s" % number, gls[acc][2], "", 0, self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("gentrn", data=data) if gls[acc][1]: data = [self.opts["conum"], self.vatctl, curdt, trdt, 1, invno, batno, gls[acc][1], 0, "Booking %s" % number, "", "", 0, self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("gentrn", data=data) return True def getRef(self, number): rec = self.sql.getRec("bkmtrn", cols=["max(bkt_refno)"], where=[("bkt_cono", "=", self.opts["conum"]), ("bkt_number", "=", number), ("bkt_refno", "like", "%7s%s" % (number, "%"))], limit=1) if not rec or not rec[0]: num = 1 else: num = int(rec[0][-2:]) + 1 return "%7s%02i" % (number, num) def pageHeading(self): self.fpdf.drawText(self.cdes, x=7, font=["courier", "B", 24]) self.fpdf.drawText(font=["courier", "B", 14]) self.fpdf.drawText(self.hdes, x=7, font=["courier", "B", 16]) if self.query == "Y": ides = "Queries Included" else: ides = "Queries Not Included" if self.rtyp == "A": if self.geninv == "Y": ides = "%s, Invoices Generated" % ides else: ides = "%s, Invoices Not Generated" % ides self.fpdf.drawText() self.fpdf.drawText(ides, x=7, font=["courier", "B", 16]) if self.rtyp == "A": self.fpdf.drawText(font=["courier", "B", 12]) self.printLine("%-25s" % "Name or Group", "%-25s" % "Unit Description", "Qty", "Arr", "Dep", " Balance ", (8, 8, 8), fill=1) else: self.fpdf.drawText(font=["courier", "B", 12]) self.printLine("%-25s" % "Unit Description", "%-25s" % "Name or Group", "Qty", "Arr", "Dep", " Balance ", (8, 8, 8), fill=1) def getDate(self, date): if type(date) == str: date = int(date.replace("-", "")) yy = int(date / 10000) mm = int(date / 100) % 100 dd = date % 100 return "%s %s %s" % (dd, mthnam[mm][1], yy) def printLine(self, a, b, c, d, e, f, hh, bdr="TLB", fill=0): if self.rtyp == "H" and a is None: if hh[2] > 8: ctyp = "M" else: ctyp = "S" elif hh[0] > 8 or hh[1] > 8 or hh[2] > 8: ctyp = "M" else: ctyp = "S" ft = ["courier", "B", 12] self.fpdf.set_font(ft[0], ft[1], ft[2]) w = self.fpdf.get_string_width("X" * 26) x = 7 y = self.fpdf.get_y() if a: self.fpdf.drawText(a, x=x, y=y, w=w, h=hh[0], border=bdr, fill=fill, ctyp=ctyp, font=ft) if self.rtyp == "H" and not fill: return x += w w = self.fpdf.get_string_width("X" * 26) self.fpdf.drawText(b, x=x, y=y, w=w, h=hh[1], border=bdr, fill=fill, ctyp=ctyp, font=ft) x += w w = self.fpdf.get_string_width("X" * 4) + 1 h = self.fpdf.get_y() - y if self.rtyp == "A": self.fpdf.drawText(c, x=x, y=y, w=w, h=h, border=bdr, align="R", fill=fill, font=ft) else: self.fpdf.drawText(c, x=x, y=y, w=w, h=hh[2], border=bdr, align="R", fill=fill, ctyp=ctyp, font=ft) ly = self.fpdf.get_y() if a or self.rtyp == "H": x += w w = self.fpdf.get_string_width("X" * 4) if self.rtyp == "A": self.fpdf.drawText(d, x=x, y=y, w=w, h=hh[2], border=bdr, fill=fill, font=ft) else: self.fpdf.drawText(d, x=x, y=y, w=w, h=hh[2], border=bdr, fill=fill, ctyp=ctyp, font=ft) x += w w = self.fpdf.get_string_width("X" * 4) if self.rtyp == "A": self.fpdf.drawText(e, x=x, y=y, w=w, h=hh[2], border=bdr, fill=fill, font=ft) else: self.fpdf.drawText(e, x=x, y=y, w=w, h=hh[2], border=bdr, fill=fill, ctyp=ctyp, font=ft) x += w w = self.fpdf.get_string_width("X" * 14) if self.rtyp == "A": self.fpdf.drawText(f, x=x, y=y, w=w, h=hh[2], border="TLRB", fill=fill, font=ft) else: self.fpdf.drawText(f, x=x, y=y, w=w, h=hh[2], border="TLRB", fill=fill, ctyp=ctyp, font=ft) self.fpdf.set_y(ly) def doExit(self): self.df.closeProcess() if "wait" not in self.opts: self.opts["mf"].closeLoop()
class bc3100(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.mainProcess() self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwlgme", "bwltab", "bwltyp", "bwlpts", "bwlent"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) bwlctl = gc.getCtl("bwlctl", self.opts["conum"]) if not bwlctl: return self.fromad = bwlctl["ctb_emadd"] return True def mainProcess(self): com = { "stype": "R", "tables": ("bwlcmp",), "cols": ( ("bcm_code", "", 0, "Cod"), ("bcm_name", "", 0, "Name", "Y")), "where": [("bcm_cono", "=", self.opts["conum"])]} gme = { "stype": "R", "tables": ("bwlgme",), "cols": (("bcg_game", "", 0, "GC"),), "where": [("bcg_cono", "=", self.opts["conum"])], "whera": [("T", "bcg_ccod", 0, 0)], "group": "bcg_game"} r1s = (("Yes", "Y"), ("No", "N")) fld = ( (("T",0,0,0),"I@bcm_code",0,"","", 0,"N",self.doCmpCod,com,None,None), (("T",0,0,0),"ONA",30,""), (("T",0,1,0),"IUI",2,"Last Game","", 0,"N",self.doLstGam,gme,None,("efld",)), (("T",0,2,0),("IRB",r1s),0,"Game Report","", "N","N",self.doGamRep,None,None,None), (("T",0,3,0),("IRB",r1s),0,"Session Prizes","", "N","N",self.doSesPrz,None,None,None), (("T",0,4,0),("IRB",r1s),0,"Session Prizes by Group","", "N","N",self.doSesGrp,None,None,None)) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) self.df = TartanDialog(self.opts["mf"], tops=False, eflds=fld, tend=tnd, txit=txt, view=("N","V"), mail=("B","N")) def doCmpCod(self, frt, pag, r, c, p, i, w): chk = self.sql.getRec("bwlcmp", where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=", w)], limit=1) if not chk: return "Invalid Competition Code" self.ccod = w self.cdes = chk[self.sql.bwlcmp_col.index("bcm_name")] self.ctyp = chk[self.sql.bwlcmp_col.index("bcm_type")] self.poff = chk[self.sql.bwlcmp_col.index("bcm_poff")] chk = self.sql.getRec("bwltyp", where=[("bct_cono", "=", self.opts["conum"]), ("bct_code", "=", self.ctyp)], limit=1) self.cfmat = chk[self.sql.bwltyp_col.index("bct_cfmat")] self.tsize = chk[self.sql.bwltyp_col.index("bct_tsize")] if self.cfmat == "R": games = self.sql.getRec("bwlgme", cols=["count(*)"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", 1)], group="bcg_group") self.games = 0 for gme in games: if gme[0] > self.games: self.games = gme[0] self.games -= 1 elif self.cfmat in ("D", "K"): self.games = self.sql.getRec("bwlgme", cols=["count(*)"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", 1)], limit=1)[0] - 1 else: self.games = chk[self.sql.bwltyp_col.index("bct_games")] self.groups = chk[self.sql.bwltyp_col.index("bct_groups")] self.grgame = chk[self.sql.bwltyp_col.index("bct_grgame")] col = ["bcg_game", "bcg_aflag", "sum(bcg_sfor)", "sum(bcg_sagt)", "sum(bcg_points)"] game = self.sql.getRec("bwlgme", cols=col, where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod)], group="bcg_game, bcg_aflag", order="bcg_game") self.lgame = 0 for g in game: if not g[1] and not g[2] and not g[3] and not g[4]: break self.lgame = g[0] if not self.lgame: return "Knockout or No Completed Games" self.df.loadEntry(frt, pag, p+1, data=self.cdes) self.df.loadEntry(frt, pag, p+2, data=self.lgame) def doLstGam(self, frt, pag, r, c, p, i, w): if not w: chk = self.sql.getRec("bwlgme", cols=["bcg_game", "sum(bcg_points)"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod)], group="bcg_game", order="bcg_game") game = 0 for g in chk: if g[1]: game = g[0] else: break if not game: return "No Completed Games" self.df.loadEntry(frt, pag, p, data=game) else: game = w chk = self.sql.getRec("bwlgme", cols=["count(*)"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", game), ("bcg_aflag", "=", "A")], group="bcg_aflag", limit=1) if chk and chk[0]: return "Game Abandoned" chk = self.sql.getRec("bwlgme", where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", game), ("bcg_aflag", "in", ("", "D"))]) if not chk: return "Invalid Game Number" ptyp = chk[0][self.sql.bwlgme_col.index("bcg_type")] pts = self.sql.getRec("bwlpts", where=[("bcp_cono", "=", self.opts["conum"]), ("bcp_code", "=", self.ctyp), ("bcp_ptyp", "=", ptyp)], limit=1) self.ponly = pts[self.sql.bwlpts_col.index("bcp_p_only")] non = [] for ck in chk: scod = ck[self.sql.bwlgme_col.index("bcg_scod")] ocod = ck[self.sql.bwlgme_col.index("bcg_ocod")] if scod > 900000 or ocod > 900000: continue if self.ponly == "Y": fors = ck[self.sql.bwlgme_col.index("bcg_points")] agts = self.sql.getRec("bwlgme", cols=["bcg_points"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", game), ("bcg_scod", "=", ocod)], limit=1)[0] else: fors = ck[self.sql.bwlgme_col.index("bcg_sfor")] agts = ck[self.sql.bwlgme_col.index("bcg_sagt")] if not fors and not agts: if scod not in non: non.append(scod) if non: return "%s Result(s) Not Yet Entered" % int(len(non) / 2) self.pgame = w if self.pgame == 1: self.gamrep = "N" self.df.loadEntry(frt, pag, p+1, data=self.gamrep) if self.pgame < self.games: self.sesp = "N" self.sesg = "N" self.df.loadEntry(frt, pag, p+1, data=self.sesp) self.df.loadEntry(frt, pag, p+2, data=self.sesg) return "sk3" return "sk1" if self.cfmat in ("D", "K", "R") or self.pgame < self.lgame: self.df.topf[0][3][5] = "N" else: self.df.topf[0][3][5] = "Y" def doGamRep(self, frt, pag, r, c, p, i, w): self.gamrep = w if self.cfmat in ("D", "K", "R") or self.pgame < self.lgame: self.sesp = "N" self.sesg = "N" self.df.loadEntry(frt, pag, p+1, data=self.sesp) self.df.loadEntry(frt, pag, p+2, data=self.sesg) return "sk2" def doSesPrz(self, frt, pag, r, c, p, i, w): self.sesp = w if self.sesp == "N" or self.groups == "N": self.sesg = "N" self.df.loadEntry(frt, pag, p+1, data=self.sesg) return "sk1" def doSesGrp(self, frt, pag, r, c, p, i, w): self.sesg = w def doEnd(self): self.df.closeProcess() chk = self.sql.getRec("bwlgme", cols=["bcg_group", "bcg_scod"], where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "=", self.pgame)], order="bcg_group") if chk[0][0] and self.cfmat == "R": groups = "Y" else: groups = self.groups self.grps = {} for rec in chk: if rec[0] not in self.grps: self.grps[rec[0]] = [[rec[1]], [], []] else: self.grps[rec[0]][0].append(rec[1]) self.keys = list(self.grps.keys()) self.keys.sort() self.fpdf = MyFpdf(name=self.__class__.__name__, head=65) self.lastg = None for g in self.keys: self.pageHeading() if self.gamrep == "Y": self.doReport("G", g) if g == 0 and len(chk) > 20: self.pageHeading() self.doReport("M", g) if self.pgame == self.games: # Enter Prizes for key in self.keys: if self.cfmat == "R" and groups == "Y": self.grps[key][1] = 0 else: self.doPrizes(key) # Match Winners & Summary self.gqty = len(self.keys) self.wins = {} self.allp = [] self.swin = [] self.where = [ ("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("bcg_game", "<=", self.pgame), ("btb_cono=bcg_cono",), ("btb_tab=bcg_scod",)] for grp in range(self.gqty): if groups == "Y": gcod = grp + 1 else: gcod = grp whr = copyList(self.where) whr.append(("bcg_group", "=", gcod)) col = [ "bcg_scod", "btb_surname", "btb_names", "sum(bcg_a_sfor) as sfor", "sum(bcg_a_sagt) as sagt", "sum(bcg_a_sfor - bcg_a_sagt) as agg", "sum(bcg_a_points) as pts"] recs = self.sql.getRec(tables=["bwlgme", "bwltab"], cols=col, where=whr, group="bcg_scod, btb_surname, btb_names", order="pts desc, agg desc, sagt asc") if not recs: continue self.wins[gcod] = [] for x in range(self.grps[gcod][1]): self.allp.append(recs[x][0]) if recs[x][2]: nam = "%s, %s" % (recs[x][1], recs[x][2].split()[0]) else: nam = recs[x][1] self.wins[gcod].append(nam) if self.cfmat == "R" and groups == "Y": self.swin.append(self.grps[gcod][0][0]) if self.sesp == "Y": self.pageHeading("S") self.doSesWin() else: for grp in self.wins: if self.wins[grp]: self.pageHeading("S") break self.doMatchWin() pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, "report", ext="pdf") self.fpdf.output(pdfnam, "F") if self.df.repeml[1] == "Y": if not self.df.repeml[2]: col = ["btb_mail"] whr = [ ("bce_cono", "=", self.opts["conum"]), ("bce_ccod", "=", self.ccod), ("btb_cono=bce_cono",), ("btb_tab=bce_scod",), ("btb_mail", "<>", "")] recs = self.sql.getRec(tables=["bwlent", "bwltab"], cols=col, where=whr) self.df.repeml[2] = [] for rec in recs: self.df.repeml[2].append(rec[0]) head = "%s - Results after game %s" % (self.cdes, self.pgame) doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=head, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) if self.pgame == self.lgame and self.cfmat == "R" and \ groups == "Y" and not self.poff: ok = askQuestion(self.opts["mf"].body, "Play-Offs", "Must a Play-Off Draw be Created and/or Printed?", default="yes") if ok == "yes": self.doSecEnd() self.opts["mf"].closeLoop() def doReport(self, rtyp, grp): whr = [ ("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod), ("btb_tab=bcg_scod",)] col = ["bcg_scod", "btb_surname", "btb_names"] if rtyp == "G": whr.extend([ ("bcg_scod", "in", self.grps[grp][0]), ("bcg_game", "=", self.pgame)]) col.extend([ "sum(bcg_sfor) as sfor", "sum(bcg_sagt) as sagt", "sum(bcg_sfor - bcg_sagt) as agg", "sum(bcg_points) as pts"]) else: whr.extend([ ("bcg_scod", "in", self.grps[grp][0]), ("bcg_game", "<=", self.pgame)]) if self.pgame <= self.grgame: col.extend([ "sum(bcg_sfor) as sfor", "sum(bcg_sagt) as sagt", "sum(bcg_sfor - bcg_sagt) as agg", "sum(bcg_points) as pts"]) else: col.extend([ "sum(bcg_a_sfor) as sfor", "sum(bcg_a_sagt) as sagt", "sum(bcg_a_sfor - bcg_a_sagt) as agg", "sum(bcg_a_points) as pts"]) recs = self.sql.getRec(tables=["bwlgme", "bwltab"], cols=col, where=whr, group="btb_tab, btb_surname, btb_names", order="pts desc, agg desc, sagt asc") if not recs: return self.groupHeading(rtyp, grp) if self.cfmat == "X": tms = {"H": [0, 0, 0, 0], "V": [0, 0, 0, 0]} for num, (scod,snam,fnam,sfor,sagt,agg,pts) in enumerate(recs): if fnam: nam = "%s, %s" % (snam.upper(), fnam.split()[0].upper()) else: nam = snam.upper() a = CCD(num+1, "UI", 3) b = CCD(nam, "NA", 30) c = CCD(sfor, "SD", 7.1) d = CCD(sagt, "SD", 7.1) e = CCD(agg, "SD", 7.1) f = CCD(pts, "SD", 7.1) self.printLine(a.disp, b.disp, c.disp, d.disp, e.disp, f.disp) if self.cfmat == "X": tm = self.sql.getRec("bwlent", cols=["bce_tcod"], where=[("bce_cono", "=", self.opts["conum"]), ("bce_ccod", "=", self.ccod), ("bce_scod", "=", scod)], limit=1) tms[tm[0]][0] = float(ASD(tms[tm[0]][0]) + ASD(c.work)) tms[tm[0]][1] = float(ASD(tms[tm[0]][1]) + ASD(d.work)) tms[tm[0]][2] = float(ASD(tms[tm[0]][2]) + ASD(e.work)) tms[tm[0]][3] = float(ASD(tms[tm[0]][3]) + ASD(f.work)) self.pglin += 1 if self.cfmat == "X": cwth = self.fpdf.cwth self.fpdf.drawText() self.fpdf.drawText("Match Summary", font=["courier", "B", 18]) self.fpdf.setFont(style="B") self.fpdf.drawText() self.fpdf.drawText("Home", w=cwth * 32, border="TLRB", align="C", fill=1, ln=0) self.fpdf.drawText("Visitors", w=cwth * 32, border="TLRB", align="C", fill=1, ln=1) x = self.fpdf.get_x() y = self.fpdf.get_y() for tm in ("H", "V"): self.fpdf.drawText("+For", x=x, y=y, w=cwth * 8, h=8, border="TLRB", align="C", fill=1) val = CCD(tms[tm][0], "SD", 7.1) self.fpdf.drawText(val.disp, x=x, w=cwth * 8, h=8, border="TLRB", align="C", fill=0) x += (cwth * 8) self.fpdf.drawText("-Agt", x=x, y=y, w=cwth * 8, h=8, border="TLRB", align="C", fill=1) val = CCD(tms[tm][1], "SD", 7.1) self.fpdf.drawText(val.disp, x=x, w=cwth * 8, h=8, border="TLRB", align="C", fill=0) x += (cwth * 8) self.fpdf.drawText("=Dif", x=x, y=y, w=cwth * 8, h=8, border="TLRB", align="C", fill=1) val = CCD(tms[tm][2], "SD", 7.1) self.fpdf.drawText(val.disp, x=x, w=cwth * 8, h=8, border="TLRB", align="C", fill=0) x += (cwth * 8) self.fpdf.drawText("Pts", x=x, y=y, w=cwth * 8, h=8, border="TLRB", align="C", fill=1) val = CCD(tms[tm][3], "SD", 7.1) self.fpdf.drawText(val.disp, x=x, w=cwth * 8, h=8, border="TLRB", align="C", fill=0) x += (cwth * 8) def doSesWin(self): # Session Winners sess = {} for gme in range(1, self.games + 1): col = [ "bcg_scod", "btb_surname", "btb_names", "sum(bcg_sfor) as sfor", "sum(bcg_sagt) as sagt", "sum(bcg_sfor - bcg_sagt) as agg", "sum(bcg_points) as pts"] whr = copyList(self.where) whr.append(("bcg_game", "=", gme)) grp = "bcg_scod, btb_surname, btb_names" odr = "pts desc, agg desc, sagt asc" if self.sesg == "Y" and gme > self.grgame: col.append("bcg_group") grp = "bcg_group, %s" % grp odr = "bcg_group, %s" % odr recs = self.sql.getRec(tables=["bwlgme", "bwltab"], cols=col, where=whr, group=grp, order=odr) done = None for rec in recs: if len(rec) == 7: gpc = 0 else: gpc = rec[7] if gpc == done: continue ign = False if self.ponly == "Y" and not rec[6]: break if self.ponly == "N" and (not rec[3] and not rec[4]): break for grp in range(self.gqty): if rec[0] in self.allp: ign = True break if not ign: self.allp.append(rec[0]) if gme not in sess: sess[gme] = {} if rec[2]: nam = "%s, %s" % (rec[1], rec[2].split()[0]) else: nam = rec[1] sess[gme][gpc] = nam done = gpc mess = "Session Winners" self.fpdf.setFont(style="B", size=14) self.fpdf.drawText(mess, align="C", border="TLRB", fill=1) self.fpdf.drawText("Ses", w=12, border="TLRB", fill=1, ln=0) if self.sesg == "Y": self.fpdf.drawText("Grp", w=12, border="TLRB", fill=1, ln=0) self.fpdf.drawText("Name", border="TLRB", fill=1) self.fpdf.setFont() for gme in range(1, self.games + 1): stxt = str("%3s" % gme) if gme not in sess: self.fpdf.drawText(stxt, w=12, border="TLRB", ln=0) if self.sesg == "Y": self.fpdf.drawText("", w=12, border="TLRB", ln=0) self.fpdf.drawText("* No Valid Winner or Abandoned *", border="TLRB") continue grps = list(sess[gme].keys()) grps.sort() for grp in grps: gtxt = "%3s" % chr(64 + grp) self.fpdf.drawText(stxt, w=12, border="TLRB", ln=0) if self.sesg == "Y": self.fpdf.drawText(gtxt, w=12, border="TLRB", ln=0) self.fpdf.drawText(sess[gme][grp], border="TLRB") self.fpdf.drawText() def doMatchWin(self): for num, gcod in enumerate(self.keys): if self.wins[gcod]: if gcod: if self.cfmat == "R": mess = "Match Winners - Section %s" % chr(64 + gcod) else: mess = "Match Winners - Group %s" % chr(64 + gcod) else: mess = "Match Winners" self.fpdf.setFont(style="B", size=14) self.fpdf.drawText(mess, align="C", border="TLRB", fill=1) self.fpdf.drawText("Pos", w=12, border="TLRB", fill=1, ln=0) self.fpdf.drawText("Name", border="TLRB", fill=1) self.fpdf.setFont() for n, s in enumerate(self.wins[gcod]): ptxt = "%3s" % (n + 1) self.fpdf.drawText(ptxt, w=12, border="TLRB", ln=0) self.fpdf.drawText(s, border="TLRB") if not num % 2: ly = self.fpdf.get_y() if num % 2 and self.fpdf.get_y() > ly: ly = self.fpdf.get_y() self.fpdf.drawText() place = ["1st", "2nd", "3rd"] for x in range(4, 21): place.append("%sth" % x) if self.tsize == 2: ppos = ("Skip", "Lead") elif self.tsize == 3: ppos = ("Skip", "Second", "Lead") elif self.tsize == 4: ppos = ("Skip", "Third", "Second", "Lead") for gcod in self.keys: if not self.grps[gcod][2]: continue for num, skp in enumerate(self.wins[gcod]): self.fpdf.add_page() self.fpdf.setFont(style="B", size=24) self.fpdf.drawText(self.cdes, h=10, align="C") self.fpdf.drawText() self.fpdf.setFont(style="B", size=18) if gcod: self.fpdf.drawText("GROUP %s" % chr(64 + gcod), h=10, align="C") self.fpdf.drawText() self.fpdf.drawText("%s Prize R%s - %s" % (place[num], self.grps[gcod][2][num], skp), h=10, align="C") self.fpdf.setFont(style="B", size=16) for pos in ppos: self.fpdf.drawText() self.fpdf.drawText() self.fpdf.drawText("%s's Name" % pos, w=50, h=8, border="TLRB", ln=0, fill=1) self.fpdf.drawText("", h=8, border="TLRB") self.fpdf.drawText("Bank Name", w=50, h=8, border="TLRB", ln=0, fill=1) self.fpdf.drawText("", h=8, border="TLRB") self.fpdf.drawText("Branch Name", w=50, h=8, border="TLRB", ln=0, fill=1) self.fpdf.drawText("", h=8, border="TLRB") self.fpdf.drawText("Branch Code", w=50, h=8, border="TLRB", ln=0, fill=1) self.fpdf.drawText("", h=8, border="TLRB") self.fpdf.drawText("Account Number", w=50, h=8, border="TLRB", ln=0, fill=1) self.fpdf.drawText("", h=8, border="TLRB") self.fpdf.drawText() self.fpdf.setFont(style="B", size=18) self.fpdf.drawText("Congratulations and Well Done!", h=10, align="C") def pageHeading(self, htyp=None): self.fpdf.add_page() head = "%s - %s" % (self.opts["conam"], self.cdes) self.fpdf.drawText(head, font=["courier", "B", 18], align="C") if htyp == "S": self.fpdf.drawText() self.fpdf.drawText("Match Summary", font=["courier", "B", 16], align="C") self.fpdf.drawText() self.pglin = 4 else: self.pglin = 1 def groupHeading(self, rtyp, group): self.fpdf.drawText(font=["courier", "B", 18], align="C") if rtyp == "G": head = "Results for Game Number: %s" % self.pgame else: head = "Match Standings After Game Number: %s" % self.pgame if group: if self.cfmat == "R": head += " for Section: %s" % chr(64 + group) else: head += " for Group: %s" % chr(64 + group) self.fpdf.drawText(head, font=["courier", "B", 16], align="C") self.fpdf.drawText() self.fpdf.setFont(style="B") self.printLine("Pos", "%-30s" % "Name", " +For ", " -Agt ", " =Dif ", " Pts ", fill=1) self.fpdf.setFont() self.pglin += 4 def printLine(self, a, b, c, d, e, f, fill=0): x = 10 w = self.fpdf.get_string_width("X"*len(a)) + 1 self.fpdf.drawText(a, x=x, w=w, border="TLB", fill=fill, ln=0) x += w w = self.fpdf.get_string_width("X"*len(b)) + 1 self.fpdf.drawText(b, x=x, w=w, border="TLB", fill=fill, ln=0) x += w w = self.fpdf.get_string_width("X"*len(c)) + 1 self.fpdf.drawText(c, x=x, w=w, border="TLB", fill=fill, ln=0) x += w w = self.fpdf.get_string_width("X"*len(d)) + 1 self.fpdf.drawText(d, x=x, w=w, border="TLB", fill=fill, ln=0) x += w w = self.fpdf.get_string_width("X"*len(e)) + 1 self.fpdf.drawText(e, x=x, w=w, border="TLB", fill=fill, ln=0) x += w w = self.fpdf.get_string_width("X"*len(f)) + 1 self.fpdf.drawText(f, x=x, w=w, border="TLRB", fill=fill) def doPrizes(self, grp): self.przgrp = grp if grp: if self.cfmat == "R": tit = "Prizes for Section %s" % chr(64 + grp) else: tit = "Prizes for Group %s" % chr(64 + grp) else: tit = "Prizes for Match" r1s = (("Yes", "Y"), ("No", "N")) fld = ( (("T",0,0,0),"IUI",2,"Number of Prizes","", 3,"N",self.doPrzNum,None,None,("efld",)), (("T",0,1,0),("IRB",r1s),0,"EFT Forms","", "N","N",self.doPrzEft,None,None,None), (("T",0,2,0),"IUI",5,"1st Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,3,0),"IUI",5,"2nd Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,4,0),"IUI",5,"3rd Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,5,0),"IUI",5,"4th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,6,0),"IUI",5,"5th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,7,0),"IUI",5,"6th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,8,0),"IUI",5,"7th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,9,0),"IUI",5,"8th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,10,0),"IUI",5,"9th Prize","", 0,"N",self.doPrzAmt,None,None,None), (("T",0,11,0),"IUI",5,"10th Prize","", 0,"N",self.doPrzAmt,None,None,None)) tnd = ((self.doPrzEnd,"n"),) self.pz = TartanDialog(self.opts["mf"], tops=True, title=tit, eflds=fld, tend=tnd, txit=None) for x in range(10): self.pz.setWidget(self.pz.topLabel[0][2+x], state="hide") self.pz.setWidget(self.pz.topEntry[0][2+x], state="hide") self.pz.mstFrame.wait_window() def doPrzNum(self, frt, pag, r, c, p, i, w): if not w and self.cfmat != "R": ok = askQuestion(self.opts["mf"].body, "Prizes", "Are You Sure that there are No Prizes?", default="no") if ok == "no": return "Invalid Number od Prizes" self.prznum = w if not self.prznum: self.przeft = [] self.pz.loadEntry(frt, pag, p+1, data="N") return "nd" def doPrzEft(self, frt, pag, r, c, p, i, w): if w == "N": self.przeft = [] return "nd" self.przeft = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for x in range(self.prznum): self.pz.setWidget(self.pz.topLabel[0][2+x], state="show") self.pz.setWidget(self.pz.topEntry[0][2+x], state="show") for x in range(self.prznum, 10): self.pz.setWidget(self.pz.topLabel[0][2+x], state="hide") self.pz.setWidget(self.pz.topEntry[0][2+x], state="hide") def doPrzAmt(self, frt, pag, r, c, p, i, w): self.przeft[p-2] = w if p == self.prznum + 1: return "nd" def doPrzEnd(self): self.grps[self.przgrp][1] = self.prznum self.grps[self.przgrp][2] = self.przeft self.pz.closeProcess() def doSecEnd(self): ccod = getNextCode(self.sql, "bwlcmp", "bcm_code", where=[("bcm_cono", "=", self.opts["conum"])], last=999) self.sql.updRec("bwlcmp", cols=["bcm_poff"], data=[ccod], where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=", self.ccod)]) cdes = self.cdes + " Play-Off" t = time.localtime() cdte = ((t[0] * 10000) + (t[1] * 100) + t[2]) self.sql.insRec("bwlcmp", data=[self.opts["conum"], ccod, cdes, cdte, 0, ""]) for skp in self.swin: self.sql.insRec("bwlent", data=[self.opts["conum"], ccod, skp, 0, "Y", ""]) callModule(self.opts["mf"], self.df, "bc2050", coy=[self.opts["conum"], self.opts["conam"]], args=ccod) def doExit(self): self.df.closeProcess() self.opts["mf"].closeLoop()
class bc3070(object): def __init__(self, **opts): self.opts = opts self.setVariables() self.mainProcess() self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwlent", "bwltab"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) bwlctl = gc.getCtl("bwlctl", self.opts["conum"]) if not bwlctl: return self.fromad = bwlctl["ctb_emadd"] t = time.localtime() self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t) self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png") if not os.path.exists(self.image): getImage("bowls", fle=self.image) if not os.path.exists(self.image): self.image = None def mainProcess(self): com = { "stype": "R", "tables": ("bwlcmp",), "cols": ( ("bcm_code", "", 0, "Cod"), ("bcm_name", "", 0, "Name", "Y"), ("bcm_date", "", 0, "Date")), "where": [("bcm_cono", "=", self.opts["conum"])]} r1s = (("Alphabtic", "A"), ("Numeric", "N")) fld = ( (("T",0,0,0),"I@bcm_code",0,"","", "","N",self.doCmpCod,com,None,("notzero",)), (("T",0,0,0),"ONA",30,""), (("T",0,1,0),("IRB",r1s),0,"Order","", "A","N",self.doCmpOrd,None,None,None)) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) self.df = TartanDialog(self.opts["mf"], tops=False, eflds=fld, tend=tnd, txit=txt, view=("N","V"), mail=("Y","Y")) def doCmpCod(self, frt, pag, r, c, p, i, w): chk = self.sql.getRec("bwlcmp", cols=["bcm_name"], where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=", w)], limit=1) if not chk: return "Invalid Competition Code" self.ccod = w self.cnam = chk[0] self.df.loadEntry(frt, pag, p+1, data=self.cnam) def doCmpOrd(self, frt, pag, r, c, p, i, w): self.cord = w def doEnd(self): self.df.closeProcess() col = ["btb_tab", "btb_surname", "btb_names", "btb_cell", "btb_mail", "bce_tcod"] whr = [ ("bce_cono", "=", self.opts["conum"]), ("bce_ccod", "=", self.ccod), ("btb_cono=bce_cono",), ("btb_tab=bce_scod",)] if self.cord == "A": odr = "btb_surname" else: odr = "btb_tab" recs = self.sql.getRec(tables=["bwlent", "bwltab"], cols=col, where=whr, order=odr) if recs: self.fpdf = MyFpdf(auto=True) self.fpdf.header = self.doHead self.fpdf.add_page() self.fpdf.set_font("Courier","",9) cwth = self.fpdf.get_string_width("X") for num, rec in enumerate(recs): tab = CCD(rec[0], "UI", 6).disp self.fpdf.drawText(txt=tab, w=cwth*7, h=5, ln=0) nm = rec[1].strip() if rec[2]: nm += ", %s" % rec[2].split()[0].upper() self.fpdf.drawText(txt=nm, w=cwth*31, h=5, ln=0) self.fpdf.drawText(txt=rec[3], w=cwth*16, h=5, ln=0) self.fpdf.drawText(txt=rec[4], w=cwth*41, h=5, ln=0) self.fpdf.drawText(txt=rec[5], w=cwth*2, h=5, ln=1) pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") head = "%s - Entered Teams" % self.cnam doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=head, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) self.opts["mf"].closeLoop() def doHead(self): if os.path.isfile(self.image): self.fpdf.image(self.image, 10, 10, 15, 11) self.fpdf.set_font("Arial","B",15) self.fpdf.cell(20) self.fpdf.cell(0,10,"Players Entered in the %s" % self.cnam,1,0,"C") self.fpdf.ln(20) self.fpdf.set_font("Courier","B",9) self.fpdf.cell(0, 5, "%-6s %-30s %-15s %-40s %1s" % \ ("Number", "Name", "Mobile", "Email", "T"), "B") self.fpdf.ln(5) def doExit(self): self.df.closeProcess() self.opts["mf"].closeLoop()
def doPrint(self): self.pr.closeProcess() pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, "select_%s" % self.date, ext="pdf") fpdf = MyFpdf(name=self.__class__.__name__, head=90) cw = fpdf.get_string_width("X") # character width ld = 4.5 # line depth fm = { "margins": ((10, 80), (5, 12.5)), # left, right, top, bottom "repeat": (1, 5), # repeat across and below "rows": ( # x, y, w, h, fill, text, qty (10, 5, 80, 1.5, .8), (10, 6.5, ((10, 1.5, .9, ("Skip", "Third", "Second", "Lead")), (23, 1.5), (23, 1.5), (24, 1.5)), 4), (10, 12.5, 80, 1.5)) } ff = { "margins": ((10, 80), ((5, 15))), # left, right, top, bottom "repeat": (1, 3), # repeat across and below "rows": ( # x, y, w, h, fill, text, qty (10, 5, 80, 2, .8), (10, 7, ((10, 2, .9, ("Skip", "Third", "Second", "Lead")), (70, 2)), 4), (10, 15, 80, 2)) } for div in ("Main", "Friendly"): whr = [("bfm_cono", "=", self.opts["conum"]), ("bfm_fmat", "=", self.fmat), ("bfm_type", "=", self.ftyp), ("bfm_date", "=", self.date)] if div == "Main": ppad = 1 rr = fm if self.ftyp == "P": ftyp = "PRACTICE" else: ftyp = "FIXTURE" h1 = "TEAMS FOR %s %s - %s %s %s" % ( self.fdes, ftyp, self.date % 100, mthnam[int( self.date / 100) % 100][1], int(self.date / 10000)) whr.append(("bfs_league", "=", "M")) else: ppad = 1.5 rr = ff h1 = "TEAMS FOR %s FRIENDLY - %s %s %s" % ( self.fdes, self.date % 100, mthnam[int( self.date / 100) % 100][1], int(self.date / 10000)) whr.append(("bfs_league", "=", "F")) whr.extend([("bfs_cono=bfm_cono", ), ("bfs_fmat=bfm_fmat", ), ("bfs_code=bfm_team", ), ("bfo_cono=bfm_cono", ), ("bfo_fmat=bfm_fmat", ), ("bfo_code=bfm_opps", ), ("bcc_code=bfo_club", )]) games = self.sql.getRec( tables=["bwlflm", "bwlfls", "bwlflo", "bwlclb"], cols=[ "bfm_round", "bfm_team", "bfs_desc", "bfo_desc", "bfm_venue", "bfm_mtime", "bfm_mplace", "bfm_captain", "bcc_name", "bfs_number" ], where=whr, order="bfm_team") if not games: continue fpdf.add_page() if games[0][0] == 0: h1 = h1.replace("FIXTURE", "PRACTICE") totp = 0 for game in games: if totp < game[9]: totp = game[9] * 4 # Draw headings fpdf.drawText(x=0, y=1 * ld, w=90 * cw, align="C", txt=h1, font=("helvetica", "B", 18)) fpdf.setFont("helvetica", "B", 12) # Draw table last, table = doDrawTable(fpdf, rr, ppad, spad=2, cw=cw, ld=ld) # Fill Form tc = [] pl = [] fpdf.setFont("helvetica", "B", 12) for x, game in enumerate(games): tc.append(game[7]) if game[4].strip().upper() == "H": text = "%s vs %s at %s" % (game[2], game[3], self.opts["conam"]) elif game[4].strip().upper() == "A": text = "%s vs %s at %s" % (game[2], game[3], game[8]) else: text = "%s vs %s at %s" % (game[2], game[3], game[4]) pos = table[0][1][x] + .5 fpdf.drawText(x=0, y=pos * ld, w=90 * cw, align="C", txt=text) pos = table[-1][1][x] + .5 if game[6].strip().upper() in ("H", "A"): text = "Meet at the Club at %5.2f" % game[5] else: text = "Meet at %s at %5.2f" % (game[6], game[5]) fpdf.drawText(x=0, y=pos * ld, w=90 * cw, align="C", txt=text) plrs = self.sql.getRec( tables=["bwlflt", "bwltab"], cols=["btb_tab", "btb_surname", "btb_names"], where=[("bft_cono", "=", self.opts["conum"]), ("bft_fmat", "=", self.fmat), ("bft_type", "=", self.ftyp), ("bft_date", "=", self.date), ("bft_team", "=", game[1]), ("btb_cono=bft_cono", ), ("btb_tab=bft_player", )], order="bft_team, bft_skip, bft_position") while len(plrs) < totp: plrs.append(["", "", ""]) pl.extend(plrs) fpdf.setFont("helvetica", "", 12) col = len(rr["rows"][1][2]) cnt = 0 for p in pl: if p == ["", "", ""]: continue pn = self.getName(p[1], p[2]) if p[0] in tc: pn = "%s (C)" % pn x = table[(int((cnt % totp) / 4) + 2)][0][0] + 1 y = table[( (cnt - (int(cnt / 4) * 4)) * col) + 2][1][int(cnt / totp)] + .5 fpdf.drawText(x=x * cw, y=y * ld, txt=pn) cnt += 1 # Draw trailer fpdf.setFont("helvetica", "B", 14) txt = """Please tick your names on the right hand side to indicate availability. If unavailable please inform skips and skips to inform selectors.""" if self.assess == "Y": txt = """%s Captains (C) are responsible to distribute and return assessment forms, completed and initialled, to a selector.""" % txt txt = """%s %s %s""" % (txt, self.pr.t_work[0][0][0], self.pr.t_work[0][0][1]) fpdf.drawText(x=10.0 * cw, y=(last + 3) * ld, txt=txt, ctyp="M") fpdf.output(pdfnam, "F") head = "Match Selections for %s" % self.disp doPrinter(mf=self.opts["mf"], header=head, pdfnam=pdfnam, repprt=self.pr.repprt, fromad=self.fromad, repeml=self.pr.repeml)
class bc3020(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.mainProcess() self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["bwldrm", "bwldrt", "bwltab"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) bwlctl = gc.getCtl("bwlctl", self.opts["conum"]) if not bwlctl: return self.nstart = bwlctl["ctb_nstart"] self.fromad = bwlctl["ctb_emadd"] t = time.localtime() self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t) self.curdt = time.strftime("%Y-%m", t) self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png") if not os.path.exists(self.image): getImage("bowls", fle=self.image) if not os.path.exists(self.image): self.image = None self.drawn = "Y" self.bounce = "N" self.teams = "N" return True def mainProcess(self): r1s = (("Yes", "Y"), ("No", "N")) fld = ((("T", 0, 0, 0), "Id2", 7, "Starting Period", "", "", "N", self.doStartPeriod, None, None, ("efld", )), (("T", 0, 1, 0), "Id2", 7, "Ending Period", "", "", "N", self.doEndPeriod, None, None, ("efld", )), (("T", 0, 2, 0), ("IRB", r1s), 0, "All Tabs", "", "Y", "N", self.doTabs, None, None, None), (("T", 0, 3, 0), ("ICB", "Tabs-In"), 0, "Draw Types", "", self.drawn, "N", self.doType, None, None, None), (("T", 0, 3, 0), ("ICB", "Bounce"), 0, "", "", self.bounce, "N", self.doType, None, None, None), (("T", 0, 3, 0), ("ICB", "Teams"), 0, "", "", self.teams, "N", self.doType, None, None, None), (("T", 0, 4, 0), ("IRB", r1s), 0, "Totals Only", "", "N", "N", self.doTots, None, None, None)) tnd = ((self.doEnd, "y"), ) txt = (self.doExit, ) self.df = TartanDialog(self.opts["mf"], tops=False, eflds=fld, tend=tnd, txit=txt, view=("N", "V"), mail=("Y", "Y")) def doStartPeriod(self, frt, pag, r, c, p, i, w): if w: self.start = CCD((w * 100) + 1, "D1", 7) else: self.start = CCD(0, "UI", 1) def doEndPeriod(self, frt, pag, r, c, p, i, w): if w: self.end = CCD(mthendDate((w * 100) + 1), "D1", 7) else: self.end = CCD(0, "d1", 7) self.end.disp = self.curdt def doTabs(self, frt, pag, r, c, p, i, w): self.whole = w def doType(self, frt, pag, r, c, p, i, w): if p == 3: self.drawn = w elif p == 4: self.bounce = w else: self.teams = w def doTots(self, frt, pag, r, c, p, i, w): self.tots = w def doEnd(self): self.df.closeProcess() dat = [] tps = [] if self.drawn == "Y": tps.extend(["B", "D"]) if self.bounce == "Y": tps.append("A") if self.teams == "Y": tps.append("C") where = [("bdt_cono", "=", self.opts["conum"]), ("bdt_tab", "<", self.nstart), ("bdt_flag", "in", tps)] if self.start.work: where.append(("bdt_date", ">=", self.start.work)) if self.end.work: where.append(("bdt_date", "<=", self.end.work)) whr = copyList(where) if self.whole == "N": tab = [] rec = getSingleRecords(self.opts["mf"], "bwldrt", ("bdt_tab", "bdt_name"), head=["X", "Tab-No", "Name"], where=whr, group="bdt_tab, bdt_name", order="bdt_name", selcol="bdt_name") if not rec: self.opts["mf"].closeLoop() return for r in rec: tab.append(r[1]) whr.append(("bdt_tab", "in", tab)) odr = "bdt_name, bdt_date" rec = self.sql.getRec("bwldrt", where=whr, order=odr) c = self.sql.bwldrt_col l = "" self.dic = {} for r in rec: dte = CCD(r[c.index("bdt_date")], "D1", 10) tim = r[c.index("bdt_time")] bdm = self.sql.getRec("bwldrm", where=[("bdm_cono", "=", self.opts["conum"]), ("bdm_date", "=", dte.work), ("bdm_time", "=", tim)], limit=1) if bdm[self.sql.bwldrm_col.index("bdm_dhist")] == "N": continue self.clash = "" side = [["", ""], ["", ""], ["", ""], ["", ""]] self.tab = r[c.index("bdt_tab")] if self.tab not in self.dic: self.dic[self.tab] = [] nam = self.getName(self.tab) pos = (0 - (r[c.index("bdt_pos")] - 4)) side[pos] = ["", nam] for x in range(1, 4): tm = self.getName(r[c.index("bdt_team%s" % x)]) if not tm: continue if self.clash: cl = "X" else: cl = "" pos = (0 - (r[c.index("bdt_pos%s" % x)] - 4)) side[pos] = [cl, tm] if self.tab != l: if l: dat.append([]) d = [nam] else: d = [""] d.extend([dte.disp, side[0], side[1], side[2], side[3]]) dat.append(d) l = self.tab self.fpdf = MyFpdf(name=self.__class__.__name__, head=120, auto=True) self.fpdf.header = self.pageHeading if self.tots == "N": # Print teams self.heading = "main" self.fpdf.add_page() cwth = self.fpdf.get_string_width("X") for d in dat: if not d: self.fpdf.drawText(txt="", w=0, h=5, border=0, ln=1) else: self.fpdf.cell(w=cwth * 21, h=5, txt=d[0], border=0, ln=0) self.fpdf.cell(w=cwth * 11, h=5, txt=d[1], border=0, ln=0) if d[2][0]: self.fpdf.cell(w=cwth * 21, h=5, txt=d[2][1], border=1, ln=0) else: self.fpdf.cell(w=cwth * 21, h=5, txt=d[2][1], border=0, ln=0) if d[3][0]: self.fpdf.cell(w=cwth * 21, h=5, txt=d[3][1], border=1, ln=0) else: self.fpdf.cell(w=cwth * 21, h=5, txt=d[3][1], border=0, ln=0) if d[4][0]: self.fpdf.cell(w=cwth * 21, h=5, txt=d[4][1], border=1, ln=0) else: self.fpdf.cell(w=cwth * 21, h=5, txt=d[4][1], border=0, ln=0) if d[5][0]: self.fpdf.cell(w=cwth * 21, h=5, txt=d[5][1], border=1, ln=1) else: self.fpdf.cell(w=cwth * 21, h=5, txt=d[5][1], border=0, ln=1) if self.whole == "Y" or self.tots == "Y": # Print top attendees self.heading = "summary" whr = copyList(where) whr.append(("bdt_tab", "<", self.nstart)) self.cnt = self.sql.getRec("bwldrt", cols=["count(*) as count", "bdt_tab"], where=whr, group="bdt_tab", order="count desc, bdt_name") while self.cnt: self.fpdf.add_page() if len(self.cnt) < 26: left = copyList(self.cnt) self.cnt = [] right = [] else: left = self.cnt[:25] self.cnt = self.cnt[25:] if len(self.cnt) < 26: right = copyList(self.cnt) self.cnt = [] else: right = self.cnt[:25] self.cnt = self.cnt[25:] left = left + (25 - len(left)) * [["", ""]] right = right + (25 - len(right)) * [["", ""]] self.fpdf.set_font("Arial", "", 15) cwth = self.fpdf.get_string_width("X") for x in range(25): if left[x][1]: left[x][1] = self.getName(left[x][1], cls=False) if right[x][1]: right[x][1] = self.getName(right[x][1], cls=False) self.fpdf.cell(cwth * 5, 8, "%5s " % left[x][0], 0, 0, "R") self.fpdf.cell(cwth * 24, 8, left[x][1], 0, 0, "L") self.fpdf.cell(cwth * 5, 8, "%5s " % right[x][0], 0, 0, "R") self.fpdf.cell(cwth * 20, 8, right[x][1], 0, 1, "L") pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") head = "Tabs Draw Summary for the period %s to %s" % (self.start.disp, self.end.disp) doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=head, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) self.opts["mf"].closeLoop() def getName(self, tab, cls=True): self.clash = False if not tab: return "" rec = self.sql.getRec("bwltab", cols=["btb_surname", "btb_names", "btb_rate1"], where=[("btb_tab", "=", tab)], limit=1) if not rec: return "VISITOR, A" if rec[1]: nam = "%s, %s" % (rec[0], rec[1][0]) else: nam = rec[0] nam = nam.replace("VAN DER", "V D") nam = nam.replace("JANSE VAN", "J V") if cls: if tab in self.dic[self.tab]: self.clash = True self.dic[self.tab].append(tab) return nam def pageHeading(self): self.fpdf.setFont("Arial", "B", 15) if os.path.isfile(self.image): self.fpdf.image(self.image, 10, 10, 15, 11) self.fpdf.cell(20) x = self.fpdf.get_x() self.fpdf.cell(0, 10, self.opts["conam"], "TLR", 1, "C") self.fpdf.set_x(x) if self.heading == "main": self.fpdf.cell(0, 10, "Tabs-In for the period %s to %s" % \ (self.start.disp, self.end.disp), "LRB", 1, "C") self.fpdf.ln(8) self.fpdf.setFont(style="B") self.fpdf.cell(0, 5, "%-20s %-10s %-20s %-20s %-20s %-20s" % \ ("Member", " Date", "Skip", "Third", "Second", "Lead"), "B") self.fpdf.ln(5) else: self.fpdf.cell(0, 10, "Top Attendees for the period "\ "%s to %s" % (self.start.disp, self.end.disp), "LRB", 0, "C") self.fpdf.ln(15) self.fpdf.cell( 0, 5, "%5s %-50s %5s %-30s" % ("Count", "Member", "Count", "Member"), "B") self.fpdf.ln(10) def doExit(self): self.df.closeProcess() self.opts["mf"].closeLoop()
def doEnd(self): self.df.closeProcess() pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, "declare_%s" % self.date, ext="pdf") fpdf = MyFpdf(name=self.__class__.__name__, head=90) cw = fpdf.get_string_width("X") # character width ld = 4.3 # line depth r1 = { "margins": ((25, 85), (10, 16)), "repeat": (1, 1), "rows": ((25, 10, 50, 1.5, .8), (25, 13, 50, 1.5, .8), (25, 15, ((11, 1.5, .8, "Division"), (4, 1.5), (11, 1.5, .8, "Round"), (4, 1.5), (6, 1.5, .8, "Date"), (14, 1.5))), (25, 17, ((10, 1.5, .8, "Played at"), (40, 1.5)))) } r2 = { "margins": ((10, 85), (19.5, 27)), "repeat": (1, 3), "rows": ((10, 19.5, ((10, 1.5, .8, "Position"), (10, 1.5, .8, "Initials"), (50, 1.5, .8, "Surname"), (10, 1.5, .8, "BSA No."))), (10, 21, ((10, 1.5, .9, ("Skip", "Third", "Second", "Lead")), (10, 1.5), (50, 1.5), (10, 1.5)), 4)) } r3 = { "margins": ((10, 85), (46, 50.5)), "repeat": (1, 1), "rows": ((10, 46, ((10, 1.5, .8, "Position"), (10, 1.5, .8, "Initials"), (50, 1.5, .8, "Surname"), (10, 1.5, .8, "BSA No."))), (10, 47.5, ((10, 1.5, .9, "Reserve"), (10, 1.5), (50, 1.5), (10, 1.5))), (10, 49, ((10, 1.5, .9, "Captain"), (10, 1.5), (50, 1.5)))) } for cnt, match in enumerate(self.recs): fpdf.add_page() side = self.sql.getRec("bwlfls", cols=["bfs_league", "bfs_division"], where=[("bfs_cono", "=", self.opts["conum"]), ("bfs_fmat", "=", self.fmat), ("bfs_code", "=", match[1])], limit=1) if side[0] == "F": continue if self.logo: fpdf.image(self.logo, 5 * cw, 1 * ld, 35, 40) fpdf.image(self.logo, 77 * cw, 1 * ld, 35, 40) fpdf.setFont("helvetica", "B", 16) fpdf.drawText(y=2 * ld, w=90 * cw, align="C", txt="WESTERN PROVINCE BOWLS") fpdf.drawText(y=4 * ld, w=90 * cw, align="C", txt="%s CHAMPIONSHIP" % self.fdes) fpdf.drawText(y=6 * ld, w=90 * cw, align="C", txt="MATCH DECLARATION FORM") fpdf.setFont("helvetica", "B", 14) fpdf.drawText(y=8*ld, w=90*cw, align="C", txt="The following players will "\ "represent") fpdf.drawText(y=11.7 * ld, w=90 * cw, align="C", txt="vs") fpdf.setFont("helvetica", "B", 12) last, tab1 = doDrawTable(fpdf, r1, ppad=1, cw=cw, ld=ld, font=False) last, tab2 = doDrawTable(fpdf, r2, ppad=1, cw=cw, ld=ld, font=False) last, tab3 = doDrawTable(fpdf, r3, ppad=1, cw=cw, ld=ld, font=False) if "Bowl" in self.opts["conam"]: home = self.opts["conam"] else: home = "%s Bowling Club" % self.opts["conam"] fpdf.drawText(y=(10 * ld) + 1.2, w=90 * cw, align="C", txt=home) opp = self.sql.getRec(tables=["bwlflo", "bwlclb"], cols=["bcc_name", "bfo_desc"], where=[("bfo_cono", "=", self.opts["conum"]), ("bfo_fmat", "=", self.fmat), ("bfo_code", "=", match[2]), ("bcc_code=bfo_club", )], limit=1) if "Bowl" in opp[0]: away = opp[0] else: away = "%s Bowling Club" % opp[0] fpdf.drawText(y=(13 * ld) + 1.2, w=90 * cw, align="C", txt=away) fpdf.drawText(x=36 * cw, y=(15 * ld) + 1.2, txt=side[1]) fpdf.drawText(x=52 * cw, y=(15 * ld) + 1.2, txt=str(match[0])) fpdf.drawText(x=63 * cw, y=(15 * ld) + 1.2, txt=self.disp) if match[3] == "H": venue = home else: venue = away fpdf.drawText(x=36 * cw, y=17.3 * ld, txt=venue) teams = self.sql.getRec( tables=["bwlflt", "bwltab"], cols=["btb_names", "btb_surname", "btb_bsano"], where=[("bft_cono", "=", self.opts["conum"]), ("bft_fmat", "=", self.fmat), ("bft_date", "=", self.date), ("bft_team", "=", match[1]), ("btb_tab=bft_player", )], order="bft_skip, bft_position") for num, player in enumerate(teams): init = "" if player[0]: for i in player[0].split(): init = init + i[0].upper() + " " pos = tab2[((num % 4) + 1) * 4][1][int(num / 4)] + .4 fpdf.drawText(x=20 * cw, y=pos * ld, txt=init.strip()) fpdf.drawText(x=30 * cw, y=pos * ld, txt=player[1]) fpdf.drawText(x=82 * cw, y=pos * ld, txt=str(player[2])) captain = self.sql.getRec( "bwltab", cols=["btb_names", "btb_surname", "btb_bsano"], where=[("btb_cono", "=", self.opts["conum"]), ("btb_tab", "=", match[4])], limit=1) init = "" if captain[0]: for i in captain[0].split(): init = init + i[0].upper() + " " fpdf.drawText(x=20 * cw, y=(tab3[8][1][0] + .4) * ld, txt=init.strip()) fpdf.drawText(x=30 * cw, y=(tab3[8][1][0] + .4) * ld, txt=captain[1]) fpdf.drawText(x=10 * cw, y=54 * ld, txt="Declaration") fpdf.drawText(x=10*cw, y=57*ld, txt="I certify that the above "\ "players are registered with WP Bowls as playing members") fpdf.drawText(x=10*cw, y=58*ld, txt="of the Club and that the "\ "names are without exception the same as those entered") fpdf.drawText(x=10*cw, y=59*ld, txt="on the scorecards relevant "\ "to this match") fpdf.drawText(x=10 * cw, y=63 * ld, txt="CAPTAIN: _________________") fpdf.drawText(x=26 * cw, y=64 * ld, txt="(Signature)") fpdf.output(pdfnam, "F") head = "Match Declaration Forms for %s" % self.disp doPrinter(mf=self.opts["mf"], header=head, pdfnam=pdfnam, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) self.closeProcess()
class dr2030(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.doProcess() self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["ctlmst", "ctlvrf", "ctlvtf", "drsmst", "drstrn", "drsrcm", "drsrct", "genmst", "gentrn"], prog=self.__class__.__name__) if self.sql.error: return self.gc = GetCtl(self.opts["mf"]) drsctl = self.gc.getCtl("drsctl", self.opts["conum"]) if not drsctl: return self.glint = drsctl["ctd_glint"] self.fromad = drsctl["ctd_emadd"] if self.glint == "Y": ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return if self.gc.chkRec(self.opts["conum"],ctlctl,["drs_ctl","vat_ctl"]): return self.drsctl = ctlctl["drs_ctl"] self.vatctl = ctlctl["vat_ctl"] ctl = self.sql.getRec("ctlmst", where=[("ctm_cono", "=", self.opts["conum"])], limit=1) for col in ("ctm_name", "ctm_add1", "ctm_add2", "ctm_add3", "ctm_pcode", "ctm_regno", "ctm_taxno", "ctm_tel", "ctm_fax", "ctm_b_name", "ctm_b_branch", "ctm_b_ibt", "ctm_b_acno", "ctm_logo"): setattr(self, "%s" % col, ctl[self.sql.ctlmst_col.index(col)]) if "LETTERHEAD" in os.environ: self.ctm_logo = os.environ["LETTERHEAD"] if not self.ctm_logo or not os.path.exists(self.ctm_logo): self.ctm_logo = None self.batchHeader() if not self.bh.batno: return t = time.localtime() self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2] return True def batchHeader(self): self.bh = Batches(self.opts["mf"], self.opts["conum"], self.opts["conam"], self.opts["period"], "DRS", self.opts["rtn"], multi="N", glint=self.glint) self.bh.doBatchHeader() if not self.bh.batno: return def doProcess(self): r1s = ( ("Monthly","M"), ("Quarterly","3"), ("Bi-Annually","6"), ("Annually","Y")) r2s = (("Yes", "Y"), ("No", "N")) fld = ( (("T",0,0,0),("IRB",r1s),0,"Frequency","", "M","N",self.doFreq,None,None,None), (("T",0,1,0),("IRB",r2s),1,"All Charges","", "N","N",self.doAll,None,None,None), (("T",0,2,0),"INa",9,"2nd Reference","", "","N",self.doRef2,None,None,None), (("T",0,3,0),("IRB",r2s),1,"Invoices","", "N","N",self.doInv,None,None,None)) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) self.df = TartanDialog(self.opts["mf"], eflds=fld, tend=tnd, txit=txt, view=("N","P"), mail=("N","Y")) def doFreq(self, frt, pag, r, c, p, i, w): self.freq = w self.wher = [("dcm_cono", "=", self.opts["conum"]), ("dcm_freq", "=", self.freq), ("dcm_last", "<", self.bh.curdt)] data = self.sql.getRec("drsrcm", where=self.wher) if not data: return "No Valid Recurring Charges" if self.freq == "M": self.mths = 1 elif self.freq == "3": self.mths = 3 elif self.freq == "6": self.mths = 6 else: self.mths = 12 def doAll(self, frt, pag, r, c, p, i, w): self.allc = w def doRef2(self, frt, pag, r, c, p, i, w): self.ref2 = w def doInv(self, frt, pag, r, c, p, i, w): self.inv = w if self.inv == "N": self.df.loadEntry(frt, pag, p+2, data="") return "nd" def doEml(self, frt, pag, r, c, p, i, w): self.eml = w def doEnd(self): self.df.closeProcess() if self.allc == "N": recs = getSingleRecords(self.opts["mf"], "drsrcm", ("dcm_num", "dcm_desc"), where=self.wher) else: recs = self.sql.getRec("drsrcm", where=self.wher) if recs: if self.inv == "Y" and self.df.repeml[1] == "N": self.fpdf = MyFpdf(orientation="L", fmat="A4", name=self.__class__.__name__, head=128) for dcm in recs: num = dcm[self.sql.drsrcm_col.index("dcm_num")] desc = dcm[self.sql.drsrcm_col.index("dcm_desc")] day = dcm[self.sql.drsrcm_col.index("dcm_day")] if day == 30: self.trdt = mthendDate((self.bh.curdt * 100) + 1) else: self.trdt = (self.bh.curdt * 100) + day vat = dcm[self.sql.drsrcm_col.index("dcm_vat")] self.vatrte = getVatRate(self.sql, self.opts["conum"], vat, self.trdt) glac = dcm[self.sql.drsrcm_col.index("dcm_glac")] nxt = self.sql.getRec("drstrn", cols=["max(drt_ref1)"], where=[("drt_cono", "=", self.opts["conum"]), ("drt_ref1", "like", "RC%03i%s" % (num, "%"))], limit=1) if not nxt[0]: nxt = 0 else: nxt = int(nxt[0][5:]) tot_val = 0 tot_vat = 0 rec = self.sql.getRec("drsrct", where=[("dct_cono", "=", self.opts["conum"]), ("dct_num", "=", num), ("dct_start", "<=", self.bh.curdt), ("dct_end", ">=", self.bh.curdt)]) col = self.sql.drsrct_col for dct in rec: self.chain = dct[col.index("dct_chain")] self.acno = dct[col.index("dct_acno")] # Check for Redundancy chk = self.sql.getRec("drsmst", cols=["drm_stat"], where=[("drm_cono", "=", self.opts["conum"]), ("drm_chain", "=", self.chain), ("drm_acno", "=", self.acno)], limit=1) if chk[0] == "X": continue # Check for Valid Period charge = False start = dct[col.index("dct_start")] year = int(start / 100) month = start % 100 while start <= self.bh.curdt: if start == self.bh.curdt: charge = True break month += self.mths if month > 12: year += 1 month -= 12 start = (year * 100) + month if not charge: continue # Create Transactions nxt += 1 self.ref = "RC%03i%04i" % (num, nxt) self.detail = textFormat(dct[col.index("dct_detail")], 73) self.amnt = dct[col.index("dct_amnt")] self.vmnt = round(self.amnt * self.vatrte / 100, 2) self.tmnt = float(ASD(self.amnt) + ASD(self.vmnt)) tot_val = float(ASD(tot_val) + ASD(self.amnt)) tot_vat = float(ASD(tot_vat) + ASD(self.vmnt)) # Debtors (drstrn) self.sql.insRec("drstrn", data=[self.opts["conum"], self.chain, self.acno, 1, self.ref, self.bh.batno, self.trdt, self.ref2, self.tmnt, self.vmnt, self.bh.curdt, self.detail[0], vat, "Y", self.opts["capnm"], self.sysdtw, 0]) if self.inv == "Y": # Create Invoice self.doInvoice() # VAT (ctlvtf) amnt = float(ASD(0) - ASD(self.amnt)) vmnt = float(ASD(0) - ASD(self.vmnt)) data = [self.opts["conum"], vat, "O", self.bh.curdt, "D", 1, self.bh.batno, self.ref, self.trdt, self.acno, self.detail[0], amnt, vmnt, 0, self.opts["capnm"], self.sysdtw, 0] self.sql.insRec("ctlvtf", data=data) if self.glint == "Y": ref = "RC%07i" % num # Update Debtors Control amnt = float(ASD(tot_val) + ASD(tot_vat)) data = (self.opts["conum"], self.drsctl, self.bh.curdt, self.trdt, 1, ref, self.bh.batno, amnt, 0, desc, "", "", 0, self.opts["capnm"], self.sysdtw, 0) self.sql.insRec("gentrn", data=data) # Update Sales Account amnt = float(ASD(0) - ASD(tot_val)) data = (self.opts["conum"], glac, self.bh.curdt, self.trdt, 1, ref, self.bh.batno, amnt, 0, desc, "", "", 0, self.opts["capnm"], self.sysdtw, 0) self.sql.insRec("gentrn", data=data) amnt = float(ASD(0) - ASD(tot_vat)) if amnt: # Update VAT Control data = (self.opts["conum"], self.vatctl, self.bh.curdt, self.trdt, 1, ref, self.bh.batno, amnt, 0, desc, "", "", 0, self.opts["capnm"], self.sysdtw, 0) self.sql.insRec("gentrn", data=data) # Update Recurring Charge (drsrcm) self.sql.updRec("drsrcm", cols=["dcm_last"], data=[self.bh.curdt], where=[("dcm_cono", "=", self.opts["conum"]), ("dcm_num", "=", num), ("dcm_freq", "=", self.freq)]) self.opts["mf"].dbm.commitDbase() if self.inv == "Y" and self.df.repeml[1] == "N": self.doPrint() self.opts["mf"].closeLoop() def doInvoice(self): if self.df.repeml[1] == "Y": self.fpdf = MyFpdf(orientation="L", fmat="A4", name=self.__class__.__name__, head=128) cw = self.fpdf.get_string_width("X") ld = self.fpdf.font[2] ica = CCD(self.tmnt, "SD", 13.2) iva = CCD(float(ASD(self.tmnt) - ASD(self.amnt)), "SD", 13.2) ivr = CCD(self.vatrte, "UD", 5.2) self.drawInvoice(cw, ld) row = 20 for detail in self.detail: row += 1 self.fpdf.drawText(x=22.2*cw, y=row*ld, txt=detail) self.fpdf.drawText(x=97*cw, y=row*ld, txt=ivr.disp) self.fpdf.drawText(x=103*cw, y=row*ld, txt=ica.disp) self.printTotals(cw, ld, ica, iva) if self.df.repeml[1] == "Y": self.doPrint() def drawInvoice(self, cw, ld): self.fpdf.add_page() self.fpdf.setFont("courier", "B", 16) self.fpdf.drawText(x=22*cw, y=1*ld, txt=self.ctm_name) self.fpdf.setFont("courier", "B", 14) self.fpdf.drawText(x=108*cw, y=2*ld, w=16, align="R", txt="Tax Invoice") self.fpdf.setFont("courier", "B", self.fpdf.font[1]) if self.ctm_logo: self.fpdf.image(self.ctm_logo, 45, 3, 138, 28) else: self.fpdf.drawText(x=22*cw, y=2.5*ld, txt=self.ctm_add1) self.fpdf.drawText(x=22*cw, y=3.5*ld, txt=self.ctm_add2) self.fpdf.drawText(x=22*cw, y=4.5*ld, txt=self.ctm_add3) self.fpdf.drawText(x=22*cw, y=5.5*ld, txt=self.ctm_pcode) self.fpdf.drawText(x=54*cw, y=2.5*ld, txt="RegNo: %s" % self.ctm_regno) self.fpdf.drawText(x=54*cw, y=3.5*ld, txt="TaxNo: %s" % self.ctm_taxno) self.fpdf.drawText(x=54*cw, y=4.5*ld, txt="TelNo: %s" % self.ctm_tel) self.fpdf.drawText(x=54*cw, y=5.5*ld, txt="FaxNo: %s" % self.ctm_fax) drm = self.sql.getRec("drsmst", where=[("drm_cono", "=", self.opts["conum"]), ("drm_chain", "=", self.chain), ("drm_acno", "=", self.acno)], limit=1) col = self.sql.drsmst_col self.fpdf.drawText(x=22.5*cw, y=10.5*ld, txt=drm[col.index("drm_name")]) self.fpdf.drawText(x=22.5*cw, y=11.5*ld, txt=drm[col.index("drm_add1")]) self.fpdf.drawText(x=22.5*cw, y=12.5*ld, txt=drm[col.index("drm_add2")]) self.fpdf.drawText(x=22.5*cw, y=13.5*ld, txt=drm[col.index("drm_add3")]) self.fpdf.drawText(x=22.5*cw, y=14.5*ld, txt=drm[col.index("drm_pcod")]) if self.ctm_b_name: dat = "Name: %s" % self.ctm_b_name dat = "%s\nBranch: %s" % (dat, self.ctm_b_branch) dat = "%s\nCode: %s" % (dat, self.ctm_b_ibt) dat = "%s\nAccount: %s\n " % (dat, self.ctm_b_acno) self.fpdf.drawText(x=22.5*cw, y=37*ld, txt=dat, ctyp="M") self.emadd = CCD(drm[col.index("drm_acc_email")], "TX") # Tables r1 = { "margins": ((22.5, 53), (8, 9)), "repeat": (1, 1), "rows": [ [22, 8.5, [[32, 1.5, .8, "Charge To:", False]]], [22, 10, [[32, 5.5]]], [22, 16, [ [9, 1.5, .8, "Acc-Num", True], [20, 1.5, .8, "V.A.T. Number", True], [42, 1.5, .8, "Contact Person", True], [12, 1.5, .8, "Date", True], [11, 1.5, .8, "Inv-Number", True]]], [22, 17.5, [ [9, 1.5, 0, self.acno, True], [20, 1.5, 0, drm[col.index("drm_vatno")], True], [42, 1.5, 0, drm[col.index("drm_sls")]], [12, 1.5, 0, CCD(self.trdt, "D1", 10).disp, True], [11, 1.5, 0, "%10s" % self.ref]]], [22, 19, [ [74, 1.5, .8, "Description", False], [7, 1.5, .8, " Tax-%", False], [13, 1.5, .8, " Value", False]]], [22, 20.5, [ [74, 12.5], [7, 12.5], [13, 12.5]]], [22, 33, [ [11, 1.5, .8, "Taxable"], [12, 1.5], [12, 1.5, .8, "Non-Taxable"], [12, 1.5], [11, 1.5, .8, "Total Tax"], [11, 1.5], [12, 1.5, .8, "Total Value"], [13, 1.5]]]]} if self.ctm_b_name: r1["rows"].extend([ [22, 35, [[32, 1.5, .8, "Banking Details", False]]], [22, 36.5, [[32, 5.5]]]]) doDrawTable(self.fpdf, r1, cw=cw, ld=ld, font=False) def printTotals(self, cw, ld, ica, iva): tot = [0, 0, iva.work, ica.work] if iva.work: tot[0] = float(ASD(ica.work) - ASD(iva.work)) else: tot[1] = ica.work self.fpdf.drawText(x=32*cw, y=33.2*ld, txt=CCD(tot[0],"SD",13.2).disp) self.fpdf.drawText(x=56*cw, y=33.2*ld, txt=CCD(tot[1],"SD",13.2).disp) self.fpdf.drawText(x=78*cw, y=33.2*ld, txt=CCD(tot[2],"SD",13.2).disp) self.fpdf.drawText(x=103*cw, y=33.2*ld, txt=CCD(tot[3],"SD",13.2).disp) def doPrint(self): if not self.fpdf.page: return if self.df.repeml[1] == "Y": self.df.repeml[2] = self.emadd.work key = "%s_%s_%s" % (self.opts["conum"], self.chain, self.acno) else: key = "%s_all_all" % self.opts["conum"] pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, key, ext="pdf") self.fpdf.output(pdfnam, "F") doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header="%s Invoice" % self.opts["conam"], repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) def doExit(self): self.df.closeProcess() self.opts["mf"].closeLoop()
def doEnd(self): self.df.closeProcess() # Get data cards = [] whr = [ ("bft_cono", "=", self.opts["conum"]), ("bft_fmat", "=", self.fmat), ("bft_type", "=", self.ftyp), ("bft_date", "=", self.date)] if self.forms == 4: maxf = 8 else: maxf = 3 whr.append(("bft_position", "=", 1)) col = ["bft_team", "bft_skip", "bft_player"] whr.extend([ ("bfs_cono=bft_cono",), ("bfs_fmat=bft_fmat",), ("bfs_code=bft_team",), ("bfs_league", "=", "M")]) recs = self.sql.getRec(tables=["bwlflt", "bwlfls"], cols=col, where=whr, order="bft_team, bft_skip, bft_position asc") for rec in recs: match = self.sql.getRec("bwlflm", cols=["bfm_opps", "bfm_venue"], where=[("bfm_cono", "=", self.opts["conum"]), ("bfm_fmat", "=", self.fmat), ("bfm_type", "=", self.ftyp), ("bfm_date", "=", self.date), ("bfm_team", "=", rec[0])], limit=1) team = self.sql.getRec("bwlfls", cols=["bfs_desc"], where=[("bfs_cono", "=", self.opts["conum"]), ("bfs_fmat", "=", self.fmat), ("bfs_code", "=", rec[0])], limit=1) opp = self.sql.getRec(tables=["bwlflo", "bwlclb"], cols=["bfo_desc", "bcc_name"], where=[("bfo_cono", "=", self.opts["conum"]), ("bfo_fmat", "=", self.fmat), ("bfo_code", "=", match[0]), ("bcc_code=bfo_club",)], limit=1) skp = self.sql.getRec("bwltab", cols=["btb_surname", "btb_names"], where=[("btb_cono", "=", self.opts["conum"]), ("btb_tab", "=", rec[1])], limit=1) if self.forms == 4: plr = self.sql.getRec(tables=["bwltab", "bwlflt"], cols=["btb_surname", "btb_names", "bft_position"], where=[("bft_cono", "=", self.opts["conum"]), ("bft_fmat", "=", self.fmat), ("bft_date", "=", self.date), ("bft_skip", "=", rec[1]), ("bft_player", "=", rec[2]), ("btb_cono=bft_cono",), ("btb_tab=bft_player",)], limit=1) else: plr = self.sql.getRec(tables=["bwltab", "bwlflt"], cols=["btb_surname", "btb_names"], where=[("bft_cono", "=", self.opts["conum"]), ("bft_fmat", "=", self.fmat), ("bft_date", "=", self.date), ("bft_skip", "=", rec[1]), ("btb_cono=bft_cono",), ("btb_tab=bft_player",)], order="bft_position") if match[1] == "H": ven = self.opts["conam"] else: ven = "%s" % opp[1] if self.forms == 4: cards.append([team[0], opp[0], ven, self.getName(skp[0], skp[1]), self.getName(plr[0], plr[1]), plr[2]]) else: card = [team[0], opp[0], ven, "%s, %s" % (skp[0], skp[1])] for p in plr: card.append(self.getName(p[0], p[1])) cards.append(card) while len(cards) % maxf: if self.forms == 4: cards.append(["", "", "", "", "", 0]) else: cards.append(["", "", "", "", "", "", "", ""]) # Print pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, "assess_%s" % self.date, ext="pdf") fpdf = MyFpdf(name=self.__class__.__name__, head=90) cw = fpdf.get_string_width("X") ld = 4.5 if self.forms == 4: rr = { "margins": ((2.5, 47.5), (1.5, 15.5)), "repeat": (2, 4), "rows": ( (2.5, 1.5, 47.5, 14.5), (2.5, 8.5, ( (8, 1.5, .8, "Title", True), (12, 1.5, .8, "Out of %s" % self.rate, True), (27.5, 1.5, .8, "Remarks", True))), (2.5, 10, ( (8, 1.5, .9, ("Skip", "Third", "Second", "Lead")), (12, 1.5)), 4))} else: rr = { "margins": ((2.5, 47.5), (1.5, 20.5)), "repeat": (1, 3), "rows": ( (2.5, 1.5, 95.1, 19.5), (2.5, 11, ( (10, 2, .8, "Position"), (20, 2, .8, "Name"), (12, 2, .8, "Rating 1-%s" % self.rate), (7, 2, .8, "Initial"), (46.1, 2, .8, "Remarks"))), (2.5, 13, ( (10, 2, .9, ("Skip", "Third", "Second", "Lead")), (20, 2), (12, 2), (7, 2)), 4))} if self.forms == 4: ppad = 1 h1 = "Assessment Form" yy = [2, 18, 34, 50] else: ppad = 1.5 h1 = "Assessment Form for %s" % self.disp yy = [2.5, 23.5, 44.5] for x in range(0, len(cards), maxf): fpdf.add_page() last, table = doDrawTable(fpdf, rr, ppad, spad=2, cw=cw, ld=ld) for y in range(maxf): card = cards[x + y] if self.forms == 4: if y % 2: xx = 53 * cw else: xx = 5 * cw sx = xx fpdf.setFont("helvetica", "B", 12) fpdf.set_y((yy[int(y / 2)]) * ld) fpdf.drawText(x=xx, w=45 * cw, align="C", txt=h1) fpdf.setFont("helvetica", "B", 8) h2 = "%s vs %s at %s on %s" % (card[0], card[1], card[2], self.disp) fpdf.drawText(x=xx, w=45 * cw, align="C", txt=h2) fpdf.setFont("helvetica", "B", 10) h3 = "Skip: %s Player: %s" % (card[3], card[4]) fpdf.drawText(x=xx, w=45 * cw, align="C", txt=h3) fpdf.drawText(h=2) fpdf.setFont("helvetica", "B", 10) else: xx = 3 * cw sx = 25 * cw fpdf.setFont("helvetica", "B", 18) fpdf.set_y((yy[y]) * ld) fpdf.drawText(x=xx, w=90 * cw, h=10, align="C", txt=h1) fpdf.setFont("helvetica", "B", 16) h2 = "%s vs %s at %s on %s" % (card[0], card[1], card[2], self.disp) fpdf.drawText(x=xx, w=90 * cw, h=8, align="C", txt=h2) fpdf.drawText() fpdf.setFont("helvetica", "B", 12) w1 = fpdf.get_string_width("XXXXXXXXX") w2 = fpdf.get_string_width("XXXXX") fpdf.drawText(x=sx + (7 * cw), w=w1, txt="Shots-For", border=1, fill=1, ln=0) fpdf.drawText(w=w1, txt="Shots-Agt", border=1, fill=1, ln=0) fpdf.drawText(w=w1, txt=" Points", border=1, fill=1, ln=0) fpdf.drawText(w=w2, txt="Total", border=1, fill=1) if self.sets == "Y": for s in range(1, 3): fpdf.drawText(x=sx, h=5, txt="Set %s" % s, ln=0) fpdf.drawText(x=sx + (7 * cw), w=w1, h=5, txt="", border=1, ln=0) fpdf.drawText(w=w1, h=5, txt="", border=1, ln=0) fpdf.drawText(w=w1, h=5, txt="", border=1, ln=0) if s == 1: fpdf.drawText(w=w2, h=5, txt="", border="LR") else: fpdf.drawText(w=w2, h=5, txt="", border="LRB") else: fpdf.drawText(x=sx + (7 * cw), w=w1, h=5, txt="", border=1, ln=0) fpdf.drawText(w=w1, h=5, txt="", border=1, ln=0) fpdf.drawText(w=w1, h=5, txt="", border=1, ln=0) fpdf.drawText(w=w2, h=5, txt="", border=1) if self.forms == 1: fpdf.setFont("helvetica", "", 12) r = (y * 21) + 4.5 for z in range(4): fpdf.set_xy(13.5 * cw, (9 + (z * 2) + r) * ld) fpdf.drawText(txt=card[4 + z]) elif self.self == "N" and card[5] in (1,2,3,4): if y % 2: posx = 127 else: posx = 25 if card[5] == 1: posy = fpdf.get_y() + 10 elif card[5] == 2: posy = fpdf.get_y() + 16.75 elif card[5] == 3: posy = fpdf.get_y() + 23.5 else: posy = fpdf.get_y() + 30.25 fpdf.drawText(x=posx, y=posy, txt="XXXXXXX") fpdf.output(pdfnam, "F") head = "Match Assessment Forms for %s" % self.disp doPrinter(mf=self.opts["mf"], header=head, pdfnam=pdfnam, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) self.opts["mf"].closeLoop()
class bc3080(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): if "args" in self.opts: self.ctyp = self.opts["args"][0] self.cnam = self.opts["args"][1] self.card = False self.qty = 1 self.doEnd() else: self.mainProcess() if "wait" in self.opts: self.df.mstFrame.wait_window() else: self.opts["mf"].startLoop() def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwltyp", "bwlpts", "bwlnot"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) bwlctl = gc.getCtl("bwlctl", self.opts["conum"]) if not bwlctl: return self.fromad = bwlctl["ctb_emadd"] t = time.localtime() self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t) self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png") if not os.path.exists(self.image): getImage("bowls", fle=self.image) if not os.path.exists(self.image): self.image = None self.card = True return True def mainProcess(self): self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]), "Competition Format") com = { "stype": "R", "tables": ("bwlcmp",), "cols": ( ("bcm_code", "", 0, "Cod"), ("bcm_name", "", 0, "Name", "Y"), ("bcm_date", "", 0, "Date")), "where": [("bcm_cono", "=", self.opts["conum"])]} r1s = (("A4 Page", "P"), ("A6 Card", "C")) fld = ( (("T",0,0,0),"I@bcm_code",0,"","", "","Y",self.doCmpCod,com,None,("notzero",)), (("T",0,0,0),"ONA",30,""), (("T",0,1,0),"ITV",(50,10),"Notes","", "","N",self.doNotes,None,None,None,None,"""Enter All Additional Rules and Notes for the Competition e.g. what to do in these cases: Trial Ends - Only 1 trial end per game. Burnt Ends - Replay the end."""), (("T",0,2,0),("IRB",r1s),0,"Paper Type","", "P","N",self.doPaper,None,None,None), (("T",0,3,0),"IUI",2,"Quantity","", 1,"N",self.doQty,None,None,("notzero",))) but = (("Edit Notes", None, self.doEdit, 0, ("T",0,4), ("T",0,5)),) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) self.df = TartanDialog(self.opts["mf"], title=self.tit, eflds=fld, butt=but, tend=tnd, txit=txt, view=("N","V"), mail=("Y","N")) def doCmpCod(self, frt, pag, r, c, p, i, w): chk = self.sql.getRec("bwlcmp", cols=["bcm_name", "bcm_type"], where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=", w)], limit=1) if not chk: return "Invalid Competition Code" self.ccod = w self.cnam = chk[0] self.ctyp = chk[1] self.df.loadEntry(frt, pag, p+1, data=self.cnam) nte = self.sql.getRec("bwlnot", where=[("bcn_cono", "=", self.opts["conum"]), ("bcn_ccod", "=", self.ccod)], limit=1) if nte: self.notes = nte[2] self.df.loadEntry(frt, pag, p+2, self.notes) return "sk2" def doEdit(self): self.df.focusField("T", 0, 3, tag=False) def doNotes(self, frt, pag, r, c, p, i, w): self.notes = w def doPaper(self, frt, pag, r, c, p, i, w): if w == "P": self.card = False else: self.card = True def doQty(self, frt, pag, r, c, p, i, w): self.qty = w def doEnd(self): if "args" not in self.opts: hdr = self.tit prt = copyList(self.df.repprt) eml = copyList(self.df.repeml) self.df.closeProcess() else: hdr = "%03i %s - %s" % (self.opts["conum"], self.opts["conam"], "Competition Format") prt = ["Y", "V", "view"] eml = None self.drawFormat() pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") doPrinter(mf=self.opts["mf"], pdfnam=pdfnam, header=hdr, repprt=prt, fromad=self.fromad, repeml=eml) if "wait" not in self.opts: self.opts["mf"].closeLoop() def drawFormat(self): whr = [ ("bct_cono", "=", self.opts["conum"]), ("bct_code", "=", self.ctyp)] rec = self.sql.getRec("bwltyp", where=whr, limit=1) ldic = {} for col in self.sql.bwltyp_col[3:]: ldic[col] = rec[self.sql.bwltyp_col.index(col)] whr = [ ("bcp_cono", "=", self.opts["conum"]), ("bcp_code", "=", self.ctyp)] rec = self.sql.getRec("bwlpts", where=whr) for r in rec: if r[self.sql.bwlpts_col.index("bcp_ptyp")] == "D": ptyp = "drawn" else: ptyp = "svs" ldic[ptyp] = {} for col in self.sql.bwlpts_col[3:]: ldic[ptyp][col] = r[self.sql.bwlpts_col.index(col)] if self.card: self.fpdf = MyFpdf(auto=True) self.fpdf.set_margins(55, 5, 55) self.fpdf.c_margin = self.fpdf.c_margin * 2 self.fpdf.set_font("Arial","",8) h = 3.5 else: self.fpdf = MyFpdf(auto=True) self.fpdf.set_font("Arial","",14) h = 6 self.fpdf.header = self.pageHeading cwth = self.fpdf.get_string_width("X") x1 = self.fpdf.l_margin + (cwth * 20) x2 = self.fpdf.l_margin + (cwth * 22) for page in range(self.qty): self.fpdf.add_page() self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_cfmat"][4], h=h, ln=0) if ldic["bct_cfmat"] == "T": txt = "Tournament" elif ldic["bct_cfmat"] in ("D", "K"): txt = "Knockout" elif ldic["bct_cfmat"] == "R": txt = "Round Robin" else: txt = "Match" self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_tsize"][4], h=h, ln=0) self.fpdf.drawText(txt=ldic["bct_tsize"], x=x1, h=h, ctyp="M") #if ldic["bct_cfmat"] in ("D", "K", "R"): # return self.fpdf.drawText(txt="Draw", h=h, ln=0) if ldic["bct_drawn"] == ldic["bct_games"]: txt = "All Games will be Random Draws." else: if ldic["bct_drawn"] == 1: txt = "The First Game will be a Random Draw and "\ "thereafter Strength v Strength." else: txt = "The First %s Games will be Random Draws and "\ "thereafter Strength v Strength." % ldic["bct_drawn"] self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") if ldic["bct_games"]: self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_games"][4], h=h, ln=0) self.fpdf.drawText(txt=ldic["bct_games"], x=x1, h=h, ctyp="M") self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_ends"][4],h=h,ln=0) self.fpdf.drawText(txt=ldic["bct_ends"], x=x1, h=h, ctyp="M") if ldic["bct_grgame"]: self.fpdf.drawText(txt="Groups", h=h, ln=0) txt = "Teams will be Split into Groups After Game %s." % \ ldic["bct_grgame"] self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") if ldic["bct_adjust"] == "Y": txt = "With the Exception of Group A, the Scores will be "\ "Adjusted as follows:" self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") if ldic["bct_expunge"]: gms = ldic["bct_expunge"].split(",") if len(gms) == 1: txt = "Game %s will be Expunged" % gms[0] else: txt = "Games %s" % gms[0] for n, g in enumerate(gms[1:]): if n == len(gms) - 2: txt = "%s and %s" % (txt, g) else: txt = "%s, %s" % (txt, g) txt = "%s will be Expunged." % txt self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M") if ldic["bct_percent"]: if ldic["bct_expunge"]: txt = "The Balance of the Games" else: txt = "All Games" txt = "%s will Retain %s%s of their score." % (txt, ldic["bct_percent"], "%") self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M") # Points self.fpdf.drawText(h=h) if ldic["bct_pdiff"] == "Y": nums = ["drawn", "svs"] else: nums = ["drawn"] for ptyp in nums: if ldic["bct_pdiff"] == "N": txt = "Scoring for All Games" elif ptyp == "drawn": txt = "Scoring for Drawn Games" else: txt = "Scoring for S v S Games" self.fpdf.drawText(txt=txt, h=h) self.fpdf.underLine(h=h, txt=txt) if ldic[ptyp]["bcp_sends"]: self.fpdf.drawText(txt="Skins", h=h, ln=0) self.fpdf.drawText(txt="Each Set of %s Ends will "\ "Constitute a Skin." % ldic[ptyp]["bcp_sends"], x=x1, h=h, ctyp="M") self.fpdf.drawText(txt="Points", h=h, ln=0) txt = "" pts = 0 if ldic[ptyp]["bcp_e_points"]: if ldic[ptyp]["bcp_e_points"] == 1: txt = "%s Point per End" % ldic[ptyp]["bcp_e_points"] else: txt = "%s Points per End" % ldic[ptyp]["bcp_e_points"] self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") pts += (ldic[ptyp]["bcp_e_points"] * ldic["bct_ends"]) if ldic[ptyp]["bcp_s_points"]: if ldic[ptyp]["bcp_s_points"] == 1: txt = "%s Point per Skin" % ldic[ptyp]["bcp_s_points"] else: txt = "%s Points per Skin" % ldic[ptyp]["bcp_s_points"] self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") pts += (ldic[ptyp]["bcp_s_points"] * int(ldic["bct_ends"] / ldic[ptyp]["bcp_sends"])) if ldic[ptyp]["bcp_g_points"]: if ldic[ptyp]["bcp_g_points"] == 1: txt = "%s Point per Game" % ldic[ptyp]["bcp_g_points"] else: txt = "%s Points per Game" % ldic[ptyp]["bcp_g_points"] self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") pts += ldic[ptyp]["bcp_g_points"] if ldic[ptyp]["bcp_bonus"] == "Y": txt = "1 Bonus Point will be Awarded as Follows:" self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") txt = "Winning by %s or More Shots or" % \ (ldic[ptyp]["bcp_win_by"] + 1) self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M") txt = "Losing by %s or Less Shots" % \ (ldic[ptyp]["bcp_lose_by"] - 1) self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M") pts += 1 if pts: if pts == 1: txt = "Point" else: txt = "Points" txt = "Therefore a Maximum of %s %s per Game." % (pts, txt) self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M") if self.notes: txt = "Notes" self.fpdf.drawText(h=h) self.fpdf.drawText(txt=txt, h=h) self.fpdf.underLine(h=h, txt=txt) self.fpdf.drawText(txt=self.notes, h=h, ctyp="M") self.sql.delRec("bwlnot", where=[("bcn_cono", "=", self.opts["conum"]), ("bcn_ccod", "=", self.ccod)]) self.sql.insRec("bwlnot", data=[self.opts["conum"], self.ccod, self.notes]) self.opts["mf"].dbm.commitDbase() def pageHeading(self): if self.card: self.fpdf.set_fill_color(220) self.fpdf.set_font("Arial","B",12) self.fpdf.drawText("Competiton Format and Points", h=6, align="C", border="TLRB", fill=True) self.fpdf.set_line_width(1) self.fpdf.rect(self.fpdf.l_margin, self.fpdf.t_margin, 100, 140) self.fpdf.set_line_width(0) self.fpdf.ln(4) return if self.image: if self.card: self.fpdf.image(self.image, x=10, y=10, w=7, h=5) else: self.fpdf.image(self.image, x=10, y=10, w=15, h=11) self.fpdf.set_font("Arial","B",15) self.fpdf.cell(20) self.fpdf.cell(0,10,"Format Sheet for the %s" % self.cnam,1,0,"C") self.fpdf.ln(20) def doExit(self): self.df.closeProcess() if "wait" not in self.opts: self.opts["mf"].closeLoop()
class wg3010(object): def __init__(self, **opts): self.opts = opts if self.setVariables(): self.mainProcess() self.opts["mf"].startLoop() def setVariables(self): gc = GetCtl(self.opts["mf"]) wagctl = gc.getCtl("wagctl", self.opts["conum"]) if not wagctl: return self.fromad = wagctl["ctw_emadd"] return True def mainProcess(self): dep = { "stype": "R", "tables": ("ctldep",), "cols": ( ("dep_code", "", 0, "Cod"), ("dep_name", "", 0, "Name", "Y")), "where": [("dep_cono", "=", self.opts["conum"])]} r1s = (("List","L"), ("Card","C")) fld = ( (("T",0,0,0),("IRB",r1s),0,"Report Type","", "L","N",self.doRptTyp,None,None,None,None), (("T",0,1,0),"I@dep_code",0,"Department Code","", "","N",self.doDepCod,dep,None,None,None)) tnd = ((self.doEnd,"y"), ) txt = (self.doExit, ) self.df = TartanDialog(self.opts["mf"], eflds=fld, tend=tnd, txit=txt, view=("Y","V"), mail=("Y","Y")) def doRptTyp(self, frt, pag, r, c, p, i, w): self.typ = w if len(self.df.topEntry[0][2]) > 3: if self.typ == "C": state = "hide" else: state = "show" if len(self.df.topEntry[0][2]) == 5: self.df.setWidget(self.df.topEntry[0][2][4][0], state=state) self.df.setWidget(self.df.topEntry[0][2][3][0], state=state) def doDepCod(self, frt, pag, r, c, p, i, w): self.dep = w def doEnd(self): self.df.closeProcess() tabs = ["wagmst"] self.head = "Salaries and Wages - Employee Master Report" whr = [("wgm_cono", "=", self.opts["conum"])] if self.dep: whr.append(("wgm_dept", "=", self.dep)) opts = "Dept: %s" % self.dep else: opts = None odr = "wgm_empno" if self.typ == "C": sql = Sql(self.opts["mf"].dbm, "wagmst", prog=self.__class__.__name__) recs = sql.getRec(tables=tabs, where=whr) if not recs: self.closeProcess() return col = sql.wagmst_col dic = sql.wagmst_dic self.fpdf = MyFpdf(name=self.__class__.__name__, head=80, auto=True) self.fpdf.header = self.doHead self.fpdf.set_font("Courier", "B", 12) cwth = self.fpdf.get_string_width("X") for rec in recs: self.fpdf.add_page() max1, max2 = 0, 0 for c in col[:-1]: if max1 < len(dic[c][4]): max1 = len(dic[c][4]) if max2 < int(dic[c][3]): max2 = int(dic[c][3]) self.fpdf.set_font("Courier", "B", 12) self.fpdf.drawText(h=5, txt="%-20s" % dic[c][4], ln=0) self.fpdf.set_font("Courier", "", 12) if dic[c][4] == "Pay Frequency": if rec[col.index(c)] == "F": txt = "Fortnightly" elif rec[col.index(c)] == "M": txt = "Monthly" else: txt = "Weekly" self.fpdf.drawText(h=5, x=cwth*40, txt=txt) elif dic[c][4] == "Pay Type": if rec[col.index(c)] == "C": txt = "Cash" elif rec[col.index(c)] == "Q": txt = "Cheque" else: txt = "Electronic" self.fpdf.drawText(h=5, x=cwth*40, txt=txt) elif dic[c][4] == "Account Type": if rec[col.index(c)] == "1": txt = "Current" elif rec[col.index(c)] == "2": txt = "Transmission" else: txt = "Savings" self.fpdf.drawText(h=5, x=cwth*40, txt=txt) else: self.fpdf.drawText(h=5, x=cwth*40, txt=CCD(rec[col.index(c)], dic[c][2], dic[c][3]).disp) pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=self.head, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) else: cols = [ ["wgm_empno", "UI", 5, "EmpNo", "y"], ["wgm_sname", "NA", 30, "Surname", "y"], ["wgm_fname", "NA", 30, "Names", "y"], ["wgm_freq", "UA", 1, "F", "y"], ["wgm_start", "D1", 10, "Comm-Date", "y"], ["wgm_term", "d1", 10, "Term-Date", "y"]] RepPrt(self.opts["mf"], conum=self.opts["conum"], conam=self.opts["conam"], name=self.__class__.__name__, tables=tabs, heads=[self.head], cols=cols, where=whr, order=odr, opts=opts, repprt=self.df.repprt, repeml=self.df.repeml, fromad=self.fromad) self.closeProcess() def doHead(self): cdes = "%-30s" % self.opts["conam"] self.fpdf.drawText(cdes, font=["courier", "B", 24]) self.fpdf.drawText(font=["courier", "B", 14]) self.fpdf.drawText(self.head, font=["courier", "B", 16]) self.fpdf.underLine(txt=self.head) def doExit(self): self.df.closeProcess() self.closeProcess() def closeProcess(self): self.opts["mf"].closeLoop()