Search in sources :

Example 36 with Account

use of com.axelor.apps.account.db.Account 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;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) 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 37 with Account

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

the class AccountController method checkIfCodeAccountAlreadyExistForCompany.

public void checkIfCodeAccountAlreadyExistForCompany(ActionRequest request, ActionResponse response) {
    try {
        Account account = request.getContext().asType(Account.class);
        Long accountId = account.getId();
        if (accountId == null) {
            accountId = 0L;
        }
        List<Account> sameAccountList = Beans.get(AccountRepository.class).all().filter("self.company = ?1 AND self.code = ?2 AND self.id != ?3", account.getCompany(), account.getCode(), accountId).fetch();
        if (!ObjectUtils.isEmpty(sameAccountList)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNT_CODE_ALREADY_IN_USE_FOR_COMPANY), account.getCode(), account.getCompany().getName());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) AxelorException(com.axelor.exception.AxelorException)

Example 38 with Account

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

the class ExpenseServiceImpl method createMoveForExpensePayment.

public Move createMoveForExpensePayment(Expense expense) throws AxelorException {
    Company company = expense.getCompany();
    PaymentMode paymentMode = expense.getPaymentMode();
    Partner partner = expense.getUser().getPartner();
    LocalDate paymentDate = expense.getPaymentDate();
    BigDecimal paymentAmount = expense.getInTaxTotal();
    BankDetails companyBankDetails = company.getDefaultBankDetails();
    Account employeeAccount;
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    MoveLine expenseMoveLine = this.getExpenseEmployeeMoveLineByLoop(expense);
    if (expenseMoveLine == null) {
        return null;
    }
    employeeAccount = expenseMoveLine.getAccount();
    Move move = moveService.getMoveCreateService().createMove(journal, company, expense.getMove().getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, false, paymentDate, null, 1, expense.getExpenseSeq(), null));
    MoveLine employeeMoveLine = moveLineService.createMoveLine(move, partner, employeeAccount, paymentAmount, true, paymentDate, null, 2, expense.getExpenseSeq(), null);
    employeeMoveLine.setTaxAmount(expense.getTaxTotal());
    move.addMoveLineListItem(employeeMoveLine);
    moveService.getMoveValidateService().validate(move);
    expense.setPaymentMove(move);
    Beans.get(ReconcileService.class).reconcile(expenseMoveLine, employeeMoveLine, true, false);
    expenseRepository.save(expense);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) ReconcileService(com.axelor.apps.account.service.ReconcileService) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 39 with Account

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

the class AccountingCutOffServiceImpl method generateCutOffMove.

public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
    if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
        return null;
    }
    Company company = stockMove.getCompany();
    AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
    Partner partner = stockMove.getPartner();
    Account partnerAccount = null;
    Currency currency = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
        currency = saleOrder.getCurrency();
        if (partner == null) {
            partner = saleOrder.getClientPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
    }
    if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        currency = purchaseOrder.getCurrency();
        if (partner == null) {
            partner = purchaseOrder.getSupplierPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
    }
    String origin = stockMove.getStockMoveSeq();
    Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
    counter = 0;
    this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
    this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
        move.setStockMove(stockMove);
        moveValidateService.validate(move);
    } else {
        moveRepository.remove(move);
        return null;
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 40 with Account

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

the class AccountingCutOffServiceImpl method generateTaxMoveLine.

protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
    TaxLine taxLine = productMoveLine.getTaxLine();
    Tax tax = taxLine.getTax();
    Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
    BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
    MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
    taxMoveLine.setDate(move.getDate());
    taxMoveLine.setDueDate(move.getDate());
    move.addMoveLineListItem(taxMoveLine);
}
Also used : Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Tax(com.axelor.apps.account.db.Tax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Aggregations

Account (com.axelor.apps.account.db.Account)59 MoveLine (com.axelor.apps.account.db.MoveLine)27 Company (com.axelor.apps.base.db.Company)26 BigDecimal (java.math.BigDecimal)26 Partner (com.axelor.apps.base.db.Partner)25 Move (com.axelor.apps.account.db.Move)21 AxelorException (com.axelor.exception.AxelorException)20 Journal (com.axelor.apps.account.db.Journal)18 Transactional (com.google.inject.persist.Transactional)18 AccountConfig (com.axelor.apps.account.db.AccountConfig)14 LocalDate (java.time.LocalDate)12 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)10 ArrayList (java.util.ArrayList)10 TaxLine (com.axelor.apps.account.db.TaxLine)8 Invoice (com.axelor.apps.account.db.Invoice)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 Product (com.axelor.apps.base.db.Product)5