@Override
  protected SupervisorPayrollItemDto doTransform(SupervisorPayrollItem e, int depth) {

    SupervisorPayrollItemDto d = new SupervisorPayrollItemDto();
    d.setId(e.getId());
    for (SupervisorConciliationItem supervisorConciliationItem :
        e.getSupervisorConciliationItems()) {
      SupervisorConciliationItemDto i = new SupervisorConciliationItemDto();
      i.setBonusAmount(NumberUtils.toString(supervisorConciliationItem.getBonusAmount()));
      i.setCreditAmount(NumberUtils.toString(supervisorConciliationItem.getCreditAmount()));
      i.setDevAmount(NumberUtils.toString(supervisorConciliationItem.getDevAmount()));
      i.setReductionAmount(NumberUtils.toString(supervisorConciliationItem.getReductionAmount()));
      i.setTotalTrader(NumberUtils.toString(supervisorConciliationItem.getTotalTrader()));
      i.setTraderName(supervisorConciliationItem.getTrader().getName());

      d.addSupervisorConciliationItem(i);
    }
    d.setSupervisorName(e.getSupervisor().getName());
    d.setTotalAmount(NumberUtils.toString(e.getTotalAmount()));
    if (e.getBonusItem() != null) {
      d.setTotalBonusAmount(NumberUtils.toString(e.getBonusItem().getCollectAmount()));
    } else {
      d.setTotalBonusAmount(NumberUtils.toString(BigDecimal.ZERO));
    }
    d.setTotalCreditAmount(NumberUtils.toString(e.getSubtotalCollect()));
    d.setTotalBonusAmount(NumberUtils.toString(e.getSubtotalBonus()));
    d.setTotalDevAmount(NumberUtils.toString(e.getSubtotalDev()));
    d.setTotalReductionAmount(NumberUtils.toString(e.getSubtotalReduction()));
    d.setDateFrom(DateUtils.toDate(e.getPayroll().getDateFrom()));
    d.setDateTo(DateUtils.toDate(e.getPayroll().getDateTo()));

    return d;
  }
Beispiel #2
0
  @Override
  public List<BillDto> searchByFilter(
      Long creditNumber,
      Long collectorId,
      String statusArg,
      Long clientId,
      String dateFromValue,
      String dateToValue,
      Boolean devTotalMark) {

    Bill.Status status = Bill.Status.getValueOf(statusArg);

    Date dateFrom = null;
    if (StringUtils.isNotEmpty(dateFromValue)) {
      dateFrom = DateUtils.parseDate(dateFromValue, DateUtils.DEFAULT_PATTERN);
    }
    Date dateTo = null;
    if (StringUtils.isNotEmpty(dateToValue)) {
      dateTo = DateUtils.parseDate(dateToValue, DateUtils.DEFAULT_PATTERN);
    }
    dateFrom = DateUtils.truncate(dateFrom);
    dateTo = DateUtils.lastSecondOfDay(dateTo);

    return this.getTransformer()
        .transformAllTo(
            this.getDao()
                .findByFilter(
                    creditNumber, collectorId, status, clientId, dateFrom, dateTo, devTotalMark));
  }
Beispiel #3
0
  @Override
  public boolean updateOverdueDays(Long billId) {

    Bill bill = this.getDao().findById(billId);

    ErrorTypedConditions.checkArgument(bill != null, ErrorType.BILL_NOT_FOUND);

    Date overdueDaysFlag = bill.getOverdueDaysFlag();
    Date now = DateUtils.now();

    int daysBetween = DateUtils.daysBetween(overdueDaysFlag, now);
    //		if(daysBetween <= 0){
    //			daysBetween = 1;
    //		}
    LOGGER.debug(String.format("dias de atraso calculados: %s", daysBetween));

    if (daysBetween > 0) {
      LOGGER.info(
          String.format("dias de atraso a actualizar: %s, para billId = %s", daysBetween, billId));

      bill.incrementOverdueDays(daysBetween);
      bill.audit();
    }

    return this.getDao().saveOrUpdate(bill);
  }
