Search in sources :

Example 41 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceLineController method getAndComputeAnalyticDistribution.

public void getAndComputeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
    InvoiceLine invoiceLine = request.getContext().asType(InvoiceLine.class);
    Invoice invoice = invoiceLine.getInvoice();
    if (invoice == null) {
        invoice = request.getContext().getParent().asType(Invoice.class);
    }
    response.setValue("analyticMoveLineList", Beans.get(InvoiceLineService.class).getAndComputeAnalyticDistribution(invoiceLine, invoice));
    response.setValue("analyticDistributionTemplate", invoiceLine.getAnalyticDistributionTemplate());
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 42 with InvoiceLine

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;
    if (parentContext == null || !parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
        InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
        invoice = invoiceLine.getInvoice();
    } else {
        invoice = parentContext.asType(Invoice.class);
    }
    return invoice;
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 43 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class ExpenseServiceImpl method createInvoiceLines.

@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<ExpenseLine> expenseLineList, int priority) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    int count = 0;
    for (ExpenseLine expenseLine : expenseLineList) {
        invoiceLineList.addAll(this.createInvoiceLine(invoice, expenseLine, priority * 100 + count));
        count++;
        expenseLine.setInvoiced(true);
    }
    return invoiceLineList;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine)

Example 44 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class IntercoServiceImpl method generateIntercoInvoice.

@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
    PartnerService partnerService = Beans.get(PartnerService.class);
    InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
    InvoiceService invoiceService = Beans.get(InvoiceService.class);
    boolean isPurchase;
    // set the status
    int generatedOperationTypeSelect;
    int priceListRepositoryType;
    switch(invoice.getOperationTypeSelect()) {
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
    }
    Company intercoCompany = findIntercoCompany(invoice.getPartner());
    Partner intercoPartner = invoice.getCompany().getPartner();
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
    Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
    BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
    AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
    PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
    Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
    intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
    intercoInvoice.setCompany(intercoCompany);
    intercoInvoice.setPartner(intercoPartner);
    intercoInvoice.setAddress(intercoAddress);
    intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
    intercoInvoice.setPaymentMode(intercoPaymentMode);
    intercoInvoice.setBankDetails(intercoBankDetails);
    Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
    intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
    if (accountingSituation != null) {
        intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
        intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
        intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
    }
    intercoInvoice.setPriceList(intercoPriceList);
    intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
    intercoInvoice.setCreatedByInterco(true);
    intercoInvoice.setInterco(false);
    intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
    if (intercoInvoice.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
            invoiceLine.setInvoice(intercoInvoice);
            createIntercoInvoiceLine(invoiceLine, isPurchase);
        }
    }
    invoiceService.compute(intercoInvoice);
    intercoInvoice.setExternalReference(invoice.getInvoiceId());
    intercoInvoice = invoiceRepository.save(intercoInvoice);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
        Beans.get(InvoiceService.class).validate(intercoInvoice);
    }
    invoice.setExternalReference(intercoInvoice.getInvoiceId());
    return intercoInvoice;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BankDetails(com.axelor.apps.base.db.BankDetails) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) PartnerService(com.axelor.apps.base.service.PartnerService) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 45 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method createInvoiceLinesFromSO.

protected List<InvoiceLine> createInvoiceLinesFromSO(Invoice invoice, SaleOrder saleOrder, Product invoicingProduct, BigDecimal percentToInvoice) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    BigDecimal lineAmountToInvoice = percentToInvoice.multiply(saleOrder.getInTaxTotal()).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, invoicingProduct, invoicingProduct.getName(), lineAmountToInvoice, lineAmountToInvoice, lineAmountToInvoice, invoicingProduct.getDescription(), BigDecimal.ONE, invoicingProduct.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, lineAmountToInvoice, null, false) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    List<InvoiceLine> invoiceOneLineList = invoiceLineGenerator.creates();
    invoiceLineList.addAll(invoiceOneLineList);
    return invoiceLineList;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)80 ArrayList (java.util.ArrayList)36 Invoice (com.axelor.apps.account.db.Invoice)27 BigDecimal (java.math.BigDecimal)22 AxelorException (com.axelor.exception.AxelorException)20 Product (com.axelor.apps.base.db.Product)13 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)12 Transactional (com.google.inject.persist.Transactional)12 Context (com.axelor.rpc.Context)11 Account (com.axelor.apps.account.db.Account)8 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)7 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)5 HashSet (java.util.HashSet)5 List (java.util.List)5