Exemple #1
0
def ParseTenantsPaymentData(excel, buildingOf, dbBuildingName):

    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return
    building_name = os.path.splitext(
        os.path.basename(excel).replace(utils.config.excelPaymentFilePrefix,
                                        '').strip())[0].strip()

    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name

    #dict year->sheet
    sheetsOf = GetPaymentSheets(book)

    if not sheetsOf:
        return

    for (year, sheet) in sheetsOf.items():
        #go over all excel rows, each represents an apartment
        for excelRecord in excel_helper.ExtractApartments(sheet, 2):

            apartment_number = excelRecord.appartment
            app = building.apartmentOf[apartment_number]

            excelRecord.monthlyData(year, app.excelCellInfoPerDate)
Exemple #2
0
def ParseTenantsGeneralData(excel, buildingOf, dbBuildingName):
    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return
    building_name = os.path.splitext(
        os.path.basename(excel).replace(utils.config.excelGeneralFilePrefix,
                                        '').strip())[0].strip()

    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name

    sheet = GetGeneralSheet(book)

    if not sheet:
        return

    #go over all excel rows, each represents an apartment
    for excelRecord in excel_helper.ExtractApartments(sheet, 2):

        apartment_number = excelRecord.appartment

        app = building.apartmentOf[apartment_number]

        app.apartment_number = apartment_number
        app.recent_payment = excelRecord.payment

        tenant = GetTenant(excelRecord)
        owner = GetOwner(excelRecord)

        if tenant or owner:
            #no owner, only tenant, so tenant is owner
            if not owner:
                app.owner = tenant
                app.owner.defacto = True
            else:
                #there is an owner
                app.owner = owner
                #if there is a tenant than he is the renter otherwise there is only an owner
                if tenant:
                    app.renter = tenant
                    app.renter.defacto = True
                else:
                    app.owner.defacto = True

        #if no details for renter and owner store an empty person as owner
        else:
            app.owner = elements.Person()
            app.owner.defacto = True

        info_db = sqlite3.connect(utils.DB_INFO)
        cursor = info_db.cursor()
        cursor.execute(
            '''SELECT excel_header, field_type, template_name from fields''')
        for excel_header, field_type, template_name in cursor.fetchall():
            app.dynamicData[
                template_name] = excel_utils.ResolveDynamicFieldValue(
                    excelRecord, excel_header, field_type)
Exemple #3
0
def ParseTenantSpecialsData(excel, buildingOf, dbBuildingName):

    book = excel_helper.OpenExcelFile(excel)
    building_name, debt_description = "", ""

    if not book:
        return

    #print 'os.path.basesname(excel): ',os.path.basename(excel)
    #print 'os.path.basename(excel).replace(utils.config.excelSpecialFilePrefix', os.path.basename(excel).replace(utils.config.excelSpecialFilePrefix, '')
    #die()
    building_name_debt_description = os.path.splitext(
        os.path.basename(excel).replace(utils.config.excelSpecialFilePrefix,
                                        '').strip())[0].strip()
    #print 'building_name_debt_description: '
    try:
        building_name, debt_description = building_name_debt_description.rsplit(
            '-', 1)
        #print 'wallaaaa :',building_name, debt_description
        #print die()
    except:
        print 'oops'
        #print die()
        pass

    building_name = building_name.strip()
    debt_description = debt_description.strip()

    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name

    sheetsOf = GetSpecialPaymentSheet(book)

    if not sheetsOf:
        #print 'returning'
        #die()
        return

    for (year, sheet) in sheetsOf.items():
        #print year

        #go over all excel rows, each represents an apartment
        for excelRecord in excel_helper.ExtractApartments(sheet, 2):

            #print 'record!!!'
            apartment_number = excelRecord.appartment
            #print 'apartment_number!!!', apartment_number
            app = building.apartmentOf[apartment_number]

            app.apartment_number = apartment_number

            excelRecord.specialYearlyData(year, app.excelCellInfoPerDate,
                                          debt_description)
