Search in sources :

Example 1 with TimetableRepository

use of com.axelor.apps.supplychain.db.repo.TimetableRepository 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 2 with TimetableRepository

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

the class InvoiceServiceSupplychainImpl method ventilate.

@Override
@Transactional(rollbackOn = { Exception.class })
public void ventilate(Invoice invoice) throws AxelorException {
    super.ventilate(invoice);
    TimetableRepository timeTableRepo = Beans.get(TimetableRepository.class);
    List<Timetable> timetableList = timeTableRepo.all().filter("self.invoice.id = ?1", invoice.getId()).fetch();
    for (Timetable timetable : timetableList) {
        timetable.setInvoiced(true);
        timeTableRepo.save(timetable);
    }
}
Also used : Timetable(com.axelor.apps.supplychain.db.Timetable) TimetableRepository(com.axelor.apps.supplychain.db.repo.TimetableRepository) Transactional(com.google.inject.persist.Transactional)

Aggregations

Timetable (com.axelor.apps.supplychain.db.Timetable)2 TimetableRepository (com.axelor.apps.supplychain.db.repo.TimetableRepository)2 Transactional (com.google.inject.persist.Transactional)2 Invoice (com.axelor.apps.account.db.Invoice)1 AxelorException (com.axelor.exception.AxelorException)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1