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