use of com.axelor.apps.base.db.BankDetails 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.base.db.BankDetails in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method getBankDetails.
@Override
public BankDetails getBankDetails(Invoice invoice) throws AxelorException {
BankDetails bankDetails;
if (invoice.getSchedulePaymentOk() && invoice.getPaymentSchedule() != null) {
bankDetails = invoice.getPaymentSchedule().getBankDetails();
if (bankDetails != null) {
return bankDetails;
}
}
bankDetails = invoice.getBankDetails();
if (bankDetails != null) {
return bankDetails;
}
Partner partner = invoice.getPartner();
Preconditions.checkNotNull(partner);
bankDetails = Beans.get(BankDetailsRepository.class).findDefaultByPartner(partner);
if (bankDetails != null) {
return bankDetails;
}
throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.PARTNER_BANK_DETAILS_MISSING), partner.getName());
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class CfonbExportService method createRecipientCFONB.
/**
* Fonction permettant de créer un enregistrement 'destinataire' pour un export de prélèvement
* d'une échéance
*
* @param company Une société
* @param paymentScheduleLine Une échéance
* @return Un enregistrement 'destinataire'
* @throws AxelorException
*/
private String createRecipientCFONB(PaymentScheduleLine paymentScheduleLine, boolean mensu) throws AxelorException {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Partner partner = paymentSchedule.getPartner();
BankDetails bankDetails = Beans.get(PaymentScheduleService.class).getBankDetails(paymentSchedule);
BigDecimal amount = paymentScheduleLine.getDirectDebitAmount();
// Référence
String ref = paymentScheduleLine.getDebitNumber();
// Nom/Raison sociale du débiteur
String partnerName = this.getPayeurPartnerName(partner);
String operationCode = // Code opération
this.cfonbConfig.getDirectDebitOperationCodeExportCFONB();
return this.createRecipientCFONB(amount, ref, partnerName, bankDetails, operationCode);
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class CompanyServiceImpl method countActiveBankDetails.
/**
* Count the number of active bank details on the provided company.
*
* @param company the company on which we count the number of active bank details
* @return the number of active bank details
*/
private int countActiveBankDetails(Company company) {
int count = 0;
List<BankDetails> bankDetailsList = company.getBankDetailsList();
if (bankDetailsList != null) {
for (BankDetails bankDetails : bankDetailsList) {
if (bankDetails.getActive()) {
++count;
}
}
}
return count;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankDetailsServiceImpl method createBankDetails.
/**
* Method allowing to create a bank details
*
* @param accountNbr
* @param bankCode
* @param bbanKey
* @param bank
* @param ownerName
* @param partner
* @param sortCode
* @return
*/
@Override
public BankDetails createBankDetails(String accountNbr, String bankCode, String bbanKey, Bank bank, String ownerName, Partner partner, String sortCode) {
BankDetails bankDetails = new BankDetails();
bankDetails.setAccountNbr(accountNbr);
bankDetails.setBankCode(bankCode);
bankDetails.setBbanKey(bbanKey);
bankDetails.setBank(bank);
bankDetails.setOwnerName(ownerName);
bankDetails.setPartner(partner);
bankDetails.setSortCode(sortCode);
return bankDetails;
}
Aggregations