예제 #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
예제 #2
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
예제 #3
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
예제 #4
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 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