use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.
the class TimetableController method generateInvoice.
public void generateInvoice(ActionRequest request, ActionResponse response) throws AxelorException {
Timetable timetable = request.getContext().asType(Timetable.class);
timetable = Beans.get(TimetableRepository.class).find(timetable.getId());
Context parentContext = request.getContext().getParent();
if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
SaleOrder saleOrder = parentContext.asType(SaleOrder.class);
if (saleOrder.getStatusSelect() < SaleOrderRepository.STATUS_ORDER_CONFIRMED) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_SALE_ORDER_NOT_CONFIRMED));
return;
}
}
if (parentContext != null && parentContext.getContextClass().equals(PurchaseOrder.class)) {
PurchaseOrder purchaseOrder = parentContext.asType(PurchaseOrder.class);
if (purchaseOrder.getStatusSelect() < PurchaseOrderRepository.STATUS_VALIDATED) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_PURCHASE_OREDR_NOT_VALIDATED));
return;
}
}
if (timetable.getInvoice() != null) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_INVOICE_ALREADY_GENERATED));
return;
}
Invoice invoice = timetableService.generateInvoice(timetable);
response.setReload(true);
response.setView(ActionView.define(I18n.get("Invoice generated")).model("com.axelor.apps.account.db.Invoice").add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", invoice.getId().toString()).map());
}
use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method updateAmountToBeSpreadOverTheTimetable.
public void updateAmountToBeSpreadOverTheTimetable(SaleOrder saleOrder) {
List<Timetable> timetableList = saleOrder.getTimetableList();
BigDecimal totalHT = saleOrder.getExTaxTotal();
BigDecimal sumTimetableAmount = BigDecimal.ZERO;
if (timetableList != null) {
for (Timetable timetable : timetableList) {
sumTimetableAmount = sumTimetableAmount.add(timetable.getAmount());
}
}
saleOrder.setAmountToBeSpreadOverTheTimetable(totalHT.subtract(sumTimetableAmount));
}
use of com.axelor.apps.supplychain.db.Timetable 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);
}
}
use of com.axelor.apps.supplychain.db.Timetable in project axelor-open-suite by axelor.
the class ForecastRecapServiceImpl method populateWithTimetables.
protected void populateWithTimetables(ForecastRecap forecastRecap, ForecastRecapLineType forecastRecapLineType) throws AxelorException {
List<Integer> statusList = StringTool.getIntegerList(forecastRecapLineType.getStatusSelect());
List<Timetable> timetableList = new ArrayList<>();
if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER) {
timetableList = timetableRepo.all().filter("self.estimatedDate BETWEEN :fromDate AND :toDate AND self.saleOrder.company = :company" + " AND self.saleOrder.statusSelect IN (:saleOrderStatusList) AND self.amount != 0" + (forecastRecap.getBankDetails() != null ? " AND self.saleOrder.companyBankDetails = :bankDetails " : "") + " AND (self.invoice IS NULL OR self.invoice.statusSelect NOT IN (:invoiceStatusSelectList)) ").bind("fromDate", forecastRecap.getFromDate()).bind("toDate", forecastRecap.getToDate()).bind("company", forecastRecap.getCompany()).bind("saleOrderStatusList", statusList).bind("bankDetails", forecastRecap.getBankDetails()).bind("invoiceStatusSelectList", invoiceStatusMap.get(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE)).fetch();
} else if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_PURCHASE_ORDER) {
timetableList = timetableRepo.all().filter("self.estimatedDate BETWEEN :fromDate AND :toDate AND self.purchaseOrder.company = :company" + " AND self.purchaseOrder.statusSelect IN (:purchaseOrderStatusList) AND self.amount != 0" + (forecastRecap.getBankDetails() != null ? " AND self.purchaseOrder.companyBankDetails = :bankDetails " : "") + " AND (self.invoice IS NULL OR self.invoice.statusSelect NOT IN (:invoiceStatusSelectList)) ").bind("fromDate", forecastRecap.getFromDate()).bind("toDate", forecastRecap.getToDate()).bind("company", forecastRecap.getCompany()).bind("purchaseOrderStatusList", statusList).bind("bankDetails", forecastRecap.getBankDetails()).bind("invoiceStatusSelectList", invoiceStatusMap.get(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE)).fetch();
}
if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER) {
for (Timetable timetable : timetableList) {
timetable = timetableRepo.find(timetable.getId());
BigDecimal amountCompanyCurr = currencyService.getAmountCurrencyConvertedAtDate(timetable.getSaleOrder().getCurrency(), forecastRecap.getCompany().getCurrency(), timetable.getAmount(), today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
this.createForecastRecapLine(timetable.getEstimatedDate(), forecastRecapLineType.getTypeSelect(), amountCompanyCurr, SaleOrder.class.getName(), timetable.getSaleOrder().getId(), timetable.getSaleOrder().getSaleOrderSeq(), forecastRecapLineTypeRepo.find(forecastRecapLineType.getId()), forecastRecapRepo.find(forecastRecap.getId()));
}
} else if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_PURCHASE_ORDER) {
for (Timetable timetable : timetableList) {
timetable = timetableRepo.find(timetable.getId());
BigDecimal amountCompanyCurr = currencyService.getAmountCurrencyConvertedAtDate(timetable.getPurchaseOrder().getCurrency(), forecastRecap.getCompany().getCurrency(), timetable.getAmount(), today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
this.createForecastRecapLine(timetable.getEstimatedDate(), forecastRecapLineType.getTypeSelect(), amountCompanyCurr, PurchaseOrder.class.getName(), timetable.getPurchaseOrder().getId(), timetable.getPurchaseOrder().getPurchaseOrderSeq(), forecastRecapLineTypeRepo.find(forecastRecapLineType.getId()), forecastRecapRepo.find(forecastRecap.getId()));
}
}
}
Aggregations