use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class PaymentScheduleServiceImpl method cancelPaymentSchedule.
/**
* Methode qui annule un échéancier
*
* @param paymentSchedule
*/
@Override
public void cancelPaymentSchedule(PaymentSchedule paymentSchedule) {
// L'échéancier est passé à annulé
paymentSchedule.setStatusSelect(PaymentScheduleRepository.STATUS_CANCELED);
for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
// Si l'échéance n'est pas complètement payée
if (paymentScheduleLine.getInTaxAmountPaid().compareTo(paymentScheduleLine.getInTaxAmount()) != 0) {
// L'échéance est passée à cloturé
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_CLOSED);
}
}
for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
// L'échéancier n'est plus selectionné sur la facture
invoice.setPaymentSchedule(null);
// L'échéancier est assigné dans un nouveau champs afin de garder un lien invisble pour
// l'utilisateur, mais utilisé pour le passage en irrécouvrable
invoice.setCanceledPaymentSchedule(paymentSchedule);
invoice.setSchedulePaymentOk(false);
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class IrrecoverableService method passInIrrecoverable.
/**
* Procédure permettant de passer un échéancier de lissage de paiement en irrécouvrable La
* procédure passera aussi les lignes d'écriture de rejet d'échéance en irrécouvrable, ainsi que
* les factures pas complètement payée selectionnées sur l'échéancier
*
* @param paymentSchedule Un échéancier de paiement
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(PaymentSchedule paymentSchedule) throws AxelorException {
Company company = paymentSchedule.getCompany();
paymentSchedule.setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
ManagementObject managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
paymentSchedule.setManagementObject(managementObject);
List<MoveLine> paymentScheduleLineRejectMoveLineList = new ArrayList<MoveLine>();
for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
if (paymentScheduleLine.getRejectMoveLine() != null && paymentScheduleLine.getRejectMoveLine().getAmountRemaining().compareTo(BigDecimal.ZERO) > 0) {
paymentScheduleLineRejectMoveLineList.add(paymentScheduleLine.getRejectMoveLine());
}
}
for (MoveLine moveLine : paymentScheduleLineRejectMoveLineList) {
this.passInIrrecoverable(moveLine, managementObject, true);
}
for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
if (invoice.getCompanyInTaxTotalRemaining().compareTo(BigDecimal.ZERO) > 0) {
this.passInIrrecoverable(invoice, managementObject);
}
}
paymentScheduleService.cancelPaymentSchedule(paymentSchedule);
paymentScheduleRepo.save(paymentSchedule);
}
use of com.axelor.apps.account.db.Invoice 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.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableReport.
/**
* Procédure permettant de passer en irrécouvrables les factures et échéances rejetées récupéré
* sur l'objet Irrécouvrable
*
* @param irrecoverable Un objet Irrécouvrable
*/
@Transactional
public void createIrrecoverableReport(Irrecoverable irrecoverable) {
Set<Invoice> invoiceSet = irrecoverable.getInvoiceSet();
Set<PaymentScheduleLine> paymentScheduleLineSet = irrecoverable.getPaymentScheduleLineSet();
irrecoverable.setMoveSet(new HashSet<Move>());
List<Partner> payerPartnerList = this.getPayerPartnerList(invoiceSet);
EntityTransaction transaction = JPA.em().getTransaction();
int i = 0;
if (payerPartnerList != null && payerPartnerList.size() != 0) {
for (Partner payerPartner : payerPartnerList) {
if (!transaction.isActive()) {
transaction.begin();
}
i++;
try {
log.debug("Tiers : {}", payerPartner.getName());
this.createIrrecoverableCustomerLine(irrecoverable, payerPartner, this.getInvoiceList(payerPartner, invoiceSet), this.getPaymentScheduleLineList(payerPartner, paymentScheduleLineSet));
irrecoverableRepo.save(irrecoverable);
transaction.commit();
if (i % 50 == 0) {
JPA.flush();
JPA.clear();
}
} catch (Exception e) {
TraceBackService.trace(e);
log.error("Bug(Anomalie) généré(e) pour le tiers : {}", payerPartner.getName());
} finally {
if (!transaction.isActive()) {
transaction.begin();
}
}
}
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class IrrecoverableService method getInvoiceList.
/**
* Fonction permettant de récupérer les factures à passer en irrécouvrable d'un tiers
*
* @param partner Un tiers
* @param allInvoiceList La liste des factures à passer en irrécouvrable de la société
* @return
*/
public List<Invoice> getInvoiceList(Partner partner, Set<Invoice> allInvoiceList) {
List<Invoice> invoiceList = new ArrayList<Invoice>();
for (Invoice invoice : allInvoiceList) {
if (invoice.getPartner().equals(partner)) {
invoiceList.add(invoice);
}
}
log.debug("Nombre de facture à passer en irrécouvrable pour le tiers : {}", invoiceList.size());
return invoiceList;
}
Aggregations