use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveValidateService method freezeAccountAndPartnerFieldsOnMoveLines.
/**
* Method that freeze the account and partner fields on move lines
*
* @param move
*/
public void freezeAccountAndPartnerFieldsOnMoveLines(Move move) {
for (MoveLine moveLine : move.getMoveLineList()) {
Account account = moveLine.getAccount();
moveLine.setAccountId(account.getId());
moveLine.setAccountCode(account.getCode());
moveLine.setAccountName(account.getName());
Partner partner = moveLine.getPartner();
if (partner != null) {
moveLine.setPartnerId(partner.getId());
moveLine.setPartnerFullName(partner.getFullName());
moveLine.setPartnerSeq(partner.getPartnerSeq());
}
if (moveLine.getTaxLine() != null) {
moveLine.setTaxRate(moveLine.getTaxLine().getValue());
moveLine.setTaxCode(moveLine.getTaxLine().getTax().getCode());
}
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class PaymentServiceImpl method useExcessPaymentWithAmountConsolidated.
@SuppressWarnings("unchecked")
@Override
public int useExcessPaymentWithAmountConsolidated(List<MoveLine> creditMoveLines, BigDecimal remainingPaidAmount, Move move, int moveLineNo, Partner partner, Company company, Account account, LocalDate date, LocalDate dueDate) throws AxelorException {
log.debug("In useExcessPaymentWithAmount");
int moveLineNo2 = moveLineNo;
BigDecimal remainingPaidAmount2 = remainingPaidAmount;
List<Reconcile> reconcileList = new ArrayList<Reconcile>();
int i = creditMoveLines.size();
if (i != 0) {
Query q = JPA.em().createQuery("select new map(ml.account, SUM(ml.amountRemaining)) FROM MoveLine as ml " + "WHERE ml in ?1 group by ml.account");
q.setParameter(1, creditMoveLines);
List<Map<Account, BigDecimal>> allMap = new ArrayList<Map<Account, BigDecimal>>();
allMap = q.getResultList();
for (Map<Account, BigDecimal> map : allMap) {
Account accountMap = (Account) map.values().toArray()[0];
BigDecimal amountMap = (BigDecimal) map.values().toArray()[1];
BigDecimal amountDebit = amountMap.min(remainingPaidAmount2);
if (amountDebit.compareTo(BigDecimal.ZERO) > 0) {
MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, accountMap, amountDebit, true, date, dueDate, moveLineNo2, null, null);
move.getMoveLineList().add(debitMoveLine);
moveLineNo2++;
for (MoveLine creditMoveLine : creditMoveLines) {
if (creditMoveLine.getAccount().equals(accountMap)) {
Reconcile reconcile = null;
i--;
// Afin de pouvoir arrêter si il n'y a plus rien à payer
if (amountDebit.compareTo(BigDecimal.ZERO) <= 0) {
break;
}
BigDecimal amountToPay = amountDebit.min(creditMoveLine.getAmountRemaining());
// Gestion du passage en 580
if (i == 0) {
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, true);
} else {
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, false);
}
if (reconcile != null) {
remainingPaidAmount2 = remainingPaidAmount2.subtract(amountToPay);
amountDebit = amountDebit.subtract(amountToPay);
reconcileList.add(reconcile);
}
}
}
}
}
for (Reconcile reconcile : reconcileList) {
reconcileService.confirmReconcile(reconcile, true);
}
}
// Si il y a un restant à payer, alors on crée un dû.
if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) > 0) {
MoveLine debitmoveLine = moveLineService.createMoveLine(move, partner, account, remainingPaidAmount2, true, date, dueDate, moveLineNo2, null, null);
move.getMoveLineList().add(debitmoveLine);
moveLineNo2++;
}
log.debug("End useExcessPaymentWithAmount");
return moveLineNo2;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class PaymentServiceImpl method createExcessPaymentWithAmount.
/**
* Il crée des écritures de trop percu avec des montants exacts pour chaque débitMoveLines avec le
* compte du débitMoveLines. A la fin, si il reste un trop-percu alors créer un trop-perçu
* classique.
*
* @param debitMoveLines Les lignes d'écriture à payer
* @param remainingPaidAmount Le montant restant à payer
* @param move Une écriture
* @param moveLineNo Un numéro de ligne d'écriture
* @return
* @throws AxelorException
*/
@Override
public int createExcessPaymentWithAmount(List<MoveLine> debitMoveLines, BigDecimal remainingPaidAmount, Move move, int moveLineNo, Partner partner, Company company, PayVoucherElementToPay payVoucherElementToPay, Account account, LocalDate paymentDate) throws AxelorException {
log.debug("In createExcessPaymentWithAmount");
int moveLineNo2 = moveLineNo;
BigDecimal remainingPaidAmount2 = remainingPaidAmount;
List<Reconcile> reconcileList = new ArrayList<Reconcile>();
int i = debitMoveLines.size();
for (MoveLine debitMoveLine : debitMoveLines) {
i--;
BigDecimal amountRemaining = debitMoveLine.getAmountRemaining();
// Afin de pouvoir arrêter si il n'y a plus rien pour payer
if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) <= 0) {
break;
}
BigDecimal amountToPay = remainingPaidAmount2.min(amountRemaining);
String invoiceName = "";
if (debitMoveLine.getMove().getInvoice() != null) {
invoiceName = debitMoveLine.getMove().getInvoice().getInvoiceId();
} else {
invoiceName = payVoucherElementToPay.getPaymentVoucher().getRef();
}
MoveLine creditMoveLine = moveLineService.createMoveLine(move, debitMoveLine.getPartner(), debitMoveLine.getAccount(), amountToPay, false, appAccountService.getTodayDate(company), moveLineNo2, invoiceName, null);
move.getMoveLineList().add(creditMoveLine);
// Utiliser uniquement dans le cas du paiemnt des échéances lors d'une saisie paiement
if (payVoucherElementToPay != null) {
creditMoveLine.setPaymentScheduleLine(payVoucherElementToPay.getMoveLine().getPaymentScheduleLine());
payVoucherElementToPay.setMoveLineGenerated(creditMoveLine);
}
moveLineNo2++;
Reconcile reconcile = null;
// Gestion du passage en 580
if (i == 0) {
log.debug("last loop");
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, true);
} else {
reconcile = reconcileService.createReconcile(debitMoveLine, creditMoveLine, amountToPay, false);
}
if (reconcile != null) {
reconcileList.add(reconcile);
remainingPaidAmount2 = remainingPaidAmount2.subtract(amountRemaining);
}
}
for (Reconcile reconcile : reconcileList) {
reconcileService.confirmReconcile(reconcile, true);
}
// Si il y a un restant à payer, alors on crée un trop-perçu.
if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) > 0) {
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, remainingPaidAmount2, false, appAccountService.getTodayDate(company), moveLineNo2, null, null);
move.getMoveLineList().add(moveLine);
moveLineNo2++;
// Gestion du passage en 580
reconcileService.balanceCredit(moveLine);
}
log.debug("End createExcessPaymentWithAmount");
return moveLineNo2;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class PaymentServiceImpl method useExcessPaymentOnMoveLines.
/**
* Use excess payment between a list of debit move lines and a list of credit move lines. The
* lists needs to be ordered by date in order to pay the invoices chronologically.
*
* @param debitMoveLines
* @param creditMoveLines
* @param dontThrow
* @throws AxelorException
*/
protected void useExcessPaymentOnMoveLines(List<MoveLine> debitMoveLines, List<MoveLine> creditMoveLines, boolean dontThrow) throws AxelorException {
if (debitMoveLines != null && creditMoveLines != null) {
log.debug("Emploie du trop perçu (nombre de lignes en débit : {}, nombre de ligne en crédit : {})", new Object[] { debitMoveLines.size(), creditMoveLines.size() });
BigDecimal debitTotalRemaining = BigDecimal.ZERO;
BigDecimal creditTotalRemaining = BigDecimal.ZERO;
for (MoveLine creditMoveLine : creditMoveLines) {
log.debug("Emploie du trop perçu : ligne en crédit : {})", creditMoveLine);
log.debug("Emploie du trop perçu : ligne en crédit (restant à payer): {})", creditMoveLine.getAmountRemaining());
creditTotalRemaining = creditTotalRemaining.add(creditMoveLine.getAmountRemaining());
}
for (MoveLine debitMoveLine : debitMoveLines) {
log.debug("Emploie du trop perçu : ligne en débit : {})", debitMoveLine);
log.debug("Emploie du trop perçu : ligne en débit (restant à payer): {})", debitMoveLine.getAmountRemaining());
debitTotalRemaining = debitTotalRemaining.add(debitMoveLine.getAmountRemaining());
}
for (MoveLine creditMoveLine : creditMoveLines) {
if (creditMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) {
for (MoveLine debitMoveLine : debitMoveLines) {
if ((debitMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) && (creditMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1)) {
try {
createReconcile(debitMoveLine, creditMoveLine, debitTotalRemaining, creditTotalRemaining);
} catch (Exception e) {
if (dontThrow) {
TraceBackService.trace(e);
log.debug(e.getMessage());
} else {
throw e;
}
}
}
}
}
}
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class InvoicePaymentValidateServiceImpl method createMoveForInvoicePayment.
/**
* Method to create a payment move for an invoice Payment
*
* <p>Create a move and reconcile it with the invoice move
*
* @param invoicePayment An invoice payment
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createMoveForInvoicePayment(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
Company company = invoice.getCompany();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Partner partner = invoice.getPartner();
LocalDate paymentDate = invoicePayment.getPaymentDate();
BigDecimal paymentAmount = invoicePayment.getAmount();
BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails();
Account customerAccount;
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
boolean isDebitInvoice = moveService.getMoveToolService().isDebitCustomer(invoice, true);
MoveLine invoiceMoveLine = moveService.getMoveToolService().getInvoiceCustomerMoveLineByLoop(invoice);
if (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
customerAccount = accountConfigService.getAdvancePaymentAccount(accountConfig);
} else {
if (invoiceMoveLine == null) {
return null;
}
customerAccount = invoiceMoveLine.getAccount();
}
String origin = invoicePayment.getInvoice().getInvoiceId();
if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_CHEQUE || invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_IPO_CHEQUE) {
origin = invoicePayment.getChequeNumber() != null ? invoicePayment.getChequeNumber() : origin;
} else if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_BANK_CARD) {
origin = invoicePayment.getInvoicePaymentRef() != null ? invoicePayment.getInvoicePaymentRef() : origin;
}
if (invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
origin = invoicePayment.getInvoice().getSupplierInvoiceNb();
}
Move move = moveService.getMoveCreateService().createMove(journal, company, invoicePayment.getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.setTradingName(invoice.getTradingName());
move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, isDebitInvoice, paymentDate, null, 1, origin, invoicePayment.getDescription()));
MoveLine customerMoveLine = moveLineService.createMoveLine(move, partner, customerAccount, paymentAmount, !isDebitInvoice, paymentDate, null, 2, origin, invoicePayment.getDescription());
move.addMoveLineListItem(customerMoveLine);
moveService.getMoveValidateService().validate(move);
if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
Reconcile reconcile = reconcileService.reconcile(invoiceMoveLine, customerMoveLine, true, false);
invoicePayment.setReconcile(reconcile);
}
invoicePayment.setMove(move);
invoicePaymentRepository.save(invoicePayment);
return invoicePayment;
}
Aggregations