def countPaymentsA(var, billName): pList = util.PAYMENTOP(var).getPaymentsForBill(billName) suma = 0.0 advanced = 0.0 for p in pList: total = p.getPaymentTotal() if p.isAdvancepayment(): advanced = cutil.addDecimal(advanced, con.BigDecimalToDecimal(total)) else: suma = cutil.addDecimal(suma, con.BigDecimalToDecimal(total)) return (suma, advanced)
def buildXMLReservation(var, resename): """ Create XML for reservation confirmation Args: var resename : reservation name Returns: xml string """ r = util.RESFORM(var).findElem(resename) li = r.getResDetail() nog = 0 sum = 0.0 seq = [] for l in li: if l.getNoP() > nog: nog = l.getNoP() total = l.getPriceTotal() sum = con.addDecimal(sum, con.BigDecimalToDecimal(total)) mx = {} _XbuildElemXML(var, mx, l) seq.append(mx) ma = {} _XbuildHeaderXML(var, ma, nog, r, r.getCustomerName()) ma["total"] = sum ma["grossvalue"] = sum ma["docid"] = resename ma["doctype"] = "XX" return dutil.doctoXML(ma, seq)
def _setPriceAfterRating(var): price = var["pricelist"] service = var["service"] if price == None or service == None: _setPrice(var) return pr = util.getPriceForPriceList(var, price, service) if pr == None: _setPrice(var) return _setPrice(var, con.BigDecimalToDecimal(pr.getPrice()))
def dialogaction(action, var): cutil.printVar("test10", action, var) if action == "checkrese": sym = var["rese"] (arrival, departure, roomname, rate, non) = rutil.getReseDateS(var, sym) print arrival, departure, roomname, rate, type(rate), non assert roomname == "P10" assert non == 2 assert con.BigDecimalToDecimal(rate) == 100.0 print arrival, type(arrival) assert datetime.date(2013, 4, 10) == arrival assert datetime.date(2013, 4, 12) == departure var["OK"] = True
def countTotalForServices(var, sli, pli): """ Counts total sum of services for bill Args: var sli : list of services (pos) pli List of services (return result of getPayments) Returns: sum of services for sli """ total = 0.0 for idp in sli: for pa in pli: if con.eqUL(idp, pa.getId()): to = con.BigDecimalToDecimal(pa.getPriceTotal()) total = con.addDecimal(total, to) return total
def _createList(var, billName): pList = PAYMENTOP(var).getPaymentsForBill(billName) suma = 0.0 li = [] for p in pList: id = p.getId() total = p.getPaymentTotal() date = p.getDateOfPayment() method = p.getPaymentMethod() suma = con.addDecimal(suma, con.BigDecimalToDecimal(total)) ma = { "id": id, "paymethod": method, "paymentdate": date, "paymenttotal": total } li.append(ma) cutil.setJMapList(var, PAYLIST, li) cutil.setFooter(var, PAYLIST, "paymenttotal", suma)
def getVar(map,dialogname,xml,listv): """ Set map with values read from xml string for dialog form. Retrieves values from XML string and set values to the map (key->value). Retrieves values only for list of keys (not for all found in XML string) Args: map : A map being set. Can be empty or contains some values already. In case of conflict new value will overwrite existing value. dialogname : Dialog name where form is available. xml : XML string to be analyzed. listv : List of keys to be set to the map. Only keys found in the list are set. Others are ignored. """ iXml = Holder.getXMLTransformer(); v = DialogVariables(); iXml.fromXML(dialogname,v,xml); for vname in listv : val = v.getValue(vname) if val == None or val.getValue() == None: map[vname] = None continue if val.getType() == TT.STRING : map[vname] = val.getValueS() continue if val.getType() == TT.BIGDECIMAL : b = val.getValueBD() map[vname] = con.BigDecimalToDecimal(b) continue if val.getType() == TT.BOOLEAN : b = val.getValueB() map[vname] = b continue if val.getType() == TT.INT or val.getType() == TT.LONG : map[vname] = val.getValue() continue if val.getType() == TT.DATE : map[vname] = con.toJDate(val.getValue()) continue if val.getType() == TT.DATETIME : map[vname] = con.toJDateTime(val.getValue()) continue
def _XbuildElemXML(var, ma, r, CV=None): da = con.toJDate(r.getServDate()) roomname = r.getRoomName() desc = util.ROOMLIST(var).findElem(roomname).getDescription() rate = r.getPrice() amount = r.getNoP() total = r.getPriceTotal() ma["date"] = da ma["roomnumber"] = roomname ma["description"] = desc ma["dailyrate"] = rate ma["amount"] = amount ma["total"] = total ma["id"] = r.getId() if CV != None: vats = rutil.getVatName(var, r) (netto, vatv, vatlevel) = CV.calculateVatValue(con.BigDecimalToDecimal(total), vats) ma["netvalue"] = netto ma["taxvalue"] = vatv ma["taxlevel"] = vatlevel ma["tax"] = vats ma["grossvalue"] = con.addDecimal(netto, vatv)
def BigDecimalToDecimal(b): return con.BigDecimalToDecimal(b)
def setvarBefore(var,custo=RCUST): xml = var["JUPDIALOG_START"] (roomname,resday,resdays,nop,roomservice,roompricelist) = rparam.XMLtoresquery(xml) if roomservice != None and roompricelist != None : rutil.setServicePriceList(var,roomservice,roompricelist) R = util.ROOMLIST(var) room = R.findElem(roomname) assert room != None if nop == None : nop = room.getNoPersons() var["name"] = roomname var["desc"] = room.getDescription() var["nop"] = nop var["noextrabeds"] = util.getIntField(room.getNoExtraBeds()) var["nochildren"] = util.getIntField(room.getNoChildren()) var["resnop"] = util.getIntField(nop) util.setCopy(var,["resename","name","datecol","desc","resdays","noextrabeds","nochildren","nop","serviceperperson","resnop"]) # util.setCopy(var,["resnochildren","respricechildren","resnoextrabeds","respriceextrabeds","respriceperroom","resnop"]) res = rutil.getReservForDay(var,roomname,resday) if len(res) == 0 : var["datecol"] = resday var["resdays"] = resdays var["resename"] = None cust.setDefaCustomer(var,custo) return assert len(res) == 1 resname = res[0].getResId() assert resname != None RFORM = util.RESFORM(var) reservation = RFORM.findElem(resname) assert reservation != None custname = reservation.getCustomerName() assert custname != None rutil.setReseName(var,resname) cust.setCustData(var,custname,custo) perperson = True list = [] S = util.SERVICES(var) mindate = None for r in reservation.getResDetail() : map = { "avail" : True, "resroomname" : r.getRoomName(), "resday" : r.getResDate(), "rlist_pricetotal" : con.BigDecimalToDecimal(r.getPriceTotal()), "rline_nop" : r.getNoP(),"rlist_priceperson" : con.BigDecimalToDecimal(r.getPrice()), "rlist_noc" : util.getIntField(r.getNoChildren()), "rlist_pricechildren" : con.BigDecimalToDecimal(r.getPriceChildren()), "rlist_noe" : util.getIntField(r.getNoExtraBeds()), "rlist_priceextra" : con.BigDecimalToDecimal(r.getPriceExtraBeds()), "rlist_serviceperperson" : r.isPerperson(), "rlist_roomservice" : r.getService(), "rlist_roompricelist" : r.getPriceListName()} if not r.isPerperson() : perperson = False if mindate == None : mindate = r.getResDate() elif mindate > r.getResDate() : mindate = r.getResDate() roomservice = cutil.ifnull(roomservice,r.getService()) roompricelist = cutil.ifnull(roompricelist,r.getPriceListName()) list.append(map) var["serviceperperson"] = perperson # restores default data previously saved reseparam.RESPARAM(resname).setParam(var) rutil.setServicePriceList(var,roomservice,roompricelist) var["datecol"] = mindate var["resdays"] = len(reservation.getResDetail()) # advance payment SUM = advarese.CALCULATE() SUM.calc(reservation) A = advarese.createAdvaRese(var) A.setVal(reservation,SUM.getTotal()) A.setCopy() confirm.createC(var).setReservationToVar(reservation) cutil.setJMapList(var,RLIST,list) cutil.setFooter(var,RLIST,"rlist_pricetotal",SUM.getTotal())
def getResStatusRese(var, r, room=None, today=None): """ Calculates and returns the status of the reservation Args: var r ReservationForm room room symbol today Returns: 0 reservation scheduled 1 reservation confirmed 2 reservation advance paid 3 reservation advanced expired 4 customer not arrived 5 vacant not paid 6 vacant paid 7 vacant excess payment 8 occupied, not paid 9 occupied, advance paid 10 occupied paid 11 occupied excess paid 12 canceled """ S = RESSTATUS() if today == None: today = con.today() S.forday = today # print today sym = r.getName() re = util.resStatus(r) if re == 0: return (12, S) li = rutil.getPayments(var, sym) for l in li: if room != None and room != l.getRoomName(): continue (S.arrival, S.departure) = rutil.calculateDates(S.arrival, S.departure, l) if today < S.arrival and re != 1: advance = r.getAdvanceDeposit() resstatusset = False if advance == None: resstatusset = True else: term = con.toJDate(r.getTermOfAdvanceDeposit()) if term != None: if today < term: resstatusset = True if resstatusset: if re == 2: return (1, S) if re == 3: return (0, S) # internal error, not expected # TO DO return (0, S) if r.getAdvancePayment() == None: return (3, S) if r.getAdvancePayment() < r.getAdvanceDeposit(): return (3, S) return (2, S) if re != 1: return (4, S) sta = None # 0 - not paid # 1 - paid # 2 - excess paid # 3 - advance paid for l in li: add = False re = con.toJDate(l.getResDate()) if util.isRoomService(l.getServiceType()) and re < today: add = True if not util.isRoomService(l.getServiceType()) and re <= today: add = True # print sym,add,l.getPriceTotal() if add: S.sumcost = con.addDecimal( S.sumcost, con.BigDecimalToDecimal(l.getPriceTotal())) S.costlist.append(l) else: if S.sumcostafter == None: S.sumcostafter = 0.0 S.sumcostafter = con.addDecimal( S.sumcostafter, con.BigDecimalToDecimal(l.getPriceTotal())) S.costlistafter.append(l) S.advancepayment = con.BigDecimalToDecimal(r.getAdvancePayment()) if S.advancepayment != None and S.advancepayment >= S.sumcost: sta = 3 else: bli = util.RESOP(var).findBillsForReservation(sym) for b in bli: (suma, advanced) = rutil.countPaymentsA(var, b.getName()) S.sumpay = con.addDecimal(S.sumpay, suma) S.advancepaymentused = con.addDecimal(S.advancepaymentused, advanced) S.sumpay = con.addDecimal(S.sumpay, S.advancepayment) # print sym,S.sumcost,S.sumpay if S.sumcost == S.sumpay and S.sumcost > 0.0: sta = 1 elif S.sumcost > S.sumpay: sta = 0 elif S.sumcost == 0 and S.sumpay == 0: sta = 0 else: sta = 2 S.advancepaymentleft = con.minusDecimal(S.advancepayment, S.advancepaymentused) if today <= S.departure: if sta == 0: return (8, S) if sta == 3: return (9, S) if sta == 2: return (11, S) return (10, S) if sta == 0: return (5, S) if sta == 3: return (6, S) if sta == 2: return (7, S) return (6, S)