Beispiel #4
0
  @Override
  public List<BillDto> searchToMakeVouchers(String fromDate, String toDate) {

    ErrorTypedConditions.checkArgument(
        StringUtils.isNotBlank(fromDate),
        "La fecha de cancelacion de credito desde es requerida.",
        ErrorType.VALIDATION_ERRORS);
    ErrorTypedConditions.checkArgument(
        StringUtils.isNotBlank(toDate),
        "La fecha de cancelacion de credito hasta es requerida.",
        ErrorType.VALIDATION_ERRORS);

    Date from = DateUtils.parseDate(fromDate);
    Date to = DateUtils.lastSecondOfDay(DateUtils.parseDate(toDate));

    ErrorTypedConditions.checkArgument(
        from.before(to) || from.equals(to),
        "La fecha de cancelación de crédito desde debe ser anterior o igual a la fecha de cancelación de crédito hasta",
        ErrorType.VALIDATION_ERRORS);

    return this.getTransformer().transformAllTo(this.getDao().findToMakeVouchers(from, to));
  }
Beispiel #5
0
  @Override
  public List<BillTicketPojo> searchBillsByCollectorZone(
      String ticketDateValue, Long collectorZone, String fromDate, String toDate) {

    ErrorTypedConditions.checkArgument(
        collectorZone != null,
        "El cobrador es requerido. Por favor elija uno y vuelva a intentarlo.");

    Date dateFrom = null;
    if (StringUtils.isNotBlank(fromDate)) {
      dateFrom = DateUtils.parseDate(fromDate);
    }
    Date dateTo = null;
    if (StringUtils.isNotBlank(toDate)) {
      dateTo = DateUtils.parseDate(toDate);
    }

    Date selectedDate = DateUtils.parseDate(ticketDateValue);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(selectedDate);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    List<Bill> bills = this.getDao().find(collectorZone, dateFrom, dateTo, dayOfWeek);

    Collections.sort(
        bills,
        new Comparator<Bill>() {
          @Override
          public int compare(Bill o1, Bill o2) {
            return Integer.valueOf(o1.remainingDays())
                .compareTo(Integer.valueOf(o2.remainingDays()));
          }
        });

    return this.billTicketTransformer.transform(ticketDateValue, bills);
  }
Beispiel #6
0
  @Override
  public BillInfoDto setCancelDiscount(Long id) {

    Bill bill = this.getDao().findById(id);
    ErrorTypedConditions.checkArgument(
        bill != null,
        String.format("Factura no encontrada con id: %s", id),
        ErrorType.VALIDATION_ERRORS);

    bill.setStatus(Status.CANCELED_DISCOUNT);
    bill.setUpdatedDate(DateUtils.now());

    BillInfoDto r = new BillInfoDto();
    r.setBillId(id);
    r.setBillStatus(bill.getStatus().name());
    r.setRemainingAmount(NumberUtils.toString(bill.getRemainingAmount()));
    r.setOverdueDays(bill.getOverdueDays());
    r.setInstallmentAmount(NumberUtils.toString(bill.getTotalDailyInstallment()));

    return r;
  }
