use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class ImportMove method importFECMove.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Object importFECMove(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof MoveLine;
MoveLine moveLine = (MoveLine) bean;
try {
moveLine.setCounter(1);
if (values.get("EcritureNum") == null) {
return null;
}
String moveReference = values.get("EcritureNum").toString();
MoveLine mvLine = moveLineRepo.all().filter("self.name LIKE '" + moveReference + "-%'").order("-counter").fetchOne();
if (mvLine != null) {
int counter = mvLine.getCounter() + 1;
moveLine.setCounter(counter);
}
if (values.get("EcritureDate") != null) {
LocalDate moveLineDate = LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE);
moveLine.setDate(moveLineDate);
}
Move move = moveRepository.all().filter("self.reference = ?", moveReference).fetchOne();
if (move == null) {
move = new Move();
move.setReference(moveReference);
if (values.get("ValidDate") != null) {
move.setStatusSelect(MoveRepository.STATUS_VALIDATED);
move.setValidationDate(LocalDate.parse(values.get("ValidDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
} else {
move.setStatusSelect(MoveRepository.STATUS_ACCOUNTED);
}
move.setCompany(getCompany(values));
move.setCompanyCurrency(move.getCompany().getCurrency());
move.setDate(LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
move.setPeriod(Beans.get(PeriodService.class).getPeriod(move.getDate(), move.getCompany(), YearRepository.TYPE_FISCAL));
if (values.get("Idevise") != null) {
move.setCurrency(Beans.get(CurrencyRepository.class).findByCode(values.get("Idevise").toString()));
move.setCurrencyCode(values.get("Idevise").toString());
}
if (values.get("JournalCode") != null) {
Journal journal = Beans.get(JournalRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("JournalCode").toString(), move.getCompany().getId()).fetchOne();
move.setJournal(journal);
}
if (values.get("CompAuxNum") != null) {
Partner partner = Beans.get(PartnerRepository.class).all().filter("self.partnerSeq = ?", values.get("CompAuxNum").toString()).fetchOne();
move.setPartner(partner);
}
moveRepository.save(move);
}
if (values.get("CompteNum") != null) {
Account account = Beans.get(AccountRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("CompteNum").toString(), move.getCompany().getId()).fetchOne();
moveLine.setAccount(account);
}
moveLine.setMove(move);
} catch (Exception e) {
TraceBackService.trace(e);
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
}
return moveLine;
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class JournalController method computeBalance.
public void computeBalance(ActionRequest request, ActionResponse response) {
Journal journal = request.getContext().asType(Journal.class);
Map<String, BigDecimal> resultMap = journalService.computeBalance(journal);
response.setValue("$balance", resultMap.get("balance"));
response.setValue("$totalDebit", resultMap.get("debit"));
response.setValue("$totalCredit", resultMap.get("credit"));
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class PaymentVoucherController method askPaymentVoucher.
public void askPaymentVoucher(ActionRequest request, ActionResponse response) {
PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
if (paymentVoucher.getHasAutoInput()) {
PaymentMode paymentMode = paymentVoucher.getPaymentMode();
Company company = paymentVoucher.getCompany();
BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
try {
Journal journal = Beans.get(PaymentModeService.class).getPaymentModeJournal(paymentMode, company, companyBankDetails);
if (journal.getExcessPaymentOk()) {
response.setAlert(I18n.get("No items have been selected. Do you want to continue?"));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class MoveSequenceService method setSequence.
public void setSequence(Move move) throws AxelorException {
Journal journal = move.getJournal();
if (journal.getSequence() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_5), journal.getName());
}
move.setReference(sequenceService.getSequenceNumber(journal.getSequence(), move.getDate()));
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMoveUseDebit.
@Override
public Move createMoveUseDebit(Invoice invoice, List<MoveLine> debitMoveLines, MoveLine invoiceCustomerMoveLine) throws AxelorException {
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
Account account = invoice.getPartnerAccount();
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfigService.getAccountConfig(company));
log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
BigDecimal remainingAmount = invoice.getInTaxTotal().abs();
log.debug("Montant à payer avec l'avoir récupéré : {}", remainingAmount);
Move oDmove = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
if (oDmove != null) {
BigDecimal totalDebitAmount = moveToolService.getTotalDebitAmount(debitMoveLines);
BigDecimal amount = totalDebitAmount.min(invoiceCustomerMoveLine.getCredit());
// Création de la ligne au débit
MoveLine debitMoveLine = moveLineService.createMoveLine(oDmove, partner, account, amount, true, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
oDmove.getMoveLineList().add(debitMoveLine);
// Emploie des dûs sur les lignes de credit qui seront créées au fil de l'eau
paymentService.createExcessPaymentWithAmount(debitMoveLines, amount, oDmove, 2, partner, company, null, account, appAccountService.getTodayDate(company));
moveValidateService.validate(oDmove);
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, invoiceCustomerMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
return oDmove;
}
Aggregations