use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursementInvoice.
/*
/**
* Méthode permettant de créer un fichier xml de virement au format SEPA
* @param export
* @param datetime
* @param reimbursementList
* @throws AxelorException
* @throws DatatypeConfigurationException
* @throws JAXBException
* @throws IOException
public void exportSepa(Company company, ZonedDateTime datetime, List<Reimbursement> reimbursementList, BankDetails bankDetails) throws AxelorException, DatatypeConfigurationException, JAXBException, IOException {
String exportFolderPath = accountConfigService.getReimbursementExportFolderPath(accountConfigService.getAccountConfig(company));
if (exportFolderPath == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.REIMBURSEMENT_2), company.getName());
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
Date date = Date.from(datetime.toInstant());
BigDecimal ctrlSum = BigDecimal.ZERO;
int nbOfTxs = 0;
/**
* Création du documemnt XML en mémoire
-/
ObjectFactory factory = new ObjectFactory();
// Débit
// Paiement
ServiceLevel2Choice svcLvl = factory.createServiceLevel2Choice();
svcLvl.setCd(ServiceLevel1Code.SEPA);
PaymentTypeInformation1 pmtTpInf = factory.createPaymentTypeInformation1();
pmtTpInf.setSvcLvl(svcLvl);
// Payeur
PartyIdentification8 dbtr = factory.createPartyIdentification8();
dbtr.setNm(bankDetails.getOwnerName());
// IBAN
AccountIdentification3Choice iban = factory.createAccountIdentification3Choice();
iban.setIBAN(bankDetails.getIban());
CashAccount7 dbtrAcct = factory.createCashAccount7();
dbtrAcct.setId(iban);
// BIC
FinancialInstitutionIdentification5Choice finInstnId = factory.createFinancialInstitutionIdentification5Choice();
finInstnId.setBIC(bankDetails.getBank().getCode());
BranchAndFinancialInstitutionIdentification3 dbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
dbtrAgt.setFinInstnId(finInstnId);
// Lot
PaymentInstructionInformation1 pmtInf = factory.createPaymentInstructionInformation1();
pmtInf.setPmtMtd(PaymentMethod3Code.TRF);
pmtInf.setPmtTpInf(pmtTpInf);
pmtInf.setReqdExctnDt(datatypeFactory.newXMLGregorianCalendar(dateFormat.format(date)));
pmtInf.setDbtr(dbtr);
pmtInf.setDbtrAcct(dbtrAcct);
pmtInf.setDbtrAgt(dbtrAgt);
// Crédit
CreditTransferTransactionInformation1 cdtTrfTxInf = null; PaymentIdentification1 pmtId = null;
AmountType2Choice amt = null; CurrencyAndAmount instdAmt = null;
PartyIdentification8 cbtr = null; CashAccount7 cbtrAcct = null;
BranchAndFinancialInstitutionIdentification3 cbtrAgt = null;
RemittanceInformation1 rmtInf = null;
for (Reimbursement reimbursement : reimbursementList){
reimbursement = reimbursementRepo.find(reimbursement.getId());
nbOfTxs++;
ctrlSum = ctrlSum.add(reimbursement.getAmountReimbursed());
bankDetails = reimbursement.getBankDetails();
// Paiement
pmtId = factory.createPaymentIdentification1();
pmtId.setEndToEndId(reimbursement.getRef());
// Montant
instdAmt = factory.createCurrencyAndAmount();
instdAmt.setCcy("EUR");
instdAmt.setValue(reimbursement.getAmountReimbursed());
amt = factory.createAmountType2Choice();
amt.setInstdAmt(instdAmt);
// Débiteur
cbtr = factory.createPartyIdentification8();
cbtr.setNm(bankDetails.getOwnerName());
// IBAN
iban = factory.createAccountIdentification3Choice();
iban.setIBAN(bankDetails.getIban());
cbtrAcct = factory.createCashAccount7();
cbtrAcct.setId(iban);
// BIC
finInstnId = factory.createFinancialInstitutionIdentification5Choice();
finInstnId.setBIC(bankDetails.getBank().getCode());
cbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
cbtrAgt.setFinInstnId(finInstnId);
rmtInf = factory.createRemittanceInformation1();
rmtInf.getUstrd().add(reimbursement.getDescription());
// Transaction
cdtTrfTxInf = factory.createCreditTransferTransactionInformation1();
cdtTrfTxInf.setPmtId(pmtId);
cdtTrfTxInf.setAmt(amt);
cdtTrfTxInf.setCdtr(cbtr);
cdtTrfTxInf.setCdtrAcct(cbtrAcct);
cdtTrfTxInf.setCdtrAgt(cbtrAgt);
cdtTrfTxInf.setRmtInf(rmtInf);
pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
}
// En-tête
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
GroupHeader1 grpHdr = factory.createGroupHeader1();
grpHdr.setCreDtTm(datatypeFactory.newXMLGregorianCalendar(dateFormat.format(date)));
grpHdr.setNbOfTxs(Integer.toString(nbOfTxs));
grpHdr.setCtrlSum(ctrlSum);
grpHdr.setGrpg(Grouping1Code.MIXD);
grpHdr.setInitgPty(dbtr);
// Parent
Pain00100102 pain00100102 = factory.createPain00100102();
pain00100102.setGrpHdr(grpHdr);
pain00100102.getPmtInf().add(pmtInf);
// Document
Document xml = factory.createDocument();
xml.setPain00100102(pain00100102);
/**
* Création du documemnt XML physique
-/
Marschaller.marschalFile(factory.createDocument(xml), "com.axelor.apps.xsd.sepa",
exportFolderPath, String.format("%s.xml", dateFormat.format(date)));
}
*/
/**
* *********************** Remboursement lors d'une facture fin de cycle
* ********************************
*/
/**
* Procédure permettant de créer un remboursement si un trop perçu est généré à la facture fin de
* cycle
*
* @param partner Un tiers
* @param company Une société
* @param moveLineList Une liste de trop-perçu
* @throws AxelorException
*/
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void createReimbursementInvoice(Partner partner, Company company, List<? extends MoveLine> moveLineList) throws AxelorException {
BigDecimal total = this.getTotalAmountRemaining((List<MoveLine>) moveLineList);
if (total.compareTo(BigDecimal.ZERO) > 0) {
this.testCompanyField(company);
Reimbursement reimbursement = this.createReimbursement(partner, company);
this.fillMoveLineSet(reimbursement, (List<MoveLine>) moveLineList, total);
if (total.compareTo(company.getAccountConfig().getUpperThresholdReimbursement()) > 0 || reimbursement.getBankDetails() == null) {
// Seuil haut dépassé
reimbursement.setStatusSelect(ReimbursementRepository.STATUS_TO_VALIDATE);
} else {
// Seuil haut non dépassé
reimbursement.setStatusSelect(ReimbursementRepository.STATUS_VALIDATED);
}
reimbursementRepo.save(reimbursement);
}
}
use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursement.
/**
* Méthode permettant de créer un remboursement
*
* @param partner Un tiers
* @param company Une société
* @return Le remboursmeent créé
* @throws AxelorException
*/
public Reimbursement createReimbursement(Partner partner, Company company) throws AxelorException {
Reimbursement reimbursement = new Reimbursement();
reimbursement.setPartner(partner);
reimbursement.setCompany(company);
BankDetails bankDetails = partnerService.getDefaultBankDetails(partner);
reimbursement.setBankDetails(bankDetails);
reimbursement.setRef(sequenceService.getSequenceNumber(SequenceRepository.REIMBOURSEMENT, company));
return reimbursement;
}
use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.
the class BatchReimbursementExport method runReimbursementExportProcess.
public void runReimbursementExportProcess(Company company) {
int i = 0;
// On récupère les remboursements dont les trop perçu ont été annulés
List<Reimbursement> reimbursementToCancelList = reimbursementRepo.all().filter("self.company = ?1 and self.statusSelect = ?2 and self.amountToReimburse = 0", ReimbursementRepository.STATUS_VALIDATED, company).fetch();
// On annule les remboursements
for (Reimbursement reimbursement : reimbursementToCancelList) {
reimbursement.setStatusSelect(ReimbursementRepository.STATUS_CANCELED);
}
// On récupère les remboursement à rembourser
List<Reimbursement> reimbursementList = reimbursementRepo.all().filter("self.company = ?1 and self.statusSelect = ?2 and self.amountToReimburse > 0 AND self.partner", company, ReimbursementRepository.STATUS_VALIDATED).fetch();
List<Reimbursement> reimbursementToExport = new ArrayList<>();
for (Reimbursement reimbursement : reimbursementList) {
try {
reimbursement = reimbursementRepo.find(reimbursement.getId());
if (reimbursementExportService.canBeReimbursed(reimbursement.getPartner(), reimbursement.getCompany())) {
reimbursementExportService.reimburse(reimbursement, company);
updateReimbursement(reimbursementRepo.find(reimbursement.getId()));
reimbursementToExport.add(reimbursement);
this.totalAmount = this.totalAmount.add(reimbursementRepo.find(reimbursement.getId()).getAmountReimbursed());
i++;
}
} catch (AxelorException e) {
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Reimbursement") + " %s", reimbursementRepo.find(reimbursement.getId()).getRef()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
incrementAnomaly();
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("Reimbursement") + " %s", reimbursementRepo.find(reimbursement.getId()).getRef()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
incrementAnomaly();
log.error("Bug(Anomalie) généré(e) pour l'export du remboursement {}", reimbursementRepo.find(reimbursement.getId()).getRef());
} finally {
if (i % 10 == 0) {
JPA.clear();
}
}
}
if (reimbursementToExport != null && !reimbursementToExport.isEmpty()) {
try {
cfonbExportService.exportCFONB(companyRepo.find(company.getId()), batchRepo.find(batch.getId()).getStartDate(), reimbursementToExport, batchRepo.find(batch.getId()).getAccountingBatch().getBankDetails());
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_1), batch.getId()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
incrementAnomaly();
log.error("Bug(Anomalie) généré(e)e dans l'export CFONB - Batch {}", batch.getId());
}
}
}
use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.
the class CfonbExportService method getTotalAmountReimbursementExport.
/**
* Méthode permettant de calculer le montant total des remboursements
*
* @param reimbursementList Une liste de remboursement
* @return Le montant total
*/
private BigDecimal getTotalAmountReimbursementExport(List<Reimbursement> reimbursementList) {
BigDecimal totalAmount = BigDecimal.ZERO;
for (Reimbursement reimbursement : reimbursementList) {
reimbursement = reimbursementRepo.find(reimbursement.getId());
totalAmount = totalAmount.add(reimbursement.getAmountReimbursed());
}
return totalAmount;
}
use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.
the class CfonbExportService method exportCFONB.
/**
* ************************************** Export CFONB
* ****************************************************
*/
/**
* Méthode permettant d'exporter les remboursements au format CFONB
*
* @param reimbursementExport
* @param ZonedDateTime
* @param reimbursementList
* @throws AxelorException
*/
public void exportCFONB(Company company, ZonedDateTime datetime, List<Reimbursement> reimbursementList, BankDetails bankDetails) throws AxelorException {
this.testCompanyExportCFONBField(company);
// paramètre obligatoire : au minimum
// un enregistrement emetteur par date de règlement (code 03)
// un enregistrement destinataire (code 06)
// un enregistrement total (code 08)
String senderCFONB = this.createSenderReimbursementCFONB(datetime, bankDetails);
List<String> multiRecipientCFONB = new ArrayList<String>();
for (Reimbursement reimbursement : reimbursementList) {
reimbursement = reimbursementRepo.find(reimbursement.getId());
multiRecipientCFONB.add(this.createRecipientCFONB(reimbursement));
}
String totalCFONB = this.createReimbursementTotalCFONB(this.getTotalAmountReimbursementExport(reimbursementList));
// cfonbToolService.testLength(senderCFONB, totalCFONB, multiRecipientCFONB, company);
// List<String> cFONB = this.createCFONBExport(senderCFONB, multiRecipientCFONB, totalCFONB);
// Mise en majuscule des enregistrement
// cFONB = this.toUpperCase(cFONB);
// this.createCFONBFile(cFONB, datetime,
// company.getAccountConfig().getReimbursementExportFolderPathCFONB(), "virement");
}
Aggregations