示例#1
0
class ml3040(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            if "args" in self.opts:
                self.tname = self.stpl
                self.mesno = 0
                self.doEnd()
            else:
                self.mainProcess()
                if "wait" in self.opts:
                    self.df.mstFrame.wait_window()
                else:
                    self.opts["mf"].startLoop()

    def setVariables(self):
        gc = GetCtl(self.opts["mf"])
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        memctl = gc.getCtl("memctl", self.opts["conum"])
        if not memctl:
            return
        self.ldays = memctl["mcm_ldays"]
        self.lme = memctl["mcm_lme"]
        self.stpl = memctl["mcm_sttpl"]
        self.fromad = memctl["mcm_emadd"]
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmes", "ctlmst", "memmst", "memtrn", "memadd", "memcat",
            "memctc", "memctp", "memctk", "memkon", "memlnk", "tplmst"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        yy = int(self.lme / 10000)
        mm = (int(self.lme / 100) % 100) + 1
        while mm > 12:
            yy += 1
            mm -= 12
        self.nme = mthendDate((yy * 10000) + (mm * 100) + 1)
        mm += 1
        while mm > 12:
            yy += 1
            mm -= 12
        self.nne = mthendDate((yy * 10000) + (mm * 100) + 1)
        self.trtypes = []
        for t in mltrtp:
            self.trtypes.append(t[0])
        return True

    def mainProcess(self):
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "R"), ("tpm_system", "=", "MEM")],
            "order":
            "tpm_tname"
        }
        self.mlm = {
            "stype":
            "R",
            "tables": ("memmst", ),
            "cols":
            (("mlm_memno", "", 0, "Mem-No"), ("mlm_oldno", "", 0, "Old-No"),
             ("mlm_idnum", "", 0, "Identity-Numb"), ("mlm_gender", "", 0, "G"),
             ("mlm_state", "", 0, "S"), ("mlm_surname", "", 0, "Surname", "Y"),
             ("mlm_names", "", 0, "Names", "F")),
            "where": [],
            "order":
            "mlm_surname, mlm_names",
            "sort":
            False
        }
        mss = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": (("mss_message", "", 0, "Num"), ("mss_detail", "NA", 50,
                                                     "Details")),
            "where": [("mss_system", "=", "MEM")],
            "order":
            "mss_message"
        }
        r1s = (("All", "Z"), ("Active", "A"), ("Deceased", "D"),
               ("Inactive", "I"), ("Resigned", "R"), ("Suspended",
                                                      "S"), ("Defaulted", "X"))
        r2s = (("Yes", "Y"), ("Range", "R"), ("Singles", "S"),
               ("Print Only", "P"), ("Email Only", "E"))
        r3s = (("Yes", "Y"), ("No", "N"))
        r4s = (("Yes", "Y"), ("No", "N"), ("Current", "C"))
        r5s = (("Number", "N"), ("Surname", "M"))
        fld = ((("T", 0, 0, 0), "INA", 20, "Template Name", "", self.stpl, "Y",
                self.doTplNam, tpm, None,
                None), (("T", 0, 1, 0), ("IRB", r1s), 0, "Status", "", "A",
                        "Y", self.doStatus, None, None, None),
               (("T", 0, 2, 0), ("IRB", r2s), 0, "Whole File", "", "Y", "Y",
                self.doWhole, None, None, None),
               (("T", 0, 3, 0), "IUI", 6, "Member Start", "Starting Number", 1,
                "Y", self.doMember, self.mlm, None,
                None), (("T", 0, 3, 0), "IUI", 6, "End", "Ending Number",
                        999999, "Y", self.doMember, self.mlm, None, None),
               (("T", 0, 4, 0), ("IRB", r3s), 0, "Current Year Only", "", "N",
                "Y", self.doCurrent, None, None,
                None), (("T", 0, 5, 0), ("IRB", r4s), 0, "Zero Balances", "",
                        "C", "Y", self.doZeros, None, None, None),
               (("T", 0, 6, 0), ("IRB", r3s), 0, "Paid Transactions", "", "Y",
                "Y", self.doPaid, None, None,
                None), (("T", 0, 7, 0), ("IRB", r3s), 0, "Minus Balances", "",
                        "N", "Y", self.doMinus, None, None,
                        None), (("T", 0, 8, 0), "IUI", 3, "Message Number", "",
                                "", "Y", self.doMessno, mss, None, ("efld", )),
               (("T", 0, 9, 0), "ID1", 10, "Statement Date", "", self.sysdtw,
                "Y", self.doDat, None, None,
                ("efld", )), (("T", 0, 10, 0), ("IRB", r5s), 0, "Sort Order",
                              "", "N", "Y", self.doSort, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doTplNam(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("tplmst",
                              where=[("tpm_tname", "=", w),
                                     ("tpm_type", "=", "S"),
                                     ("tpm_system", "=", "MEM")],
                              limit=1)
        if not acc:
            return "Invalid Template Name"
        self.tname = w

    def doStatus(self, frt, pag, r, c, p, i, w):
        self.status = w
        self.mlm["where"] = [("mlm_cono", "=", self.opts["conum"])]
        if self.status != "Z":  # Not All
            self.mlm["where"].append(("mlm_state", "=", self.status))

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w
        if self.whole != "R":
            self.df.loadEntry(frt, pag, p + 1, data="")
            self.df.loadEntry(frt, pag, p + 2, data="")
            return "sk2"

    def doMember(self, frt, pag, r, c, p, i, w):
        if p == 3:
            self.start = w
        elif w < self.start:
            return "Invalid Member, Before From"
        else:
            self.to = w

    def doCurrent(self, frt, pag, r, c, p, i, w):
        self.current = w

    def doZeros(self, frt, pag, r, c, p, i, w):
        self.zeros = w
        if self.zeros == "Y":
            self.paid = "Y"
            self.df.loadEntry(frt, pag, p + 1, data=self.paid)
            return "sk1"

    def doPaid(self, frt, pag, r, c, p, i, w):
        self.paid = w

    def doMinus(self, frt, pag, r, c, p, i, w):
        self.minus = w

    def doMessno(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("ctlmes",
                                  cols=["mss_detail"],
                                  where=[("mss_system", "=", "MEM"),
                                         ("mss_message", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Message Number"
        self.mesno = w

    def doDat(self, frt, pag, r, c, p, i, w):
        self.pro = False
        self.ynd = False
        if w > self.nne:
            showError(self.opts["mf"].body, "Month End Error",
                      "More than Two Month Ends are Missing, Aborting ...")
            return "rf"
        if w > self.nme:
            if self.nme == self.opts["period"][2][0]:
                ok = askQuestion(self.opts["mf"].body, "Year End Error",
                    "A Year End as at %s Has Not Been Run\n\n"\
                    "Would You Like to Raise Pro-Forma Charges?" %
                    self.opts["period"][2][1])
                if ok == "yes":
                    self.pro = True
                    self.ynd = True
            else:
                ok = askQuestion(self.opts["mf"].body, "Month End Error",
                    "A Month End as at %s Has Not Been Run\n\n"\
                    "Would You Like to Raise Pro-Forma Charges?" %
                    CCD(self.nme, "D1", 10).disp)
                if ok == "yes":
                    self.pro = True
        self.datew = w
        self.dated = self.df.t_disp[pag][0][p]
        self.curdt = int(w / 100)

    def doSort(self, frt, pag, r, c, p, i, w):
        self.sort = w

    def doEnd(self):
        if "args" in self.opts:
            self.whole = "S"
            self.current = "N"
            self.zeros = "Y"
            self.paid = "Y"
            self.minus = "Y"
            self.mes = None
            self.mes = self.sql.getRec("ctlmes",
                                       cols=["mss_detail"],
                                       where=[("mss_system", "=", "MEM"),
                                              ("mss_message", "=", 1)],
                                       limit=1)
            self.curdt = int(self.opts["args"][1] / 100)
            self.dated = CCD(self.opts["args"][1], "D1", 10).disp
            self.pro = False
            self.repprt = self.opts["args"][2]
            self.repeml = self.opts["args"][3]
            recs = [self.opts["args"][0]]
        else:
            self.df.closeProcess()
            self.repprt = self.df.repprt
            self.repeml = self.df.repeml
            whr = [("mlm_cono", "=", self.opts["conum"])]
            if self.status != "Z":  # Not All
                whr.append(("mlm_state", "=", self.status))
            if self.sort == "N":
                odr = "mlm_memno"
            else:
                odr = "mlm_surname"
            if self.whole == "S":
                recs = getSingleRecords(
                    self.opts["mf"],
                    "memmst", ("mlm_memno", "mlm_surname", "mlm_names"),
                    head=["X", "Number", "Surname", "Names"],
                    where=whr,
                    order=odr,
                    selcol="mlm_surname")
            else:
                if self.whole == "R":
                    whr.append(("mlm_memno", "between", self.start, self.to))
                recs = self.sql.getRec("memmst", where=whr, order=odr)
                if not recs:
                    showError(self.opts["mf"].body, "Error",
                              "No Accounts Selected")
                    if "wait" not in self.opts:
                        self.opts["mf"].closeLoop()
                    return
            # Remove all linked accounts
            col = self.sql.memmst_col
            nos = []
            for acc in recs:
                nos.append(acc[col.index("mlm_memno")])
            chk = copyList(recs)
            for acc in chk:
                whr = [("mll_cono", "=", self.opts["conum"]),
                       ("mll_lnkno", "=", acc[col.index("mlm_memno")])]
                lnk = self.sql.getRec("memlnk", where=whr, limit=1)
                if lnk and lnk[1] in nos:
                    recs.remove(acc)
        if recs:
            self.emadd = self.repeml[2]
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()
            if self.repeml[1] == "N":
                mess = "Printing Statements"
            else:
                mess = "Printing and Emailing Statements"
            p = ProgressBar(self.opts["mf"].body,
                            typ=mess,
                            mxs=len(recs),
                            esc=True)
            for num, rec in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                if self.pro:
                    self.doProForma(rec)
                self.doProcess(rec)
            p.closeProgress()
            if self.pro:
                self.opts["mf"].dbm.rollbackDbase()
            if p.quit or not self.form.page:
                pass
            elif self.repeml[1] == "N" or self.emadd:
                self.repeml[2] = self.emadd
                self.doPrint()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()

    def doLoadStatic(self):
        cmc = self.sql.ctlmst_col
        ctm = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        for fld in cmc:
            dat = ctm[cmc.index(fld)]
            if fld in self.form.tptp:
                if fld == "ctm_logo":
                    self.form.letterhead(cmc, ctm, fld, dat)
                    continue
                self.form.tptp[fld][1] = dat
        if "letterhead" in self.form.tptp:
            self.form.letterhead(cmc, ctm, "letterhead", None)
        self.form.document_date(self.dated)
        self.form.bank_details(cmc, ctm, 0)

    def doProForma(self, rec):
        self.refno = 0
        dmc = self.sql.memmst_col
        acc = [rec[dmc.index("mlm_memno")]]
        lnk = self.sql.getRec("memlnk",
                              cols=["mll_lnkno"],
                              where=[("mll_cono", "=", self.opts["conum"]),
                                     ("mll_memno", "=", acc[0])])
        for l in lnk:
            chk = self.sql.getRec("memmst",
                                  cols=["mlm_state"],
                                  where=[("mlm_cono", "=", self.opts["conum"]),
                                         ("mlm_memno", "=", l[0])],
                                  limit=1)
            if chk and chk[0] == "A":
                acc.append(l[0])
        for memno in acc:
            if self.ynd:
                data = doChkCatChg(self.opts["mf"], self.opts["conum"], memno,
                                   self.datew)
                if data:
                    if not data[3]:
                        self.doRaiseCharge(memno,
                                           "B",
                                           data[0],
                                           data[1],
                                           data[2],
                                           data[3],
                                           data[4],
                                           data[5],
                                           skip=True)
                    self.sql.delRec("memcat",
                                    where=[("mlc_cono", "=",
                                            self.opts["conum"]),
                                           ("mlc_memno", "=", memno),
                                           ("mlc_type", "=", "B"),
                                           ("mlc_code", "=", data[0])])
                    self.sql.insRec("memcat",
                                    data=[
                                        self.opts["conum"], memno, "B",
                                        data[7], "", self.datew, 0, 0
                                    ])
            cols = [
                "mlc_type", "mlc_code", "mcc_desc", "mcc_freq", "mlc_start",
                "mlc_end", "mlc_last"
            ]
            wher = [("mlc_cono", "=", self.opts["conum"]),
                    ("mlc_memno", "=", memno), ("mlc_start", ">", 0),
                    ("mlc_start", "<=", self.datew), ("mcc_cono=mlc_cono", ),
                    ("mcc_type=mlc_type", ), ("mcc_code=mlc_code", ),
                    ("mcc_freq", "<>", "N")]
            cats = self.sql.getRec(tables=["memcat", "memctc"],
                                   cols=cols,
                                   where=wher,
                                   order="mlc_type, mlc_code")
            for ctyp, code, desc, freq, start, end, last in cats:
                if start > self.datew:
                    # Not yet Started
                    continue
                if last and end and end < self.datew:
                    # Ended
                    continue
                if last and freq == "O":
                    # Once Off
                    continue
                if last and last > self.opts["period"][2][0]:
                    # Already Raised for Next Period in Advance
                    continue
                if not self.ynd and last and freq == "A" and \
                        last >= self.opts["period"][1][0] and \
                        last <= self.opts["period"][2][0]:
                    # Already Raised in Financial Period
                    continue
                self.doRaiseCharge(memno, ctyp, code, start, end, last, freq,
                                   desc)

    def doRaiseCharge(self,
                      memno,
                      ctyp,
                      code,
                      start,
                      end,
                      last,
                      freq,
                      desc,
                      skip=False):
        if freq == "O":
            dte = True
            nxt = False
        else:
            dte = False
            nxt = bool(self.ynd or freq == "M")
            if not last:
                if dateDiff(start, self.nme, "days") > self.ldays:
                    dte = True
                else:
                    nxt = True
        if dte:
            trdt = start
            amt = self.doGetCharge(ctyp, code, trdt)
            if amt:
                self.doUpdateTables(memno, ctyp, code, desc, trdt, amt)
        if not skip and nxt:
            if end and self.datew > end:
                return
            trdt = self.datew
            amt = self.doGetCharge(ctyp, code, trdt)
            if amt:
                self.doUpdateTables(memno, ctyp, code, desc, trdt, amt)

    def doGetCharge(self, ctyp, code, date):
        prc = self.sql.getRec("memctp",
                              where=[("mcp_cono", "=", self.opts["conum"]),
                                     ("mcp_type", "=", ctyp),
                                     ("mcp_code", "=", code),
                                     ("mcp_date", "<=", date)],
                              order="mcp_date desc",
                              limit=1)
        if not prc:
            # No Price
            return
        if prc[5] == "N" or (self.ynd and date == self.datew):
            # Not Pro Rata or End of Financial Year
            amt = CCD(prc[6], "UD", 12.2).work
        else:
            # Extract Pro Rata Rate
            mths = 17 - dateDiff(date, self.opts["period"][2][0], "months")
            if mths < 1:
                mths = 12
            amt = CCD(prc[mths], "UD", 12.2).work
        if not amt:
            # No Charge
            return
        else:
            return amt

    def doUpdateTables(self, memno, ctyp, code, desc, trdt, amt):
        batch = "PROFORM"
        self.refno += 1
        refno = "PF%07i" % self.refno
        curdt = int(trdt / 100)
        # VAT Rate and Amount
        vrte = getVatRate(self.sql, self.opts["conum"], self.taxdf, trdt)
        if vrte is None:
            vrte = 0.0
        vat = CCD(round(((amt * vrte) / 114), 2), "UD", 12.2).work
        # Members Ledger Transaction (memtrn)
        self.sql.insRec("memtrn",
                        data=[
                            self.opts["conum"], memno, 1, refno, batch, trdt,
                            amt, vat, curdt, ctyp, code, desc, self.taxdf, "",
                            self.opts["capnm"], self.sysdtw, 0
                        ],
                        unique="mlt_refno")
        # Members Category Record (memcat)
        self.sql.updRec("memcat",
                        cols=["mlc_last"],
                        data=[trdt],
                        where=[("mlc_cono", "=", self.opts["conum"]),
                               ("mlc_memno", "=", memno),
                               ("mlc_type", "=", ctyp),
                               ("mlc_code", "=", code)])

    def doProcess(self, mlm):
        dmc = self.sql.memmst_col
        tdc = self.form.sql.tpldet_col
        self.memno = mlm[dmc.index("mlm_memno")]
        self.doGetBalTrn()
        if not self.mlt[1]:
            return
        if self.zeros == "N" and not self.tbal:
            return
        elif self.zeros == "C" and not self.tbal and not self.mlt[2]:
            return
        if self.minus == "N" and self.tbal < 0:
            return
        eml = []
        kon = self.sql.getRec(tables=["memctk", "memkon"],
                              cols=["mlk_detail"],
                              where=[("mck_type", "=", "E"),
                                     ("mlk_cono", "=", self.opts["conum"]),
                                     ("mlk_memno", "=", self.memno),
                                     ("mlk_code=mck_code", )])
        for k in kon:
            eml.append(k[0])
        if self.whole == "E" and not eml:
            return
        elif self.whole == "P" and eml:
            return
        for col in dmc:
            d = "%s_C00" % col
            if d in self.form.newdic:
                dat = mlm[dmc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        self.doHeader(mlm, dmc, tdc)
        mlc, mlt = self.mlt[:2]
        if self.current == "Y":
            amt = 0
            bal = 0
            cdt = int(self.opts["period"][2][0] / 100)
            trn = copy.deepcopy(mlt)
            mlt = []
            while trn:
                rec = trn.pop()
                if rec[mlc.index("mlt_curdt")] < cdt:
                    amt = float(ASD(amt) + ASD(rec[mlc.index("mlt_tramt")]))
                    bal = float(ASD(bal) + ASD(rec[mlc.index("balance")]))
                else:
                    mlt.append(rec)
            if amt or bal:
                rec[mlc.index("mlt_type")] = 3
                rec[mlc.index("mlt_refno")] = "B/FWD"
                rec[mlc.index("mlt_batch")] = ""
                rec[mlc.index("mlt_tramt")] = amt
                rec[mlc.index("balance")] = bal
                rec[mlc.index("mlt_taxamt")] = 0
                rec[mlc.index("mlt_desc")] = "Balance Brought Forward"
                rec[mlc.index("mlt_taxind")] = ""
                rec[mlc.index("mlt_batind")] = ""
                mlt.insert(0, rec)
        if len(mlt) <= self.form.maxlines:
            self.doBody(mlc, mlt, tdc)
        else:
            amt = 0
            bal = 0
            lines = len(mlt) - self.form.maxlines + 1
            for _ in range(lines):
                trn = mlt.pop(0)
                amt = float(ASD(amt) + ASD(trn[mlc.index("mlt_tramt")]))
                bal = float(ASD(bal) + ASD(trn[mlc.index("balance")]))
            trn[mlc.index("mlt_type")] = 3
            trn[mlc.index("mlt_refno")] = "B/FWD"
            trn[mlc.index("mlt_batch")] = ""
            trn[mlc.index("mlt_tramt")] = amt
            trn[mlc.index("balance")] = bal
            trn[mlc.index("mlt_taxamt")] = 0
            trn[mlc.index("mlt_desc")] = "Balance Brought Forward"
            trn[mlc.index("mlt_taxind")] = ""
            trn[mlc.index("mlt_batind")] = ""
            mlt.insert(0, trn)
            self.doBody(mlc, mlt, tdc)
        self.doTotal(tdc)
        self.doTail(tdc)
        if self.repeml[1] == "Y" and not self.emadd:
            self.repeml[2] = eml
            self.doPrint()

    def doGetBalTrn(self):
        if self.paid == "Y":
            trans = "A"
        else:
            trans = "Y"
        bals = Balances(self.opts["mf"], "MEM", self.opts["conum"], self.curdt,
                        (self.memno, ))
        self.obal, self.tbal, self.ages, self.mlt = bals.doAllBals(trans=trans)
        lnk = self.sql.getRec("memlnk",
                              cols=["mll_lnkno"],
                              where=[("mll_cono", "=", self.opts["conum"]),
                                     ("mll_memno", "=", self.memno)])
        if not lnk:
            return
        for l in lnk:
            bals = Balances(self.opts["mf"], "MEM", self.opts["conum"],
                            self.curdt, (l[0], ))
            obal, tbal, ages, mlt = bals.doAllBals(trans=trans)
            for n, d in enumerate(mlt[1]):
                mlt[1][n][mlt[0].index("mlt_desc")] = "%s (%s)" % \
                    (d[mlt[0].index("mlt_desc")][:30],
                    d[mlt[0].index("mlt_memno")])
            self.obal = float(ASD(self.obal) + ASD(obal))
            self.tbal = float(ASD(self.tbal) + ASD(tbal))
            for x in range(5):
                self.ages[x] = float(ASD(self.ages[x]) + ASD(ages[x]))
            self.mlt[1].extend(mlt[1])
            self.mlt[2] += mlt[2]
        # Sort Transaction by Date
        self.mlt[1].sort(key=lambda x: x[mlt[0].index("mlt_trdt")])

    def doHeader(self, mlm, dmc, tdc):
        self.form.add_page()
        if "account_details" in self.form.tptp:
            tit = mlm[dmc.index("mlm_title")]
            sur = mlm[dmc.index("mlm_surname")]
            nam = mlm[dmc.index("mlm_names")]
            ini = ""
            for n, d in enumerate(nam.split()):
                if n < 3:
                    if not ini:
                        ini = d[0].upper()
                    else:
                        ini = "%s %s" % (ini, d[0].upper())
            nad = "%s %s %s" % (tit.strip(), ini.strip(), sur.strip())
            add = self.sql.getRec("memadd",
                                  where=[("mla_cono", "=", self.opts["conum"]),
                                         ("mla_memno", "=", self.memno),
                                         ("mla_type", "=", "P")],
                                  limit=1)
            adc = self.sql.memadd_col
            if add:
                if add[adc.index("mla_add1")]:
                    nad = "%s\n%s" % (nad, add[adc.index("mla_add1")])
                if add[adc.index("mla_add2")]:
                    nad = "%s\n%s" % (nad, add[adc.index("mla_add2")])
                if add[adc.index("mla_add3")]:
                    nad = "%s\n%s" % (nad, add[adc.index("mla_add3")])
                if add[adc.index("mla_city")]:
                    nad = "%s\n%s" % (nad, add[adc.index("mla_city")])
                if add[adc.index("mla_country")]:
                    nad = "%s\n%-s, %-s" % (nad, add[adc.index("mla_code")],
                                            add[adc.index("mla_country")])
                else:
                    nad = "%s\n%s" % (nad, add[adc.index("mla_code")])
            else:
                nad = "\n\n\n\n\n"
            self.form.newdic["account_details_C00"][tdc.index(
                "tpd_text")] = nad
        for key in self.form.newkey:
            nl = copyList(self.form.newdic[key])
            if nl[tdc.index("tpd_place")] != "A":
                continue
            if nl[tdc.index("tpd_detseq")] == "mlm_memno_C00":
                nl[tdc.index("tpd_text")] = self.memno
            self.form.doDrawDetail(nl)

    def doBody(self, mlc, mlt, tdc):
        text = self.form.sql.tpldet_col.index("tpd_text")
        self.tots = [0.0, 0.0, 0.0]
        count = 0
        for trans in mlt:
            if trans[mlc.index("mlt_type")] not in (5, 6) and \
                    trans[mlc.index("mlt_curdt")] == self.curdt:
                if self.paid == "Y":
                    self.tots[1] = float(ASD(self.tots[1]) + \
                        ASD(trans[mlc.index("mlt_tramt")]))
                else:
                    self.tots[1] = float(ASD(self.tots[1]) + \
                        ASD(trans[mlc.index("balance")]))
                if trans[mlc.index("mlt_taxamt")]:
                    self.tots[1] = float(ASD(self.tots[1]) - \
                        ASD(trans[mlc.index("mlt_taxamt")]))
                    self.tots[2] = float(ASD(self.tots[2]) + \
                        ASD(trans[mlc.index("mlt_taxamt")]))
            else:
                self.tots[0] = float(ASD(self.tots[0]) + \
                    ASD(trans[mlc.index("balance")]))
            for cod in self.form.body:
                if cod == "type_code":
                    c = "mlt_type"
                elif self.paid == "N" and cod == "mlt_tramt":
                    c = "balance"
                else:
                    c = cod
                d = "%s_C%02i" % (cod, count)
                if cod == "type_code":
                    ttyp = trans[mlc.index(c)]
                    self.form.newdic[d][text] = mltrtp[ttyp - 1][0]
                else:
                    self.form.newdic[d][text] = trans[mlc.index(c)]
                self.form.doDrawDetail(self.form.newdic[d])
            count += 1
        for x in range(count, self.form.maxlines):
            for cod in self.form.body:
                d = "%s_C%02i" % (cod, x)
                self.form.newdic[d][tdc.index("tpd_text")] = "BLANK"
                self.form.doDrawDetail(self.form.newdic[d])

    def doTotal(self, tdc):
        for c in self.form.total:
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                line = self.form.newdic[d]
                if c == "120_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[4]
                elif c == "90_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[3]
                elif c == "60_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[2]
                elif c == "30_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[1]
                elif c == "current_balance":
                    line[tdc.index("tpd_text")] = self.ages[0]
                elif c == "total_arrears":
                    line[tdc.index("tpd_text")] = self.tots[0]
                elif c == "month_exclusive":
                    line[tdc.index("tpd_text")] = self.tots[1]
                elif c == "month_tax":
                    line[tdc.index("tpd_text")] = self.tots[2]
                elif c == "total_balance":
                    line[tdc.index("tpd_text")] = self.tbal
                self.form.doDrawDetail(line)

    def doTail(self, tdc):
        for c in self.form.tail:
            if c == "message" and not self.mesno:
                continue
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                if d == "message_C00" and self.mesno:
                    mes = self.sql.getRec("ctlmes",
                                          cols=["mss_detail"],
                                          where=[("mss_system", "=", "MEM"),
                                                 ("mss_message", "=",
                                                  self.mesno)],
                                          limit=1)
                    self.form.newdic[d][tdc.index("tpd_text")] = mes[0]
                self.form.doDrawDetail(self.form.newdic[d])

    def doPrint(self):
        if self.repeml[1] == "Y" and not self.emadd:
            key = "%s_%s" % (self.opts["conum"], self.memno)
        else:
            key = "%s_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            key,
                            ext="pdf")
        self.form.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Statement at %s" %
                  (self.opts["conam"], self.dated),
                  fromad=self.fromad,
                  repprt=self.repprt,
                  repeml=self.repeml)
        if self.repeml[1] == "Y":
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
示例#2
0
class bk3070(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            if "args" in self.opts:
                self.doEnd()
            else:
                self.mainProcess()
                if "wait" in self.opts:
                    self.df.mstFrame.wait_window()
                else:
                    self.opts["mf"].startLoop()

    def setVariables(self):
        gc = GetCtl(self.opts["mf"])
        bkmctl = gc.getCtl("bkmctl", self.opts["conum"])
        if not bkmctl:
            return
        self.stpl = bkmctl["cbk_statpl"]
        self.fromad = bkmctl["cbk_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = CCD(self.sysdtw, "D1", 10).disp
        self.sql = Sql(self.opts["mf"].dbm,
                       ["ctlmst", "bkmcon", "bkmmst", "bkmtrn", "tplmst"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        return True

    def mainProcess(self):
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "S"), ("tpm_system", "=", "BKM")],
            "order":
            "tpm_tname"
        }
        bkm = {
            "stype":
            "R",
            "tables": ("bkmmst", "bkmcon"),
            "cols": (("bkm_number", "", 0, "Booking"),
                     ("bkc_sname", "", 0, "Surname", "Y"), ("bkc_names", "", 0,
                                                            "Names", "F")),
            "where":
            (("bkm_cono", "=", self.opts["conum"]), ("bkm_state", "<>", "X"),
             ("bkc_cono=bkm_cono", ), ("bkc_ccode=bkm_ccode", ))
        }
        r1s = (("Yes", "Y"), ("Range", "R"), ("Singles", "S"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "INA", 20, "Template Name", "", self.stpl, "Y",
                self.doTplNam, tpm, None, None),
               (("T", 0, 1,
                 0), ("IRB", r1s), 0, "Whole File", "", "Y", "N", self.doWhole,
                None, None, None), (("T", 0, 2, 0), "IUI", 7, "From Booking",
                                    "", "", "N", self.doAcc, bkm, None, None),
               (("T", 0, 3, 0), "IUI", 7, "To Booking", "", "", "N",
                self.doAcc, bkm, None, None),
               (("T", 0, 4, 0), ("IRB", r2s), 0, "Include Cancellations", "",
                "Y", "N", self.doCancel, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doTplNam(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("tplmst",
                              where=[("tpm_tname", "=", w),
                                     ("tpm_type", "=", "S"),
                                     ("tpm_system", "=", "BKM")],
                              limit=1)
        if not acc:
            return "Invalid Template Name"
        self.tname = w

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w
        if self.whole in ("Y", "S"):
            self.snum = 0
            self.enum = 0
            self.df.loadEntry("T", 0, p + 1, data="")
            self.df.loadEntry("T", 0, p + 2, data="")
            return "sk2"

    def doAcc(self, frt, pag, r, c, p, i, w):
        if p == 2:
            self.snum = w
        else:
            self.enum = w
        chk = self.sql.getRec("bkmmst",
                              where=[("bkm_cono", "=", self.opts["conum"]),
                                     ("bkm_number", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Booking Number"
        if p == 2:
            self.df.loadEntry(frt, pag, p + 1, data=self.snum)

    def doCancel(self, frt, pag, r, c, p, i, w):
        self.cancel = w

    def doEnd(self):
        if "args" in self.opts:
            self.cancel = "Y"
            self.tname = self.stpl
            self.whole = "A"
            self.snum = 0
            self.enum = 0
            if len(self.opts["args"]) == 1:
                self.repprt = ["N", "V", "view"]
                self.repeml = ["N", "N", "", "", "Y"]
            else:
                self.repprt = self.opts["args"][1]
                self.repeml = self.opts["args"][2]
        else:
            self.df.closeProcess()
            self.repprt = self.df.repprt
            self.repeml = self.df.repeml
            if not self.enum:
                self.enum = 9999999
        self.emadd = self.repeml[2]
        tab = ["bkmmst"]
        whr = [("bkm_cono", "=", self.opts["conum"])]
        if self.cancel == "N":
            whr.append(("bkm_state", "<>", "X"))
        odr = "bkm_number"
        if self.whole == "A":
            if type(self.opts["args"][0]) == int:
                whr.append(("bkm_number", "=", self.opts["args"][0]))
            else:
                whr.append(("bkm_number", "in", self.opts["args"][0]))
            recs = self.sql.getRec("bkmmst", where=whr, order=odr)
        elif self.whole == "S":
            tab.append("bkmcon")
            col = ["bkm_number", "bkc_sname", "bkc_names"]
            whr.extend([("bkc_cono=bkm_cono", ), ("bkc_ccode=bkm_ccode", )])
            dic = {}
            for c in col:
                for t in tab:
                    d = getattr(self.sql, "%s_dic" % t)
                    if c in d:
                        dic[c] = d[c]
            data = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr)
            data = getSingleRecords(self.opts["mf"],
                                    tab,
                                    col,
                                    dic=dic,
                                    where=data,
                                    ttype="D")
            recs = []
            for dat in data:
                acc = self.sql.getRec("bkmmst",
                                      where=[("bkm_cono", "=",
                                              self.opts["conum"]),
                                             ("bkm_number", "=", dat[0])])
                recs.append(acc[0])
        else:
            if self.whole == "R":
                whr.extend([("bkm_number", ">=", self.snum),
                            ("bkm_number", "<=", self.enum)])
            recs = self.sql.getRec("bkmmst", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Error", "No Bookings Selected")
        else:
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()
            p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
            for num, rec in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                self.doProcess(rec)
            p.closeProgress()
            if p.quit or not self.form.page:
                pass
            elif self.repeml[1] == "N" or self.emadd:
                self.repeml[2] = self.emadd
                self.doPrint()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()

    def doLoadStatic(self):
        cmc = self.sql.ctlmst_col
        ctm = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        for fld in cmc:
            dat = ctm[cmc.index(fld)]
            if fld in self.form.tptp:
                if fld == "ctm_logo":
                    self.form.letterhead(cmc, ctm, fld, dat)
                    continue
                self.form.tptp[fld][1] = dat
        if "letterhead" in self.form.tptp:
            self.form.letterhead(cmc, ctm, "letterhead", None)
        self.form.document_date(self.sysdtd)
        self.form.bank_details(cmc, ctm, 0)

    def doProcess(self, bkm):
        bmc = self.sql.bkmmst_col
        ccc = self.sql.bkmcon_col
        btc = self.sql.bkmtrn_col
        tdc = self.form.sql.tpldet_col
        self.num = bkm[bmc.index("bkm_number")]
        self.cod = bkm[bmc.index("bkm_ccode")]
        con = self.sql.getRec("bkmcon",
                              where=[("bkc_cono", "=", self.opts["conum"]),
                                     ("bkc_ccode", "=", self.cod)],
                              limit=1)
        eml = con[self.sql.bkmcon_col.index("bkc_email")]
        if "contact_details" in self.form.tptp:
            dat = "%s %s %s" % (con[ccc.index("bkc_title")],
                                con[ccc.index("bkc_names")],
                                con[ccc.index("bkc_sname")])
            if bkm[bmc.index("bkm_group")]:
                dat = "%s\n%s" % (dat, bkm[bmc.index("bkm_group")][:40])
            for fld in ("addr1", "addr2", "addr3", "pcode"):
                dat = "%1s\n%s" % (dat, con[ccc.index("bkc_%s" % fld)])
            self.form.newdic["contact_details_C00"][tdc.index(
                "tpd_text")] = dat
        for col in bmc:
            d = "%s_C00" % col
            if d in self.form.newdic:
                dat = bkm[bmc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        bkt = self.sql.getRec("bkmtrn",
                              where=[("bkt_cono", "=", self.opts["conum"]),
                                     ("bkt_number", "=", self.num)],
                              order="bkt_date, bkt_refno")
        if not bkt:
            return
        self.doBody(btc, bkt, tdc)
        self.doTotal(tdc)
        self.doTail()
        if self.repeml[1] == "Y" and not self.emadd:
            self.repeml[2] = eml
            self.doPrint()

    def doPrint(self):
        if self.repeml[1] == "Y" and not self.emadd:
            key = "%s_%s" % (self.opts["conum"], self.num)
        else:
            key = "%s_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            key,
                            ext="pdf")
        self.form.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Statement at %s" %
                  (self.opts["conam"], self.sysdtd),
                  repprt=self.repprt,
                  fromad=self.fromad,
                  repeml=self.repeml)
        if self.repeml[1] == "Y":
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()

    def doBody(self, btc, bkt, tdc):
        page = 0
        count = 0
        self.tbal = 0
        for trans in bkt:
            if not count:
                page += 1
                count = self.doHeader(page)
            if count == self.form.maxlines:
                page = self.doCfwd(page)
                count = self.doHeader(page)
            ldic = {}
            for cod in self.form.body:
                if cod in ("type_code", "line_paid", "line_balance"):
                    continue
                if cod == "bkt_desc":
                    des = self.form.doSplitText("bkt_desc_C00",
                                                trans[btc.index(cod)])
                    if len(des) > 1 and not des[-1]:
                        del des[-1]
                else:
                    ldic[cod] = CCD(trans[btc.index(cod)],
                                    self.form.tptp[cod][0][1],
                                    self.form.tptp[cod][0][2])
            ldic["line_paid"] = 0
            ldic["line_balance"] = ldic["bkt_tramt"].work
            self.tbal = float(ASD(self.tbal) + ASD(ldic["bkt_tramt"].work))
            for n, l in enumerate(des):
                if count == self.form.maxlines:
                    page = self.doCfwd(page)
                    count = self.doHeader(page)
                if n == 0 and len(des) == 1:
                    include = copyList(self.form.body)
                elif n == 0:
                    include = ("bkt_date", "bkt_refno", "type_code")
                elif n + 1 == len(des):
                    include = copyList(self.form.body)
                    include.remove("bkt_date")
                    include.remove("bkt_refno")
                    include.remove("type_code")
                else:
                    include = []
                for code in self.form.body:
                    seq = "%s_C%02i" % (code, count)
                    if code == "bkt_desc":
                        data = l
                    elif code in include:
                        if code == "type_code":
                            data = bktrtp[trans[btc.index("bkt_type")] - 1][0]
                        else:
                            data = ldic[code].work
                    else:
                        data = "BLANK"
                    self.form.newdic[seq][tdc.index("tpd_text")] = data
                    self.form.doDrawDetail(self.form.newdic[seq])
                count += 1
        for x in range(count, self.form.maxlines):
            for cod in self.form.body:
                d = "%s_C%02i" % (cod, x)
                self.form.newdic[d][tdc.index("tpd_text")] = "BLANK"
                self.form.doDrawDetail(self.form.newdic[d])

    def doHeader(self, page):
        self.form.add_page()
        tdc = self.form.sql.tpldet_col
        for key in self.form.newkey:
            nl = copyList(self.form.newdic[key])
            if nl[tdc.index("tpd_place")] != "A":
                continue
            if nl[tdc.index("tpd_detseq")] == "bkm_number_C00":
                nl[tdc.index("tpd_text")] = self.num
            elif nl[tdc.index("tpd_detseq")] == "page_number_C00":
                nl[tdc.index("tpd_text")] = str(page)
            self.form.doDrawDetail(nl)
        return 0

    def doCfwd(self, page):
        if "carried_forward" in self.form.tptp:
            tdc = self.form.sql.tpldet_col
            line = copyList(self.form.cfwd)
            line[tdc.index("tpd_text")] = "Continued on Page %i" % (page + 1)
            self.form.doDrawDetail(line)
        return page + 1

    def doTotal(self, tdc):
        for c in self.form.total:
            if c != "total_balance":
                continue
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                line = self.form.newdic[d]
                line[tdc.index("tpd_text")] = self.tbal
                self.form.doDrawDetail(line)

    def doTail(self):
        for c in self.form.tail:
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[d])

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
示例#3
0
class dr3080(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,
            ["ctlmes", "ctlmst", "drschn", "drsmst", "drstrn", "tplmst"],
            prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        drsctl = gc.getCtl("drsctl", self.opts["conum"])
        if not drsctl:
            return
        self.chains = drsctl["ctd_chain"]
        self.stpl = drsctl["ctd_tplnam"]
        self.ageing = drsctl["ctd_ageing"]
        self.fromad = drsctl["ctd_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        if self.chains == "N":
            self.schn = 0
            self.echn = 0
        return True

    def mainProcess(self):
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "S"), ("tpm_system", "=", "DRS")],
            "order":
            "tpm_tname"
        }
        drc = {
            "stype": "R",
            "tables": ("drschn", ),
            "cols":
            (("chm_chain", "", 0, "Num"), ("chm_name", "", 0, "Name", "Y")),
            "where": [("chm_cono", "=", self.opts["conum"])]
        }
        drm = {
            "stype":
            "R",
            "tables": ("drsmst", ),
            "cols":
            (("drm_acno", "", 0, "Acc-Num"), ("drm_name", "", 0, "Name", "Y"),
             ("drm_add1", "", 0, "Address Line 1"))
        }
        if self.chains == "Y":
            drm["where"] = [("drm_cono", "=", self.opts["conum"])]
            drm["whera"] = [["C", "drm_chain", 0, 1]]
        else:
            drm["where"] = [("drm_cono", "=", self.opts["conum"]),
                            ("drm_chain", "=", 0)]
        mss = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": (("mss_message", "", 0, "Num"), ("mss_detail", "NA", 50,
                                                     "Details")),
            "where": [("mss_system", "=", "STA")]
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        r2s = (("Yes", "Y"), ("Range", "R"), ("Singles", "S"))
        r3s = (("Number", "N"), ("Name", "M"), ("Postal Code", "P"))
        fld = [[["T", 0, 0, 0], "INA", 20, "Template Name", "", self.stpl, "Y",
                self.doTplNam, tpm, None, None],
               [["T", 0, 1, 0], ("IRB", r1s), 0, "Open Item", "", "Y", "Y",
                self.doOItem, None, None, None],
               [["T", 0, 2, 0], "IUI", 2, "Maximum Pages", "", 1, "Y",
                self.doPages, None, None, None],
               [["T", 0, 3, 0], ("IRB", r2s), 0, "Whole File", "", "S", "Y",
                self.doWhole, None, None, None],
               [["T", 0, 4, 0], "IUI", 3, "From Chain", "", "", "Y",
                self.doChn, drc, None, None],
               [["T", 0, 5, 0], "INA", 7, "From Account", "", "", "Y",
                self.doAcc, drm, None, None],
               [["T", 0, 6, 0], "INA", 3, "To Chain", "", "", "Y", self.doChn,
                drc, None, None],
               [["T", 0, 7, 0], "INA", 7, "To Account", "", "", "Y",
                self.doAcc, drm, None, None],
               [["T", 0, 8, 0], ("IRB", r3s), 0, "Sort Order", "", "N", "Y",
                self.doSort, None, None, None],
               [["T", 0, 9, 0], ("IRB", r1s), 0, "Include Zero Balances", "",
                "N", "Y", self.doZeros, None, None, None],
               [["T", 0, 10, 0], ("IRB", r1s), 0, "Include Negative Balances",
                "", "N", "Y", self.doMinus, None, None, None],
               [["T", 0, 11, 0], ("IRB", r1s), 0, "Include Stopped Accounts",
                "", "N", "Y", self.doStops, None, None, None],
               [["T", 0, 12, 0], ("IRB", r1s), 0, "Include Redundant Accounts",
                "", "N", "Y", self.doRedu, None, None, None],
               [["T", 0, 13,
                 0], ("IRB", r1s), 0, "Include Allocated Transactions", "",
                "N", "Y", self.doAlloc, None, None, None],
               [["T", 0, 14, 0], "ID1", 10, "Statement Date", "", self.sysdtw,
                "Y", self.doDat, None, None, ("efld", )],
               [["T", 0, 15, 0], "IUI", 3, "Message Number", "", "", "Y",
                self.doMessno, mss, None, ("efld", )]]
        if self.chains != "Y":
            del fld[6]
            del fld[4]
            for n, f in enumerate(fld):
                fld[n][0][2] = n
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doTplNam(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("tplmst",
                              where=[("tpm_tname", "=", w),
                                     ("tpm_type", "=", "S"),
                                     ("tpm_system", "=", "DRS")],
                              limit=1)
        if not acc:
            return "Invalid Template Name"
        self.tname = w
        self.sttyp = acc[self.sql.tplmst_col.index("tpm_sttp")]
        if self.sttyp == "N":
            self.oitem = "Y"
            self.pages = 0
            self.df.loadEntry(frt, pag, p + 1, data=self.oitem)
            self.df.loadEntry(frt, pag, p + 2, data=self.pages)
            return "sk2"

    def doOItem(self, frt, pag, r, c, p, i, w):
        self.oitem = w
        if self.oitem == "N":
            self.pages = 0
            self.df.loadEntry(frt, pag, p + 1, data=self.pages)
            return "sk1"

    def doPages(self, frt, pag, r, c, p, i, w):
        self.pages = w

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w
        if self.whole in ("Y", "S"):
            self.schn = 0
            self.echn = 0
            self.sacc = ""
            self.eacc = ""
            if self.chains == "Y":
                self.df.loadEntry("T", 0, p + 1, data=self.schn)
                self.df.loadEntry("T", 0, p + 2, data=self.sacc)
                self.df.loadEntry("T", 0, p + 3, data=self.echn)
                self.df.loadEntry("T", 0, p + 4, data=self.eacc)
                return "sk4"
            else:
                self.df.loadEntry("T", 0, p + 1, data=self.sacc)
                self.df.loadEntry("T", 0, p + 2, data=self.eacc)
                return "sk2"

    def doChn(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("drschn",
                              cols=["chm_name"],
                              where=[("chm_chain", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Chain Store"
        if c == 5:
            self.schn = w
        else:
            self.echn = w

    def doAcc(self, frt, pag, r, c, p, i, w):
        if self.chains == "Y" and c == 6:
            chk = self.schn
            self.sacc = w
        elif self.chains == "Y" and c == 8:
            chk = self.echn
            self.eacc = w
        elif c == 5:
            chk = self.schn
            self.sacc = w
        else:
            chk = self.echn
            self.eacc = w
        chk = self.sql.getRec("drsmst",
                              cols=["drm_name"],
                              where=[("drm_cono", "=", self.opts["conum"]),
                                     ("drm_chain", "=", chk),
                                     ("drm_acno", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Debtors Account"

    def doSort(self, frt, pag, r, c, p, i, w):
        self.sort = w

    def doZeros(self, frt, pag, r, c, p, i, w):
        self.zeros = w

    def doMinus(self, frt, pag, r, c, p, i, w):
        self.minus = w

    def doStops(self, frt, pag, r, c, p, i, w):
        self.stops = w

    def doRedu(self, frt, pag, r, c, p, i, w):
        self.redu = w
        if self.sttyp == "O":
            self.alloc = "Y"
            self.df.loadEntry(frt, pag, p + 1, data=self.alloc)
            return "sk1"

    def doAlloc(self, frt, pag, r, c, p, i, w):
        self.alloc = w

    def doMessno(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("ctlmes",
                                  cols=["mss_detail"],
                                  where=[("mss_system", "=", "STA"),
                                         ("mss_message", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Message Number"
        self.mess = w

    def doDat(self, frt, pag, r, c, p, i, w):
        self.datew = w
        self.dated = self.df.t_disp[pag][0][p]
        self.curdt = int(w / 100)

    def doEnd(self):
        self.df.closeProcess()
        self.emadd = self.df.repeml[2]
        if not self.echn:
            self.echn = 999
        if not self.eacc:
            self.eacc = "zzzzzzz"
        whr = [("drm_cono", "=", self.opts["conum"]),
               ("drm_chain", ">=", self.schn), ("drm_acno", ">=", self.sacc),
               ("drm_chain", "<=", self.echn), ("drm_acno", "<=", self.eacc)]
        if self.stops == "N":
            whr.append(("drm_stop", "<>", "Y"))
        if self.redu == "N":
            whr.append(("drm_stat", "<>", "X"))
        if self.whole == "S":
            recs = getSingleRecords(self.opts["mf"],
                                    "drsmst",
                                    ("drm_chain", "drm_acno", "drm_name"),
                                    where=whr)
        else:
            if self.sort == "N":
                odr = "drm_chain, drm_acno"
            elif self.sort == "M":
                odr = "drm_name"
            else:
                odr = "drm_pcod"
            recs = self.sql.getRec("drsmst", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Error", "No Accounts Selected")
        else:
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()
            p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
            for num, rec in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                self.doProcess(rec)
            p.closeProgress()
            if p.quit or not self.form.page:
                pass
            elif self.df.repeml[1] == "N" or self.emadd:
                self.df.repeml[2] = self.emadd
                self.doPrint()
        self.opts["mf"].closeLoop()

    def doLoadStatic(self):
        cmc = self.sql.ctlmst_col
        ctm = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        for fld in cmc:
            dat = ctm[cmc.index(fld)]
            if fld in self.form.tptp:
                if fld == "ctm_logo":
                    self.form.letterhead(cmc, ctm, fld, dat)
                    continue
                self.form.tptp[fld][1] = dat
        if "letterhead" in self.form.tptp:
            self.form.letterhead(cmc, ctm, "letterhead", None)
        self.form.document_date(self.dated)
        self.form.bank_details(cmc, ctm, 0)

    def doProcess(self, drm):
        dmc = self.sql.drsmst_col
        dtc = self.sql.drstrn_col
        tdc = self.form.sql.tpldet_col
        self.chn = drm[dmc.index("drm_chain")]
        self.acc = drm[dmc.index("drm_acno")]
        eml = drm[dmc.index("drm_acc_email")]
        self.form.account_details("drm", dmc, drm, 1)
        if drm[dmc.index("drm_stames")]:
            self.mesno = drm[dmc.index("drm_stames")]
        else:
            self.mesno = self.mess
        for col in dmc:
            d = "%s_C00" % col
            if d in self.form.newdic:
                dat = drm[dmc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        bals = Balances(self.opts["mf"], "DRS", self.opts["conum"], self.curdt,
                        (self.chn, self.acc))
        if self.alloc == "Y":
            tt = "A"
        else:
            tt = "Y"
        obal, self.tbal, self.ages, trns = bals.doAllBals(trans=tt)
        if not trns[1]:
            return
        if self.sttyp == "O":
            self.tots = [0.0, 0.0, 0.0]
            cmth = False
            tran = copyList(trns[1])
            for t in tran:
                if t[dtc.index("drt_type")] not in (2, 6) and \
                        t[dtc.index("drt_curdt")] == self.curdt:
                    self.tots[1] = float(ASD(self.tots[1]) + \
                        ASD(t[dtc.index("drt_tramt")]))
                    if t[dtc.index("drt_taxamt")]:
                        self.tots[1] = float(ASD(self.tots[1]) - \
                            ASD(t[dtc.index("drt_taxamt")]))
                        self.tots[2] = float(ASD(self.tots[2]) + \
                            ASD(t[dtc.index("drt_taxamt")]))
                else:
                    self.tots[0] = float(ASD(self.tots[0]) + \
                        ASD(t[dtc.index("drt_tramt")]))
                if t[dtc.index("drt_curdt")] == self.curdt:
                    cmth = True
                elif self.oitem == "N":
                    trns[1].remove(t)
            if self.zeros == "N" and not self.tbal and not cmth:
                return
            if self.minus == "N" and self.tbal < 0:
                return
            if self.oitem == "N" and obal:
                t[trns[0].index("drt_type")] = 3
                t[trns[0].index("drt_ref1")] = "O/Bal"
                t[trns[0].index("drt_batch")] = ""
                t[trns[0].index("drt_trdt")] = (self.curdt * 100) + 1
                t[trns[0].index("drt_ref2")] = ""
                t[trns[0].index("drt_tramt")] = obal
                t[trns[0].index("drt_taxamt")] = 0
                t[trns[0].index("drt_desc")] = "Opening Balance"
                t[trns[0].index("drt_taxind")] = ""
                t[trns[0].index("drt_batind")] = ""
                trns[1].insert(0, t)
            if len(trns[1]) <= self.form.maxlines:
                self.doBody(trns[0], trns[1], tdc)
            else:
                pages = int(len(trns[1]) / self.form.maxlines)
                if len(trns[1]) % self.form.maxlines:
                    pages += 1
                if pages <= self.pages:
                    self.doBody(trns[0], trns[1], tdc)
                else:
                    bal = 0
                    lines = len(
                        trns[1]) - (self.pages * self.form.maxlines) + 1
                    for _ in range(lines):
                        trn = trns[1].pop(0)
                        bal = float(
                            ASD(bal) + ASD(trn[dtc.index("drt_tramt")]))
                    trn[trns[0].index("drt_type")] = 3
                    trn[trns[0].index("drt_ref1")] = "B/FWD"
                    trn[trns[0].index("drt_batch")] = ""
                    trn[trns[0].index("drt_ref2")] = ""
                    trn[trns[0].index("drt_tramt")] = bal
                    trn[trns[0].index("drt_taxamt")] = 0
                    trn[trns[0].index("drt_desc")] = "Balance Brought Forward"
                    trn[trns[0].index("drt_taxind")] = ""
                    trn[trns[0].index("drt_batind")] = ""
                    trns[1].insert(0, trn)
                    self.doBody(trns[0], trns[1], tdc)
        else:
            if self.zeros == "N" and not self.tbal:
                return
            if self.minus == "N" and self.tbal < 0:
                return
            self.doBody(trns[0], trns[1], tdc)
        self.doTotal(tdc)
        self.doTail(tdc)
        if self.df.repeml[1] == "Y" and not self.emadd:
            self.df.repeml[2] = eml
            self.doPrint()

    def doPrint(self):
        if self.df.repeml[1] == "Y" and not self.emadd:
            key = "%s_%s_%s" % (self.opts["conum"], self.chn, self.acc)
        else:
            key = "%s_all_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            key,
                            ext="pdf")
        self.form.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Statement for %s as at %s" %
                  (self.opts["conam"], self.acc, self.dated),
                  repprt=self.df.repprt,
                  fromad=self.fromad,
                  repeml=self.df.repeml)
        if self.df.repeml[1] == "Y":
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()

    def doBody(self, dtc, drt, tdc):
        page = 0
        count = 0
        rbal = 0
        text = tdc.index("tpd_text")
        for trans in drt:
            if not count:
                page += 1
                count = self.doHeader(page)
            if count == self.form.maxlines:
                page = self.doCfwd(page)
                count = self.doHeader(page)
            for cod in self.form.body:
                if cod == "type_code":
                    c = "drt_type"
                elif cod == "line_paid":
                    c = "paid"
                elif cod == "line_balance":
                    c = "balance"
                else:
                    c = cod
                d = "%s_C%02i" % (cod, count)
                if cod == "type_code":
                    ttyp = trans[dtc.index(c)]
                    self.form.newdic[d][text] = drtrtp[ttyp - 1][0]
                elif self.sttyp == "O" and cod == "running_balance":
                    self.form.newdic[d][text] = rbal
                else:
                    self.form.newdic[d][text] = trans[dtc.index(c)]
                    if self.sttyp == "O" and cod == "drt_tramt":
                        rbal = float(ASD(rbal) + ASD(trans[dtc.index(c)]))
                self.form.doDrawDetail(self.form.newdic[d])
            count += 1
        for x in range(count, self.form.maxlines):
            for cod in self.form.body:
                d = "%s_C%02i" % (cod, x)
                self.form.newdic[d][tdc.index("tpd_text")] = "BLANK"
                self.form.doDrawDetail(self.form.newdic[d])

    def doHeader(self, page):
        self.form.add_page()
        tdc = self.form.sql.tpldet_col
        for key in self.form.newkey:
            nl = copyList(self.form.newdic[key])
            if nl[tdc.index("tpd_place")] != "A":
                continue
            if nl[tdc.index("tpd_detseq")] == "drm_acno_C00":
                nl[tdc.index("tpd_text")] = self.acc
            elif nl[tdc.index("tpd_detseq")] == "page_number_C00":
                nl[tdc.index("tpd_text")] = str(page)
            self.form.doDrawDetail(nl)
        return 0

    def doCfwd(self, page):
        if "carried_forward" in self.form.tptp:
            tdc = self.form.sql.tpldet_col
            line = copyList(self.form.cfwd)
            line[tdc.index("tpd_text")] = "Continued on Page %i" % (page + 1)
            self.form.doDrawDetail(line)
        return page + 1

    def doTotal(self, tdc):
        for c in self.form.total:
            if self.ageing == "N" and c != "total_balance":
                continue
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                line = self.form.newdic[d]
                if c == "120_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[4]
                elif c == "90_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[3]
                elif c == "60_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[2]
                elif c == "30_day_balance":
                    line[tdc.index("tpd_text")] = self.ages[1]
                elif c == "current_balance":
                    line[tdc.index("tpd_text")] = self.ages[0]
                elif c == "total_arrears":
                    line[tdc.index("tpd_text")] = self.tots[0]
                elif c == "month_exclusive":
                    line[tdc.index("tpd_text")] = self.tots[1]
                elif c == "month_tax":
                    line[tdc.index("tpd_text")] = self.tots[2]
                elif c == "total_balance":
                    line[tdc.index("tpd_text")] = self.tbal
                self.form.doDrawDetail(line)

    def doTail(self, tdc):
        for c in self.form.tail:
            if c == "message" and not self.mesno:
                continue
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                if d == "message_C00" and self.mesno:
                    mes = self.sql.getRec("ctlmes",
                                          cols=["mss_detail"],
                                          where=[("mss_system", "=", "STA"),
                                                 ("mss_message", "=",
                                                  self.mesno)],
                                          limit=1)
                    self.form.newdic[d][tdc.index("tpd_text")] = mes[0]
                self.form.doDrawDetail(self.form.newdic[d])

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
示例#4
0
class rt3040(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, [
            "ctlmes", "ctlmst", "rtlmst", "rtltrn", "rtlprm", "rtlcon",
            "tplmst"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        rtlctl = gc.getCtl("rtlctl", self.opts["conum"])
        if not rtlctl:
            return
        self.stpl = rtlctl["ctr_tplnam"]
        self.fromad = rtlctl["ctr_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.trtypes = []
        for t in rttrtp:
            self.trtypes.append(t[0])
        return True

    def mainProcess(self):
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "R"), ("tpm_system", "=", "MEM")],
            "order":
            "tpm_tname"
        }
        mss = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": (("mss_message", "", 0, "Num"), ("mss_detail", "NA", 50,
                                                     "Details")),
            "where": [("mss_system", "=", "RTL")]
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "INA", 20, "Template Name", "", self.stpl, "Y",
                self.doTplNam, tpm, None, None),
               (("T", 0, 1,
                 0), ("IRB", r1s), 0, "Whole File", "", "Y", "Y", self.doWhole,
                None, None, None), (("T", 0, 2, 0), ("IRB", r1s), 0,
                                    "Zero Balances", "Include Zero Balances",
                                    "N", "Y", self.doZeros, None, None, None),
               (("T", 0, 3, 0), ("IRB", r1s), 0, "Minus Balances",
                "Include Minus Balances", "N", "Y", self.doMinus, None, None,
                None), (("T", 0, 4, 0), "IUI", 3, "Message Number", "", "",
                        "Y", self.doMessno, mss, None, ("efld", )),
               (("T", 0, 5, 0), "ID1", 10, "Statement Date", "", self.sysdtw,
                "Y", self.doDat, None, None, ("efld", )))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doTplNam(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("tplmst",
                              where=[("tpm_tname", "=", w),
                                     ("tpm_type", "=", "S"),
                                     ("tpm_system", "=", "RTL")],
                              limit=1)
        if not acc:
            return "Invalid Template Name"
        self.tname = w

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w

    def doZeros(self, frt, pag, r, c, p, i, w):
        self.zeros = w

    def doMinus(self, frt, pag, r, c, p, i, w):
        self.minus = w

    def doMessno(self, frt, pag, r, c, p, i, w):
        if w:
            self.mes = self.sql.getRec("ctlmes",
                                       cols=["mss_detail"],
                                       where=[("mss_system", "=", "RTL"),
                                              ("mss_message", "=", w)],
                                       limit=1)
            if not self.mes:
                return "Invalid Message Number"
        self.mesno = w

    def doDat(self, frt, pag, r, c, p, i, w):
        self.datew = w
        self.dated = self.df.t_disp[pag][0][p]
        self.curdt = int(w / 100)

    def doEnd(self):
        self.df.closeProcess()
        self.emadd = self.df.repeml[2]
        if self.whole == "N":
            recs = getSingleRecords(self.opts["mf"],
                                    "rtlmst",
                                    ("rtm_code", "rtm_acno", "rtm_name"),
                                    where=[("rtm_cono", "=",
                                            self.opts["conum"])])
        else:
            whr = [("rtm_cono", "=", self.opts["conum"])]
            odr = "rtm_code, rtm_acno"
            recs = self.sql.getRec("rtlmst", where=whr, order=odr)
            if not recs:
                showError(self.opts["mf"].body, "Error",
                          "No Accounts Selected")
        if recs:
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()
            p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
            for num, rec in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                self.doProcess(rec)
            p.closeProgress()
            if p.quit or not self.form.page:
                pass
            elif self.df.repeml[1] == "N" or not self.emadd:
                self.df.repeml[2] = self.emadd
                self.doPrint()
        self.opts["mf"].closeLoop()

    def doLoadStatic(self):
        cmc = self.sql.ctlmst_col
        ctm = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        for fld in cmc:
            dat = ctm[cmc.index(fld)]
            if fld in self.form.tptp:
                if fld == "ctm_logo":
                    self.form.letterhead(cmc, ctm, fld, dat)
                    continue
                self.form.tptp[fld][1] = dat
        if "letterhead" in self.form.tptp:
            self.form.letterhead(cmc, ctm, "letterhead", None)
        self.form.document_date(self.dated)
        self.form.bank_details(cmc, ctm, 0)

    def doProcess(self, rtm):
        rmc = self.sql.rtlmst_col
        rtc = copyList(self.sql.rtltrn_col)
        tdc = self.form.sql.tpldet_col
        self.code = rtm[rmc.index("rtm_code")]
        self.acno = rtm[rmc.index("rtm_acno")]
        eml = rtm[rmc.index("rtm_email")]
        for col in rmc:
            d = "%s_00" % col
            if d in self.form.newdic:
                dat = rtm[rmc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        prm = self.sql.getRec("rtlprm",
                              where=[("rtp_cono", "=", self.opts["conum"]),
                                     ("rtp_code", "=", self.code)],
                              limit=1)
        if not prm:
            prm = [0, "", "", "", "", "", "", 0, 0]
        prc = self.sql.rtlprm_col
        for col in prc:
            d = "%s_00" % col
            if col in self.form.newdic:
                dat = prm[prc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        con = self.sql.getRec("rtlcon",
                              where=[("rtc_cono", "=", self.opts["conum"]),
                                     ("rtc_code", "=", self.code),
                                     ("rtc_acno", "=", self.acno)],
                              limit=1)
        coc = self.sql.rtlprm_col
        for col in coc:
            d = "%s_00" % col
            if col in self.form.newdic:
                dat = con[coc.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        self.tots = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
        rtt = self.sql.getRec(
            "rtltrn",
            cols=["round(sum(rtt_tramt), 2)", "round(sum(rtt_taxamt), 2)"],
            where=[("rtt_cono", "=", self.opts["conum"]),
                   ("rtt_code", "=", self.code), ("rtt_acno", "=", self.acno),
                   ("rtt_trdt", "<=", self.datew),
                   ("rtt_curdt", "=", self.curdt)],
            limit=1)
        if rtt[0]:
            self.tots[0] = rtt[0]
            self.tots[2] = rtt[0]
            self.tots[5] = rtt[0]
        if rtt[1]:
            self.tots[0] = float(ASD(self.tots[0]) - ASD(rtt[1]))
            self.tots[1] = rtt[1]
        arr = self.sql.getRec("rtltrn",
                              cols=["round(sum(rtt_tramt), 2)"],
                              where=[("rtt_cono", "=", self.opts["conum"]),
                                     ("rtt_code", "=", self.code),
                                     ("rtt_acno", "=", self.acno),
                                     ("rtt_curdt", "<", self.curdt)],
                              limit=1)
        if arr[0]:
            self.tots[3] = arr[0]
            self.tots[5] = float(ASD(self.tots[5]) + ASD(arr[0]))
        if self.zeros == "N" and not self.tots[5]:
            return
        if self.minus == "N" and self.tots[5] < 0:
            return
        rtc = [
            "rtt_trdt", "rtt_refno", "rtt_type", "rtt_desc", "rtt_cnum",
            "rtt_tramt"
        ]
        rtt = self.sql.getRec(
            "rtltrn",
            cols=[
                "rtt_trdt", "rtt_refno", "rtt_type", "rtt_desc", "rtt_cnum",
                "round(sum(rtt_tramt), 2)"
            ],
            where=[("rtt_cono", "=", self.opts["conum"]),
                   ("rtt_code", "=", self.code), ("rtt_acno", "=", self.acno),
                   ("rtt_type", "<>", 5), ("rtt_trdt", "<=", self.datew)],
            group="rtt_trdt, rtt_refno, rtt_type, rtt_desc, rtt_cnum",
            order="rtt_trdt, rtt_cnum, rtt_refno")
        if not rtt:
            rtt = []
        trans = []
        for trn in rtt:
            tramt = trn[rtc.index("rtt_tramt")]
            if tramt < 0:
                trn.extend([0, tramt])
            else:
                trn.extend([tramt, 0])
            trans.append(trn)
        rtc.extend(["line_debit", "line_credit"])
        self.doHeader(rtm, rmc, prm, prc, tdc)
        if len(trans) <= self.form.maxlines:
            self.doBody(rtc, trans, tdc)
        else:
            bal = 0
            lines = len(trans) - self.form.maxlines + 1
            for _ in range(lines):
                trn = trans.pop(0)
                bal = float(ASD(bal) + ASD(trn[5]))
            trn[rtc.index("rtt_refno")] = "B/FWD"
            trn[rtc.index("rtt_type")] = 3
            trn[rtc.index("rtt_desc")] = "Balance Brought Forward"
            trn[rtc.index("rtt_tramt")] = bal
            if bal < 0:
                trn[rtc.index("line_debit")] = 0
                trn[rtc.index("line_credit")] = bal
            else:
                trn[rtc.index("line_debit")] = bal
                trn[rtc.index("line_credit")] = 0
            trans.insert(0, trn)
            self.doBody(rtc, trans, tdc)
        self.doTotal(tdc)
        self.doTail(tdc)
        if self.df.repeml[1] == "Y" and not self.emadd:
            self.df.repeml[2] = eml
            self.doPrint()

    def doHeader(self, rtm, rmc, prm, prc, tdc):
        self.form.add_page()
        if "account_details" in self.form.tptp:
            nad = rtm[rmc.index("rtm_name")]
            add1 = rtm[rmc.index("rtm_addr1")]
            if add1:
                nad = "%1s\n%1s" % (nad, add1)
                nad = "%1s\n%1s" % (nad, rtm[rmc.index("rtm_addr2")])
                nad = "%1s\n%1s" % (nad, rtm[rmc.index("rtm_addr3")])
                nad = "%1s\n%1s" % (nad, rtm[rmc.index("rtm_pcode")])
            else:
                nad = prm[prc.index("rtp_addr1")]
                nad = "%1s\n%1s" % (nad, prm[prc.index("rtp_addr2")])
                nad = "%1s\n%1s" % (nad, prm[prc.index("rtp_addr3")])
                nad = "%1s\n%1s" % (nad, prm[prc.index("rtp_pcode")])
            self.form.newdic["account_details_C00"][tdc.index(
                "tpd_text")] = nad
        for key in self.form.newkey:
            nl = copyList(self.form.newdic[key])
            if nl[tdc.index("tpd_place")] != "A":
                continue
            if nl[tdc.index("tpd_detseq")] == "rtm_code_C00":
                nl[tdc.index("tpd_text")] = self.code
            elif nl[tdc.index("tpd_detseq")] == "rtm_acno_C00":
                nl[tdc.index("tpd_text")] = self.acno
            self.form.doDrawDetail(nl)

    def doBody(self, rtc, rtt, tdc):
        text = self.form.sql.tpldet_col.index("tpd_text")
        count = 0
        bal = 0
        for trans in rtt:
            for cod in self.form.body:
                if cod == "type_code":
                    c = "rtt_type"
                else:
                    c = cod
                d = "%s_C%02i" % (cod, count)
                if cod == "type_code":
                    ttyp = trans[rtc.index(c)]
                    self.form.newdic[d][text] = rttrtp[ttyp - 1][0]
                elif cod in ("line_debit", "line_credit"):
                    tramt = trans[rtc.index(c)]
                    bal = float(ASD(bal) + ASD(tramt))
                    self.form.newdic[d][text] = trans[rtc.index(c)]
                elif c == "line_balance":
                    self.form.newdic[d][text] = bal
                else:
                    self.form.newdic[d][text] = trans[rtc.index(c)]
                self.form.doDrawDetail(self.form.newdic[d])
            count += 1
        for x in range(count, self.form.maxlines):
            for cod in self.form.body:
                d = "%s_C%02i" % (cod, x)
                self.form.newdic[d][tdc.index("tpd_text")] = "BLANK"
                self.form.doDrawDetail(self.form.newdic[d])

    def doTotal(self, tdc):
        for c in self.form.total:
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                line = self.form.newdic[d]
                if c == "period_rental":
                    line[tdc.index("tpd_text")] = self.tots[0]
                elif c == "period_vat":
                    line[tdc.index("tpd_text")] = self.tots[1]
                elif c == "total_rental":
                    line[tdc.index("tpd_text")] = self.tots[2]
                elif c == "total_arrears":
                    line[tdc.index("tpd_text")] = self.tots[3]
                elif c == "interest":
                    line[tdc.index("tpd_text")] = self.tots[4]
                elif c == "total_balance":
                    line[tdc.index("tpd_text")] = self.tots[5]
                self.form.doDrawDetail(line)

    def doTail(self, tdc):
        for c in self.form.tail:
            if c == "message" and not self.mesno:
                continue
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                if d == "message_C00" and self.mesno:
                    mes = self.sql.getRec("ctlmes",
                                          cols=["mss_detail"],
                                          where=[("mss_system", "=", "STA"),
                                                 ("mss_message", "=",
                                                  self.mesno)],
                                          limit=1)
                    self.form.newdic[d][tdc.index("tpd_text")] = mes[0]
                self.form.doDrawDetail(self.form.newdic[d])

    def doPrint(self):
        if self.df.repeml[1] == "Y" and not self.emadd:
            key = "%s_%s_%s" % (self.opts["conum"], self.code, self.acno)
        else:
            key = "%s_all_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            key,
                            ext="pdf")
        self.form.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Statement at %s" %
                  (self.opts["conam"], self.dated),
                  fromad=self.fromad,
                  repprt=self.df.repprt,
                  repeml=self.df.repeml)
        if self.df.repeml[1] == "Y":
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
示例#5
0
class ln3040(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"])
        lonctl = gc.getCtl("lonctl", self.opts["conum"])
        if not lonctl:
            return
        self.capb = lonctl["cln_capb"]
        self.capf = lonctl["cln_capf"]
        self.lint = lonctl["cln_last"]
        self.stpl = lonctl["cln_tplnam"]
        self.fromad = lonctl["cln_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.curdt = int(self.sysdtw / 100)
        self.sper = int(self.opts["period"][1][0] / 100)
        self.eper = int(self.opts["period"][2][0] / 100)
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmes", "ctlmst", "ctlynd", "lonmf1", "lonmf2", "lontrn",
            "tplmst"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        return True

    def mainProcess(self):
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "S"), ("tpm_system", "=", "LON")],
            "order":
            "tpm_tname"
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        r2s = (("Number", "A"), ("Name", "N"))
        fld = ((("T", 0, 0, 0), "INA", 20, "Template Name", "", self.stpl, "Y",
                self.doTplNam, tpm, None, None),
               (("T", 0, 1, 0), "Id2", 7, "Start Period", "", self.sper, "N",
                self.doSPer, None, None,
                None), (("T", 0, 2, 0), "ID2", 7, "End Period", "", self.eper,
                        "N", self.doEPer, None, None,
                        None), (("T", 0, 3, 0), ("IRB", r1s), 0, "Whole File",
                                "", "N", "N", self.doWhole, None, None, None),
               (("T", 0, 4, 0), ("IRB", r2s), 0, "Sort Order", "", "A", "N",
                self.doSort, None, None, None),
               (("T", 0, 5, 0), ("IRB", r1s), 0, "Include Zero Balances", "",
                "N", "N", self.doZeros, None, None, None),
               (("T", 0, 6, 0), ("IRB", r1s), 0, "Include Pending Interest",
                "", "N", "N", self.doPend, None, None, None),
               (("T", 0, 7, 0), ("IRB", r1s), 0, "Interest Totals Only", "",
                "Y", "N", self.doITots, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doTplNam(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("tplmst",
                              where=[("tpm_tname", "=", w),
                                     ("tpm_type", "=", "S"),
                                     ("tpm_system", "=", "LON")],
                              limit=1)
        if not acc:
            return "Invalid Template Name"
        self.tname = w

    def doSPer(self, frt, pag, r, c, p, i, w):
        self.sperw = w
        self.sperd = self.df.t_disp[pag][0][p]

    def doEPer(self, frt, pag, r, c, p, i, w):
        self.eperw = w
        self.eperd = self.df.t_disp[pag][0][p]
        self.date = CCD(mthendDate((w * 100) + 1), "D1", 10)

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w

    def doSort(self, frt, pag, r, c, p, i, w):
        self.sort = w

    def doZeros(self, frt, pag, r, c, p, i, w):
        self.zeros = w

    def doPend(self, frt, pag, r, c, p, i, w):
        self.pend = w

    def doITots(self, frt, pag, r, c, p, i, w):
        self.itot = w

    def doEnd(self):
        self.df.closeProcess()
        self.emadd = self.df.repeml[2]
        if self.whole == "N":
            recs = getSingleRecords(self.opts["mf"],
                                    "lonmf1", ("lm1_acno", "lm1_name"),
                                    where=[("lm1_cono", "=",
                                            self.opts["conum"])])
        else:
            whr = [("lm1_cono", "=", self.opts["conum"])]
            if self.sort == "A":
                odr = "lm1_acno"
            else:
                odr = "lm1_name"
            recs = self.sql.getRec("lonmf1", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Error", "No Accounts Selected")
        else:
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()
            p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
            for num, rec in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                self.doProcess(rec)
            p.closeProgress()
            if p.quit or not self.form.page:
                pass
            elif self.df.repeml[1] == "N" or self.emadd:
                self.df.repeml[2] = self.emadd
                self.doPrint()
        self.opts["mf"].closeLoop()

    def doLoadStatic(self):
        cmc = self.sql.ctlmst_col
        ctm = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        for fld in cmc:
            dat = ctm[cmc.index(fld)]
            if fld in self.form.tptp:
                if fld == "ctm_logo":
                    self.form.letterhead(cmc, ctm, fld, dat)
                    continue
                self.form.tptp[fld][1] = dat
        if "letterhead" in self.form.tptp:
            self.form.letterhead(cmc, ctm, "letterhead", None)
        self.form.document_date(self.date.disp)
        self.form.bank_details(cmc, ctm, 0)

    def doProcess(self, lm1):
        l1c = self.sql.lonmf1_col
        tdc = self.form.sql.tpldet_col
        self.acno = lm1[l1c.index("lm1_acno")]
        self.emlto = lm1[l1c.index("lm1_email")]
        self.form.account_details("lm1", l1c, lm1, 1)
        for col in l1c:
            d = "%s_C00" % col
            if d in self.form.newdic:
                dat = lm1[l1c.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        lonmf2 = self.sql.getRec("lonmf2",
                                 where=[("lm2_cono", "=", self.opts["conum"]),
                                        ("lm2_acno", "=", self.acno)],
                                 order="lm2_loan")
        for loan in lonmf2:
            self.doStatement(tdc, loan)

    def doStatement(self, tdc, lm2):
        l2c = self.sql.lonmf2_col
        ltc = copyList(self.sql.lontrn_col)
        self.loan = lm2[l2c.index("lm2_loan")]
        for col in l2c:
            d = "%s_C00" % col
            if d in self.form.newdic:
                dat = lm2[l2c.index(col)]
                self.form.newdic[d][tdc.index("tpd_text")] = dat
        if self.pend == "Y":
            # Raise Pending Interest
            LoanInterest("L",
                         self.opts["mf"].dbm,
                         lm2,
                         update="Y",
                         tdate=self.date.work,
                         batch="Pending",
                         curdt=self.curdt,
                         capnm="")
        # Get Transactions
        whr = [("lnt_cono", "=", self.opts["conum"]),
               ("lnt_acno", "=", self.acno), ("lnt_loan", "=", self.loan),
               ("lnt_curdt", "<=", self.eperw)]
        odr = "lnt_curdt, lnt_trdt, lnt_type, lnt_refno"
        if self.itot == "Y":
            w = whr[:]
            w.append(("lnt_type", "<>", 4))
            trns = self.sql.getRec("lontrn", where=w, order=odr)
            if self.capb == "A":  # Anniversary
                fcap = [lm2[l2c.index("lm2_start")], 0]
                if self.capf == "A":
                    fcap[1] = projectDate(fcap[0], 1, typ="years")
                else:
                    fcap[1] = projectDate(fcap[0], 6, typ="months")
            else:  # Financial
                periods = self.sql.getRec(
                    "ctlynd",
                    cols=["cye_period", "cye_start", "cye_end"],
                    where=[("cye_cono", "=", self.opts["conum"])],
                    order="cye_period")
                fcap = [periods[0][1], periods[0][2]]
                if self.capf == "B":  # Bi-Annual
                    fcap[1] = projectDate(fcap[1], -6, typ="months")
            capdt = [copyList(fcap)]
            while fcap[1] < self.date.work:
                if self.capf == "A":
                    fcap[0] = projectDate(fcap[0], 1, typ="years")
                    fcap[1] = projectDate(fcap[1], 1, typ="years")
                else:
                    fcap[0] = projectDate(fcap[0], 6, typ="months")
                    fcap[1] = projectDate(fcap[1], 6, typ="months")
                if fcap[1] <= self.date.work:
                    capdt.append(copyList(fcap))
            for capd in capdt:
                w = whr[:]
                w.append(("lnt_type", "=", 4))
                w.append(("lnt_trdt", "between", capd[0], capd[1]))
                ints = self.sql.getRec("lontrn", where=w, order=odr)
                if not ints:
                    continue
                ddes = "Dr Int %s to %s"
                cdes = "Cr Int %s to %s"
                dbal = 0
                cbal = 0
                for trn in ints:
                    amt = trn[ltc.index("lnt_tramt")]
                    if amt < 0:
                        cbal = float(ASD(cbal) + ASD(amt))
                    else:
                        dbal = float(ASD(dbal) + ASD(amt))
                if dbal:
                    trn[ltc.index("lnt_tramt")] = dbal
                    trn[ltc.index("lnt_desc")] = ddes % (CCD(
                        int(capd[0] / 100), "D2",
                        7).disp, CCD(int(capd[1] / 100), "D2", 7).disp)
                    trns.append(copyList(trn))
                if cbal:
                    trn[ltc.index("lnt_tramt")] = cbal
                    trn[ltc.index("lnt_desc")] = cdes % (CCD(
                        int(capd[0] / 100), "D2",
                        7).disp, CCD(int(capd[1] / 100), "D2", 7).disp)
                    trns.append(copyList(trn))
            trns = sorted(trns, key=itemgetter(5))
        else:
            trns = self.sql.getRec("lontrn", where=whr, order=odr)
        if not trns:
            return
        self.bal = 0
        self.tots = 0
        if self.sperw:
            obal = 0
            trans = copyList(trns)
            for trn in trans:
                tramt = trn[self.sql.lontrn_col.index("lnt_tramt")]
                if trn[self.sql.lontrn_col.index("lnt_curdt")] < self.sperw:
                    obal = float(ASD(obal) + ASD(tramt))
                    trns.remove(trn)
            trn[ltc.index("lnt_type")] = 3
            trn[ltc.index("lnt_trdt")] = (self.sperw * 100) + 1
            trn[ltc.index("lnt_refno")] = "O/Bal"
            trn[ltc.index("lnt_batch")] = ""
            trn[ltc.index("lnt_tramt")] = obal
            trn[ltc.index("lnt_desc")] = "Opening Balance"
            trn[ltc.index("lnt_batind")] = ""
            trns.insert(0, trn)
        trans = []
        for trn in trns:
            tramt = trn[ltc.index("lnt_tramt")]
            self.tots = float(ASD(self.tots) + ASD(tramt))
            if tramt < 0:
                trn.extend([0, tramt])
            else:
                trn.extend([tramt, 0])
            trans.append(trn)
        ltc.extend(["line_debit", "line_credit"])
        if self.zeros == "N" and not self.tots:
            return
        self.doBody(ltc, trans, tdc)
        self.doTotal(tdc)
        self.doTail(tdc)
        if self.pend == "Y":
            self.opts["mf"].dbm.rollbackDbase()
        if self.df.repeml[1] == "Y" and not self.emadd:
            self.df.repeml[2] = self.emlto
            self.doPrint()

    def doPrint(self):
        if self.df.repeml[1] == "Y" and not self.emadd:
            key = "%s_%s_%s" % (self.opts["conum"], self.acno, self.loan)
        else:
            key = "%s_all_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            key,
                            ext="pdf")
        self.form.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Statement at %s" %
                  (self.opts["conam"], self.date.disp),
                  repprt=self.df.repprt,
                  fromad=self.fromad,
                  repeml=self.df.repeml)
        if self.df.repeml[1] == "Y":
            self.form = DrawForm(self.opts["mf"].dbm,
                                 self.tname,
                                 wrkdir=self.opts["mf"].rcdic["wrkdir"])
            self.doLoadStatic()
            self.form.doNewDetail()

    def doBody(self, ltc, lnt, tdc):
        page = 0
        count = 0
        text = tdc.index("tpd_text")
        for trans in lnt:
            if not count:
                page += 1
                count = self.doHeader(page)
            if count == self.form.maxlines:
                page = self.doCfwd(page)
                count = self.doHeader(page)
            for cod in self.form.body:
                if cod == "type_code":
                    c = "lnt_type"
                elif cod == "line_paid":
                    c = "paid"
                else:
                    c = cod
                d = "%s_C%02i" % (cod, count)
                if cod == "type_code":
                    ttyp = trans[ltc.index(c)]
                    self.form.newdic[d][text] = lntrtp[ttyp - 1][0]
                elif c in ("line_debit", "line_credit"):
                    tramt = trans[ltc.index(c)]
                    self.bal = float(ASD(self.bal) + ASD(tramt))
                    self.form.newdic[d][text] = trans[ltc.index(c)]
                elif c == "line_balance":
                    self.form.newdic[d][text] = self.bal
                else:
                    self.form.newdic[d][text] = trans[ltc.index(c)]
                self.form.doDrawDetail(self.form.newdic[d])
            count += 1
        for x in range(count, self.form.maxlines):
            for cod in self.form.body:
                d = "%s_C%02i" % (cod, x)
                self.form.newdic[d][tdc.index("tpd_text")] = "BLANK"
                self.form.doDrawDetail(self.form.newdic[d])

    def doHeader(self, page):
        self.form.add_page()
        tdc = self.form.sql.tpldet_col
        for key in self.form.newkey:
            nl = copyList(self.form.newdic[key])
            if nl[tdc.index("tpd_place")] != "A":
                continue
            if nl[tdc.index("tpd_detseq")] == "lm1_acno_C00":
                nl[tdc.index("tpd_text")] = self.acno
            elif nl[tdc.index("tpd_detseq")] == "page_number_C00":
                nl[tdc.index("tpd_text")] = str(page)
            self.form.doDrawDetail(nl)
        return 0

    def doCfwd(self, page):
        if "carried_forward" in self.form.tptp:
            tdc = self.form.sql.tpldet_col
            line = copyList(self.form.cfwd)
            line[tdc.index("tpd_text")] = "Continued on Page %i" % (page + 1)
            self.form.doDrawDetail(line)
        return page + 1

    def doTotal(self, tdc):
        for c in self.form.total:
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                line = self.form.newdic[d]
                if c == "total_balance":
                    line[tdc.index("tpd_text")] = self.tots
                self.form.doDrawDetail(line)

    def doTail(self, tdc):
        for c in self.form.tail:
            t = "%s_T00" % c
            if c in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[c])
            elif t in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[t])
            d = "%s_C00" % c
            if d in self.form.newdic:
                self.form.doDrawDetail(self.form.newdic[d])

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()