use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveCancelService method cancel.
@Transactional(rollbackOn = { Exception.class })
public void cancel(Move move) throws AxelorException {
if (move == null) {
return;
}
for (MoveLine moveLine : move.getMoveLineList()) {
if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountPaid().compareTo(BigDecimal.ZERO) != 0) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_1));
}
}
if (move.getPeriod() == null || move.getPeriod().getStatusSelect() == PeriodRepository.STATUS_CLOSED) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_2));
}
if (move.getStatusSelect().equals(MoveRepository.STATUS_VALIDATED)) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_4));
}
try {
if (move.getStatusSelect() == MoveRepository.STATUS_NEW || accountConfigService.getAccountConfig(move.getCompany()).getAllowRemovalValidatedMove()) {
moveRepository.remove(move);
} else {
move.setStatusSelect(MoveRepository.STATUS_CANCELED);
moveRepository.save(move);
}
} catch (Exception e) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_3));
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveCreateService method createMove.
/**
* Creating a new generic accounting move
*
* @param journal
* @param company
* @param currency
* @param partner
* @param date
* @param paymentMode
* @param technicalOriginSelect
* @param ignoreInDebtRecoveryOk
* @param ignoreInAccountingOk
* @return
* @throws AxelorException
*/
public Move createMove(Journal journal, Company company, Currency currency, Partner partner, LocalDate date, PaymentMode paymentMode, int technicalOriginSelect, int functionalOriginSelect, boolean ignoreInDebtRecoveryOk, boolean ignoreInAccountingOk, boolean autoYearClosureMove) throws AxelorException {
log.debug("Creating a new generic accounting move (journal : {}, company : {}", new Object[] { journal.getName(), company.getName() });
Move move = new Move();
move.setJournal(journal);
move.setCompany(company);
move.setIgnoreInDebtRecoveryOk(ignoreInDebtRecoveryOk);
move.setIgnoreInAccountingOk(ignoreInAccountingOk);
move.setAutoYearClosureMove(autoYearClosureMove);
if (autoYearClosureMove) {
move.setPeriod(periodService.getPeriod(date, company, YearRepository.TYPE_FISCAL));
if (move.getPeriod() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), date.toString());
}
} else {
move.setPeriod(periodService.getActivePeriod(date, company, YearRepository.TYPE_FISCAL));
}
move.setDate(date);
move.setMoveLineList(new ArrayList<MoveLine>());
Currency companyCurrency = companyConfigService.getCompanyCurrency(company);
if (companyCurrency != null) {
move.setCompanyCurrency(companyCurrency);
move.setCompanyCurrencyCode(companyCurrency.getCode());
}
if (currency == null) {
currency = move.getCompanyCurrency();
}
if (currency != null) {
move.setCurrency(currency);
move.setCurrencyCode(currency.getCode());
}
move.setPartner(partner);
move.setPaymentMode(paymentMode);
move.setTechnicalOriginSelect(technicalOriginSelect);
move.setFunctionalOriginSelect(functionalOriginSelect);
moveRepository.save(move);
move.setReference(Beans.get(SequenceService.class).getDraftSequenceNumber(move));
return move;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class MoveDueService method getInvoiceDue.
public List<MoveLine> getInvoiceDue(Invoice invoice, boolean useOthersInvoiceDue) throws AxelorException {
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
List<MoveLine> debitMoveLines = Lists.newArrayList();
// Ajout de la facture d'origine
MoveLine originalInvoice = this.getOrignalInvoiceFromRefund(invoice);
if (originalInvoice != null) {
debitMoveLines.add(originalInvoice);
}
// Récupérer les dûs du tiers pour le même compte que celui de l'avoir
List<? extends MoveLine> othersDebitMoveLines = null;
if (useOthersInvoiceDue) {
if (debitMoveLines != null && debitMoveLines.size() != 0) {
othersDebitMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.debit > 0 AND self.amountRemaining > 0 " + " AND self.partner = ?5 AND self NOT IN (?6) ORDER BY self.date ASC ", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, partner, debitMoveLines).fetch();
} else {
othersDebitMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.debit > 0 AND self.amountRemaining > 0 " + " AND self.partner = ?5 ORDER BY self.date ASC ", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, partner).fetch();
}
debitMoveLines.addAll(othersDebitMoveLines);
}
log.debug("Nombre de ligne à payer avec l'avoir récupéré : {}", debitMoveLines.size());
return debitMoveLines;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class PaymentVoucherCreateService method createPaymentVoucherIPO.
@Transactional(rollbackOn = { Exception.class })
public PaymentVoucher createPaymentVoucherIPO(Invoice invoice, LocalDate date, BigDecimal amount, PaymentMode paymentMode) throws AxelorException {
MoveLine customerMoveLine = moveToolService.getCustomerMoveLineByQuery(invoice);
log.debug("Création d'une saisie paiement par TIP ou TIP chèque - facture : {}", invoice.getInvoiceId());
log.debug("Création d'une saisie paiement par TIP ou TIP chèque - mode de paiement : {}", paymentMode.getCode());
log.debug("Création d'une saisie paiement par TIP ou TIP chèque - société : {}", invoice.getCompany().getName());
log.debug("Création d'une saisie paiement par TIP ou TIP chèque - tiers payeur : {}", invoice.getPartner().getName());
PaymentVoucher paymentVoucher = this.createPaymentVoucher(invoice.getCompany(), null, paymentMode, date, invoice.getPartner(), amount, null, invoice, null, null, null);
paymentVoucher.setHasAutoInput(true);
List<PayVoucherElementToPay> lines = new ArrayList<PayVoucherElementToPay>();
lines.add(payVoucherElementToPayService.createPayVoucherElementToPay(paymentVoucher, 1, invoice, customerMoveLine, customerMoveLine.getDebit(), customerMoveLine.getAmountRemaining(), amount));
paymentVoucher.setPayVoucherElementToPayList(lines);
paymentVoucherRepository.save(paymentVoucher);
paymentVoucherConfirmService.confirmPaymentVoucher(paymentVoucher);
return paymentVoucher;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class InvoicePaymentCreateServiceImpl method determineIfReconcileFromInvoice.
/**
* We try to get to the status of the invoice from the reconcile to see if this move was created
* from a payment for an advance payment invoice.
*
* @param move
* @return the found advance invoice if the move is from a payment that comes from this invoice.
* null in other cases
*/
protected Invoice determineIfReconcileFromInvoice(Move move) {
List<MoveLine> moveLineList = move.getMoveLineList();
if (moveLineList == null || moveLineList.size() != 2) {
return null;
}
InvoicePaymentRepository invoicePaymentRepo = Beans.get(InvoicePaymentRepository.class);
for (MoveLine moveLine : moveLineList) {
// search for the reconcile between the debit line
if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
Reconcile reconcile = Beans.get(ReconcileRepository.class).all().filter("self.debitMoveLine = ?", moveLine).fetchOne();
if (reconcile == null) {
return null;
}
// associated payment
if (reconcile.getCreditMoveLine() == null || reconcile.getCreditMoveLine().getMove() == null) {
continue;
}
Move candidatePaymentMove = reconcile.getCreditMoveLine().getMove();
InvoicePayment invoicePayment = invoicePaymentRepo.all().filter("self.move = :_move").bind("_move", candidatePaymentMove).fetchOne();
// payment, then return true.
if (invoicePayment != null && invoicePayment.getInvoice() != null && invoicePayment.getInvoice().getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
return invoicePayment.getInvoice();
}
}
}
return null;
}
Aggregations