def doChkDate(self, date): if date < self.sper or date > self.eper: return "Invalid Date, Not in Financial Period" if self.lastp and self.lastp < self.sper: dte1 = mthendDate(self.lastp * 100) dte2 = mthendDate(self.sper * 100) if dateDiff(dte1, dte2, "months") > 1: return "Missing Depreciation for Previous Period" self.curdt = date
def setVariables(self): gc = GetCtl(self.opts["mf"]) lonctl = gc.getCtl("lonctl", self.opts["conum"]) if not lonctl: return glint = lonctl["cln_glint"] tab = ["lonctl", "lonmf2", "lontrn"] if glint == "Y": ctlctl = gc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return ctls = ["lon_ctl", "int_rec", "int_pay"] if gc.chkRec(self.opts["conum"], ctlctl, ctls): return self.glctl = ( ctlctl["lon_ctl"], ctlctl["int_rec"], ctlctl["int_pay"]) tab.append("gentrn") else: self.glctl = None self.sql = Sql(self.opts["mf"].dbm, tables=tab, prog=self.__class__.__name__) if self.sql.error: return t = time.localtime() self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2] yr = int(self.sysdtw / 10000) mt = (int(self.sysdtw / 100) % 100) - 1 self.lme = mthendDate((yr * 10000) + (mt * 100) + 1) return True
def getEndDate(self, date): yr = int(date / 10000) + 1 mt = (int(date / 100) % 100) - 1 if not mt: yr -= 1 mt = 12 return mthendDate(((yr * 10000) + (mt * 100) + 1))
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 doFlagPaid(self, frt, pag, r, c, p, i, w): self.flag = w if self.flag == "N": self.paid = 0 return "sk1" self.df.topf[pag][7][8]["where"] = [ ("vtt_cono", "=", self.opts["conum"]), ("vtt_paid", ">=", mthendDate(self.eper * 100)) ]
def setVariables(self): mc = GetCtl(self.opts["mf"]) ctlmst = mc.getCtl("ctlmst", self.opts["conum"]) if not ctlmst: return self.taxdf = ctlmst["ctm_taxdf"] memctl = mc.getCtl("memctl", self.opts["conum"]) if not memctl: return self.glint = memctl["mcm_glint"] self.ldays = memctl["mcm_ldays"] self.lme = memctl["mcm_lme"] self.lmd = int(memctl["mcm_lme"] / 100) yr = int(self.lme / 10000) mth = (int(self.lme / 100) % 100) + 1 if mth > 12: yr += 1 mth = 1 self.tme = mthendDate((yr * 10000) + (mth * 100) + 00) tabs = [ "chglog", "ctlbat", "ctlmst", "ctlvrf", "ctlvtf", "memage", "memcat", "memctc", "memctl", "memctp", "memmst", "memtrn" ] if self.glint == "Y": tabs.append("gentrn") ctlctl = mc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return ctls = ["mem_ctl", "mem_pen", "vat_ctl"] if mc.chkRec(self.opts["conum"], ctlctl, ctls): return self.memctl = ctlctl["mem_ctl"] self.penctl = ctlctl["mem_pen"] self.vatctl = ctlctl["vat_ctl"] else: self.penctl = 0 self.sql = Sql(self.opts["mf"].dbm, tabs, prog=self.__class__.__name__) if self.sql.error: return if self.glint == "Y": check = self.sql.getRec("memctc", where=[("mcc_cono", "=", self.opts["conum"]), ("mcc_freq", "<>", "N"), ("mcc_glac", "=", 0)]) if check: mess = "The following Category Record(s) are Missing G/L "\ "Accounts:\n" for rec in check: mess = "%s\n%s, %2s, %s" % (mess, rec[1], rec[2], rec[3]) showError(self.opts["mf"].body, "Invalid Category", mess) return t = time.localtime() self.sysdt = (t[0] * 10000) + (t[1] * 100) + t[2] self.ynd = False return True
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 doPeriod(self, frt, pag, r, c, p, i, w): if w > int(self.sysdtw / 100): return "Invalid Period" self.curdt = w self.date = CCD(mthendDate(w * 100), "D1", 10) if self.locs == "N": self.df.loadEntry(frt, pag, p + 1, data="1") no = self.doLoc(frt, pag, r, c + 1, p + 1, i + 1, "1") if no: return no return "sk1"
def sortImports(self): dte = mthendDate((self.perw * 100) + 1) col = ["grt_date", "grt_refno", "grt_memo", "grt_amount"] whr = [ ("grt_cono", "=", self.opts["conum"]), ("grt_acno", "=", self.acno), ("grt_date", "<=", dte), ("grt_flag", "=", "N")] odr = "grt_date, grt_refno" self.imps = self.sql.getRec("genrct", cols=col, where=whr, order=odr) if not self.imps: self.imps = []
def setVariables(self): gc = GetCtl(self.opts["mf"]) ctlmst = gc.getCtl("ctlmst", self.opts["conum"]) if not ctlmst: return self.taxdf = ctlmst["ctm_taxdf"] memctl = gc.getCtl("memctl", self.opts["conum"]) if not memctl: return self.ldays = memctl["mcm_ldays"] self.lme = memctl["mcm_lme"] self.stpl = memctl["mcm_sttpl"] self.fromad = memctl["mcm_emadd"] self.sql = Sql(self.opts["mf"].dbm, [ "ctlmes", "ctlmst", "memmst", "memtrn", "memadd", "memcat", "memctc", "memctp", "memctk", "memkon", "memlnk", "tplmst" ], prog=self.__class__.__name__) if self.sql.error: return t = time.localtime() self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2] yy = int(self.lme / 10000) mm = (int(self.lme / 100) % 100) + 1 while mm > 12: yy += 1 mm -= 12 self.nme = mthendDate((yy * 10000) + (mm * 100) + 1) mm += 1 while mm > 12: yy += 1 mm -= 12 self.nne = mthendDate((yy * 10000) + (mm * 100) + 1) self.trtypes = [] for t in mltrtp: self.trtypes.append(t[0]) return True
def doStartPer(self, frt, pag, r, c, p, i, w): y = int(w / 10000) - 1 m = int((w % 10000) / 100) if m == 2: if not y % 4: d = 29 else: d = 28 else: d = w % 100 self.s0 = (y * 10000) + (m * 100) + d self.s1 = w y = int(w / 10000) + 1 m -= 1 if not m: m = 12 y -= 1 self.pf.t_work[0][0][1] = mthendDate((y * 10000) + (m * 100) + 1)
def doExpiredContract(self): tit = ("Renew Rental Contract", ) r1s = (("Monthly", "M"), ("Quarterly", "3"), ("Bi-Annually", "6"), ("Annually", "A")) chdt = self.strt.work while True: chdt = projectDate(chdt, self.mths, typ="months") exdt = mthendDate(projectDate(chdt, self.mths - 1, typ="months")) if int(exdt / 100) > self.curdt: break self.fld = ((("T", 0, 0, 0), "OUA", 7, "Owner Code"), (("T", 0, 1, 0), "OUA", 7, "Premises Code"), (("T", 0, 2, 0), "ONA", 7, "Account Code"), (("T", 0, 3, 0), "ONA", 30, "Tenant Name"), (("T", 0, 4, 0), ("IRB", r1s), 0, "Payment Frequency", "", self.freq, "N", None, None, None, None), (("T", 0, 5, 0), "ID1", 10, "Start Date", "", chdt, "N", None, None, None, ("efld", )), (("T", 0, 6, 0), "IUI", 3, "Number of Periods", "", self.pers, "N", None, None, None, ("notzero", )), (("T", 0, 7, 0), "IUD", 12.2, "Rental Amount", "", self.amnt, "N", None, None, None, ("notzero", )), (("T", 0, 8, 0), "IUD", 12.2, "Deposit Amount", "", self.depo, "N", None, None, None, ("efld", )), (("T", 0, 9, 0), "IUD", 12.2, "Basic Water Amount", "", "", "N", None, None, None, ("efld", )), (("T", 0, 10, 0), "IUI", 1, "Type", "", "", "N", None, None, None, ("efld", )), (("T", 0, 11, 0), "IUD", 12.2, "Basic Exlectricity Amount", "", "", "N", None, None, None, ("efld", )), (("T", 0, 12, 0), "IUI", 1, "Type", "", "", "N", None, None, None, ("efld", ))) tnd = ((self.doExpireEnd, "y"), ) txt = (None, ) self.na = TartanDialog(self.opts["mf"], tops=True, title=tit, eflds=self.fld, tend=tnd, txit=txt, focus=False) self.doLoadFocus(chdt) self.na.mstFrame.wait_window()
def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, [ "ctlvrf", "ctlvtf", "gentrn", "rcactl", "rcaprm", "rcaowm", "rcaowt", "rcatnm", "rcacon", "rcatnt" ], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) rcactl = gc.getCtl("rcactl", self.opts["conum"]) if not rcactl: return self.lme = rcactl["cte_lme"] self.glint = rcactl["cte_glint"] if self.glint == "Y": self.glbnk = rcactl["cte_glbnk"] ctlctl = gc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return ctls = ["rca_com", "rca_own", "rca_tnt", "vat_ctl"] if gc.chkRec(self.opts["conum"], ctlctl, ctls): return self.rcacom = ctlctl["rca_com"] self.rcaown = ctlctl["rca_own"] self.rcatnt = ctlctl["rca_tnt"] self.rcatrx = ctlctl["rca_trx"] self.convat = ctlctl["vat_ctl"] # Check for Company Record ctlmst = gc.getCtl("ctlmst", self.opts["conum"]) if not ctlmst: return # Set Company VAT Default self.taxdf = ctlmst["ctm_taxdf"] if not self.taxdf: self.taxdf = "N" t = time.localtime() self.sysdtw = (t[0] * 10000) + (t[1] * 100) + t[2] self.tme = mthendDate(self.sysdtw) return True
def setVariables(self): self.sql = Sql(self.opts["mf"].dbm, ["ctlbat", "ctlvrf", "ctlvtf", "gentrn", "rtlctl", "rtlprm", "rtlmst", "rtlcon", "rtltrn"], prog=self.__class__.__name__) if self.sql.error: return gc = GetCtl(self.opts["mf"]) rtlctl = gc.getCtl("rtlctl", self.opts["conum"]) if not rtlctl: return self.glint = rtlctl["ctr_glint"] self.lme = rtlctl["ctr_lme"] if self.glint == "Y": ctlctl = gc.getCtl("ctlctl", self.opts["conum"]) if not ctlctl: return if 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.tme = mthendDate(self.sysdtw) return True
def doFormulae(self): taxinc, retinc, totinc = self.doTaxableIncome() #if taxinc <= 0: # self.taxamt = 0 # return ann = 0 ret = 0 self.taxamt, prb, arb, nrb, rmx = self.doCompute(taxinc) if taxinc != totinc: ann, _, _, _, _ = self.doCompute(totinc) ann = float(ASD(ann) - ASD(self.taxamt)) yrend = mthendDate((self.taxyr * 10000) + 228) age = dateDiff(self.dob, yrend, "years") if age > 64: prb = float(ASD(prb) + ASD(arb)) if age > 74: prb = float(ASD(prb) + ASD(nrb)) self.taxamt = float(ASD(self.taxamt) - ASD(prb)) if retinc > 0 and retinc > rmx: avg = round(((self.taxamt / taxinc) * 100), 2) ret = round(((float(ASD(retinc) - ASD(rmx))) * avg / 100), 2) self.taxamt = round((self.taxamt * self.pers / self.base), 2) self.taxamt = float(ASD(self.taxamt) + ASD(ann) + ASD(ret))
def raiseExtraTrans(self): self.tme = mthendDate(self.repdt) if int(self.tme / 100) == int(self.opts["period"][2][0] / 100): self.ynd = True else: self.ynd = False yy = int(self.tme / 10000) mm = (int(self.tme / 100) % 100) + 1 while mm > 12: yy += 1 mm -= 12 self.nxtdt = (yy * 10000) + (mm * 100) + 1 self.refno = 0 if self.ynd: data = doChkCatChg(self.opts["mf"], self.opts["conum"], self.memno, self.nxtdt) if data: self.doRaiseCharge("B", data[0], data[1], data[3], data[4], data[5], skip=True) self.sql.delRec("memcat", where=[("mlc_cono", "=", self.opts["conum"]), ("mlc_memno", "=", self.memno), ("mlc_type", "=", "B"), ("mlc_code", "=", data[0])]) self.sql.insRec("memcat", data=[ self.opts["conum"], self.memno, "B", data[7], "", self.nxtdt, 0, 0 ]) cols = [ "mlc_type", "mlc_code", "mcc_desc", "mcc_freq", "mlc_start", "mlc_end", "mlc_last" ] wher = [("mlc_cono", "=", self.opts["conum"]), ("mlc_memno", "=", self.memno), ("mlc_start", ">", 0), ("mlc_start", "<=", self.nxtdt), ("mcc_cono=mlc_cono", ), ("mcc_type=mlc_type", ), ("mcc_code=mlc_code", ), ("mcc_freq", "<>", "N")] cats = self.sql.getRec(tables=["memcat", "memctc"], cols=cols, where=wher, order="mlc_type, mlc_code") for ctyp, code, desc, freq, start, end, last in cats: if start > self.nxtdt: # Not yet Started continue if last and end and end < self.nxtdt: # Ended continue if last and freq == "O": # Once Off continue if last and last > self.opts["period"][2][0]: # Already Raised for Next Period in Advance continue if not self.ynd and last and freq == "A" and \ last >= self.opts["period"][1][0] and \ last <= self.opts["period"][2][0]: # Already Raised in Financial Period continue self.doRaiseCharge(ctyp, code, start, last, freq, desc)
def doEnd(self): self.df.closeProcess() if self.reptyp == "B": col = ["bkm_state", "bkm_guests", "bkm_arrive", "bkm_depart"] whr = [("bkm_btype", "=", "A"), ("bkm_arrive", ">=", self.sdate, "and", "bkm_depart", "<=", self.edate)] else: col = ["bkm_state", "bkm_value", "bkm_arrive", "bkm_depart"] whr = [("bkm_btype", "=", "A"), ("bkm_arrive", "between", self.sdate, self.edate, "or", "bkm_depart", "between", self.sdate, self.edate)] rec = self.sql.getRec("bkmmst", cols=col, where=whr) num = 1 lookup = {} mth = int(self.sdate / 100) % 100 end = int(self.edate / 100) % 100 lookup[mth] = num while mth != end: mth += 1 if mth > 12: mth = 1 num += 1 lookup[mth] = num for r in rec: if self.reptyp == "B": if int(r[2] / 100) == int(r[3] / 100): days = dateDiff(r[2], r[3], "days") mth = int(r[2] / 100) % 100 self.desc[r[0]][lookup[mth]] += (days * r[1]) if r[0] == "X": continue self.desc["T"][lookup[mth]] += (days * r[1]) else: mnd = mthendDate(r[2]) days = dateDiff(r[2], mnd, "days") mth = int(r[2] / 100) % 100 self.desc[r[0]][lookup[mth]] += (days * r[1]) self.desc["T"][lookup[mth]] += (days * r[1]) mth = int(r[3] / 100) % 100 days = dateDiff(((int(r[3] / 100) * 100) + 1), r[3], "days") self.desc[r[0]][lookup[mth]] += (days * r[1]) if r[0] == "X": continue self.desc["T"][lookup[mth]] += (days * r[1]) else: mth = int(r[2] / 100) % 100 self.desc[r[0]][lookup[mth]] += r[1] if r[0] == "X": continue self.desc["T"][lookup[mth]] += r[1] achart = [] mchart = [] for s in self.desc: mchart.append([s] + self.desc[s]) if s in ("T", "X"): continue achart.append([s] + self.desc[s]) if self.reptyp == "B": typ = "Beds" else: typ = "Value" CreateChart(self.opts["mf"], self.opts["conum"], self.opts["conam"], [int(self.sdate / 100), int(self.edate / 100)], [[self.opts["conam"], "Status Summary"], typ], achart, mchart) self.opts["mf"].closeLoop()
def doRaiseDep(self): # Calculate Depreciations and check if Raised # else create transaction and accumulate variables # # Extract Closing Balance at lurdt where = [("ast_cono", "=", self.opts["conum"]), ("ast_group", "=", self.group.work), ("ast_code", "=", self.code)] whr = copyList(where) whr.append(("ast_curdt", "<=", self.lurdt)) bal = self.sql.getRec( "asstrn", cols=["round(sum(ast_amt1), 2)", "round(sum(ast_amt2), 2)"], where=whr, limit=1) if bal and bal[0] <= 0: return # Get Date Purchased and Months to trdt self.trdt = mthendDate(self.lurdt * 100) acc = self.sql.getRec("asstrn", cols=["min(ast_date)"], where=[("ast_cono", "=", self.opts["conum"]), ("ast_group", "=", self.group.work), ("ast_code", "=", self.code), ("ast_mtyp", "=", 1)], limit=1) years = dateDiff(acc[0], self.trdt, "years") if years > 6: # Maximum of 7 variable rates in assdep record years = 6 # Extract Depreciation up to previous year end whr = copyList(where) whr.extend([("ast_mtyp", "=", 4), ("ast_curdt", "<", self.sper)]) pmd = self.sql.getRec( "asstrn", cols=["round(sum(ast_amt1), 2)", "round(sum(ast_amt2), 2)"], where=whr, limit=1) if not pmd[0]: pmd[0] = 0 if not pmd[1]: pmd[1] = 0 # # Extract Depreciation for lurdt whr = copyList(where) whr.extend([("ast_mtyp", "=", 4), ("ast_curdt", "=", self.lurdt)]) cmd = self.sql.getRec("asstrn", cols=[ "max(ast_refno)", "round(sum(ast_amt1), 2)", "round(sum(ast_amt2), 2)" ], where=whr, limit=1) if not cmd[0] or cmd[0] == "Take-On": self.refno = CCD(1, "Na", 9).work else: self.refno = CCD(cmd[0], "Na", 9).work if not cmd[1]: cmd[1] = 0 if not cmd[2]: cmd[2] = 0 if self.dep[self.sql.assdep_col.index("asd_typec")] == "S": # Straight Line cval = self.cap crat = self.dep[self.sql.assdep_col.index("asd_rate1c")] for x in range(2, years + 2): n = self.dep[self.sql.assdep_col.index("asd_rate%sc" % x)] if n: crat = n else: # Depreciating Balance cval = float(ASD(self.cap) + ASD(pmd[0])) crat = self.dep[self.sql.assdep_col.index("asd_rate1c")] if cval: if cval < 0: cdep = 0 else: cdep = round((cval * crat / 100.0 / 12), 2) cdep = float(ASD(cdep) + ASD(cmd[1])) cbal = float(ASD(bal[0]) - ASD(cdep)) if cbal < 0: cdep = float(ASD(cdep) + ASD(cbal)) cdep = float(ASD(0) - ASD(cdep)) typer = self.dep[self.sql.assdep_col.index("asd_typer")] if self.rordp == "N" or typer == "N": rdep = 0 else: if typer == "S": # Straight Line rval = self.cap rrat = self.dep[self.sql.assdep_col.index("asd_rate1r")] for x in range(2, years + 2): n = self.dep[self.sql.assdep_col.index("asd_rate%sr" % x)] if n: rrat = n else: # Depreciating Balance rval = float(ASD(self.cap) + ASD(pmd[1])) rrat = self.dep[self.sql.assdep_col.index("asd_rate1r")] if rval: if rval < 0: rdep = 0 else: rdep = round((rval * rrat / 100.0 / 12), 2) rdep = float(ASD(rdep) + ASD(cmd[2])) rbal = float(ASD(bal[1]) - ASD(rdep)) if rbal < 0: rdep = float(ASD(rdep) + ASD(rbal)) rdep = float(ASD(0) - ASD(rdep)) if cdep or rdep: data = [ self.opts["conum"], self.group.work, self.code, 4, self.refno, "AutoDep", self.trdt, 4, cdep, rdep, 0, self.lurdt, "Auto Raising of Depreciation", "", "", self.opts["capnm"], self.sysdtw, 0 ] self.sql.insRec("asstrn", data=data) if self.glint == "Y" and cdep: self.doWriteGen(self.depacc, cdep) cdep = float(ASD(0) - ASD(cdep)) self.doWriteGen(self.expacc, cdep)
def doEndPer(self, frt, pag, r, c, p, i, w): if w < self.sper: return "Invalid Period, before Start" self.edate = mthendDate((w * 100) + 1) if dateDiff(self.sdate, self.edate, "months") > 11: return "More than 12 month period"
def printReport(self, recs): p = ProgressBar(self.opts["mf"].body, mxs=len(recs), esc=True) self.head = "%03u %-167s" % (self.opts["conum"], self.opts["conam"]) self.fpdf = MyFpdf(name=self.__class__.__name__, head=self.head) self.pglin = 999 mst = self.sql.rcatnm_col con = self.sql.rcacon_col self.tots = [0, 0, 0, 0, 0, 0] self.cred = [0, 0, 0, 0, 0, 0] for num, dat in enumerate(recs): p.displayProgress(num) if p.quit: break ownr = CCD(dat[con.index("rcc_owner")], "NA", 7) code = CCD(dat[con.index("rcc_code")], "NA", 7) acno = CCD(dat[con.index("rcc_acno")], "NA", 7) cnum = CCD(dat[con.index("rcc_cnum")], "UI", 3) freq = CCD(dat[con.index("rcc_payind")], "UA", 1) strt = CCD(dat[con.index("rcc_start")], "D1", 10) prds = CCD(dat[con.index("rcc_period")], "UI", 3) stat = CCD(dat[con.index("rcc_status")], "UA", 1) if self.styp != "X": curdt = int(self.date / 100) if self.months: yy = int(curdt / 100) mm = (curdt % 100) + self.months while mm > 12: yy += 1 mm -= 12 curdt = (yy * 100) + mm if freq.work == "M": mths = 1 * prds.work elif freq.work == "3": mths = 3 * prds.work elif freq.work == "6": mths = 6 * prds.work else: mths = 12 * prds.work exdt = projectDate(strt.work, mths - 1, typ="months") exdt = CCD(mthendDate(exdt), "D1", 10) if self.styp == "E" and int(exdt.work / 100) > curdt: continue else: exdt = CCD(0, "d1", 10) acc = self.sql.getRec("rcatnm", where=[("rtn_cono", "=", self.opts["conum"]), ("rtn_owner", "=", ownr.work), ("rtn_code", "=", code.work), ("rtn_acno", "=", acno.work)], limit=1) name = CCD(acc[mst.index("rtn_name")], "NA", 30) if self.cons == "Y": trn = self.sql.getRec("rcatnt", cols=["rtu_mtyp", "round(sum(rtu_tramt), 2)"], where=[("rtu_cono", "=", self.opts["conum"]), ("rtu_owner", "=", ownr.work), ("rtu_code", "=", code.work), ("rtu_acno", "=", acno.work), ("rtu_trdt", "<=", self.date)], group="rtu_mtyp") else: trn = self.sql.getRec("rcatnt", cols=["rtu_mtyp", "round(sum(rtu_tramt), 2)"], where=[("rtu_cono", "=", self.opts["conum"]), ("rtu_owner", "=", ownr.work), ("rtu_code", "=", code.work), ("rtu_acno", "=", acno.work), ("rtu_cnum", "=", cnum.work), ("rtu_trdt", "<=", self.date)], group="rtu_mtyp") rtl = CCD(0, "SD", 13.2) dep = CCD(0, "SD", 13.2) fee = CCD(0, "SD", 13.2) sv1 = CCD(0, "SD", 13.2) sv2 = CCD(0, "SD", 13.2) rep = CCD(0, "SD", 13.2) if trn: for t in trn: if t[0] == 1: rtl = CCD(t[1], "SD", 13.2) elif t[0] == 2: dep = CCD(t[1], "SD", 13.2) elif t[0] == 3: fee = CCD(t[1], "SD", 13.2) elif t[0] == 4: sv1 = CCD(t[1], "SD", 13.2) elif t[0] == 5: sv2 = CCD(t[1], "SD", 13.2) elif t[0] == 6: rep = CCD(t[1], "SD", 13.2) srv = CCD(float(ASD(sv1.work) + ASD(sv2.work)), "SD", 13.2) bal = float(ASD(rtl.work) + ASD(fee.work) + ASD(srv.work) + \ ASD(rep.work)) bal = CCD(bal, "SD", 13.2) if self.pglin > self.fpdf.lpp: self.pageHeading() self.fpdf.drawText("%s %s %s %s %s %s %s %s %s %s %s %s %s "\ "%s %s %s" % (ownr.disp, code.disp, acno.disp, cnum.disp, name.disp, freq.disp, strt.disp, prds.disp, exdt.disp, stat.disp, dep.disp, rtl.disp, fee.disp, srv.disp, rep.disp, bal.disp)) self.tots[0] = float(ASD(self.tots[0]) + ASD(dep.work)) if dep.work < 0: self.cred[0] = float(ASD(self.cred[0]) + ASD(dep.work)) self.tots[1] = float(ASD(self.tots[1]) + ASD(rtl.work)) if rtl.work < 0: self.cred[1] = float(ASD(self.cred[1]) + ASD(rtl.work)) self.tots[2] = float(ASD(self.tots[2]) + ASD(fee.work)) if fee.work < 0: self.cred[2] = float(ASD(self.cred[2]) + ASD(fee.work)) self.tots[3] = float(ASD(self.tots[3]) + ASD(srv.work)) if srv.work < 0: self.cred[3] = float(ASD(self.cred[3]) + ASD(srv.work)) self.tots[4] = float(ASD(self.tots[4]) + ASD(rep.work)) if rep.work < 0: self.cred[4] = float(ASD(self.cred[4]) + ASD(rep.work)) self.tots[5] = float(ASD(self.tots[5]) + ASD(bal.work)) if bal.work < 0: self.cred[5] = float(ASD(self.cred[5]) + ASD(bal.work)) self.pglin += 1 t = [] for x in range(6): t.append(CCD(self.tots[x], "SD", 13.2).disp) self.fpdf.underLine(txt=self.head) self.fpdf.drawText("%27s %-30s %29s %-13s %-13s %-13s %-13s "\ "%-13s %-13s" % ("", "Grand Totals", "", t[0], t[1], t[2], t[3], t[4], t[5])) t = [] for x in range(6): t.append(CCD(self.cred[x], "SD", 13.2).disp) self.fpdf.underLine(txt=self.head) self.fpdf.drawText("%27s %-30s %29s %-13s %-13s %-13s %-13s "\ "%-13s %-13s" % ("", "Credits", "", t[0], t[1], t[2], t[3], t[4], t[5])) p.closeProgress() if self.fpdf.page and not p.quit: pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"], self.__class__.__name__, self.opts["conum"], ext="pdf") self.fpdf.output(pdfnam, "F") doPrinter(mf=self.opts["mf"], conum=self.opts["conum"], pdfnam=pdfnam, header=self.tit, repprt=self.df.repprt, fromad=self.fromad, repeml=self.df.repeml) self.closeProcess()
def doEndPer(self, frt, pag, r, c, p, i, w): self.edate = mthendDate((w * 100) + 1) if dateDiff(self.sdate, self.edate, "months") > 11: return "More than 12 month period"
def doDate(self, frt, pag, r, c, p, i, w): self.curdt = w self.cdte = self.df.t_disp[pag][0][i] self.date = mthendDate(w * 100)
def doEnd(self): self.df.closeProcess() whr = [("rcc_cono", "=", self.opts["conum"]), ("rtn_cono=rcc_cono", ), ("rtn_owner=rcc_owner", ), ("rtn_code=rcc_code", ), ("rtn_acno=rcc_acno", ), ("rcc_status", "<>", "X")] recs = self.sql.getRec( tables=["rcacon", "rcatnm"], cols=[ "rcc_cono", "rcc_owner", "rcc_code", "rcc_acno", "rcc_cnum", "rcc_payind", "rcc_start", "rcc_period", "rcc_rtlamt", "rcc_deposit", "rcc_wamt", "rcc_wtyp", "rcc_eamt", "rcc_etyp", "rtn_name" ], where=whr, ) if recs: for num, self.con in enumerate(recs): own = self.sql.getRec("rcaowm", cols=["rom_vatdf"], where=[("rom_cono", "=", self.opts["conum"]), ("rom_acno", "=", self.con[1])], limit=1) if not own: showError( self.opts["mf"].body, "Missing Owner", "This Owner's Record (%s) Could Not Be Found!" % self.con[1]) continue self.vatdf = own[0] self.prm = self.sql.getRec("rcaprm", cols=["rcp_crate"], where=[ ("rcp_cono", "=", self.opts["conum"]), ("rcp_owner", "=", self.con[1]), ("rcp_code", "=", self.con[2]) ], limit=1) if not self.prm: showError( self.opts["mf"].body, "Missing Premises", "This Premises's Record (%s %s) Could Not Be Found!" % (self.con[1], self.con[2])) continue self.freq = self.con[5] self.strt = CCD(self.con[6], "D1", 10) self.pers = self.con[7] self.amnt = self.con[8] self.depo = self.con[9] self.wamt = self.con[10] self.wtyp = self.con[11] self.eamt = self.con[12] self.etyp = self.con[13] if self.freq == "M": self.mths = 1 * self.pers elif self.freq == "3": self.mths = 3 * self.pers elif self.freq == "6": self.mths = 6 * self.pers else: self.mths = 12 * self.pers exdt = projectDate(self.strt.work, self.mths - 1, typ="months") exdt = CCD(mthendDate(exdt), "D1", 10) if int(exdt.work / 100) <= self.curdt: self.sql.updRec("rcacon", cols=["rcc_status"], data=["X"], where=[("rcc_cono", "=", self.con[0]), ("rcc_owner", "=", self.con[1]), ("rcc_code", "=", self.con[2]), ("rcc_acno", "=", self.con[3]), ("rcc_cnum", "=", self.con[4])]) ok = askQuestion(self.opts["mf"].body, "Expired Contract", "This contract has Expired, would you like to "\ "Renew it?\n\nOwner: %s\nPremises: %s\nAccount: %s\n"\ "Name: %s\nStart: %s\nEnd: %s" % (self.con[1], self.con[2], self.con[3], self.con[14], self.strt.disp, exdt.disp)) if ok == "no": continue self.doExpiredContract() self.doRaiseRental(num) self.doRaiseExtra(num) self.sql.updRec("rcactl", cols=["cte_lme"], data=[self.tme], where=[("cte_cono", "=", self.opts["conum"])]) self.opts["mf"].dbm.commitDbase(ask=True, mess="Do You Want To Save "\ "All Changes?\n\nPlease Note That Once The Changes Have Been "\ "Saved, There Is No Going Back Without Restoring From Backup!") self.opts["mf"].closeLoop()
def doTrdate(self, frt, pag, r, c, p, i, w): self.trdate = 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(w): return "Invalid Date, Not a Month End"
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 doEPer(self, frt, pag, r, c, p, i, w): self.eperw = w self.eperd = self.df.t_disp[pag][0][p] self.date = CCD(mthendDate((w * 100) + 1), "D1", 10)
def doEndPeriod(self, frt, pag, r, c, p, i, w): if w: self.end = CCD(mthendDate((w * 100) + 1), "D1", 7) else: self.end = CCD(0, "d1", 7) self.end.disp = self.curdt
def doYearEnd(self, per): self.sql.updRec("ctlynd", cols=["cye_last", "cye_final"], data=[self.sysdtw, self.final], where=[("cye_cono", "=", self.opts["conum"]), ("cye_period", "=", per)]) if per == self.c_per: start_c = self.start end_c = self.end if (per + 1) > self.l_per: newy = int(end_c / 10000) newm = (int(end_c / 100) % 100) + 1 if newm > 12: newy += 1 newm -= 12 news = (newy * 10000) + (newm * 100) + 1 newy = int(end_c / 10000) + 1 newm = int(end_c / 100) % 100 newe = (newy * 10000) + (newm * 100) + 1 newe = mthendDate(newe) self.sql.insRec( "ctlynd", data=[self.opts["conum"], (per + 1), news, newe, 0, "N"]) else: s, e, f = getPeriods(self.opts["mf"], self.opts["conum"], per) if s is None or e is None: return start_c = s.work end_c = e.work sp = int(start_c / 100) ep = int(end_c / 100) s, e, f = getPeriods(self.opts["mf"], self.opts["conum"], (per + 1)) start_n = s.work if "GL" not in self.mod: return self.sql.delRec("genbal", where=[("glo_cono", "=", self.opts["conum"]), ("glo_trdt", "=", start_n)]) gm = self.sql.getRec("genmst", cols=["glm_acno, glm_type"], where=[("glm_cono", "=", self.opts["conum"])]) if gm: for ac in gm: ov = self.sql.getRec("genbal", cols=["glo_cyr"], where=[("glo_cono", "=", self.opts["conum"]), ("glo_acno", "=", ac[0]), ("glo_trdt", "=", start_c)], limit=1) if not ov: ov = CCD(0, "SD", 13.2) else: ov = CCD(ov[0], "SD", 13.2) cy = self.sql.getRec("gentrn", cols=["round(sum(glt_tramt), 2)"], where=[("glt_cono", "=", self.opts["conum"]), ("glt_acno", "=", ac[0]), ("glt_curdt", "between", sp, ep)], limit=1) if not cy[0]: cy = CCD(0, "SD", 13.2) else: cy = CCD(cy[0], "SD", 13.2) bal = float(ASD(ov.work) + ASD(cy.work)) if ac[1] == "P": self.retinc = float(ASD(self.retinc) + ASD(bal)) bal = 0.00 self.sql.insRec("genbal", data=[self.opts["conum"], ac[0], start_n, bal]) ri_bal = self.sql.getRec("genbal", cols=["glo_cyr"], where=[("glo_cono", "=", self.opts["conum"]), ("glo_acno", "=", self.ri_acc), ("glo_trdt", "=", start_n)], limit=1) if not ri_bal: self.sql.insRec("genbal", data=[ self.opts["conum"], self.ri_acc, start_n, self.retinc ]) else: bal = float(ASD(ri_bal[0]) + ASD(self.retinc)) self.sql.updRec("genbal", cols=["glo_cyr"], data=[bal], where=[("glo_cono", "=", self.opts["conum"]), ("glo_acno", "=", self.ri_acc), ("glo_trdt", "=", start_n)])