Search in sources :

Example 81 with Partner

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

the class StockMoveInvoiceController method generateInvoiceConcatInStockMoveCheckMissingFields.

/**
 * Called from mass invoicing out stock move form view. Call method to check for missing fields.
 * If there are missing fields, show a wizard. Else call {@link
 * StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
 * generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatInStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        List<Long> stockMoveIdList = new ArrayList<>();
        List<Map> stockMoveMap = (List<Map>) request.getContext().get("supplierStockMoveToInvoice");
        for (Map map : stockMoveMap) {
            stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
        }
        for (Long stockMoveId : stockMoveIdList) {
            stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
        }
        Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateSupplierInvoice(stockMoveList);
        boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
        boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
        boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
        Partner partner = stockMoveList.get(0).getPartner();
        if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
            ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-suppl-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
            if (paymentConditionToCheck) {
                confirmView.context("contextPaymentConditionToCheck", "true");
            } else {
                confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
            }
            if (paymentModeToCheck) {
                confirmView.context("contextPaymentModeToCheck", "true");
            } else {
                confirmView.context("paymentMode", mapResult.get("paymentMode"));
            }
            if (contactPartnerToCheck) {
                confirmView.context("contextContactPartnerToCheck", "true");
                confirmView.context("contextPartnerId", partner.getId().toString());
            } else {
                confirmView.context("contactPartner", mapResult.get("contactPartner"));
            }
            confirmView.context("supplierStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
            response.setView(confirmView.map());
        } else {
            Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList);
            invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner)

Example 82 with Partner

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

the class StockMoveInvoiceController method generateInvoiceConcatInStockMove.

/**
 * Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
 * call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiIncomingStockMove(List,
 * PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatInStockMove(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        String stockMoveListStr = (String) request.getContext().get("supplierStockMoveToInvoice");
        for (String stockMoveId : stockMoveListStr.split(",")) {
            stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
        }
        PaymentCondition paymentCondition = null;
        PaymentMode paymentMode = null;
        Partner contactPartner = null;
        if (request.getContext().get("paymentCondition") != null) {
            paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
        }
        if (request.getContext().get("paymentMode") != null) {
            paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
        }
        if (request.getContext().get("contactPartner") != null) {
            contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
        }
        Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
        invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 83 with Partner

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

the class SaleOrderController method mergeSaleOrder.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeSaleOrder(ActionRequest request, ActionResponse response) {
    List<SaleOrder> saleOrderList = new ArrayList<>();
    List<Long> saleOrderIdList = new ArrayList<>();
    boolean fromPopup = false;
    String lineToMerge;
    if (request.getContext().get("saleQuotationToMerge") != null) {
        lineToMerge = "saleQuotationToMerge";
    } else {
        lineToMerge = "saleOrderToMerge";
    }
    if (request.getContext().get(lineToMerge) != null) {
        if (request.getContext().get(lineToMerge) instanceof List) {
            // No confirmation popup, sale orders are content in a parameter list
            List<Map> saleOrderMap = (List<Map>) request.getContext().get(lineToMerge);
            for (Map map : saleOrderMap) {
                saleOrderIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, sale order's id are in a string separated by ","
            String saleOrderIdListStr = (String) request.getContext().get(lineToMerge);
            for (String saleOrderId : saleOrderIdListStr.split(",")) {
                saleOrderIdList.add(new Long(saleOrderId));
            }
            fromPopup = true;
        }
    }
    // Check if currency, clientPartner and company are the same for all selected
    // sale orders
    Currency commonCurrency = null;
    Partner commonClientPartner = null;
    Company commonCompany = null;
    Partner commonContactPartner = null;
    Team commonTeam = null;
    // Useful to determine if a difference exists between teams of all sale orders
    boolean existTeamDiff = false;
    // Useful to determine if a difference exists between contact partners of all
    // sale orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all sale
    // orders
    boolean existPriceListDiff = false;
    StockLocation commonLocation = null;
    // Useful to determine if a difference exists between stock locations of all
    // sale orders
    boolean existLocationDiff = false;
    SaleOrder saleOrderTemp;
    int count = 1;
    for (Long saleOrderId : saleOrderIdList) {
        saleOrderTemp = JPA.em().find(SaleOrder.class, saleOrderId);
        saleOrderList.add(saleOrderTemp);
        if (count == 1) {
            commonCurrency = saleOrderTemp.getCurrency();
            commonClientPartner = saleOrderTemp.getClientPartner();
            commonCompany = saleOrderTemp.getCompany();
            commonContactPartner = saleOrderTemp.getContactPartner();
            commonTeam = saleOrderTemp.getTeam();
            commonPriceList = saleOrderTemp.getPriceList();
            commonLocation = saleOrderTemp.getStockLocation();
        } else {
            if (commonCurrency != null && !commonCurrency.equals(saleOrderTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonClientPartner != null && !commonClientPartner.equals(saleOrderTemp.getClientPartner())) {
                commonClientPartner = null;
            }
            if (commonCompany != null && !commonCompany.equals(saleOrderTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(saleOrderTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonTeam != null && !commonTeam.equals(saleOrderTemp.getTeam())) {
                commonTeam = null;
                existTeamDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(saleOrderTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (commonLocation != null && !commonLocation.equals(saleOrderTemp.getStockLocation())) {
                commonLocation = null;
                existLocationDiff = true;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CURRENCY));
    }
    if (commonClientPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CLIENT_PARTNER));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_COMPANY));
    }
    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 (request.getContext().get("team") != null) {
        commonTeam = JPA.em().find(Team.class, new Long((Integer) ((Map) request.getContext().get("team")).get("id")));
    }
    if (request.getContext().get("stockLocation") != null) {
        commonLocation = JPA.em().find(StockLocation.class, new Long((Integer) ((Map) request.getContext().get("stockLocation")).get("id")));
    }
    if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existTeamDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge sale order").model(Wizard.class.getName()).add("form", "sale-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", commonClientPartner.getId().toString());
        }
        if (existTeamDiff) {
            confirmView.context("contextTeamToCheck", "true");
        }
        if (existLocationDiff) {
            confirmView.context("contextLocationToCheck", "true");
        }
        confirmView.context(lineToMerge, Joiner.on(",").join(saleOrderIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        SaleOrder saleOrder = Beans.get(SaleOrderCreateServiceSupplychainImpl.class).mergeSaleOrders(saleOrderList, commonCurrency, commonClientPartner, commonCompany, commonLocation, commonContactPartner, commonPriceList, commonTeam);
        if (saleOrder != null) {
            // Open the generated sale order in a new tab
            response.setView(ActionView.define("Sale order").model(SaleOrder.class.getName()).add("grid", "sale-order-grid").add("form", "sale-order-form").param("search-filters", "sale-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) SaleOrderCreateServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderCreateServiceSupplychainImpl) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) Team(com.axelor.team.db.Team) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard)

Example 84 with Partner

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

the class SaleOrderController method getSelectedId.

@SuppressWarnings("rawtypes")
private Map<String, Object> getSelectedId(ActionRequest request, ActionResponse response, SaleOrder saleOrder) throws AxelorException {
    Partner supplierPartner = null;
    List<Long> saleOrderLineIdSelected = new ArrayList<>();
    Map<String, Object> values = new HashMap<String, Object>();
    Boolean isDirectOrderLocation = false;
    Boolean noProduct = true;
    if (saleOrder.getDirectOrderLocation() && saleOrder.getStockLocation() != null && saleOrder.getStockLocation().getPartner() != null && saleOrder.getStockLocation().getPartner().getIsSupplier()) {
        values.put("supplierPartner", saleOrder.getStockLocation().getPartner());
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            if (saleOrderLine.isSelected()) {
                if (saleOrderLine.getProduct() != null) {
                    noProduct = false;
                }
                saleOrderLineIdSelected.add(saleOrderLine.getId());
            }
        }
        values.put("saleOrderLineIdSelected", saleOrderLineIdSelected);
        isDirectOrderLocation = true;
        values.put("isDirectOrderLocation", isDirectOrderLocation);
        if (saleOrderLineIdSelected.isEmpty() || noProduct) {
            throw new AxelorException(3, I18n.get(IExceptionMessage.SO_LINE_PURCHASE_AT_LEAST_ONE));
        }
    } else if (request.getContext().get("supplierPartnerSelect") != null) {
        supplierPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("supplierPartnerSelect")).get("id")));
        values.put("supplierPartner", supplierPartner);
        String saleOrderLineIdSelectedStr = (String) request.getContext().get("saleOrderLineIdSelected");
        for (String saleOrderId : saleOrderLineIdSelectedStr.split(",")) {
            saleOrderLineIdSelected.add(new Long(saleOrderId));
        }
        values.put("saleOrderLineIdSelected", saleOrderLineIdSelected);
        values.put("isDirectOrderLocation", isDirectOrderLocation);
    }
    return values;
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Partner(com.axelor.apps.base.db.Partner)

Example 85 with Partner

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

the class JobApplicationServiceImpl method createContact.

protected Partner createContact(JobApplication jobApplication) {
    Partner contact = new Partner();
    contact.setPartnerTypeSelect(2);
    contact.setFirstName(jobApplication.getFirstName());
    contact.setName(jobApplication.getLastName());
    contact.setIsContact(true);
    contact.setIsEmployee(true);
    contact.setFixedPhone(jobApplication.getFixedPhone());
    contact.setMobilePhone(jobApplication.getMobilePhone());
    contact.setEmailAddress(jobApplication.getEmailAddress());
    if (jobApplication.getPicture() != null) {
        File file = MetaFiles.getPath(jobApplication.getPicture()).toFile();
        try {
            contact.setPicture(metaFiles.upload(file));
        } catch (IOException e) {
            TraceBackService.trace(e);
        }
    }
    partnerService.setPartnerFullName(contact);
    return contact;
}
Also used : IOException(java.io.IOException) Partner(com.axelor.apps.base.db.Partner) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) DMSFile(com.axelor.dms.db.DMSFile)

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