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;
}
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;
}
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());
}
}
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));
}
}
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);
}
}
}
Aggregations