📄 orderservices.java
字号:
Debug.logError(e1, "Error calling countProductQuantityOrdered service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCallingCountProductQuantityOrderedService",locale) + e1.toString()); } } } if (!"PURCHASE_ORDER".equals(orderTypeId) && productStoreId == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorTheProductStoreIdCanOnlyBeNullForPurchaseOrders",locale)); } Iterator normalizedIter = normalizedItemQuantities.keySet().iterator(); while (normalizedIter.hasNext()) { // lookup the product entity for each normalized item; error on products not found String currentProductId = (String) normalizedIter.next(); Double currentQuantity = (Double) normalizedItemQuantities.get(currentProductId); String itemName = (String) normalizedItemNames.get(currentProductId); GenericValue product = null; try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", currentProductId)); } catch (GenericEntityException e) { String errMsg = UtilProperties.getMessage(resource, "product.not_found", new Object[] { currentProductId }, locale); Debug.logError(e, errMsg, module); errorMessages.add(errMsg); continue; } if (product == null) { String errMsg = UtilProperties.getMessage(resource, "product.not_found", new Object[] { currentProductId }, locale); Debug.logError(errMsg, module); errorMessages.add(errMsg); continue; } if ("SALES_ORDER".equals(orderTypeId)) { // check to see if introductionDate hasn't passed yet if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) { String excMsg = UtilProperties.getMessage(resource, "product.not_yet_for_sale", new Object[] { getProductName(product, itemName), product.getString("productId") }, locale); Debug.logWarning(excMsg, module); errorMessages.add(excMsg); continue; } } if ("SALES_ORDER".equals(orderTypeId)) { // check to see if salesDiscontinuationDate has passed if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) { String excMsg = UtilProperties.getMessage(resource, "product.no_longer_for_sale", new Object[] { getProductName(product, itemName), product.getString("productId") }, locale); Debug.logWarning(excMsg, module); errorMessages.add(excMsg); continue; } } if ("SALES_ORDER".equals(orderTypeId)) { // check to see if we have inventory available try { Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "quantity", currentQuantity)); if (ServiceUtil.isError(invReqResult)) { errorMessages.add(invReqResult.get(ModelService.ERROR_MESSAGE)); errorMessages.addAll((List) invReqResult.get(ModelService.ERROR_MESSAGE_LIST)); } else if (!"Y".equals((String) invReqResult.get("availableOrNotRequired"))) { String invErrMsg = UtilProperties.getMessage(resource, "product.out_of_stock", new Object[] { getProductName(product, itemName), currentProductId }, locale); Debug.logWarning(invErrMsg, module); errorMessages.add(invErrMsg); continue; } } catch (GenericServiceException e) { String errMsg = "Fatal error calling inventory checking services: " + e.toString(); Debug.logError(e, errMsg, module); errorMessages.add(errMsg); } } } // add the fixedAsset id to the workefforts map by obtaining the fixed Asset number from the FixedAssetProduct table List workEfforts = (List) context.get("workEfforts"); // is an optional parameter from this service but mandatory for rental items Iterator orderItemIter = orderItems.iterator(); while (orderItemIter.hasNext()) { GenericValue orderItem = (GenericValue) orderItemIter.next(); if ("RENTAL_ORDER_ITEM".equals(orderItem.getString("orderItemTypeId"))) { // check to see if workefforts are available for this order type. if (workEfforts == null || workEfforts.size() == 0) { String errMsg = "Work Efforts missing for ordertype RENTAL_ORDER_ITEM " + "Product: " + orderItem.getString("productId"); Debug.logError(errMsg, module); errorMessages.add(errMsg); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderRentalOrderItems",locale)); } Iterator we = workEfforts.iterator(); // find the related workEffortItem (workEffortId = orderSeqId) while (we.hasNext()) { // create the entity maps required. GenericValue workEffort = (GenericValue) we.next(); if (workEffort.getString("workEffortId").equals(orderItem.getString("orderItemSeqId"))) { List selFixedAssetProduct = null; try { List allFixedAssetProduct = delegator.findByAnd("FixedAssetProduct",UtilMisc.toMap("productId",orderItem.getString("productId"),"fixedAssetProductTypeId", "FAPT_USE")); selFixedAssetProduct = EntityUtil.filterByDate(allFixedAssetProduct, nowTimestamp, "fromDate", "thruDate", true); } catch (GenericEntityException e) { String excMsg = "Could not find related Fixed Asset for the product: " + orderItem.getString("productId"); Debug.logError(excMsg, module); errorMessages.add(excMsg); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCouldNotFindRelatedFixedAssetForTheProduct",UtilMisc.toMap("productId",orderItem.getString("productId")), locale )); } if (selFixedAssetProduct != null && selFixedAssetProduct.size() > 0) { Iterator firstOne = selFixedAssetProduct.iterator(); if(firstOne.hasNext()) { GenericValue fixedAssetProduct = delegator.makeValue("FixedAssetProduct", null); fixedAssetProduct = (GenericValue) firstOne.next(); workEffort.set("fixedAssetId",fixedAssetProduct.get("fixedAssetId")); workEffort.set("quantityToProduce",orderItem.get("quantity")); // have quantity easy available later... } } break; // item found, so go to next orderitem. } } } } if (errorMessages.size() > 0) { return ServiceUtil.returnError(errorMessages); } // the inital status for ALL order types String initialStatus = "ORDER_CREATED"; successResult.put("statusId", initialStatus); // create the order object String orderId = null; String orgPartyId = null; if (productStore != null) { orgPartyId = productStore.getString("payToPartyId"); } else if (billFromVendorPartyId != null) { orgPartyId = billFromVendorPartyId; } if (UtilValidate.isNotEmpty(orgPartyId)) { Map getNextOrderIdContext = UtilMisc.toMap("partyId", orgPartyId, "userLogin", userLogin); if ((orderTypeId.equals("SALES_ORDER")) || (productStoreId != null)) { getNextOrderIdContext.put("productStoreId", productStoreId); } try { Map getNextOrderIdResult = dispatcher.runSync("getNextOrderId", getNextOrderIdContext); if (ServiceUtil.isError(getNextOrderIdResult)) { return ServiceUtil.returnError("Error getting next orderId while creating order", null, null, getNextOrderIdResult); } orderId = (String) getNextOrderIdResult.get("orderId"); } catch (GenericServiceException e) { String errMsg = "Error creating order while getting orderId: " + e.toString(); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } } if (UtilValidate.isEmpty(orderId)) { // for purchase orders or when other orderId generation fails, a product store id should not be required to make an order orderId = delegator.getNextSeqId("OrderHeader"); } String billingAccountId = (String) context.get("billingAccountId"); Timestamp orderDate = (Timestamp) context.get("orderDate"); if (orderDate == null) { orderDate = nowTimestamp; } Map orderHeaderMap = UtilMisc.toMap("orderId", orderId, "orderTypeId", orderTypeId, "orderDate", orderDate, "entryDate", nowTimestamp, "statusId", initialStatus, "billingAccountId", billingAccountId); if (isImmediatelyFulfilled) { // also flag this order as needing inventory issuance so that when it is set to complete it will be issued immediately (needsInventoryIssuance = Y) orderHeaderMap.put("needsInventoryIssuance", "Y"); } GenericValue orderHeader = delegator.makeValue("OrderHeader", orderHeaderMap); // determine the sales channel String salesChannelEnumId = (String) context.get("salesChannelEnumId"); if ((salesChannelEnumId == null) || salesChannelEnumId.equals("UNKNWN_SALES_CHANNEL")) { // try the default store sales channel if (orderTypeId.equals("SALES_ORDER") && (productStore != null)) { salesChannelEnumId = productStore.getString("defaultSalesChannelEnumId"); } // if there's still no channel, set to unknown channel if (salesChannelEnumId == null) { salesChannelEnumId = "UNKNWN_SALES_CHANNEL"; } } orderHeader.set("salesChannelEnumId", salesChannelEnumId); if (context.get("currencyUom") != null) { orderHeader.set("currencyUom", context.get("currencyUom")); } if (context.get("firstAttemptOrderId") != null) { orderHeader.set("firstAttemptOrderId", context.get("firstAttemptOrderId")); } if (context.get("grandTotal") != null) { orderHeader.set("grandTotal", context.get("grandTotal")); } if (UtilValidate.isNotEmpty((String) context.get("visitId"))) { orderHeader.set("visitId", context.get("visitId")); } if (UtilValidate.isNotEmpty((String) context.get("internalCode"))) { orderHeader.set("internalCode", context.get("internalCode")); } if (UtilValidate.isNotEmpty((String) context.get("externalId"))) { orderHeader.set("externalId", context.get("externalId")); } if (UtilValidate.isNotEmpty((String) context.get("originFacilityId"))) { orderHeader.set("originFacilityId", context.get("originFacilityId")); } if (UtilValidate.isNotEmpty((String) context.get("productStoreId"))) { orderHeader.set("productStoreId", context.get("productStoreId")); } if (UtilValidate.isNotEmpty((String) context.get("transactionId"))) { orderHeader.set("transactionId", context.get("transactionId")); } if (UtilValidate.isNotEmpty((String) context.get("terminalId"))) { orderHeader.set("terminalId", context.get("terminalId")); } if (UtilValidate.isNotEmpty((String) context.get("webSiteId"))) { orderHeader.set("webSiteId", context.get("webSiteId")); } if (userLogin != null && userLogin.get("userLoginId") != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -