use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceSupplychainRepository method copy.
@Override
public Invoice copy(Invoice entity, boolean deep) {
Invoice copy = super.copy(entity, deep);
copy.setSaleOrder(null);
copy.setPurchaseOrder(null);
copy.setStockMoveSet(null);
for (InvoiceLine line : copy.getInvoiceLineList()) {
line.setSaleOrderLine(null);
line.setPurchaseOrderLine(null);
line.setStockMoveLine(null);
line.setOutgoingStockMove(null);
line.setIncomingStockMove(null);
}
return copy;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class BudgetService method updateBudgetLinesFromInvoice.
public void updateBudgetLinesFromInvoice(Invoice invoice) {
List<InvoiceLine> invoiceLineList = invoice.getInvoiceLineList();
if (invoiceLineList == null) {
return;
}
invoiceLineList.stream().filter(invoiceLine -> invoiceLine.getBudgetDistributionList() != null).flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
Budget budget = budgetDistribution.getBudget();
updateLines(budget);
computeTotalAmountRealized(budget);
});
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class TimesheetProjectServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
if (!Beans.get(AppHumanResourceService.class).isApp("business-project")) {
return super.createInvoiceLines(invoice, timesheetLineList, priority);
}
List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
int count = 0;
DateTimeFormatter ddmmFormat = DateTimeFormatter.ofPattern("dd/MM");
HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<String, Object[]>();
// Check if a consolidation by product and user must be done
boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
for (TimesheetLine timesheetLine : timesheetLineList) {
Object[] tabInformations = new Object[6];
tabInformations[0] = timesheetLine.getProduct();
tabInformations[1] = timesheetLine.getUser();
// Start date
tabInformations[2] = timesheetLine.getDate();
// End date, useful only for consolidation
tabInformations[3] = timesheetLine.getDate();
tabInformations[4] = timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration();
tabInformations[5] = timesheetLine.getProject();
String key = null;
if (consolidate) {
key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId() + "|" + timesheetLine.getProject().getId();
if (timeSheetInformationsMap.containsKey(key)) {
tabInformations = timeSheetInformationsMap.get(key);
// Update date
if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
// If date is lower than start date then replace start date by this one
tabInformations[2] = timesheetLine.getDate();
} else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
// If date is upper than end date then replace end date by this one
tabInformations[3] = timesheetLine.getDate();
}
tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration());
} else {
timeSheetInformationsMap.put(key, tabInformations);
}
} else {
key = String.valueOf(timesheetLine.getId());
timeSheetInformationsMap.put(key, tabInformations);
}
}
for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
String strDate = null;
Product product = (Product) timesheetInformations[0];
User user = (User) timesheetInformations[1];
LocalDate startDate = (LocalDate) timesheetInformations[2];
LocalDate endDate = (LocalDate) timesheetInformations[3];
BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
Project project = (Project) timesheetInformations[5];
PriceList priceList = project.getPriceList();
if (consolidate) {
if (startDate != null && endDate != null) {
strDate = startDate.format(ddmmFormat) + " - " + endDate.format(ddmmFormat);
}
} else {
if (startDate != null) {
strDate = startDate.format(ddmmFormat);
}
}
invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
invoiceLineList.get(invoiceLineList.size() - 1).setProject(project);
count++;
}
return invoiceLineList;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceProjectServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
Company company = purchaseOrderLine.getPurchaseOrder() != null ? purchaseOrderLine.getPurchaseOrder().getCompany() : null;
BigDecimal price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
BigDecimal discountAmount = price;
int discountTypeSelect = 1;
if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PRICE_LIST) {
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (priceList != null) {
PriceListLine priceListLine = purchaseOrderLineServiceImpl.getPriceListLine(purchaseOrderLine, priceList, price);
if (priceListLine != null) {
discountTypeSelect = priceListLine.getTypeSelect();
}
if ((appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
price = priceListService.computeDiscount(price, (int) discounts.get("discountTypeSelect"), discountAmount);
}
} else {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
if (discounts.get("price") != null) {
price = (BigDecimal) discounts.get("price");
}
}
}
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PERCENTAGE) {
price = price.multiply(invoice.getPartner().getChargeBackPurchase().divide(new BigDecimal(100), appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP)).setScale(appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP);
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else {
InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method ventilate.
/**
* Ventilation comptable d'une facture. (Transaction)
*
* @param invoice Une facture.
* @throws AxelorException
*/
@Override
@Transactional(rollbackOn = { Exception.class })
public void ventilate(Invoice invoice) throws AxelorException {
if (invoice.getPaymentCondition() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
if (invoice.getPaymentMode() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
Account account = invoiceLine.getAccount();
if (invoiceLine.getAccount() == null && (invoiceLine.getTypeSelect() == InvoiceLineRepository.TYPE_NORMAL)) {
throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.VENTILATE_STATE_6), invoiceLine.getProductName());
}
if (account != null && !account.getAnalyticDistributionAuthorized() && (invoiceLine.getAnalyticDistributionTemplate() != null || (invoiceLine.getAnalyticMoveLineList() != null && !invoiceLine.getAnalyticMoveLineList().isEmpty()))) {
throw new AxelorException(invoice, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.VENTILATE_STATE_7));
}
}
log.debug("Ventilation de la facture {}", invoice.getInvoiceId());
ventilateFactory.getVentilator(invoice).process();
invoiceRepo.save(invoice);
if (this.checkEnablePDFGenerationOnVentilation(invoice)) {
Beans.get(InvoicePrintService.class).printAndSave(invoice, InvoiceRepository.REPORT_TYPE_ORIGINAL_INVOICE, ReportSettings.FORMAT_PDF, null);
}
}
Aggregations