use of com.axelor.apps.account.db.AccountConfig 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.AccountConfig in project axelor-open-suite by axelor.
the class DoubtfulCustomerService method testCompanyField.
/**
* Procédure permettant de vérifier le remplissage des champs dans la société, nécessaire au
* traitement du passage en client douteux
*
* @param company Une société
* @throws AxelorException
*/
public void testCompanyField(Company company) throws AxelorException {
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
accountConfigService.getDoubtfulCustomerAccount(accountConfig);
accountConfigService.getAutoMiscOpeJournal(accountConfig);
accountConfigService.getSixMonthDebtPassReason(accountConfig);
accountConfigService.getThreeMonthDebtPassReason(accountConfig);
}
use of com.axelor.apps.account.db.AccountConfig in project axelor-open-suite by axelor.
the class BatchDoubtfulCustomer method process.
@SuppressWarnings("unchecked")
@Override
protected void process() {
if (!end) {
Company company = batch.getAccountingBatch().getCompany();
AccountConfig accountConfig = company.getAccountConfig();
Account doubtfulCustomerAccount = accountConfig.getDoubtfulCustomerAccount();
String sixMonthDebtPassReason = accountConfig.getSixMonthDebtPassReason();
String threeMonthDebtPassReason = accountConfig.getThreeMonthDebtPassReason();
// FACTURES
List<Move> moveList = doubtfulCustomerService.getMove(0, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 6 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveList = doubtfulCustomerService.getMove(1, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 3 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, threeMonthDebtPassReason);
// FACTURES REJETES
List<MoveLine> moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(0, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 6 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(1, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 3 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, threeMonthDebtPassReason);
updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(companyRepo.find(company.getId()));
}
}
use of com.axelor.apps.account.db.AccountConfig in project axelor-open-suite by axelor.
the class DebtRecoveryService method testCompanyField.
public void testCompanyField(Company company) throws AxelorException {
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
accountConfigService.getDebtRecoveryConfigLineList(accountConfig);
}
use of com.axelor.apps.account.db.AccountConfig in project axelor-open-suite by axelor.
the class FixedAssetServiceImpl method createFixedAssets.
@Override
@Transactional(rollbackOn = { Exception.class })
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
List<FixedAsset> fixedAssetList = new ArrayList<>();
if (invoice == null || CollectionUtils.isEmpty(invoice.getInvoiceLineList())) {
return fixedAssetList;
}
AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany());
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
if (accountConfig.getFixedAssetCatReqOnInvoice() && invoiceLine.getFixedAssets() && invoiceLine.getFixedAssetCategory() == null) {
throw new AxelorException(invoiceLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_LINE_ERROR_FIXED_ASSET_CATEGORY), invoiceLine.getProductName());
}
if (!invoiceLine.getFixedAssets() || invoiceLine.getFixedAssetCategory() == null) {
continue;
}
FixedAsset fixedAsset = new FixedAsset();
fixedAsset.setFixedAssetCategory(invoiceLine.getFixedAssetCategory());
if (fixedAsset.getFixedAssetCategory().getIsValidateFixedAsset()) {
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_VALIDATED);
} else {
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DRAFT);
}
fixedAsset.setAcquisitionDate(invoice.getInvoiceDate());
fixedAsset.setFirstDepreciationDate(invoice.getInvoiceDate());
fixedAsset.setReference(invoice.getInvoiceId());
fixedAsset.setName(invoiceLine.getProductName() + " (" + invoiceLine.getQty() + ")");
fixedAsset.setCompany(fixedAsset.getFixedAssetCategory().getCompany());
fixedAsset.setJournal(fixedAsset.getFixedAssetCategory().getJournal());
fixedAsset.setComputationMethodSelect(fixedAsset.getFixedAssetCategory().getComputationMethodSelect());
fixedAsset.setDegressiveCoef(fixedAsset.getFixedAssetCategory().getDegressiveCoef());
fixedAsset.setNumberOfDepreciation(fixedAsset.getFixedAssetCategory().getNumberOfDepreciation());
fixedAsset.setPeriodicityInMonth(fixedAsset.getFixedAssetCategory().getPeriodicityInMonth());
fixedAsset.setDurationInMonth(fixedAsset.getFixedAssetCategory().getDurationInMonth());
fixedAsset.setGrossValue(invoiceLine.getCompanyExTaxTotal());
fixedAsset.setPartner(invoice.getPartner());
fixedAsset.setPurchaseAccount(invoiceLine.getAccount());
fixedAsset.setInvoiceLine(invoiceLine);
this.generateAndComputeLines(fixedAsset);
fixedAssetList.add(fixedAssetRepo.save(fixedAsset));
}
return fixedAssetList;
}
Aggregations