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);
}
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()));
}
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;
}
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()));
}
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;
}
Aggregations