use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method transformToRefund.
/**
* Change the operation type and invert all prices in the invoice.
*
* @param invoice an invoice
* @return the refund invoice
*/
protected Invoice transformToRefund(Invoice invoice) throws AxelorException {
Invoice refund = new RefundInvoice(invoice).generate();
if (refund.getInvoiceLineList() != null) {
for (InvoiceLine invoiceLine : refund.getInvoiceLineList()) {
invoiceLine.setPrice(invoiceLine.getPrice().negate());
invoiceLine.setPriceDiscounted(invoiceLine.getPriceDiscounted().negate());
invoiceLine.setInTaxPrice(invoiceLine.getInTaxPrice().negate());
invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().negate());
invoiceLine.setInTaxTotal(invoiceLine.getInTaxTotal().negate());
invoiceLine.setCompanyExTaxTotal(invoiceLine.getCompanyExTaxTotal().negate());
invoiceLine.setCompanyInTaxTotal(invoiceLine.getCompanyInTaxTotal().negate());
}
}
if (refund.getInvoiceLineTaxList() != null) {
for (InvoiceLineTax invoiceLineTax : refund.getInvoiceLineTaxList()) {
invoiceLineTax.setExTaxBase(invoiceLineTax.getExTaxBase().negate());
invoiceLineTax.setTaxTotal(invoiceLineTax.getTaxTotal().negate());
invoiceLineTax.setCompanyExTaxBase(invoiceLineTax.getCompanyExTaxBase().negate());
invoiceLineTax.setInTaxTotal(invoiceLineTax.getInTaxTotal().negate());
invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyInTaxTotal().negate());
}
}
refund.setExTaxTotal(refund.getExTaxTotal().negate());
refund.setInTaxTotal(refund.getInTaxTotal().negate());
refund.setCompanyExTaxTotal(refund.getCompanyExTaxTotal().negate());
refund.setCompanyInTaxTotal(refund.getCompanyInTaxTotal().negate());
refund.setTaxTotal(refund.getTaxTotal().negate());
refund.setAmountRemaining(refund.getAmountRemaining().negate());
refund.setCompanyTaxTotal(refund.getCompanyTaxTotal().negate());
refund.setPaymentMode(InvoiceToolService.getPaymentMode(refund));
return invoiceRepository.save(refund);
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableMove.
/**
* Fonction permettant de créer l'écriture de passage en irrécouvrable d'une facture
*
* @param invoice Une facture
* @param prorataRate Le taux de restant à payer sur la facture
* @param isInvoiceReject La facture est-elle rejetée?
* @return
* @throws AxelorException
*/
public Move createIrrecoverableMove(Invoice invoice, BigDecimal prorataRate, boolean isInvoiceReject, String irrecoverableName) throws AxelorException {
Company company = invoice.getCompany();
Partner payerPartner = invoice.getPartner();
AccountConfig accountConfig = company.getAccountConfig();
// Move
Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_SALE);
int seq = 1;
BigDecimal amount = BigDecimal.ZERO;
MoveLine debitMoveLine = null;
BigDecimal creditAmount = null;
BigDecimal debitAmount = null;
if (isInvoiceReject) {
creditAmount = invoice.getRejectMoveLine().getAmountRemaining();
debitAmount = creditAmount;
} else {
creditAmount = invoice.getCompanyInTaxTotalRemaining();
debitAmount = creditAmount;
}
// Debits MoveLines Tva
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
amount = (invoiceLineTax.getTaxTotal().multiply(prorataRate)).setScale(2, RoundingMode.HALF_UP);
// do not generate move line with amount equal to zero
if (amount.signum() == 0) {
continue;
}
debitMoveLine = moveLineService.createMoveLine(move, payerPartner, taxAccountService.getAccount(invoiceLineTax.getTaxLine().getTax(), company, false, false), amount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(debitMoveLine);
seq++;
debitAmount = debitAmount.subtract(amount);
}
// Debit MoveLine 654 (irrecoverable account)
debitMoveLine = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), debitAmount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(debitMoveLine);
seq++;
// Getting customer MoveLine from Facture
MoveLine customerMoveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
if (customerMoveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
}
customerMoveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
// Credit MoveLine Customer account (411, 416, ...)
MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, customerMoveLine.getAccount(), creditAmount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
move.getMoveLineList().add(creditMoveLine);
Reconcile reconcile = reconcileService.createReconcile(customerMoveLine, creditMoveLine, creditAmount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
return move;
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method generateTaxPaymentMoveLineList.
@Override
@Transactional(rollbackOn = { Exception.class })
public MoveLine generateTaxPaymentMoveLineList(MoveLine customerMoveLine, Invoice invoice, Reconcile reconcile) throws AxelorException {
BigDecimal paymentAmount = reconcile.getAmount();
BigDecimal invoiceTotalAmount = invoice.getCompanyInTaxTotal();
for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
TaxLine taxLine = invoiceLineTax.getTaxLine();
BigDecimal vatRate = taxLine.getValue();
BigDecimal baseAmount = invoiceLineTax.getCompanyExTaxBase();
BigDecimal detailPaymentAmount = baseAmount.multiply(paymentAmount).divide(invoiceTotalAmount, 6, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
TaxPaymentMoveLine taxPaymentMoveLine = new TaxPaymentMoveLine(customerMoveLine, taxLine, reconcile, vatRate, detailPaymentAmount, Beans.get(AppBaseService.class).getTodayDate(reconcile.getCompany()));
taxPaymentMoveLine = taxPaymentMoveLineService.computeTaxAmount(taxPaymentMoveLine);
customerMoveLine.addTaxPaymentMoveLineListItem(taxPaymentMoveLine);
}
this.computeTaxAmount(customerMoveLine);
return Beans.get(MoveLineRepository.class).save(customerMoveLine);
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class TaxInvoiceLine method createOrUpdateInvoiceLineTaxRc.
protected void createOrUpdateInvoiceLineTaxRc(InvoiceLine invoiceLine, TaxLine taxLineRC, TaxEquiv taxEquiv, Map<TaxLine, InvoiceLineTax> map) {
if (map.containsKey(taxLineRC)) {
InvoiceLineTax invoiceLineTaxRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
updateInvoiceLineTax(invoiceLine, invoiceLineTaxRC);
invoiceLineTaxRC.setReverseCharged(true);
} else {
InvoiceLineTax invoiceLineTaxRC = createInvoiceLineTax(invoiceLine, taxLineRC);
invoiceLineTaxRC.setReverseCharged(true);
map.put(taxLineRC, invoiceLineTaxRC);
}
}
use of com.axelor.apps.account.db.InvoiceLineTax in project axelor-open-suite by axelor.
the class TaxInvoiceLine method finalizeInvoiceLineTaxes.
protected List<InvoiceLineTax> finalizeInvoiceLineTaxes(Map<TaxLine, InvoiceLineTax> map) {
List<InvoiceLineTax> invoiceLineTaxList = new ArrayList<>();
for (InvoiceLineTax invoiceLineTax : map.values()) {
BigDecimal taxValue = invoiceLineTax.getTaxLine().getValue();
// Dans la devise de la facture
BigDecimal exTaxBase = (invoiceLineTax.getReverseCharged()) ? invoiceLineTax.getExTaxBase().negate() : invoiceLineTax.getExTaxBase();
BigDecimal taxTotal = computeAmount(exTaxBase, taxValue);
invoiceLineTax.setTaxTotal(taxTotal);
invoiceLineTax.setInTaxTotal(invoiceLineTax.getExTaxBase().add(taxTotal));
// Dans la devise de la société
BigDecimal companyExTaxBase = (invoiceLineTax.getReverseCharged()) ? invoiceLineTax.getCompanyExTaxBase().negate() : invoiceLineTax.getCompanyExTaxBase();
BigDecimal companyTaxTotal = computeAmount(companyExTaxBase, taxValue);
invoiceLineTax.setCompanyTaxTotal(companyTaxTotal);
invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyExTaxBase().add(companyTaxTotal));
BigDecimal subTotalExcludingFixedAssets = invoiceLineTax.getReverseCharged() ? invoiceLineTax.getSubTotalExcludingFixedAssets().negate() : invoiceLineTax.getSubTotalExcludingFixedAssets();
invoiceLineTax.setSubTotalExcludingFixedAssets(computeAmount(subTotalExcludingFixedAssets, taxValue));
invoiceLineTax.setSubTotalOfFixedAssets(taxTotal.subtract(invoiceLineTax.getSubTotalExcludingFixedAssets()).setScale(2, RoundingMode.HALF_UP));
BigDecimal companySubTotalExcludingFixedAssets = invoiceLineTax.getReverseCharged() ? invoiceLineTax.getCompanySubTotalExcludingFixedAssets().negate() : invoiceLineTax.getCompanySubTotalExcludingFixedAssets();
invoiceLineTax.setCompanySubTotalExcludingFixedAssets(computeAmount(companySubTotalExcludingFixedAssets, taxValue));
invoiceLineTax.setCompanySubTotalOfFixedAssets(companyTaxTotal.subtract(invoiceLineTax.getCompanySubTotalExcludingFixedAssets()).setScale(2, RoundingMode.HALF_UP));
invoiceLineTaxList.add(invoiceLineTax);
LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", invoiceLineTax.getTaxTotal(), invoiceLineTax.getInTaxTotal());
}
return invoiceLineTaxList;
}
Aggregations