Пример #1
0
class arc320(object):
    def __init__(self, **opts):
        self.opts = opts
        self.setVariables()
        self.mainProcess()
        self.opts["mf"].startLoop()

    def setVariables(self):
        gc = GetCtl(self.opts["mf"])
        assctl = gc.getCtl("assctl", self.opts["conum"])
        if not assctl:
            return
        self.fromad = assctl["cta_emadd"]

    def mainProcess(self):
        tnd = ((self.doEnd, "Y"), )
        txt = (self.closeProcess, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=[],
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"))

    def doEnd(self):
        tables = ["assgrp"]
        heads = ["Asset Groups Master Listing"]
        col = [["asg_group", "UA", 3.0, "Grp"],
               ["asg_desc", "NA", 30.0, "Description"],
               ["asg_assacc", "UI", 7.0, "Ass-Acc"],
               ["asg_depacc", "UI", 7.0, "Dep-Acc"],
               ["asg_expacc", "UI", 7.0, "Exp-Acc"]]
        whr = [("asg_cono", "=", self.opts["conum"])]
        odr = "asg_group"
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"],
               name=self.__class__.__name__,
               tables=tables,
               heads=heads,
               cols=col,
               where=whr,
               order=odr,
               conum=self.opts["conum"],
               conam=self.opts["conam"],
               repprt=self.df.repprt,
               repeml=self.df.repeml,
               fromad=self.fromad)
        self.df.enableButtonsTags(state=state)
        self.closeProcess()

    def closeProcess(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #2
0
class wgc220(object):
    def __init__(self, **opts):
        self.opts = opts
        self.mainProcess()
        self.opts["mf"].startLoop()

    def mainProcess(self):
        r1s = (("Number", "N"), ("Description", "D"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Sort Order          ",
                "Sort Order", "N", "Y", self.doSort, None, None, None), )
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"))

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

    def doEnd(self):
        self.df.closeProcess()
        tables = ["wagrcv"]
        heads = ["Receiver of Revenue Codes Listing"]
        cols = [["rcv_code", "UI", 4.0, "Code"],
                ["rcv_desc", "NA", 50.0, "Description"]]
        if self.sort == "N":
            order = "rcv_code"
        else:
            order = "rcv_desc"
        opts = "Sort Order: %s" % self.sort
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"],
               name=self.__class__.__name__,
               tables=tables,
               heads=heads,
               cols=cols,
               order=order,
               opts=opts,
               repprt=self.df.repprt)
        self.df.enableButtonsTags(state=state)
        self.opts["mf"].closeLoop()

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #3
0
class stc220(object):
    def __init__(self, **opts):
        self.opts = opts
        self.mainProcess()
        self.opts["mf"].startLoop()

    def mainProcess(self):
        fld = ()
        tnd = ((self.doEnd, "Y"), )
        txt = (self.closeProcess, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"))

    def doEnd(self):
        tables = ["struoi"]
        heads = ["Units Of Issue Master Listing"]
        col = [["unm_unit", "NA", 10.0, "Unit"],
               ["unm_desc", "NA", 30.0, "Description"]]
        whr = [("unm_cono", "=", self.opts["conum"])]
        odr = "unm_unit"
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"],
               name=self.__class__.__name__,
               tables=tables,
               heads=heads,
               cols=col,
               order=odr,
               where=whr,
               conum=self.opts["conum"],
               conam=self.opts["conam"],
               repprt=self.df.repprt)
        self.df.enableButtonsTags(state=state)
        self.closeProcess()

    def closeProcess(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #4
0
class bs1010(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"])
        ctlsys = gc.getCtl("ctlsys")
        if not ctlsys:
            return
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        tabs = ["bksmst", "bksown", "bksaut", "chglog"]
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        return True

    def mainProcess(self):
        bmf = {
            "stype":
            "R",
            "tables": ("bksmst", "bksown"),
            "cols":
            (("bmf_stat", "", 0, "S"), ("bmf_code", "", 0, "Code"),
             ("bmf_titl", "", 0, "Title", "Y"), ("bmf_ownr", "", 0, "Ownr"),
             ("bof_fnam", "", 0, "Name"), ("bmf_mnth", "", 0, "Mth-Rec")),
            "where": [("bmf_cono", "=", self.opts["conum"]),
                      ("bof_cono=bmf_cono", ), ("bof_code=bmf_ownr", )],
            "order":
            "bmf_stat, bmf_titl",
            "index":
            1
        }
        amf = {
            "stype":
            "R",
            "tables": ("bksaut", ),
            "cols":
            (("baf_code", "", 0, "Code"), ("baf_snam", "", 0, "Surname", "Y"),
             ("baf_fnam", "", 0, "Names")),
            "order":
            "baf_code"
        }
        omf = {
            "stype":
            "R",
            "tables": ("bksown", ),
            "cols":
            (("bof_code", "", 0, "Code"), ("bof_snam", "", 0, "Surname", "Y"),
             ("bof_fnam", "", 0, "Names")),
            "where": [("bof_cono", "=", self.opts["conum"])],
            "order":
            "bof_code"
        }
        r1s = (("Current", "C"), ("Removed", "X"))
        fld = ((("T", 0, 0,
                 0), "IUI", 4, "Code", "", "", "Y", self.doCode, bmf, None,
                ("efld", )), (("T", 0, 1, 0), "ITX", 30, "Title", "", "", "N",
                              self.doTitle, None, None, ("notblank", )),
               (("T", 0, 2, 0), "IUI", 4, "Author", "", "", "N", self.doAuthor,
                amf, None, ("efld", )), (("T", 0, 2, 0), "ONA", 30, ""),
               (("T", 0, 3, 0), "IUI", 4, "Owner", "", "", "N", self.doOwner,
                omf, None, ("efld", )), (("T", 0, 3, 0), "ONA", 30, ""),
               (("T", 0, 4,
                 0), "ID2", 7, "Month", "", "", "N", self.doMonth, None, None,
                ("efld", )), (("T", 0, 5, 0), ("IRB", r1s), 0, "Status", "",
                              "C", "N", self.doStatus, None, None, None))
        but = (("Accept", None, self.doAccept, 0, ("T", 0, 2),
                (("T", 0, 0), ("T", 0, 1))), ("Exit", None, self.doExit, 0,
                                              ("T", 0, 1), None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt)

    def doCode(self, frt, pag, r, c, p, i, w):
        self.bcode = w
        if not self.bcode:
            ok = askQuestion(self.opts["mf"].body,
                             "New Book",
                             "Is This a New Book?",
                             default="no")
            if ok == "no":
                return "Invalid Code"
            self.newbk = True
            self.bcode = getNextCode(self.sql,
                                     "bksmst",
                                     "bmf_code",
                                     start=1,
                                     last=9999)
            self.df.loadEntry(frt, pag, p, data=self.bcode)
        else:
            self.old = self.sql.getRec("bksmst",
                                       where=[("bmf_cono", "=",
                                               self.opts["conum"]),
                                              ("bmf_code", "=", self.bcode)],
                                       limit=1)
            if not self.old:
                ok = askQuestion(self.opts["mf"].body,
                                 "Code",
                                 "Is This a Manual Code?",
                                 default="no")
                if ok == "no":
                    return "Invalid Code"
                self.newbk = True
                return
            col = 0
            self.newbk = False
            for num, dat in enumerate(self.old[1:-1]):
                self.df.loadEntry(frt, pag, col, data=dat)
                if num == 2:
                    col += 1
                    self.df.loadEntry(frt, pag, col, data=self.getAuthor(dat))
                elif num == 3:
                    col += 1
                    self.df.loadEntry(frt, pag, col, data=self.getOwner(dat))
                col += 1

    def doDelete(self):
        self.sql.delRec("bksmst",
                        where=[("bmf_cono", "=", self.opts["conum"]),
                               ("bmf_code", "=", self.bcode)])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doTitle(self, frt, pag, r, c, p, i, w):
        self.title = w

    def doAuthor(self, frt, pag, r, c, p, i, w):
        self.acode = w
        if not self.acode:
            ok = askQuestion(self.opts["mf"].body,
                             "New Author",
                             "Is This a New Author?",
                             default="no")
            if ok == "no":
                return "Invalid Code"
            self.doNewAuthor()
            if not self.aend:
                return "rf"
            self.df.loadEntry(frt, pag, p, data=self.acode)
        acc = self.sql.getRec("bksaut",
                              where=[("baf_code", "=", self.acode)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        self.df.loadEntry(frt, pag, p + 1, data=self.getAuthor(self.acode))

    def doNewAuthor(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        tit = ("Author's Details", )
        fld = ((("T", 0, 0, 0), "ITX", 30, "Surname", "", "", "Y", None, None,
                None, ("notblank", )), (("T", 0, 1, 0), "ITX", 30, "Names", "",
                                        "", "Y", None, None, None, ("efld", )))
        self.aa = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doAutEnd, "y"), ),
                               txit=(self.doAutExit, ))
        self.aa.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doAutEnd(self):
        self.aend = True
        self.acode = getNextCode(self.sql,
                                 "bksaut",
                                 "baf_code",
                                 start=1,
                                 last=9999)
        data = [self.acode, self.aa.t_work[0][0][0], self.aa.t_work[0][0][1]]
        self.sql.insRec("bksaut", data=data)
        self.aa.closeProcess()

    def doAutExit(self):
        self.aend = False
        self.aa.closeProcess()

    def getAuthor(self, code):
        acc = self.sql.getRec("bksaut",
                              where=[("baf_code", "=", code)],
                              limit=1)
        if acc:
            return "%s, %s" % (acc[1], acc[2])
        else:
            return ""

    def doOwner(self, frt, pag, r, c, p, i, w):
        self.ocode = w
        if not self.ocode:
            ok = askQuestion(self.opts["mf"].body,
                             "New Member",
                             "Is This a New Member?",
                             default="no")
            if ok == "no":
                return "Invalid Code"
            self.doNewOwner()
            if not self.oend:
                return "rf"
            self.df.loadEntry(frt, pag, p, data=self.ocode)
        acc = self.sql.getRec("bksown",
                              where=[("bof_cono", "=", self.opts["conum"]),
                                     ("bof_code", "=", self.ocode)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        self.df.loadEntry(frt, pag, p + 1, data=self.getOwner(self.ocode))

    def doNewOwner(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        tit = ("Owner's Details", )
        fld = ((("T", 0, 0, 0), "ITX", 30, "Surname", "", "", "Y", None, None,
                None, ("notblank", )), (("T", 0, 1, 0), "ITX", 30, "Names", "",
                                        "", "Y", None, None, None, ("efld", )))
        self.oo = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doOwnEnd, "y"), ),
                               txit=(self.doOwnExit, ))
        self.oo.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doOwnEnd(self):
        self.oend = True
        self.ocode = getNextCode(self.sql,
                                 "bksown",
                                 "bof_code",
                                 start=1,
                                 last=9999)
        data = [
            self.opts["conum"], self.acode, self.oo.t_work[0][0][0],
            self.oo.t_work[0][0][1], "", "", "", "", "", "", "", ""
        ]
        self.sql.insRec("bksown", data=data)
        self.oo.closeProcess()

    def doOwnExit(self):
        self.oend = False
        self.oo.closeProcess()

    def getOwner(self, code):
        acc = self.sql.getRec("bksown",
                              where=[("bof_cono", "=", self.opts["conum"]),
                                     ("bof_code", "=", code)],
                              limit=1)
        if acc:
            return "%s, %s" % (acc[2], acc[3])
        else:
            return ""

    def doMonth(self, frt, pag, r, c, p, i, w):
        self.month = w

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

    def doEnd(self):
        data = [self.opts["conum"]]
        for num, dat in enumerate(self.df.t_work[0][0]):
            if num in (3, 5):
                continue
            data.append(dat)
        if self.newbk:
            self.sql.insRec("bksmst", data=data)
        elif data != self.old[:len(data)]:
            col = self.sql.bksmst_col
            data.append(self.old[col.index("bmf_xflag")])
            self.sql.updRec("bksmst",
                            data=data,
                            where=[("bmf_cono", "=", self.opts["conum"]),
                                   ("bmf_code", "=", self.bcode)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.old):
                if dat != data[num]:
                    self.sql.insRec(
                        "chglog",
                        data=[
                            "bksmst", "U",
                            "%03i%04i" % (self.opts["conum"], self.bcode),
                            col[num], dte, self.opts["capnm"],
                            str(dat),
                            str(data[num]), "", 0
                        ])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doAccept(self):
        frt, pag, col, mes = self.df.doCheckFields()
        if mes:
            self.df.focusField(frt, pag, (col + 1), err=mes)
        else:
            self.df.doEndFrame("T", 0, cnf="N")

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #5
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()
Пример #6
0
class cr1010(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,
            ["chglog", "ctlnot", "crsmst", "crstrn", "genmst", "strpom"],
            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.glint = crsctl["ctc_glint"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def mainProcess(self):
        crm = {
            "stype":
            "R",
            "tables": ("crsmst", ),
            "cols":
            (("crm_acno", "", 0, "Acc-Num"), ("crm_name", "", 0, "Name", "Y")),
            "where": [("crm_cono", "=", self.opts["conum"]),
                      ("crm_stat", "<>", "X")]
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        tag = (("Basic-_A", None, ("T", 1, 1), ("T", 0, 1)),
               ("Basic-_B", None, ("T", 1, 1), ("T", 0, 1)))
        r1s = (("Monthly", "M"), ("Daily", "D"))
        r2s = (("Yes", "Y"), ("No", "N"))
        self.fld = [
            (("T",0,0,0),"INA",7,"Acc-Num","Account Number",
                "","Y",self.doAcno,crm,None,("efld",),None,
                "To Automatically Generate Account Numbers for "\
                "New Accounts enter a Blank Account Number."),
            (("T",0,0,0),"INA",30,"Name","",
                "","N",self.doName,None,self.doDelete,("notblank",)),
            (("T",1,0,0),"INA",30,"Address Line 1","",
                "","N",None,None,None,("notblank",)),
            (("T",1,1,0),"INA",30,"Address Line 2","",
                "","N",None,None,None,("efld",)),
            (("T",1,2,0),"INA",30,"Address Line 3","",
                "","N",None,None,None,("efld",)),
            (("T",1,3,0),"INA",4,"Postal Code","",
                "","N",None,None,None,("efld",)),
            (("T",1,4,0),"INA",20,"Telephone Number","",
                "","N",None,None,None,("efld",)),
            (("T",1,5,0),"INA",20,"Fax Number","",
                "","N",None,None,None,("efld",)),
            (("T",1,6,0),"INA",30,"Manager's Name","",
                "","N",None,None,None,("efld",)),
            (("T",1,6,0),"ITX",30,"E-Mail","Manager's E-Mail",
                "","N",None,None,None,("email",)),
            (("T",1,7,0),"INA",30,"Account's Contact","Account's Contact Name",
                "","N",None,None,None,("efld",)),
            (("T",1,7,0),"ITX",30,"E-Mail","Account's E-Mail",
                "","N",None,None,None,("email",)),
            (("T",1,8,0),"INA",30,"Order's Contact","Order's Contact Name",
                "","N",None,None,None,("efld",)),
            (("T",1,8,0),"ITX",30,"E-Mail","Order's E-Mail",
                "","N",None,None,None,("email",)),
            (("T",1,9,0),"Id1",10,"Date Account Opened","",
                self.sysdtw,"N",None,None,None,("efld",)),
            (("T",1,10,0),"INA",10,"V.A.T Number","",
                "","N",None,None,None,("efld",)),
            (("T",2,0,0),("IRB",r1s),0,"Terms Base","",
                "M","N",self.doTermsBase,None,None,None),
            (("T",2,1,0),"IUI",2,"Statement Day","",
                "","N",None,None,None,("between",1,30)),
            (("T",2,2,0),"IUI",3,"Terms","",
                "","N",None,None,None,("between",0,90)),
            (("T",2,3,0),"IUI",7,"Credit Limit","",
                "","N",None,None,None,("efld",)),
            (("T",2,4,0),"IUD",5.2,"Trade Discount","",
                "","N",None,None,None,("efld",)),
            (("T",2,5,0),"IUD",5.2,"Settlement Discount",
                "Settlement Discount","","N",None,None,None,("efld",)),
            (("T",2,6,0),("IRB",r2s),0,"Payment Indicator","",
                "Y","N",None,None,None,None),
            (("T",2,7,0),"INA",20,"Bank Name","",
                "","N",None,None,None,("efld",)),
            (("T",2,8,0),"IUI",8,"Bank Branch","",
                "","N",None,None,None,("efld",)),
            (("T",2,9,0),"INA",16,"Bank Account","",
                "","N",None,None,None,("efld",))]
        if self.glint == "Y":
            self.fld.append((("T", 2, 10, 0), "IUI", 7, "G/L Account Number",
                             "G/L Account Number", "", "N", self.doGlac, glm,
                             None, ("efld", )))
        else:
            self.fld.append((("T", 2, 10, 0), "OUI", 7, "G/L Account Number"))
        but = (("Import", None, self.doImport, 0, ("T", 0, 1), ("T", 0, 2),
                "Import Account Details from a CSV or XLS File."),
               ("Accept", None, self.doAccept, 0, ("T", 1, 1), ("T", 0, 1)),
               ("Print", None, self.doPrint, 0, ("T", 0, 2), ("T", 2, 0)),
               ("Cancel", None, self.doCancel, 0, ("T", 0, 2),
                ("T", 2, 0)), ("Quit", None, self.doQuit, 1, None, None))
        tnd = ((self.doEnd, "N"), (self.doEnd, "N"), (self.doAccept, "Y"))
        txt = (self.doExit, self.doExit, self.doExit)
        self.df = TartanDialog(self.opts["mf"],
                               eflds=self.fld,
                               tags=tag,
                               butt=but,
                               tend=tnd,
                               txit=txt,
                               clicks=self.doClick)
        if "args" in self.opts:
            self.df.doKeyPressed("T", 0, 0, data=self.opts["args"])

    def doClick(self, *opts):
        if self.df.pag == 0:
            return
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def doAcno(self, frt, pag, r, c, p, i, w):
        self.acno = w
        if self.acno:
            self.old = self.sql.getRec("crsmst",
                                       where=[("crm_cono", "=",
                                               self.opts["conum"]),
                                              ("crm_acno", "=", self.acno)],
                                       limit=1)
        if not self.acno or not self.old:
            ok = askQuestion(self.opts["mf"].body,
                             "New Account",
                             "Is This a New Account?",
                             default="no")
            if ok == "no":
                return "Invalid Account Number"
            pw = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="CRS",
                            code="NewAcc")
            if pw.flag == "no":
                if "args" in self.opts:
                    return "xt"
                else:
                    return "New Account Creation is Not Allowed"
            self.new = True
        elif self.old[self.sql.crsmst_col.index("crm_stat")] == "X":
            return "Invalid Account, Redundant"
        else:
            self.new = False
            self.df.loadEntry("T", pag, p + 1, data=self.old[2])
            d = 3
            for pge in range(1, self.df.pgs + 1):
                for x in range(0, self.df.topq[pge]):
                    self.df.loadEntry("T", pge, x, data=self.old[d])
                    d = d + 1

    def doName(self, frt, pag, r, c, p, i, w):
        self.name = w
        if self.new and not self.acno:
            for x in range(1, 100):
                self.acno = genAccNum(self.name, x, 7)
                chk = self.sql.getRec("crsmst",
                                      where=[("crm_cono", "=",
                                              self.opts["conum"]),
                                             ("crm_acno", "=", self.acno)],
                                      limit=1)
                if not chk:
                    break
            self.df.loadEntry("T", 0, 0, data=self.acno)

    def doTermsBase(self, frt, pag, r, c, p, i, w):
        if w == "D":
            self.df.loadEntry(frt, pag, p + 1, 0)
            return "sk1"

    def doGlac(self, frt, pag, r, c, p, i, w):
        if w:
            chk = chkGenAcc(self.opts["mf"], self.opts["conum"], w)
            if type(chk) is str:
                return chk

    def doDelete(self):
        trs = self.sql.getRec("crstrn",
                              cols=["count(*)"],
                              where=[("crt_cono", "=", self.opts["conum"]),
                                     ("crt_acno", "=", self.acno)],
                              limit=1)
        if trs[0]:
            return "%s Transactions Exist, Not Deleted" % trs[0]
        pom = self.sql.getRec("strpom",
                              cols=["count(*)"],
                              where=[("pom_cono", "=", self.opts["conum"]),
                                     ("pom_acno", "=", self.acno)],
                              limit=1)
        if pom[0]:
            return "%s Purchase Order Exists, Not Deleted" % pom[0]
        nte = self.sql.getRec("ctlnot",
                              cols=["count(*)"],
                              where=[("not_cono", "=", self.opts["conum"]),
                                     ("not_sys", "=", "CRS"),
                                     ("not_key", "=", self.acno)],
                              limit=1)
        if nte[0]:
            return "%s Notes Exist, Not Deleted" % nte[0]
        self.sql.delRec("crsmst",
                        where=[("crm_cono", "=", self.opts["conum"]),
                               ("crm_acno", "=", self.acno)])
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        self.sql.insRec("chglog", data=["crsmst", "D", "%03i%-7s" % \
            (self.opts["conum"], self.acno), "", dte, self.opts["capnm"],
            "", "", "", 0])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doEnd(self):
        if self.df.pag == 0:
            self.df.focusField("T", 1, 1, clr=self.new)
        elif self.df.pag == 1:
            self.df.selPage("Basic-B")
            self.df.focusField("T", 2, 1, clr=self.new)

    def doAccept(self):
        frt, pag, col, mes = self.df.doCheckFields()
        if mes:
            if pag > 0 and pag != self.df.pag:
                if frt == "T":
                    self.df.last[pag][0] = col + 1
                else:
                    self.df.last[pag][1] = col + 1
                self.df.selPage(self.df.tags[pag - 1][0])
            else:
                self.df.focusField(frt, pag, (col + 1), err=mes)
            return
        data = [self.opts["conum"]]
        for x in range(0, 3):
            for y in range(0, len(self.df.t_work[x][0])):
                data.append(self.df.t_work[x][0][y])
        if self.new:
            data.extend(["N", ""])
            self.sql.insRec("crsmst", data=data)
        else:
            col = self.sql.crsmst_col
            data.append(self.old[col.index("crm_stat")])
            data.append(self.old[col.index("crm_xflag")])
            if data != self.old[:len(data)]:
                self.sql.updRec("crsmst",
                                data=data,
                                where=[("crm_cono", "=", self.opts["conum"]),
                                       ("crm_acno", "=", self.acno)])
                dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
                for num, dat in enumerate(self.old):
                    if dat != data[num]:
                        self.sql.insRec(
                            "chglog",
                            data=[
                                "crsmst", "U",
                                "%03i%-7s" % (self.opts["conum"], self.acno),
                                col[num], dte, self.opts["capnm"],
                                str(dat),
                                str(data[num]), "", 0
                            ])
        if "args" in self.opts:
            self.doQuit()
        else:
            self.opts["mf"].dbm.commitDbase()
            self.df.last[0] = [0, 0]
            self.df.selPage("Basic-A")
            self.df.focusField("T", 0, 1)

    def doPrint(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        TabPrt(self.opts["mf"],
               self.opts["conum"],
               self.opts["conam"],
               name=self.__class__.__name__,
               tabs="crsmst",
               where=[("crm_cono", "=", self.opts["conum"]),
                      ("crm_acno", "=", self.acno)])
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doImport(self):
        self.df.setWidget(self.df.B3, state="disabled")
        self.df.setWidget(self.df.mstFrame, state="hide")
        fi = FileImport(self.opts["mf"], imptab="crsmst", impskp=["crm_cono"])
        sp = ProgressBar(self.opts["mf"].body,
                         typ="Importing Creditor's Accounts",
                         mxs=len(fi.impdat))
        err = None
        for num, line in enumerate(fi.impdat):
            sp.displayProgress(num)
            if not line[0]:
                if not line[1]:
                    err = "Blank Account Number and Blank Name"
                    break
                for x in range(1, 100):
                    line[0] = genAccNum(line[1], x, 7)
                    chk = self.sql.getRec("crsmst",
                                          where=[("crm_cono", "=",
                                                  self.opts["conum"]),
                                                 ("crm_acno", "=", line[0])],
                                          limit=1)
                    if not chk:
                        break
            chk = self.sql.getRec("crsmst",
                                  where=[("crm_cono", "=", self.opts["conum"]),
                                         ("crm_acno", "=", line[0])],
                                  limit=1)
            if chk:
                err = "%s %s Already Exists" % (fi.impcol[0][0], line[0])
                break
            if not line[1]:
                err = "Blank Name"
                break
            if not line[14]:
                line[14] = self.sysdtw
            if not line[16]:
                line[16] = "M"
            if not line[17]:
                line[17] = 30
            if not line[18]:
                line[18] = 30
            if not line[22]:
                line[22] = "Y"
            if self.glint and line[26]:
                chk = self.sql.getRec("genmst",
                                      where=[("glm_cono", "=",
                                              self.opts["conum"]),
                                             ("glm_acno", "=", line[26])],
                                      limit=1)
                if not chk:
                    err = "Invalid General Ledger Account"
                    break
            line.insert(0, self.opts["conum"])
            self.sql.insRec("crsmst", data=line)
        sp.closeProgress()
        if err:
            err = "Line %s: %s" % ((num + 1), err)
            showError(
                self.opts["mf"].body, "Import Error", """%s

Please Correct your Import File and then Try Again.""" % err)
            self.opts["mf"].dbm.rollbackDbase()
        else:
            self.opts["mf"].dbm.commitDbase()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.df.last[0] = [0, 0]
        self.df.selPage("Basic-A")
        self.df.focusField("T", 0, 1)

    def doExit(self):
        if self.df.pag == 0:
            self.doQuit()
        elif self.df.pag == 1:
            self.df.focusField("T", 0, 1)
        else:
            self.df.selPage("Basic-A")

    def doQuit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Пример #7
0
class tb1030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            self.doReset()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       "ftable",
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.doGetTable()
        if not self.table:
            return
        self.sql = Sql(self.opts["mf"].dbm, ["ftable", self.table],
                       prog=self.__class__.__name__)
        self.sqi = Sql(self.opts["mf"].dbm,
                       self.table,
                       prog=self.__class__.__name__)
        self.read = "N"
        return True

    def doGetTable(self):
        tit = ("Table to Fix/Amend", )
        tbl = {
            "stype":
            "R",
            "tables": ("ftable", ),
            "cols": (("ft_tabl", "", 0, "Table"), ("ft_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("ft_seq", "=", 1)],
            "screen":
            self.opts["mf"].body
        }
        fld = ((("T", 0, 0, 0), "I@ft_tabl", 0, "", "", "", "N", self.doTabNam,
                tbl, None, None), )
        tnd = ((self.doTabEnd, "y"), )
        txt = (self.doTabExit, )
        self.tb = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=tnd,
                               txit=txt)
        self.tb.mstFrame.wait_window()

    def doTabNam(self, frt, pag, r, c, p, i, w):
        desc = self.sql.getRec("ftable",
                               cols=["ft_desc"],
                               where=[("ft_tabl", "=", w)],
                               limit=1)
        if not desc:
            return "Invalid Table"
        self.table = w
        self.desc = desc[0]

    def doTabExit(self):
        self.table = None
        self.doTabEnd()

    def doTabEnd(self):
        self.tb.closeProcess()

    def mainProcess(self):
        self.dics = getattr(self.sql, "%s_dic" % self.table)
        self.lcol = getattr(self.sql, "%s_col" % self.table)
        self.pgs = int((len(self.lcol) - 1) / 15) + 1
        fld = []
        cnt = 0
        lpg = 0
        for num, col in enumerate(self.lcol):
            if self.pgs == 1:
                pag = 0
            else:
                pag = int(num / 15) + 1
            if pag != lpg:
                lpg = pag
                cnt = 0
            if self.dics[col][2][0] == "D":
                typ = "I%s" % self.dics[col][2].lower()
            else:
                typ = "I%s" % self.dics[col][2]
            siz = self.dics[col][3]
            if siz > 50:
                siz = 50
            fld.append([["T", pag, cnt, 0], typ, siz, self.dics[col][4],
                        self.dics[col][4], "", "N", None, None, None, None])
            cnt += 1
        but = (("Display", None, self.doDisplay, None, None,
                None), ("Update", None, self.doUpdate, None, None,
                        None), ("Create", None, self.doCreate, 1, None, None),
               ("Delete", None, self.doDelete, None, None,
                None), ("Cancel", None, self.doReset, None, None,
                        None), ("Exit", None, self.doExit, 1, None, None))
        if self.pgs == 1:
            tag = None
            tnd = ((self.doEnd, "n"), )
            txt = (self.doExit, )
        else:
            tag = []
            tnd = [None]
            txt = [None]
            for pag in range(1, (self.pgs + 1)):
                tag.append(["Page-_%s" % pag, self.chgPage, ("T", 1, 1), None])
                tnd.append([self.doEnd, "n"])
                txt.append(self.doExit)
        if self.pgs == 1:
            self.df = TartanDialog(self.opts["mf"],
                                   tops=True,
                                   title=self.desc,
                                   eflds=fld,
                                   tags=tag,
                                   tend=tnd,
                                   txit=txt,
                                   butt=but,
                                   clicks=self.doClick)
        else:
            self.df = TartanDialog(self.opts["mf"],
                                   eflds=fld,
                                   tags=tag,
                                   tend=tnd,
                                   txit=txt,
                                   butt=but,
                                   clicks=self.doClick)

    def doClick(self, *opts):
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def chgPage(self):
        self.df.focusField("T", self.df.pag, 1, clr=False)

    def doDisplay(self):
        whr = []
        hed = []
        pos = 0
        for pag in range(self.df.pgs + 1):
            for num, fld in enumerate(self.df.t_work[pag][0]):
                hed.append(self.dics[self.lcol[pos]][5])
                if fld:
                    if type(fld) == str and fld.count("%"):
                        eql = "like"
                    else:
                        eql = "="
                    if self.dics[self.lcol[pos]][2][1] in ("A", "a"):
                        whr.append((self.lcol[pos], eql, fld))
                    else:
                        whr.append((self.lcol[pos], eql, fld))
                pos += 1
        keys = self.sql.getRec("ftable",
                               where=[("ft_tabl", "=", self.table),
                                      ("ft_seq", "=", 1)],
                               limit=1)
        odr = ""
        for x in range(4, 14):
            if keys[x]:
                odr = "%s%s," % (odr, keys[x])
        odr = odr[:-1]
        recs = self.sql.getRec(tables=self.table, where=whr, order=odr)
        if recs:
            titl = "Available Records"
            dat = []
            for rec in recs:
                a = []
                for n, c in enumerate(self.lcol):
                    d = CCD(rec[n], self.dics[c][2], self.dics[c][3])
                    a.append(d.disp)
                dat.append(a)
            state = self.df.disableButtonsTags()
            sc = SChoice(self.opts["mf"],
                         scrn=self.opts["mf"].body,
                         titl=titl,
                         head=hed,
                         data=dat,
                         retn="I",
                         mode="S")
            self.df.enableButtonsTags(state=state)
            if sc.selection is not None:
                self.read = "Y"
                self.olddata = recs[sc.selection]
                for num, dat in enumerate(self.olddata):
                    if self.pgs == 1:
                        pag = 0
                        idx = num
                    else:
                        pag = int(num / 15) + 1
                        idx = num - ((pag - 1) * 15)
                    self.df.loadEntry("T", pag, idx, data=dat)
                self.df.setWidget(self.df.B0, "disabled")
                self.df.setWidget(self.df.B1, "normal")
                self.df.setWidget(self.df.B3, "normal")
                self.df.setWidget(self.df.B4, "normal")
            else:
                self.read = "N"
            frt, pag, row, col = self.df.first
            self.df.focusField(frt, pag, 1, clr=False)

    def doUpdate(self):
        if self.read == "N":
            return
        self.sql.delRec(self.table, data=self.olddata)
        self.olddata = []
        newdata = []
        for pag in range((self.df.pgs + 1)):
            newdata.extend(self.df.t_work[pag][0])
        self.sqi.insRec(self.table, data=newdata)
        self.doReset()

    def doCreate(self):
        newdata = []
        for pag in range((self.df.pgs + 1)):
            newdata.extend(self.df.t_work[pag][0])
        keys = self.sql.getRec("ftable",
                               where=[("ft_tabl", "=", self.table),
                                      ("ft_type", "=", "U")])
        for key in keys:
            col = []
            dat = []
            for fld in key[4:]:
                if fld:
                    col.append(fld)
                    idx = getattr(self.sqi, "%s_col" % self.table)
                    dat.append(newdata[idx.index(fld)])
            whr = []
            for num, ccc in enumerate(col):
                whr.append((ccc, "=", dat[num]))
            chk = self.sqi.getRec(tables=self.table, where=whr)
            if chk:
                showError(self.opts["mf"].body, "Duplicate Key",
                          "A Record like this Already Exists")
                return
        self.sqi.insRec(self.table, data=newdata)
        self.doReset()

    def doDelete(self):
        if self.read == "N":
            return
        if self.table in ("gentrn", "crstrn", "drstrn"):
            ask = askQuestion(self.opts["mf"].body,
                              "Delete",
                              "Delete All Associated Records?",
                              default="no")
        else:
            ask = "no"
        if ask == "yes":
            err = ""
            tabs = ["gentrn", "ctlvtf", "crsctl", "crstrn", "drsctl", "drstrn"]
            sql = Sql(self.opts["mf"].dbm, tables=tabs)
            conum = self.olddata[0]
            if self.table == "gentrn":
                system = "G"
                docno = CCD(self.olddata[5], "Na", 9).work
                date = CCD(self.olddata[3], "D1", 10).work
                dtyp = CCD(self.olddata[4], "UI", 2).work
                gtyp = dtyp
            elif self.table == "crstrn":
                system = "C"
                acno = CCD(self.olddata[1], "NA", 7).work
                dtyp = CCD(self.olddata[2], "UI", 2).work
                docno = CCD(self.olddata[3], "Na", 9).work
                date = CCD(self.olddata[5], "D1", 10).work
                if dtyp in (1, 4):
                    gtyp = 5  # Purchase
                elif dtyp == 2:
                    gtyp = 6  # Receipt
                elif dtyp == 3:
                    gtyp = 4  # Journal
                elif dtyp == 5:
                    gtyp = 2  # Payment
                glint = sql.getRec("crsctl",
                                   cols=["ctc_glint"],
                                   where=[("ctc_cono", "=", conum)],
                                   limit=1)[0]
            else:
                system = "D"
                chain = CCD(self.olddata[1], "UI", 3).work
                acno = CCD(self.olddata[2], "NA", 7).work
                dtyp = CCD(self.olddata[3], "UI", 2).work
                docno = CCD(self.olddata[4], "Na", 9).work
                date = CCD(self.olddata[6], "D1", 10).work
                if dtyp in (1, 4):
                    gtyp = 1  # Sale
                elif dtyp == 2:
                    gtyp = 6  # Receipt
                elif dtyp == 3:
                    gtyp = 4  # Journal
                elif dtyp == 5:
                    gtyp = 2  # Payment
                glint = sql.getRec("drsctl",
                                   cols=["ctd_glint"],
                                   where=[("ctd_cono", "=", conum)],
                                   limit=1)[0]
            sqv = [("vtt_cono", "=", conum), ("vtt_styp", "=", system),
                   ("vtt_refno", "=", docno), ("vtt_refdt", "=", date),
                   ("vtt_ttyp", "=", dtyp)]
            recs = sql.getRec("ctlvtf", where=sqv)
            if len(recs) > 1:
                err = "ctlvtf recs %s\n" % len(recs)
            texc = 0
            ttax = 0
            for rec in recs:
                texc = float(ASD(texc) + ASD(rec[11]))
                ttax = float(ASD(ttax) + ASD(rec[12]))
            ttot = float(ASD(texc) + ASD(ttax))
            ok = "yes"
            if system == "G" or glint == "Y":
                sqg = [("glt_cono", "=", conum), ("glt_refno", "=", docno),
                       ("glt_trdt", "=", date), ("glt_type", "=", gtyp)]
                recs = sql.getRec("gentrn", where=sqg)
                gamt = 0
                gtax = 0
                for rec in recs:
                    gamt = float(ASD(gamt) + ASD(rec[7]))
                    gtax = float(ASD(gtax) + ASD(rec[8]))
                if gtax != ttax:
                    err = "%sctlvtf %s <> gentrn %s\n" % (err, ttax, gtax)
                if gamt:
                    err = "%sgentrn debits <> credits" % err
            if system == "C":
                sqc = [("crt_cono", "=", conum), ("crt_acno", "=", acno),
                       ("crt_ref1", "=", docno), ("crt_trdt", "=", date),
                       ("crt_type", "=", dtyp)]
                recs = sql.getRec("crstrn", where=sqc)
                if len(recs) > 1:
                    err = "%scrstrn recs %s\n" % (err, len(recs))
                camt = 0
                ctax = 0
                for rec in recs:
                    camt = float(ASD(camt) + ASD(rec[7]))
                    ctax = float(ASD(ctax) + ASD(rec[8]))
                if ctax != ttax:
                    err = "%sctlvtf %s <> crstrn %s\n" % (err, ttax, ctax)
                if camt != ttot:
                    err = "%sctlvtf tot %s <> crstrn tot %s" % (err, ttot,
                                                                camt)
            if system == "D":
                sqd = [("drt_cono", "=", conum), ("drt_chain", "=", chain),
                       ("drt_acno", "=", acno), ("drt_ref1", "=", docno),
                       ("drt_trdt", "=", date), ("drt_type", "=", dtyp)]
                recs = sql.getRec("drstrn", where=sqd)
                if len(recs) > 1:
                    err = "%sdrstrn recs %s\n" % (err, len(recs))
                damt = 0
                dtax = 0
                for rec in recs:
                    damt = float(ASD(damt) - ASD(rec[8]))
                    dtax = float(ASD(dtax) - ASD(rec[9]))
                if dtax != ttax:
                    err = "%sctlvtf %s <> drstrn %s\n" % (err, ttax, dtax)
                if damt != ttot:
                    err = "%sctlvtf tot %s <> drstrn tot %s" % (err, ttot,
                                                                damt)
            if err:
                ok = askQuestion(self.opts["mf"].body, "Error",
                                 "%s\n\nDelete transaction (y/n)?" % err)
            if ok == "yes":
                sql.delRec("ctlvtf", where=sqv)
                if system == "G" or glint == "Y":
                    sql.delRec("gentrn", where=sqg)
                if system == "C":
                    sql.delRec("crstrn", where=sqc)
                if system == "D":
                    sql.delRec("drstrn", where=sqd)
        else:
            self.sql.delRec(self.table, data=self.olddata)
        self.olddata = []
        self.doReset()

    def doEnd(self):
        self.df.focusField(self.df.frt, self.df.pag, 1, clr=False)

    def doReset(self):
        self.read = "N"
        if self.pgs == 1:
            self.df.focusField("T", 0, 1)
        else:
            self.df.selPage(self.df.tags[0][0])
            self.df.focusField("T", 1, 1)
        self.df.setWidget(self.df.B0, "normal")
        self.df.setWidget(self.df.B1, "disabled")
        self.df.setWidget(self.df.B3, "disabled")
        self.df.setWidget(self.df.B4, "disabled")

    def doExit(self):
        mes = None
        dft = "yes"
        if self.table == "gentrn":
            bals = self.sql.getRec("gentrn", cols=["sum(glt_tramt)"], limit=1)
            if bals[0]:
                amt = CCD(bals[0], "SD", 13.2)
                mes = "General Ledger Out of Balance by %s\n\n"\
                    "Commit Anyway?" % amt.disp.lstrip()
                dft = "no"
        self.opts["mf"].dbm.commitDbase(ask=True, mess=mes, default=dft)
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #8
0
class cr4010(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, ["crsmst", "crstrn", "strpom"],
            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"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.curdt = int(self.sysdtw / 100)
        self.paidup = "N"
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
            "Creditors Interrogation (%s)" % self.__class__.__name__)
        crm = {
            "stype": "R",
            "tables": ("crsmst",),
            "cols": (
                ("crm_acno", "", 0, "Acc-Num"),
                ("crm_name", "", 0, "Name", "Y")),
            "where": [("crm_cono", "=", self.opts["conum"])]}
        tag = (
            ("Basic-_A", self.doTagSelect, ("T",0,2), ("T",0,1)),
            ("Basic-_B", self.doTagSelect, ("T",0,2), ("T",0,1)),
            ("Balances", self.doTagSelect, ("T",0,2), ("T",0,1)),
            ("History", self.doTagSelect, ("T",0,2), ("T",0,1)),
            ("Trans", self.doTrans1, ("T",0,2), ("T",0,1)),
            ("Orders", self.doOrders, ("T",0,2), ("T",0,1)))
        r1s = (("No","N"),("Yes","Y"))
        fld = (
            (("T",0,0,0),"INA",7,"Acc-Num","Account Number",
                "","N",self.doAccNum,crm,None,None),
            (("T",0,0,0),"ONA",30,"Name"),
            (("T",1,0,0),"ONA",30,"Address Line 1"),
            (("T",1,1,0),"ONA",30,"Address Line 2"),
            (("T",1,2,0),"ONA",30,"Address Line 3"),
            (("T",1,3,0),"ONA",4,"Postal Code"),
            (("T",1,4,0),"ONA",20,"Telephone"),
            (("T",1,5,0),"ONA",20,"Fax"),
            (("T",1,6,0),"ONA",30,"Manager"),
            (("T",1,6,0),"OTX",30,"E-Mail"),
            (("T",1,7,0),"ONA",30,"Accounts"),
            (("T",1,7,0),"OTX",30,"E-Mail"),
            (("T",1,8,0),"ONA",30,"Orders"),
            (("T",1,8,0),"OTX",30,"E-Mail"),
            (("T",1,9,0),"Od1",10,"Date Opened"),
            (("T",1,10,0),"ONA",10,"V.A.T. Number"),
            (("T",2,0,0),"OUA",1,"Terms Base"),
            (("T",2,1,0),"OUI",2,"Statement Day"),
            (("T",2,2,0),"OUI",3,"Terms"),
            (("T",2,3,0),"OUI",5,"Credit Limit"),
            (("T",2,4,0),"OUD",5.2,"Trade Discount"),
            (("T",2,5,0),"OUD",5.2,"Settlement Discount"),
            (("T",2,6,0),"OUA",1,"Payment Indicator"),
            (("T",2,7,0),"OUA",20,"Bank Name"),
            (("T",2,8,0),"OUI",8,"Bank Branch"),
            (("T",2,9,0),"OUA",16,"Bank Account"),
            (("T",2,10,0),"OUI",7,"G/L Account"),
            (("T",2,11,0),"OUA",1,"Status"),
            (("T",3,0,0),"Od1",10,"Date Last Purchased"),
            (("T",3,1,0),"Od1",10,"Date Last Paid"),
            (("T",3,2,0),"OSD",13.2,"Total Balance"),
            (("T",3,3,0),"OSD",13.2,"Current"),
            (("T",3,4,0),"OSD",13.2,"30 Days"),
            (("T",3,5,0),"OSD",13.2,"60 Days"),
            (("T",3,6,0),"OSD",13.2,"90 Days"),
            (("T",3,7,0),"OSD",13.2,"120 Days"),
            (("C",4,0,0),"OSD",13.2,"Purchases","","","N",
                None,None,None,None,("Months",13)),
            (("C",4,0,1),"OSD",13.2,"Payments"),
            (("T",5,0,0),("IRB",r1s),0,"History", "",
                "N","N",self.doTrans2,None,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, None)
        txt = (self.doExit, None, None, None, None, self.doExit)
        self.df = TartanDialog(self.opts["mf"], title=self.tit, tags=tag,
            eflds=fld, butt=but, tend=tnd, txit=txt)
        yer = int(self.sysdtw / 10000)
        mon = int((self.sysdtw % 10000) / 100)
        self.hist_tit = []
        for x in range(1, 14):
            if x == 13:
                txt = "Last 12 Month Total"
                self.df.colLabel[4][x-1].configure(text=txt)
                self.hist_tit.append(txt)
            else:
                nam = mthnam[mon][1]
                nam = nam + (" " * (15-len(nam))) + str(yer)
                self.df.colLabel[4][x-1].configure(text=nam)
                self.hist_tit.append(nam)
            if x != 13:
                mon = mon - 1
                if mon == 0:
                    mon = mon + 12
                    yer = yer - 1

    def doAccNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("crsmst", where=[("crm_cono", "=",
            self.opts["conum"]), ("crm_acno", "=", w)], limit=1)
        if not acc:
            return "Invalid Account Number"
        self.acno = w
        self.name = acc[self.sql.crsmst_col.index("crm_name")]
        self.df.loadEntry("T",0, 1, data=self.name)
        seq = 3
        for x in range(0, self.df.topq[1]):
            self.df.loadEntry("T", 1, x, data=acc[seq])
            seq += 1
        for x in range(0, self.df.topq[2]):
            self.df.loadEntry("T", 2, x, data=acc[seq])
            seq += 1
        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):
        bals = Balances(self.opts["mf"], "CRS", self.opts["conum"],
            int(self.sysdtw / 100), (self.acno,))
        obal, tbal, ages = bals.doAllBals()
        this, hist = bals.doCrsDrsHist()
        self.purch = hist[0]
        self.pays = hist[1]
        last = self.sql.getRec("crstrn", cols=["max(crt_trdt)"],
            where=[("crt_cono", "=", self.opts["conum"]), ("crt_acno", "=",
            self.acno), ("crt_type", "=", 1)], limit=1)
        if not last or not last[0]:
            lastpurd = 0
        else:
            lastpurd = last[0]
        last = self.sql.getRec("crstrn", cols=["max(crt_trdt)"],
            where=[("crt_cono", "=", self.opts["conum"]), ("crt_acno", "=",
            self.acno), ("crt_type", "=", 5)], limit=1)
        if not last or not last[0]:
            lastpayd = 0
        else:
            lastpayd = last[0]
        for x in range(0, 8):
            if x == 0:
                data = lastpurd
            elif x == 1:
                data = lastpayd
            elif x == 2:
                data = tbal
            else:
                data = ages[x-3]
            self.df.loadEntry("T", 3, x, data=data)
        p = 0
        for x in range(0, 13):
            i = 0
            self.df.loadEntry("C", 4, p, data=self.purch[x])
            p = p + 1
            i = i + 1
            pay = float(ASD(0) - ASD(self.pays[x]))
            self.df.loadEntry("C", 4, p, data=pay)
            p = p + 1
            i = i + 1

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

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

    def doTrans2(self, frt, pag, r, c, p, i, w):
        self.paidup = w
        whr = [
            ("crt_cono", "=", self.opts["conum"]),
            ("crt_acno", "=", self.acno)]
        if self.paidup == "Y":
            col, recs = getTrn(self.opts["mf"].dbm, "crs", whr=whr)
        else:
            col, recs = getTrn(self.opts["mf"].dbm, "crs", dte=self.curdt,
                whr=whr)
        if recs:
            data = []
            for dat in recs:
                data.append([
                    dat[col.index("crt_trdt")],
                    dat[col.index("crt_curdt")],
                    dat[col.index("crt_batch")],
                    dat[col.index("crt_type")],
                    dat[col.index("crt_ref1")],
                    dat[col.index("crt_tramt")],
                    dat[col.index("paid")],
                    dat[col.index("balance")],
                    dat[col.index("crt_desc")]])
            tit = "Transactions for Account: %s - %s" % (self.acno, self.name)
            col = (
                ("crt_trdt", "Date", 10, "D1", "N"),
                ("crt_curdt", "Curr-Dt", 7, "D2", "N"),
                ("crt_batch", "Batch", 7, "Na", "N"),
                ("crt_type", "Typ", 3, ("XX", crtrtp), "N"),
                ("crt_ref1", "Reference", 9, "Na", "Y"),
                ("crt_tramt", "Amount", 13.2, "SD", "N"),
                ("alloc", "Allocated", 13.2, "SD", "N"),
                ("balan", "Balance", 13.2, "SD", "N"),
                ("crt_desc", "Details", 30, "NA", "N"))
            state = self.df.disableButtonsTags()
            while True:
                rec = SelectChoice(self.df.nb.Page4, tit, col, data)
                # Display all transaction details
                if rec.selection:
                    self.df.setWidget(self.df.mstFrame, state="hide")
                    whr = [
                        ("crt_cono", "=", self.opts["conum"]),
                        ("crt_acno", "=", self.acno),
                        ("crt_type", "=", rec.selection[4]),
                        ("crt_ref1", "=", rec.selection[5])]
                    TabPrt(self.opts["mf"], tabs="crstrn", where=whr,
                        pdia=False)
                    self.df.setWidget(self.df.mstFrame, state="show")
                else:
                    break
            self.df.enableButtonsTags(state=state)
        self.doTrans1()

    def doOrders(self):
        col = self.sql.strpom_col
        whr = [
            ("pom_cono", "=", self.opts["conum"]),
            ("pom_acno", "=", self.acno),
            ("pom_delno", "<>", "cancel"),
            ("pom_deldt", "=", 0)]
        recs = self.sql.getRec("strpom", where=whr, order="pom_date")
        if recs:
            data = []
            for dat in recs:
                data.append([
                    dat[col.index("pom_date")],
                    dat[col.index("pom_ordno")],
                    dat[col.index("pom_cusord")],
                    dat[col.index("pom_jobnum")],
                    dat[col.index("pom_contact")]])
            tit = "Orders for Account: %s - %s" % (self.acno, self.name)
            col = (
                ("pom_date", "   Date", 10, "D1", "N"),
                ("pom_ordno", "Doc-Numbr", 9, "UI", "N"),
                ("pom_cusord", "Cust-Ord-Num", 15, "Na"),
                ("pom_jobnum", "Job-Num", 7, "Na"),
                ("pom_contact", "Contact", 30, "NA"))
            state = self.df.disableButtonsTags()
            while True:
                rec = SelectChoice(self.df.nb.Page6, tit, col, data)
                # Attempt to display the document
                if rec.selection:
                    self.df.setWidget(self.df.mstFrame, state="hide")
                    try:
                        doc = int(rec.selection[2])
                        PrintOrder(self.opts["mf"], self.opts["conum"],
                            self.opts["conam"], doc, repprt=["N", "V",
                            "view"], copy="y")
                    except:
                        pass
                    self.df.setWidget(self.df.mstFrame, state="show")
                else:
                    break
            self.df.enableButtonsTags(state=state)

    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"], "CRS", self.acno)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doClear(self):
        self.df.selPage("Basic-A")
        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):
        if opt == "N":
            return
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        if opt in ("I", "B"):
            table = "crsmst"
            whr = [
                ("crm_cono", "=", self.opts["conum"]),
                ("crm_acno", "=", self.acno)]
            rp = TabPrt(self.opts["mf"], self.opts["conum"], self.opts["conam"],
                name=self.__class__.__name__, tabs=table, where=whr,
                keys=[self.acno])
            repprt = rp.repprt
            repeml = rp.repeml
            xits = rp.xits
        else:
            repprt = None
            repeml = None
            xits = False
        if opt in ("T", "B") and not xits:
            heads = ["Creditor's Transactions",
                "Account: %s  Name: %s" % (self.acno, self.name)]
            whr = [
                ("crt_cono", "=", self.opts["conum"]),
                ("crt_acno", "=", self.acno)]
            if self.paidup == "Y":
                col, recs = getTrn(self.opts["mf"].dbm, "crs", whr=whr)
            else:
                col, recs = getTrn(self.opts["mf"].dbm, "crs",
                    dte=self.curdt, whr=whr)
            cols = []
            data = []
            dic = self.sql.crstrn_dic
            for num, rec in enumerate(recs):
                dat = []
                for nam in ["crt_ref1", "crt_trdt", "crt_type",
                        "crt_tramt", "paid", "balance", "crt_desc"]:
                    if not num:
                        if nam == "paid":
                            cols.append(["paid", "SD", 13.2, "Paid"])
                        elif nam == "balance":
                            cols.append(["balance", "SD", 13.2, "Balance"])
                        else:
                            cols.append([nam, dic[nam][2], dic[nam][3],
                                dic[nam][5]])
                    dat.append(rec[col.index(nam)])
                data.append(dat)
            if repprt:
                prtdia = False
            else:
                prtdia = (("Y","V"),("Y","N"))
            rp = RepPrt(self.opts["mf"], conum=self.opts["conum"],
                conam=self.opts["conam"], name=self.__class__.__name__,
                ttype="D", tables=data, heads=heads, cols=cols,
                trtp=["crt_type", crtrtp], prtdia=prtdia, repprt=repprt,
                repeml=repeml, fromad=self.fromad)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Пример #9
0
class ml2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Check for Valid Posting Routine
        if self.opts["rtn"] not in (1, 2, 3, 4):
            showError(self.opts["mf"].body, "Control Error",
                "Invalid Routine %s, Only 1-4 Are Allowed" % \
                str(self.opts["rtn"]))
            return
        tabs = ["ctlvmf", "ctlvrf", "ctlvtf", "memmst", "memtrn"]
        self.gc = GetCtl(self.opts["mf"])
        memctl = self.gc.getCtl("memctl", self.opts["conum"])
        if not memctl:
            return
        self.glint = memctl["mcm_glint"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["mem_ctl", "vat_ctl", "dis_all"]
            if self.gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.memctl = ctlctl["mem_ctl"]
            self.dis_all = ctlctl["dis_all"]
            tabs.extend(["gentrn", "genmst"])
        # Create SQL Object
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "MEM",
                          self.opts["rtn"],
                          glint=self.glint)
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        ctlmst = self.gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        if self.opts["rtn"] == 1:
            self.glt = 1
        elif self.opts["rtn"] == 2:
            self.glt = 2
        elif self.opts["rtn"] == 3:
            self.glt = 4
        elif self.opts["rtn"] == 4:
            self.glt = 1
        self.agevar = tk.BooleanVar()
        self.agevar.set(False)
        return True

    def drawDialog(self):
        mlm = {
            "stype":
            "R",
            "tables": ("memmst", ),
            "cols":
            (("mlm_memno", "", 0, "Mem-No"), ("mlm_oldno", "", 0, "Old-No"),
             ("mlm_gender", "", 0, "G"), ("mlm_state", "", 0, "S"),
             ("mlm_surname", "", 0, "Surname", "Y"), ("mlm_names", "", 0,
                                                      "Names", "F")),
            "where": [("mlm_cono", "=", self.opts["conum"])],
            "order":
            "mlm_surname, mlm_names",
            "sort":
            False
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        vtm = {
            "stype":
            "R",
            "tables": ("ctlvmf", ),
            "cols": (("vtm_code", "", 0, "C"), ("vtm_desc", "", 0,
                                                "Description", "Y")),
            "where": [("vtm_cono", "=", self.opts["conum"])]
        }
        fld = [(("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2, "Value"),
               (("C", 1, 0, 0), "IUI", 6, "Mem-No", "Member Number", "r", "N",
                self.doMemAcc, mlm, None, ("notzero", )),
               [("C", 1, 0, 1), "ONA", 10, "Name"],
               (("C", 1, 0, 2), "INa", 9, "Reference", "Reference Number One",
                "i", "N", self.doRefno, None, None, ("notblank", )),
               (("C", 1, 0, 3), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 4), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, ("efld", ))]
        if self.opts["rtn"] == 2:
            fld[3][2] = 20
            fld.extend([
                (("C", 1, 0, 5), "ISD", 13.2, "Discount", "Discount Amount",
                 "", "N", self.doDisAmt, None, None, None, None,
                 "Discount Amount to be Added to the Transaction Amount."),
                (("C", 1, 0, 6), "OSD", 13.2, "Total-Amount"),
                (("C", 1, 0,
                  7), "INA", (20, 30), "Details", "Transaction Details", "",
                 "N", self.doTrnDet, None, None, None)
            ])
        elif self.glint == "Y":
            fld[3][2] = 24
            fld.extend([
                (("C", 1, 0, 5), "INA", 30, "Details", "Transaction Details",
                 "", "N", self.doTrnDet, None, None, None),
                (("T", 2, 0, 0), "OSD", 13.2, "Unallocated Balance"),
                (("C", 2, 0, 0), "IUI", 7, "Acc-Num", "Account Number", "",
                 "N", self.doGenAcc, glm, None, None),
                (("C", 2, 0, 1), "ONA", 19, "Description"),
                (("C", 2, 0, 2), "IUA", 1, "V", "V.A.T Code", self.taxdf, "N",
                 self.doVatCode2, vtm, None, ("notblank", )),
                (("C", 2, 0, 3), "ISD", 13.2, "All-Amt", "Allocation Amount",
                 "", "N", self.doAllAmt, None, None, ("efld", )),
                (("C", 2, 0, 4), "ISD", 13.2, "V.A.T", "V.A.T Amount", "", "N",
                 self.doAllVat, None, None, None),
                (("C", 2, 0, 5), "INA", (26, 30), "Details", "", "", "N",
                 self.doAllDet, None, None, ("notblank", ))
            ])
        else:
            fld[3][2] = 22
            fld.extend([
                (("C", 1, 0, 6), "IUA", 1, "V", "V.A.T Code", self.taxdf, "N",
                 self.doVatCode1, vtm, None, ("notblank", )),
                (("C", 1, 0, 7), "ISD", 13.2, "V.A.T", "V.A.T Amount", "", "N",
                 self.doVatAmt, None, None, None),
                (("C", 1, 0,
                  8), "INA", (20, 30), "Details", "Transaction Details", "",
                 "N", self.doTrnDet, None, None, None)
            ])
        but = (
            ("Age _Normal",None,self.doAgeNormal,0,None,None,
                "Only Show Unallocated Transactions",1),
            ("Age _History",None,self.doAgeHistory,0,None,None,
                "Show All Transactions Including Already Allocated",1),
            ("Age _Automatic",None,self.doAgeAuto,0,None,None,
                "Automatically Allocate the Amount Starting With the "\
                "Oldest Unallocated One",1),
            ("Age _Current",None,self.doAgeCurrent,0,None,None,
                "Leave the Transaction Unallocated",1),
            ("Cancel",None,self.doCancel,0,("C",2,1),("C",1,1),"",1))
        tag = [("Transaction", None, None, None, False)]
        cnd = [(None, "n"), (self.endPage1, "y")]
        cxt = [None, self.exitPage1]
        if self.opts["rtn"] != 2 and self.glint == "Y":
            tag.append(("Allocation", None, None, None, False))
            cnd.append((self.endPage2, "y"))
            cxt.append(self.exitPage2)
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tags=tag,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 1, 1)

    def doMemAcc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("memmst",
                              cols=["mlm_title", "mlm_initial", "mlm_surname"],
                              where=[("mlm_cono", "=", self.opts["conum"]),
                                     ("mlm_memno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Member Number"
        self.memno = w
        self.name = "%s, %s %s" % (acc[2], acc[0], acc[1])
        self.df.loadEntry("C", pag, p + 1, data=self.name)

    def doRefno(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("memtrn",
                              cols=["mlt_batch"],
                              where=[("mlt_cono", "=", self.opts["conum"]),
                                     ("mlt_memno", "=", self.memno),
                                     ("mlt_type", "=", self.opts["rtn"]),
                                     ("mlt_refno", "=", w)],
                              limit=1)
        if acc:
            return "Transaction Already Exists"
        self.refno = w

    def doTrnDat(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not in Financial Period"
        if w > mthendDate(self.bh.curdt * 100):
            return "Invalid Date, After Batch Period"
        if self.bh.multi == "N" and int(w / 100) > self.bh.curdt:
            return "Invalid Date, After Batch Period"
        self.trndat = w

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w
        if self.glint == "Y" or self.opts["rtn"] == 2:
            self.vatcode = "N"
            self.vatamt = 0

    def doVatCode1(self, frt, pag, r, c, p, i, w):
        vrte = getVatRate(self.sql, self.opts["conum"], w, self.trndat)
        if vrte is None:
            return "Invalid V.A.T Code"
        self.vatcode = w
        self.vatamt = round((self.trnamt * vrte / (vrte + 100)), 2)
        self.df.loadEntry(frt, pag, p + 1, self.vatamt)
        if not self.vatamt:
            return "sk1"

    def doVatAmt(self, frt, pag, r, c, p, i, w):
        if self.trnamt < 0 and w > 0:
            self.vatamt = float(ASD(0) - ASD(w))
        elif self.trnamt > 0 and w < 0:
            self.vatamt = float(ASD(0) - ASD(w))
        else:
            self.vatamt = w
        self.df.loadEntry(frt, pag, p, data=self.vatamt)

    def doDisAmt(self, frt, pag, r, c, p, i, w):
        if self.trnamt < 0 and w > 0:
            self.disamt = float(ASD(0) - ASD(w))
        elif self.trnamt > 0 and w < 0:
            self.disamt = float(ASD(0) - ASD(w))
        else:
            self.disamt = w
        self.df.loadEntry(frt, pag, p, data=self.disamt)
        totamt = float(ASD(self.trnamt) + ASD(self.disamt))
        self.df.loadEntry(frt, pag, p + 1, data=totamt)

    def doTrnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w
        if self.opts["rtn"] != 2 and self.glint == "Y":
            self.df.colf[2][5][5] = w
        self.allocated = float(0.00)

    def endPage1(self):
        self.cancel = False
        self.agecan = False
        self.batupd = False
        self.updateTables1()
        if self.cancel:
            return
        else:
            self.updateBatch()
            if self.trnamt == 0:
                self.df.advanceLine(1)
            else:
                self.allocated = float(0.0)
                if self.opts["rtn"] == 2 or self.glint == "N":
                    self.doMemTrn()
                    self.opts["mf"].dbm.commitDbase()
                    self.df.selPage("Transaction")
                    self.df.advanceLine(1)
                else:
                    self.df.selPage("Allocation")
                    self.df.loadEntry("T", 2, 0, data=self.trnamt)
                    self.df.focusField("C", 2, 1)

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        self.amt = self.trnamt
        self.vat = self.vatamt
        if self.opts["rtn"] == 1:  # Invoices
            recon = 0
            self.dis = 0.00
        elif self.opts["rtn"] == 2:  # Payment
            if self.trnamt == 0:
                recon = self.curdt
            else:
                recon = 0
            self.vat = 0.00
            self.dis = self.disamt
        elif self.opts["rtn"] == 3:  # Journal
            recon = 0
            self.dis = 0.00
        elif self.opts["rtn"] == 4:  # Credit Note
            recon = 0
            self.amt = float(ASD(0) - ASD(self.amt))
            self.dis = 0.00
        if self.opts["rtn"] == 1:
            self.ageloop = False
            self.doAgeCurrent()
        else:
            state = self.df.disableButtonsTags()
            self.opts["mf"].updateStatus("Choose an Ageing Option")
            for x in range(0, 4):
                wid = getattr(self.df, "B%s" % x)
                self.df.setWidget(wid, "normal")
            self.df.setWidget(self.df.B0, "focus")
            self.agevar.set(True)
            self.df.mstFrame.wait_variable(self.agevar)
            self.df.enableButtonsTags(state=state)
            if self.agecan:
                self.doCancel()
                return
        if self.glint == "N":
            return
        # General Ledger Control Transaction (Members)
        val = float(ASD(self.amt) + ASD(self.dis))
        data = (self.opts["conum"], self.memctl, self.curdt, self.trndat,
                self.glt, self.refno, self.bh.batno, val, 0.00, self.trndet,
                "N", "", recon, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        # General Ledger Control Transaction (Bank)
        if self.opts["rtn"] == 2:
            val = float(ASD(0) - ASD(self.amt))
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                    self.glt, self.refno, self.bh.batno, val, 0.00,
                    self.trndet, "N", "", recon, self.opts["capnm"],
                    self.sysdtw, 0)
            self.sql.insRec("gentrn", data=data)
            # General Ledger Control Transaction (Discount)
            if self.dis:
                val = float(ASD(0) - ASD(self.dis))
                data = (self.opts["conum"], self.dis_all, self.curdt,
                        self.trndat, self.glt, self.refno, self.bh.batno, val,
                        0.00, self.trndet, "N", "", recon, self.opts["capnm"],
                        self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)

    def doAgeNormal(self):
        self.doAgeing("N")

    def doAgeHistory(self):
        self.doAgeing("H")

    def doAgeAuto(self):
        self.doAgeing("O")

    def doAgeCurrent(self):
        self.doAgeing("C")

    def doAgeing(self, atype):
        # Disable All Ageing Buttons
        for x in range(0, 4):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "disabled")
        self.opts["mf"].updateStatus("Select Transaction to Allocate Against")
        age = AgeAll(self.opts["mf"],
                     system="mem",
                     agetyp=atype,
                     agekey=[
                         self.opts["conum"], self.memno, self.opts["rtn"],
                         self.refno, self.curdt, self.amt, self.dis
                     ])
        self.agecan = age.cancel
        if self.agevar.get():
            self.agevar.set(False)

    def exitPage1(self):
        self.df.closeProcess()
        self.bh.doBatchTotal()
        self.opts["mf"].closeLoop()

    def doGenAcc(self, frt, pag, r, c, p, i, w):
        chk = chkGenAcc(self.opts["mf"], self.opts["conum"], w)
        if type(chk) is str:
            return chk
        if not chk[2]:
            self.taxgl = self.taxdf
        else:
            self.taxgl = chk[2]
        self.genacc = w
        self.df.loadEntry("C", pag, p + 1, data=chk[0])
        self.df.loadEntry("C", pag, p + 2, data=self.taxgl)

    def doVatCode2(self, frt, pag, r, c, p, i, w):
        ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"], error=False)
        if not ctlctl:
            return "Missing ctlctl Record for Company"
        if self.gc.chkRec(self.opts["conum"], ctlctl, ["vat_ctl"]):
            return "Missing or Invalid Control Record"
        self.convat = ctlctl["vat_ctl"]
        self.vatrte = getVatRate(self.sql, self.opts["conum"], w, self.trndat)
        if self.vatrte is None:
            return "Invalid V.A.T Code"
        self.vatcode = w

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if w == 0:
            allamt = float(ASD(self.trnamt) - ASD(self.allocated))
            self.allamt = round((allamt * 100 / (100 + self.vatrte)), 2)
            self.df.loadEntry(frt, pag, p, data=self.allamt)
            self.allvat = float(ASD(allamt) - ASD(self.allamt))
        else:
            self.allamt = w
            self.allvat = round((self.allamt * self.vatrte / 100), 2)
        self.df.loadEntry(frt, pag, p + 1, data=self.allvat)
        if not self.allvat:
            self.df.loadEntry(frt, pag, p + 2, data=self.name)
            return "sk1"

    def doAllVat(self, frt, pag, r, c, p, i, w):
        if self.allamt < 0 and w > 0:
            self.allvat = float(ASD(0) - ASD(w))
        elif self.allamt > 0 and w < 0:
            self.allvat = float(ASD(0) - ASD(w))
        else:
            self.allvat = w
        self.df.loadEntry(frt, pag, p, data=self.allvat)
        self.df.loadEntry(frt, pag, p + 1, data=self.name)

    def doAllDet(self, frt, pag, r, c, p, i, w):
        self.alldet = w

    def doCancel(self):
        if self.agecan:
            ok = "yes"
        else:
            ok = askQuestion(
                self.opts["mf"].body,
                head="Cancel",
                mess="Are You Certain You Want to Cancel This Entry?")
        if ok == "yes":
            self.cancel = True
            self.opts["mf"].dbm.rollbackDbase()
            if self.batupd:
                self.updateBatch(rev=True)
            if self.glint == "Y":
                self.df.clearFrame("C", 2)
            row = int((self.df.last[1][1] - 1) / self.df.colq[1])
            col = (row * self.df.colq[1]) + 1
            self.df.selPage("Transaction")
            self.df.focusField("C", 1, col)

    def endPage2(self):
        self.updateTables2()
        self.allocated = float(ASD(self.allocated) + \
            ASD(self.allamt) + ASD(self.allvat))
        if self.allocated == self.trnamt:
            self.doMemTrn()
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def updateTables2(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        if self.opts["rtn"] == 1:  # Invoices
            self.credit()
        elif self.opts["rtn"] == 3:  # Journal Entry
            self.credit()
        elif self.opts["rtn"] == 4:  # Credit Notes
            self.debit()

    def debit(self):
        amt = self.allamt
        vat = self.allvat
        self.restDebitCredit(amt, vat)

    def credit(self):
        amt = float(ASD(0) - ASD(self.allamt))
        vat = float(ASD(0) - ASD(self.allvat))
        self.restDebitCredit(amt, vat)

    def restDebitCredit(self, amt, vat):
        # VAT Transaction (ctlvtf)
        data = (self.opts["conum"], self.vatcode, "O", self.curdt, "M",
                self.glt, self.bh.batno, self.refno, self.trndat, self.memno,
                self.alldet, amt, vat, 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("ctlvtf", data=data)
        if self.glint == "N":
            return
        # General Ledger Transaction (Expense)
        data = (self.opts["conum"], self.genacc, self.curdt, self.trndat,
                self.glt, self.refno, self.bh.batno, amt, vat, self.alldet,
                self.vatcode, "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        if vat:
            # General Ledger Control Transaction (V.A.T.)
            data = (self.opts["conum"], self.convat, self.curdt, self.trndat,
                    self.glt, self.refno, self.bh.batno, vat, 0.00,
                    self.alldet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)
        vat = float(ASD(0) - ASD(vat))
        self.vat += vat

    def exitPage2(self):
        self.df.focusField("C", 2, self.df.col)

    def doMemTrn(self):
        # Members Ledger Transaction
        data = [
            self.opts["conum"], self.memno, self.opts["rtn"], self.refno,
            self.bh.batno, self.trndat, self.amt, self.vat, self.curdt, "", 0,
            self.trndet, self.vatcode, "N", self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("memtrn", data=data)
        if self.dis:
            data = [
                self.opts["conum"], self.memno, 6, self.refno, self.bh.batno,
                self.trndat, self.dis, self.vat, self.curdt, "", 0,
                self.trndet, self.vatcode, "N", self.opts["capnm"],
                self.sysdtw, 0
            ]
            self.sql.insRec("memtrn", data=data, unique="mlt_refno")

    def updateBatch(self, rev=False):
        if rev:
            self.bh.batqty -= 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.trnamt))
        else:
            self.batupd = True
            self.bh.batqty += 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.trnamt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
Пример #10
0
class st6030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.dataHeader()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["strmf1", "strtrn", "chglog"],
            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
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.curdt = int(self.sysdtw / 100)
        return True

    def dataHeader(self):
        grp = {
            "stype": "R",
            "tables": ("strgrp",),
            "cols": (
                ("gpm_group", "", 0, "Grp"),
                ("gpm_desc", "", 0, "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]}
        self.stm = {
            "stype": "R",
            "tables": ("strmf1",),
            "cols": (
                ("st1_code", "", 0, "Product Code"),
                ("st1_desc", "", 0, "Description", "Y")),
            "where": [],
            "whera": [["T", "st1_group", 0, 0]],
            "index": 0}
        fld = [
            (("T",0,0,0),"INA",3,"Group","Product Group",
                "","Y",self.doGroup,grp,None,("notblank",)),
            (("T",0,1,0),"INA",20,"Code","Product Code",
                "","N",self.doCode,self.stm,None,("notblank",)),
            (("T",0,2,0),"ONA",30,"Description")]
        but = (
            ("Generate",None,self.doGenerate,1,None,(("T",0,1),("T",0,2)),
                "Mark zero items, which have been inactive, as redundant"),
            ("Create",None,self.doCreate,1,None,(("T",0,1),("T",0,2)),
                "Mark a zero item as redundant"),
            ("Restore",None,self.doRestore,1,None,(("T",0,1),("T",0,2)),
                "Mark a redundant item as normal"),
            ("Exit",None,self.exitPage,1,None,(("T",0,1),("T",0,2))))
        tnd = ((self.endPage, "y"),)
        txt = (self.exitPage,)
        self.df = TartanDialog(self.opts["mf"], eflds=fld,
            butt=but, tend=tnd, txit=txt, focus=False)
        self.df.setWidget(self.df.B0, state="normal")
        self.df.setWidget(self.df.B1, state="normal")
        self.df.setWidget(self.df.B2, state="normal")
        self.df.setWidget(self.df.B3, state="normal")

    def doGenerate(self):
        tit = "Generate Redundant Items"
        fld = (
            (("T",0,0,0),"IUI",3,"Months Inactive","",
                24,"Y",self.doMonths,None,None,("efld",)),)
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        self.mt = TartanDialog(self.opts["mf"], title=tit, tops=True,
            eflds=fld, tend=((self.doMthEnd, "y"),), txit=(self.doMthExit,))
        self.mt.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doMonths(self, frt, pag, r, c, p, i, w):
        months = w
        yr = int(self.curdt / 100)
        mt = self.curdt % 100
        for mth in range(months):
            mt -= 1
            if not mt:
                mt = 12
                yr -= 1
        self.startp = (yr * 100) + mt

    def doMthEnd(self):
        self.mt.closeProcess()
        whr = [
            ("st1_cono", "=", self.opts["conum"]),
            ("st1_type", "=", "N"),
            ("stt_cono=st1_cono",),
            ("stt_group=st1_group",),
            ("stt_code=st1_code",)]
        accs = self.sql.getRec(tables=["strmf1", "strtrn"], cols=["st1_group",
            "st1_code", "max(stt_curdt)", "sum(stt_qty)", "sum(stt_cost)"],
            where=whr, order="st1_group, st1_code")
        chgs = []
        for acc in accs:
            if acc[2] < self.startp and not acc[3] and not acc[4]:
                chgs.append(acc[:2])
        if not chgs:
            showError(self.opts["mf"].body, "Processing Error",
                "No Redundant Records")
        else:
            self.cnt = 0
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            p = ProgressBar(self.opts["mf"].body, mxs=len(chgs),
                typ="Redundant Items")
            for num, rec in enumerate(chgs):
                p.displayProgress(num)
                self.sql.updRec("strmf1", cols=["st1_type"], data=["X"],
                    where=[("st1_cono", "=", self.opts["conum"]),
                    ("st1_group", "=", rec[0]), ("st1_code", "=", rec[1])])
                key = "%03i%-3s%-20s" % (self.opts["conum"], rec[0], rec[1])
                self.sql.insRec("chglog", data=["strmf1", "U", key,
                    "st1_type", dte, self.opts["capnm"], "N", "X", "", 0])
            p.closeProgress()
            mess = """%s Items Will be Marked as Redundant.

Would you like to COMMIT these Changes?""" % len(chgs)
            self.opts["mf"].dbm.commitDbase(ask=True, mess=mess)

    def doMthExit(self):
        self.mt.closeProcess()

    def doCreate(self):
        self.flag = "C"
        self.stm["where"] = [
                ("st1_cono", "=", self.opts["conum"]),
                ("st1_type", "<>", "X")]
        self.df.focusField("T", 0, 1)

    def doRestore(self):
        self.flag = "R"
        self.stm["where"] = [
                ("st1_cono", "=", self.opts["conum"]),
                ("st1_type", "=", "X")]
        self.df.focusField("T", 0, 1)

    def doGroup(self, frt, pag, r, c, p, i, w):
        if self.flag == "C":
            chk = self.sql.getRec("strmf1", where=[("st1_cono",
                "=", self.opts["conum"]), ("st1_group", "=", w),
                ("st1_type", "<>", "X")], limit=1)
        else:
            chk = self.sql.getRec("strmf1", where=[("st1_cono",
                "=", self.opts["conum"]), ("st1_group", "=", w),
                ("st1_type", "=", "X")], limit=1)
        if not chk:
            return "Invalid Group"
        self.grp = w

    def doCode(self, frt, pag, r, c, p, i, w):
        whr = [
            ("st1_cono", "=", self.opts["conum"]),
            ("st1_group", "=", self.grp),
            ("st1_code", "=", w)]
        if self.flag == "C":
            err = "Invalid, Not Normal"
            whr.append(("st1_type", "=", "N"))
        else:
            err = "Invalid, Not Redundant"
            whr.append(("st1_type", "=", "X"))
        chk = self.sql.getRec("strmf1", where=whr, limit=1)
        if not chk:
            return err
        if self.flag == "C":
            qty = self.sql.getRec("strtrn", cols=["sum(stt_qty)"],
                where=[("stt_cono", "=", self.opts["conum"]),
                ("stt_group", "=", self.grp), ("stt_code", "=", w)],
                limit=1)
            if qty[0]:
                return "Balance Exists"
        self.cod = w
        desc = chk[self.sql.strmf1_col.index("st1_desc")]
        self.df.loadEntry(frt, pag, p+1, data=desc)

    def endPage(self):
        if self.flag == "C":
            old = "N"
            new = "X"
        else:
            old = "X"
            new = "N"
        self.sql.updRec("strmf1", cols=["st1_type"], data=[new],
            where=[("st1_cono", "=", self.opts["conum"]),
            ("st1_group", "=", self.grp), ("st1_code", "=", self.cod)])
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        key = "%03i%-3s%-20s" % (self.opts["conum"], self.grp, self.cod)
        self.sql.insRec("chglog", data=["strmf1", "U", key,
            "st1_type", dte, self.opts["capnm"], old, new, "", 0])
        self.opts["mf"].dbm.commitDbase()
        self.df.clearFrame("T", 0)
        self.flag = ""

    def exitPage(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #11
0
class bc2040(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwltab",
            "bwlent", "bwltyp", "bwlgme"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        bwlctl = gc.getCtl("bwlctl", self.opts["conum"])
        if not bwlctl:
            return
        self.nstart = bwlctl["ctb_nstart"]
        self.dbase = bwlctl["ctb_dbase"]
        return True

    def mainProcess(self):
        com = {
            "stype": "R",
            "tables": ("bwlcmp",),
            "cols": (
                ("bcm_code", "", 0, "Cod"),
                ("bcm_name", "", 0, "Name", "Y"),
                ("bcm_date", "", 0, "Date")),
            "where": [("bcm_cono", "=", self.opts["conum"])]}
        typ = {
            "stype": "R",
            "tables": ("bwltyp",),
            "cols": (
                ("bct_code", "", 0, "Cod"),
                ("bct_desc", "", 0, "Description", "Y")),
            "where": [("bct_cono", "=", self.opts["conum"])]}
        sk1 = {
            "stype": "R",
            "tables": ("bwltab",),
            "cols": (
                ("btb_tab", "", 0, "Cod"),
                ("btb_surname", "", 0, "Surname", "Y"),
                ("btb_names", "", 0, "Names")),
            "where": [("btb_cono", "=", self.opts["conum"])],
            "order": "btb_surname"}
        sk2 = {
            "stype": "R",
            "tables": ("bwlent", "bwltab"),
            "cols": (
                ("btb_tab", "", 0, "Cod"),
                ("btb_surname", "", 0, "Surname", "Y"),
                ("btb_names", "", 0, "Names"),
                ("bce_tcod", "", 0, "T"),
                ("bce_paid", "", 0, "P")),
            "where": [
                ("btb_cono", "=", self.opts["conum"]),
                ("btb_tab=bce_scod",)],
            "whera": [("T", "bce_ccod", 0, 0)],
            "order": "btb_surname"}
        fld = (
            (("T",0,0,0),"I@bcm_code",0,"Code","Competition Code",
                "","Y",self.doCmpCod,com,None,("efld",)),
            (("T",0,0,0),"I@bcm_name",0,"Name","",
                "","N",self.doCmpNam,None,self.doDelCmp,("notblank",)),
            (("T",0,0,0),"I@bcm_date",0,"Date","",
                "","N",None,None,None,("efld",)),
            (("T",0,0,0),"I@bcm_type",0,"Type","",
                "","N",self.doCmpTyp,typ,None,("efld",)),
            (("C",0,0,0),"I@btb_tab",0,"P-Code","Player's Code",
                "","Y",self.doSkpCod,sk1,None,("efld",)),
            (("C",0,0,1),"ONA",30,"Name","",
                "","N",None,None,None,("notblank",)),
            (("C",0,0,2),"I@bce_tcod",0,"T","Team Code (H or V)",
                "H","n",self.doTeam,None,None,("in", ("H","V"))),
            (("C",0,0,4),"I@bce_paid",0,"","Paid Flag (Y or N)",
                "N","N",self.doPaid,None,self.doDelSkp,("in", ("Y","N"))))
        but = (("Entered Players",sk2,None,0,("C",0,1),("T",0,1)),)
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        cnd = ((self.doEnd,"n"),)
        cxt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], tops=False,
            eflds=fld, butt=but, tend=tnd, txit=txt, cend=cnd, cxit=cxt)

    def doCmpCod(self, frt, pag, r, c, p, i, w):
        self.erase = False
        self.skips = []
        if not w:
            self.ccod = getNextCode(self.sql, "bwlcmp", "bcm_code",
                where=[("bcm_cono", "=", self.opts["conum"])], last=999)
            self.df.loadEntry(frt, pag, p, data=self.ccod)
        else:
            self.ccod = w
        self.cmp = self.sql.getRec("bwlcmp", where=[("bcm_cono", "=",
            self.opts["conum"]), ("bcm_code", "=", self.ccod)], limit=1)
        if not self.cmp:
            ok = askQuestion(self.opts["mf"].body, head="New Competition",
                mess="Is This a New Competition?", default="no")
            if ok == "no":
                return "rf"
            self.newcmp = True
        else:
            if self.cmp[self.sql.bwlcmp_col.index("bcm_poff")]:
                showError(self.opts["mf"].body, "Complete",
                    "This Sectional Competition Has Been Completed.")
                return "rf"
            gme = self.sql.getRec("bwlgme", cols=["count(*)"],
                where=[("bcg_cono", "=", self.opts["conum"]), ("bcg_ccod", "=",
                self.ccod), ("bcg_ocod", "<>", 0)], limit=1)
            if gme[0]:
                ok = askQuestion(self.opts["mf"].body, "Error",
                    """This Competition Has Already Been Drawn.

Do You Want to Erase All Draws and Results?""", default="no")
                if ok == "no":
                    return "rf"
                self.erase = True
            self.newcmp = False
            for num, fld in enumerate(self.cmp[1:-2]):
                self.df.loadEntry(frt, pag, p+num, data=fld)
            ent = self.sql.getRec("bwlent", cols=["bce_scod"],
                where=[("bce_cono", "=", self.opts["conum"]),
                ("bce_ccod", "=", self.ccod)])
            for e in ent:
                self.skips.append(e[0])

    def doDelCmp(self):
        if self.newcmp:
            showError(self.opts["mf"].body, "Delete", "New Competition")
            return
        if self.skips:
            ok = askQuestion(self.opts["mf"].body, "Delete", "Entries Exist "\
                "for this Competition, Are You Sure it must be Deleted?",
                default="no")
            if ok == "no":
                return
        self.sql.delRec("bwlcmp", where=[("bcm_cono", "=", self.opts["conum"]),
            ("bcm_code", "=", self.ccod)])
        if self.skips:
            self.sql.delRec("bwlent", where=[("bce_cono",
                "=", self.opts["conum"]), ("bce_ccod", "=", self.ccod)])
            self.sql.delRec("bwlgme", where=[("bcg_cono",
                "=", self.opts["conum"]), ("bcg_ccod", "=", self.ccod)])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doCmpNam(self, frt, pag, r, c, p, i, w):
        self.cmpnam = w

    def doCmpTyp(self, frt, pag, r, c, p, i, w):
        if not w:
            ok = askQuestion(self.opts["mf"].body, head="New Type",
                mess="Is This a New Competition Type?")
            if ok == "yes":
                w = getNextCode(self.sql, "bwltyp", "bct_code",
                    where=[("bct_cono", "=", self.opts["conum"])], last=99)
                w = callModule(self.opts["mf"], self.df, "bc1040",
                    coy=(self.opts["conum"], self.opts["conam"]), args=w,
                    ret="ctype")
                self.df.loadEntry(frt, pag, p, data=w)
        self.typ = self.sql.getRec("bwltyp", where=[("bct_cono", "=",
            self.opts["conum"]), ("bct_code", "=", w)], limit=1)
        if not self.typ:
            return "Invalid Competition Type"
        self.cfmat = self.typ[self.sql.bwltyp_col.index("bct_cfmat")]
        self.tsize = self.typ[self.sql.bwltyp_col.index("bct_tsize")]

    def doSkpCod(self, frt, pag, r, c, p, i, w):
        if not w:
            ok = askQuestion(self.opts["mf"].body, head="New Non-Member",
                mess="Is This a New Non-Member Player?", default="yes")
            if ok == "no":
                return "Invalid Skip Code"
            cod = self.doNewCode()
            if not cod:
                return "Invalid Skip Code"
            self.df.loadEntry(frt, pag, p, data=cod)
        else:
            cod = w
        if cod not in self.skips:
            self.skips.append(cod)
        self.scod = cod
        chk = self.sql.getRec("bwltab", cols=["btb_surname",
            "btb_names"], where=[("btb_cono", "=", self.opts["conum"]),
            ("btb_tab", "=", self.scod)], limit=1)
        if not chk:
            return "Invalid Player Code"
        self.df.loadEntry(frt, pag, p+1, data=self.getName(chk))
        ent = self.sql.getRec("bwlent", cols=["bce_tcod",
            "bce_paid"], where=[("bce_cono", "=", self.opts["conum"]),
            ("bce_ccod", "=", self.ccod), ("bce_scod", "=", self.scod)],
            limit=1)
        if ent:
            self.newent = False
            self.df.loadEntry(frt, pag, p+2, data=ent[0])
            self.df.loadEntry(frt, pag, p+3, data=ent[1])
        else:
            self.newent = True
        if self.cfmat == "X":
            if self.scod < self.nstart:
                self.tcod = "H"
            else:
                self.tcod = "V"
            self.df.loadEntry(frt, pag, p+2, data=self.tcod)
        else:
            self.tcod = ""
            return "sk2"

    def doTeam(self, frt, pag, r, c, p, i, w):
        self.tcod = w

    def doNewCode(self):
        r1s = (("Male","M"), ("Female","F"))
        r2s = (("Skip",4), ("Third",3), ("Second",2), ("Lead",1))
        fld = (
            (("T",0,0,0),("IRB",r1s),0,"Gender","",
                "M","Y",None,None,None,None),
            (("T",0,1,0),"I@btb_surname",0,"","",
                "","Y",None,None,None,("notblank",)),
            (("T",0,2,0),"I@btb_names",0,"","",
                "","Y",None,None,None,("notblank",)),
            (("T",0,3,0),"I@btb_home",0,"","",
                "","Y",None,None,None,("efld",)),
            (("T",0,4,0),"I@btb_work",0,"","",
                "","Y",None,None,None,("efld",)),
            (("T",0,5,0),"I@btb_cell",0,"","",
                "","Y",None,None,None,("efld",)),
            (("T",0,6,0),"I@btb_mail",0,"","",
                "","Y",self.doNMail,None,None,("efld",)),
            (("T",0,7,0),("IRB",r2s),0,"Position","",
                4,"Y",self.doNPos,None,None,None),
            (("T",0,8,0),"I@btb_rate1",0,"Rating","",
                "","Y",None,None,None,("efld",)))
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        self.new = TartanDialog(self.opts["mf"], eflds=fld,
            tend=((self.doNEnd,"y"),), txit=(self.doNExit,))
        self.new.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state)
        return self.newcod

    def doNMail(self, frt, pag, r, c, p, i, w):
        if self.cfmat in ("T", "K", "R", "X"):
            if self.dbase in ("C", "P"):
                self.new.loadEntry(frt, pag, p+1, data=4)
            else:
                self.new.loadEntry(frt, pag, p+1, data=0)
            if self.dbase in ("C", "R"):
                self.new.loadEntry(frt, pag, p+2, data=5)
            else:
                self.new.loadEntry(frt, pag, p+2, data=0)
            return "sk2"
        if self.dbase == "R":
            self.new.loadEntry(frt, pag, p+1, data=0)
            return "sk1"

    def doNPos(self, frt, pag, r, c, p, i, w):
        if self.dbase == "P":
            self.new.loadEntry(frt, pag, p+1, data=0)
            return "sk1"

    def doNEnd(self):
        self.new.closeProcess()
        self.newcod = getNextCode(self.sql, "bwltab", "btb_tab",
            where=[("btb_cono", "=", self.opts["conum"])],
            start=self.nstart, last=900000)
        data = [self.opts["conum"], self.newcod, 0]
        data.extend(self.new.t_work[0][0][1:3])
        data.extend([self.new.t_work[0][0][0], "", "", "", ""])
        data.extend(self.new.t_work[0][0][3:])
        data.extend(self.new.t_work[0][0][7:])
        data.append(0)
        self.sql.insRec("bwltab", data=data)

    def doNExit(self):
        self.new.closeProcess()
        self.newcod = None

    def getName(self, chk):
        name = chk[0]
        if chk[1]:
            name += ","
            for i in chk[1].split():
                name = "%s %s" % (name, i)
        return name.upper()

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

    def doDelSkp(self):
        self.sql.delRec("bwlent", where=[("bce_cono", "=",
            self.opts["conum"]), ("bce_ccod", "=", self.ccod),
            ("bce_scod", "=", self.scod)])
        self.sql.delRec("bwlgme", where=[("bcg_cono", "=",
            self.opts["conum"]), ("bcg_ccod", "=", self.ccod),
            ("bcg_scod", "=", self.scod)])
        self.loadButton()

    def doEnd(self):
        if self.df.frt == "T":
            data = [self.opts["conum"]] + self.df.t_work[0][0] + [0]
            if self.newcmp:
                self.sql.insRec("bwlcmp", data=data)
            else:
                if self.erase:
                    self.sql.delRec("bwlgme", where=[("bcg_cono", "=",
                        self.opts["conum"]), ("bcg_ccod", "=", self.ccod)])
                    if self.cfmat in ("D", "K"):
                        self.sql.delRec("bwltms", where=[("btd_cono", "=",
                            self.opts["conum"]), ("btd_ccod", "=", self.ccod)])
                        self.sql.delRec("bwlrnd", where=[("bcr_cono", "=",
                            self.opts["conum"]), ("bcr_ccod", "=", self.ccod)])
                    if self.cfmat in ("T", "X"):
                        recs = self.sql.getRec("bwlent",
                            cols=["bce_scod"], where=[("bce_cono",
                            "=", self.opts["conum"]), ("bce_ccod",
                            "=", self.ccod)], order="bce_scod")
                        skips = []
                        for rec in recs:
                            skips.append(rec[0])
                        self.doPopulate(skips)
                data.append(self.cmp[self.sql.bwlcmp_col.index("bcm_xflag")])
                self.sql.updRec("bwlcmp", data=data, where=[("bcm_cono", "=",
                    self.opts["conum"]), ("bcm_code", "=", self.ccod)])
            self.loadButton()
            self.df.focusField("C", 0, 1)
        else:
            if self.newent:
                self.sql.insRec("bwlent", data=[self.opts["conum"], self.ccod,
                    self.scod, self.tcod, self.paid])
                if self.cfmat in ("T", "X"):
                    self.doPopulate([self.scod])
            else:
                self.sql.updRec("bwlent", cols=["bce_tcod", "bce_paid"],
                    data=[self.tcod, self.paid], where=[("bce_cono", "=",
                    self.opts["conum"]), ("bce_ccod", "=", self.ccod),
                    ("bce_scod", "=", self.scod)])
            self.loadButton()
            self.df.advanceLine(0)

    def doPopulate(self, scods):
        # Populate bwlgme records
        num = self.typ[self.sql.bwltyp_col.index("bct_games")]
        dgm = self.typ[self.sql.bwltyp_col.index("bct_drawn")]
        for scod in scods:
            data = [self.opts["conum"], self.ccod, scod, 0, "",
                0, 0, "", 0, 0, 0, 0, 0, 0, 0, "", 0, 0]
            for x in range(0, dgm):
                data[3] = x + 1
                data[4] = "D"
                self.sql.insRec("bwlgme", data=data)
            for x in range(dgm, num):
                data[3] = x + 1
                data[4] = "S"
                self.sql.insRec("bwlgme", data=data)

    def loadButton(self):
        rec = self.sql.getRec("bwlent", cols=["count(*)"],
            where=[("bce_cono", "=", self.opts["conum"]), ("bce_ccod", "=",
            self.ccod)], limit=1)
        self.df.B0.setLabel("Entered Players (%s)" % int(rec[0]), udl=0)

    def doExit(self):
        if self.df.frt == "C":
            self.opts["mf"].dbm.commitDbase()
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #12
0
class st2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.exit = False
            self.selectPrinter()
            if not self.exit:
                self.mainProcess()
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmst", "ctlmes", "ctlvrf", "ctlrep", "crsmst", "gentrn",
            "strgrp", "strloc", "strmf1", "strmf2", "strpom", "strpot",
            "strtrn", "strgmu", "strcmu", "tplmst"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        mods = []
        for x in range(0, len(ctlmst["ctm_modules"].rstrip()), 2):
            mods.append(ctlmst["ctm_modules"][x:x + 2])
        if "CR" not in mods:
            showError(
                self.opts["mf"].body, "System Error",
                "This module requires you to have a Creditor's Activated")
            return
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.stgl = strctl["cts_glint"]
        self.locs = strctl["cts_locs"]
        self.plevs = strctl["cts_plevs"]
        self.dtpl = strctl["cts_tplnam"]
        if self.stgl == "Y":
            ctlctl = gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["stk_soh", "stk_susp"]
            if gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.soh = ctlctl["stk_soh"]
            self.ssp = ctlctl["stk_susp"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def selectPrinter(self):
        tit = ("Printer Selection", )
        tpm = {
            "stype":
            "R",
            "tables": ("tplmst", ),
            "cols": (("tpm_tname", "", 0, "Template"), ("tpm_title", "", 0,
                                                        "Title", "Y")),
            "where": [("tpm_type", "=", "O"), ("tpm_system", "=", "STR")],
            "order":
            "tpm_tname"
        }
        fld = ((("T", 0, 0, 0), "INA", 20, "Template Name", "", self.dtpl, "N",
                self.doTplNam, tpm, None, None),
               (("T", 0, 1, 0), "ID1", 10, "Order Date", "", self.sysdtw, "N",
                self.doOrdDate, None, None, ("efld", )))
        self.pr = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=((self.doPrtEnd, "y"), ),
                               txit=(self.doPrtExit, ),
                               view=("N", "P"),
                               mail=("N", "Y", "Y"))
        self.opts["mf"].startLoop()

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

    def doOrdDate(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not In Financial Period"
        self.trdt = w
        self.trdd = self.pr.t_disp[0][0][1]
        self.curdt = int(self.trdt / 100)
        self.batch = "S%s" % self.curdt

    def doPrtEnd(self):
        self.doPrtClose()

    def doPrtExit(self):
        self.exit = True
        self.doPrtClose()

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

    def mainProcess(self):
        doc = {
            "stype":
            "R",
            "tables": ("strpom", "crsmst"),
            "cols":
            (("pom_ordno", "", 0, "Ord-Num"), ("pom_acno", "", 0, "Acc-Num"),
             ("crm_name", "", 0, "Name", "Y")),
            "where": [("pom_cono", "=", self.opts["conum"]),
                      ("crm_cono=pom_cono", ), ("crm_acno=pom_acno", ),
                      ("pom_delno", "=", "")]
        }
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        crm = {
            "stype":
            "R",
            "tables": ("crsmst", ),
            "cols": [("crm_acno", "", 0, "Acc-Num"),
                     ("crm_name", "", 0, "Name", "Y")],
            "where": [("crm_cono", "=", self.opts["conum"]),
                      ("crm_stat", "<>", "X")],
            "index":
            0
        }
        odr = {
            "stype": "R",
            "tables": ("ctlrep", ),
            "cols": [("rep_code", "", 0, "Ord"),
                     ("rep_name", "", 0, "Name", "Y")],
            "where": [("rep_cono", "=", self.opts["conum"])],
            "index": 0
        }
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        cod = {
            "stype":
            "R",
            "tables": ("strmf1", ),
            "cols": (("st1_code", "", 0, "Product-Code"),
                     ("st1_desc", "", 0, "Description", "Y")),
            "where": [("st1_cono", "=", self.opts["conum"]),
                      ("st1_type", "not", "in", ("R", "X")),
                      ("st1_value_ind", "<>", "N")],
            "whera": [("C", "st1_group", 0)],
            "order":
            "st1_group, st1_code"
        }
        r1s = (("New", "N"), ("Amend", "A"), ("Receive", "R"), ("Cancel", "C"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Action", "", "N", "Y",
                self.doActTyp, None, None,
                None), (("T", 0, 1, 0), "IUI", 9, "Ord-No", "Order Number", "",
                        "N", self.doOrdNum, doc, None, ("notblank", )),
               (("T", 0, 2, 0), "IUA", 1, "Loc", "Location Code", "1", "N",
                self.doLoc, loc, None, None), (("T", 0, 2, 0), "ONA", 30, ""),
               (("T", 0, 3, 0), "INA", 7, "Acc-No", "Account Number", "", "N",
                self.doCrsAcc, crm, None, None), (("T", 0, 3, 0), "ONA", 30,
                                                  ""),
               (("T", 0, 4, 0), "INa", 3, "Ord-By", "Ordered By", "", "N",
                self.doOrdBy, odr, None, None), (("T", 0, 4, 0), "ONA", 30,
                                                 ""),
               (("T", 0, 5, 0), "INa", 7, "Del-No", "Delivery Note Number", "",
                "N", self.doDelNum, None, None, ("notblank", )),
               (("T", 0, 5, 0), "ID1", 10, "Date", "Delivery Date", self.trdt,
                "N", self.doDelDate, None, None,
                ("efld", )), (("C", 0, 0, 0), "INA", 3, "Grp", "Product Group",
                              "", "Y", self.doGrp, grp, None, None),
               (("C", 0, 0, 1), "INA", 20, "Product-Code", "", "", "N",
                self.doCod, cod, None,
                None), (("C", 0, 0, 2), "INA", (20, 30), "Description", "", "",
                        "N", self.doDes, None, None,
                        None), (("C", 0, 0, 3), "ISD", 11.2, "Quantity", "", 1,
                                "N", self.doQty, None, None, ("notzero", )),
               (("C", 0, 0, 4), "IUA", 1, "V", "V.A.T. Code", "I", "N",
                self.doVat, None, None, ("notblank", )),
               (("C", 0, 0, 5), "IUD", 10.2, "Price", "Exclusive Price", "",
                "N", self.doPri, None, None,
                None), (("C", 0, 0, 6), "IUD", 6.2, "Dis-%", "Trade Discount",
                        "", "N", self.doDis, None, None,
                        None), (("C", 0, 0, 7), "OSD", 10.2, "Value"))
        self.row = (15, )
        self.but = (("Cancel", None, self.doCancel, 1, ("C", 0, 1),
                     ("T", 0, 1)), ("DelAdd", None, self.doDelAdd, 1,
                                    ("C", 0, 1), ("T", 0, 1)),
                    ("Ribbon", None, self.doRibbon, 1, ("C", 0, 1),
                     ("T", 0, 1)), ("Message", None, self.doMessag, 1,
                                    ("C", 0, 1), ("T", 0, 1)),
                    ("Edit", None, self.doEdit, 0, ("C", 0, 1), ("C", 0, 2)),
                    ("Reprint", None, self.doReprnt, 0, ("T", 0, 1),
                     ("T", 0, 2)), ("CrsMaint", None, self.doCrsMaint, 0,
                                    ("T", 0, 5), ("T", 0, 6)),
                    ("CrsQuery", None, self.doCrsQuery, 1, None,
                     None), ("StrMaint", None, self.doStrMaint, 0, ("C", 0, 1),
                             (("T", 0, 1), ("C", 0, 2))),
                    ("StrQuery", None, self.doStkQuery, 1, None,
                     None), ("Exit", None, self.doTopExit, 0, ("T", 0, 1),
                             (("T", 0, 2), ("T", 0, 3),
                              ("T", 0, 5)), "Exit Purchase Orders"),
                    ("Accept", None, self.doAccept, 0, ("C", 0, 1),
                     (("T", 0, 1), ("C", 0, 2))))
        tnd = ((self.doTopEnd, "n"), )
        txt = (self.doTopExit, )
        cnd = ((self.doColEnd, "n"), )
        cxt = (None, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               rows=self.row,
                               butt=self.but,
                               tend=tnd,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               vport=True)

    def doActTyp(self, frt, pag, r, c, p, i, w):
        # Initialise Action Variables
        self.acttyp = w
        # Initialise Variables
        self.dnum = ""
        self.onum = ""
        self.jnum = ""
        self.dadd = ""
        self.cnam = ""
        self.vatn = ""
        self.ribbon = None
        ctl = self.sql.getRec("ctlmst",
                              where=[("ctm_cono", "=", self.opts["conum"])],
                              limit=1)
        self.deladd = [
            ctl[self.sql.ctlmst_col.index("ctm_sadd1")],
            ctl[self.sql.ctlmst_col.index("ctm_sadd2")],
            ctl[self.sql.ctlmst_col.index("ctm_sadd3")],
            ctl[self.sql.ctlmst_col.index("ctm_spcode")]
        ]
        self.message = ""
        for x in (1, 2, 3):
            if self.acttyp == "R":
                self.df.butt[x][1] = 0
                self.df.butt[x][2] = None
            else:
                self.df.butt[x][1] = 1
                self.df.butt[x][2] = ["C", 0, 1]
        if self.acttyp == "N":
            # Location default
            if self.locs == "N":
                self.loc = "1"
                self.df.loadEntry(frt, pag, p + 2, data=self.loc)
                self.df.loadEntry(frt, pag, p + 3, data="Location One")
                return "sk3"
            return "sk1"

    def doOrdNum(self, frt, pag, r, c, p, i, w):
        strpom = self.sql.getRec("strpom",
                                 where=[("pom_cono", "=", self.opts["conum"]),
                                        ("pom_ordno", "=", w)],
                                 limit=1)
        if not strpom:
            return "Invalid Document"
        if strpom[self.sql.strpom_col.index("pom_delno")] == "cancel":
            if self.acttyp == "C":
                return "Already Cancelled"
            ok = askQuestion(
                self.opts["mf"].body,
                "Cancelled",
                "This order was Cancelled.\n\nDo you want to Reinstate It?",
                default="no")
            if ok == "no":
                return "Order Cancelled"
            self.sql.updRec("strpom",
                            cols=["pom_delno"],
                            data=[""],
                            where=[("pom_cono", "=", self.opts["conum"]),
                                   ("pom_ordno", "=", w)])
            strpom[self.sql.strpom_col.index("pom_delno")] = ""
        elif strpom[self.sql.strpom_col.index("pom_delno")]:
            return "Order Already Received"
        self.ordno = CCD(w, "UI", 9.0).work
        self.othno = CCD(w, "Na", 9.0).work
        self.loc = strpom[self.sql.strpom_col.index("pom_loc")]
        self.acno = strpom[self.sql.strpom_col.index("pom_acno")]
        self.cnam = strpom[self.sql.strpom_col.index("pom_contact")]
        self.vatn = strpom[self.sql.strpom_col.index("pom_vatno")]
        self.ordby = strpom[self.sql.strpom_col.index("pom_ordby")]
        self.ribbon = ["", "", self.cnam, self.vatn]
        self.df.loadEntry(frt, pag, p + 1, data=self.loc)
        self.doLoc(frt, pag, r, c + 1, p + 1, i + 1, self.loc)
        self.df.loadEntry(frt, pag, p + 3, data=self.acno)
        self.doCrsAcc(frt, pag, r, c + 3, p + 3, i + 3, self.acno)
        self.df.loadEntry(frt, pag, p + 5, data=self.ordby)
        self.doOrdBy(frt, pag, r, c + 5, p + 5, i + 5, self.ordby)
        if self.acttyp == "R":
            return "sk6"
        else:
            return "nd"

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

    def doCrsAcc(self, frt, pag, r, c, p, i, w):
        self.crsmst = self.sql.getRec("crsmst",
                                      where=[("crm_cono", "=",
                                              self.opts["conum"]),
                                             ("crm_acno", "=", w)],
                                      limit=1)
        if not self.crsmst:
            return "Invalid Account"
        if self.crsmst[self.sql.crsmst_col.index("crm_stat")] == "X":
            return "Invalid Account, Redundant"
        self.acno = w
        self.name = self.crsmst[self.sql.crsmst_col.index("crm_name")]
        self.df.loadEntry(frt, pag, p + 1, data=self.name)

    def doOrdBy(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("ctlrep",
                              cols=["rep_name"],
                              where=[("rep_cono", "=", self.opts["conum"]),
                                     ("rep_code", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        self.ordby = w
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        return "sk3"

    def doDelNum(self, frt, pag, r, c, p, i, w):
        self.delno = w

    def doDelDate(self, frt, pag, r, c, p, i, w):
        self.deldt = w

    def doTopEnd(self):
        if self.acttyp == "N":
            # Get and Display Next Document Number
            ordno = self.sql.getRec("strpom",
                                    cols=["max(pom_ordno)"],
                                    where=[("pom_cono", "=",
                                            self.opts["conum"])],
                                    limit=1)
            if not ordno[0]:
                self.ordno = CCD(1, "UI", 9).work
                self.othno = CCD(1, "Na", 9).work
            else:
                self.ordno = CCD((int(ordno[0]) + 1), "UI", 9).work
                self.othno = CCD((int(ordno[0]) + 1), "Na", 9).work
            self.df.loadEntry(self.df.frt, self.df.pag, 1, data=self.ordno)
            # Create Document Transaction (Head)
            self.dad1, self.dad2, self.dad3, self.dad4 = "", "", "", ""
            data = [
                self.opts["conum"], self.ordno, self.loc, self.trdt, self.acno,
                self.dad1, self.dad2, self.dad3, self.dad4, "", "", "", "",
                self.ordby, "", "", 0, self.opts["capnm"], self.sysdtw
            ]
            # Write and Commit Header
            self.sql.insRec("strpom", data=data)
            self.opts["mf"].dbm.commitDbase()
            # Clear Totals
            self.doClearTots()
        elif self.acttyp == "C":
            self.doReadLoadStr()
            ok = askQuestion(self.opts["mf"].body,
                             "Cancel",
                             "Are You Sure This Order Must be Cancelled?",
                             default="no")
            if ok == "yes":
                # Print Cancellation
                self.df.setWidget(self.df.mstFrame, state="hide")
                PrintOrder(self.opts["mf"],
                           self.opts["conum"],
                           self.opts["conam"],
                           self.ordno,
                           tname=self.tname,
                           repprt=self.pr.repprt,
                           repeml=self.pr.repeml,
                           copy=self.acttyp.lower())
                self.df.setWidget(self.df.mstFrame, state="show")
                # Update Deletetion
                self.sql.updRec("strpom",
                                cols=["pom_delno"],
                                data=["cancel"],
                                where=[("pom_cono", "=", self.opts["conum"]),
                                       ("pom_ordno", "=", self.ordno)])
                self.opts["mf"].dbm.commitDbase()
            # Clear totals and focus
            self.doClearTots()
            self.df.focusField("T", 0, 1)
        else:
            self.doReadLoadStr()
            self.amend = False

    def doReadLoadStr(self):
        self.doClearTots()
        data = self.sql.getRec("strpot",
                               where=[("pot_cono", "=", self.opts["conum"]),
                                      ("pot_ordno", "=", self.ordno)],
                               order="pot_group, pot_code")
        if not data:
            return
        for seq, line in enumerate(data):
            self.doExtData(line)
            if seq >= self.row[0]:
                self.df.scrollScreen(0)
                pos = (self.row[0] - 1) * 9
            else:
                pos = seq * 9
            # Load Values
            self.df.loadEntry("C", 0, pos, data=self.grp)
            self.df.loadEntry("C", 0, pos + 1, data=self.code)
            self.df.loadEntry("C", 0, pos + 2, data=self.desc)
            self.df.loadEntry("C", 0, pos + 3, data=self.qty)
            self.df.loadEntry("C", 0, pos + 5, data=self.vatcod)
            self.df.loadEntry("C", 0, pos + 6, data=self.price)
            self.df.loadEntry("C", 0, pos + 7, data=self.disrat)
            self.df.loadEntry("C", 0, pos + 8, data=self.excamt)
            self.vattot = float(ASD(self.vattot) + ASD(self.vatamt))
            self.ordtot = float(ASD(self.ordtot) + ASD(self.excamt))
            self.inctot = float(ASD(self.inctot) + ASD(self.incamt))
        if seq >= (self.row[0] - 1):
            self.df.scrollScreen(0)
        else:
            self.df.focusField("C", 0, pos + 10)
        self.df.setViewPort("O", self.inctot)

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

    def doClearTots(self):
        self.vattot = 0
        self.ordtot = 0
        self.inctot = 0
        self.df.clearFrame("C", 0)
        self.df.focusField("C", 0, 1)
        self.df.setViewPort(None, 0)

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

    def doCod(self, frt, pag, r, c, p, i, w):
        strmf1 = self.sql.getRec("strmf1",
                                 where=[("st1_cono", "=", self.opts["conum"]),
                                        ("st1_group", "=", self.grp),
                                        ("st1_code", "=", w)],
                                 limit=1)
        if not strmf1:
            return "Invalid Code"
        if strmf1[self.sql.strmf1_col.index("st1_type")] == "R":
            return "Invalid Code (Recipe)"
        if strmf1[self.sql.strmf1_col.index("st1_type")] == "X":
            return "Invalid Code (Redundant)"
        if strmf1[self.sql.strmf1_col.index("st1_value_ind")] == "N":
            return "Invalid Code (Value Indicator)"
        self.vatcod = strmf1[self.sql.strmf1_col.index("st1_vatcode")]
        strmf2 = self.sql.getRec("strmf2",
                                 where=[("st2_cono", "=", self.opts["conum"]),
                                        ("st2_group", "=", self.grp),
                                        ("st2_code", "=", w),
                                        ("st2_loc", "=", self.loc)],
                                 limit=1)
        if not strmf2:
            return "Invalid Location"
        odt = self.sql.getRec("strpot",
                              cols=["count(*)"],
                              where=[("pot_cono", "=", self.opts["conum"]),
                                     ("pot_ordno", "=", self.ordno),
                                     ("pot_group", "=", self.grp),
                                     ("pot_code", "=", w)],
                              limit=1)
        if odt[0]:
            return "This Item is Already On This Order"
        odq = self.sql.getRec(tables=["strpom", "strpot"],
                              cols=["sum(pot_qty)"],
                              where=[("pom_cono", "=", self.opts["conum"]),
                                     ("pom_loc", "=", self.loc),
                                     ("pom_delno", "=", ""),
                                     ("pot_cono", "=", self.opts["conum"]),
                                     ("pot_ordno=pom_ordno", ),
                                     ("pot_group", "=", self.grp),
                                     ("pot_code", "=", w)],
                              limit=1)
        if odq[0]:
            state = self.df.disableButtonsTags()
            cf = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="STR",
                            code="DupOrd",
                            desc="%s of this Item is Already On Order" %
                            odq[0])
            self.df.enableButtonsTags(state=state)
            if cf.flag == "no":
                return "rf"
        self.code = w
        desc = strmf1[self.sql.strmf1_col.index("st1_desc")]
        self.uoi = strmf1[self.sql.strmf1_col.index("st1_uoi")]
        self.df.loadEntry(frt, pag, p + 1, data=desc)

    def doDes(self, frt, pag, r, c, p, i, w):
        self.desc = w

    def doQty(self, frt, pag, r, c, p, i, w):
        self.qty = w
        self.df.loadEntry(frt, pag, p + 1, data=self.vatcod)

    def doVat(self, frt, pag, r, c, p, i, w):
        self.vatrte = getVatRate(self.sql, self.opts["conum"], w, self.trdt)
        if self.vatrte is None:
            return "Invalid V.A.T Code"
        self.vatcod = w
        # Last Cost Price
        lcost = getCost(self.sql,
                        self.opts["conum"],
                        self.grp,
                        self.code,
                        loc=self.loc,
                        qty=1,
                        ind="L")
        self.df.loadEntry(frt, pag, p + 1, data=lcost)

    def doPri(self, frt, pag, r, c, p, i, w):
        self.price = w
        self.inc = round((self.price * (self.vatrte + 100.0) / 100.0), 4)
        self.exc = round((self.price * 1), 2)
        dis = self.crsmst[self.sql.crsmst_col.index("crm_trdis")]
        self.df.loadEntry(frt, pag, p + 1, data=dis)

    def doDis(self, frt, pag, r, c, p, i, w):
        self.disrat = w
        dis = float(ASD(100) - ASD(self.disrat))
        self.excamt = round((self.qty * self.exc * dis / 100.0), 2)
        self.incamt = round((self.qty * self.inc * dis / 100.0), 2)
        self.vatamt = float(ASD(self.incamt) - ASD(self.excamt))
        self.df.loadEntry(frt, pag, p + 1, data=self.excamt)
        self.vattot = float(ASD(self.vattot) + ASD(self.vatamt))
        self.ordtot = float(ASD(self.ordtot) + ASD(self.excamt))
        self.inctot = float(ASD(self.inctot) + ASD(self.incamt))
        self.df.setViewPort("O", self.inctot)

    def doColEnd(self):
        # Create Purchase Order Transaction (Body)
        data = [
            self.opts["conum"], self.ordno, self.grp, self.code, self.uoi,
            self.desc, self.qty, self.price, self.disrat, self.vatcod,
            self.vatrte, self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("strpot", data=data)
        if self.acttyp == "A":
            self.amend = True
        self.df.advanceLine(0)

    def doCrsQuery(self):
        callModule(self.opts["mf"],
                   self.df,
                   "cr4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])

    def doStkQuery(self):
        callModule(self.opts["mf"],
                   self.df,
                   "st4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=self.opts["period"],
                   user=self.opts["capnm"])

    def doDelAdd(self):
        tit = ("Delivery Address", )
        fld = ((("T", 0, 0, 0), "INA", 30, "Address-1", "Address Line 1", "",
                "N", None, None, None,
                None), (("T", 0, 1, 0), "INA", 30, "Address-2",
                        "Address Line 2", "", "N", None, None, None, None),
               (("T", 0, 2, 0), "INA", 30, "Address-3", "Address Line 3", "",
                "N", None, None, None, None),
               (("T", 0, 3, 0), "INA", 30, "Address-4", "Address Line 4", "",
                "N", None, None, None, None))
        state = self.df.disableButtonsTags()
        self.da = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doDelEnd, "n"), ),
                               txit=(self.doDelExit, ),
                               focus=False)
        for x in range(0, len(self.deladd)):
            self.da.loadEntry("T", 0, 0 + x, data=self.deladd[x])
        self.da.focusField("T", 0, 1, clr=False)
        self.da.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doDelEnd(self):
        self.deladd = []
        for x in range(0, self.da.topq[0]):
            self.deladd.append(self.da.t_work[0][0][x])
        self.doDelExit()

    def doDelExit(self):
        self.da.closeProcess()

    def doMessag(self):
        tit = ("Order Message", )
        cod = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": [("mss_message", "", 0, "Cod"),
                     ("mss_detail", "", 60, "Details")],
            "where": [("mss_system", "=", "STR")],
            "screen":
            self.df.mstFrame
        }
        fld = ((("T", 0, 0, 0), "IUI", 3, "Message Code", "", "", "N",
                self.doMesCod, cod, None, None),
               (("T", 0, 1, 0), "ITv", (30, 6), "Message", "", self.message,
                "N", None, None, None, None))
        but = (("Accept", None, self.doMesEnd, 0, ("T", 0, 1), ("T", 0, 0)), )
        state = self.df.disableButtonsTags()
        self.mg = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doMesEnd, "n"), ),
                               txit=(self.doMesExit, ),
                               butt=but)
        self.mg.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doMesCod(self, frt, pag, r, c, p, i, w):
        if w:
            mess = self.sql.getRec("ctlmes",
                                   where=[("mss_system", "=", "STR"),
                                          ("mss_message", "=", w)],
                                   limit=1)
            if not mess:
                return "Invalid Message Code"
            self.message = mess[self.sql.ctlmse_col.index("mss_detail")]
            self.mg.loadEntry(frt, pag, p + 1, data=self.message)

    def doMesEnd(self):
        wid, self.message = self.mg.getEntry("T", 0, 1)
        self.doMesExit()

    def doMesExit(self):
        self.mg.closeProcess()

    def doEdit(self):
        # Display document items and allow editing of desc, qty and price
        recs = self.sql.getRec("strpot",
                               where=[("pot_cono", "=", self.opts["conum"]),
                                      ("pot_ordno", "=", self.ordno)],
                               order="pot_group, pot_code")
        if recs:
            data = []
            for l in recs:
                qty = CCD(l[self.sql.strpot_col.index("pot_qty")], "SD", 11.2)
                prc = CCD(l[self.sql.strpot_col.index("pot_price")], "UD",
                          10.2)
                dis = CCD(l[self.sql.strpot_col.index("pot_disper")], "UD",
                          6.2)
                data.append([
                    l[self.sql.strpot_col.index("pot_group")],
                    l[self.sql.strpot_col.index("pot_code")],
                    l[self.sql.strpot_col.index("pot_desc")], qty.disp,
                    l[self.sql.strpot_col.index("pot_vatcod")], prc.disp,
                    dis.disp
                ])
            head = ("Grp", "Product-Code", "Description", "Quantity", "V",
                    "Price", "Disc-%")
            lin = {
                "stype":
                "C",
                "head":
                head,
                "typs": (("NA", 3), ("NA", 20), ("NA", 30), ("SD", 11.2),
                         ("UA", 1), ("UD", 10.2), ("UD", 6.2)),
                "data":
                data
            }
            state = self.df.disableButtonsTags()
            chg = self.df.selChoice(lin)
            if chg and chg.selection:
                self.change = chg.selection
                self.doChanges()
            self.df.enableButtonsTags(state=state)
        self.df.focusField("C", 0, self.df.col)

    def doChanges(self):
        tit = ("Change Items", )
        fld = ((("T", 0, 1, 0), "ONA", 3, "Group"), (("T", 0, 2, 0), "ONA", 20,
                                                     "Code"),
               (("T", 0, 3, 0), "INA", 30, "Description", "", "", "N",
                self.doChgDes, None, None, ("notblank", )),
               (("T", 0, 4, 0), "ISD", 11.2, "Quantity", "", "", "N",
                self.doChgQty, None, None, ("notzero", )),
               (("T", 0, 5, 0), "IUD", 10.2, "Selling Price", "", "", "N",
                self.doChgPrc, None, None, ("notzero", )),
               (("T", 0, 6, 0), "IUD", 6.2, "Discount Percent", "", "", "N",
                self.doChgDis, None, None, ("efld", )))
        but = (("Delete", None, self.doChgDel, 1, None, None), )
        tnd = ((self.doChgEnd, "n"), )
        txt = (self.doChgExit, )
        self.cg = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt)
        self.cg.loadEntry("T", 0, 0, data=self.change[0])
        self.cg.loadEntry("T", 0, 1, data=self.change[1])
        self.cg.loadEntry("T", 0, 2, data=self.change[2])
        self.cg.loadEntry("T", 0, 3, data=self.change[3])
        self.cg.loadEntry("T", 0, 4, data=self.change[5])
        self.cg.loadEntry("T", 0, 5, data=self.change[6])
        self.cg.focusField("T", 0, 3, clr=False)
        self.cg.mstFrame.wait_window()

    def doChgDes(self, frt, pag, r, c, p, i, w):
        self.desc = w

    def doChgQty(self, frt, pag, r, c, p, i, w):
        self.qty = w

    def doChgPrc(self, frt, pag, r, c, p, i, w):
        self.price = w

    def doChgDis(self, frt, pag, r, c, p, i, w):
        self.disrat = w

    def doChgDel(self):
        grp = self.change[0]
        cod = self.change[1]
        self.sql.delRec("strpot",
                        where=[("pot_cono", "=", self.opts["conum"]),
                               ("pot_ordno", "=", self.ordno),
                               ("pot_group", "=", grp),
                               ("pot_code", "=", cod)])
        if self.acttyp == "A":
            self.amend = True
        self.doChgExit(loader=True)

    def doChgEnd(self):
        grp = self.change[0]
        cod = self.change[1]
        col = ["pot_desc", "pot_qty", "pot_price", "pot_disper"]
        dat = [self.desc, self.qty, self.price, self.disrat]
        whr = [("pot_cono", "=", self.opts["conum"]),
               ("pot_ordno", "=", self.ordno), ("pot_group", "=", grp),
               ("pot_code", "=", cod)]
        self.sql.updRec("strpot", cols=col, data=dat, where=whr)
        if self.acttyp == "A":
            self.amend = True
        self.doChgExit(loader=True)

    def doChgExit(self, loader=False):
        self.cg.closeProcess()
        if loader:
            self.doReadLoadStr()

    def doReprnt(self):
        tit = ("Reprint Orders", )
        odr = {
            "stype":
            "R",
            "tables": ("strpom", "crsmst"),
            "cols": [("pom_ordno", "", 0, "Doc-Num"),
                     ("pom_date", "", 0, "Date"),
                     ("pom_acno", "", 0, "Acc-Num"),
                     ("crm_name", "", 0, "Name", "Y")],
            "where": [("pom_cono", "=", self.opts["conum"]),
                      ("pom_cono=crm_cono", ), ("pom_acno=crm_acno", )],
            "screen":
            self.opts["mf"].body
        }
        r1s = (("Copies", "C"), ("Originals", "O"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Document Mode", "", "C", "N",
                self.doMode, None, None, None),
               (("T", 0, 1, 0), "IUI", 9, "From Number",
                "From Document Number", "", "N", self.doOrd, odr, None,
                ("notzero", )), [("T", 0, 2, 0), "IUI", 9, "To   Number",
                                 "To Document Number", "", "N", None, odr,
                                 None, ("notzero", )])
        state = self.df.disableButtonsTags()
        self.rp = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doReprntEnd, "n"), ),
                               txit=(self.doReprntExit, ),
                               view=("N", "V"),
                               mail=("B", "Y"))
        self.rp.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doMode(self, frt, pag, r, c, p, i, w):
        if w == "C":
            self.copy = "y"
        else:
            self.copy = "n"

    def doOrd(self, frt, pag, r, c, p, i, w):
        self.rp.topf[pag][2][5] = w

    def doReprntEnd(self):
        self.rp.closeProcess()
        self.df.setWidget(self.df.mstFrame, state="hide")
        frm = self.rp.t_work[0][0][1]
        if not self.rp.t_work[0][0][2]:
            to = frm
        else:
            to = self.rp.t_work[0][0][2]
        odr = self.sql.getRec("strpom",
                              cols=["pom_ordno"],
                              where=[("pom_cono", "=", self.opts["conum"]),
                                     ("pom_ordno", ">=", frm),
                                     ("pom_ordno", "<=", to)])
        if odr:
            PrintOrder(self.opts["mf"],
                       self.opts["conum"],
                       self.opts["conam"],
                       odr,
                       tname=self.tname,
                       repprt=self.rp.repprt,
                       repeml=self.rp.repeml,
                       copy=self.copy)
        self.df.setWidget(self.df.mstFrame, state="show")

    def doReprntExit(self):
        self.rp.closeProcess()

    def doCrsMaint(self):
        state = self.df.disableButtonsTags()
        cf = PwdConfirm(self.opts["mf"],
                        conum=self.opts["conum"],
                        system="STR",
                        code="NewCrs")
        if cf.flag == "yes":
            callModule(self.opts["mf"],
                       self.df,
                       "cr1010",
                       coy=(self.opts["conum"], self.opts["conam"]),
                       period=None,
                       user=self.opts["capnm"])
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doStrMaint(self):
        state = self.df.disableButtonsTags()
        cf = PwdConfirm(self.opts["mf"],
                        conum=self.opts["conum"],
                        system="STR",
                        code="NewStr")
        if cf.flag == "yes":
            callModule(self.opts["mf"],
                       self.df,
                       "st1010",
                       coy=(self.opts["conum"], self.opts["conam"]),
                       period=None,
                       user=self.opts["capnm"])
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doAccept(self):
        self.df.setWidget(self.df.B11, "disabled")
        if self.df.col == 1:
            self.doCancel()
        else:
            # Update Tables
            self.doUpdateTables()
            # Commit Transaction
            self.opts["mf"].dbm.commitDbase()
            # Print Document
            if self.acttyp == "N" or (self.acttyp == "A" and self.amend):
                self.df.setWidget(self.df.mstFrame, state="hide")
                PrintOrder(self.opts["mf"],
                           self.opts["conum"],
                           self.opts["conam"],
                           self.ordno,
                           tname=self.tname,
                           repprt=self.pr.repprt,
                           repeml=self.pr.repeml,
                           copy=self.acttyp.lower())
                self.df.setWidget(self.df.mstFrame, state="show")
            self.df.focusField("T", 0, 1)

    def doRibbon(self):
        tit = ("Ribbon Line", )
        fld = ((("T", 0, 0, 0), "INA", 30, "Customer Order", "", self.cnam,
                "N", None, None, None, None),
               (("T", 0, 1,
                 0), "INA", 30, "Job Number", "", self.cnam, "N", None, None,
                None, None), (("T", 0, 2, 0), "INA", 30, "Contact Person", "",
                              self.cnam, "N", None, None, None, None),
               (("T", 0, 3, 0), "INA", 10, "VAT Number", "", self.vatn, "N",
                self.doVatNum, None, None, None))
        state = self.df.disableButtonsTags()
        self.rb = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doRibEnd, "n"), ),
                               txit=(self.doRibExit, ),
                               focus=False)
        if self.ribbon:
            self.rb.loadEntry("T", 0, 0, data=self.ribbon[0])
            self.rb.loadEntry("T", 0, 1, data=self.ribbon[1])
            self.rb.loadEntry("T", 0, 2, data=self.ribbon[2])
            self.rb.loadEntry("T", 0, 3, data=self.ribbon[3])
        self.rb.focusField("T", 0, 1)
        self.rb.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doVatNum(self, frt, pag, r, c, p, i, w):
        if self.ordtot >= 1000.00 and not w:
            return "Invalid VAT Number"

    def doRibEnd(self):
        self.ribbon = []
        for x in range(0, self.rb.topq[0]):
            self.ribbon.append(self.rb.t_work[0][0][x])
        self.doRibExit()

    def doRibExit(self):
        self.rb.closeProcess()

    def doUpdateTables(self):
        # Update strpom with ribbon, delivery and message details
        whr = [("pom_cono", "=", self.opts["conum"]),
               ("pom_ordno", "=", self.ordno), ("pom_acno", "=", self.acno)]
        if self.ribbon:
            self.sql.updRec(
                "strpom",
                cols=["pom_cusord", "pom_jobnum", "pom_contact", "pom_vatno"],
                data=[
                    self.ribbon[0], self.ribbon[1], self.ribbon[2],
                    self.ribbon[3]
                ],
                where=whr)
            if not self.vatn:
                self.sql.updRec("crsmst",
                                cols=["crm_vatno"],
                                data=[self.ribbon[1]],
                                where=[("crm_cono", "=", self.opts["conum"]),
                                       ("crm_acno", "=", self.acno)])
        if self.deladd:
            self.sql.updRec(
                "strpom",
                cols=["pom_add1", "pom_add2", "pom_add3", "pom_add4"],
                data=[
                    self.deladd[0], self.deladd[1], self.deladd[2],
                    self.deladd[3]
                ],
                where=whr)
        if self.message:
            self.sql.updRec("strpom",
                            cols=["pom_mess"],
                            data=[self.message],
                            where=whr)
        if self.acttyp != "R":
            return
        # Receipt of Order
        # Create Stores Transactions and update strpot lines
        trn = self.sql.getRec("strpot",
                              where=[("pot_cono", "=", self.opts["conum"]),
                                     ("pot_ordno", "=", self.ordno)],
                              order="pot_group, pot_code")
        if not trn:
            return
        for line in trn:
            self.doExtData(line)
            curdt = int(self.deldt / 100)
            # Update strpom record
            self.sql.updRec("strpom",
                            cols=["pom_delno", "pom_deldt"],
                            data=[self.delno, self.deldt],
                            where=[("pom_cono", "=", self.opts["conum"]),
                                   ("pom_ordno", "=", self.ordno)])
            # Write strtrn record
            data = [
                self.opts["conum"], self.grp, self.code, self.loc, self.deldt,
                1, self.othno, self.batch, self.delno, self.qty, self.excamt,
                0, curdt, self.name, 0, self.acno, "", "STR", self.disrat, "",
                self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("strtrn", data=data)
            # If Integrated Create GL Transaction (SOH and Recon Accounts)
            if self.stgl == "Y" and self.excamt:
                # Stock on Hand Control
                data = (self.opts["conum"], self.soh, curdt, self.deldt, 5,
                        self.othno, self.batch, self.excamt, 0, self.name, "",
                        "", 0, self.opts["capnm"], self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
                cst = float(ASD(0) - ASD(self.excamt))
                # Stock Reconciliation Control
                data = (self.opts["conum"], self.ssp, curdt, self.deldt, 5,
                        self.othno, self.batch, cst, 0, self.name, "", "", 0,
                        self.opts["capnm"], self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)

    def doExtData(self, line):
        self.grp = line[self.sql.strpot_col.index("pot_group")]
        self.code = line[self.sql.strpot_col.index("pot_code")]
        self.uoi = line[self.sql.strpot_col.index("pot_uoi")]
        self.desc = line[self.sql.strpot_col.index("pot_desc")]
        self.qty = line[self.sql.strpot_col.index("pot_qty")]
        self.price = line[self.sql.strpot_col.index("pot_price")]
        self.disrat = line[self.sql.strpot_col.index("pot_disper")]
        self.vatcod = line[self.sql.strpot_col.index("pot_vatcod")]
        self.vatrte = line[self.sql.strpot_col.index("pot_vatrat")]
        # Calculate Values
        rat = float(ASD(100) + ASD(self.vatrte))
        inc = round((self.price * rat / 100.0), 4)
        exc = round((self.price * 1), 2)
        dis = float(ASD(100) - ASD(self.disrat))
        self.excamt = round((self.qty * exc * dis / 100.0), 2)
        self.incamt = round((self.qty * inc * dis / 100.0), 2)
        self.vatamt = float(ASD(self.incamt) - ASD(self.excamt))

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        if self.acttyp == "N":
            self.sql.updRec("strpom",
                            cols=["pom_delno"],
                            data=["cancel"],
                            where=[("pom_cono", "=", self.opts["conum"]),
                                   ("pom_ordno", "=", self.ordno),
                                   ("pom_acno", "=", self.acno)])
            self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)
Пример #13
0
class cr2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Check for Valid Posting Routine
        if self.opts["rtn"] not in (1, 2, 3, 4, 5):
            showError(self.opts["mf"].body, "Control Error",
                "Invalid Routine %s, Only 1 - 5 Are Allowed" % \
                str(self.opts["rtn"]))
            return
        # Create SQL Object
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmst", "ctlvmf", "ctlvrf", "ctlvtf", "crsmst", "crstrn",
            "genint", "genmst", "gentrn", "lonmf1", "lonmf2", "lonrte",
            "lontrn", "wagedc", "wagmst", "waglmf", "wagltf"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        # Check for Company record
        self.gc = GetCtl(self.opts["mf"])
        self.allcoy = self.opts["conum"]
        self.allnam = self.opts["conam"]
        ctlmst = self.gc.getCtl("ctlmst", self.allcoy)
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        # Check for Intercompany Facility
        if not self.sql.getRec("ctlmst",
                               cols=["count(*)"],
                               where=[("ctm_cono", "<>", self.opts["conum"])],
                               limit=1)[0]:
            self.incoac = False
        else:
            rec = self.sql.getRec("genint",
                                  cols=["cti_inco"],
                                  where=[("cti_cono", "=", self.opts["conum"])
                                         ])
            if rec:
                self.incoac = [self.opts["conum"]]
                [self.incoac.append(coy[0]) for coy in rec]
            else:
                self.incoac = False
        # Get Enabled Modules
        self.lonmod = False
        self.lonpag = None
        self.slnmod = False
        self.slnpag = None
        for x in range(0, len(ctlmst["ctm_modules"].rstrip()), 2):
            if ctlmst["ctm_modules"][x:x + 2] == "LN":
                self.lonmod = True
            elif ctlmst["ctm_modules"][x:x + 2] == "SL":
                self.slnmod = True
        # Rest of Controls
        crsctl = self.gc.getCtl("crsctl", self.opts["conum"])
        if not crsctl:
            return
        self.glint = crsctl["ctc_glint"]
        self.glinp = crsctl["ctc_glinp"]
        if self.glint == "Y":
            self.ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not self.ctlctl:
                return
            ctls = ["crs_ctl", "vat_ctl", "dis_rec"]
            if self.gc.chkRec(self.opts["conum"], self.ctlctl, ctls):
                return
            self.crsctl = self.ctlctl["crs_ctl"]
            self.disrec = self.ctlctl["dis_rec"]
        # Batch Header
        self.batchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        if self.opts["rtn"] == 1:
            self.glt = 5
        elif self.opts["rtn"] == 2:
            self.glt = 6
        elif self.opts["rtn"] == 3:
            self.glt = 4
        elif self.opts["rtn"] == 4:
            self.glt = 5
        elif self.opts["rtn"] == 5:
            self.glt = 2
        self.agevar = tk.BooleanVar()
        self.othvar = tk.BooleanVar()
        self.agevar.set(False)
        self.othvar.set(False)
        return True

    def batchHeader(self):
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "CRS",
                          self.opts["rtn"],
                          glint=self.glint)
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return

    def drawDialog(self):
        crm = {
            "stype":
            "R",
            "tables": ("crsmst", ),
            "cols":
            (("crm_acno", "", 0, "Acc-Num"), ("crm_name", "", 0, "Name", "Y")),
            "where": [("crm_cono", "=", self.opts["conum"]),
                      ("crm_stat", "<>", "X")]
        }
        coy = {
            "stype": "R",
            "tables": ("ctlmst", ),
            "cols":
            (("ctm_cono", "", 0, "Coy"), ("ctm_name", "", 0, "Name", "Y"))
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "whera": [("C", "glm_cono", 0, 2)]
        }
        vtm = {
            "stype":
            "R",
            "tables": ("ctlvmf", ),
            "cols": (("vtm_code", "", 0, "C"), ("vtm_desc", "", 0,
                                                "Description", "Y")),
            "where": [("vtm_cono", "=", self.opts["conum"])]
        }
        if self.opts["rtn"] in (1, 4) and self.lonmod:
            lm1 = {
                "stype":
                "R",
                "tables": ("lonmf1", ),
                "cols": (("lm1_acno", "", 0, "Acc-Num"), ("lm1_name", "", 0,
                                                          "Name", "Y")),
                "whera": [("C", "lm1_cono", 0, 2)]
            }
            lm2 = {
                "stype":
                "R",
                "tables": ("lonmf2", ),
                "cols": (("lm2_loan", "", 0, "Ln"), ("lm2_desc", "", 0,
                                                     "Description", "Y")),
                "whera": [("C", "lm2_cono", 0, 2), ("C", "lm2_acno", 0)]
            }
        if self.opts["rtn"] in (1, 4) and self.slnmod:
            wgm = {
                "stype":
                "R",
                "tables": ("wagmst", ),
                "cols": (("wgm_empno", "", 0, "EmpNo"), ("wgm_sname", "", 0,
                                                         "Surname", "Y"),
                         ("wgm_fname", "", 0, "Names")),
                "whera": [("C", "wgm_cono", 0, 2)]
            }
            lnm = {
                "stype":
                "R",
                "tables": ("waglmf", ),
                "cols": (("wlm_loan", "", 0, "Ln"), ("wlm_desc", "", 0,
                                                     "Description", "Y")),
                "where": [("wlm_cono", "=", self.opts["conum"])],
                "whera": [("C", "wgm_cono", 0, 2), ("C", "wlm_empno", 0)]
            }
            ced = {
                "stype":
                "R",
                "tables": ("wagedc", ),
                "cols": (("ced_type", "", 0, "T"), ("ced_code", "", 0, "Cde"),
                         ("ced_desc", "", 0, "Description", "Y")),
                "where": [("ced_type", "=", "D")],
                "whera": [("C", "wgm_cono", 0, 2)],
                "index":
                1
            }
        viw = {
            "stype":
            "R",
            "tables": ("crstrn", ),
            "cols": (("crt_acno", "", 0, ""), ("crt_ref1", "", 0, ""),
                     ("crt_trdt", "", 0, ""), ("crt_tramt", "", 0,
                                               ""), ("crt_taxamt", "", 0, "")),
            "where": [("crt_cono", "=", self.opts["conum"]),
                      ("crt_type", "=", self.opts["rtn"]),
                      ("crt_batch", "=", self.bh.batno)],
            "order":
            "crt_seq",
            "comnd":
            self.doView
        }
        fld = [(("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2, "Value"),
               (("C", 1, 0, 0), "INA", 7, "Acc-Num", "Account Number", "r",
                "Y", self.doCrsAcc, crm, None, None),
               [("C", 1, 0, 1), "ONA", 10, "Name"],
               (("C", 1, 0, 2), "INa", 9, "Reference", "Reference Number One",
                "i", "N", self.doRef1, None, None, ("notblank", )),
               (("C", 1, 0, 3), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 4), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, None)]
        if self.opts["rtn"] in (2, 5):
            fld[3][2] = 22
            fld.extend([
                (("C", 1, 0, 5), "ISD", 13.2, "Discount", "Discount Amount",
                 "", "N", self.doDisAmt, None, None, None, None,
                 "Discount Amount to be Added to the Transaction Amount."),
                (("C", 1, 0, 6), "OSD", 13.2, "Total-Amount"),
                [("C", 1, 0, 7), "INA", (22, 30), "Details",
                 "Transaction Details", "", "N", self.doTrnDet, None, None,
                 None]
            ])
        elif self.glint == "Y":
            if self.glinp == "E":
                tx1 = "Exc-Amount"
                tx2 = "Exclusive Amount"
            else:
                tx1 = "Inc-Amount"
                tx2 = "Inclusive Amount"
            fld[3][2] = 30
            fld.extend([(("C", 1, 0, 5), "INA", (27, 30), "Details",
                         "Transaction Details", "", "N", self.doTrnDet, None,
                         None, None),
                        [("T", 2, 0, 0), "OSD", 13.2, "Unallocated Balance"],
                        [("C", 2, 0, 0), "IUI", 3, "Coy", "Company Number",
                         self.opts["conum"], "N", self.doCoyNum, coy, None,
                         None],
                        (("C", 2, 0, 1), "IUI", 7, "Acc-Num", "Account Number",
                         "", "N", self.doGenAcc, glm, None, None),
                        (("C", 2, 0, 2), "ONA", 19, "Description"),
                        (("C", 2, 0, 3), "IUA", 1, "V", "V.A.T Code", "", "N",
                         self.doVatCode2, vtm, None, ("notblank", )),
                        (("C", 2, 0, 4), "ISD", 13.2, tx1, tx2, "", "N",
                         self.doAllAmt, None, None, ("efld", )),
                        (("C", 2, 0, 5), "ISD", 13.2, "V.A.T", "V.A.T Amount",
                         "", "N", self.doAllVat, None, None, None),
                        (("C", 2, 0, 6), "INA", (26, 30), "Details", "",
                         "", "N", self.doAllDet, None, None, ("notblank", ))])
            if not self.incoac:
                fld[9][1] = "OUI"
            nxt = 3
            if self.opts["rtn"] in (1, 4) and self.lonmod:
                fld.extend([
                    (("T", nxt, 0, 0), "OSD", 13.2, "Unallocated Balance"),
                    (("C", nxt, 0, 0), "IUA", 7, "Acc-Num", "Account Number",
                     0, "N", self.doLonAcc, lm1, None, None),
                    (("C", nxt, 0, 1), "ONA", 30, "Name"),
                    (("C", nxt, 0, 2), "IUI", 2, "Ln", "Loan Number", "", "N",
                     self.doLonNum, lm2, None, None),
                    (("C", nxt, 0, 3), "INA", 30, "Description", "", "", "N",
                     self.doLonDes, None, None, ("notblank", )),
                    (("C", nxt, 0, 4), "ISD", 13.2, "Amount", "", "", "N",
                     self.doLonAmt, None, None, ("efld", )),
                    (("C", nxt, 0, 5), "IUD", 6.2, "DRte-%", "Debit Rate", "",
                     "N", self.doLonDri, None, None, None),
                    (("C", nxt, 0, 6), "IUD", 6.2, "CRte-%", "Credit Rate", "",
                     "N", self.doLonDri, None, None, None),
                    (("C", nxt, 0, 7), "IUI", 3, "Mth", "Period in Months", "",
                     "N", self.doLonMth, None, None, ("efld", )),
                    (("C", nxt, 0, 8), "OUD", 12.2, "Repayment")
                ])
                self.lonpag = nxt
                nxt += 1
            if self.opts["rtn"] in (1, 4) and self.slnmod:
                fld.extend([
                    (("T", nxt, 0, 0), "OSD", 13.2, "Unallocated Balance"),
                    (("C", nxt, 0, 0), "IUI", 5, "EmpNo", "Employee Number", 0,
                     "N", self.doEmpNum, wgm, None, None),
                    (("C", nxt, 0, 1), "ONA", 20, "Name"),
                    (("C", nxt, 0, 2), "IUI", 2, "Ln", "Loan Number", "", "N",
                     self.doSlnNum, lnm, None, None),
                    (("C", nxt, 0, 3), "INA", 20, "Description", "", "", "N",
                     self.doSlnDes, None, None, ("notblank", )),
                    (("C", nxt, 0, 4), "ISD", 13.2, "Amount", "", "", "N",
                     self.doSlnAmt, None, None, ("efld", )),
                    (("C", nxt, 0, 5), "IUI", 3, "Cde", "Deduction Code", "",
                     "N", self.doSlnCod, ced, None, ("efld", )),
                    (("C", nxt, 0, 6), "ONA", 20, "Description"),
                    (("C", nxt, 0, 7), "IUD", 6.2, "Intr-%", "Interest Rate",
                     "", "N", self.doSlnInt, None, None, None),
                    (("C", nxt, 0,
                      8), "IUD", 13.2, "Ded-Amt", "Deduction Amount", "", "N",
                     self.doSlnDed, None, None, ("efld", ))
                ])
                self.slnpag = nxt
        else:
            fld[3][2] = 20
            fld.extend([(("C", 1, 0,
                          5), "IUA", 1, "V", "V.A.T Code", self.taxdf, "N",
                         self.doVatCode1, vtm, None, ("notblank", )),
                        (("C", 1, 0, 6), "ISD", 13.2, "V.A.T", "V.A.T Amount",
                         "", "N", self.doVatAmt, None, None, None),
                        [("C", 1, 0, 7), "INA", (18, 30), "Details",
                         "Transaction Details", "", "N", self.doTrnDet, None,
                         None, None]])
        but = (
            ("Interrogate",None,self.queryCrs,0,("C",1,1),("C",1,2),
                "Interrogate Creditors Records",1),
            ("View Entries",viw,None,0,("C",1,1),("C",1,2),
                "View Batch Transactions",1),
            ("Maintain",None,self.maintainCrs,0,("C",1,1),("C",1,2),
                "Maintain Creditors Records",1),
            ("Canc_el",None,self.doCancel,0,("C",2,1),("C",1,1),
                "Cancel the Entry",1),
            ("Age _Normal",None,self.doAgeNormal,0,None,None,
                "Only Show Unallocated Transactions",2),
            ("Age _History",None,self.doAgeHistory,0,None,None,
                "Show All Transactions Including Already Allocated",2),
            ("Age _Automatic",None,self.doAgeAuto,0,None,None,
                "Automatically Allocate the Amount Starting With the "\
                "Oldest Unallocated Transaction",2),
            ("Age _Current",None,self.doAgeCurrent,0,None,None,
                "Leave the Transaction Unallocated",2))
        tag = [("Transaction", None, None, None, False)]
        cnd = [(None, "n"), (self.endPage1, "y")]
        cxt = [None, self.exitPage1]
        if self.opts["rtn"] not in (2, 5) and self.glint == "Y":
            tag.append(("Allocation", None, None, None, False))
            cnd.append((self.endPage2, "y"))
            cxt.append(self.exitPage2)
            if self.opts["rtn"] in (1, 4) and self.lonmod:
                tag.append(("LON", None, None, None, False))
                cnd.append((self.endLon, "y"))
                cxt.append(self.exitLon)
            if self.opts["rtn"] in (1, 4) and self.slnmod:
                tag.append(("SLN", None, None, None, False))
                cnd.append((self.endSln, "y"))
                cxt.append(self.exitSln)
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tags=tag,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 1, 1)

    def doView(self, *event):
        self.df.focusField("C", 1, 1)

    def doCrsAcc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("crsmst",
                              cols=[
                                  "crm_name", "crm_terms", "crm_vatno",
                                  "crm_termsb", "crm_stday", "crm_pydis",
                                  "crm_glac", "crm_stat"
                              ],
                              where=[("crm_cono", "=", self.opts["conum"]),
                                     ("crm_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account Number"
        if acc[7] == "X":
            return "Invalid Account, Redundant"
        self.cracno = w
        self.name = acc[0]
        self.term = acc[1]
        self.vatn = acc[2]
        self.base = acc[3]
        self.stdt = acc[4]
        self.pdis = acc[5]
        self.glac = acc[6]
        self.popv = False
        self.df.loadEntry(frt, pag, p + 1, data=self.name)

    def doRef1(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("crstrn",
                              cols=["crt_batch"],
                              where=[("crt_cono", "=", self.opts["conum"]),
                                     ("crt_acno", "=", self.cracno),
                                     ("crt_type", "=", self.opts["rtn"]),
                                     ("crt_ref1", "=", w)],
                              limit=1)
        if acc:
            return "Transaction Already Exists"
        self.trnref = w

    def doTrnDat(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not in Financial Period"
        if self.bh.multi == "N" and int(w / 100) > self.bh.curdt:
            return "Invalid Date, After Batch Period"
        self.trndat = w

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w
        if self.glint == "Y" or self.opts["rtn"] in (2, 5):
            self.vatcode = "N"
            self.vatamt = 0
        if self.opts["rtn"] not in (2, 5) and self.glint == "N":
            if not self.vatn:
                self.df.loadEntry(frt, pag, p + 1, data="N")
            else:
                self.df.loadEntry(frt, pag, p + 1, data=self.taxdf)

    def doVatCode1(self, frt, pag, r, c, p, i, w):
        vrte = getVatRate(self.sql, self.opts["conum"], w, self.trndat)
        if vrte is None:
            return "Invalid V.A.T Code"
        if vrte and not self.vatn:
            ok = askQuestion(self.opts["mf"].window, "VAT Number",
                "This Account Does Not Have a VAT Number.\n\nMust "\
                "it be Populated?", default="yes")
            if ok == "yes":
                self.vatn = w
                self.popv = True
        self.vatcode = w
        self.vatamt = round((self.trnamt * vrte / (vrte + 100)), 2)
        self.df.loadEntry(frt, pag, p + 1, data=self.vatamt)
        if not self.vatamt:
            return "sk1"

    def doVatAmt(self, frt, pag, r, c, p, i, w):
        if self.trnamt < 0 and w > 0:
            self.vatamt = float(ASD(0) - ASD(w))
        elif self.trnamt > 0 and w < 0:
            self.vatamt = float(ASD(0) - ASD(w))
        else:
            self.vatamt = w
        self.df.loadEntry(frt, pag, p, data=self.vatamt)

    def doDisAmt(self, frt, pag, r, c, p, i, w):
        if self.trnamt < 0 and w > 0:
            self.disamt = float(ASD(0) - ASD(w))
        elif self.trnamt > 0 and w < 0:
            self.disamt = float(ASD(0) - ASD(w))
        else:
            self.disamt = w
        self.df.loadEntry(frt, pag, p, data=self.disamt)
        totamt = float(ASD(self.trnamt) + ASD(self.disamt))
        self.df.loadEntry(frt, pag, p + 1, data=totamt)

    def doTrnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w
        if self.opts["rtn"] not in (2, 5) and self.glint == "Y":
            self.df.colf[2][6][5] = w
        self.allocated = float(0.00)

    def endPage1(self):
        self.cancel = False
        self.agecan = False
        self.batupd = False
        self.updateTables1()
        if self.cancel:
            return
        else:
            self.updateBatch()
            if self.trnamt == 0:
                self.df.advanceLine(1)
            else:
                self.allocated = float(0.0)
                if self.opts["rtn"] in (2, 5) or self.glint == "N":
                    self.doCrsTrn()
                    self.opts["mf"].dbm.commitDbase()
                    self.df.selPage("Transaction")
                    self.df.advanceLine(1)
                else:
                    self.df.selPage("Allocation")
                    self.df.loadEntry("T", 2, 0, data=self.trnamt)
                    self.df.focusField("C", 2, 1)

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        self.amt = self.trnamt
        self.vat = self.vatamt
        if self.opts["rtn"] == 1:  # Invoices
            self.recon = 0
            self.dis = 0.00
            self.per = self.pdis
        elif self.opts["rtn"] == 2:  # Receipts
            if self.trnamt == 0:
                self.recon = self.curdt
            else:
                self.recon = 0
            self.vat = 0.00
            self.dis = self.disamt
            self.per = 0.00
        elif self.opts["rtn"] == 3:  # Journals
            self.recon = 0
            self.dis = 0.00
            self.per = 0.00
        elif self.opts["rtn"] == 4:  # Credit Notes
            self.recon = 0
            self.amt = float(ASD(0) - ASD(self.amt))
            self.vat = float(ASD(0) - ASD(self.vat))
            self.dis = 0.00
            self.per = self.pdis
        elif self.opts["rtn"] == 5:  # Payments
            if self.trnamt == 0:
                self.recon = self.curdt
            else:
                self.recon = 0
            self.amt = float(ASD(0) - ASD(self.amt))
            self.vat = 0.00
            self.dis = float(ASD(0) - ASD(self.disamt))
            self.per = 0.00
        if self.opts["rtn"] == 1:
            self.doAgeCurrent()
        else:
            state = self.df.disableButtonsTags()
            self.opts["mf"].updateStatus("Choose an Ageing Option")
            for x in range(4, 8):
                if self.opts["rtn"] == 3 and x == 6:
                    continue
                wid = getattr(self.df, "B%s" % x)
                self.df.setWidget(wid, "normal")
            self.df.setWidget(self.df.B4, "focus")
            self.agevar.set(True)
            self.df.mstFrame.wait_variable(self.agevar)
            self.df.enableButtonsTags(state=state)
            if self.agecan:
                self.doCancel()
                return
        if self.glint == "N":
            return
        # General Ledger Control Transaction (Creditors)
        val = float(ASD(0) - ASD(self.amt) - ASD(self.dis))
        data = (self.opts["conum"], self.crsctl, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, val, 0.00, self.trndet,
                "N", "", self.recon, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        # General Ledger Control Transaction (Bank)
        if self.opts["rtn"] in (2, 5):
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                    self.glt, self.trnref, self.bh.batno, self.amt, 0.00,
                    self.trndet, "N", "", self.recon, self.opts["capnm"],
                    self.sysdtw, 0)
            self.sql.insRec("gentrn", data=data)
            # General Ledger Control Transaction (Discount)
            if self.dis:
                data = (self.opts["conum"], self.disrec, self.curdt,
                        self.trndat, self.glt, self.trnref, self.bh.batno,
                        self.dis, 0.00, self.trndet, "N", "", self.recon,
                        self.opts["capnm"], self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)

    def doAgeNormal(self):
        self.doAgeing("N")

    def doAgeHistory(self):
        self.doAgeing("H")

    def doAgeAuto(self):
        self.doAgeing("O")

    def doAgeCurrent(self):
        self.doAgeing("C")

    def doAgeing(self, atype):
        # Disable All Ageing Buttons
        for x in range(4, 8):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "disabled")
        self.opts["mf"].updateStatus("Select Transaction to Allocate Against")
        age = AgeAll(self.opts["mf"],
                     system="crs",
                     agetyp=atype,
                     agekey=[
                         self.opts["conum"], self.cracno, self.opts["rtn"],
                         self.trnref, self.curdt, self.amt, self.dis
                     ])
        self.agecan = age.cancel
        if self.agevar.get():
            self.agevar.set(False)

    def exitPage1(self):
        self.df.closeProcess()
        self.bh.doBatchTotal()
        self.opts["mf"].closeLoop()

    def doCoyNum(self, frt, pag, r, c, p, i, w):
        nam = self.sql.getRec("ctlmst",
                              cols=["ctm_name"],
                              where=[("ctm_cono", "=", w)],
                              limit=1)
        if not nam:
            return "Invalid Company, Missing"
        if self.incoac and w not in self.incoac:
            return "Invalid Company, No Intercompany Record 1"
        if w != self.opts["conum"]:
            acc = self.sql.getRec("genint",
                                  where=[("cti_cono", "=", w),
                                         ("cti_inco", "=", self.opts["conum"])
                                         ],
                                  limit=1)
            if not acc:
                return "Invalid Company, No Intercompany Record 2"
        self.ctlctl = self.gc.getCtl("ctlctl", w)
        if not self.ctlctl:
            return "rf"
        self.allcoy = w
        self.allnam = nam[0]
        self.df.loadEntry(frt, pag, p + 1, data=self.glac)

    def doGenAcc(self, frt, pag, r, c, p, i, w):
        ctl = True
        self.loan = False
        if "lon_ctl" in self.ctlctl and w == self.ctlctl["lon_ctl"]:
            self.loan = "other"
        elif "wag_slc" in self.ctlctl and w == self.ctlctl["wag_slc"]:
            self.loan = "staff"
        if self.loan:
            ctl = False
        chk = chkGenAcc(self.opts["mf"], self.allcoy, w, ctl=ctl)
        if type(chk) is str:
            return chk
        if not self.vatn:
            self.taxgl = "N"
        elif not chk[2]:
            self.taxgl = self.taxdf
        else:
            self.taxgl = chk[2]
        self.genacc = w
        self.df.loadEntry(frt, pag, p + 1, data=chk[0])
        self.df.loadEntry(frt, pag, p + 2, data=self.taxgl)

    def doVatCode2(self, frt, pag, r, c, p, i, w):
        ctlctl = self.gc.getCtl("ctlctl", self.allcoy, error=False)
        if not ctlctl:
            return "Missing ctlctl Record for Company"
        if self.gc.chkRec(self.allcoy, ctlctl, ["vat_ctl"]):
            return "Missing or Invalid Control Record"
        self.convat = ctlctl["vat_ctl"]
        self.vatrte = getVatRate(self.sql, self.allcoy, w, self.trndat)
        if self.vatrte is None:
            return "Invalid V.A.T Code"
        if self.vatrte and not self.vatn:
            ok = askQuestion(self.opts["mf"].window, "VAT Number",
                "This Account Does Not Have a VAT Number.\n\nMust "\
                "it be Populated?", default="yes")
            if ok == "yes":
                self.vatn = w
                self.popv = True
        self.vatcode = w

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if not w:
            incamt = float(ASD(self.trnamt) - ASD(self.allocated))
        elif self.glinp == "E":
            incamt = round((w * (100 + self.vatrte) / 100), 2)
        else:
            incamt = w
        self.allamt = round((incamt * 100 / (100 + self.vatrte)), 2)
        self.allvat = float(ASD(incamt) - ASD(self.allamt))
        if self.glinp == "E":
            self.df.loadEntry(frt, pag, p, data=self.allamt)
        else:
            self.df.loadEntry(frt, pag, p, data=incamt)
        self.df.loadEntry(frt, pag, p + 1, data=self.allvat)
        if not self.allvat:
            self.df.loadEntry(frt, pag, p + 2, data=self.name)
            return "sk1"

    def doAllVat(self, frt, pag, r, c, p, i, w):
        if (self.allamt < 0 and w > 0) or (self.allamt > 0 and w < 0):
            w = float(ASD(0) - ASD(w))
        if self.glinp == "I" and w != self.allvat:
            self.allamt = float(ASD(self.allamt) + ASD(self.allvat) - ASD(w))
        self.allvat = w
        self.df.loadEntry(frt, pag, p, data=self.allvat)
        self.df.loadEntry(frt, pag, p + 1, data=self.name)

    def doAllDet(self, frt, pag, r, c, p, i, w):
        self.alldet = w

    def doCancel(self):
        if self.agecan:
            ok = "yes"
        else:
            ok = askQuestion(
                self.opts["mf"].body,
                head="Cancel",
                mess="Are You Certain You Want to Cancel This Entry?")
        if ok == "yes":
            self.cancel = True
            self.opts["mf"].dbm.rollbackDbase()
            if self.batupd:
                self.updateBatch(rev=True)
            for pg in range(self.df.pgs, 1, -1):
                self.df.clearFrame("C", pg)
            self.df.selPage("Transaction")
            row = int((self.df.last[1][1] - 1) / self.df.colq[1])
            col = (row * self.df.colq[1]) + 1
            self.df.focusField("C", 1, col)
            if self.othvar.get():
                self.othvar.set(False)

    def endPage2(self):
        self.updateTables2()
        if self.loan and self.loan == "other":
            self.othtot = self.allamt
            self.df.selPage("LON")
            self.df.loadEntry("T", self.lonpag, 0, data=self.othtot)
            self.df.focusField("C", self.lonpag, 1)
            self.othvar.set(True)
            self.df.mstFrame.wait_variable(self.othvar)
            if self.cancel:
                return
        elif self.loan and self.loan == "staff":
            self.othtot = self.allamt
            self.df.selPage("SLN")
            self.df.loadEntry("T", self.slnpag, 0, data=self.othtot)
            self.df.focusField("C", self.slnpag, 1)
            self.othvar.set(True)
            self.df.mstFrame.wait_variable(self.othvar)
            if self.cancel:
                return
        self.allocated = float(ASD(self.allocated) + ASD(self.allamt) + \
            ASD(self.allvat))
        if self.allocated == self.trnamt:
            self.doCrsTrn()
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def updateTables2(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        if self.opts["rtn"] == 1:  # Invoices
            self.debit()
        elif self.opts["rtn"] == 3:  # Journals
            self.debit()
        elif self.opts["rtn"] == 4:  # Credit Notes
            self.credit()

    def debit(self):
        amt = self.allamt
        vat = self.allvat
        self.restDebitCredit(amt, vat)

    def credit(self):
        amt = float(ASD(0) - ASD(self.allamt))
        vat = float(ASD(0) - ASD(self.allvat))
        self.restDebitCredit(amt, vat)

    def restDebitCredit(self, amt, vat):
        # VAT Transaction (ctlvtf)
        data = (self.allcoy, self.vatcode, "I", self.curdt, "C",
                self.opts["rtn"], self.bh.batno, self.trnref, self.trndat,
                self.cracno, self.alldet, amt, vat, 0, self.opts["capnm"],
                self.sysdtw, 0)
        self.sql.insRec("ctlvtf", data=data)
        if self.glint == "N":
            return
        # General Ledger Transaction (Expense)
        data = (self.allcoy, self.genacc, self.curdt, self.trndat, self.glt,
                self.trnref, self.bh.batno, amt, vat, self.alldet,
                self.vatcode, "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        # General Ledger Transaction (Intercompany)
        if self.allcoy != self.opts["conum"]:
            # General Ledger Transaction (Intercompany From)
            acc = self.sql.getRec("genint",
                                  cols=["cti_acno"],
                                  where=[("cti_cono", "=", self.opts["conum"]),
                                         ("cti_inco", "=", self.allcoy)],
                                  limit=1)[0]
            val = float(ASD(amt) + ASD(vat))
            data = (self.opts["conum"], acc, self.curdt, self.trndat, self.glt,
                    self.trnref, self.bh.batno, val, 0.00, self.alldet, "N",
                    "", 0, self.opts["capnm"], self.sysdtw, 0)
            self.sql.insRec("gentrn", data=data)
            # General Ledger Transaction (Intercompany To)
            acc = self.sql.getRec("genint",
                                  cols=["cti_acno"],
                                  where=[("cti_cono", "=", self.allcoy),
                                         ("cti_inco", "=", self.opts["conum"])
                                         ],
                                  limit=1)[0]
            val = float(ASD(0) - ASD(amt) - ASD(vat))
            data = (self.allcoy, acc, self.curdt, self.trndat, self.glt,
                    self.trnref, self.bh.batno, val, 0.00, self.alldet, "N",
                    "", 0, self.opts["capnm"], self.sysdtw, 0)
            self.sql.insRec("gentrn", data=data)
        if vat:
            # General Ledger Control Transaction (V.A.T.)
            data = (self.allcoy, self.convat, self.curdt, self.trndat,
                    self.glt, self.trnref, self.bh.batno, vat, 0.00,
                    self.alldet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)
        self.vat = float(ASD(self.vat) + ASD(vat))

    def exitPage2(self):
        self.df.focusField("C", 2, self.df.col)

    def doCrsTrn(self):
        # Creditors Master File
        if self.popv:
            self.sql.updRec("crsmst",
                            cols=["crm_vatno"],
                            data=["Unknown"],
                            where=[("crm_cono", "=", self.opts["conum"]),
                                   ("crm_acno", "=", self.cracno)])
        # Creditors Ledger Transaction
        paydt = paymentDate(self.base, self.stdt, self.term, self.trndat)
        data = [
            self.opts["conum"], self.cracno, self.opts["rtn"], self.trnref,
            self.bh.batno, self.trndat, "", self.amt, self.vat, self.per,
            self.curdt, paydt, "Y", self.amt, self.trndet, self.vatcode, "N",
            self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("crstrn", data=data)
        if not self.dis:
            return
        data = [
            self.opts["conum"], self.cracno, 6, self.trnref, self.bh.batno,
            self.trndat, "", self.dis, self.vat, 0, self.curdt, paydt, "Y",
            self.dis, self.trndet, self.vatcode, "N", self.opts["capnm"],
            self.sysdtw, 0
        ]
        self.sql.insRec("crstrn", data=data)

    def updateBatch(self, rev=False):
        if rev:
            self.bh.batqty = self.bh.batqty - 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.trnamt))
        else:
            self.batupd = True
            self.bh.batqty = self.bh.batqty + 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.trnamt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def queryCrs(self):
        callModule(self.opts["mf"],
                   self.df,
                   "cr4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])

    def maintainCrs(self):
        callModule(self.opts["mf"],
                   self.df,
                   "cr1010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])

    def doLonAcc(self, frt, pag, r, c, p, i, w):
        newacc = False
        if not w and self.opts["rtn"] == 1:
            yn = askQuestion(self.opts["mf"].body,
                             "New Account",
                             "Is This a New Account?",
                             default="no")
            if yn == "no":
                return "Invalid Account Number"
            newacc = True
            w = callModule(self.opts["mf"],
                           self.df,
                           "ln1010",
                           coy=(self.allcoy, self.allnam),
                           user=self.opts["capnm"],
                           args="auto",
                           ret="acno")
            self.df.loadEntry(frt, pag, p, data=w)
        acc = self.sql.getRec("lonmf1",
                              cols=["lm1_name"],
                              where=[("lm1_cono", "=", self.allcoy),
                                     ("lm1_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account Number"
        self.lonacc = w
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        if newacc:
            self.lonnum = 1
            self.newlon = True
            self.df.loadEntry(frt, pag, p + 2, data=self.lonnum)
            return "sk2"

    def doLonNum(self, frt, pag, r, c, p, i, w):
        if not w and self.opts["rtn"] == 1:
            ok = askQuestion(self.opts["mf"].body,
                             head="New Loan",
                             mess="Is This a New Loan?",
                             default="no")
            if ok == "yes":
                self.newlon = True
                self.lonnum = getNextCode(self.sql,
                                          "lonmf2",
                                          "lm2_loan",
                                          where=[
                                              ("lm2_cono", "=", self.allcoy),
                                              ("lm2_acno", "=", self.lonacc)
                                          ],
                                          start=1,
                                          last=9999999)
                self.df.loadEntry(frt, pag, p, data=self.lonnum)
            else:
                return "Invalid Loan Number"
        else:
            self.lonmf2 = self.sql.getRec("lonmf2",
                                          where=[
                                              ("lm2_cono", "=", self.allcoy),
                                              ("lm2_acno", "=", self.lonacc),
                                              ("lm2_loan", "=", w)
                                          ],
                                          limit=1)
            if not self.lonmf2:
                return "Invalid Loan Number"
            self.lonnum = w
            self.newlon = False
            self.londes = self.lonmf2[self.sql.lonmf2_col.index("lm2_desc")]
            self.londat = self.lonmf2[self.sql.lonmf2_col.index("lm2_start")]
            self.lonmth = self.lonmf2[self.sql.lonmf2_col.index("lm2_pmths")]
            self.lonpay = self.lonmf2[self.sql.lonmf2_col.index("lm2_repay")]
            if self.lonmth:
                return "Invalid Entry, Fixed Loan"
            self.df.loadEntry(frt, pag, p + 1, data=self.londes)
            return "sk1"

    def doLonDes(self, frt, pag, r, c, p, i, w):
        self.londes = w

    def doLonAmt(self, frt, pag, r, c, p, i, w):
        self.lonamt = w
        if not self.lonamt:
            self.lonamt = self.othtot
        self.df.loadEntry(frt, pag, p, data=self.lonamt)
        if not self.newlon:
            self.newdri = 0
            return "nd"

    def doLonDri(self, frt, pag, r, c, p, i, w):
        self.newdri = w

    def doLonCri(self, frt, pag, r, c, p, i, w):
        self.newcri = w

    def doLonMth(self, frt, pag, r, c, p, i, w):
        self.lonmth = w
        if self.lonmth:
            rte = (self.newdri / 1200.0)
            self.lonpay = round(
                ((self.lonamt * rte) * ((1 + rte)**w)) / (((1 + rte)**w) - 1),
                2)
        else:
            self.lonpay = 0
        self.df.loadEntry(frt, pag, p + 1, data=self.lonpay)

    def endLon(self):
        if self.opts["rtn"] == 4:
            tramt = float(ASD(0.0) - ASD(self.lonamt))
        else:
            tramt = self.lonamt
        self.othtot = float(ASD(self.othtot) - ASD(self.lonamt))
        if self.newlon:
            # Loans Rate
            self.sql.insRec("lonrte",
                            data=[
                                self.allcoy, self.lonacc, self.lonnum,
                                self.trndat, self.newdri, self.newcri
                            ])
            # Loans Ledger Masterfile
            self.sql.insRec("lonmf2",
                            data=[
                                self.allcoy, self.lonacc, self.lonnum,
                                self.londes, self.trndat, self.lonmth,
                                self.lonpay, 0
                            ])
            self.othrtn = 2
        else:
            self.othrtn = 3
        # Loans Ledger Transaction
        data = [
            self.allcoy, self.lonacc, self.lonnum, self.bh.batno, self.othrtn,
            self.trndat, self.trnref, tramt, self.curdt, self.alldet, "",
            self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("lontrn", data=data)
        if self.othtot:
            self.df.loadEntry("T", self.lonpag, 0, data=self.othtot)
            self.df.advanceLine(self.lonpag)
        else:
            self.othvar.set(False)

    def exitLon(self):
        self.df.focusField("C", self.lonpag, self.df.col)

    def doEmpNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("wagmst",
                              cols=["wgm_sname", "wgm_fname"],
                              where=[("wgm_cono", "=", self.allcoy),
                                     ("wgm_empno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Employee Number"
        self.empnum = w
        empnam = "%s, %s" % (acc[0], acc[1].split()[0])
        self.df.loadEntry(frt, pag, p + 1, data=empnam)

    def doSlnNum(self, frt, pag, r, c, p, i, w):
        if not w and self.opts["rtn"] == 1:
            ok = askQuestion(self.opts["mf"].body,
                             head="New Loan",
                             mess="Is This a New Loan?",
                             default="no")
            if ok == "yes":
                self.newsln = True
                self.slnnum = getNextCode(self.sql,
                                          "waglmf",
                                          "wlm_loan",
                                          where=[
                                              ("wlm_cono", "=", self.allcoy),
                                              ("wlm_empno", "=", self.empnum)
                                          ],
                                          start=1,
                                          last=9999999)
                self.df.loadEntry(frt, pag, p, data=self.slnnum)
            else:
                return "Invalid Loan Number"
        else:
            acc = self.sql.getRec("waglmf",
                                  where=[("wlm_cono", "=", self.allcoy),
                                         ("wlm_empno", "=", self.empnum),
                                         ("wlm_loan", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Loan Number"
            self.slnnum = w
            self.newsln = False
            self.slndes = acc[self.sql.waglmf_col.index("wlm_desc")]
            self.slncod = acc[self.sql.waglmf_col.index("wlm_code")]
            self.slnrte = acc[self.sql.waglmf_col.index("wlm_rate")]
            self.slndat = acc[self.sql.waglmf_col.index("wlm_start")]
            self.slnded = acc[self.sql.waglmf_col.index("wlm_repay")]
            self.df.loadEntry(frt, pag, p + 1, data=self.slndes)
            return "sk1"

    def doSlnDes(self, frt, pag, r, c, p, i, w):
        self.slndes = w

    def doSlnAmt(self, frt, pag, r, c, p, i, w):
        self.slnamt = w
        if not self.slnamt:
            self.slnamt = self.othtot
        self.df.loadEntry(frt, pag, p, data=self.slnamt)
        if not self.newsln:
            self.df.loadEntry(frt, pag, p + 1, data=self.slncod)

    def doSlnCod(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("wagedc",
                              cols=["ced_desc"],
                              where=[("ced_cono", "=", self.allcoy),
                                     ("ced_type", "=", "D"),
                                     ("ced_code", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        self.slncod = w
        if not self.newsln:
            self.newrte = 0
            self.slnded = 0
            return "nd"

    def doSlnInt(self, frt, pag, r, c, p, i, w):
        self.newrte = w
        if not self.newsln:
            self.df.loadEntry(frt, pag, p + 2, data=self.slnded)

    def doSlnDed(self, frt, pag, r, c, p, i, w):
        self.slnded = w

    def endSln(self):
        if self.opts["rtn"] == 4:
            tramt = float(ASD(0.0) - ASD(self.slnamt))
        else:
            tramt = self.slnamt
        self.othtot = float(ASD(self.othtot) - ASD(self.slnamt))
        if self.newsln:
            # Staff Loans Ledger Masterfile
            self.sql.insRec("waglmf",
                            data=[
                                self.allcoy, self.empnum, self.slnnum,
                                self.slndes, self.slncod, self.newrte,
                                self.trndat, self.slnded
                            ])
            self.othrtn = 2
        else:
            self.othrtn = 3
        # Staff Loans Ledger Transaction
        data = [
            self.allcoy, self.empnum, self.slnnum, self.bh.batno, self.othrtn,
            self.trndat, self.trnref, tramt, tramt, self.slnded, self.newrte,
            self.curdt, self.alldet, "", self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("wagltf", data=data)
        if self.othtot:
            self.df.loadEntry("T", self.slnpag, 0, data=self.othtot)
            self.df.advanceLine(self.slnpag)
        else:
            self.othvar.set(False)

    def exitSln(self):
        self.df.focusField("C", self.slnpag, self.df.col)
Пример #14
0
class cs2010(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"])
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        if not self.taxdf:
            self.taxdf = "N"
        cshctl = gc.getCtl("cshctl", self.opts["conum"])
        if not cshctl:
            return
        self.glint = cshctl["ccc_glint"]
        if self.glint == "Y":
            tabs = ["genmst"]
        else:
            tabs = ["cshmst"]
        tabs.extend(["cshana", "cshcnt"])
        self.sql = Sql(self.opts["mf"].dbm,
                       tables=tabs,
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        if self.glint == "Y":
            self.ctl = [["csh_ctl", "Cash Control", 0]]
            ctlctl = gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            for num, ctl in enumerate(self.ctl):
                if ctl[0] in ctlctl:
                    self.ctl[num][2] = ctlctl[ctl[0]]
        t = time.localtime()
        self.sysdtw = ((t[0] * 10000) + (t[1] * 100) + t[2])
        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):
        tag = (("Expenses", None, None, None, False),
               ("Income", None, None, None, False), ("Cash", None, None, None,
                                                     False))
        dte = {
            "stype": "R",
            "tables": ("cshcnt", ),
            "cols": (("cct_date", "", 0, "Date"), ),
            "where": [("cct_cono", "=", self.opts["conum"])],
            "group": "cct_date"
        }
        if self.glint == "Y":
            self.cod = {
                "stype":
                "R",
                "tables": ("genmst", ),
                "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                          "Description", "Y")),
                "where": [("glm_cono", "=", self.opts["conum"])],
                "order":
                "glm_acno"
            }
        else:
            self.cod = {
                "stype":
                "R",
                "tables": ("cshmst", ),
                "cols": (("ccm_acno", "", 0, "Acc-Num"), ("ccm_desc", "", 0,
                                                          "Description", "Y")),
                "where": [("ccm_cono", "=", self.opts["conum"])],
                "order":
                "ccm_acno"
            }
        des = {
            "stype":
            "R",
            "tables": ("cshana", ),
            "cols": (("can_desc", "", 0, "Description", "Y"), ("can_vatcod",
                                                               "", 0, "V")),
            "where": [("can_cono", "=", self.opts["conum"])],
            "whera": (("C", "can_code", 1, 1), ),
            "group":
            "can_desc",
            "order":
            "can_desc"
        }
        r1s = (("Expenses", "P"), ("Income", "T"), ("Cash", "C"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Type", "", "P", "N",
                self.doType, None, None, None),
               (("T", 0, 1, 0), "I@cct_date", 0, "", "", self.sysdtw, "N",
                self.doDate, dte, None, ("efld", )), (("T", 0, 2, 0), "OSD",
                                                      13.2, "Expenses Total"),
               (("T", 0, 3, 0), "OSD", 13.2,
                "Income Total"), (("T", 0, 4, 0), "OSD", 13.2, "Cash Total"),
               (("C", 1, 0, 0), "I@can_trdt", 0, "", "", "", "N", None, None,
                None, ("efld", )), (("C", 1, 1,
                                     0), "I@can_code", 0, "", "", "", "N",
                                    self.doCode, self.cod, None, None),
               (("C", 1, 2, 0), "I@can_desc", 0, "", "", "", "N", self.doDesc,
                des, None, ("notblank", )), (("C", 1, 3, 0), "I@can_vatcod", 0,
                                             "", "", "N", "N", self.doVCode,
                                             None, None, ("notblank", )),
               (("C", 1, 4, 0), "I@can_incamt", 0, "", "", "", "N",
                self.doIncAmt, None, None,
                ("efld", )), (("C", 1, 5, 0), "I@can_vatamt", 0, "", "", "",
                              "N", None, None, None, ("efld", )),
               (("C", 2, 0, 0), "I@can_trdt", 0, "", "", "", "N", None, None,
                None, ("efld", )), (("C", 2, 1, 0), "I@can_code", 0, "", "",
                                    "", "N", self.doCode, self.cod, None,
                                    None), (("C", 2, 2, 0), "I@can_desc", 0,
                                            "", "", "", "N", self.doDesc, des,
                                            None, ("notblank", )),
               (("C", 2, 3, 0), "I@can_vatcod", 0, "", "", "N", "N",
                self.doVCode, None, None,
                ("notblank", )), (("C", 2, 4, 0), "I@can_incamt", 0, "", "",
                                  "", "N", self.doIncAmt, None, None,
                                  ("efld", )), (("C", 2, 5, 0), "I@can_vatamt",
                                                0, "", "", "", "N", None, None,
                                                None, ("efld", )),
               (("T", 3, 0, 0), "ISD", 13.2, "Cheques", "", "", "N",
                self.doCheq, None, None,
                ("efld", )), (("C", 3, 0, 0), "IUI", 5, "Quant", "Quantity", 0,
                              "N", self.doQty, None, None, None,
                              ("Denomination",
                               14)), (("C", 3, 1, 0), "OSD", 13.2, "Value", "",
                                      "", "N", None, None, None, ("efld", )))
        tnd = ((self.doTopEnd, "y"), None, None, (self.doTopEnd, "n"))
        txt = (self.doTopExit, None, None, None)
        cnd = (None, (self.doColEnd, "y"), (self.doColEnd, "y"),
               (self.doColEnd, "n"))
        cxt = (None, self.doColExit, self.doColExit, self.doColExit)
        but = (("Accept", None, self.doColExit, 0, (("C", 1, 1), ("C", 2, 1)),
                (("C", 1, 2), ("C", 2, 2))),
               ("Edit", None, self.doEdit, 0, (("C", 1, 1), ("C", 2, 1)),
                (("C", 1, 2), ("C", 2, 2))), ("Quit", None, self.doQuit, 0,
                                              ("T", 0, 0), ("T", 0, 1)))
        self.df = TartanDialog(self.opts["mf"],
                               tags=tag,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               butt=but,
                               focus=False)
        for x in range(14):
            self.df.colLabel[3][x].configure(text=self.denoms[x][0])
        self.df.focusField("T", 0, 1)

    def doType(self, frt, pag, r, c, p, i, w):
        self.trtp = w
        self.edit = None
        self.amend = False
        self.loader = False
        self.etotal = 0
        self.itotal = 0
        self.ctotal = 0

    def doDate(self, frt, pag, r, c, p, i, w):
        self.date = w
        rec = self.sql.getRec("cshana",
                              where=[("can_cono", "=", self.opts["conum"]),
                                     ("can_type", "=", "P"),
                                     ("can_date", "=", self.date)])
        if rec and self.trtp == "P":
            self.amend = True
        for rr in rec:
            self.etotal = float(ASD(self.etotal) + ASD(rr[7]))
        self.df.loadEntry(frt, pag, p + 1, data=self.etotal)
        rec = self.sql.getRec("cshana",
                              where=[("can_cono", "=", self.opts["conum"]),
                                     ("can_type", "=", "T"),
                                     ("can_date", "=", self.date)])
        if rec and self.trtp == "T":
            self.amend = True
        for rr in rec:
            self.itotal = float(ASD(self.itotal) + ASD(rr[7]))
        self.df.loadEntry(frt, pag, p + 2, data=self.itotal)
        self.rec = self.sql.getRec("cshcnt",
                                   where=[("cct_cono", "=",
                                           self.opts["conum"]),
                                          ("cct_type", "=", "T"),
                                          ("cct_date", "=", self.date)],
                                   limit=1)
        if self.rec and self.trtp == "C":
            self.amend = True
        if self.amend:
            return "nc"

    def doCode(self, frt, pag, r, c, p, i, w):
        if self.glint == "N" and not w:
            ok = askQuestion(self.opts["mf"].body,
                             "Code Maintenance",
                             "Do You Want to Add or Edit Codes?",
                             default="no")
            if ok == "no":
                return "rf"
            w = callModule(self.opts["mf"],
                           self.df,
                           "cs1010",
                           coy=[self.opts["conum"], self.opts["conam"]],
                           user=self.opts["capnm"],
                           args=True,
                           ret="acno")
            self.df.loadEntry(frt, pag, p, data=w)
        if self.glint == "Y":
            acc = self.sql.getRec("genmst",
                                  cols=["glm_desc", "glm_vat"],
                                  where=[("glm_cono", "=", self.opts["conum"]),
                                         ("glm_acno", "=", w)],
                                  limit=1)
        else:
            acc = self.sql.getRec("cshmst",
                                  cols=["ccm_desc", "ccm_vat"],
                                  where=[("ccm_cono", "=", self.opts["conum"]),
                                         ("ccm_acno", "=", w)],
                                  limit=1)
        if not acc:
            return "Invalid Code"
        self.code = w
        self.vcod = acc[1]
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])

    def doDesc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("cshana",
                              cols=["can_vatcod"],
                              where=[("can_cono", "=", self.opts["conum"]),
                                     ("can_code", "=", self.code),
                                     ("can_desc", "=", w)],
                              order="can_date desc",
                              limit=1)
        if acc:
            self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        else:
            self.df.loadEntry(frt, pag, p + 1, data=self.vcod)

    def doVCode(self, frt, pag, r, c, p, i, w):
        self.vatrte = getVatRate(self.sql, self.opts["conum"], w, self.date)
        if self.vatrte is None:
            ask = askQuestion(self.opts["mf"].body,
                              "New Code",
                              "Code Does Not Exist, Create a New Code?",
                              default="no")
            if ask == "no":
                return "Invalid VAT Code"
            w = callModule(self.opts["mf"],
                           self.df,
                           "ms1040",
                           coy=[self.opts["conum"], self.opts["conam"]],
                           user=self.opts["capnm"],
                           args=w,
                           ret="code")
            self.df.loadEntry(frt, pag, p, data=w)
        self.vatrte = getVatRate(self.sql, self.opts["conum"], w, self.date)
        if self.vatrte is None:
            return "Invalid VAT Code"

    def doIncAmt(self, frt, pag, r, c, p, i, w):
        self.iamt = w
        if self.vatrte:
            vat = self.iamt * self.vatrte / float(ASD(100) + ASD(self.vatrte))
            self.df.loadEntry(frt, pag, p + 1, data=round(vat, 2))
        else:
            self.df.loadEntry(frt, pag, p + 1, data=0)
            if not self.loader:
                return "sk1"

    def doCheq(self, frt, pag, r, c, p, i, w):
        self.ctotal = w
        self.df.loadEntry("T", 0, 4, data=self.ctotal)

    def doQty(self, frt, pag, r, c, p, i, w):
        val = w * self.denoms[int(p / 2)][1]
        self.df.loadEntry(frt, pag, p + 1, val)
        self.ctotal = float(ASD(self.ctotal) + ASD(val))
        self.df.loadEntry("T", 0, 4, data=self.ctotal)

    def doEdit(self):
        if self.df.pag in (1, 2):
            self.doEditPage12()
        else:
            self.doEditPage3()

    def doEditPage12(self):
        ana = self.sql.getRec("cshana",
                              where=[("can_cono", "=", self.opts["conum"]),
                                     ("can_type", "=", self.trtp),
                                     ("can_date", "=", self.date)])
        data = []
        for rec in ana:
            dat = []
            for n, d in enumerate(rec):
                if n in (0, 1, 2, 9):
                    continue
                dat.append(d)
            data.append(dat)
        titl = "Analysis"
        head = ("Date", "Code", "Description", "V", "Inc-Amount", "VAT-Amount",
                "Seq")
        lin = {
            "stype":
            "C",
            "titl":
            titl,
            "head":
            head,
            "typs": (("D1", 10), ("UI", 7), ("NA", 30), ("UA", 1),
                     ("SD", 13.2), ("SD", 13.2), ("UA", 1), ("US", 10)),
            "data":
            data
        }
        state = self.df.disableButtonsTags()
        self.opts["mf"].updateStatus("Select a Line to Edit")
        chg = self.df.selChoice(lin)
        if chg and chg.selection:
            self.edit = self.sql.getRec("cshana",
                                        where=[("can_seq", "=",
                                                chg.selection[-1])],
                                        limit=1)
            self.doChgChanges()
        else:
            self.edit = None
        self.doLoadAnalysis()
        self.df.enableButtonsTags(state=state)

    def doChgChanges(self):
        tit = ("Change Line", )
        fld = ((("T", 0, 0,
                 0), "I@can_trdt", 10, "", "", "", "N", self.doChgDate, None,
                None, ("efld", )), (("T", 0, 1, 0), "I@can_code", 0, "", "",
                                    "", "N", None, self.cod, None, None),
               (("T", 0, 2, 0), "I@can_desc", 0, "", "", "", "N", None, None,
                None, ("efld", )), (("T", 0, 3,
                                     0), "I@can_vatcod", 0, "", "", "", "N",
                                    self.doChgVCode, None, None, ("efld", )),
               (("T", 0, 4, 0), "I@can_incamt", 0, "", "", "", "N",
                self.doChgIncAmt, None, None,
                ("efld", )), (("T", 0, 5, 0), "I@can_vatamt", 0, "", "", "",
                              "N", None, None, None, ("efld", )))
        but = [["Delete", None, self.doChgDel, 1, None, None]]
        self.cg = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               butt=but,
                               tend=((self.doChgEnd, "n"), ),
                               txit=(self.doChgExit, ),
                               focus=False)
        for num, dat in enumerate(self.edit[3:9]):
            self.cg.loadEntry("T", 0, num, data=dat)
        self.cg.focusField("T", 0, 1, clr=False)
        self.cg.mstFrame.wait_window()

    def doChgDate(self, frt, pag, r, c, p, i, w):
        self.chgdte = w

    def doChgVCode(self, frt, pag, r, c, p, i, w):
        self.vatrte = getVatRate(self.sql, self.opts["conum"], w, self.chgdte)
        if self.vatrte is None:
            return "Invalid VAT Code"

    def doChgIncAmt(self, frt, pag, r, c, p, i, w):
        self.iamt = w
        if self.vatrte:
            vat = self.iamt * self.vatrte / float(ASD(100) + ASD(self.vatrte))
            self.cg.loadEntry(frt, pag, p + 1, data=round(vat, 2))
        else:
            self.cg.loadEntry(frt, pag, p + 1, data=0)
            return "sk1"

    def doChgDel(self):
        self.sql.delRec("cshana", data=self.edit)
        self.doChgExit()

    def doChgEnd(self):
        self.sql.delRec("cshana", data=self.edit)
        for num, fld in enumerate(self.cg.t_work[0][0]):
            self.edit[num + 3] = fld
        self.sql.insRec("cshana", data=self.edit)
        self.opts["mf"].dbm.commitDbase()
        self.doChgExit()

    def doChgExit(self):
        self.cg.closeProcess()

    def doEditPage3(self):
        titl = "Denominations"
        data = []
        for num, rec in enumerate(self.df.c_work[3]):
            data.append([self.denoms[num][0], rec[0], rec[1]])
        lin = {
            "stype": "C",
            "deco": True,
            "titl": titl,
            "head": ("Denom", "Qty", "Value"),
            "typs": (("NA", 4), ("UI", 5), ("SD", 13.2)),
            "data": data,
            "retn": "I"
        }
        state = self.df.disableButtonsTags()
        self.opts["mf"].updateStatus("Select a Denomination to Edit")
        chg = self.df.selChoice(lin)
        self.df.enableButtonsTags(state=state)
        if chg and chg.selection:
            self.edit = self.df.col
            qty, val = self.df.c_work[3][chg.selection[0]]
            self.ctotal = float(ASD(self.ctotal) - ASD(val))
            self.df.focusField("C", 3, (chg.selection[0] * 2) + 1)
        else:
            self.edit = None
            self.df.focusField("C", 3, self.df.col)

    def doTopEnd(self):
        if self.df.pag == 0:
            if self.trtp == "P":
                self.df.selPage("Expenses")
                if self.amend:
                    self.doLoadAnalysis()
                else:
                    self.df.focusField("C", 1, 1)
            elif self.trtp == "T":
                self.df.selPage("Income")
                if self.amend:
                    self.doLoadAnalysis()
                else:
                    self.df.focusField("C", 2, 1)
            else:
                self.df.selPage("Cash")
                if not self.amend:
                    self.df.focusField("T", 3, 1)
                else:
                    self.doLoadCash()
        elif self.df.pag == 3:
            self.df.focusField("C", 3, 1)

    def doColEnd(self):
        if self.trtp in ("P", "T"):
            if self.trtp == "P":
                data = [self.opts["conum"], self.trtp, self.date]
                data.extend(self.df.c_work[1][self.df.row])
                data.append("N")
                self.sql.insRec("cshana", data=data)
                self.etotal = float(ASD(self.etotal) + ASD(self.iamt))
                self.df.loadEntry("T", 0, 2, data=self.etotal)
                self.df.advanceLine(1)
            else:
                data = [self.opts["conum"], self.trtp, self.date]
                data.extend(self.df.c_work[2][self.df.row])
                data.append("N")
                self.sql.insRec("cshana", data=data)
                self.itotal = float(ASD(self.itotal) + ASD(self.iamt))
                self.df.loadEntry("T", 0, 3, data=self.itotal)
                self.df.advanceLine(2)
        else:
            if self.df.col == 28:
                ask = askQuestion(self.opts["mf"].body, "Accept",
                                  "Accept All Entries")
                if ask == "yes":
                    data = [self.opts["conum"], "T", self.date]
                    data.append(self.df.t_work[3][0][0])
                    for x in range(14):
                        data.append(self.df.c_work[3][x][0])
                    if self.amend:
                        self.sql.delRec("cshcnt",
                                        where=[("cct_cono", "=",
                                                self.opts["conum"]),
                                               ("cct_type", "=", "T"),
                                               ("cct_date", "=", self.date)])
                    self.sql.insRec("cshcnt", data=data)
                    self.opts["mf"].dbm.commitDbase()
                    self.doRestart()
                else:
                    self.df.focusField("T", 3, 1, clr=False)
            elif self.edit:
                col = self.edit
                self.edit = None
                self.df.focusField("C", 3, col)
            else:
                self.df.advanceLine(self.df.pag)

    def doLoadCash(self):
        self.df.doInvoke(["T", 3, 1, self.doCheq], self.rec[3])
        for num, qty in enumerate(self.rec[4:-1]):
            col = (num * 2) + 1
            self.df.doInvoke(["C", 3, col, self.doQty], qty)

    def doLoadAnalysis(self):
        self.loader = True
        total = 0
        if self.trtp == "P":
            pag = 1
        else:
            pag = 2
        self.df.clearFrame("C", pag)
        ana = self.sql.getRec("cshana",
                              where=[("can_cono", "=", self.opts["conum"]),
                                     ("can_type", "=", self.trtp),
                                     ("can_date", "=", self.date)],
                              order="can_seq")
        if not ana:
            self.df.focusField("C", pag, 1)
        else:
            for num, rec in enumerate(ana):
                if num > 14:
                    num = 14
                for pos, dat in enumerate(rec[3:9]):
                    col = (num * 6) + pos + 1
                    if pos == 3:
                        self.df.doInvoke(["C", pag, col, self.doVCode], dat)
                    elif pos == 4:
                        self.df.doInvoke(["C", pag, col, self.doIncAmt], dat)
                    else:
                        self.df.doInvoke(["C", pag, col, "rt"], dat)
                total = float(ASD(total) + ASD(self.iamt))
                self.df.advanceLine(pag)
        if self.trtp == "P":
            self.etotal = total
            self.df.loadEntry("T", 0, 2, data=self.etotal)
        else:
            self.itotal = total
            self.df.loadEntry("T", 0, 3, data=self.itotal)
        self.loader = False

    def doQuit(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.doRestart()

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

    def doColExit(self):
        if self.df.pag != 3:
            self.opts["mf"].dbm.commitDbase()
            self.doRestart()
        elif self.df.pos:
            self.df.loadEntry("C",
                              3,
                              self.df.pos,
                              data=self.df.c_work[3][self.df.row][self.df.idx])
            r = self.df.row - 1
            c = self.df.col - 2
            self.ctotal = float(
                ASD(self.ctotal) - ASD(self.df.c_work[3][r][1]))
            self.df.focusField("C", 3, c)

    def doRestart(self):
        self.df.clearFrame("C", 1)
        self.df.clearFrame("C", 2)
        self.df.clearFrame("T", 3)
        self.df.clearFrame("C", 3)
        self.df.selPage("Expenses")
        self.df.focusField("T", 0, 1, clr=True)
Пример #15
0
class cr6030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.dataHeader()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["crsmst", "crstrn", "chglog"],
            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
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.curdt = int(self.sysdtw / 100)
        return True

    def dataHeader(self):
        self.crm = {
            "stype": "R",
            "tables": ("crsmst",),
            "cols": [
                ("crm_acno", "", 0, "Acc-Num"),
                ("crm_name", "", 0, "Name", "Y")],
            "where": [],
            "index": 0}
        fld = [
            (("T",0,0,0),"INA",7,"Acc-Num","Account Number",
                "","N",self.doAcno,self.crm,None,("notblank",)),
            (("T",0,1,0),"ONA",30,"Name")]
        but = (
            ("Generate",None,self.doGenerate,1,None,(("T",0,1),("T",0,2)),
                "Mark zero items, which have been inactive, as redundant"),
            ("Create",None,self.doCreate,1,None,(("T",0,1),("T",0,2)),
                "Mark a zero item as redundant"),
            ("Restore",None,self.doRestore,1,None,(("T",0,1),("T",0,2)),
                "Mark a redundant item as normal"),
            ("Exit",None,self.exitPage,1,None,(("T",0,1),("T",0,2))))
        tnd = ((self.endPage, "y"),)
        txt = (self.exitPage,)
        self.df = TartanDialog(self.opts["mf"], eflds=fld,
            butt=but, tend=tnd, txit=txt, focus=False)
        self.df.setWidget(self.df.B0, state="normal")
        self.df.setWidget(self.df.B1, state="normal")
        self.df.setWidget(self.df.B2, state="normal")
        self.df.setWidget(self.df.B3, state="normal")

    def doGenerate(self):
        tit = "Generate Redundant Accounts"
        fld = (
            (("T",0,0,0),"IUI",2,"Months Inactive","",
                24,"Y",self.doMonths,None,None,("efld",)),)
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        self.mt = TartanDialog(self.opts["mf"], title=tit, tops=True,
            eflds=fld, tend=((self.doMthEnd, "y"),), txit=(self.doMthExit,))
        self.mt.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)

    def doMonths(self, frt, pag, r, c, p, i, w):
        months = w
        yr = int(self.curdt / 100)
        mt = self.curdt % 100
        for mth in range(months):
            mt -= 1
            if not mt:
                mt = 12
                yr -= 1
        self.startp = (yr * 100) + mt

    def doMthEnd(self):
        self.mt.closeProcess()
        whr = [
            ("crm_cono", "=", self.opts["conum"]),
            ("crm_stat", "=", "N")]
        msts = self.sql.getRec("crsmst", cols=["crm_acno",
            "crm_opened"], where=whr, order="crm_acno")
        chgs = []
        for mst in msts:
            whr = [
                ("crt_cono", "=", self.opts["conum"]),
                ("crt_acno", "=", mst[0])]
            rec = self.sql.getRec("crstrn", cols=["max(crt_curdt)",
                "sum(crt_tramt)"], where=whr, limit=1)
            if rec[0] and rec[0] < self.startp and not rec[1]:
                chgs.append(mst[0])
            elif not rec[0] and int(mst[1] / 100) < self.startp:
                chgs.append(mst[0])
        if not chgs:
            showError(self.opts["mf"].body, "Processing Error",
                "No New Redundant Accounts")
        else:
            self.cnt = 0
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            p = ProgressBar(self.opts["mf"].body, mxs=len(chgs),
                typ="Flagging Redundant Accounts")
            for num, rec in enumerate(chgs):
                p.displayProgress(num)
                self.sql.updRec("crsmst", cols=["crm_stat"], data=["X"],
                    where=[("crm_cono", "=", self.opts["conum"]),
                    ("crm_acno", "=", rec)])
                key = "%03i%-7s" % (self.opts["conum"], rec)
                self.sql.insRec("chglog", data=["crsmst", "U", key,
                    "crm_stat", dte, self.opts["capnm"], "N", "X", "", 0])
            p.closeProgress()
            mess = """%s Accounts Will be Flagged as Redundant.

Would you like to COMMIT these Changes?""" % len(chgs)
            self.opts["mf"].dbm.commitDbase(ask=True, mess=mess, default="no")

    def doMthExit(self):
        self.mt.closeProcess()

    def doCreate(self):
        self.flag = "C"
        self.crm["where"] = [
            ("crm_cono", "=", self.opts["conum"]),
            ("crm_stat", "<>", "X")]
        self.df.focusField("T", 0, 1)

    def doRestore(self):
        self.flag = "R"
        self.crm["where"] = [
            ("crm_cono", "=", self.opts["conum"]),
            ("crm_stat", "=", "X")]
        self.df.focusField("T", 0, 1)

    def doAcno(self, frt, pag, r, c, p, i, w):
        if self.flag == "C":
            typ = "<>"
        else:
            typ = "="
        chk = self.sql.getRec("crsmst", where=[("crm_cono",
            "=", self.opts["conum"]), ("crm_acno", "=", w),
            ("crm_stat", typ, "X")], limit=1)
        if not chk:
            return "Invalid Code"
        if self.flag == "C":
            bal = self.sql.getRec("crstrn", cols=["sum(crt_tramt)"],
                where=[("crt_cono", "=", self.opts["conum"]),
                ("crt_acno", "=", w)], limit=1)
            if bal[0]:
                return "Balance Exists"
        self.acno = w
        name = chk[self.sql.crsmst_col.index("crm_name")]
        self.df.loadEntry(frt, pag, p+1, data=name)

    def endPage(self):
        if self.flag == "C":
            old = "N"
            new = "X"
        else:
            old = "X"
            new = "N"
        self.sql.updRec("crsmst", cols=["crm_stat"], data=[new],
            where=[("crm_cono", "=", self.opts["conum"]),
            ("crm_acno", "=", self.acno)])
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        key = "%03i%-7s" % (self.opts["conum"], self.acno)
        self.sql.insRec("chglog", data=["crsmst", "U", key, "crm_stat",
            dte, self.opts["capnm"], old, new, 0])
        self.opts["mf"].dbm.commitDbase()
        self.df.clearFrame("T", 0)
        self.flag = ""

    def exitPage(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #16
0
class wg2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.dataHeader()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       ["wagedc", "wagmst", "wagcap", "wagcod"],
                       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.m_hrs = wagctl["ctw_m_hrs"]
        self.w_hrs = wagctl["ctw_w_hrs"]
        self.d_hrs = wagctl["ctw_d_hrs"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.edit = None
        return True

    def dataHeader(self):
        wgm = {
            "stype":
            "R",
            "tables": ("wagmst", ),
            "cols": (("wgm_empno", "", 0, "Emp-Num"),
                     ("wgm_sname", "", 0, "Surname", "Y"), ("wgm_fname", "", 0,
                                                            "First Names")),
            "where": [("wgm_cono", "=", self.opts["conum"]),
                      ("wgm_term", "=", 0)]
        }
        wed = {
            "stype":
            "R",
            "tables": ("wagedc", ),
            "cols": (("ced_code", "", 0, "Code"), ("ced_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("ced_cono", "=", self.opts["conum"])],
            "whera": [["C", "ced_type", 4, 0]]
        }
        fld = ((("C", 0, 0, 0), "IUI", 5, "EmpNo", "Employee Number", "r", "N",
                self.doEmpno, wgm, None, ("efld", )), (("C", 0, 0, 1), "ONA",
                                                       40, "Name"),
               (("C", 0, 0, 2), "OUI", 3,
                "Dep"), (("C", 0, 0, 3), "IUI", 5, "JobNo", "Job Number", "r",
                         "N", None, None, None, ("efld", )),
               (("C", 0, 0, 4), "IUA", 1, "T", "Earnings/Deduction/NoPay", "r",
                "N", self.doType, None, None, ("in", ("E", "D"))),
               (("C", 0, 0, 5), "IUI", 3, "Cde", "Code Number", "", "N",
                self.doCode, wed, None, ("efld", )), (("C", 0, 0, 6), "ONA",
                                                      20, "Description"),
               (("C", 0, 0, 7), "IUA", 1, "P", "Pay (Y or N)", "Y", "N",
                self.doPay, None, None, ("in", ("Y", "N"))), [
                    ("C", 0, 0, 8), "ISD", 13.2, "Amount", "", "", "N",
                    self.doAmt, None, None, None
                ])
        but = (("Edit", None, self.editData, 0, ("C", 0, 1), ("C", 0, 2)),
               ("Interrogate", None, self.queryWag, 0, ("C", 0, 1), ("C", 0,
                                                                     2)))
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               butt=but,
                               cend=((self.endData, "y"), ),
                               cxit=(self.exitData, ))

    def doEmpno(self, frt, pag, r, c, p, i, w):
        rec = self.sql.getRec("wagmst",
                              cols=[
                                  "wgm_sname", "wgm_fname", "wgm_dept",
                                  "wgm_freq", "wgm_term"
                              ],
                              where=[("wgm_cono", "=", self.opts["conum"]),
                                     ("wgm_empno", "=", w)],
                              limit=1)
        if not rec:
            return "Invalid Employee Number"
        elif rec[4]:
            return "Employment Terminated"
        self.empno = w
        name = "%s, %s" % (rec[0], rec[1].split()[0])
        self.df.loadEntry(frt, pag, p + 1, data=name)
        self.df.loadEntry(frt, pag, p + 2, data=rec[2])
        self.freq = rec[3]

    def doType(self, frt, pag, r, c, p, i, w):
        self.rtyp = w

    def doCode(self, frt, pag, r, c, p, i, w):
        self.code = w
        rec = self.readWagedc()
        if not rec:
            return "Invalid Code"
        chk = self.sql.getRec("wagcap",
                              where=[("wcp_cono", "=", self.opts["conum"]),
                                     ("wcp_empno", "=", self.empno),
                                     ("wcp_type", "=", self.rtyp),
                                     ("wcp_code", "=", self.code)])
        if chk:
            if self.rtyp == "E":
                txt = "Earnings"
            else:
                txt = "Deduction"
            ok = askQuestion(self.df.mstFrame, head="Duplicate",
                mess="An Entry for this %s Code Already Exists "\
                "for this Employee.\n\nIs This Correct?" % txt)
            if ok == "no":
                return "rf"
        self.df.loadEntry(frt, pag, p + 1, rec[0])
        if self.rtyp == "E" and self.code == 1:
            std = self.sql.getRec("wagcod",
                                  cols=["wcd_eamt"],
                                  where=[("wcd_cono", "=", self.opts["conum"]),
                                         ("wcd_empno", "=", self.empno),
                                         ("wcd_type", "=", "E"),
                                         ("wcd_code", "=", self.code)],
                                  limit=1)
            if std and std[0]:
                hrs = std[0]
            elif self.freq == "M":
                hrs = self.m_hrs
            elif self.freq == "W":
                hrs = self.w_hrs
            elif self.freq == "D":
                hrs = self.d_hrs
            else:
                hrs = self.m_hrs
            self.df.colf[0][8][5] = hrs
        else:
            self.df.colf[0][8][5] = ""

    def doPay(self, frt, pag, r, c, p, i, w):
        pass

    def doAmt(self, frt, pag, r, c, p, i, w):
        self.xrow = r

    def readWagedc(self):
        rec = self.sql.getRec("wagedc",
                              cols=["ced_desc"],
                              where=[("ced_cono", "=", self.opts["conum"]),
                                     ("ced_type", "=", self.rtyp),
                                     ("ced_code", "=", self.code)],
                              limit=1)
        if not rec:
            return None
        else:
            return rec

    def endData(self):
        r = self.xrow
        data = [
            self.opts["conum"], self.empno, self.df.c_work[0][r][2],
            self.df.c_work[0][r][3], self.df.c_work[0][r][4],
            self.df.c_work[0][r][5], self.df.c_work[0][r][7],
            self.df.c_work[0][r][8], "N", self.opts["capnm"], self.sysdtw
        ]
        if self.edit:
            data.append(self.edit)
            self.sql.updRec("wagcap",
                            data=data,
                            where=[("wcp_seq", "=", self.edit)])
            self.edit = None
        else:
            data.append(0)
            self.sql.insRec("wagcap", data=data)
        self.df.advanceLine(0)

    def exitData(self):
        self.opts["mf"].dbm.commitDbase()
        self.df.closeProcess()
        self.opts["mf"].closeLoop()

    def editData(self):
        # Display captured items and allow editing
        col = [
            "wcp_empno", "wgm_sname", "wcp_dept", "wcp_job", "wcp_type",
            "wcp_code", "ced_desc", "wcp_ind", "wcp_amt", "wcp_seq"
        ]
        whr = [("wcp_cono", "=", self.opts["conum"]), ("wcp_paid", "=", "N"),
               ("wgm_cono=wcp_cono", ), ("wgm_empno=wcp_empno", ),
               ("ced_cono=wcp_cono", ), ("ced_type=wcp_type", ),
               ("ced_code=wcp_code", )]
        data = self.sql.getRec(tables=["wagcap", "wagmst", "wagedc"],
                               cols=col,
                               where=whr,
                               order="wcp_empno")
        if not data:
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)
            return
        titl = "Captured Items"
        head = ("EmpNo", "Surname", "Dep", "JobNo", "T", "Cod", "Description",
                "I", "Amount", "Sequence")
        lin = {
            "stype":
            "C",
            "titl":
            titl,
            "head":
            head,
            "typs": [("UI", 5), ("NA", 30), ("UI", 3), ("UI", 5), ("UA", 1),
                     ("UI", 3), ("NA", 20), ("UA", 1), ("SD", 13.2),
                     ("UI", 10)],
            "data":
            data,
            "butt": [("Delete", self.doDelete, True)]
        }
        state = self.df.disableButtonsTags()
        self.opts["mf"].updateStatus("Select an Item to Edit")
        chg = SChoice(self.opts["mf"],
                      deco=True,
                      titl=lin["titl"],
                      head=lin["head"],
                      data=lin["data"],
                      typs=lin["typs"],
                      mode="S",
                      retn="D",
                      butt=lin["butt"],
                      scrn=self.df.mstFrame)
        self.df.enableButtonsTags(state=state)
        if chg and chg.selection:
            for num, fld in enumerate(chg.selection):
                if num in (0, 3, 4, 5):
                    self.df.doKeyPressed("C", 0, self.df.pos, fld)
                elif num == (len(chg.selection) - 1):
                    self.edit = int(fld)
                else:
                    self.df.loadEntry(self.df.frt, self.df.pag, num, data=fld)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doDelete(self, args):
        self.sql.delRec("wagcap", where=[("wcp_seq", "=", args[-1:][0])])

    def queryWag(self):
        callModule(self.opts["mf"],
                   self.df,
                   "wg4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])
Пример #17
0
class gl2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["ctlynd", "genmst", "genbal"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        per = self.sql.getRec("ctlynd",
                              where=[("cye_cono", "=", self.opts["conum"]),
                                     ("cye_period", "=", 0)],
                              limit=1)
        if not per:
            showError(
                self.opts["mf"].body, "Period Error", """No Period 0!

Please Contact your Software Support and Quote this Message as this is a Serious Error!"""
            )
            return
        self.start = per[self.sql.ctlynd_col.index("cye_start")]
        return True

    def drawDialog(self):
        sel_acc = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        sel_all = {
            "stype":
            "R",
            "tables": ("genbal", "genmst"),
            "cols":
            (("glo_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                              "Description"),
             ("glo_trdt", "", 0, "Date"), ("glo_cyr", "", 0, "Balance")),
            "where": [("glo_cono", "=", self.opts["conum"]),
                      ("glm_cono=glo_cono", ), ("glm_acno=glo_acno", ),
                      ("glo_trdt", "=", self.start)]
        }
        fld = ((("C", 0, 0, 0), "IUI", 7, "Acc-Num", "Account Number", "", "N",
                self.doAcc, sel_acc, None, None), (("C", 0, 0, 1), "ONA", 30,
                                                   "Description"),
               (("C", 0, 0, 2), "ISD", 13.2, "Balance", "Balance Value", "",
                "N", self.doBal, None, None, None))
        but = (("Import File", None, self.doImport, 0, ("C", 0, 1), ("C", 0,
                                                                     2),
                "Import Opening Balances from a CSV or XLS File."),
               ("All Entries", sel_all, None, 1, ("C", 0, 1), None,
                "Display All Existing Balances"),
               ("Exit", None, self.exitData, 1, ("C", 0, 1), ("C", 0, 2)))
        row = (20, )
        self.df = TartanDialog(self.opts["mf"],
                               rows=row,
                               eflds=fld,
                               cend=((self.endData, "y"), ),
                               cxit=(self.exitData, ),
                               butt=but)

    def doImport(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        impcol = [["Account Number", 0, "UI", 7],
                  ["Opening Balance", 1, "SD", 13.2]]
        fi = FileImport(self.opts["mf"], impcol=impcol)
        err = None
        for num, line in enumerate(fi.impdat):
            if len(line) != 2:
                err = "Line %s: Invalid Number of Fields (S/B %s is %s)" % \
                    (num + 1, 2, len(line))
                break
            self.acc = line[0]
            chk = self.sql.getRec("genmst",
                                  where=[("glm_cono", "=", self.opts["conum"]),
                                         ("glm_acno", "=", self.acc)],
                                  limit=1)
            if not chk:
                err = "Line %s: Invalid Account %s" % ((num + 1), self.acc)
                break
            self.bal = line[1]
            self.old = self.sql.getRec("genbal",
                                       cols=["glo_cyr"],
                                       where=[("glo_cono", "=",
                                               self.opts["conum"]),
                                              ("glo_acno", "=", self.acc),
                                              ("glo_trdt", "=", self.start)],
                                       limit=1)
            if not self.old:
                self.new_acc = "y"
            else:
                self.new_acc = "n"
            self.endData(det=True)
        if err:
            showError(self.opts["mf"].body, "Import Error", err)
        elif fi.impdat:
            self.opts["mf"].dbm.commitDbase()
        self.df.enableButtonsTags(state=state)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doAcc(self, frt, pag, r, c, p, i, w):
        desc = self.sql.getRec("genmst",
                               cols=["glm_desc"],
                               where=[("glm_cono", "=", self.opts["conum"]),
                                      ("glm_acno", "=", w)],
                               limit=1)
        if not desc:
            return "Invalid Account Number"
        self.acc = w
        self.df.loadEntry(frt, pag, p + 1, data=desc[0])
        self.old = self.sql.getRec("genbal",
                                   where=[("glo_cono", "=",
                                           self.opts["conum"]),
                                          ("glo_acno", "=", self.acc),
                                          ("glo_trdt", "=", self.start)],
                                   limit=1)
        if not self.old:
            self.new_acc = "y"
        else:
            self.new_acc = "n"
            bal = self.old[self.sql.genbal_col.index("glo_cyr")]
            self.df.loadEntry(frt, pag, p + 2, data=bal)

    def doBal(self, frt, pag, r, c, p, i, w):
        self.bal = w

    def endData(self, det=False):
        data = [self.opts["conum"], self.acc, self.start, self.bal]
        if self.new_acc == "y":
            self.sql.insRec("genbal", data=data)
        elif data != self.old[:len(data)]:
            col = self.sql.genbal_col
            data.append(self.old[col.index("glo_xflag")])
            self.sql.updRec("genbal",
                            data=data,
                            where=[("glo_cono", "=", self.opts["conum"]),
                                   ("glo_acno", "=", self.acc),
                                   ("glo_trdt", "=", self.start)])
        if det:
            return
        self.opts["mf"].dbm.commitDbase()
        nxt = self.sql.getRec("genmst",
                              cols=["glm_acno"],
                              where=[("glm_cono", "=", self.opts["conum"]),
                                     ("glm_acno", ">", self.acc)],
                              limit=1)
        if nxt:
            self.df.colf[0][0][5] = nxt[0]
        else:
            self.df.colf[0][0][5] = 0
        self.df.advanceLine(0)

    def exitData(self):
        bals = self.sql.getRec("genbal",
                               cols=["sum(glo_cyr)"],
                               where=[("glo_cono", "=", self.opts["conum"]),
                                      ("glo_trdt", "=", self.start)],
                               limit=1)
        if bals[0]:
            diff = CCD(bals[0], "SD", 13.2)
            showError(self.opts["mf"].body, "Out of Balance",
                      "Opening Balances Do Not Balance by %s" % diff.disp)
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)
        else:
            showInfo(
                self.opts["mf"].body, "Year End",
                """A Year End for the Previous Period Must be Executed to Include These Opening Balances.

If the Current Period is 1 then the Year End for Period 0 must be Executed.""")
            self.df.closeProcess()
            self.opts["mf"].closeLoop()
Пример #18
0
class ml2020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Check for Valid Posting Routine
        if self.opts["rtn"] != 5:
            mes = "Invalid Routine %s" % str(self.opts["rtn"])
            showError(self.opts["mf"].body, "Control Error", mes)
            return
        tabs = ["ctlvmf", "memmst", "memtrn"]
        self.gc = GetCtl(self.opts["mf"])
        memctl = self.gc.getCtl("memctl", self.opts["conum"])
        if not memctl:
            return
        self.glint = memctl["mcm_glint"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["mem_ctl", "vat_ctl", "dis_all"]
            if self.gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.memctl = ctlctl["mem_ctl"]
            self.dis_all = ctlctl["dis_all"]
            tabs.extend(["genmst", "gentrn"])
        # Setup SQL Object
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "MEM",
                          self.opts["rtn"],
                          glint=self.glint)
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return
        self.bh.batval = float(ASD(0) - ASD(self.bh.batval))
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        ctlmst = self.gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        self.glt = 4
        self.agevar = tk.BooleanVar()
        self.agevar.set(False)
        return True

    def drawDialog(self):
        mlm = {
            "stype":
            "R",
            "tables": ("memmst", ),
            "cols":
            (("mlm_memno", "", 0, "Mem-No"), ("mlm_oldno", "", 0, "Old-No"),
             ("mlm_gender", "", 0, "G"), ("mlm_state", "", 0, "S"),
             ("mlm_surname", "", 0, "Surname", "Y"), ("mlm_names", "", 0,
                                                      "Names", "F")),
            "where": [("mlm_cono", "=", self.opts["conum"])],
            "order":
            "mlm_surname, mlm_names",
            "sort":
            False
        }
        tag = (("Deposit", None, None, None, False), ("Allocation", None, None,
                                                      None, False))
        fld = ((("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2, "Value"),
               (("C", 1, 0, 0), "INa", 9, "Reference", "Reference Number One",
                "i", "Y", self.doRefno, None, None, ("efld", )),
               (("C", 1, 0, 1), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 2), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, ("notzero", )),
               (("C", 1, 0, 3), "INA", 30, "Details", "Deposit Details", "",
                "N", self.doTrnDet, None, None,
                None), (("T", 2, 0, 0), "OSD", 13.2, "Unallocated Balance"),
               (("C", 2, 0, 0), "IUI", 6, "Mem-No", "Member Number", "r", "N",
                self.doMemAcc, mlm, None, ("notblank", )), (("C", 2, 0, 1),
                                                            "ONA", 30, "Name"),
               (("C", 2, 0, 2), "ISD", 13.2, "Receipt", "Receipt Amount", "",
                "N", self.doAllAmt, None, None, ("efld", )),
               (("C", 2, 0, 3), "ISD", 13.2, "Discount", "Discount Amount",
                "", "N", self.doDisAmt, None, None, ("efld", ), None,
                "Discount Amount to be Added to the Receipt Amount."),
               (("C", 2, 0, 4), "OSD", 13.2, "Total-Amount"))
        but = (
            ("Age _Normal",None,self.doAgeNormal,0,None,None,
                "Only Show Unallocated Transactions",1),
            ("Age _History",None,self.doAgeHistory,0,None,None,
                "Show All Transactions Including Already Allocated",1),
            ("Age _Automatic",None,self.doAgeAuto,0,None,None,
                "Automatically Allocate the Amount Starting With the "\
                "Oldest Unallocated One",1),
            ("Age _Current",None,self.doAgeCurrent,0,None,None,
                "Leave the Transaction Unallocated",1),
            ("Cancel",None,self.doCancel,0,("C",2,1),("C",1,1),"",1))
        txt = (None, None, None)
        cnd = [None, (self.endPage1, "y"), (self.endPage2, "y")]
        cxt = [None, self.exitPage1, self.exitPage2]
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tags=tag,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 1, 1)

    def doRefno(self, frt, pag, r, c, p, i, w):
        if not w:
            trns = self.sql.getRec("memtrn",
                                   cols=["mlt_refno"],
                                   where=[("mlt_cono", "=",
                                           self.opts["conum"]),
                                          ("mlt_refno", "like", "R________")],
                                   order="mlt_refno desc")
            auto = False
            for trn in trns:
                try:
                    w = "R%08i" % (int(trn[0][1:]) + 1)
                    auto = True
                    break
                except:
                    pass
            if not auto:
                w = "R00000001"
            self.df.loadEntry(frt, pag, p, data=w)
        chk = self.sql.getRec("memtrn",
                              cols=["mlt_memno"],
                              where=[("mlt_cono", "=", self.opts["conum"]),
                                     ("mlt_type", "=", self.opts["rtn"]),
                                     ("mlt_refno", "=", w)])
        if chk:
            return "A Transaction with this Number Already Exists"
        self.refno = w

    def doTrnDat(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not in Financial Period"
        if self.bh.multi == "N" and int(w / 100) > self.bh.curdt:
            return "Invalid Date, After Batch Period"
        self.trndat = w

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w

    def doTrnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w
        self.allocated = float(0.00)

    def endPage1(self):
        self.batupd = False
        self.updateTables1()
        self.updateBatch()
        self.agecan = False
        self.allocated = float(0.0)
        self.df.selPage("Allocation")
        self.df.loadEntry("T", 2, 0, data=self.trnamt)
        self.df.focusField("C", 2, 1)

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        if self.glint == "Y":
            # General Ledger Control Transaction (Bank)
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                    self.glt, self.refno, self.bh.batno, self.trnamt, 0.00,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)

    def exitPage1(self):
        self.df.closeProcess()
        self.bh.doBatchTotal()
        self.opts["mf"].closeLoop()

    def doMemAcc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("memmst",
                              cols=["mlm_title", "mlm_initial", "mlm_surname"],
                              where=[("mlm_cono", "=", self.opts["conum"]),
                                     ("mlm_memno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Member Number"
        self.memno = w
        self.name = "%s, %s %s" % (acc[2], acc[0], acc[1])
        self.df.loadEntry("C", pag, p + 1, data=self.name)
        self.allref = self.refno
        while self.sql.getRec("memtrn",
                              cols=["mlt_batch"],
                              where=[("mlt_cono", "=", self.opts["conum"]),
                                     ("mlt_memno", "=", self.memno),
                                     ("mlt_type", "=", self.opts["rtn"]),
                                     ("mlt_refno", "=", self.allref)]):
            self.doGetAnotherRef()

    def doGetAnotherRef(self):
        tit = ("Duplicate Reference Number", )
        fld = ((("T", 0, 0, 0), "ONa", 9, "Old Reference", "", self.allref,
                "N", None, None, None, None),
               (("T", 0, 1, 0), "INa", 9, "New Reference", "", "", "N",
                self.doRefNew, None, None, ("notblank", )))
        tnd = ((self.doRefEnd, "n"), )
        txt = (self.doRefExit, )
        state = self.df.disableButtonsTags()
        self.tf = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=tnd,
                               txit=txt)
        self.tf.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)

    def doRefExit(self):
        self.tf.focusField("T", 0, 2)

    def doRefNew(self, frt, pag, r, c, p, i, w):
        self.allref = w

    def doRefEnd(self):
        self.tf.closeProcess()

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if w == 0:
            self.allamt = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry(frt, pag, p, data=self.allamt)
        else:
            self.allamt = w

    def doDisAmt(self, frt, pag, r, c, p, i, w):
        if self.allamt < 0 and w > 0:
            ok = self.checkSign()
        elif self.allamt > 0 and w < 0:
            ok = self.checkSign()
        else:
            ok = "yes"
        if ok != "yes":
            return "Invalid Discount Amount (Sign Error)"
        self.disamt = w
        totamt = float(ASD(self.allamt) + ASD(self.disamt))
        self.df.loadEntry(frt, pag, p + 1, data=totamt)

    def checkSign(self):
        return askQuestion(self.opts["mf"].body, "Check Sign",
            "The Sign of the Discount Amount is not the same as the Sign "\
            "of the Receipt Amount, Is This Correct?")

    def endPage2(self):
        self.amt = float(ASD(0) - ASD(self.allamt))
        self.dis = float(ASD(0) - ASD(self.disamt))
        state = self.df.disableButtonsTags()
        self.opts["mf"].updateStatus("Choose an Ageing Option")
        for x in range(0, 5):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "normal")
        self.df.setWidget(self.df.B0, "focus")
        self.agevar.set(True)
        self.df.mstFrame.wait_variable(self.agevar)
        self.df.enableButtonsTags(state=state)
        if self.agecan:
            self.doCancel()
            return
        # Members Ledger Transaction
        data = [
            self.opts["conum"], self.memno, self.opts["rtn"], self.allref,
            self.bh.batno, self.trndat, self.amt, 0.00, self.curdt, "", 0,
            self.trndet, "", "N", self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("memtrn", data=data)
        if self.dis:
            data = [
                self.opts["conum"], self.memno, 6, self.allref, self.bh.batno,
                self.trndat, self.dis, 0.00, self.curdt, "", 0, self.trndet,
                "", "N", self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("memtrn", data=data, unique="mlt_refno")
        self.allocated = float(ASD(self.allocated) + ASD(self.allamt))
        if self.glint == "Y":
            # General Ledger Control Transaction (Members)
            amt = float(ASD(self.amt) + ASD(self.dis))
            data = (self.opts["conum"], self.memctl, self.curdt, self.trndat,
                    self.glt, self.allref, self.bh.batno, amt, 0.00,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)
            # General Ledger Control Transaction (Discount)
            if self.disamt:
                data = (self.opts["conum"], self.dis_all, self.curdt,
                        self.trndat, self.glt, self.allref, self.bh.batno,
                        self.disamt, 0.00, self.trndet, "N", "", 0,
                        self.opts["capnm"], self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
        if self.allocated == self.trnamt:
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Deposit")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def doAgeNormal(self):
        self.doAgeing("N")

    def doAgeHistory(self):
        self.doAgeing("H")

    def doAgeAuto(self):
        self.doAgeing("O")

    def doAgeCurrent(self):
        self.doAgeing("C")

    def doAgeing(self, atype):
        # Disable All Ageing Buttons
        for x in range(0, 4):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "disabled")
        self.opts["mf"].updateStatus("Select Transaction to Allocate Against")
        age = AgeAll(self.opts["mf"],
                     system="mem",
                     agetyp=atype,
                     agekey=[
                         self.opts["conum"], self.memno, self.opts["rtn"],
                         self.allref, self.curdt, self.amt, self.dis
                     ])
        self.agecan = age.cancel
        self.agevar.set(False)

    def doCancel(self):
        if self.agecan:
            ok = "yes"
        else:
            ok = askQuestion(
                self.opts["mf"].body,
                head="Cancel",
                mess="Are You Certain You Want to Cancel This Entry?")
        if ok == "yes":
            self.opts["mf"].dbm.rollbackDbase()
            if self.batupd:
                self.updateBatch(rev=True)
            self.df.clearFrame("C", 2)
            self.df.selPage("Deposit")
            row = int((self.df.last[1][1] - 1) / self.df.colq[1])
            col = (row * self.df.colq[1]) + 1
            self.df.focusField("C", 1, col)

    def updateBatch(self, rev=False):
        if rev:
            self.bh.batqty -= 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.trnamt))
        else:
            self.batupd = True
            self.bh.batqty += 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.trnamt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def exitPage2(self):
        self.df.focusField("C", 2, self.df.col)
Пример #19
0
class ar2020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        if self.opts["rtn"] not in (1, 2, 3):
            mes = "Invalid Routine %s" % str(self.opts["rtn"])
            showError(self.opts["mf"].body, "Control Error", mes)
            return
        self.gc = GetCtl(self.opts["mf"])
        assctl = self.gc.getCtl("assctl", self.opts["conum"])
        if not assctl:
            return
        self.glint = assctl["cta_glint"]
        self.rordp = assctl["cta_rordp"]
        tabs = [
            "assgrp", "assmst", "assdep", "asstrn", "ctlvmf", "ctlvrf",
            "ctlvtf", "genint", "genmst", "gentrn"
        ]
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        if self.glint == "Y":
            # Check Sale of Asset Record
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            if self.gc.chkRec(self.opts["conum"], ctlctl, "ass_sls"):
                return
            self.slsac = ctlctl["ass_sls"]
            # Check for VAT Control
            if self.gc.chkRec(self.opts["conum"], ctlctl, ["vat_ctl"]):
                return
            self.convat = ctlctl["vat_ctl"]
            # Check All Group Control Records
            errs = ("Group %s Has An Invalid", "Asset Control Account (%s)",
                    "Accumulated Depreciation Account (%s)",
                    "Depreciation Expense Account (%s)")
            ass = self.sql.getRec(
                "assgrp",
                cols=["asg_group", "asg_assacc", "asg_depacc", "asg_expacc"],
                where=[("asg_cono", "=", self.opts["conum"])])
            for acc in ass:
                for x in range(1, 4):
                    chk = self.sql.getRec("genmst",
                                          where=[("glm_cono", "=",
                                                  self.opts["conum"]),
                                                 ("glm_acno", "=", acc[x])],
                                          limit=1)
                    if not chk:
                        mess = "%s %s" % (errs[0] % acc[0], errs[x] % acc[x])
                        showError(self.opts["mf"].body, "Control Error", mess)
                        return
        self.batchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def batchHeader(self):
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "ASS",
                          self.opts["rtn"],
                          glint=self.glint)
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return
        if self.opts["rtn"] == 2:
            self.bh.batval = float(ASD(0) - ASD(self.bh.batval))

    def drawDialog(self):
        grp = {
            "stype":
            "R",
            "tables": ("assgrp", ),
            "cols": (("asg_group", "", 0, "Grp"), ("asg_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("asg_cono", "=", self.opts["conum"])]
        }
        cod = {
            "stype":
            "R",
            "tables": ("assmst", ),
            "cols": (("asm_code", "", 0, "Cod-Num"), ("asm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("asm_cono", "=", self.opts["conum"])],
            "whera": [["C", "asm_group", 0, 1]]
        }
        vtm = {
            "stype":
            "R",
            "tables": ("ctlvmf", ),
            "cols": (("vtm_code", "", 0, "C"), ("vtm_desc", "", 0,
                                                "Description", "Y")),
            "where": [("vtm_cono", "=", self.opts["conum"])]
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        data = []
        for x in range(1, (len(armvtp) + 1)):
            data.append([x, armvtp[x - 1][1]])
        mov = {
            "stype": "C",
            "titl": "Valid Types",
            "head": ("C", "Description"),
            "data": data
        }
        fld = [(("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2, "Value"),
               (("C", 1, 0, 0), "IUA", 3, "Grp", "Asset Group", "r", "N",
                self.doAssGrp, grp, None, None),
               (("C", 1, 0, 1), "INa", 7, "Cod-Num", "Asset Code", "r", "N",
                self.doAssCod, cod, None, ("notblank", )),
               (("C", 1, 0, 2), "ONA", 13, "Description"),
               (("C", 1, 0, 3), "INa", 9, "Reference", "Reference Number One",
                "i", "N", self.doTrnRef, None, None, ("notblank", )),
               (("C", 1, 0, 4), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 5), "IUI", 1, "M", "Movement Type", "r", "N",
                self.doTrnMov, mov, None, ("in", (1, 2, 3, 4, 5))),
               (("C", 1, 0, 6), "ISD", 13.2, "Company", "Company Amount", "",
                "N", self.doCoyAmt, None, None, None),
               (("C", 1, 0, 7), "ISD", 13.2, "Receiver", "Receiver Amount", "",
                "N", self.doRorAmt, None, None, None),
               (("C", 1, 0, 8), "IUA", 1, "V", "V.A.T Code", "C", "N",
                self.doVatCod, vtm, None, ("notblank", )),
               (("C", 1, 0, 9), "ISD", 13.2, "V.A.T", "V.A.T Amount", "", "N",
                self.doVatAmt, None, None, None),
               (("C", 1, 0,
                 10), "INA", (13, 30), "Details", "Transaction Details", "",
                "N", self.doTrnDet, None, None, None)]
        if self.opts["rtn"] not in (1, 2) and self.glint == "Y":
            fld.extend([[("T", 2, 0, 0), "OSD", 13.2, "Unallocated Balance"],
                        (("C", 2, 0, 0), "IUI", 7, "Acc-Num", "Account Number",
                         "", "N", self.doGenAcc, glm, None, None),
                        (("C", 2, 0, 1), "ONA", 30, "Description"),
                        (("C", 2, 0,
                          2), "ISD", 13.2, "All-Amt", "Allocation Amount", "",
                         "N", self.doAllAmt, None, None, ("efld", )),
                        (("C", 2, 0, 3), "INA", 30, "Details", "", "", "N",
                         self.doAllDet, None, None, ("notblank", ))])
        but = (("Interrogate", None, self.queryAss, 0, ("C", 1, 1),
                ("C", 1, 2)), ("Cancel", None, self.doCancel, 0, ("C", 2, 1),
                               ("C", 1, 1)))
        tag = [("Transaction", None, None, None, False)]
        cnd = [(None, "n"), (self.endPage1, "y")]
        cxt = [None, self.exitPage1]
        if self.opts["rtn"] not in (1, 2) and self.glint == "Y":
            tag.append(("Allocation", None, None, None, False))
            cnd.append((self.endPage2, "y"))
            cxt.append(self.exitPage2)
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tags=tag,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 1, 1)

    def doAssGrp(self, frt, pag, r, c, p, i, w):
        whr = [("asg_cono", "=", self.opts["conum"]), ("asg_group", "=", w)]
        acc = self.sql.getRec("assgrp", where=whr, limit=1)
        if not acc:
            return "Invalid Asset Group"
        self.group = w
        self.depcod = acc[self.sql.assgrp_col.index("asg_depcod")]
        self.assacc = acc[self.sql.assgrp_col.index("asg_assacc")]
        self.depacc = acc[self.sql.assgrp_col.index("asg_depacc")]
        self.expacc = acc[self.sql.assgrp_col.index("asg_expacc")]

    def doAssCod(self, frt, pag, r, c, p, i, w):
        self.code = w
        self.buydt = 0
        self.seldt = 0
        col = ["asm_desc", "asm_depcod"]
        whr = [("asm_cono", "=", self.opts["conum"]),
               ("asm_group", "=", self.group), ("asm_code", "=", self.code)]
        acc = self.sql.getRec("assmst", cols=col, where=whr, limit=1)
        if not acc:
            ok = askQuestion(screen=self.opts["mf"].body,
                             head="New Asset",
                             mess="Asset does not exist, Create?")
            if ok == "no":
                return "Invalid Asset"
            self.doNewAsset()
            acc = self.sql.getRec("assmst", cols=col, where=whr, limit=1)
            if not acc:
                return "Asset Not Found"
            self.new = "y"
        else:
            self.new = "n"
        dep = self.sql.getRec("assdep",
                              cols=["asd_rate1r"],
                              where=[("asd_cono", "=", self.opts["conum"]),
                                     ("asd_code", "=", acc[1])],
                              limit=1)
        self.rate1r = dep[0]
        col = ["ast_date"]
        whr = [("ast_cono", "=", self.opts["conum"]),
               ("ast_group", "=", self.group), ("ast_code", "=", self.code),
               ("ast_mtyp", "=", 1)]
        pur = self.sql.getRec("asstrn", cols=col, where=whr, limit=1)
        if pur:
            self.buydt = pur[0]
        whr = [("ast_cono", "=", self.opts["conum"]),
               ("ast_group", "=", self.group), ("ast_code", "=", self.code),
               ("ast_mtyp", "in", (3, 5))]
        sel = self.sql.getRec("asstrn", cols=col, where=whr, limit=1)
        if sel:
            self.seldt = sel[0]
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])

    def doTrnRef(self, frt, pag, r, c, p, i, w):
        self.trnref = w

    def doTrnDat(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not in Financial Period"
        if self.bh.multi == "N" and int(w / 100) > self.bh.curdt:
            return "Invalid Date, After Batch Period"
        self.trndat = w
        if self.new == "y":
            self.trnmov = 1
            self.df.loadEntry(frt, pag, p + 1, data=self.trnmov)
            return "sk1"

    def doTrnMov(self, frt, pag, r, c, p, i, w):
        if type(w) == list:
            w = w[0] + 1
        # Do some tests to see if not new again or already sold etc.
        if w == 4 and self.opts["rtn"] != 3:
            return "Depreciation Only Allowed with Journal Entries"
        if self.opts["rtn"] == 1 and w not in (1, 2):
            return "Invalid Choice For Payment"
        if self.opts["rtn"] == 2 and w not in (5, ):
            return "Invalid Choice For Receipt"
        if w == 1 and self.buydt:
            return "Asset Already Purchased"
        if w in (2, 3, 4, 5) and self.seldt:
            return "Asset Already Sold or Written Off"
        if w in (2, 3, 4, 5) and not self.buydt:
            return "Asset Not Yet Purchased"
        self.df.loadEntry(frt, pag, p, data=w)
        self.trnmov = w
        if self.trnmov == 3:
            bal = self.sql.getRec("asstrn",
                                  cols=["sum(ast_amt1)", "sum(ast_amt2)"],
                                  where=[("ast_cono", "=", self.opts["conum"]),
                                         ("ast_group", "=", self.group),
                                         ("ast_code", "=", self.code)],
                                  limit=1)
            self.coyamt = float(ASD(0) - ASD(bal[0]))
            self.df.loadEntry(frt, pag, p + 1, data=self.coyamt)
            self.roramt = float(ASD(0) - ASD(bal[0]))
            self.df.loadEntry(frt, pag, p + 2, data=self.roramt)
            self.vatcode = ""
            self.trnvat = 0
            return "sk4"

    def doCoyAmt(self, frt, pag, r, c, p, i, w):
        if self.opts["rtn"] == 3 and self.trnmov == 5 and w > 0:
            ok = askQuestion(screen=self.opts["mf"].body,
                             head="Debit",
                             mess="Should this Amount not be a Credit Entry?")
            if ok == "yes":
                w = float(ASD(0) - ASD(w))
                self.df.loadEntry(frt, pag, p, data=w)
        self.coyamt = w
        if self.rordp == "N" or not self.rate1r or self.trnmov != 4:
            self.roramt = 0
            self.df.loadEntry(frt, pag, p + 1, data=self.roramt)
            if self.trnmov == 4:
                self.vatcode = ""
                self.trnvat = 0
                self.df.loadEntry(frt, pag, p + 2, data=self.vatcode)
                self.df.loadEntry(frt, pag, p + 3, data=self.trnvat)
                return "sk3"
            return "sk1"

    def doRorAmt(self, frt, pag, r, c, p, i, w):
        if self.opts["rtn"] == 3 and self.trnmov == 5 and w > 0:
            ok = askQuestion(screen=self.opts["mf"].body,
                             head="Debit",
                             mess="Should this Amount not be a Credit Entry?")
            if ok == "yes":
                w = float(ASD(0) - ASD(w))
                self.df.loadEntry(frt, pag, p, data=w)
        self.roramt = w
        self.vatcode = ""
        self.trnvat = 0
        self.df.loadEntry(frt, pag, p + 1, data=self.vatcode)
        self.df.loadEntry(frt, pag, p + 2, data=self.trnvat)
        return "sk2"

    def doVatCod(self, frt, pag, r, c, p, i, w):
        vrte = getVatRate(self.sql, self.opts["conum"], w, self.trndat)
        if vrte is None:
            return "Invalid V.A.T Code"
        self.vatcode = w
        self.trnvat = round((self.coyamt * vrte / (vrte + 100)), 2)
        self.df.loadEntry(frt, pag, p + 1, data=self.trnvat)
        if not self.trnvat:
            return "sk1"

    def doVatAmt(self, frt, pag, r, c, p, i, w):
        if self.coyamt < 0 and w > 0:
            self.trnvat = float(ASD(0) - ASD(w))
        elif self.coyamt > 0 and w < 0:
            self.trnvat = float(ASD(0) - ASD(w))
        else:
            self.trnvat = w
        self.df.loadEntry(frt, pag, p, data=self.trnvat)

    def doTrnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w
        if self.opts["rtn"] not in (1, 2) and self.glint == "Y":
            self.df.colf[2][3][5] = w

    def endPage1(self):
        self.batupd = False
        self.updateTables1()
        self.updateBatch()
        if self.coyamt == 0:
            self.df.advanceLine(1)
        else:
            self.allocated = float(0.0)
            if self.glint == "N" or self.opts["rtn"] in (1, 2) or \
                    self.trnmov == 4:
                self.opts["mf"].dbm.commitDbase()
                self.df.advanceLine(1)
            else:
                self.coyamt = float(ASD(0) - ASD(self.coyamt))
                self.df.loadEntry("T", 2, 0, data=self.coyamt)
                self.df.selPage("Allocation")
                self.df.focusField("C", 2, 1)

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        self.amt = self.coyamt
        self.vat = self.trnvat
        if self.trnmov == 4:
            self.net = float(ASD(0) - ASD(self.coyamt))
            self.ror = float(ASD(0) - ASD(self.roramt))
        else:
            self.net = self.ror = float(ASD(self.coyamt) - ASD(self.trnvat))
        if self.opts["rtn"] == 1:  # Payments
            if self.coyamt == 0:
                self.recon = self.curdt
            else:
                self.recon = 0
            acc = self.assacc
            self.glt = 2
        elif self.opts["rtn"] == 2:  # Receipts
            if self.coyamt == 0:
                self.recon = self.curdt
            else:
                self.recon = 0
            self.amt = float(ASD(0) - ASD(self.amt))
            self.vat = float(ASD(0) - ASD(self.vat))
            self.net = float(ASD(0) - ASD(self.net))
            acc = self.assacc
            self.glt = 6
        elif self.opts["rtn"] == 3:  # Journal Entries
            self.recon = 0
            if self.trnmov == 4:
                acc = self.depacc
            else:
                acc = self.assacc
            self.glt = 4
        # Asset Register Transaction
        data = [
            self.opts["conum"], self.group, self.code, self.opts["rtn"],
            self.trnref, self.bh.batno, self.trndat, self.trnmov, self.net,
            self.ror, self.vat, self.curdt, self.trndet, self.vatcode, "N",
            self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("asstrn", data=data)
        if self.vatcode:
            # VAT Transaction (ctlvtf)
            data = (self.opts["conum"], self.vatcode, "I", self.curdt, "A",
                    self.opts["rtn"], self.bh.batno, self.trnref, self.trndat,
                    self.code, self.trndet, self.amt, self.vat, 0,
                    self.opts["capnm"], self.sysdtw, 0)
            self.sql.insRec("ctlvtf", data=data)
        if self.glint == "N":
            return
        # General Ledger Asset or Depreciation Account
        data = (self.opts["conum"], acc, self.curdt, self.trndat, self.glt,
                self.trnref, self.bh.batno, self.net, self.vat, self.trndet,
                self.vatcode, "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        if self.vat:
            # General Ledger Control Transaction (V.A.T.)
            data = [
                self.opts["conum"], self.convat, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, self.vat, 0.00,
                self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("gentrn", data=data)
        self.amt = float(ASD(0) - ASD(self.amt))
        if self.opts["rtn"] in (1, 2):
            # General Ledger Control Transaction (Bank)
            data = [
                self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, self.amt, 0.00,
                self.trndet, "N", "", self.recon, self.opts["capnm"],
                self.sysdtw, 0
            ]
            self.sql.insRec("gentrn", data=data)
        elif self.trnmov == 4:
            # General Ledger Expense Account (Depreciation)
            data = [
                self.opts["conum"], self.expacc, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, self.coyamt, self.vat,
                self.trndet, "N", "", self.recon, self.opts["capnm"],
                self.sysdtw, 0
            ]
            self.sql.insRec("gentrn", data=data)
        if self.trnmov == 5:
            # Sale of Asset
            # Raise Depreciation
            callModule(self.opts["mf"],
                       None,
                       "ar2030",
                       coy=(self.opts["conum"], self.opts["conam"]),
                       period=self.opts["period"],
                       user=self.opts["capnm"],
                       args=(self.curdt, self.group, self.code))
            # Generate Sale
            amt = self.sql.getRec("asstrn",
                                  cols=["sum(ast_amt1)"],
                                  where=[("ast_cono", "=", self.opts["conum"]),
                                         ("ast_group", "=", self.group),
                                         ("ast_code", "=", self.code)],
                                  limit=1)
            if amt[0]:
                data = [
                    self.opts["conum"], self.slsac, self.curdt, self.trndat,
                    self.glt, self.trnref, self.bh.batno, amt[0], 0,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
                data[1] = acc
                data[7] = float(ASD(0) - ASD(amt[0]))
                self.sql.insRec("gentrn", data=data)

    def exitPage1(self):
        self.df.closeProcess()
        self.bh.doBatchTotal()
        self.opts["mf"].closeLoop()

    def doGenAcc(self, frt, pag, r, c, p, i, w):
        chk = chkGenAcc(self.opts["mf"], self.opts["conum"], w)
        if type(chk) is str:
            return chk
        self.genacc = w
        self.df.loadEntry("C", pag, p + 1, data=chk[0])

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if w == 0:
            self.allamt = float(ASD(self.coyamt) - ASD(self.allocated))
            self.df.loadEntry(frt, pag, p, data=self.allamt)
        else:
            self.allamt = w

    def doAllDet(self, frt, pag, r, c, p, i, w):
        self.alldet = w

    def doCancel(self):
        ok = askQuestion(self.opts["mf"].body,
                         head="Cancel",
                         mess="Are You Certain You Want to Cancel This Entry?")
        if ok == "yes":
            self.opts["mf"].dbm.rollbackDbase()
            if self.batupd:
                self.updateBatch(rev=True)
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            row = int(int((self.df.last[1][1] - 1) / self.df.colq[1]))
            col = (row * self.df.colq[1]) + 1
            self.df.focusField("C", 1, col)

    def endPage2(self):
        self.updateTables2()
        self.allocated = float(ASD(self.allocated) + ASD(self.allamt))
        if self.allocated == self.coyamt:
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.coyamt) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def updateTables2(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        # General Ledger Transaction (Allocation)
        amt = float(ASD(0) - ASD(self.allamt))
        data = (self.opts["conum"], self.genacc, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, amt, 0.00, self.alldet,
                "N", "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)

    def exitPage2(self):
        self.df.focusField("C", 2, self.df.col)

    def updateBatch(self, rev=False):
        if rev:
            self.bh.batqty -= 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.coyamt))
        else:
            self.batupd = True
            self.bh.batqty += 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.coyamt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def doNewAsset(self):
        tit = ("Create New Asset", )
        dep = {
            "stype":
            "R",
            "tables": ("assdep", ),
            "cols": (("asd_code", "", 0, "Cod"), ("asd_desc", "", 0,
                                                  "Description", "Y")),
            "where": [("asd_cono", "=", self.opts["conum"])]
        }
        self.fld = ((("T", 0, 0, 0), "INA", 30, "Description", "", "", "N",
                     None, None, None, ("notblank", )),
                    (("T", 0, 1, 0), "INa", 3, "Dep Code", "Depreciation Code",
                     self.depcod, "N", self.doDepCode, dep, None,
                     ("notblank", )), (("T", 0, 1, 0), "ONA", 34, ""))
        tnd = ((self.doNewEnd, "N"), )
        txt = (self.doNewXit, )
        state = self.df.disableButtonsTags()
        self.na = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=self.fld,
                               tend=tnd,
                               txit=txt)
        self.na.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)

    def doDepCode(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("assdep",
                              cols=["asd_desc"],
                              where=[("asd_cono", "=", self.opts["conum"]),
                                     ("asd_code", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Depreciation Code"
        self.na.loadEntry(frt, pag, p + 1, data=chk[0])

    def doNewEnd(self):
        dat = [self.opts["conum"], self.group, self.code]
        for x in range(len(self.na.t_work[0][0]) - 1):
            dat.append(self.na.t_work[0][0][x])
        self.sql.insRec("assmst", data=dat)
        self.doNewXit()

    def doNewXit(self):
        self.na.closeProcess()

    def queryAss(self):
        callModule(self.opts["mf"],
                   self.df,
                   "ar4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=self.opts["period"],
                   user=self.opts["capnm"])
Пример #20
0
class glc110(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["ctlctl", "genmst"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        # -------------------------------
        # General Ledger Control Records
        # -------------------------------
        # Get Company Details
        gc = GetCtl(self.opts["mf"])
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        # Standard Controls
        self.glctrl = [("bank_1", "Bank Control 1"),
                       ("bank_2", "Bank Control 2"),
                       ("bank_3", "Bank Control 3"),
                       ("bank_4", "Bank Control 4"),
                       ("bank_5", "Bank Control 5"),
                       ("bank_6", "Bank Control 6"),
                       ("bank_7", "Bank Control 7"),
                       ("bank_8", "Bank Control 8"),
                       ("bank_9", "Bank Control 9"),
                       ("bank_10", "Bank Control 10"),
                       ("p_cash", "Petty Cash Control"),
                       ("crs_ctl", "Creditors Control"),
                       ("drs_ctl", "Debtors Control"),
                       ("ret_inc", "Retained Income"),
                       ("vat_ctl", "VAT Control")]
        # Check for Integrated Systems
        mod = []
        for x in range(0, len(ctlmst["ctm_modules"].rstrip()), 2):
            mod.append(ctlmst["ctm_modules"][x:x + 2])
        # Load Systems Integration
        if mod.count("AR"):
            assctl = gc.getCtl("assctl", self.opts["conum"], error=False)
            if assctl and assctl["cta_glint"] == "Y":
                self.glctrl.extend([("ass_sls", "Sale of Assets")])
        if mod.count("BK"):
            bkmctl = gc.getCtl("bkmctl", self.opts["conum"], error=False)
            if bkmctl and bkmctl["cbk_glint"] == "Y":
                self.glctrl.extend([("bkm_ctl", "Bookings Control"),
                                    ("bkm_chq", "Cheques Received"),
                                    ("bkm_csh", "Cash Received"),
                                    ("bkm_ccg", "Cancellation Fee")])
                if not mod.count("DR"):
                    self.glctrl.extend([("dis_all", "Discount Allowed")])
        if mod.count("CR"):
            crsctl = gc.getCtl("crsctl", self.opts["conum"], error=False)
            if crsctl and crsctl["ctc_glint"] == "Y":
                self.glctrl.extend([("dis_rec", "Discount Received")])
        if mod.count("CS"):
            cshctl = gc.getCtl("cshctl", self.opts["conum"], error=False)
            if cshctl and cshctl["ccc_glint"] == "Y":
                self.glctrl.extend([("csh_ctl", "Cash Control")])
        if mod.count("DR"):
            drsctl = gc.getCtl("drsctl", self.opts["conum"], error=False)
            if drsctl and drsctl["ctd_glint"] == "Y":
                self.glctrl.extend([("dis_all", "Discount Allowed")])
        if mod.count("LN"):
            lonctl = gc.getCtl("lonctl", self.opts["conum"], error=False)
            if lonctl and lonctl["cln_glint"] == "Y":
                self.glctrl.extend([("lon_ctl", "Loans Control"),
                                    ("int_pay", "Interest Paid"),
                                    ("int_rec", "Interest Received")])
        if mod.count("ML"):
            memctl = gc.getCtl("memctl", self.opts["conum"], error=False)
            if memctl and memctl["mcm_glint"] == "Y":
                self.glctrl.extend([("mem_ctl", "Members Control"),
                                    ("mem_pen", "Members Penalties")])
        if mod.count("RC"):
            rcactl = gc.getCtl("rcactl", self.opts["conum"], error=False)
            if rcactl and rcactl["cte_glint"] == "Y":
                self.glctrl.extend([("rca_com", "Commission Raised"),
                                    ("rca_dep", "Deposits Control"),
                                    ("rca_fee", "Contract Fees"),
                                    ("rca_own", "Owners Control"),
                                    ("rca_orx", "Owners Charges"),
                                    ("rca_tnt", "Tenants Control"),
                                    ("rca_trx", "Tenants Charges")])
        if mod.count("ST"):
            strctl = gc.getCtl("strctl", self.opts["conum"], error=False)
            if strctl and strctl["cts_glint"] == "Y":
                self.glctrl.extend([("stk_soh", "Stock on Hand"),
                                    ("stk_susp", "Stock Reconciliation")])
        if mod.count("WG") or mod.count("SL"):
            wagctl = gc.getCtl("wagctl", self.opts["conum"], error=False)
            if wagctl and wagctl["ctw_glint"] == "Y":
                self.glctrl.extend([("wag_ctl", "Salaries Control"),
                                    ("wag_slc", "Staff Loans Control"),
                                    ("wag_sli", "Staff Loans Interest")])
        return True

    def drawDialog(self):
        ctl = {
            "stype": "C",
            "titl": "Select Control",
            "head": ("Code", "Description"),
            "typs": (("NA", 10), ("NA", 30)),
            "data": self.glctrl
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        r1s = (("None", "N"), ("OFX", "O"), ("QIF", "Q"), ("S/Bank Online",
                                                           "S"))
        r2s = (("None", "N"), ("CCYYMMDD", "A"), ("DDMMCCYY", "B"),
               ("MMDD(CC)YY", "C"))
        fld = ((("T", 0, 0, 0), "INA", 10, "Code", "Control Code", "", "Y",
                self.doCode, ctl, None, None), (("T", 0, 0, 25), "ONA", 30,
                                                "Description"),
               (("T", 0, 1, 0), "IUI", 7, "G/L Acc-Num", "G/L Account Number",
                "", "N", self.doAccNum, glm, self.doDelete,
                ("notzero", )), (("T", 0, 1, 25), "ONA", 30, "Description"),
               (("T", 0, 2, 0), "INA", 16, "Bank Account",
                "Bank Account Number", "", "N", self.doImpBnk, None, None,
                ("efld", )), (("T", 0, 3, 0), ("IRB", r1s), 0, "Import Format",
                              "", "N", "N", self.doImpFmt, None, None, None),
               (("T", 0, 4, 0), ("IRB", r2s), 0, "Date Format", "", "A", "N",
                self.doDteFmt, None, None, None))
        but = (("Accept", None, self.doAccept, 0, ("T", 0, 3), ("T", 0, 0)),
               ("Cancel", None, self.doCancel, 0, ("T", 0, 3), ("T", 0, 0)),
               ("Print", None, self.doPrint, 0, ("T", 0, 1),
                ("T", 0, 2)), ("Quit", None, self.doExit, 1, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt)

    def doCode(self, frt, pag, r, c, p, i, w):
        self.code = w
        d1 = ""
        for ctl in self.glctrl:
            if self.code in ctl:
                d1 = ctl[1]
                break
        if not d1:
            return "Invalid Control Code"
        self.df.loadEntry(frt, pag, p + 1, data=d1)
        self.acc = self.sql.getRec("ctlctl",
                                   where=[("ctl_cono", "=",
                                           self.opts["conum"]),
                                          ("ctl_code", "=", self.code)],
                                   limit=1)
        if not self.acc:
            self.new = "y"
        else:
            self.new = "n"
            col = self.sql.ctlctl_col
            desc = self.readAcno(self.acc[col.index("ctl_conacc")])
            if not desc:
                desc = [""]
            self.df.loadEntry(frt,
                              pag,
                              p + 2,
                              data=self.acc[col.index("ctl_conacc")])
            self.df.loadEntry(frt, pag, p + 3, data=desc[0])
            self.df.loadEntry(frt,
                              pag,
                              p + 4,
                              data=self.acc[col.index("ctl_bankac")])
            self.df.loadEntry(frt,
                              pag,
                              p + 5,
                              data=self.acc[col.index("ctl_impfmt")])
            self.df.loadEntry(frt,
                              pag,
                              p + 6,
                              data=self.acc[col.index("ctl_dtefmt")])

    def doDelete(self):
        self.sql.delRec("ctlctl",
                        where=[("ctl_cono", "=", self.opts["conum"]),
                               ("ctl_code", "=", self.code)])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doAccNum(self, frt, pag, r, c, p, i, w):
        desc = self.readAcno(w)
        if not desc:
            return "Invalid Account Number"
        self.df.loadEntry(frt, pag, p + 1, data=desc[0])
        if self.code[:4] != "bank":
            self.impfmt = "N"
            self.bankac = ""
            self.dtefmt = "N"
            return "nd"

    def readAcno(self, acno):
        self.acno = acno
        acc = self.sql.getRec("genmst",
                              cols=["glm_desc"],
                              where=[("glm_cono", "=", self.opts["conum"]),
                                     ("glm_acno", "=", self.acno)],
                              limit=1)
        return acc

    def doImpBnk(self, frt, pag, r, c, p, i, w):
        self.bankac = w
        if not self.bankac:
            self.impfmt = "N"
            self.dtefmt = "N"
            self.df.loadEntry(frt, pag, p + 1, data=self.impfmt)
            self.df.loadEntry(frt, pag, p + 2, data=self.dtefmt)
            return "sk2"

    def doImpFmt(self, frt, pag, r, c, p, i, w):
        self.impfmt = w
        if self.impfmt == "N":
            self.dtefmt = "N"
            self.df.loadEntry(frt, pag, p + 1, data=self.dtefmt)
            return "nd"
        self.df.loadEntry(frt, pag, p + 1, data="A")

    def doDteFmt(self, frt, pag, r, c, p, i, w):
        if w not in ("A", "B", "C"):
            return "Invalid Date Format"
        self.dtefmt = w

    def doEnd(self):
        data = [
            self.opts["conum"], self.code, self.df.t_work[0][0][1], self.acno,
            self.bankac, self.impfmt, self.dtefmt
        ]
        if self.new == "y":
            self.sql.insRec("ctlctl", data=data)
        elif data != self.acc[:len(data)]:
            col = self.sql.ctlctl_col
            data.append(self.acc[col.index("ctl_xflag")])
            self.sql.updRec("ctlctl",
                            data=data,
                            where=[("ctl_cono", "=", self.opts["conum"]),
                                   ("ctl_code", "=", self.code)])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doAccept(self):
        frt, pag, col, mes = self.df.doCheckFields()
        if mes:
            self.df.focusField(frt, pag, (col + 1), err=mes)
        else:
            self.df.doEndFrame("T", 0, cnf="N")

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.df.focusField("T", 0, 1)

    def doPrint(self):
        table = ["ctlctl"]
        heads = ["General Ledger Control Accounts"]
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, "hide")
        RepPrt(self.opts["mf"],
               name="glc110",
               tables=table,
               heads=heads,
               where=[("ctl_cono", "=", self.opts["conum"])],
               order="ctl_code",
               prtdia=(("Y", "V"), ("Y", "N")))
        self.df.setWidget(self.df.mstFrame, "show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #21
0
class wgc320(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,
                       "wagedc",
                       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"]
        return True

    def mainProcess(self):
        r1s = (("Earnings", "E"), ("Deductions", "D"), ("Both", "B"))
        r2s = (("Code Number", "N"), ("Description", "D"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Report Type     ",
                "Report Type", "E", "Y", self.doType, None, None, None),
               (("T", 0, 1, 0), ("IRB", r2s), 0, "Sort Order      ",
                "Sort Order", "N", "Y", self.doSort, None, None, None))
        tnd = ((self.doEnd, "Y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "N"))

    def doType(self, frt, pag, r, c, p, i, w):
        self.rtyp = w

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

    def doEnd(self):
        self.df.closeProcess()
        if self.sort == "N":
            odr = "ced_type desc, ced_code"
        else:
            odr = "ced_type desc, ced_desc"
        if self.rtyp in ("E", "D"):
            recs = self.sql.getRec("wagedc",
                                   where=[("ced_cono", "=",
                                           self.opts["conum"]),
                                          ("ced_type", "=", self.rtyp)],
                                   order=odr)
        else:
            recs = self.sql.getRec("wagedc",
                                   where=[("ced_cono", "=", self.opts["conum"])
                                          ],
                                   order=odr)
        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):
        descs = [
            "", "Type", "Code Number", "Description", "Fixed or Variable",
            "EMPLOYEE Rate or Amount", "         Based On", "         Amount",
            "         Limit", "         G/L Cono", "         G/L Number",
            "         Earnings Type", "EMPLOYER Rate or Amount",
            "         Based On", "         Amount", "         Limit",
            "         G/L Cono", "         G/L Number", "Tax Code",
            "Taxable Portion", "Receiver of Revenue Code",
            "Include in Union Report", "Must Pay", "Balance Number",
            "Hourly Limit", "Monthly Deduction", "UIF Portion", "SDL Portion"
        ]
        tables = []
        for rec in recs:
            for y in range(1, len(recs[0]) - 1):
                lin = []
                lin.append("")
                lin.append(descs[y])
                lin.append(rec[y])
                tables.append(lin)
        if self.rtyp == "E":
            typ = "Earnings"
        elif self.rtyp == "D":
            typ = "Deductions"
        else:
            typ = "Earnings and Deductions"
        heads = ["%s Codes Listing" % typ]
        cols = [["a", "NA", 15.0, " "], ["b", "RW", 30.0, "Field Name"],
                ["c", "NA", 30.0, "Details"]]
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"],
               name=self.__class__.__name__,
               tables=tables,
               heads=heads,
               cols=cols,
               conum=self.opts["conum"],
               ttype="D",
               conam=self.opts["conam"],
               lines=(len(descs) - 1),
               repprt=self.df.repprt,
               repeml=self.df.repeml,
               fromad=self.fromad)
        self.df.enableButtonsTags(state=state)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #22
0
class dr1010(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, [
            "ctlmes", "ctlrep", "chglog", "ctlnot", "slsiv1", "drsact",
            "drschn", "drsdel", "drsmst", "drstrn", "drstyp"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        drsctl = gc.getCtl("drsctl", self.opts["conum"])
        if not drsctl:
            return
        self.chains = drsctl["ctd_chain"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

    def mainProcess(self):
        drc = {
            "stype": "R",
            "tables": ("drschn", ),
            "cols":
            (("chm_chain", "", 0, "Num"), ("chm_name", "", 0, "Name", "Y")),
            "where": [("chm_cono", "=", self.opts["conum"])]
        }
        drm = {
            "stype":
            "R",
            "tables": ("drsmst", ),
            "cols":
            (("drm_acno", "", 0, "Acc-Num"), ("drm_name", "", 0, "Name", "Y"),
             ("drm_add1", "", 0, "Address Line 1"))
        }
        if self.chains == "Y":
            drm["where"] = [("drm_cono", "=", self.opts["conum"])]
            drm["whera"] = [["T", "drm_chain", 0]]
        else:
            drm["where"] = [("drm_cono", "=", self.opts["conum"]),
                            ("drm_chain", "=", 0)]
        drm["where"].append(("drm_stat", "<>", "X"))
        dlm = {
            "stype":
            "R",
            "tables": ("drsdel", ),
            "cols": (("del_code", "", 0, "Del-Cod"), ("del_add1", "", 0,
                                                      "Address", "Y"))
        }
        rpm = {
            "stype": "R",
            "tables": ("ctlrep", ),
            "cols":
            (("rep_code", "", 0, "Rep"), ("rep_name", "", 0, "Name", "Y")),
            "where": [("rep_cono", "=", self.opts["conum"])]
        }
        act = {
            "stype":
            "R",
            "tables": ("drsact", ),
            "cols": (("dac_code", "", 0, "Cod"), ("dac_desc", "", 0,
                                                  "Description", "Y"))
        }
        typ = {
            "stype":
            "R",
            "tables": ("drstyp", ),
            "cols": (("dtp_code", "", 0, "Cod"), ("dtp_desc", "", 0,
                                                  "Description", "Y"))
        }
        msi = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": (("mss_message", "", 0, "Num"), ("mss_detail", "NA", 50,
                                                     "Details", "Y")),
            "where": [("mss_system", "=", "INV")]
        }
        mss = {
            "stype":
            "R",
            "tables": ("ctlmes", ),
            "cols": (("mss_message", "", 0, "Num"), ("mss_detail", "NA", 50,
                                                     "Details", "Y")),
            "where": [("mss_system", "=", "STA")]
        }
        tag = (("Basic-_A", None, ("T", 1, 1), ("T", 0, 1)),
               ("Basic-_B", None, ("T", 1, 1), ("T", 0, 1)))
        r1s = (("Yes", "Y"), ("No", "N"))
        r2s = (("New", "N"), ("Good", "G"), ("Fair", "F"), ("Poor", "P"),
               ("Bad", "B"))
        self.fld = [
            [("T",0,0,0),"IUI",3,"Chain Store","",
                "","Y",self.doChain,drc,None,("efld",)],
            [("T",0,0,14),"INA",7,"Acc-Num","Account Number",
                "","N",self.doAcno,drm,None,("efld",),None,
                "To Automatically Generate Account Numbers for "\
                "New Accounts enter a Blank Account Number."],
            (("T",0,0,30),"INA",30,"Name","",
                "","N",self.doName,None,self.doDelete,("notblank",)),
            [("T",0,0,0),"INA",7,"Acc-Num","Account Number",
                "","Y",self.doAcno,drm,None,("efld",),None,
                "To Automatically Generate Account Numbers for "\
                "New Accounts enter a Blank Account Number."],
            (("T",0,0,14),"INA",30,"Name","",
                "","N",self.doName,None,self.doDelete,("notblank",)),
            (("T",1,0,0),"INA",30,"Address Line 1","",
                "","N",None,None,None,("notblank",)),
            (("T",1,1,0),"INA",30,"Address Line 2","",
                "","N",None,None,None,("efld",)),
            (("T",1,2,0),"INA",30,"Address Line 3","",
                "","N",None,None,None,("efld",)),
            (("T",1,3,0),"INA",4,"Postal Code","",
                "","N",None,None,None,("efld",)),
            (("T",1,4,0),"INA",20,"Telephone","",
                "","N",None,None,None,("efld",)),
            (("T",1,5,0),"INA",20,"Fax","",
                "","N",None,None,None,("efld",)),
            (("T",1,6,0),"INA",30,"Manager","Manager's Name",
                "","N",None,None,None,("efld",)),
            (("T",1,6,47),"ITX",30,"E-Mail","Manager's E-Mail Address",
                "","N",None,None,None,("email",)),
            (("T",1,7,0),"INA",30,"Accounts","Accounts Contact",
                "","N",None,None,None,("efld",)),
            (("T",1,7,47),"ITX",30,"E-Mail","Accounts E-Mail Address",
                "","N",None,None,None,("email",)),
            (("T",1,8,0),"INA",30,"Sales","Sales Contact",
                "","N",None,None,None,("efld",)),
            (("T",1,8,47),"ITX",30,"E-Mail","Sales E-Mail Address",
                "","N",None,None,None,("email",)),
            (("T",1,9,0),"Id1",10,"Date Opened","Date Account Opened",
                self.sysdtw,"N",None,None,None,("efld",)),
            (("T",1,10,0),"Id1",10,"Date Registered","",
                "","N",None,None,None,("efld",)),
            (("T",1,11,0),"INA",10,"V.A.T Number","",
                "","N",None,None,None,("efld",)),
            (("T",1,12,0),"INa",7,"Delivery Code","",
                "","N",self.doDelivery,dlm,None,("efld",)),
            (("T",1,13,0),"INa",3,"Rep Code","",
                "","N",self.doRep,rpm,None,("efld",)),
            (("T",1,13,20),"ONA",26,""),
            (("T",1,14,0),"IUA",3,"Business Activity","",
                "","N",self.doBusAct,act,None,("efld",)),
            (("T",1,14,20),"ONA",26,""),
            (("T",1,15,0),"IUA",3,"Business Type","",
                "","N",self.doBusTyp,typ,None,("efld",)),
            (("T",1,15,20),"ONA",26,""),
            (("T",2,0,0),"IUI",1,"Price Level","",
                "","N",None,None,None,("efld",)),
            (("T",2,1,0),"IUD",5.2,"Discount Percentage","",
                "","N",None,None,None,("efld",)),
            (("T",2,2,0),"IUD",5.2,"Interest Percentage","",
                "","N",None,None,None,("efld",)),
            (("T",2,3,0),"IUI",3,"Referral Terms","",
                "","N",None,None,None,("efld",)),
            (("T",2,4,0),"IUI",3,"Rejected Terms","",
                "","N",None,None,None,("efld",)),
            (("T",2,5,0),"IUI",5,"Credit Limit","",
                "","N",None,None,None,("efld",)),
            (("T",2,6,0),("IRB",r1s),0,"Stop Indicator","",
                "N","N",None,None,None,None),
            (("T",2,7,0),"IUI",3,"Invoice Message","",
                "","N",self.doImes,msi,None,("efld",)),
            (("T",2,7,22),"ONA",50,""),
            (("T",2,8,0),"IUI",3,"Statement Message","",
                "","N",self.doSmes,mss,None,("efld",)),
            (("T",2,8,22),"ONA",50,""),
            (("T",2,9,0),("IRB",r2s),0,"Credit Rating","",
                "N","N",None,None,None,None)]
        but = (("Import", None, self.doImport, 0, ("T", 0, 1), ("T", 0, 2),
                "Import Account Details from a CSV or XLS File."),
               ("Accept", None, self.doAccept, 0, ("T", 1, 1), ("T", 0, 1)),
               ("Print", None, self.doPrint, 0, ("T", 1, 1), ("T", 0, 1)),
               ("Cancel", None, self.doCancel, 0, ("T", 1, 1),
                ("T", 0, 1)), ("Quit", None, self.doExit1, 1, None, None))
        tnd = ((self.doEnd1, "N"), (self.doEnd2, "N"), (self.doAccept, "Y"))
        txt = (self.doExit1, self.doExit2, self.doExit3)
        if self.chains == "Y":
            del self.fld[3]
            del self.fld[3]
        else:
            del self.fld[0]
            del self.fld[0]
            del self.fld[0]
            self.chain = 0
        self.df = TartanDialog(self.opts["mf"],
                               eflds=self.fld,
                               tags=tag,
                               butt=but,
                               tend=tnd,
                               txit=txt,
                               clicks=self.doClick)
        if "args" in self.opts:
            if self.chains == "Y":
                self.df.doKeyPressed("T", 0, 0, data=self.opts["args"][0])
                self.df.doKeyPressed("T", 0, 1, data=self.opts["args"][1])
            else:
                self.chain = self.opts["args"][0]
                self.df.doKeyPressed("T", 0, 0, data=self.opts["args"][1])

    def doClick(self, *opts):
        if self.df.pag == 0:
            return
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def doChain(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drschn",
                                  where=[("chm_cono", "=", self.opts["conum"]),
                                         ("chm_chain", "=", self.chain)],
                                  limit=1)
            if not acc:
                return "Invalid Chain Store"
        self.chain = w

    def doAcno(self, frt, pag, r, c, p, i, w):
        self.acno = w
        if self.acno:
            self.old = self.sql.getRec("drsmst",
                                       where=[("drm_cono", "=",
                                               self.opts["conum"]),
                                              ("drm_chain", "=", self.chain),
                                              ("drm_acno", "=", self.acno)],
                                       limit=1)
        if not self.acno or not self.old:
            ok = askQuestion(self.opts["mf"].body,
                             "New Account",
                             "Is This a New Account?",
                             default="no")
            if ok == "no":
                return "Invalid Account Number"
            pw = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="DRS",
                            code="NewAcc")
            if pw.flag == "no":
                if "args" in self.opts:
                    return "xt"
                else:
                    return "New Account Creation is Not Allowed"
            self.new = True
        elif self.old[self.sql.drsmst_col.index("drm_stat")] == "X":
            return "Invalid Account, Redundant"
        else:
            self.new = False
            self.df.loadEntry("T", pag, p + 1, data=self.old[3])
            d = 4
            for pg in range(1, self.df.pgs + 1):
                for x in range(0, self.df.topq[pg]):
                    if pg == 1 and x in (17, 19, 21):
                        continue
                    if pg == 2 and x in (8, 10):
                        continue
                    if pg == 2 and x == 11 and not self.old[d]:
                        data = "N"
                    else:
                        data = self.old[d]
                    self.df.loadEntry("T", pg, x, data=data)
                    d += 1
            self.loadRep()
            self.loadAct()
            self.loadTyp()
            self.loadInvMess()
            self.loadStaMess()

    def loadRep(self):
        acc = self.sql.getRec("ctlrep",
                              cols=["rep_name"],
                              where=[("rep_cono", "=", self.opts["conum"]),
                                     ("rep_code", "=",
                                      self.df.t_work[1][0][16])],
                              limit=1)
        if acc:
            self.df.loadEntry("T", 1, 17, data=acc[0])

    def loadAct(self):
        acc = self.sql.getRec("drsact",
                              cols=["dac_desc"],
                              where=[("dac_code", "=",
                                      self.df.t_work[1][0][18])],
                              limit=1)
        if acc:
            self.df.loadEntry("T", 1, 19, data=acc[0])

    def loadTyp(self):
        acc = self.sql.getRec("drstyp",
                              cols=["dtp_desc"],
                              where=[("dtp_code", "=",
                                      self.df.t_work[1][0][20])],
                              limit=1)
        if acc:
            self.df.loadEntry("T", 1, 21, data=acc[0])

    def loadInvMess(self):
        acc = self.sql.getRec("ctlmes",
                              cols=["mss_detail"],
                              where=[("mss_system", "=", "INV"),
                                     ("mss_message", "=",
                                      self.df.t_work[2][0][7])],
                              limit=1)
        if acc:
            self.df.loadEntry("T", 2, 8, data=acc[0])

    def loadStaMess(self):
        acc = self.sql.getRec("ctlmes",
                              cols=["mss_detail"],
                              where=[("mss_system", "=", "STA"),
                                     ("mss_message", "=",
                                      self.df.t_work[2][0][9])],
                              limit=1)
        if acc:
            self.df.loadEntry("T", 2, 10, data=acc[0])

    def doName(self, frt, pag, r, c, p, i, w):
        self.name = w
        if self.new and not self.acno:
            for x in range(1, 100):
                self.acno = genAccNum(self.name, x, 7)
                chk = self.sql.getRec("drsmst",
                                      where=[("drm_cono", "=",
                                              self.opts["conum"]),
                                             ("drm_chain", "=", self.chain),
                                             ("drm_acno", "=", self.acno)],
                                      limit=1)
                if not chk:
                    break
            self.df.loadEntry("T", 0, 0, data=self.acno)

    def doDelivery(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drsdel",
                                  where=[("del_code", "=", w)],
                                  limit=1)
            if not acc:
                ok = askQuestion(self.opts["mf"].body, head="Delivery Address",
                    mess="This Delivery Address Does Not Exist, Would "\
                    "You Like to Create It Now?", default="no")
                if ok == "no":
                    return "rf"
                callModule(self.opts["mf"],
                           self.df,
                           "drc410",
                           coy=(self.opts["conum"], self.opts["conam"]),
                           period=None,
                           user=None,
                           args=w)
                acc = self.sql.getRec("drsdel",
                                      where=[("del_code", "=", w)],
                                      limit=1)
                if not acc:
                    return "rf"

    def doRep(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("ctlrep",
                                  cols=["rep_name"],
                                  where=[("rep_cono", "=", self.opts["conum"]),
                                         ("rep_code", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Rep"
            self.df.loadEntry("T", 1, p + 1, data=acc[0])

    def doBusAct(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drsact",
                                  cols=["dac_desc"],
                                  where=[("dac_code", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Business Activity"
            self.df.loadEntry("T", 1, p + 1, data=acc[0])

    def doBusTyp(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drstyp",
                                  cols=["dtp_desc"],
                                  where=[("dtp_code", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Business Type"
            self.df.loadEntry("T", 1, p + 1, data=acc[0])

    def doImes(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("ctlmes",
                                  cols=["mss_detail"],
                                  where=[("mss_system", "=", "INV"),
                                         ("mss_message", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Invoice Message"
            self.df.loadEntry("T", 2, p + 1, data=acc[0])

    def doSmes(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("ctlmes",
                                  cols=["mss_detail"],
                                  where=[("mss_system", "=", "STA"),
                                         ("mss_message", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Statement Message"
            self.df.loadEntry("T", 2, p + 1, data=acc[0])

    def doDelete(self):
        trs = self.sql.getRec("drstrn",
                              cols=["count(*)"],
                              where=[("drt_cono", "=", self.opts["conum"]),
                                     ("drt_chain", "=", self.chain),
                                     ("drt_acno", "=", self.acno)],
                              limit=1)
        if trs[0]:
            return "%s Transactions Exist, Not Deleted" % trs[0]
        iv1 = self.sql.getRec("slsiv1",
                              cols=["count(*)"],
                              where=[("si1_cono", "=", self.opts["conum"]),
                                     ("si1_chain", "=", self.chain),
                                     ("si1_acno", "=", self.acno)],
                              limit=1)
        if iv1[0]:
            return "%s Sales Document Exists, Not Deleted" % iv1[0]
        key = "%03i%s" % (self.chain, self.acno)
        nte = self.sql.getRec("ctlnot",
                              cols=["count(*)"],
                              where=[("not_cono", "=", self.opts["conum"]),
                                     ("not_sys", "=", "DRS"),
                                     ("not_key", "=", key)],
                              limit=1)
        if nte[0]:
            return "%s Notes Exist, Not Deleted" % nte[0]
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        self.sql.delRec("drsmst",
                        where=[("drm_cono", "=", self.opts["conum"]),
                               ("drm_chain", "=", self.chain),
                               ("drm_acno", "=", self.acno)])
        self.sql.insRec("chglog", data=["drsmst", "D", "%03i%03i%-7s" % \
            (self.opts["conum"], self.chain, self.acno), "", dte,
            self.opts["capnm"], "", "", "", 0])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doEnd1(self):
        self.df.focusField("T", 1, 1, clr=self.new)

    def doEnd2(self):
        self.df.selPage("Basic-B")
        self.df.focusField("T", 2, 1, clr=self.new)

    def doAccept(self):
        frt, pag, col, mes = self.df.doCheckFields()
        if mes:
            if pag > 0 and pag != self.df.pag:
                if frt == "T":
                    self.df.last[pag][0] = col + 1
                else:
                    self.df.last[pag][1] = col + 1
                self.df.selPage(self.df.tags[pag - 1][0])
            else:
                self.df.focusField(frt, pag, (col + 1), err=mes)
        else:
            data = [self.opts["conum"], self.chain]
            if self.chains == "Y":
                f = 1
            else:
                f = 0
            for x in range(f, f + 2):
                data.append(self.df.t_work[0][0][x])
            for x in range(0, len(self.df.t_work[1][0])):
                if x in (17, 19, 21):
                    continue
                data.append(self.df.t_work[1][0][x])
            for x in range(0, len(self.df.t_work[2][0])):
                if x in (8, 10):
                    continue
                data.append(self.df.t_work[2][0][x])
            if self.new:
                data.extend(["N", ""])
                self.sql.insRec("drsmst", data=data)
            else:
                col = self.sql.drsmst_col
                data.append(self.old[col.index("drm_stat")])
                data.append(self.old[col.index("drm_xflag")])
                if data != self.old:
                    self.sql.updRec("drsmst",
                                    data=data,
                                    where=[("drm_cono", "=",
                                            self.opts["conum"]),
                                           ("drm_chain", "=", self.chain),
                                           ("drm_acno", "=", self.acno)])
                    dte = int("%04i%02i%02i%02i%02i%02i" %
                              time.localtime()[:-3])
                    for num, dat in enumerate(self.old):
                        if dat != data[num]:
                            self.sql.insRec(
                                "chglog",
                                data=[
                                    "drsmst", "U",
                                    "%03i%03i%-7s" % (self.opts["conum"],
                                                      self.chain, self.acno),
                                    col[num], dte, self.opts["capnm"],
                                    str(dat),
                                    str(data[num]), "", 0
                                ])
            if "args" in self.opts:
                self.doExit1()
            else:
                self.opts["mf"].dbm.commitDbase()
                self.df.last[0] = [0, 0]
                self.df.selPage("Basic-A")
                self.df.focusField("T", 0, 1)

    def doImport(self):
        self.df.setWidget(self.df.B3, state="disabled")
        self.df.setWidget(self.df.mstFrame, state="hide")
        fi = FileImport(self.opts["mf"], imptab="drsmst", impskp=["drm_cono"])
        sp = ProgressBar(self.opts["mf"].body,
                         typ="Importing Debtor's Accounts",
                         mxs=len(fi.impdat))
        err = None
        for num, line in enumerate(fi.impdat):
            sp.displayProgress(num)
            if not line[1]:
                if not line[2]:
                    err = "Blank Account Number and Blank Name"
                    break
                for x in range(1, 100):
                    line[1] = genAccNum(line[2], x, 7)
                    chk = self.sql.getRec("drsmst",
                                          where=[("drm_cono", "=",
                                                  self.opts["conum"]),
                                                 ("drm_chain", "=", line[0]),
                                                 ("drm_acno", "=", line[1])],
                                          limit=1)
                    if not chk:
                        break
            chk = self.sql.getRec("drsmst",
                                  where=[("drm_cono", "=", self.opts["conum"]),
                                         ("drm_chain", "=", line[0]),
                                         ("drm_acno", "=", line[1])],
                                  limit=1)
            if chk:
                err = "%s %s %s %s Already Exists" % (fi.impcol[0][0], line[0],
                                                      fi.impcol[1][0], line[1])
                break
            if not line[2]:
                err = "Blank Name"
                break
            if not line[15]:
                line[15] = self.sysdtw
            if not line[28]:
                line[28] = "N"
            if not line[31]:
                line[31] = "N"
            line.insert(0, self.opts["conum"])
            self.sql.insRec("drsmst", data=line)
        sp.closeProgress()
        if err:
            err = "Line %s: %s" % ((num + 1), err)
            showError(
                self.opts["mf"].body, "Import Error", """%s

Please Correct your Import File and then Try Again.""" % err)
            self.opts["mf"].dbm.rollbackDbase()
        else:
            self.opts["mf"].dbm.commitDbase()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doPrint(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        TabPrt(self.opts["mf"],
               self.opts["conum"],
               self.opts["conam"],
               name=self.__class__.__name__,
               tabs="drsmst",
               where=[("drm_cono", "=", self.opts["conum"]),
                      ("drm_chain", "=", self.chain),
                      ("drm_acno", "=", self.acno)])
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.df.last[0] = [0, 0]
        self.df.selPage("Basic-A")
        self.df.focusField("T", 0, 1)

    def doExit1(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()

    def doExit2(self):
        self.df.focusField("T", 0, 1)

    def doExit3(self):
        self.df.selPage("Basic-A")
Пример #23
0
class ms1040(object):
    def __init__(self, **opts):
        self.opts = opts
        if "args" in opts:
            self.code = opts["args"]
        else:
            self.code = None
        if self.setVariables():
            self.mainProcess()
            if self.code:
                self.df.doKeyPressed("T", 0, 0, self.code)
            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, ["ctlvmf", "ctlvrf", "ctlvtf",
            "chglog"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        if not self.code:
            gc = GetCtl(self.opts["mf"])
            ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
            if not ctlmst:
                return
            if not ctlmst["ctm_taxno"]:
                showError(self.opts["mf"].body, "Unregistered",
                    "The Company Record Does Not Have a V.A.T. Number")
                return
        return True

    def mainProcess(self):
        vtm = {
            "stype": "R",
            "tables": ("ctlvmf",),
            "cols": (
                ("vtm_code", "", 0, "C"),
                ("vtm_desc", "", 0, "Description", "Y"),
                ("vtm_cat", "", 0, "C")),
            "where": [("vtm_cono", "=", self.opts["conum"])]}
        vtr = {
            "stype": "R",
            "tables": ("ctlvrf",),
            "cols": (
                ("vtr_date", "", 0, "Start-Date"),
                ("vtr_rate", "", 0, "Rate")),
            "where": [("vtr_cono", "=", self.opts["conum"])],
            "whera": [["T", "vtr_code", 0, 0]]}
        vtt = {
            "stype": "C",
            "titl": "VAT Types",
            "head": ("C", "Description"),
            "data": [
                ["N", "None"],
                ["S", "Standard"],
                ["Z", "Zero Rated"],
                ["C", "Capital Item"],
                ["X", "Excluded Item"]]}
        fld = (
            (("T",0,0,0),"IUA",1,"V.A.T. Code","",
                "","Y",self.doCode,vtm,None,("notblank",)),
            (("T",0,1,0),"INA",30,"Description","",
                "","N",self.doDesc,None,self.doDelete,("notblank",)),
            (("T",0,2,0),"IUA",1,"Category","",
                "S","N",self.doCat,vtt,None,("in", ("C","N","S","X","Z"))),
            (("C",0,0,0),"Id1",10,"Start-Date","The Starting Date",
                "","N",self.doStart,vtr,None,("efld",)),
            (("C",0,0,1),"IUD",6.2,"Rate-%","The Rate",
                "","N",self.doRate,None,None,("efld",)))
        but = (
            ("Print",None,self.doPrint,0,("T",0,1),(("T",0,0),("T",0,2))),
            ("Add",None,self.doAdd,0,("T",0,0),None),
            ("Edit",None,self.doEdit,0,("T",0,0),None),
            ("Exit",None,self.doExit,0,("T",0,0),(("T",0,1),("C",0,1))))
        tnd = ((self.doTEnd,"y"), )
        txt = (self.doTExit, )
        cnd = ((self.doCEnd,"y"), )
        cxt = (self.doCExit, )
        self.df = TartanDialog(self.opts["mf"], eflds=fld,
            butt=but, tend=tnd, txit=txt, cend=cnd, cxit=cxt, rows=(15,))

    def doPrint(self):
        hds = "V.A.T. Records"
        col = [
            ["vtm_code", "UA",  1,   "C"],
            ["vtm_desc", "NA", 30,   "Description"],
            ["vtm_cat", "UA",   1,   "T"],
            ["vtr_date", "d1", 10,   "Start-Date"],
            ["vtr_rate", "UD",  6.2, "Rate"]]
        recs = self.sql.getRec(tables=["ctlvmf", "ctlvrf"], cols=["vtm_code",
            "vtm_desc", "vtm_cat", "vtr_date", "vtr_rate"], where=[("vtm_cono",
            "=", self.opts["conum"]), ("vtr_cono=vtm_cono",),
            ("vtr_code=vtm_code",)], order="vtm_code, vtr_date")
        code = None
        data = copyList(recs)
        for num, rec in enumerate(recs):
            if rec[0] == code:
                data[num][0] = ""
                data[num][1] = ""
                data[num][2] = ""
            code = rec[0]
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        RepPrt(self.opts["mf"], name=self.__class__.__name__, tables=data,
            heads=[hds], ttype="D", cols=col, prtdia=(("Y","V"), ("Y","N")))
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField("T", 0, 1)

    def doCode(self, frt, pag, r, c, p, i, w):
        self.code = w
        self.oldm = self.sql.getRec("ctlvmf", where=[("vtm_cono", "=",
            self.opts["conum"]), ("vtm_code", "=", self.code)], limit=1)
        if not self.oldm:
            self.newm = True
        else:
            self.newm = False
            self.desc = self.oldm[self.sql.ctlvmf_col.index("vtm_desc")]
            self.df.loadEntry(frt, pag, p+1, data=self.desc)
            self.cat = self.oldm[self.sql.ctlvmf_col.index("vtm_cat")]
            self.df.loadEntry(frt, pag, p+2, data=self.cat)
            self.doLoadRates()
            return "ff2"

    def doDelete(self):
        if self.df.frt == "T":
            if self.doCheckTrn():
                showError(self.opts["mf"].body, "Exists",
                    "Transactions Exist for this Code, Not Deleted")
                return
            self.sql.delRec("ctlvmf", where=[("vtm_cono", "=",
                self.opts["conum"]), ("vtm_code", "=", self.code)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            self.sql.insRec("chglog", data=["ctlvmf", "D", "%03i%-1s" % \
                (self.opts["conum"], self.code), "", dte, self.opts["capnm"],
                "", "", "", 0])
            self.sql.delRec("ctlvrf", where=[("vtr_cono", "=",
                self.opts["conum"]), ("vtr_code", "=", self.code)])
            self.opts["mf"].dbm.commitDbase()

    def doDesc(self, frt, pag, r, c, p, i, w):
        self.desc = w

    def doCat(self, frt, pag, r, c, p, i, w):
        self.cat = w

    def doTEnd(self):
        self.edit = False
        datm = [self.opts["conum"]]
        datm.extend(self.df.t_work[0][0][:3])
        if self.newm:
            self.sql.insRec("ctlvmf", data=datm)
            if self.cat in ("N", "X", "Z"):
                newr = [self.opts["conum"], self.code, 0, 0]
                self.sql.insRec("ctlvrf", data=newr)
                self.opts["mf"].dbm.commitDbase()
                self.df.focusField("T", 0, 1)
            else:
                self.doButtons()
                self.df.focusField("C", 0, 1)
        elif self.cat in ("N", "X", "Z"):
            self.df.focusField("T", 0, 1)
        elif datm != self.oldm[:len(datm)]:
            col = self.sql.ctlvmf_col
            datm.append(self.oldm[col.index("vtm_xflag")])
            self.sql.updRec("ctlvmf", data=datm, where=[("vtm_cono", "=",
                self.opts["conum"]), ("vtm_code", "=", self.code)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.oldm):
                if dat != datm[num]:
                    self.sql.insRec("chglog", data=["ctlvmf",
                    "U", "%03i%-1s" % (self.opts["conum"], self.code),
                    col[num], dte, self.opts["capnm"], str(dat),
                    str(datm[num]), "", 0])
            self.doButtons()
        self.opts["mf"].dbm.commitDbase()

    def doTExit(self):
        chks = ""
        recs = self.sql.getRec("ctlvmf", where=[("vtm_cono", "=",
            self.opts["conum"])])
        for rec in recs:
            rte = self.sql.getRec("ctlvrf", where=[("vtr_cono",
                "=", self.opts["conum"]), ("vtr_code", "=", rec[1])])
            if not rte:
                if rec[3] in ("N", "X", "Z"):
                    self.sql.insRec("ctlvrf", data=[rec[0], rec[1], 0, 0])
                    self.opts["mf"].dbm.commitDbase()
                    continue
                chks = "%s\n%1s %-30s %1s" % (chks, rec[1], rec[2], rec[3])
        if chks:
            showError(self.opts["mf"].body, "Missing Rate Record", "The "\
                "following VAT Codes do Not have Rate Records:\n%s\n\n"\
                "You will Not be able to Exit until you either Create "\
                "Rate Records or Delete these codes." % chks)
            self.df.focusField("T", 0, 1)
        else:
            self.df.closeProcess()
            if "wait" not in self.opts:
                self.opts["mf"].closeLoop()

    def doAdd(self):
        for num, rec in enumerate(self.df.c_work[0]):
            if not rec[0] and not rec[1]:
                pos = (num * 2) + 1
                self.df.focusField("C", 0, pos)
                break

    def doEdit(self):
        self.edit = True
        self.newr = False
        tit = "Edit Rate"
        vtr = {
            "stype": "R",
            "tables": ("ctlvrf",),
            "cols": (
                ("vtr_date", "", 0, "Start-Date"),
                ("vtr_rate", "", 0, "Rate")),
            "where": [
                ("vtr_cono", "=", self.opts["conum"]),
                ("vtr_code", "=", self.code)]}
        fld = (
            (("T",0,0,0),"OUA",1,"V.A.T. Code"),
            (("T",0,1,0),"ONA",30,"Description"),
            (("T",0,2,0),"OUA",1,"Category"),
            (("T",0,3,0),"Id1",10,"Start-Date","The Starting Date",
                "","N",self.doEStart,vtr,self.doEDelete,("efld",)),
            (("T",0,4,0),"IUD",6.2,"Rate-%","The Rate",
                "","N",self.doERate,None,self.doEDelete,("notzero",)))
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        self.ed = TartanDialog(self.opts["mf"], title=tit, tops=True,
            eflds=fld, tend=((self.doEEnd,"n"),), txit=(self.doEExit,))
        self.ed.loadEntry("T", 0, 0, data=self.code)
        self.ed.loadEntry("T", 0, 1, data=self.desc)
        self.ed.loadEntry("T", 0, 2, data=self.cat)
        self.ed.mstFrame.wait_window()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        if self.exit:
            self.df.focusField("T", 0, 1)
        else:
            self.doExit()

    def doEDelete(self):
        self.exit = False
        if self.ed.pos == 3:
            if self.doCheckTrn():
                return ("T", 0, 4, "Transactions Exist, Not Deleted")
            self.sql.delRec("ctlvmf", where=[("vtm_cono", "=",
                self.opts["conum"]), ("vtm_code", "=", self.code)])
            self.sql.delRec("ctlvrf", where=[("vtr_cono", "=",
                self.opts["conum"]), ("vtr_code", "=", self.code)])
        else:
            if self.doCheckTrn(self.start):
                return ("T", 0, 5, "Transactions Exist, Not Deleted")
            self.sql.delRec("ctlvrf", where=[("vtr_cono", "=",
                self.opts["conum"]), ("vtr_code", "=", self.code),
                ("vtr_date", "=", self.start)])
        self.ed.closeProcess()
        chk = self.sql.getRec("ctlvrf", cols=["count(*)"],
            where=[("vtr_cono", "=", self.opts["conum"]),
            ("vtr_code", "=", self.code)], limit=1)
        if not chk[0]:
            self.sql.delRec("ctlvmf", where=[("vtm_cono", "=",
                self.opts["conum"]), ("vtm_code", "=", self.code)])
            self.exit = True
        self.opts["mf"].dbm.commitDbase()
        return "nf"

    def doEStart(self, frt, pag, r, c, p, i, w):
        self.oldr = self.sql.getRec("ctlvrf", where=[("vtr_cono",
            "=", self.opts["conum"]), ("vtr_code", "=", self.code),
            ("vtr_date", "=", w)], limit=1)
        if not self.oldr:
            return "Date Does Not Exist"
        if self.doCheckTrn(w):
            showError(self.opts["mf"].body, "Date Error",
                "Transactions Exist for Date, Editing Not Allowed.")
            return "Invalid Date"
        self.start = w
        self.rate = self.oldr[3]
        self.ed.loadEntry(frt, pag, p+1, data=self.rate)

    def doERate(self, frt, pag, r, c, p, i, w):
        if not w:
            yes = askQuestion(self.opts["mf"].body, "Zero Rate",
                "Are You Sure That This Rate is Correct?", default="no")
            if yes == "no":
                return "Invalid Rate"
        self.rate = w

    def doEEnd(self):
        self.ed.closeProcess()
        self.doCEnd()

    def doEExit(self):
        self.ed.closeProcess()

    def doStart(self, frt, pag, r, c, p, i, w):
        if self.doCheckTrn(w):
            showError(self.opts["mf"].body, "Date Error",
                "Transactions Exist On or After This Starting Date.")
            return "Invalid Date"
        self.start = w
        self.oldr = self.sql.getRec("ctlvrf", where=[("vtr_cono",
            "=", self.opts["conum"]), ("vtr_code", "=", self.code),
            ("vtr_date", "=", self.start)], limit=1)
        if not self.oldr:
            self.newr = True
            if self.cat in ("N", "X", "Z"):
                if self.edit:
                    self.ed.loadEntry(frt, pag, p+1, data=0)
                else:
                    self.df.loadEntry(frt, pag, p+1, data=0)
                return "nd"
        else:
            self.newr = False
            if self.edit:
                self.ed.loadEntry(frt, pag, p+1,
                    data=self.oldr[self.sql.ctlvrf_col.index("vtr_rate")])
            else:
                self.df.loadEntry(frt, pag, p+1,
                    data=self.oldr[self.sql.ctlvrf_col.index("vtr_rate")])

    def doRate(self, frt, pag, r, c, p, i, w):
        if not w:
            yes = askQuestion(self.opts["mf"].body, "Zero Rate",
                "Are You Sure That This Rate is Correct?", default="no")
            if yes == "no":
                return "Invalid Rate"
        self.rate = w

    def doCheckTrn(self, date=None):
        where = [
            ("vtt_cono", "=", self.opts["conum"]),
            ("vtt_code", "=", self.code)]
        if date:
            where.append(("vtt_refdt", ">=", date))
        return self.sql.getRec("ctlvtf", cols=["count(*)"],
            where=where, limit=1)[0]

    def doCEnd(self):
        datr = [self.opts["conum"], self.code, self.start, self.rate]
        if self.newr:
            self.sql.insRec("ctlvrf", data=datr)
        elif datr != self.oldr[:len(datr)]:
            col = self.sql.ctlvrf_col
            datr.append(self.oldr[col.index("vtr_xflag")])
            self.sql.updRec("ctlvrf", data=datr, where=[("vtr_cono", "=",
                self.opts["conum"]), ("vtr_code", "=", self.code),
                ("vtr_date", "=", self.start)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.oldr):
                if dat != datr[num]:
                    self.sql.insRec("chglog", data=["ctlvrf", "U",
                        "%03i%-1s" % (self.opts["conum"], self.code),
                        col[num], dte, self.opts["capnm"], str(dat),
                        str(datr[num]), "", 0])
        self.opts["mf"].dbm.commitDbase()
        self.edit = False
        self.doExit()

    def doCExit(self):
        self.edit = False
        self.doExit()

    def doLoadRates(self):
        self.df.clearFrame("C", 0)
        recs = self.sql.getRec("ctlvrf",
            cols=["vtr_date", "vtr_rate"],
            where=[("vtr_cono", "=", self.opts["conum"]),
            ("vtr_code", "=", self.code)], order="vtr_date")
        for num, rec in enumerate(recs):
            pos = (num * 2)
            if pos > 27:
                self.df.scrollScreen(0)
                pos = 26
            self.df.focusField("C", 0, pos + 1)
            self.df.loadEntry("C", 0, pos, data=rec[0])
            self.df.focusField("C", 0, pos + 2)
            self.df.loadEntry("C", 0, pos + 1, data=rec[1], zero=True)

    def doButtons(self):
        self.df.setWidget(self.df.B1, "normal")
        self.df.setWidget(self.df.B2, "normal")
        self.df.setWidget(self.df.B3, "normal")
        self.opts["mf"].window.focus_set()

    def doExit(self):
        self.df.setWidget(self.df.B3, "disabled")
        self.df.focusField("T", 0, 1)
Пример #24
0
class bc1010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "args" in self.opts:
                self.tabcvt = False
                self.gentab = False
                self.newtab = True
                self.tab = self.opts["args"]
                self.df.loadEntry("T", 0, 0, data=self.tab)
                self.df.topf[0][0][1] = "OUI"
                self.df.topf[0][1][1] = "OUI"
                self.df.focusField("T", 0, 2)
            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, [
            "chglog", "bwlent", "bwlgme", "bwltab", "bwldrt", "bwlflm",
            "bwlflt", "memmst", "memkon", "memadd", "memcat"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            if self.sql.error == ["memmst", "memkon"]:
                self.memmst = False
            else:
                return
        else:
            self.memmst = True
        gc = GetCtl(self.opts["mf"])
        bwlctl = gc.getCtl("bwlctl", self.opts["conum"])
        if not bwlctl:
            return
        self.mlint = bwlctl["ctb_mlint"]
        self.samen = bwlctl["ctb_samen"]
        self.mscat = bwlctl["ctb_mscat"]
        self.mstart = bwlctl["ctb_mstart"]
        self.fstart = bwlctl["ctb_fstart"]
        self.nstart = bwlctl["ctb_nstart"]
        self.dbase = bwlctl["ctb_dbase"]
        self.order = bwlctl["ctb_order"]
        self.mixed = bwlctl["ctb_mixed"]
        self.fromad = bwlctl["ctb_emadd"]
        self.keys = (("bwltab", "btb_cono", "btb_tab"), ("bwldrt", "bdt_cono",
                                                         "bdt_tab"),
                     ("bwlent", "bce_cono", "bce_scod"), ("bwlflt", "bft_cono",
                                                          "bft_player"),
                     ("bwlgme", "bcg_cono", "bcg_scod"), ("bwldrt", "bdt_cono",
                                                          "bdt_team1"),
                     ("bwldrt", "bdt_cono",
                      "bdt_team2"), ("bwldrt", "bdt_cono", "bdt_team3"),
                     ("bwlflt", "bft_cono", "bft_skip"), ("bwlgme", "bcg_cono",
                                                          "bcg_ocod"))
        return True

    def mainProcess(self):
        tab = {
            "stype":
            "R",
            "tables": ("bwltab", ),
            "cols": [("btb_tab", "", 0, "Tab"),
                     ("btb_surname", "", 0, "Surname", "Y"),
                     ("btb_names", "", 0, "Names"),
                     ("btb_bsano", "", 0, "BSA-No")],
            "where": [("btb_cono", "=", self.opts["conum"])],
            "order":
            "btb_surname"
        }
        if self.mlint == "N":
            mlm = None
        else:
            tab["cols"].insert(3, ("btb_memno", "", 0, "Mem-No"))
            mlm = {
                "stype":
                "R",
                "tables": ("memmst", ),
                "cols":
                (("mlm_memno", "", 0,
                  "Mem-No"), ("mlm_oldno", "", 0,
                              "Old-No"), ("mlm_idnum", "", 0, "Identity-Numb"),
                 ("mlm_gender", "", 0, "G"), ("mlm_state", "", 0, "S"),
                 ("mlm_surname", "", 0, "Surname", "Y"), ("mlm_names", "", 0,
                                                          "Names", "F")),
                "where": [("mlm_cono", "=", self.opts["conum"])],
                "order":
                "mlm_surname, mlm_names"
            }
        r1s = (("Male", "M"), ("Female", "F"))
        if self.dbase == "R":
            r2s = (("None", "0"), )
        else:
            r2s = (("Skip", "4"), ("Third", "3"), ("Second", "2"), ("Lead",
                                                                    "1"))
        fld = [(("T", 0, 0,
                 0), "I@btb_tab", 0, "", "", "", "Y", self.doTab, tab, None,
                ("efld", ), None, "Note: Tab numbers Must be Unique."),
               [("T", 0, 1, 0), "I@btb_memno", 0, "", "", "", "N",
                self.doMember, mlm, self.doDelete, ("efld", )],
               (("T", 0, 2, 0), "I@btb_surname", 0, "", "", "", "N",
                self.doSurname, None, self.doDelete, ("notblank", )),
               (("T", 0, 3, 0), "I@btb_names", 0, "", "", "", "N",
                self.doNames, None, None, ("efld", )),
               (("T", 0, 4, 0), ("IRB", r1s), 0, "Gender", "", "M", "N",
                self.doGender, None, None, None),
               (("T", 0, 5, 0), "I@btb_add1", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 6, 0), "I@btb_add2", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 7, 0), "I@btb_add3", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 8, 0), "I@btb_pcod", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 9, 0), "I@btb_home", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 10, 0), "I@btb_work", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 11, 0), "I@btb_cell", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 12, 0), "I@btb_mail", 0, "", "", "", "N",
                self.doEmail, None, None, ("efld", )),
               (("T", 0, 13, 0), ("IRB", r2s), 0, "Position - Primary", "",
                "1", "N", self.doPos, None, self.doDelete, None),
               (("T", 0, 14, 0), "I@btb_rate1", 0, "", "", "", "N",
                self.doRate, None, None, ("efld", )),
               (("T", 0, 15, 0), ("IRB", r2s), 0, "Position - Mixed", "", "1",
                "N", self.doPos, None, None, None),
               (("T", 0, 16, 0), "I@btb_rate2", 0, "", "", "", "N", None, None,
                None, ("efld", )),
               (("T", 0, 17, 0), "I@btb_bsano", 0, "", "", "", "N", None, None,
                None, ("efld", ))]
        if self.mlint == "N":
            fld[1] = [("T", 0, 1, 0), "O@btb_memno", 0, ""]
        if self.mlint == "Y":
            but = []
        else:
            but = [("Import", None, self.doImport, 0, ("T", 0, 1),
                    (("T", 0, 2), ("T", 0, 3)),
                    "Import Tabs and/or Ratings from a CSV or XLS File.")]
        but.extend([("Accept", None, self.doEnd, 0, ("T", 0, 3), ("T", 0, 0),
                     "Accept All Fields and Continue"),
                    ("Convert", None, self.doConvert, 0, ("T", 0, 3),
                     ("T", 0, 4), "Convert a Visitor's Tab to a Member's Tab"),
                    ("Print", None, self.doPrint, 1, None, None)])
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               tops=False,
                               eflds=fld,
                               butt=but,
                               tend=tnd,
                               txit=txt,
                               clicks=self.doClick)

    def doClick(self, *opts):
        if self.df.col == 1:
            return
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def doTab(self, frt, pag, r, c, p, i, w):
        self.tab = w
        self.newvis = False
        self.tabcvt = False
        self.tabchg = False
        if not self.tab:
            if self.mlint == "Y" and self.samen == "Y":
                ok = askQuestion(self.opts["mf"].body,
                                 "New Tab",
                                 "Is this TAB for a Visitor",
                                 default="no")
                if ok == "no":
                    return "New Member, Please Create in Ledger"
                self.newvis = True
            self.gentab = True
            self.newtab = True
        else:
            self.gentab = False
            self.oldtab = self.sql.getRec("bwltab",
                                          where=[("btb_cono", "=",
                                                  self.opts["conum"]),
                                                 ("btb_tab", "=", self.tab)],
                                          limit=1)
            if not self.oldtab:
                self.newtab = True
            else:
                self.newtab = False
                for num, fld in enumerate(self.oldtab[1:-1]):
                    if num == 2:
                        self.snam = fld
                    elif num == 3:
                        self.fnam = fld
                    elif num == 4:
                        self.gender = fld
                    elif num in (13, 15):
                        fld = str(fld)
                        if num == 13:
                            self.pos1 = fld
                    self.df.loadEntry(frt, pag, num, data=fld)
        if self.tab and self.mlint == "Y":
            if self.oldtab:
                memno = self.oldtab[self.sql.bwltab_col.index("btb_memno")]
            elif self.tab < self.nstart and self.samen == "Y":
                memno = self.tab
            else:
                memno = 0
        else:
            memno = 0
        if memno:
            chk = self.doLoadMember(memno)
            if chk:
                return chk
            if self.dbase == "R":
                return "sk13"
            return "sk12"
        if self.newvis or self.tab >= self.nstart:
            return "sk1"

    def doMember(self, frt, pag, r, c, p, i, w):
        if w:
            if self.newtab or not self.oldtab[2]:
                chk = self.sql.getRec("bwltab",
                                      where=[("btb_cono", "=",
                                              self.opts["conum"]),
                                             ("btb_memno", "=", w)],
                                      limit=1)
                if chk:
                    return "Member Already Has a TAB"
            chk = self.doLoadMember(w)
            if chk:
                return chk
            if self.newtab and not self.tab:
                chk = self.getNextTab()
                if not chk:
                    return "Invalid Membership Number"
            if self.dbase == "R":
                return "sk12"
            return "sk11"
        elif self.tab and self.tab < self.nstart and self.mlint == "Y":
            return "Invalid Membership Number"

    def doLoadMember(self, memno):
        # Check member
        acc = self.sql.getRec("memmst",
                              cols=["mlm_surname", "mlm_names", "mlm_gender"],
                              where=[("mlm_cono", "=", self.opts["conum"]),
                                     ("mlm_memno", "=", memno)],
                              limit=1)
        if not acc:
            return "Member %s Does Not Exist" % memno
        # Check category
        if self.mscat:
            cat = self.sql.getRec("memcat",
                                  where=[("mlc_cono", "=", self.opts["conum"]),
                                         ("mlc_memno", "=", memno),
                                         ("mlc_type", "=", "C"),
                                         ("mlc_code", "=", self.mscat)],
                                  limit=1)
            if not cat:
                return "Member %s is Not in the Bowls Category" % memno
        self.snam = acc[0]
        self.fnam = acc[1]
        self.gender = acc[2]
        self.df.loadEntry("T", 0, 1, data=memno)
        self.df.loadEntry("T", 0, 2, data=self.snam)
        self.df.loadEntry("T", 0, 3, data=self.fnam)
        self.df.loadEntry("T", 0, 4, data=self.gender)
        for typ in ("A", "P"):
            ad = self.sql.getRec(
                "memadd",
                cols=["mla_add1", "mla_add2", "mla_add3", "mla_code"],
                where=[("mla_cono", "=", self.opts["conum"]),
                       ("mla_memno", "=", memno), ("mla_type", "=", typ)],
                limit=1)
            if ad:
                break
        if ad:
            self.df.loadEntry("T", 0, 5, data=ad[0])
            self.df.loadEntry("T", 0, 6, data=ad[1])
            self.df.loadEntry("T", 0, 7, data=ad[2])
            self.df.loadEntry("T", 0, 8, data=ad[3])
        for num, cod in enumerate((1, 2, 3, 5)):
            kk = self.sql.getRec("memkon",
                                 cols=["mlk_detail"],
                                 where=[("mlk_cono", "=", self.opts["conum"]),
                                        ("mlk_memno", "=", memno),
                                        ("mlk_code", "=", cod)],
                                 limit=1)
            if kk:
                self.df.loadEntry("T", 0, num + 9, data=kk[0])

    def doSurname(self, frt, pag, r, c, p, i, w):
        self.sname = w

    def doNames(self, frt, pag, r, c, p, i, w):
        if self.newtab:
            chk = self.sql.getRec("bwltab",
                                  where=[("btb_cono", "=", self.opts["conum"]),
                                         ("btb_surname", "=", self.sname,
                                          "and", "btb_names", "=", w)],
                                  limit=1)
            if chk:
                tab = chk[self.sql.bwltab_col.index("btb_tab")]
                self.doTab(frt, pag, 0, 1, 0, 0, tab)
                return "ff3"
            if self.mstart < self.fstart and self.tab >= self.fstart:
                self.df.loadEntry(frt, pag, p + 1, data="F")
            elif self.fstart < self.mstart and self.tab < self.mstart:
                self.df.loadEntry(frt, pag, p + 1, data="F")
            return
        if self.sname != self.snam or w != self.fnam:
            but = [("Amendment", "A"), ("Re-Issue", "R"), ("Neither", "N")]
            ok = askChoice(self.opts["mf"].body,
                           "Name Change",
                           "Please Select the Reason for the Name Change",
                           butt=but,
                           default="Neither")
            if ok == "N":
                return "ff3"
            if ok == "R":
                self.tabchg = True
                for x in range(1, 15):
                    self.df.clearEntry(frt, pag, c + x)

    def doGender(self, frt, pag, r, c, p, i, w):
        self.gender = w
        if self.gentab:
            chk = self.getNextTab()
            if not chk:
                return "ff2|Invalid Membership Number"
        if self.tab < self.nstart:
            if self.mstart < self.fstart:
                if self.gender == "M" and self.tab >= self.fstart:
                    return "ff5|Invalid Gender for Tab Number"
                elif self.gender == "F" and self.tab < self.fstart:
                    return "ff5|Invalid Gender for Tab Number"
            else:
                if self.gender == "F" and self.tab >= self.mstart:
                    return "ff5|Invalid Gender for Tab Number"
                elif self.gender == "M" and self.tab < self.mstart:
                    return "ff5|Invalid Gender for Tab Number"

    def doEmail(self, frt, pag, r, c, p, i, w):
        if self.dbase in ("C", "P") and self.df.t_work[0][0][13] == "0":
            self.df.t_work[0][0][13] = "1"
        if self.dbase == "R":
            self.pos1 = "0"
            self.df.loadEntry(frt, pag, p + 1, data="")
            self.df.loadEntry(frt, pag, p + 1, data="")
            return "sk1"

    def doPos(self, frt, pag, r, c, p, i, w):
        if p == 13:
            self.pos1 = w
            self.df.loadEntry(frt, pag, p + 2, data=w)
        if self.dbase == "P":
            self.df.loadEntry(frt, pag, p + 1, data="")
            if p == 13:
                self.df.loadEntry(frt, pag, p + 3, data="")
            if self.mixed == "N":
                return "sk3"
            else:
                return "sk1"

    def doRate(self, frt, pag, r, c, p, i, w):
        self.df.loadEntry(frt, pag, p + 1, data=self.pos1)
        self.df.loadEntry(frt, pag, p + 2, data=w)
        if self.dbase == "R":
            self.df.loadEntry(frt, pag, p + 1, data="")
            if self.mixed == "N":
                return "sk2"
            else:
                return "sk1"
        if self.mixed == "N":
            return "sk2"

    def getNextTab(self):
        if self.newvis:
            ok = "yes"
        else:
            ok = askQuestion(self.opts["mf"].body,
                             "Type",
                             "Is this TAB for a Visitor",
                             default="no")
        if ok == "no":
            if self.samen == "Y":
                return
            if self.gender == "M":
                start = self.mstart
                if self.mstart < self.fstart:
                    last = self.fstart
                else:
                    last = self.nstart
            else:
                start = self.fstart
                if self.mstart < self.fstart:
                    last = self.nstart
                else:
                    last = self.mstart
        else:
            start = self.nstart
            last = 900000
        self.tab = getNextCode(self.sql,
                               "bwltab",
                               "btb_tab",
                               where=[("btb_cono", "=", self.opts["conum"])],
                               start=start,
                               last=last)
        self.df.loadEntry("T", 0, 0, data=self.tab)
        return True

    def doDelete(self):
        if self.newtab:
            return
        error = False
        for key in self.keys:
            if key[0] == "bwltab":
                continue
            chk = self.sql.getRec(tables=key[0],
                                  where=[(key[1], "=", self.opts["conum"]),
                                         (key[2], "=", self.tab)],
                                  limit=1)
            if chk:
                error = True
                break
        if error:
            if self.tab < self.nstart:
                # Member
                ok = askQuestion(self.opts["mf"].body,
                                 "Convert",
                                 "Convert this Member to a Visitor",
                                 default="yes")
                if ok == "no":
                    return "Not Deleted nor Converted"
                tab = getNextCode(self.sql,
                                  "bwltab",
                                  "btb_tab",
                                  where=[("btb_cono", "=", self.opts["conum"])
                                         ],
                                  start=self.nstart,
                                  last=900000)
                for key in self.keys:
                    self.sql.updRec(key[0],
                                    cols=[key[2]],
                                    data=[tab],
                                    where=[(key[1], "=", self.opts["conum"]),
                                           (key[2], "=", self.tab)])
            else:
                # Visitor
                chk = self.sql.getRec("bwlent",
                                      where=[("bce_cono", "=",
                                              self.opts["conum"]),
                                             ("bce_scod", "=", self.tab)])
                if chk:
                    return "There is History for this Player, Not Deleted"
                self.sql.delRec("bwltab",
                                where=[("btb_cono", "=", self.opts["conum"]),
                                       ("btb_tab", "=", self.tab)])
        else:
            self.sql.delRec("bwltab",
                            where=[("btb_cono", "=", self.opts["conum"]),
                                   ("btb_tab", "=", self.tab)])
        self.opts["mf"].dbm.commitDbase()

    def doConvert(self):
        titl = "Enter Member's Tab Number"
        ent = SimpleDialog(parent=self.df.window,
                           title=titl,
                           cols=(("a", "Tab Number          ", 6, "UI",
                                  "Tab"), ))
        ent.sframe.wait_window()
        try:
            self.merge = False
            if self.gender == "M":
                start = self.mstart
                if self.mstart < self.fstart:
                    last = self.fstart - 1
                else:
                    last = self.nstart - 1
            else:
                start = self.fstart
                if self.mstart < self.fstart:
                    last = self.nstart - 1
                else:
                    last = self.mstart - 1
            tab = ent.data[0]
            if not tab:
                tab = getNextCode(self.sql,
                                  "bwltab",
                                  "btb_tab",
                                  where=[("btb_cono", "=", self.opts["conum"])
                                         ],
                                  start=start,
                                  last=last)
            if tab < start or tab > last:
                showInfo(self.opts["mf"].body, "Error",
                         "Invalid Tab Number for Gender")
                raise Exception
            chk = self.sql.getRec("bwltab",
                                  where=[("btb_cono", "=", self.opts["conum"]),
                                         ("btb_tab", "=", tab)],
                                  limit=1)
            if chk:
                ok = askQuestion(
                    self.opts["mf"].body, "Invalid",
                    "This Tab is Already Allocated, Do You Want to Merge?")
                if ok == "no":
                    raise Exception
                self.merge = True
            self.tabcvt = True
            self.old = self.tab
            self.tab = tab
            self.df.loadEntry(self.df.frt, self.df.pag, 0, data=self.tab)
            self.df.focusField(self.df.frt, self.df.pag, 6)
        except:
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doPrint(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        if self.mlint == "Y":
            self.colsd = [["Membership Number", "N", "btb_memno"]]
        else:
            self.colsd = []
        self.colsd.extend([["Surname & Initials", "Y", "name"],
                           ["Surname", "N", "btb_surname"],
                           ["First Names", "N", "btb_names"],
                           ["Gender", "N", "btb_gender"],
                           ["Address", "N", "address"],
                           ["Telephone - Home", "N", "btb_home"],
                           ["Telephone - Work", "N", "btb_work"],
                           ["Telephone - Cell", "N", "btb_cell"],
                           ["Email Address", "N", "btb_mail"],
                           ["Ratings", "N", "ratings"],
                           ["BSA Number", "N", "btb_bsano"],
                           ["Order", "T", "order"]])
        r1s = (("Members", "M"), ("Guests", "G"), ("All", "A"))
        r2s = (("Males", "M"), ("Females", "F"), ("All", "A"))
        r3s = (("Yes", "Y"), ("No", "N"))
        r4s = (("Tab", "T"), ("Surname", "S"), ("Rating", "R"))
        fld = [(("T", 0, 0, 0), ("IRB", r1s), 0, "Tab Group", "", "M", "Y",
                self.doCGroup, None, None, None),
               (("T", 0, 1, 0), ("IRB", r2s), 0, "Gender", "", "A", "Y",
                self.doCGender, None, None, None)]
        idx = 1
        for dat in self.colsd:
            idx += 1
            if dat == self.colsd[-1]:
                rb = r4s
            else:
                rb = r3s
            fld.append((("T", 0, idx, 0), ("IRB", rb), 0, dat[0], "", dat[1],
                        "N", self.doCField, None, None, None))
        tnd = ((self.doCEnd, "Y"), )
        txt = (self.doCExit, )
        self.pr = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"),
                               mail=("Y", "Y"))
        self.pr.mstFrame.wait_window()
        if self.cols:
            cols = []
            dic = self.sql.bwltab_dic
            for col in self.cols:
                if col == "name":
                    cols.append(["name", "NA", 30, "Name"])
                elif col == "address":
                    cols.append([
                        "btb_add1", dic["btb_add1"][2], dic["btb_add1"][3],
                        dic["btb_add1"][5]
                    ])
                    cols.append([
                        "btb_add2", dic["btb_add2"][2], dic["btb_add2"][3],
                        dic["btb_add2"][5]
                    ])
                    cols.append([
                        "btb_add3", dic["btb_add3"][2], dic["btb_add3"][3],
                        dic["btb_add3"][5]
                    ])
                    cols.append([
                        "btb_pcod", dic["btb_pcod"][2], dic["btb_pcod"][3],
                        dic["btb_pcod"][5]
                    ])
                elif col == "ratings":
                    if self.dbase == "P":
                        cols.append([
                            "btb_pos1", dic["btb_pos1"][2], dic["btb_pos1"][3],
                            dic["btb_pos1"][5]
                        ])
                        cols.append([
                            "btb_pos2", dic["btb_pos2"][2], dic["btb_pos2"][3],
                            dic["btb_pos2"][5]
                        ])
                    elif self.dbase == "R":
                        cols.append([
                            "btb_rate1", dic["btb_rate1"][2],
                            dic["btb_rate1"][3], dic["btb_rate1"][5]
                        ])
                        cols.append([
                            "btb_rate2", dic["btb_rate2"][2],
                            dic["btb_rate2"][3], dic["btb_rate2"][5]
                        ])
                    else:
                        cols.append([
                            "btb_pos1", dic["btb_pos1"][2], dic["btb_pos1"][3],
                            dic["btb_pos1"][5]
                        ])
                        cols.append([
                            "btb_rate1", dic["btb_rate1"][2],
                            dic["btb_rate1"][3], dic["btb_rate1"][5]
                        ])
                        cols.append([
                            "btb_pos2", dic["btb_pos2"][2], dic["btb_pos2"][3],
                            dic["btb_pos2"][5]
                        ])
                        cols.append([
                            "btb_rate2", dic["btb_rate2"][2],
                            dic["btb_rate2"][3], dic["btb_rate2"][5]
                        ])
                else:
                    cols.append([col, dic[col][2], dic[col][3], dic[col][5]])
            whr = [("btb_cono", "=", self.opts["conum"])]
            if self.cgroup == "M":
                whr.append(("btb_tab", "<", self.nstart))
            elif self.cgroup == "G":
                whr.append(("btb_tab", ">=", self.nstart))
            if self.cgender in ("F", "M"):
                whr.append(("btb_gender", "=", self.cgender))
            if self.odr == "T":
                odr = "btb_tab"
            elif self.odr == "S":
                odr = "btb_surname, btb_names"
            else:
                odr = "btb_pos1 desc, btb_rate1 desc, btb_surname, btb_names"
            recs = self.sql.getRec("bwltab", where=whr, order=odr)
            data = []
            btc = self.sql.bwltab_col
            for rec in recs:
                dat = []
                for col in self.cols:
                    if col == "name":
                        snam = rec[btc.index("btb_surname")]
                        fnam = rec[btc.index("btb_names")]
                        if fnam:
                            fnam = fnam.split()
                            for num, nam in enumerate(fnam):
                                if not num:
                                    init = nam[0].upper()
                                else:
                                    init = "%s %s" % (init, nam[0].upper())
                            dat.append("%s, %s" % (snam, init))
                        else:
                            dat.append(snam)
                    elif col == "address":
                        dat.append(rec[btc.index("btb_add1")])
                        dat.append(rec[btc.index("btb_add2")])
                        dat.append(rec[btc.index("btb_add3")])
                        dat.append(rec[btc.index("btb_pcod")])
                    elif col == "ratings":
                        if self.dbase == "P":
                            dat.append(rec[btc.index("btb_pos1")])
                            dat.append(rec[btc.index("btb_pos2")])
                        elif self.dbase == "R":
                            dat.append(rec[btc.index("btb_rate1")])
                            dat.append(rec[btc.index("btb_rate2")])
                        else:
                            dat.append(rec[btc.index("btb_pos1")])
                            dat.append(rec[btc.index("btb_rate1")])
                            dat.append(rec[btc.index("btb_pos2")])
                            dat.append(rec[btc.index("btb_rate2")])
                    else:
                        dat.append(rec[btc.index(col)])
                data.append(dat)
            tit = "Tabs Lising for"
            if self.cgroup == "A":
                tit = "%s Members and Guests" % tit
            elif self.cgroup == "M":
                tit = "%s Members Only" % tit
            else:
                tit = "%s Guests Only" % tit
            if self.cgender == "A":
                tit = "%s (All Genders)" % tit
            elif self.cgender == "M":
                tit = "%s (Males Only)" % tit
            else:
                tit = "%s (Females Only)" % tit
            RepPrt(self.opts["mf"],
                   name=self.__class__.__name__,
                   conum=self.opts["conum"],
                   conam=self.opts["conam"],
                   heads=[tit],
                   ttype="D",
                   tables=data,
                   cols=cols,
                   repprt=self.pr.repprt,
                   repeml=self.pr.repeml,
                   fromad=self.fromad)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.window.focus_force()
        self.df.focusField("T", 0, 1)

    def doCGroup(self, frt, pag, r, c, p, i, w):
        self.cgroup = w

    def doCGender(self, frt, pag, r, c, p, i, w):
        self.cgender = w

    def doCField(self, frt, pag, r, c, p, i, w):
        if self.mlint == "N":
            idx = 2
        else:
            idx = 3
        if p == idx and w == "Y":
            self.pr.loadEntry(frt, pag, p + 1, data="N")
            self.pr.loadEntry(frt, pag, p + 2, data="N")
            return "sk2"

    def doCEnd(self):
        self.pr.closeProcess()
        self.cols = ["btb_tab"]
        if self.pr.repeml[0] == "N":
            end = -2
        else:
            end = -4
        for num, dat in enumerate(self.pr.t_work[0][0][2:end]):
            if dat == "Y":
                self.cols.append(self.colsd[num][2])
            elif dat in ("T", "S", "R"):
                self.odr = dat

    def doCExit(self):
        self.cols = []
        self.pr.closeProcess()

    def doEnd(self):
        if self.tabcvt:
            # Conversion to Member
            for key in self.keys:
                if key[0] == "bwltab" and self.merge:
                    self.sql.delRec(key[0],
                                    where=[(key[1], "=", self.opts["conum"]),
                                           (key[2], "=", self.old)])
                    continue
                self.sql.updRec(key[0],
                                cols=[key[2]],
                                data=[self.tab],
                                where=[(key[1], "=", self.opts["conum"]),
                                       (key[2], "=", self.old)])
        # Continue
        cols = []
        for x in range(18):
            cols.append(x)
        if self.dbase == "R":
            cols.remove(13)
            cols.remove(15)
        flds = ("T", 0, cols)
        frt, pag, col, mes = self.df.doCheckFields(flds)
        if mes:
            self.df.focusField(frt, pag, (col + 1), err=mes)
            return
        tabdat = [self.opts["conum"]] + self.df.t_work[0][0]
        if self.newtab:
            self.sql.insRec("bwltab", data=tabdat)
        elif self.tabchg:
            tabdat.append("")
            self.doTabChg(tabdat)
        elif tabdat != self.oldtab[:len(tabdat)]:
            col = self.sql.bwltab_col
            tabdat.append(self.oldtab[col.index("btb_xflag")])
            self.sql.updRec("bwltab",
                            data=tabdat,
                            where=[("btb_cono", "=", self.opts["conum"]),
                                   ("btb_tab", "=", self.tab)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.oldtab):
                if dat != tabdat[num]:
                    self.sql.insRec(
                        "chglog",
                        data=[
                            "bwltab", "U",
                            "%03i%06s" % (self.opts["conum"], self.tab),
                            col[num], dte, self.opts["capnm"],
                            str(dat),
                            str(tabdat[num]), "", 0
                        ])
        self.opts["mf"].dbm.commitDbase()
        if "args" in self.opts:
            self.doExit()
        else:
            self.df.focusField("T", 0, 1)

    def doTabChg(self, tabdat):
        code = getNextCode(self.sql,
                           "bwltab",
                           "btb_tab",
                           where=[("btb_cono", "=", self.opts["conum"])],
                           start=self.nstart,
                           last=900000)
        tables = (("bwldrt", "bdt_cono", "bdt_tab", "bdt_team1", "bdt_team2",
                   "bdt_team3"), ("bwlent", "bce_cono", "bce_scod"),
                  ("bwlflm", "bfm_cono", "bfm_captain"),
                  ("bwlflt", "bft_cono", "bft_skip", "bft_player"),
                  ("bwlgme", "bcg_cono", "bcg_scod",
                   "bcg_ocod"), ("bwltab", "btb_cono", "btb_tab"))
        for tab in tables:
            for col in tab[2:]:
                self.sql.updRec(tab[0],
                                cols=[col],
                                data=[code],
                                where=[(tab[1], "=", self.opts["conum"]),
                                       (col, "=", self.tab)])
        self.sql.insRec("bwltab", data=tabdat)

    def doImport(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        tit = ("Import Details", )
        r1s = (("Ratings Only", "R"), ("All Fields", "A"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Details", "", "R", "N",
                self.doImpDet, None, None, None), )
        self.ip = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=((self.doImpEnd, "y"), ),
                               txit=(self.doImpExit, ))
        self.ip.mstFrame.wait_window()
        # Populate
        if self.impdet is None:
            self.df.setWidget(self.df.mstFrame, state="show")
            self.df.enableButtonsTags(state=state)
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)
            return
        fi = FileImport(self.opts["mf"], imptab="bwltab", impskp=self.impskp)
        sp = ProgressBar(self.opts["mf"].body,
                         typ="Importing Ratings",
                         mxs=len(fi.impdat))
        err = None
        for num, line in enumerate(fi.impdat):
            sp.displayProgress(num)
            if self.mixed == "N":
                line.extend([0, ""])
            chk = self.sql.getRec("bwltab",
                                  where=[("btb_cono", "=", self.opts["conum"]),
                                         ("btb_tab", "=", line[0])],
                                  limit=1)
            if not chk:
                if self.impdet == "R":
                    err = "%s %s Does Not Exist" % (fi.impcol[0][0], line[0])
                    break
                line.insert(0, self.opts["conum"])
                if self.mlint == "N":
                    line.insert(2, 0)
                self.sql.insRec("bwltab", data=line)
            else:
                tmp = ["btb_pos1", "btb_rate1", "btb_pos2", "btb_rate2"]
                if self.impdet == "R":
                    cols = tmp
                else:
                    cols = [
                        "btb_surname", "btb_names", "btb_gender", "btb_add1",
                        "btb_add2", "btb_add3", "btb_pcod", "btb_home",
                        "btb_work", "btb_cell", "btb_mail"
                    ] + tmp + ["btb_bsano"]
                self.sql.updRec("bwltab",
                                cols=cols,
                                data=line[1:],
                                where=[("btb_cono", "=", self.opts["conum"]),
                                       ("btb_tab", "=", line[0])])
        sp.closeProgress()
        if err:
            err = "Line %s: %s" % ((num + 1), err)
            showError(
                self.opts["mf"].body, "Import Error", """%s

Please Correct your Import File and then Try Again.""" % err)
            self.opts["mf"].dbm.rollbackDbase()
        else:
            self.opts["mf"].dbm.commitDbase()
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doImpDet(self, frt, pag, r, c, p, i, w):
        self.impdet = w

    def doImpEnd(self):
        self.impskp = ["btb_cono"]
        if self.mlint == "N":
            self.impskp.append("btb_memno")
        if self.impdet == "R":
            self.impskp.extend([
                "btb_surname", "btb_names", "btb_gender", "btb_add1",
                "btb_add2", "btb_add3", "btb_pcod", "btb_home", "btb_work",
                "btb_cell", "btb_mail", "btb_bsano"
            ])
        if self.mixed == "N":
            self.impskp.extend(["btb_pos2", "btb_rate2"])
        self.impskp.append("btb_xflag")
        self.ip.closeProcess()

    def doImpExit(self):
        self.impdet = None
        self.ip.closeProcess()

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()
Пример #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()
Пример #26
0
class st1010(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, [
            "ctlvmf", "ctlrep", "drschn", "drsmst", "genmst", "slsiv1",
            "slsiv2", "strgrp", "strloc", "strmf1", "strmf2", "strgmu",
            "strcmu", "strprc", "strrcp", "struoi", "strtrn", "strpot",
            "strvar", "slsiv3", "chglog"
        ],
                       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.glint = strctl["cts_glint"]
        self.locs = strctl["cts_locs"]
        self.plevs = strctl["cts_plevs"]
        self.automu = strctl["cts_automu"]
        self.drsctl = gc.getCtl("drsctl", self.opts["conum"], error=False)
        if not self.drsctl:
            self.chains = "N"
        else:
            self.chains = self.drsctl["ctd_chain"]
        return True

    def mainProcess(self):
        gpm = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        stm = {
            "stype":
            "R",
            "tables": ("strmf1", ),
            "cols":
            (("st1_group", "", 0, "Grp"), ("st1_code", "", 0, "Product Code"),
             ("st1_type", "", 0, "T"), ("st1_desc", "", 0, "Description",
                                        "Y")),
            "where": [("st1_cono", "=", self.opts["conum"]),
                      ("st1_type", "<>", "X")],
            "whera": [],
            "index":
            1
        }
        loc = {
            "stype":
            "R",
            "tables": ("strloc", ),
            "cols":
            (("srl_loc", "", 0, "L"), ("srl_desc", "", 0, "Description", "Y")),
            "where": [("srl_cono", "=", self.opts["conum"])]
        }
        unm = {
            "stype":
            "R",
            "tables": ("struoi", ),
            "cols": (("unm_unit", "", 0, "Unit"), ("unm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("unm_cono", "=", self.opts["conum"])]
        }
        drc = {
            "stype": "R",
            "tables": ("drschn", ),
            "cols":
            (("chm_chain", "", 0, "Num"), ("chm_name", "", 0, "Name", "Y")),
            "where": [("chm_cono", "=", self.opts["conum"])]
        }
        drm = {
            "stype":
            "R",
            "tables": ("drsmst", ),
            "cols":
            (("drm_acno", "", 0, "Acc-Num"), ("drm_name", "", 0, "Name", "Y"),
             ("drm_add1", "", 0, "Address Line 1"))
        }
        if self.chains == "Y":
            drm["where"] = [("drm_cono", "=", self.opts["conum"]),
                            ("drm_stat", "<>", "X")]
            drm["whera"] = [["T", "drm_chain", 10]]
        else:
            drm["where"] = [("drm_cono", "=", self.opts["conum"]),
                            ("drm_chain", "=", 0), ("drm_stat", "<>", "X")]
        vtm = {
            "stype":
            "R",
            "tables": ("ctlvmf", ),
            "cols": (("vtm_code", "", 0, "C"), ("vtm_desc", "", 0,
                                                "Description", "Y")),
            "where": [("vtm_cono", "=", self.opts["conum"])]
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_cono", "=", self.opts["conum"])]
        }
        tag = (("Basic-_A", None, ("T", 0, 0),
                ("T", 0, 1)), ("Basic-_B", None, ("T", 0, 0), ("T", 0, 1)),
               ("Recipes", self.doReadLoadRecipe, None, ("T", 0, 1)))
        r1s = (("Normal", "N"), ("Recipe", "R"))
        r2s = (("Average", "A"), ("Standard", "S"), ("None", "N"))
        r3s = (("Manual", "M"), ("Automatic", "A"), ("Zero", "N"))
        self.fld = [(("T", 0, 0, 0), "IUA", 3, "Group", "Product Group", "",
                     "Y", self.doGroup, gpm, None, ("notblank", )),
                    (("T", 0, 0, 0), "INA", 20, "Code", "Product Code", "",
                     "N", self.doCode, stm, None, ("notblank", )),
                    (("T", 0, 0, 0), "IUA", 1, "Loc", "Location", "1", "N",
                     self.doLoc, loc, None, ("notblank", )),
                    (("T", 0, 0, 0), "ONA", 30, ""),
                    (("T", 1, 0, 0), ("IRB", r1s), 0, "Type of Item", "", "N",
                     "N", self.doType, None, None, None),
                    (("T", 1, 1, 0), "INA", 30, "Description", "", "", "N",
                     None, None, self.doDelete, ("notblank", )),
                    (("T", 1, 2, 0), "INA", 10, "Unit of Issue", "", "", "N",
                     self.doUoi, unm, None, ("notblank", )),
                    (("T", 1, 2, 0), "ONA", 30, ""),
                    (("T", 1, 3, 0), ("IRB", r2s), 0, "Cost Price Indicator",
                     "", "A", "N", self.doValInd, None, None, None),
                    (("T", 1, 4, 0), "IUA", 1, "VAT Code", "", "", "N",
                     self.doVat, vtm, None, ("notblank", )),
                    (("T", 1, 4, 0), "ONA", 30, ""),
                    (("T", 1, 5, 0), "IUI", 3, "Exclusive Chainstore", "", "",
                     "N", self.doChnExcl, drc, None, ("efld", )),
                    (("T", 1, 5, 0), "ONA", 30, ""),
                    (("T", 1, 6, 0), "INA", 7, "Exclusive Account", "", "",
                     "N", self.doAccExcl, drm, None, ("efld", )),
                    (("T", 1, 6, 0), "ONA", 30, ""),
                    (("T", 1, 7, 0), "IUI", 7, "Sales Code", "", "", "N",
                     self.doSales, glm, None, ("efld", )),
                    (("T", 1, 7, 0), "ONA", 30, ""),
                    (("T", 1, 8, 0), "IUI", 7, "COS Code", "", "", "N",
                     self.doCos, glm, None, ("efld", )),
                    (("T", 1, 8, 0), "ONA", 30, ""),
                    (("T", 2, 0, 0), "IUA", 8, "Bin Number", "", "", "N", None,
                     None, self.doDelete, ("efld", )),
                    (("T", 2, 1, 0), ("IRB", r3s), 0, "Re-Order Indicator", "",
                     "A", "N", self.doReord, None, None, None),
                    (("T", 2, 2, 0), "IUI", 7, "Re-Order Level", "", "", "N",
                     None, None, None, ("efld", )),
                    (("T", 2, 3, 0), "IUI", 7, "Re-Order Quantity", "", "",
                     "N", None, None, None, ("efld", ))]
        if self.automu in ("A", "L"):
            self.fld.append(
                (("T", 2, 4, 0), "IUD", 6.2, "Percentabge Markup Lv1", "", "",
                 "N", None, None, None, ("efld", )))
            for x in range(1, self.plevs):
                self.fld.append((("T", 2, 4, 0), "IUD", 6.2, "Lv%s" % (x + 1),
                                 "", "", "N", None, None, None, ("efld", )))
        self.fld.extend([(("C", 3, 0, 0), "INA", 3, "Grp", "Product Group",
                          "r", "N", self.doRecGrp, gpm, None, None),
                         (("C", 3, 0,
                           1), "INA", 20, "Product-Code", "Product Code", "",
                          "N", self.doRecCod, stm, None, None),
                         (("C", 3, 0, 2), "ONA", 30, "Description"),
                         (("C", 3, 0, 3), "IUD", 11.2, "Quantity", "", "", "N",
                          self.doRecQty, None, self.doDelRec, ("notzero", ))])
        but = (("Edit", None, self.doEditor, 0, ("C", 3, 1), None),
               ("Accept", None, self.doAccept, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Cancel", None, self.doCancel, 0, ("T", 0, 0),
                ("T", 0, 1)), ("Quit", None, self.doQuit, 1, None, None))
        tnd = ((self.doEnd, "N"), (self.doEnd, "N"), (self.doEnd, "Y"), None)
        txt = (self.doExit, self.doExit, self.doExit, self.doExit)
        cnd = (None, None, None, (self.doEnd, "N"))
        cxt = (None, None, None, self.doExit)
        self.df = TartanDialog(self.opts["mf"],
                               eflds=self.fld,
                               tags=tag,
                               butt=but,
                               tend=tnd,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               clicks=self.doClick)

    def doClick(self, *opts):
        if self.df.pag == 0 or not self.gtype:
            return
        if opts[0] == (1, 0) and not self.newcode:
            return
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def doGroup(self, frt, pag, r, c, p, i, w):
        self.grpacc = self.sql.getRec(
            "strgrp",
            cols=["gpm_vatcode", "gpm_sales", "gpm_costs"],
            where=[("gpm_cono", "=", self.opts["conum"]),
                   ("gpm_group", "=", w)],
            limit=1)
        if not self.grpacc:
            return "Invalid Group"
        self.group = w
        self.df.topf[0][1][8]["whera"] = [["T", "st1_group", 0, 0]]

    def doCode(self, frt, pag, r, c, p, i, w):
        self.code = w
        self.mups = [0, 0, 0, 0, 0]
        self.old1 = self.sql.getRec("strmf1",
                                    where=[("st1_cono", "=",
                                            self.opts["conum"]),
                                           ("st1_group", "=", self.group),
                                           ("st1_code", "=", w)],
                                    limit=1)
        if not self.old1:
            self.newcode = True
            self.gtype = None
        elif self.old1[3] == "X":
            return "Redundant Code"
        else:
            self.newcode = False
            d = 3
            for x in range(0, self.df.topq[1]):
                if x in (3, 6, 8, 10, 12, 14):
                    continue
                if x == 0:
                    self.gtype = self.old1[d]
                self.df.loadEntry("T", 1, x, data=self.old1[d])
                if x == 2:
                    get = self.getUoi(self.old1[d])
                    if get:
                        self.df.loadEntry("T", 1, x + 1, data=get[0])
                if x == 5:
                    get = self.getVat(self.old1[d])
                    if get:
                        self.df.loadEntry("T", 1, x + 1, data=get[0])
                if x == 7:
                    get = self.getChnExcl(self.old1[d])
                    if get:
                        self.df.loadEntry("T", 1, x + 1, data=get[0])
                if x == 9:
                    get = self.getAccExcl(self.old1[d])
                    if get:
                        self.df.loadEntry("T", 1, x + 1, data=get[0])
                if self.glint == "Y" and x in (11, 13):
                    get = self.getGenDes(self.old1[d])
                    if get:
                        self.df.loadEntry("T", 1, x + 1, data=get[0])
                d += 1
        if self.locs == "N":
            self.loc = "1"
            self.df.loadEntry("T", 0, 2, data=self.loc)
            err = self.checkLoc()
            if err:
                return err
            return "sk1"

    def doLoc(self, frt, pag, r, c, p, i, w):
        if w == 0:
            return "Invalid Location"
        self.loc = w
        err = self.checkLoc()
        if err:
            return err

    def checkLoc(self):
        acc = self.sql.getRec("strloc",
                              cols=["srl_desc"],
                              where=[("srl_cono", "=", self.opts["conum"]),
                                     ("srl_loc", "=", self.loc)],
                              limit=1)
        if not acc:
            return "Invalid Location Code"
        else:
            self.df.loadEntry("T", 0, 3, data=acc[0])
        self.old2 = self.sql.getRec("strmf2",
                                    where=[("st2_cono", "=",
                                            self.opts["conum"]),
                                           ("st2_group", "=", self.group),
                                           ("st2_code", "=", self.code),
                                           ("st2_loc", "=", self.loc)],
                                    limit=1)
        if not self.old2:
            ok = askQuestion(self.opts["mf"].body, "New Location",
                "This location does not exist for this product. " \
                "Are you sure that you want to create it?")
            if ok == "yes":
                self.newloc = "Y"
            else:
                return "Rejected Location"
        if not self.old2:
            self.newloc = "Y"
        else:
            self.newloc = "N"
            d = 3
            for x in range(0, 4):
                d = d + 1
                self.df.loadEntry("T", 2, x, data=self.old2[d])
            if self.automu in ("A", "L"):
                for y in range(self.plevs):
                    mup = getMarkup(self.sql, self.opts["conum"], self.group,
                                    self.code, self.loc, y + 1)
                    self.df.loadEntry("T", 2, 4 + y, data=mup)
                    self.mups[y] = mup

    def doType(self, frt, pag, r, c, p, i, w):
        self.gtype = w
        if self.gtype == "R":
            self.df.enableTag(2)
        else:
            self.df.disableTag(2)

    def doUoi(self, frt, pag, r, c, p, i, w):
        acc = self.getUoi(w)
        if not acc:
            return "Invalid UOI Record"
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])

    def doValInd(self, frt, pag, r, c, p, i, w):
        self.df.topf[1][5][5] = self.grpacc[0]

    def doVat(self, frt, pag, r, c, p, i, w):
        acc = self.getVat(w)
        if not acc:
            return "Invalid VAT Record"
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        if not self.drsctl:
            self.chain = 0
            self.df.loadEntry(frt, pag, p + 1, data=0)
            self.df.loadEntry(frt, pag, p + 1, data="")
            self.df.loadEntry(frt, pag, p + 1, data="")
            self.df.loadEntry(frt, pag, p + 1, data="")
            if self.glint == "N":
                return "sk9"
            else:
                return "sk4"

    def doChnExcl(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.getChnExcl(w)
            if not acc:
                return "Invalid Chainstore"
            self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        self.chain = w

    def doAccExcl(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.getAccExcl(w)
            if not acc:
                return "Invalid Debtors Account"
            self.df.loadEntry(frt, pag, p + 1, data=acc[0])
        if self.glint == "N":
            return "sk5"
        if self.newcode:
            self.df.loadEntry(frt, pag, p + 2, data=self.grpacc[1])
            if self.grpacc[1]:
                acc = self.getGenDes(self.grpacc[1])
                if not acc:
                    return "Invalid Sales Code"
                self.df.loadEntry(frt, pag, p + 3, data=acc[0])
            self.df.loadEntry(frt, pag, p + 4, data=self.grpacc[2])
            if self.grpacc[2]:
                acc = self.getGenDes(self.grpacc[2])
                if not acc:
                    return "Invalid C.O.S. Code"
                self.df.loadEntry(frt, pag, p + 5, data=acc[0])

    def doSales(self, frt, pag, r, c, p, i, w):
        acc = self.getGenDes(w)
        if not acc:
            return "Invalid Sales Account"
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])

    def doCos(self, frt, pag, r, c, p, i, w):
        acc = self.getGenDes(w)
        if not acc:
            return "Invalid COS Account"
        self.df.loadEntry(frt, pag, p + 1, data=acc[0])

    def doReord(self, frt, pag, r, c, p, i, w):
        if w == "N":
            self.df.loadEntry(frt, pag, p + 1, data=0)
            self.df.loadEntry(frt, pag, p + 2, data=0)
            return "sk2"

    def getUoi(self, dat):
        acc = self.sql.getRec("struoi",
                              cols=["unm_desc"],
                              where=[("unm_cono", "=", self.opts["conum"]),
                                     ("unm_unit", "=", dat)],
                              limit=1)
        return acc

    def getVat(self, dat):
        acc = self.sql.getRec("ctlvmf",
                              cols=["vtm_desc"],
                              where=[("vtm_cono", "=", self.opts["conum"]),
                                     ("vtm_code", "=", dat)],
                              limit=1)
        return acc

    def getChnExcl(self, dat):
        self.chain = dat
        if dat:
            acc = self.sql.getRec("drschn",
                                  cols=["chm_name"],
                                  where=[("chm_cono", "=", self.opts["conum"]),
                                         ("chm_chain", "=", dat)],
                                  limit=1)
            return acc

    def getAccExcl(self, dat):
        if dat:
            acc = self.sql.getRec("drsmst",
                                  cols=["drm_name"],
                                  where=[("drm_cono", "=", self.opts["conum"]),
                                         ("drm_chain", "=", self.chain),
                                         ("drm_acno", "=", dat),
                                         ("drm_stat", "<>", "X")],
                                  limit=1)
            return acc

    def getGenDes(self, dat):
        if dat:
            acc = self.sql.getRec("genmst",
                                  cols=["glm_desc"],
                                  where=[("glm_cono", "=", self.opts["conum"]),
                                         ("glm_acno", "=", dat)],
                                  limit=1)
            return acc

    def doRecGrp(self, frt, pag, r, c, p, i, w):
        self.rgroup = 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.df.topf[0][1][8]["whera"] = [["C", "st1_group", 0, 3]]

    def doRecCod(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("strmf1",
                              cols=["st1_type", "st1_desc"],
                              where=[("st1_cono", "=", self.opts["conum"]),
                                     ("st1_group", "=", self.rgroup),
                                     ("st1_code", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        if acc[0] == "R":
            return "Invalid Type (Recipe)"
        self.df.loadEntry(frt, pag, p + 1, data=acc[1])
        acc = self.sql.getRec("strmf2",
                              cols=["st2_bin"],
                              where=[("st2_cono", "=", self.opts["conum"]),
                                     ("st2_group", "=", self.rgroup),
                                     ("st2_code", "=", w),
                                     ("st2_loc", "=", self.loc)],
                              limit=1)
        if not acc:
            return "Invalid Code (2)"
        self.rcode = w
        acc = self.sql.getRec("strrcp",
                              cols=["srr_rqty"],
                              where=[("srr_cono", "=", self.opts["conum"]),
                                     ("srr_group", "=", self.group),
                                     ("srr_code", "=", self.code),
                                     ("srr_loc", "=", self.loc),
                                     ("srr_rgroup", "=", self.rgroup),
                                     ("srr_rcode", "=", self.rcode)],
                              limit=1)
        if acc:
            self.newrec = "n"
            self.df.loadEntry(frt, pag, p + 2, data=acc[0])
        else:
            self.newrec = "y"

    def doRecQty(self, frt, pag, r, c, p, i, w):
        self.rqty = w

    def doEditor(self):
        if self.df.pag != 3:
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)
            return
        # Display recipe items and allow editing of details
        data = self.sql.getRec(
            tables=["strrcp", "strmf1"],
            cols=["srr_rgroup", "srr_rcode", "st1_desc", "srr_rqty"],
            where=[("srr_cono", "=", self.opts["conum"]),
                   ("srr_group", "=", self.group),
                   ("srr_code", "=", self.code), ("srr_loc", "=", self.loc),
                   ("st1_cono=srr_cono", ), ("st1_group=srr_rgroup", ),
                   ("st1_code=srr_rcode", )])
        if data:
            titl = "Recipe Items"
            head = ("Grp", "Product-Code", "Description", "Quantity")
            lin = {
                "stype": "C",
                "titl": titl,
                "head": head,
                "typs": (("NA", 3), ("NA", 20), ("NA", 30), ("SD", 10.2)),
                "data": data
            }
            state = self.df.disableButtonsTags()
            self.opts["mf"].updateStatus("Select a Product to Edit")
            chg = self.df.selChoice(lin)
            if chg and chg.selection:
                self.change = chg.selection
                self.doChgChanges()
            self.df.enableButtonsTags(state=state)
            self.df.focusField("C", 3, self.df.col)

    def doChgChanges(self):
        tit = ("Change Items", )
        gpm = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        stm = {
            "stype":
            "R",
            "tables": ("strmf1", ),
            "cols":
            (("st1_group", "", 0, "Grp"), ("st1_code", "", 0, "Product Code"),
             ("st1_type", "", 0, "T"), ("st1_desc", "", 0, "Description",
                                        "Y")),
            "where": [("st1_cono", "=", self.opts["conum"])],
            "whera": [],
            "index":
            1
        }
        fld = ((("T", 0, 0, 0), "INA", 3, "Group", "Product Group", "", "N",
                self.doChgGrp, gpm, None, ('notblank', )),
               (("T", 0, 1, 0), "INA", 20, "Code", "Product Code", "", "N",
                self.doChgCod, stm, None,
                ('notblank', )), (("T", 0, 2, 0), "ONA", 30, "Description"),
               (("T", 0, 3, 0), "ISD", 10.2, "Quantity", "", "", "N",
                self.doChgQty, None, None, ('notzero', )))
        but = [["Delete", None, self.doChgDel, 1, None, None]]
        self.cg = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               butt=but,
                               tend=((self.doChgEnd, "n"), ),
                               txit=(self.doChgExit, ))
        self.cg.loadEntry("T", 0, 0, data=self.change[0])
        self.cg.loadEntry("T", 0, 1, data=self.change[1])
        self.cg.loadEntry("T", 0, 2, data=self.change[2])
        self.cg.loadEntry("T", 0, 3, data=self.change[3])
        self.cg.focusField("T", 0, 1, clr=False)
        self.cg.mstFrame.wait_window()

    def doChgGrp(self, frt, pag, r, c, p, i, 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.rgroup = w
        self.cg.topf[0][1][8]["whera"] = [["T", "st1_group", 0, 0]]

    def doChgCod(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("strmf1",
                              cols=["st1_type", "st1_desc"],
                              where=[("st1_cono", "=", self.opts["conum"]),
                                     ("st1_group", "=", self.rgroup),
                                     ("st1_code", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Code"
        if acc[0] != "N":
            return "Invalid Type"
        cnt = self.sql.getRec("strrcp",
                              cols=["count(*)"],
                              where=[("srr_cono", "=", self.opts["conum"]),
                                     ("srr_group", "=", self.rgroup),
                                     ("srr_code", "=", w)],
                              limit=1)
        if cnt[0]:
            return "Product Already In Recipe"
        self.rcode = w
        self.cg.loadEntry("T", 0, 2, data=acc[1])

    def doChgQty(self, frt, pag, r, c, p, i, w):
        self.rqty = w

    def doChgDel(self):
        self.sql.delRec("strrcp",
                        where=[("srr_cono", "=", self.opts["conum"]),
                               ("srr_group", "=", self.group),
                               ("srr_code", "=", self.code),
                               ("srr_loc", "=", self.loc),
                               ("srr_rgroup", "=", self.change[0]),
                               ("srr_rcode", "=", self.change[1])])
        self.doReadLoadRecipe()
        self.doChgExit()

    def doChgEnd(self):
        self.sql.updRec("strrcp",
                        cols=["srr_rgroup", "srr_rcode", "srr_rqty"],
                        data=[self.rgroup, self.rcode, self.rqty],
                        where=[("srr_cono", "=", self.opts["conum"]),
                               ("srr_group", "=", self.group),
                               ("srr_code", "=", self.loc),
                               ("srr_loc", "=", self.loc),
                               ("srr_rgroup", "=", self.change[0]),
                               ("srr_rcode", "=", self.change[1])])
        self.doReadLoadRecipe()
        self.doChgExit()

    def doChgExit(self):
        self.cg.closeProcess()

    def doDelete(self):
        trn = self.sql.getRec("strpot",
                              cols=["count(*)"],
                              where=[("pot_cono", "=", self.opts["conum"]),
                                     ("pot_group", "=", self.group),
                                     ("pot_code", "=", self.code)],
                              limit=1)
        if trn[0]:
            return "Purchase Orders Exist, Not Deleted"
        trn = self.sql.getRec("strtrn",
                              cols=["count(*)"],
                              where=[("stt_cono", "=", self.opts["conum"]),
                                     ("stt_group", "=", self.group),
                                     ("stt_code", "=", self.code),
                                     ("stt_loc", "=", self.loc)],
                              limit=1)
        if trn[0]:
            return "Stores Transactions Exist, Not Deleted"
        trn = self.sql.getRec("slsiv2",
                              cols=["count(*)"],
                              where=[("si2_cono", "=", self.opts["conum"]),
                                     ("si2_group", "=", self.group),
                                     ("si2_code", "=", self.code),
                                     ("si2_loc", "=", self.loc)],
                              limit=1)
        if trn[0]:
            return "Sales-2 Transactions Exist, Not Deleted"
        trn = self.sql.getRec("slsiv3",
                              cols=["count(*)"],
                              where=[("si3_cono", "=", self.opts["conum"]),
                                     ("si3_rgroup", "=", self.group),
                                     ("si3_rcode", "=", self.code)],
                              limit=1)
        if trn[0]:
            return "Sales-3 Transactions Exist, Not Deleted"
        self.sql.delRec("strmf2",
                        where=[("st2_cono", "=", self.opts["conum"]),
                               ("st2_group", "=", self.group),
                               ("st2_code", "=", self.code),
                               ("st2_loc", "=", self.loc)])
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        self.sql.insRec("chglog", data=["strmf2", "D", "%03i%-3s%-20s%-1s" % \
            (self.opts["conum"], self.group, self.code, self.loc), "", dte,
        self.opts["capnm"], "", "", "", 0])
        st2 = self.sql.getRec("strmf2",
                              cols=["count(*)"],
                              where=[("st2_cono", "=", self.opts["conum"]),
                                     ("st2_group", "=", self.group),
                                     ("st2_code", "=", self.code)],
                              limit=1)
        if not st2[0]:
            self.sql.delRec("strmf1",
                            where=[("st1_cono", "=", self.opts["conum"]),
                                   ("st1_group", "=", self.group),
                                   ("st1_code", "=", self.code)])
            self.sql.insRec("chglog", data=["strmf1", "D", "%03i%-3s%-20s" % \
                (self.opts["conum"], self.group, self.code), "", dte,
                self.opts["capnm"], "", "", "", 0])
        # Other Files
        self.sql.delRec("strcst",
                        where=[("stc_cono", "=", self.opts["conum"]),
                               ("stc_group", "=", self.group),
                               ("stc_code", "=", self.code),
                               ("stc_loc", "=", self.loc)])
        self.sql.delRec("strprc",
                        where=[("stp_cono", "=", self.opts["conum"]),
                               ("stp_group", "=", self.group),
                               ("stp_code", "=", self.code),
                               ("stp_loc", "=", self.loc)])
        self.sql.delRec("strrcp",
                        where=[("srr_cono", "=", self.opts["conum"]),
                               ("srr_group", "=", self.group),
                               ("srr_code", "=", self.code),
                               ("srr_loc", "=", self.loc)])
        self.sql.delRec("strrcp",
                        where=[("srr_cono", "=", self.opts["conum"]),
                               ("srr_loc", "=", self.loc),
                               ("srr_rgroup", "=", self.group),
                               ("srr_rcode", "=", self.code)])
        self.sql.delRec("strvar",
                        where=[("stv_cono", "=", self.opts["conum"]),
                               ("stv_group", "=", self.group),
                               ("stv_code", "=", self.code),
                               ("stv_loc", "=", self.loc)])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doDelRec(self):
        self.sql.delRec("strrcp",
                        where=[("srr_cono", "=", self.opts["conum"]),
                               ("srr_group", "=", self.group),
                               ("srr_code", "=", self.code),
                               ("srr_loc", "=", self.loc),
                               ("srr_rgroup", "=", self.rgroup),
                               ("srr_rcode", "=", self.rcode)])
        self.df.clearLine(2, focus=True)

    def doEnd(self):
        if self.df.frt == "T" and self.df.pag == 0:
            if self.newcode:
                self.df.focusField("T", 1, 1)
            else:
                if self.gtype == "R":
                    self.df.enableTag(2)
                self.df.skip[1] = [1]
                self.df.focusField("T", 1, 2, clr=False)
        elif self.df.frt == "T" and self.df.pag == 1:
            self.df.selPage("Basic-B")
        elif self.df.frt == "T" and self.df.pag == 2:
            if self.gtype == "R":
                self.df.selPage("Recipes")
            else:
                self.doEnder()
        elif self.df.frt == "C" and self.df.pag == 3:
            data = [
                self.opts["conum"], self.group, self.code, self.loc,
                self.rgroup, self.rcode, self.rqty
            ]
            if self.newrec == "y":
                self.sql.insRec("strrcp", data=data)
                self.df.advanceLine(3)
            else:
                whr = [("srr_cono", "=", self.opts["conum"]),
                       ("srr_group", "=", self.group),
                       ("srr_code", "=", self.code),
                       ("srr_loc", "=", self.loc),
                       ("srr_rgroup", "=", self.rgroup),
                       ("srr_rcode", "=", self.rcode)]
                self.sql.updRec("strrcp", data=data, where=whr)
                self.doReadLoadRecipe()

    def doEnder(self):
        data = [self.opts["conum"]]
        for x in range(0, 2):
            data.append(self.df.t_work[0][0][x])
        for x in range(0, len(self.df.t_work[1][0])):
            if x in (3, 6, 8, 10, 12, 14):
                continue
            data.append(self.df.t_work[1][0][x])
        if self.newcode:
            self.sql.insRec("strmf1", data=data)
        elif data != self.old1[:len(data)]:
            col = self.sql.strmf1_col
            data.append(self.old1[col.index("st1_xflag")])
            self.sql.updRec("strmf1",
                            data=data,
                            where=[("st1_cono", "=", self.opts["conum"]),
                                   ("st1_group", "=", self.group),
                                   ("st1_code", "=", self.code)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.old1):
                if dat != data[num]:
                    self.sql.insRec(
                        "chglog",
                        data=[
                            "strmf1", "U",
                            "%03i%-3s%-20s" %
                            (self.opts["conum"], self.group, self.code),
                            col[num], dte, self.opts["capnm"],
                            str(dat),
                            str(data[num]), "", 0
                        ])
        data = [self.opts["conum"], self.group, self.code, self.loc]
        for x in range(0, 4):
            data.append(self.df.t_work[2][0][x])
        if self.newloc == "Y":
            self.sql.insRec("strmf2", data=data)
        elif data != self.old2[:len(data)]:
            col = self.sql.strmf2_col
            data.append(self.old2[col.index("st2_xflag")])
            self.sql.updRec("strmf2",
                            data=data,
                            where=[("st2_cono", "=", self.opts["conum"]),
                                   ("st2_group", "=", self.group),
                                   ("st2_code", "=", self.code),
                                   ("st2_loc", "=", self.loc)])
            dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
            for num, dat in enumerate(self.old2):
                if dat != data[num]:
                    self.sql.insRec("chglog",
                                    data=[
                                        "strmf2", "U",
                                        "%03i%-3s%-20s%-1s" %
                                        (self.opts["conum"], self.group,
                                         self.code, self.loc), col[num], dte,
                                        self.opts["capnm"],
                                        str(dat),
                                        str(data[num]), "", 0
                                    ])
        self.sql.delRec("strcmu",
                        where=[("smc_cono", "=", self.opts["conum"]),
                               ("smc_group", "=", self.group),
                               ("smc_code", "=", self.code),
                               ("smc_loc", "=", self.loc)])
        for num, mup in enumerate(self.df.t_work[2][0][4:]):
            if mup and mup != self.mups[num]:
                self.sql.insRec("strcmu",
                                data=[
                                    self.opts["conum"], self.group, self.code,
                                    self.loc, num + 1, mup
                                ])
        self.opts["mf"].dbm.commitDbase()
        self.df.selPage("Basic-A")
        self.df.focusField("T", 0, 1)

    def doReadLoadRecipe(self):
        self.df.clearFrame("C", 3)
        self.df.focusField("C", 3, 1)
        rec = self.sql.getRec(
            tables=["strrcp", "strmf1"],
            cols=["srr_rgroup", "srr_rcode", "st1_desc", "srr_rqty"],
            where=[("srr_cono", "=", self.opts["conum"]),
                   ("srr_group", "=", self.group),
                   ("srr_code", "=", self.code), ("srr_loc", "=", self.loc),
                   ("st1_cono=srr_cono", ), ("st1_group=srr_rgroup", ),
                   ("st1_code=srr_rcode", )])
        if rec:
            mxs = (self.df.rows[3] - 1) * self.df.colq[3]
            for l, r in enumerate(rec):
                for i, d in enumerate(r):
                    c = l * self.df.colq[3]
                    if c > mxs:
                        c = mxs
                    self.df.loadEntry("C", 3, (c + i), data=d)
                self.df.advanceLine(3)

    def doExit(self):
        if self.df.frt == "T" and self.df.pag == 0:
            self.doQuit()
        elif self.df.frt == "T" and self.df.pag == 1:
            if self.newcode:
                self.df.focusField("T", 1, 1)
            else:
                self.df.skip[1] = [1]
                self.df.focusField("T", 1, 2, clr=False)
        elif self.df.frt == "T" and self.df.pag == 2:
            self.df.focusField("T", 2, 1)
        elif self.df.frt == "C" and self.df.pag == 3:
            if self.df.col == 1:
                self.df.focusField("C", 3, 1)
            else:
                self.doEnder()

    def doAccept(self):
        ok = "yes"
        for page in (1, 2):
            frt, pag, col, err = self.df.doCheckFields(("T", page, None))
            if err:
                ok = "no"
                if pag and pag != self.df.pag:
                    self.df.selPage(self.df.tags[pag - 1][0])
                self.df.focusField(frt, pag, (col + 1), err=err)
                break
        if ok == "yes":
            self.doEnder()

    def doQuit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.df.selPage("Basic-A")
        self.df.focusField("T", 0, 1)
Пример #27
0
class dr2020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Check for Valid Posting Routine
        if self.opts["rtn"] != 2:
            mes = "Invalid Routine %s" % str(self.opts["rtn"])
            showError(self.opts["mf"].body, "Control Error", mes)
            return
        # Setup SQL Object
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmst", "ctlvmf", "drschn", "drsmst", "drstrn", "genint",
            "genmst", "gentrn"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        # Check for Intercompany Facility
        if not self.sql.getRec("ctlmst",
                               cols=["count(*)"],
                               where=[("ctm_cono", "<>", self.opts["conum"])],
                               limit=1)[0]:
            self.incoac = False
        else:
            itg = self.sql.getRec("genint",
                                  cols=["cti_inco"],
                                  where=[("cti_cono", "=", self.opts["conum"])
                                         ])
            if itg:
                self.incoac = [self.opts["conum"]]
                [self.incoac.append(coy[0]) for coy in itg]
            else:
                self.incoac = False
        #
        self.gc = GetCtl(self.opts["mf"])
        drsctl = self.gc.getCtl("drsctl", self.opts["conum"])
        if not drsctl:
            return
        self.glint = drsctl["ctd_glint"]
        self.chains = drsctl["ctd_chain"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["drs_ctl", "vat_ctl", "dis_all"]
            if self.gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.drsctl = ctlctl["drs_ctl"]
            self.dis_all = ctlctl["dis_all"]
        self.batchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.allcoy = self.opts["conum"]
        ctlmst = self.gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        if self.chains == "N":
            self.chain = 0
        self.glt = 6
        self.agevar = tk.BooleanVar()
        self.agevar.set(False)
        return True

    def batchHeader(self):
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "DRS",
                          self.opts["rtn"],
                          glint=self.glint)
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return
        self.bh.batval = float(ASD(0) - ASD(self.bh.batval))

    def drawDialog(self):
        drc = {
            "stype": "R",
            "tables": ("drschn", ),
            "cols":
            (("chm_chain", "", 0, "Num"), ("chm_name", "", 0, "Name", "Y")),
            "where": [("chm_cono", "=", self.opts["conum"])]
        }
        drm = {
            "stype":
            "R",
            "tables": ("drsmst", ),
            "cols":
            (("drm_acno", "", 0, "Acc-Num"), ("drm_name", "", 0, "Name", "Y"),
             ("drm_add1", "", 0, "Address Line 1"))
        }
        if self.chains == "Y":
            drm["where"] = [("drm_cono", "=", self.opts["conum"])]
            drm["whera"] = [["C", "drm_chain", 0, 1]]
        else:
            drm["where"] = [("drm_cono", "=", self.opts["conum"]),
                            ("drm_chain", "=", 0)]
        drm["where"].append(("drm_stat", "<>", "X"))
        coy = {
            "stype": "R",
            "tables": ("ctlmst", ),
            "cols":
            (("ctm_cono", "", 0, "Coy"), ("ctm_name", "", 0, "Name", "Y"))
        }
        viw = {
            "stype":
            "R",
            "tables": ("drstrn", ),
            "cols": (("drt_chain", "", 0, ""), ("drt_acno", "", 0, ""),
                     ("drt_ref1", "", 0, ""), ("drt_trdt", "", 0, ""),
                     ("drt_tramt", "", 0, ""), ("drt_taxamt", "", 0, "")),
            "where": [("drt_cono", "=", self.opts["conum"]),
                      ("drt_type", "=", self.opts["rtn"]),
                      ("drt_batch", "=", self.bh.batno)],
            "order":
            "drt_seq"
        }
        tag = (("Deposit", None, None, None, False), ("Allocation", None, None,
                                                      None, False))
        fld = [(("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2, "Value"),
               (("C", 1, 0, 0), "INa", 9, "Reference", "Reference Number One",
                "i", "Y", self.doRef1, None, None, ("efld", )),
               (("C", 1, 0, 1), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 2), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, ("notzero", )),
               (("C", 1, 0, 3), "INA", (30), "Details", "Deposit Details", "",
                "N", self.doTrnDet, None, None, None),
               (("T", 2, 0, 0), "OSD", 13.2, "Unallocated Balance"),
               [("C", 2, 0, 0), "OUI", 3, "Coy", "Company Number",
                self.opts["conum"], "N", self.doCoyNum, coy, None,
                ("notzero", )],
               [("C", 2, 0, 1), "IUI", 3, "Chn", "Chain Store", "r", "N",
                self.doChain, drc, None, ("efld", )],
               (("C", 2, 0, 2), "INA", 7, "Acc-Num", "Account Number", "r",
                "N", self.doDrsAcc, drm, None, ("notblank", )),
               (("C", 2, 0, 3), "ONA", 30, "Name"),
               (("C", 2, 0, 4), "ISD", 13.2, "Receipt", "Receipt Amount", "",
                "N", self.doAllAmt, None, None, ("efld", )),
               (("C", 2, 0, 5), "ISD", 13.2, "Discount", "Discount Amount", "",
                "N", self.doDisAmt, None, None, ("efld", ), None,
                "Discount Amount to be Added to the Receipt Amount"),
               (("C", 2, 0, 6), "OSD", 13.2, "Total-Amount")]
        if self.glint == "Y" and self.incoac:
            fld[7][1] = "IUI"
        if self.chains == "N":
            fld[8][1] = "OUI"
            but = [("View Entries", viw, None, 1, ("C", 2, 3), ("C", 2, 4),
                    "View Batch Transactions", 1),
                   ("Interrogate", None, self.queryDrs, 0, ("C", 2, 3),
                    ("C", 2, 0), "Interrogate Debtors Accounts", 1),
                   ("Maintain", None, self.maintainDrs, 0, ("C", 2, 3),
                    ("C", 2, 4), "Maintain Debtors Accounts", 1),
                   ("Canc_el", None, self.doCancel, 0, ("C", 2, 1),
                    ("C", 1, 1), "", 1)]
        else:
            but = [("View Entries", viw, None, 0, ("C", 2, 3), ("C", 2, 4),
                    "View Batch Transactions", 1),
                   ("Interrogate", None, self.queryDrs, 0, ("C", 2, 2),
                    ("C", 2, 0), "Interrogate Debtors Accounts", 1),
                   ("Maintain", None, self.maintainDrs, 0, ("C", 2, 2),
                    ("C", 2, 3), "Maintain Debtors Accounts", 1),
                   ("Canc_el", None, self.doCancel, 0, ("C", 2, 1),
                    ("C", 1, 1), "", 1)]
        but.extend((
                ("Age _Normal",None,self.doAgeNormal,0,None,None,
                    "Only Show Unallocated Transactions",2),
                ("Age _History",None,self.doAgeHistory,0,None,None,
                    "Show All Transactions, Including Already Allocated",2),
                ("Age _Automatic",None,self.doAgeAuto,0,None,None,
                    "Automatically Allocate the Amount Starting With the "\
                    "Oldest Unallocated One",2),
                ("Age _Current",None,self.doAgeCurrent,0,None,None,
                    "Leave the Transaction Unallocated",2)))
        txt = (None, None, None)
        cnd = [None, (self.endPage1, "y"), (self.endPage2, "y")]
        cxt = [None, self.exitPage1, self.exitPage2]
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tags=tag,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 1, 1)

    def doRef1(self, frt, pag, r, c, p, i, w):
        if not w:
            trns = self.sql.getRec("drstrn",
                                   cols=["drt_ref1"],
                                   where=[("drt_cono", "=",
                                           self.opts["conum"]),
                                          ("drt_ref1", "like", "R________")],
                                   order="drt_ref1 desc")
            auto = False
            for trn in trns:
                try:
                    w = "R%08i" % (int(trn[0][1:]) + 1)
                    auto = True
                    break
                except:
                    pass
            if not auto:
                w = "R00000001"
            self.df.loadEntry(frt, pag, p, data=w)
        chk = self.sql.getRec("drstrn",
                              cols=["drt_acno"],
                              where=[("drt_cono", "=", self.opts["conum"]),
                                     ("drt_type", "=", self.opts["rtn"]),
                                     ("drt_ref1", "=", w)])
        if chk:
            return "A Transaction with this Reference Already Exists"
        self.ref1 = w

    def doTrnDat(self, frt, pag, r, c, p, i, w):
        if w < self.opts["period"][1][0] or w > self.opts["period"][2][0]:
            return "Invalid Date, Not in Financial Period"
        if self.bh.multi == "N" and int(w / 100) > self.bh.curdt:
            return "Invalid Date, After Batch Period"
        self.trndat = w

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w

    def doTrnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w
        self.allocated = float(0.00)

    def endPage1(self):
        self.agecan = False
        self.batupd = False
        self.updateTables1()
        self.updateBatch()
        self.allocated = float(0.0)
        self.df.selPage("Allocation")
        self.df.loadEntry("T", 2, 0, data=self.trnamt)
        self.df.focusField("C", 2, 1)

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trndat / 100)
        else:
            self.curdt = self.bh.curdt
        if self.glint == "Y":
            # General Ledger Control Transaction (Bank)
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                    self.glt, self.ref1, self.bh.batno, self.trnamt, 0.00,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)

    def exitPage1(self):
        self.df.closeProcess()
        self.bh.doBatchTotal()
        self.opts["mf"].closeLoop()

    def doCoyNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("ctlmst",
                              cols=["ctm_name"],
                              where=[("ctm_cono", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Company, Missing"
        if self.incoac and w not in self.incoac:
            return "Invalid Company, No Intercompany Record 1"
        if w != self.opts["conum"]:
            acc = self.sql.getRec("genint",
                                  where=[("cti_cono", "=", w),
                                         ("cti_inco", "=", self.opts["conum"])
                                         ],
                                  limit=1)
            if not acc:
                return "Invalid Company, No Intercompany Record 2"
        self.allcoy = w

    def doChain(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drschn",
                                  cols=["chm_chain"],
                                  where=[("chm_cono", "=", self.allcoy),
                                         ("chm_chain", "=", w)],
                                  limit=1)
            if not acc:
                return "Invalid Chain Store"
        self.chain = w

    def doDrsAcc(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("drsmst",
                              cols=["drm_name", "drm_stat"],
                              where=[("drm_cono", "=", self.allcoy),
                                     ("drm_chain", "=", self.chain),
                                     ("drm_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account Number"
        if acc[1] == "X":
            return "Invalid Account, Redundant"
        self.dracno = w
        self.name = acc[0]
        self.df.loadEntry("C", pag, p + 1, data=self.name)
        self.allref = self.ref1
        while self.sql.getRec("drstrn",
                              cols=["drt_batch"],
                              where=[("drt_cono", "=", self.allcoy),
                                     ("drt_chain", "=", self.chain),
                                     ("drt_acno", "=", self.dracno),
                                     ("drt_type", "=", self.opts["rtn"]),
                                     ("drt_ref1", "=", self.allref)]):
            self.doGetAnotherRef()

    def doGetAnotherRef(self):
        tit = ("Duplicate Reference Number", )
        fld = ((("T", 0, 0, 0), "ONa", 9, "Old Reference", "", self.allref,
                "N", None, None, None, None),
               (("T", 0, 1, 0), "INa", 9, "New Reference", "", "", "N",
                self.doRefNew, None, None, ("notblank", )))
        tnd = ((self.doRefEnd, "n"), )
        txt = (self.doRefExit, )
        state = self.df.disableButtonsTags()
        self.tf = TartanDialog(self.opts["mf"],
                               title=tit,
                               tops=True,
                               eflds=fld,
                               tend=tnd,
                               txit=txt)
        self.tf.mstFrame.wait_window()
        self.df.enableButtonsTags(state=state)

    def doRefExit(self):
        self.tf.focusField("T", 0, 2)

    def doRefNew(self, frt, pag, r, c, p, i, w):
        self.allref = w

    def doRefEnd(self):
        self.tf.closeProcess()

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if w == 0:
            self.allamt = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry(frt, pag, p, data=self.allamt)
        else:
            self.allamt = w

    def doDisAmt(self, frt, pag, r, c, p, i, w):
        if self.allamt < 0 and w > 0:
            ok = self.checkSign()
        elif self.allamt > 0 and w < 0:
            ok = self.checkSign()
        else:
            ok = "yes"
        if ok != "yes":
            return "Invalid Discount Amount (Sign Error)"
        self.disamt = w
        totamt = float(ASD(self.allamt) + ASD(self.disamt))
        self.df.loadEntry(frt, pag, p + 1, data=totamt)

    def checkSign(self):
        return askQuestion(self.opts["mf"].body, "Check Sign",
            "The Sign of the Discount Amount is not the same "\
            "as the Sign of the Receipt Amount, Is This Correct?")

    def endPage2(self):
        self.amt = float(ASD(0) - ASD(self.allamt))
        self.dis = float(ASD(0) - ASD(self.disamt))
        state = self.df.disableButtonsTags()
        self.opts["mf"].updateStatus("Choose an Ageing Option")
        for x in range(4, 8):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "normal")
        self.agevar.set(True)
        self.df.mstFrame.wait_variable(self.agevar)
        self.df.enableButtonsTags(state=state)
        if self.agecan:
            self.doCancel()
            return
        # Debtors Ledger Transaction
        data = [
            self.allcoy, self.chain, self.dracno, self.opts["rtn"],
            self.allref, self.bh.batno, self.trndat, "", self.amt, 0.00,
            self.curdt, self.trndet, "", "N", self.opts["capnm"], self.sysdtw,
            0
        ]
        self.sql.insRec("drstrn", data=data)
        if self.dis:
            data = [
                self.allcoy, self.chain, self.dracno, 6, self.allref,
                self.bh.batno, self.trndat, "", self.dis, 0.00, self.curdt,
                self.trndet, "", "N", self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("drstrn", data=data)
        self.allocated = float(ASD(self.allocated) + ASD(self.allamt))
        if self.glint == "Y":
            # General Ledger Control Transaction (Debtors)
            amt = float(ASD(self.amt) + ASD(self.dis))
            data = (self.allcoy, self.drsctl, self.curdt, self.trndat,
                    self.glt, self.allref, self.bh.batno, amt, 0.00,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)
            # General Ledger Control Transaction (Discount)
            if self.disamt:
                data = (self.allcoy, self.dis_all, self.curdt, self.trndat,
                        self.glt, self.allref, self.bh.batno, self.disamt,
                        0.00, self.trndet, "N", "", 0, self.opts["capnm"],
                        self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
            # General Ledger Transaction (Intercompany)
            if self.allcoy != self.opts["conum"]:
                # General Ledger Transaction (Intercompany From)
                acc = self.sql.getRec("genint",
                                      cols=["cti_acno"],
                                      where=[("cti_cono", "=",
                                              self.opts["conum"]),
                                             ("cti_inco", "=", self.allcoy)],
                                      limit=1)[0]
                data = (self.opts["conum"], acc, self.curdt, self.trndat,
                        self.glt, self.allref, self.bh.batno, self.amt, 0.00,
                        self.trndet, "N", "", 0, self.opts["capnm"],
                        self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
                # General Ledger Transaction (Intercompany To)
                acc = self.sql.getRec("genint",
                                      cols=["cti_acno"],
                                      where=[("cti_cono", "=", self.allcoy),
                                             ("cti_inco", "=",
                                              self.opts["conum"])],
                                      limit=1)[0]
                amt = float(ASD(0) - ASD(self.amt))
                data = (self.allcoy, acc, self.curdt, self.trndat, self.glt,
                        self.allref, self.bh.batno, amt, 0.00, self.trndet,
                        "N", "", 0, self.opts["capnm"], self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
        if self.allocated == self.trnamt:
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Deposit")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.trnamt) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def doAgeNormal(self):
        self.doAgeing("N")

    def doAgeHistory(self):
        self.doAgeing("H")

    def doAgeAuto(self):
        self.doAgeing("O")

    def doAgeCurrent(self):
        self.doAgeing("C")

    def doAgeing(self, atype):
        # Disable All Ageing Buttons
        for x in range(4, 8):
            wid = getattr(self.df, "B%s" % x)
            self.df.setWidget(wid, "disabled")
        self.opts["mf"].updateStatus("Select Transaction to Allocate Against")
        age = AgeAll(self.opts["mf"],
                     system="drs",
                     agetyp=atype,
                     agekey=[
                         self.allcoy, self.chain, self.dracno,
                         self.opts["rtn"], self.allref, self.curdt, self.amt,
                         self.dis
                     ])
        self.agecan = age.cancel
        self.agevar.set(False)

    def doCancel(self):
        if self.agecan:
            ok = "yes"
        else:
            ok = askQuestion(
                self.opts["mf"].body,
                head="Cancel",
                mess="Are You Certain You Want to Cancel This Entry?")
        if ok == "yes":
            self.opts["mf"].dbm.rollbackDbase()
            if self.batupd:
                self.updateBatch(rev=True)
            self.df.clearFrame("C", 2)
            self.df.selPage("Deposit")
            row = int((self.df.last[1][1] - 1) / self.df.colq[1])
            col = (row * self.df.colq[1]) + 1
            self.df.focusField("C", 1, col)

    def exitPage2(self):
        self.df.focusField("C", 2, self.df.col)

    def updateBatch(self, rev=False):
        if rev:
            self.bh.batqty = self.bh.batqty - 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.trnamt))
        else:
            self.batupd = True
            self.bh.batqty = self.bh.batqty + 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.trnamt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def queryDrs(self):
        callModule(self.opts["mf"],
                   self.df,
                   "dr4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])

    def maintainDrs(self):
        callModule(self.opts["mf"],
                   self.df,
                   "dr1010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])
Пример #28
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()
Пример #29
0
class stc320(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", "strgrp"],
                       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.glint = strctl["cts_glint"]
        return True

    def mainProcess(self):
        fld = ()
        tnd = ((self.doEnd, "Y"), )
        txt = (self.closeProcess, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("Y", "V"))

    def doEnd(self):
        heads = ["Product Groups Master Listing"]
        grps = self.sql.getRec("strgrp",
                               cols=[
                                   "gpm_group", "gpm_desc", "gpm_vatcode",
                                   "gpm_sales", "gpm_costs"
                               ],
                               where=[("gpm_cono", "=", self.opts["conum"])],
                               order="gpm_group")
        data = []
        for grp in grps:
            if self.glint == "Y":
                ac1 = self.getGenDesc(grp[3])
                if not ac1:
                    ac1 = [""]
                ac2 = self.getGenDesc(grp[4])
                if not ac2:
                    ac2 = [""]
            else:
                ac1 = ac2 = [""]
            gp = grp[:4]
            gp.extend([ac1[0], grp[4], ac2[0]])
            data.append(gp)
        cols = [["a", "UA", 3.0, "Grp"], ["b", "NA", 30.0, "Description"],
                ["c", "UA", 1.0, "V"], ["d", "UI", 7.0, "SLS-Acc"],
                ["e", "NA", 30.0, "Description"], ["f", "UI", 7.0, "COS-Acc"],
                ["g", "NA", 30.0, "Description"]]
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"],
               name=self.__class__.__name__,
               tables=data,
               heads=heads,
               cols=cols,
               conum=self.opts["conum"],
               conam=self.opts["conam"],
               ttype="D",
               repprt=self.df.repprt)
        self.df.enableButtonsTags(state=state)
        self.closeProcess()

    def getGenDesc(self, acc):
        des = self.sql.getRec("genmst",
                              cols=["glm_desc"],
                              where=[("glm_cono", "=", self.opts["conum"]),
                                     ("glm_acno", "=", acc)],
                              limit=1)
        return des

    def closeProcess(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Пример #30
0
class wg1010(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, ["ctldep", "chglog", "wagbal",
            "wagcap", "wagcod", "wagedc", "wagmst", "wagtf1", "wagtf2",
            "waglmf", "wagltf"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        return True

    def mainProcess(self):
        wgm = {
            "stype": "R",
            "tables": ("wagmst",),
            "cols": (
                ("wgm_empno", "", 0, "EmpNo"),
                ("wgm_sname", "", 0, "Surname", "Y"),
                ("wgm_fname", "", 0, "Names"),
                ("wgm_freq", "", 0, "F"),
                ("wgm_start", "", 0, "Start-Date"),
                ("wgm_term", "", 0, "Term-Date")),
            "where": [("wgm_cono", "=", self.opts["conum"])]}
        dep = {
            "stype": "R",
            "tables": ("ctldep",),
            "cols": (
                ("dep_code", "", 0, "Dep"),
                ("dep_name", "", 0, "Name", "Y")),
            "where": [("dep_cono", "=", self.opts["conum"])]}
        wec = {
            "stype": "R",
            "tables": ("wagedc",),
            "cols": (
                ("ced_code", "", 0, "Code"),
                ("ced_desc", "", 0, "Description", "Y")),
            "where": [
                ("ced_cono", "=", self.opts["conum"]),
                ("ced_type", "=", "E")]}
        wdc = {
            "stype": "R",
            "tables": ("wagedc",),
            "cols": (
                ("ced_code", "", 0, "Code"),
                ("ced_desc", "", 0, "Description", "Y")),
            "where": [
                ("ced_cono", "=", self.opts["conum"]),
                ("ced_type", "=", "D")]}
        r1s = (("Weekly","W"),("2xWeekly","F"),("Monthly   ","M"))
        r2s = (("Cash  ","C"),("Cheque  ","Q"),("Electronic","E"))
        r3s = (("Yes","Y"),("No","N"))
        r4s = (("Current","1"),("Transmission","2"),("Savings","3"))
        fld = (
            (("T",0,0,0),"IUI",5,"Emp-Num","Employee Number",
                "","Y",self.doEmpNum,wgm,None,("notzero",)),
            (("T",0,0,0),"IUI",3,"Department","",
                "","N",self.doDept,dep,None,None),
            (("T",0,0,0),"IUI",1,"Class","",
                "","N",None,None,None,None),
            (("T",1,0,0),"INA",30,"Surname","",
                "","N",None,None,None,("notblank",)),
            (("T",1,1,0),"INA",30,"Names","",
                "","N",None,None,None,("notblank",)),
            (("T",1,2,0),"ID1",10,"Date of Birth","",
                "","N",self.doDOB,None,None,("efld",)),
            (("T",1,3,0),"INA",13,"ID Number","",
                "","N",self.doIdNo,None,None,("idno",)),
            (("T",1,4,0),"INA",16,"Spouse Name","",
                "","N",None,None,None,None),
            (("T",1,5,0),"INA",13,"Spouse ID Number","",
                "","N",self.doIdNo,None,None,("idno",)),
            (("T",1,6,0),"INA",30,"Address Line 1","",
                "","N",None,None,None,("notblank",)),
            (("T",1,7,0),"INA",30,"Address Line 2","",
                "","N",None,None,None,None),
            (("T",1,8,0),"INA",30,"Address Line 3","",
                "","N",None,None,None,None),
            (("T",1,9,0),"INA",4,"Postal Code","",
                "","N",None,None,None,("notblank",)),
            (("T",1,10,0),"INA",16,"Telephone Number","",
                "","N",None,None,None,None),
            (("T",1,11,0),"ITX",50,"E-Mail Address","",
                "","N",None,None,None,("email",)),
            (("T",1,12,0),"ID1",10,"Start Date","",
                "","N",None,None,None,("efld",)),
            (("T",1,13,0),"IUD",10.2,"Salary/Rate","",
                "","N",None,None,None,("efld",)),
            (("T",1,14,0),("IRB",r1s),0,"Pay Freq","Pay Frequency",
                "M","N",None,None,None,None),
            (("T",1,15,0),("IRB",r2s),0,"Pay Type","",
                "E","N",self.doPayTyp,None,None,None),
            (("T",2,0,0),("IRB",r3s),0,"P.A.Y.E.","",
                "Y","N",None,None,None,None),
            (("T",2,1,0),"INA",16,"Tax Office","",
                "","N",None,None,None,None),
            (("T",2,2,0),"INA",10,"Tax Number","",
                "","N",None,None,None,None),
            (("T",2,3,0),"IUA",1,"Nature of Employee","",
                "A","N",None,None,None,("notblank",)),
            (("T",2,4,0),"IUI",9,"Reg Number","Registration Number",
                "","N",None,None,None,None),
            (("T",2,5,0),"IUA",1,"Voluntary Excess","",
                "N","N",None,None,None,None),
            (("T",2,6,0),"IUD",6.2,"Fixed Rate","",
                "","N",None,None,None,None),
            (("T",2,7,0),"INA",13,"Directive","",
                "","N",None,None,None,None),
            (("T",3,0,0),("IRB",r4s),0,"Account Type","Bank Account Type",
                "1","N",None,None,None,None),
            (("T",3,1,0),"INA",30,"Bank Name","",
                "","N",self.doBankNam,None,None,None),
            (("T",3,2,0),"IUI",8,"Branch Code","Bank Branch Code",
                "","N",self.doBankBch,None,None,None),
            (("T",3,3,0),"INA",16,"Account Number","Bank Account Number",
                "","N",self.doBankAcc,None,None,None),
            (("T",3,4,0),"INA",30,"Account Holder's Name","",
                "","N",self.doHolderNam,None,None,None),
            (("T",3,5,0),"IUI",1,"Holder's Relationship","",
                "","N",self.doHolderRel,None,None,None),
            (("C",4,0,0),"IUI",3,"Cod","Earnings Code",
                "","N",self.doEarnCod,wec,None,("efld",)),
            (("C",4,0,1),"ONA",30,"Description"),
            (("C",4,0,2),"ISD",13.2,"Amnt/Rate","Amount or Rate",
                "","N",self.doEarnAmt,None,self.doCodeDelete,("efld",)),
            (("C",5,0,0),"IUI",3,"Cod","Deduction Code",
                "","N",self.doDedCod,wdc,None,("efld",)),
            (("C",5,0,1),"ONA",30,"Description"),
            (("C",5,0,2),"ISD",13.2,"Amnt/Rate","Employees Amount or Rate",
                "","N",self.doDedEAmt,None,self.doCodeDelete,("efld",)),
            (("C",5,0,3),"ISD",13.2,"Amnt/Rate","Employers Amount or Rate",
                "","N",self.doDedRAmt,None,None,("efld",)),
            (("T",6,0,0),"ISD",13.2,"Balance-1","",
                "","N",None,None,None,("efld",)),
            (("T",6,1,0),"ISD",13.2,"Balance-2","",
                "","N",None,None,None,("efld",)),
            (("T",6,2,0),"ISD",13.2,"Balance-3","",
                "","N",None,None,None,("efld",)))
        tag = (
            ("General",None,("T",0,0),("T",0,1)),
            ("Tax",None,("T",0,0),("T",0,1)),
            ("Bank",None,("T",0,0),("T",0,1)),
            ("Earnings",None,("T",0,0),("T",0,1)),
            ("Deductions",None,("T",0,0),("T",0,1)),
            ("Balances",None,("T",0,0),("T",0,1)))
        tnd = (
            (self.doEnd, "n"),
            (self.doEnd, "n"),
            (self.doEnd, "n"),
            (self.doEnd, "n"),
            None,
            None,
            (self.doEnd, "y"))
        txt = (
            self.doExit,
            self.doExit,
            self.doExit,
            self.doExit,
            None,
            None,
            self.doExit)
        cnd = (
            None,
            None,
            None,
            None,
            (self.doEndEarn, "y"),
            (self.doEndDed, "y"),
            None)
        cxt = (
            None,
            None,
            None,
            None,
            self.doExit,
            self.doExit,
            None)
        but = (
            ("Accept",None,self.doAccept,0,("T",0,2),("T",0,1)),
            ("Print",None,self.doPrint,0,("T",0,2),("T",0,0)),
            ("Cancel",None,self.doCancel,0,("T",0,2),("T",0,0)),
            ("Quit",None,self.doCloseProcess,1,None,None))
        row = [0,0,0,0,15,15,0]
        self.df = TartanDialog(self.opts["mf"], eflds=fld, tags=tag,
            rows=row, tend=tnd, txit=txt, cend=cnd, cxit=cxt, butt=but,
            clicks=self.doClick)

    def doClick(self, *opts):
        if self.df.pag == 0:
            return
        self.df.focusField("T", opts[0][0], opts[0][1] + 1)

    def doEmpNum(self, frt, pag, r, c, p, i, w):
        self.empno = w
        self.oldm = self.sql.getRec("wagmst", where=[("wgm_cono", "=",
            self.opts["conum"]), ("wgm_empno", "=", self.empno)], limit=1)
        self.oldb = self.sql.getRec("wagbal", where=[("wbl_cono", "=",
            self.opts["conum"]), ("wbl_empno", "=", self.empno)],
            order="wbl_balno")
        if not self.oldm:
            self.new = True
            self.term = 0
            self.ptyp = ""
        else:
            self.new = False
            self.term = self.oldm[len(self.oldm)-1]
            d = 1
            for pg in range(0, self.df.pgs):
                for x in range(0, self.df.topq[pg]):
                    self.df.loadEntry("T", pg, x, data=self.oldm[d])
                    d = d + 1
            self.ptyp = self.df.t_work[1][0][15]
            self.doLoadEarnDed("E")
            self.doLoadEarnDed("D")
            if self.oldb:
                for b in self.oldb:
                    self.df.loadEntry("T", 6, b[2]-1, data=b[3])

    def doDept(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("ctldep", cols=["dep_name"],
            where=[("dep_cono", "=", self.opts["conum"]),
            ("dep_code", "=", w)], limit=1)
        if not acc:
            return "Invalid Department"
        self.dept = w

    def doDOB(self, frt, pag, r, c, p, i, w):
        self.dob = w

    def doIdNo(self, frt, pag, r, c, p, i, w):
        if p == 6:
            a = int(int(w) / 10000000)
            b = int(self.dob % 1000000)
            if a != b:
                return "ID Number Does Not Agree with Birth Date"

    def doPayTyp(self, frt, pag, r, c, p, i, w):
        self.ptyp = w

    def doBankNam(self, frt, pag, r, c, p, i, w):
        if self.ptyp == "E" and not w:
            return "Invalid Bank Name"

    def doBankBch(self, frt, pag, r, c, p, i, w):
        if self.ptyp == "E" and not w:
            return "Invalid Branch"

    def doBankAcc(self, frt, pag, r, c, p, i, w):
        if self.ptyp == "E" and not w:
            return "Invalid Account"

    def doHolderNam(self, frt, pag, r, c, p, i, w):
        self.holnam = w

    def doHolderRel(self, frt, pag, r, c, p, i, w):
        self.holrel = w

    def doEnd(self):
        if self.df.pag == 0:
            self.df.focusField("T", 1, 1)
        elif self.df.pag == 1:
            self.df.selPage("Tax")
            self.df.focusField("T", 2, 1)
        elif self.df.pag == 2:
            self.df.selPage("Bank")
            self.df.focusField("T", 3, 1)
        elif self.df.pag == 3:
            self.df.selPage("Earnings")
        elif self.df.pag == 6:
            self.doAccept()

    def doEarnCod(self, frt, pag, r, c, p, i, w):
        desc = self.sql.getRec("wagedc", cols=["ced_desc"],
            where=[("ced_cono", "=", self.opts["conum"]), ("ced_type", "=",
            "E"), ("ced_code", "=", w)], limit=1)
        if not desc:
            return "Invalid Code"
        self.code = w
        self.df.loadEntry(frt, pag, p+1, data=desc[0])
        code = self.sql.getRec("wagcod", cols=["wcd_eamt", "wcd_ramt"],
            where=[("wcd_cono", "=", self.opts["conum"]), ("wcd_empno", "=",
            self.empno), ("wcd_type", "=", "E"), ("wcd_code", "=", w)],
            limit=1)
        if not code:
            self.ncod = "y"
        else:
            self.ncod = "n"
            self.df.loadEntry(frt, pag, p+2, data=code[0])

    def doEarnAmt(self, frt, pag, r, c, p, i, w):
        self.eamt = w
        self.ramt = 0

    def doEndEarn(self):
        self.doEndCode("E")

    def doDedCod(self, frt, pag, r, c, p, i, w):
        desc = self.sql.getRec("wagedc", cols=["ced_desc"],
            where=[("ced_cono", "=", self.opts["conum"]), ("ced_type", "=",
            "D"), ("ced_code", "=", w)], limit=1)
        if not desc:
            return "Invalid Code"
        self.code = w
        self.df.loadEntry(frt, pag, p+1, data=desc[0])
        code = self.sql.getRec("wagcod", cols=["wcd_eamt", "wcd_ramt"],
            where=[("wcd_cono", "=", self.opts["conum"]), ("wcd_empno", "=",
            self.empno), ("wcd_type", "=", "D"), ("wcd_code", "=", w)],
            limit=1)
        if not code:
            self.ncod = "y"
        else:
            self.ncod = "n"
            self.df.loadEntry(frt, pag, p+2, data=code[0])
            self.df.loadEntry(frt, pag, p+3, data=code[1])

    def doDedEAmt(self, frt, pag, r, c, p, i, w):
        self.eamt = w

    def doDedRAmt(self, frt, pag, r, c, p, i, w):
        self.ramt = w

    def doEndDed(self):
        self.doEndCode("D")

    def doEndCode(self, rtype):
        if self.ncod == "y":
            self.sql.insRec("wagcod", data=[self.opts["conum"],
            self.empno, rtype, self.code, self.eamt, self.ramt])
        else:
            self.sql.updRec("wagcod", cols=["wcd_eamt", "wcd_ramt"],
                data=[self.eamt, self.ramt], where=[("wcd_cono", "=",
                self.opts["conum"]), ("wcd_empno", "=", self.empno),
                ("wcd_type", "=", rtype), ("wcd_code", "=", self.code)])
        self.doLoadEarnDed(rtype, focus=True)

    def doLoadEarnDed(self, rtype, focus=False):
        if rtype == "E":
            pag = 4
        else:
            pag = 5
        self.df.clearFrame("C", pag)
        codes = self.sql.getRec(tables=["wagcod", "wagedc"], cols=["wcd_code",
            "ced_desc", "wcd_eamt", "wcd_ramt"], where=[("wcd_cono", "=",
            self.opts["conum"]), ("wcd_empno", "=", self.empno), ("wcd_type",
            "=", rtype), ("ced_cono = wcd_cono",), ("ced_type = wcd_type",),
            ("ced_code = wcd_code",)])
        if not codes:
            return
        p = 0
        for cod in codes:
            for i, c in enumerate(cod):
                if rtype == "E" and i == 3:
                    continue
                self.df.loadEntry("C", pag, p, data=c)
                p = p + 1
        if focus:
            self.df.focusField("C", pag, p+1)
        else:
            self.df.last[pag][1] = p + 1

    def doCodeDelete(self):
        if self.df.pag == 4:
            rtype = "E"
        else:
            rtype = "D"
        code = self.df.c_work[self.df.pag][self.df.row][self.df.idx-2]
        self.sql.delRec("wagcod", where=[("wcd_cono", "=", self.opts["conum"]),
            ("wcd_empno", "=", self.empno), ("wcd_type", "=", rtype),
            ("wcd_code", "=", code)])
        self.doLoadEarnDed(rtype, focus=True)

    def doAccept(self):
        frt, pag, col, mes = self.df.doCheckFields(("T",0,None))
        if not mes:
            frt, pag, col, mes = self.df.doCheckFields(("T",1,None))
        if not mes:
            frt, pag, col, mes = self.df.doCheckFields(("T",2,None))
        if not mes and self.df.t_work[1][0][15] == "E":
            frt, pag, col, mes = self.df.doCheckFields(("T",3,None))
        if mes:
            if pag > 0 and pag != self.df.pag:
                if frt == "T":
                    self.df.last[pag][0] = col+1
                else:
                    self.df.last[pag][1] = col+1
                self.df.selPage(self.df.tags[pag - 1][0])
            self.df.focusField(frt, pag, (col+1), err=mes)
        else:
            data = [self.opts["conum"]]
            for p in range(0, self.df.pgs):
                for x in range(0, self.df.topq[p]):
                    data.append(self.df.t_work[p][0][x])
            data.append(self.term)
            if self.new:
                self.sql.insRec("wagmst", data=data)
                for b in range(3):
                    data = [self.opts["conum"], self.empno, b+1,
                        self.df.t_work[6][0][b], ""]
                    self.sql.insRec("wagbal", data=data)
            else:
                dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
                if data != self.oldm[:len(data)]:
                    col = self.sql.wagmst_col
                    data.append(self.oldm[col.index("wgm_xflag")])
                    self.sql.updRec("wagmst", data=data, where=[("wgm_cono",
                        "=", self.opts["conum"]), ("wgm_empno", "=",
                        self.empno)])
                    for num, dat in enumerate(self.oldm):
                        if dat != data[num]:
                            self.sql.insRec("chglog", data=["wagmst", "U",
                                "%03i%05i" % (self.opts["conum"], self.empno),
                                col[num], dte, self.opts["capnm"], str(dat),
                                str(data[num]), "", 0])
                for n, b in enumerate(self.df.t_work[6][0]):
                    lvl = n + 1
                    data = [self.opts["conum"], self.empno, lvl, b]
                    whr = [
                        ("wbl_cono", "=", self.opts["conum"]),
                        ("wbl_empno", "=", self.empno),
                        ("wbl_balno", "=", lvl)]
                    chk = self.sql.getRec("wagbal", where=whr, limit=1)
                    if not chk:
                        self.sql.insRec("wagbal", data=data)
                        continue
                    if data != self.oldb[n][:len(data)]:
                        col = self.sql.wagbal_col
                        data.append(self.oldb[n][col.index("wbl_xflag")])
                        self.sql.updRec("wagbal", data=data, where=whr)
                        for num, dat in enumerate(self.oldb[n]):
                            if dat != data[num]:
                                self.sql.insRec("chglog", data=["wagbal", "U",
                                    "%03i%05i%i" % (self.opts["conum"],
                                    self.empno, lvl), col[num], dte,
                                    self.opts["capnm"], str(dat),
                                    str(data[num]), "", 0])
            self.opts["mf"].dbm.commitDbase()
            self.df.last[0] = [0, 0]
            self.df.selPage("General")
            self.df.focusField("T", 0, 1)

    def doMainDelete(self):
        t = self.sql.getRec("wagtf1", cols=["count(*)"],
            where=[("wt1_cono", "=", self.opts["conum"]), ("wt1_empno", "=",
            self.empno)], limit=1)
        if t[0]:
            return "Transactions 1 Exist, Not Deleted"
        t = self.sql.getRec("wagtf2", cols=["count(*)"],
            where=[("wt2_cono", "=", self.opts["conum"]), ("wt2_empno=%s", "=",
            self.empno)], limit=1)
        if t[0]:
            return "Transactions 2 Exist, Not Deleted"
        t = self.sql.getRec("wagltf", cols=["count(*)"],
            where=[("wlt_cono", "=", self.opts["conum"]), ("wlt_empno", "=",
            self.empno)], limit=1)
        if t[0]:
            return "Loan Transactions Exist, Not Deleted"
        self.sql.delRec("wagbal", where=[("wbl_cono", "=", self.opts["conum"]),
            ("wbl_empno", "=", self.empno)])
        self.sql.delRec("wagcap", where=[("wcp_cono", "=", self.opts["conum"]),
            ("wcp_empno", "=", self.empno)])
        self.sql.delRec("wagcod", where=[("wcd_cono", "=", self.opts["conum"]),
            ("wcd_empno", "=", self.empno)])
        self.sql.delRec("waglmf", where=[("wlm_cono", "=", self.opts["conum"]),
            ("wlm_empno", "=", self.empno)])
        self.sql.delRec("wagmst", where=[("wgm_cono", "=", self.opts["conum"]),
            ("wgm_empno", "=", self.empno)])
        dte = int("%04i%02i%02i%02i%02i%02i" % time.localtime()[:-3])
        self.sql.insRec("chglog", data=["wagmst", "D", "%03i%05i" %
            (self.opts["conum"], self.empno), "", dte, self.opts["capnm"],
            "", "", "", 0])
        self.opts["mf"].dbm.commitDbase()
        self.df.focusField("T", 0, 1)

    def doPrint(self):
        tables = []
        for pag in range(0, (self.df.pgs+1)):
            for x in range(0, self.df.topq[pag]):
                lin = []
                lin.append(self.df.topf[pag][x][3])
                lin.append(self.df.t_disp[pag][0][x])
                tables.append(lin)
        heads = ["Salaries and Wages File Maintenance"]
        cols = [["a","NA",30.0,"Field Name"],
                ["b","NA",30.0,"Values"]]
        state = self.df.disableButtonsTags()
        RepPrt(self.opts["mf"], name=self.__class__.__name__, tables=tables,
            heads=heads, cols=cols, conum=self.opts["conum"],
            conam=self.opts["conam"], ttype="D")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doCancel(self):
        self.opts["mf"].dbm.rollbackDbase()
        self.df.last[0] = [0, 0]
        self.df.selPage("General")
        self.df.focusField("T", 0, 1)

    def doExit(self):
        if self.df.pag == 0:
            self.doCloseProcess()
        elif self.df.pag == 1:
            self.df.focusField("T", 0, 3)
        elif self.df.pag == 2:
            self.df.selPage("General")
        elif self.df.pag == 3:
            self.df.selPage("Tax")
        elif self.df.pag == 4:
            self.df.selPage("Deductions")
        elif self.df.pag == 5:
            self.df.selPage("Balances")

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