Search in sources :

Example 11 with PaymentMode

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

the class ExpenseServiceImpl method validate.

@Override
@Transactional(rollbackOn = { Exception.class })
public void validate(Expense expense) throws AxelorException {
    Employee employee = expense.getUser().getEmployee();
    if (employee == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getFullName());
    }
    if (expense.getPeriod() == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EXPENSE_MISSING_PERIOD));
    }
    List<ExpenseLine> kilometricExpenseLineList = expense.getKilometricExpenseLineList();
    KilometricService kilometricService = Beans.get(KilometricService.class);
    if (ObjectUtils.notEmpty(kilometricExpenseLineList)) {
        for (ExpenseLine line : kilometricExpenseLineList) {
            BigDecimal amount = kilometricService.computeKilometricExpense(line, employee);
            line.setTotalAmount(amount);
            line.setUntaxedAmount(amount);
            kilometricService.updateKilometricLog(line, employee);
        }
        compute(expense);
    }
    Beans.get(EmployeeAdvanceService.class).fillExpenseWithAdvances(expense);
    expense.setStatusSelect(ExpenseRepository.STATUS_VALIDATED);
    expense.setValidatedBy(AuthUtils.getUser());
    expense.setValidationDate(appAccountService.getTodayDate(expense.getCompany()));
    if (expense.getUser().getPartner() != null) {
        PaymentMode paymentMode = expense.getUser().getPartner().getOutPaymentMode();
        expense.setPaymentMode(paymentMode);
    }
    expenseRepository.save(expense);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) EmployeeAdvanceService(com.axelor.apps.hr.service.EmployeeAdvanceService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 12 with PaymentMode

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

the class ExpenseServiceImpl method addPayment.

@Override
@Transactional(rollbackOn = { Exception.class })
public void addPayment(Expense expense, BankDetails bankDetails) throws AxelorException {
    expense.setPaymentDate(appAccountService.getTodayDate(expense.getCompany()));
    PaymentMode paymentMode = expense.getPaymentMode();
    if (paymentMode == null) {
        paymentMode = expense.getUser().getPartner().getOutPaymentMode();
        if (paymentMode == null) {
            throw new AxelorException(expense, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EXPENSE_MISSING_PAYMENT_MODE));
        }
        expense.setPaymentMode(paymentMode);
    }
    if (paymentMode.getGenerateBankOrder()) {
        BankOrder bankOrder = Beans.get(BankOrderCreateServiceHr.class).createBankOrder(expense, bankDetails);
        expense.setBankOrder(bankOrder);
        Beans.get(BankOrderRepository.class).save(bankOrder);
        expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_PENDING);
    } else {
        if (accountConfigService.getAccountConfig(expense.getCompany()).getGenerateMoveForInvoicePayment()) {
            this.createMoveForExpensePayment(expense);
        }
        if (paymentMode.getAutomaticTransmission()) {
            expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_PENDING);
        } else {
            expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
            expense.setStatusSelect(ExpenseRepository.STATUS_REIMBURSED);
        }
    }
    expense.setPaymentAmount(expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount()));
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankOrderCreateServiceHr(com.axelor.apps.hr.service.bankorder.BankOrderCreateServiceHr) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) BankOrderRepository(com.axelor.apps.bankpayment.db.repo.BankOrderRepository) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 13 with PaymentMode

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

the class IntercoServiceImpl method generateIntercoPurchaseFromSale.

