📄 orderview.bsh
字号:
/*
* Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*@author Andy Zeneski (jaz@ofbiz.org)
*@version $Revision: 1.10 $
*@since 2.2
*/
import java.util.*;
import java.sql.Timestamp;
import org.ofbiz.entity.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.base.util.*;
import org.ofbiz.order.order.*;
import org.ofbiz.party.contact.*;
delegator = request.getAttribute("delegator");
security = request.getAttribute("security");
userLogin = session.getAttribute("userLogin");
orderId = request.getParameter("orderId");
if (orderId == null) {
orderId = request.getParameter("order_id");
}
context.put("orderId", orderId);
workEffortId = request.getParameter("workEffortId");
assignPartyId = request.getParameter("partyId");
assignRoleTypeId = request.getParameter("roleTypeId");
fromDate = request.getParameter("fromDate");
delegate = request.getParameter("delegate");
if (delegate != null && request.getParameter("toFromDate") != null) {
fromDate = request.getParameter("toFromDate");
}
context.put("workEffortId", workEffortId);
context.put("assignPartyId", assignPartyId);
context.put("assignRoleTypeId", assignRoleTypeId);
context.put("fromDate", fromDate);
context.put("delegate", delegate);
orderHeader = null;
if (orderId != null && orderId.length() > 0) {
orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
}
if (orderHeader != null) {
// set hasPermission, must always exist if the orderHeader != null
// hasPermission if: has ORDERMGR_VIEW, ORDERMGR_ROLE_VIEW & associated with order, or is associated in the SUPPLIER_AGENT role
hasPermission = false;
canViewInternalDetails = false;
if (security.hasEntityPermission("ORDERMGR", "_VIEW", session)) {
hasPermission = true;
canViewInternalDetails = true;
} else if (security.hasEntityPermission("ORDERMGR_ROLE", "_VIEW", session)) {
currentUserOrderRoles = orderHeader.getRelated("OrderRole", UtilMisc.toMap("partyId", userLogin.get("partyId")), null);
if (currentUserOrderRoles != null && currentUserOrderRoles.size() > 0) {
hasPermission = true;
canViewInternalDetails = true;
}
} else {
// regardless of permission, allow if this is the supplier
currentUserSupplierOrderRoles = orderHeader.getRelated("OrderRole", UtilMisc.toMap("partyId", userLogin.get("partyId"), "roleTypeId", "SUPPLIER_AGENT"), null);
if (currentUserSupplierOrderRoles != null && currentUserSupplierOrderRoles.size() > 0) {
hasPermission = true;
}
}
context.put("hasPermission", hasPermission);
context.put("canViewInternalDetails", canViewInternalDetails);
orderReadHelper = new OrderReadHelper(orderHeader);
orderItems = orderReadHelper.getValidOrderItems();
orderAdjustments = orderReadHelper.getAdjustments();
orderHeaderAdjustments = orderReadHelper.getOrderHeaderAdjustments();
orderSubTotal = orderReadHelper.getOrderItemsSubTotal();
context.put("orderHeader", orderHeader);
context.put("orderReadHelper", orderReadHelper);
context.put("orderItems", orderItems);
context.put("orderAdjustments", orderAdjustments);
context.put("orderHeaderAdjustments", orderHeaderAdjustments);
context.put("orderSubTotal", orderSubTotal);
context.put("currencyUomId", orderReadHelper.getCurrency());
// get the order type
orderType = orderHeader.getString("orderTypeId");
context.put("orderType", orderType);
// get the display party
displayParty = null;
if ("PURCHASE_ORDER".equals(orderType)) {
displayParty = orderReadHelper.getSupplierAgent();
} else {
displayParty = orderReadHelper.getPlacingParty();
}
if (displayParty != null) {
partyId = displayParty.getString("partyId");
context.put("displayParty", displayParty);
context.put("partyId", partyId);
}
otherAdjAmount = OrderReadHelper.calcOrderAdjustments(orderHeaderAdjustments, orderSubTotal, true, false, false);
context.put("otherAdjAmount", otherAdjAmount);
shippingAmount = OrderReadHelper.getAllOrderItemsAdjustmentsTotal(orderItems, orderAdjustments, false, false, true);
shippingAmount += OrderReadHelper.calcOrderAdjustments(orderHeaderAdjustments, orderSubTotal, false, false, true);
context.put("shippingAmount", shippingAmount);
taxAmount = OrderReadHelper.getAllOrderItemsAdjustmentsTotal(orderItems, orderAdjustments, false, true, false);
taxAmount += OrderReadHelper.calcOrderAdjustments(orderHeaderAdjustments, orderSubTotal, false, true, false);
context.put("taxAmount", taxAmount);
grandTotal = OrderReadHelper.getOrderGrandTotal(orderItems, orderAdjustments);
context.put("grandTotal", grandTotal);
orderItemList = orderReadHelper.getOrderItems();
context.put("orderItemList", orderItemList);
shippingAddress = orderReadHelper.getShippingAddress();
context.put("shippingAddress", shippingAddress);
billingAddress = orderReadHelper.getBillingAddress();
context.put("billingAddress", billingAddress);
distributorId = orderReadHelper.getDistributorId();
context.put("distributorId", distributorId);
affiliateId = orderReadHelper.getAffiliateId();
context.put("affiliateId", affiliateId);
billingAccount = orderHeader.getRelatedOne("BillingAccount");
context.put("billingAccount", billingAccount);
// get a list of all shipments, and a list of ItemIssuances per order item
allShipmentsMap = new HashMap();
primaryShipments = orderHeader.getRelated("PrimaryShipment");
primaryShipmentIter = primaryShipments.iterator();
while (primaryShipmentIter.hasNext()) {
primaryShipment = primaryShipmentIter.next();
allShipmentsMap.put(primaryShipment.get("shipmentId"), primaryShipment);
}
itemIssuancesPerItem = new HashMap();
itemIssuances = orderHeader.getRelated("ItemIssuance", null, UtilMisc.toList("shipmentId", "shipmentItemSeqId"));
itemIssuanceIter = itemIssuances.iterator();
while (itemIssuanceIter.hasNext()) {
itemIssuance = itemIssuanceIter.next();
if (!allShipmentsMap.containsKey(itemIssuance.get("shipmentId"))) {
iiShipment = itemIssuance.getRelatedOne("Shipment");
if (iiShipment != null) {
allShipmentsMap.put(iiShipment.get("shipmentId"), iiShipment);
}
}
perItemList = itemIssuancesPerItem.get(itemIssuance.get("orderItemSeqId"));
if (perItemList == null) {
perItemList = new LinkedList();
itemIssuancesPerItem.put(itemIssuance.get("orderItemSeqId"), perItemList);
}
perItemList.add(itemIssuance);
}
context.put("allShipments", allShipmentsMap.values());
context.put("itemIssuancesPerItem", itemIssuancesPerItem);
// get a list of all invoices
allInvoices = new OrderedSet();
orderBilling = delegator.findByAnd("OrderItemBilling", UtilMisc.toMap("orderId", orderId), UtilMisc.toList("invoiceId"));
obIter = orderBilling.iterator();
while (obIter.hasNext()) {
billingGv = obIter.next();
allInvoices.add(billingGv.getString("invoiceId"));
}
context.put("invoices", allInvoices);
oppFields = UtilMisc.toList(new EntityExpr("orderId", EntityOperator.EQUALS, orderId), new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PAYMENT_CANCELLED"));
orderPaymentPreferences = delegator.findByAnd("OrderPaymentPreference", oppFields);
context.put("orderPaymentPreferences", orderPaymentPreferences);
shipmentPreference = null;
carrierPartyId = null;
shipmentMethodTypeId = null;
shipmentMethodType = null;
shippingInstructions = null;
trackingNumber = null;
maySplit = null;
giftMessage = null;
isGift = null;
orderShipmentPreferences = UtilMisc.toIterator(orderHeader.getRelated("OrderShipmentPreference"));
if (orderShipmentPreferences != null && orderShipmentPreferences.hasNext()) {
shipmentPreference = (GenericValue)orderShipmentPreferences.next();
carrierPartyId = shipmentPreference.getString("carrierPartyId");
shipmentMethodTypeId = shipmentPreference.getString("shipmentMethodTypeId");
shipmentMethodType = delegator.findByPrimaryKey("ShipmentMethodType", UtilMisc.toMap("shipmentMethodTypeId", shipmentMethodTypeId));
shippingInstructions = shipmentPreference.getString("shippingInstructions");
trackingNumber = shipmentPreference.getString("trackingNumber");
maySplit = shipmentPreference.getString("maySplit");
giftMessage = shipmentPreference.getString("giftMessage");
isGift = shipmentPreference.getString("isGift");
}
context.put("shipmentPreference", shipmentPreference);
context.put("carrierPartyId", carrierPartyId);
context.put("shipmentMethodTypeId", shipmentMethodTypeId);
context.put("shipmentMethodType", shipmentMethodType);
context.put("shippingInstructions", shippingInstructions);
context.put("trackingNumber", trackingNumber);
context.put("maySplit", maySplit);
context.put("giftMessage", giftMessage);
context.put("isGift", isGift);
// get Shipment tracking info
osisCond = new EntityFieldMap(UtilMisc.toMap("orderId", orderId), EntityOperator.AND);
osisOrder = UtilMisc.toList("shipmentId", "shipmentRouteSegmentId", "shipmentPackageSeqId");
osisFields = UtilMisc.toList("shipmentId", "shipmentRouteSegmentId", "carrierPartyId", "shipmentMethodTypeId");
osisFields.add("shipmentPackageSeqId"); osisFields.add("trackingCode"); osisFields.add("boxNumber");
osisFindOptions = new EntityFindOptions(); osisFindOptions.setDistinct(true);
osisEli = delegator.findListIteratorByCondition("OrderShipmentInfoSummary", osisCond, null, osisFields, osisOrder, osisFindOptions);
orderShipmentInfoSummaryList = osisEli.getCompleteList();
osisEli.close();
context.put("orderShipmentInfoSummaryList", orderShipmentInfoSummaryList);
customerPoNumber = null;
orderItemPOIter = UtilMisc.toIterator(orderItemList);
if (orderItemPOIter != null && orderItemPOIter.hasNext()) {
customerPoNumber = ((GenericValue)orderItemPOIter.next()).getString("correspondingPoId");
}
context.put("customerPoNumber", customerPoNumber);
statusChange = delegator.findByAnd("StatusValidChange",UtilMisc.toMap("statusId",orderHeader.getString("statusId")));
context.put("statusChange", statusChange);
currentStatus = orderHeader.getRelatedOne("StatusItem");
context.put("currentStatus", currentStatus);
orderHeaderStatuses = orderReadHelper.getOrderHeaderStatuses();
context.put("orderHeaderStatuses", orderHeaderStatuses);
adjustmentTypes = delegator.findAll("OrderAdjustmentType", UtilMisc.toList("description"));
context.put("orderAdjustmentTypes", adjustmentTypes);
notes = delegator.findByAnd("OrderHeaderNoteView", UtilMisc.toMap("orderId", orderId), UtilMisc.toList("-noteDateTime"));
context.put("orderNotes", notes);
cmvm = ContactMechWorker.getOrderContactMechValueMaps(delegator, orderId);
context.put("orderContactMechValueMaps", cmvm);
}
paramString = "";
if (orderId != null) paramString = paramString + "order_id=" + orderId;
if (workEffortId != null) paramString = paramString + "&workEffortId=" + workEffortId;
if (assignPartyId != null) paramString = paramString + "&partyId=" + assignPartyId;
if (assignRoleTypeId != null) paramString = paramString + "&roleTypeId=" + assignRoleTypeId;
if (fromDate != null) paramString = paramString + "&fromDate=" + fromDate;
context.put("paramString", paramString);
workEffortStatus = null;
if (workEffortId != null && assignPartyId != null && assignRoleTypeId != null && fromDate != null) {
fields = UtilMisc.toMap("workEffortId", workEffortId, "partyId", assignPartyId, "roleTypeId", assignRoleTypeId, "fromDate", fromDate);
wepa = delegator.findByPrimaryKey("WorkEffortPartyAssignment", fields);
if (wepa != null && wepa.get("statusId") != null && wepa.getString("statusId").equals("CAL_ACCEPTED")) {
workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
workEffortStatus = workEffort.getString("currentStatusId");
if (workEffortStatus != null) {
context.put("workEffortStatus", workEffortStatus);
if (workEffortStatus.equals("WF_RUNNING") || workEffortStatus.equals("WF_SUSPENDED"))
context.put("inProcess", new Boolean(true));
}
if (workEffort != null) {
if ((delegate != null && delegate.equals("true")) || (workEffortStatus != null && workEffortStatus.equals("WF_RUNNING"))) {
actFields = UtilMisc.toMap("packageId", workEffort.getString("workflowPackageId"), "packageVersion", workEffort.getString("workflowPackageVersion"), "processId", workEffort.getString("workflowProcessId"), "processVersion", workEffort.getString("workflowProcessVersion"), "activityId", workEffort.getString("workflowActivityId"));
activity = delegator.findByPrimaryKey("WorkflowActivity", actFields);
if (activity != null) {
transitions = activity.getRelated("FromWorkflowTransition", null, UtilMisc.toList("-transitionId"));
context.put("wfTransitions", transitions);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -