Subversion Repositories SmartDukaan

Rev

Rev 18774 | Rev 18795 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18774 Rev 18794
Line 9038... Line 9038...
9038
            creditorMap['Sanctions'] = sanctionsList
9038
            creditorMap['Sanctions'] = sanctionsList
9039
            returnMap[sanction.creditor_id] = creditorMap
9039
            returnMap[sanction.creditor_id] = creditorMap
9040
                    
9040
                    
9041
    return returnMap
9041
    return returnMap
9042
 
9042
 
-
 
9043
def get_user_sanction_details_paginated(userId, creditorId, limit=0, offset=0):
-
 
9044
    totalCount = session.query(func.count(UserSanction.id)).all()
-
 
9045
    hasMore = False
-
 
9046
    if limit >0 and offset > 0 and (limit+offset) < totalCount:
-
 
9047
        hasMore = True 
-
 
9048
    us_query = UserSanction.query
-
 
9049
    if userId:
-
 
9050
        us_query = us_query.filter(UserSanction.user_id == userId)
-
 
9051
    if creditorId:
-
 
9052
        us_query = us_query.filter(UserSanction.creditor_id == creditorId)
-
 
9053
    if limit>0:
-
 
9054
        us_query = us_query.limit(limit)
-
 
9055
    if offset>0 and limit >0:
-
 
9056
        us_query = us_query.offset(offset)
-
 
9057
        
-
 
9058
    allSanctions = us_query.all()
-
 
9059
    returnMap = {}
-
 
9060
    for sanction in allSanctions:
-
 
9061
        ticket_size = -1
-
 
9062
        if creditorTicketSizeMap.has_key(sanction.creditor_id):
-
 
9063
            ticket_size = creditorTicketSizeMap.get(sanction.creditor_id)
-
 
9064
        else:
-
 
9065
            fetchCreditorTicketSizeMap()
-
 
9066
            ticket_size = creditorTicketSizeMap.get(sanction.creditor_id)
-
 
9067
        
-
 
9068
        if returnMap.has_key(sanction.creditor_id):
-
 
9069
            creditorMap = returnMap.get(sanction.creditor_id)
-
 
9070
            creditorMap['TicketSize'] = ticket_size
-
 
9071
            if creditorMap.has_key('Sanctions'):
-
 
9072
                sanctionsList = creditorMap.get('Sanctions')
-
 
9073
                sanctionsList.append(sanction)
-
 
9074
                creditorMap['Sanctions'] = sanctionsList
-
 
9075
            else:
-
 
9076
                sanctionsList =[]
-
 
9077
                sanctionsList.append(sanction)
-
 
9078
                creditorMap['Sanctions'] = sanctionsList
-
 
9079
            returnMap[sanction.creditor_id] = creditorMap
-
 
9080
        else:
-
 
9081
            creditorMap = {}
-
 
9082
            creditorMap['TicketSize'] = ticket_size
-
 
9083
            sanctionsList =[]
-
 
9084
            sanctionsList.append(sanction)
-
 
9085
            creditorMap['Sanctions'] = sanctionsList
-
 
9086
            returnMap[sanction.creditor_id] = creditorMap
-
 
9087
                    
-
 
9088
    return hasMore, totalCount, returnMap
-
 
9089
 
9043
def update_user_sanction(userSanction):
9090
def update_user_sanction(userSanction):
9044
    userS = UserSanction.get_by(id=userSanction.id)
9091
    userS = UserSanction.get_by(id=userSanction.id)
9045
    if userS is None:
9092
    if userS is None:
9046
        return False
9093
        return False
9047
    else:
9094
    else:
Line 9069... Line 9116...
9069
        credit_hs_query = credit_hs_query.limit(limit)
9116
        credit_hs_query = credit_hs_query.limit(limit)
9070
    if offset>0 and limit >0:
9117
    if offset>0 and limit >0:
9071
        credit_hs_query = credit_hs_query.offset(offset)
9118
        credit_hs_query = credit_hs_query.offset(offset)
9072
    return credit_hs_query.all()
9119
    return credit_hs_query.all()
9073
 
9120
 
-
 
9121
def get_credit_history_records_paginated(paymentId, userId, creditorId, creditTxnType, limit=0, offset=0):
-
 
9122
    totalCount = session.query(func.count(CreditHistory.id)).all()
-
 
9123
    hasMore = False
-
 
