Search in sources :

Example 51 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class PaymentScheduleLineBankPaymentServiceImpl method reject.

@Override
@Transactional(rollbackOn = { Exception.class })
public void reject(PaymentScheduleLine paymentScheduleLine, InterbankCodeLine rejectionReason, boolean represent) throws AxelorException {
    Preconditions.checkNotNull(paymentScheduleLine, I18n.get("Payment schedule line cannot be null."));
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    Preconditions.checkNotNull(paymentSchedule, I18n.get("Parent payment schedule cannot be null."));
    if (paymentScheduleLine.getStatusSelect() != PaymentScheduleLineRepository.STATUS_VALIDATED) {
        throw new AxelorException(paymentScheduleLine, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get("Only validated payment schedule lines can be rejected."));
    }
    Move rejectionMove = createRejectionMove(paymentScheduleLine);
    if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS) {
        cancelInvoicePayments(paymentScheduleLine);
    }
    if (represent) {
        representPaymentScheduleLine(paymentScheduleLine);
    }
    if (rejectionReason == null) {
        rejectionReason = getDefaultRejectionReason();
    }
    MoveLine rejectionMoveLine = moveService.findMoveLineByAccount(rejectionMove, paymentScheduleLine.getAdvanceMoveLine().getAccount());
    paymentScheduleLine.setInterbankCodeLine(rejectionReason);
    paymentScheduleLine.setRejectMoveLine(rejectionMoveLine);
    paymentScheduleLine.setRejectDate(rejectionMove.getDate());
    paymentScheduleLine.setAmountRejected(paymentScheduleLine.getRejectMoveLine().getDebit());
    paymentScheduleLine.setRejectedOk(true);
    paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_CLOSED);
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 52 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class BatchAccountingCutOff method process.

@Override
protected void process() {
    int offset = 0;
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    LocalDate moveDate = supplychainBatch.getMoveDate();
    LocalDate reverseMoveDate = supplychainBatch.getReverseMoveDate();
    boolean recoveredTax = supplychainBatch.getRecoveredTax();
    boolean ati = supplychainBatch.getAti();
    String moveDescription = supplychainBatch.getMoveDescription();
    int accountingCutOffTypeSelect = supplychainBatch.getAccountingCutOffTypeSelect();
    updateBatch(moveDate, accountingCutOffTypeSelect);
    Company company = supplychainBatch.getCompany();
    boolean includeNotStockManagedProduct = supplychainBatch.getIncludeNotStockManagedProduct();
    if (accountingCutOffTypeSelect == 0) {
        return;
    }
    List<StockMove> stockMoveList;
    while (!(stockMoveList = cutOffService.getStockMoves(company, accountingCutOffTypeSelect, moveDate, FETCH_LIMIT, offset)).isEmpty()) {
        findBatch();
        for (StockMove stockMove : stockMoveList) {
            ++offset;
            try {
                List<Move> moveList = cutOffService.generateCutOffMoves(stockMove, moveDate, reverseMoveDate, accountingCutOffTypeSelect, recoveredTax, ati, moveDescription, includeNotStockManagedProduct);
                if (moveList != null && !moveList.isEmpty()) {
                    updateStockMove(stockMove);
                    for (Move move : moveList) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the stock move {}", stockMove.getStockMoveSeq());
                break;
            }
        }
        JPA.clear();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException)

Example 53 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class PaymentVoucherConfirmService method createMoveAndConfirm.

/**
 * Confirm payment voucher and create move.
 *
 * @param paymentVoucher
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createMoveAndConfirm(PaymentVoucher paymentVoucher) throws AxelorException {
    Partner payerPartner = paymentVoucher.getPartner();
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    LocalDate paymentDate = paymentVoucher.getPaymentDate();
    boolean scheduleToBePaid = false;
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    // If paid by a moveline check if all the lines selected have the same account + company
    // Excess payment
    boolean allRight = paymentVoucherControlService.checkIfSameAccount(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine());
    // Check if allright=true (means companies and accounts in lines are all the same and same as in
    // move line selected for paying
    log.debug("allRight : {}", allRight);
    if (allRight) {
        scheduleToBePaid = this.toPayWithExcessPayment(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine(), scheduleToBePaid, paymentDate);
    }
    if (paymentVoucher.getMoveLine() == null || (paymentVoucher.getMoveLine() != null && !allRight) || (scheduleToBePaid && !allRight && paymentVoucher.getMoveLine() != null)) {
        // Manage all the cases in the same way. As if a move line (Excess payment) is selected, we
        // cancel it first
        Move move = moveService.getMoveCreateService().createMoveWithPaymentVoucher(journal, company, paymentVoucher, payerPartner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        move.setPaymentVoucher(paymentVoucher);
        move.setTradingName(paymentVoucher.getTradingName());
        paymentVoucher.setGeneratedMove(move);
        // Create move lines for payment lines
        BigDecimal paidLineTotal = BigDecimal.ZERO;
        int moveLineNo = 1;
        boolean isDebitToPay = paymentVoucherToolService.isDebitToPay(paymentVoucher);
        for (PayVoucherElementToPay payVoucherElementToPay : this.getPayVoucherElementToPayList(paymentVoucher)) {
            MoveLine moveLineToPay = payVoucherElementToPay.getMoveLine();
            log.debug("PV moveLineToPay debit : {}", moveLineToPay.getDebit());
            log.debug("PV moveLineToPay amountPaid : {}", moveLineToPay.getAmountPaid());
            BigDecimal amountToPay = payVoucherElementToPay.getAmountToPayCurrency();
            if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
                paidLineTotal = paidLineTotal.add(amountToPay);
                this.payMoveLine(move, moveLineNo++, payerPartner, moveLineToPay, amountToPay, payVoucherElementToPay, isDebitToPay, paymentDate);
            }
        }
        // Create move line for the payment amount
        MoveLine moveLine = null;
        // in the else case we create a classical balance on the bank account of the payment mode
        if (paymentVoucher.getMoveLine() != null) {
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), paymentVoucher.getMoveLine().getAccount(), paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            Reconcile reconcile = reconcileService.createReconcile(moveLine, paymentVoucher.getMoveLine(), moveLine.getDebit(), !isDebitToPay);
            if (reconcile != null) {
                reconcileService.confirmReconcile(reconcile, true);
            }
        } else {
            moveLine = moveLineService.createMoveLine(move, payerPartner, paymentModeAccount, paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
        }
        move.getMoveLineList().add(moveLine);
        // Then Use Excess payment on old invoices / moveLines
        if (paymentVoucher.getPaidAmount().compareTo(paidLineTotal) > 0) {
            BigDecimal remainingPaidAmount = paymentVoucher.getRemainingAmount();
            // TODO rajouter le process d'imputation automatique
            // if(paymentVoucher.getHasAutoInput())  {
            // 
            // List<MoveLine> debitMoveLines =
            // Lists.newArrayList(pas.getDebitLinesToPay(contractLine,
            // paymentVoucher.getPaymentScheduleToPay()));
            // pas.createExcessPaymentWithAmount(debitMoveLines, remainingPaidAmount,
            // move, moveLineNo,
            // paymentVoucher.getPayerPartner(), company, contractLine, null,
            // paymentDate, updateCustomerAccount);
            // }
            // else  {
            Account partnerAccount = Beans.get(AccountCustomerService.class).getPartnerAccount(payerPartner, company, paymentVoucherToolService.isPurchase(paymentVoucher));
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), partnerAccount, remainingPaidAmount, !isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            move.getMoveLineList().add(moveLine);
            if (isDebitToPay) {
                reconcileService.balanceCredit(moveLine);
            }
        }
        moveService.getMoveValidateService().validate(move);
        paymentVoucher.setGeneratedMove(move);
    }
    paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_CONFIRMED);
    deleteUnPaidLines(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) AccountCustomerService(com.axelor.apps.account.service.AccountCustomerService) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 54 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class PaymentVoucherLoadService method createPayVoucherDueElement.

public PayVoucherDueElement createPayVoucherDueElement(MoveLine moveLine) throws AxelorException {
    Move move = moveLine.getMove();
    PayVoucherDueElement payVoucherDueElement = new PayVoucherDueElement();
    payVoucherDueElement.setMoveLine(moveLine);
    payVoucherDueElement.setDueAmount(moveLine.getCurrencyAmount());
    BigDecimal paidAmountInElementCurrency = currencyService.getAmountCurrencyConvertedAtDate(move.getCompanyCurrency(), move.getCurrency(), moveLine.getAmountPaid(), moveLine.getDate()).setScale(2, RoundingMode.HALF_UP);
    payVoucherDueElement.setPaidAmount(paidAmountInElementCurrency);
    payVoucherDueElement.setAmountRemaining(payVoucherDueElement.getDueAmount().subtract(payVoucherDueElement.getPaidAmount()));
    payVoucherDueElement.setCurrency(move.getCurrency());
    return payVoucherDueElement;
}
Also used : Move(com.axelor.apps.account.db.Move) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) BigDecimal(java.math.BigDecimal)

Example 55 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class MoveController method printMove.

public void printMove(ActionRequest request, ActionResponse response) throws AxelorException {
    Move move = request.getContext().asType(Move.class);
    move = Beans.get(MoveRepository.class).find(move.getId());
    String moveName = move.getReference().toString();
    String fileLink = ReportFactory.createReport(IReport.ACCOUNT_MOVE, moveName + "-${date}").addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("Timezone", move.getCompany() != null ? move.getCompany().getTimezone() : null).addParam("moveId", move.getId()).generate().getFileLink();
    response.setView(ActionView.define(moveName).add("html", fileLink).map());
}
Also used : Move(com.axelor.apps.account.db.Move)

Aggregations

Move (com.axelor.apps.account.db.Move)101 MoveLine (com.axelor.apps.account.db.MoveLine)51 Transactional (com.google.inject.persist.Transactional)37 Company (com.axelor.apps.base.db.Company)36 AxelorException (com.axelor.exception.AxelorException)34 BigDecimal (java.math.BigDecimal)33 Partner (com.axelor.apps.base.db.Partner)31 LocalDate (java.time.LocalDate)28 Journal (com.axelor.apps.account.db.Journal)25 Account (com.axelor.apps.account.db.Account)22 ArrayList (java.util.ArrayList)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)18 Reconcile (com.axelor.apps.account.db.Reconcile)14 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)11 Invoice (com.axelor.apps.account.db.Invoice)11 List (java.util.List)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)5 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)5 MoveService (com.axelor.apps.account.service.move.MoveService)5