use of com.axelor.apps.account.db.InterbankCodeLine in project axelor-open-suite by axelor.
the class ChequeRejectionService method createChequeRejectionMove.
/**
* Méthode permettant de créer une écriture de rejet de chèque (L'extourne de l'écriture de
* paiement)
*
* @param chequeRejection Un rejet de cheque brouillon
* @param company Une société
* @return L'écriture de rejet de chèque
* @throws AxelorException
*/
public Move createChequeRejectionMove(ChequeRejection chequeRejection, Company company) throws AxelorException {
this.testCompanyField(company);
Journal journal = company.getAccountConfig().getRejectJournal();
PaymentVoucher paymentVoucher = chequeRejection.getPaymentVoucher();
Move paymentMove = paymentVoucher.getGeneratedMove();
Partner partner = paymentVoucher.getPartner();
InterbankCodeLine interbankCodeLine = chequeRejection.getInterbankCodeLine();
String description = chequeRejection.getDescription();
LocalDate rejectionDate = chequeRejection.getRejectionDate();
// Move
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, rejectionDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
int ref = 1;
for (MoveLine moveLine : paymentMove.getMoveLineList()) {
if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
// Debit MoveLine
MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getCredit(), true, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
move.getMoveLineList().add(debitMoveLine);
debitMoveLine.setInterbankCodeLine(interbankCodeLine);
debitMoveLine.setDescription(description);
} else {
// Credit MoveLine
MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getDebit(), false, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
move.getMoveLineList().add(creditMoveLine);
creditMoveLine.setInterbankCodeLine(interbankCodeLine);
creditMoveLine.setDescription(description);
}
ref++;
}
move.setRejectOk(true);
moveService.getMoveValidateService().validate(move);
return move;
}
use of com.axelor.apps.account.db.InterbankCodeLine in project axelor-open-suite by axelor.
the class BankStatementFileAFB120Service method createBankStatementLine.
@Transactional
public BankStatementLineAFB120 createBankStatementLine(Map<String, Object> structuredContentLine, int sequence) {
String description = (String) structuredContentLine.get("description");
if (structuredContentLine.containsKey("additionalInformation") && structuredContentLine.get("additionalInformation") != null) {
description += "\n" + (String) structuredContentLine.get("additionalInformation");
}
BankDetails bankDetails = null;
if (structuredContentLine.containsKey("bankDetails") && structuredContentLine.get("bankDetails") != null) {
bankDetails = bankDetailsRepository.find(((BankDetails) structuredContentLine.get("bankDetails")).getId());
}
Currency currency = null;
if (structuredContentLine.containsKey("currency") && structuredContentLine.get("currency") != null) {
currency = currencyRepository.find(((Currency) structuredContentLine.get("currency")).getId());
}
InterbankCodeLine operationInterbankCodeLine = null;
if (structuredContentLine.containsKey("operationInterbankCodeLine") && structuredContentLine.get("operationInterbankCodeLine") != null) {
operationInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("operationInterbankCodeLine")).getId());
}
InterbankCodeLine rejectInterbankCodeLine = null;
if (structuredContentLine.containsKey("rejectInterbankCodeLine") && structuredContentLine.get("rejectInterbankCodeLine") != null) {
rejectInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("rejectInterbankCodeLine")).getId());
}
BankStatementLineAFB120 bankStatementLineAFB120 = bankStatementLineAFB120Service.createBankStatementLine(findBankStatement(), sequence, bankDetails, (BigDecimal) structuredContentLine.get("debit"), (BigDecimal) structuredContentLine.get("credit"), currency, description, (LocalDate) structuredContentLine.get("operationDate"), (LocalDate) structuredContentLine.get("valueDate"), operationInterbankCodeLine, rejectInterbankCodeLine, (String) structuredContentLine.get("origin"), (String) structuredContentLine.get("reference"), (int) structuredContentLine.get("lineType"), (String) structuredContentLine.get("unavailabilityIndexSelect"), (String) structuredContentLine.get("commissionExemptionIndexSelect"));
return bankStatementLineAFB120Repository.save(bankStatementLineAFB120);
}
use of com.axelor.apps.account.db.InterbankCodeLine in project axelor-open-suite by axelor.
the class PaymentScheduleLineController method reject.
public void reject(ActionRequest request, ActionResponse response) {
try {
@SuppressWarnings("unchecked") List<? extends Number> idList = MoreObjects.firstNonNull((List<? extends Number>) request.getContext().get("idList"), Collections.emptyList());
boolean represent = (boolean) request.getContext().get("represent");
// TODO: one rejection reason per payment schedule line
InterbankCodeLine interbankCodeLine;
@SuppressWarnings("unchecked") Map<String, Object> interbankCodeLineMap = (Map<String, Object>) request.getContext().get("interbankCodeLine");
if (interbankCodeLineMap != null) {
interbankCodeLine = Beans.get(InterbankCodeLineRepository.class).find(((Number) interbankCodeLineMap.get("id")).longValue());
} else {
interbankCodeLine = null;
}
Map<Long, InterbankCodeLine> idMap = new LinkedHashMap<>();
idList.stream().map(Number::longValue).forEach(id -> idMap.put(id, interbankCodeLine));
PaymentScheduleLineBankPaymentService paymentScheduleLineBankPaymentService = Beans.get(PaymentScheduleLineBankPaymentService.class);
if (idMap.size() == 1) {
Entry<Long, InterbankCodeLine> entry = idMap.entrySet().iterator().next();
long id = entry.getKey();
InterbankCodeLine rejectionReason = entry.getValue();
paymentScheduleLineBankPaymentService.reject(id, rejectionReason, represent);
} else {
int errorCount = paymentScheduleLineBankPaymentService.rejectFromIdMap(idMap, represent);
if (errorCount != 0) {
response.setError(String.format(I18n.get("%d errors occurred. Please check tracebacks for details."), errorCount));
return;
}
}
response.setFlash(String.format(I18n.get("%d line successfully rejected", "%d lines successfully rejected", idMap.size()), idMap.size()));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.InterbankCodeLine in project axelor-open-suite by axelor.
the class PaymentScheduleLineBankPaymentServiceImpl method rejectFromMap.
protected <T> int rejectFromMap(Map<T, InterbankCodeLine> map, boolean represent, Function<T, PaymentScheduleLine> findFunc) {
int errorCount = 0;
for (Entry<T, InterbankCodeLine> entry : map.entrySet()) {
T key = entry.getKey();
InterbankCodeLine rejectionReason = entry.getValue();
PaymentScheduleLine paymentScheduleLine = findFunc.apply(key);
try {
reject(paymentScheduleLine, rejectionReason, represent);
} catch (Exception e) {
TraceBackService.trace(e);
++errorCount;
}
}
return errorCount;
}
use of com.axelor.apps.account.db.InterbankCodeLine in project axelor-open-suite by axelor.
the class ReimbursementImportService method createReimbursementRejectMoveLine.
@Transactional(rollbackOn = { Exception.class })
public Reimbursement createReimbursementRejectMoveLine(String[] reject, Company company, int seq, Move move, LocalDate rejectDate) throws AxelorException {
String refReject = reject[1];
// String amountReject = reject[2];
InterbankCodeLine causeReject = rejectImportService.getInterbankCodeLine(reject[3], 0);
MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
Reimbursement reimbursement = reimbursementRepo.all().filter("UPPER(self.ref) = ?1 AND self.company = ?2", refReject, company).fetchOne();
if (reimbursement == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.REIMBURSEMENT_3), refReject, company.getName());
}
Partner partner = reimbursement.getPartner();
BigDecimal amount = reimbursement.getAmountReimbursed();
// Création de la ligne au crédit
MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, company.getAccountConfig().getCustomerAccount(), amount, false, rejectDate, seq, refReject, null);
move.getMoveLineList().add(creditMoveLine);
moveLineRepo.save(creditMoveLine);
moveRepo.save(move);
creditMoveLine.setInterbankCodeLine(causeReject);
reimbursement.setRejectedOk(true);
reimbursement.setRejectDate(rejectDate);
reimbursement.setRejectMoveLine(creditMoveLine);
reimbursement.setInterbankCodeLine(causeReject);
reimbursementRepo.save(reimbursement);
return reimbursement;
}
Aggregations