9124
    if limit >0 and offset > 0 and (limit+offset) < totalCount:
-
 
9125
        hasMore = True
-
 
9126
    credit_hs_query = CreditHistory.query
-
 
9127
    if paymentId and paymentId>0:
-
 
9128
        credit_hs_query = credit_hs_query.filter(CreditHistory.payment_id==paymentId)
-
 
9129
    if userId and userId>0:
-
 
9130
        credit_hs_query = credit_hs_query.filter(CreditHistory.user_id==userId)
-
 
9131
    if creditorId and creditorId>0:
-
 
9132
        credit_hs_query = credit_hs_query.filter(CreditHistory.creditor_id==creditorId)
-
 
9133
    if creditTxnType:
-
 
9134
        credit_hs_query = credit_hs_query.filter(CreditHistory.credit_type==CreditTxnType._VALUES_TO_NAMES[creditTxnType])
-
 
9135
    credit_hs_query = credit_hs_query.order_by(desc(CreditHistory.created))
-
 
9136
    if limit>0:
-
 
9137
        credit_hs_query = credit_hs_query.limit(limit)
-
 
9138
    if offset>0 and limit >0:
-
 
9139
        credit_hs_query = credit_hs_query.offset(offset)
-
 
9140
    return hasMore, totalCount, credit_hs_query.all()
-
 
9141
 
9074
def process_credit_transaction(paymentId, userId, creditorId, creditTxns, invoiceNumber=None):
9142
def process_credit_transaction(paymentId, userId, creditorId, creditTxns, invoiceNumber=None):
9075
    us_query = UserSanction.query
9143
    us_query = UserSanction.query
9076
    if userId:
9144
    if userId:
9077
        us_query = us_query.filter(UserSanction.user_id == userId)
9145
        us_query = us_query.filter(UserSanction.user_id == userId)
9078
    if creditorId:
9146
    if creditorId:
Line 9178... Line 9246...
9178
    if offset>0 and limit>0:
9246
    if offset>0 and limit>0:
9179
        loan_hs_query = loan_hs_query.offset(offset)
9247
        loan_hs_query = loan_hs_query.offset(offset)
9180
    
9248
    
9181
    return loan_hs_query.all()
9249
    return loan_hs_query.all()
9182
 
9250
 
-
 
9251
def get_loan_history_records_paginated(paymentId, userId, creditorId, creditTxnType, limit=0, offset=0):
-
 
9252
    totalCount = session.query(func.count(LoanHistory.id)).all()
-
 
9253
    hasMore = False
-
 
9254
    if limit >0 and offset > 0 and (limit+offset) < totalCount:
-
 
9255
        hasMore = True
-
 
9256
    loan_hs_query = LoanHistory.query
-
 
9257
    if paymentId and paymentId>0:
-
 
9258
        loan_hs_query = loan_hs_query.filter(LoanHistory.payment_id==paymentId)
-
 
9259
    if userId and userId>0:
-
 
9260
        loan_hs_query = loan_hs_query.filter(LoanHistory.user_id==userId)
-
 
9261
    if creditorId and creditorId>0:
-
 
9262
        loan_hs_query = loan_hs_query.filter(LoanHistory.creditor_id==creditorId)
-
 
9263
    if creditTxnType:
-
 
9264
        loan_hs_query = loan_hs_query.filter(LoanHistory.credit_type==CreditTxnType._VALUES_TO_NAMES[creditTxnType])
-
 
9265
    loan_hs_query = loan_hs_query.order_by(desc(LoanHistory.created))
-
 
9266
    if limit>0:
-
 
9267
        loan_hs_query = loan_hs_query.limit(limit)
-
 
9268
    if offset>0 and limit>0:
-
 
9269
        loan_hs_query = loan_hs_query.offset(offset)
-
 
9270
    
-
 
9271
    return hasMore, totalCount, loan_hs_query.all()
-
 
9272
 
9183
def process_loan_transaction(paymentId, userId, creditorId, loantxns):
9273
def process_loan_transaction(paymentId, userId, creditorId, loantxns):
9184
    us_query = UserSanction.query
9274
    us_query = UserSanction.query
9185
    if userId:
9275
    if userId:
9186
        us_query = us_query.filter(UserSanction.user_id == userId)
9276
        us_query = us_query.filter(UserSanction.user_id == userId)
9187
    if creditorId:
9277
    if creditorId: