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;
}
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);
}
}
Aggregations