Esempio n. 1
0
 def setVariables(self):
     self.sql = Sql(
         self.opts["mf"].dbm,
         ["genmst", "gentrn", "wagedc", "wagmst", "waglmf", "wagltf"],
         prog=self.__class__.__name__)
     if self.sql.error:
         return
     self.gc = GetCtl(self.opts["mf"])
     wagctl = self.gc.getCtl("wagctl", self.opts["conum"])
     if not wagctl:
         return
     self.glint = wagctl["ctw_glint"]
     if self.glint == "Y":
         ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
         if not ctlctl:
             return
         if self.gc.chkRec(self.opts["conum"], ctlctl, ["wag_slc"]):
             return
         self.slnctl = ctlctl["wag_slc"]
     self.bh = Batches(self.opts["mf"],
                       self.opts["conum"],
                       self.opts["conam"],
                       self.opts["period"],
                       "SLN",
                       2,
                       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]
     return True
Esempio n. 2
0
 def batchHeader(self):
     self.bh = Batches(self.opts["mf"], self.opts["conum"],
         self.opts["conam"], self.opts["period"], "DRS", self.opts["rtn"],
         multi="N", glint=self.glint)
     self.bh.doBatchHeader()
     if not self.bh.batno:
         return
Esempio n. 3
0
 def setVariables(self):
     tabs = [
         "ctlmst", "ctlvmf", "ctlvrf", "ctlvtf", "genint", "genmst",
         "gentrn", "rtlprm", "rtlmst", "rtlcon", "rtltrn"
     ]
     self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
     if self.sql.error:
         return
     if self.opts["rtn"] not in (2, 3, 4):
         mes = "Invalid Routine %s" % str(self.opts["rtn"])
         showError(self.opts["mf"].body, "Control Error", mes)
         return
     self.gc = GetCtl(self.opts["mf"])
     rtlctl = self.gc.getCtl("rtlctl", self.opts["conum"])
     if not rtlctl:
         return
     self.glint = rtlctl["ctr_glint"]
     if self.glint == "Y":
         # Check All Premises Control Records
         errs = ("Premises %s Has An Invalid",
                 "Rental Control Account (%s)",
                 "Rental Income Account (%s)")
         ass = self.sql.getRec(
             "rtlprm",
             cols=["rtp_code", "rtp_rtlacc", "rtp_incacc"],
             where=[("rtp_cono", "=", self.opts["conum"])])
         for acc in ass:
             for x in range(1, 3):
                 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
         # Check for VAT Control
         ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
         if not ctlctl:
             return
         if self.gc.chkRec(self.opts["conum"], ctlctl, ["vat_ctl"]):
             return
         self.convat = ctlctl["vat_ctl"]
     t = time.localtime()
     self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
     self.bh = Batches(self.opts["mf"],
                       self.opts["conum"],
                       self.opts["conam"],
                       self.opts["period"],
                       "RTL",
                       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))
     return True
Esempio n. 4
0
 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))
Esempio n. 5
0
 def batchHeader(self):
     self.bh = Batches(self.opts["mf"],
                       self.opts["conum"],
                       self.opts["conam"],
                       self.opts["period"],
                       "SLN",
                       5,
                       glint=self.glint)
     self.bh.doBatchHeader()
     if not self.bh.batno:
         return
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 def setVariables(self):
     # Check for Company Record
     self.gc = GetCtl(self.opts["mf"])
     ctlmst = self.gc.getCtl("ctlmst", self.opts["conum"])
     if not ctlmst:
         return
     # Check and Load VAT Control
     self.ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
     if not self.ctlctl:
         return
     if self.gc.chkRec(self.opts["conum"], self.ctlctl, ["vat_ctl"]):
         return
     self.convat = self.ctlctl["vat_ctl"]
     # Set Batch Indicator
     self.batind = "Y"
     # Create SQL Object
     tabs = [
         "ctlctl", "ctlmst", "ctlvmf", "ctlvrf", "ctlvtf", "genint",
         "genjlm", "genjlt", "genmst", "gentrn", "assgrp", "rtlprm"
     ]
     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"],
                       "GEN",
                       self.opts["rtn"],
                       multi="Y")
     self.bh.doBatchHeader()
     if not self.bh.batno:
         return
     t = time.localtime()
     self.sysdtw = ((t[0] * 10000) + (t[1] * 100) + t[2])
     self.s_per = int(self.opts["period"][1][0] / 100)
     self.e_per = int(self.opts["period"][1][0] / 100)
     return True
Esempio n. 9
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)
Esempio n. 10
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"])
Esempio n. 11
0
class rt2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        tabs = [
            "ctlmst", "ctlvmf", "ctlvrf", "ctlvtf", "genint", "genmst",
            "gentrn", "rtlprm", "rtlmst", "rtlcon", "rtltrn"
        ]
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        if self.opts["rtn"] not in (2, 3, 4):
            mes = "Invalid Routine %s" % str(self.opts["rtn"])
            showError(self.opts["mf"].body, "Control Error", mes)
            return
        self.gc = GetCtl(self.opts["mf"])
        rtlctl = self.gc.getCtl("rtlctl", self.opts["conum"])
        if not rtlctl:
            return
        self.glint = rtlctl["ctr_glint"]
        if self.glint == "Y":
            # Check All Premises Control Records
            errs = ("Premises %s Has An Invalid",
                    "Rental Control Account (%s)",
                    "Rental Income Account (%s)")
            ass = self.sql.getRec(
                "rtlprm",
                cols=["rtp_code", "rtp_rtlacc", "rtp_incacc"],
                where=[("rtp_cono", "=", self.opts["conum"])])
            for acc in ass:
                for x in range(1, 3):
                    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
            # Check for VAT Control
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            if self.gc.chkRec(self.opts["conum"], ctlctl, ["vat_ctl"]):
                return
            self.convat = ctlctl["vat_ctl"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "RTL",
                          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))
        return True

    def drawDialog(self):
        prm = {
            "stype":
            "R",
            "tables": ("rtlprm", ),
            "cols": (("rtp_code", "", 0, "Prm-Cod"), ("rtp_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("rtp_cono", "=", self.opts["conum"])]
        }
        mst = {
            "stype":
            "R",
            "tables": ("rtlmst", ),
            "cols":
            (("rtm_acno", "", 0, "Acc-Num"), ("rtm_name", "", 0, "Name", "Y")),
            "where": [("rtm_cono", "=", self.opts["conum"])],
            "whera": [["C", "rtm_code", 0, 1]]
        }
        con = {
            "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": [["C", "rtc_code", 0, 1], ["C", "rtc_acno", 1, 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"])]
        }
        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, "Prm-Cod", "Premises Code", "r", "N",
                self.doPrmCod, prm, None, None),
               (("C", 1, 0, 1), "INA", 7, "Acc-Num", "Account Number", "r",
                "N", self.doAccNum, mst, None, None),
               (("C", 1, 0, 2), "IUI", 3, "Seq", "Contract Sequence", "", "N",
                self.doConSeq, con, None, None),
               (("C", 1, 0, 3), "INa", 9, "Reference", "Reference Number", "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), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, None),
               (("C", 1, 0, 6), "IUA", 1, "V", "V.A.T Code", "", "N",
                self.doVatCod, vtm, None, ("notblank", )),
               (("C", 1, 0, 7), "ISD", 11.2, "V.A.T", "V.A.T Amount", "", "N",
                self.doVatAmt, None, None, None),
               [("C", 1, 0, 8), "INA", 30, "Details", "Transaction Details",
                "", "N", self.doTrnDet, None, None, None]]
        if self.opts["rtn"] not in (2, 3) and self.glint == "Y":
            fld[10][2] = (22, 30)
            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.queryRtl, 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 (2, 3) 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 doPrmCod(self, frt, pag, r, c, p, i, w):
        whr = [("rtp_cono", "=", self.opts["conum"]), ("rtp_code", "=", w)]
        acc = self.sql.getRec("rtlprm", where=whr, limit=1)
        if not acc:
            return "Invalid Premises Code"
        self.code = w
        self.rtlacc = acc[self.sql.rtlprm_col.index("rtp_rtlacc")]

    def doAccNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("rtlmst",
                              cols=["rtm_name", "rtm_vatind"],
                              where=[("rtm_cono", "=", self.opts["conum"]),
                                     ("rtm_code", "=", self.code),
                                     ("rtm_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account Number"
        self.acno = w
        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 "No Valid Contracts"
        self.cnum = con[-1:][0][3]
        self.df.colf[1][2][5] = self.cnum
        if self.opts["rtn"] == 4:
            self.df.colf[1][6][5] = acc[1]
        else:
            self.df.colf[1][6][5] = "N"

    def doConSeq(self, frt, pag, r, c, p, i, w):
        con = self.sql.getRec("rtlcon",
                              where=[("rtc_cono", "=", self.opts["conum"]),
                                     ("rtc_code", "=", self.code),
                                     ("rtc_acno", "=", self.acno),
                                     ("rtc_cnum", "=", w)],
                              order="rtc_cnum")
        if not con:
            return "Invalid Contract Sequence"
        self.cnum = w

    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

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w
        if self.opts["rtn"] in (2, 3):
            self.vatcode = ""
            self.trnvat = 0
            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.trnamt * 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.trnamt < 0 and w > 0:
            self.trnvat = float(ASD(0) - ASD(w))
        elif self.trnamt > 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 (2, 3) and self.glint == "Y":
            self.df.colf[2][3][5] = w

    def endPage1(self):
        self.batupd = False
        self.updateTables1()
        self.updateBatch()
        if self.trnamt == 0:
            self.df.advanceLine(1)
        else:
            self.allocated = float(0.0)
            if self.opts["rtn"] in (2, 3) or self.glint == "N":
                self.opts["mf"].dbm.commitDbase()
                self.df.selPage("Transaction")
                self.df.advanceLine(1)
            else:
                self.trnamt = float(ASD(self.trnamt) - ASD(self.trnvat))
                self.df.loadEntry("T", 2, 0, data=self.trnamt)
                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.trnamt
        self.vat = self.trnvat
        if self.opts["rtn"] == 2:  # Receipts
            if self.trnamt == 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.glt = 6
        elif self.opts["rtn"] == 3:  # Payments
            if self.trnamt == 0:
                self.recon = self.curdt
            else:
                self.recon = 0
            self.glt = 2
        elif self.opts["rtn"] == 4:  # Journal Entries
            self.recon = 0
            self.glt = 4
        # Rental Ledger Transaction
        data = [
            self.opts["conum"], self.code, self.acno, self.cnum,
            self.opts["rtn"], self.trnref, self.bh.batno, self.trndat,
            self.amt, self.vat, self.curdt, self.trndet, self.vatcode, "N",
            self.opts["capnm"], self.sysdtw, 0
        ]
        self.sql.insRec("rtltrn", data=data)
        if self.vatcode:
            # VAT Transaction (ctlvtf)
            exc = float(ASD(0) - ASD(self.amt) + ASD(self.vat))
            vat = float(ASD(0) - ASD(self.vat))
            data = (self.opts["conum"], self.vatcode, "O", self.curdt, "R",
                    self.opts["rtn"], self.bh.batno, self.trnref, self.trndat,
                    self.code, self.trndet, exc, vat, 0, self.opts["capnm"],
                    self.sysdtw, 0)
            self.sql.insRec("ctlvtf", data=data)
        if self.glint == "N":
            return
        # General Ledger Rental Account
        data = (self.opts["conum"], self.rtlacc, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, self.amt, self.vat,
                self.trndet, self.vatcode, "", 0, self.opts["capnm"],
                self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        self.trnamt = float(ASD(0) - ASD(self.amt))
        self.trnvat = float(ASD(0) - ASD(self.vat))
        if self.vatcode and self.trnvat:
            # 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.trnvat, 0.00,
                    self.trndet, "N", "", 0, self.opts["capnm"], self.sysdtw,
                    0)
            self.sql.insRec("gentrn", data=data)
        if self.opts["rtn"] in (2, 3):
            # General Ledger Control Transaction (Bank)
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                    self.glt, self.trnref, self.bh.batno, self.trnamt, 0.00,
                    self.trndet, "N", "", self.recon, 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 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.trnamt) - 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((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.trnamt:
            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
        # General Ledger Transaction (Source)
        data = (self.opts["conum"], self.genacc, self.curdt, self.trndat,
                self.glt, self.trnref, self.bh.batno, self.allamt, 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 = 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 queryRtl(self):
        callModule(self.opts["mf"],
                   self.df,
                   "rt4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])
Esempio n. 12
0
class gl2050(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.doProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Check for Company Record
        self.gc = GetCtl(self.opts["mf"])
        ctlmst = self.gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        # Check and Load VAT Control
        self.ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
        if not self.ctlctl:
            return
        if self.gc.chkRec(self.opts["conum"], self.ctlctl, ["vat_ctl"]):
            return
        self.convat = self.ctlctl["vat_ctl"]
        # Set Batch Indicator
        self.batind = "Y"
        # Create SQL Object
        tabs = [
            "ctlctl", "ctlmst", "ctlvmf", "ctlvrf", "ctlvtf", "genint",
            "genjlm", "genjlt", "genmst", "gentrn", "assgrp", "rtlprm"
        ]
        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"],
                          "GEN",
                          self.opts["rtn"],
                          multi="Y")
        self.bh.doBatchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = ((t[0] * 10000) + (t[1] * 100) + t[2])
        self.s_per = int(self.opts["period"][1][0] / 100)
        self.e_per = int(self.opts["period"][1][0] / 100)
        return True

    def doProcess(self):
        r1s = (("Monthly", "M"), ("Quarterly", "3"), ("Bi-Annually", "6"),
               ("Annually", "Y"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), ("IRB", r1s), 0, "Frequency", "", "M", "N",
                self.doFreq, None, None, None),
               (("T", 0, 1, 0), ("IRB", r2s), 9, "All Journals", "", "N", "N",
                self.doAllJnl, None, None, None),
               (("T", 0, 2, 0), ("IRB", r2s), 1, "All Periods", "", "N", "N",
                self.doAllPer, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"], eflds=fld, tend=tnd, txit=txt)

    def doFreq(self, frt, pag, r, c, p, i, w):
        self.freq = w
        self.wher = [("gjm_cono", "=", self.opts["conum"]),
                     ("gjm_freq", "=", self.freq),
                     ("gjm_start", "<=", self.bh.curdt),
                     ("gjm_end", ">=", self.bh.curdt),
                     ("gjm_last", "<", self.bh.curdt)]
        data = self.sql.getRec("genjlm",
                               cols=["gjm_num", "gjm_desc"],
                               where=self.wher)
        if not data:
            return "No Valid Standard Journals"
        if self.freq == "M":
            self.mths = 1
        elif self.freq == "3":
            self.mths = 3
        elif self.freq == "6":
            self.mths = 6
        else:
            self.mths = 12

    def doAllJnl(self, frt, pag, r, c, p, i, w):
        self.alljnl = w

    def doAllPer(self, frt, pag, r, c, p, i, w):
        self.allper = w

    def doEnd(self):
        self.df.closeProcess()
        if self.alljnl == "N":
            recs = getSingleRecords(self.opts["mf"],
                                    "genjlm", ("gjm_num", "gjm_desc"),
                                    where=self.wher)
        else:
            recs = self.sql.getRec("genjlm", where=self.wher)
        if not recs:
            self.opts["mf"].closeLoop()
            return
        for gjm in recs:
            self.trnref = gjm[self.sql.genjlm_col.index("gjm_num")]
            self.trndet = gjm[self.sql.genjlm_col.index("gjm_desc")]
            start = gjm[self.sql.genjlm_col.index("gjm_start")]
            last = gjm[self.sql.genjlm_col.index("gjm_last")]
            dates = []
            while start <= self.bh.curdt:
                if start < self.s_per or start <= last:
                    pass
                elif self.allper == "N" and start == self.bh.curdt:
                    dates.append(start)
                elif self.allper == "Y" and start <= self.bh.curdt:
                    dates.append(start)
                start = self.nextPeriod(start)
            for self.curdt in dates:
                self.trndat = mthendDate((self.curdt * 100))
                data = self.sql.getRec(
                    "genjlt",
                    cols=["gjt_acno", "gjt_amnt", "gjt_vatc"],
                    where=[("gjt_cono", "=", self.opts["conum"]),
                           ("gjt_num", "=", self.trnref),
                           ("gjt_amnt", "<>", 0)])
                if not data:
                    continue
                for tran in data:
                    self.acno = tran[0]
                    self.trnamt = tran[1]
                    self.vatcod = tran[2]
                    vrte = getVatRate(self.sql, self.opts["conum"],
                                      self.vatcod, self.trndat)
                    if vrte is None:
                        vrte = 0.0
                    self.vatamt = round((self.trnamt * vrte / (vrte + 100)), 2)
                    self.updateTables()
                    self.updateBatch()
                self.sql.updRec("genjlm",
                                cols=["gjm_last"],
                                data=[self.curdt],
                                where=[("gjm_cono", "=", self.opts["conum"]),
                                       ("gjm_num", "=", self.trnref),
                                       ("gjm_freq", "=", self.freq)])
        self.opts["mf"].dbm.commitDbase()
        self.opts["mf"].closeLoop()

    def nextPeriod(self, period):
        yy = int(period / 100)
        mm = (period % 100) + self.mths
        if mm > 12:
            yy += 1
            mm -= 12
        return (yy * 100) + mm

    def updateTables(self):
        amt = float(ASD(self.trnamt) - ASD(self.vatamt))
        data = (self.opts["conum"], self.acno, self.curdt, self.trndat,
                self.opts["rtn"], self.trnref, self.bh.batno, amt, self.vatamt,
                self.trndet, self.vatcod, self.batind, 0, self.opts["capnm"],
                self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        if self.vatcod:
            if self.vatamt:
                data = (self.opts["conum"], self.convat, self.curdt,
                        self.trndat, self.opts["rtn"], self.trnref,
                        self.bh.batno, self.vatamt, 0.00, self.trndet,
                        self.vatcod, self.batind, 0, self.opts["capnm"],
                        self.sysdtw, 0)
                self.sql.insRec("gentrn", data=data)
            if amt < 0:
                vtyp = "O"
            else:
                vtyp = "I"
            data = (self.opts["conum"], self.vatcod, vtyp, self.curdt, "G",
                    self.opts["rtn"], self.bh.batno, self.trnref, self.trndat,
                    self.acno, self.trndet, amt, self.vatamt, 0,
                    self.opts["capnm"], self.sysdtw, 0)
            self.sql.insRec("ctlvtf", 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.bh.batqty = self.bh.batqty + 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.trnamt))

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Esempio n. 13
0
class ln2010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.drawDialog()
            self.opts["mf"].startLoop()

    def setVariables(self):
        # Create SQL Object
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlmst", "lonmf1", "lonmf2", "lonrte", "lontrn", "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"])
        lonctl = self.gc.getCtl("lonctl", self.opts["conum"])
        if not lonctl:
            return
        self.glint = lonctl["cln_glint"]
        self.drte = lonctl["cln_drte"]
        self.crte = lonctl["cln_crte"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["lon_ctl", "int_rec", "int_pay"]
            if self.gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.lonctl = ctlctl["lon_ctl"]
            self.intrec = ctlctl["int_rec"]
            self.intpay = ctlctl["int_pay"]
        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"]
        return True

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

    def drawDialog(self):
        lm1 = {
            "stype":
            "R",
            "tables": ("lonmf1", ),
            "cols":
            (("lm1_acno", "", 0, "Acc-Num"), ("lm1_name", "", 0, "Name", "Y")),
            "where": [("lm1_cono", "=", self.opts["conum"])]
        }
        lm2 = {
            "stype":
            "R",
            "tables": ("lonmf2", ),
            "cols": (("lm2_loan", "", 0, "Ln"), ("lm2_desc", "", 0,
                                                 "Description", "Y")),
            "where": [("lm2_cono", "=", self.opts["conum"])],
            "whera": [("C", "lm2_acno", 0)]
        }
        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]]
        }
        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 Code", "", "Y",
                self.doLonAcc, lm1, None, ("efld", )),
               (("C", 1, 0, 1), "ONA", 10, "Name"),
               (("C", 1, 0, 2), "IUI", 2, "LN", "Loan Number", "", "N",
                self.doLonNum, lm2, None, ("efld", )),
               (("C", 1, 0, 3), "ITX", (12, 30), "Description", "", "", "N",
                self.doLonDes, None, None, ("notblank", )),
               (("C", 1, 0, 4), "ID1", 10, "Date", "Transaction Date", "r",
                "N", self.doTrnDat, None, None, ("efld", )),
               (("C", 1, 0, 5), "INa", 9, "Reference", "Reference Number One",
                "i", "N", self.doTrnRef, None, None, ("notblank", )),
               (("C", 1, 0, 6), "ISD", 13.2, "Amount", "Transaction Amount",
                "", "N", self.doTrnAmt, None, None, ("notzero", )),
               (("C", 1, 0, 7), "IUD", 6.2, "DRte-%", "Debit Rate", self.drte,
                "N", self.doLonDrt, None, None, None),
               (("C", 1, 0, 8), "IUD", 6.2, "CRte-%", "Credit Rate", self.crte,
                "N", self.doLonCrt, None, None, None),
               (("C", 1, 0, 9), "IUI", 3, "Mth", "Period in Months", "", "N",
                self.doLonMth, None, None, ("efld", )),
               (("C", 1, 0, 10), "OUD", 12.2, "Repay-Amt"),
               (("C", 1, 0, 11), "INA", 30, "Details", "Loan Details", "", "N",
                self.doTrnDet, None, None, None)]
        if self.opts["rtn"] == 3 and self.glint == "Y":
            fld.extend([(("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,
                          4), "ISD", 13.2, "All-Amount", "Allocation Amount",
                         "", "N", self.doAllAmt, None, None, ("efld", )),
                        (("C", 2, 0, 6), "INA", 30, "Allocation Details", "",
                         "", "N", self.doAllDet, None, None, ("notblank", ))])
            if not self.incoac:
                fld[15][1] = "OUI"
        but = [("Interrogate", None, self.querySln, 0, ("C", 1, 1), ("C", 1,
                                                                     2))]
        tag = [("Transaction", None, None, None, False)]
        cnd = [(None, "n"), (self.endPage1, "y")]
        cxt = [None, self.exitPage1]
        if self.opts["rtn"] == 3 and self.glint == "Y":
            but.append(
                ("Cancel", None, self.doCancel, 0, ("C", 2, 1), ("C", 1, 1)))
            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 doLonAcc(self, frt, pag, r, c, p, i, w):
        newacc = False
        if not w and self.opts["rtn"] in (1, 2, 3):
            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.opts["conum"], self.opts["conam"]),
                           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.name = acc[0]
        self.df.loadEntry(frt, pag, p + 1, data=self.name)
        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):
        self.newlon = False
        if not w and self.opts["rtn"] in (1, 2, 3):
            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.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.opts["rtn"] in (1, 3) and self.lonmth:
                showError(
                    self.opts["mf"].body, "Fixed Loan",
                    """This is a Fixed Period Loan.

Please Create a New Loan for this Account.""")
                return "Invalid Loan Number"
            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 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 doTrnRef(self, frt, pag, r, c, p, i, w):
        self.refno = w

    def doTrnAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w
        if not self.newlon:
            self.londrt = 0
            self.loncrt = 0
            self.lonmth = 0
            self.lonpay = 0
            if self.opts["rtn"] in (1, 2):
                return "nd"
            else:
                return "sk4"

    def doLonDrt(self, frt, pag, r, c, p, i, w):
        self.londrt = w

    def doLonCrt(self, frt, pag, r, c, p, i, w):
        self.loncrt = w

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

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

    def endPage1(self):
        self.batupd = False
        self.updateTables1()
        self.updateBatch()
        if not self.val:
            self.df.advanceLine(1)
        elif self.opts["rtn"] in (1, 2, 4) or self.glint == "N":
            self.opts["mf"].dbm.commitDbase()
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            self.allocated = float(0.0)
            self.df.loadEntry("T", 2, 0, data=self.val)
            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
        if self.opts["rtn"] == 1:
            self.glt = 2
            desc = "Loan Advance"
            self.val = self.trnamt
        elif self.opts["rtn"] == 2:
            self.glt = 6
            desc = "Loan Repayment"
            self.val = float(ASD(0) - ASD(self.trnamt))
        elif self.opts["rtn"] == 3:
            self.glt = 4
            desc = self.trndet
            self.val = self.trnamt
        elif self.opts["rtn"] == 4:
            self.glt = 4
            desc = self.trndet
            self.val = self.trnamt
        if self.newlon:
            # Loans Masterfile
            self.sql.insRec("lonmf2",
                            data=[
                                self.opts["conum"], self.lonacc, self.lonnum,
                                self.londes, self.trndat, self.lonmth,
                                self.lonpay, 0
                            ])
            # Loans Rate File
            self.sql.insRec("lonrte",
                            data=[
                                self.opts["conum"], self.lonacc, self.lonnum,
                                self.trndat, self.londrt, self.loncrt
                            ])
        # Loans Transaction File
        self.sql.insRec("lontrn",
                        data=[
                            self.opts["conum"], self.lonacc, self.lonnum,
                            self.bh.batno, self.opts["rtn"], self.trndat,
                            self.refno, self.val, self.curdt, desc, "N",
                            self.opts["capnm"], self.sysdtw, 0
                        ])
        if self.glint == "N":
            return
        # General Ledger Loans Control Account
        data = (self.opts["conum"], self.lonctl, self.curdt, self.trndat,
                self.glt, self.refno, self.bh.batno, self.val, 0.00, self.name,
                "N", "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        if self.opts["rtn"] in (1, 2, 4):
            # General Ledger Bank or Interest
            self.val = float(ASD(0) - ASD(self.val))
            if self.opts["rtn"] in (1, 2):
                ctl = self.bh.acc
            elif self.val < 0:
                ctl = self.intrec
            else:
                ctl = self.intpay
            data = (self.opts["conum"], ctl, self.curdt, self.trndat, self.glt,
                    self.refno, self.bh.batno, self.val, 0.00,
                    "Loan - %s" % self.name, "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 doGenAcc(self, frt, pag, r, c, p, i, w):
        chk = chkGenAcc(self.opts["mf"], self.allcoy, w)
        if type(chk) is str:
            return chk
        self.genacc = w
        self.df.loadEntry(frt, pag, p + 1, data=chk[0])

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if w == 0:
            self.allamt = float(ASD(self.val) - 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((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.val:
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.val) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def updateTables2(self):
        val = float(ASD(0) - ASD(self.allamt))
        # General Ledger Transaction (Allocation)
        data = (self.allcoy, self.genacc, self.curdt, self.trndat, self.glt,
                self.refno, self.bh.batno, val, 0.00, self.alldet, "", "", 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.refno, 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(val))
            data = (self.allcoy, acc, self.curdt, self.trndat, self.glt,
                    self.refno, self.bh.batno, val, 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 = self.bh.batqty - 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.val))
        else:
            self.batupd = True
            self.bh.batqty = self.bh.batqty + 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.val))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def querySln(self):
        callModule(self.opts["mf"],
                   self.df,
                   "ln4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])
Esempio n. 14
0
class dr2010(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, 3, 4, 5):
            showError(self.opts["mf"].body, "Control Error",
                "Invalid Routine %s, Only 1, 3, 4 and 5 Are Allowed" % \
                str(self.opts["rtn"]))
            return
        # Create SQL Object
        self.sql = Sql(self.opts["mf"].dbm, ["ctlmst", "ctlvmf", "ctlvrf",
            "ctlvtf", "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.glinp = drsctl["ctd_glinp"]
        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
        if self.opts["rtn"] == 1:
            self.glt = 1
        elif self.opts["rtn"] == 3:
            self.glt = 4
        elif self.opts["rtn"] == 4:
            self.glt = 1
        elif self.opts["rtn"] == 5:
            self.glt = 2
        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
        if self.opts["rtn"] == 4:
            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"))}
        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"])]}
        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"}
        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",3,"Chn","Chain Store",
                "r","Y",self.doChain,drc,None,("efld",)],
            [("C",1,0,1),"INA",7,"Acc-Num","Account Number",
                "r","N",self.doDrsAcc,drm,None,("notblank",)],
            [("C",1,0,2),"ONA",10,"Name"],
            (("C",1,0,3),"INa",9,"Reference","Reference Number One",
                "i","N",self.doRef1,None,None,("notblank",)),
            (("C",1,0,4),"ID1",10,"Date","Transaction Date",
                "r","N",self.doTrnDat,None,None,("efld",)),
            (("C",1,0,5),"ISD",13.2,"Amount","Transaction Amount",
                "","N",self.doTrnAmt,None,None,("efld",))]
        if self.opts["rtn"] == 5:
            fld[4][2] = 20
            fld.extend([
                [["C",1,0,6],"ISD",13.2,"Discount",
                    "Discount Amount","","N",self.doDisAmt,None,None,None,None,
                    "Discout Amount to be Added to the Transaction Amount"],
                [["C",1,0,7],"OSD",13.2,"Total-Amount"],
                [["C",1,0,8],"INA",(20,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[4][2] = 24
            fld.extend([
                [["C",1,0,6],"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",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",
                    self.taxdf,"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[10][1] = "OUI"
        else:
            fld[4][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]])
        if self.chains == "N":
            fld[2][1] = "OUI"
            idx = 2
        else:
            idx = 1
        but = (
            ("Interrogate",None,self.queryDrs,0,("C",1,idx),("C",1,idx+1),
                "Interrogate Debtors Records",1),
            ("View Entries",viw,None,0,("C",1,idx),("C",1,idx+1),
                "View Batch Transactions",1),
            ("Maintain",None,self.maintainDrs,0,("C",1,idx),("C",1,idx+1),
                "Maintain Debtors 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 One",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"] != 5 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 doChain(self, frt, pag, r, c, p, i, w):
        if w:
            acc = self.sql.getRec("drschn", cols=["chm_chain"],
                where=[("chm_cono", "=", self.opts["conum"]), ("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.opts["conum"]), ("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)

    def doRef1(self, frt, pag, r, c, p, i, w):
        self.ref1 = w
        acc = self.sql.getRec("drstrn", cols=["drt_batch"],
            where=[("drt_cono", "=", self.opts["conum"]), ("drt_chain", "=",
            self.chain), ("drt_acno", "=", self.dracno), ("drt_type", "=",
            self.opts["rtn"]), ("drt_ref1", "=", self.ref1)], limit=1)
        if acc:
            return "Transaction Already Exists"

    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"] == 5:
            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"] != 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"] == 5 or self.glint == "N":
                    self.doDrsTrn()
                    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"] == 3:                        # Journals
            recon = 0
            self.dis = 0.00
        elif self.opts["rtn"] == 4:                        # Credit Notes
            recon = 0
            self.amt = float(ASD(0) - ASD(self.amt))
            self.vat = float(ASD(0) - ASD(self.vat))
            self.dis = 0.00
        elif self.opts["rtn"] == 5:                        # Payments
            if self.trnamt == 0:
                recon = self.curdt
            else:
                recon = 0
            self.vat = 0.00
            self.dis = self.disamt
        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 (Debtors)
        val = float(ASD(self.amt) + ASD(self.dis))
        data = (self.opts["conum"], self.drsctl, self.curdt, self.trndat,
            self.glt, self.ref1, 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"] == 5:
            val = float(ASD(0) - ASD(self.amt))
            data = (self.opts["conum"], self.bh.acc, self.curdt, self.trndat,
                self.glt, self.ref1, 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.ref1, 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(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.opts["conum"], self.chain, self.dracno,
            self.opts["rtn"], self.ref1, 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):
        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 doGenAcc(self, frt, pag, r, c, p, i, w):
        chk = chkGenAcc(self.opts["mf"], self.allcoy, 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, 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.allcoy, 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.allcoy, 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 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)
            if self.glint == "Y" and self.opts["rtn"] != 5:
                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.doDrsTrn()
            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:                        # Journals
            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.allcoy, self.vatcode, "O", self.curdt, "D",
            self.opts["rtn"], self.bh.batno, self.ref1, self.trndat,
            self.dracno, 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 (Allocation)
        data = (self.allcoy, self.genacc, self.curdt, self.trndat,
            self.glt, self.ref1, 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.ref1, 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.ref1, 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.ref1, 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 doDrsTrn(self):
        # Debtors Ledger Transaction
        data = [self.opts["conum"], self.chain, self.dracno, self.opts["rtn"],
            self.ref1, self.bh.batno, self.trndat, "", self.amt, self.vat,
            self.curdt, self.trndet, self.vatcode, "N", self.opts["capnm"],
            self.sysdtw, 0]
        self.sql.insRec("drstrn", data=data)
        if not self.dis:
            return
        data = [self.opts["conum"], self.chain, self.dracno, 6, self.ref1,
            self.bh.batno, self.trndat, "", self.dis, self.vat, self.curdt,
            self.trndet, self.vatcode, "N", self.opts["capnm"], self.sysdtw, 0]
        self.sql.insRec("drstrn", 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 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"])
Esempio n. 15
0
class dr2030(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.doProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["ctlmst", "ctlvrf", "ctlvtf",
            "drsmst", "drstrn", "drsrcm", "drsrct", "genmst", "gentrn"],
            prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.gc = GetCtl(self.opts["mf"])
        drsctl = self.gc.getCtl("drsctl", self.opts["conum"])
        if not drsctl:
            return
        self.glint = drsctl["ctd_glint"]
        self.fromad = drsctl["ctd_emadd"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            if self.gc.chkRec(self.opts["conum"],ctlctl,["drs_ctl","vat_ctl"]):
                return
            self.drsctl = ctlctl["drs_ctl"]
            self.vatctl = ctlctl["vat_ctl"]
        ctl = self.sql.getRec("ctlmst",
            where=[("ctm_cono", "=", self.opts["conum"])], limit=1)
        for col in ("ctm_name", "ctm_add1", "ctm_add2", "ctm_add3",
                    "ctm_pcode", "ctm_regno", "ctm_taxno", "ctm_tel",
                    "ctm_fax", "ctm_b_name", "ctm_b_branch", "ctm_b_ibt",
                    "ctm_b_acno", "ctm_logo"):
            setattr(self, "%s" % col, ctl[self.sql.ctlmst_col.index(col)])
        if "LETTERHEAD" in os.environ:
            self.ctm_logo = os.environ["LETTERHEAD"]
        if not self.ctm_logo or not os.path.exists(self.ctm_logo):
            self.ctm_logo = None
        self.batchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

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

    def doProcess(self):
        r1s = (
            ("Monthly","M"),
            ("Quarterly","3"),
            ("Bi-Annually","6"),
            ("Annually","Y"))
        r2s = (("Yes", "Y"), ("No", "N"))
        fld = (
            (("T",0,0,0),("IRB",r1s),0,"Frequency","",
                "M","N",self.doFreq,None,None,None),
            (("T",0,1,0),("IRB",r2s),1,"All Charges","",
                "N","N",self.doAll,None,None,None),
            (("T",0,2,0),"INa",9,"2nd Reference","",
                "","N",self.doRef2,None,None,None),
            (("T",0,3,0),("IRB",r2s),1,"Invoices","",
                "N","N",self.doInv,None,None,None))
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], eflds=fld,
            tend=tnd, txit=txt, view=("N","P"), mail=("N","Y"))

    def doFreq(self, frt, pag, r, c, p, i, w):
        self.freq = w
        self.wher = [("dcm_cono", "=", self.opts["conum"]), ("dcm_freq", "=",
            self.freq), ("dcm_last", "<", self.bh.curdt)]
        data = self.sql.getRec("drsrcm", where=self.wher)
        if not data:
            return "No Valid Recurring Charges"
        if self.freq == "M":
            self.mths = 1
        elif self.freq == "3":
            self.mths = 3
        elif self.freq == "6":
            self.mths = 6
        else:
            self.mths = 12

    def doAll(self, frt, pag, r, c, p, i, w):
        self.allc = w

    def doRef2(self, frt, pag, r, c, p, i, w):
        self.ref2 = w

    def doInv(self, frt, pag, r, c, p, i, w):
        self.inv = w
        if self.inv == "N":
            self.df.loadEntry(frt, pag, p+2, data="")
            return "nd"

    def doEml(self, frt, pag, r, c, p, i, w):
        self.eml = w

    def doEnd(self):
        self.df.closeProcess()
        if self.allc == "N":
            recs = getSingleRecords(self.opts["mf"], "drsrcm", ("dcm_num",
                "dcm_desc"), where=self.wher)
        else:
            recs = self.sql.getRec("drsrcm", where=self.wher)
        if recs:
            if self.inv == "Y" and self.df.repeml[1] == "N":
                self.fpdf = MyFpdf(orientation="L", fmat="A4",
                    name=self.__class__.__name__, head=128)
            for dcm in recs:
                num = dcm[self.sql.drsrcm_col.index("dcm_num")]
                desc = dcm[self.sql.drsrcm_col.index("dcm_desc")]
                day = dcm[self.sql.drsrcm_col.index("dcm_day")]
                if day == 30:
                    self.trdt = mthendDate((self.bh.curdt * 100) + 1)
                else:
                    self.trdt = (self.bh.curdt * 100) + day
                vat = dcm[self.sql.drsrcm_col.index("dcm_vat")]
                self.vatrte = getVatRate(self.sql, self.opts["conum"],
                    vat, self.trdt)
                glac = dcm[self.sql.drsrcm_col.index("dcm_glac")]
                nxt = self.sql.getRec("drstrn", cols=["max(drt_ref1)"],
                    where=[("drt_cono", "=", self.opts["conum"]), ("drt_ref1",
                    "like", "RC%03i%s" % (num, "%"))], limit=1)
                if not nxt[0]:
                    nxt = 0
                else:
                    nxt = int(nxt[0][5:])
                tot_val = 0
                tot_vat = 0
                rec = self.sql.getRec("drsrct", where=[("dct_cono", "=",
                    self.opts["conum"]), ("dct_num", "=", num), ("dct_start",
                    "<=", self.bh.curdt), ("dct_end", ">=", self.bh.curdt)])
                col = self.sql.drsrct_col
                for dct in rec:
                    self.chain = dct[col.index("dct_chain")]
                    self.acno = dct[col.index("dct_acno")]
                    # Check for Redundancy
                    chk = self.sql.getRec("drsmst", cols=["drm_stat"],
                        where=[("drm_cono", "=", self.opts["conum"]),
                        ("drm_chain", "=", self.chain), ("drm_acno", "=",
                        self.acno)], limit=1)
                    if chk[0] == "X":
                        continue
                    # Check for Valid Period
                    charge = False
                    start = dct[col.index("dct_start")]
                    year = int(start / 100)
                    month = start % 100
                    while start <= self.bh.curdt:
                        if start == self.bh.curdt:
                            charge = True
                            break
                        month += self.mths
                        if month > 12:
                            year += 1
                            month -= 12
                        start = (year * 100) + month
                    if not charge:
                        continue
                    # Create Transactions
                    nxt += 1
                    self.ref = "RC%03i%04i" % (num, nxt)
                    self.detail = textFormat(dct[col.index("dct_detail")], 73)
                    self.amnt = dct[col.index("dct_amnt")]
                    self.vmnt = round(self.amnt * self.vatrte / 100, 2)
                    self.tmnt = float(ASD(self.amnt) + ASD(self.vmnt))
                    tot_val = float(ASD(tot_val) + ASD(self.amnt))
                    tot_vat = float(ASD(tot_vat) + ASD(self.vmnt))
                    # Debtors (drstrn)
                    self.sql.insRec("drstrn", data=[self.opts["conum"],
                        self.chain, self.acno, 1, self.ref, self.bh.batno,
                        self.trdt, self.ref2, self.tmnt, self.vmnt,
                        self.bh.curdt, self.detail[0], vat, "Y",
                        self.opts["capnm"], self.sysdtw, 0])
                    if self.inv == "Y":
                        # Create Invoice
                        self.doInvoice()
                    # VAT (ctlvtf)
                    amnt = float(ASD(0) - ASD(self.amnt))
                    vmnt = float(ASD(0) - ASD(self.vmnt))
                    data = [self.opts["conum"], vat, "O", self.bh.curdt,
                        "D", 1, self.bh.batno, self.ref, self.trdt, self.acno,
                        self.detail[0], amnt, vmnt, 0, self.opts["capnm"],
                        self.sysdtw, 0]
                    self.sql.insRec("ctlvtf", data=data)
                if self.glint == "Y":
                    ref = "RC%07i" % num
                    # Update Debtors Control
                    amnt = float(ASD(tot_val) + ASD(tot_vat))
                    data = (self.opts["conum"], self.drsctl, self.bh.curdt,
                        self.trdt, 1, ref, self.bh.batno, amnt, 0, desc,
                        "", "", 0, self.opts["capnm"], self.sysdtw, 0)
                    self.sql.insRec("gentrn", data=data)
                    # Update Sales Account
                    amnt = float(ASD(0) - ASD(tot_val))
                    data = (self.opts["conum"], glac, self.bh.curdt, self.trdt,
                        1, ref, self.bh.batno, amnt, 0, desc, "", "", 0,
                        self.opts["capnm"], self.sysdtw, 0)
                    self.sql.insRec("gentrn", data=data)
                    amnt = float(ASD(0) - ASD(tot_vat))
                    if amnt:
                        # Update VAT Control
                        data = (self.opts["conum"], self.vatctl, self.bh.curdt,
                            self.trdt, 1, ref, self.bh.batno, amnt, 0, desc,
                            "", "", 0, self.opts["capnm"], self.sysdtw, 0)
                        self.sql.insRec("gentrn", data=data)
                # Update Recurring Charge (drsrcm)
                self.sql.updRec("drsrcm", cols=["dcm_last"],
                    data=[self.bh.curdt], where=[("dcm_cono", "=",
                    self.opts["conum"]), ("dcm_num", "=", num), ("dcm_freq",
                    "=", self.freq)])
            self.opts["mf"].dbm.commitDbase()
            if self.inv == "Y" and self.df.repeml[1] == "N":
                self.doPrint()
        self.opts["mf"].closeLoop()

    def doInvoice(self):
        if self.df.repeml[1] == "Y":
            self.fpdf = MyFpdf(orientation="L", fmat="A4",
                name=self.__class__.__name__, head=128)
        cw = self.fpdf.get_string_width("X")
        ld = self.fpdf.font[2]
        ica = CCD(self.tmnt, "SD", 13.2)
        iva = CCD(float(ASD(self.tmnt) - ASD(self.amnt)), "SD", 13.2)
        ivr = CCD(self.vatrte, "UD", 5.2)
        self.drawInvoice(cw, ld)
        row = 20
        for detail in self.detail:
            row += 1
            self.fpdf.drawText(x=22.2*cw, y=row*ld, txt=detail)
        self.fpdf.drawText(x=97*cw, y=row*ld, txt=ivr.disp)
        self.fpdf.drawText(x=103*cw, y=row*ld, txt=ica.disp)
        self.printTotals(cw, ld, ica, iva)
        if self.df.repeml[1] == "Y":
            self.doPrint()

    def drawInvoice(self, cw, ld):
        self.fpdf.add_page()
        self.fpdf.setFont("courier", "B", 16)
        self.fpdf.drawText(x=22*cw, y=1*ld, txt=self.ctm_name)
        self.fpdf.setFont("courier", "B", 14)
        self.fpdf.drawText(x=108*cw, y=2*ld, w=16, align="R", txt="Tax Invoice")
        self.fpdf.setFont("courier", "B", self.fpdf.font[1])
        if self.ctm_logo:
            self.fpdf.image(self.ctm_logo, 45, 3, 138, 28)
        else:
            self.fpdf.drawText(x=22*cw, y=2.5*ld, txt=self.ctm_add1)
            self.fpdf.drawText(x=22*cw, y=3.5*ld, txt=self.ctm_add2)
            self.fpdf.drawText(x=22*cw, y=4.5*ld, txt=self.ctm_add3)
            self.fpdf.drawText(x=22*cw, y=5.5*ld, txt=self.ctm_pcode)
            self.fpdf.drawText(x=54*cw, y=2.5*ld,
                txt="RegNo: %s" % self.ctm_regno)
            self.fpdf.drawText(x=54*cw, y=3.5*ld,
                txt="TaxNo: %s" % self.ctm_taxno)
            self.fpdf.drawText(x=54*cw, y=4.5*ld,
                txt="TelNo: %s" % self.ctm_tel)
            self.fpdf.drawText(x=54*cw, y=5.5*ld,
                txt="FaxNo: %s" % self.ctm_fax)
        drm = self.sql.getRec("drsmst", where=[("drm_cono", "=",
            self.opts["conum"]), ("drm_chain", "=", self.chain), ("drm_acno",
            "=", self.acno)], limit=1)
        col = self.sql.drsmst_col
        self.fpdf.drawText(x=22.5*cw, y=10.5*ld, txt=drm[col.index("drm_name")])
        self.fpdf.drawText(x=22.5*cw, y=11.5*ld, txt=drm[col.index("drm_add1")])
        self.fpdf.drawText(x=22.5*cw, y=12.5*ld, txt=drm[col.index("drm_add2")])
        self.fpdf.drawText(x=22.5*cw, y=13.5*ld, txt=drm[col.index("drm_add3")])
        self.fpdf.drawText(x=22.5*cw, y=14.5*ld, txt=drm[col.index("drm_pcod")])
        if self.ctm_b_name:
            dat = "Name:    %s" % self.ctm_b_name
            dat = "%s\nBranch:  %s" % (dat, self.ctm_b_branch)
            dat = "%s\nCode:    %s" % (dat, self.ctm_b_ibt)
            dat = "%s\nAccount: %s\n " % (dat, self.ctm_b_acno)
            self.fpdf.drawText(x=22.5*cw, y=37*ld, txt=dat, ctyp="M")
        self.emadd = CCD(drm[col.index("drm_acc_email")], "TX")
        # Tables
        r1 = {
            "margins": ((22.5, 53), (8, 9)),
            "repeat": (1, 1),
            "rows": [
                [22, 8.5, [[32, 1.5, .8, "Charge To:", False]]],
                [22, 10, [[32, 5.5]]],
                [22, 16, [
                    [9, 1.5, .8, "Acc-Num", True],
                    [20, 1.5, .8, "V.A.T. Number", True],
                    [42, 1.5, .8, "Contact Person", True],
                    [12, 1.5, .8, "Date", True],
                    [11, 1.5, .8, "Inv-Number", True]]],
                [22, 17.5, [
                    [9, 1.5, 0, self.acno, True],
                    [20, 1.5, 0, drm[col.index("drm_vatno")], True],
                    [42, 1.5, 0, drm[col.index("drm_sls")]],
                    [12, 1.5, 0, CCD(self.trdt, "D1", 10).disp, True],
                    [11, 1.5, 0, "%10s" % self.ref]]],
                [22, 19, [
                    [74, 1.5, .8, "Description", False],
                    [7, 1.5, .8, " Tax-%", False],
                    [13, 1.5, .8, "       Value", False]]],
                [22, 20.5, [
                    [74, 12.5],
                    [7, 12.5],
                    [13, 12.5]]],
                [22, 33, [
                    [11, 1.5, .8, "Taxable"],
                    [12, 1.5],
                    [12, 1.5, .8, "Non-Taxable"],
                    [12, 1.5],
                    [11, 1.5, .8, "Total Tax"],
                    [11, 1.5],
                    [12, 1.5, .8, "Total Value"],
                    [13, 1.5]]]]}
        if self.ctm_b_name:
            r1["rows"].extend([
                [22, 35, [[32, 1.5, .8, "Banking Details", False]]],
                [22, 36.5, [[32, 5.5]]]])
        doDrawTable(self.fpdf, r1, cw=cw, ld=ld, font=False)

    def printTotals(self, cw, ld, ica, iva):
        tot = [0, 0, iva.work, ica.work]
        if iva.work:
            tot[0] = float(ASD(ica.work) - ASD(iva.work))
        else:
            tot[1] = ica.work
        self.fpdf.drawText(x=32*cw, y=33.2*ld, txt=CCD(tot[0],"SD",13.2).disp)
        self.fpdf.drawText(x=56*cw, y=33.2*ld, txt=CCD(tot[1],"SD",13.2).disp)
        self.fpdf.drawText(x=78*cw, y=33.2*ld, txt=CCD(tot[2],"SD",13.2).disp)
        self.fpdf.drawText(x=103*cw, y=33.2*ld, txt=CCD(tot[3],"SD",13.2).disp)

    def doPrint(self):
        if not self.fpdf.page:
            return
        if self.df.repeml[1] == "Y":
            self.df.repeml[2] = self.emadd.work
            key = "%s_%s_%s" % (self.opts["conum"], self.chain, self.acno)
        else:
            key = "%s_all_all" % self.opts["conum"]
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
            self.__class__.__name__, key, ext="pdf")
        self.fpdf.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam,
            header="%s Invoice" % self.opts["conam"], repprt=self.df.repprt,
            fromad=self.fromad, repeml=self.df.repeml)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
0
class sl2010(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,
            ["genmst", "gentrn", "wagedc", "wagmst", "waglmf", "wagltf"],
            prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.gc = GetCtl(self.opts["mf"])
        wagctl = self.gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.glint = wagctl["ctw_glint"]
        if self.glint == "Y":
            ctlctl = self.gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            if self.gc.chkRec(self.opts["conum"], ctlctl, ["wag_slc"]):
                return
            self.slnctl = ctlctl["wag_slc"]
        self.bh = Batches(self.opts["mf"],
                          self.opts["conum"],
                          self.opts["conam"],
                          self.opts["period"],
                          "SLN",
                          2,
                          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]
        return True

    def dataHeader(self):
        wgm = {
            "stype":
            "R",
            "tables": ("wagmst", ),
            "cols": (("wgm_empno", "", 0, "EmpNo"), ("wgm_sname", "", 0,
                                                     "Surname", "Y")),
            "where": [("wgm_cono", "=", self.opts["conum"])]
        }
        ced = {
            "stype":
            "R",
            "tables": ("wagedc", ),
            "cols": (("ced_type", "", 0, "T"), ("ced_code", "", 0, "Cde"),
                     ("ced_desc", "", 0, "Description", "Y")),
            "where": [("ced_cono", "=", self.opts["conum"]),
                      ("ced_type", "=", "D")],
            "index":
            1
        }
        fld = ((("T", 0, 0, 0), "OUI", 9, "Batch %s Quantity" % self.bh.batno),
               (("T", 0, 0, 0), "OSD", 13.2,
                "Value"), (("C", 0, 0, 0), "IUI", 5, "EmpNo",
                           "Employee Number", "", "N", self.doEmpno, wgm, None,
                           None), (("C", 0, 0, 1), "ONA", 20,
                                   "Name"), (("C", 0, 0, 2), "OUI", 2, "Ln"),
               (("C", 0, 0,
                 3), "INA", 15, "Description", "", "", "N", self.doDesc, None,
                None, None), (("C", 0, 0, 4), "ID1", 10, "Date", "", "", "N",
                              self.doSdate, None, None, None),
               (("C", 0, 0, 5), "INa", 9, "Ref-No", "Reference Number", "",
                "N", self.doRef, None, None, ("notblank", )),
               (("C", 0, 0, 6), "IUI", 3, "Cde", "Deduction Code", "", "N",
                self.doCode, ced, None, ("notzero", )),
               (("C", 0, 0, 7), "IUD", 6.2, "Intr-%", "Interest Rate", "", "N",
                self.doInt, None, None,
                None), (("C", 0, 0, 8), "IUD", 12.2, "Loan-Amt", "Loan Amount",
                        "", "N", self.doAmt, None, None, ("notzero", )),
               (("C", 0, 0, 9), "IUD", 12.2, "Ded-Amt", "Deduction Amount", "",
                "N", self.doDed, None, None, ("efld", )))
        but = (("Interrogate", None, self.querySln, 0, ("C", 0, 1), ("C", 0,
                                                                     2)), )
        cnd = ((self.endPage, "y"), )
        cxt = (self.exitPage, )
        self.df = TartanDialog(self.opts["mf"],
                               eflds=fld,
                               butt=but,
                               cend=cnd,
                               cxit=cxt)
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)
        self.df.focusField("C", 0, 1)

    def doEmpno(self, frt, pag, r, c, p, i, w):
        self.empno = w
        acc = self.sql.getRec("wagmst",
                              cols=["wgm_sname", "wgm_fname"],
                              where=[("wgm_cono", "=", self.opts["conum"]),
                                     ("wgm_empno", "=", self.empno)],
                              limit=1)
        if not acc:
            return "Invalid Employee Number"
        self.name = "%s, %s" % (acc[0], acc[1].split()[0])
        self.df.loadEntry("C", pag, p + 1, data=self.name)
        self.loan = getNextCode(self.sql,
                                "waglmf",
                                "wlm_loan",
                                where=[("wlm_cono", "=", self.opts["conum"]),
                                       ("wlm_empno", "=", self.empno)],
                                start=1,
                                last=9999999)
        self.df.loadEntry("C", pag, p + 2, data=self.loan)

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

    def doSdate(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.sdate = w

    def doRef(self, frt, pag, r, c, p, i, w):
        self.ref = w

    def doCode(self, frt, pag, r, c, p, i, w):
        self.code = 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"

    def doInt(self, frt, pag, r, c, p, i, w):
        self.rte = w

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

    def doDed(self, frt, pag, r, c, p, i, w):
        self.ded = w

    def endPage(self):
        self.updateTables()
        self.updateBatch()
        self.opts["mf"].dbm.commitDbase()
        self.df.advanceLine(0)

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

    def updateTables(self):
        if self.bh.multi == "Y":
            curdt = int(self.sdate / 100)
        else:
            curdt = self.bh.curdt
        self.sql.insRec("waglmf",
                        data=[
                            self.opts["conum"], self.empno, self.loan,
                            self.desc, self.code, self.rte, self.sdate,
                            self.ded
                        ])
        self.sql.insRec("wagltf",
                        data=[
                            self.opts["conum"], self.empno, self.loan,
                            self.bh.batno, 2, self.sdate, self.ref, self.amt,
                            self.amt, self.ded, self.rte, curdt, self.desc,
                            "N", self.opts["capnm"], self.sysdtw, 0
                        ])
        if self.glint == "N":
            return
        # General Ledger Staff Loans Control Account
        data = (self.opts["conum"], self.slnctl, curdt, self.sdate, 2,
                self.ref, self.bh.batno, self.amt, 0.00, self.name, "N", "", 0,
                self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        amt = float(ASD(0) - ASD(self.amt))
        # General Ledger Bank Account
        data = (self.opts["conum"], self.bh.acc, curdt, self.sdate, 2,
                self.ref, self.bh.batno, amt, 0.00,
                "Staff Loan - %s" % self.name, "N", "", 0, self.opts["capnm"],
                self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)

    def updateBatch(self):
        self.bh.batqty = self.bh.batqty + 1
        self.bh.batval = float(ASD(self.bh.batval) + ASD(self.amt))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

    def querySln(self):
        callModule(self.opts["mf"],
                   self.df,
                   "sl4010",
                   coy=(self.opts["conum"], self.opts["conam"]),
                   period=None,
                   user=self.opts["capnm"])
Esempio n. 19
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"])
Esempio n. 20
0
class sl2020(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,
                       ["genmst", "gentrn", "wagmst", "waglmf", "wagltf"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        self.col = self.sql.waglmf_col
        gc = GetCtl(self.opts["mf"])
        wagctl = gc.getCtl("wagctl", self.opts["conum"])
        if not wagctl:
            return
        self.glint = wagctl["ctw_glint"]
        if self.glint == "Y":
            ctlctl = gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = ["wag_slc", "wag_sli"]
            if gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.glctls = (ctlctl["wag_slc"], ctlctl["wag_sli"])
        else:
            self.glctls = None
        self.batchHeader()
        if not self.bh.batno:
            return
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        return True

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

    def dataHeader(self):
        wgm = {
            "stype":
            "R",
            "tables": ("wagmst", ),
            "cols": (("wgm_empno", "", 0, "EmpNo"),
                     ("wgm_sname", "", 0, "Surname", "Y"), ("wgm_fname", "", 0,
                                                            "Names")),
            "where": [("wgm_cono", "=", self.opts["conum"])]
        }
        lnm = {
            "stype":
            "R",
            "tables": ("waglmf", ),
            "cols": (("wlm_loan", "", 0, "Ln"), ("wlm_desc", "", 0,
                                                 "Description", "Y")),
            "where": [("wlm_cono", "=", self.opts["conum"])],
            "whera": (("C", "wlm_empno", 0), ),
            "index":
            0
        }
        typ = {
            "stype":
            "C",
            "titl":
            "Transaction Types",
            "head": ("C", "Description"),
            "data": ((1, "Interest Adjustment"), (3, "Further Advance"),
                     (4, "Loan Repayment"), (5, "Loan Adjustment")),
            "index":
            0
        }
        glm = {
            "stype":
            "R",
            "tables": ("genmst", ),
            "cols": (("glm_acno", "", 0, "Acc-Num"), ("glm_desc", "", 0,
                                                      "Description", "Y")),
            "where": [("glm_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", 5, "EmpNo", "Employee Number", "", "N",
                self.doEmp, wgm, None, None),
               (("C", 1, 0, 1), "ONA", 10, "Name"),
               (("C", 1, 0, 2), "IUI", 2, "Ln", "Loan Number", "", "N",
                self.doLoan, lnm, None, ("notzero", )),
               (("C", 1, 0, 3), "ONA", 10, "Descript", "Description", "", "N",
                None, None, None, None),
               (("C", 1, 0, 4), "ID1", 10, "Trans-Date", "Transaction Date",
                self.sysdtw, "N", self.doTrdate, None, None, None),
               (("C", 1, 0, 5), "IUI", 1, "T", "Transaction Type", "", "N",
                self.doTyp, typ, None, ("in", (1, 3, 4, 5))),
               (("C", 1, 0, 6), "INa", 9, "Reference", "Reference Number", "i",
                "N", self.doRef, None, None, ("notblank", )),
               (("C", 1, 0, 7), "IUD", 6.2, "Intr-%", "New Interest Rate", "",
                "N", self.doPer, None, None, None),
               (("C", 1, 0, 8), "ISD", 13.2, "Interest",
                "Interest (Adds to interest raised)", "", "Y", self.doInt,
                None, None, ("notzero", )),
               (("C", 1, 0, 9), "ISD", 13.2, "Amount",
                "Amount (Adds to advances or payments)", "", "Y", self.doPay,
                None, None, ("notzero", )),
               (("C", 1, 0, 10), "IUD", 9.2, "Deduct",
                "Deduction Amount (New total deduction)", "", "Y", self.doDed,
                None, None, ("efld", ))]
        if 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.querySln, 0, ("C", 1, 1), ("C", 1,
                                                                     2))]
        tag = [("Transaction", None, None, None, False)]
        cnd = [(None, "n"), (self.endPage1, "y")]
        cxt = [None, self.exitPage1]
        if self.glint == "Y":
            but.append(
                ("Cancel", None, self.doCancel, 0, ("C", 2, 1), ("C", 1, 1)))
            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 doEmp(self, frt, pag, r, c, p, i, w):
        self.empno = w
        acc = self.sql.getRec("wagmst",
                              cols=["wgm_sname"],
                              where=[("wgm_cono", "=", self.opts["conum"]),
                                     ("wgm_empno", "=", self.empno)],
                              limit=1)
        if not acc:
            return "Invalid Employee Number"
        self.name = acc[0]
        self.df.loadEntry("C", pag, p + 1, data=self.name)
        chk = self.sql.getRec("waglmf",
                              where=[("wlm_cono", "=", self.opts["conum"]),
                                     ("wlm_empno", "=", self.empno)])
        if len(chk) == 1:
            self.acc = chk[0]
            self.loan = self.acc[self.col.index("wlm_loan")]
            desc = self.acc[self.col.index("wlm_desc")]
            self.df.loadEntry("C", pag, p + 2, data=self.loan)
            self.df.loadEntry("C", pag, p + 3, data=desc)
            return "sk3"

    def doLoan(self, frt, pag, r, c, p, i, w):
        self.loan = w
        self.acc = self.sql.getRec("waglmf",
                                   where=[("wlm_cono", "=",
                                           self.opts["conum"]),
                                          ("wlm_empno", "=", self.empno),
                                          ("wlm_loan", "=", self.loan)],
                                   limit=1)
        if not self.acc:
            return "Invalid Loan Number"
        desc = self.acc[self.col.index("wlm_desc")]
        self.df.loadEntry("C", pag, p + 1, data=desc)

    def doTrdate(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.trdate = w

    def doTyp(self, frt, pag, r, c, p, i, w):
        self.typ = w

    def doRef(self, frt, pag, r, c, p, i, w):
        self.ref = w
        per = self.acc[self.col.index("wlm_rate")]
        self.df.loadEntry("C", pag, p + 1, data=per)

    def doPer(self, frt, pag, r, c, p, i, w):
        self.per = w
        if self.typ in (3, 4, 5):
            self.intp = 0
            return "sk1"

    def doInt(self, frt, pag, r, c, p, i, w):
        self.intp = w
        self.pay = 0
        self.ded = 0
        return "sk2"

    def doPay(self, frt, pag, r, c, p, i, w):
        self.pay = w
        amt = self.acc[self.col.index("wlm_repay")]
        self.df.loadEntry("C", pag, p + 1, data=amt)

    def doDed(self, frt, pag, r, c, p, i, w):
        self.ded = w

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

    def updateTables1(self):
        if self.bh.multi == "Y":
            self.curdt = int(self.trdate / 100)
        else:
            self.curdt = self.bh.curdt
        if self.typ == 1:
            self.glt = 4
            desc = "Interest Adj"
            self.val = self.intp
            ded = self.acc[self.col.index("wlm_repay")]
            cap = 0.00
        elif self.typ == 3:
            self.glt = 2
            desc = "Advance"
            self.val = self.pay
            ded = self.ded
            cap = self.val
        elif self.typ == 4:
            self.glt = 6
            desc = "Repayment"
            self.val = float(ASD(0) - ASD(self.pay))
            ded = self.ded
            cap = 0.00
        elif self.typ == 5:
            self.glt = 4
            desc = "Adjustment"
            self.val = self.pay
            ded = self.ded
            cap = 0.00
        self.sql.updRec("waglmf",
                        cols=["wlm_rate", "wlm_repay"],
                        data=[self.per, ded],
                        where=[("wlm_cono", "=", self.opts["conum"]),
                               ("wlm_empno", "=", self.empno),
                               ("wlm_loan", "=", self.loan)])
        self.sql.insRec("wagltf",
                        data=[
                            self.opts["conum"], self.empno, self.loan,
                            self.bh.batno, self.typ, self.trdate, self.ref,
                            self.val, cap, ded, self.per, self.curdt, desc,
                            "N", self.opts["capnm"], self.sysdtw, 0
                        ])
        if self.glint == "N":
            return
        # General Ledger Staff Loans Control Account
        data = (self.opts["conum"], self.glctls[0], self.curdt, self.trdate,
                self.glt, self.ref, self.bh.batno, self.val, 0.00, self.name,
                "N", "", 0, self.opts["capnm"], self.sysdtw, 0)
        self.sql.insRec("gentrn", data=data)
        self.val = float(ASD(0) - ASD(self.val))
        if self.typ == 1:
            # General Ledger Interest Received
            data = (self.opts["conum"], self.glctls[1], self.curdt,
                    self.trdate, self.glt, self.ref, self.bh.batno, self.val,
                    0.00, "Staff Loan - %s" % self.name, "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 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.val) - 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((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.val:
            self.opts["mf"].dbm.commitDbase()
            self.df.clearFrame("C", 2)
            self.df.selPage("Transaction")
            self.df.advanceLine(1)
        else:
            bal = float(ASD(self.val) - ASD(self.allocated))
            self.df.loadEntry("T", 2, 0, data=bal)
            self.df.advanceLine(2)

    def updateTables2(self):
        # General Ledger Transaction (Source)
        data = (self.opts["conum"], self.genacc, self.curdt, self.trdate,
                self.glt, self.ref, self.bh.batno, self.allamt, 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 = self.bh.batqty - 1
            self.bh.batval = float(ASD(self.bh.batval) - ASD(self.val))
        else:
            self.batupd = True
            self.bh.batqty = self.bh.batqty + 1
            self.bh.batval = float(ASD(self.bh.batval) + ASD(self.val))
        self.df.loadEntry("T", 0, 0, data=self.bh.batqty)
        self.df.loadEntry("T", 0, 1, data=self.bh.batval)

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