Exemplo n.º 1
0
 def saveResidence(self):
     residenceid = request.POST['residenceId']
     tenantid = request.POST['tenantId']
     startdate = request.POST['startdate'].strip()
     enddate = request.POST['enddate'].strip()
     street = request.POST['street'].strip()
     city = request.POST['city'].strip()
     state = request.POST['state'].strip()
     landlordname = request.POST['landlordname'].strip()
     landlordphone = request.POST['landlordphone'].strip()
     landlordemail = request.POST['landlordemail'].strip()
     reason = request.POST['reason'].strip()
     
     errors = []
     if not valid.date(startdate):
         errors.append({'selector':'#residenceStart','message':'Please enter a valid date.'})
     if not valid.date(enddate):
         errors.append({'selector':'#residenceEnd','message':'Please enter a valid date.'})
     if not valid.date(startdate, enddate):
         errors.append({'selector':'#residenceEnd','message':'The end date is greater than the start date.'})
     if not valid.street(street):
         errors.append({'selector':'#residenceStreet','message':'Please enter a valid street.'})
     if not valid.city(city):
         errors.append({'selector':'#residenceCity','message':'Please enter a valid city.'})
     if not valid.state(state):
         errors.append({'selector':'#residenceState','message':'Please enter a valid state.'})
     """
     if not valid.name(landlordname) and len(landlordname):
         errors.append({'selector':'#residenceLandlord','message':'Please enter a valid name for the landlord.'})
     """
     if not valid.phone(landlordphone) and len(landlordphone):
         errors.append({'selector':'#residenceLandlordPhone','message':'Please enter a phone number for the landlord.'})
     if not valid.email(landlordemail) and len(landlordemail):
         errors.append({'selector':'#residenceLandlordEmail','message':'Please enter a valid email for the landlord.'})
     if not valid.text(reason) and len(reason):
         errors.append({'selector':'#residenceReasonLeaving','message':'There is an error with the "reason for leaving" field.  Please double check you didn\'t enter any strange characters.'})
     if errors:
         return json.dumps({'errors':errors})
     
     startdate = startdate.split("/")
     startdate = datetime.date(int(startdate[2]), int(startdate[0]), int(startdate[1]))
     
     enddate = enddate.split("/")
     enddate = datetime.date(int(enddate[2]), int(enddate[0]), int(enddate[1]))
     
     if residenceid == '0':
         residenceid = str(uuid.uuid1())
         model.Previous_residence(residenceid, tenantid, startdate, enddate, street,\
                                  city, state, landlordname, landlordemail, landlordphone, reason) 
     else:
         model.Previous_residence.save(residenceid, tenantid, startdate, enddate, street,\
                                       city, state, landlordname, landlordemail, landlordphone, reason) 
     
     redirect_to(protocol=settings.PROTOCOL, controller='tenant', action='json', id=tenantid)
Exemplo n.º 2
0
 def endLease(self):
     leaseid = request.POST['leaseid']
     unitid = request.POST['unitId']
     
     if valid.date(request.POST['moveOutDate']):
         out = request.POST['moveOutDate'].split('/')
         outdate = datetime.date(int(out[2]), int(out[0]), int(out[1]))
         #pulse
         unit = model.Unit.get_unit(unitid)
         property_name = model.Property.get_name_by_id(unit.propertyid)
         model.Pulse.create(
                      unitid = unit.id,
                      propertyid = unit.propertyid,
                      type = 'lease',
                      html = '<div class="unit">Moveout date has been set for <a href="/unit/view/{1}">{3} #{2}</a> to {0}</div>'.format(
                                 outdate.strftime("%B %d, %Y"),
                                 unit.id,
                                 unit.label,
                                 property_name
                                 )
                      )
     else:
         outdate = None
     model.Lease.update(leaseid, outdate=outdate)
     redirect_to(controller='lease', action='json', id=leaseid)