@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder generateIntercoPurchaseFromSale(SaleOrder saleOrder) throws AxelorException {
    PurchaseOrderService purchaseOrderService = Beans.get(PurchaseOrderService.class);
    Company intercoCompany = findIntercoCompany(saleOrder.getClientPartner());
    // create purchase order
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setCompany(intercoCompany);
    purchaseOrder.setContactPartner(saleOrder.getContactPartner());
    purchaseOrder.setCurrency(saleOrder.getCurrency());
    purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
    purchaseOrder.setOrderDate(saleOrder.getCreationDate());
    purchaseOrder.setPriceList(saleOrder.getPriceList());
    purchaseOrder.setTradingName(saleOrder.getTradingName());
    purchaseOrder.setPurchaseOrderLineList(new ArrayList<>());
    purchaseOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, intercoCompany));
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
    purchaseOrder.setSupplierPartner(saleOrder.getCompany().getPartner());
    purchaseOrder.setTradingName(saleOrder.getTradingName());
    // in ati
    purchaseOrder.setInAti(saleOrder.getInAti());
    // copy payments
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(saleOrder.getPaymentMode());
    purchaseOrder.setPaymentMode(intercoPaymentMode);
    purchaseOrder.setPaymentCondition(saleOrder.getPaymentCondition());
    // copy delivery info
    purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
    purchaseOrder.setStockLocation(Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(intercoCompany));
    purchaseOrder.setShipmentMode(saleOrder.getShipmentMode());
    purchaseOrder.setFreightCarrierMode(saleOrder.getFreightCarrierMode());
    // copy timetable info
    purchaseOrder.setExpectedRealisationDate(saleOrder.getExpectedRealisationDate());
    purchaseOrder.setAmountToBeSpreadOverTheTimetable(saleOrder.getAmountToBeSpreadOverTheTimetable());
    // create lines
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList != null) {
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            this.createIntercoPurchaseLineFromSaleLine(saleOrderLine, purchaseOrder);
        }
    }
    purchaseOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
    // compute the purchase order
    purchaseOrderService.computePurchaseOrder(purchaseOrder);
    purchaseOrder.setCreatedByInterco(true);
    Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseOrderCreateRequested()) {
        Beans.get(PurchaseOrderService.class).requestPurchaseOrder(purchaseOrder);
    }
    saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
    purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
    return purchaseOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 14 with PaymentMode

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

the class PaymentVoucherSequenceService method getReference.

public String getReference(PaymentVoucher paymentVoucher) throws AxelorException {
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    return sequenceService.getSequenceNumber(paymentModeService.getPaymentModeSequence(paymentMode, company, paymentVoucher.getCompanyBankDetails()));
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 15 with PaymentMode

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

the class InvoicePaymentCreateServiceImpl method createInvoicePayment.

/**
 * @param invoice
 * @param amount
 * @param paymentDate
 * @param paymentMove
 * @return
 */
public InvoicePayment createInvoicePayment(Invoice invoice, BigDecimal amount, Move paymentMove) throws AxelorException {
    LocalDate paymentDate = paymentMove.getDate();
    BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(paymentMove.getCompanyCurrency(), paymentMove.getCurrency(), amount, paymentDate);
    int typePaymentMove = this.determineType(paymentMove);
    Currency currency = paymentMove.getCurrency();
    if (currency == null) {
        currency = paymentMove.getCompanyCurrency();
    }
    PaymentMode paymentMode;
    InvoicePayment invoicePayment;
    if (typePaymentMove == InvoicePaymentRepository.TYPE_REFUND_INVOICE || typePaymentMove == InvoicePaymentRepository.TYPE_INVOICE) {
        paymentMode = null;
    } else {
        paymentMode = paymentMove.getPaymentMode();
    }
    invoicePayment = this.createInvoicePayment(invoice, amountConverted, paymentDate, currency, paymentMode, typePaymentMove);
    invoicePayment.setMove(paymentMove);
    invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
    PaymentVoucher paymentVoucher = paymentMove.getPaymentVoucher();
    if (paymentVoucher != null) {
        invoicePayment.setCompanyBankDetails(paymentVoucher.getCompanyBankDetails());
    } else if (invoice.getSchedulePaymentOk() && invoice.getPaymentSchedule() != null) {
        BankDetails companyBankDetails = invoice.getPaymentSchedule().getCompanyBankDetails();
        invoicePayment.setCompanyBankDetails(companyBankDetails);
    }
    computeAdvancePaymentImputation(invoicePayment, paymentMove);
    invoice.addInvoicePaymentListItem(invoicePayment);
    invoicePaymentToolService.updateAmountPaid(invoice);
    invoicePaymentRepository.save(invoicePayment);
    return invoicePayment;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) BankDetails(com.axelor.apps.base.db.BankDetails) Currency(com.axelor.apps.base.db.Currency) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

PaymentMode (com.axelor.apps.account.db.PaymentMode)45 Company (com.axelor.apps.base.db.Company)27 Partner (com.axelor.apps.base.db.Partner)26 BankDetails (com.axelor.apps.base.db.BankDetails)21 Invoice (com.axelor.apps.account.db.Invoice)18 AxelorException (com.axelor.exception.AxelorException)17 Transactional (com.google.inject.persist.Transactional)13 BigDecimal (java.math.BigDecimal)11 LocalDate (java.time.LocalDate)10 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)9 Currency (com.axelor.apps.base.db.Currency)9 ArrayList (java.util.ArrayList)8 Journal (com.axelor.apps.account.db.Journal)7 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 Map (java.util.Map)7 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)6 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)6 Account (com.axelor.apps.account.db.Account)5 Move (com.axelor.apps.account.db.Move)5 PriceList (com.axelor.apps.base.db.PriceList)5