Exemple #4
0
def ParseTenantsGeneralData(excel, buildingOf, dbBuildingName):

    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return
    building_name = os.path.splitext(
        os.path.basename(excel).replace(utils.config.excelGeneralFilePrefix,
                                        '').strip())[0].strip()
    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name

    sheet = GetGeneralSheet(book)

    if not sheet:
        return

    #go over all excel rows, each represents an apartment
    for excelRecord in excel_helper.ExtractApartments(sheet, 2):

        apartment_number = excelRecord.appartment

        app = building.apartmentOf[apartment_number]

        app.apartment_number = apartment_number
        app.recent_payment = excelRecord.payment

        tenant = GetTenant(excelRecord)
        owner = GetOwner(excelRecord)

        if tenant or owner:
            #no owner, only tenant, so tenant is owner
            if not owner:
                app.owner = tenant
                app.owner.defacto = True
            else:
                #there is an owner
                app.owner = owner
                #if there is a tenant than he is the renter otherwise there is only an owner
                if tenant:
                    app.renter = tenant
                    app.renter.defacto = True
                else:
                    app.owner.defacto = True

        #if no details for renter and owner store an empty person as owner
        else:
            app.owner = elements.Person()
            app.owner.defacto = True
Exemple #5
0
def ParseTenantsGeneralData(excel, buildingOf, dbBuildingName):

    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return

    sheet = GetGeneralSheet(book)

    if not sheet:
        return

    #building_codes = set()
    #go over all excel rows, each represents an apartment
    for excelRecord in excel_helper.ExtractApartments(sheet, 1, 1, 0):
        #print 'hey: ', excelRecord.building_code
        #building_codes.insert(excelRecord.building_code)
        building_name = excelRecord.building
        print excelRecord.building_code, excelRecord.appartment

        #if there is a specific building to update
        if not dbBuildingName or dbBuildingName == building_name:

            building = buildingOf[building_name]
            building.based_on_files.add(excel)
            building.building_name = building_name

            apartment_number = excelRecord.appartment
            app = building.apartmentOf[apartment_number]

            app.apartment_number = apartment_number
            app.focal_point = excelRecord.focal_point
            app.renter = GetRenter(excelRecord)
            app.owner = GetOwner(excelRecord)

            # When the apartment is marked as focal point, store it only on the owner's behalf ( if an owner exists )
            if app.focal_point and app.owner:
                app.owner.focal_point = True

            #could be that no renter or owner details exist
            if app.renter or app.owner:
                if app.renter:
                    app.renter.defacto = True
                else:
                    app.owner.defacto = True

            #if no details for renter and owner store an empty person as owner
            else:
                app.owner = elements.Person()
                app.owner.defacto = True
Exemple #6
0
def ParseTenantsPaymentData(excel, buildingOf, dbBuildingName):
        
    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return
    building_name = os.path.splitext(os.path.basename(excel).replace(utils.config.excelPaymentFilePrefix, '').strip())[0].strip()
    
    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name    

    #dict year->sheet
    sheetsOf = GetPaymentSheets(book)
    
    if not sheetsOf:
        return                    
    
    for (year, sheet) in sheetsOf.items():   
        global indexAppartnment
        indexAppartnment = -1
        apartment_number = ""
        
        #go over all excel rows, each represents an apartment
        for excelRecord in excel_helper.ExtractApartments(sheet, 2):
            
            indexAppartnment += 1
                    
            appStart = ( indexAppartnment%4 == 0)
            
            if appStart and indexAppartnment:
                #time to insert  
                apt_num = utils.Intify(apartment_number) if utils.Intify(apartment_number) else apartment_number
                app = building.apartmentOf[apt_num]
                app.apartment_number = apt_num                
                recordToKeep.monthlyData(year, app.excelCellInfoPerDate)                                                
            if appStart:
                apartment_number = excelRecord.appartment
                recordToKeep = excelRecord
                
        #insert last appartment       
    if (indexAppartnment + 1) % 4 == 0:
            #time to insert  
            apt_num = utils.Intify(apartment_number) if utils.Intify(apartment_number) else apartment_number
            app = building.apartmentOf[apt_num]
            app.apartment_number = apt_num                
            recordToKeep.monthlyData(year, app.excelCellInfoPerDate)        
