Exemple #1
0
 def foxAlert():        
     companyid = request.environ.get('COMPANY_ID')
     username = request.environ.get('REMOTE_USER')
     propertyids = Property.get_property_ids_of_username(username)
     
     mc = Memcache()
     key = 'foxalert:{0}'.format(username)
     fox_alert = mc.get(key)
     if fox_alert == 'Saved': return False
     
     if len(propertyids) == 0:
         return {
                 'title': "Welcome!",
                 'message':"I'm here to help you. Let's get started by creating a property!",
                 'button':"Let's get started!",
                 'link':'/property/setup'
                 }
     
     if Property.totalUnitsInProperties(propertyids) == 0:
         return {
                 'title': "Create a unit!",
                 'message':"I just realized you don't have any units... let's create one!",
                 'button':"Okay!",
                 'link':'/property/setup/{0}'.format(propertyids[0])
                 }
         
     units_with_floorplans = Company.getUnitsWithFloorplans(propertyids)
     if len(units_with_floorplans) == 0:
         units = Unit.get_units_of_properties(propertyids)
         unitid = units[0].id
         propertyid = units[0].propertyid
         return {
                 'title': "No floorplans yet?",
                 'message': "Your units need floorplans. Floorplans are cool because you can apply them to other units in the same building.",
                 "button": "Add Floorplans",
                 'link': '/property/setup/{0}/{1}'.format(propertyid,unitid)
                 }
     
     lease = Lease.get_earliest(propertyids)
     if not lease:
         unitid = units_with_floorplans[0].id
         return {
                 'title': "Got leases?",
                 'message': "Are you ready to add a lease to one of your units?",
                 "button": "Yes, take me there!",
                 'link': '/unit/view/{0}'.format(unitid)
                 }
     
     mc.set(key, 'Saved', time=86400)
     
     return False
Exemple #2
0
 def monthlyOccupancy(self):
     
     propertyid = request.POST['propertyid']
     
     # get current month / year
     today = datetime.date.today()
     this_month = today.month
     prev_year = today.year - 1
     
     months_arr = []
     occupancy_data = []
     
     for i in xrange(1, 13):
         current_month = this_month + i
         current_year = prev_year
         if current_month > 12:
             current_month = current_month - 12
             current_year = prev_year + 1
         months_arr.append(current_month)
         current_percentage = Property.occupancyPercentage(propertyid, current_year, current_month)
         occupancy_data.append(current_percentage)
     
     months_arr = map(monthToString, months_arr)
             
     return json.dumps({
         'xAxis': months_arr,
         'series': [{
             'name': 'Occupancy',
             'data': occupancy_data
         }]
     })
Exemple #3
0
 def totalRentPaidInMonth(year, month):
     
     from rentfox.model import Lease, Transaction
     
     proplist = Property.get_property_ids_of_username(request.environ.get('REMOTE_USER'))
     
     total_rent_paid = meta.Session.query(Transaction).\
         outerjoin((Lease,Lease.id==Transaction.leaseid), (Unit,Lease.unitid==Unit.id)).\
         filter(Transaction.type == 'Rent').\
         filter(Transaction.foryear == year).\
         filter(Lease.deleted == None).\
         filter(Unit.propertyid.in_(proplist)).\
         filter(Transaction.formonth == month).count()
     
     return total_rent_paid
Exemple #4
0
 def rename(newlabel, unitid):
     
     from rentfox.model.property import Property
     
     unit = meta.Session.query(Unit).filter(Unit.deleted==None).filter_by(id=unitid).first()
     unit.label = newlabel
     
     meta.Session.commit()
     session.save()
     
     # update index
     property = Property.get_property(unit.propertyid)
     text = ' '.join([str(newlabel), str(newlabel), str(newlabel), str(property.name), str(property.address)])
     index_update = IndexUpdate()
     index_update.updateItem('unit', unitid)
     index_update.updateData(text)
     index_update.update()
