use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoicingProjectService method createInvoiceLine.
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, int priority) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), priority, false, null, purchaseOrderLine, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
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 InvoicingProjectService method populate.
public List<InvoiceLine> populate(Invoice invoice, InvoicingProject folder) throws AxelorException {
List<SaleOrderLine> saleOrderLineList = new ArrayList<SaleOrderLine>(folder.getSaleOrderLineSet());
List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>(folder.getPurchaseOrderLineSet());
List<TimesheetLine> timesheetLineList = new ArrayList<TimesheetLine>(folder.getLogTimesSet());
List<ExpenseLine> expenseLineList = new ArrayList<ExpenseLine>(folder.getExpenseLineSet());
List<ProjectTask> projectTaskList = new ArrayList<ProjectTask>(folder.getProjectTaskSet());
List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
invoiceLineList.addAll(this.createSaleOrderInvoiceLines(invoice, saleOrderLineList, folder.getSaleOrderLineSetPrioritySelect()));
invoiceLineList.addAll(this.createPurchaseOrderInvoiceLines(invoice, purchaseOrderLineList, folder.getPurchaseOrderLineSetPrioritySelect()));
invoiceLineList.addAll(timesheetService.createInvoiceLines(invoice, timesheetLineList, folder.getLogTimesSetPrioritySelect()));
invoiceLineList.addAll(expenseService.createInvoiceLines(invoice, expenseLineList, folder.getExpenseLineSetPrioritySelect()));
invoiceLineList.addAll(projectTaskBusinessProjectService.createInvoiceLines(invoice, projectTaskList, folder.getProjectTaskSetPrioritySelect()));
Collections.sort(invoiceLineList, new InvoiceLineComparator());
for (InvoiceLine invoiceLine : invoiceLineList) {
invoiceLine.setSequence(sequence);
sequence++;
}
return invoiceLineList;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceServiceSupplychainImpl method computePackTotal.
@Override
public void computePackTotal(Invoice invoice) {
List<InvoiceLine> invoiceLineList = invoice.getInvoiceLineList();
if (!invoiceLineService.hasEndOfPackTypeLine(invoiceLineList)) {
return;
}
invoiceLineList.sort(Comparator.comparing(InvoiceLine::getSequence));
BigDecimal totalExTaxTotal = BigDecimal.ZERO;
BigDecimal totalInTaxTotal = BigDecimal.ZERO;
for (InvoiceLine invoiceLine : invoiceLineList) {
switch(invoiceLine.getTypeSelect()) {
case InvoiceLineRepository.TYPE_NORMAL:
totalExTaxTotal = totalExTaxTotal.add(invoiceLine.getExTaxTotal());
totalInTaxTotal = totalInTaxTotal.add(invoiceLine.getInTaxTotal());
break;
case InvoiceLineRepository.TYPE_TITLE:
break;
case InvoiceLineRepository.TYPE_START_OF_PACK:
totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
break;
case InvoiceLineRepository.TYPE_END_OF_PACK:
invoiceLine.setQty(BigDecimal.ZERO);
invoiceLine.setExTaxTotal(invoiceLine.getIsShowTotal() ? totalExTaxTotal : BigDecimal.ZERO);
invoiceLine.setInTaxTotal(invoiceLine.getIsShowTotal() ? totalInTaxTotal : BigDecimal.ZERO);
totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
break;
default:
break;
}
}
invoice.setInvoiceLineList(invoiceLineList);
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiIncomingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyInInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiIncomingStockMove(dummyInvoice, stockMove);
}
/* check if some other fields are different and assign a default value */
if (dummyInvoice.getAddress() == null) {
dummyInvoice.setAddress(Beans.get(PartnerService.class).getInvoicingAddress(dummyInvoice.getPartner()));
dummyInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(dummyInvoice.getAddress()));
}
fillReferenceInvoiceFromMultiInStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE, dummyInvoice.getCompany(), dummyInvoice.getPaymentCondition(), dummyInvoice.getPaymentMode(), dummyInvoice.getAddress(), dummyInvoice.getPartner(), dummyInvoice.getContactPartner(), dummyInvoice.getCurrency(), dummyInvoice.getPriceList(), dummyInvoice.getInternalReference(), dummyInvoice.getExternalReference(), dummyInvoice.getInAti(), null, dummyInvoice.getTradingName(), null) {
@Override
public Invoice generate() throws AxelorException {
return super.createInvoiceHeader();
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
createdInvoiceLines.forEach(this::negateInvoiceLinePrice);
}
invoiceLineList.addAll(createdInvoiceLines);
}
invoiceGenerator.populate(invoice, invoiceLineList);
invoiceRepository.save(invoice);
invoice = toPositivePriceInvoice(invoice);
if (invoice.getExTaxTotal().signum() == 0 && stockMoveList.stream().allMatch(StockMove::getIsReversion)) {
invoice.setOperationTypeSelect(InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceLineController method getInvoice.
public Invoice getInvoice(Context context) {
Context parentContext = context.getParent();
Invoice invoice = parentContext.asType(Invoice.class);
if (!parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
invoice = invoiceLine.getInvoice();
}
return invoice;
}
Aggregations