Search in sources :

Example 56 with Invoice

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

the class PurchaseOrderInvoiceServiceImpl method generateInvoice.

@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLinesSelected, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    Invoice invoice = this.createInvoice(purchaseOrder, purchaseOrderLinesSelected, qtyToInvoiceMap);
    invoiceRepo.save(invoice);
    Beans.get(PurchaseOrderRepository.class).save(fillPurchaseOrder(purchaseOrder, invoice));
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) Transactional(com.google.inject.persist.Transactional)

Example 57 with Invoice

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

the class PurchaseOrderInvoiceServiceImpl method generateInvoice.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(PurchaseOrder purchaseOrder) throws AxelorException {
    Invoice invoice = this.createInvoice(purchaseOrder);
    invoice = invoiceRepo.save(invoice);
    invoiceService.setDraftSequence(invoice);
    invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional)

Example 58 with Invoice

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

the class VentilateState method checkInvoiceDate.

/**
 * - Without reset : assure that he doesn't exist invoice with an invoice date greater than the
 * current invoice date. - With monthly reset : determine the sequence using the Max number stored
 * on ventilated invoice on the same month. - With year reset : determine the sequence using the
 * Max number stored on ventilated invoice on the same year.
 *
 * @param sequence
 * @throws AxelorException
 */
protected void checkInvoiceDate(Sequence sequence) throws AxelorException {
    String query = "self.statusSelect = :ventilated AND self.invoiceDate > :invoiceDate AND self.operationTypeSelect = :operationTypeSelect AND self.company = :company ";
    Map<String, Object> params = new HashMap<>();
    params.put("ventilated", InvoiceRepository.STATUS_VENTILATED);
    params.put("invoiceDate", invoice.getInvoiceDate());
    params.put("operationTypeSelect", invoice.getOperationTypeSelect());
    params.put("company", invoice.getCompany());
    if (sequence.getMonthlyResetOk()) {
        query += "AND EXTRACT (month from self.invoiceDate) = :month ";
        params.put("month", invoice.getInvoiceDate().getMonthValue());
    }
    if (sequence.getYearlyResetOk()) {
        query += "AND EXTRACT (year from self.invoiceDate) = :year ";
        params.put("year", invoice.getInvoiceDate().getYear());
    }
    if (invoiceRepo.all().filter(query).bind(params).count() > 0) {
        Invoice lastInvoice = invoiceRepo.all().filter(query).bind(params).order("invoiceDate").fetchOne();
        if (sequence.getMonthlyResetOk()) {
            throw new AxelorException(sequence, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.VENTILATE_STATE_2), lastInvoice.getInvoiceDate().getMonth().toString());
        }
        if (sequence.getYearlyResetOk()) {
            throw new AxelorException(sequence, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.VENTILATE_STATE_3), Integer.toString(lastInvoice.getInvoiceDate().getYear()));
        }
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.VENTILATE_STATE_1), lastInvoice.getInvoiceDate().toString());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) WorkflowInvoice(com.axelor.apps.account.service.invoice.workflow.WorkflowInvoice) HashMap(java.util.HashMap)

Example 59 with Invoice

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

the class WorkflowVentilationServiceImpl method copyAdvancePaymentToInvoice.

/**
 * Copy payments from selected advance payment invoices to this invoice.
 *
 * @param invoice
 */
protected void copyAdvancePaymentToInvoice(Invoice invoice) throws AxelorException {
    Set<Invoice> advancePaymentInvoiceSet = invoice.getAdvancePaymentInvoiceSet();
    if (advancePaymentInvoiceSet == null) {
        return;
    }
    for (Invoice advancePaymentInvoice : advancePaymentInvoiceSet) {
        List<InvoicePayment> advancePayments = advancePaymentInvoice.getInvoicePaymentList();
        if (advancePayments == null) {
            continue;
        }
        for (InvoicePayment advancePayment : advancePayments) {
            InvoicePayment imputationPayment = invoicePaymentCreateService.createInvoicePayment(invoice, advancePayment.getAmount(), advancePayment.getPaymentDate(), advancePayment.getCurrency(), advancePayment.getPaymentMode(), InvoicePaymentRepository.TYPE_ADV_PAYMENT_IMPUTATION);
            advancePayment.setImputedBy(imputationPayment);
            imputationPayment.setCompanyBankDetails(advancePayment.getCompanyBankDetails());
            invoice.addInvoicePaymentListItem(imputationPayment);
            invoicePaymentRepo.save(imputationPayment);
        }
    }
    // if the sum of amounts in advance payment is greater than the amount
    // of the invoice, then we cancel the ventilation.
    List<InvoicePayment> invoicePayments = invoice.getInvoicePaymentList();
    if (invoicePayments == null || invoicePayments.isEmpty()) {
        return;
    }
    BigDecimal totalPayments = invoicePayments.stream().map(InvoicePayment::getAmount).reduce(BigDecimal::add).get();
    if (totalPayments.compareTo(invoice.getInTaxTotal()) > 0) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.AMOUNT_ADVANCE_PAYMENTS_TOO_HIGH));
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) BigDecimal(java.math.BigDecimal)

Example 60 with Invoice

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

the class InvoicePaymentCreateServiceImpl method computeAdvancePaymentImputation.

protected void computeAdvancePaymentImputation(InvoicePayment invoicePayment, Move paymentMove) {
    // check if the payment is an advance payment imputation
    Invoice advanceInvoice = determineIfReconcileFromInvoice(paymentMove);
    if (advanceInvoice != null) {
        List<InvoicePayment> invoicePaymentList = advanceInvoice.getInvoicePaymentList();
        if (invoicePaymentList != null && !invoicePaymentList.isEmpty()) {
            // set right type
            invoicePayment.setTypeSelect(InvoicePaymentRepository.TYPE_ADV_PAYMENT_IMPUTATION);
            // create link between advance payment and its imputation
            InvoicePayment advancePayment = advanceInvoice.getInvoicePaymentList().get(0);
            advancePayment.setImputedBy(invoicePayment);
            invoicePaymentRepository.save(advancePayment);
            // set the imputed payment currency
            invoicePayment.setCurrency(advancePayment.getCurrency());
            BigDecimal currentImputedAmount = invoicePayment.getAmount();
            // we force the payment amount to be equal to the advance
            // invoice amount, so we get the right amount in the
            // right currency.
            BigDecimal totalAmountInAdvanceInvoice = advancePayment.getInvoice().getCompanyInTaxTotal();
            BigDecimal convertedImputedAmount = currentImputedAmount.multiply(advancePayment.getAmount()).divide(totalAmountInAdvanceInvoice, 2, RoundingMode.HALF_UP);
            invoicePayment.setAmount(convertedImputedAmount);
        }
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) BigDecimal(java.math.BigDecimal)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14