use of com.axelor.apps.account.db.repo.MoveLineRepository in project axelor-open-suite by axelor.
the class PaymentVoucherLoadService method getMoveLines.
/**
* Searching move lines to pay
*
* @param pv paymentVoucher
* @param mlToIgnore moveLine list to ignore
* @return moveLines a list of moveLines
* @throws AxelorException
*/
public List<MoveLine> getMoveLines(PaymentVoucher paymentVoucher) throws AxelorException {
MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
String query = "self.partner = ?1 " + "and self.account.useForPartnerBalance = 't' " + "and self.amountRemaining > 0 " + "and (self.move.statusSelect = ?3 OR self.move.statusSelect = ?4)" + "and self.move.ignoreInDebtRecoveryOk = 'f' " + "and self.move.company = ?2 " + "and self.move.invoice.pfpValidateStatusSelect != ?5 " + "and (?6 IS NULL OR self.move.tradingName = ?6)";
if (paymentVoucherToolService.isDebitToPay(paymentVoucher)) {
query += " and self.debit > 0 ";
} else {
query += " and self.credit > 0 ";
}
return moveLineRepo.all().filter(query, paymentVoucher.getPartner(), paymentVoucher.getCompany(), MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, InvoiceRepository.PFP_STATUS_LITIGATION, paymentVoucher.getTradingName()).fetch();
}
use of com.axelor.apps.account.db.repo.MoveLineRepository in project axelor-open-suite by axelor.
the class MoveLineController method showCalculatedBalance.
public void showCalculatedBalance(ActionRequest request, ActionResponse response) {
BigDecimal totalCredit = new BigDecimal(0), totalDebit = new BigDecimal(0), finalBalance;
@SuppressWarnings("unchecked") List<Integer> idList = (List<Integer>) request.getContext().get("_ids");
try {
if (idList != null && !idList.isEmpty()) {
MoveLineRepository moveLineRepository = Beans.get(MoveLineRepository.class);
for (Integer id : idList) {
if (id != null) {
MoveLine moveLine = moveLineRepository.find(id.longValue());
if (moveLine != null && moveLine.getMove() != null) {
Integer statusSelect = moveLine.getMove().getStatusSelect();
if (statusSelect.equals(MoveRepository.STATUS_VALIDATED) || statusSelect.equals(MoveRepository.STATUS_ACCOUNTED)) {
totalCredit = totalCredit.add(moveLine.getCredit());
totalDebit = totalDebit.add(moveLine.getDebit());
}
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get("Cannot find the move line with id: %s"), id.longValue());
}
} else {
throw new AxelorException(MoveLine.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get("One id is null"));
}
}
finalBalance = totalDebit.subtract(totalCredit);
response.setView(ActionView.define("Calculation").model(Wizard.class.getName()).add("form", "account-move-line-calculation-wizard-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("width", "500").param("popup-save", "false").context("_credit", totalCredit).context("_debit", totalDebit).context("_balance", finalBalance).map());
} else {
response.setAlert(I18n.get(IExceptionMessage.NO_MOVE_LINE_SELECTED));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.repo.MoveLineRepository in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursementInvoice.
/**
* Procédure permettant de créer un remboursement si un trop perçu est généré à la facture fin de
* cycle grand comptes
*
* @param invoice Une facture
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createReimbursementInvoice(Invoice invoice) throws AxelorException {
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
// récupération des trop-perçus du tiers
List<? extends MoveLine> moveLineList = moveLineRepo.all().filter("self.account.useForPartnerBalance = 'true' " + "AND (self.move.statusSelect = ?1 OR self.move.statusSelect = ?2) AND self.amountRemaining > 0 AND self.credit > 0 AND self.partner = ?3 AND self.reimbursementStatusSelect = ?4 ", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, partner, MoveLineRepository.REIMBURSEMENT_STATUS_NULL).fetch();
this.createReimbursementInvoice(partner, company, moveLineList);
}
use of com.axelor.apps.account.db.repo.MoveLineRepository in project axelor-open-suite by axelor.
the class ReimbursementImportService method createReimbursementRejectMoveLine.
@Transactional(rollbackOn = { Exception.class })
public Reimbursement createReimbursementRejectMoveLine(String[] reject, Company company, int seq, Move move, LocalDate rejectDate) throws AxelorException {
String refReject = reject[1];
// String amountReject = reject[2];
InterbankCodeLine causeReject = rejectImportService.getInterbankCodeLine(reject[3], 0);
MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
Reimbursement reimbursement = reimbursementRepo.all().filter("UPPER(self.ref) = ?1 AND self.company = ?2", refReject, company).fetchOne();
if (reimbursement == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.REIMBURSEMENT_3), refReject, company.getName());
}
Partner partner = reimbursement.getPartner();
BigDecimal amount = reimbursement.getAmountReimbursed();
// Création de la ligne au crédit
MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, company.getAccountConfig().getCustomerAccount(), amount, false, rejectDate, seq, refReject, null);
move.getMoveLineList().add(creditMoveLine);
moveLineRepo.save(creditMoveLine);
moveRepo.save(move);
creditMoveLine.setInterbankCodeLine(causeReject);
reimbursement.setRejectedOk(true);
reimbursement.setRejectDate(rejectDate);
reimbursement.setRejectMoveLine(creditMoveLine);
reimbursement.setInterbankCodeLine(causeReject);
reimbursementRepo.save(reimbursement);
return reimbursement;
}
use of com.axelor.apps.account.db.repo.MoveLineRepository in project axelor-open-suite by axelor.
the class YearServiceAccountImpl method computeReportedBalance2.
@Deprecated
public BigDecimal computeReportedBalance2(LocalDate fromDate, LocalDate toDate, Partner partner, Account account) {
MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
List<? extends MoveLine> moveLineList = moveLineRepo.all().filter("self.partner = ?1 AND self.ignoreInAccountingOk = 'false' AND self.date >= ?2 AND self.date <= ?3 AND self.account = ?4", partner, fromDate, toDate, account).fetch();
BigDecimal reportedBalanceAmount = BigDecimal.ZERO;
for (MoveLine moveLine : moveLineList) {
if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
reportedBalanceAmount = reportedBalanceAmount.subtract(moveLine.getAmountRemaining());
} else if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
reportedBalanceAmount = reportedBalanceAmount.add(moveLine.getAmountRemaining());
}
}
if (log.isDebugEnabled()) {
log.debug("Solde rapporté : {}", reportedBalanceAmount);
}
return reportedBalanceAmount;
}
Aggregations