use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class AccountCustomerService method updateAccountingSituationCustomerAccount.
@Transactional(rollbackOn = { Exception.class })
public AccountingSituation updateAccountingSituationCustomerAccount(AccountingSituation accountingSituation, boolean updateCustAccount, boolean updateDueCustAccount, boolean updateDueDebtRecoveryCustAccount) throws AxelorException {
Partner partner = accountingSituation.getPartner();
Company company = accountingSituation.getCompany();
log.debug("Update customer account (Partner : {}, Company : {}, Update balance : {}, balance due : {}, balance due debt recovery : {})", partner.getName(), company.getName(), updateCustAccount, updateDueCustAccount, updateDueDebtRecoveryCustAccount);
if (updateCustAccount) {
accountingSituation.setBalanceCustAccount(this.getBalance(partner, company));
}
if (updateDueCustAccount) {
accountingSituation.setBalanceDueCustAccount(this.getBalanceDue(partner, company, null));
}
if (updateDueDebtRecoveryCustAccount) {
accountingSituation.setBalanceDueDebtRecoveryCustAccount(this.getBalanceDueDebtRecovery(partner, company, null));
}
accountingSituation.setCustAccountMustBeUpdateOk(false);
accSituationRepo.save(accountingSituation);
return accountingSituation;
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1000.
/**
* Méthode réalisant l'export des FEC (Fichiers des écritures Comptables)
*
* @throws AxelorException
* @throws IOException
*/
@Transactional(rollbackOn = { Exception.class })
public MetaFile exportMoveLineTypeSelect1000(AccountingReport accountingReport, boolean administration, boolean replay) throws AxelorException, IOException {
log.info("In Export type 1000 service : ");
List<String[]> allMoveLineData = new ArrayList<>();
Company company = accountingReport.getCompany();
LocalDate interfaceDate = accountingReport.getDate();
String moveLineQueryStr = String.format("(self.move.statusSelect = %s", MoveRepository.STATUS_VALIDATED);
if (!administration) {
moveLineQueryStr += String.format(" OR self.move.statusSelect = %s", MoveRepository.STATUS_ACCOUNTED);
}
moveLineQueryStr += ")";
moveLineQueryStr += String.format(" AND self.move.company = %s", company.getId());
if (accountingReport.getYear() != null) {
moveLineQueryStr += String.format(" AND self.move.period.year = %s", accountingReport.getYear().getId());
}
if (accountingReport.getPeriod() != null) {
moveLineQueryStr += String.format(" AND self.move.period = %s", accountingReport.getPeriod().getId());
} else {
if (accountingReport.getDateFrom() != null) {
moveLineQueryStr += String.format(" AND self.date >= '%s'", accountingReport.getDateFrom().toString());
}
if (accountingReport.getDateTo() != null) {
moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDateTo().toString());
}
}
if (accountingReport.getDate() != null) {
moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDate().toString());
}
moveLineQueryStr += " AND self.move.ignoreInAccountingOk = false";
if (!administration) {
moveLineQueryStr += " AND self.move.journal.notExportOk = false";
if (replay) {
moveLineQueryStr += String.format(" AND self.move.accountingOk = true AND self.move.accountingReport.id = %s", accountingReport.getId());
} else {
moveLineQueryStr += " AND self.move.accountingOk = false";
}
}
List<MoveLine> moveLineList = moveLineRepo.all().filter(moveLineQueryStr).order("move.validationDate").order("date").order("name").fetch();
if (!moveLineList.isEmpty()) {
List<Move> moveList = new ArrayList<>();
for (MoveLine moveLine : moveLineList) {
String[] items = new String[18];
Move move = moveLine.getMove();
if (!moveList.contains(move)) {
moveList.add(move);
}
Journal journal = move.getJournal();
items[0] = journal.getCode();
items[1] = journal.getName();
items[2] = moveLine.getMove().getReference();
items[3] = moveLine.getDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
items[4] = moveLine.getAccount().getCode();
items[5] = moveLine.getAccount().getName();
items[6] = "";
items[7] = "";
Partner partner = moveLine.getPartner();
if (partner != null) {
items[6] = partner.getPartnerSeq();
items[7] = partner.getName();
}
items[8] = moveLine.getOrigin();
if (moveLine.getOriginDate() != null) {
items[9] = moveLine.getOriginDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
}
items[10] = moveLine.getDescription();
items[11] = moveLine.getDebit().toString().replace('.', ',');
items[12] = moveLine.getCredit().toString().replace('.', ',');
ReconcileGroup reconcileGroup = moveLine.getReconcileGroup();
if (reconcileGroup != null && reconcileGroup.getStatusSelect() == ReconcileGroupRepository.STATUS_FINAL) {
items[13] = reconcileGroup.getCode();
items[14] = reconcileGroup.getDateOfLettering().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD)).toString();
} else {
items[13] = "";
items[14] = "";
}
if (move.getValidationDate() != null) {
items[15] = move.getValidationDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
}
items[16] = moveLine.getCurrencyAmount().toString().replace('.', ',');
if (moveLine.getCurrencyAmount().compareTo(BigDecimal.ZERO) > 0 && moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
items[16] = "-" + items[16];
}
if (move.getCurrency() != null) {
items[17] = move.getCurrency().getCode();
}
allMoveLineData.add(items);
}
if (!administration) {
String exportNumber = this.getSaleExportNumber(company);
this.updateMoveList(moveList, accountingReport, interfaceDate, exportNumber);
}
}
accountingReport = accountingReportRepo.find(accountingReport.getId());
String fileName = this.setFileName(accountingReport);
accountingReportRepo.save(accountingReport);
return writeMoveLineToCsvFile(company, fileName, this.createHeaderForJournalEntry(), allMoveLineData, accountingReport);
}
use of com.axelor.apps.base.db.Partner 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.apps.base.db.Partner 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.base.db.Partner in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursementMove.
/**
* Methode permettant de créer l'écriture de remboursement
*
* @param reimbursement Un objet d'export des prélèvements
* @throws AxelorException
*/
public void createReimbursementMove(Reimbursement reimbursement, Company company) throws AxelorException {
reimbursement = reimbursementRepo.find(reimbursement.getId());
Partner partner = null;
Move newMove = null;
boolean first = true;
AccountConfig accountConfig = company.getAccountConfig();
if (reimbursement.getMoveLineSet() != null && !reimbursement.getMoveLineSet().isEmpty()) {
int seq = 1;
for (MoveLine moveLine : reimbursement.getMoveLineSet()) {
BigDecimal amountRemaining = moveLine.getAmountRemaining();
if (amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
partner = moveLine.getPartner();
// On passe les lignes d'écriture (trop perçu) à l'état 'remboursé'
moveLine.setReimbursementStatusSelect(MoveLineRepository.REIMBURSEMENT_STATUS_REIMBURSED);
if (first) {
newMove = moveService.getMoveCreateService().createMove(accountConfig.getReimbursementJournal(), company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
first = false;
}
// Création d'une ligne au débit
MoveLine newDebitMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, true, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
newMove.getMoveLineList().add(newDebitMoveLine);
if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
newDebitMoveLine.setDescription(reimbursement.getDescription());
}
seq++;
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(newDebitMoveLine, moveLine, amountRemaining, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
}
// Création de la ligne au crédit
MoveLine newCreditMoveLine = moveLineService.createMoveLine(newMove, partner, accountConfig.getReimbursementAccount(), reimbursement.getAmountReimbursed(), false, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
newMove.getMoveLineList().add(newCreditMoveLine);
if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
newCreditMoveLine.setDescription(reimbursement.getDescription());
}
moveService.getMoveValidateService().validate(newMove);
moveRepo.save(newMove);
}
}
Aggregations