Exemple #5
0
 def totalActiveLeasesInMonth(year, month):
     
     from rentfox.model import Lease, Transaction
     
     proplist = Property.get_property_ids_of_username(request.environ.get('REMOTE_USER'))
     
     
     lastDay = calendar.monthrange(year,month)
     lastDay = lastDay[1]
     firstDate = datetime.date(year,month,1)
     lastDate = datetime.date(year,month,int(lastDay))
     
     total_leases = meta.Session.query(Lease).\
         join(Unit).\
         filter(Unit.propertyid.in_(proplist)).\
         filter(Lease.deleted == None).\
         filter(and_(Lease.startdate <= lastDate, or_(Lease.outdate==None, Lease.outdate >= firstDate))).count()
     
     return total_leases
Exemple #6
0
 def delete(unitid):
     from rentfox.model.recycle import Recycle
     from rentfox.model.property import Property
     from rentfox.model.lease import Lease
     
     unit = meta.Session.query(Unit).filter_by(id=unitid).first()
     property_name = Property.get_name_by_id(unit.propertyid)
     
     recycleId = Recycle.create("Unit {0} deleted from {1}".format(unit.label, property_name))
     
     unit.deleted = recycleId
     Lease.deleteByUnitId(unitid, recycleId)
     
     meta.Session.commit()
     session.save()
     
     index_update = IndexUpdate()
     index_update.updateItem('unit', unitid)
     index_update.updateTerm('deleted', 0, recycleId)
     index_update.update()
Exemple #7
0
 def create(propertyid, label, index):
     newUnit = Unit()
     newUnit.id = str(uuid.uuid1())
     newUnit.propertyid = propertyid
     newUnit.label = label
     meta.Session.add(newUnit)
     
     from rentfox.model.property import Property
     
     # index for searching later
     property = Property.get_property(propertyid)
     type = 'unit'
     id = newUnit.id
     text = ' '.join([str(label), str(label), str(label), str(property.name), str(property.address)])
     terms = [
              {'type':'company', 'id':request.environ.get('COMPANY_ID')},
              {'type':'property', 'id':propertyid},
              {'type':'unit', 'id':id}
              ]
     
     index.index(type, id, text, terms)
Exemple #8
0
 def find(self):
 	
     q = request.GET['q']
     
     if not valid.search(q):
         return json.dumps({'errors':[{'selector':'', "message":"Search only accepts letters and numbers. Please try again."}]})
     
     page = int(request.GET['page'])
     limit = int(request.GET['limit'])
     filter = str(request.GET['filter'])
     
     username = request.environ.get('REMOTE_USER')
     property_access_list = Property.get_property_ids_of_username(username)
     
     s = Search(q)
     s.filter('company', request.environ.get('COMPANY_ID'))
     s.filter('property', property_access_list)
     s.filter('deleted', '0')
     if filter != 'all': s.filter('type', filter)
     matches = s.find(page, limit) 
     partial_results = matches['results']
     
     results = []
     for result in partial_results:
         type = result['type']
         uuid = result['uuid']
         try:
             if type == 'property':
                 property = Property.get_property(uuid)
                 results.append({'type': type,
                                 'id': uuid,
                                 'title': property.name,
                                 'link': '/property/view/{0}'.format(property.id),
                                 'description': '{0}, {1}, {2} {3}'.format(property.address, 
                                                                           property.city, 
                                                                           property.state, 
                                                                           property.zip)})
             elif type == 'unit':
                 unit = Unit.get_unit(uuid)
                 property = Property.get_property(unit.propertyid)
                 results.append({'type': type,
                                 'id': uuid,
                                 'title': '{0} #{1}'.format(property.name, unit.label),
                                 'link': '/unit/view/{0}'.format(unit.id),
                                 'description': '{0} #{1}, {2}, {3} {4}'.format(property.address, 
                                                                                unit.label, 
                                                                                property.city, 
                                                                                property.state, 
                                                                                property.zip)})
             elif type == 'tenant':
                 tenant = Tenant.get(uuid)
                 
                 details = []
                 if tenant.email: details.append(tenant.email)
                 if tenant.phone: details.append(tenant.phone)
                 contact_info = '<br />'.join(details)
                 
                 results.append({'type': type,
                                 'id': uuid,
                                 'title': '{0} {1}'.format(tenant.first_name, tenant.last_name),
                                 'link': '/tenant/view/{0}'.format(tenant.id),
                                 'description': contact_info})
             elif type == 'contact':
                 contact = Contact.get(uuid)
                 
                 details = []
                 if contact.email: details.append(contact.email)
                 if contact.phone: details.append(contact.phone)
                 contact_info = '<br />'.join(details)
                 
                 address = '<br />{0}, {1}'.format(contact.address, contact.city) if contact.address and contact.city else ''
                 description = '<br />{0}'.format(contact.description) if contact.description else ''
                 
                 results.append({'type': type,
                                 'id': uuid,
                                 'title': contact.label,
                                 'description': '{0}{1}{2}'.format(contact_info,
                                                                     address,
                                                                     description)})
         except:
             pass
         
     return json.dumps({'results':results,
                        'start':matches['start'],
                        'end':matches['end'],
                        'page':matches['page'],
                        'total':matches['total']})