Exemple #7
0
def GetBuildingCodeDict():
    excel = os.path.join(utils.config.rootBuildingsDir,
                         utils.config.excelGeneralFilePrefix + '.xls')
    assert os.path.exists(excel)
    codesOf = {}

    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return

    sheet = GetGeneralSheet(book)

    if not sheet:
        return

        # go over all excel rows, each represents an apartment
    for excelRecord in excel_helper.ExtractApartments(sheet, 1, 1, 0):
        codesOf[excelRecord.building_code] = excelRecord.building

    return codesOf
Exemple #8
0
def ParseTenantsGeneralData(excel, buildingOf, dbBuildingName):
    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return

    sheet = GetGeneralSheet(book)

    if not sheet:
        return

        # go over all excel rows, each represents an apartment
    for excelRecord in excel_helper.ExtractApartments(sheet, 1, 1, 0):

        building_name = excelRecord.building

        # if there is a specific building to update
        if not dbBuildingName or dbBuildingName == building_name:

            building = buildingOf[building_name]
            building.based_on_files.add(excel)
            building.building_name = building_name

            apartment_number = excelRecord.appartment
            app = building.apartmentOf[apartment_number]

            app.apartment_number = apartment_number

            app.renter = GetRenter(excelRecord)
            app.owner = GetOwner(excelRecord)

            # could be that no renter or owner details exist
            if app.renter or app.owner:
                if app.renter:
                    app.renter.defacto = True
                else:
                    app.owner.defacto = True

            # if no details for renter and owner store an empty person as owner
            else:
                app.owner = elements.Person()
                app.owner.defacto = True
Exemple #9
0
def ParseTenantSpecialsData(excel, buildingOf, dbBuildingName):    
    book = excel_helper.OpenExcelFile(excel)
    building_name, debt_description = "", ""
    
    if not book:
        return
    building_name_debt_description = os.path.splitext(os.path.basename(excel).replace(utils.config.excelSpecialFilePrefix, '').strip())[0].strip()
    
    try:
        building_name, debt_description = building_name_debt_description.rsplit('-', 1)
    except:
        pass
    
    building_name = building_name.strip()
    debt_description = debt_description.strip()        
    
    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name

    #dict year->sheet
    sheetsOf = GetPaymentSheets(book, utils.config.excelSpecialSheetPrefix)
    
    if not sheetsOf:
        return                    
    
    for (year, sheet) in sheetsOf.items():    
        #go over all excel rows, each represents an apartment
        for excelRecord in excel_helper.ExtractApartments(sheet, 2):
            
            apartment_number = excelRecord.appartment
            app = building.apartmentOf[apartment_number]
            
            app.apartment_number = apartment_number            
            
            excelRecord.specialYearlyData(year, app.excelCellInfoPerDate, debt_description)    
Exemple #10
0
def ParseTenantsPaymentData(excel, buildingOf, dbBuildingName):
    # get a dict of building code -> building name
    codesOf = GetBuildingCodeDict()

    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return

    sheet = GetPaymentSheet(book)

    if not sheet:
        return

        # first building starts here
    start_row = 14

    while True:
        skip_building = False
        # column 10 = K, thats where the building code supposed to be
        building_code_cell = sheet.cell_value(start_row, 10)

        # no more buiuldings, finish everything
        if not len(building_code_cell):
            break
        # extract building code
        building_code = utils.Intify(
            building_code_cell.split(
                'חובות דיירים'.decode('utf-8'))[-1].strip())

        if building_code:
            try:
                # take building name from the dict extracted from the general tenants sheet
                building_name = codesOf[building_code]
                print building_code, building_name
                # retrieve building object
                building = buildingOf[building_name]
                building.based_on_files.add(excel)
                building.building_name = building_name
            except KeyError:
                skip_building = True

        # if for some reason there is no code, iterate the rows but don't update building tenants
        else:
            skip_building = True

        # tenants data starts 2 rows after the header
        start_row += 2
        for num_tenants, excelRecord in enumerate(
                excel_helper.ExtractApartments(sheet, start_row + 2, 2,
                                               start_row)):
            if skip_building:
                continue

            apartment_number = excelRecord.appartment
            app = building.apartmentOf[apartment_number]
            excelRecord.monthlyData(app.excelCellInfoPerDate)

            # set pointer to the last tenant in the table
        start_row += (num_tenants + 1) * 2
        # set pointer to the next building
        start_row += 5