Exemplo n.º 3
0
 def validate(self):
     type = request.POST['type']
     action = request.POST['action']
     errorslist = []
     
     if type == 'expense':
         transType = request.POST['expenseType']
         transTo = request.POST['payTo']
         transAmount = request.POST['expenseAmount']
         transDate = request.POST['expenseDate']
         if transType == 'Choose expense type':
             errorslist.append({"message":"Please choose an expense type from the drop down menu"})
         if not valid.label(transTo):
             errorslist.append({'selector':'#expensePay', "message":"Please enter a valid name"})
         if not valid.money(transAmount):
             errorslist.append({'selector':'#expenseAmount', "message":"Please enter a valid amount"})
         if not valid.date(transDate):
             errorslist.append({'selector':'#expenseDate', "message":'Please enter a valid date (mm/dd/yyyy)'})
         transDate = transDate.split('/')
         year = int(transDate[2])
         if year < 2009:
             errorslist.append({'selector':'#expenseDate', "message":'Cannot add a transaction before 2009'})
         
     else:
         transType = request.POST['incomeType']
         transFrom = request.POST['incomeFrom']
         transAmount = request.POST['incomeAmount']
         transDate = request.POST['incomeDate']
         if transType == 'Choose income type':
             errorslist.append({"message":"Please choose an income type from the drop down menu"})
         if not valid.label(transFrom):
             errorslist.append({'selector':'#incomeFrom', "message":"Please enter a valid name"})
         if not valid.money(transAmount):
             errorslist.append({'selector':'#incomeAmount', "message":"Please enter a valid amount"})
         if not valid.date(transDate):
             errorslist.append({'selector':'#incomeDate', "message":'Please enter a valid date (mm/dd/yyyy)'})
         transDate = transDate.split('/')
         year = int(transDate[2])
         if year < 2009:
             errorslist.append({'selector':'#expenseDate', "message":'Cannot add a transaction before 2009'})
             
     return errorslist
Exemplo n.º 4
0
    def endLease(self):
        leaseid = request.POST["leaseid"]
        unitid = request.POST["unitId"]

        if valid.date(request.POST["moveOutDate"]):
            out = request.POST["moveOutDate"].split("/")
            outdate = datetime.date(int(out[2]), int(out[0]), int(out[1]))
            # pulse
            unit = model.Unit.get_unit(unitid)
            property_name = model.Property.get_name_by_id(unit.propertyid)
            model.Pulse.create(
                unitid=unit.id,
                propertyid=unit.propertyid,
                type="lease",
                html='<div class="unit">Moveout date has been set for <a href="/unit/view/{1}">{3} #{2}</a> to {0}</div>'.format(
                    outdate.strftime("%B %d, %Y"), unit.id, unit.label, property_name
                ),
            )
        else:
            outdate = None
        model.Lease.update(leaseid, outdate=outdate)
        redirect_to(protocol=settings.PROTOCOL, controller="lease", action="json", id=leaseid)
Exemplo n.º 5
0
 def updateTenant(self):
     tenantid = request.POST['tenantId']
     fname = request.POST['fname']
     lname = request.POST['lname']
     email = request.POST['email']
     phone = request.POST['phone']
     if len(request.POST['dob'].strip()):
         birthday = request.POST['dob'].split('/')
         dob = datetime.date(int(birthday[2]), int(birthday[0]), int(birthday[1]))
     else:
         dob = None
     ssn = request.POST['ssn']
     
     errors = []
     if not valid.name(fname):
         errors.append({'selector':'#tenantFname','message':'The first name is invalid.'})
     if not valid.name(lname):
         errors.append({'selector':'#tenantLname','message':'The last name is invalid.'})
     if not valid.phone(phone) and len(phone):
         errors.append({'selector':'#tenantPhone','message':'The phone number is not valid.'})
     if not valid.email(email) and len(email):
         errors.append({'selector':'#tenantEmail','message':'Please enter a valid email address.'})
     if not valid.date(request.POST['dob']) and len(request.POST['dob']):
         errors.append({'selector':'#tenantDOB','message':'Please enter a valid date for the D.O.B.'})
     if not valid.ssn(ssn) and len(ssn):
         errors.append({'selector':'#tenantSSN','message':'Please enter a valid social security number.'})
     if errors:
         return json.dumps({'errors':errors})
     
     model.Tenant.update(
                         id=tenantid,
                         first_name=fname,
                         last_name=lname,
                         email=email,
                         phone=phone,
                         dob=dob,
                         ssn=ssn)
     redirect_to(protocol=settings.PROTOCOL, controller='tenant', action='json', id=tenantid)
