class sc3010(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, "scpcmp", prog=self.__class__.__name__) 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": ("scpcmp",), "cols": ( ("scp_ccod", "", 0, "Cod"), ("scp_name", "", 0, "Name", "Y")), "where": [("scp_cono", "=", self.opts["conum"])]} fld = ( (("T",0,0,0),"I@scp_ccod",0,"Code","", "","N",self.doCmpCod,com,None,("notzero",)), (("T",0,0,0),"ONA",30,"")) tnd = ((self.doEnd,"y"),) txt = (self.doExit,) self.df = TartanDialog(self.opts["mf"], tops=False, eflds=fld, tend=tnd, txit=txt, view=("N","V")) def doCmpCod(self, frt, pag, r, c, p, i, w): chk = self.sql.getRec("scpcmp", cols=["scp_name"], where=[("scp_cono", "=", self.opts["conum"]), ("scp_ccod", "=", 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 doEnd(self): self.df.closeProcess() col = ["scm_scod", "scm_surname", "scm_names", "scm_gender", "scc_name", "scm_phone"] whr = [ ("sce_cono", "=", self.opts["conum"]), ("sce_ccod", "=", self.ccod), ("scm_cono=sce_cono",), ("scm_scod=sce_scod",), ("scc_club=scm_club",)] recs = self.sql.getRec(tables=["scpent", "scpmem", "scpclb"], cols=col, where=whr, order="scm_surname") if recs: self.fpdf = MyFpdf(auto=True, name="sc3010", head=90) self.fpdf.header = self.doHead self.fpdf.add_page() cwth = self.fpdf.cwth for num, rec in enumerate(recs): self.fpdf.drawText(txt="%6s" % rec[0], w=cwth*7, h=5, ln=0) nm = rec[1].strip() + ", %s" % rec[2].split()[0] self.fpdf.drawText(txt=nm, w=cwth*31, h=5, ln=0) self.fpdf.drawText(txt=rec[3], w=cwth*2, h=5, ln=0) self.fpdf.drawText(txt=rec[4], w=cwth*31, h=5, ln=0) ph = rec[5].replace(" ", "").strip() self.fpdf.drawText(txt=ph, w=cwth*16, h=5, ln=1) 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, repprt=self.df.repprt, 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.setFont(style="B") self.fpdf.cell(0, 5, "%-6s %-30s %-1s %-30s %-15s" % \ ("Reg-No", "Name", "G", "Club", "Contact"), "B") self.fpdf.ln(5) def doExit(self): self.df.closeProcess() self.opts["mf"].closeLoop()
class bs3010(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, ["bksmst", "bksaut", "bksown"], prog=self.__class__.__name__) if self.sql.error: return t = time.localtime() self.curdt = time.strftime("%Y-%m", t) self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "books.png") if not os.path.exists(self.image): getImage("books", fle=self.image) if not os.path.exists(self.image): self.image = None return True def mainProcess(self): lst = { "stype": "R", "tables": ("bksmst", ), "cols": (("bmf_mnth", "", 0, "Month"), ), "where": [("bmf_cono", "=", self.opts["conum"])], "group": "bmf_mnth", "order": "bmf_mnth" } r1s = (("All", "A"), ("Current", "C"), ("Removed", "R")) r2s = (("Title", "T"), ("Date", "D"), ("Author", "A"), ("Owner", "O")) fld = ((("T", 0, 0, 0), "ID2", 7, "Last Meeting", "", "", "N", self.doLast, lst, None, ("efld", )), (("T", 0, 1, 0), ("IRB", r1s), 0, "Status", "", "A", "N", self.doStatus, None, None, None), (("T", 0, 2, 0), ("IRB", r2s), 0, "Order", "", "T", "N", self.doOrder, 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", "Y")) def doLast(self, frt, pag, r, c, p, i, w): self.last = w self.new = False def doStatus(self, frt, pag, r, c, p, i, w): self.status = w def doOrder(self, frt, pag, r, c, p, i, w): self.order = w def doEnd(self): self.df.closeProcess() if self.df.repeml[1] == "Y": if not self.df.repeml[2]: owns = self.sql.getRec("bksown", cols=["bof_mail"], where=[("bof_mail", "<>", ""), ("bof_stat", "=", "C")]) adds = None for own in owns: if not adds: adds = own[0] else: adds = "%s,%s" % (adds, own[0]) self.df.repeml[2] = adds if not self.df.repeml[3]: self.df.repeml[3] = """Dear Member Attached please find the latest list of books. All books which came onto the list at the last meeting are highlighted and, if available, a precis will be printed at the end. Thanks and Regards. """ tab = ["bksmst", "bksaut", "bksown"] col = [ "bmf_stat", "bmf_titl", "bmf_code", "baf_snam", "baf_fnam", "bmf_mnth", "bof_fnam", "bof_snam" ] odr = "" if self.status == "C": whr = [("bmf_stat", "=", "C")] elif self.status == "R": whr = [("bmf_stat", "=", "X")] else: whr = [] odr = "bmf_stat" whr.extend([("baf_code=bmf_auth", ), ("bof_code=bmf_ownr", )]) if self.order == "T": if odr: odr = "%s, bmf_titl" % odr else: odr = "bmf_titl" elif self.order == "D": if odr: odr = "%s, bmf_mnth, bmf_titl" % odr else: odr = "bmf_mnth, bmf_titl" elif self.order == "A": if odr: odr = "%s, baf_snam, baf_fnam, bmf_titl" % odr else: odr = "baf_snam, baf_fnam, bmf_titl" elif self.order == "O": if odr: odr = "%s, bmf_ownr, bmf_titl" % odr else: odr = "bmf_ownr, bmf_titl" recs = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr) if not recs: showError(self.opts["mf"].body, "Selection Error", "No Records Selected") self.opts["mf"].closeLoop() return self.fpdf = MyFpdf(name="bs3010", head=90, auto=True) self.fpdf.header = self.pageHeading self.stat = recs[0][0] self.fpdf.add_page() new = [] for rec in recs: stat = CCD(rec[0], "UA", 1).disp if stat != self.stat: self.stat = stat self.fpdf.add_page() titl = CCD(rec[1], "NA", 30).disp code = CCD(rec[2], "UI", 4).disp auth = CCD("%s, %s" % (rec[3], rec[4]), "NA", 30).disp mnth = CCD(rec[5], "D2", 7).disp ownr = CCD("%s %s" % (rec[6], rec[7][0]), "NA", 12).disp if rec[5] < self.last: fill = 0 else: new.append([auth, titl]) fill = 1 self.fpdf.drawText("%1s %30s %4s %30s %7s %10s" % (stat, titl, code, auth, mnth, ownr), h=5, fill=fill) if new: sp = SplashScreen( self.opts["mf"].body, "Preparing Summary of New Books ... Please Wait") self.new = True self.fpdf.add_page() for book in new: try: if self.fpdf.get_y() > 260: self.fpdf.add_page() desc = self.getDesc(book) if desc: w = self.fpdf.cwth * 9 desc = desc.rstrip().encode("latin-1", "ignore").decode( "latin-1", "ignore") self.fpdf.drawText(w=w, txt="Title: ", font="B", ln=0) self.fpdf.drawText(txt=book[1].rstrip(), font="I") self.fpdf.drawText(w=w, txt="Author: ", font="B", ln=0) self.fpdf.drawText(txt=book[0].rstrip(), font="I") self.fpdf.drawText(w=w, txt="Details: ", font="B", ln=0) self.fpdf.drawText(txt=desc, font="I", ctyp="M") if book != new[-1]: self.fpdf.drawText() except: pass sp.closeSplash() pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") head = "Book List as at %s" % (self.curdt) doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=head, repprt=self.df.repprt, repeml=self.df.repeml) self.opts["mf"].closeLoop() def pageHeading(self, new=False): self.fpdf.setFont("Arial", "B", 15) x = self.fpdf.get_x() if self.image: self.fpdf.image(self.image, 11, 10, 15, 20) self.fpdf.image(self.image, 185, 10, 15, 20) self.fpdf.cell(20) self.fpdf.set_x(x) self.fpdf.cell(0, 10, self.opts["conam"], "TLR", 1, "C") if self.new: txt = "Summary of New Books" elif self.stat == "C": txt = "Current Books as at %s" % self.curdt else: txt = "Removed Books as at %s" % self.curdt self.fpdf.cell(0, 10, txt, "LRB", 1, "C") self.fpdf.ln(8) self.fpdf.setFont(style="B") if not self.new: self.fpdf.cell( 0, 5, "%-1s %-30s %-4s %-30s %-7s %-12s" % ("S", "Title", "Code", "Author", "Mth-Rec", "Owner"), "B") self.fpdf.ln(5) def getDesc(self, book): auth = book[0].strip().lower() titl = book[1].strip().lower().replace(",", "") if titl[:4] == "the ": titl = titl[4:] elif titl[-4:] == " the": titl = titl[:-4] get = requests.get("https://www.googleapis.com/books/v1/volumes?q="\ "{intitle:'%s'+inauthor:'%s'" % (titl, auth), timeout=5) if get.status_code == 200 and get.json()["totalItems"]: ok = False for item in get.json()["items"]: tita = titl.lower().\ replace("the ","").replace(", the", "") titb = item["volumeInfo"]["title"].lower().\ replace("the ","").replace(", the", "") if titb.count(tita): if "description" in item["volumeInfo"]: ok = True break if ok: return item["volumeInfo"]["description"] 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()
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()
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()