Exemple #11
0
def ParseTenantsGeneralData(excel, buildingOf, dbBuildingName):    
    print excel
    book = excel_helper.OpenExcelFile(excel)
    if not book:
        return    
    building_name = os.path.splitext(os.path.basename(excel).replace(utils.config.excelGeneralFilePrefix, '').strip())[0].strip()
    print building_name
    building = buildingOf[building_name]
    building.based_on_files.add(excel)
    building.building_name = building_name
    
    sheet = GetGeneralSheet(book)
    
    if not sheet:
        return                    
    
    global indexAppartnment
    indexAppartnment = -1
    renter_mails = []
    owner_mails = []
    renter_phones = []
    owner_phones = []
    renter_name = ""
    owner_name = ""
    payment = 0
    apartment_number = ""
    
    #go over all excel rows, each represents an apartment
    for i, excelRecord in enumerate(excel_helper.ExtractApartments(sheet, 2)):
        indexAppartnment += 1
        
        appStart = ( indexAppartnment%4 == 0)
        
        if appStart and indexAppartnment:
            #time to insert
            apt_num = utils.Intify(apartment_number) if utils.Intify(apartment_number) else apartment_number
            app = building.apartmentOf[apt_num]
            app.apartment_number = apt_num
            
            app.recent_payment = payment
            if type(renter_name) == int or len(renter_name):
                app.renter = elements.Person(renter_name, renter_mails, renter_phones )
            else:
                app.renter = None
                
            if type(owner_name) == int or len(owner_name):
                app.owner = elements.Person(owner_name, owner_mails, owner_phones )
            else:
                app.owner = None
                
            if app.renter:
                app.renter.defacto = True
            else:
                app.owner.defacto = True            
                        
            
            #initialize
            renter_mails = []
            owner_mails = []
            renter_phones = []
            owner_phones = []
            renter_name = ""
            owner_name = ""
            payment = 0
            apartment_number = ""
                
        if indexAppartnment % 4 == 0:            
            apartment_number = excelRecord.appartment            
            renter_name = excelRecord.renter
            owner_name = excelRecord.owner
            payment = excelRecord.payment
            
        if len(excelRecord.renterMails):
            renter_mails.append(','.join(excelRecord.renterMails))
        if len(excelRecord.ownerMails):
            owner_mails.append(','.join(excelRecord.ownerMails))
        if len(excelRecord.renterPhones):
            renter_phones.append(','.join(excelRecord.renterPhones))
        if len(excelRecord.ownerPhones):        
            owner_phones.append(','.join(excelRecord.ownerPhones))
    
        #app.apartment_number = apartment_number
        #app.recent_payment = excelRecord.payment
        #app.renter = GetRenter(excelRecord)
        #app.owner = GetOwner(excelRecord)
        
        #could be that no renter or owner details exist
        #if app.renter or app.owner:
            #if app.renter:
                #app.renter.defacto = True
            #else:
                #app.owner.defacto = True
        
        ##if no details for renter and owner store an empty person as owner
        #else:
            #app.owner = elements.Person()
            #app.owner.defacto = True
     
    #insert last appartment       
    if (indexAppartnment + 1) % 4 == 0:
        #time to insert
        apt_num = utils.Intify(apartment_number) if utils.Intify(apartment_number) else apartment_number
        app = building.apartmentOf[apt_num]
        app.apartment_number = apt_num
        
        app.recent_payment = payment
        if type(renter_name) == int or len(renter_name):
            app.renter = elements.Person(renter_name, renter_mails, renter_phones )
        else:
            app.renter = None
            
        if type(owner_name) == int or len(owner_name):
            app.owner = elements.Person(owner_name, owner_mails, owner_phones )
        else:
            app.owner = None
            
        if app.renter:
            app.renter.defacto = True
        else:
            app.owner.defacto = True