use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetailsFromPartner.
/**
* Looks for the bank details in accounting situation.
*
* @param company
* @param paymentMode
* @param partner
* @return The bank details corresponding to the partner and the company with the right payment
* mode null if the partner is null or the accounting situation empty
*/
protected BankDetails getDefaultCompanyBankDetailsFromPartner(Company company, PaymentMode paymentMode, Partner partner) {
if (partner == null) {
return null;
}
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation == null) {
return null;
}
BankDetails candidateBankDetails = null;
if (paymentMode.getInOutSelect() == PaymentModeRepository.IN) {
candidateBankDetails = accountingSituation.getCompanyInBankDetails();
} else if (paymentMode.getInOutSelect() == PaymentModeRepository.OUT) {
candidateBankDetails = accountingSituation.getCompanyOutBankDetails();
}
return candidateBankDetails;
}
use of com.axelor.apps.account.db.AccountingSituation 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.AccountingSituation in project axelor-open-suite by axelor.
the class DebtRecoverySessionService method getDebtRecoveryMethod.
/**
* Fonction permettant de récupérer une méthode de relance en fonction de la categorie du tiers et
* d'une société
*
* @param debtRecovery Une relance
* @return
*/
public DebtRecoveryMethod getDebtRecoveryMethod(DebtRecovery debtRecovery) {
AccountingSituation accountingSituation = debtRecovery.getTradingName() == null ? debtRecovery.getAccountingSituation() : debtRecovery.getTradingNameAccountingSituation();
Company company = accountingSituation.getCompany();
Partner partner = accountingSituation.getPartner();
List<DebtRecoveryConfigLine> debtRecoveryConfigLines = company.getAccountConfig().getDebtRecoveryConfigLineList();
for (DebtRecoveryConfigLine debtRecoveryConfigLine : debtRecoveryConfigLines) {
if (debtRecoveryConfigLine.getPartnerCategory().equals(partner.getPartnerCategory())) {
log.debug("méthode de relance determinée ");
return debtRecoveryConfigLine.getDebtRecoveryMethod();
}
}
log.debug("méthode de relance non determinée ");
return null;
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class InvoiceController method setDefaultMail.
/**
* set default value for automatic invoice printing
*
* @param request
* @param response
* @throws AxelorException
*/
public void setDefaultMail(ActionRequest request, ActionResponse response) {
Invoice invoice = request.getContext().asType(Invoice.class);
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
if (company != null && partner != null) {
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation != null) {
response.setValue("invoiceAutomaticMail", accountingSituation.getInvoiceAutomaticMail());
response.setValue("invoiceMessageTemplate", accountingSituation.getInvoiceMessageTemplate());
response.setValue("invoiceAutomaticMailOnValidate", accountingSituation.getInvoiceAutomaticMailOnValidate());
response.setValue("invoiceMessageTemplateOnValidate", accountingSituation.getInvoiceMessageTemplateOnValidate());
}
}
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class AccountingSituationSupplychainServiceImpl method updateCustomerCreditFromSaleOrder.
@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class }, ignore = { BlockedSaleOrderException.class })
public void updateCustomerCreditFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
if (!appAccountService.getAppAccount().getManageCustomerCredit()) {
return;
}
Partner partner = saleOrder.getClientPartner();
List<AccountingSituation> accountingSituationList = partner.getAccountingSituationList();
for (AccountingSituation accountingSituation : accountingSituationList) {
if (accountingSituation.getCompany().equals(saleOrder.getCompany())) {
// Update UsedCredit
accountingSituation = this.computeUsedCredit(accountingSituation);
if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION) {
BigDecimal inTaxInvoicedAmount = getInTaxInvoicedAmount(saleOrder);
BigDecimal usedCredit = accountingSituation.getUsedCredit().add(saleOrder.getInTaxTotal()).subtract(inTaxInvoicedAmount);
accountingSituation.setUsedCredit(usedCredit);
}
boolean usedCreditExceeded = isUsedCreditExceeded(accountingSituation);
if (usedCreditExceeded) {
saleOrder.setBlockedOnCustCreditExceed(true);
if (!saleOrder.getManualUnblock()) {
String message = accountingSituation.getCompany().getOrderBloquedMessage();
if (Strings.isNullOrEmpty(message)) {
message = String.format(I18n.get(IExceptionMessage.SALE_ORDER_CLIENT_PARTNER_EXCEEDED_CREDIT), partner.getFullName(), saleOrder.getSaleOrderSeq());
}
throw new BlockedSaleOrderException(accountingSituation, message);
}
}
}
}
}
Aggregations