Beispiel #7
0
  @Override
  public BillDto insert(BillDto d) {

    ErrorTypedConditions.checkArgument(
        StringUtils.isNotBlank(d.getStartDate()),
        "La fecha es requerida",
        ErrorType.VALIDATION_ERRORS);

    List<BillProductDto> billProducts = d.getBillProducts();

    ErrorTypedConditions.checkArgument(
        billProducts != null && !billProducts.isEmpty(),
        String.format("No se registran productos asociados a la factura"),
        ErrorType.PRODUCT_REQUIRED);

    ErrorTypedConditions.checkArgument(
        d.getClientId() != null, "id de cliente requerido", ErrorType.VALIDATION_ERRORS);

    Client client = this.clientDao.findById(d.getClientId());

    ErrorTypedConditions.checkArgument(
        client != null,
        String.format("Cliente no encontrado con id: %s", d.getClientId()),
        ErrorType.CLIENT_NOT_FOUND);

    ErrorTypedConditions.checkArgument(
        d.getTraderId() != null, "id de vendedor requerido", ErrorType.VALIDATION_ERRORS);

    Trader trader = this.traderDao.findById(d.getTraderId());

    ErrorTypedConditions.checkArgument(
        trader != null,
        String.format("Vendedor no encontrado con id: %s", d.getTraderId()),
        ErrorType.TRADER_NOT_FOUND);

    ErrorTypedConditions.checkArgument(
        trader.getStatus() == Trader.Status.Activo,
        String.format(
            "Vendedor con id: %s esta Inactivo para realizar ventas. Por favor activelo nuevamente.",
            d.getTraderId()),
        ErrorType.TRADER_NOT_FOUND);

    ErrorTypedConditions.checkArgument(
        d.getCreditNumber() != null, "nro de credito requerido", ErrorType.VALIDATION_ERRORS);

    Bill found = this.getDao().findByCreditNumber(d.getCreditNumber());

    ErrorTypedConditions.checkArgument(
        found == null,
        String.format("Ya existe factura con nro. de credito %s", d.getCreditNumber()),
        ErrorType.VALIDATION_ERRORS);

    Bill e = new Bill();

    for (BillProductDto p : billProducts) {
      BillProduct bp = new BillProduct();
      bp.setAmount(NumberUtils.toBigDecimal(p.getAmount()));
      bp.setBill(e);
      bp.setCount(p.getCount());
      bp.setDailyInstallment(NumberUtils.toBigDecimal(p.getDailyInstallment()));
      Product product = this.productDao.findById(p.getProductId());

      ErrorTypedConditions.checkArgument(
          product != null,
          String.format("Producto no encontrado con id: %s", p.getProductId()),
          ErrorType.PRODUCT_NOT_FOUND);

      bp.setProduct(product);
      product.decrementStock(p.getCount());
      this.productDao.saveOrUpdate(product);
      e.addBillProduct(bp);
    }
    e.setClient(client);
    Date startDate = DateUtils.parseDate(d.getStartDate());
    e.setStartDate(startDate);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(startDate);

    int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);

    e.setWeekOfYear(weekOfYear);

    int month = calendar.get(Calendar.MONTH);
    e.setMonth(month);

    int year = calendar.get(Calendar.YEAR);
    e.setYear(year);

    final BigDecimal calculatedTotalAmount = e.calculateTotalAmount();
    //		if(calculatedTotalAmount.compareTo(NumberUtils.toBigDecimal(d.getTotalAmount())) != 0){
    //			throw new ErrorTypedException("Error de validacion de importe total",
    // ErrorType.UNKNOWN_ERROR);
    //		}
    e.setTotalAmount(calculatedTotalAmount);
    e.setTotalAmountToLiq(calculatedTotalAmount);

    BigDecimal calculatedTotalDailyInstallment = e.calculateTotalDailyInstallment();
    //
    //	if(calculatedTotalDailyInstallment.compareTo(NumberUtils.toBigDecimal(d.getTotalDailyInstallment())) != 0){
    //			throw new ErrorTypedException("Error de validacion de total de valor de cuota diaria",
    // ErrorType.UNKNOWN_ERROR);
    //		}
    e.setTotalDailyInstallment(calculatedTotalDailyInstallment);

    Date now = new Date();

    int days = DateUtils.daysBetween(startDate, now);

    e.setOverdueDays(days);
    e.setRemainingAmount(calculatedTotalAmount);
    e.setTrader(trader);
    e.setEndDate(e.calculateEndDate());

    ErrorTypedConditions.checkArgument(
        d.getCollectorId() != null, "Id de cobrador es requerido", ErrorType.VALIDATION_ERRORS);

    Collector collector = this.collectorDao.findById(d.getCollectorId());

    ErrorTypedConditions.checkArgument(
        collector != null,
        String.format("Cobrador no encontrado con id: %s", d.getCollectorId()),
        ErrorType.VALIDATION_ERRORS);

    e.setCollector(collector);
    e.setCreditNumber(Long.valueOf(d.getCreditNumber()));
    this.getDao().saveOrUpdate(e);
    /*
    Payment payment = new Payment();
    payment.setAmount(calculatedTotalDailyInstallment);

    payment.setBill(e);
    payment.setCollector(collector);
    payment.setDate(startDate);

    e.addPayment(payment);
    // le resto el 1er pago ...
    e.setRemainingAmount(NumberUtils.subtract(calculatedTotalAmount, calculatedTotalDailyInstallment));
    */
    e.setStatus(Status.ACTIVE);

    this.getDao().saveOrUpdate(e);

    return this.getTransformer().transform(e);
  }
