Search in sources :

Example 76 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerController method checkPartnerNameArchived.

public void checkPartnerNameArchived(ActionRequest request, ActionResponse response) {
    try {
        Partner partner = request.getContext().asType(Partner.class);
        Partner partnerArchived = Beans.get(PartnerService.class).isThereDuplicatePartnerInArchive(partner);
        if (partnerArchived != null) {
            response.setValue("$duplicatePartnerInArchiveText", partnerArchived.getPartnerSeq());
            response.setAttr("$duplicatePartnerInArchiveText", "hidden", false);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) BirtException(org.eclipse.birt.core.exception.BirtException) IbanFormatException(org.iban4j.IbanFormatException) InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) AxelorException(com.axelor.exception.AxelorException) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) IOException(java.io.IOException)

Example 77 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerController method showEnvelope.

/**
 * Fonction appeler par le bouton imprimer
 *
 * @param request
 * @param response
 * @return
 * @throws BirtException
 * @throws IOException
 */
public void showEnvelope(ActionRequest request, ActionResponse response) throws AxelorException {
    Partner partner = request.getContext().asType(Partner.class);
    String name = I18n.get("Partner") + " " + partner.getPartnerSeq();
    String fileLink = ReportFactory.createReport(IReport.PARTNER, name + "-${date}").addParam("Locale", ReportSettings.getPrintingLocale(partner)).addParam("Timezone", getTimezone(partner.getUser())).addParam("PartnerId", partner.getId()).generate().getFileLink();
    LOG.debug("Printing " + name);
    response.setView(ActionView.define(name).add("html", fileLink).map());
}
Also used : Partner(com.axelor.apps.base.db.Partner)

Example 78 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PurchaseOrderController method mergePurchaseOrder.

