Beispiel #1
0
  // Pro rate Weekly Bill
  public BillingOrderCommand getProrataWeeklyFirstBill(
      BillingOrderData billingOrderData, DiscountMasterData discountMasterData) {

    LocalDate startDate = null;
    LocalDate endDate = null;
    BigDecimal price = null;
    LocalDate invoiceTillDate = null;
    LocalDate nextbillDate = null;

    startDate = new LocalDate(billingOrderData.getBillStartDate());
    endDate = startDate.dayOfWeek().withMaximumValue();
    LocalDate weekStartDate = startDate.dayOfWeek().withMinimumValue();
    Plan plan = this.planRepository.findOne(billingOrderData.getPlanId());

    int totalDays = 0;

    totalDays = Days.daysBetween(startDate, endDate).getDays() + 1;
    BigDecimal weeklyPricePerDay = getWeeklyPricePerDay(billingOrderData);

    Integer billingDays = 7 * billingOrderData.getChargeDuration();

    if (totalDays < billingDays) {
      price = weeklyPricePerDay.multiply(new BigDecimal(totalDays));
      if (plan.getBillRule() == 300 && !startDate.equals(weekStartDate)) {
        price = BigDecimal.ZERO;
      }
    } else if (totalDays == billingDays) {
      price = billingOrderData.getPrice();
    }

    invoiceTillDate = endDate;
    nextbillDate = endDate.plusDays(1);

    List<InvoiceTaxCommand> listOfTaxes =
        this.calculateDiscountAndTax(
            billingOrderData, discountMasterData, startDate, endDate, price);
    return this.createBillingOrderCommand(
        billingOrderData,
        startDate,
        endDate,
        invoiceTillDate,
        nextbillDate,
        price,
        listOfTaxes,
        discountMasterData);
  }
Beispiel #2
0
  // prorata monthly bill
  public BillingOrderCommand getProrataMonthlyFirstBill(
      BillingOrderData billingOrderData, DiscountMasterData discountMasterData) {

    BigDecimal pricePerDay = BigDecimal.ZERO;
    LocalDate startDate = null;
    LocalDate endDate = null;
    BigDecimal price = null;
    LocalDate invoiceTillDate = null;
    LocalDate nextbillDate = null;

    startDate = new LocalDate(billingOrderData.getBillStartDate());
    LocalDate durationDate =
        startDate.plusMonths(billingOrderData.getChargeDuration()).minusDays(1);
    LocalDate monthStartDate = startDate.dayOfMonth().withMinimumValue();
    int totalDays = Days.daysBetween(startDate, durationDate).getDays() + 1;
    Plan plan = this.planRepository.findOne(billingOrderData.getPlanId());

    // check startDate is monthStartDate
    if (startDate.equals(monthStartDate)) {
      endDate =
          startDate.plusMonths(billingOrderData.getChargeDuration()).minusDays(1); // durationDate
    } else {
      endDate = startDate.dayOfMonth().withMaximumValue();
    }

    if (endDate.toDate().before(billingOrderData.getBillEndDate())
        || endDate.toDate().equals(billingOrderData.getBillEndDate())) {

      price = billingOrderData.getPrice(); // .setScale(Integer.parseInt(roundingDecimal()));

      if (billingOrderData.getChargeDuration() == 12 && !startDate.equals(monthStartDate)) {

        int maximumDaysInYear = new LocalDate().dayOfYear().withMaximumValue().getDayOfYear();
        pricePerDay = price.divide(new BigDecimal(maximumDaysInYear), RoundingMode.HALF_UP);

      } else if (!startDate.equals(monthStartDate)) {

        pricePerDay = price.divide(new BigDecimal(totalDays), RoundingMode.HALF_UP);
        ;
      }

      int currentDay = startDate.getDayOfMonth();
      int endOfMonth = startDate.dayOfMonth().withMaximumValue().getDayOfMonth();
      int onlymonthyTotalDays = endOfMonth - currentDay + 1;

      if (onlymonthyTotalDays < endOfMonth) {
        price = pricePerDay.multiply(new BigDecimal(onlymonthyTotalDays));
      }

      // plan with No prorata and not start day of month
      if (plan.getBillRule() == 300
          && startDate.compareTo(monthStartDate) > 0
          && plan.isPrepaid() == 'N') {
        price = BigDecimal.ZERO;
      } else if (plan.getBillRule() == 200 && plan.isPrepaid() == 'N') {
        price = billingOrderData.getPrice();
      }

    } else if (endDate.toDate().after(billingOrderData.getBillEndDate())) {
      endDate = new LocalDate(billingOrderData.getBillEndDate());
      price =
          getDisconnectionCredit(
              startDate,
              endDate,
              billingOrderData.getPrice(),
              billingOrderData.getDurationType(),
              billingOrderData.getChargeDuration());
    }

    invoiceTillDate = endDate;
    nextbillDate = invoiceTillDate.plusDays(1);

    // check promotion or discount is apply or not --Tax is calculated on
    // Net charges if those applied..
    List<InvoiceTaxCommand> listOfTaxes =
        this.calculateDiscountAndTax(
            billingOrderData, discountMasterData, startDate, endDate, price);

    return this.createBillingOrderCommand(
        billingOrderData,
        startDate,
        endDate,
        invoiceTillDate,
        nextbillDate,
        price,
        listOfTaxes,
        discountMasterData);
  }