⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            orderHeader.set("createdBy", userLogin.getString("userLoginId"));        }        // first try to create the OrderHeader; if this does not fail, continue.        try {            delegator.create(orderHeader);        } catch (GenericEntityException e) {            Debug.logError(e, "Cannot create OrderHeader entity; problems with insert", module);            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderOrderCreationFailedPleaseNotifyCustomerService",locale));        }        // create the order status record        String orderStatusSeqId = delegator.getNextSeqId("OrderStatus");        GenericValue orderStatus = delegator.makeValue("OrderStatus", UtilMisc.toMap("orderStatusId", orderStatusSeqId));        orderStatus.set("orderId", orderId);        orderStatus.set("statusId", orderHeader.getString("statusId"));        orderStatus.set("statusDatetime", nowTimestamp);        orderStatus.set("statusUserLogin", userLogin.getString("userLoginId"));        toBeStored.add(orderStatus);        // set the order items        Iterator oi = orderItems.iterator();        while (oi.hasNext()) {            GenericValue orderItem = (GenericValue) oi.next();            orderItem.set("orderId", orderId);            toBeStored.add(orderItem);            // create the item status record            String itemStatusId = delegator.getNextSeqId("OrderStatus");            GenericValue itemStatus = delegator.makeValue("OrderStatus", UtilMisc.toMap("orderStatusId", itemStatusId));            itemStatus.put("statusId", orderItem.get("statusId"));            itemStatus.put("orderId", orderId);            itemStatus.put("orderItemSeqId", orderItem.get("orderItemSeqId"));            itemStatus.put("statusDatetime", nowTimestamp);            itemStatus.set("statusUserLogin", userLogin.getString("userLoginId"));            toBeStored.add(itemStatus);        }        // set the order attributes        List orderAttributes = (List) context.get("orderAttributes");        if (orderAttributes != null && orderAttributes.size() > 0) {            Iterator oattr = orderAttributes.iterator();            while (oattr.hasNext()) {                GenericValue oatt = (GenericValue) oattr.next();                oatt.set("orderId", orderId);                toBeStored.add(oatt);            }        }        // set the order item attributes        List orderItemAttributes = (List) context.get("orderItemAttributes");        if (orderItemAttributes != null && orderItemAttributes.size() > 0) {            Iterator oiattr = orderItemAttributes.iterator();            while (oiattr.hasNext()) {                GenericValue oiatt = (GenericValue) oiattr.next();                oiatt.set("orderId", orderId);                toBeStored.add(oiatt);            }        }        // create the workeffort records        // and connect them with the orderitem over the WorkOrderItemFulfillment        // create also the techData calendars to keep track of availability of the fixed asset.        if (workEfforts != null && workEfforts.size() > 0) {            Iterator we = workEfforts.iterator();            while (we.hasNext()) {                // create the entity maps required.                GenericValue workEffort = (GenericValue) we.next();                GenericValue workOrderItemFulfillment = delegator.makeValue("WorkOrderItemFulfillment", null);                // find fixed asset supplied on the workeffort map                GenericValue fixedAsset = null;                Debug.logInfo("find the fixedAsset",module);                try { fixedAsset = delegator.findByPrimaryKey("FixedAsset",                        UtilMisc.toMap("fixedAssetId", workEffort.get("fixedAssetId")));                }                catch (GenericEntityException e) {                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderFixedAssetNotFoundFixedAssetId ", UtilMisc.toMap("fixedAssetId",workEffort.get("fixedAssetId")), locale));                }                if (fixedAsset == null) {                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderFixedAssetNotFoundFixedAssetId ", UtilMisc.toMap("fixedAssetId",workEffort.get("fixedAssetId")), locale));                }                // see if this fixed asset has a calendar, when no create one and attach to fixed asset                Debug.logInfo("find the techdatacalendar",module);                GenericValue techDataCalendar = null;                try { techDataCalendar = fixedAsset.getRelatedOne("TechDataCalendar");                }                catch (GenericEntityException e) {                    Debug.logInfo("TechData calendar does not exist yet so create for fixedAsset: " + fixedAsset.get("fixedAssetId") ,module);                }                if(techDataCalendar == null ) {                    techDataCalendar = delegator.makeValue("TechDataCalendar", null);                    Debug.logInfo("create techdata calendar because it does not exist",module);                    String calendarId = delegator.getNextSeqId("techDataCalendar").toString();                    techDataCalendar.set("calendarId", calendarId);                    toBeStored.add(techDataCalendar);                    Debug.logInfo("update fixed Asset",module);                    fixedAsset.set("calendarId",calendarId);                    toBeStored.add(fixedAsset);                }                // then create the workEffort and the workOrderItemFulfillment to connect to the order and orderItem                workOrderItemFulfillment.set("orderItemSeqId", workEffort.get("workEffortId").toString()); // orderItemSeqNo is stored here so save first                // workeffort                String workEffortId = delegator.getNextSeqId("WorkEffort").toString(); // find next available workEffortId                workEffort.set("workEffortId", workEffortId);                workEffort.set("workEffortTypeId", "ASSET_USAGE");                toBeStored.add(workEffort);  // store workeffort before workOrderItemFulfillment because of workEffortId key constraint                // workOrderItemFulfillment                workOrderItemFulfillment.set("workEffortId", workEffortId);                workOrderItemFulfillment.set("orderId", orderId);                toBeStored.add(workOrderItemFulfillment);//                Debug.logInfo("Workeffort "+ workEffortId + " created for asset " + workEffort.get("fixedAssetId") + " and order "+ workOrderItemFulfillment.get("orderId") + "/" + workOrderItemFulfillment.get("orderItemSeqId") + " created", module);//                // now create the TechDataExcDay, when they do not exist, create otherwise update the capacity values                // please note that calendarId is the same for (TechData)Calendar, CalendarExcDay and CalendarExWeek                Timestamp estimatedStartDate = workEffort.getTimestamp("estimatedStartDate");                Timestamp estimatedCompletionDate = workEffort.getTimestamp("estimatedCompletionDate");                long dayCount = (estimatedCompletionDate.getTime() - estimatedStartDate.getTime())/86400000;                while (--dayCount >= 0)    {                    GenericValue techDataCalendarExcDay = null;                    // find an existing Day exception record                    Timestamp exceptionDateStartTime = new Timestamp((long)(estimatedStartDate.getTime() + (dayCount * 86400000)));                    try {     techDataCalendarExcDay = delegator.findByPrimaryKey("TechDataCalendarExcDay",                            UtilMisc.toMap("calendarId", fixedAsset.get("calendarId"), "exceptionDateStartTime", exceptionDateStartTime));                    }                    catch (GenericEntityException e) {                        Debug.logInfo(" techData excday record not found so creating........", module);                    }                    if (techDataCalendarExcDay == null)    {                        techDataCalendarExcDay = delegator.makeValue("TechDataCalendarExcDay", null);                        techDataCalendarExcDay.set("calendarId", fixedAsset.get("calendarId"));                        techDataCalendarExcDay.set("exceptionDateStartTime", exceptionDateStartTime);                        techDataCalendarExcDay.set("usedCapacity",new Double(00.00));  // initialise to zero                        techDataCalendarExcDay.set("exceptionCapacity", fixedAsset.getDouble("productionCapacity"));//                       Debug.logInfo(" techData excday record not found creating for calendarId: " + techDataCalendarExcDay.getString("calendarId") +//                               " and date: " + exceptionDateStartTime.toString(), module);                    }                    // add the quantity to the quantity on the date record                    Double newUsedCapacity = new Double(techDataCalendarExcDay.getDouble("usedCapacity").doubleValue() +                            workEffort.getDouble("quantityToProduce").doubleValue());                    // check to see if the requested quantity is available on the requested day but only when the maximum capacity is set on the fixed asset                    if (fixedAsset.get("productionCapacity") != null)    {//                       Debug.logInfo("see if maximum not reached, available:  " + techDataCalendarExcDay.getString("exceptionCapacity") +//                               " already allocated: " + techDataCalendarExcDay.getString("usedCapacity") +//                                " Requested: " + workEffort.getString("quantityToProduce"), module);                       if (newUsedCapacity.compareTo(techDataCalendarExcDay.getDouble("exceptionCapacity")) > 0)    {                            String errMsg = "ERROR: fixed_Asset_sold_out AssetId: " + workEffort.get("fixedAssetId") + " on date: " + techDataCalendarExcDay.getString("exceptionDateStartTime");                            Debug.logError(errMsg, module);                            errorMessages.add(errMsg);                            continue;                        }                    }                    techDataCalendarExcDay.set("usedCapacity", newUsedCapacity);                    toBeStored.add(techDataCalendarExcDay);//                  Debug.logInfo("Update success CalendarID: " + techDataCalendarExcDay.get("calendarId").toString() +//                            " and for date: " + techDataCalendarExcDay.get("exceptionDateStartTime").toString() +//                            " and for quantity: " + techDataCalendarExcDay.getDouble("usedCapacity").toString(), module);                }            }        }        if (errorMessages.size() > 0) {            return ServiceUtil.returnError(errorMessages);        }        // set the orderId on all adjustments; this list will include order and        // item adjustments...        if (orderAdjustments != null && orderAdjustments.size() > 0) {            Iterator iter = orderAdjustments.iterator();            while (iter.hasNext()) {                GenericValue orderAdjustment = (GenericValue) iter.next();                try {                    orderAdjustment.set("orderAdjustmentId", delegator.getNextSeqId("OrderAdjustment"));                } catch (IllegalArgumentException e) {                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotGetNextSequenceIdForOrderAdjustmentCannotCreateOrder",locale));                }                orderAdjustment.set("orderId", orderId);                orderAdjustment.set("createdDate", UtilDateTime.nowTimestamp());                orderAdjustment.set("createdByUserLogin", userLogin.getString("userLoginId"));                if (orderAdjustment.get("orderItemSeqId") == null || orderAdjustment.getString("orderItemSeqId").length() == 0) {                    orderAdjustment.set("orderItemSeqId", DataModelConstants.SEQ_ID_NA);                }                if (orderAdjustment.get("shipGroupSeqId") == null || orderAdjustment.getString("shipGroupSeqId").length() == 0) {                    orderAdjustment.set("shipGroupSeqId", DataModelConstants.SEQ_ID_NA);                }                toBeStored.add(orderAdjustment);            }        }        // set the order contact mechs        List orderContactMechs = (List) context.get("orderContactMechs");        if (orderContactMechs != null && orderContactMechs.size() > 0) {            Iterator ocmi = orderContactMechs.iterator();            while (ocmi.hasNext()) {                GenericValue ocm = (GenericValue) ocmi.next();                ocm.set("orderId", orderId);                toBeStored.add(ocm);            }        }        // set the order item contact mechs        List orderItemContactMechs = (List) context.get("orderItemContactMechs");        if (orderItemContactMechs != null && orderItemContactMechs.size() > 0) {            Iterator oicmi = orderItemContactMechs.iterator();            while (oicmi.hasNext()) {                GenericValue oicm = (GenericValue) oicmi.next();                oicm.set("orderId", orderId);                toBeStored.add(oicm);            }        }        // set the order item ship groups        if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) {            Iterator osiInfos = orderItemShipGroupInfo.iterator();            while (osiInfos.hasNext()) {                GenericValue valueObj = (GenericValue) osiInfos.next();                valueObj.set("orderId", orderId);                if ("OrderItemShipGroup".equals(valueObj.getEntityName())) {                    // ship group                    if (valueObj.get("carrierRoleTypeId") == null) {                        valueObj.set("carrierRoleTypeId", "CARRIER");                    }                } else if ("OrderAdjustment".equals(valueObj.getEntityName())) {                    // shipping / tax adjustment(s)                    if (valueObj.get("orderItemSeqId") == null || valueObj.getString("orderItemSeqId").length() == 0) {                        valueObj.set("orderItemSeqId", DataModelConstants.SEQ_ID_NA);                    }                    valueObj.set("orderAdjustmentId", delegator.getNextSeqId("OrderAdjustment"));                    valueObj.set("createdDate", UtilDateTime.nowTimestamp());                    valueObj.set("createdByUserLogin", userLogin.getString("userLoginId"));                }                toBeStored.add(valueObj);            }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -