Exemplo n.º 1
0
class BookingService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.Booking = self.ec.InitEntityClass('Booking')
        self.service_account = AccountService()

    def get_booking_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Booking).select_all()
            return result

        return None

    def get_booking_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Booking).select_by_id(idValue)
            return result

        return None

    def add_booking(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Booking):
            with self.base_service.DbContext() as __context:

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                # create new object of Booking
                modelBooking = self.Booking()
                modelBooking.BookingId = str(self.util_common.generateUUID())
                modelBooking.AccountBookerId = hasattr(
                    paramModel,
                    'AccountBookerId') and paramModel.AccountBookerId or None
                modelBooking.PropPriceId = hasattr(
                    paramModel,
                    'PropPriceId') and paramModel.PropPriceId or None
                modelBooking.DateArrival = hasattr(
                    paramModel,
                    'DateArrival') and paramModel.DateArrival or None
                modelBooking.DateCheckout = hasattr(
                    paramModel,
                    'DateCheckout') and paramModel.DateCheckout or None
                modelBooking.DateActualArrival = hasattr(
                    paramModel, 'DateActualArrival'
                ) and paramModel.DateActualArrival or None
                modelBooking.DateActualCheckout = hasattr(
                    paramModel, 'DateActualCheckout'
                ) and paramModel.DateActualCheckout or None
                modelBooking.TotalPeople = hasattr(
                    paramModel,
                    'TotalPeople') and paramModel.TotalPeople or None
                modelBooking.PriceDealed = hasattr(
                    paramModel,
                    'PriceDealed') and paramModel.PriceDealed or None
                modelBooking.DepositDealed = hasattr(
                    paramModel,
                    'DepositDealed') and paramModel.DepositDealed or None
                modelBooking.PaymentDateInMonth = hasattr(
                    paramModel, 'PaymentDateInMonth'
                ) and paramModel.PaymentDateInMonth or None

                modelBooking.CreatedBy = modelAdmin.IndexNo
                modelBooking.LastModifiedBy = modelAdmin.IndexNo
                modelBooking.DateCreated = str(
                    self.util_common.currentDateTime())
                modelBooking.DateLastModified = str(
                    self.util_common.currentDateTime())

                # insert to db
                result = __context.table(
                    self.Booking).insert_by_model(modelBooking)
                if result:
                    return modelBooking

        return None

    def update_booking(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Booking):

            modelBookingFromDb = self.get_booking_byId(paramModel.BookingId)

            if (modelBookingFromDb is not None):

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                modelBookingFromDb.AccountBookerId = hasattr(
                    paramModel, 'AccountBookerId'
                ) and paramModel.AccountBookerId or modelBookingFromDb.AccountBookerId
                modelBookingFromDb.PropPriceId = hasattr(
                    paramModel, 'PropPriceId'
                ) and paramModel.PropPriceId or modelBookingFromDb.PropPriceId
                modelBookingFromDb.DateArrival = hasattr(
                    paramModel, 'DateArrival'
                ) and paramModel.DateArrival or modelBookingFromDb.DateArrival
                modelBookingFromDb.DateCheckout = hasattr(
                    paramModel, 'DateCheckout'
                ) and paramModel.DateCheckout or modelBookingFromDb.DateCheckout
                modelBookingFromDb.DateActualArrival = hasattr(
                    paramModel, 'DateActualArrival'
                ) and paramModel.DateActualArrival or modelBookingFromDb.DateActualArrival
                modelBookingFromDb.DateActualCheckout = hasattr(
                    paramModel, 'DateActualCheckout'
                ) and paramModel.DateActualCheckout or modelBookingFromDb.DateActualCheckout
                modelBookingFromDb.TotalPeople = hasattr(
                    paramModel, 'TotalPeople'
                ) and paramModel.TotalPeople or modelBookingFromDb.TotalPeople
                modelBookingFromDb.PriceDealed = hasattr(
                    paramModel, 'PriceDealed'
                ) and paramModel.PriceDealed or modelBookingFromDb.PriceDealed
                modelBookingFromDb.DepositDealed = hasattr(
                    paramModel, 'DepositDealed'
                ) and paramModel.DepositDealed or modelBookingFromDb.DepositDealed
                modelBookingFromDb.PaymentDateInMonth = hasattr(
                    paramModel, 'PaymentDateInMonth'
                ) and paramModel.PaymentDateInMonth or modelBookingFromDb.PaymentDateInMonth

                modelBookingFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelBookingFromDb.DateLastModified = str(
                    self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.Booking).update_by_model(modelBookingFromDb)
                    if result:
                        return modelBookingFromDb
        return None
