use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class PaymentScheduleLineServiceImpl method createPaymentMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
Preconditions.checkNotNull(paymentScheduleLine);
Preconditions.checkNotNull(companyBankDetails);
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String name = paymentScheduleLine.getName();
LocalDate todayDate = appBaseService.getTodayDate(company);
Account account = accountingSituationService.getCustomerAccount(partner, company);
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
move.addMoveLineListItem(creditMoveLine);
creditMoveLine = moveLineRepo.save(creditMoveLine);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
move.addMoveLineListItem(debitMoveLine);
debitMoveLine = moveLineRepo.save(debitMoveLine);
moveService.getMoveValidateService().validate(move);
// Reconcile
if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
if (moveToolService.isSameAccount(debitMoveLineList, account)) {
List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
}
}
paymentScheduleLine.setDirectDebitAmount(amount);
paymentScheduleLine.setInTaxAmountPaid(amount);
paymentScheduleLine.setAdvanceOrPaymentMove(move);
paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
return move;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class SaleOrderController method fillCompanyBankDetails.
/**
* Called on partner, company or payment change. Fill the bank details with a default value.
*
* @param request
* @param response
* @throws AxelorException
*/
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
Company company = saleOrder.getCompany();
Partner partner = saleOrder.getClientPartner();
if (company == null) {
return;
}
if (partner != null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
}
BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
response.setValue("companyBankDetails", defaultBankDetails);
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class InvoiceGenerator method createInvoiceHeader.
protected Invoice createInvoiceHeader() throws AxelorException {
Invoice invoice = new Invoice();
invoice.setCompany(company);
invoice.setOperationTypeSelect(operationType);
if (partner == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
if (Beans.get(BlockingService.class).getBlocking(partner, company, BlockingRepository.INVOICING_BLOCKING) != null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_VALIDATE_BLOCKING));
}
invoice.setPartner(partner);
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation != null) {
invoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
invoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
invoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
}
if (paymentCondition == null) {
paymentCondition = InvoiceToolService.getPaymentCondition(invoice);
}
invoice.setPaymentCondition(paymentCondition);
if (paymentMode == null) {
paymentMode = InvoiceToolService.getPaymentMode(invoice);
}
invoice.setPaymentMode(paymentMode);
if (mainInvoicingAddress == null) {
mainInvoicingAddress = Beans.get(PartnerService.class).getInvoicingAddress(partner);
}
invoice.setAddress(mainInvoicingAddress);
invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
invoice.setContactPartner(contactPartner);
if (currency == null) {
currency = partner.getCurrency();
}
if (currency == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_6), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
invoice.setCurrency(currency);
invoice.setStatusSelect(InvoiceRepository.STATUS_DRAFT);
invoice.setPriceList(priceList);
invoice.setInternalReference(internalReference);
invoice.setExternalReference(externalReference);
invoice.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, company));
invoice.setTradingName(tradingName);
if (groupProductsOnPrintings == null) {
groupProductsOnPrintings = partner.getGroupProductsOnPrintings();
}
invoice.setGroupProductsOnPrintings(groupProductsOnPrintings);
// Set ATI mode on invoice
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
int atiChoice = accountConfig.getInvoiceInAtiSelect();
if (inAti == null) {
invoice.setInAti(accountConfigService.getInvoiceInAti(accountConfig));
} else if (atiChoice == AccountConfigRepository.INVOICE_ATI_DEFAULT || atiChoice == AccountConfigRepository.INVOICE_WT_DEFAULT) {
invoice.setInAti(inAti);
} else if (atiChoice == AccountConfigRepository.INVOICE_ATI_ALWAYS) {
invoice.setInAti(true);
} else {
invoice.setInAti(false);
}
if (partner.getFactorizedCustomer() && accountConfig.getFactorPartner() != null) {
List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
companyBankDetails = bankDetailsList.stream().filter(bankDetails -> bankDetails.getIsDefault()).findFirst().orElse(null);
} else if (accountingSituation != null) {
if (paymentMode != null) {
if (paymentMode.equals(partner.getOutPaymentMode())) {
companyBankDetails = accountingSituation.getCompanyOutBankDetails();
} else if (paymentMode.equals(partner.getInPaymentMode())) {
companyBankDetails = accountingSituation.getCompanyInBankDetails();
}
}
}
if (companyBankDetails == null) {
companyBankDetails = company.getDefaultBankDetails();
List<BankDetails> allowedBDs = Beans.get(PaymentModeService.class).getCompatibleBankDetailsList(paymentMode, company);
if (!allowedBDs.contains(companyBankDetails)) {
companyBankDetails = null;
}
}
invoice.setCompanyBankDetails(companyBankDetails);
if (partner.getBankDetailsList() != null && invoice.getBankDetails() == null) {
invoice.setBankDetails(partner.getBankDetailsList().stream().filter(b -> b.getActive() && b.getIsDefault()).findFirst().orElse(null));
}
if (partner != null && !Strings.isNullOrEmpty(partner.getInvoiceComments())) {
invoice.setNote(partner.getInvoiceComments());
}
invoice.setInvoicesCopySelect(getInvoiceCopy());
initCollections(invoice);
return invoice;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method checkPartnerBankDetailsList.
@Override
public Boolean checkPartnerBankDetailsList(Invoice invoice) {
PaymentMode paymentMode = invoice.getPaymentMode();
Partner partner = invoice.getPartner();
if (partner == null || paymentMode == null) {
return true;
}
int paymentModeInOutSelect = paymentMode.getInOutSelect();
int paymentModeTypeSelect = paymentMode.getTypeSelect();
if ((paymentModeInOutSelect == PaymentModeRepository.IN && (paymentModeTypeSelect == PaymentModeRepository.TYPE_IPO || paymentModeTypeSelect == PaymentModeRepository.TYPE_IPO_CHEQUE || paymentModeTypeSelect == PaymentModeRepository.TYPE_DD)) || (paymentModeInOutSelect == PaymentModeRepository.OUT && paymentModeTypeSelect == PaymentModeRepository.TYPE_TRANSFER)) {
return partner.getBankDetailsList().stream().anyMatch(bankDetails -> bankDetails.getActive());
}
return true;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class InvoiceController method fillPaymentModeAndCondition.
/**
* Function returning both the paymentMode and the paymentCondition
*
* @param request
* @param response
*/
public void fillPaymentModeAndCondition(ActionRequest request, ActionResponse response) {
Invoice invoice = request.getContext().asType(Invoice.class);
try {
if (invoice.getOperationTypeSelect() == null) {
return;
}
PaymentMode paymentMode = InvoiceToolService.getPaymentMode(invoice);
PaymentCondition paymentCondition = InvoiceToolService.getPaymentCondition(invoice);
response.setValue("paymentMode", paymentMode);
response.setValue("paymentCondition", paymentCondition);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations