Пример #1
0
class rc2010(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", "genmst", "gentrn",
            "rcaowm", "rcaowt", "rcaprm", "rcatnm", "rcacon", "rcatnt"
        ]
        self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        ctlmst = gc.getCtl("ctlmst", self.opts["conum"])
        if not ctlmst:
            return
        self.taxdf = ctlmst["ctm_taxdf"]
        rcactl = gc.getCtl("rcactl", self.opts["conum"])
        if not rcactl:
            return
        self.glint = rcactl["cte_glint"]
        self.ch1 = ((rcactl["cte_lme"] // 100) * 100) + 1
        self.ch2 = projectDate(self.ch1, 2, typ="months")
        if self.glint == "Y":
            self.glbnk = rcactl["cte_glbnk"]
            ctlctl = gc.getCtl("ctlctl", self.opts["conum"])
            if not ctlctl:
                return
            ctls = [
                "rca_com", "rca_dep", "rca_fee", "rca_orx", "rca_own",
                "rca_tnt", "rca_trx", "vat_ctl"
            ]
            if gc.chkRec(self.opts["conum"], ctlctl, ctls):
                return
            self.rcacom = ctlctl["rca_com"]
            self.rcadep = ctlctl["rca_dep"]
            self.rcafee = ctlctl["rca_fee"]
            self.rcaorx = ctlctl["rca_orx"]
            self.rcaown = ctlctl["rca_own"]
            self.rcatnt = ctlctl["rca_tnt"]
            self.rcatrx = ctlctl["rca_trx"]
            self.convat = ctlctl["vat_ctl"]
        t = time.localtime()
        self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2]
        self.batno = "R%04i%02i" % (t[0], t[1])
        return True

    def drawDialog(self):
        # Transaction Types
        typ = {
            "stype": "C",
            "titl": "Select the Required Type",
            "head": ("C", "Type"),
            "data": []
        }
        # Movement Types
        data = []
        for x in range(1, len(rcmvtp) + 1):
            data.append((x, rcmvtp[x - 1][1]))
        mov = {
            "stype": "C",
            "titl": "Select the Required Type",
            "head": ("C", "Type"),
            "data": data
        }
        # Premises
        prm = {
            "stype":
            "R",
            "tables": ("rcaprm", "rcaowm"),
            "cols":
            (("rcp_owner", "", 0, "Owner"), ("rom_name", "", 0, "Owner"),
             ("rcp_code", "", 0, "Prm-Cod"), ("rcp_addr1", "", 0,
                                              "Address-Line-1")),
            "where": [("rcp_cono", "=", self.opts["conum"]),
                      ("rom_cono=rcp_cono", ), ("rom_acno=rcp_owner", )],
            "index":
            2
        }
        # Tenant
        tnm = {
            "stype":
            "R",
            "tables": ("rcatnm", ),
            "cols": (("rtn_acno", "", 0, "Acc-Num"), ("rtn_name", "", 0,
                                                      "Description", "Y")),
            "where": [("rtn_cono", "=", self.opts["conum"])],
            "whera": [("T", "rtn_owner", 0, 1)]
        }
        # Contract
        con = {
            "stype":
            "R",
            "tables": ("rcacon", ),
            "cols": (("rcc_cnum", "", 0, "Seq"), ("rcc_payind", "", 0, "F"),
                     ("rcc_start", "", 0, "Start-Date"),
                     ("rcc_period", "", 0, "Per"), ("rcc_status", "", 0, "S")),
            "where": [("rcc_cono", "=", self.opts["conum"])],
            "whera": [("T", "rcc_owner", 0, 1), ("T", "rcc_code", 0, 0),
                      ("T", "rcc_acno", 0, 2)]
        }
        # VAT Records
        vtm = {
            "stype":
            "R",
            "tables": ("ctlvmf", ),
            "cols": (("vtm_code", "", 0, "C"), ("vtm_desc", "", 0,
                                                "Description", "Y")),
            "where": [("vtm_cono", "=", self.opts["conum"])]
        }
        tag = (
            (
                "Owner",
                None,
                (("T", 2, 1), ("C", 2, 1)),  # On
                (("C", 1, 1), ("T", 2, 2), ("C", 2, 2))),  # Off
            (
                "Tenant",
                None,
                ("C", 1, 1),  # On
                (("C", 1, 2), ("T", 2, 1), ("C", 2, 1))),  # Off
            ("Allocation", self.doAllocation, None, None))
        fld = [
            (("T", 0, 0, 0), "INA", 7, "Prm-Cod", "Premises Code", "", "Y",
             self.doPrmCod, prm, None, None),
            (("T", 0, 0, 0), "ONA", 30, "Description"),
            (("T", 1, 0, 0), "ONA", 7, "Acc-Num"),
            (("T", 1, 0, 0), "ONA", 30, "Name"),
            (("T", 1, 0, 0), "OSD", 11.2, "Payable"),
            (("C", 1, 0, 0), "INa", 9, "Reference", "Reference Number", "i",
             "Y", self.doOwnRef, None, None, ("notblank", )),
            (("C", 1, 0, 1), "ID1", 10, "Date", "Transaction Date", "r", "N",
             self.doOwnDat, None, None, ("efld", )),
            (("C", 1, 0, 2), "IUI", 1, "T", "Transaction Type", "r", "N",
             self.doOwnTyp, typ, None, ("notzero", )),
            (("C", 1, 0, 3), "ISD", 11.2, "Amount", "Transaction Amount", "",
             "N", self.doOwnAmt, None, None, None),
            (("C", 1, 0, 4), "IUA", 1, "V", "V.A.T Code", "N", "N",
             self.doOwnCod, vtm, None, ("efld", )),
            (("C", 1, 0, 5), "ISD", 11.2, "V.A.T", "V.A.T Amount", "", "N",
             self.doOwnVat, None, None, None),
            (("C", 1, 0, 6), "INA", 47, "Details", "Transaction Details", "",
             "N", self.doOwnDet, None, None, None),
            (("T", 2, 0, 0), "INA", 7, "Acc-Num", "Account Number", "", "Y",
             self.doAccNum, tnm, None, None),
            (("T", 2, 0, 0), "ONA", 30, "Name"),
            (("T", 2, 0, 0), "IUI", 3, "Seq", "Contract Number", "", "N",
             self.doConSeq, con, None, None),
            (("T", 2, 0, 0), "OSD", 11.2, "Balance"),
            (("C", 2, 0, 0), "INa", 9, "Reference", "Reference Number", "i",
             "Y", self.doTntRef, None, None, ("notblank", )),
            (("C", 2, 0, 1), "ID1", 10, "Date", "Transaction Date", "r", "N",
             self.doTntDat, None, None, ("efld", )),
            (("C", 2, 0, 2), "IUI", 1, "T", "Transaction Type", "r", "N",
             self.doTntTyp, typ, None, ("notzero", )),
            (("C", 2, 0, 3), "ISD", 11.2, "Amount", "Transaction Amount", "",
             "N", self.doTntAmt, None, None, None),
            (("C", 2, 0, 4), "INA", (60, 30), "Details", "Transaction Details",
             "", "N", self.doTntDet, None, None, None),
            (("T", 3, 0, 0), "OSD", 11.2, "Rentals     "),
            (("T", 3, 0, 0), "OSD", 11.2, "Deposit     "),
            (("T", 3, 0, 0), "OSD", 11.2, "Fees        "),
            (("T", 3, 1, 0), "OSD", 11.2, "Services (O)"),
            (("T", 3, 1, 0), "OSD", 11.2, "Services (A)"),
            (("T", 3, 1, 0), "OSD", 11.2, "Repairs     "),
            (("T", 3, 2, 0), "OSD", 11.2, "Allocation"),
            (("C", 3, 0, 0), "IUI", 1, "M", "Movement Type", "", "Y",
             self.doAllMov, mov, None, ("between", 1, 6)),
            (("C", 3, 0, 1), "ISD", 11.2, "Amount", "Allocation Amount", "",
             "N", self.doAllAmt, None, None, None),
            (("C", 3, 0, 2), "IUA", 1, "V", "V.A.T Code", "N", "N",
             self.doAllCod, vtm, None, ("efld", )),
            (("C", 3, 0, 3), "ISD", 11.2, "V.A.T", "V.A.T Amount", "", "N",
             self.doAllVat, None, None, None),
            (("C", 3, 0, 4), "INA", (50, 30), "Details", "Transaction Details",
             "", "N", self.doAllDet, None, None, None)
        ]
        row = [0, 4, 4, 10]
        tnd = [(self.endPage, "y"), (self.endPage, "y"), (self.endPage, "y"),
               (self.endPage, "y")]
        txt = [self.exitPage, self.exitPage, self.exitPage, self.exitPage]
        cnd = [(None, "n"), (self.endPage, "y"), (self.endPage, "y"),
               (self.endPage, "y")]
        cxt = [None, self.exitPage, self.exitPage, self.exitPage]
        but = (("Notes", None, self.allNotes, 0, ("T", 0, 0), ("T", 0, 1)),
               ("Statement", None, self.allStmnt, 0,
                (("C", 1, 1), ("C", 2, 1)), (("T", 0, 1), ("T", 2, 1))),
               ("Cancel", None, self.doAllCancel, 0, ("C", 3, 1), ("C", 2, 1)))
        self.df = TartanDialog(self.opts["mf"],
                               tags=tag,
                               eflds=fld,
                               rows=row,
                               tend=tnd,
                               txit=txt,
                               cend=cnd,
                               cxit=cxt,
                               butt=but)

    def doPrmCod(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec(
            "rcaprm",
            cols=["rcp_desc", "rcp_owner", "rcp_crate", "rcp_addr1"],
            where=[("rcp_cono", "=", self.opts["conum"]),
                   ("rcp_code", "=", w)],
            limit=1)
        if not acc:
            return "Invalid Premises Code"
        self.code = w
        desc, self.owner, self.crate, addr1 = acc
        if desc:
            self.df.loadEntry(frt, pag, p + 1, data=desc)
        else:
            self.df.loadEntry(frt, pag, p + 1, data=addr1)
        acc = self.sql.getRec("rcaowm",
                              cols=["rom_name", "rom_vatdf"],
                              where=[("rom_cono", "=", self.opts["conum"]),
                                     ("rom_acno", "=", self.owner)],
                              limit=1)
        if not acc:
            return "Missing Owner Record (%s)" % self.owner
        self.df.loadEntry("T", 1, 0, data=self.owner)
        self.df.loadEntry("T", 1, 1, data=acc[0])
        self.vatdf = acc[1]
        self.acno = None

    def doAccNum(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("rcatnm",
                              cols=["rtn_name"],
                              where=[("rtn_cono", "=", self.opts["conum"]),
                                     ("rtn_owner", "=", self.owner),
                                     ("rtn_code", "=", self.code),
                                     ("rtn_acno", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Account Number"
        self.acno = w
        self.name = acc[0]
        self.df.loadEntry(frt, pag, p + 1, data=self.name)
        con = self.sql.getRec("rcacon",
                              where=[("rcc_cono", "=", self.opts["conum"]),
                                     ("rcc_owner", "=", self.owner),
                                     ("rcc_code", "=", self.code),
                                     ("rcc_acno", "=", self.acno)],
                              order="rcc_cnum")
        if not con:
            return "No Valid Contracts"
        self.cnum = con[-1:][0][self.sql.rcacon_col.index("rcc_cnum")]
        self.df.topf[2][2][5] = self.cnum

    def doConSeq(self, frt, pag, r, c, p, i, w):
        con = self.sql.getRec("rcacon",
                              where=[("rcc_cono", "=", self.opts["conum"]),
                                     ("rcc_code", "=", self.code),
                                     ("rcc_acno", "=", self.acno),
                                     ("rcc_cnum", "=", w)],
                              order="rcc_cnum")
        if not con:
            return "Invalid Contract Sequence"
        self.cnum = w
        self.showTenantBalance()

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

    def doOwnDat(self, frt, pag, r, c, p, i, w):
        if w < self.ch1 or w > self.ch2:
            ov = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="RCA",
                            code="DateOver")
            if ov.flag == "no":
                return "Invalid Date (< %s or > %s)" % (self.ch1, self.ch2)
        self.trndat = w
        data = []
        for x in range(2, len(rctrtp) + 1):
            data.append((x, rctrtp[x - 1][1]))
        self.df.colf[1][2][8]["data"] = data

    def doOwnTyp(self, frt, pag, r, c, p, i, w):
        if w not in (2, 3, 4):
            return "Invalid Transaction Type"
        self.trntyp = w

    def doOwnAmt(self, frt, pag, r, c, p, i, w):
        if self.trntyp == 3 and w > self.due:
            op = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="RCA",
                            code="Overpaid")
            if op.flag == "no":
                return "Overpaid"
        self.trnamt = w
        # Ignore VAT at this stage
        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 doOwnCod(self, frt, pag, r, c, p, i, w):
        pass

    #    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 doOwnVat(self, frt, pag, r, c, p, i, w):
        pass

    #    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 doOwnDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w

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

    def doTntDat(self, frt, pag, r, c, p, i, w):
        if w < self.ch1 or w > self.ch2:
            ov = PwdConfirm(self.opts["mf"],
                            conum=self.opts["conum"],
                            system="RCA",
                            code="DateOver")
            if ov.flag == "no":
                return "Invalid Date (< %s or > %s)" % (self.ch1, self.ch2)
        self.trndat = w
        data = []
        for x in range(1, len(rctrtp) + 1):
            data.append((x, rctrtp[x - 1][1]))
        self.df.colf[2][2][8]["data"] = data

    def doTntTyp(self, frt, pag, r, c, p, i, w):
        if w not in (1, 2, 3, 4):
            return "Invalid Transaction Type"
        self.trntyp = w

    def doTntAmt(self, frt, pag, r, c, p, i, w):
        self.trnamt = w
        if self.trntyp == 1:
            # Rental Raised
            self.vatcode = self.vatdf
            vrte = getVatRate(self.sql, self.opts["conum"], self.vatcode,
                              self.trndat)
            if vrte is None:
                vrte = 0.0
            self.trnvat = round((w * vrte / (vrte + 100)), 2)
            self.df.loadEntry(frt, pag, p + 1, data="Rental Raised")
        else:
            # Ignore VAT at this stage
            self.vatcode = ""
            self.trnvat = 0

    def doTntDet(self, frt, pag, r, c, p, i, w):
        self.trndet = w

    def doAllocation(self):
        self.df.setWidget(self.df.B1, state="normal")

    def doAllMov(self, frt, pag, r, c, p, i, w):
        if w == 2 and self.trntyp not in (2, 3):
            return "Deposits Only Allowed for Receipts and Payments"
        self.allmov = w

    def doAllAmt(self, frt, pag, r, c, p, i, w):
        if not w:
            self.allamt = float(ASD(self.trnamt) - ASD(self.alltot))
            self.df.loadEntry(frt, pag, p, data=self.allamt)
        else:
            self.allamt = w
        if self.allmov == 2:
            # Deposit
            self.allcod = ""
            self.df.loadEntry(frt, pag, p + 1, data=self.allcod)
            self.allvat = 0
            self.df.loadEntry(frt, pag, p + 2, data=self.allvat)
            return "sk2"
        if self.trntyp in (2, 3):
            # Receipt or Payment
            self.df.loadEntry(frt, pag, p + 1, self.vatdf)
        if self.trntyp == 4 and self.allmov == 3:
            # Journal Fee
            self.df.loadEntry(frt, pag, p + 1, self.taxdf)
        else:
            self.allcod = ""
            self.allvat = 0

    def doAllCod(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.allcod = w
        self.allvat = round((self.allamt * vrte / (vrte + 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.trndet)
            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.trndet)

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

    def doAllCancel(self):
        self.allocs = []
        self.df.clearFrame("C", 3)
        self.df.setWidget(self.df.B1, state="disabled")
        self.df.selPage("Tenant")
        self.df.clearLine(2, int((self.df.last[2][1] - 1) / self.df.colq[2]),
                          "Y")

    def endPage(self):
        if self.df.frt == "T" and self.df.pag == 0:
            self.df.focusField("C", 1, 1)
        elif self.df.frt == "C" and self.df.pag == 1:
            # Owners
            self.updateTables()
            self.df.advanceLine(self.df.pag)
        elif self.df.frt == "T" and self.df.pag == 2:
            self.df.focusField("C", 2, 1)
        elif self.df.frt == "C" and self.df.pag == 2:
            # Tenants
            self.allocs = []
            self.alltot = 0.0
            if self.trntyp == 1:
                self.movtyp = 1
                self.updateTables()
                self.df.advanceLine(self.df.pag)
            else:
                self.df.selPage("Allocation")
                dpp = 0.0
                acc = self.sql.getRec("rcacon",
                                      cols=["rcc_deposit"],
                                      where=[("rcc_cono", "=",
                                              self.opts["conum"]),
                                             ("rcc_owner", "=", self.owner),
                                             ("rcc_code", "=", self.code),
                                             ("rcc_acno", "=", self.acno)],
                                      order="rcc_cnum")
                if acc:
                    dpo = acc[-1:][0][0]
                else:
                    dpo = 0.0
                dat = self.sql.getRec(
                    "rcatnt",
                    cols=["rtu_mtyp", "round(sum(rtu_tramt), 2)"],
                    where=[("rtu_cono", "=", self.opts["conum"]),
                           ("rtu_owner", "=", self.owner),
                           ("rtu_code", "=", self.code),
                           ("rtu_acno", "=", self.acno)],
                    group="rtu_mtyp",
                    order="rtu_mtyp")
                if dat:
                    for d in dat:
                        if d[0] == 2:
                            dpp = d[1]
                        else:
                            self.df.loadEntry("T", 3, d[0] - 1, data=d[1])
                dpo = float(ASD(dpo) + ASD(dpp))
                if dpo:
                    self.df.loadEntry("T", 3, 1, data=dpo)
                self.df.loadEntry("T", 3, 6, data=self.trnamt)
                self.df.focusField("C", 3, 1)
        else:
            # Allocations
            self.allocs.append(
                [self.allmov, self.allamt, self.allcod, self.allvat])
            self.alltot = float(ASD(self.alltot) + ASD(self.allamt))
            bal = float(ASD(self.trnamt) - ASD(self.alltot))
            if bal:
                pos = self.allmov - 1
                if self.trntyp == 2:
                    a = float(
                        ASD(self.df.t_work[3][0][pos]) - ASD(self.allamt))
                else:
                    a = float(
                        ASD(self.df.t_work[3][0][pos]) + ASD(self.allamt))
                self.df.loadEntry("T", 3, pos, data=a)
                self.df.loadEntry("T", 3, 6, data=bal)
                self.df.advanceLine(3)
            else:
                for line in self.allocs:
                    self.movtyp, self.trnamt, self.vatcode, self.trnvat = line
                    self.updateTables()
                self.df.clearFrame("C", 3)
                self.df.selPage("Tenant")
                self.df.advanceLine(2)
        self.showOwnerTrans()
        if self.acno:
            self.showTenantTrans()

    def showOwnerTrans(self):
        whr = [("rot_cono", "=", self.opts["conum"]),
               ("rot_acno", "=", self.owner)]
        tot = self.sql.getRec("rcaowt",
                              cols=["round(sum(rot_tramt),2)"],
                              where=[("rot_cono", "=", self.opts["conum"]),
                                     ("rot_acno", "=", self.owner)],
                              limit=1)
        if not tot or not tot[0]:
            self.due = 0
        else:
            self.due = float(ASD(0) - ASD(tot[0]))
        arr = self.sql.getRec("rcatnt",
                              cols=["round(sum(rtu_tramt),2)"],
                              where=[("rtu_cono", "=", self.opts["conum"]),
                                     ("rtu_owner", "=", self.owner),
                                     ("rtu_mtyp", "in", (1, 4))],
                              limit=1)
        if arr and arr[0]:
            self.due = float(ASD(self.due) - ASD(arr[0]))
        self.df.loadEntry("T", 1, 2, data=self.due)
        tab = ["rcaowt"]
        col = [
            "rot_trdt", "rot_type", "rot_refno", "rot_desc", "rot_tramt",
            "rot_taxamt"
        ]
        whr = [("rot_cono", "=", self.opts["conum"]),
               ("rot_acno", "=", self.owner)]
        odr = "rot_trdt, rot_type, rot_refno"
        dat = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr)
        data = []
        bals = 0
        for d in dat:
            bals = float(ASD(bals) + ASD(d[4]))
            data.append(d + [bals])
        col = (("rot_trdt", "Trans-Date", 10, "D1",
                "N"), ("rot_type", "Typ", 3, ("XX", rctrtp),
                       "N"), ("rot_refno", "Reference", 9, "Na",
                              "N"), ("rot_desc", "Details", 39, "NA", "N"),
               ("rot_tramt", "Amount", 11.2, "SD",
                "N"), ("rot_taxamt", "VAT-Amount", 11.2, "SD",
                       "N"), ("balance", "Balance", 15.2, "SD", "N"))
        try:
            self.otrn.closeProcess()
        except:
            pass
        self.otrn = SelectChoice(self.df.topPage1,
                                 None,
                                 col,
                                 data,
                                 wait=False,
                                 neww=False,
                                 butt=False,
                                 sort=False,
                                 live=False,
                                 modal=False,
                                 lines=9)

    def showTenantTrans(self):
        tab = ["rcatnt"]
        col = [
            "rtu_trdt", "rtu_type", "rtu_refno", "rtu_desc", "rtu_mtyp",
            "rtu_tramt", "rtu_taxamt"
        ]
        whr = [("rtu_cono", "=", self.opts["conum"]),
               ("rtu_owner", "=", self.owner), ("rtu_code", "=", self.code),
               ("rtu_acno", "=", self.acno)]
        odr = "rtu_trdt, rtu_type, rtu_refno, rtu_mtyp"
        dat = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr)
        data = []
        bals = 0
        for d in dat:
            bals = float(ASD(bals) + ASD(d[5]))
            data.append(d + [bals])
        col = (("rtu_trdt", "Trans-Date", 10, "D1",
                "N"), ("rtu_type", "Typ", 3, ("XX", rctrtp),
                       "N"), ("rtu_refno", "Reference", 9, "Na",
                              "N"), ("rtu_desc", "Details", 35, "NA", "N"),
               ("rtu_mtyp", "Mov", 3, ("XX", rcmvtp),
                "N"), ("rtu_tramt", "Amount", 11.2, "SD",
                       "N"), ("rtu_taxamt", "VAT-Amount", 11.2, "SD",
                              "N"), ("balance", "Balance", 15.2, "SD", "N"))
        try:
            self.ttrn.closeProcess()
        except:
            pass
        self.ttrn = SelectChoice(self.df.topPage2,
                                 None,
                                 col,
                                 data,
                                 wait=False,
                                 neww=False,
                                 butt=False,
                                 sort=False,
                                 live=False,
                                 modal=False,
                                 lines=9)

    def showTenantBalance(self):
        bal = self.sql.getRec("rcatnt",
                              cols=["round(sum(rtu_tramt),2)"],
                              where=[("rtu_cono", "=", self.opts["conum"]),
                                     ("rtu_owner", "=", self.owner),
                                     ("rtu_code", "=", self.code),
                                     ("rtu_acno", "=", self.acno),
                                     ("rtu_cnum", "=", self.cnum),
                                     ("rtu_mtyp", "<>", 2)],
                              limit=1)
        self.df.loadEntry("T", 2, 3, data=bal[0])

    def updateTables(self):
        curdt = int(self.trndat / 100)
        amt = self.trnamt
        vat = self.trnvat
        if self.trntyp in (1, 4):
            # Rental and Journal
            gltyp = 4
        elif self.trntyp == 2:
            # Receipt
            gltyp = 6
            bnk = amt
            amt = float(ASD(0) - ASD(amt))
            vat = float(ASD(0) - ASD(vat))
        elif self.trntyp == 3:
            # Payment
            gltyp = 2
            bnk = float(ASD(0) - ASD(amt))
        if self.df.pag == 1:
            # Owners Transaction
            accod = self.owner
            data = [
                self.opts["conum"], self.owner, self.trntyp, self.trnref,
                self.batno, self.trndat, amt, vat, curdt, self.trndet,
                self.vatcode, "", self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("rcaowt", data=data)
            if self.glint == "Y":
                # General Ledger Transaction for Owner Control
                gld = "%7s %s" % (self.owner, self.trndet[:22])
                data = [
                    self.opts["conum"], self.rcaown, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, amt, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
        else:
            # Tenants Transaction
            accod = self.code
            data = [
                self.opts["conum"], self.owner, self.code, self.acno,
                self.cnum, self.trntyp, self.trnref, self.batno, self.trndat,
                self.movtyp, amt, vat, curdt, self.trndet, self.vatcode, "",
                self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("rcatnt", data=data)
            if self.glint == "Y":
                gld = "%7s %7s %7s" % (self.owner, self.code, self.acno)
                if self.df.pag == 3 and self.movtyp == 2:
                    # General Ledger Transaction for Deposit Control
                    acc = self.rcadep
                else:
                    # General Ledger Transaction for Tenant Control
                    acc = self.rcatnt
                data = [
                    self.opts["conum"], acc, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, amt, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            self.showTenantBalance()
        if self.trntyp in (2, 3):
            if self.glint == "Y":
                # General Ledger Transaction for Bank Account
                data = [
                    self.opts["conum"], self.glbnk, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, bnk, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            return
        if self.df.pag == 1 and self.df.pag == 1:
            # Owners Journal Entries (Unallocated)
            if self.glint == "Y":
                amt = float(ASD(0) - ASD(amt))
                data = [
                    self.opts["conum"], self.rcaorx, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, amt, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            return
        if self.df.pag == 2 and self.movtyp == 1:
            # Rental and Commission Raised
            rta = float(ASD(0) - ASD(amt))
            rtv = float(ASD(0) - ASD(vat))
            des = "Rental on %s Premises" % self.code
            data = [
                self.opts["conum"], self.owner, self.trntyp, self.trnref,
                self.batno, self.trndat, rta, rtv, curdt, des, self.vatcode,
                "", self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("rcaowt", data=data)
            if self.glint == "Y":
                # General Ledger Transaction for Owner Control
                gld = "%7s Rental on %7s" % (self.owner, self.code)
                data = [
                    self.opts["conum"], self.rcaown, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, rta, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            if self.crate:
                # If there is a Commission Rate on the Premises Record
                cma = float(ASD(0) - ASD(round((rta * self.crate / 100.0), 2)))
                vrte = getVatRate(self.sql, self.opts["conum"], self.taxdf,
                                  self.trndat)
                if vrte is None:
                    vrte = 0.0
                cmv = round((cma * vrte / 100.0), 2)
                cmt = float(ASD(cma) + ASD(cmv))
                cma = float(ASD(0) - ASD(cma))
                tax = float(ASD(0) - ASD(cmv))
                des = "Commission @ %3.5s%s Inclusive" % (self.crate, "%")
                data = [
                    self.opts["conum"], self.owner, 4, self.trnref, self.batno,
                    self.trndat, cmt, cmv, curdt, des, self.vatdf, "",
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("rcaowt", data=data)
                if self.glint == "Y":
                    # Update Owner Control
                    gld = "%7s Commission Raised" % self.owner
                    data = [
                        self.opts["conum"], self.rcaown, curdt, self.trndat,
                        gltyp, self.trnref, self.batno, cmt, 0, gld, "", "", 0,
                        self.opts["capnm"], self.sysdtw, 0
                    ]
                    self.sql.insRec("gentrn", data=data)
                    # Update Commission Account
                    data = [
                        self.opts["conum"], self.rcacom, curdt, self.trndat,
                        gltyp, self.trnref, self.batno, cma, tax, gld, "", "",
                        0, self.opts["capnm"], self.sysdtw, 0
                    ]
                    self.sql.insRec("gentrn", data=data)
                if self.taxdf:
                    # VAT Transaction (ctlvtf)
                    data = [
                        self.opts["conum"], self.taxdf, "O", curdt, "R",
                        self.trntyp, self.batno, self.trnref, self.trndat,
                        self.acno, self.name, cma, tax, 0, self.opts["capnm"],
                        self.sysdtw, 0
                    ]
                    self.sql.insRec("ctlvtf", data=data)
                    if self.glint == "Y" and tax:
                        # Update VAT Control
                        data = [
                            self.opts["conum"], self.convat, curdt,
                            self.trndat, gltyp, self.trnref, self.batno, tax,
                            0, gld, "", "", 0, self.opts["capnm"], self.sysdtw,
                            0
                        ]
                        self.sql.insRec("gentrn", data=data)
            return
        if self.df.pag == 3 and self.movtyp == 3:
            # Contract Fees
            amt = float(ASD(0) - ASD(amt) + ASD(vat))
            vat = float(ASD(0) - ASD(vat))
            if self.glint == "Y":
                # Update Contract Fee Account
                data = [
                    self.opts["conum"], self.rcafee, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, amt, vat, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            if self.taxdf:
                # VAT Transaction (ctlvtf)
                data = (self.opts["conum"], self.vatcode, "O", curdt, "R",
                        self.trntyp, self.batno, self.trnref, self.trndat,
                        accod, self.trndet, amt, vat, 0, self.opts["capnm"],
                        self.sysdtw, 0)
                self.sql.insRec("ctlvtf", data=data)
                if self.glint == "Y":
                    # Update VAT Control
                    data = [
                        self.opts["conum"], self.convat, curdt, self.trndat,
                        gltyp, self.trnref, self.batno, vat, 0, gld, "", "", 0,
                        self.opts["capnm"], self.sysdtw, 0
                    ]
                    self.sql.insRec("gentrn", data=data)
            return
        if self.df.pag == 3 and self.movtyp == 4:
            # Services - Owner Recovery
            rta = float(ASD(0) - ASD(amt))
            rtv = float(ASD(0) - ASD(vat))
            des = "Services Recovery on %s" % self.code
            data = [
                self.opts["conum"], self.owner, self.trntyp, self.trnref,
                self.batno, self.trndat, rta, rtv, curdt, des, self.vatcode,
                "", self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("rcaowt", data=data)
            if self.glint == "Y":
                # General Ledger Transaction for Owner Control
                gld = "%7s Services Recovery" % self.owner
                data = [
                    self.opts["conum"], self.rcaown, curdt, self.trndat, gltyp,
                    self.trnref, self.batno, rta, 0, gld, "", "", 0,
                    self.opts["capnm"], self.sysdtw, 0
                ]
                self.sql.insRec("gentrn", data=data)
            return
        # Tenants Journal Entries (Unallocated)
        if self.glint == "Y":
            amt = float(ASD(0) - ASD(amt))
            data = [
                self.opts["conum"], self.rcatrx, curdt, self.trndat, gltyp,
                self.trnref, self.batno, amt, 0, gld, "", "", 0,
                self.opts["capnm"], self.sysdtw, 0
            ]
            self.sql.insRec("gentrn", data=data)

    def exitPage(self):
        if self.df.frt == "T" and self.df.pag == 0:
            self.df.closeProcess()
            self.opts["mf"].closeLoop()
        elif self.df.frt == "C" and self.df.pag == 3:
            self.df.focusField("C", 3, self.df.col)
        else:
            self.opts["mf"].dbm.commitDbase(ask=True)
            try:
                self.otrn.closeProcess()
            except:
                pass
            try:
                self.ttrn.closeProcess()
            except:
                pass
            self.df.selPage("Owner")
            self.df.focusField("T", 0, 1)

    def allNotes(self):
        if self.df.frt == "C":
            state = self.df.disableButtonsTags()
            self.df.setWidget(self.df.mstFrame, state="hide")
            if self.df.pag == 1:
                key = "%s" % self.owner
            else:
                key = "%7s%7s%s" % (self.owner, self.code, self.acno)
            NotesCreate(self.opts["mf"],
                        self.opts["conum"],
                        self.opts["conam"],
                        self.opts["capnm"],
                        "RCA",
                        key,
                        commit=False)
            self.df.setWidget(self.df.mstFrame, state="show")
            self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def allStmnt(self):
        if self.df.frt == "C" and self.df.pag == 1:
            self.sargs = [self.owner]
            self.repModule("rc3050")
        elif self.df.frt == "C" and self.df.pag == 2:
            self.sargs = [self.owner, self.code, self.acno]
            self.repModule("rc3060")
        else:
            self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def repModule(self, mod):
        self.exit = False
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        tit = ("Date and Printer Selection", )
        fld = ((("T", 0, 0, 0), "ID1", 10, "Statement Date", "", self.sysdtw,
                "N", self.doPrtDate, None, None, ("efld", )), )
        self.st = TartanDialog(self.opts["mf"],
                               tops=True,
                               title=tit,
                               eflds=fld,
                               tend=((self.doPrtEnd, "y"), ),
                               txit=(self.doPrtExit, ),
                               view=("N", "V"),
                               mail=("B", "Y"))
        self.st.mstFrame.wait_window()
        if not self.exit:
            self.sargs.extend(
                [self.stdtw, self.stdtd, self.st.repprt, self.st.repeml])
            popt = {
                "mf": self.opts["mf"],
                "conum": self.opts["conum"],
                "conam": self.opts["conam"],
                "capnm": self.opts["capnm"],
                "args": self.sargs
            }
            runModule(mod, **popt)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.enableButtonsTags(state=state)
        self.df.focusField(self.df.frt, self.df.pag, self.df.col)

    def doPrtDate(self, frt, pag, r, c, p, i, w):
        self.stdtw = w
        self.stdtd = self.st.t_disp[0][0][0]

    def doPrtEnd(self):
        self.doPrtClose()

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

    def doPrtClose(self):
        self.st.closeProcess()
Пример #2
0
class st1010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            if "wait" in self.opts:
                self.df.mstFrame.wait_window()
            else:
                self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, [
            "ctlvmf", "ctlrep", "drschn", "drsmst", "genmst", "slsiv1",
            "slsiv2", "strgrp", "strloc", "strmf1", "strmf2", "strgmu",
            "strcmu", "strprc", "strrcp", "struoi", "strtrn", "strpot",
            "strvar", "slsiv3", "chglog"
        ],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.glint = strctl["cts_glint"]
        self.locs = strctl["cts_locs"]
        self.plevs = strctl["cts_plevs"]
        self.automu = strctl["cts_automu"]
        self.drsctl = gc.getCtl("drsctl", self.opts["conum"], error=False)
        if not self.drsctl:
            self.chains = "N"
        else:
            self.chains = self.drsctl["ctd_chain"]
        return True

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def doRecGrp(self, frt, pag, r, c, p, i, w):
        self.rgroup = w
        acc = self.sql.getRec("strgrp",
                              cols=["gpm_desc"],
                              where=[("gpm_cono", "=", self.opts["conum"]),
                                     ("gpm_group", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Group"
        self.df.topf[0][1][8]["whera"] = [["C", "st1_group", 0, 3]]

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

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

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

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

    def doChgGrp(self, frt, pag, r, c, p, i, w):
        acc = self.sql.getRec("strgrp",
                              cols=["gpm_desc"],
                              where=[("gpm_cono", "=", self.opts["conum"]),
                                     ("gpm_group", "=", w)],
                              limit=1)
        if not acc:
            return "Invalid Group"
        self.rgroup = w
        self.cg.topf[0][1][8]["whera"] = [["T", "st1_group", 0, 0]]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm,
                       ["strgrp", "strmf1", "strmf2", "strloc", "strprc"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        strctl = gc.getCtl("strctl", self.opts["conum"])
        if not strctl:
            return
        self.locs = strctl["cts_locs"]
        self.plevs = strctl["cts_plevs"]
        return True

    def drawDialog(self):
        grp = {
            "stype":
            "R",
            "tables": ("strgrp", ),
            "cols": (("gpm_group", "", 0, "Grp"), ("gpm_desc", "", 0,
                                                   "Description", "Y")),
            "where": [("gpm_cono", "=", self.opts["conum"])]
        }
        st1 = {
            "stype":
            "R",
            "tables": ("strmf1", ),
            "cols":
            (("st1_code", "", 0, "Product-Code"), ("st1_type", "", 0, "T"),
             ("st1_desc", "", 0, "Description", "Y")),
            "where": [("st1_cono", "=", self.opts["conum"]),
                      ("st1_type", "<>", "X")],
            "whera": [("C", "st1_group", 0)]
        }
        loc = {
            "stype":
            "R",
            "tables": ("strmf2", "strloc"),
            "cols": (("st2_loc", "", 0, "Acc-Num"), ("srl_desc", "", 0,
                                                     "Description")),
            "where": [("st2_cono", "=", self.opts["conum"])],
            "whera": (("C", "st2_group", 0), ("C", "st2_code", 1))
        }
        self.fld = [(("C", 0, 0, 0), "IUA", 3, "Grp", "Product Group", "", "Y",
                     self.doGrp, grp, None, None),
                    (("C", 0, 0, 1), "INA", 20, "Code", "Product Code", "",
                     "N", self.doCode, st1, None, None),
                    (("C", 0, 0, 2), "ONA", 30, "Description"),
                    (("C", 0, 0, 3), "IUA", 1, "L", "Location", "", "N",
                     self.doLoc, loc, None, None)]
        for x in range(self.plevs):
            lev = x + 1
            txt = "Level-%s" % lev
            if lev == 1:
                ddd = self.doDelete
            else:
                ddd = None
            self.fld.append((("C", 0, 0, x + 4), "IUD", 10.2, txt, txt, "",
                             "N", self.doLevel, None, ddd, ("notzero", )))
        but = (
            ("Import File",None,self.doImport,0,("C",0,1),("C",0,2),
                "Import Selling Prices from a CSV or XLS File "\
                "having the following columns: Group, Code, "\
                "Location, Prices by Level"),
            ("Exit", None, self.doExit, 1, ("C", 0, 1), ("C", 0, 2)))
        row = (20, )
        self.df = TartanDialog(self.opts["mf"],
                               rows=row,
                               eflds=self.fld,
                               cend=((self.doEnd, "y"), ),
                               cxit=(self.doExit, ),
                               butt=but)

    def doImport(self):
        state = self.df.disableButtonsTags()
        self.df.setWidget(self.df.mstFrame, state="hide")
        impcol = []
        pos = 0
        for num, fld in enumerate(self.fld):
            if num == 2:
                continue
            if type(fld[2]) in (tuple, list):
                size = fld[2][1]
            else:
                size = fld[2]
            impcol.append([fld[4], pos, fld[1][1:], size])
            pos += 1
        fi = FileImport(self.opts["mf"], impcol=impcol)
        err = None
        for num, line in enumerate(fi.impdat):
            if len(line) != pos:
                err = "Line %s: Invalid Number of Fields (S/B %s is %s)" % \
                    (num + 1, pos, len(line))
                break
            self.grp = line[0]
            chk = self.sql.getRec("strgrp",
                                  where=[("gpm_cono", "=", self.opts["conum"]),
                                         ("gpm_group", "=", self.grp)],
                                  limit=1)
            if not chk:
                err = "Line %s: Invalid Group %s" % ((num + 1), self.grp)
                break
            self.cod = line[1]
            chk = self.sql.getRec("strmf1",
                                  where=[("st1_cono", "=", self.opts["conum"]),
                                         ("st1_group", "=", self.grp),
                                         ("st1_code", "=", self.cod)],
                                  limit=1)
            if not chk:
                err = "Line %s: Invalid Code %s" % ((num + 1), self.cod)
                break
            self.loc = line[2]
            chk = self.sql.getRec("strmf2",
                                  where=[("st2_cono", "=", self.opts["conum"]),
                                         ("st2_group", "=", self.grp),
                                         ("st2_code", "=", self.cod),
                                         ("st2_loc", "=", self.loc)],
                                  limit=1)
            if not chk:
                err = "Line %s: Invalid Location %s" % ((num + 1), self.loc)
                break
            self.levs = []
            for x in range(self.plevs):
                self.levs.append(line[x + 3])
            if len(self.levs) != self.plevs:
                err = "Line %s: Invalid Number of Levels (S/B %s is %s)" % \
                    ((num + 1), self.plevs, len(self.levs))
            self.doEnd(det=True)
        if err:
            showError(self.opts["mf"].body, "Import Error", err)
        elif fi.impdat:
            self.opts["mf"].dbm.commitDbase()
        self.df.enableButtonsTags(state=state)
        self.df.setWidget(self.df.mstFrame, state="show")
        self.df.focusField(self.df.frt, self.df.pag, 1)

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

    def doCode(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("strmf1",
                              cols=["st1_desc"],
                              where=[("st1_cono", "=", self.opts["conum"]),
                                     ("st1_group", "=", self.grp),
                                     ("st1_code", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Code"
        self.cod = w
        self.df.loadEntry(frt, pag, p + 1, data=chk[0])
        if self.locs == "N":
            self.loc = "1"
            self.df.loadEntry(frt, pag, p + 2, data=self.loc)
            self.doLoadLevs(p + 3)
            return "sk2"

    def doLoc(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("strmf2",
                              where=[("st2_cono", "=", self.opts["conum"]),
                                     ("st2_group", "=", self.grp),
                                     ("st2_code", "=", self.cod),
                                     ("st2_loc", "=", w)],
                              limit=1)
        if not chk:
            return "Invalid Location"
        self.loc = w
        self.doLoadLevs(p + 1)

    def doDelete(self):
        self.sql.delRec("strprc",
                        where=[("stp_cono", "=", self.opts["conum"]),
                               ("stp_group", "=", self.grp),
                               ("stp_code", "=", self.cod),
                               ("stp_loc", "=", self.loc)])
        self.opts["mf"].dbm.commitDbase()
        self.df.clearLine(0, focus=True)

    def doLoadLevs(self, p):
        self.levs = []
        for x in range(self.plevs):
            prc = self.sql.getRec("strprc",
                                  cols=["stp_price"],
                                  where=[("stp_cono", "=", self.opts["conum"]),
                                         ("stp_group", "=", self.grp),
                                         ("stp_code", "=", self.cod),
                                         ("stp_loc", "=", self.loc),
                                         ("stp_level", "=", x + 1)],
                                  limit=1)
            if not prc:
                prc = [0]
            self.df.loadEntry("C", 0, p, data=prc[0])
            self.levs.append(prc[0])
            p += 1

    def doLevel(self, frt, pag, r, c, p, i, w):
        self.levs[i - 4] = w

    def doEnd(self, det=False):
        self.sql.delRec("strprc",
                        where=[("stp_cono", "=", self.opts["conum"]),
                               ("stp_group", "=", self.grp),
                               ("stp_code", "=", self.cod),
                               ("stp_loc", "=", self.loc)])
        for num, lev in enumerate(self.levs):
            self.sql.insRec("strprc",
                            data=[
                                self.opts["conum"], self.grp, self.cod,
                                self.loc, num + 1, lev
                            ])
        self.opts["mf"].dbm.commitDbase()
        self.df.advanceLine(0)
        self.df.loadEntry("C", 0, self.df.pos, data=self.grp)
        self.df.focusField("C", 0, self.df.col + 1)

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