Exemplo n.º 6
0
    def validate(self, action=None):
        startdate = request.POST["startdate"]
        enddate = request.POST["enddate"]
        deposit = request.POST["deposit"]
        rent = request.POST["rent"].replace(",", "")
        latecharge = request.POST["latecharge"]
        unitid = request.POST["unitId"]
        now = datetime.date.today()
        m2m = request.POST["m2m"]
        if m2m == "false":
            end_date = request.POST["enddate"].split("/")
            end_date = datetime.date(int(end_date[2]), int(end_date[0]), int(end_date[1]))

        errorslist = []

        if request.POST["m2m"] == "false":
            if startdate and not enddate:
                errorslist.append(
                    {"selector": "#lease-end", "message": "There is contract start date but no contract end date"}
                )
            elif enddate and not startdate:
                errorslist.append(
                    {"selector": "#lease-start", "message": "There is contract end date but no contract start date"}
                )
            elif not valid.date(startdate):
                errorslist.append(
                    {"selector": "#lease-start", "message": 'Please enter a valid date, i.e. "01/08/2010"'}
                )
            elif not valid.date(enddate):
                errorslist.append({"selector": "#lease-end", "message": 'Please enter a valid date, i.e. "01/08/2010"'})
            elif not valid.date(startdate, enddate):
                errorslist.append(
                    {"selector": "#lease-start", "message": "Contract start date cannot be after contract end date"}
                )
            elif m2m == "false" and now > end_date:
                errorslist.append(
                    {"selector": "#lease-end", "message": "Sorry, an expired lease contract cannot be added/edited"}
                )
        else:
            if not valid.date(startdate):
                errorslist.append(
                    {"selector": "#lease-start", "message": 'Please enter a valid date, i.e. "01/08/2010"'}
                )
        start = startdate.split("/")
        startYear = int(start[2])
        if startYear < 2006:
            errorslist.append({"selector": "#lease-start", "message": "Start date must be after 2005"})
        if not valid.money(rent):
            errorslist.append({"selector": "#lease-rent", "message": "Rent: Please enter a valid value"})
        if not valid.money(deposit):
            errorslist.append({"selector": "#lease-deposit", "message": "Deposit: Please enter a valid value"})
        if latecharge and not valid.money(latecharge):
            errorslist.append({"selector": "#lease-lateFee", "message": "Late Fee: Please enter a valid value"})

        if not valid.rent(rent):
            errorslist.append({"selector": "#lease-rent", "message": "That's a bit too high for monthly rent."})
        if not valid.deposit(deposit):
            errorslist.append({"selector": "#lease-deposit", "message": "That's a bit too high for a deposit."})
        if not valid.latecharge(latecharge):
            errorslist.append({"selector": "#lease-lateFee", "message": "That's a bit too high for late charge."})

        if action == "create" and not errorslist:
            now = datetime.date.today()
            start = startdate.split("/")
            startYear = int(start[2])
            start = datetime.date(int(start[2]), int(start[0]), int(start[1]))

            if model.Lease.overlap(unitid, startdate):
                errorslist.append(
                    {"message": "Lease date overlap. Please make sure this lease does not overlap with another lease."}
                )
            elif model.Lease.has_future_lease(unitid) and start > now:
                errorslist.append(
                    {
                        "message": "This unit already has a future lease set up. Please delete that one before creating a new one."
                    }
                )

        return errorslist