Beispiel #8
0
  @Override
  public BillDetailDto searchDetail(Long billId) {
    BillDetailDto d = new BillDetailDto();

    Bill bill = this.getDao().findById(billId);

    ErrorTypedConditions.checkArgument(bill != null, ErrorType.BILL_NOT_FOUND);

    d.setClientAddress(bill.getClient().getCompanyAddress());
    d.setClientName(bill.getClient().getName());
    d.setCreditAmount(NumberUtils.toString(bill.getTotalAmount()));
    d.setCreditDate(DateUtils.toDate(bill.getStartDate()));

    BigDecimal firstPayment = BigDecimal.ZERO;
    if (bill.getPayments() != null && bill.getPayments().size() > 0) {
      firstPayment = bill.getPayments().get(0).getAmount();
    }

    d.setFirstInstallmentAmount(NumberUtils.toString(firstPayment));
    d.setInstallmentAmount(NumberUtils.toString(bill.getTotalDailyInstallment()));

    d.setWeekAmount(
        NumberUtils.toString(
            NumberUtils.multiply(bill.getTotalDailyInstallment(), new BigDecimal(7))));

    d.setCurrentAmount(
        NumberUtils.toString(
            NumberUtils.subtract(bill.getTotalAmount(), bill.getRemainingAmount())));

    d.setRemainingAmount(NumberUtils.toString(bill.getRemainingAmount()));
    d.setTraderName(bill.getTrader().getName());
    d.setCreditNumber(StringUtils.toString(bill.getCreditNumber()));
    d.setCompletedDate(
        (bill.getCompletedDate() != null)
            ? DateUtils.toDate(bill.getCompletedDate())
            : StringUtils.EMPTY);
    d.setStatus(bill.getStatus().name());
    d.setCollectorId(bill.getCollector().getId());
    d.setCollectorDescription(
        String.valueOf(bill.getCollector().getZone())
            + " / "
            + bill.getCollector().getDescription());
    d.setCustomerCompanyType(
        (StringUtils.isNotBlank(bill.getClient().getCompanyType()))
            ? bill.getClient().getCompanyType()
            : StringUtils.EMPTY);

    for (Payment p : bill.getPayments()) {
      BillDetailPaymentDto r = new BillDetailPaymentDto();
      r.setAmount(NumberUtils.toString(p.getAmount()));
      r.setCollector(
          String.valueOf(
              (p.getCollector() != null)
                  ? p.getCollector().getZone() + " / " + p.getCollector().getDescription()
                  : StringUtils.EMPTY));
      r.setDate(DateUtils.toDate(p.getDate()));
      r.setId(p.getId());
      r.setTraderPayment(p.isTraderPayment() ? "SI" : " - ");

      d.getPayments().add(r);
    }

    for (Dev p : bill.getDevList()) {
      BillDetailDevolutionDto r = new BillDetailDevolutionDto();
      r.setAmount(NumberUtils.toString(p.getAmount()));
      r.setDate(DateUtils.toDate(p.getDate()));
      r.setInstallmentAmount(NumberUtils.toString(p.getInstallmentAmount()));
      r.setProductDescription(p.getProduct().getDescription());
      r.setObservations(p.getObservations());
      r.setCount(p.getProductCount());

      d.getDevolutions().add(r);
    }
    for (BillProduct p : bill.getBillProducts()) {
      BillProductDetailDto r = new BillProductDetailDto();
      r.setCount((p.getCount() != null) ? String.valueOf(p.getCount()) : "0");
      r.setCodProducto(p.getProduct().getCode());
      r.setDescription(
          p.getProduct().getDescription()
              + " / "
              + NumberUtils.toString(p.getProduct().getPrice()));
      r.setInstallmentAmount(NumberUtils.toString(p.getDailyInstallment()));
      r.setTotalAmount(NumberUtils.toString(p.getAmount()));

      d.getProducts().add(r);
    }
    for (Discount e : bill.getDiscounts()) {
      BillDetailDiscountDto r = new BillDetailDiscountDto();
      r.setAmount(NumberUtils.toString(e.getAmount()));
      r.setDate(DateUtils.toDate(e.getDate()));
      r.setObservations(e.getObservations());

      d.getDiscounts().add(r);
    }
    for (ProductReduction e : bill.getProductReductionList()) {
      BillDetailReductionDto r = new BillDetailReductionDto();
      r.setId(e.getId());
      r.setAmount(NumberUtils.toString(e.getAmount()));
      r.setDate(DateUtils.toDate(e.getDate()));
      r.setObservations(e.getObservations());

      d.getReductions().add(r);
    }

    return d;
  }