Search in sources :

Example 1 with Notification

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

the class NotificationServiceImpl method populateNotificationItemList.

@Override
public void populateNotificationItemList(Notification notification) {
    notification.clearNotificationItemList();
    Comparator<Invoice> byInvoiceDate = (i1, i2) -> i1.getInvoiceDate().compareTo(i2.getInvoiceDate());
    Comparator<Invoice> byDueDate = (i1, i2) -> i1.getDueDate().compareTo(i2.getDueDate());
    Comparator<Invoice> byInvoiceId = (i1, i2) -> i1.getInvoiceId().compareTo(i2.getInvoiceId());
    List<Invoice> invoiceList = new ArrayList<Invoice>();
    if (notification.getSubrogationRelease() != null) {
        invoiceList = notification.getSubrogationRelease().getInvoiceSet().stream().sorted(byInvoiceDate.thenComparing(byDueDate).thenComparing(byInvoiceId)).collect(Collectors.toList());
    }
    for (Invoice invoice : invoiceList) {
        if (invoice.getAmountRemaining().signum() > 0) {
            notification.addNotificationItemListItem(createNotificationItem(invoice));
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) Inject(com.google.inject.Inject) NotificationItem(com.axelor.apps.account.db.NotificationItem) TypedQuery(javax.persistence.TypedQuery) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) NotificationRepository(com.axelor.apps.account.db.repo.NotificationRepository) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) I18n(com.axelor.i18n.I18n) NoSuchElementException(java.util.NoSuchElementException) Journal(com.axelor.apps.account.db.Journal) JPA(com.axelor.db.JPA) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) List(java.util.List) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Notification(com.axelor.apps.account.db.Notification) Comparator(java.util.Comparator) SubrogationReleaseRepository(com.axelor.apps.account.db.repo.SubrogationReleaseRepository) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList)

Example 2 with Notification

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

the class NotificationController method validate.

public void validate(ActionRequest request, ActionResponse response) {
    try {
        Notification notification = request.getContext().asType(Notification.class);
        notification = Beans.get(NotificationRepository.class).find(notification.getId());
        Beans.get(NotificationService.class).validate(notification);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : NotificationService(com.axelor.apps.account.service.NotificationService) Notification(com.axelor.apps.account.db.Notification)

Example 3 with Notification

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

the class NotificationController method populateNotificationItemList.

public void populateNotificationItemList(ActionRequest request, ActionResponse response) {
    try {
        Notification notification = request.getContext().asType(Notification.class);
        Beans.get(NotificationService.class).populateNotificationItemList(notification);
        response.setValue("notificationItemList", notification.getNotificationItemList());
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : NotificationService(com.axelor.apps.account.service.NotificationService) Notification(com.axelor.apps.account.db.Notification)

Example 4 with Notification

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

the class NotificationController method displayMoveLines.

public void displayMoveLines(ActionRequest request, ActionResponse response) {
    try {
        Notification notification = request.getContext().asType(Notification.class);
        List<Long> moveLineIdList = new ArrayList<Long>();
        for (NotificationItem notificationItem : notification.getNotificationItemList()) {
            for (MoveLine moveLine : notificationItem.getMove().getMoveLineList()) {
                moveLineIdList.add(moveLine.getId());
            }
        }
        response.setView(ActionView.define("MoveLines").model(MoveLine.class.getName()).add("grid", "move-line-grid").add("form", "move-line-form").param("search-filters", "move-line-filters").domain("self.id in (" + Joiner.on(",").join(moveLineIdList) + ")").map());
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : NotificationItem(com.axelor.apps.account.db.NotificationItem) ArrayList(java.util.ArrayList) MoveLine(com.axelor.apps.account.db.MoveLine) Notification(com.axelor.apps.account.db.Notification)

Example 5 with Notification

use of com.axelor.apps.account.db.Notification 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

Notification (com.axelor.apps.account.db.Notification)5 MoveLine (com.axelor.apps.account.db.MoveLine)3 Account (com.axelor.apps.account.db.Account)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 Invoice (com.axelor.apps.account.db.Invoice)2 Journal (com.axelor.apps.account.db.Journal)2 Move (com.axelor.apps.account.db.Move)2 NotificationItem (com.axelor.apps.account.db.NotificationItem)2 SubrogationRelease (com.axelor.apps.account.db.SubrogationRelease)2 NotificationService (com.axelor.apps.account.service.NotificationService)2 Company (com.axelor.apps.base.db.Company)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)1 NotificationRepository (com.axelor.apps.account.db.repo.NotificationRepository)1 SubrogationReleaseRepository (com.axelor.apps.account.db.repo.SubrogationReleaseRepository)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 MoveService (com.axelor.apps.account.service.move.MoveService)1 JPA (com.axelor.db.JPA)1