Search in sources :

Example 11 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class NotificationServiceImpl method createPaymentMove.

@Transactional(rollbackOn = { Exception.class })
protected Move createPaymentMove(NotificationItem notificationItem) throws AxelorException {
    Notification notification = notificationItem.getNotification();
    Invoice invoice = notificationItem.getInvoice();
    Company company = invoice.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = getJournal(accountConfig);
    SubrogationRelease subrogationRelease = getSubrogationRelease(notificationItem);
    String origin = computeOrigin(subrogationRelease, invoice);
    BigDecimal amountPaid = notificationItem.getAmountPaid();
    if (amountPaid.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    }
    Move paymentMove = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), notification.getPaymentDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    MoveLine creditMoveLine, debitMoveLine;
    Account account = getAccount(accountConfig, notificationItem);
    debitMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), account, amountPaid, true, notification.getPaymentDate(), null, 1, origin, invoice.getInvoiceId());
    creditMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), invoice.getPartnerAccount(), amountPaid, false, notification.getPaymentDate(), null, 2, origin, invoice.getInvoiceId());
    paymentMove.addMoveLineListItem(debitMoveLine);
    paymentMove.addMoveLineListItem(creditMoveLine);
    paymentMove = moveRepository.save(paymentMove);
    moveService.getMoveValidateService().validate(paymentMove);
    MoveLine invoiceMoveLine = findInvoiceAccountMoveLine(invoice);
    MoveLine subrogationReleaseMoveLine = findSubrogationReleaseAccountMoveLine(invoice);
    if (invoiceMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) {
        reconcileService.reconcile(invoiceMoveLine, creditMoveLine, true, true);
        if (subrogationReleaseMoveLine != null && notificationItem.getTypeSelect() == NotificationRepository.TYPE_PAYMENT_TO_THE_FACTORE) {
            reconcileService.reconcile(debitMoveLine, subrogationReleaseMoveLine, true, false);
        }
    }
    notificationItem.setMove(paymentMove);
    if (subrogationRelease != null) {
        subrogationReleaseService.clear(subrogationRelease);
    }
    return paymentMove;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Notification(com.axelor.apps.account.db.Notification) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Aggregations

SubrogationRelease (com.axelor.apps.account.db.SubrogationRelease)11 SubrogationReleaseService (com.axelor.apps.account.service.SubrogationReleaseService)5 Invoice (com.axelor.apps.account.db.Invoice)4 Move (com.axelor.apps.account.db.Move)3 MoveLine (com.axelor.apps.account.db.MoveLine)3 Company (com.axelor.apps.base.db.Company)3 Account (com.axelor.apps.account.db.Account)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 Journal (com.axelor.apps.account.db.Journal)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 ReportFactory (com.axelor.apps.ReportFactory)1 Notification (com.axelor.apps.account.db.Notification)1 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)1 SubrogationReleaseRepository (com.axelor.apps.account.db.repo.SubrogationReleaseRepository)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 IReport (com.axelor.apps.account.report.IReport)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 InvoiceToolService (com.axelor.apps.account.service.invoice.InvoiceToolService)1