Ejemplo n.º 1
0
 def record_rent(**kwargs):
     transaction = Transaction()
         
     for key in kwargs:
         transaction.__setattr__(key, kwargs[key])
     
     meta.Session.add(transaction)
     meta.Session.commit()
     session.save()
     
     #pulse
     unit = Unit.get_unit(kwargs['unitid'])
     property_name = Property.get_name_by_id(unit.propertyid)
     Pulse.create(
                  unitid = unit.id,
                  propertyid = unit.propertyid,
                  type = 'rent',
                  html = '<div class="unit"><a href="/unit/view/{1}">{3} #{2}</a> has paid ${0} rent for {4}/{5}.</div>'.format(
                             kwargs['amount'],
                             unit.id,
                             unit.label,
                             property_name,
                             kwargs['formonth'],
                             kwargs['foryear']
                             )
                  )
Ejemplo n.º 2
0
 def markPaid(self):
     unitId = request.POST['unitId']
     leaseId = request.POST['leaseId']
     amount = request.POST['amount']
     due = int(request.POST['due'])
     forMonth = int(request.POST['forMonth'])
     forYear = int(request.POST['forYear'])
     markLatePaid = request.POST['markLatePaid']
     
     result = {}
     if markLatePaid == '1':
         Transaction.record_late_paid(unitId,forMonth,forYear)
     else:
         companyId = request.environ.get("COMPANY_ID")
         now = datetime.datetime.today()
         id = str(uuid.uuid1())
         record = Unit.get_unit_info(unitId)
         
         curM = now.month
         curY = now.year
         
         if curM != forMonth or (curM == forMonth and curY != forYear):
             now = datetime.datetime.today()
             curHour = now.hour
             curMin = now.minute
             curSec = now.second
             date = datetime.datetime(forYear,forMonth,due,curHour,curMin,curSec)
         else:
             date = now
         
         Transaction.record_rent(
                                 id=str(uuid.uuid1()),
                                 companyid=companyId,
                                 propertyid=record[2],
                                 leaseid=leaseId,
                                 unitid=unitId,
                                 type='Rent',
                                 formonth=forMonth,
                                 foryear=forYear,
                                 date=date,
                                 income=1,
                                 name='Unit ' + record[0] + ', ' + record[1],
                                 amount=amount
                                 )
     
     return json.dumps(result)
Ejemplo n.º 3
0
 def undo_rent(unitId, forMonth, forYear):
     records = meta.Session.query(Transaction).filter(and_(Transaction.unitid==unitId,\
                                                          Transaction.formonth==forMonth,\
                                                          Transaction.foryear==forYear)).all()
     for record in records:
         meta.Session.delete(record)
     meta.Session.commit()
     session.save()
     
     #pulse
     unit = Unit.get_unit(unitId)
     property_name = Property.get_name_by_id(unit.propertyid)
     Pulse.create(
                  unitid = unit.id,
                  propertyid = unit.propertyid,
                  type = 'warning',
                  html = '<div class="unit"><a href="/unit/view/{1}">{3} #{2}</a>\'s rent for {0} has been unmarked.</div>'.format(
                             '{0}/{1}'.format(forMonth, forYear),
                             unit.id,
                             unit.label,
                             property_name
                             )
                  )
Ejemplo n.º 4
0
 def create(**kwargs):
     lease = Lease()
     
     for key in kwargs:
         lease.__setattr__(key, kwargs[key])
     
     meta.Session.add(lease)
     meta.Session.commit()
     session.save()
     
     unit = Unit.get_unit(kwargs['unitid'])
     property_name = Property.get_name_by_id(unit.propertyid)
     Pulse.create(
                  unitid = unit.id,
                  propertyid = unit.propertyid,
                  type = 'lease',
                  html = '<div class="unit">A new lease will begin on {0} in <a href="/unit/view/{1}">{3} #{2}</a></div>'.format(
                             kwargs['startdate'].strftime('%B %d'),
                             unit.id,
                             unit.label,
                             property_name
                             )
                  )
Ejemplo n.º 5
0
 def delete(leaseid):
     lease = Lease.get(leaseid)
     
     #pulse
     unit = Unit.get_unit(lease.unitid)
     property_name = Property.get_name_by_id(unit.propertyid)
     lease_start = lease.startdate.strftime("%B %d, %Y")
     unit_label = unit.label
     Pulse.create(
                  unitid = unit.id,
                  propertyid = unit.propertyid,
                  type = 'warning',
                  html = '<div class="unit">Lease starting from {0} for <a href="/unit/view/{1}">{3} #{2}</a>\'s has been deleted.</div>'.format(
                             lease_start,
                             unit.id,
                             unit_label,
                             property_name
                             )
                  )
     
     recycleId = Recycle.create("Lease starting from {0} deleted from {1} #{2}".format(lease_start, property_name, unit_label))
     lease.deleted = recycleId
     meta.Session.commit()
     session.save()
Ejemplo n.º 6
0
 def addExpense(self):
     errorslist = self.validate()
     
     if errorslist:
         obj = {
             'errors': errorslist
         }
         return json.dumps(obj)
     
     expenseType = request.POST['expenseType']
     payTo = request.POST['payTo']
     expenseAmount = '-'+request.POST['expenseAmount']
     expenseDate = request.POST['expenseDate']
     contactType = request.POST['contactType']
     contactId = request.POST['contactId']
     companyId = request.environ.get("COMPANY_ID")
     now = datetime.datetime.today()
     curHour = now.hour
     curMin = now.minute
     curSec = now.second
     date = expenseDate.split('/')
     date = datetime.datetime(int(date[2]),int(date[0]),int(date[1]),curHour,curMin,curSec)
     
     if contactType == 'unit':
         leaseId = Lease.get_current_of_unit(contactId)
         if not leaseId:
             leaseId = None
         unitInfo = Unit.get_unit_info(contactId)
         propertyId = unitInfo[2]
         payTo = payTo.split('#')
         prop = payTo[0]
         prop = prop.strip()
         unit = payTo[1]
         payTo = prop + ' #' + unit
         
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 leaseid=leaseId,
                                 unitid=contactId,
                                 companyid=companyId,
                                 propertyid=propertyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'property':
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 companyid=companyId,
                                 propertyid=contactId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'tenant':
         leaseId = Tenant_lease.get_lease_of_tenant(contactId)
         if not leaseId:
             leaseId = None
         record = Tenant.get_tenantInfo(contactId)
         if record:
             unitId = record[0]
             propertyId = record[1]
         else:
             unitId = None
             propertyId = None
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 leaseid=leaseId,
                                 unitid=unitId,
                                 companyid=companyId,
                                 propertyid=propertyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'contact':
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 contactid=contactId,
                                 companyid=companyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     else:
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 companyid=companyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     return json.dumps('')