Exemplo n.º 2
0
class CountryService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.Country = self.ec.InitEntityClass('Country')
        self.service_account = AccountService()

    def get_country_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Country).select_all()
            return result

        return None

    def get_country_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Country).select_by_id(idValue)
            return result

        return None

    def get_country_byName(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' Name like '%{0}%' '''.format(searchText)
            result = __context.table(self.Country).select_by(conditions)
            return result

        return None

    def get_country_byCode(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' CountryCode like '%{0}%' '''.format(searchText)
            result = __context.table(self.Country).select_by(conditions)
            return result

        return None

    def add_country(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Country):
            with self.base_service.DbContext() as __context:

                modelLastCountry = __context.table(
                    self.Country).select_lastrecord(
                    )  # get last record of Country table to increment IndexNo

                # create new object of Country
                modelCountry = self.Country()
                modelCountry.CountryId = modelLastCountry.CountryId + 1
                modelCountry.Name = hasattr(paramModel,
                                            'Name') and paramModel.Name or None
                modelCountry.CountryCode = hasattr(
                    paramModel,
                    'CountryCode') and paramModel.CountryCode or None
                modelCountry.SortOrder = hasattr(
                    paramModel, 'SortOrder') and paramModel.SortOrder or None
                modelCountry.IsAvailable = hasattr(
                    paramModel, 'IsAvailable') and paramModel.IsAvailable or 1

                # insert to db
                result = __context.table(
                    self.Country).insert_by_model(modelCountry)
                if result:
                    return modelCountry

        return None

    def update_country(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Country):

            modelCountryFromDb = self.get_country_byId(paramModel.CountryId)

            if (modelCountryFromDb is not None):

                modelCountryFromDb.Name = hasattr(
                    paramModel,
                    'Name') and paramModel.Name or modelCountryFromDb.Name
                modelCountryFromDb.CountryCode = hasattr(
                    paramModel, 'CountryCode'
                ) and paramModel.CountryCode or modelCountryFromDb.CountryCode
                modelCountryFromDb.SortOrder = hasattr(
                    paramModel, 'SortOrder'
                ) and paramModel.SortOrder or modelCountryFromDb.SortOrder
                modelCountryFromDb.IsAvailable = hasattr(
                    paramModel, 'IsAvailable'
                ) and paramModel.IsAvailable or modelCountryFromDb.IsAvailable

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.Country).update_by_model(modelCountryFromDb)
                    if result:
                        return modelCountryFromDb
        return None
Exemplo n.º 3
0
class BookingPaymentService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.BookingPayment = self.ec.InitEntityClass('BookingPayment')
        self.service_account = AccountService()

    def get_bookingpayment_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.BookingPayment).select_all()
            return result

        return None

    def get_bookingpayment_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.BookingPayment).select_by_id(idValue)
            return result

        return None

    def add_bookingpayment(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.BookingPayment):
            with self.base_service.DbContext() as __context:

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                # create new object of BookingPayment
                modelBookingPayment = self.BookingPayment()
                modelBookingPayment.BookingPaymentId = str(
                    self.util_common.generateUUID())
                modelBookingPayment.BookingId = hasattr(
                    paramModel, 'BookingId') and paramModel.BookingId or None
                modelBookingPayment.DepositAmount = hasattr(
                    paramModel,
                    'DepositAmount') and paramModel.DepositAmount or 0
                modelBookingPayment.DepositPaid = hasattr(
                    paramModel, 'DepositPaid') and paramModel.DepositPaid or 0
                modelBookingPayment.FixedAmount = hasattr(
                    paramModel, 'FixedAmount') and paramModel.FixedAmount or 0
                modelBookingPayment.FixedPaid = hasattr(
                    paramModel, 'FixedPaid') and paramModel.FixedPaid or 0
                modelBookingPayment.DateApplied = hasattr(
                    paramModel,
                    'DateApplied') and paramModel.DateApplied or None
                modelBookingPayment.DateEnd = hasattr(
                    paramModel, 'DateEnd') and paramModel.DateEnd or None
                modelBookingPayment.IsClosed = hasattr(
                    paramModel, 'IsClosed') and paramModel.IsClosed or 0

                modelBookingPayment.CreatedBy = modelAdmin.IndexNo
                modelBookingPayment.LastModifiedBy = modelAdmin.IndexNo
                modelBookingPayment.DateCreated = str(
                    self.util_common.currentDateTime())
                modelBookingPayment.DateLastModified = str(
                    self.util_common.currentDateTime())

                # insert to db
                result = __context.table(
                    self.BookingPayment).insert_by_model(modelBookingPayment)
                if result:
                    return modelBookingPayment

        return None

    def update_bookingpayment(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.BookingPayment):

            modelBookingPaymentFromDb = self.get_bookingpayment_byId(
                paramModel.BookingPaymentId)

            if (modelBookingPaymentFromDb is not None):

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                modelBookingPaymentFromDb.BookingId = hasattr(
                    paramModel, 'BookingId'
                ) and paramModel.BookingId or modelBookingPaymentFromDb.BookingId
                modelBookingPaymentFromDb.DepositAmount = hasattr(
                    paramModel, 'DepositAmount'
                ) and paramModel.DepositAmount or modelBookingPaymentFromDb.DepositAmount
                modelBookingPaymentFromDb.DepositPaid = hasattr(
                    paramModel, 'DepositPaid'
                ) and paramModel.DepositPaid or modelBookingPaymentFromDb.DepositPaid
                modelBookingPaymentFromDb.FixedAmount = hasattr(
                    paramModel, 'FixedAmount'
                ) and paramModel.FixedAmount or modelBookingPaymentFromDb.FixedAmount
                modelBookingPaymentFromDb.FixedPaid = hasattr(
                    paramModel, 'FixedPaid'
                ) and paramModel.FixedPaid or modelBookingPaymentFromDb.FixedPaid
                modelBookingPaymentFromDb.DateApplied = hasattr(
                    paramModel, 'DateApplied'
                ) and paramModel.DateApplied or modelBookingPaymentFromDb.DateApplied
                modelBookingPaymentFromDb.DateEnd = hasattr(
                    paramModel, 'DateEnd'
                ) and paramModel.DateEnd or modelBookingPaymentFromDb.DateEnd
                modelBookingPaymentFromDb.IsClosed = hasattr(
                    paramModel, 'IsClosed'
                ) and paramModel.IsClosed or modelBookingPaymentFromDb.IsClosed

                modelBookingPaymentFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelBookingPaymentFromDb.DateLastModified = str(
                    self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.BookingPayment).update_by_model(
                            modelBookingPaymentFromDb)
                    if result:
                        return modelBookingPaymentFromDb
        return None
Exemplo n.º 4
0
class TimeUnitService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.TimeUnit = self.ec.InitEntityClass('TimeUnit')
        self.service_account = AccountService()

    def get_timeunit_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.TimeUnit).select_all()
            return result

        return None

    def get_timeunit_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.TimeUnit).select_by_id(idValue)
            return result

        return None

    def get_timeunit_byName(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' Name like '%{0}%' '''.format(searchText)
            result = __context.table(self.TimeUnit).select_by(conditions)
            return result

        return None

    def add_timeunit(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.TimeUnit):
            with self.base_service.DbContext() as __context:

                modelLastTimeUnit = __context.table(
                    self.TimeUnit).select_lastrecord(
                    )  # get last record of TimeUnit table to increment IndexNo

                # create new object of TimeUnit
                modelTimeUnit = self.TimeUnit()
                modelTimeUnit.TimeUnitId = modelLastTimeUnit.TimeUnitId + 1
                modelTimeUnit.Name = hasattr(
                    paramModel, 'Name') and paramModel.Name or None
                modelTimeUnit.Description = hasattr(
                    paramModel,
                    'Description') and paramModel.Description or None
                modelTimeUnit.ToHours = hasattr(
                    paramModel, 'ToHours') and paramModel.ToHours or None
                modelTimeUnit.ToHoursLeapYear = hasattr(
                    paramModel,
                    'ToHoursLeapYear') and paramModel.ToHoursLeapYear or None
                modelTimeUnit.SortOrder = hasattr(
                    paramModel, 'SortOrder') and paramModel.SortOrder or None
                modelTimeUnit.IsAvailable = hasattr(
                    paramModel, 'IsAvailable') and paramModel.IsAvailable or 1

                # insert to db
                result = __context.table(
                    self.TimeUnit).insert_by_model(modelTimeUnit)
                if result:
                    return modelTimeUnit

        return None

    def update_timeunit(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.TimeUnit):

            modelTimeUnitFromDb = self.get_timeunit_byId(paramModel.TimeUnitId)

            if (modelTimeUnitFromDb is not None):

                modelTimeUnitFromDb.Name = hasattr(
                    paramModel,
                    'Name') and paramModel.Name or modelTimeUnitFromDb.Name
                modelTimeUnitFromDb.Description = hasattr(
                    paramModel, 'Description'
                ) and paramModel.Description or modelTimeUnitFromDb.Description
                modelTimeUnitFromDb.ToHours = hasattr(
                    paramModel, 'ToHours'
                ) and paramModel.ToHours or modelTimeUnitFromDb.ToHours
                modelTimeUnitFromDb.ToHoursLeapYear = hasattr(
                    paramModel, 'ToHoursLeapYear'
                ) and paramModel.ToHoursLeapYear or modelTimeUnitFromDb.ToHoursLeapYear
                modelTimeUnitFromDb.SortOrder = hasattr(
                    paramModel, 'SortOrder'
                ) and paramModel.SortOrder or modelTimeUnitFromDb.SortOrder
                modelTimeUnitFromDb.IsAvailable = hasattr(
                    paramModel, 'IsAvailable'
                ) and paramModel.IsAvailable or modelTimeUnitFromDb.IsAvailable

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.TimeUnit).update_by_model(modelTimeUnitFromDb)
                    if result:
                        return modelTimeUnitFromDb
        return None
