public PlanSummary process(ArrayList<Chargeable> data) { PlanSummary ret = new PlanSummary(this); ret.addPlanCall( new PlanChargeable( new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE), monthFee, this.getCurrency())); Set<String> recipients = new HashSet<String>(); int secondsTotal = 0; for (Chargeable chargeable : data) { if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) { Call call = (Call) chargeable; if (call.getType() != Call.CALL_TYPE_SENT) { continue; } double callPrice = 0; if (call.getContact().getMsisdnType() == MsisdnType.ES_SPECIAL_ZER0) { callPrice = 0; } else { int hourOfDay = call.getDate().get(Calendar.HOUR_OF_DAY); boolean insideDay = (hourOfDay < 8 || hourOfDay >= 18); if (insideDay) { secondsTotal += call.getDuration(); recipients.add(call.getContact().getMsisdn()); } boolean insidePlan = insideDay && secondsTotal <= maxSecondsMonth && recipients.size() <= maxRecipients; if (!insidePlan) { long duration = (secondsTotal > maxSecondsMonth) && (secondsTotal - call.getDuration() <= maxSecondsMonth) ? secondsTotal - maxSecondsMonth : call.getDuration(); callPrice += initialPrice + (duration * pricePerSecond); } } ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency())); } else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) { Sms sms = (Sms) chargeable; if (sms.getType() == Sms.SMS_TYPE_RECEIVED) { continue; } ret.addPlanCall(new PlanChargeable(chargeable, smsPrice, this.getCurrency())); } } return ret; }
public PlanSummary process(ArrayList<Chargeable> data) { PlanSummary ret = new PlanSummary(this); ret.addPlanCall( new PlanChargeable( new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE), monthFee, this.getCurrency())); long secondsTotal = 0; int smsSent = 0; for (Chargeable chargeable : data) { if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) { Call call = (Call) chargeable; if (call.getType() != Call.CALL_TYPE_SENT) { continue; } double callPrice = 0; if (call.getContact().getMsisdnType() == MsisdnType.ES_SPECIAL_ZER0) { callPrice = 0; } else { secondsTotal += call.getDuration(); if (secondsTotal > maxSecondsMonth) { long duration = (secondsTotal > maxSecondsMonth) && (secondsTotal - call.getDuration() <= maxSecondsMonth) ? secondsTotal - maxSecondsMonth : call.getDuration(); callPrice += initialPrice + (duration * pricePerSecond); } } ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency())); } else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) { Sms sms = (Sms) chargeable; if (sms.getType() == Sms.SMS_TYPE_RECEIVED) { continue; } smsSent++; ret.addPlanCall( new PlanChargeable( chargeable, (smsSent > maxFreeSMS) ? smsPrice : 0, this.getCurrency())); } } return ret; }