Ejemplo n.º 1
0
class wgc420(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",
            prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.fromad = wagctl["ctw_emadd"]
        t = time.localtime()
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        return True

    def mainProcess(self):
        self.tit = ("Wages Messages Listing (%s)" % self.__class__.__name__)
        fld = []
        tnd = ((self.doEnd,"Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"], title=self.tit, eflds=fld,
            tend=tnd, txit=txt, view=("N","V"))

    def doEnd(self):
        self.df.closeProcess()
        recs = self.sql.getRec("ctlmes", cols=["mss_system",
            "mss_message", "mss_detail"], where=[("mss_system", "=", "WAG")],
            order="mss_system, mss_message")
        if not recs:
            showError(self.opts["mf"].body, "Transaction Error",
                "No Transactions Selected")
        else:
            self.printReport(recs)
        self.opts["mf"].closeLoop()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%-3u %-76s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pgnum = 0
        self.pglin = 999
        old_sys = recs[0][0]
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            self.sys = CCD(dat[0], "NA", 3)
            mes = CCD(dat[1], "UI", 3)
            det = CCD(dat[2], "NA", 150)
            fmt = textFormat(det.work, width=30)
            if len(fmt) > 5:
                l = 5
            else:
                l = len(fmt)
            if old_sys != self.sys.work:
                old_sys = self.sys.work
                self.pglin = self.fpdf.lpp
            if self.pglin > (self.fpdf.lpp - 5):
                self.pageHeading()
            self.fpdf.drawText("%-14s %s %-10s %s" %
                ("", mes.disp, "", fmt[0]))
            self.pglin += 1
            for q in range(1, len(fmt)):
                self.fpdf.drawText("%-29s %s" % ("", fmt[q]))
                self.pglin += 1
            self.fpdf.drawText()
            for r in range(l, 5):
                fmt.append("")
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                self.__class__.__name__, 0, ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"], pdfnam=pdfnam, header=self.tit,
                repprt=self.df.repprt, fromad=self.fromad,
                repeml=self.df.repeml)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.pgnum += 1
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-s %-10s" %
            ("Salaries and Wages Messages as at", self.sysdtd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-14s %-3s %-10s %-30s" %
            ("", "Num", "", "Message"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 6

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 2
0
class cr3010(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, ["ctlbat", "crstrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        crsctl = gc.getCtl("crsctl", self.opts["conum"])
        if not crsctl:
            return
        self.fromad = crsctl["ctc_emadd"]
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Creditors Batch Error Listing (%s)" %
                    self.__class__.__name__)
        data = ["All Types"]
        for typ in crtrtp:
            data.append(typ[1])
        btt = {"stype": "C", "titl": "Valid Types", "data": data, "retn": "I"}
        btm = {
            "stype":
            "R",
            "tables": ("ctlbat", ),
            "cols":
            (("btm_batno", "", 0, "Bat-Num"), ("btm_rtyp", ("xx", crtrtp), 20,
                                               "Type"),
             ("btm_curdt", "", 0, "Curr-Dt"), ("btm_multi", "", 0, "M")),
            "where": [("btm_cono", "=", self.opts["conum"]),
                      ("btm_styp", "=", "CRS"), ("btm_ind", "=", "N")],
            "whera": []
        }
        fld = ((("T", 0, 0, 0), "IUI", 1, "Type", "Transaction Type", "", "Y",
                self.doBatTyp, btt, None, None),
               (("T", 0, 1, 0), "INa", 7, "Batch-Number", "Batch Number", "",
                "Y", self.doBatNum, btm, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"))

    def doBatTyp(self, frt, pag, r, c, p, i, w):
        if w > len(crtrtp):
            return "Invalid Batch Type"
        self.rtyp = w
        if self.rtyp:
            self.df.topf[pag][1][8]["whera"] = [["T", "btm_rtyp", 0]]
        else:
            self.df.topf[pag][1][8]["whera"] = []

    def doBatNum(self, frt, pag, r, c, p, i, w):
        self.batno = w

    def doEnd(self):
        self.df.closeProcess()
        whr = [("btm_cono", "=", self.opts["conum"]), ("btm_styp", "=", "CRS")]
        if self.rtyp:
            whr.append(("btm_rtyp", "=", self.rtyp))
        if self.batno:
            whr.append(("btm_batno", "=", self.batno))
        whr.append(("btm_ind", "=", "N"))
        odr = "btm_rtyp, btm_batno"
        recs = self.sql.getRec("ctlbat", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Batch Error",
                      "No Batch Transactions Selected")
        else:
            self.printReport(recs)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-82s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.btot = [0, 0]
        self.pgnum = 0
        self.pglin = 999
        bc = self.sql.ctlbat_col
        tc = self.sql.crstrn_col
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            self.rtyp = CCD(dat[bc.index("btm_rtyp")], "UI", 1)
            self.batno = CCD(dat[bc.index("btm_batno")], "Na", 7)
            self.curdt = CCD(dat[bc.index("btm_curdt")], "D2", 7)
            self.multi = CCD(dat[bc.index("btm_multi")], "UA", 1)
            self.trno = CCD(dat[bc.index("btm_trno")], "UI", 7)
            self.trval = CCD(dat[bc.index("btm_trval")], "SD", 13.2)
            whr = [("crt_cono", "=", self.opts["conum"]),
                   ("crt_type", "=", self.rtyp.work),
                   ("crt_batch", "=", self.batno.work),
                   ("crt_batind", "=", "N")]
            odr = "crt_seq"
            trndat = self.sql.getRec("crstrn", where=whr, order=odr)
            if not trndat:
                continue
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            else:
                self.batchHeading()
            for trn in trndat:
                acno = CCD(trn[tc.index("crt_acno")], "NA", 7)
                trdt = CCD(trn[tc.index("crt_trdt")], "D1", 10)
                ref1 = CCD(trn[tc.index("crt_ref1")], "Na", 9)
                desc = CCD(trn[tc.index("crt_desc")], "NA", 30)
                tramt = CCD(trn[tc.index("crt_tramt")], "SD", 13.2)
                taxamt = CCD(trn[tc.index("crt_taxamt")], "SD", 13.2)
                if self.pglin > self.fpdf.lpp:
                    self.pageHeading()
                self.fpdf.drawText("%s %s %s %s %s %s" %
                                   (acno.disp, trdt.disp, ref1.disp, desc.disp,
                                    tramt.disp, taxamt.disp))
                self.btot[0] += 1
                self.btot[1] = float(ASD(self.btot[1]) + ASD(tramt.work))
                self.pglin += 1
            self.batchTotal()
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.pgnum += 1
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText(
            "%-36s %43s %5s" %
            ("Creditors Ledger Batch Error Listing", "Page", self.pgnum))
        self.fpdf.drawText()
        self.fpdf.setFont()
        self.pglin = 4
        self.batchHeading()

    def batchHeading(self):
        if self.pglin > self.fpdf.lpp - 4:
            self.pageHeading()
            return
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(
            "%-s %-s %-s %-17s %-s %-s %-s %s" %
            ("Batch:", self.batno.disp, "Type:", crtrtp[self.rtyp.work - 1][1],
             "Current Date:", self.curdt.disp, "Multi Allocations:",
             self.multi.disp))
        self.fpdf.drawText()
        self.fpdf.drawText("%-7s %-10s %-9s %-30s %-13s %-13s" %
                           ("Acc-Num", "   Date", "Reference", "Description",
                            "  Trn-Amount", "  Tax-Amount"))
        self.fpdf.underLine(self.head)
        self.fpdf.setFont()
        self.pglin += 4

    def batchTotal(self):
        if self.pglin > self.fpdf.lpp - 5:
            self.pageHeading()
        self.fpdf.drawText()
        j = CCD(self.trno.work, "SI", 7)
        k = CCD(self.trval.work, "SD", 13.2)
        self.fpdf.drawText("%-39s %-10s %-7s %-10s %-13s" %
                           ("Prelisted", "Quantity", j.disp, "Value", k.disp))
        l = CCD(self.btot[0], "SI", 7)
        m = CCD(self.btot[1], "SD", 13.2)
        self.fpdf.drawText("%-39s %-10s %-7s %-10s %-13s" %
                           ("Entered", "Quantity", l.disp, "Value", m.disp))
        n = CCD((j.work - l.work), "SI", 7)
        o = CCD(float(ASD(k.work) - ASD(m.work)), "SD", 13.2)
        self.fpdf.drawText("%-39s %-10s %-7s %-10s %-13s" %
                           ("Difference", "Quantity", n.disp, "Value", o.disp))
        self.fpdf.setFont(style="B")
        self.fpdf.underLine(self.head)
        self.fpdf.setFont()
        self.btot[0] = 0
        self.btot[1] = 0
        self.pglin += 5

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 3
0
class si3010(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,
                       ["ctlrep", "drsmst", "slsiv1", "slsiv2"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        slsctl = gc.getCtl("slsctl", self.opts["conum"])
        if not slsctl:
            return
        self.fromad = slsctl["ctv_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i)" % \
            (t[0], t[1], t[2], t[3], t[4])
        self.slstot = [0, 0, 0, 0]
        self.tot2 = 0
        self.tot3 = 0
        self.tot4 = 0
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Sales Orders Outstanding (%s)" % self.__class__.__name__)
        si1 = {
            "stype":
            "R",
            "tables": ("slsiv1", ),
            "cols":
            (("si1_docno", "", 0, "Order-Num"), ("si1_chain", "", 0, "Chn"),
             ("si1_acno", "", 0, "Drs-Acc"), ("si1_date", "", 0,
                                              "Order-Date")),
            "where": [("si1_cono", "=", self.opts["conum"]),
                      ("si1_invno", "=", "")],
            "whera": [("T", "si1_rtn", 0)]
        }
        r1s = (("Sales", "O"), ("Works", "W"), ("Quotes", "Q"))
        r2s = (("List", "L"), ("Detail", "D"))
        r3s = (("Rep's Name", "R"), ("Delivery Address", "D"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Order Type", "", "O", "Y",
                self.doOrdTyp, None, None, None),
               (("T", 0, 1, 0), ("IRB", r2s), 0, "Report Type", "", "L", "Y",
                self.doRepTyp, None, None,
                None), (("T", 0, 2, 0), ("IRB", r3s), 0, "Content", "", "R",
                        "Y", self.doContent, None, None,
                        None), (("T", 0, 3, 0), "IUI", 9, "From Order Number",
                                "", "", "Y", self.doOrd1, si1, None, None),
               (("T", 0, 4, 0), "IUI", 9, "To   Order Number", "", "", "Y",
                self.doOrd2, si1, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "N"))

    def doOrdTyp(self, frt, pag, r, c, p, i, w):
        self.otype = w

    def doRepTyp(self, frt, pag, r, c, p, i, w):
        self.rtype = w
        if self.rtype == "L":
            self.ord1 = 0
            self.ord2 = 999999999
            self.df.setWidget(self.df.topEntry[0][5][3][0], state="show")
            self.df.setWidget(self.df.topEntry[0][5][4][0], state="show")
        else:
            self.df.loadEntry(frt, pag, p + 1, data="")
            self.df.setWidget(self.df.topEntry[0][5][3][0], state="hide")
            self.df.setWidget(self.df.topEntry[0][5][4][0], state="hide")
            return "sk1"

    def doContent(self, frt, pag, r, c, p, i, w):
        self.content = w
        return "sk2"

    def doOrd1(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("slsiv1",
                                  where=[("si1_cono", "=", self.opts["conum"]),
                                         ("si1_rtn", "=", self.otype),
                                         ("si1_docno", "=", w),
                                         ("si1_invno", "=", "")],
                                  limit=1)
            if not acc:
                return "This is Not an Outstanding Order"
        self.ord1 = w

    def doOrd2(self, frt, pag, r, c, p, i, w):
        if w:
            if w < self.ord1:
                return "Invalid Last Order < First Order"
            acc = self.sql.getRec("slsiv1",
                                  where=[("si1_cono", "=", self.opts["conum"]),
                                         ("si1_rtn", "=", self.otype),
                                         ("si1_docno", "=", w),
                                         ("si1_invno", "=", "")],
                                  limit=1)
            if not acc:
                return "This is Not an Outstanding Order"
            self.ord2 = w
        else:
            self.ord2 = 999999999

    def doEnd(self):
        self.df.closeProcess()
        whr = (("si1_cono", "=", self.opts["conum"]), ("si1_rtn", "=",
                                                       self.otype),
               ("si1_docno", "between", self.ord1, self.ord2), ("si1_invno",
                                                                "=", ""))
        odr = "si1_docno"
        recs = self.sql.getRec("slsiv1", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Orders Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [
            "%03u %-30s %s" %
            (self.opts["conum"], self.opts["conam"], self.sysdttm)
        ]
        self.expheads.append("Outstanding Sales Orders Report as at %s" % \
            self.sysdtd)
        self.expcolsh = [[
            "Order-Num", "Order-Date", "Chn", "Acc-Num", "Name", "Rep",
            "Rep-Name", "Job-Num", "Taxable", "Non-Taxable", "Total-Tax",
            "Total-Value"
        ]]
        if self.rtype == "L" and self.content == "D":
            self.expcolsh[0][6] = "Delivery-Address"
        self.expforms = [("Na", 9), ("D1", 10), ("UI", 3), ("NA", 7),
                         ("NA", 30), ("Na", 3), ("NA", 30), ("Na", 7),
                         ("SD", 13.2), ("SD", 13.2), ("SD", 13.2),
                         ("SD", 13.2)]
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            if not self.getValues(dat):
                continue
            self.getOrdTot()
            self.expdatas.append([
                "BODY",
                [
                    self.odr.work, self.dte.work, self.chn.work, self.drs.work,
                    self.drsnam, self.rep.work, self.context, self.job.work,
                    self.total_taxable, self.total_nontaxable, self.total_tax,
                    self.total_value
                ]
            ])
        self.expdatas.append(["BLANK"])
        self.expdatas.append(["TOTAL", [""] * 8 + self.slstot])
        p.closeProgress()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        if self.rtype == "L":
            self.head = "%03u %-157s" % (self.opts["conum"],
                                         self.opts["conam"])
        else:
            self.head = "%03u %-86s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            if not self.getValues(dat):
                continue
            if self.rtype == "D":
                self.printHeader()
            self.printBody()
        if self.rtype == "L":
            t1 = CCD(self.slstot[0], "SD", 13.2)
            t2 = CCD(self.slstot[1], "SD", 13.2)
            t3 = CCD(self.slstot[2], "SD", 13.2)
            t4 = CCD(self.slstot[3], "SD", 13.2)
            self.fpdf.drawText()
            self.fpdf.drawText("%106s %s %s %s %s" %
                               ("", t1.disp, t2.disp, t3.disp, t4.disp))
        p.closeProgress()
        if not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def getValues(self, data):
        col = self.sql.slsiv1_col
        self.odr = CCD(data[col.index("si1_docno")], "Na", 9)
        self.si2 = self.sql.getRec("slsiv2",
                                   where=[("si2_cono", "=",
                                           self.opts["conum"]),
                                          ("si2_rtn", "=", self.otype),
                                          ("si2_docno", "=", self.odr.work)],
                                   order="si2_line")
        if not self.si2:
            return
        self.mod = CCD(data[col.index("si1_mode")], "UA", 1)
        self.chn = CCD(data[col.index("si1_chain")], "UI", 3)
        self.drs = CCD(data[col.index("si1_acno")], "NA", 7)
        acc = self.sql.getRec("drsmst",
                              cols=["drm_name"],
                              where=[("drm_cono", "=", self.opts["conum"]),
                                     ("drm_chain", "=", self.chn.work),
                                     ("drm_acno", "=", self.drs.work)],
                              limit=1)
        if not acc:
            self.drsnam = ""
        else:
            self.drsnam = acc[0]
        self.dte = CCD(data[col.index("si1_date")], "D1", 10)
        self.job = CCD(data[col.index("si1_jobno")], "Na", 7)
        self.rep = CCD(data[col.index("si1_rep")], "Na", 3)
        if self.rtype == "L" and self.content == "R":
            acc = self.sql.getRec("ctlrep",
                                  cols=["rep_name"],
                                  where=[("rep_cono", "=", self.opts["conum"]),
                                         ("rep_code", "=", self.rep.work)],
                                  limit=1)
            if not acc:
                self.context = ""
            else:
                self.context = acc[0]
        else:
            self.context = data[col.index("si1_add1")]
        return True

    def printHeader(self):
        self.pageHeading()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText()
        if self.rtype == "L":
            if self.content == "R":
                text = "Rep-Name"
            else:
                text = "Delivery-Address"
            self.fpdf.drawText("%-9s %-10s %-3s %-7s %-30s %-3s %-30s %-7s"\
                "%13s %13s %13s %13s" % ("Order-Num", "Order-Date", "Chn",
                "Acc-Num", "Name", "Rep", text, "Job-Num", "Taxable",
                "Non-Taxable", "Total-Tax", "Total-Value"))
            self.pglin += 3
        else:
            text = "Order Number: %-9s Date: %-10s Salesman: %-3s %-30s" % \
                (self.odr.disp, self.dte.disp, self.rep.disp, self.context)
            self.fpdf.drawText(text)
            self.fpdf.drawText()
            text = "Chain: %-3s  Acc-Num: %-7s  Name: %-30s" % (
                self.chn.disp, self.drs.disp, self.drsnam)
            self.fpdf.drawText(text)
            self.fpdf.drawText()
            self.fpdf.drawText("%-3s %-20s %-30s %-1s %10s  %-1s %11s %-6s" % \
                ("Grp", "Product-Code", "Description", "L", "Qty-Ord", "V",
                "U-Price", "Disc-%"))
            self.pglin += 7
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        if self.otype == "O":
            txt = "Sales"
        elif self.otype == "W":
            txt = "Works"
        else:
            txt = "Quote"
        self.fpdf.drawText("%-37s %-10s" % \
            ("Outstanding %s Documents Report as at" % txt, self.sysdtd))
        self.fpdf.setFont()
        self.pglin = 3

    def printBody(self):
        if self.rtype == "L":
            if self.pglin > self.fpdf.lpp:
                self.printHeader()
            self.getOrdTot()
            v1 = CCD(self.total_taxable, "SD", 13.2)
            v2 = CCD(self.total_nontaxable, "SD", 13.2)
            v3 = CCD(self.total_tax, "SD", 13.2)
            v4 = CCD(self.total_value, "SD", 13.2)
            text = "%s %s %s %s %-30s %s %-30s %s %s %s %s %s" % \
                (self.odr.disp, self.dte.disp, self.chn.disp, self.drs.disp,
                self.drsnam, self.rep.disp, self.context, self.job.disp,
                v1.disp, v2.disp, v3.disp, v4.disp)
            self.fpdf.drawText(text)
            self.pglin += 1
        else:
            col = self.sql.slsiv2_col
            for dat in self.si2:
                grp = CCD(dat[col.index("si2_group")], "UA", 3)
                cod = CCD(dat[col.index("si2_code")], "NA", 20)
                des = CCD(dat[col.index("si2_desc")], "NA", 30)
                loc = CCD(dat[col.index("si2_loc")], "UA", 1)
                qty = CCD(dat[col.index("si2_qty")], "SD", 11.2)
                vat = CCD(dat[col.index("si2_vat_code")], "UA", 1)
                prc = CCD(dat[col.index("si2_price")], "UD", 11.2)
                dis = CCD(dat[col.index("si2_disc_per")], "UD", 6.2)
                if self.pglin > self.fpdf.lpp:
                    self.printHeader()
                self.fpdf.drawText("%s %s %s %s %s %s %s %s" %
                                   (grp.disp, cod.disp, des.disp, loc.disp,
                                    qty.disp, vat.disp, prc.disp, dis.disp))
                self.pglin += 1

    def getOrdTot(self):
        self.total_taxable = 0
        self.total_nontaxable = 0
        self.total_tax = 0
        self.total_value = 0
        col = self.sql.slsiv2_col
        for dat in self.si2:
            dis = CCD(dat[col.index("si2_disc_per")], "UD", 6.2)
            qty = CCD(dat[col.index("si2_qty")], "SD", 13.2)
            pri = CCD(dat[col.index("si2_price")], "UD", 12.2)
            vat = CCD(dat[col.index("si2_vat_rate")], "UD", 6.2)
            excpri = round((pri.work * 1), 2)
            incrat = float(ASD(100.0) + ASD(vat.work))
            incpri = round((pri.work * incrat / 100.0), 4)
            net = float(ASD(100.0) - ASD(dis.work))
            excamt = round((qty.work * excpri * net / 100.0), 2)
            incamt = round((qty.work * incpri * net / 100.0), 2)
            vatamt = float(ASD(incamt) - ASD(excamt))
            if excamt == incamt:
                self.total_nontaxable = float(ASD(self.total_nontaxable) + \
                    ASD(excamt))
            else:
                self.total_taxable = float(ASD(self.total_taxable) + \
                    ASD(excamt))
            self.total_tax = float(ASD(self.total_tax) + ASD(vatamt))
            self.total_value = float(ASD(self.total_value) + ASD(incamt))
        self.slstot[0] = float(ASD(self.slstot[0]) + ASD(self.total_taxable))
        self.slstot[1] = float(
            ASD(self.slstot[1]) + ASD(self.total_nontaxable))
        self.slstot[2] = float(ASD(self.slstot[2]) + ASD(self.total_tax))
        self.slstot[3] = float(ASD(self.slstot[3]) + ASD(self.total_value))

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 4
0
class st3120(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,
                       ["strloc", "strgrp", "strmf1", "strmf2"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        self.fromad = strctl["cts_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i)" % (
            t[0], t[1], t[2], t[3], t[4])
        self.head = "%03u %-30s" % (self.opts["conum"], self.opts["conam"])
        self.colsh = [
            "Grp", "Product-Code", "Description", "U.O.I", "Qty-Balance",
            "Qty-OnOrder", "Qty-BkOrder", "Qty-ToOrder"
        ]
        self.forms = [("UA", 3), ("NA", 20), ("NA", 30), ("NA", 10),
                      ("SD", 12, 2), ("SD", 12.2), ("SD", 12.2), ("SD", 12.2)]
        self.stot = 0
        self.gtot = 0
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Stock On Hand Report (%s)" % self.__class__.__name__)
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "ID1", 10, "Reporting Date", "", self.sysdtw,
                "Y", self.doDate, None, None, ("efld", )),
               (("T", 0, 1,
                 0), "IUA", 1, "Location", "", "", "Y", self.doLoc, loc, None,
                ("efld", )), (("T", 0, 2, 0), "IUA", 3, "Product Group", "",
                              "", "Y", self.doGrp, grp, None, ("efld", )),
               (("T", 0, 3, 0), ("IRB", r1s), 0, "Include Zeros", "", "N", "Y",
                self.doZero, None, None, None, None,
                "Include Items Which Have a Zero Order Quantity"))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "N"))

    def doDate(self, frt, pag, r, c, p, i, w):
        self.repdtw = w
        self.repdtd = self.df.t_disp[pag][0][0]

    def doLoc(self, frt, pag, r, c, p, i, w):
        if not w:
            self.loc = ""
            self.locd = "ALL"
        else:
            acc = self.sql.getRec("strloc",
                                  cols=["srl_desc"],
                                  where=[("srl_cono", "=", self.opts["conum"]),
                                         ("srl_loc", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Location"
            self.loc = w
            self.locd = acc[0]

    def doGrp(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("strgrp",
                                  cols=["gpm_desc"],
                                  where=[("gpm_cono", "=", self.opts["conum"]),
                                         ("gpm_group", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Group"
        self.group = w

    def doZero(self, frt, pag, r, c, p, i, w):
        self.zero = w

    def doEnd(self):
        self.df.closeProcess()
        whr = [("st1_cono", "=", self.opts["conum"])]
        if self.group:
            whr.append(("st1_group", "=", self.group))
        whr.append(("st1_type", "<>", "X"))
        whr.append(("st1_value_ind", "=", "A"))
        recs = self.sql.getRec(
            "strmf1",
            cols=["st1_group", "st1_code", "st1_desc", "st1_uoi"],
            where=whr,
            order="st1_group, st1_code")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Records Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        self.opts["mf"].closeLoop()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [self.head + " %s" % self.sysdttm]
        self.expheads.append("Stock to Order Report as at %s" % self.sysdtd)
        self.expheads.append("(Options: Report Date %s)" % self.repdtd)
        self.expheads.append("Location %s  %s" % (self.loc, self.locd))
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            self.expdatas.append([
                "BODY",
                [
                    vals[0].work, vals[1].work, vals[2].work, vals[3].work,
                    vals[4].work, vals[5].work, vals[6].work, vals[7].work
                ]
            ])
        p.closeProgress()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        chrs = len(self.colsh)
        for f in self.forms:
            chrs += int(f[1])
        if f[0][0].lower() == "s":
            chrs -= 2
        else:
            chrs -= 1
        self.head1 = self.head
        self.head2 = "Stock to Order Report as at %s" % self.sysdtd
        pad = chrs - len(self.head2)
        self.head2 = self.head2 + (" " * pad)
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head2)
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText(
                "%s %s %s %s %s %s %s %s" %
                (vals[0].disp, vals[1].disp, vals[2].disp, vals[3].disp,
                 vals[4].disp, vals[5].disp, vals[6].disp, vals[7].disp))
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            if self.pglin > (self.fpdf.lpp - 2):
                self.pageHeading()
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)
        self.closeProcess()

    def getValues(self, data):
        grp = CCD(data[0], "UA", 3)
        code = CCD(data[1], "NA", 20)
        desc = CCD(data[2], "UA", 30)
        uoi = CCD(data[3], "NA", 10)
        whr = [("st2_cono", "=", self.opts["conum"]),
               ("st2_group", "=", grp.work), ("st2_code", "=", code.work)]
        if self.loc:
            whr.append(("st2_loc", "=", self.loc))
        st2 = self.sql.getRec(
            "strmf2",
            cols=["st2_reord_ind", "st2_reord_level", "st2_reord_qty"],
            where=whr,
            limit=1)
        if not st2:
            return
        if self.zero == "N" and not st2[1]:
            return
        req = CCD(st2[1], "SD", 12.2)
        bals = Balances(self.opts["mf"],
                        "STR",
                        self.opts["conum"],
                        int(self.repdtw / 100),
                        keys=(grp.work, code.work, self.loc))
        cbal, obal, bbal = bals.doStrOrds()
        tbal = float(ASD(cbal.work) + ASD(obal.work) - ASD(bbal.work))
        if req.work < tbal:
            if self.zero == "N":
                return
            tbal = CCD(0, "SD", 12.2)
            return (grp, code, desc, uoi, cbal, obal, bbal, tbal)
        tbal = float(ASD(req.work) - ASD(tbal))
        if tbal < st2[2]:
            tbal = st2[2]
        tbal = CCD(tbal, "SD", 12.2)
        if self.zero == "N" and not tbal.work:
            return
        if self.zero == "Y" and not cbal.work and not obal.work and not \
                                            bbal.work and not tbal.work:
            return
        return (grp, code, desc, uoi, cbal, obal, bbal, tbal)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head1)
        self.fpdf.drawText()
        self.fpdf.drawText(self.head2)
        self.fpdf.drawText()
        self.fpdf.drawText("%-22s%-10s%-1s" % \
            ("(Options: Report Date-", self.df.t_disp[0][0][0], ")"))
        self.fpdf.drawText()
        self.fpdf.drawText("%-8s %s  %s" % \
            ("Location", self.loc, self.locd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-3s %-20s %-30s %-10s %11s  %11s  %11s  %11s" % \
            ("Grp", "Product-Code", "Description", "U.O.I", "Qty-Balance",
            "Qty-OnOrder", "Qty-BkOrder", "Qty-ToOrder"))
        self.fpdf.drawText("%s" % (self.fpdf.suc * len(self.head2)))
        self.fpdf.setFont()
        self.pglin = 10

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 5
0
class gl3020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["ctlmst", "genmst", "gentrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        # Check for Multiple Companies
        coy = self.sql.getRec("ctlmst", cols=["count(*)"], limit=1)
        if coy[0]:
            self.multi = "Y"
        else:
            self.multi = "N"
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.head = "%03u %-30s" % (self.opts["conum"], self.opts["conam"])
        self.colsh = [
            "TP", "BatchNo", "Coy", "Acc-Num", "Description", "Reference",
            "Date", "Debits", "Credits", "Tax-Amount", "T", "Remarks"
        ]
        self.forms = [("UI", 2, False, False, True), ("Na", 7),
                      ("UI", 3, False, False, True),
                      ("UI", 7, False, False, True), ("NA", 30), ("Na", 9),
                      ("D1", 10), ("SD", 15.2), ("SD", 15.2), ("SD", 15.2),
                      ("UA", 1), ("NA", 30)]
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        self.gqt = [0] * (len(gltrtp) + 1)
        self.gdr = [0] * (len(gltrtp) + 1)
        self.gcr = [0] * (len(gltrtp) + 1)
        self.gvt = [0] * (len(gltrtp) + 1)
        self.totind = "N"
        self.other = "N"
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "General Ledger Audit Trail (%s)" %
                    self.__class__.__name__)
        data = ["All Types"]
        for typ in gltrtp:
            data.append(typ[1])
        btt = {"stype": "C", "titl": "Valid Types", "data": data, "retn": "I"}
        btm = {
            "stype":
            "R",
            "tables": ("gentrn", ),
            "cols": (("glt_batch", "", 0,
                      "Bat-Num"), ("glt_type", ("xx", gltrtp), 20, "Type"),
                     ("glt_curdt", "", 0, "Cur-Dat")),
            "where": [],
            "group":
            "glt_batch, glt_type, glt_curdt",
            "order":
            "glt_type, glt_curdt, glt_batch"
        }
        r1s = (("Financial", "F"), ("Capture", "C"))
        r2s = (("Yes", "Y"), ("No", "N"))
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["F", "", "", "", "", "", "", "Y"]
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = [(("T", 0, 0, 0), ("IRB", r1s), 0, "Period Type", "", var[0],
                "Y", self.doPtyp, None, None, None),
               (("T", 0, 1, 0), "Id2", 7, "Starting Period", "", self.s_per,
                "N", self.doStartPer, None, None, ("efld", )),
               (("T", 0, 2, 0), "Id2", 7, "Ending Period", "", self.e_per, "N",
                self.doEndPer, None, None, ("efld", )),
               (("T", 0, 3, 0), "Id1", 10, "Starting Date", "", self.sysdtw,
                "N", self.doStartDat, None, None, ("efld", )),
               (("T", 0, 4, 0), "Id1", 10, "Ending Date", "", self.sysdtw, "N",
                self.doEndDat, None, None, ("efld", )),
               (("T", 0, 5, 0), "IUI", 1, "Type", "Transaction Type", var[5],
                "N", self.doBatTyp, btt, None, None),
               (("T", 0, 6, 0), "INa", 7, "Batch Number", "", var[6], "N",
                self.doBatNum, btm, None, None),
               (("T", 0, 7, 0), ("IRB", r2s), 0, "Totals Only", "", var[7],
                "N", self.doTots, None, None, None)]
        if self.multi == "Y":
            fld.append((("T", 0, 8, 0), ("IRB", r2s), 10, "Other Companies",
                        "", "N", "N", self.doCoy, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doPtyp(self, frt, pag, r, c, p, i, w):
        self.ptyp = w
        if self.ptyp == "C":
            return "sk2"

    def doStartPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.s_per
        elif w < self.s_per or w > self.e_per:
            return "Invalid Period"
        self.sperw = w
        self.df.loadEntry(frt, pag, p, data=self.sperw)
        self.sperd = self.df.t_disp[pag][0][i]

    def doEndPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.e_per
        elif w < self.sperw or w > self.e_per:
            return "Invalid Period"
        self.eperw = w
        self.df.loadEntry(frt, pag, p, self.eperw)
        self.eperd = self.df.t_disp[pag][0][i]
        return "sk2"

    def doStartDat(self, frt, pag, r, c, p, i, w):
        self.sdatw = w
        self.df.loadEntry(frt, pag, p, data=self.sdatw)
        self.sperd = self.df.t_disp[pag][0][i]

    def doEndDat(self, frt, pag, r, c, p, i, w):
        if w < self.sdatw:
            return "Invalid Date"
        self.edatw = w
        self.df.loadEntry(frt, pag, p, self.edatw)
        self.eperd = self.df.t_disp[pag][0][i]

    def doBatTyp(self, frt, pag, r, c, p, i, w):
        if w > len(gltrtp):
            return "Invalid Batch Type"
        self.btyp = w
        whr = [("glt_cono", "=", self.opts["conum"])]
        if self.ptyp == "F":
            whr.append(("glt_curdt", "between", self.sperw, self.eperw))
        else:
            whr.append(("glt_capdt", "between", self.sdatw, self.edatw))
        if self.btyp:
            whr.append(("glt_type", "=", self.btyp))
        self.df.topf[pag][i + 1][8]["where"] = whr

    def doBatNum(self, frt, pag, r, c, p, i, w):
        self.batch = w

    def doTots(self, frt, pag, r, c, p, i, w):
        self.totsonly = w
        if "args" in self.opts and "noprint" in self.opts["args"]:
            return
        if self.totsonly == "Y":
            if self.multi == "Y":
                self.df.setWidget(self.df.topEntry[0][9][3][0], state="hide")
                self.df.setWidget(self.df.topEntry[0][9][4][0], state="hide")
            else:
                self.df.setWidget(self.df.topEntry[0][8][3][0], state="hide")
                self.df.setWidget(self.df.topEntry[0][8][4][0], state="hide")
        else:
            if self.multi == "Y":
                self.df.setWidget(self.df.topEntry[0][9][3][0], state="show")
                self.df.setWidget(self.df.topEntry[0][9][4][0], state="show")
            else:
                self.df.setWidget(self.df.topEntry[0][8][3][0], state="show")
                self.df.setWidget(self.df.topEntry[0][8][4][0], state="show")

    def doCoy(self, frt, pag, r, c, p, i, w):
        self.other = w

    def doEnd(self):
        self.df.closeProcess()
        jon = "left outer join genmst on glt_cono=glm_cono and "\
            "glt_acno=glm_acno"
        col = [
            "glt_cono", "glt_acno", "glt_trdt", "glt_type", "glt_refno",
            "glt_batch", "glt_tramt", "glt_taxamt", "glt_desc", "glt_taxind",
            "glm_desc"
        ]
        if self.other == "Y":
            self.doSelCoy()
            if self.con == "X":
                self.closeProcess()
                return
            whr = [("glt_cono", "in", tuple(self.con))]
        else:
            whr = [("glt_cono", "=", self.opts["conum"])]
        if self.ptyp == "F":
            whr.append(("glt_curdt", "between", self.sperw, self.eperw))
        else:
            whr.append(("glt_capdt", "between", self.sdatw, self.edatw))
        if self.btyp:
            whr.append(("glt_type", "=", self.btyp))
        if self.batch:
            whr.append(("glt_batch", "=", self.batch))
        odr = "glt_type, glt_batch, glt_trdt, glt_refno"
        recs = self.sql.getRec("gentrn",
                               join=jon,
                               cols=col,
                               where=whr,
                               order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Transaction Error",
                      "No Transactions Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def doSelCoy(self):
        tit = ("Company Selection", )
        self.coys = self.sql.getRec("ctlmst",
                                    cols=["ctm_cono", "ctm_name"],
                                    order="ctm_cono")
        coy = {
            "stype": "C",
            "head": ("Num", "Name"),
            "typs": (("UI", 3), ("NA", 30)),
            "data": self.coys,
            "mode": "M",
            "comnd": self.doCoyCmd
        }
        r1s = (("Yes", "Y"), ("Include", "I"), ("Exclude", "E"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "All Companies", "", "Y", "N",
                self.doAllCoy, None, None, None, None),
               (("T", 0, 1, 0), "INA", 30, "Companies", "", "", "N",
                self.doCoySel, coy, None, None, None))
        self.cf = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=((self.doCoyEnd, "y"), ),
                               txit=(self.doCoyExit, ))
        self.cf.mstFrame.wait_window()

    def doAllCoy(self, frt, pag, r, c, p, i, w):
        self.con = w
        if self.con == "Y":
            self.con = []
            for coy in self.coys:
                self.con.append(coy[0])
            return "nd"
        elif self.con == "I":
            self.cf.topf[pag][i + 1][8]["titl"] = "Select Companies to Include"
        else:
            self.cf.topf[pag][i + 1][8]["titl"] = "Select Companies to Exclude"

    def doCoyCmd(self, frt, pag, r, c, p, i, w):
        c = ""
        for co in w:
            if int(co):
                c = c + str(int(co)) + ","
        if len(c) > 1:
            c = c[:-1]
        self.cf.loadEntry(frt, pag, p, data=c)

    def doCoySel(self, frt, pag, r, c, p, i, w):
        if w[-1:] == ",":
            w = w[:-1]
        self.coy = w.split(",")

    def doCoyEnd(self):
        if self.con == "I":
            self.con = self.coy
        elif self.con == "E":
            self.con = []
            for co in self.coys:
                self.con.append(int(co[0]))
            for co in self.coy:
                del self.con[self.con.index(int(co))]
            self.con.sort()
        self.doCoyClose()

    def doCoyExit(self):
        self.con = "X"
        self.doCoyClose()

    def doCoyClose(self):
        self.cf.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [self.head + " %s" % self.sysdttm]
        self.expheads.append("General Ledger Audit Trail for Period "\
            "%s to %s" % (self.sperd, self.eperd))
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            cono, acno, trdt, trtp, refno, batch, debit, credit, taxamt, \
                detail, taxind, desc = vals
            line = [
                "BODY",
                [
                    trtp.work, batch.work, cono.work, acno.work, desc.work,
                    refno.work, trdt.work, debit.work, credit.work,
                    taxamt.work, taxind.work, detail.work
                ]
            ]
            self.expdatas.append(line)
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        if self.totsonly == "Y":
            self.head = "%03i %-95s" % (self.opts["conum"], self.opts["conam"])
        else:
            self.head = "%03i %-138s" % (self.opts["conum"],
                                         self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.bqty = 0
        self.bdrs = 0
        self.bcrs = 0
        self.bvat = 0
        self.tqty = 0
        self.tdrs = 0
        self.tcrs = 0
        self.tvat = 0
        self.trtp = 0
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            cono, acno, trdt, trtp, refno, batch, debit, credit, taxamt, \
                detail, taxind, desc = vals
            if not self.trtp:
                self.trtp = trtp.work
                self.batch = batch.work
            if trtp.work != self.trtp:
                self.batchTotal()
                self.typeTotal()
                self.trtp = trtp.work
                self.batch = batch.work
                self.pglin = 999
            if batch.work != self.batch:
                self.batchTotal()
                self.batch = batch.work
                if self.totsonly != "Y":
                    self.typeHeading()
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            if self.totsonly != "Y":
                self.fpdf.drawText(
                    "%s %s %s %s %s %s %s %s %s %s" %
                    (cono.disp, acno.disp, desc.disp, refno.disp, trdt.disp,
                     debit.disp, credit.disp, taxamt.disp, taxind.disp,
                     detail.disp))
                self.pglin += 1
            # Batch Totals
            self.bqty += 1
            self.bdrs = float(ASD(self.bdrs) + ASD(debit.work))
            self.bcrs = float(ASD(self.bcrs) + ASD(credit.work))
            self.bvat = float(ASD(self.bvat) + ASD(taxamt.work))
            # Type Totals
            self.tqty += 1
            self.tdrs = float(ASD(self.tdrs) + ASD(debit.work))
            self.tcrs = float(ASD(self.tcrs) + ASD(credit.work))
            self.tvat = float(ASD(self.tvat) + ASD(taxamt.work))
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.batchTotal()
            self.typeTotal()
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          repeml=self.df.repeml)

    def getValues(self, data):
        cono = CCD(data[0], "UI", 3)
        acno = CCD(data[1], "UI", 7)
        trdt = CCD(data[2], "D1", 10)
        trtp = CCD(data[3], "UI", 2)
        refno = CCD(data[4], "Na", 9)
        batch = CCD(data[5], "Na", 7)
        if data[6] < 0:
            debit = CCD(0, "SD", 15.2)
            credit = CCD(data[6], "SD", 15.2)
        else:
            debit = CCD(data[6], "SD", 15.2)
            credit = CCD(0, "SD", 15.2)
        taxamt = CCD(data[7], "SD", 15.2)
        detail = CCD(data[8], "NA", 30)
        taxind = CCD(data[9], "NA", 1)
        desc = CCD(data[10], "NA", 30)
        self.gqt[trtp.work - 1] = self.gqt[trtp.work - 1] + 1
        self.gdr[trtp.work - 1] = float(ASD(self.gdr[trtp.work - 1]) + \
            ASD(debit.work))
        self.gcr[trtp.work - 1] = float(ASD(self.gcr[trtp.work - 1]) + \
            ASD(credit.work))
        self.gvt[trtp.work - 1] = float(ASD(self.gvt[trtp.work - 1]) + \
            ASD(taxamt.work))
        return (cono, acno, trdt, trtp, refno, batch, debit, credit, taxamt,
                detail, taxind, desc)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.drawText(self.head, font=["B"])
        self.fpdf.drawText()
        if self.totsonly == "Y":
            self.fpdf.drawText("%-37s %-7s %-2s %-50s" %
                               ("General Ledger Audit Trail for Period",
                                self.sperd, "to", self.eperd))
        else:
            self.fpdf.drawText("%-37s %-7s %-2s %-94s" %
                               ("General Ledger Audit Trail for Period",
                                self.sperd, "to", self.eperd))
        self.fpdf.drawText()
        self.pglin = 4
        if self.totind == "N":
            self.typeHeading()
        else:
            self.fpdf.drawText("%-14s" % "Totals Summary")
            self.fpdf.drawText()
            if self.totsonly == "Y":
                self.fpdf.drawText(
                    "%-27s%-8s  %-15s %-15s %-15s %-15s" %
                    ("Document Type", "Quantity", "        Debits",
                     "       Credits", "    Difference", "        V.A.T."))
            else:
                self.fpdf.drawText(
                    "%-34s%-8s  %-15s %-15s %-15s %-15s" %
                    ("Document Type", "Quantity", "        Debits",
                     "       Credits", "    Difference", "        V.A.T."))
            self.fpdf.underLine(self.head)
            self.pglin += 4
            self.fpdf.setFont()

    def typeHeading(self):
        if self.fpdf.lpp - self.pglin < 4:
            self.pageHeading()
            return
        if self.totsonly != "Y":
            batch = self.batch
        else:
            batch = "Various"
        self.fpdf.drawText(
            "%-7s %7s %-10s %3s" %
            ("Batch", batch, "    Type", gltrtp[self.trtp - 1][1]),
            font=["B"])
        self.fpdf.drawText()
        if self.totsonly == "Y":
            self.fpdf.drawText("%-36s %-15s %-15s %-15s %-15s" %
                               ("Details", "        Debits", "       Credits",
                                "    Difference", "        V.A.T."))
        else:
            self.fpdf.drawText("%-3s %-7s %-30s %-9s %-10s %-15s %-15s "\
                "%-15s %-1s %-30s" % ("Coy", "Acc-Num", "Description",
                "Reference", "   Date", "        Debits", "       Credits",
                "    Tax-Amount", "T", "Remarks"))
        self.fpdf.underLine(self.head)
        self.fpdf.setFont()
        self.pglin += 4

    def batchTotal(self):
        if self.fpdf.lpp - self.pglin < 3:
            self.pageHeading()
        j = CCD(self.bdrs, "SD", 15.2)
        k = CCD(self.bcrs, "SD", 15.2)
        l = CCD(float(ASD(j.work) + ASD(k.work)), "SD", 15.2)
        m = CCD(self.bvat, "SD", 15.2)
        if self.totsonly == "Y":
            self.fpdf.drawText("%-36s %15s %15s %15s %15s" %
                               ("Batch " + self.batch + " Totals", j.disp,
                                k.disp, l.disp, m.disp))
            self.pglin += 1
        else:
            self.fpdf.drawText()
            self.fpdf.drawText("%-11s %-51s %15s %15s %15s" %
                               (" ", "Batch " + self.batch + " Totals", j.disp,
                                k.disp, m.disp))
            self.fpdf.drawText()
            self.pglin += 3
        self.bqty = 0
        self.bcrs = 0
        self.bdrs = 0
        self.bvat = 0

    def typeTotal(self):
        if self.fpdf.lpp - self.pglin < 2:
            self.pageHeading()
        j = CCD(self.tdrs, "SD", 15.2)
        k = CCD(self.tcrs, "SD", 15.2)
        l = CCD(float(ASD(j.work) + ASD(k.work)), "SD", 15.2)
        m = CCD(self.tvat, "SD", 15.2)
        if self.totsonly == "Y":
            self.fpdf.drawText()
            self.fpdf.drawText("%-36s %15s %15s %15s %15s" %
                               ("Type Totals", j.disp, k.disp, l.disp, m.disp))
            self.pglin += 2
        else:
            self.fpdf.drawText("%-11s %-51s %15s %15s %15s" %
                               (" ", "Type-Totals", j.disp, k.disp, m.disp))
            self.pglin += 1
        self.fpdf.drawText()
        self.pglin += 1
        self.tqty = 0
        self.tcrs = 0
        self.tdrs = 0
        self.tvat = 0

    def grandTotal(self):
        tot = [0, 0, 0, 0, 0]
        if self.df.repprt[2] == "export":
            for x in range(0, len(gltrtp)):
                tot[0] = float(ASD(tot[0]) + ASD(self.gdr[x]))
                tot[1] = float(ASD(tot[1]) + ASD(self.gcr[x]))
                tot[2] = float(ASD(tot[2]) + ASD(self.gvt[x]))
            self.expdatas.append(["ULINES"])
            self.expdatas.append([
                "TOTAL",
                [
                    "", "", "", "", "Grand Totals", "", "", tot[0], tot[1],
                    tot[2], ""
                ]
            ])
            self.expdatas.append(["ULINED"])
            return
        self.totind = "Y"
        self.pageHeading()
        for x, t in enumerate(gltrtp):
            qt = CCD(self.gqt[x], "SI", 8)
            dr = CCD(self.gdr[x], "SD", 15.2)
            cr = CCD(self.gcr[x], "SD", 15.2)
            df = float(ASD(dr.work) + ASD(cr.work))
            df = CCD(df, "SD", 15.2)
            vt = CCD(self.gvt[x], "SD", 15.2)
            if self.totsonly == "Y":
                self.fpdf.drawText(
                    "%-27s %s %s %s %s %s" %
                    (t[1], qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
            else:
                self.fpdf.drawText(
                    "%-34s %s %s %s %s %s" %
                    (t[1], qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
            tot[0] = tot[0] + qt.work
            tot[1] = float(ASD(tot[1]) + ASD(dr.work))
            tot[2] = float(ASD(tot[2]) + ASD(cr.work))
            tot[3] = float(ASD(tot[3]) + ASD(df.work))
            tot[4] = float(ASD(tot[4]) + ASD(vt.work))
        self.fpdf.drawText()
        qt = CCD(tot[0], "SI", 8)
        dr = CCD(tot[1], "SD", 15.2)
        cr = CCD(tot[2], "SD", 15.2)
        df = CCD(tot[3], "SD", 15.2)
        vt = CCD(tot[4], "SD", 15.2)
        if self.totsonly == "Y":
            self.fpdf.drawText(
                "%-27s %s %s %s %s %s" %
                ("Grand Totals", qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
        else:
            self.fpdf.drawText(
                "%-34s %s %s %s %s %s" %
                ("Grand Totals", qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
        self.fpdf.drawText()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 6
0
class si3020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["strgrp", "strloc", "strmf1"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        slsctl = gc.getCtl("slsctl", self.opts["conum"])
        if not slsctl:
            return
        self.fromad = slsctl["ctv_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.colsh = [[
            "", "", "", "", ["*********** Month to Date **********", 4, 7],
            ["*********** Year To Date ***********", 8, 11]
        ]]
        self.colsh.append([
            "Grp", "Product-Code", "Description", "U.O.I", "Quantity", "Value",
            "Profit", "Prft-%", "Quantity", "Value", "Profit", "Prft-%"
        ])
        self.forms = [("UA", 3), ("NA", 20), ("NA", 30), ("NA", 10), ("SI", 9),
                      ("SI", 9), ("SI", 9), ("SD", 7.2), ("SI", 9), ("SI", 9),
                      ("SI", 9), ("SD", 7.2)]
        self.stot = [0] * 6
        self.gtot = [0] * 6
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Sales By Product Report (%s)" % self.__class__.__name__)
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["", "", ""]
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), "ID2", 7, "Cut-Off Period", "",
                int(self.sysdtw / 100), "Y", self.doCut, None, None,
                ("efld", )), (("T", 0, 1, 0), "IUA", 1, "Location", "", var[1],
                              "N", self.doLoc, loc, None, ("efld", )),
               (("T", 0, 2, 0), "IUA", 3, "Product Group", "", var[2], "N",
                self.doGroup, grp, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doCut(self, frt, pag, r, c, p, i, w):
        self.cutoff = w
        self.cutper = self.df.t_disp[pag][r][p]
        if self.locs == "N":
            self.loc = ""
            self.locd = "ALL"
            return "sk1"

    def doLoc(self, frt, pag, r, c, p, i, w):
        if not w:
            self.locd = "ALL"
        else:
            acc = self.sql.getRec("strloc",
                                  cols=["srl_desc"],
                                  where=[("srl_cono", "=", self.opts["conum"]),
                                         ("srl_loc", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Location"
            self.locd = "%s %s" % (w, acc[0])
        self.loc = w

    def doGroup(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.getGroup(w)
            if not acc:
                return "Invalid Group"
        self.group = w

    def doEnd(self):
        self.df.closeProcess()
        if not self.group:
            sgrp = ""
            egrp = "zzz"
        else:
            sgrp = egrp = self.group
        recs = self.sql.getRec(
            "strmf1",
            cols=["st1_group", "st1_code", "st1_desc", "st1_uoi"],
            where=[("st1_cono", "=", self.opts["conum"]),
                   ("st1_group", ">=", sgrp), ("st1_group", "<=", egrp)],
            order="st1_group, st1_code")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Records Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [
            "%03u %-30s %s" %
            (self.opts["conum"], self.opts["conam"], self.sysdttm)
        ]
        self.expheads.append("Sales Report By Product up to %s" % self.cutper)
        self.expcolsh = self.colsh
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            code, desc, uoi, mq, ms, mp, mn, yq, ys, yp, yn = vals
            self.expdatas.append([
                "BODY",
                [
                    self.grp.work, code.work, desc.work, uoi.work, mq.work,
                    ms.work, mp.work, mn.work, yq.work, ys.work, yp.work,
                    yn.work
                ]
            ])
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-138s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        lstgrp = ""
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            if lstgrp and lstgrp != self.grp.work:
                self.groupTotal()
                self.pglin = 999
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            code, desc, uoi, mq, ms, mp, mn, yq, ys, yp, yn = vals
            self.fpdf.drawText("%s %s %s %s %s %s %s     %s %s %s %s" % \
                (code.disp, desc.disp, uoi.disp, mq.disp, ms.disp,
                mp.disp, mn.disp, yq.disp, ys.disp, yp.disp, yn.disp))
            self.stot[0] = float(ASD(self.stot[0]) + ASD(mq.work))
            self.stot[1] = float(ASD(self.stot[1]) + ASD(ms.work))
            self.stot[2] = float(ASD(self.stot[2]) + ASD(mp.work))
            self.stot[3] = float(ASD(self.stot[3]) + ASD(yq.work))
            self.stot[4] = float(ASD(self.stot[4]) + ASD(ys.work))
            self.stot[5] = float(ASD(self.stot[5]) + ASD(yp.work))
            self.pglin += 1
            lstgrp = self.grp.work
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.groupTotal()
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          fromad=self.fromad,
                          repeml=self.df.repeml)

    def getValues(self, data):
        self.grp = CCD(data[0], "UA", 3)
        code = CCD(data[1], "NA", 20)
        desc = CCD(data[2], "NA", 30)
        uoi = CCD(data[3], "NA", 10)
        bals = Balances(self.opts["mf"],
                        "STR",
                        self.opts["conum"],
                        self.cutoff,
                        keys=(self.grp.work, code.work, self.loc,
                              ("P", self.opts["period"][0])))
        m_ob, m_mv, m_cb, y_ob, y_mv, y_cb, ac, lc, ls = bals.doStrBals()
        m_qty = 0
        m_cst = 0
        m_sls = 0
        for t, q, c, s in m_mv:
            if t == 7:
                m_qty = q
                m_cst = c
                m_sls = s
                break
        y_qty = 0
        y_cst = 0
        y_sls = 0
        for t, q, c, s in y_mv:
            if t == 7:
                y_qty = q
                y_cst = c
                y_sls = s
                break
        mq = CCD(float(ASD(0) - ASD(m_qty)), "SI", 9)
        mc = CCD(float(ASD(0) - ASD(m_cst)), "SI", 9)
        ms = CCD(float(ASD(0) - ASD(m_sls)), "SI", 9)
        mp = float(ASD(ms.work) - ASD(mc.work))
        mp = CCD(mp, "SI", 9)
        if ms.work == 0:
            mn = 0
        else:
            mn = round((mp.work * 100 / ms.work), 2)
        mn = CCD(mn, "SD", 7.2)
        yq = CCD(float(ASD(0) - ASD(y_qty)), "SI", 9)
        yc = CCD(float(ASD(0) - ASD(y_cst)), "SI", 9)
        ys = CCD(float(ASD(0) - ASD(y_sls)), "SI", 9)
        yp = float(ASD(ys.work) - ASD(yc.work))
        yp = CCD(yp, "SI", 9)
        if not ys.work:
            yn = 0
        else:
            yn = round((yp.work * 100.0 / ys.work), 2)
        yn = CCD(yn, "SD", 7.2)
        if mq.work == 0 and mc.work == 0 and ms.work == 0 and \
                yq.work == 0 and yc.work == 0 and ys.work == 0:
            return
        self.gtot[0] = float(ASD(self.gtot[0]) + ASD(mq.work))
        self.gtot[1] = float(ASD(self.gtot[1]) + ASD(ms.work))
        self.gtot[2] = float(ASD(self.gtot[2]) + ASD(mp.work))
        self.gtot[3] = float(ASD(self.gtot[3]) + ASD(yq.work))
        self.gtot[4] = float(ASD(self.gtot[4]) + ASD(ys.work))
        self.gtot[5] = float(ASD(self.gtot[5]) + ASD(yp.work))
        return (code, desc, uoi, mq, ms, mp, mn, yq, ys, yp, yn)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-29s %-7s" % \
            ("Sales Report By Product up to", self.cutper))
        self.fpdf.drawText()
        acc = self.getGroup(self.grp.work)
        if acc:
            grpd = acc[0]
        else:
            grpd = "Missing Group Record"
        self.fpdf.drawText("%s %s %s     %s %s" % \
            ("Group:", self.grp.disp, grpd, "Location:", self.locd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-62s %-36s %-5s%-36s " %
                           ("", "*********** Month T0 Date **********", "",
                            "*********** Year To Date ***********"))
        self.fpdf.drawText("%-20s %-30s %-10s %9s %9s %9s %7s     "\
            "%9s %9s %9s %7s" % ("Product-Code", "Description", "U.O.I",
            "Quantity ", "Value ", "Profit ", "Prft-% ",
            "Quantity ", "Value ", "Profit ", "Prft-% "))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 9

    def getGroup(self, grp):
        acc = self.sql.getRec("strgrp",
                              cols=["gpm_desc"],
                              where=[("gpm_cono", "=", self.opts["conum"]),
                                     ("gpm_group", "=", grp)],
                              limit=1)
        return acc

    def groupTotal(self):
        self.fpdf.drawText()
        mq = CCD(self.stot[0], "SI", 9)
        ms = CCD(self.stot[1], "SI", 9)
        mp = CCD(self.stot[2], "SI", 9)
        if ms.work == 0:
            mn = 0
        else:
            mn = round((mp.work * 100 / ms.work), 2)
        mn = CCD(mn, "SD", 7.2)
        yq = CCD(self.stot[3], "SI", 9)
        ys = CCD(self.stot[4], "SI", 9)
        yp = CCD(self.stot[5], "SI", 9)
        if ys.work == 0:
            yn = 0
        else:
            yn = round((yp.work * 100 / ys.work), 2)
        yn = CCD(yn, "SD", 7.2)
        self.fpdf.drawText("%-20s %-41s %s %s %s %s     %s %s %s %s" % \
            ("", "Group Totals", mq.disp, ms.disp, mp.disp, mn.disp,
            yq.disp, ys.disp, yp.disp, yn.disp))
        self.stot = [0] * 6

    def grandTotal(self):
        mq = CCD(self.gtot[0], "SI", 9)
        ms = CCD(self.gtot[1], "SI", 9)
        mp = CCD(self.gtot[2], "SI", 9)
        if ms.work == 0:
            mn = 0
        else:
            mn = round((mp.work * 100 / ms.work), 2)
        mn = CCD(mn, "SD", 7.2)
        yq = CCD(self.gtot[3], "SI", 9)
        ys = CCD(self.gtot[4], "SI", 9)
        yp = CCD(self.gtot[5], "SI", 9)
        if ys.work == 0:
            yn = 0
        else:
            yn = round((yp.work * 100 / ys.work), 2)
        yn = CCD(yn, "SD", 7.2)
        if self.df.repprt[2] == "export":
            self.expdatas.append(["ULINES"])
            self.expdatas.append([
                "TOTAL",
                [
                    "", "", "Grand Totals", "", mq.work, ms.work, mp.work,
                    mn.work, yq.work, ys.work, yp.work, yn.work
                ]
            ])
            self.expdatas.append(["ULINED"])
            return
        self.fpdf.drawText()
        self.fpdf.drawText("%-20s %-41s %s %s %s %s     %s %s %s %s" % \
            ("", "Grand Totals", mq.disp, ms.disp, mp.disp, mn.disp,
            yq.disp, ys.disp, yp.disp, yn.disp))

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 7
0
class ar3020(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,
                       "asstrn",
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        assctl = gc.getCtl("assctl", self.opts["conum"])
        if not assctl:
            return
        self.fromad = assctl["cta_emadd"]
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        self.totind = "N"
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Asset Register Audit Trail (%s)" %
                    self.__class__.__name__)
        data = ["All Types"]
        for typ in artrtp:
            data.append(typ[1])
        btt = {"stype": "C", "titl": "Valid Types", "data": data, "retn": "I"}
        btm = {
            "stype":
            "R",
            "tables": ("asstrn", ),
            "cols": (("ast_batch", "", 0,
                      "Bat-Num"), ("ast_type", ("xx", artrtp), 20, "Type"),
                     ("ast_curdt", "", 0, "Cur-Dat")),
            "where": [],
            "group":
            "ast_batch, ast_type, ast_curdt",
            "order":
            "ast_type, ast_curdt, ast_batch"
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "Id2", 7, "Starting Period", "", "", "Y",
                self.doStartPer, None, None,
                ("efld", )), (("T", 0, 1, 0), "Id2", 7, "Ending Period", "",
                              "", "Y", self.doEndPer, None, None, ("efld", )),
               (("T", 0, 2, 0), "IUI", 1, "Type", "Transaction Type", "", "Y",
                self.doBatTyp, btt, None, None),
               (("T", 0, 3,
                 0), "INa", 7, "Batch Number", "", "", "Y", self.doBatNum, btm,
                None, None), (("T", 0, 4, 0), ("IRB", r1s), 0, "Totals Only",
                              "", "Y", "Y", self.doTots, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doStartPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.s_per
        elif w < self.s_per or w > self.e_per:
            return "Invalid Period"
        self.sdat = self.df.loadEntry(frt, pag, p, data=w)

    def doEndPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.e_per
        elif w < self.sdat.work or w > self.e_per:
            return "Invalid Period"
        self.edat = self.df.loadEntry(frt, pag, p, data=w)

    def doBatTyp(self, frt, pag, r, c, p, i, w):
        if w > len(artrtp):
            return "Invalid Batch Type"
        self.btype = w
        whr = [("ast_cono", "=", self.opts["conum"]),
               ("ast_curdt", "between", self.sdat.work, self.edat.work)]
        if self.btype:
            whr.append(("ast_type", "=", self.btype))
        self.df.topf[pag][i + 1][8]["where"] = whr

    def doBatNum(self, frt, pag, r, c, p, i, w):
        self.batch = w

    def doTots(self, frt, pag, r, c, p, i, w):
        self.totsonly = w

    def doEnd(self):
        self.df.closeProcess()
        if not self.btype:
            styp = 0
            etyp = 99
        else:
            styp = etyp = self.btype
        if not self.batch:
            sbat = ""
            ebat = "zzzzzzz"
        else:
            sbat = ebat = self.batch
        recs = self.sql.getRec("asstrn",
                               where=[("ast_cono", "=", self.opts["conum"]),
                                      ("ast_curdt", "between", self.sdat.work,
                                       self.edat.work),
                                      ("ast_batch", "between", sbat, ebat),
                                      ("ast_type", "between", styp, etyp)],
                               order="ast_type, ast_batch, ast_refno")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Asset Transactions Selected")
        else:
            self.printReport(recs)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-105s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.bcnt = 0
        self.bmt1 = 0
        self.bmt2 = 0
        self.bvat = 0
        self.tcnt = 0
        self.tmt1 = 0
        self.tmt2 = 0
        self.tvat = 0
        self.gcnt = [0, 0, 0, 0, 0]
        self.gmt1 = [0, 0, 0, 0, 0]
        self.gmt2 = [0, 0, 0, 0, 0]
        self.gvat = [0, 0, 0, 0, 0]
        self.trtp = 0
        self.pglin = 999
        tc = self.sql.asstrn_col
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            trtp = CCD(dat[tc.index("ast_type")], "UI", 2)
            batch = CCD(dat[tc.index("ast_batch")], "Na", 7)
            grp = CCD(dat[tc.index("ast_group")], "UA", 3)
            code = CCD(dat[tc.index("ast_code")], "Na", 7)
            refno = CCD(dat[tc.index("ast_refno")], "Na", 9)
            mtyp = CCD(dat[tc.index("ast_mtyp")], "UI", 1)
            trdt = CCD(dat[tc.index("ast_date")], "D1", 10)
            desc = CCD(dat[tc.index("ast_desc")], "NA", 30)
            amt1 = CCD(dat[tc.index("ast_amt1")], "SD", 13.2)
            amt2 = CCD(dat[tc.index("ast_amt2")], "SD", 13.2)
            vat = CCD(dat[tc.index("ast_vat")], "SD", 13.2)
            taxind = CCD(dat[tc.index("ast_taxind")], "NA", 1)
            if not self.trtp:
                self.trtp = trtp.work
                self.batch = batch.work
            if trtp.work != self.trtp:
                self.batchTotal()
                self.typeTotal()
                self.trtp = trtp.work
                self.batch = batch.work
                self.pglin = 999
            if batch.work != self.batch:
                self.batchTotal()
                self.batch = batch.work
                if self.totsonly != "Y":
                    self.typeHeading()
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            if self.totsonly != "Y":
                self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s" % \
                    (grp.disp, code.disp, refno.disp, trdt.disp, desc.disp,
                    mtyp.disp, amt1.disp, amt2.disp, vat.disp, taxind.disp))
                self.pglin += 1
            self.bcnt = self.bcnt + 1
            self.bmt1 = float(ASD(self.bmt1) + ASD(amt1.work))
            self.bmt2 = float(ASD(self.bmt2) + ASD(amt2.work))
            self.bvat = float(ASD(self.bvat) + ASD(vat.work))
            self.tcnt = self.tcnt + 1
            self.tmt1 = float(ASD(self.tmt1) + ASD(amt1.work))
            self.tmt2 = float(ASD(self.tmt2) + ASD(amt2.work))
            self.tvat = float(ASD(self.tvat) + ASD(vat.work))
            self.gcnt[trtp.work - 1] = self.gcnt[trtp.work - 1] + 1
            self.gmt1[trtp.work - 1] = float(ASD(self.gmt1[trtp.work - 1]) + \
                ASD(amt1.work))
            self.gmt2[trtp.work - 1] = float(ASD(self.gmt2[trtp.work - 1]) + \
                ASD(amt2.work))
            self.gvat[trtp.work - 1] = float(ASD(self.gvat[trtp.work - 1]) + \
                ASD(vat.work))
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.batchTotal()
            self.typeTotal()
            self.grandTotal()
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      repeml=self.df.repeml,
                      fromad=self.fromad)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-36s %-7s %-2s %-61s" %
                           ("Asset Register Audit Trail for Period",
                            self.sdat.disp, "to", self.edat.disp))
        self.fpdf.drawText()
        self.pglin = 4
        if self.totind == "N":
            self.typeHeading()
        else:
            self.fpdf.drawText("%-14s" % "Totals Summary")
            self.fpdf.drawText()
            self.fpdf.drawText("%-30s %-8s %-13s %-13s %-13s" %
                               ("Document Type", " Number", "    Amount-1",
                                "    Amount-2", "     VAT-Amt"))
            self.fpdf.underLine(txt=self.head)
            self.fpdf.setFont()
            self.pglin += 4

    def typeHeading(self):
        if self.totsonly != "Y":
            batch = self.batch
        else:
            batch = "Various"
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("%-7s %7s %-10s %3s" % \
            ("Batch", batch, "    Type", artrtp[self.trtp - 1][1]))
        self.fpdf.drawText()
        self.fpdf.drawText("%-3s %-7s %-9s %-10s %-30s %1s %-13s %-13s %-13s "\
            "%1s" % ("Grp", "Code", "Reference", "   Date", "Remarks", "M",
            "    Amount-1", "    Amount-2", "     VAT-Amt", "I"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin += 4

    def batchTotal(self):
        k = CCD(self.bmt1, "SD", 13.2)
        l = CCD(self.bmt2, "SD", 13.2)
        m = CCD(self.bvat, "SD", 13.2)
        if self.totsonly != "Y":
            self.fpdf.drawText()
            self.pglin += 1
        self.fpdf.drawText("%-32s %-32s %13s %13s %13s" % \
            (" ", "Batch " + self.batch + " Totals", k.disp, l.disp, m.disp))
        self.pglin += 1
        if self.totsonly == "N":
            self.fpdf.drawText()
            self.pglin += 1
        self.bcnt = 0
        self.bmt1 = 0
        self.bmt2 = 0
        self.bvat = 0

    def typeTotal(self):
        k = CCD(self.tmt1, "SD", 13.2)
        l = CCD(self.tmt2, "SD", 13.2)
        m = CCD(self.tvat, "SD", 13.2)
        if self.totsonly == "Y":
            self.fpdf.drawText()
            self.pglin += 1
        self.fpdf.drawText("%-32s %-32s %13s %13s %13s" % \
            (" ", "Type-Totals", k.disp, l.disp, m.disp))
        self.pglin += 1
        self.tcnt = 0
        self.tmt1 = 0
        self.tmt2 = 0
        self.tvat = 0

    def grandTotal(self):
        self.totind = "Y"
        self.pageHeading()
        tot = [0, 0, 0, 0]
        for x, t in enumerate(artrtp):
            cnt = CCD(self.gcnt[x], "SI", 7)
            mt1 = CCD(self.gmt1[x], "SD", 13.2)
            mt2 = CCD(self.gmt2[x], "SD", 13.2)
            vat = CCD(self.gvat[x], "SD", 13.2)
            self.fpdf.drawText("%-31s %s %s %s %s" % \
                (t[1], cnt.disp, mt1.disp, mt2.disp, vat.disp))
            tot[0] = tot[0] + cnt.work
            tot[1] = float(ASD(tot[1]) + ASD(mt1.work))
            tot[2] = float(ASD(tot[2]) + ASD(mt2.work))
            tot[3] = float(ASD(tot[3]) + ASD(vat.work))
        self.fpdf.drawText()
        cnt = CCD(tot[0], "SI", 8)
        mt1 = CCD(tot[1], "SD", 13.2)
        mt2 = CCD(tot[2], "SD", 13.2)
        vat = CCD(tot[3], "SD", 13.2)
        self.fpdf.drawText("%-30s %s %s %s %s" % \
            ("Grand Totals", cnt.disp, mt1.disp, mt2.disp, vat.disp))
        self.fpdf.drawText()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 8
0
class bs3010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bksmst", "bksaut", "bksown"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.curdt = time.strftime("%Y-%m", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "books.png")
        if not os.path.exists(self.image):
            getImage("books", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None
        return True

    def mainProcess(self):
        lst = {
            "stype": "R",
            "tables": ("bksmst", ),
            "cols": (("bmf_mnth", "", 0, "Month"), ),
            "where": [("bmf_cono", "=", self.opts["conum"])],
            "group": "bmf_mnth",
            "order": "bmf_mnth"
        }
        r1s = (("All", "A"), ("Current", "C"), ("Removed", "R"))
        r2s = (("Title", "T"), ("Date", "D"), ("Author", "A"), ("Owner", "O"))
        fld = ((("T", 0, 0, 0), "ID2", 7, "Last Meeting", "", "", "N",
                self.doLast, lst, None, ("efld", )),
               (("T", 0, 1, 0), ("IRB", r1s), 0, "Status", "", "A", "N",
                self.doStatus, None, None, None),
               (("T", 0, 2, 0), ("IRB", r2s), 0, "Order", "", "T", "N",
                self.doOrder, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               tops=False,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doLast(self, frt, pag, r, c, p, i, w):
        self.last = w
        self.new = False

    def doStatus(self, frt, pag, r, c, p, i, w):
        self.status = w

    def doOrder(self, frt, pag, r, c, p, i, w):
        self.order = w

    def doEnd(self):
        self.df.closeProcess()
        if self.df.repeml[1] == "Y":
            if not self.df.repeml[2]:
                owns = self.sql.getRec("bksown",
                                       cols=["bof_mail"],
                                       where=[("bof_mail", "<>", ""),
                                              ("bof_stat", "=", "C")])
                adds = None
                for own in owns:
                    if not adds:
                        adds = own[0]
                    else:
                        adds = "%s,%s" % (adds, own[0])
                self.df.repeml[2] = adds
            if not self.df.repeml[3]:
                self.df.repeml[3] = """Dear Member

Attached please find the latest list of books.

All books which came onto the list at the last meeting are highlighted and, if available, a precis will be printed at the end.

Thanks and Regards.
"""
        tab = ["bksmst", "bksaut", "bksown"]
        col = [
            "bmf_stat", "bmf_titl", "bmf_code", "baf_snam", "baf_fnam",
            "bmf_mnth", "bof_fnam", "bof_snam"
        ]
        odr = ""
        if self.status == "C":
            whr = [("bmf_stat", "=", "C")]
        elif self.status == "R":
            whr = [("bmf_stat", "=", "X")]
        else:
            whr = []
            odr = "bmf_stat"
        whr.extend([("baf_code=bmf_auth", ), ("bof_code=bmf_ownr", )])
        if self.order == "T":
            if odr:
                odr = "%s, bmf_titl" % odr
            else:
                odr = "bmf_titl"
        elif self.order == "D":
            if odr:
                odr = "%s, bmf_mnth, bmf_titl" % odr
            else:
                odr = "bmf_mnth, bmf_titl"
        elif self.order == "A":
            if odr:
                odr = "%s, baf_snam, baf_fnam, bmf_titl" % odr
            else:
                odr = "baf_snam, baf_fnam, bmf_titl"
        elif self.order == "O":
            if odr:
                odr = "%s, bmf_ownr, bmf_titl" % odr
            else:
                odr = "bmf_ownr, bmf_titl"
        recs = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Records Selected")
            self.opts["mf"].closeLoop()
            return
        self.fpdf = MyFpdf(name="bs3010", head=90, auto=True)
        self.fpdf.header = self.pageHeading
        self.stat = recs[0][0]
        self.fpdf.add_page()
        new = []
        for rec in recs:
            stat = CCD(rec[0], "UA", 1).disp
            if stat != self.stat:
                self.stat = stat
                self.fpdf.add_page()
            titl = CCD(rec[1], "NA", 30).disp
            code = CCD(rec[2], "UI", 4).disp
            auth = CCD("%s, %s" % (rec[3], rec[4]), "NA", 30).disp
            mnth = CCD(rec[5], "D2", 7).disp
            ownr = CCD("%s %s" % (rec[6], rec[7][0]), "NA", 12).disp
            if rec[5] < self.last:
                fill = 0
            else:
                new.append([auth, titl])
                fill = 1
            self.fpdf.drawText("%1s %30s %4s %30s %7s %10s" %
                               (stat, titl, code, auth, mnth, ownr),
                               h=5,
                               fill=fill)
        if new:
            sp = SplashScreen(
                self.opts["mf"].body,
                "Preparing Summary of New Books ... Please Wait")
            self.new = True
            self.fpdf.add_page()
            for book in new:
                try:
                    if self.fpdf.get_y() > 260:
                        self.fpdf.add_page()
                    desc = self.getDesc(book)
                    if desc:
                        w = self.fpdf.cwth * 9
                        desc = desc.rstrip().encode("latin-1",
                                                    "ignore").decode(
                                                        "latin-1", "ignore")
                        self.fpdf.drawText(w=w, txt="Title: ", font="B", ln=0)
                        self.fpdf.drawText(txt=book[1].rstrip(), font="I")
                        self.fpdf.drawText(w=w, txt="Author: ", font="B", ln=0)
                        self.fpdf.drawText(txt=book[0].rstrip(), font="I")
                        self.fpdf.drawText(w=w,
                                           txt="Details: ",
                                           font="B",
                                           ln=0)
                        self.fpdf.drawText(txt=desc, font="I", ctyp="M")
                        if book != new[-1]:
                            self.fpdf.drawText()
                except:
                    pass
            sp.closeSplash()
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf.output(pdfnam, "F")
        head = "Book List as at %s" % (self.curdt)
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header=head,
                  repprt=self.df.repprt,
                  repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def pageHeading(self, new=False):
        self.fpdf.setFont("Arial", "B", 15)
        x = self.fpdf.get_x()
        if self.image:
            self.fpdf.image(self.image, 11, 10, 15, 20)
            self.fpdf.image(self.image, 185, 10, 15, 20)
            self.fpdf.cell(20)
        self.fpdf.set_x(x)
        self.fpdf.cell(0, 10, self.opts["conam"], "TLR", 1, "C")
        if self.new:
            txt = "Summary of New Books"
        elif self.stat == "C":
            txt = "Current Books as at %s" % self.curdt
        else:
            txt = "Removed Books as at %s" % self.curdt
        self.fpdf.cell(0, 10, txt, "LRB", 1, "C")
        self.fpdf.ln(8)
        self.fpdf.setFont(style="B")
        if not self.new:
            self.fpdf.cell(
                0, 5, "%-1s %-30s %-4s %-30s %-7s %-12s" %
                ("S", "Title", "Code", "Author", "Mth-Rec", "Owner"), "B")
        self.fpdf.ln(5)

    def getDesc(self, book):
        auth = book[0].strip().lower()
        titl = book[1].strip().lower().replace(",", "")
        if titl[:4] == "the ":
            titl = titl[4:]
        elif titl[-4:] == " the":
            titl = titl[:-4]
        get = requests.get("https://www.googleapis.com/books/v1/volumes?q="\
            "{intitle:'%s'+inauthor:'%s'" % (titl, auth), timeout=5)
        if get.status_code == 200 and get.json()["totalItems"]:
            ok = False
            for item in get.json()["items"]:
                tita = titl.lower().\
                    replace("the ","").replace(", the", "")
                titb = item["volumeInfo"]["title"].lower().\
                    replace("the ","").replace(", the", "")
                if titb.count(tita):
                    if "description" in item["volumeInfo"]:
                        ok = True
                        break
            if ok:
                return item["volumeInfo"]["description"]

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 9
0
class st3050(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, ["strgrp", "strmf1", "strloc",
            "strrcp"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        self.fromad = strctl["cts_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
            "Stores Recipe Listing (%s)" % self.__class__.__name__)
        loc = {
            "stype": "R",
            "tables": ("strloc",),
            "cols": (
                ("srl_loc", "", 0, "L"),
                ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]}
        grp = {
            "stype": "R",
            "tables": ("strgrp",),
            "cols": (
                ("gpm_group", "", 0, "Grp"),
                ("gpm_desc", "", 0, "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]}
        r1s = (("Yes","Y"), ("Singles", "S"))
        r2s = (("Yes","Y"), ("No","N"))
        if self.locs == "N":
            self.loc = "1"
            fld = []
        else:
            fld = [[("T",0,0,0),"IUA",1,"Location","",
                "1","Y",self.doLoc,loc,None,("notblank",)]]
        fld.extend([
            (("T",0,1,0),"IUA",3,"Product Group","",
                "","Y",self.doGroup,grp,None,None),
            (("T",0,2,0),("IRB",r1s),0,"Whole File","",
                "S","Y",self.doWhole,None,None,None),
            (("T",0,3,0),("IRB",r2s),0,"Recipe per Page","Recipe per Page",
                "N","Y",self.doPage,None,None,None)])
        tnd = ((self.doEnd,"Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"], title=self.tit, eflds=fld,
            tend=tnd, txit=txt, view=("N","V"), mail=("Y","N"))

    def doLoc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("strloc", cols=["srl_desc"],
            where=[("srl_cono", "=", self.opts["conum"]), ("srl_loc", "=", w)],
            limit=1)
        if not acc:
            return "Invalid Location"
        self.loc = w

    def doGroup(self, frt, pag, r, c, p, i, w):
        if not w:
            self.group = ""
        else:
            acc = self.sql.getRec("strgrp", cols=["gpm_desc"],
                where=[("gpm_cono", "=", self.opts["conum"]), ("gpm_group",
                "=", w)], limit=1)
            if not acc:
                return "Invalid Group"
            self.group = w

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

    def doPage(self, frt, pag, r, c, p, i, w):
        self.page = w

    def doEnd(self):
        self.df.closeProcess()
        if not self.group:
            self.sgrp = ""
            self.egrp = "zzz"
        else:
            self.sgrp = self.group
            self.egrp = self.group
        whr = [
            ("st1_cono", "=", self.opts["conum"]),
            ("st1_group", ">=", self.sgrp),
            ("st1_group", "<=", self.egrp),
            ("st1_type", "=", "R")]
        odr = "st1_group, st1_code"
        if self.whole == "S":
            recs = getSingleRecords(self.opts["mf"], "strmf1",
                ("st1_group", "st1_code", "st1_desc"), where=whr, order=odr)
        else:
            recs = self.sql.getRec("strmf1", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                "No Records Selected")
        else:
            self.printReport(recs)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-71s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        oldrec = ""
        self.pglin = 999
        st1 = self.sql.strmf1_col
        srr = self.sql.strrcp_col
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            grp = CCD(dat[st1.index("st1_group")], "UA", 3)
            cod = CCD(dat[st1.index("st1_code")], "NA", 20)
            dsc = CCD(dat[st1.index("st1_desc")], "NA", 30)
            whr = [
                ("srr_cono", "=", self.opts["conum"]),
                ("srr_group", "=", grp.work),
                ("srr_code", "=", cod.work)]
            if self.locs == "Y":
                whr.append(("srr_loc", "=", self.loc))
            odr = "srr_rgroup, srr_rcode"
            rec = self.sql.getRec("strrcp", where=whr, order=odr)
            if not rec:
                continue
            newrec = "%s%s" % (grp.work, cod.work)
            if oldrec and newrec != oldrec:
                self.pageHeading(grp, cod, dsc, chg=True)
            for z in rec:
                if self.pglin > self.fpdf.lpp:
                    self.pageHeading(grp, cod, dsc)
                gp = CCD(z[srr.index("srr_rgroup")], "UA", 3)
                cd = CCD(z[srr.index("srr_rcode")],  "NA", 20)
                qt = CCD(z[srr.index("srr_rqty")], "UD", 11.2)
                dd = self.sql.getRec("strmf1", cols=["st1_desc"],
                    where=[("st1_cono", "=", self.opts["conum"]), ("st1_group",
                    "=", gp.work), ("st1_code", "=", cd.work)], limit=1)
                if dd:
                    dc = dd[0]
                else:
                    dc = ""
                self.fpdf.drawText("%s %s %-38s %s" % (gp.disp, cd.disp, dc,
                    qt.disp))
                self.pglin += 1
                oldrec = newrec
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                self.__class__.__name__, self.opts["conum"], ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                pdfnam=pdfnam, header=self.tit, repprt=self.df.repprt,
                fromad=self.fromad, repeml=self.df.repeml)

    def pageHeading(self, grp, cod, dsc, chg=False):
        if self.page == "N" and chg and self.pglin < (self.fpdf.lpp - 10):
            self.fpdf.drawText()
            self.fpdf.drawText()
            self.fpdf.setFont(style="B")
            self.pglin += 2
        else:
            self.fpdf.add_page()
            self.fpdf.setFont(style="B")
            self.fpdf.drawText(self.head)
            self.fpdf.drawText()
            self.fpdf.drawText("%-19s %-10s" % ("Stock Recipes as at",
                self.sysdtd))
            self.fpdf.drawText()
            self.pglin = 4
        if self.locs == "Y":
            self.fpdf.drawText("%-5s %s  %-4s %s  %-8s %s %s" %
                ("Group", grp.disp, "Code", cod.disp, dsc.disp,
                "Loc", self.loc))
        else:
            self.fpdf.drawText("%-5s %s  %-4s %s %s" % ("Group", grp.disp,
                "Code", cod.disp, dsc.disp))
        self.fpdf.drawText()
        self.fpdf.drawText("%-3s %-20s %-38s %11s" % ("Grp", "Product-Code",
            "Description", "Quantity"))
        self.fpdf.underLine(txt=self.head)
        self.pglin += 4
        self.fpdf.setFont()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 10
0
class rt3030(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, ["rtlmst", "rtltrn", "rtlcon"],
                       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.fromad = rtlctl["ctr_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Rentals Ledger Master Listing (%s)" %
                    self.__class__.__name__)
        r1s = (("Yes", "Y"), ("No", "N"))
        r2s = (("All", "Y"), ("Current", "C"), ("Arrears", "A"),
               ("Expiring", "E"), ("Expired", "X"))
        fld = ((("T", 0, 0, 0), "ID1", 10, "Report Date", "", self.sysdtw, "Y",
                self.doDate, None, None, ("efld", )),
               (("T", 0, 1, 0), ("IRB", r2s), 0, "Contracts",
                "Contracts to Print", "Y", "Y", self.doType, None, None,
                None), (("T", 0, 2, 0), "IUI", 2, "Months to Expiry", "", 1,
                        "Y", self.doMonths, None, None, ("notzero", )),
               (("T", 0, 3, 0), ("IRB", r1s), 0, "Consolidate", "", "N", "Y",
                self.doCons, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doDate(self, frt, pag, r, c, p, i, w):
        self.date = w
        self.datd = self.df.t_disp[0][0][0]

    def doType(self, frt, pag, r, c, p, i, w):
        self.styp = w
        if self.styp != "E":
            self.months = 0
            if self.styp != "Y":
                self.cons = "N"
                return "sk2"
            return "sk1"

    def doMonths(self, frt, pag, r, c, p, i, w):
        self.months = w
        if self.styp != "Y":
            self.cons = "N"
            return "sk1"

    def doCons(self, frt, pag, r, c, p, i, w):
        self.cons = w

    def doEnd(self):
        self.df.closeProcess()
        odr = "rtc_code, rtc_acno, rtc_cnum"
        whr = [("rtc_cono", "=", self.opts["conum"]),
               ("rtc_start", "<=", self.date)]
        if self.styp in ("C", "X"):
            whr.append(("rtc_status", "=", self.styp))
        if self.cons == "Y":
            recs = []
            cols = ["rtc_code", "rtc_acno", "max(rtc_cnum)"]
            accs = self.sql.getRec("rtlcon",
                                   cols=cols,
                                   where=whr,
                                   group="rtc_code, rtc_acno",
                                   order="rtc_code, rtc_acno")
            for acc in accs:
                w = copyList(whr)
                w.append(("rtc_code", "=", acc[0]))
                w.append(("rtc_acno", "=", acc[1]))
                w.append(("rtc_cnum", "=", acc[2]))
                rec = self.sql.getRec("rtlcon", where=w, limit=1)
                recs.append(rec)
        else:
            recs = self.sql.getRec("rtlcon", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Records Selected")
        else:
            self.printReport(recs)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-145s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        mst = self.sql.rtlmst_col
        con = self.sql.rtlcon_col
        self.tots = [0, 0, 0, 0, 0]
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            code = CCD(dat[con.index("rtc_code")], "NA", 7)
            acno = CCD(dat[con.index("rtc_acno")], "NA", 7)
            cnum = CCD(dat[con.index("rtc_cnum")], "UI", 3)
            freq = CCD(dat[con.index("rtc_payind")], "UA", 1)
            strt = CCD(dat[con.index("rtc_start")], "D1", 10)
            prds = CCD(dat[con.index("rtc_period")], "UI", 3)
            stat = CCD(dat[con.index("rtc_status")], "UA", 1)
            if self.styp != "X":
                curdt = int(self.date / 100)
                if self.months:
                    yy = int(curdt / 100)
                    mm = (curdt % 100) + self.months
                    while mm > 12:
                        yy += 1
                        mm -= 12
                    curdt = (yy * 100) + mm
                if freq.work == "M":
                    mths = 1 * prds.work
                elif freq.work == "3":
                    mths = 3 * prds.work
                elif freq.work == "6":
                    mths = 6 * prds.work
                else:
                    mths = 12 * prds.work
                yy = int(strt.work / 10000)
                mm = int((strt.work % 10000) / 100) + mths - 1
                while mm < 1:
                    yy -= 1
                    mm += 12
                while mm > 12:
                    yy += 1
                    mm -= 12
                chkmth = copyList(mthnam)
                if mm == 2:
                    if not yy % 4:
                        chkmth[2][2] = 29
                    else:
                        chkmth[2][2] = 28
                exdt = CCD(((yy * 10000) + (mm * 100) + chkmth[mm][2]), "D1",
                           10)
                if self.styp == "E" and int(exdt.work / 100) > curdt:
                    continue
            else:
                exdt = CCD(0, "d1", 10)
            acc = self.sql.getRec("rtlmst",
                                  where=[("rtm_cono", "=", self.opts["conum"]),
                                         ("rtm_code", "=", code.work),
                                         ("rtm_acno", "=", acno.work)],
                                  limit=1)
            name = CCD(acc[mst.index("rtm_name")], "NA", 30)
            if self.cons == "Y":
                trn = self.sql.getRec(
                    "rtltrn",
                    cols=["rtt_type", "round(sum(rtt_tramt), 2)"],
                    where=[("rtt_cono", "=", self.opts["conum"]),
                           ("rtt_code", "=", code.work),
                           ("rtt_acno", "=", acno.work),
                           ("rtt_trdt", "<=", self.date)],
                    group="rtt_type")
            else:
                trn = self.sql.getRec(
                    "rtltrn",
                    cols=["rtt_type", "round(sum(rtt_tramt), 2)"],
                    where=[("rtt_cono", "=", self.opts["conum"]),
                           ("rtt_code", "=", code.work),
                           ("rtt_acno", "=", acno.work),
                           ("rtt_cnum", "=", cnum.work),
                           ("rtt_trdt", "<=", self.date)],
                    group="rtt_type")
            rtl = CCD(0, "SD", 13.2)
            rec = CCD(0, "SD", 13.2)
            pmt = CCD(0, "SD", 13.2)
            jnl = CCD(0, "SD", 13.2)
            if trn:
                for t in trn:
                    if t[0] == 1:
                        rtl = CCD(t[1], "SD", 13.2)
                    elif t[0] == 2:
                        rec = CCD(t[1], "SD", 13.2)
                    elif t[0] == 3:
                        pmt = CCD(t[1], "SD", 13.2)
                    elif t[0] == 4:
                        jnl = CCD(t[1], "SD", 13.2)
            bal = float(ASD(rtl.work) + ASD(rec.work) + ASD(pmt.work) + \
                ASD(jnl.work))
            bal = CCD(bal, "SD", 13.2)
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s %s %s %s %s" % \
                (code.disp, acno.disp, cnum.disp, name.disp, freq.disp,
                strt.disp, prds.disp, exdt.disp, stat.disp, rtl.disp,
                rec.disp, pmt.disp, jnl.disp, bal.disp))
            self.tots[0] = float(ASD(self.tots[0]) + ASD(rtl.work))
            self.tots[1] = float(ASD(self.tots[1]) + ASD(rec.work))
            self.tots[2] = float(ASD(self.tots[2]) + ASD(pmt.work))
            self.tots[3] = float(ASD(self.tots[3]) + ASD(jnl.work))
            self.tots[4] = float(ASD(self.tots[4]) + ASD(bal.work))
            self.pglin += 1
        t = []
        for x in range(5):
            t.append(CCD(self.tots[x], "SD", 13.2).disp)
        self.fpdf.underLine(txt=self.head)
        self.fpdf.drawText("%19s %-30s %29s %-13s %-13s %-13s %-13s %-13s" % \
            ("", "Grand Totals", "", t[0], t[1], t[2], t[3], t[4]))
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)
        self.closeProcess()

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-34s %-10s" % ("Rentals Ledger Master "\
            "Report as at", self.datd))
        self.fpdf.drawText()
        opts = "%-14s %-1s" % ("(Options: Type", self.styp)
        if self.styp == "E":
            opts = "%s %-6s %-2s)" % \
            (opts, "Months", self.months)
        elif self.cons == "Y":
            opts = "%s %-12s %-1s)" % \
            (opts, "Consolidated", self.cons)
        else:
            opts = "%s)" % opts
        self.fpdf.drawText(opts)
        self.fpdf.drawText()
        self.fpdf.drawText("%-7s %-7s %-3s %-30s %-1s %-10s %-3s %-10s %-1s "\
            "%-13s %-13s %-13s %-13s %-13s" % ("Prm-Cod", "Acc-Num", "Seq",
            "Name", "F", "Start-Date", "Per", "Expir-Date", "S",
            "     Rentals ", "    Receipts ", "    Payments ",
            "    Journals ", "     Balance "))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 11
0
class tb3010(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, ["ftable", "ffield"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.head = "Tartan Systems"
        return True

    def mainProcess(self):
        dats = [["ALL", "All Systems"]]
        syss = list(allsys.keys())
        syss.sort()
        for s in syss:
            dats.append((s, allsys[s][0]))
        syss.append("ALL")
        sts = {
            "stype": "C",
            "titl": "Select the Required System",
            "head": ("COD", "System"),
            "data": dats
        }
        r1s = (("All", "A"), ("System", "S"), ("Singles", "X"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Tables", "", "X", "Y",
                self.doTab, None, None, None),
               (("T", 0, 1, 0), "IUA", 3, "System", "", "ALL", "Y", self.doSys,
                sts, None, ("in", syss)))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doTab(self, frt, pag, r, c, p, i, w):
        self.seltab = w
        if self.seltab != "S":
            self.sys = None
            return "sk1"

    def doSys(self, frt, pag, r, c, p, i, w):
        if w == "MST":
            self.sys = "ctl"
        else:
            self.sys = w

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

    def printReport(self):
        if self.seltab == "X":
            tabs = getSingleRecords(self.opts["mf"],
                                    "ftable", ("ft_tabl", "ft_desc"),
                                    where=[("ft_seq", "=", 1)])
        else:
            whr = [("ft_seq", "=", 1)]
            if self.seltab == "S":
                whr.append(("ft_tabl", "like", self.sys.lower() + "%"))
            tabs = self.sql.getRec("ftable",
                                   cols=["ft_tabl", "ft_desc"],
                                   where=whr,
                                   order="ft_tabl")
        if not tabs:
            return
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=80)
        self.pgnum = 0
        p = ProgressBar(self.opts["mf"].body, mxs=len(tabs), esc=True)
        for num, tab in enumerate(tabs):
            p.displayProgress(num)
            if p.quit:
                break
            recs = self.sql.getRec("ffield",
                                   where=[("ff_tabl", "=", tab[0])],
                                   order="ff_seq")
            if not recs:
                continue
            self.doHeading("F", tab[0])
            for rec in recs:
                a = CCD(rec[1], "UI", 3).disp
                b = CCD(rec[2], "NA", 20).disp
                c = CCD(rec[3], "NA", 2).disp
                d = CCD(rec[4], "UD", 6.1).disp
                e = CCD(rec[5], "NA", 30).disp
                f = CCD(rec[6], "NA", 30).disp
                self.fpdf.drawText("%3s %-20s %2s %6s %-30s %-30s" % \
                    (a, b, c, d, e, f))
            recs = self.sql.getRec("ftable",
                                   where=[("ft_tabl", "=", tab[0])],
                                   order="ft_seq")
            if not recs:
                continue
            self.doHeading("I", tab[0])
            for rec in recs:
                a = CCD(rec[1], "NA", 20).disp
                b = CCD(rec[2], "UI", 1).disp
                c = CCD(rec[3], "NA", 1).disp
                d = CCD(rec[4], "NA", 10).disp
                e = CCD(rec[5], "NA", 10).disp
                f = CCD(rec[6], "NA", 10).disp
                g = CCD(rec[7], "NA", 10).disp
                h = CCD(rec[8], "NA", 10).disp
                i = CCD(rec[9], "NA", 10).disp
                j = CCD(rec[10], "NA", 10).disp
                self.fpdf.drawText("%-20s %2s %1s %-10s %-10s %-10s %-10s "\
                    "%-10s %-10s %-10s" % (a, b, c, d, e, f, g, h, i, j))
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                0,
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=1,
                      pdfnam=pdfnam,
                      header="Table Fields and Indexes",
                      repprt=self.df.repprt,
                      repeml=self.df.repeml)

    def doHeading(self, htyp, table):
        self.fpdf.setFont(style="B")
        if htyp == "F":
            self.fpdf.add_page()
            self.pgnum += 1
            self.fpdf.drawText(self.head)
            self.fpdf.drawText()
            self.fpdf.drawText("%-90s %-5s %5s" % ("Table Fields for "\
                "Table %s" % table, "Page", self.pgnum))
            head = "%3s %-20s %2s %6s %-30s %-30s" % (
                "Seq", "Field Name", "Tp", "Size", "Description", "Heading")
        else:
            self.fpdf.drawText()
            self.fpdf.drawText("Table Indexes for Table %s" % table)
            head = "%-20s %2s %1s %-10s %-10s %-10s %-10s %-10s %-10s "\
                "%-10s" % ("Table Description", "Sq", "T", "1st-Col",
                "2nd-Col", "3rd-Col", "4th-Col", "5th-Col", "6th-Col",
                "7th-Col")
        self.fpdf.drawText()
        self.fpdf.drawText(head)
        self.fpdf.underLine(head)
        self.fpdf.setFont()

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 12
0
class ln3030(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, ["lonmf1", "lonmf2", "lontrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        lonctl = gc.getCtl("lonctl", self.opts["conum"])
        if not lonctl:
            return
        self.fromad = lonctl["cln_emadd"]
        t = time.localtime()
        self.curdt = int(((t[0] * 10000) + (t[1] * 100) + t[2]) / 100)
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Loans Balances Listing (%s)" % self.__class__.__name__)
        r1s = (("Number", "N"), ("Name", "M"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "ID2", 7, "Reporting Period", "", self.curdt,
                "Y", self.doDate, None, None,
                ("efld", )), (("T", 0, 1, 0), ("IRB", r1s), 1, "Sort Order",
                              "", "N", "Y", self.doSort, None, None, None),
               (("T", 0, 2, 0), ("IRB", r2s), 1, "Include Zero Balances", "",
                "N", "Y", self.doZero, None, None, None),
               (("T", 0, 3, 0), ("IRB", r2s), 1, "Include Pending Interest",
                "", "N", "Y", self.doPend, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doDate(self, frt, pag, r, c, p, i, w):
        self.curdt = w
        self.cdte = self.df.t_disp[pag][0][i]
        self.date = mthendDate(w * 100)

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

    def doZero(self, frt, pag, r, c, p, i, w):
        self.zero = w

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

    def doEnd(self):
        self.df.closeProcess()
        if self.sort == "N":
            odr = "lm1_acno"
        else:
            odr = "lm1_name"
        lm1 = self.sql.getRec("lonmf1",
                              where=[("lm1_cono", "=", self.opts["conum"])],
                              order=odr)
        if not lm1:
            showError(self.opts["mf"].body, "Loans Error", "No Loans Selected")
        else:
            self.printReport(lm1)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        if self.pend == "Y":
            self.head = "%03u %-118s" % (self.opts["conum"],
                                         self.opts["conam"])
        else:
            self.head = "%03u %-90s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        ltot = 0
        itot = 0
        ntot = 0
        self.pglin = 999
        for num, rec in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            acc = CCD(rec[self.sql.lonmf1_col.index("lm1_acno")], "UA", 7)
            nam = CCD(rec[self.sql.lonmf1_col.index("lm1_name")], "NA", 28)
            lm2 = self.sql.getRec("lonmf2",
                                  where=[("lm2_cono", "=", self.opts["conum"]),
                                         ("lm2_acno", "=", acc.work)],
                                  order="lm2_loan")
            for dat in lm2:
                lon = CCD(dat[self.sql.lonmf2_col.index("lm2_loan")], "UI", 2)
                des = CCD(dat[self.sql.lonmf2_col.index("lm2_desc")], "NA", 30)
                dte = CCD(dat[self.sql.lonmf2_col.index("lm2_start")], "d1",
                          10)
                col = ["sum(lnt_tramt)"]
                whr = [("lnt_cono", "=", self.opts["conum"]),
                       ("lnt_acno", "=", acc.work),
                       ("lnt_loan", "=", lon.work),
                       ("lnt_curdt", "<=", self.curdt)]
                lbal = self.sql.getRec("lontrn", cols=col, where=whr, limit=1)
                lbal = CCD(lbal[0], "SD", 13.2)
                if self.zero == "N" and not lbal.work:
                    continue
                if self.pglin > self.fpdf.lpp:
                    self.pageHeading()
                ltot = float(ASD(ltot) + ASD(lbal.work))
                if self.pend == "Y":
                    LoanInterest("L",
                                 self.opts["mf"].dbm,
                                 dat,
                                 update="Y",
                                 tdate=self.date,
                                 batch="Pending",
                                 curdt=self.curdt)
                    nbal = self.sql.getRec("lontrn",
                                           cols=col,
                                           where=whr,
                                           limit=1)
                    nbal = CCD(nbal[0], "SD", 13.2)
                    ntot = float(ASD(ntot) + ASD(nbal.work))
                    ibal = CCD(nbal.work - lbal.work, "SD", 13.2)
                    itot = float(ASD(itot) + ASD(ibal.work))
                    self.fpdf.drawText(
                        "%s %s %s %s %s %s %s %s" %
                        (acc.disp, nam.disp, lon.disp, des.disp, dte.disp,
                         lbal.disp, ibal.disp, nbal.disp))
                else:
                    self.fpdf.drawText("%s %s %s %s %s %s" %
                                       (acc.disp, nam.disp, lon.disp, des.disp,
                                        dte.disp, lbal.disp))
                self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.fpdf.underLine(txt=self.head)
            ltot = CCD(ltot, "SD", 13.2)
            if self.pend == "Y":
                itot = CCD(itot, "SD", 13.2)
                ntot = CCD(ntot, "SD", 13.2)
                self.fpdf.drawText(
                    "%8s%-74s%13s %13s %13s" %
                    ("", "Totals", ltot.disp, itot.disp, ntot.disp))
            else:
                self.fpdf.drawText("%8s%-74s%13s" % ("", "Totals", ltot.disp))
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        txt = "%-29s %-7s" % ("Loans Balances Listing as at", self.cdte)
        self.fpdf.drawText(txt=txt)
        self.fpdf.drawText()
        self.fpdf.drawText("%s %s  %s %s)" % \
            ("(Options: Sort:", self.sort, "Include-Zero-Bal:", self.zero))
        self.fpdf.drawText()
        txt = "%-7s %-28s %-2s %-30s %-10s" % \
            ("Acc-Num", "Name", "Ln", "Description", "Start-Date")
        if self.pend == "Y":
            txt = "%s %13s %13s %13s" % \
                (txt, "Ledger-Bal ", "Interest ", "Balance ")
        else:
            txt = "%s %13s" % (txt, "Balance ")
        self.fpdf.drawText(txt=txt)
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 13
0
class gl3040(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            if "args" in self.opts and "noprint" not in self.opts["args"]:
                self.opebal = "N"
                self.incope = "Y"
                self.start = self.s_per
                self.end, self.zerbal, self.repprt, self.repeml, self.fpdf = \
                        self.opts["args"]
                self.doEnd()
            elif "wait" in self.opts:
                self.mainProcess()
                self.df.mstFrame.wait_window()
            else:
                self.mainProcess()
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["genbal", "genmst", "gentrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.head1 = ("%03u %-30s" % (self.opts["conum"], self.opts["conam"]))
        self.colsh = ["Acc-Num", "T", "Description", "Debit", "Credit"]
        self.forms = [("UI", 7), ("UA", 1), ("NA", 40)] + [("SD", 14.2)] * 2
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        self.dtot = 0.00
        self.ctot = 0.00
        self.gp = 0.00
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "General Ledger Trial Balance (%s)" %
                    self.__class__.__name__)
        r1s = (("Yes", "Y"), ("No", "N"))
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["N", "Y", "", "", "Y"]
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Opening Balances Only", "",
                var[0], "Y", self.doOpeBal1, None, None, None),
               (("T", 0, 1, 0), ("IRB", r1s), 0, "Include Opening Balances",
                "", var[1], "N", self.doOpeBal2, None, None, None),
               (("T", 0, 2, 0), "Id2", 7, "Starting Period", "", self.s_per,
                "N", self.doStartPer, None, None, ("efld", )),
               (("T", 0, 3, 0), "Id2", 7, "Ending Period", "", self.e_per, "N",
                self.doEndPer, None, None, ("efld", )),
               (("T", 0, 4, 0), ("IRB", r1s), 0, "Ignore Zero Balances", "",
                var[4], "N", self.doZerBal, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doOpeBal1(self, frt, pag, r, c, p, i, w):
        self.opebal = w
        if self.opebal == "Y":
            self.start = None
            self.end = None
            self.incope = None
            return "sk3"

    def doOpeBal2(self, frt, pag, r, c, p, i, w):
        self.incope = w
        if self.incope == "Y":
            self.start = self.s_per
            self.df.loadEntry("T", 0, 2, data=self.start)
            return "sk1"

    def doStartPer(self, frt, pag, r, c, p, i, w):
        if w < self.s_per or w > self.e_per:
            return "Invalid Period, Outside Financial Period"
        self.start = w

    def doEndPer(self, frt, pag, r, c, p, i, w):
        if w < self.start:
            return "Invalid Period, Before Start Period"
        if w > self.e_per:
            return "Invalid Period, Outside Financial Period"
        self.end = w

    def doZerBal(self, frt, pag, r, c, p, i, w):
        self.zerbal = w

    def doEnd(self):
        if "args" not in self.opts or "noprint" in self.opts["args"]:
            self.repprt = self.df.repprt
            self.repeml = self.df.repeml
            self.t_work = [self.df.t_work[0][0]]
            self.df.closeProcess()
        recs = self.sql.getRec("genmst",
                               cols=["glm_acno", "glm_desc", "glm_type"],
                               where=[("glm_cono", "=", self.opts["conum"])],
                               order="glm_type desc, glm_acno")
        if not recs:
            showError(self.opts["mf"].body, "Selection Error", "No Accounts")
        elif self.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        if "args" not in self.opts or "noprint" in self.opts["args"]:
            self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        expheads = [self.head1 + " %s" % self.sysdttm]
        if self.opebal == "Y":
            date = CCD(self.opts["period"][1][0], "D1", 10)
            expheads.append("General Ledger Opening Balances as at %s" % \
                date.disp)
        else:
            sdate = CCD(self.start, "D2", 7)
            edate = CCD(self.end, "D2", 7)
            expheads.append("General Ledger Trial Balance for Period %s "\
                "to %s" % (sdate.disp, edate.disp))
            expheads.append("(Options: Opening Balances Included %s)" % \
                self.incope)
        expcolsh = [self.colsh]
        expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            self.expdatas.append([
                "BODY",
                [
                    vals[0].work, vals[1].work, vals[2].work, vals[3].work,
                    vals[4].work
                ]
            ])
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.repprt[1],
                      name=expnam,
                      heads=expheads,
                      colsh=expcolsh,
                      forms=expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        chrs = len(self.colsh)
        for f in self.forms:
            chrs += int(f[1])
        if f[0][0].lower() == "s":
            chrs -= 2
        else:
            chrs -= 1
        if self.opebal == "Y":
            date = CCD(self.opts["period"][1][0], "D1", 10.0)
            self.head2 = "General Ledger Opening Balances as at %s%s" % \
                (date.disp, "%s%s")
        else:
            sdate = CCD(self.start, "D2", 7)
            edate = CCD(self.end, "D2", 7)
            self.head2 = "General Ledger Trial Balance for Period %s to %s" % \
                (sdate.disp, edate.disp)
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        if "args" not in self.opts or "noprint" in self.opts["args"]:
            self.fpdf = MyFpdf(name=self.__class__.__name__, head=80)
        self.pglin = 999
        for num, rec in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(rec)
            if not vals:
                continue
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText("%s %1s %-40s %s %s" %
                               (vals[0].disp, vals[1].disp, vals[2].disp,
                                vals[3].disp, vals[4].disp))
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.grandTotal()
            if "args" not in self.opts:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.repprt,
                          repeml=self.repeml)

    def getValues(self, data):
        acno = CCD(data[0], "UI", 7)
        desc = CCD(data[1], "NA", 40)
        atyp = CCD(data[2], "UA", 1)
        bal = 0.0
        if self.opebal == "Y" or self.incope == "Y":
            o = self.sql.getRec("genbal",
                                cols=["glo_cyr"],
                                where=[("glo_cono", "=", self.opts["conum"]),
                                       ("glo_acno", "=", acno.work),
                                       ("glo_trdt", "=",
                                        self.opts["period"][1][0])],
                                limit=1)
            if o:
                b = CCD(o[0], "SD", 14.2)
            else:
                b = CCD(0, "SD", 14.2)
            bal = float(ASD(bal) + ASD(b.work))
        if self.opebal == "N" and self.incope == "Y":
            o = self.sql.getRec("gentrn",
                                cols=["round(sum(glt_tramt),2)"],
                                where=[("glt_cono", "=", self.opts["conum"]),
                                       ("glt_acno", "=", acno.work),
                                       ("glt_curdt", ">", self.s_per),
                                       ("glt_curdt", "<", self.start)],
                                limit=1)
            if o and o[0]:
                b = CCD(float(o[0]), "SD", 14.2)
            else:
                b = CCD(0, "SD", 14.2)
            bal = float(ASD(bal) + ASD(b.work))
        if self.opebal == "N":
            o = self.sql.getRec("gentrn",
                                cols=["round(sum(glt_tramt),2)"],
                                where=[("glt_cono", "=", self.opts["conum"]),
                                       ("glt_acno", "=", acno.work),
                                       ("glt_curdt", "between", self.start,
                                        self.end)],
                                limit=1)
            if o and o[0]:
                b = CCD(float(o[0]), "SD", 14.2)
            else:
                b = CCD(0, "SD", 14.2)
            bal = float(ASD(bal) + ASD(b.work))
        if bal == 0 and self.zerbal == "Y":
            return
        if bal < 0:
            cr = CCD(bal, "SD", 14.2)
            dr = CCD(0.00, "SD", 14.2)
        else:
            dr = CCD(bal, "SD", 14.2)
            cr = CCD(0.00, "SD", 14.2)
        self.dtot = float(ASD(self.dtot) + ASD(dr.work))
        self.ctot = float(ASD(self.ctot) + ASD(cr.work))
        if atyp.work == "P":
            self.gp = float(ASD(self.gp) + ASD(dr.work) + ASD(cr.work))
        return (acno, atyp, desc, dr, cr)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head1)
        self.fpdf.drawText()
        self.fpdf.drawText(self.head2)
        if self.opebal == "N":
            self.fpdf.drawText()
            self.fpdf.drawText("(Options: Opening Balances Included %s)" % \
                (self.incope))
        self.fpdf.drawText()
        self.fpdf.drawText("%-7s %-1s %-40s %14s %14s" % \
            ("Acc-Num", "T", "Description", "Debit ", "Credit "))
        self.fpdf.underLine()
        self.fpdf.setFont()
        if self.opebal == "Y":
            self.pglin = 6
        else:
            self.pglin = 8

    def grandTotal(self):
        if self.repprt[2] == "export":
            self.expdatas.append(["ULINES"])
            self.expdatas.append(
                ["TOTAL", ["", "", "Grand Totals", self.dtot, self.ctot]])
            self.expdatas.append(["ULINED"])
            return
        d = CCD(self.dtot, "SD", 14.2)
        c = CCD(self.ctot, "SD", 14.2)
        self.fpdf.setFont(style="B")
        if self.fpdf.lpp - self.pglin < 5:
            self.pageHeading()
        else:
            self.fpdf.underLine()
        self.fpdf.drawText("%9s %-40s %14s %14s" % \
            ("", "Grand-Totals", d.disp, c.disp))
        self.pglin += 2
        if self.pglin > self.fpdf.lpp:
            self.pageHeading()
        gp = CCD(self.gp, "SD", 14.2)
        if gp.work > 0:
            self.fpdf.drawText()
            self.fpdf.drawText("%9s %-40s %14s %14s" % \
                ("", "Gross-Loss", gp.disp, ""))
        else:
            self.fpdf.drawText()
            self.fpdf.drawText("%9s %-40s %14s %14s" % \
                ("", "Gross-Profit", "", gp.disp))
        self.pglin += 2
        diff = CCD(float(ASD(d.work) + ASD(c.work)), "SD", 14.2)
        if diff.work:
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText()
            self.fpdf.drawText("%9s %-40s %14s %14s" % \
                ("", "Difference", "", diff.disp))
        self.fpdf.setFont()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 14
0
class sc3010(object):
    def __init__(self, **opts):
        self.opts = opts
        self.setVariables()
        self.mainProcess()
        self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, "scpcmp",
            prog=self.__class__.__name__)
        t = time.localtime()
        self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png")
        if not os.path.exists(self.image):
            getImage("bowls", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None

    def mainProcess(self):
        com = {
            "stype": "R",
            "tables": ("scpcmp",),
            "cols": (
                ("scp_ccod", "", 0, "Cod"),
                ("scp_name", "", 0, "Name", "Y")),
            "where": [("scp_cono", "=", self.opts["conum"])]}
        fld = (
            (("T",0,0,0),"I@scp_ccod",0,"Code","",
                "","N",self.doCmpCod,com,None,("notzero",)),
            (("T",0,0,0),"ONA",30,""))
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], tops=False,
            eflds=fld, tend=tnd, txit=txt, view=("N","V"))

    def doCmpCod(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("scpcmp", cols=["scp_name"],
            where=[("scp_cono", "=", self.opts["conum"]), ("scp_ccod", "=",
            w)], limit=1)
        if not chk:
            return "Invalid Competition Code"
        self.ccod = w
        self.cnam = chk[0]
        self.df.loadEntry(frt, pag, p+1, data=self.cnam)

    def doEnd(self):
        self.df.closeProcess()
        col = ["scm_scod", "scm_surname", "scm_names", "scm_gender",
            "scc_name", "scm_phone"]
        whr = [
            ("sce_cono", "=", self.opts["conum"]),
            ("sce_ccod", "=", self.ccod),
            ("scm_cono=sce_cono",),
            ("scm_scod=sce_scod",),
            ("scc_club=scm_club",)]
        recs = self.sql.getRec(tables=["scpent", "scpmem", "scpclb"], cols=col,
            where=whr, order="scm_surname")
        if recs:
            self.fpdf = MyFpdf(auto=True, name="sc3010", head=90)
            self.fpdf.header = self.doHead
            self.fpdf.add_page()
            cwth = self.fpdf.cwth
            for num, rec in enumerate(recs):
                self.fpdf.drawText(txt="%6s" % rec[0], w=cwth*7, h=5, ln=0)
                nm = rec[1].strip() + ", %s" % rec[2].split()[0]
                self.fpdf.drawText(txt=nm, w=cwth*31, h=5, ln=0)
                self.fpdf.drawText(txt=rec[3], w=cwth*2, h=5, ln=0)
                self.fpdf.drawText(txt=rec[4], w=cwth*31, h=5, ln=0)
                ph = rec[5].replace(" ", "").strip()
                self.fpdf.drawText(txt=ph, w=cwth*16, h=5, ln=1)
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                self.__class__.__name__, self.opts["conum"], ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"], pdfnam=pdfnam,
                repprt=self.df.repprt,
                repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def doHead(self):
        if os.path.isfile(self.image):
            self.fpdf.image(self.image, 10, 10, 15, 11)
        self.fpdf.set_font("Arial","B",15)
        self.fpdf.cell(20)
        self.fpdf.cell(0,10,"Players Entered in the %s" % self.cnam,1,0,"C")
        self.fpdf.ln(20)
        self.fpdf.setFont(style="B")
        self.fpdf.cell(0, 5, "%-6s %-30s %-1s %-30s %-15s" % \
            ("Reg-No", "Name", "G", "Club", "Contact"), "B")
        self.fpdf.ln(5)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 15
0
class dr3060(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, ["drsact", "drstyp", "drsmst"],
                       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.fromad = drsctl["ctd_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i)" % \
            (t[0], t[1], t[2], t[3], t[4])
        self.colsh = [
            "Chn", "Acc-Num", "Name", "Address", "Code", "Tel-Number",
            "Fax-Number", "Contact Details", "Deliver", "Rep", "Act", "Typ",
            "P", "Rft", "C-Limit"
        ]
        self.forms = [("UI", 3), ("NA", 7), ("NA", 30), ("NA", 30), ("NA", 4),
                      ("NA", 12), ("NA", 12), ("NA", 40), ("Na", 7), ("Na", 3),
                      ("UA", 3), ("UA", 3), ("UI", 1), ("UI", 3), ("UI", 3),
                      ("UI", 7)]
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Debtors Master Listing (%s)" % self.__class__.__name__)
        daa = self.sql.getRec("drsmst",
                              cols=["drm_bus_activity", "count(*)"],
                              where=[("drm_cono", "=", self.opts["conum"])],
                              group="drm_bus_activity",
                              order="drm_bus_activity")
        act = {
            "stype": "C",
            "titl": "Valid Activities",
            "head": ("Act", "Quantity"),
            "data": daa,
            "typs": (("NA", 3), ("UI", 8)),
            "size": (400, 400)
        }
        dab = self.sql.getRec("drsmst",
                              cols=["drm_bus_type", "count(*)"],
                              where=[("drm_cono", "=", self.opts["conum"])],
                              group="drm_bus_type",
                              order="drm_bus_type")
        typ = {
            "stype": "C",
            "titl": "Valid Types",
            "head": ("Typ", "Quantity"),
            "data": dab,
            "typs": (("NA", 3), ("UI", 8)),
            "size": (400, 400)
        }
        r1s = (("Number", "N"), ("Name", "M"))
        r2s = (("Yes", "Y"), ("No", "N"))
        r3s = (("Manager", "M"), ("Accounts", "A"), ("Sales", "S"))
        r4s = (("Yes", "Y"), ("No", "N"), ("Only", "O"))
        fld = ((("T", 0, 0, 0), "INA", 3, "Activity", "Account Activity", "",
                "N", self.doAct, act, None, None), (("T", 0, 0, 0), "ONA", 30,
                                                    ""),
               (("T", 0, 1, 0), "INA", 3, "Type", "Account Type", "", "N",
                self.doTyp, typ, None, None), (("T", 0, 1, 0), "ONA", 30, ""),
               (("T", 0, 2, 0), ("IRB", r1s), 0, "Sort Order", "", "N", "Y",
                self.doSort, None, None,
                None), (("T", 0, 3, 0), ("IRB", r2s), 0, "Full Address", "",
                        "N", "Y", self.doAddress, None, None, None),
               (("T", 0, 4, 0), ("IRB", r3s), 0, "Contact Details", "", "M",
                "Y", self.doContact, None, None,
                None), (("T", 0, 5, 0), ("IRB", r4s), 0, "Include Redundant",
                        "", "N", "Y", self.doRedu, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "N"))

    def doAct(self, frt, pag, r, c, p, i, w):
        self.act = w
        if not self.act:
            self.df.loadEntry(frt, pag, p + 1, "All Activities")
        else:
            chk = self.sql.getRec("drsact",
                                  where=[("dac_code", "=", self.act)],
                                  limit=1)
            if not chk:
                return "Invalid Activity Code"
            self.df.loadEntry(frt, pag, p + 1, chk[1])

    def doTyp(self, frt, pag, r, c, p, i, w):
        self.typ = w
        if not self.typ:
            self.df.loadEntry(frt, pag, p + 1, "All Types")
        else:
            chk = self.sql.getRec("drstyp",
                                  where=[("dtp_code", "=", self.typ)],
                                  limit=1)
            if not chk:
                return "Invalid Type Code"
            self.df.loadEntry(frt, pag, p + 1, chk[1])

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

    def doAddress(self, frt, pag, r, c, p, i, w):
        self.address = w

    def doContact(self, frt, pag, r, c, p, i, w):
        self.condet = w

    def doRedu(self, frt, pag, r, c, p, i, w):
        self.redu = w

    def doEnd(self):
        self.df.closeProcess()
        whr = [("drm_cono", "=", self.opts["conum"])]
        if self.act:
            whr.append(("drm_bus_activity", "=", self.act))
        if self.typ:
            whr.append(("drm_bus_type", "=", self.typ))
        if self.redu == "N":
            whr.append(("drm_stat", "<>", "X"))
        elif self.redu == "O":
            whr.append(("drm_stat", "=", "X"))
        if self.sort == "N":
            odr = "drm_chain, drm_acno"
        else:
            odr = "drm_name"
        recs = self.sql.getRec("drsmst", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Records Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        expheads = [
            "%03u %-30s %s %6s" % (self.opts["conum"], self.opts["conam"],
                                   self.sysdttm, self.__class__.__name__)
        ]
        expheads.append("Debtors Master Code List as at %s" % self.sysdtd)
        expcolsh = [self.colsh]
        expforms = self.forms
        expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            expdatas.append([
                "BODY",
                [
                    vals[0].work, vals[1].work, vals[2].work, vals[3].work,
                    vals[4].work, vals[5].work, vals[6].work, vals[7].work,
                    vals[8].work, vals[9].work, vals[10].work, vals[11].work,
                    vals[12].work, vals[13].work, vals[14].work, vals[15].work
                ]
            ])
        p.closeProgress()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=expheads,
                      colsh=expcolsh,
                      forms=expforms,
                      datas=expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-179s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s %s %s "\
                "%s %s %s %s" % (vals[0].disp, vals[1].disp, vals[2].disp,
                vals[3].disp, vals[4].disp, vals[5].disp, vals[6].disp,
                vals[7].disp, vals[8].disp, vals[9].disp, vals[10].disp,
                vals[11].disp, vals[12].disp, vals[13].disp, vals[14].disp,
                vals[15].disp))
            if self.address == "Y" and vals[16].work:
                self.fpdf.drawText("%42s %-30s" % ("", vals[16].disp))
                self.pglin += 1
            if self.address == "Y" and vals[17].work:
                self.fpdf.drawText("%42s %-30s" % ("", vals[17].disp))
                self.pglin += 1
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def getValues(self, dat):
        col = self.sql.drsmst_col
        chn = CCD(dat[col.index("drm_chain")], "UI", 3)
        acno = CCD(dat[col.index("drm_acno")], "NA", 7)
        name = CCD(dat[col.index("drm_name")], "NA", 30)
        add1 = CCD(dat[col.index("drm_add1")], "NA", 30)
        pcod = CCD(dat[col.index("drm_pcod")], "NA", 4)
        tel = CCD(dat[col.index("drm_tel")], "NA", 12)
        fax = CCD(dat[col.index("drm_fax")], "NA", 12)
        if self.condet == "M":
            contact = dat[col.index("drm_mgr")]
            email = dat[col.index("drm_mgr_email")].split(",")
        elif self.condet == "A":
            contact = dat[col.index("drm_acc")]
            email = dat[col.index("drm_acc_email")].split(",")
        else:
            contact = dat[col.index("drm_sls")]
            email = dat[col.index("drm_sls_email")].split(",")
        nameml = CCD("%s <%s>" % (contact, email[0]), "NA", 40)
        delv = CCD(dat[col.index("drm_delivery")], "Na", 7)
        rep = CCD(dat[col.index("drm_rep")], "Na", 3)
        bact = CCD(dat[col.index("drm_bus_activity")], "UA", 3)
        btyp = CCD(dat[col.index("drm_bus_type")], "UA", 3)
        prices = CCD(dat[col.index("drm_plev")], "UI", 1)
        rfterm = CCD(dat[col.index("drm_rfterms")], "UI", 3)
        rjterm = CCD(dat[col.index("drm_rjterms")], "UI", 3)
        limit = CCD(dat[col.index("drm_limit")], "UI", 7)
        add2 = CCD(dat[col.index("drm_add2")], "NA", 30)
        add3 = CCD(dat[col.index("drm_add3")], "NA", 30)
        return (chn, acno, name, add1, pcod, tel, fax, nameml, delv, rep, bact,
                btyp, prices, rfterm, rjterm, limit, add2, add3)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-32s %-150s" % \
            ("Debtors Ledger Master List as at", self.sysdtd))
        self.fpdf.drawText()
        self.fpdf.drawText("(%-15s%1s)" %
                           ("Options: Sort-", self.df.t_disp[0][0][0]))
        self.fpdf.drawText()
        if self.condet == "M":
            det = "Manager's Contact Details"
        elif self.condet == "A":
            det = "Accounts Contact Details"
        else:
            det = "Orders Contact Details"
        self.fpdf.drawText("%-3s %-7s %-30s %-30s %-4s %-12s %-12s %-40s "\
            "%-7s %-3s %-3s %-3s %1s %-3s %-3s %-7s" % ("Chn", "Acc-Num",
            "Name", "Address", "Code", "Tel-Number", "Fax-Number", det,
            "Deliver", "Rep", "Act", "Typ", "P", "Rft","Rjt","C-Limit"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 16
0
class rt4010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       ["rtlprm", "rtlmst", "rtlcon", "rtltrn"],
                       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
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Rental Ledger Interrogation (%s)" %
                    self.__class__.__name__)
        prm = {
            "stype":
            "R",
            "tables": ("rtlprm", ),
            "cols": (("rtp_code", "", 0, "Prm-Code"), ("rtp_desc", "", 0,
                                                       "Description", "Y")),
            "where": [("rtp_cono", "=", self.opts["conum"])]
        }
        acc = {
            "stype":
            "R",
            "tables": ("rtlmst", ),
            "cols":
            (("rtm_acno", "", 0, "Acc-Num"), ("rtm_name", "", 0, "Name", "Y")),
            "where": [("rtm_cono", "=", self.opts["conum"])],
            "whera": (("T", "rtm_code", 0, 0), )
        }
        seq = {
            "stype":
            "R",
            "tables": ("rtlcon", ),
            "cols":
            (("rtc_cnum", "", 0, "Acc-Num"), ("rtc_payind", "", 0, "F"),
             ("rtc_start", "", 0, "Start-Date"), ("rtc_period", "", 0, "Per")),
            "where": [("rtc_cono", "=", self.opts["conum"])],
            "whera": [["T", "rtc_code", 0, 0], ["T", "rtc_acno", 1, 0]]
        }
        tag = (("Premises", self.doTagSelect, ("T", 0, 0), ("T", 0, 1)),
               ("Tenant", self.doTagSelect, ("T", 0, 0), ("T", 0, 1)),
               ("Balances", self.doTagSelect, ("T", 0, 0), ("T", 0, 1)),
               ("Transactions", self.doTrans1, ("T", 0, 0), ("T", 0, 1)))
        fld = ((("T", 0, 0, 0), "INA", 7, "Premises", "Premises Code", "", "Y",
                self.doPremises, prm, None, ("notblank", )),
               (("T", 0, 0, 0), "INA", 7, "Account", "Account Code", "", "N",
                self.doAccount, acc, None,
                ("notblank", )), (("T", 0, 0, 0), "ONA", 30, "Name"),
               (("T", 1, 0, 0), "ONA", 30,
                "Description"), (("T", 1, 1, 0), "ONA", 30, "Address-1"),
               (("T", 1, 2, 0), "ONA", 30,
                "Address-2"), (("T", 1, 3, 0), "ONA", 30, "Address-3"),
               (("T", 1, 4, 0), "ONA", 4,
                "Postal Code"), (("T", 2, 0, 0), "ONA", 30, "Address-1"),
               (("T", 2, 1, 0), "ONA", 30,
                "Address-2"), (("T", 2, 2, 0), "ONA", 30, "Address-3"),
               (("T", 2, 3, 0), "ONA", 4,
                "Postal Code"), (("T", 2, 4, 0), "ONA", 20,
                                 "Telephone Number"), (("T", 2, 5, 0), "OTX",
                                                       50, "E-Mail Address"),
               (("T", 2, 6, 0), "OUA", 1,
                "VAT Indicator"), (("T", 2, 7, 0), "ONA", 10, "VAT Number"),
               (("T", 2, 8, 0), "OUA", 1,
                "Payment Frequency"), (("T", 2, 9, 0), "OD1", 10,
                                       "Start Date"), (("T", 2, 10, 0), "OUI",
                                                       3, "Number of Periods"),
               (("T", 2, 11, 0), "OUD", 12.2,
                "Rental Amount"), (("T", 2, 12, 0), "OUA", 1, "Status"),
               (("C", 3, 0, 0), "OSD", 13.2, "Value", "", "", "N", None, None,
                None, None, ("Details", 5)), (("T", 4, 0, 0), "IUI", 3,
                                              "Sequence Number", "", "N", "N",
                                              self.doTrans2, seq, None, None))
        but = (("Clear", None, self.doClear, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Notes", None, self.doNotes, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Print", None, self.doPrint, 0, ("T", 0, 0),
                ("T", 0, 1)), ("Quit", None, self.doExit, 1, None, None))
        tnd = ((self.doEndTop, "N"), None, None, None, None)
        txt = (self.doExit, None, None, None, self.doExit)
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               tags=tag,
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt)
        self.df.colLabel[3][0].configure(text="Rentals ")
        self.df.colLabel[3][1].configure(text="Receipts")
        self.df.colLabel[3][2].configure(text="Payments")
        self.df.colLabel[3][3].configure(text="Journals")
        self.df.colLabel[3][4].configure(text="Balance ")

    def doPremises(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("rtlprm",
                              where=[("rtp_cono", "=", self.opts["conum"]),
                                     ("rtp_code", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Premises"
        self.code = w
        for num, fld in enumerate(acc):
            if num < 2 or num > 6:
                continue
            self.df.loadEntry("T", 1, (num - 2), data=fld)

    def doAccount(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("rtlmst",
                              where=[("rtm_cono", "=", self.opts["conum"]),
                                     ("rtm_code", "=", self.code),
                                     ("rtm_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account"
        self.acno = w
        self.name = acc[self.sql.rtlmst_col.index("rtm_name")]
        con = self.sql.getRec("rtlcon",
                              where=[("rtc_cono", "=", self.opts["conum"]),
                                     ("rtc_code", "=", self.code),
                                     ("rtc_acno", "=", self.acno)],
                              order="rtc_cnum")
        if not con:
            return "Invalid Contract"
        self.df.loadEntry(frt, pag, p + 1, data=acc[3])
        for num, fld in enumerate(acc[4:]):
            self.df.loadEntry("T", 2, num, data=fld)
        self.cnum = con[-1:][0][3]
        self.df.topf[4][0][5] = self.cnum
        for num, fld in enumerate(con[-1:][0][4:-1]):
            self.df.loadEntry("T", 2, num + 8, data=fld)
        self.loadBalances()
        self.opts["mf"].updateStatus("")

    def doEndTop(self):
        self.df.last[0] = [0, 0]
        self.df.setWidget(self.df.topEntry[0][0], state="disabled")

    def loadBalances(self):
        rtl = 0
        rec = 0
        pmt = 0
        jnl = 0
        bal = self.sql.getRec("rtltrn",
                              cols=["rtt_type", "round(sum(rtt_tramt), 2)"],
                              where=[("rtt_cono", "=", self.opts["conum"]),
                                     ("rtt_code", "=", self.code),
                                     ("rtt_acno", "=", self.acno)],
                              group="rtt_type",
                              order="rtt_type")
        if bal:
            for a in bal:
                if a[0] == 1:
                    rtl = a[1]
                if a[0] == 2:
                    rec = a[1]
                if a[0] == 3:
                    pmt = a[1]
                if a[0] == 4:
                    jnl = a[1]
        bal = float(ASD(rtl) + ASD(rec) + ASD(pmt) + ASD(jnl))
        self.df.loadEntry("C", 3, 0, data=rtl)
        self.df.loadEntry("C", 3, 1, data=rec)
        self.df.loadEntry("C", 3, 2, data=pmt)
        self.df.loadEntry("C", 3, 3, data=jnl)
        self.df.loadEntry("C", 3, 4, data=bal)
        self.trn = self.sql.getRec("rtltrn",
                                   where=[("rtt_cono", "=",
                                           self.opts["conum"]),
                                          ("rtt_code", "=", self.code),
                                          ("rtt_acno", "=", self.acno)],
                                   order="rtt_trdt, rtt_type")

    def doTagSelect(self):
        self.opts["mf"].updateStatus("")

    def doTrans1(self):
        self.df.focusField("T", 4, 1)

    def doTrans2(self, frt, pag, r, c, p, i, w):
        tit = "Transactions for Account: %s %s - %s" % \
            (self.code, self.acno, self.name)
        tab = ["rtltrn"]
        col = (("rtt_trdt", "", 0, "   Date"), ("rtt_curdt", "", 0, "Curr-Dt"),
               ("rtt_batch", "", 0,
                "Batch"), ("rtt_type", ("XX", rttrtp), 3,
                           "Typ"), ("rtt_refno", "", 0, "Reference",
                                    "Y"), ("rtt_tramt", "", 0, "     Amount"),
               ("rtt_taxamt", "", 0, " VAT-Amount"), ("rtt_desc", "", 0,
                                                      "Details"))
        whr = [("rtt_cono", "=", self.opts["conum"]),
               ("rtt_code", "=", self.code), ("rtt_acno", "=", self.acno)]
        if w:
            whr.append(("rtt_cnum", "=", w))
        odr = "rtt_trdt, rtt_type"
        state = self.df.disableButtonsTags()
        SRec(self.opts["mf"],
             screen=self.df.nb.Page2,
             title=tit,
             tables=tab,
             cols=col,
             where=whr,
             order=odr)
        self.df.enableButtonsTags(state=state)
        self.doTrans1()

    def doNotes(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        NotesCreate(self.opts["mf"], self.opts["conum"], self.opts["conam"],
                    self.opts["capnm"], "RTL",
                    "%7s%s" % (self.code, self.acno))
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doClear(self):
        self.df.selPage("Premises")
        self.df.focusField("T", 0, 1)

    def doPrint(self):
        mess = "Select the Required Print Option."
        butt = (("Information", "I"), ("Transactions", "T"), ("Both", "B"),
                ("None", "N"))
        self.doPrintOption(
            askChoice(self.opts["mf"].body, "Print Options", mess, butt=butt))
        if self.df.topq[self.df.pag]:
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doPrintOption(self, opt):
        if opt == "N":
            return
        self.head = "%03u %-101s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        if opt != "T":
            self.pageHeading()
            self.printInfo()
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        if opt == "I":
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=["N", "V", "view"])
        elif opt == "B":
            if not self.trn:
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=["N", "V", "view"])
            else:
                self.pageHeading()
                self.pageHeadingTrans()
                self.printTrans()
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=["N", "V", "view"])
        elif opt == "T":
            if self.trn:
                self.pageHeading()
                self.pageHeadingTrans()
                self.printTrans()
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=["N", "V", "view"])

    def printInfo(self):
        for x in range(0, len(self.df.topf[0])):
            self.fpdf.drawText(
                "%-26s%-25s %s" %
                ("", self.df.topf[0][x][3], self.df.t_disp[0][0][x]))
        self.fpdf.drawText()
        for x in range(0, len(self.df.topf[1])):
            self.fpdf.drawText(
                "%-26s%-25s %s" %
                ("", self.df.topf[1][x][3], self.df.t_disp[1][0][x]))
        self.fpdf.drawText()
        for x in range(0, len(self.df.topf[2])):
            self.fpdf.drawText(
                "%-26s%-25s %s" %
                ("", self.df.topf[2][x][3], self.df.t_disp[2][0][x]))
        self.fpdf.drawText()
        self.pglin += 3 + len(self.df.topf[3])
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("%26s%-34s %13s" % ("", "Details", "Amount "))
        self.fpdf.drawText("%26s%s" % ("", self.fpdf.suc * 48))
        self.fpdf.setFont()
        desc = ("Rentals ", "Receipts", "Payments", "Journals", "Balance ")
        for n, d in enumerate(self.df.c_disp[3]):
            self.fpdf.drawText("%26s%-34s %13s" % ("", desc[n], d[0]))

    def printTrans(self):
        col = self.sql.rtltrn_col
        bal = 0
        for ct in self.trn:
            trdt = CCD(ct[col.index("rtt_trdt")], "D1", 10)
            refno = CCD(ct[col.index("rtt_refno")], "Na", 9)
            trtp = CCD(ct[col.index("rtt_type")], "UI", 1)
            batch = CCD(ct[col.index("rtt_batch")], "Na", 7)
            desc = CCD(ct[col.index("rtt_desc")], "NA", 30)
            tramt = ct[col.index("rtt_tramt")]
            if tramt < 0:
                debit = CCD(0, "SD", 13.2)
                credit = CCD(tramt, "SD", 13.2)
            else:
                debit = CCD(tramt, "SD", 13.2)
                credit = CCD(0, "SD", 13.2)
            bal = float(ASD(bal) + ASD(tramt))
            tot = CCD(bal, "SD", 13.2)
            taxamt = CCD(ct[col.index("rtt_taxamt")], "SD", 13.2)
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
                self.pageHeadingTrans()
            self.fpdf.drawText(
                "%s %s %s %s %s %s %s %s %s" %
                (trdt.disp, refno.disp, rttrtp[(trtp.work - 1)][0], batch.disp,
                 desc.disp, debit.disp, credit.disp, tot.disp, taxamt.disp))
            self.pglin += 1

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-34s %-10s" % \
            ("Rentals Ledger Interrogation as at", self.sysdtd))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 6

    def pageHeadingTrans(self):
        self.fpdf.drawText(
            "%-16s %s %s %s %s %s %s %s %s" %
            ("", self.df.topf[0][0][3], self.df.t_disp[0][0][0], "",
             self.df.topf[0][1][3], self.df.t_disp[0][0][1], "",
             self.df.topf[0][2][3], self.df.t_disp[0][0][2]))
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("%-10s %-9s %-3s %-7s %-30s %-13s %-13s %-13s" % \
            ("   Date", "Reference", "Typ", "Batch", "Remarks",
            "       Debit", "      Credit",  "     Balance"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 17
0
class ml3060(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            if "args" in self.opts:
                self.reptyp = "A"
                if self.opts["args"][0] > self.opts["args"][1]:
                    self.start = CCD(self.opts["args"][1], "D1", 10)
                else:
                    self.start = CCD(self.opts["args"][0], "D1", 10)
                self.dte = int("%08i000000" % self.start.work)
                self.end = CCD(self.opts["args"][1], "D1", 10)
                self.chgtyp = "A"
                self.cat = ""
                self.cod = 0
                self.processRecords()
            else:
                self.mainProcess()
                if "wait" in self.opts:
                    self.df.mstFrame.wait_window()
                else:
                    self.opts["mf"].startLoop()

    def setVariables(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Members Category Changes (%s)" % self.__class__.__name__)
        self.sql = Sql(self.opts["mf"].dbm,
                       ["chglog", "memcat", "memctc", "memmst"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        memctl = gc.getCtl("memctl", self.opts["conum"])
        if not memctl:
            return
        self.fromad = memctl["mcm_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i)" % \
            (t[0], t[1], t[2], t[3], t[4])
        self.head = "%03u %-30s" % (self.opts["conum"], self.opts["conam"])
        self.colsh = [
            "Mem-No", "Titles", "Inits", "Surname", "Actions", "Category",
            "Action-Dte", "Operator", "Start-Date", " End-Date", "Last-Date"
        ]
        self.forms = [("UI", 6), ("NA", 6), ("NA", 5), ("NA", 30), ("UA", 7),
                      ("NA", 30), ("D1", 10), ("NA", 20), ("d1", 10),
                      ("d1", 10), ("d1", 10)]
        self.ctyp = (("All", "A"), ("New", "N"), ("Updated", "U"), ("Deleted",
                                                                    "D"))
        self.catg = (("All", "X"), ("Fees", "A"), ("Main", "B"),
                     ("Sports", "C"), ("Debentures", "D"))
        return True

    def mainProcess(self):
        cod = {
            "stype":
            "R",
            "tables": ("memctc", ),
            "cols": (("mcc_code", "", 0, "Cd"), ("mcc_desc", "", 0,
                                                 "Description", "Y")),
            "where": [("mcc_cono", "=", self.opts["conum"])],
            "whera": [["T", "mcc_type", 3]],
            "order":
            "mcc_code",
            "size": (400, 600)
        }
        r1s = (("Actual", "A"), ("Pending", "P"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Report Type", "", "A", "Y",
                self.doRepTyp, None, None,
                None), (("T", 0, 1, 0), "Id1", 10, "Starting Date", "",
                        self.sysdtw, "Y", self.doStartDate, None, None, None),
               (("T", 0, 2, 0), "ID1", 10, "Ending   Date", "Ending Date",
                self.sysdtw, "Y", self.doEndDate, None, None, ("notzero", )),
               (("T", 0, 3, 0), ("IRB", self.ctyp), 0, "Change Type", "", "A",
                "Y", self.doChgTyp, None, None,
                None), (("T", 0, 4, 0), ("IRB", self.catg), 0, "Category", "",
                        "X", "Y", self.doCat, None, None,
                        None), (("T", 0, 5, 0), "IUI", 2, "Code", "", 0, "Y",
                                self.doCod, cod, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "N"))

    def doRepTyp(self, frt, pag, r, c, p, i, w):
        self.reptyp = w

    def doStartDate(self, frt, pag, r, c, p, i, w):
        self.start = CCD(w, "d1", 10)
        self.dte = int("%08i000000" % self.start.work)
        if self.reptyp == "P":
            self.end = self.start
            self.df.loadEntry(frt, pag, p + 1, data=self.end.work)
            return "sk1"

    def doEndDate(self, frt, pag, r, c, p, i, w):
        if w < self.start.work:
            return "Invalid End Date, Before Start Date"
        self.end = CCD(w, "D1", 10)
        if self.reptyp == "P":
            self.chgtyp = "A"
            self.cat = None
            self.cod = None
            self.df.loadEntry(frt, pag, p + 1, data="A")
            self.df.loadEntry(frt, pag, p + 2, data="X")
            self.df.loadEntry(frt, pag, p + 3, data=0)
            return "sk3"

    def doChgTyp(self, frt, pag, r, c, p, i, w):
        self.chgtyp = w

    def doCat(self, frt, pag, r, c, p, i, w):
        self.cat = w
        if w == "X":
            self.cat = None
            self.cod = None
            self.df.loadEntry(frt, pag, p + 1, data=0)
            return "sk1"
        self.cat = w

    def doCod(self, frt, pag, r, c, p, i, w):
        self.cod = w

    def doEnd(self):
        self.df.closeProcess()
        if self.reptyp == "P":
            sp = SplashScreen(self.opts["mf"].body,
                              "Preparing Report ... Please Wait")
            recs = self.sql.getRec("memmst",
                                   cols=["mlm_memno"],
                                   where=[("mlm_cono", "=",
                                           self.opts["conum"]),
                                          ("mlm_state", "=", "A")])
            for rec in recs:
                data = doChkCatChg(self.opts["mf"], self.opts["conum"], rec[0],
                                   self.start.work)
                if data:
                    self.sql.insRec(
                        "chglog",
                        data=[
                            "memcat", "D",
                            "%03i%06i%1s%02i" %
                            (self.opts["conum"], rec[0], "B", data[0]), "",
                            self.dte, "",
                            str(data[1]),
                            str(data[2]), "", 0
                        ])
                    self.sql.insRec(
                        "chglog",
                        data=[
                            "memcat", "N",
                            "%03i%06i%1s%02i" %
                            (self.opts["conum"], rec[0], "B", data[7]), "",
                            self.dte, "",
                            str(self.start.work),
                            str(0), "", 0
                        ])
            sp.closeSplash()
        self.processRecords()
        self.closeProcess()

    def processRecords(self):
        if "args" in self.opts:
            self.repprt = ["N", "V", "view"]
            self.repeml = None
        else:
            self.repprt = self.df.repprt
            self.repeml = self.df.repeml
        whr = [("chg_tab", "=", "memcat")]
        if self.reptyp == "P":
            whr.append(("chg_dte", "=", self.dte))
        else:
            end = str((self.end.work * 1000000) + 999999)
            if self.start.work:
                start = str(self.start.work * 1000000)
                whr.append(("chg_dte", "between", start, end))
            else:
                whr.append(("chg_dte", "<=", end))
        if self.chgtyp != "A":
            whr.append(("chg_act", "=", self.chgtyp))
        if self.cat:
            key = "%03i______%1s" % (self.opts["conum"], self.cat)
            if self.cod:
                key = "%s%02i" % (key, self.cod)
            else:
                key = "%s__" % key
            whr.append(("chg_key", "like", key))
        odr = "chg_key, chg_seq"
        chg = self.sql.getRec("chglog", where=whr, order=odr)
        if self.reptyp == "P":
            self.opts["mf"].dbm.rollbackDbase()
        if not chg:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Available Records")
        elif self.repprt[2] == "export":
            self.exportReport(chg)
        else:
            self.printReport(chg)

    def exportReport(self, chg):
        p = ProgressBar(self.opts["mf"].body, mxs=len(chg), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [self.head + " %s" % self.sysdttm]
        self.expheads.append("Members Category Changes between %s and %s" %
                             (self.start.disp, self.end.disp))
        self.expheads.append(self.getOptions())
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        lmemno = 0
        for num, dat in enumerate(chg):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            if vals[0].work == lmemno:
                self.expdatas.append([
                    "BODY",
                    [
                        "", "", "", "", vals[4], vals[5].work, vals[6].work,
                        vals[7].work, vals[8].work, vals[9].work, vals[10].work
                    ]
                ])
            else:
                self.expdatas.append([
                    "BODY",
                    [
                        vals[0].work, vals[1].work, vals[2].work, vals[3].work,
                        vals[4], vals[5].work, vals[6].work, vals[7].work,
                        vals[8].work, vals[9].work, vals[10].work
                    ]
                ])
            lmemno = vals[0].work
        p.closeProgress()
        doWriteExport(xtype=self.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, chg):
        p = ProgressBar(self.opts["mf"].body, mxs=len(chg), esc=True)
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=154)
        self.pgnum = 0
        self.pglin = 999
        for num, dat in enumerate(chg):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
                lmemno = 0
            if vals[0].work == lmemno:
                self.fpdf.drawText("%6s %6s %5s %30s %s %s %s %s %s %s %s" % \
                    ("", "", "", "", vals[4], vals[5].disp, vals[6].disp,
                    vals[7].disp, vals[8].disp, vals[9].disp, vals[10].disp))
            else:
                self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s %s" % \
                    (vals[0].disp, vals[1].disp, vals[2].disp, vals[3].disp,
                    vals[4], vals[5].disp, vals[6].disp, vals[7].disp,
                    vals[8].disp, vals[9].disp, vals[10].disp))
            lmemno = vals[0].work
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.repprt,
                      fromad=self.fromad,
                      repeml=self.repeml)

    def getValues(self, data):
        key = data[self.sql.chglog_col.index("chg_key")]
        cono = CCD(key[:3], "UI", 3)
        if cono.work != self.opts["conum"]:
            return
        memno = CCD(key[3:9], "UI", 6)
        ctype = CCD(key[9:10], "UA", 1)
        code = CCD(key[10:12], "UI", 2)
        last = CCD(0, "d1", 10)
        if data[self.sql.chglog_col.index("chg_act")] == "D":
            act = "Removed"
        elif data[self.sql.chglog_col.index("chg_act")] == "N":
            act = "Added  "
            last = self.sql.getRec("memcat",
                                   cols=["mlc_last"],
                                   where=[("mlc_cono", "=",
                                           self.opts["conum"]),
                                          ("mlc_memno", "=", memno.work),
                                          ("mlc_type", "=", ctype.work),
                                          ("mlc_code", "=", code.work)],
                                   limit=1)
            if not last:
                last = CCD("Removed?", "NA", 10)
            else:
                last = CCD(last[0], "d1", 10)
        elif data[self.sql.chglog_col.index("chg_act")] == "U":
            act = "Changed"
        else:
            act = "Unknown"
        dte = int(data[self.sql.chglog_col.index("chg_dte")])
        dte = CCD(int(dte / 1000000), "D1", 10)
        usr = CCD(data[self.sql.chglog_col.index("chg_usr")], "NA", 20)
        old = CCD(data[self.sql.chglog_col.index("chg_old")], "d1", 10)
        new = CCD(data[self.sql.chglog_col.index("chg_new")], "d1", 10)
        mst = self.sql.getRec("memmst",
                              where=[("mlm_cono", "=", self.opts["conum"]),
                                     ("mlm_memno", "=", memno.work)],
                              limit=1)
        if not mst:
            return
        tit = CCD(mst[self.sql.memmst_col.index("mlm_title")], "UA", 6)
        ini = CCD(mst[self.sql.memmst_col.index("mlm_initial")], "UA", 5)
        sur = CCD(mst[self.sql.memmst_col.index("mlm_surname")], "NA", 30)
        cat = self.sql.getRec("memctc",
                              where=[("mcc_cono", "=", self.opts["conum"]),
                                     ("mcc_type", "=", ctype.work),
                                     ("mcc_code", "=", code.work)],
                              limit=1)
        if not cat:
            return
        des = CCD(cat[self.sql.memctc_col.index("mcc_desc")], "NA", 30)
        return (memno, tit, ini, sur, act, des, dte, usr, old, new, last)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.pgnum += 1
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-32s %10s %3s %10s %89s %5s" % \
            ("Members Category Changes between", self.start.disp, "and",
            self.end.disp, "Page", self.pgnum))
        self.fpdf.drawText()
        self.fpdf.drawText(self.getOptions())
        self.fpdf.drawText()
        self.fpdf.drawText("%6s %-6s %-5s %-30s %1s %-30s %10s %-20s %10s "\
            "%10s %10s" % ("Mem-No", "Titles", "Inits", "Surname", "Actions",
            "Category", "Action-Dte", "Operator", "Start-Date", " End-Date",
            "Last-Date"))
        self.fpdf.underLine(txt="X" * 154)
        self.fpdf.setFont()
        self.pglin = 8

    def getOptions(self):
        if self.reptyp == "A":
            mess = "Options: Actual"
        else:
            mess = "Options: Pending"
        for x in self.ctyp:
            if self.chgtyp == x[1]:
                mess = mess + ", Type %s" % x[0]
                break
        for x in self.catg:
            if self.cat == x[1]:
                mess = mess + ", Category %s" % x[0]
        if self.cod:
            mess = mess + ", Code %s" % self.cod
        return mess

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 18
0
class sl4010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["ctlynd", "wagmst", "waglmf",
            "wagltf"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        # Get the current period starting date
        period = self.sql.getRec("ctlynd", cols=["max(cye_period)"],
            where=[("cye_cono", "=", self.opts["conum"])], limit=1)[0]
        self.opts["period"] = getPeriods(self.opts["mf"], self.opts["conum"],
            period)[0].work
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
            "Staff Loans Interrogation (%s)" % self.__class__.__name__)
        wgm = {
            "stype": "R",
            "tables": ("waglmf", "wagmst"),
            "cols": (
                ("wlm_empno", "", 0, "EmpNo"),
                ("wgm_sname", "", 0, "Surname", "Y"),
                ("wgm_fname", "", 0, "Names")),
            "where": [
                ("wlm_cono", "=", self.opts["conum"]),
                ("wgm_cono=wlm_cono",),
                ("wgm_empno=wlm_empno",)],
            "group": "wlm_empno"}
        lnm = {
            "stype": "R",
            "tables": ("waglmf",),
            "cols": (
                ("wlm_empno", "", 0, "EmpNo"),
                ("wlm_loan", "", 0, "Ln"),
                ("wlm_desc", "", 0, "Description", "Y")),
            "where": [("wlm_cono", "=", self.opts["conum"])],
            "whera": [["T", "wlm_empno", 0, 0]],
            "order": "wlm_empno, wlm_loan",
            "index": 1}
        r1s = (("Yes", "Y"), ("No", "N"))
        tag = (
            ("General", self.doGeneral, ("T",0,0), ("T",0,1)),
            ("Trans", self.doTrans1, ("T",0,0), ("T",0,1)))
        fld = (
            (("T",0,0,0),"IUI",5,"Emp-Num","Employee Number",
                "","N",self.doEmp,wgm,None,("notzero",)),
            (("T",0,0,0),"ONA",40,"Name"),
            (("T",0,1,0),"IUI",5,"Loan-Num","Loan Number",
                "","N",self.doLoan,lnm,None,("notzero",)),
            (("T",0,1,0),"ONA",40,"Desc"),
            (("T",1,0,0),"OUI",3,"Deduction Code"),
            (("T",1,1,0),"OUD",6.2,"Interest Percentage"),
            (("T",1,2,0),"OD1",10,"Start Date"),
            (("T",1,3,0),"OSD",13.2,"Deduction Amount"),
            (("T",1,4,0),"OSD",13.2,"Total Advances"),
            (("T",1,5,0),"OSD",13.2,"Total Interest"),
            (("T",1,6,0),"OSD",13.2,"Total Repayments"),
            (("T",1,7,0),"OSD",13.2,"Total Adjustments"),
            (("T",1,8,0),"OSD",13.2,"Balance"),
            (("T",1,9,0),"Od1",10,"Last Interest Raised"),
            (("T",1,10,0),"Od1",10,"Last Payment Received"),
            (("T",2,0,0),("IRB",r1s),0,"History","",
                "Y","Y",self.doTrans2,None,None,None))
        tnd = ((self.doEndTop,"N"), None, None)
        txt = (self.doExit, None, None)
        cnd = (None, None, None)
        cxt = (None, None, None)
        but = (
            ("Clear",None,self.doClear,0,("T",0,0),("T",0,1)),
            ("Print",None,self.doPrint,0,("T",0,0),("T",0,1)),
            ("Quit",None,self.doExit,1,None,None))
        self.df = TartanDialog(self.opts["mf"], title=self.tit, eflds=fld,
            tags=tag, tend=tnd, txit=txt, cend=cnd, cxit=cxt, butt=but)

    def doEmp(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("wagmst", cols=["wgm_sname",
            "wgm_fname"], where=[("wgm_cono", "=", self.opts["conum"]),
            ("wgm_empno", "=", w)], limit=1)
        if not acc:
            return "Invalid Employee Number"
        self.empno = w
        self.name = "%s, %s" % (acc[0], acc[1])
        self.history = "Y"
        self.df.loadEntry("T", pag, p+1, data=self.name)

    def doLoan(self, frt, pag, r, c, p, i, w):
        lmc = self.sql.waglmf_col
        rec = self.sql.getRec("waglmf", where=[("wlm_cono", "=",
            self.opts["conum"]), ("wlm_empno", "=", self.empno),
            ("wlm_loan", "=", w)], limit=1)
        if not rec:
            return "Invalid Loan Number"
        self.loan = w
        self.desc = rec[lmc.index("wlm_desc")]
        self.df.loadEntry("T", pag, p+1, data=self.desc)
        self.df.loadEntry("T", 1, 0, data=rec[lmc.index("wlm_code")])
        self.df.loadEntry("T", 1, 1, data=rec[lmc.index("wlm_rate")])
        self.df.loadEntry("T", 1, 2, data=rec[lmc.index("wlm_start")])
        self.df.loadEntry("T", 1, 3, data=rec[lmc.index("wlm_repay")])
        # Raise Interest
        LoanInterest("S", self.opts["mf"].dbm, rec, update="Y",
            curdt=int(self.sysdtw / 100), tdate=self.sysdtw, refno="Pending")
        # Get Balances
        self.lon = 0.0
        self.imt = 0.0
        self.pay = 0.0
        self.adj = 0.0
        self.bal = 0.0
        self.idt = 0
        self.pdt = 0
        whr = [
            ("wlt_cono", "=", self.opts["conum"]),
            ("wlt_empno", "=", self.empno),
            ("wlt_loan", "=", self.loan)]
        odr = "wlt_trdt, wlt_type"
        self.wlt = self.sql.getRec("wagltf", where=whr, order=odr)
        if self.wlt:
            col = self.sql.wagltf_col
            for rec in self.wlt:
                dat = CCD(rec[col.index("wlt_trdt")], "d1", 10)
                typ = CCD(rec[col.index("wlt_type")], "UI",  2)
                amt = CCD(rec[col.index("wlt_amt")], "SD",13.2)
                self.bal = float(ASD(self.bal) + ASD(amt.work))
                if typ.work == 1:
                    self.idt = dat.work
                    self.imt = float(ASD(self.imt) + ASD(amt.work))
                elif typ.work in (2, 3):
                    self.lon = float(ASD(self.lon) + ASD(amt.work))
                elif typ.work == 4:
                    self.pay = float(ASD(self.pay) + ASD(amt.work))
                    self.pdt = dat.work
                elif typ.work == 5:
                    self.adj = float(ASD(self.adj) + ASD(amt.work))
        # Load Balances
        self.df.loadEntry("T", 1, 4, data=self.lon)
        self.df.loadEntry("T", 1, 5, data=self.imt)
        self.df.loadEntry("T", 1, 6, data=self.pay)
        self.df.loadEntry("T", 1, 7, data=self.adj)
        self.df.loadEntry("T", 1, 8, data=self.bal)
        self.df.loadEntry("T", 1, 9, data=self.idt)
        self.df.loadEntry("T", 1, 10, data=self.pdt)
        self.opts["mf"].updateStatus("")

    def doHist(self, frt, pag, r, c, p, i, w):
        self.history = w

    def doEndTop(self):
        self.df.last[0] = [0, 0]
        self.df.setWidget(self.df.topEntry[0][0], state="disabled")

    def loadBalances(self):
        whr = [
            ("wlt_cono", "=", self.opts["conum"]),
            ("wlt_empno", "=", self.empno),
            ("wlt_loan", "=", self.loan)]
        odr = "wlt_trdt, wlt_type"
        self.wlt = self.sql.getRec("wagltf", where=whr, order=odr)
        if self.wlt:
            for rec in self.wlt:
                dat = CCD(rec[self.sql.wagltf_col.index("wlt_trdt")], "d1", 10)
                typ = CCD(rec[self.sql.wagltf_col.index("wlt_type")], "UI",  2)
                amt = CCD(rec[self.sql.wagltf_col.index("wlt_amt")], "SD",13.2)
                self.bal = float(ASD(self.bal) + ASD(amt.work))
                self.cap = float(ASD(self.cap) + ASD(amt.work))
                if typ.work == 1:
                    if dat.work >= self.opts["period"] and \
                            dat.work >= self.df.t_work[1][0][3]:
                        self.cap = float(ASD(self.cap) - ASD(amt.work))
                        self.due = float(ASD(self.due) + ASD(amt.work))
                    self.imt = float(ASD(self.imt) + ASD(amt.work))
                    self.idt = dat.work
                elif typ.work in (2, 3):
                    self.lon = float(ASD(self.lon) + ASD(amt.work))
                elif typ.work == 4:
                    self.pay = float(ASD(self.pay) + ASD(amt.work))
                    self.pdt = dat.work
                elif typ.work == 5:
                    self.adj = float(ASD(self.adj) + ASD(amt.work))

    def doGeneral(self):
        self.opts["mf"].updateStatus("")

    def doTrans1(self):
        self.df.focusField("T", 2, 1)

    def doTrans2(self, frt, pag, r, c, p, i, w):
        self.history = w
        tit = "Transactions for Loan: %s %s - %s" % \
            (self.empno, self.name, self.desc)
        tab = ["wagltf"]
        col = (("wlt_trdt", "", 0, "   Date"),
                ("wlt_batch", "", 0, "Batch"),
                ("wlt_type", ("XX", sltrtp), 3, "Typ"),
                ("wlt_ref", "", 0, "Reference", "Y"),
                ("wlt_per", "", 0, " Int-%"),
                ("wlt_amt", "", 0, "      Amount"),
                ("wlt_ded", "", 0, "   Deduction"),
                ("wlt_desc", "", 0, "Remarks"))
        whr = [
            ("wlt_cono", "=", self.opts["conum"]),
            ("wlt_empno", "=", self.empno),
            ("wlt_loan", "=", self.loan)]
        if self.history == "N":
            whr.append(("wlt_curdt", ">=", int(self.opts["period"] / 100)))
        odr = "wlt_trdt, wlt_type, wlt_ref"
        state = self.df.disableButtonsTags()
        SRec(self.opts["mf"], screen=self.df.nb.Page2, title=tit, tables=tab,
            cols=col, where=whr, order=odr)
        self.df.enableButtonsTags(state=state)
        self.df.focusField("T", 2, 1)

    def doClear(self):
        self.df.selPage("General")
        self.df.focusField("T", 0, 1)

    def doPrint(self):
        mess = "Select the Required Print Option."
        butt = (
            ("Information", "I"),
            ("Transactions", "T"),
            ("Both", "B"),
            ("None", "N"))
        self.doPrintOption(askChoice(self.opts["mf"].body, "Print Options",
            mess, butt=butt))
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doPrintOption(self, opt):
        print(opt)
        if opt == "N":
            return
        self.head = "%03u %-93s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        if opt != "T":
            self.pageHeading()
            self.printInfo()
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
            self.__class__.__name__, self.opts["conum"], ext="pdf")
        if opt == "I":
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                pdfnam=pdfnam, header=self.tit, repprt=["N", "V", "view"])
        elif opt == "B":
            if not self.wlt:
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                    pdfnam=pdfnam, header=self.tit, repprt=["N", "V", "view"])
            else:
                self.acctot = 0.0
                self.pageHeading()
                self.pageHeadingTrans()
                self.printTrans()
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                    pdfnam=pdfnam, header=self.tit, repprt=["N", "V", "view"])
        elif opt == "T":
            if self.wlt:
                self.acctot = 0.0
                self.pageHeading()
                self.pageHeadingTrans()
                self.printTrans()
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                    pdfnam=pdfnam, header=self.tit, repprt=["N", "V", "view"])

    def printInfo(self):
        self.fpdf.drawText("%-5s %-20s %-25s %s" % ("", "",
                self.df.topf[0][0][3], self.df.t_disp[0][0][0]))
        self.fpdf.drawText("%-5s %-20s %-25s %s" % ("", "",
                self.df.topf[0][1][3], self.df.t_disp[0][0][1]))
        self.fpdf.drawText("%-5s %-20s %-25s %s" % ("", "",
                self.df.topf[0][2][3], self.df.t_disp[0][0][2]))
        self.fpdf.drawText()
        for x in range(0, len(self.df.topf[1])):
            self.fpdf.drawText("%-5s %-20s %-25s %s" % ("", "",
                self.df.topf[1][x][3], self.df.t_disp[1][0][x]))
        self.fpdf.drawText()

    def printTrans(self):
        whr = [
            ("wlt_cono", "=", self.opts["conum"]),
            ("wlt_empno", "=", self.empno),
            ("wlt_loan", "=", self.loan)]
        odr = "wlt_trdt, wlt_type"
        if self.history == "N":
            whr.append(("wlt_curdt", ">=", int(self.opts["period"] / 100)))
        recs = self.sql.getRec("wagltf", where=whr, order=odr)
        for rec in recs:
            trd = CCD(rec[self.sql.wagltf_col.index("wlt_trdt")], "D1", 10)
            typ = CCD(rec[self.sql.wagltf_col.index("wlt_type")], "UI", 1)
            ref = CCD(rec[self.sql.wagltf_col.index("wlt_ref")], "Na", 9)
            bat = CCD(rec[self.sql.wagltf_col.index("wlt_batch")], "Na", 7)
            rte = CCD(rec[self.sql.wagltf_col.index("wlt_per")], "UD", 6.2)
            amt = CCD(rec[self.sql.wagltf_col.index("wlt_amt")], "SD", 13.2)
            ded = CCD(rec[self.sql.wagltf_col.index("wlt_ded")], "SD", 13.2)
            det = CCD(rec[self.sql.wagltf_col.index("wlt_desc")], "NA", 30)
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
                self.pageHeadingTrans()
            self.acctot = float(ASD(self.acctot) + ASD(amt.work))
            self.fpdf.drawText("%s %s %s %s %s %s %s %s" % (trd.disp,
                sltrtp[(typ.work - 1)][0], ref.disp, bat.disp,
                rte.disp, amt.disp, ded.disp, det.disp))
            self.pglin += 1
        self.fpdf.underLine(txt=self.head)
        b = CCD(self.acctot, "SD", 13.2)
        self.fpdf.drawText("%-39s %13s %13s %-30s" % \
            ("", b.disp, "", "Closing Balance"))

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("Staff Loans Interrogation as at %s" % self.sysdtd)
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 3

    def pageHeadingTrans(self):
        self.fpdf.setFont(style="B")
        text = "%-8s %5s %-4s %s" % (self.df.topf[0][0][3],
            self.df.t_disp[0][0][0], self.df.topf[0][1][3],
            self.df.t_disp[0][0][1])
        self.fpdf.drawText(text)
        text = "%-8s %5s %-4s %s" % (self.df.topf[0][2][3],
            self.df.t_disp[0][0][2], self.df.topf[0][3][3],
            self.df.t_disp[0][0][3])
        self.fpdf.drawText(text)
        self.fpdf.drawText()
        self.fpdf.drawText("%-10s %-3s %-9s %-7s %6s %12s  %12s  %-30s" % \
            ("   Date", "Typ", "Reference", "Batch", "Int%",
            "    Amount", "  Deduction", "Remarks"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 7
        b = CCD(self.acctot, "SD", 13.2)
        if self.acctot != 0:
            self.fpdf.drawText("%-39s %13s %13s %-30s" % \
                ("", b.disp, "", "Brought Forward"))
            self.pglin += 1

    def doExit(self):
        try:
            self.opts["mf"].dbm.rollbackDbase()
        except:
            pass
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 19
0
class si3040(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["strgrp", "strloc", "strmf1"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        drsctl = gc.getCtl("drsctl", self.opts["conum"])
        if not drsctl:
            self.chnstr = "N"
        else:
            self.chnstr = drsctl["ctd_chain"]
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        slsctl = gc.getCtl("slsctl", self.opts["conum"])
        if not slsctl:
            return
        self.fromad = slsctl["ctv_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.forms = [("UA", 3), ("NA", 20), ("NA", 30),
                      ("NA", 10)] + [("SI", 10)] * 12
        self.stots = [0] * 12
        self.gtots = [0] * 12
        self.mchart = []
        self.tipe = None
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Product Sales History (%s)" % self.__class__.__name__)
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        chm = {
            "stype": "R",
            "tables": ("drschn", ),
            "cols":
            (("chm_chain", "", 0, "Chn"), ("chm_name", "", 0, "Name", "Y")),
            "where": (("chm_cono", "=", self.opts["conum"]), )
        }
        r1s = (("Quantity", "Q"), ("Value", "V"), ("Profit", "P"))
        r2s = (("Yes", "Y"), ("No", "N"))
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            self.accs = self.opts["args"]["work"][1]
            view = None
            mail = None
        else:
            var = ["", "V", "", "", 0, "Y"]
            self.accs = []
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), "ID2", 7, "Cut-Off Period", "",
                int(self.sysdtw / 100), "Y", self.doCut, None, None,
                ("efld", )), (("T", 0, 1, 0), ("IRB", r1s), 0, "Type", "",
                              var[1], "N", self.doType, None, None, None),
               (("T", 0, 2, 0), "IUA", 1, "Location", "", var[2], "N",
                self.doLoc, loc, None,
                ("efld", )), (("T", 0, 3, 0), "IUA", 3, "Product Group", "",
                              var[3], "N", self.doGroup, grp, None, None),
               (("T", 0, 4, 0), "IUI", 3, "Chain Store", "", var[4], "N",
                self.doDrsChn, chm, None,
                None), (("T", 0, 5, 0), ("IRB", r2s), 0, "All Accounts", "",
                        var[5], "N", self.doDrsAcc, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doCut(self, frt, pag, r, c, p, i, w):
        self.coffw = w
        self.coffd = self.df.t_disp[pag][r][p]

    def doType(self, frt, pag, r, c, p, i, w):
        self.rtype = w
        if self.locs == "N":
            self.loc = ""
            self.locd = "ALL"
            return "sk1"

    def doLoc(self, frt, pag, r, c, p, i, w):
        if not w:
            self.locd = "ALL"
        else:
            acc = self.sql.getRec("strloc",
                                  cols=["srl_desc"],
                                  where=[("srl_cono", "=", self.opts["conum"]),
                                         ("srl_loc", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Location"
            self.locd = "%s %s" % (w, acc[0])
        self.loc = w

    def doGroup(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.getGroup(w)
            if not acc:
                return "Invalid Group"
        self.grp = w
        if self.chnstr == "N":
            self.chain = ""
            self.df.loadEntry(frt, pag, p + 1, data="")
            return "sk1"

    def doDrsChn(self, frt, pag, r, c, p, i, w):
        self.chain = w

    def doDrsAcc(self, frt, pag, r, c, p, i, w):
        self.acno = []
        if w == "Y":
            return
        whr = [("drm_cono", "=", self.opts["conum"])]
        if self.chain:
            whr.append(("drm_chain", "=", self.chain))
        acc = getSingleRecords(self.opts["mf"],
                               "drsmst", ("drm_acno", "drm_name"),
                               where=whr,
                               order="drm_chain, drm_acno",
                               items=[0, self.accs])
        for a in acc:
            self.acno.append(a[2])

    def doEnd(self):
        self.df.closeProcess()
        if not self.grp:
            sgrp = ""
            egrp = "zzz"
        else:
            sgrp = egrp = self.grp
        recs = self.sql.getRec(
            "strmf1",
            cols=["st1_group", "st1_code", "st1_desc", "st1_uoi"],
            where=[("st1_cono", "=", self.opts["conum"]),
                   ("st1_group", ">=", sgrp), ("st1_group", "<=", egrp)],
            order="st1_group, st1_code")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Records Selected")
        else:
            self.start = self.coffw - 99
            if self.start % 100 == 13:
                self.start = self.start + 88
            s = self.start % 100
            self.mthhead = ""
            self.colsh = ["Grp", "Stock-Code", "Description", "U.O.I."]
            for _ in range(12):
                if self.mthhead:
                    self.mthhead = "%s%9s " % (self.mthhead, mthnam[s][1])
                else:
                    self.mthhead = "%9s " % mthnam[s][1]
                self.colsh.append(mthnam[s][1])
                s += 1
                if s == 13:
                    s = 1
            if self.df.repprt[2] == "export":
                self.exportReport(recs)
            else:
                self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
            self.t_work.append(self.acno)
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [
            "%03u %-30s %s" %
            (self.opts["conum"], self.opts["conam"], self.sysdttm)
        ]
        self.expheads.append("Stores Sales History for the 12 Month Period "\
            "to %s" % self.coffd)
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            cod, dsc, uoi, amt, purchd, purchw = vals
            line = ["BODY", [self.grp.work, cod.work, dsc.work, uoi.work]]
            line[1].extend(purchw)
            self.expdatas.append(line)
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-182s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        self.lstgrp = ""
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            cod, dsc, uoi, amt, purchd, purchw = vals
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText(
                "%s %s %s %s %s" %
                (self.grp.disp, cod.disp, dsc.disp, uoi.disp, purchd))
            self.pglin += 1
            self.lstgrp = self.grp.work
        p.closeProgress()
        if not self.fpdf.page or p.quit:
            return
        self.groupTotal()
        self.grandTotal()
        if "args" in self.opts and "noprint" in self.opts["args"]:
            return
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header=self.tit,
                  repprt=self.df.repprt,
                  fromad=self.fromad,
                  repeml=self.df.repeml)
        if self.df.repprt[1] == "X" or not self.tipe:
            return
        CreateChart(self.opts["mf"],
                    self.opts["conum"],
                    self.opts["conam"], [self.start, self.coffw],
                    [[self.opts["conam"], "Product Sales History"], self.tipe],
                    None,
                    self.mchart,
                    ylab=self.tipe)

    def getValues(self, data):
        self.grp = CCD(data[0], "UA", 3)
        if self.df.repprt[2] != "export":
            if self.lstgrp and self.lstgrp != self.grp.work:
                self.groupTotal()
        cod = CCD(data[1], "NA", 20)
        dsc = CCD(data[2], "NA", 30)
        uoi = CCD(data[3], "NA", 10)
        bals = Balances(self.opts["mf"],
                        "STR",
                        self.opts["conum"],
                        self.coffw,
                        keys=(self.grp.work, cod.work, self.loc, ("S",
                                                                  self.start)))
        more = []
        if self.chain:
            more.append(("stt_chain", "=", self.chain))
        if self.acno:
            more.append(("stt_acno", "in", tuple(self.acno)))
        this, hist = bals.doStrHist(more=more)
        bals = hist[2]
        purchd = ""
        purchw = []
        tot = 0
        for x in range(11, -1, -1):
            if self.rtype == "Q":
                amt = float(ASD(0) - ASD(bals[x][0]))
            elif self.rtype == "V":
                amt = float(ASD(0) - ASD(bals[x][2]))
            else:
                amt = float(ASD(0) - ASD(bals[x][2]) + ASD(bals[x][1]))
            amt = CCD(round(amt, 0), "SI", 10)
            tot = float(ASD(tot) + ASD(amt.work))
            self.stots[x] = float(ASD(self.stots[x]) + ASD(amt.work))
            self.gtots[x] = float(ASD(self.gtots[x]) + ASD(amt.work))
            purchd = purchd + amt.disp
            purchw.append(amt.work)
        if tot == 0:
            return
        return (cod, dsc, uoi, amt, purchd, purchw)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-47s %-7s" % \
            ("Stores Sales History for the 12 Month Period to", self.coffd))
        self.fpdf.drawText()
        acc = self.getGroup(self.grp.work)
        if acc:
            grpd = acc[0]
        else:
            grpd = "Missing Group Record"
        if self.rtype == "Q":
            self.tipe = "Quantities"
        elif self.rtype == "V":
            self.tipe = "Values"
        else:
            self.tipe = "Profits"
        self.fpdf.drawText("%s %s %s    %s %s    %s" % \
            ("Group:", self.grp.disp, grpd, "Location:", self.locd, self.tipe))
        self.fpdf.drawText()
        self.fpdf.drawText("%-3s %-20s %-30s %-10s %s" % \
            ("Grp", "Stock-Code", "Description", "U.O.I.", self.mthhead))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def getGroup(self, grp):
        acc = self.sql.getRec("strgrp",
                              cols=["gpm_desc"],
                              where=[("gpm_cono", "=", self.opts["conum"]),
                                     ("gpm_group", "=", grp)],
                              limit=1)
        return acc

    def groupTotal(self):
        purchd = ""
        mchart = ["T", "Group %s Totals" % self.lstgrp]
        p = None
        for x in range(11, -1, -1):
            a = CCD(self.stots[x], "SI", 10)
            self.stots[x] = 0
            purchd = purchd + a.disp
            mchart.append(a.work)
            if a.work:
                p = "y"
        if p:
            self.mchart.append(mchart)
            self.fpdf.drawText()
            self.fpdf.drawText("%-24s %-41s %s" % (" ", mchart[1], purchd))
            self.pageHeading()

    def grandTotal(self):
        if self.df.repprt[2] == "export":
            self.expdatas.append(["ULINES"])
            datas = ["TOTAL", ["", "", "Grand Totals", ""]]
            for x in range(11, -1, -1):
                datas[1].append(CCD(self.gtots[x], "SI", 10).work)
            self.expdatas.append(datas)
            self.expdatas.append(["ULINED"])
            return
        purchd = ""
        mchart = ["T", "Grand Totals"]
        for x in range(11, -1, -1):
            a = CCD(self.gtots[x], "SI", 10)
            purchd = purchd + a.disp
            mchart.append(a.work)
        self.mchart.append(mchart)
        self.fpdf.drawText()
        self.fpdf.drawText("%-24s %-41s %s" % (" ", mchart[1], purchd))
        self.fpdf.drawText()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 20
0
class sl3040(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, ["wagmst", "waglmf", "wagltf"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.fromad = wagctl["ctw_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.head = "%03u %-118s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        return True

    def mainProcess(self):
        r1s = (("Yes", "Y"), ("Singles", "S"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "Id1", 10, "Start Date", "", "", "Y",
                self.doFdate, None, None, ("efld", )),
               (("T", 0, 1, 0), "ID1", 10, "Last Date", "", self.sysdtw, "Y",
                self.doLdate, None, None,
                ("efld", )), (("T", 0, 2, 0), ("IRB", r1s), 0, "Whole File",
                              "", "S", "Y", self.doWhole, None, None, None),
               (("T", 0, 3, 0), ("IRB", r2s), 0, "Ignore Paid Ups", "", "Y",
                "Y", self.doPaidup, 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 doFdate(self, frt, pag, r, c, p, i, w):
        self.fdate = w

    def doLdate(self, frt, pag, r, c, p, i, w):
        self.ldate = w
        self.dated = self.df.t_disp[pag][0][p]

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

    def doPaidup(self, frt, pag, r, c, p, i, w):
        self.paidup = w

    def doEnd(self):
        self.df.closeProcess()
        if self.whole == "S":
            col = [
                "wlm_empno", "wgm_sname", "wgm_fname", "wlm_loan", "wlm_desc"
            ]
            whr = [("wlm_cono", "=", self.opts["conum"]),
                   ("wgm_cono=wlm_cono", ), ("wgm_empno=wlm_empno", )]
            dic = {}
            dic["wlm_empno"] = self.sql.waglmf_dic["wlm_empno"]
            dic["wlm_loan"] = self.sql.waglmf_dic["wlm_loan"]
            dic["wlm_desc"] = self.sql.waglmf_dic["wlm_desc"]
            dic["wgm_sname"] = self.sql.wagmst_dic["wgm_sname"]
            dic["wgm_fname"] = self.sql.wagmst_dic["wgm_fname"]
            dat = self.sql.getRec(tables=["waglmf", "wagmst"],
                                  cols=col,
                                  where=whr,
                                  order="wlm_empno, wlm_loan")
            get = getSingleRecords(self.opts["mf"],
                                   "waglmf",
                                   col,
                                   where=dat,
                                   ttype="D",
                                   dic=dic)
            if get:
                acc = []
                for g in get:
                    acc.append(g[0])
                whr = [("wlm_cono", "=", self.opts["conum"]),
                       ("wlm_empno", "in", acc)]
                odr = "wlm_empno, wlm_loan"
                recs = self.sql.getRec("waglmf", where=whr, order=odr)
            else:
                recs = None
        else:
            whr = [("wlm_cono", "=", self.opts["conum"])]
            odr = "wlm_empno, wlm_loan"
            recs = self.sql.getRec("waglmf", where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Error", "No Accounts Selected")
        else:
            p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
            for num, emp in enumerate(recs):
                p.displayProgress(num)
                if p.quit:
                    break
                self.doProcess(emp)
            p.closeProgress()
            if self.fpdf.page and not p.quit and self.df.repeml[1] == "N":
                self.doPrint()
        self.opts["mf"].closeLoop()

    def doProcess(self, emp):
        self.totbal = 0
        wlc = self.sql.waglmf_col
        self.emp = CCD(emp[wlc.index("wlm_empno")], "UI", 5)
        whr = [("wgm_cono", "=", self.opts["conum"]),
               ("wgm_empno", "=", self.emp.work)]
        col = ("wgm_sname", "wgm_fname", "wgm_emadd")
        mst = self.sql.getRec("wagmst", where=whr, cols=col, limit=1)
        self.nam = CCD(mst[0] + ", " + mst[1], "NA", 60)
        self.lon = CCD(emp[wlc.index("wlm_loan")], "UI", 2)
        self.des = CCD(emp[wlc.index("wlm_desc")], "NA", 30)
        whr = [("wlt_cono", "=", self.opts["conum"]),
               ("wlt_empno", "=", self.emp.work),
               ("wlt_loan", "=", self.lon.work)]
        col = ("wlt_trdt", "wlt_type", "wlt_ref", "wlt_batch", "wlt_per",
               "wlt_amt", "wlt_ded", "wlt_desc")
        odr = "wlt_trdt, wlt_type, wlt_ref"
        wlt = self.sql.getRec("wagltf", where=whr, cols=col, order=odr)
        if wlt:
            self.loadBalances(wlt)
            if self.paidup == "Y" and not self.cbal:
                pass
            else:
                self.printHeader()
                self.printBody(wlt)
                if self.df.repeml[1] == "Y":
                    self.df.repeml[2] = mst[2]
                    self.doPrint()

    def loadBalances(self, wlt):
        self.obal = 0.0
        self.cbal = 0.0
        for x, w in enumerate(wlt):
            dat = CCD(w[0], "d1", 10)
            amt = CCD(w[5], "SD", 13.2)
            if self.fdate and dat.work < self.fdate:
                self.obal = float(ASD(self.obal) + ASD(float(amt.work)))
            if dat.work <= self.ldate:
                self.cbal = float(ASD(self.cbal) + ASD(float(amt.work)))

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-27s %-15s %2s %15s" % \
            ("Staff Loans Statements from", self.df.t_disp[0][0][0],
            "to", self.df.t_disp[0][0][1]))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 4

    def printHeader(self):
        self.pageHeading()
        self.pglin += 1
        self.fpdf.setFont(style="B")
        mess = "%-8s %-5s %-60s %-4s %-2s %-30s" % (
            "Employee", self.emp.disp, self.nam.disp, "Loan", self.lon.disp,
            self.des.disp)
        self.fpdf.drawText(mess)
        self.pglin += 1
        self.fpdf.drawText()
        self.pglin += 1
        mess = "%-10s %-3s %-9s %-7s %-6s %-13s %-13s %-13s %-30s" % \
            ("   Date", "Typ", "Reference", "Batch", "  Int-%",
            "      Amount", "   Deduction", "     Balance", "Remarks")
        self.fpdf.drawText(mess)
        self.pglin += 1
        self.fpdf.underLine(txt=self.head)
        self.pglin += 1
        self.fpdf.setFont()

    def printBody(self, wlt):
        for trn in wlt:
            dat = CCD(trn[0], "d1", 10)
            bat = CCD(trn[3], "Na", 7)
            typ = CCD(trn[1], "UI", 2)
            ref = CCD(trn[2], "Na", 9)
            per = CCD(trn[4], "UD", 7.2)
            amt = CCD(trn[5], "SD", 13.2)
            ded = CCD(trn[6], "SD", 13.2)
            des = CCD(trn[7], "NA", 30)
            if self.fdate and dat.work < self.fdate:
                continue
            if dat.work > self.ldate:
                continue
            if self.pglin > self.fpdf.lpp:
                self.printHeader()
                bal = CCD(self.obal, "SD", 13.2)
                if bal.work:
                    mess = "%-69s%s%-30s" % ("", bal.disp, " Brought Forward")
                    self.fpdf.drawText(mess)
                    self.pglin += 1
            self.obal = float(ASD(self.obal) + ASD(float(amt.work)))
            bal = CCD(self.obal, "SD", 13.2)
            mess = "%s %s %s %s %s %s %s %s %s" % \
                (dat.disp, sltrtp[typ.work - 1][0], ref.disp, bat.disp,
                per.disp, amt.disp, ded.disp, bal.disp, des.disp)
            self.fpdf.drawText(mess)
            self.pglin += 1

    def doPrint(self):
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header="%s Loan Statement at %s" %
                  (self.opts["conam"], self.dated),
                  fromad=self.fromad,
                  repprt=self.df.repprt,
                  repeml=self.df.repeml)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 21
0
class cs3010(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"])
        cshctl = gc.getCtl("cshctl", self.opts["conum"])
        if not cshctl:
            return
        self.glint = cshctl["ccc_glint"]
        self.fromad = cshctl["ccc_emadd"]
        if self.glint == "Y":
            tabs = ["genmst"]
        else:
            tabs = ["cshmst"]
        tabs.extend(["cshcnt", "cshana"])
        self.sql = Sql(self.opts["mf"].dbm,
                       tables=tabs,
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.dte = self.sql.getRec("cshcnt",
                                   cols=["max(cct_date)"],
                                   where=[("cct_cono", "=", self.opts["conum"])
                                          ],
                                   limit=1)[0]
        self.denoms = (("R200", 200), ("R100", 100), ("R50", 50), ("R20", 20),
                       ("R10", 10), ("R5", 5), ("R2", 2), ("R1", 1),
                       ("C50", .5), ("C20", .2), ("C10", .1), ("C5", .05),
                       ("C2", .02), ("C1", .01))
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Cash Reconciliation Report (%s)" %
                    self.__class__.__name__)
        dte = {
            "stype": "R",
            "tables": ("cshcnt", ),
            "cols": (("cct_date", "", 0, "Date"), ),
            "where": [("cct_cono", "=", self.opts["conum"])],
            "group": "cct_date"
        }
        fld = ((("T", 0, 0, 0), "ID1", 10, "From Date", "", self.dte, "Y",
                self.doFrom, dte, None, ("efld", )),
               (("T", 0, 1, 0), "Id1", 10, "To   Date", "To Date", "", "Y",
                self.doTo, dte, None, ("efld", )),
               (("T", 0, 2, 0), "ISD", 13.2, "Float", "Cash Float", 2000, "Y",
                self.doFloat, None, None, ("notzero", )))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doFrom(self, frt, pag, r, c, p, i, w):
        self.fm = w
        self.fmd = self.df.t_disp[pag][r][p]
        self.df.loadEntry(frt, pag, p + 1, data=self.fm)

    def doTo(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.fm
        elif w < self.fm:
            return "Invalid To Date"
        self.to = w
        self.tod = CCD(w, "D1", 10).disp
        csh = self.sql.getRec("cshcnt",
                              where=[("cct_cono", "=", self.opts["conum"]),
                                     ("cct_type", "=", "T"),
                                     ("cct_date", "between", self.fm, self.to)
                                     ])
        if not csh:
            return "ff1|Invalid Cash Capture Dates"

    def doFloat(self, frt, pag, r, c, p, i, w):
        self.float = CCD(w, "SD", 13.2)

    def doEnd(self):
        self.df.closeProcess()
        self.tk1 = self.sql.getRec("cshana",
                                   where=[("can_cono", "=",
                                           self.opts["conum"]),
                                          ("can_type", "=", "P"),
                                          ("can_date", "between", self.fm,
                                           self.to)],
                                   order="can_trdt, can_code")
        self.tk2 = self.sql.getRec("cshana",
                                   where=[("can_cono", "=",
                                           self.opts["conum"]),
                                          ("can_type", "=", "T"),
                                          ("can_date", "between", self.fm,
                                           self.to)],
                                   order="can_trdt, can_code")
        self.head = "%03u %-78s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pglin = 999
        if self.tk1:
            self.pageHeading()
            self.printExpTak(self.tk1, 1)
        if not self.quit:
            if self.tk2:
                self.pageHeading()
                self.printExpTak(self.tk2, 2)
            if not self.quit:
                self.doSummary()
        if not self.quit:
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)
        self.closeProcess()

    def printExpTak(self, recs, ptyp=None):
        self.fpdf.setFont(style="B")
        if ptyp == 1:
            self.fpdf.drawText("Cash Expenditure")
        else:
            self.fpdf.drawText("Cash Takings")
        self.fpdf.drawText()
        self.fpdf.drawText(
            "%-10s %-36s %7s %13s %13s" %
            ("  Date", "Description", "Code", "Vat-Amount ", "Inc-Amount "))
        self.fpdf.underLine(txt=self.head)
        self.pglin += 4
        self.fpdf.setFont()
        tot = 0
        vat = 0
        c1 = self.sql.cshana_col
        pb = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        for num, dat in enumerate(recs):
            pb.displayProgress(num)
            self.quit = pb.quit
            if self.quit:
                break
            trdt = CCD(dat[c1.index("can_trdt")], "D1", 10)
            code = CCD(dat[c1.index("can_code")], "UI", 7)
            desc = CCD(dat[c1.index("can_desc")], "NA", 36)
            inca = CCD(dat[c1.index("can_incamt")], "SD", 13.2)
            vata = CCD(dat[c1.index("can_vatamt")], "SD", 13.2)
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText(
                "%s %s %s %s %s" %
                (trdt.disp, desc.disp, code.disp, vata.disp, inca.disp))
            self.pglin += 1
            tot = float(ASD(tot) + ASD(inca.work))
            vat = float(ASD(vat) + ASD(vata.work))
        pb.closeProgress()
        if self.quit:
            return
        tot = CCD(tot, "SD", 13.2)
        vat = CCD(vat, "SD", 13.2)
        self.fpdf.drawText("%55s %-12s  %-12s" %
                           ("", self.fpdf.suc * 12, self.fpdf.suc * 12))
        if ptyp == 1:
            self.fpdf.drawText("%10s %-36s         %13s %13s" %
                               ("", "Total Expenses", vat.disp, tot.disp))
        else:
            self.fpdf.drawText("%10s %-36s         %13s %13s" %
                               ("", "Total Takings", vat.disp, tot.disp))
        self.fpdf.drawText()

    def doSummary(self):
        self.pageHeading()
        if self.glint == "Y":
            tab = ["cshana", "genmst"]
            col = [
                "can_code", "glm_desc", "sum(can_incamt)", "sum(can_vatamt)"
            ]
            whr = [("can_cono", "=", self.opts["conum"]),
                   ("can_date", "between", self.fm, self.to),
                   ("glm_cono=can_cono", ), ("glm_acno=can_code", )]
            grp = "can_code, glm_desc"
        else:
            tab = ["cshana", "cshmst"]
            col = [
                "can_code", "ccm_desc", "sum(can_incamt)", "sum(can_vatamt)"
            ]
            whr = [("can_cono", "=", self.opts["conum"]),
                   ("can_date", "between", self.fm, self.to),
                   ("ccm_cono=can_cono", ), ("ccm_acno=can_code", )]
            grp = "can_code, ccm_desc"
        w = whr[:]
        w.insert(2, ("can_type", "=", "P"))
        recs = self.sql.getRec(tables=tab,
                               cols=col,
                               where=w,
                               group=grp,
                               order="can_code")
        self.printSummary(recs, 1)
        w = whr[:]
        w.insert(2, ("can_type", "=", "T"))
        recs = self.sql.getRec(tables=tab,
                               cols=col,
                               where=w,
                               group=grp,
                               order="can_code")
        self.printSummary(recs, 2)

    def printSummary(self, recs, ptyp=None):
        self.fpdf.setFont(style="B")
        if ptyp == 1:
            self.fpdf.drawText("Expenses Summary")
        else:
            self.fpdf.drawText("Takings Summary")
        self.fpdf.drawText()
        self.fpdf.drawText("%7s %-61s %13s" %
                           ("Code", "Description", "Amount "))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin += 4
        tot = 0
        vat = 0
        for rec in recs:
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            a = CCD(rec[2], "SD", 13.2)
            b = CCD(rec[3], "SD", 13.2)
            c = CCD(float(ASD(a.work) - ASD(b.work)), "SD", 13.2)
            tot = float(ASD(tot) + ASD(a.work))
            vat = float(ASD(vat) + ASD(b.work))
            self.fpdf.drawText("%7s %-61s %s" % (rec[0], rec[1], c.disp))
            self.pglin += 1
        vat = CCD(vat, "SD", 13.2)
        self.fpdf.drawText("%7s %-61s %s" % ("", "Value Added Tax", vat.disp))
        self.fpdf.drawText("%69s %-12s" % ("", self.fpdf.suc * 12))
        if ptyp == 1:
            self.exp = CCD(tot, "SD", 13.2)
            self.fpdf.drawText("%7s %-61s %s" % ("", "Total", self.exp.disp))
        else:
            self.tak = CCD(tot, "SD", 13.2)
            self.fpdf.drawText("%7s %-61s %s" % ("", "Total", self.tak.disp))
        self.fpdf.drawText()
        self.fpdf.drawText()
        self.pglin += 5
        if ptyp == 1:
            return
        if (self.pglin + 30) > self.fpdf.lpp:
            self.pageHeading()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Cash Summary")
        self.fpdf.drawText()
        self.fpdf.drawText("%-26s %42s %13s" %
                           ("Denomination", "Quantity", "Amount "))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin += 4
        col = [
            "sum(cct_cheq)", "sum(cct_r200)", "sum(cct_r100)", "sum(cct_r50)",
            "sum(cct_r20)", "sum(cct_r10)", "sum(cct_r5)", "sum(cct_r2)",
            "sum(cct_r1)", "sum(cct_c50)", "sum(cct_c20)", "sum(cct_c10)",
            "sum(cct_c5)", "sum(cct_c2)", "sum(cct_c1)"
        ]
        recs = self.sql.getRec("cshcnt",
                               cols=col,
                               where=[("cct_cono", "=", self.opts["conum"]),
                                      ("cct_type", "=", "T"),
                                      ("cct_date", "between", self.fm, self.to)
                                      ],
                               limit=1)
        if recs and recs[0]:
            val = CCD(recs[0], "SD", 13.2)
            csh = val.work
            self.fpdf.drawText("%-26s %42s %s" % ("Cheques", "", val.disp))
            self.pglin += 1
        else:
            csh = 0
        for x in range(1, 15):
            if recs[x]:
                qty = CCD(recs[x], "UI", 5)
                val = CCD(qty.work * self.denoms[x - 1][1], "SD", 13.2)
                csh = float(ASD(csh) + ASD(val.work))
                self.fpdf.drawText("%-26s %42s %s" %
                                   (self.denoms[x - 1][0], qty.disp, val.disp))
                self.pglin += 1
        self.fpdf.drawText("%69s %-12s" % ("", self.fpdf.suc * 12))
        csh = CCD(csh, "SD", 13.2)
        self.fpdf.drawText("%-26s %42s %s" % ("Total", "", csh.disp))
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Cash Reconciliation")
        self.fpdf.setFont()
        self.fpdf.drawText()
        self.fpdf.drawText("%-26s %42s %s" %
                           ("Total Takings", "", self.tak.disp))
        self.fpdf.drawText("%-26s %42s %s" %
                           ("Total Expended", "", self.exp.disp))
        self.fpdf.drawText("%69s %-12s" % ("", self.fpdf.suc * 12))
        dif = CCD(float(ASD(self.tak.work) - ASD(self.exp.work)), "SD", 13.2)
        self.fpdf.drawText("%-26s %42s %s" % ("Cash Expected", "", dif.disp))
        self.fpdf.drawText("%-26s %42s %s" % ("Cash Actual", "", csh.disp))
        self.fpdf.drawText("%69s %-12s" % ("", self.fpdf.suc * 12))
        dif = CCD(float(ASD(dif.work) - ASD(csh.work)), "SD", 13.2)
        if dif.work:
            if dif.work < 0:
                text = "Cash Over"
                dif = CCD(float(ASD(0) - ASD(dif.work)), "SD", 13.2)
            else:
                text = "Cash Under"
            self.fpdf.drawText("%-26s %42s %s" % (text, "", dif.disp))

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-30s %10s to %-35s" % \
            ("Cash Reconciliation for Period", self.fmd, self.tod))
        self.fpdf.drawText()
        self.pglin = 4
        self.fpdf.setFont()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 22
0
class dr3050(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       ["drsact", "drstyp", "drsmst", "drstrn"],
                       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.fromad = drsctl["ctd_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.head = "%03u %-30s" % (self.opts["conum"], self.opts["conam"])
        self.colsh = [
            "Chn", "Acc-Num", "Name", "Cr-Balance", "Tot-Balance", "Current",
            "30-Days", "60-Days", "90-Days", "Over-90-Days"
        ]
        self.forms = [("UI", 3), ("NA", 7), ("NA", 30)] + [("SD", 13.2)] * 7
        self.gtots = [0] * 7
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Debtors Age Analysis (%s)" % self.__class__.__name__)
        dra = {
            "stype":
            "R",
            "tables": ("drsact", ),
            "cols": (("dac_code", "", 0, "Cod"), ("dac_desc", "", 0,
                                                  "Description", "Y"))
        }
        drt = {
            "stype":
            "R",
            "tables": ("drstyp", ),
            "cols": (("dtp_code", "", 0, "Cod"), ("dtp_desc", "", 0,
                                                  "Description", "Y"))
        }
        r1s = (("Agedt", "A"), ("Curdt", "C"))
        r2s = (("Yes", "Y"), ("No", "N"))
        r3s = (("Yes", "Y"), ("No", "N"), ("Only", "O"))
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["A", "", "N", "", "", 0, "Y", "Y"]
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Base", "", var[0], "Y",
                self.doBase, None, None, None),
               (("T", 0, 1, 0), "ID2", 7, "Cut-Off Period", "",
                int(self.sysdtw / 100), "N", self.doCutOff, None, None,
                None), (("T", 0, 2, 0), ("IRB", r2s), 0, "Totals Only", "",
                        var[2], "N", self.doTots, None, None, None),
               (("T", 0, 3, 0), "IUA", 3, "Business Activity", "", var[3], "N",
                self.doDrsAct, dra, None,
                None), (("T", 0, 4, 0), "IUA", 3, "Business Type", "", var[4],
                        "N", self.doDrsTyp, drt, None, None),
               (("T", 0, 5, 0), "IUI", 7, "Lower Balance Limit", "", var[5],
                "N", self.doLimit, None, None, None),
               (("T", 0, 6, 0), ("IRB", r3s), 0, "Include Credit Balances", "",
                var[6], "N", self.doCredit, None, None, None),
               (("T", 0, 7, 0), ("IRB", r2s), 0, "Ignore Zero Balances", "",
                var[7], "N", self.doZero, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doBase(self, frt, pag, r, c, p, i, w):
        self.base = w

    def doCutOff(self, frt, pag, r, c, p, i, w):
        self.cutoff = w
        self.opts["period"] = self.df.t_disp[pag][r][p]

    def doTots(self, frt, pag, r, c, p, i, w):
        self.totsonly = w
        if self.totsonly == "Y":
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                self.df.setWidget(self.df.topEntry[0][8][3][0], state="hide")
                self.df.setWidget(self.df.topEntry[0][8][4][0], state="hide")
            self.drsact = "All"
            self.df.loadEntry(frt, pag, p + 1, data=self.drsact)
            self.drstyp = "All"
            self.df.loadEntry(frt, pag, p + 2, data=self.drstyp)
            self.limit = 0
            self.df.loadEntry(frt, pag, p + 3, data=self.limit)
            self.credit = "Y"
            self.df.loadEntry(frt, pag, p + 4, data=self.credit)
            self.zero = "Y"
            self.df.loadEntry(frt, pag, p + 5, data=self.zero)
            return "sk5"
        elif "args" in self.opts and "noprint" in self.opts["args"]:
            pass
        else:
            self.df.setWidget(self.df.topEntry[0][8][3][0], state="show")
            self.df.setWidget(self.df.topEntry[0][8][4][0], state="show")

    def doDrsAct(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drsact",
                                  where=[("dac_code", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Account Activity"
            self.drsact = w
        else:
            self.drsact = "All"

    def doDrsTyp(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drstyp",
                                  where=[("dtp_code", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Account Activity"
            self.drstyp = w
        else:
            self.drstyp = "All"

    def doLimit(self, frt, pag, r, c, p, i, w):
        self.limit = w
        if self.limit:
            self.credit = "N"
            self.df.loadEntry(frt, pag, p + 1, data=self.limit)
            self.zero = "Y"
            self.df.loadEntry(frt, pag, p + 3, data=self.zero)
            return "sk2"

    def doCredit(self, frt, pag, r, c, p, i, w):
        self.credit = w
        if self.credit == "O":
            self.zero = "Y"
            self.df.loadEntry(frt, pag, p + 1, data=self.zero)
            return "sk1"

    def doZero(self, frt, pag, r, c, p, i, w):
        self.zero = w

    def doEnd(self):
        self.df.closeProcess()
        whr = [("drm_cono", "=", self.opts["conum"])]
        if self.drsact != "All":
            whr.append(("drm_bus_activity", "=", self.drsact))
        if self.drstyp != "All":
            whr.append(("drm_bus_type", "=", self.drstyp))
        odr = "drm_chain, drm_acno"
        recs = self.sql.getRec("drsmst",
                               cols=["drm_chain", "drm_acno", "drm_name"],
                               where=whr,
                               order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Records Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [self.head + " %s" % self.sysdttm]
        self.expheads.append("Debtor's Age Analaysis up to %s" %
                             self.opts["period"])
        self.expheads.append("Options: Activity %s Type %s Low-Bal %s "\
            "Cr-Bals %s Ignore-Zeros %s" % (self.drsact, self.drstyp,
            self.limit, self.credit, self.zero))
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            line = ["BODY", [vals[0].work, vals[1].work, vals[2].work]]
            for val in vals[3:]:
                line[1].append(val.work)
            self.expdatas.append(line)
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        chrs = len(self.colsh)
        for f in self.forms:
            chrs += int(f[1])
        if f[0][0].lower() == "s":
            chrs -= 2
        else:
            chrs -= 1
        self.head1 = self.head
        self.head2 = "Debtor's Age Analysis up to %s" % self.opts["period"]
        pad = chrs - len(self.head2)
        self.head2 = self.head2 + (" " * pad)
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head2)
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                if self.fpdf.page:
                    self.fpdf.drawText()
                    self.fpdf.drawText("Print Job ABORTED")
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            if self.totsonly != "Y":
                if self.pglin > self.fpdf.lpp:
                    self.pageHeading()
                self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s" % \
                    (vals[0].disp, vals[1].disp, vals[2].disp, vals[3].disp,
                    vals[4].disp, vals[5].disp, vals[6].disp, vals[7].disp,
                    vals[8].disp, vals[9].disp))
                self.pglin += 1
        p.closeProgress()
        if p.quit:
            return
        if self.totsonly == "Y":
            self.pageHeading()
        if self.fpdf.page:
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          fromad=self.fromad,
                          repeml=self.df.repeml)

    def getValues(self, data):
        chn = CCD(data[0], "UI", 3)
        acc = CCD(data[1], "NA", 7)
        name = CCD(data[2], "NA", 30)
        if self.base == "A":
            bals = Balances(self.opts["mf"],
                            "DRS",
                            self.opts["conum"],
                            self.cutoff,
                            keys=(data[0], data[1]))
            obal, cbal, ages = bals.doAllBals()
        else:
            pers = []
            yr = int(self.cutoff / 100)
            mt = int(self.cutoff % 100)
            for x in range(4):
                pers.append((yr * 100) + mt)
                mt -= 1
                if not mt:
                    yr -= 1
                    mt = 12
            cbal = 0
            ages = [0, 0, 0, 0, 0]
            bals = self.sql.getRec("drstrn",
                                   cols=["drt_curdt", "sum(drt_tramt)"],
                                   where=[("drt_cono", "=",
                                           self.opts["conum"]),
                                          ("drt_chain", "=", chn.work),
                                          ("drt_acno", "=", acc.work),
                                          ("drt_curdt", "<=", pers[0])],
                                   group="drt_curdt",
                                   order="drt_curdt")
            for bal in bals:
                try:
                    idx = pers.index(bal[0])
                except:
                    idx = 4
                ages[idx] = float(ASD(ages[idx]) + ASD(bal[1]))
                cbal = float(ASD(cbal) + ASD(bal[1]))
        bal = CCD(cbal, "SD", 13.2)
        if self.limit and bal.work < self.limit:
            return
        if self.zero == "Y" and not bal.work:
            return
        if self.credit == "N" and bal.work < 0:
            return
        if self.credit == "O" and bal.work >= 0:
            return
        cur = CCD(ages[0], "SD", 13.2)
        d30 = CCD(ages[1], "SD", 13.2)
        d60 = CCD(ages[2], "SD", 13.2)
        d90 = CCD(ages[3], "SD", 13.2)
        d120 = CCD(ages[4], "SD", 13.2)
        if bal.work < 0:
            deb = CCD(bal.work, "SD", 13.2)
        else:
            deb = CCD(0, "SD", 13.2)
        self.gtots[0] = float(ASD(self.gtots[0]) + ASD(deb.work))
        self.gtots[1] = float(ASD(self.gtots[1]) + ASD(bal.work))
        self.gtots[2] = float(ASD(self.gtots[2]) + ASD(cur.work))
        self.gtots[3] = float(ASD(self.gtots[3]) + ASD(d30.work))
        self.gtots[4] = float(ASD(self.gtots[4]) + ASD(d60.work))
        self.gtots[5] = float(ASD(self.gtots[5]) + ASD(d90.work))
        self.gtots[6] = float(ASD(self.gtots[6]) + ASD(d120.work))
        return (chn, acc, name, deb, bal, cur, d30, d60, d90, d120)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head1)
        self.fpdf.drawText()
        self.fpdf.drawText(self.head2)
        self.fpdf.drawText()
        self.fpdf.drawText(
            "(%s%-3s%3s%6s%-3s%3s%9s%-8s%3s%13s%1s%3s%17s%s)" %
            ("Options: Activity: ", self.drsact, "", "Type: ", self.drstyp, "",
             "Low-Bal: ", self.limit, "", "Cr-Bals: ", self.credit, "",
             "Ignore-Zero-Bal: ", self.zero))
        self.fpdf.drawText()
        self.fpdf.drawText("%-3s %-7s %-30s %-13s %-13s %-13s %-13s %-13s "\
            "%-13s %-13s" % ("Chn", "Acc-Num", "Name", "  Cr-Balance",
            " Tot-Balance", "     Current", "     30-Days", "     60-Days",
            "     90-Days", "Over-90-Days"))
        self.fpdf.drawText("%s" % (self.fpdf.suc * len(self.head2)))
        self.fpdf.setFont()
        self.pglin = 8

    def grandTotal(self):
        if self.df.repprt[2] == "export":
            self.expdatas.append(["ULINES"])
            self.expdatas.append(
                ["TOTAL", ["", "", "Grand Totals"] + self.gtots])
            self.expdatas.append(["ULINED"])
            return
        ldic = {}
        for x in range(0, 7):
            ldic["t%s" % x] = CCD(self.gtots[x], "SD", 13.2)
            if self.gtots[1] == 0:
                ldic["p%s" % x] = CCD(0, "SD", 13.2)
            else:
                ldic["p%s" % x] = CCD(
                    round((self.gtots[x] / self.gtots[1] * 100), 2), "OSD",
                    13.2)
        self.fpdf.drawText()
        self.fpdf.drawText("%-11s %-30s %13s %13s %13s %13s %13s %13s %13s" %
                           (" ", "Grand Totals", ldic["t0"].disp,
                            ldic["t1"].disp, ldic["t2"].disp, ldic["t3"].disp,
                            ldic["t4"].disp, ldic["t5"].disp, ldic["t6"].disp))
        self.fpdf.drawText()
        self.fpdf.drawText("%-11s %-30s %13s %13s %13s %13s %13s %13s %13s" %
                           (" ", "Percentages", ldic["p0"].disp,
                            ldic["p1"].disp, ldic["p2"].disp, ldic["p3"].disp,
                            ldic["p4"].disp, ldic["p5"].disp, ldic["p6"].disp))

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 23
0
class st3080(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       ["strloc", "strgrp", "strmf1", "strtrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        self.fromad = strctl["cts_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i) %6s" % (
            t[0], t[1], t[2], t[3], t[4], self.__class__.__name__)
        self.colsh = [
            "Grp", "Product-Code", "Description", "U.O.I", "Qty-Balance",
            "Val-Balance"
        ]
        self.forms = [("UA", 3), ("NA", 20), ("NA", 30), ("NA", 10),
                      ("SD", 12.2), ("SD", 12.2)]
        self.gtot = 0
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Stock On Hand Report (%s)" % self.__class__.__name__)
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        r1s = (("Yes", "Y"), ("No", "N"))
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["", "", "", "Y", "Y"]
            view = ("Y", "V")
            mail = ("Y", "N")
        fld = [(("T", 0, 0, 0), "ID2", 7, "Reporting Period", "",
                int(self.sysdtw / 100), "Y", self.doPeriod, None, None,
                ("efld", )),
               [("T", 0, 1, 0), "IUA", 1, "Location", "", var[1], "N",
                self.doLoc, loc, None, ("efld", )],
               (("T", 0, 2, 0), "IUA", 3, "Product Group", "", var[2], "N",
                self.doGroup, grp, None, None),
               (("T", 0, 3, 0), ("IRB", r1s), 0, "Ignore Zero Balances", "",
                var[3], "N", self.doZero, None, None, None),
               (("T", 0, 4, 0), ("IRB", r1s), 0, "Ignore Redundant Stock", "",
                var[4], "N", self.doRedt, None, None, None)]
        if self.locs == "N":
            fld[1][1] = "OUA"
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doPeriod(self, frt, pag, r, c, p, i, w):
        if w > int(self.sysdtw / 100):
            return "Invalid Period"
        self.curdt = w
        self.date = CCD(mthendDate(w * 100), "D1", 10)
        if self.locs == "N":
            self.df.loadEntry(frt, pag, p + 1, data="1")
            no = self.doLoc(frt, pag, r, c + 1, p + 1, i + 1, "1")
            if no:
                return no
            return "sk1"

    def doLoc(self, frt, pag, r, c, p, i, w):
        if not w:
            self.loc = ""
            self.locd = "ALL"
        else:
            acc = self.sql.getRec("strloc",
                                  cols=["srl_desc"],
                                  where=[("srl_cono", "=", self.opts["conum"]),
                                         ("srl_loc", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Location"
            self.loc = w
            self.locd = acc[0]

    def doGroup(self, frt, pag, r, c, p, i, w):
        if not w:
            self.group = ""
        else:
            acc = self.sql.getRec("strgrp",
                                  cols=["gpm_desc"],
                                  where=[("gpm_cono", "=", self.opts["conum"]),
                                         ("gpm_group", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Group"
            self.group = w

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

    def doRedt(self, frt, pag, r, c, p, i, w):
        self.redt = w

    def doEnd(self):
        self.df.closeProcess()
        if not self.group:
            self.sgrp = ""
            self.egrp = "zzz"
        else:
            self.sgrp = self.group
            self.egrp = self.group
        whr = [("st1_cono", "=", self.opts["conum"]),
               ("st1_group", ">=", self.sgrp), ("st1_group", "<=", self.egrp)]
        if self.redt == "Y":
            whr.append(("st1_type", "not", "in", ("R", "X")))
        else:
            whr.append(("st1_type", "<>", "R"))
        recs = self.sql.getRec(
            "strmf1",
            cols=["st1_group", "st1_code", "st1_desc", "st1_uoi"],
            where=whr,
            order="st1_group, st1_code")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Records Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [
            "%03u %-30s %s" %
            (self.opts["conum"], self.opts["conam"], self.sysdttm)
        ]
        self.expheads.append("Stock On Hand Report as at %s" % self.date.disp)
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            self.expdatas.append([
                "BODY",
                [
                    vals[0].work, vals[1].work, vals[2].work, vals[3].work,
                    vals[4].work, vals[5].work
                ]
            ])
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-83s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.stot = 0
        old_grp = ""
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            grp, code, desc, uoi, qbal, vbal = vals
            if old_grp and old_grp != grp.work:
                self.groupTotal()
                self.pglin = 999
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText("%s %s %s %s %s" % \
                (code.disp, desc.disp, uoi.disp, qbal.disp, vbal.disp))
            self.pglin += 1
            self.stot = float(ASD(self.stot) + ASD(vbal.work))
            old_grp = grp.work
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.groupTotal()
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          fromad=self.fromad,
                          repeml=self.df.repeml)

    def getValues(self, data):
        grp = CCD(data[0], "UA", 3)
        self.groupd = grp.disp
        code = CCD(data[1], "NA", 20)
        desc = CCD(data[2], "NA", 30)
        uoi = CCD(data[3], "NA", 10)
        whr = [("stt_cono", "=", self.opts["conum"]),
               ("stt_group", "=", grp.work), ("stt_code", "=", code.work)]
        if self.loc:
            whr.append(("stt_loc", "=", self.loc))
        whr.append(("stt_curdt", "<=", self.curdt))
        bal = self.sql.getRec(
            "strtrn",
            cols=["round(sum(stt_qty), 2)", "round(sum(stt_cost), 2)"],
            where=whr,
            limit=1)
        if not bal[0]:
            bal[0] = 0
        if not bal[1]:
            bal[1] = 0
        qbal = CCD(bal[0], "SD", 12.2)
        vbal = CCD(bal[1], "SD", 12.2)
        if self.zero == "Y" and qbal.work == 0 and vbal.work == 0:
            return
        self.gtot = float(ASD(self.gtot) + ASD(vbal.work))
        return (grp, code, desc, uoi, qbal, vbal)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-26s %-10s" % \
            ("Stock On Hand Report as at", self.date.disp))
        self.fpdf.drawText()
        self.fpdf.drawText(
            "%-5s %3s      %-8s %s  %s" %
            ("Group", self.groupd, "Location", self.loc, self.locd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-20s %-30s %-10s %11s %12s" %
                           ("Product-Code", "Description", "U.O.I",
                            "Qty-Balance", "Val-Balance"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def groupTotal(self):
        val = CCD(self.stot, "SD", 12.2)
        self.fpdf.drawText()
        self.fpdf.drawText("%-20s %-41s %12s %12s" % \
            ("", "Group Totals", "", val.disp))
        self.fpdf.drawText()
        self.stot = 0

    def grandTotal(self):
        if self.df.repprt[2] == "export":
            self.expdatas.append(["ULINES"])
            self.expdatas.append(
                ["TOTAL", ["", "", "Grand Totals", "", "", self.gtot]])
            self.expdatas.append(["ULINED"])
            return
        val = CCD(self.gtot, "SD", 12.2)
        self.fpdf.drawText("%-20s %-41s %12s %12s" % \
            (" ", "Grand Totals", "", val.disp))

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 24
0
class rt3020(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, ["ctlmst", "rtlmst", "rtltrn"],
                       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.fromad = rtlctl["ctr_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdttm = "(Printed on: %i/%02i/%02i at %02i:%02i)" % \
            (t[0], t[1], t[2], t[3], t[4])
        self.colsh = [
            "TP", "BatchNo", "Prm-Cod", "Acc-Num", "Name", "Reference", "Date",
            "Debits", "Credits", "Tax-Amount", "T", "Remarks"
        ]
        self.forms = [("UI", 2, False, False, True), ("Na", 7), ("NA", 7),
                      ("NA", 7), ("NA", 30), ("Na", 9), ("D1", 10),
                      ("SD", 13.2), ("SD", 13.2), ("SD", 13.2), ("UA", 1),
                      ("NA", 30)]
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        self.gqt = [0] * (len(rttrtp) + 1)
        self.gdr = [0] * (len(rttrtp) + 1)
        self.gcr = [0] * (len(rttrtp) + 1)
        self.gvt = [0] * (len(rttrtp) + 1)
        self.totind = "N"
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Rental's Ledger Audit Trail (%s)" %
                    self.__class__.__name__)
        data = ["All Types"]
        for typ in rttrtp:
            data.append(typ[1])
        btt = {"stype": "C", "titl": "Valid Types", "data": data, "retn": "I"}
        btm = {
            "stype":
            "R",
            "tables": ("rtltrn", ),
            "cols": (("rtt_batch", "", 0,
                      "Bat-Num"), ("rtt_type", ("xx", rttrtp), 20, "Type"),
                     ("rtt_curdt", "", 0, "Cur-Dat")),
            "where": [],
            "group":
            "rtt_batch, rtt_type, rtt_curdt",
            "order":
            "rtt_type, rtt_curdt, rtt_batch"
        }
        r1s = (("Financial", "F"), ("Capture", "C"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = [(("T", 0, 0, 0), ("IRB", r1s), 0, "Period Type", "", "F", "Y",
                self.doPtyp, None, None, None),
               (("T", 0, 1, 0), "Id2", 7, "Starting Period", "", self.s_per,
                "Y", self.doStartPer, None, None, ("efld", )),
               (("T", 0, 2, 0), "Id2", 7, "Ending Period", "", self.e_per, "Y",
                self.doEndPer, None, None, ("efld", )),
               (("T", 0, 3, 0), "Id1", 10, "Starting Date", "", self.sysdtw,
                "Y", self.doStartDat, None, None, ("efld", )),
               (("T", 0, 4, 0), "Id1", 10, "Ending Date", "", self.sysdtw, "Y",
                self.doEndDat, None, None, ("efld", )),
               (("T", 0, 5, 0), "IUI", 1, "Type", "Transaction Type", "", "Y",
                self.doBatTyp, btt, None, None),
               (("T", 0, 6, 0), "INa", 7, "Batch Number", "", "", "Y",
                self.doBatNum, btm, None, None),
               (("T", 0, 7, 0), ("IRB", r2s), 0, "Totals Only", "", "Y", "Y",
                self.doTots, None, None, None)]
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "N"))

    def doPtyp(self, frt, pag, r, c, p, i, w):
        self.ptyp = w
        if self.ptyp == "C":
            return "sk2"

    def doStartPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.s_per
        elif w < self.s_per or w > self.e_per:
            return "Invalid Period"
        self.sperw = w
        self.df.loadEntry(frt, pag, p, data=self.sperw)
        self.sperd = self.df.t_disp[pag][0][i]

    def doEndPer(self, frt, pag, r, c, p, i, w):
        if not w:
            w = self.e_per
        elif w < self.sperw or w > self.e_per:
            return "Invalid Period"
        self.eperw = w
        self.df.loadEntry(frt, pag, p, self.eperw)
        self.eperd = self.df.t_disp[pag][0][i]
        return "sk2"

    def doStartDat(self, frt, pag, r, c, p, i, w):
        self.sdatw = w
        self.df.loadEntry(frt, pag, p, data=self.sdatw)
        self.sperd = self.df.t_disp[pag][0][i]

    def doEndDat(self, frt, pag, r, c, p, i, w):
        if w < self.sdatw:
            return "Invalid Date"
        self.edatw = w
        self.df.loadEntry(frt, pag, p, self.edatw)
        self.eperd = self.df.t_disp[pag][0][i]

    def doBatTyp(self, frt, pag, r, c, p, i, w):
        if w > len(rttrtp):
            return "Invalid Batch Type"
        self.btyp = w
        self.whr = [("rtt_cono", "=", self.opts["conum"])]
        if self.ptyp == "F":
            self.whr.append(("rtt_curdt", "between", self.sperw, self.eperw))
        else:
            self.whr.append(("rtt_capdt", "between", self.sdatw, self.edatw))
        if self.btyp:
            self.whr.append(("rtt_type", "=", self.btyp))
        self.df.topf[pag][i + 1][8]["where"] = self.whr

    def doBatNum(self, frt, pag, r, c, p, i, w):
        self.batch = w

    def doTots(self, frt, pag, r, c, p, i, w):
        self.totsonly = w
        if self.totsonly == "Y":
            self.df.setWidget(self.df.topEntry[0][8][3][0], state="hide")
            self.df.setWidget(self.df.topEntry[0][8][4][0], state="hide")
        else:
            self.df.setWidget(self.df.topEntry[0][8][3][0], state="show")
            self.df.setWidget(self.df.topEntry[0][8][4][0], state="show")

    def doEnd(self):
        self.df.closeProcess()
        jon = "left outer join rtlmst on rtt_cono=rtm_cono and "\
            "rtt_code=rtm_code and rtt_acno=rtm_acno"
        col = [
            "rtt_code", "rtt_acno", "rtt_trdt", "rtt_type", "rtt_refno",
            "rtt_batch", "rtt_tramt", "rtt_taxamt", "rtt_desc", "rtt_taxind",
            "rtm_name"
        ]
        odr = "rtt_type, rtt_batch, rtt_trdt, rtt_refno"
        recs = self.sql.getRec("rtltrn",
                               join=jon,
                               cols=col,
                               where=self.whr,
                               order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Transaction Error",
                      "No Transactions Selected")
        elif self.df.repprt[2] == "export":
            self.exportReport(recs)
        else:
            self.printReport(recs)
        self.closeProcess()

    def exportReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        expnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__, self.opts["conum"])
        self.expheads = [
            "%03u %-30s %s" %
            (self.opts["conum"], self.opts["conam"], self.sysdttm)
        ]
        self.expheads.append("Rental's Ledger Audit Trail for Period "\
            "%s to %s" % (self.sperd, self.eperd))
        self.expcolsh = [self.colsh]
        self.expforms = self.forms
        self.expdatas = []
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                p.closeProgress()
                return
            vals = self.getValues(dat)
            if not vals:
                continue
            code, acno, trdt, trtp, refno, batch, debit, credit, taxamt, \
                detail, taxind, name = vals
            line = [
                "BODY",
                [
                    trtp.work, batch.work, code.work, acno.work, name.work,
                    refno.work, trdt.work, debit.work, credit.work,
                    taxamt.work, taxind.work, detail.work
                ]
            ]
            self.expdatas.append(line)
        p.closeProgress()
        self.grandTotal()
        doWriteExport(xtype=self.df.repprt[1],
                      name=expnam,
                      heads=self.expheads,
                      colsh=self.expcolsh,
                      forms=self.expforms,
                      datas=self.expdatas,
                      rcdic=self.opts["mf"].rcdic)

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        if self.totsonly == "Y":
            self.head = "%03u %-87s" % (self.opts["conum"], self.opts["conam"])
        else:
            self.head = "%03u %-133s" % (self.opts["conum"],
                                         self.opts["conam"])
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.bqty = 0
        self.bdrs = 0
        self.bcrs = 0
        self.bvat = 0
        self.tqty = 0
        self.tdrs = 0
        self.tcrs = 0
        self.tvat = 0
        self.trtp = 0
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            vals = self.getValues(dat)
            if not vals:
                continue
            code, acno, trdt, trtp, refno, batch, debit, credit, taxamt, \
                detail, taxind, name = vals
            if not self.trtp:
                self.trtp = trtp.work
                self.batch = batch.work
            if trtp.work != self.trtp:
                self.batchTotal()
                self.typeTotal()
                self.trtp = trtp.work
                self.batch = batch.work
                self.pglin = 999
            if batch.work != self.batch:
                self.batchTotal()
                self.batch = batch.work
                if self.totsonly != "Y":
                    self.typeHeading()
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            if self.totsonly != "Y":
                self.fpdf.drawText(
                    "%s %s %s %s %s %s %s %s %s %s" %
                    (code.disp, acno.disp, name.disp, refno.disp, trdt.disp,
                     debit.disp, credit.disp, taxamt.disp, taxind.disp,
                     detail.disp))
                self.pglin += 1
            # Batch Totals
            self.bqty += 1
            self.bdrs = float(ASD(self.bdrs) + ASD(debit.work))
            self.bcrs = float(ASD(self.bcrs) + ASD(credit.work))
            self.bvat = float(ASD(self.bvat) + ASD(taxamt.work))
            # Type Totals
            self.tqty += 1
            self.tdrs = float(ASD(self.tdrs) + ASD(debit.work))
            self.tcrs = float(ASD(self.tcrs) + ASD(credit.work))
            self.tvat = float(ASD(self.tvat) + ASD(taxamt.work))
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.batchTotal()
            self.typeTotal()
            self.grandTotal()
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def getValues(self, data):
        code = CCD(data[0], "NA", 7)
        acno = CCD(data[1], "NA", 7)
        trdt = CCD(data[2], "D1", 10)
        trtp = CCD(data[3], "UI", 2)
        refno = CCD(data[4], "Na", 9)
        batch = CCD(data[5], "Na", 7)
        if data[6] < 0:
            debit = CCD(0, "SD", 13.2)
            credit = CCD(data[6], "SD", 13.2)
        else:
            debit = CCD(data[6], "SD", 13.2)
            credit = CCD(0, "SD", 13.2)
        taxamt = CCD(data[7], "SD", 13.2)
        detail = CCD(data[8], "NA", 30)
        taxind = CCD(data[9], "NA", 1)
        name = CCD(data[10], "NA", 30)
        self.gqt[trtp.work - 1] = self.gqt[trtp.work - 1] + 1
        self.gdr[trtp.work - 1] = float(ASD(self.gdr[trtp.work - 1]) + \
            ASD(debit.work))
        self.gcr[trtp.work - 1] = float(ASD(self.gcr[trtp.work - 1]) + \
            ASD(credit.work))
        self.gvt[trtp.work - 1] = float(ASD(self.gvt[trtp.work - 1]) + \
            ASD(taxamt.work))
        return (code, acno, trdt, trtp, refno, batch, debit, credit, taxamt,
                detail, taxind, name)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-38s %-7s %-2s %-7s" % \
            ("Rental's Ledger Audit Trail for Period",
            self.sperd, "to", self.eperd))
        self.fpdf.drawText()
        self.pglin = 4
        if self.totind == "N":
            self.typeHeading()
        else:
            self.fpdf.drawText("%-14s" % "Totals Summary")
            self.fpdf.drawText()
            if self.totsonly == "Y":
                self.fpdf.drawText("%-27s%-8s  %-13s %-13s %-13s %-13s" % \
                    ("Document Type", "Quantity", "      Debits",
                    "     Credits", "  Difference", "      V.A.T."))
            else:
                self.fpdf.drawText("%-34s%-8s  %-13s %-13s %-13s %-13s" % \
                    ("Document Type", "Quantity", "      Debits",
                    "     Credits", "  Difference", "      V.A.T."))
            self.fpdf.underLine(txt=self.head)
            self.fpdf.setFont()
            self.pglin += 4

    def typeHeading(self):
        if self.totsonly != "Y":
            batch = self.batch
        else:
            batch = "Various"
        if self.fpdf.lpp - self.pglin < 7:
            self.pageHeading()
            return
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("%-7s %7s %-10s %3s" % \
            ("Batch", batch, "    Type", rttrtp[self.trtp - 1][1]))
        self.fpdf.drawText()
        if self.totsonly == "Y":
            self.fpdf.drawText("%-36s %-13s %-13s %-13s %-13s" % \
                ("Details", "      Debits", "     Credits", "  Difference",
                "      V.A.T."))
        else:
            self.fpdf.drawText("%-7s %-7s %-30s %-9s %-10s %-13s %-13s %-13s "\
                "%-1s %-30s" % ("Prm-Num", "Acc-Num", "Name", "Reference",
                "   Date", "      Debits", "     Credits", "  Tax-Amount",
                "T", "Remarks"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin += 4

    def batchTotal(self):
        j = CCD(self.bdrs, "SD", 13.2)
        k = CCD(self.bcrs, "SD", 13.2)
        l = CCD(float(ASD(j.work) + ASD(k.work)), "SD", 13.2)
        m = CCD(self.bvat, "SD", 13.2)
        if self.totsonly == "Y":
            self.fpdf.drawText("%-36s %13s %13s %13s %13s" % \
                ("Batch " + self.batch + " Totals", j.disp,
                k.disp, l.disp, m.disp))
            self.pglin += 1
        else:
            self.fpdf.drawText()
            self.fpdf.drawText("%-15s %-51s %13s %13s %13s" %
                               (" ", "Batch " + self.batch + " Totals", j.disp,
                                k.disp, m.disp))
            self.fpdf.drawText()
            self.pglin += 3
        self.bqty = 0
        self.bcrs = 0
        self.bdrs = 0
        self.bvat = 0

    def typeTotal(self):
        j = CCD(self.tdrs, "SD", 13.2)
        k = CCD(self.tcrs, "SD", 13.2)
        l = CCD(float(ASD(j.work) + ASD(k.work)), "SD", 13.2)
        m = CCD(self.tvat, "SD", 13.2)
        if self.totsonly == "Y":
            self.fpdf.drawText()
            self.fpdf.drawText("%-36s %13s %13s %13s %13s" % \
                ("Type Totals", j.disp, k.disp, l.disp, m.disp))
            self.pglin += 2
        else:
            self.fpdf.drawText("%-15s %-51s %13s %13s %13s" % \
            (" ", "Type-Totals", j.disp, k.disp, m.disp))
            self.pglin += 1
        self.fpdf.drawText()
        self.pglin += 1
        self.tqty = 0
        self.tcrs = 0
        self.tdrs = 0
        self.tvat = 0

    def grandTotal(self):
        tot = [0, 0, 0, 0, 0]
        if self.df.repprt[2] == "export":
            for x in range(0, len(rttrtp)):
                tot[0] = float(ASD(tot[0]) + ASD(self.gdr[x]))
                tot[1] = float(ASD(tot[1]) + ASD(self.gcr[x]))
                tot[2] = float(ASD(tot[2]) + ASD(self.gvt[x]))
            self.expdatas.append(["ULINES"])
            self.expdatas.append([
                "TOTAL",
                [
                    "", "", "", "", "Grand Totals", "", "", tot[0], tot[1],
                    tot[2], ""
                ]
            ])
            self.expdatas.append(["ULINED"])
            return
        self.totind = "Y"
        self.pageHeading()
        for x, t in enumerate(rttrtp):
            qt = CCD(self.gqt[x], "SI", 8)
            dr = CCD(self.gdr[x], "SD", 13.2)
            cr = CCD(self.gcr[x], "SD", 13.2)
            df = float(ASD(dr.work) + ASD(cr.work))
            df = CCD(df, "SD", 13.2)
            vt = CCD(self.gvt[x], "SD", 13.2)
            if self.totsonly == "Y":
                self.fpdf.drawText("%-27s %s %s %s %s %s" % \
                (t[1], qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
            else:
                self.fpdf.drawText("%-34s %s %s %s %s %s" % \
                (t[1], qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
            tot[0] = tot[0] + qt.work
            tot[1] = float(ASD(tot[1]) + ASD(dr.work))
            tot[2] = float(ASD(tot[2]) + ASD(cr.work))
            tot[3] = float(ASD(tot[3]) + ASD(df.work))
            tot[4] = float(ASD(tot[4]) + ASD(vt.work))
        self.fpdf.drawText()
        qt = CCD(tot[0], "SI", 8)
        dr = CCD(tot[1], "SD", 13.2)
        cr = CCD(tot[2], "SD", 13.2)
        df = CCD(tot[3], "SD", 13.2)
        vt = CCD(tot[4], "SD", 13.2)
        if self.totsonly == "Y":
            self.fpdf.drawText("%-27s %s %s %s %s %s" % \
            ("Grand Totals", qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
        else:
            self.fpdf.drawText("%-34s %s %s %s %s %s" % \
            ("Grand Totals", qt.disp, dr.disp, cr.disp, df.disp, vt.disp))
        self.fpdf.drawText()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 25
0
class gl4010(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,
                       ["genmst", "genbal", "genbud", "gentrn"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        self.i_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        df = self.e_per - self.i_per - 87
        if df > 12:
            self.d_per = df - 12
            yr = int(self.i_per / 100)
            mt = int(self.i_per % 100)
            for _ in range(self.d_per):
                mt += 1
                if mt > 12:
                    mt -= 12
                    yr += 1
            self.s_per = (yr * 100) + mt
        else:
            self.d_per = 0
            self.s_per = self.i_per
        self.d_pyr = 0
        if self.opts["period"][0]:
            s, e, f = getPeriods(self.opts["mf"], self.opts["conum"],
                                 (self.opts["period"][0] - 1))
            if (s, e, f) == (None, None, None):
                return
            self.s_lyr = s.work
            self.i_pyr = int(s.work / 100)
            self.e_pyr = int(e.work / 100)
            df = self.e_pyr - self.i_pyr - 87
            if df > 12:
                self.d_pyr = df - 12
                yr = int(self.i_pyr / 100)
                mt = self.i_pyr % 100
                for _ in range(self.d_pyr):
                    mt += 1
                    if mt > 12:
                        mt -= 12
                        yr += 1
                self.s_pyr = (yr * 100) + mt
            else:
                self.s_pyr = self.i_pyr
        self.trnper = 0
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "General Ledger Interrogation (%s)" %
                    self.__class__.__name__)
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])],
            "order":
            "glm_acno"
        }
        fld = ((("T", 0, 0, 0, 7), "IUI", 7, "Acc-Num", "Account Number", "",
                "N", self.doAccNum, glm, None, None), (("T", 0, 0, 0), "ONA",
                                                       30, "Description"),
               (("T", 0, 0, 0), "OUA", 1, "Type"), (("T", 0, 0, 0), "OUA", 1,
                                                    "Indicator"),
               (("C", 1, 0, 0), "OSD", 13.2, "Actual", "", "", "N", None, None,
                None, None, ("Months", 14)), (("C", 1, 0, 1), "OSD", 13.2,
                                              "Budget"),
               (("C", 1, 0, 2), "OSD", 13.2,
                "Variance"), (("C", 1, 0, 3), "OSD", 13.2, "Last-Year"),
               (("T", 2, 0, 0), "Id2", 7, "Period (YYYYMM)",
                "Financial Period (0=All)", self.trnper, "Y", self.doPeriod,
                None, None, None))
        tag = (("Balances", self.doBals, ("T", 0, 2), ("T", 0, 1)),
               ("Transactions", self.doTrans1, ("T", 0, 2), ("T", 0, 1)))
        but = (("Clear", None, self.doClear, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Notes", None, self.doNotes, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Print", None, self.doPrint, 1, ("T", 0, 0),
                ("T", 0, 1)), ("Quit", None, self.doExit, 1, None, None))
        tnd = ((self.doTopEnd, "N"), None, (self.doTrans2, "N"))
        txt = (self.doExit, None, self.doExit)
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               tags=tag,
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt)
        mon = self.s_per % 100
        yer = int(self.s_per / 100)
        for x in range(14):
            if x == 0:
                txt = "Opening Balance"
                self.df.colLabel[1][x].configure(text=txt)
            elif x == 13:
                txt = "Closing Balance"
                self.df.colLabel[1][x].configure(text=txt)
            else:
                nam = mthnam[mon][1]
                nam = nam + (" " * (11 - len(nam))) + str(yer)
                self.df.colLabel[1][x].configure(text=nam)
            if x not in (0, 13):
                mon = mon + 1
                if mon > 12:
                    mon = mon - 12
                    yer = yer + 1
        txt = "Closing Balance"
        self.df.colLabel[1][13].configure(text=txt)

    def doAccNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("genmst",
                              cols=["glm_desc", "glm_type", "glm_ind"],
                              where=[("glm_cono", "=", self.opts["conum"]),
                                     ("glm_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account"
        self.acno = w
        self.desc = acc[0]
        for x in range(1, self.df.topq[pag]):
            self.df.loadEntry(frt, pag, p + x, data=acc[x - 1])
        if self.opts["period"][0]:
            gp = self.sql.getRec("genbal",
                                 cols=["glo_cyr"],
                                 where=[("glo_cono", "=", self.opts["conum"]),
                                        ("glo_acno", "=", self.acno),
                                        ("glo_trdt", "=", self.s_lyr)])
        gc = self.sql.getRec("genbal",
                             cols=["glo_cyr"],
                             where=[("glo_cono", "=", self.opts["conum"]),
                                    ("glo_acno", "=", self.acno),
                                    ("glo_trdt", "=",
                                     self.opts["period"][1][0])])
        gt = self.sql.getRec("gentrn",
                             cols=["glt_type", "glt_curdt", "glt_tramt"],
                             where=[("glt_cono", "=", self.opts["conum"]),
                                    ("glt_acno", "=", self.acno),
                                    ("glt_curdt", "between", self.i_per,
                                     self.e_per)])
        gb = self.sql.getRec("genbud",
                             cols=["glb_curdt", "glb_tramt"],
                             where=[("glb_cono", "=", self.opts["conum"]),
                                    ("glb_acno", "=", self.acno),
                                    ("glb_curdt", "between", self.i_per,
                                     self.e_per)])
        if self.opts["period"][0]:
            gl = self.sql.getRec("gentrn",
                                 cols=["glt_curdt", "glt_tramt"],
                                 where=[("glt_cono", "=", self.opts["conum"]),
                                        ("glt_acno", "=", self.acno),
                                        ("glt_curdt", "between", self.i_pyr,
                                         self.e_pyr)])
        act = [0] * 14
        bud = [0] * 14
        lyr = [0] * 14
        adc = []
        adl = []
        if self.d_per:
            # Current period more than 12 months
            sy = sy = int(self.i_per / 100)
            sm = self.i_per % 100
            for _ in range(self.d_per):
                adc.append(sm)
                sm += 1
                if sm > 12:
                    sy += 1
                    sm = 1
        elif self.d_pyr:
            # Previous period more than 12 months
            sy = sy = int(self.i_pyr / 100)
            sm = self.i_pyr % 100
            for _ in range(self.d_pyr):
                adl.append(sm)
                sm += 1
                if sm > 12:
                    sy += 1
                    sm = 1
        if gc:
            self.obal = gc[0][0]
            act[0] = float(ASD(act[0]) + ASD(self.obal))
            act[13] = float(ASD(act[13]) + ASD(self.obal))
            if self.opts["period"][0] and gp:
                lyr[0] = float(ASD(lyr[0]) + ASD(float(gp[0][0])))
                lyr[13] = float(ASD(lyr[13]) + ASD(float(gp[0][0])))
        else:
            self.obal = 0
        yre = self.e_per % 100
        if gt:
            for x, t in enumerate(gt):
                cyr = int(t[1] / 100)
                mon = t[1] % 100
                if adc and cyr == sy and mon in adc:
                    col = 1
                else:
                    col = mon - yre
                    if col <= 0:
                        col = col + 12
                act[col] = float(ASD(act[col]) + ASD(float(t[2])))
                act[13] = float(ASD(act[13]) + ASD(float(t[2])))
        if gb:
            for x, t in enumerate(gb):
                mon = int(str(t[0])[4:6])
                col = mon - yre
                if col <= 0:
                    col = col + 12
                bud[col] = float(ASD(bud[col]) + ASD(float(t[1])))
                bud[13] = float(ASD(bud[13]) + ASD(float(t[1])))
        if self.opts["period"][0] and gl:
            for x, t in enumerate(gl):
                cyr = int(t[0] / 100)
                mon = t[0] % 100
                if adl and cyr == sy and mon in adl:
                    col = 1
                else:
                    col = mon - yre
                    if col <= 0:
                        col = col + 12
                lyr[col] = float(ASD(lyr[col]) + ASD(float(t[1])))
                lyr[13] = float(ASD(lyr[13]) + ASD(float(t[1])))
        p = 0
        for x in range(14):
            i = 0
            self.df.loadEntry("C", 1, p, data=act[x])
            p = p + 1
            i = i + 1
            self.df.loadEntry("C", 1, p, data=bud[x])
            p = p + 1
            i = i + 1
            data = float(ASD(bud[x]) - ASD(act[x]))
            self.df.loadEntry("C", 1, p, data=data)
            p = p + 1
            i = i + 1
            self.df.loadEntry("C", 1, p, data=lyr[x])
            p = p + 1
        self.df.last[0] = [0, 0]
        self.opts["mf"].updateStatus("")

    def doBals(self):
        self.opts["mf"].updateStatus("")

    def doTrans1(self):
        self.df.focusField("T", 2, 1)

    def doTrans2(self):
        tit = "Transactions for Account: %s - %s" % (self.acno, self.desc)
        gtt = ["gentrn"]
        gtc = (("glt_trdt", "", 0,
                "   Date"), ("glt_refno", "", 0, "Reference",
                             "Y"), ("glt_type", ("XX", gltrtp), 3, "Typ"),
               ("glt_batch", "", 0, "Batch"), ("glt_tramt", "", 0,
                                               "       Debit"),
               ("glt_tramt", "", 0, "      Credit"), ("balance", "SD", 13.2,
                                                      "     Balance"),
               ("glt_desc", "", 0, "Remarks"), ("glt_seq", "", 0, "Sequence"))
        mthno, acctot = self.getObal()
        if mthno.work == 0:
            d = self.opts["period"][1][0]
        else:
            d = (self.trnper * 100) + 1
        if acctot:
            if acctot < 0:
                dr = 0
                cr = acctot
            else:
                dr = acctot
                cr = 0
            data = [[d, "B/Fwd", 4, "", dr, cr, acctot, "Opening Balance", 0]]
        else:
            data = []
        trn = self.getTrans()
        if trn:
            col = self.sql.gentrn_col
            for rec in trn:
                acctot = float(ASD(acctot) + ASD(rec[col.index("glt_tramt")]))
                if rec[col.index("glt_tramt")] < 0:
                    dr = 0
                    cr = rec[col.index("glt_tramt")]
                else:
                    dr = rec[col.index("glt_tramt")]
                    cr = 0
                data.append([
                    rec[col.index("glt_trdt")], rec[col.index("glt_refno")],
                    rec[col.index("glt_type")], rec[col.index("glt_batch")],
                    dr, cr, acctot, rec[col.index("glt_desc")],
                    rec[col.index("glt_seq")]
                ])
        state = self.df.disableButtonsTags()
        while True:
            rec = SRec(self.opts["mf"],
                       screen=self.df.nb.Page2,
                       title=tit,
                       tables=gtt,
                       cols=gtc,
                       where=data,
                       wtype="D",
                       sort=False)
            # Display all transaction details
            if rec.selection:
                self.df.setWidget(self.df.mstFrame, state="hide")
                whr = [("glt_seq", "=", rec.selection[8])]
                TabPrt(self.opts["mf"], tabs="gentrn", where=whr, pdia=False)
                self.df.setWidget(self.df.mstFrame, state="show")
            else:
                break
        self.df.enableButtonsTags(state=state)
        self.doTrans1()

    def doNotes(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        NotesCreate(self.opts["mf"], self.opts["conum"], self.opts["conam"],
                    self.opts["capnm"], "GEN", self.acno)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doTopEnd(self):
        self.df.last[0] = [0, 0]
        self.df.setWidget(self.df.topEntry[0][0], state="disabled")

    def doClear(self):
        self.df.selPage("Balances")
        self.df.focusField("T", 0, 1)

    def doPrint(self):
        self.df.setWidget(self.df.mstFrame, state="hide")
        tit = ("Printer/Email Selection", )
        r1s = (("Info", "I"), ("Trans", "T"))
        fld = ((("T", 0, 1, 0), ("IRB", r1s), 0, "Selection", "", "I", "N",
                self.doPrtSel, None, None, None),
               (("T", 0, 2,
                 0), "Id2", 7, "Period (YYYYMM)", "Financial Period (0=All)",
                self.trnper, "Y", self.doPeriod, None, None, None))
        self.pr = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=((self.doPrtEnd, "y"), ),
                               txit=(self.doPrtExit, ),
                               view=("Y", "V"),
                               mail=("Y", "N"))
        self.pr.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.focusField("T", 2, 1)

    def doPrtSel(self, frt, pag, r, c, p, i, w):
        self.sel = w
        for x in (2, 3):
            if bool(self.sel == "I"):
                self.pr.setWidget(self.pr.topEntry[0][2][x][0], state="hide")
            else:
                self.pr.setWidget(self.pr.topEntry[0][2][x][0], state="show")
        if self.sel == "I":
            return "sk1"

    def doPrtEnd(self):
        self.pr.closeProcess()
        self.head = "%03u %-99s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.pgnum = 0
        self.pglin = 999
        self.num = self.df.t_disp[0][0][0]
        self.dsc = self.df.t_disp[0][0][1]
        atype = self.df.t_disp[0][0][2]
        ind = self.df.t_disp[0][0][3]
        if self.pr.t_work[0][0][0] == "I":
            self.pageHeading()
            self.fpdf.drawText("%-8s %-12s %-6s %-35s %-6s %-7s %-11s %s" % \
                ("Acc No:", self.num, "Desc:", self.dsc, "Type:", atype,
                "Indicator:", ind))
            self.fpdf.drawText()
            self.fpdf.drawText("%-21s %-20s %-18s %-19s %-18s" % \
                ("", "Actual", "Budget", "Variance", "Last Year"))
            self.fpdf.drawText()
            m = self.s_per % 100
            for x in range(14):
                if x == 0:
                    mon = "Opening"
                elif x == 13:
                    mon = "Closing"
                else:
                    mon = mthnam[m][1]
                    m = m + 1
                    if m > 12:
                        m = m - 12
                act = self.df.c_disp[1][x][0]
                bud = self.df.c_disp[1][x][1]
                var = self.df.c_disp[1][x][2]
                lyr = self.df.c_disp[1][x][3]
                self.fpdf.drawText("%-15s %-20s %-20s %-20s %-20s" %
                                   (mon, act, bud, var, lyr))
                if x in (0, 12):
                    self.fpdf.drawText()
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.pr.repprt,
                      repeml=self.pr.repeml)
        else:
            trn = self.getTrans()
            if trn:
                heads = ["General Ledger Interrogation as at %s" % self.sysdtd]
                mthno, acctot = self.getObal()
                if mthno.work == 0:
                    x = "(For all months)"
                    d = self.opts["period"][1][0]
                else:
                    x = "(For month " + mthno.disp + ")"
                    d = (self.trnper * 100) + 1
                heads.append("Account %s %s %s" % (self.num, self.dsc, x))
                cols = [["glt_trdt", "D1", 10, "   Date"],
                        ["glt_refno", "Na", 9, "Reference"],
                        ["glt_type", "NA", 3, "Typ"],
                        ["glt_batch", "Na", 7, "BatchNo"],
                        ["debit", "SD", 13.2, "       Debit "],
                        ["credit", "SD", 13.2, "      Credit "],
                        ["balance", "SD", 13.2, "     Balance "],
                        ["glt_desc", "NA", 30, "Remarks"]]
                if acctot:
                    if acctot < 0:
                        dr = 0
                        cr = acctot
                    else:
                        dr = acctot
                        cr = 0
                    data = [(d, "B/Fwd", "", "", dr, cr, acctot,
                             "Opening Balance")]
                else:
                    data = []
                col = self.sql.gentrn_col
                for num, rec in enumerate(trn):
                    trdt = rec[col.index("glt_trdt")]
                    refno = rec[col.index("glt_refno")]
                    trtp = gltrtp[(rec[col.index("glt_type")]) - 1][0]
                    batch = rec[col.index("glt_batch")]
                    tramt = rec[col.index("glt_tramt")]
                    if tramt < 0:
                        debit = 0
                        credit = tramt
                    else:
                        debit = tramt
                        credit = 0
                    detail = rec[col.index("glt_desc")]
                    acctot = float(ASD(acctot) + ASD(tramt))
                    data.append((trdt, refno, trtp, batch, debit, credit,
                                 acctot, detail))
                RepPrt(self.opts["mf"],
                       name=self.__class__.__name__,
                       conum=self.opts["conum"],
                       conam=self.opts["conam"],
                       tables=data,
                       heads=heads,
                       cols=cols,
                       ttype="D",
                       repprt=self.pr.repprt,
                       repeml=self.pr.repeml)

    def doPrtExit(self):
        self.pr.closeProcess()

    def doPeriod(self, frt, pag, r, c, p, i, w):
        if w != 0 and (w < self.i_per or w > self.e_per):
            return "Invalid Period"
        self.trnper = w

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.pgnum += 1
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-34s %-10s %51s %5s" % \
            ("General Ledger Interrogation as at", self.sysdtd,
            "Page", self.pgnum))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 4

    def getObal(self):
        acbal = self.obal
        if self.trnper:
            o = self.sql.getRec("gentrn",
                                cols=["round(sum(glt_tramt), 2)"],
                                where=[("glt_cono", "=", self.opts["conum"]),
                                       ("glt_acno", "=", self.acno),
                                       ("glt_curdt", ">=", self.i_per),
                                       ("glt_curdt", "<", self.trnper)],
                                limit=1)
            if o[0]:
                acbal = float(ASD(acbal) + ASD(o[0]))
        mthno = CCD(self.trnper % 100, "UI", 2.0)
        return mthno, acbal

    def getTrans(self):
        odr = "glt_acno, glt_curdt, glt_trdt, glt_type, glt_refno, glt_batch"
        if not self.trnper:
            whr = [("glt_cono", "=", self.opts["conum"]),
                   ("glt_acno", "=", self.acno),
                   ("glt_curdt", "between", self.i_per, self.e_per)]
        else:
            whr = [("glt_cono", "=", self.opts["conum"]),
                   ("glt_acno", "=", self.acno),
                   ("glt_curdt", "=", self.trnper)]
        return self.sql.getRec("gentrn", where=whr, order=odr)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Ejemplo n.º 26
0
class gl3080(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, ["ctlctl", "genbal", "genmst",
            "gentrn", "genrct"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][2][0] / 100)
        t = time.localtime()
        self.c_per = (t[0] * 100) + t[1]
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
            "General Ledger Bank Reconciliation (%s)" % self.__class__.__name__)
        glm = {
            "stype": "R",
            "tables": ("ctlctl", "genmst"),
            "cols": (
                ("ctl_conacc", "", 0, "Acc-Num"),
                ("glm_desc", "", 0, "Description", "Y")),
            "where": [
                ("ctl_cono", "=", self.opts["conum"]),
                ("ctl_code", "like", "bank_%"),
                ("glm_cono=ctl_cono",),
                ("glm_acno=ctl_conacc",)]}
        fld = (
            (("T",0,0,0),"IUI",7,"Bank Account","",
                "","Y",self.doBankAcc,glm,None,("efld",)),
            (("T",0,1,0),"Id2",7,"Accounting Period","",
                self.c_per,"Y",self.doPer,None,None,("efld",)))
        tnd = ((self.doEnd,"y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"], title=self.tit, eflds=fld,
            tend=tnd, txit=txt, view=("N","V"), mail=("Y","N"))

    def doBankAcc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec(tables=["ctlctl", "genmst"], cols=["glm_desc"],
            where=[("glm_cono", "=", self.opts["conum"]), ("glm_acno", "=", w),
            ("ctl_cono=glm_cono",), ("ctl_conacc=glm_acno",), ("ctl_code",
            "like", "bank_%")], limit=1)
        if not acc:
            return "Invalid Bank Account Number"
        self.acno = w
        self.name = acc[0]

    def doPer(self, frt, pag, r, c, p, i, w):
        self.perw = w
        self.perd = self.df.t_disp[pag][r][p]

    def doEnd(self):
        self.df.closeProcess()
        self.extractBalance()
        self.sortPayments()
        self.sortReceipts()
        self.sortImports()
        self.printReport()
        self.closeProcess()

    def sortPayments(self):
        col = ["glt_trdt", "glt_refno", "glt_desc", "glt_tramt"]
        whr = [
            ("glt_cono", "=", self.opts["conum"]),
            ("glt_acno", "=", self.acno),
            ("glt_curdt", "<=", self.perw),
            ("(", "glt_recon", "=", 0, "or", "glt_recon", ">", self.perw, ")"),
            ("glt_type", "in", (2, 4))]
        odr = "glt_curdt, glt_trdt, glt_type, glt_refno, glt_batch"
        self.pays = self.sql.getRec("gentrn", cols=col, where=whr,
            order=odr)
        if not self.pays:
            self.pays = []

    def sortReceipts(self):
        col = ["glt_trdt", "glt_refno", "glt_desc", "glt_tramt"]
        whr = [
            ("glt_cono", "=", self.opts["conum"]),
            ("glt_acno", "=", self.acno),
            ("glt_curdt", "<=", self.perw),
            ("(", "glt_recon", "=", 0, "or", "glt_recon", ">", self.perw, ")"),
            ("glt_type", "=", 6)]
        odr = "glt_curdt, glt_trdt, glt_type, glt_refno, glt_batch"
        self.recs = self.sql.getRec("gentrn", cols=col, where=whr,
            order=odr)
        if not self.recs:
            self.recs = []

    def sortImports(self):
        dte = mthendDate((self.perw * 100) + 1)
        col = ["grt_date", "grt_refno", "grt_memo", "grt_amount"]
        whr = [
            ("grt_cono", "=", self.opts["conum"]),
            ("grt_acno", "=", self.acno),
            ("grt_date", "<=", dte),
            ("grt_flag", "=", "N")]
        odr = "grt_date, grt_refno"
        self.imps = self.sql.getRec("genrct", cols=col, where=whr,
            order=odr)
        if not self.imps:
            self.imps = []

    def printReport(self):
        p = ProgressBar(self.opts["mf"].body,
            mxs=(len(self.pays) + len(self.recs) + len(self.imps)))
        self.head = "%03u %-30s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=90)
        self.pglin = 999
        self.tot_chq = 0
        self.tot_dep = 0
        self.tot_imp = 0
        self.pageHeading()
        bal = CCD(self.bal, "SD", 13.2)
        self.fpdf.drawText("%-71s %-13s" % ("Balance as per Cash Book",
            bal.disp))
        if self.pays:
            self.fpdf.drawText()
            self.fpdf.drawText("%-70s" % ("Add: Cheques Not Presented",))
            self.fpdf.drawText()
            self.pglin += 4
            mxs = len(self.pays) - 1
            for num, pay in enumerate(self.pays):
                p.displayProgress(num)
                self.printLine(num, mxs, pay, "C")
            self.pglin += 1
        if self.recs:
            self.fpdf.drawText()
            self.fpdf.drawText("%-70s" % ("Less: Deposits Not Presented",))
            self.fpdf.drawText()
            self.pglin += 3
            mxs = len(self.recs) - 1
            for num, rec in enumerate(self.recs):
                p.displayProgress(len(self.pays) + num)
                self.printLine(num, mxs, rec, "D")
        # Bank Imports
        if self.imps:
            self.fpdf.drawText()
            self.fpdf.drawText("%-70s" % ("+-: Imports Not Captured",))
            self.fpdf.drawText()
            self.pglin += 3
            mxs = len(self.imps) - 1
            for num, rec in enumerate(self.imps):
                p.displayProgress(len(self.pays) + len(self.imps) + num)
                self.printLine(num, mxs, rec, "I")
        p.closeProgress()
        self.fpdf.underLine(txt="%72s%12s" % ("", 12 * self.fpdf.suc))
        b = float(ASD(self.bal) + ASD(self.tot_chq) - ASD(self.tot_dep) + \
            ASD(self.tot_imp))
        bal = CCD(b, "SD", 13.2)
        self.fpdf.drawText("%-71s %-13s" % ("Balance as per Bank Statement",
            bal.disp))
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
            self.__class__.__name__, self.opts["conum"], ext="pdf")
        self.fpdf.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
            pdfnam=pdfnam, header=self.tit, repprt=self.df.repprt,
            repeml=self.df.repeml)

    def printLine(self, num, mxs, dat, typ):
        trdt = CCD(dat[0], "D1", 10)
        refno = CCD(dat[1], "Na", 9)
        desc = CCD(dat[2], "NA", 30)
        if typ in ("D", "I"):
            amt = dat[3]
        else:
            amt = float(ASD(0) - ASD(dat[3]))
        tramt = CCD(amt, "SD", 13.2)
        if self.pglin > self.fpdf.lpp:
            self.pageHeading()
        if typ == "C":
            self.tot_chq = float(ASD(self.tot_chq) + ASD(tramt.work))
            if num == mxs:
                bal = CCD(self.tot_chq, "SD", 13.2)
        elif typ == "D":
            self.tot_dep = float(ASD(self.tot_dep) + ASD(tramt.work))
            if num == mxs:
                bal = CCD(self.tot_dep, "SD", 13.2)
        else:
            self.tot_imp = float(ASD(self.tot_imp) + ASD(tramt.work))
            if num == mxs:
                bal = CCD(self.tot_imp, "SD", 13.2)
        if num == mxs:
            self.fpdf.drawText("%-5s %-9s %-10s %-30s %-13s %-13s" % \
                ("", refno.disp, trdt.disp, desc.disp, tramt.disp, bal.disp))
        else:
            self.fpdf.drawText("%-5s %-9s %-10s %-30s %-13s" % \
                ("", refno.disp, trdt.disp, desc.disp, tramt.disp))
        self.pglin += 1

    def extractBalance(self):
        o = self.sql.getRec("genbal", cols=["glo_cyr"],
            where=[("glo_cono", "=", self.opts["conum"]), ("glo_acno",
            "=", self.acno), ("glo_trdt", "=", self.opts["period"][1][0])],
            limit=1)
        if o:
            b = CCD(o[0], "SD", 13.2)
        else:
            b = CCD(0, "SD", 13.2)
        self.bal = b.work
        o = self.sql.getRec("gentrn", cols=["round(sum(glt_tramt), 2)"],
            where=[("glt_cono", "=", self.opts["conum"]), ("glt_acno", "=",
            self.acno), ("glt_curdt", ">=", self.s_per), ("glt_curdt", "<=",
            self.perw)], limit=1)
        if o[0]:
            b = CCD(o[0], "SD", 13.2)
        else:
            b = CCD(0, "SD", 13.2)
        self.bal = float(ASD(self.bal) + ASD(b.work))

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("Bank Reconciliation for %s (%s) up to Period %s" %
            (self.name, self.acno, self.perd))
        self.fpdf.underLine()
        self.fpdf.setFont()
        self.pglin = 4

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 27
0
class sl3030(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, ["wagmst", "waglmf", "wagltf"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.fromad = wagctl["ctw_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.sysdtd = "%i/%02i/%02i" % (t[0], t[1], t[2])
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Staff Loans Master Listing (%s)" %
                    self.__class__.__name__)
        r1s = (("Number", "N"), ("Name", "M"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 1, "Sort Order", "", "N", "Y",
                self.doSort, None, None, None),
               (("T", 0, 1, 0), ("IRB", r2s), 1, "Ignore Zero Balances",
                "Ignore Zero Balances", "Y", "Y", self.doZero, None, None,
                None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

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

    def doZero(self, frt, pag, r, c, p, i, w):
        self.zero = w

    def doEnd(self):
        self.df.closeProcess()
        col = [
            "wlm_empno", "wgm_sname", "wgm_fname", "wlm_loan", "wlm_desc",
            "wlm_code", "wlm_start", "wlm_rate", "wlm_repay", "sum(wlt_amt)"
        ]
        whr = [("wlm_cono", "=", self.opts["conum"]), ("wlm_cono=wgm_cono", ),
               ("wlm_empno=wgm_empno", ), ("wlt_cono=wgm_cono", ),
               ("wlt_empno=wgm_empno", ), ("wlt_loan=wlm_loan", )]
        if self.sort == "N":
            odr = "wlm_empno, wlm_loan"
        else:
            odr = "wlm_sname, wlm_loan"
        recs = self.sql.getRec(tables=["waglmf", "wagmst", "wagltf"],
                               cols=col,
                               where=whr,
                               order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Transaction Error",
                      "No Transactions Selected")
        else:
            self.printReport(recs)
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-115s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        tot = 0
        self.pglin = 999
        for num, dat in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            emp = CCD(dat[0], "UI", 5)
            nam = CCD("%s, %s" % (dat[1], dat[2].split()[0]), "NA", 40)
            lon = CCD(dat[3], "UI", 2)
            des = CCD(dat[4], "NA", 20)
            cod = CCD(dat[5], "UI", 2)
            dte = CCD(dat[6], "d1", 10)
            per = CCD(dat[7], "UD", 6.2)
            ded = CCD(dat[8], "SD", 13.2)
            bal = CCD(dat[9], "SD", 13.2)
            if self.zero == "Y" and not bal.work:
                continue
            tot = float(ASD(tot) + ASD(bal.work))
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText(
                "%s %s %s %s %s %s %s %s %s" %
                (emp.disp, nam.disp, lon.disp, des.disp, cod.disp, dte.disp,
                 per.disp, ded.disp, bal.disp))
            self.pglin += 1
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            tot = CCD(tot, "SD", 13.2)
            self.fpdf.drawText()
            self.fpdf.drawText("%5s %-100s%s" % ("", "Total", tot.disp))
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                self.__class__.__name__,
                                self.opts["conum"],
                                ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"],
                      conum=self.opts["conum"],
                      pdfnam=pdfnam,
                      header=self.tit,
                      repprt=self.df.repprt,
                      fromad=self.fromad,
                      repeml=self.df.repeml)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-29s %-10s" % \
            ("Staff Loans Master List as at", self.sysdtd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-15s%-1s%-3s%-16s%-1s%-3s%-4s%-1s%-1s" % \
            ("(Options: Sort-", self.df.t_disp[0][0][0], "",
                "Ignore Zero Bal-", self.df.t_disp[0][0][1], "",
                "Csv-", self.df.t_disp[0][0][2], ")"))
        self.fpdf.drawText()
        self.fpdf.drawText("%-5s %-40s %-2s %-20s %-2s %-10s %-6s %-13s "\
            "%-13s" % ("EmpNo", "Name", "Ln", "Description", "Cd",
            "Start-Date", "I-Rate", "   Deduction", "     Balance"))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        self.opts["mf"].closeLoop()
Ejemplo n.º 28
0
class dr3030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["drsmst", "drstrn"],
                       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.fromad = drsctl["ctd_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Debtors Transactions Due For Payment (%s)" %
                    self.__class__.__name__)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            view = None
            mail = None
        else:
            view = ("N", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), "ID1", 10, "Payment Date", "", self.sysdtw,
                "Y", self.doPayDate, None, None, ("efld", )), )
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doPayDate(self, frt, pag, r, c, p, i, w):
        if w == 0:
            w = self.sysdtw
        self.pdatw = w
        self.pdatd = self.df.t_disp[0][0][0]
        self.df.loadEntry(frt, pag, p, data=self.pdatw)

    def doEnd(self):
        self.df.closeProcess()
        mst = self.sql.getRec("drsmst",
                              cols=["drm_chain", "drm_acno", "drm_name"],
                              where=[("drm_cono", "=", self.opts["conum"])],
                              order="drm_chain, drm_acno")
        if not mst:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Accounts Selected")
        else:
            self.printReport(mst)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def printReport(self, mst):
        p = ProgressBar(self.opts["mf"].body, mxs=len(mst), esc=True)
        self.head = "%03u %-71s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.ctots = [0, 0, 0]
        self.gtots = [0, 0, 0]
        self.pglin = 999
        for seq, rec in enumerate(mst):
            p.displayProgress(seq)
            if p.quit:
                break
            chn = CCD(rec[0], "UI", 3)
            acno = CCD(rec[1], "NA", 7)
            name = CCD(rec[2], "NA", 30)
            col, trns = getTrn(self.opts["mf"].dbm,
                               "drs",
                               whr=[("drt_cono", "=", self.opts["conum"]),
                                    ("drt_chain", "=", chn.work),
                                    ("drt_acno", "=", acno.work),
                                    ("drt_trdt", "<=", self.pdatw)],
                               neg=False,
                               zer="N")
            if not trns:
                continue
            if self.pglin == 999:
                self.pageHeading(chn.disp, acno.disp, name.disp)
            else:
                self.newAccount(chn.disp, acno.disp, name.disp)
            for trn in trns:
                ref1 = CCD(trn[col.index("drt_ref1")], "Na", 9)
                ref2 = CCD(trn[col.index("drt_ref2")], "Na", 9)
                trtp = CCD(trn[col.index("drt_type")], "UI", 1)
                trdt = CCD(trn[col.index("drt_trdt")], "d1", 10)
                tramt = CCD(trn[col.index("drt_tramt")], "SD", 13.2)
                paid = CCD(trn[col.index("paid")], "SD", 13.2)
                trbal = CCD(trn[col.index("balance")], "SD", 13.2)
                if self.pglin > self.fpdf.lpp:
                    self.pageHeading(chn.disp, acno.disp, name.disp)
                self.fpdf.drawText(
                    "%s %s %s %s %s %s %s" %
                    (ref1.disp, ref2.disp, drtrtp[trtp.work - 1][0], trdt.disp,
                     tramt.disp, paid.disp, trbal.disp))
                self.pglin += 1
                self.ctots[0] = float(ASD(self.ctots[0]) + ASD(tramt.work))
                self.ctots[1] = float(ASD(self.ctots[1]) + ASD(paid.work))
                self.ctots[2] = float(ASD(self.ctots[2]) + ASD(trbal.work))
                self.gtots[0] = float(ASD(self.gtots[0]) + ASD(tramt.work))
                self.gtots[1] = float(ASD(self.gtots[1]) + ASD(paid.work))
                self.gtots[2] = float(ASD(self.gtots[2]) + ASD(trbal.work))
            if self.fpdf.page:
                self.accountTotal()
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          fromad=self.fromad,
                          repeml=self.df.repeml)

    def pageHeading(self, chn, acno, name):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        self.fpdf.drawText("%-42s %-32s" % \
            ("Debtors Transactions Due For Payment as at", self.pdatd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-19s%-10s%-1s" % \
            ("(Options: Pay Date-", self.df.t_disp[0][0][0], ")"))
        self.fpdf.setFont()
        self.pglin = 5
        self.newAccount(chn, acno, name)

    def newAccount(self, chn, acno, name):
        if self.pglin > (self.fpdf.lpp - 10):
            self.pageHeading(chn, acno, name)
        else:
            self.fpdf.setFont(style="B")
            self.fpdf.underLine(txt=self.head)
            self.fpdf.drawText("%-7s %-3s %-7s %-30s" % \
                ("Account", chn, acno, name))
            self.fpdf.drawText()
            self.fpdf.drawText("%-9s %-9s %-3s %-10s %-13s %-13s %-13s" % \
                ("Reference", "Ref-Num-2", "Typ", "   Date",
                "      Amount", "        Paid", "     Balance"))
            self.fpdf.underLine(txt=self.head)
            self.fpdf.setFont()
            self.pglin += 5

    def accountTotal(self):
        j = CCD(self.ctots[0], "SD", 13.2)
        k = CCD(self.ctots[1], "SD", 13.2)
        l = CCD(self.ctots[2], "SD", 13.2)
        self.fpdf.drawText()
        self.fpdf.drawText("%-34s %-13s %13s %13s" % \
            ("Account Totals", j.disp, k.disp, l.disp))
        self.ctots = [0, 0, 0]
        self.pglin += 2

    def grandTotal(self):
        j = CCD(self.gtots[0], "SD", 13.2)
        k = CCD(self.gtots[1], "SD", 13.2)
        l = CCD(self.gtots[2], "SD", 13.2)
        self.fpdf.drawText()
        self.fpdf.drawText("%-34s %13s %-13s %13s" % \
            ("Grand Totals", j.disp, k.disp, l.disp))
        self.fpdf.drawText()

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 29
0
class si3030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["strgrp", "strloc", "strmf1"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        slsctl = gc.getCtl("slsctl", self.opts["conum"])
        if not slsctl:
            return
        self.fromad = slsctl["ctv_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Period Sales By Product Report (%s)" %
                    self.__class__.__name__)
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        if "args" in self.opts and "noprint" in self.opts["args"]:
            var = self.opts["args"]["work"][0]
            view = None
            mail = None
        else:
            var = ["", "", ""]
            view = ("N", "V")
            mail = ("Y", "N")
        fld = ((("T", 0, 0, 0), "ID2", 7, "Period", "", int(self.sysdtw / 100),
                "Y", self.doPer, None, None, ("efld", )),
               (("T", 0, 1, 0), "IUA", 1, "Location", "", var[1], "N",
                self.doLoc, loc, None, ("efld", )),
               (("T", 0, 2, 0), "IUA", 3, "Product Group", "", var[2], "N",
                self.doGroup, grp, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=view,
                               mail=mail)

    def doPer(self, frt, pag, r, c, p, i, w):
        if w < int(self.opts["period"][1][0] / 100) or \
                w > int(self.opts["period"][2][0] / 100):
            return "Invalid Period"
        self.per = w
        if self.locs == "N":
            self.loc = ""
            self.locd = "ALL"
            return "sk1"

    def doLoc(self, frt, pag, r, c, p, i, w):
        if not w:
            self.locd = "ALL"
        else:
            acc = self.sql.getRec("strloc",
                                  cols=["srl_desc"],
                                  where=[("srl_cono", "=", self.opts["conum"]),
                                         ("srl_loc", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Location"
            self.locd = "%s %s" % (w, acc[0])
        self.loc = w

    def doGroup(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.getGroup(w)
            if not acc:
                return "Invalid Group"
        self.grp = w

    def doEnd(self):
        self.df.closeProcess()
        if not self.grp:
            sgrp = ""
            egrp = "zzz"
        else:
            sgrp = egrp = self.grp
        recs = self.sql.getRec(
            "strmf1",
            cols=["st1_group", "st1_code", "st1_desc", "st1_uoi"],
            where=[("st1_cono", "=", self.opts["conum"]),
                   ("st1_group", ">=", sgrp), ("st1_group", "<=", egrp)],
            order="st1_group, st1_code")
        if not recs:
            showError(self.opts["mf"].body, "Processing Error",
                      "No Records Selected")
        else:
            self.printReport(recs)
        if "args" in self.opts and "noprint" in self.opts["args"]:
            self.t_work = [self.df.t_work[0][0]]
        self.closeProcess()

    def printReport(self, recs):
        p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True)
        self.head = "%03u %-108s" % (self.opts["conum"], self.opts["conam"])
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head)
        self.stot = [0] * 3
        self.gtot = [0] * 3
        lstgrp = ""
        self.pglin = 999
        for num, rec in enumerate(recs):
            p.displayProgress(num)
            if p.quit:
                break
            self.grp = CCD(rec[0], "UA", 3)
            code = CCD(rec[1], "NA", 20)
            desc = CCD(rec[2], "NA", 30)
            uoi = CCD(rec[3], "NA", 10)
            bals = Balances(self.opts["mf"],
                            "STR",
                            self.opts["conum"],
                            self.per,
                            keys=(self.grp.work, code.work, self.loc,
                                  ("P", self.opts["period"][0])))
            m_ob, m_mv, m_cb, y_ob, y_mv, y_cb, ac, lc, ls = bals.doStrBals()
            m_qty = 0
            m_cst = 0
            m_sls = 0
            for t, q, c, s in m_mv:
                if t == 7:
                    m_qty = q
                    m_cst = c
                    m_sls = s
                    break
            mq = CCD(float(ASD(0) - ASD(m_qty)), "SD", 13.2)
            mc = CCD(float(ASD(0) - ASD(m_cst)), "SD", 13.2)
            ms = CCD(float(ASD(0) - ASD(m_sls)), "SD", 13.2)
            mp = float(ASD(ms.work) - ASD(mc.work))
            mp = CCD(mp, "SD", 13.2)
            if ms.work == 0:
                mn = 0
            else:
                mn = round((mp.work * 100.0 / ms.work), 2)
            mn = CCD(mn, "SD", 7.2)
            if mq.work == 0 and mc.work == 0 and ms.work == 0:
                continue
            if lstgrp and lstgrp != self.grp.work:
                self.groupTotal()
                self.pglin = 999
            if self.pglin > self.fpdf.lpp:
                self.pageHeading()
            self.fpdf.drawText("%s %s %s %s %s %s %s" %
                               (code.disp, desc.disp, uoi.disp, mq.disp,
                                ms.disp, mp.disp, mn.disp))
            self.stot[0] = float(ASD(self.stot[0]) + ASD(mq.work))
            self.stot[1] = float(ASD(self.stot[1]) + ASD(ms.work))
            self.stot[2] = float(ASD(self.stot[2]) + ASD(mp.work))
            self.gtot[0] = float(ASD(self.gtot[0]) + ASD(mq.work))
            self.gtot[1] = float(ASD(self.gtot[1]) + ASD(ms.work))
            self.gtot[2] = float(ASD(self.gtot[2]) + ASD(mp.work))
            self.pglin += 1
            lstgrp = self.grp.work
        p.closeProgress()
        if self.fpdf.page and not p.quit:
            self.groupTotal()
            self.grandTotal()
            if "args" not in self.opts or "noprint" not in self.opts["args"]:
                pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                                    self.__class__.__name__,
                                    self.opts["conum"],
                                    ext="pdf")
                self.fpdf.output(pdfnam, "F")
                doPrinter(mf=self.opts["mf"],
                          conum=self.opts["conum"],
                          pdfnam=pdfnam,
                          header=self.tit,
                          repprt=self.df.repprt,
                          fromad=self.fromad,
                          repeml=self.df.repeml)

    def pageHeading(self):
        self.fpdf.add_page()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText(self.head)
        self.fpdf.drawText()
        per = CCD(self.per, "D2", 7)
        self.fpdf.drawText("%-27s %-7s" % \
            ("Period Sales By Product for", per.disp))
        self.fpdf.drawText()
        acc = self.getGroup(self.grp.work)
        if acc:
            grpd = acc[0]
        else:
            grpd = "Missing Group Record"
        self.fpdf.drawText("%s %s %s    %s %s" % \
            ("Group:", self.grp.disp, grpd, "Location:", self.locd))
        self.fpdf.drawText()
        self.fpdf.drawText("%-20s %-30s %-10s %13s %13s %13s %7s" % \
            ("Product-Code", "Description", "U.O.I",
            "Quantity ", "Value ", "Profit ", "Prft-% "))
        self.fpdf.underLine(txt=self.head)
        self.fpdf.setFont()
        self.pglin = 8

    def getGroup(self, grp):
        acc = self.sql.getRec("strgrp",
                              cols=["gpm_desc"],
                              where=[("gpm_cono", "=", self.opts["conum"]),
                                     ("gpm_group", "=", grp)],
                              limit=1)
        return acc

    def groupTotal(self):
        self.fpdf.drawText()
        mq = CCD(self.stot[0], "SD", 13.2)
        ms = CCD(self.stot[1], "SD", 13.2)
        mp = CCD(self.stot[2], "SD", 13.2)
        if ms.work == 0:
            mn = 0
        else:
            mn = round((mp.work * 100.0 / ms.work), 2)
        mn = CCD(mn, "SD", 7.2)
        self.fpdf.drawText("%-20s %-41s %s %s %s %s" % \
            ("", "Group Totals", mq.disp, ms.disp, mp.disp, mn.disp))
        self.stot = [0] * 3

    def grandTotal(self):
        self.fpdf.drawText()
        mq = CCD(self.gtot[0], "SD", 13.2)
        ms = CCD(self.gtot[1], "SD", 13.2)
        mp = CCD(self.gtot[2], "SD", 13.2)
        if ms.work == 0:
            mn = 0
        else:
            mn = round((mp.work * 100.0 / ms.work), 2)
        mn = CCD(mn, "SD", 7.2)
        self.fpdf.drawText("%-20s %-41s %s %s %s %s" % \
            ("", "Grand Totals", mq.disp, ms.disp, mp.disp, mn.disp))

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

    def closeProcess(self):
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Ejemplo n.º 30
0
class wg3050(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, [
            "ctlsys", "ctlmst", "wagctl", "wagedc", "wagmst", "wagirp",
            "wagtf2", "wagrcv", "wagtxa", "wagtxr", "wagtf1"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.fromad = wagctl["ctw_emadd"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        ctc = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        ctw = self.sql.getRec("wagctl",
                              where=[("ctw_cono", "=", self.opts["conum"])],
                              limit=1)
        if not ctc or not ctw:
            return
        self.coad1 = ctc[self.sql.ctlmst_col.index("ctm_add1")]
        self.coad2 = ctc[self.sql.ctlmst_col.index("ctm_add2")]
        self.coad3 = ctc[self.sql.ctlmst_col.index("ctm_add3")]
        try:
            self.cocod = int(ctc[self.sql.ctlmst_col.index("ctm_pcode")])
        except:
            self.cocod = 0
        self.cname = ctc[self.sql.ctlmst_col.index("ctm_contact")]
        self.cotel = ctc[self.sql.ctlmst_col.index("ctm_tel")]
        self.coeml = ctc[self.sql.ctlmst_col.index("ctm_email")].strip()
        try:
            self.regno = int(ctw[self.sql.wagctl_col.index("ctw_regno")])
        except:
            return
        self.sdlno = ctw[self.sql.wagctl_col.index("ctw_sdlno")]
        self.uifno = ctw[self.sql.wagctl_col.index("ctw_uifno")]
        self.trade = ctw[self.sql.wagctl_col.index("ctw_trade")]
        self.codip = ctw[self.sql.wagctl_col.index("ctw_irp_dip")]
        self.totrecs = 0
        self.totcode = 0
        self.totamnt = 0
        self.pdfnam = None
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
                    "Salaries IRP5 Statements (%s)" % self.__class__.__name__)
        wgm = {
            "stype":
            "R",
            "tables": ("wagmst", ),
            "cols":
            (("wgm_empno", "", 0, "EmpNo"), ("wgm_sname", "", 0, "Surname"),
             ("wgm_fname", "", 0, "Names"), ("wgm_start", "", 0, "Start-Date"),
             ("wgm_term", "", 0, "Term-Date"))
        }
        r1s = (("Live", "L"), ("Test", "T"))
        r2s = (("Yes", "Y"), ("No", "N"))
        r3s = (("Yes", "Y"), ("Range", "R"), ("Singles", "S"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Submission Type", "", "T",
                "Y", self.doType, None, None, None),
               (("T", 0, 1,
                 0), "IUI", 4, "Tax Year", "", 0, "Y", self.doYear, None, None,
                ("notzero", )), (("T", 0, 2, 0), "ID1", 10, "Cut Off Date", "",
                                 0, "N", self.doDate, None, None, ("efld", )),
               (("T", 0, 3, 0), ("IRB", r2s), 0, "Reprint",
                "Reprint Statements", "Y", "Y", self.doReprint, None, None,
                None), (("T", 0, 4, 0), ("IRB", r2s), 0, "Preview",
                        "Preview Only", "Y", "Y", self.doPreview, None, None,
                        None), (("T", 0, 5, 0), ("IRB", r3s), 0, "Whole File",
                                "", "S", "Y", self.doWhole, None, None, None),
               (("T", 0, 6, 0), ("IRB", r2s), 10, "Include Other Companies",
                "", "N", "N", self.doCoy, None, None,
                None), (("T", 0, 7, 0), "IUI", 5, "From Employee", "", "", "Y",
                        self.doEmp, wgm, None, None),
               (("T", 0, 8, 0), "IUI", 5, "To   Employee", "To Employee", "",
                "Y", self.doEmp, wgm, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               title=self.tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "P"),
                               mail=("B", "Y"))

    def doType(self, frt, pag, r, c, p, i, w):
        if w == "L":
            self.rtype = "LIVE"
        else:
            self.rtype = "TEST"

    def doYear(self, frt, pag, r, c, p, i, w):
        self.taxyr = w
        self.allow, self.rates = payeTables(self.sql, self.taxyr)
        if not self.allow or not self.rates:
            showError(self.opts["mf"].body, "Missing Rates",
                      "There are No Tax Rates for Year %s" % self.taxyr)
            self.doExit()
        self.sdate = CCD(((self.taxyr - 1) * 10000) + 301, "D1", 10)
        if self.taxyr % 4:
            self.edate = (self.taxyr * 10000) + 200 + 28
        else:
            self.edate = (self.taxyr * 10000) + 200 + 29
        if self.sysdtw < self.edate:
            self.edate = self.sysdtw
        self.edate = CCD(self.edate, "D1", 10)
        self.uifr = float(ASD(self.allow[5]) + ASD(self.allow[6]))
        self.sdlr = float(ASD(self.allow[7]) + ASD(self.allow[8]))
        self.df.loadEntry(frt, pag, p + 1, data=self.edate.work)

    def doDate(self, frt, pag, r, c, p, i, w):
        yr = int(w / 10000)
        if yr < (self.taxyr - 1) or yr > self.taxyr:
            return "Invalid Date"
        self.taxmth = int(w / 100) % 100
        if self.taxmth < 3 and yr < self.taxyr:
            return "Invalid Date"
        if self.taxmth > 2 and yr == self.taxyr:
            return "Invalid Date"
        self.edate = CCD(w, "D1", 10)
        whr = [("wgm_cono", "=", self.opts["conum"]),
               ("wgm_start", "<", self.edate.work),
               ("(", "wgm_term", "=", 0, "or", "wgm_term", ">=",
                self.sdate.work, ")")]
        self.df.topf[0][7][8]["where"] = whr
        self.df.topf[0][8][8]["where"] = whr

    def doReprint(self, frt, pag, r, c, p, i, w):
        self.reprint = w
        seq = self.sql.getRec("wagirp",
                              cols=["max(wip_irpno)"],
                              where=[("wip_cono", "=", self.opts["conum"])],
                              limit=1)
        if not seq[0]:
            self.lastreg = 0
            self.lastirp = 0
        else:
            self.lastirp = seq[0]
            reg = self.sql.getRec("wagirp",
                                  cols=["wip_genno"],
                                  where=[("wip_cono", "=", self.opts["conum"]),
                                         ("wip_irpno", "=", self.lastirp)],
                                  limit=1)
            self.lastreg = reg[0]
        if self.reprint == "Y":
            self.preview = "Y"
            self.df.loadEntry("T", 0, p + 1, data=self.preview)
            return "sk1"

    def doPreview(self, frt, pag, r, c, p, i, w):
        self.preview = w

    def doWhole(self, frt, pag, r, c, p, i, w):
        self.whole = w
        if self.whole in ("Y", "S"):
            self.semp = 0
            self.eemp = 0
            self.df.loadEntry("T", 0, p + 2, data=self.semp)
            self.df.loadEntry("T", 0, p + 3, data=self.eemp)
            if self.whole == "S":
                self.other = "N"
                self.df.loadEntry("T", 0, p + 1, data=self.other)
                return "sk3"
        else:
            self.other = "N"
            self.df.loadEntry("T", 0, p + 1, data=self.other)
            return "sk1"

    def doCoy(self, frt, pag, r, c, p, i, w):
        self.other = w
        return "sk2"

    def doEmp(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("wagmst",
                              cols=["wgm_sname"],
                              where=[("wgm_cono", "=", self.opts["conum"]),
                                     ("wgm_empno", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Employee Number"
        if p == 7:
            self.semp = w
        else:
            self.eemp = w

    def doEnd(self):
        self.df.closeProcess()
        self.emldf = self.df.repeml[2]
        self.error = False
        self.doWriteHeader()
        if self.error:
            self.opts["mf"].dbm.rollbackDbase()
            self.closeProcess()
            return
        if self.df.repeml[1] == "N":
            self.printSetup()
        if not self.eemp:
            self.eemp = 99999
        if self.other == "Y":
            self.doSelCoy()
            if self.con == "X":
                return
            whr = [("wgm_cono", "in", tuple(self.con))]
        else:
            whr = [("wgm_cono", "=", self.opts["conum"])]
        whr.extend([("wgm_empno", "between", self.semp, self.eemp),
                    ("wgm_paye", "=", "Y"),
                    ("wgm_start", "<=", self.edate.work),
                    ("(", "wgm_term", "=", 0, "or", "wgm_term", ">",
                     self.sdate.work, ")")])
        if self.whole == "S":
            recs = getSingleRecords(self.opts["mf"],
                                    "wagmst", ("wgm_empno", "wgm_sname"),
                                    where=whr)
        else:
            recs = self.sql.getRec("wagmst",
                                   where=whr,
                                   order="wgm_cono, wgm_empno")
        if not recs:
            showError(self.opts["mf"].body, "Error", "No Employees Selected")
        else:
            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)
                if self.error:
                    break
            p.closeProgress()
            if p.quit or self.error:
                self.opts["mf"].dbm.rollbackDbase()
            else:
                # Employer Total
                total = CCD(self.totamnt, "UD", 15.2)
                self.irp5fl.write('6010,%015i,6020,%015i,6030,%015.2f,9999\n' \
                    % (self.totrecs, self.totcode, total.work))
                self.irp5fl.close()
                self.doCheckTotals()
                if self.error:
                    self.opts["mf"].dbm.rollbackDbase()
                else:
                    if self.preview == "Y":
                        self.opts["mf"].dbm.rollbackDbase()
                    else:
                        self.opts["mf"].dbm.commitDbase()
                    if self.df.repeml[1] == "N" or self.emldf:
                        self.df.repeml[2] = self.emldf
                        self.doPrint()
        self.closeProcess()

    def doWriteHeader(self):
        # Header Record
        if self.reprint == "N" or not self.lastreg:
            self.lastreg += 1
        self.irp5nm = os.path.join(
            self.opts["mf"].rcdic["wrkdir"],
            "irp5fl_%03i_%04i.txt" % (self.opts["conum"], self.taxyr))
        self.irp5fl = open(self.irp5nm, "w")
        # Employer Details
        try:
            recon = int("%4i%02i" % (self.taxyr, self.taxmth))
            self.irp5fl.write('2010,"%s",2015,"%4s",2020,%010i,2022,"%-10s",'\
                '2024,"%-10s",2025,"%s",2026,"%s",2027,"%s",2028,"tartan",'\
                '2030,%04i,2031,%06i,2035,%04i,2064,"%s",2065,"%s",2066,"%s",'\
                '2080,%04i,9999\n' % (self.opts["conam"].strip(), self.rtype,
                self.regno, self.sdlno, self.uifno, self.cname.strip(),
                self.cotel[:11].strip(), self.coeml, self.taxyr, recon,
                self.trade, self.coad1[:24].strip(), self.coad2.strip(),
                self.coad3[:21].strip(), self.cocod))
            self.totrecs += 1
            for code in (2010, 2015, 2020, 2022, 2024, 2025, 2026, 2027, 2028,
                         2030, 2031, 2035, 2064, 2065, 2066, 2080, 9999):
                self.totcode += code
        except Exception as err:
            showError(None, "Header Record Error", "There is a Problem "\
                "with your Company or Control Records, Please Fix the "\
                "Problem and then Reprint\n\n%s" % err)
            self.error = True

    def doSelCoy(self):
        tit = ("Company Selection", )
        self.coys = self.sql.getRec("ctlmst",
                                    cols=["ctm_cono", "ctm_name"],
                                    order="ctm_cono")
        coy = {
            "stype": "C",
            "titl": "",
            "head": ("Num", "Name"),
            "data": self.coys,
            "mode": "M",
            "comnd": self.doCoyCmd
        }
        r1s = (("Yes", "Y"), ("Include", "I"), ("Exclude", "E"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "All Companies", "", "Y", "N",
                self.doAllCoy, None, None, None, None),
               (("T", 0, 1, 0), "INA", 30, "Companies", "", "", "N",
                self.doCoySel, coy, None, None, None))
        self.cf = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=((self.doCoyEnd, "y"), ),
                               txit=(self.doCoyExit, ))
        self.cf.mstFrame.wait_window()

    def doAllCoy(self, frt, pag, r, c, p, i, w):
        self.con = w
        if self.con == "Y":
            self.con = []
            for coy in self.coys:
                self.con.append(coy[0])
            return "nd"
        elif self.con == "I":
            self.cf.topf[pag][2][8]["titl"] = "Select Companies to Include"
        else:
            self.cf.topf[pag][2][8]["titl"] = "Select Companies to Exclude"

    def doCoyCmd(self, frt, pag, r, c, p, i, w):
        c = ""
        for co in w:
            if int(co[0]):
                c = c + str(int(co[0])) + ","
        if len(c) > 1:
            c = c[:-1]
        self.cf.loadEntry(frt, pag, p, data=c)

    def doCoySel(self, frt, pag, r, c, p, i, w):
        if w[-1:] == ",":
            w = w[:-1]
        self.coy = w.split(",")

    def doCoyEnd(self):
        if self.con == "I":
            self.con = self.coy
        elif self.con == "E":
            self.con = []
            for co in self.coys:
                self.con.append(int(co[0]))
            for co in self.coy:
                del self.con[self.con.index(int(co))]
            self.con.sort()
        self.doCoyClose()

    def doCoyExit(self):
        self.con = "X"
        self.doCoyClose()

    def doCoyClose(self):
        self.cf.closeProcess()

    def doProcess(self, wgm):
        col = self.sql.wagmst_col
        self.com = wgm[col.index("wgm_cono")]
        self.emp = wgm[col.index("wgm_empno")]
        if self.reprint == "N":
            chk = self.sql.getRec("wagirp",
                                  cols=["wip_irpno"],
                                  where=[("wip_cono", "=", self.com),
                                         ("wip_empno", "=", self.emp),
                                         ("wip_year", "=", self.taxyr)],
                                  limit=1)
            if chk:
                return
        self.sname = wgm[col.index("wgm_sname")]
        fname = wgm[col.index("wgm_fname")].split()
        if len(fname) == 1:
            self.fname = fname[0]
        else:
            self.fname = "%s %s" % (fname[0], fname[1])
        self.inits = ""
        for i in fname:
            self.inits = self.inits + i[0]
        self.nature = wgm[col.index("wgm_nature")]
        try:
            self.idno = int(wgm[col.index("wgm_idno")])
        except:
            self.idno = 0
        self.dob = CCD(wgm[col.index("wgm_dob")], "D1", 10)
        self.emadd = wgm[col.index("wgm_emadd")].strip()
        self.addr1 = wgm[col.index("wgm_addr1")]
        self.addr2 = wgm[col.index("wgm_addr2")]
        self.addr3 = wgm[col.index("wgm_addr3")]
        try:
            self.pcode = int(wgm[col.index("wgm_pcode")])
        except:
            self.pcode = 0
        self.taxno = CCD(wgm[col.index("wgm_taxno")], "NA", 10)
        self.start = CCD(wgm[col.index("wgm_start")], "D1", 10)
        if self.start.work < self.sdate.work:
            self.start = self.sdate
        self.term = CCD(wgm[col.index("wgm_term")], "D1", 10)
        if not self.term.work:
            self.term = self.edate
        self.freq = wgm[col.index("wgm_freq")]
        # Test number with modulus 10
        if self.taxno.work and len(self.taxno.work) == 10:
            paye10 = 0
            for x in range(0, 9, 2):
                paye10b = int(self.taxno.work[x]) * 2
                paye10 = paye10 + int(paye10b / 10) + (paye10b % 10)
                if x < 8:
                    paye10 = paye10 + int(self.taxno.work[(x + 1)])
            paye10 = paye10 % 10
            paye10 = 10 - paye10
            if paye10 != int(self.taxno.work[9]):
                self.taxno = CCD("0000000000", "NA", 10)
        else:
            self.taxno = CCD("0000000000", "NA", 10)
        #
        self.vol = wgm[col.index("wgm_vol_over")]
        rate = CCD(wgm[col.index("wgm_fix_rate")], "UD", 6.2)
        if rate.work:
            self.fixed = "Y"
        else:
            self.fixed = "N"
        self.direct = wgm[col.index("wgm_direct")]
        self.btype = wgm[col.index("wgm_btype")]
        self.bname = wgm[col.index("wgm_bname")]
        self.branch = wgm[col.index("wgm_bbranch")]
        self.bacno = wgm[col.index("wgm_bacno")]
        self.payee = wgm[col.index("wgm_bpayee")]
        self.relate = wgm[col.index("wgm_relate")]
        # Extract all transactions
        wt1 = self.sql.getRec("wagtf1",
                              cols=["sum(wt1_uifpay)", "sum(wt1_sdlpay)"],
                              where=[("wt1_cono", "=", self.com),
                                     ("wt1_empno", "=", self.emp),
                                     ("wt1_date", "between", self.sdate.work,
                                      self.edate.work)],
                              limit=1)
        self.uifpay, self.sdlpay = wt1
        wt2 = self.sql.getRec(tables=["wagtf2", "wagedc"],
                              cols=[
                                  "wt2_type", "ced_ror", "ced_taxcode",
                                  "round(sum(wt2_eamt), 2)"
                              ],
                              where=[("wt2_cono", "=", self.com),
                                     ("wt2_empno", "=", self.emp),
                                     ("wt2_date", "between",
                                      self.sdate.work, self.edate.work),
                                     ("ced_cono=wt2_cono", ),
                                     ("ced_type=wt2_type", ),
                                     ("ced_code=wt2_code", ),
                                     ("ced_ror", "between", 3601, 4103)],
                              group="wt2_type, ced_ror, ced_taxcode",
                              order="wt2_type desc, ced_ror")
        if wt2:
            if self.df.repeml[1] == "Y":
                self.printSetup()
            self.printHeader()
            if self.error:
                return
            # Retirement Funding
            self.rfund = "N"
            for trn in wt2:
                if trn[1] in (4001, 4002, 4003, 4004):
                    self.rfund = "Y"
            #
            trtp = None
            for trn in wt2:
                chk = self.sql.getRec("wagrcv",
                                      cols=["rcv_desc"],
                                      where=[("rcv_code", "=", trn[1])],
                                      limit=1)
                if not chk:
                    showError(
                        self.opts["mf"].body, "Invalid Code",
                        """This Receiver of Revenue Code (%s) Does Not Exist.

Please Amend the Earnings or Deduction Codes containing It and then Try Again."""
                        % trn[1])
                    break
                trn.insert(3, chk[0])
                if trn[0] == "E":
                    trtp = self.doEarningCode(trtp, trn)
                else:
                    if trtp == "E":
                        self.printGross()
                    if trn[1] < 4101:
                        trtp = self.doDeductionCode(trtp, trn)
                    elif trn[1] == 4102:
                        trtp = "T"
                        site = self.doSite()
                        self.printTax(site, trn)
            if trtp == "E":
                self.printGross()
            if trtp != "T" and self.ttyp == "IT3(a)":
                self.printTax()
            if self.preview == "N":
                self.sql.insRec("wagirp",
                                data=[
                                    self.opts["conum"], self.taxyr,
                                    self.lastreg, self.emp, self.lastirp
                                ])
            if self.df.repeml[1] == "Y" and not self.emldf:
                self.df.repeml[2] = self.emadd
                self.doPrint()

    def doEarningCode(self, trtp, trn):
        if not trtp:
            self.fpdf.setFont(style="B")
            self.fpdf.drawText("Income Sources")
            self.fpdf.drawText("Code    Description              "\
                "                        R/F-Ind         Amount")
            self.fpdf.setFont()
        # Earning Codes 3601-3617, 3651-3667, 3701-3718, 3751-3768
        # 3801-3816, 3851-3866, 3901-3922, 3951-3957
        trtp = "E"
        if trn[1] == 3601:
            rfund = self.rfund
        else:
            rfund = "N"
        if trn[1] == 3810:
            trn[4] = round((trn[4] / 3), 2)
        self.fpdf.drawText("%-4s    %-50s  %1s         %9s" % \
            (trn[1], trn[3], rfund, int(trn[4])))
        self.emprec = '%s,%04i,%015i' % (self.emprec, trn[1], int(trn[4]))
        self.totcode += trn[1]
        if trn[1] in (3602, 3604, 3609, 3612, 3703, 3705, 3709, 3714):
            # Non Taxable Income
            self.totntax = self.totntax + int(trn[4])
        else:
            if trn[2] == "O":
                # Annual Payment
                self.totannp = self.totannp + int(trn[4])
            if rfund == "Y":
                # Retirement Funding
                self.totyrfi = self.totyrfi + int(trn[4])
            else:
                self.totnrfi = self.totnrfi + int(trn[4])
            self.totincm = self.totincm + int(trn[4])
        self.totamnt = float(ASD(self.totamnt) + ASD(int(trn[4])))
        return trtp

    def doDeductionCode(self, trtp, trn):
        if trtp in (None, "E"):
            self.fpdf.setFont(style="B")
            self.fpdf.drawText("Deductions")
            self.fpdf.drawText("Code    Description              "\
                "                        Clearance       Amount")
            self.fpdf.setFont()
        # Deduction Codes 4001-4007, 4018, 4024, 4026, 4030, 4474, 4493, 4497
        trtp = "D"
        self.fpdf.drawText("%-4s    %-50s  %1s         %9s" % \
            (trn[1], trn[3], "N", int(trn[4])))
        self.emprec = '%s,%04i,%015i' % (self.emprec, trn[1], int(trn[4]))
        self.totcode += trn[1]
        self.totamnt = float(ASD(self.totamnt) + ASD(int(trn[4])))
        return trtp

    def doSite(self):
        inc = round((self.allow[4] * self.base / self.pers), 4)
        tax = 0
        for lvl in self.rates:
            if inc > lvl[0]:
                tax = round(lvl[1] + (((inc - lvl[0] + 1) * lvl[2]) / 100.0),
                            2)
            if tax:
                break
        tax = float(ASD(tax) - ASD(self.allow[0]))
        age = dateDiff(self.dob.work, self.edate.work, "years")
        if age > 64:
            tax = float(ASD(tax) - ASD(self.allow[1]))
        if age > 74:
            tax = float(ASD(tax) - ASD(self.allow[2]))
        tax = round((tax * self.pers / self.base), 2)
        if tax < 0:
            return 0
        else:
            return tax

    def doCheckTotals(self):
        csvrdr = csv.reader(open(self.irp5nm, "r"),
                            delimiter=",",
                            quotechar='"',
                            quoting=csv.QUOTE_MINIMAL)
        empls = 0
        count = 0
        total = 0
        empcd = (2010, 3010)
        totcd = (4472, 4473, 4474, 4485, 4486, 4487, 4493, 4497)
        fincd = (6010, 6020, 6030)
        check = {}
        for line in csvrdr:
            for num in range(0, len(line), 2):
                if int(line[0]) in fincd:
                    if int(line[num]) != 9999:
                        if int(line[num]) in (6010, 6020):
                            check["C%s" % line[num]] = int(line[num + 1])
                        else:
                            check["C%s" % line[num]] = float(line[num + 1])
                elif int(line[num]) == 9999:
                    count += int(line[num])
                else:
                    if int(line[num]) in empcd:
                        empls += 1
                    count += int(line[num])
                    if int(line[num]) > 3600 and int(line[num]) < 4150:
                        total += float(line[num + 1])
                    elif int(line[num]) in totcd:
                        total += float(line[num + 1])
        check["C6010"] -= empls
        check["C6020"] -= count
        check["C6030"] = float(ASD(check["C6030"]) - ASD(total))
        if check["C6010"] or check["C6020"] or check["C6030"]:
            showError(None, "Total Error", "There is a Problem "\
                "with Totals Record. Please Contact Your IT Manager.")
            self.error = True

    def printSetup(self):
        pth = self.opts["mf"].rcdic["wrkdir"]
        if self.df.repeml[1] == "Y":
            key = "%s_%s" % (self.com, self.emp)
            self.pdfnam = getModName(pth,
                                     self.__class__.__name__,
                                     key,
                                     ext="pdf")
        elif not self.pdfnam:
            self.pdfnam = getModName(pth,
                                     self.__class__.__name__,
                                     self.opts["conum"],
                                     ext="pdf")
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=90)

    def printHeader(self):
        self.fpdf.add_page()
        # Employee Totals
        self.totannp = 0
        self.totntax = 0
        self.totntax = 0
        self.totyrfi = 0
        self.totnrfi = 0
        self.totincm = 0
        # Calculate Pay Periods
        if self.freq == "M":
            self.base = 12
            y1 = int(self.term.work / 10000)
            y2 = int(self.start.work / 10000)
            m1 = int((self.term.work - (y1 * 10000)) / 100)
            m2 = int((self.start.work - (y2 * 10000)) / 100)
            self.pers = 1 + ((y1 - y2) * self.base) + (m1 - m2)
            while self.pers > self.base:
                self.pers = self.pers - self.base
        else:
            days = dateDiff(self.start.work, self.term.work, "days")
            if self.freq == "W":
                per = 7
                self.base = 52
            else:
                per = 14
                self.base = 26
            self.pers = int(days / per)
            if days % per > 0:
                self.pers = self.pers + 1
            if self.pers > self.base:
                self.pers = self.base
        # Extract PAYE Paid
        tax = self.sql.getRec(tables=["wagtf2", "wagedc"],
                              cols=["round(sum(wt2_eamt), 2)"],
                              where=[("wt2_cono", "=", self.com),
                                     ("wt2_empno", "=", self.emp),
                                     ("wt2_date", "between",
                                      self.sdate.work, self.edate.work),
                                     ("ced_cono=wt2_cono", ),
                                     ("ced_type=wt2_type", ),
                                     ("ced_code=wt2_code", ),
                                     ("ced_ror", "=", 4102)])
        if tax[0][0]:
            self.tax = CCD(tax[0][0], "UD", 12.2)
        else:
            self.tax = CCD(0, "UD", 12.2)
        if self.tax.work:
            self.ttyp = "IRP 5"
        else:
            self.ttyp = "IT3(a)"
        #
        if self.reprint == "Y":
            acc = self.sql.getRec("wagirp",
                                  cols=["wip_irpno"],
                                  where=[("wip_cono", "=", self.opts["conum"]),
                                         ("wip_year", "=", self.taxyr),
                                         ("wip_empno", "=", self.emp)],
                                  limit=1)
            if not acc:
                self.lastirp += 1
            else:
                self.lastirp = acc[0]
        else:
            self.lastirp += 1
        irp5 = CCD(self.lastirp, "UI", 10)
        self.irp5 = "%010i%4i%2i%014i" % (self.regno, self.taxyr, self.taxmth,
                                          self.lastirp)
        # Print Fields
        self.fpdf.drawText()
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("%6s                    EMPLOYEES TAX "\
            "CERTIFICATE                      %6s" % (self.ttyp, self.ttyp))
        self.fpdf.drawText()
        self.fpdf.drawText("Employer Information")
        self.fpdf.setFont(size=8)
        self.fpdf.drawText("Trading Name      %-30s" % self.opts["conam"])
        self.fpdf.drawText("IRP 5 Number      %s                   "\
            "   Business Address  %30s" % (irp5.disp, self.coad1))
        self.fpdf.drawText("Reference No.     %10s                 "\
            "                       %30s" % (self.regno, self.coad2))
        self.fpdf.drawText("Tax Year          %s                       "\
            "                       %30s" % (self.taxyr, self.coad3))
        self.fpdf.drawText("Dipl. Immunity    %1s                          "\
            "                       %30s" % (self.codip, self.cocod))
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Employee Information")
        self.fpdf.setFont(size=8)
        self.fpdf.drawText("Nature of Person  %1s                          "\
            "     Employee Surname  %30s" % (self.nature, self.sname))
        self.fpdf.drawText("First Two Names   %-30s  "\
            "Employee Initials %s" % (self.fname, self.inits))
        self.fpdf.drawText("Identity Number   %13s              "\
            "     Residential Addr  %30s" % (self.idno, self.addr1))
        self.fpdf.drawText("Passport Number                              "\
            "                       %30s" % self.addr2)
        self.fpdf.drawText("Date of Birth     %s                 "\
            "                       %30s" % (self.dob.disp, self.addr3))
        self.fpdf.drawText("Company/CC/Trust                             "\
            "                       %30s" % self.pcode)
        self.fpdf.drawText("Income Tax Number %s" % self.taxno.disp)
        self.fpdf.drawText("                                             "\
            "     Employee Number   %5s" % self.emp)
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Tax Calculation Information")
        self.fpdf.setFont(size=8)
        self.fpdf.drawText("Employed From  %s        Employed To    %s"\
            "        Voluntary Over-Deduction  %1s" % (self.start.disp,
            self.term.disp, self.vol))
        self.fpdf.drawText("Periods in Year  %08.4f        Periods Worked"\
            "   %08.4f        Fixed Rate %s Directive %13s" % (self.base,
            self.pers, self.fixed, self.direct))
        self.fpdf.drawText()
        # Employee Details
        # Removing 3070, pasport number and 3075, country of issue
        try:
            if self.dob.work % 1000000 != int(int(self.idno) / 10000000):
                raise Exception
            try:
                btype = int(self.btype)
            except:
                btype = 0
            try:
                bacno = int(self.bacno)
            except:
                bacno = 0
            try:
                taxno = int(self.taxno.work)
            except:
                taxno = 0
            self.emprec = '3010,"%s",3015,"%s",3020,"%1s",3025,%04i,'\
                '3030,"%s",3040,"%s",3050,"%s",3060,%013i,3080,%08i,'\
                '3100,%010i,3125,"%s",3136,"%s",3147,"%s",3148,"%s",'\
                '3149,"%s",3150,"%s",3160,"%s",3170,%08i,3180,%08i,'\
                '3200,%08.4f,3210,%08.4f,3214,"%s",3215,"%s",3216,"%s",'\
                '3217,"%s",3218,"X",3230,"%s",3240,%01i,3241,%s,3242,%s,'\
                '3245,"%s",3246,%01i' % (self.irp5, self.ttyp, self.nature,
                self.taxyr, self.sname, self.fname, self.inits, self.idno,
                self.dob.work, taxno, self.emadd, self.cotel[:11].strip(),
                self.coad1[:24].strip(), self.coad2.strip(),
                self.coad3[:21].strip(), self.cocod, self.emp,
                self.start.work, self.term.work, self.base, self.pers,
                self.addr1, self.addr2, self.addr3, self.pcode,
                self.direct, btype, bacno, self.branch, self.payee,
                self.relate)
            for code in (3010, 3015, 3020, 3025, 3030, 3040, 3050, 3060, 3080,
                         3100, 3125, 3136, 3147, 3148, 3149, 3150, 3160, 3170,
                         3180, 3200, 3210, 3214, 3215, 3216, 3217, 3218, 3230,
                         3240, 3241, 3242, 3245, 3246):
                self.totcode += code
            self.totrecs += 1
        except Exception as err:
            showError(None, "Header Record Error", "There is a Problem "\
                "with Employee %s's Record. Please Fix the Problem and "\
                "then Reprint\n\n%s" % (self.emp, err))
            self.error = True

    def printGross(self):
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Gross Remuneration")
        self.fpdf.drawText("Code    Description                            "\
            "                          Amount")
        self.fpdf.setFont()
        amount = CCD(self.totannp, "UI", 15)
        if amount.work:
            self.fpdf.drawText("3695    Annual Payments                   "\
                "                      %s" % amount.disp)
        amount = CCD(self.totntax, "UI", 15)
        if amount.work:
            self.fpdf.drawText("3696    Non-Taxable Income                "\
                "                      %s" % amount.disp)
        amount = CCD(self.totyrfi, "UI", 15)
        if amount.work:
            self.fpdf.drawText("3697    Retirement Funding Income         "\
                "                      %s" % amount.disp)
        amount = CCD(self.totnrfi, "UI", 15)
        if amount.work:
            self.fpdf.drawText("3698    Non-Retirement Funding Income     "\
                "                      %s" % amount.disp)
        amount = CCD(self.totincm, "UI", 15)
        if amount.work:
            self.fpdf.drawText("3699    Gross Remuneration                "\
                "                      %s" % amount.disp)
        self.fpdf.drawText()
        # Gross Earnings
        self.emprec = '%s,3696,%015i,3697,%015i,3698,%015i' % (
            self.emprec, self.totntax, self.totyrfi, self.totnrfi)
        for code in (3696, 3697, 3698):
            self.totcode += code
        self.totamnt = float(ASD(self.totamnt) + ASD(self.totntax))
        self.totamnt = float(ASD(self.totamnt) + ASD(self.totyrfi))
        self.totamnt = float(ASD(self.totamnt) + ASD(self.totnrfi))

    def printTax(self, site=None, trn=None):
        self.fpdf.drawText()
        self.fpdf.setFont(style="B")
        self.fpdf.drawText("Employees Tax Deductions")
        self.fpdf.drawText("Code    Description                       "\
            "                               Amount")
        self.fpdf.setFont()
        if not site and not trn:
            # Tax Codes IT3(a) 4150
            self.fpdf.drawText("4150    Reason Code                       "\
                "                         %s" % "          02")
            self.emprec = '%s,4150,%02i' % (self.emprec, 2)
            for code in (4150, ):
                self.totcode += code
            total = CCD(0, "UD", 15.2)
        else:
            # Tax Codes 4101, 4102, 4115
            site = CCD(site, "UD", 15.2)
            if site.work >= trn[4]:
                site = CCD(trn[4], "UD", 15.2)
                paye = 0
            else:
                paye = float(ASD(trn[4]) - ASD(site.work))
            paye = CCD(paye, "UD", 15.2)
            total = CCD(trn[4], "UD", 15.2)
            if site.work:
                self.fpdf.drawText("4101    Standard Income Tax - SITE   "\
                    "                           %s" % site.disp)
            if paye.work:
                self.fpdf.drawText("4102    Pay As You Earn              "\
                    "                           %s" % paye.disp)
            if total.work:
                self.fpdf.drawText("4103    Total Employees Tax          "\
                    "                           %s" % total.disp)
            self.emprec = '%s,4101,%014.2f,4102,%014.2f' % (
                self.emprec, site.work, paye.work)
            for code in (4101, 4102):
                self.totcode += code
            self.totamnt = float(ASD(self.totamnt) + ASD(site.work))
            self.totamnt = float(ASD(self.totamnt) + ASD(paye.work))
        # Tax Codes 4141, 4142, 4149, 4116, 4150
        uif = CCD((self.uifpay * self.uifr) / 100.0, "UD", 15.2)
        sdl = CCD((self.sdlpay * self.sdlr) / 100.0, "UD", 15.2)
        total = CCD(total.work, "UD", 15.2)
        self.emprec = '%s,4141,%014.2f,4142,%014.2f,4149,%014.2f,9999\n' % \
            (self.emprec, uif.work, sdl.work, total.work)
        for code in (4141, 4142, 4149, 9999):
            self.totcode += code
        self.totamnt = float(ASD(self.totamnt) + ASD(uif.work))
        self.totamnt = float(ASD(self.totamnt) + ASD(sdl.work))
        self.totamnt = float(ASD(self.totamnt) + ASD(total.work))
        self.irp5fl.write(self.emprec)

    def doPrint(self):
        self.fpdf.output(self.pdfnam, "F")
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=self.pdfnam,
                  header=self.tit,
                  repprt=self.df.repprt,
                  fromad=self.fromad,
                  repeml=self.df.repeml)

    def doExit(self):
        self.df.closeProcess()
        self.closeProcess()

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