Exemplo n.º 5
0
class ClientService():

    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.Client = self.ec.InitEntityClass('Client')
        self.service_account = AccountService()


    def get_client_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Client).select_all()
            return result
        
        return None

    def get_client_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Client).select_by_id(idValue)
            return result
        
        return None
    
    def get_client_byName(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' FullName like '%{0}%' '''.format(searchText)
            result = __context.table(self.Client).select_by(conditions) 
            return result
        
        return None
   
    def add_client(self, paramModel):
        if( paramModel is not None and inspect.isclass(type(paramModel)) and type(paramModel) == self.Client):
            with self.base_service.DbContext() as __context:
                
                modelAdmin = self.service_account.get_accountAdmin()# get limit 1 result 

                modelLastClient = __context.table(self.Client).select_lastrecord()# get last record of Client table to increment IndexNo
                
                # create new object of Client
                modelClient = self.Client()
                modelClient.ClientId = str(self.util_common.generateUUID())
                modelClient.IndexNo = hasattr(paramModel, 'IndexNo') and paramModel.IndexNo or (modelLastClient.IndexNo + 1)
                modelClient.BookerFgCode = hasattr(paramModel, 'BookerFgCode') and paramModel.BookerFgCode or '00000000'
                modelClient.IdentityPicture = hasattr(paramModel, 'IdentityPicture') and paramModel.IdentityPicture or None
                modelClient.IdentityCardId = hasattr(paramModel, 'IdentityCardId') and paramModel.IdentityCardId or None
                modelClient.FullName = hasattr(paramModel, 'FullName') and paramModel.FullName.upper() or None
                modelClient.FourgramCode = hasattr(paramModel, 'FullName') and self.__generateFourgramCode(paramModel.FullName) or None
                modelClient.Phone1 = hasattr(paramModel, 'Phone1') and paramModel.Phone1 or None
                modelClient.Phone2 = hasattr(paramModel, 'Phone2') and paramModel.Phone2 or None
                modelClient.Email = hasattr(paramModel, 'Email') and paramModel.Email or None
                modelClient.TemporaryAddress = hasattr(paramModel, 'TemporaryAddress') and paramModel.TemporaryAddress or None
                modelClient.CurrentJob = hasattr(paramModel, 'CurrentJob') and paramModel.CurrentJob or None
                modelClient.SignatureScan = hasattr(paramModel, 'SignatureScan') and paramModel.SignatureScan or None
                modelClient.IsAvailable = hasattr(paramModel, 'IsAvailable') and paramModel.IsAvailable or 1
                
                modelClient.CreatedBy = modelAdmin.IndexNo
                modelClient.LastModifiedBy = modelAdmin.IndexNo
                modelClient.DateCreated = str(self.util_common.currentDateTime())
                modelClient.DateLastModified = str(self.util_common.currentDateTime())

                # insert to db
                result = __context.table(self.Client).insert_by_model(modelClient)
                if result:
                    return modelClient
        
        return None

    def update_client(self, paramModel):
        if(paramModel is not None and inspect.isclass(type(paramModel)) and type(paramModel) == self.Client):
            
            modelClientFromDb = self.get_client_byId(paramModel.ClientId)
            
            if(modelClientFromDb is not None):

                modelAdmin = self.service_account.get_accountAdmin()# get limit 1 result 

                modelClientFromDb.IndexNo = hasattr(paramModel, 'IndexNo') and paramModel.IndexNo or modelClientFromDb.IndexNo
                modelClientFromDb.BookerFgCode = hasattr(paramModel, 'BookerFgCode') and paramModel.BookerFgCode or modelClientFromDb.BookerFgCode
                modelClientFromDb.IdentityPicture = hasattr(paramModel, 'IdentityPicture') and paramModel.IdentityPicture or modelClientFromDb.IdentityPicture
                modelClientFromDb.FullName = hasattr(paramModel, 'FullName') and paramModel.FullName.upper() or modelClientFromDb.FullName
                modelClientFromDb.Phone1 = hasattr(paramModel, 'Phone1') and paramModel.Phone1 or modelClientFromDb.Phone1
                modelClientFromDb.Phone2 = hasattr(paramModel, 'Phone2') and paramModel.Phone2 or modelClientFromDb.Phone2
                modelClientFromDb.Email = hasattr(paramModel, 'Email') and paramModel.Email or modelClientFromDb.Email
                modelClientFromDb.TemporaryAddress = hasattr(paramModel, 'TemporaryAddress') and paramModel.TemporaryAddress or modelClientFromDb.TemporaryAddress
                modelClientFromDb.CurrentJob = hasattr(paramModel, 'CurrentJob') and paramModel.CurrentJob or modelClientFromDb.CurrentJob
                modelClientFromDb.SignatureScan = hasattr(paramModel, 'SignatureScan') and paramModel.SignatureScan or modelClientFromDb.SignatureScan
                modelClientFromDb.IsAvailable = hasattr(paramModel, 'IsAvailable') and paramModel.IsAvailable or modelClientFromDb.IsAvailable
               
                modelClientFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelClientFromDb.DateLastModified = str(self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(self.Client).update_by_model(modelClientFromDb)
                    if result:
                        return modelClientFromDb
        return None

        
    def __generateFourgramCode(self, fullname):
        if fullname:
            fourgramcode = ''

            lstWord = fullname.strip().split(' ')
            firstWord = lstWord[0]
            lastWord = lstWord[len(lstWord) - 1]
            finalChars = str(lastWord[:2]).upper() + str(firstWord[:2]).upper()# get first 2 character of string

            with self.base_service.DbContext() as __context:
                conditions = ''' FourgramCode like '%{0}%' ORDER BY FourgramCode DESC LIMIT 1'''.format(finalChars)
                result = __context.table(self.Client).select_by(conditions) 
                
                if result:
                    
                    # lastDigitFCode = result[0].FourgramCode[-4:]
                    lastDigitFCode = ''.join([n for n in list(result[0].FourgramCode) if n.isdigit()])
                    fourgramcode = finalChars + str("{:04d}".format(int(lastDigitFCode) + 1))
                else:
                    fourgramcode = finalChars + "{:04d}".format(1)# display number leading zeros with format 4 digits
            
            return fourgramcode

        return None
class PropertyAvailibiltyTypeService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.PropertyAvailibiltyType = self.ec.InitEntityClass(
            'PropertyAvailibiltyType')
        self.service_account = AccountService()

    def get_propavailtype_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.PropertyAvailibiltyType).select_all()
            return result

        return None

    def get_propavailtype_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(
                self.PropertyAvailibiltyType).select_by_id(idValue)
            return result

        return None

    def get_propavailtype_byName(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' Name like '%{0}%' '''.format(searchText)
            result = __context.table(
                self.PropertyAvailibiltyType).select_by(conditions)
            return result

        return None

    def add_propavailtype(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.PropertyAvailibiltyType):
            with self.base_service.DbContext() as __context:

                modelLastPropertyAvailibiltyType = __context.table(
                    self.PropertyAvailibiltyType
                ).select_lastrecord(
                )  # get last record of PropertyAvailibiltyType table to increment IndexNo

                # create new object of PropertyAvailibiltyType
                modelPropertyAvailibiltyType = self.PropertyAvailibiltyType()
                modelPropertyAvailibiltyType.PropAvailTypeId = modelLastPropertyAvailibiltyType.PropAvailTypeId + 1
                modelPropertyAvailibiltyType.Name = hasattr(
                    paramModel, 'Name') and paramModel.Name or None
                modelPropertyAvailibiltyType.Description = hasattr(
                    paramModel,
                    'Description') and paramModel.Description or None
                modelPropertyAvailibiltyType.SortOrder = hasattr(
                    paramModel, 'SortOrder') and paramModel.SortOrder or None
                modelPropertyAvailibiltyType.IsAvailable = hasattr(
                    paramModel, 'IsAvailable') and paramModel.IsAvailable or 1

                # insert to db
                result = __context.table(
                    self.PropertyAvailibiltyType).insert_by_model(
                        modelPropertyAvailibiltyType)
                if result:
                    return modelPropertyAvailibiltyType

        return None

    def update_propavailtype(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.PropertyAvailibiltyType):

            modelPropertyAvailibiltyTypeFromDb = self.get_propavailtype_byId(
                paramModel.PropAvailTypeId)

            if (modelPropertyAvailibiltyTypeFromDb is not None):

                modelPropertyAvailibiltyTypeFromDb.Name = hasattr(
                    paramModel, 'Name'
                ) and paramModel.Name or modelPropertyAvailibiltyTypeFromDb.Name
                modelPropertyAvailibiltyTypeFromDb.Description = hasattr(
                    paramModel, 'Description'
                ) and paramModel.Description or modelPropertyAvailibiltyTypeFromDb.Description
                modelPropertyAvailibiltyTypeFromDb.SortOrder = hasattr(
                    paramModel, 'SortOrder'
                ) and paramModel.SortOrder or modelPropertyAvailibiltyTypeFromDb.SortOrder
                modelPropertyAvailibiltyTypeFromDb.IsAvailable = hasattr(
                    paramModel, 'IsAvailable'
                ) and paramModel.IsAvailable or modelPropertyAvailibiltyTypeFromDb.IsAvailable

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.PropertyAvailibiltyType).update_by_model(
                            modelPropertyAvailibiltyTypeFromDb)
                    if result:
                        return modelPropertyAvailibiltyTypeFromDb
        return None
Exemplo n.º 7
0
class PropertyPricePolicyService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.PropertyPricePolicy = self.ec.InitEntityClass(
            'PropertyPricePolicy')
        self.service_account = AccountService()

    def get_proppricepol_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.PropertyPricePolicy).select_all()
            return result

        return None

    def get_proppricepol_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(
                self.PropertyPricePolicy).select_by_id(idValue)
            return result

        return None

    def add_proppricepol(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.PropertyPricePolicy):
            with self.base_service.DbContext() as __context:

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                modelLastPropertyPricePolicy = __context.table(
                    self.PropertyPricePolicy
                ).select_lastrecord(
                )  # get last record of PropertyPricePolicy table to increment IndexNo

                # create new object of PropertyPricePolicy
                modelPropertyPricePolicy = self.PropertyPricePolicy()
                modelPropertyPricePolicy.PropPriceId = modelLastPropertyPricePolicy.PropPriceId + 1
                modelPropertyPricePolicy.PropertyItemId = hasattr(
                    paramModel,
                    'PropertyItemId') and paramModel.PropertyItemId or None
                modelPropertyPricePolicy.TimeUnitId = hasattr(
                    paramModel, 'TimeUnitId') and paramModel.TimeUnitId or None
                modelPropertyPricePolicy.CostActual = hasattr(
                    paramModel, 'CostActual') and paramModel.CostActual or None
                modelPropertyPricePolicy.PriceOrigin = hasattr(
                    paramModel,
                    'PriceOrigin') and paramModel.PriceOrigin or None
                modelPropertyPricePolicy.PercentageDiscount = hasattr(
                    paramModel, 'PercentageDiscount'
                ) and paramModel.PercentageDiscount or None
                modelPropertyPricePolicy.PriceActual = hasattr(
                    paramModel,
                    'PriceActual') and paramModel.PriceActual or None
                modelPropertyPricePolicy.DepositAmount = hasattr(
                    paramModel,
                    'DepositAmount') and paramModel.DepositAmount or None
                modelPropertyPricePolicy.DateApplied = hasattr(
                    paramModel,
                    'DateApplied') and paramModel.DateApplied or None
                modelPropertyPricePolicy.IsConfirmed = hasattr(
                    paramModel, 'IsConfirmed') and paramModel.IsConfirmed or 0

                modelPropertyPricePolicy.CreatedBy = modelAdmin.IndexNo
                modelPropertyPricePolicy.LastModifiedBy = modelAdmin.IndexNo
                modelPropertyPricePolicy.DateCreated = str(
                    self.util_common.currentDateTime())
                modelPropertyPricePolicy.DateLastModified = str(
                    self.util_common.currentDateTime())

                # insert to db
                result = __context.table(
                    self.PropertyPricePolicy).insert_by_model(
                        modelPropertyPricePolicy)
                if result:
                    return modelPropertyPricePolicy

        return None

    def update_proppricepol(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.PropertyPricePolicy):

            modelPropertyPricePolicyFromDb = self.get_proppricepol_byId(
                paramModel.PropPriceId)

            if (modelPropertyPricePolicyFromDb is not None):

                modelAdmin = self.service_account.get_accountAdmin(
                )  # get limit 1 result

                modelPropertyPricePolicyFromDb.PropertyItemId = hasattr(
                    paramModel, 'PropertyItemId'
                ) and paramModel.PropertyItemId or modelPropertyPricePolicyFromDb.PropertyItemId
                modelPropertyPricePolicyFromDb.TimeUnitId = hasattr(
                    paramModel, 'TimeUnitId'
                ) and paramModel.TimeUnitId or modelPropertyPricePolicyFromDb.TimeUnitId
                modelPropertyPricePolicyFromDb.CostActual = hasattr(
                    paramModel, 'CostActual'
                ) and paramModel.CostActual or modelPropertyPricePolicyFromDb.CostActual
                modelPropertyPricePolicyFromDb.PriceOrigin = hasattr(
                    paramModel, 'PriceOrigin'
                ) and paramModel.PriceOrigin or modelPropertyPricePolicyFromDb.PriceOrigin
                modelPropertyPricePolicyFromDb.PercentageDiscount = hasattr(
                    paramModel, 'PercentageDiscount'
                ) and paramModel.PercentageDiscount or modelPropertyPricePolicyFromDb.PercentageDiscount
                modelPropertyPricePolicyFromDb.PriceActual = hasattr(
                    paramModel, 'PriceActual'
                ) and paramModel.PriceActual or modelPropertyPricePolicyFromDb.PriceActual
                modelPropertyPricePolicyFromDb.DepositAmount = hasattr(
                    paramModel, 'DepositAmount'
                ) and paramModel.DepositAmount or modelPropertyPricePolicyFromDb.DepositAmount
                modelPropertyPricePolicyFromDb.DateApplied = hasattr(
                    paramModel, 'DateApplied'
                ) and paramModel.DateApplied or modelPropertyPricePolicyFromDb.DateApplied
                modelPropertyPricePolicyFromDb.IsConfirmed = hasattr(
                    paramModel, 'IsConfirmed'
                ) and paramModel.IsConfirmed or modelPropertyPricePolicyFromDb.IsConfirmed

                modelPropertyPricePolicyFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelPropertyPricePolicyFromDb.DateLastModified = str(
                    self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.PropertyPricePolicy).update_by_model(
                            modelPropertyPricePolicyFromDb)
                    if result:
                        return modelPropertyPricePolicyFromDb
        return None
class PropertyItemService():

    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.PropertyItem = self.ec.InitEntityClass('PropertyItem')
        self.service_account = AccountService()


    def get_propitem_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.PropertyItem).select_all()
            return result
        
        return None

    def get_propitem_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.PropertyItem).select_by_id(idValue)
            return result
        
        return None
    
    def get_propitem_byName(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' FullName like '%{0}%' '''.format(searchText)
            result = __context.table(self.PropertyItem).select_by(conditions) 
            return result
        
        return None
   
    def add_propitem(self, paramModel):
        if( paramModel is not None and inspect.isclass(type(paramModel)) and type(paramModel) == self.PropertyItem):
            with self.base_service.DbContext() as __context:
                
                modelAdmin = self.service_account.get_accountAdmin()# get limit 1 result 

                modelLastPropertyItem = __context.table(self.PropertyItem).select_lastrecord()# get last record of PropertyItem table to increment IndexNo
                
                # create new object of PropertyItem
                modelPropertyItem = self.PropertyItem()
                modelPropertyItem.PropertyItemId = str(self.util_common.generateUUID())
                modelPropertyItem.IndexNo = hasattr(paramModel, 'IndexNo') and paramModel.IndexNo or (modelLastPropertyItem.IndexNo + 1)
                modelPropertyItem.ParentId = hasattr(paramModel, 'ParentId') and paramModel.ParentId or None
                modelPropertyItem.PropertyId = hasattr(paramModel, 'PropertyId') and paramModel.PropertyId or None
                modelPropertyItem.PropertyTypeId = hasattr(paramModel, 'PropertyTypeId') and paramModel.PropertyTypeId or None
                modelPropertyItem.PropertyStatusId = hasattr(paramModel, 'PropertyStatusId') and paramModel.PropertyStatusId or None
                modelPropertyItem.PropAvailTypeId = hasattr(paramModel, 'PropAvailTypeId') and paramModel.PropAvailTypeId or None
                modelPropertyItem.Name = hasattr(paramModel, 'Name') and paramModel.Name or None
                modelPropertyItem.ShortDescription = hasattr(paramModel, 'ShortDescription') and paramModel.ShortDescription or None
                modelPropertyItem.LongDescription = hasattr(paramModel, 'LongDescription') and paramModel.LongDescription or None
                modelPropertyItem.FloorNo = hasattr(paramModel, 'FloorNo') and paramModel.FloorNo or None
                modelPropertyItem.RoomName = hasattr(paramModel, 'RoomName') and paramModel.RoomName or None
                modelPropertyItem.Width = hasattr(paramModel, 'Width') and paramModel.Width or 0
                modelPropertyItem.Length = hasattr(paramModel, 'Length') and paramModel.Length or 0
                modelPropertyItem.AreaUsage = hasattr(paramModel, 'AreaUsage') and paramModel.AreaUsage or 0
                modelPropertyItem.MaxAllowPeople = hasattr(paramModel, 'MaxAllowPeople') and paramModel.MaxAllowPeople or None
                modelPropertyItem.LastElectricalUsageNo = hasattr(paramModel, 'LastElectricalUsageNo') and paramModel.LastElectricalUsageNo or None
                modelPropertyItem.LastWaterUsageNo = hasattr(paramModel, 'LastWaterUsageNo') and paramModel.LastWaterUsageNo or None
                modelPropertyItem.IsAvailable = hasattr(paramModel, 'IsAvailable') and paramModel.IsAvailable or 1
                modelPropertyItem.IsRemoved = hasattr(paramModel, 'IsRemoved') and paramModel.IsRemoved or 0

                modelPropertyItem.CreatedBy = modelAdmin.IndexNo
                modelPropertyItem.LastModifiedBy = modelAdmin.IndexNo
                modelPropertyItem.DateCreated = str(self.util_common.currentDateTime())
                modelPropertyItem.DateLastModified = str(self.util_common.currentDateTime())

                # insert to db
                result = __context.table(self.PropertyItem).insert_by_model(modelPropertyItem)
                if result:
                    return modelPropertyItem
        
        return None

    def update_propitem(self, paramModel):
        if(paramModel is not None and inspect.isclass(type(paramModel)) and type(paramModel) == self.PropertyItem):
            
            modelPropertyItemFromDb = self.get_propitem_byId(paramModel.PropertyItemId)
            
            if(modelPropertyItemFromDb is not None):

                modelAdmin = self.service_account.get_accountAdmin()# get limit 1 result 
           
                modelPropertyItemFromDb.IndexNo = hasattr(paramModel, 'IndexNo') and paramModel.IndexNo or modelPropertyItemFromDb.IndexNo
                modelPropertyItemFromDb.ParentId = hasattr(paramModel, 'ParentId') and paramModel.ParentId or modelPropertyItemFromDb.ParentId
                modelPropertyItemFromDb.PropertyId = hasattr(paramModel, 'PropertyId') and paramModel.PropertyId or modelPropertyItemFromDb.PropertyId
                modelPropertyItemFromDb.PropertyTypeId = hasattr(paramModel, 'PropertyTypeId') and paramModel.PropertyTypeId or modelPropertyItemFromDb.PropertyTypeId
                modelPropertyItemFromDb.PropertyStatusId = hasattr(paramModel, 'PropertyStatusId') and paramModel.PropertyStatusId or modelPropertyItemFromDb.PropertyStatusId
                modelPropertyItemFromDb.PropAvailTypeId = hasattr(paramModel, 'PropAvailTypeId') and paramModel.PropAvailTypeId or modelPropertyItemFromDb.PropAvailTypeId
                modelPropertyItemFromDb.Name = hasattr(paramModel, 'Name') and paramModel.Name or modelPropertyItemFromDb.Name
                modelPropertyItemFromDb.ShortDescription = hasattr(paramModel, 'ShortDescription') and paramModel.ShortDescription or modelPropertyItemFromDb.ShortDescription
                modelPropertyItemFromDb.LongDescription = hasattr(paramModel, 'LongDescription') and paramModel.LongDescription or modelPropertyItemFromDb.LongDescription
                modelPropertyItemFromDb.FloorNo = hasattr(paramModel, 'FloorNo') and paramModel.FloorNo or modelPropertyItemFromDb.FloorNo
                modelPropertyItemFromDb.RoomName = hasattr(paramModel, 'RoomName') and paramModel.RoomName or modelPropertyItemFromDb.RoomName
                modelPropertyItemFromDb.Width = hasattr(paramModel, 'Width') and paramModel.Width or modelPropertyItemFromDb.Width
                modelPropertyItemFromDb.Length = hasattr(paramModel, 'Length') and paramModel.Length or modelPropertyItemFromDb.Length
                modelPropertyItemFromDb.AreaUsage = hasattr(paramModel, 'AreaUsage') and paramModel.AreaUsage or modelPropertyItemFromDb.AreaUsage
                modelPropertyItemFromDb.MaxAllowPeople = hasattr(paramModel, 'MaxAllowPeople') and paramModel.MaxAllowPeople or modelPropertyItemFromDb.MaxAllowPeople
                modelPropertyItemFromDb.LastElectricalUsageNo = hasattr(paramModel, 'LastElectricalUsageNo') and paramModel.LastElectricalUsageNo or modelPropertyItemFromDb.LastElectricalUsageNo
                modelPropertyItemFromDb.LastWaterUsageNo = hasattr(paramModel, 'LastWaterUsageNo') and paramModel.LastWaterUsageNo or modelPropertyItemFromDb.LastWaterUsageNo
                modelPropertyItemFromDb.IsAvailable = hasattr(paramModel, 'IsAvailable') and paramModel.IsAvailable or 1
                modelPropertyItemFromDb.IsRemoved = hasattr(paramModel, 'IsRemoved') and paramModel.IsRemoved or 0
                
                modelPropertyItemFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelPropertyItemFromDb.DateLastModified = str(self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(self.PropertyItem).update_by_model(modelPropertyItemFromDb)
                    if result:
                        return modelPropertyItemFromDb
        return None
Exemplo n.º 9
0
class AccountService():
    def __init__(self):
        self.base_service = BaseService()
        self.db = BaseService.DbFilePath
        self.ec = self.base_service.Entity()
        self.util_common = self.base_service.UtilCommon()
        self.util_security = self.base_service.UtilSecurity()
        self.Account = self.ec.InitEntityClass('Account')

    def get_account_all(self):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Account).select_all()
            return result

        return None

    def get_account_byId(self, idValue):
        with self.base_service.DbContext() as __context:
            result = __context.table(self.Account).select_by_id(idValue)
            return result

        return None

    def get_account_byUname(self, searchText):
        with self.base_service.DbContext() as __context:
            conditions = ''' Username like '%{0}%' '''.format(searchText)
            result = __context.table(self.Account).select_by(conditions)
            return result

        return None

    def get_accountAdmin(self):
        with self.base_service.DbContext() as __context:
            conditions = ''' IsMasterAdmin = 1 '''
            result = __context.table(self.Account).select_by(conditions)
            return result[0]

        return None

    def add_account(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Account):
            with self.base_service.DbContext() as __context:

                modelAdmin = self.get_accountAdmin()  # get limit 1 result

                modelLastAccount = __context.table(
                    self.Account).select_lastrecord(
                    )  # get last record of Account table to increment IndexNo

                password = hasattr(
                    paramModel,
                    'Pw') and paramModel.Pw or self.util_common.randomString(8)
                hashedpassword = self.util_security.generatePasswordByBcrypt(
                    password, 6)  # generate hashed password using bcrypt

                # create new object of Account
                modelAcc = self.Account()
                modelAcc.AccountId = str(self.util_common.generateUUID())
                modelAcc.IndexNo = hasattr(
                    paramModel, 'IndexNo') and paramModel.IndexNo or (
                        modelLastAccount.IndexNo + 1)
                modelAcc.Username = hasattr(
                    paramModel, 'Username') and paramModel.Username or None
                modelAcc.IsBooker = hasattr(
                    paramModel, 'IsBooker') and paramModel.IsBooker or 1
                modelAcc.IpAddress = hasattr(
                    paramModel, 'IpAddress') and paramModel.IpAddress or None
                modelAcc.Pw = hashedpassword
                modelAcc.SaltKey = hasattr(
                    paramModel, 'SaltKey') and paramModel.SaltKey or None
                modelAcc.IsAvailable = hasattr(
                    paramModel, 'IsAvailable') and paramModel.IsAvailable or 1

                modelAcc.CreatedBy = modelAdmin.IndexNo
                modelAcc.LastModifiedBy = modelAdmin.IndexNo
                modelAcc.DateCreated = str(self.util_common.currentDateTime())
                modelAcc.DateLastModified = str(
                    self.util_common.currentDateTime())
                # insert to db
                result = __context.table(
                    self.Account).insert_by_model(modelAcc)
                if result:
                    return modelAcc

        return None

    def update_account(self, paramModel):
        if (paramModel is not None and inspect.isclass(type(paramModel))
                and type(paramModel) == self.Account):

            modelAccFromDb = self.get_account_byId(paramModel.AccountId)

            if (modelAccFromDb is not None):

                modelAdmin = self.get_accountAdmin()  # get limit 1 result
                modelAccFromDb.Pw = (
                    # if paramModel.Pw (new password) has value and it not matched exist password
                    (hasattr(paramModel, 'Pw')
                     and not self.util_security.verifyHashed(
                         self.util_security, paramModel.Pw, modelAccFromDb.Pw))
                    # then generate new hashed password for new password
                    and self.util_security.generatePasswordByBcrypt(
                        paramModel.Pw, 6)
                    # else if they matched together, get exist password
                    or modelAccFromDb.Pw)
                modelAccFromDb.IndexNo = hasattr(
                    paramModel,
                    'IndexNo') and paramModel.IndexNo or modelAccFromDb.IndexNo
                modelAccFromDb.Username = hasattr(
                    paramModel, 'Username'
                ) and paramModel.Username or modelAccFromDb.Username
                modelAccFromDb.IsBooker = hasattr(
                    paramModel, 'IsBooker'
                ) and paramModel.IsBooker or modelAccFromDb.IsBooker
                modelAccFromDb.IsMasterAdmin = hasattr(
                    paramModel, 'IsMasterAdmin'
                ) and paramModel.IsMasterAdmin or modelAccFromDb.IsMasterAdmin
                modelAccFromDb.IpAddress = hasattr(
                    paramModel, 'IpAddress'
                ) and paramModel.IpAddress or modelAccFromDb.IpAddress
                modelAccFromDb.DateLastLogin = hasattr(
                    paramModel, 'DateLastLogin'
                ) and paramModel.DateLastLogin or modelAccFromDb.DateLastLogin
                modelAccFromDb.IsAvailable = hasattr(
                    paramModel, 'IsAvailable'
                ) and paramModel.IsAvailable or modelAccFromDb.IsAvailable

                modelAccFromDb.LastModifiedBy = modelAdmin.IndexNo
                modelAccFromDb.DateLastModified = str(
                    self.util_common.currentDateTime())

                with self.base_service.DbContext() as __context:
                    # update to db
                    result = __context.table(
                        self.Account).update_by_model(modelAccFromDb)
                    if result:
                        return modelAccFromDb
        return None