Search in sources :

Example 1 with Timetable

use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.

the class PurchaseOrderServiceSupplychainImpl method updateAmountToBeSpreadOverTheTimetable.

@Override
public void updateAmountToBeSpreadOverTheTimetable(PurchaseOrder purchaseOrder) {
    List<Timetable> timetableList = purchaseOrder.getTimetableList();
    BigDecimal totalHT = purchaseOrder.getExTaxTotal();
    BigDecimal sumTimetableAmount = BigDecimal.ZERO;
    if (timetableList != null) {
        for (Timetable timetable : timetableList) {
            sumTimetableAmount = sumTimetableAmount.add(timetable.getAmount());
        }
    }
    purchaseOrder.setAmountToBeSpreadOverTheTimetable(totalHT.subtract(sumTimetableAmount));
}
Also used : Timetable(com.axelor.apps.supplychain.db.Timetable) BigDecimal(java.math.BigDecimal)

Example 2 with Timetable

use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.

the class PurchaseOrderInvoiceServiceImpl method generateInvoiceFromTimetableForPurchaseOrder.

@Transactional(rollbackOn = { Exception.class })
protected Invoice generateInvoiceFromTimetableForPurchaseOrder(PurchaseOrder purchaseOrder, List<Long> timetableIdList) throws AxelorException {
    if (ObjectUtils.isEmpty(timetableIdList)) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_NO_TIMETABLES_SELECTED));
    }
    BigDecimal percentSum = BigDecimal.ZERO;
    List<Timetable> timetableList = new ArrayList<>();
    for (Long timetableId : timetableIdList) {
        Timetable timetable = timetableRepo.find(timetableId);
        timetableList.add(timetable);
        percentSum = percentSum.add(timetable.getPercentage());
    }
    Invoice invoice = generateInvoiceFromLines(purchaseOrder, percentSum);
    for (Timetable timetable : timetableList) {
        timetable.setInvoice(invoice);
        timetable.setInvoiced(true);
        timetableRepo.save(timetable);
    }
    return invoice;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Timetable(com.axelor.apps.supplychain.db.Timetable) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 3 with Timetable

use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.

the class TimetableServiceImpl method applyTemplate.

public List<Timetable> applyTemplate(TimetableTemplate template, BigDecimal exTaxTotal, LocalDate computationDate) {
    List<Timetable> timetables = new ArrayList<>();
    for (TimetableTemplateLine templateLine : template.getTimetableTemplateLineList()) {
        Timetable timetable = new Timetable();
        timetable.setEstimatedDate(InvoiceToolService.getDueDate(templateLine.getPaymentCondition(), computationDate));
        timetable.setPercentage(templateLine.getPercentage());
        timetable.setAmount(exTaxTotal.multiply(templateLine.getPercentage()).divide(BigDecimal.valueOf(100)));
        timetables.add(timetable);
    }
    timetables.sort(Comparator.comparing(Timetable::getEstimatedDate));
    return timetables;
}
Also used : Timetable(com.axelor.apps.supplychain.db.Timetable) ArrayList(java.util.ArrayList) TimetableTemplateLine(com.axelor.apps.supplychain.db.TimetableTemplateLine)

Example 4 with Timetable

use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method generateInvoice.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(SaleOrder saleOrder, int operationSelect, BigDecimal amount, boolean isPercent, Map<Long, BigDecimal> qtyToInvoiceMap, List<Long> timetableIdList) throws AxelorException {
    Invoice invoice;
    switch(operationSelect) {
        case SaleOrderRepository.INVOICE_ALL:
            invoice = generateInvoice(saleOrder);
            break;
        case SaleOrderRepository.INVOICE_LINES:
            invoice = generateInvoiceFromLines(saleOrder, qtyToInvoiceMap, isPercent);
            break;
        case SaleOrderRepository.INVOICE_ADVANCE_PAYMENT:
            invoice = generateAdvancePayment(saleOrder, amount, isPercent);
            break;
        case SaleOrderRepository.INVOICE_TIMETABLES:
            BigDecimal percentSum = BigDecimal.ZERO;
            TimetableRepository timetableRepo = Beans.get(TimetableRepository.class);
            List<Timetable> timetableList = new ArrayList<>();
            if (timetableIdList == null || timetableIdList.isEmpty()) {
                throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_NO_TIMETABLES_SELECTED));
            }
            for (Long timetableId : timetableIdList) {
                Timetable timetable = timetableRepo.find(timetableId);
                timetableList.add(timetable);
                percentSum = percentSum.add(timetable.getPercentage());
            }
            invoice = generateInvoiceFromLines(saleOrder, this.generateQtyToInvoiceMap(saleOrder, percentSum), true);
            if (!timetableList.isEmpty()) {
                for (Timetable timetable : timetableList) {
                    timetable.setInvoice(invoice);
                    timetableRepo.save(timetable);
                }
            }
            break;
        default:
            return null;
    }
    invoice.setSaleOrder(saleOrder);
    if (!Strings.isNullOrEmpty(saleOrder.getInvoiceComments())) {
        invoice.setNote(saleOrder.getInvoiceComments());
    }
    if (ObjectUtils.isEmpty(invoice.getProformaComments()) && !Strings.isNullOrEmpty(saleOrder.getProformaComments())) {
        invoice.setProformaComments(saleOrder.getProformaComments());
    }
    // fill default advance payment invoice
    if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
        invoice.setAdvancePaymentInvoiceSet(invoiceService.getDefaultAdvancePaymentInvoice(invoice));
    }
    invoice.setPartnerTaxNbr(saleOrder.getClientPartner().getTaxNbr());
    invoice = invoiceRepo.save(invoice);
    return invoice;
}
Also used : Timetable(com.axelor.apps.supplychain.db.Timetable) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) TimetableRepository(com.axelor.apps.supplychain.db.repo.TimetableRepository) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 5 with Timetable

use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.

the class TimetableController method applyTemplate.

public void applyTemplate(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    try {
        if (context.get("timetableTemplate") == null || context.get("exTaxTotal") == null || context.get("computationDate") == null) {
            return;
        }
        TimetableTemplate template = (TimetableTemplate) context.get("timetableTemplate");
        List<Timetable> timetableList = timetableService.applyTemplate(template, (BigDecimal) context.get("exTaxTotal"), (LocalDate) context.get("computationDate"));
        response.setValue("timetableList", timetableList);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Timetable(com.axelor.apps.supplychain.db.Timetable) TimetableTemplate(com.axelor.apps.supplychain.db.TimetableTemplate) AxelorException(com.axelor.exception.AxelorException)

Aggregations

Timetable (com.axelor.apps.supplychain.db.Timetable)9 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)4 Invoice (com.axelor.apps.account.db.Invoice)3 AxelorException (com.axelor.exception.AxelorException)3 Transactional (com.google.inject.persist.Transactional)3 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 TimetableRepository (com.axelor.apps.supplychain.db.repo.TimetableRepository)2 Context (com.axelor.rpc.Context)2 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 TimetableTemplate (com.axelor.apps.supplychain.db.TimetableTemplate)1 TimetableTemplateLine (com.axelor.apps.supplychain.db.TimetableTemplateLine)1