// Generate single purchase order from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergePurchaseOrder(ActionRequest request, ActionResponse response) {
    List<PurchaseOrder> purchaseOrderList = new ArrayList<PurchaseOrder>();
    List<Long> purchaseOrderIdList = new ArrayList<Long>();
    boolean fromPopup = false;
    if (request.getContext().get("purchaseOrderToMerge") != null) {
        if (request.getContext().get("purchaseOrderToMerge") instanceof List) {
            // No confirmation popup, purchase orders are content in a parameter list
            List<Map> purchaseOrderMap = (List<Map>) request.getContext().get("purchaseOrderToMerge");
            for (Map map : purchaseOrderMap) {
                purchaseOrderIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, purchase order's id are in a string separated by ","
            String purchaseOrderIdListStr = (String) request.getContext().get("purchaseOrderToMerge");
            for (String purchaseOrderId : purchaseOrderIdListStr.split(",")) {
                purchaseOrderIdList.add(new Long(purchaseOrderId));
            }
            fromPopup = true;
        }
    }
    // Check if currency, supplierPartner, company and tradingName are the same for all selected
    // purchase orders
    Currency commonCurrency = null;
    Partner commonSupplierPartner = null;
    Company commonCompany = null;
    Partner commonContactPartner = null;
    TradingName commonTradingName = null;
    // Useful to determine if a difference exists between contact partners of all purchase orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all purchase orders
    boolean existPriceListDiff = false;
    PurchaseOrder purchaseOrderTemp;
    boolean allTradingNamesAreNull = true;
    int count = 1;
    for (Long purchaseOrderId : purchaseOrderIdList) {
        purchaseOrderTemp = JPA.em().find(PurchaseOrder.class, purchaseOrderId);
        purchaseOrderList.add(purchaseOrderTemp);
        if (count == 1) {
            commonCurrency = purchaseOrderTemp.getCurrency();
            commonSupplierPartner = purchaseOrderTemp.getSupplierPartner();
            commonCompany = purchaseOrderTemp.getCompany();
            commonContactPartner = purchaseOrderTemp.getContactPartner();
            commonPriceList = purchaseOrderTemp.getPriceList();
            commonTradingName = purchaseOrderTemp.getTradingName();
            allTradingNamesAreNull = commonTradingName == null;
        } else {
            if (commonCurrency != null && !commonCurrency.equals(purchaseOrderTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonSupplierPartner != null && !commonSupplierPartner.equals(purchaseOrderTemp.getSupplierPartner())) {
                commonSupplierPartner = null;
            }
            if (commonCompany != null && !commonCompany.equals(purchaseOrderTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(purchaseOrderTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(purchaseOrderTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (!Objects.equals(commonTradingName, purchaseOrderTemp.getTradingName())) {
                commonTradingName = null;
                allTradingNamesAreNull = false;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_CURRENCY));
    }
    if (commonSupplierPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_SUPPLIER_PARTNER));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_COMPANY));
    }
    if (commonTradingName == null && !allTradingNamesAreNull) {
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_TRADING_NAME));
    }
    if (fieldErrors.length() > 0) {
        response.setFlash(fieldErrors.toString());
        return;
    }
    // Check if priceList or contactPartner are content in parameters
    if (request.getContext().get("priceList") != null) {
        commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
    }
    if (request.getContext().get("contactPartner") != null) {
        commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
    }
    if (!fromPopup && (existContactPartnerDiff || existPriceListDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge purchase order").model(Wizard.class.getName()).add("form", "purchase-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
        if (existPriceListDiff) {
            confirmView.context("contextPriceListToCheck", "true");
        }
        if (existContactPartnerDiff) {
            confirmView.context("contextContactPartnerToCheck", "true");
            confirmView.context("contextPartnerId", commonSupplierPartner.getId().toString());
        }
        confirmView.context("purchaseOrderToMerge", Joiner.on(",").join(purchaseOrderIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderService.class).mergePurchaseOrders(purchaseOrderList, commonCurrency, commonSupplierPartner, commonCompany, commonContactPartner, commonPriceList, commonTradingName);
        if (purchaseOrder != null) {
            // Open the generated purchase order in a new tab
            response.setView(ActionView.define("Purchase order").model(PurchaseOrder.class.getName()).add("grid", "purchase-order-grid").add("form", "purchase-order-form").param("search-filters", "purchase-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(purchaseOrder.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) TradingName(com.axelor.apps.base.db.TradingName) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard)

Example 79 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerSaleServiceImpl method findPartnerMails.

@Override
public List<Long> findPartnerMails(Partner partner) {
    if (!Beans.get(AppSaleService.class).isApp("sale")) {
        return super.findPartnerMails(partner);
    }
    List<Long> idList = new ArrayList<Long>();
    idList.addAll(this.findMailsFromPartner(partner));
    idList.addAll(this.findMailsFromSaleOrder(partner));
    Set<Partner> contactSet = partner.getContactPartnerSet();
    if (contactSet != null && !contactSet.isEmpty()) {
        for (Partner contact : contactSet) {
            idList.addAll(this.findMailsFromPartner(contact));
            idList.addAll(this.findMailsFromSaleOrderContact(contact));
        }
    }
    return idList;
}
Also used : ArrayList(java.util.ArrayList) Partner(com.axelor.apps.base.db.Partner)

Example 80 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class SaleOrderLineController method supplierPartnerDefault.

/**
 * Called from sale order line form, on product change and on sale supply select change
 *
 * @param request
 * @param response
 */
public void supplierPartnerDefault(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_PURCHASE) {
        return;
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (saleOrder == null) {
        Context parentContext = request.getContext().getParent();
        if (parentContext == null) {
            return;
        }
        saleOrder = parentContext.asType(SaleOrder.class);
    }
    if (saleOrder == null) {
        return;
    }
    Partner supplierPartner = null;
    if (saleOrderLine.getProduct() != null) {
        supplierPartner = saleOrderLine.getProduct().getDefaultSupplierPartner();
    }
    if (supplierPartner != null) {
        Blocking blocking = Beans.get(BlockingService.class).getBlocking(supplierPartner, saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
        if (blocking != null) {
            supplierPartner = null;
        }
    }
    response.setValue("supplierPartner", supplierPartner);
}
Also used : Context(com.axelor.rpc.Context) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner)

Aggregations

Partner (com.axelor.apps.base.db.Partner)199 AxelorException (com.axelor.exception.AxelorException)68 Company (com.axelor.apps.base.db.Company)67 Transactional (com.google.inject.persist.Transactional)54 BigDecimal (java.math.BigDecimal)43 ArrayList (java.util.ArrayList)34 MoveLine (com.axelor.apps.account.db.MoveLine)32 Move (com.axelor.apps.account.db.Move)30 PaymentMode (com.axelor.apps.account.db.PaymentMode)26 LocalDate (java.time.LocalDate)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)24 BankDetails (com.axelor.apps.base.db.BankDetails)24 List (java.util.List)22 PartnerService (com.axelor.apps.base.service.PartnerService)18 Map (java.util.Map)18 Journal (com.axelor.apps.account.db.Journal)17 Address (com.axelor.apps.base.db.Address)14 Currency (com.axelor.apps.base.db.Currency)14 AccountConfig (com.axelor.apps.account.db.AccountConfig)13