use of com.axelor.exception.AxelorException 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.exception.AxelorException in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableInvoiceLineMove.
@Transactional(rollbackOn = { Exception.class })
public void createIrrecoverableInvoiceLineMove(Irrecoverable irrecoverable, Invoice invoice) throws AxelorException {
BigDecimal prorataRate = this.getProrataRate(invoice, invoice.getRejectMoveLine() != null);
// Ajout de l'écriture générée
Move move = this.createIrrecoverableMove(invoice, prorataRate, invoice.getRejectMoveLine() != null, irrecoverable.getName());
if (move == null) {
throw new AxelorException(irrecoverable, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
moveService.getMoveValidateService().validate(move);
irrecoverable.getMoveSet().add(move);
invoice.setIrrecoverableStatusSelect(InvoiceRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
if (invoice.getCanceledPaymentSchedule() != null && this.isAllInvoicePassedInIrrecoverable(invoice.getCanceledPaymentSchedule())) {
invoice.getCanceledPaymentSchedule().setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class IrrecoverableService method passInIrrecoverable.
/**
* Procédure permettant de passer une facture en irrécouvrable
*
* @param invoice Une facture
* @param generateEvent Un évènement à t'il déjà été créé par un autre objet ?
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(Invoice invoice, boolean generateEvent) throws AxelorException {
invoice.setIrrecoverableStatusSelect(InvoiceRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
if (generateEvent) {
Company company = invoice.getCompany();
ManagementObject managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
invoice.setManagementObject(managementObject);
MoveLine moveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
if (moveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
}
this.passInIrrecoverable(moveLine, managementObject, false);
}
invoiceRepo.save(invoice);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class IrrecoverableService method passInIrrecoverable.
/**
* Procédure permettant de
*
* @param irrecoverable
* @throws AxelorException
*/
public int passInIrrecoverable(Irrecoverable irrecoverable) throws AxelorException {
irrecoverable.setMoveSet(new HashSet<Move>());
EntityTransaction transaction = JPA.em().getTransaction();
int anomaly = 0;
this.testCompanyField(irrecoverable.getCompany());
int i = 0;
if (irrecoverable.getInvoiceSet() != null && irrecoverable.getInvoiceSet().size() != 0) {
for (Invoice invoice : irrecoverable.getInvoiceSet()) {
i++;
if (!transaction.isActive()) {
transaction.begin();
}
try {
log.debug("Facture : {}", invoice.getInvoiceId());
this.createIrrecoverableInvoiceLineMove(irrecoverable, invoice);
irrecoverableRepo.save(irrecoverable);
if (i % 50 == 0) {
JPA.flush();
JPA.clear();
}
} catch (AxelorException e) {
anomaly++;
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Invoice") + " %s", invoice.getInvoiceId()), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
log.error("Bug(Anomalie) généré(e) pour la facture : {}", invoice.getInvoiceId());
} catch (Exception e) {
anomaly++;
TraceBackService.trace(new Exception(String.format(I18n.get("Invoice") + " %s", invoice.getInvoiceId()), e), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
log.error("Bug(Anomalie) généré(e) pour la facture : {}", invoice.getInvoiceId());
} finally {
if (!transaction.isActive()) {
transaction.begin();
}
}
}
}
if (irrecoverable.getPaymentScheduleLineSet() != null && irrecoverable.getPaymentScheduleLineSet().size() != 0) {
for (PaymentScheduleLine paymentScheduleLine : irrecoverable.getPaymentScheduleLineSet()) {
i++;
if (!transaction.isActive()) {
transaction.begin();
}
try {
log.debug("Ligne d'échéancier : {}", paymentScheduleLine.getName());
this.createMoveForPaymentScheduleLineReject(irrecoverable, paymentScheduleLine);
irrecoverableRepo.save(irrecoverable);
if (i % 50 == 0) {
JPA.flush();
JPA.clear();
}
} catch (AxelorException e) {
anomaly++;
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.IRRECOVERABLE_1), paymentScheduleLine.getName()), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
log.error("Bug(Anomalie) généré(e) pour la ligne d'échéancier : {}", paymentScheduleLine.getName());
} catch (Exception e) {
anomaly++;
TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.IRRECOVERABLE_1), paymentScheduleLine.getName()), e), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
log.error("Bug(Anomalie) généré(e) pour la ligne d'échéancier : {}", paymentScheduleLine.getName());
} finally {
if (!transaction.isActive()) {
transaction.begin();
}
}
}
}
if (!transaction.isActive()) {
transaction.begin();
}
irrecoverable.setStatusSelect(IrrecoverableRepository.STATUS_VALIDATED);
irrecoverableRepo.save(irrecoverable);
transaction.commit();
return anomaly;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class SubrogationReleaseServiceImpl method transmitRelease.
@Override
@Transactional(rollbackOn = { Exception.class })
public void transmitRelease(SubrogationRelease subrogationRelease) throws AxelorException {
SequenceService sequenceService = Beans.get(SequenceService.class);
String sequenceNumber = sequenceService.getSequenceNumber("subrogationRelease", subrogationRelease.getCompany());
if (Strings.isNullOrEmpty(sequenceNumber)) {
throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.SUBROGATION_RELEASE_MISSING_SEQUENCE), subrogationRelease.getCompany().getName());
}
this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
subrogationRelease.setSequenceNumber(sequenceNumber);
subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_TRANSMITTED);
subrogationRelease.setTransmissionDate(appBaseService.getTodayDate(subrogationRelease.getCompany()));
}
Aggregations