Exemple #9
0
 def delete_units(units, propertyid):
     
     from rentfox.model.property import Property
     from rentfox.model.recycle import Recycle
     from rentfox.model.lease import Lease
     
     count = 0
     
     property_name = Property.get_name_by_id(propertyid)
     recycleId = Recycle.create("Units deleted from {0}".format(property_name))
     
     index_update = IndexUpdate()
     
     if '-' in units:
         unitRange = units.split('-')
         start = unitRange[0]
         end = unitRange[1]
         
         # Special case: Allow for labels such as 12-B or C-2 to be deleted.
         if (start.isdigit() and end.isalpha())\
             or (end.isdigit() and start.isalpha()):
             
             existingUnits = Unit.get_units_list(propertyid)
             if str(units) in existingUnits:
                 
                 unit = Unit.get_unit_with_propertyid(units, propertyid)
                 unit.deleted = recycleId
                 
                 index_update.updateItem('unit', unit.id)
                 index_update.updateTerm('deleted', 0, recycleId)
                 index_update.update()
                 
                 Lease.deleteByUnitId(unit.id, recycleId)
                 count += 1
         else:
             existingUnits = Unit.get_units_list(propertyid)
             for unit in range(int(start), int(end) + 1):
                 if str(unit) in existingUnits:
                     unit = Unit.get_unit_with_propertyid(str(unit), propertyid)
                     unit.deleted = recycleId
                     
                     index_update.updateItem('unit', unit.id)
                     index_update.updateTerm('deleted', 0, recycleId)
                     index_update.update()
                     
                     Lease.deleteByUnitId(unit.id, recycleId)
                     count += 1
     elif ',' in units:
         unitList = units.split(',')
         existingUnits = Unit.get_units_list(propertyid)
         for unit in unitList:
             if str(unit) in existingUnits:
                 unit = Unit.get_unit_with_propertyid(str(unit), propertyid)
                 unit.deleted = recycleId
                 
                 index_update.updateItem('unit', unit.id)
                 index_update.updateTerm('deleted', 0, recycleId)
                 index_update.update()
                 
                 Lease.deleteByUnitId(unit.id, recycleId)
                 count += 1
     else:
         unit = Unit.get_unit_with_propertyid(units, propertyid)
         unit.deleted = recycleId
         
         index_update.updateItem('unit', unit.id)
         index_update.updateTerm('deleted', 0, recycleId)
         index_update.update()
         
         Lease.deleteByUnitId(unit.id, recycleId)
         count += 1
     
     if count == 0:
         Recycle.delete(recycleId)
         return False
         
     meta.Session.commit()
     session.save()