use of com.axelor.apps.account.db.Invoice 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.Invoice in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method mergeInvoice.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice mergeInvoice(List<Invoice> invoiceList, Company company, Currency currency, Partner partner, Partner contactPartner, PriceList priceList, PaymentMode paymentMode, PaymentCondition paymentCondition) throws AxelorException {
String numSeq = "";
String externalRef = "";
for (Invoice invoiceLocal : invoiceList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
if (invoiceLocal.getInternalReference() != null) {
numSeq += invoiceLocal.getInternalReference();
}
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (invoiceLocal.getExternalReference() != null) {
externalRef += invoiceLocal.getExternalReference();
}
}
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, paymentCondition, paymentMode, partnerService.getInvoicingAddress(partner), partner, contactPartner, currency, priceList, numSeq, externalRef, null, company.getDefaultBankDetails(), null, null) {
@Override
public Invoice generate() throws AxelorException {
return super.createInvoiceHeader();
}
};
Invoice invoiceMerged = invoiceGenerator.generate();
List<InvoiceLine> invoiceLines = this.getInvoiceLinesFromInvoiceList(invoiceList);
invoiceGenerator.populate(invoiceMerged, invoiceLines);
this.setInvoiceForInvoiceLines(invoiceLines, invoiceMerged);
invoiceRepo.save(invoiceMerged);
return invoiceMerged;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method createRefund.
/**
* Créer un avoir.
*
* <p>Un avoir est une facture "inversée". Tout le montant sont opposés à la facture originale.
*
* @param invoice
* @return
* @throws AxelorException
*/
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createRefund(Invoice invoice) throws AxelorException {
Invoice refund = new RefundInvoice(invoice).generate();
invoice.addRefundInvoiceListItem(refund);
invoiceRepo.save(invoice);
return refund;
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class DoubtfulCustomerService method createDoubtFulCustomerMove.
/**
* Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
* de facture
*
* @param move Une écritures de facture
* @param doubtfulCustomerAccount Un compte client douteux
* @param debtPassReason Un motif de passage en client douteux
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createDoubtFulCustomerMove(Move move, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
log.debug("Concerned account move : {} ", move.getReference());
Company company = move.getCompany();
Partner partner = move.getPartner();
Invoice invoice = move.getInvoice();
Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, invoice.getCurrency(), partner, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, move.getFunctionalOriginSelect());
newMove.setInvoice(invoice);
LocalDate todayDate = appBaseService.getTodayDate(company);
MoveLine invoicePartnerMoveLine = null;
for (MoveLine moveLine : move.getMoveLineList()) {
if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getAccount() != doubtfulCustomerAccount && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
invoicePartnerMoveLine = moveLine;
}
}
String origin = "";
BigDecimal amountRemaining = BigDecimal.ZERO;
MoveLine creditMoveLine = null;
if (invoicePartnerMoveLine != null) {
amountRemaining = invoicePartnerMoveLine.getAmountRemaining();
// Debit move line on partner account
creditMoveLine = moveLineService.createMoveLine(newMove, partner, invoicePartnerMoveLine.getAccount(), amountRemaining, false, todayDate, 1, move.getInvoice().getInvoiceId(), debtPassReason);
newMove.getMoveLineList().add(creditMoveLine);
origin = creditMoveLine.getOrigin();
}
// Credit move line on partner account
MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, partner, doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, origin, debtPassReason);
newMove.getMoveLineList().add(debitMoveLine);
debitMoveLine.setPassageReason(debtPassReason);
moveService.getMoveValidateService().validate(newMove);
moveRepo.save(newMove);
if (creditMoveLine != null) {
Reconcile reconcile = reconcileService.createReconcile(invoicePartnerMoveLine, creditMoveLine, amountRemaining, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
this.invoiceProcess(newMove, doubtfulCustomerAccount, debtPassReason);
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class DoubtfulCustomerService method invoiceRejectProcess.
/**
* Procédure permettant de mettre à jour les champs d'une facture rejetée avec la nouvelle
* écriture de débit sur le compte 416
*
* @param moveLine La nouvelle ligne d'écriture de débit sur le compte 416
* @param doubtfulCustomerAccount Un compte client douteux
* @param debtPassReason Un motif de passage en client douteux
*/
public Invoice invoiceRejectProcess(MoveLine moveLine, Account doubtfulCustomerAccount, String debtPassReason) {
Invoice invoice = moveLine.getInvoiceReject();
invoice.setRejectMoveLine(moveLine);
invoice.setDoubtfulCustomerOk(true);
return invoice;
}
Aggregations