use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method convertLead.
@SuppressWarnings("unchecked")
public void convertLead(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
Partner partner = createPartnerData(context);
Partner contactPartner = null;
if (partner != null) {
contactPartner = createContactData(context, partner);
}
try {
lead = Beans.get(LeadService.class).convertLead(lead, partner, contactPartner);
} catch (Exception e) {
TraceBackService.trace(e);
}
if (lead.getPartner() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONVERT_LEAD_ERROR));
}
openPartner(response, lead);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method createPartnerData.
@SuppressWarnings("unchecked")
private Partner createPartnerData(Context context) throws AxelorException {
Integer leadToPartnerSelect = (Integer) context.get("leadToPartnerSelect");
ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
Partner partner = null;
if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_CREATE_PARTNER) {
Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_PARTNER_MISSING_ADDRESS));
}
partner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("partner"), primaryAddress);
// TODO check all required fields...
} else if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_SELECT_PARTNER) {
Map<String, Object> selectPartnerContext = (Map<String, Object>) context.get("selectPartner");
partner = Beans.get(PartnerRepository.class).find(((Integer) selectPartnerContext.get("id")).longValue());
if (!partner.getIsCustomer()) {
partner.setIsProspect(true);
}
}
return partner;
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class MapRestCrm method getOpportunities.
@Path("/opportunity")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getOpportunities() {
ObjectNode mainNode = factory.objectNode();
try {
List<? extends Opportunity> opportunities = opportunityRepo.all().fetch();
ArrayNode arrayNode = factory.arrayNode();
for (Opportunity opportunity : opportunities) {
Partner partner = opportunity.getPartner();
if (partner == null) {
continue;
}
ObjectNode objectNode = factory.objectNode();
String currencyCode = "";
if (opportunity.getCurrency() != null) {
currencyCode = opportunity.getCurrency().getCode();
}
String amtLabel = "Amount";
if (!Strings.isNullOrEmpty(I18n.get("amount"))) {
amtLabel = I18n.get("amount");
}
String amount = amtLabel + " : " + opportunity.getAmount() + " " + currencyCode;
objectNode.put("fullName", opportunity.getName() + "<br/>" + amount);
objectNode.put("fixedPhone", partner.getFixedPhone() != null ? partner.getFixedPhone() : " ");
if (partner.getEmailAddress() != null) {
objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
}
Address address = Beans.get(PartnerService.class).getInvoicingAddress(partner);
if (address != null) {
String addressString = mapRestService.makeAddressString(address, objectNode);
objectNode.put("address", addressString);
}
objectNode.put("pinColor", "pink");
objectNode.put("pinChar", I18n.get(ITranslation.PIN_CHAR_OPPORTUNITY));
arrayNode.add(objectNode);
}
mapRestService.setData(mainNode, arrayNode);
} catch (Exception e) {
mapRestService.setError(mainNode, e);
}
return mainNode;
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class PartnerProductQualityRatingServiceImpl method undoCalculation.
@Override
@Transactional(rollbackOn = { Exception.class })
public void undoCalculation(StockMove stockMove) throws AxelorException {
Partner partner = stockMove.getPartner();
if (partner == null || !partner.getIsSupplier()) {
return;
}
List<StockMoveLine> stockMoveLines = stockMove.getStockMoveLineList();
if (stockMoveLines != null) {
for (StockMoveLine stockMoveLine : stockMoveLines) {
Product product = stockMoveLine.getProduct();
Optional<PartnerProductQualityRating> optional = searchPartnerProductQualityRating(partner, product);
if (optional.isPresent()) {
PartnerProductQualityRating partnerProductQualityRating = optional.get();
updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine, true);
}
}
}
updateSupplier(partner);
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class PartnerSaleController method displayValues.
public void displayValues(ActionRequest request, ActionResponse response) {
Partner customer = request.getContext().asType(Partner.class);
try {
customer = Beans.get(PartnerRepository.class).find(customer.getId());
SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
if (productList.isEmpty()) {
response.setAttr("$saleDetailsByProduct", "hidden", true);
return;
}
response.setAttr("$saleDetailsByProduct", "hidden", false);
HashMap<String, BigDecimal> qtyAndPrice;
for (Product product : productList) {
qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", product.getName());
map.put("$quantitySold", qtyAndPrice.get("qty"));
map.put("$totalPrice", qtyAndPrice.get("price"));
map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
saleDetailsByProduct.add(map);
}
response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations