trigger sumofLPT on loan__Loan_Payment_Transaction__c (after insert, after update, after delete) {
List<loan__Loan_Account__c> llaList = new List<loan__Loan_Account__c>();
Set<ID> setlpt = new Set<ID>();
for(loan__Loan_Payment_Transaction__c lpt: trigger.new)
{
setlpt.add(lpt.id);
}
Decimal sum1;
Decimal sum2;
Decimal sum3;
Decimal sum4;
for(loan__Loan_Account__c loan: [select name, (select name, loan__Cleared__c, loan__Rejected__c, loan__Rejection_Reason__c, loan__Reversed__c, loan__Reversal_Reason__c, loan__Transaction_Amount__c FROM loan__Loan_Payment_Transactions__r)
FROM loan__Loan_Account__c ])
{
sum1 = 0;
sum2 = 0;
sum3 = 0;
sum4 = 0;
for(loan__Loan_Payment_Transaction__c lpt1:loan.loan__Loan_Payment_Transactions__r){
if(lpt1.loan__Rejected__c == true){
sum1 += lpt1.loan__Transaction_Amount__c;
loan.Rejected_Transaction_Amount__c = sum1;
System.debug('!!!!!!!!!!!!!sum1'+sum1);
System.debug('@@@@@@@@@@@@@loan.Rejected_Transaction_Amount__c'+loan.Rejected_Transaction_Amount__c);
}
/*else
{
for(loan__Loan_Payment_Transaction__c lpt2: Trigger.old){
if((Trigger.isUpdate || Trigger.isDelete) && lpt1.loan__Rejected__c == true){
loan__Loan_Payment_Transaction__c lpt1old = Trigger.oldMap.get(lpt1.Id);
}
}
}*/
if(lpt1.loan__Reversed__c == true){
sum2 += lpt1.loan__Transaction_Amount__c;
loan.Reversed_Transaction_Amount__c = sum2;
System.debug('!!!!!!!!!!!!!sum2'+sum2);
System.debug('@@@@@@@@@@@@@loan.Reversed_Transaction_Amount__c'+loan.Reversed_Transaction_Amount__c);
}
if(lpt1.loan__Cleared__c == true){
sum3 += lpt1.loan__Transaction_Amount__c;
loan.Cleared_Transaction_Amount__c = sum3;
System.debug('!!!!!!!!!!!!!sum3'+sum3);
System.debug('@@@@@@@@@@@@@loan.Cleared_Transaction_Amount__c'+loan.Cleared_Transaction_Amount__c);
}
if(lpt1.loan__Cleared__c == false && lpt1.loan__Reversed__c == false && lpt1.loan__Rejected__c == false){
sum4 += lpt1.loan__Transaction_Amount__c;
loan.Uncleared_Transaction_Amount__c = sum4;
System.debug('!!!!!!!!!!!!!sum4'+sum4);
System.debug('@@@@@@@@@@@@@loan.Uncleared_Transaction_Amount__c'+loan.Uncleared_Transaction_Amount__c);
}
}
llaList.add(loan);
}
update llaList;
}
No comments:
Post a Comment