use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method mergeInvoice.
@Override
@Transactional
public Invoice mergeInvoice(List<Invoice> invoiceList, Company company, Currency currency, Partner partner, Partner contactPartner, PriceList priceList, PaymentMode paymentMode, PaymentCondition paymentCondition, SaleOrder saleOrder) throws AxelorException {
log.debug("service supplychain 1 (saleOrder) {}", saleOrder);
if (saleOrder != null) {
String numSeq = "";
String externalRef = "";
for (Invoice invoiceLocal : invoiceList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
if (invoiceLocal.getInternalReference() != null) {
numSeq += invoiceLocal.getInternalReference();
}
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (invoiceLocal.getExternalReference() != null) {
externalRef += invoiceLocal.getExternalReference();
}
}
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
Invoice invoiceMerged = invoiceGenerator.generate();
invoiceMerged.setExternalReference(externalRef);
invoiceMerged.setInternalReference(numSeq);
if (paymentMode != null)
invoiceMerged.setPaymentMode(paymentMode);
if (paymentCondition != null)
invoiceMerged.setPaymentCondition(paymentCondition);
List<InvoiceLine> invoiceLines = invoiceService.getInvoiceLinesFromInvoiceList(invoiceList);
invoiceGenerator.populate(invoiceMerged, invoiceLines);
invoiceService.setInvoiceForInvoiceLines(invoiceLines, invoiceMerged);
invoiceMerged.setSaleOrder(null);
invoiceRepo.save(invoiceMerged);
swapStockMoveInvoices(invoiceList, invoiceMerged);
invoiceService.deleteOldInvoices(invoiceList);
return invoiceMerged;
} else {
Invoice invoiceMerged = invoiceService.mergeInvoice(invoiceList, company, currency, partner, contactPartner, priceList, paymentMode, paymentCondition);
swapStockMoveInvoices(invoiceList, invoiceMerged);
invoiceService.deleteOldInvoices(invoiceList);
return invoiceMerged;
}
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoice.
public Invoice createInvoice(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(purchaseOrder);
Invoice invoice = invoiceGenerator.generate();
invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, purchaseOrderLineList, qtyToInvoiceMap));
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoice.
@Override
public Invoice createInvoice(PurchaseOrder purchaseOrder) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(purchaseOrder);
Invoice invoice = invoiceGenerator.generate();
List<InvoiceLine> invoiceLineList = this.createInvoiceLines(invoice, purchaseOrder.getPurchaseOrderLineList());
invoiceGenerator.populate(invoice, invoiceLineList);
invoice.setPurchaseOrder(purchaseOrder);
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class ContractServiceImpl method generateInvoice.
public Invoice generateInvoice(Contract contract) throws AxelorException {
InvoiceGenerator invoiceGenerator = new InvoiceGeneratorContract(contract);
Invoice invoice = invoiceGenerator.generate();
return invoice;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceGenerator in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiOutgoingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
Set<Address> deliveryAddressSet = new HashSet<>();
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyOutInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiOutgoingStockMove(dummyInvoice, stockMove);
if (stockMove.getToAddressStr() != null) {
deliveryAddressSet.add(stockMove.getToAddress());
}
}
/* 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()));
}
fillReferenceInvoiceFromMultiOutStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, 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(), dummyInvoice.getGroupProductsOnPrintings()) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setPartnerTaxNbr(partner.getTaxNbr());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
StringBuilder deliveryAddressStr = new StringBuilder();
AddressService addressService = Beans.get(AddressService.class);
for (Address address : deliveryAddressSet) {
deliveryAddressStr.append(addressService.computeAddressStr(address).replaceAll("\n", ", ") + "\n");
}
invoice.setDeliveryAddressStr(deliveryAddressStr.toString());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
stockMoveInvoiceService.checkSplitSalePartiallyInvoicedStockMoveLines(stockMoveLocal, stockMoveLocal.getStockMoveLineList());
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
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_CLIENT_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
Aggregations