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

📄 orderstatus.bsh

📁 国外的一套开源CRM
💻 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
 *@version    $Revision: 1.10 $
 *@since      2.1
*/

import org.ofbiz.base.util.*;
import org.ofbiz.entity.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.accounting.payment.*;
import org.ofbiz.order.order.*;
import org.ofbiz.party.contact.*;
import org.ofbiz.product.catalog.*;
import org.ofbiz.product.store.*;

delegator = request.getAttribute("delegator");
userLogin = session.getAttribute("userLogin"); 
orderId = request.getParameter("order_id");
if (orderId == null)
    orderId = request.getAttribute("order_id");
orderHeader = null;

if (orderId != null && orderId.length() > 0) {
  orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
  if (orderHeader != null) {      
      orderRole = delegator.findByPrimaryKey("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", userLogin.getString("partyId"), "roleTypeId", "PLACING_CUSTOMER"));
      if (orderRole == null) {
          context.remove("orderHeader");
          orderHeader = null;
      }
  }
}

if (orderHeader != null) {
    //context.put("orderHeader", orderHeader);   
    orderReadHelper = new OrderReadHelper(orderHeader);
    orderItems = orderReadHelper.getOrderItems();
    orderAdjustments = orderReadHelper.getAdjustments();
    orderHeaderAdjustments = orderReadHelper.getOrderHeaderAdjustments();
    orderSubTotal = orderReadHelper.getOrderItemsSubTotal();
    headerAdjustmentsToShow = orderReadHelper.getOrderHeaderAdjustmentsToShow();

	context.put("orderId", orderId);
    context.put("orderHeader", orderHeader);
    context.put("localOrderReadHelper", orderReadHelper);
    context.put("orderItems", orderReadHelper.getOrderItems());
    context.put("orderAdjustments", orderAdjustments);
    context.put("orderHeaderAdjustments", orderHeaderAdjustments);
    context.put("orderSubTotal", orderSubTotal);
    context.put("headerAdjustmentsToShow", headerAdjustmentsToShow);
    context.put("currencyUomId", orderReadHelper.getCurrency());
    
    shippingAmount = OrderReadHelper.getAllOrderItemsAdjustmentsTotal(orderItems, orderAdjustments, false, false, true);
    shippingAmount += OrderReadHelper.calcOrderAdjustments(orderHeaderAdjustments, orderSubTotal, false, false, true);
    context.put("orderShippingTotal", shippingAmount);

    taxAmount = OrderReadHelper.getAllOrderItemsAdjustmentsTotal(orderItems, orderAdjustments, false, true, false);
    taxAmount += OrderReadHelper.calcOrderAdjustments(orderHeaderAdjustments, orderSubTotal, false, true, false);
    context.put("orderTaxTotal", taxAmount);   
    context.put("orderGrandTotal", OrderReadHelper.getOrderGrandTotal(orderItems, orderAdjustments));
    
    placingCustomerOrderRoles = delegator.findByAnd("OrderRole",UtilMisc.toMap("orderId", orderId, "roleTypeId", "PLACING_CUSTOMER"));
    placingCustomerOrderRole = EntityUtil.getFirst(placingCustomerOrderRoles);        
    placingCustomerPerson = placingCustomerOrderRole == null ? null : delegator.findByPrimaryKey("Person",UtilMisc.toMap("partyId", placingCustomerOrderRole.getString("partyId")));
    context.put("placingCustomerPerson", placingCustomerPerson);

    shippingAddress = orderReadHelper.getShippingAddress();
    context.put("shippingAddress", shippingAddress);
    billingAccount = orderHeader.getRelatedOne("BillingAccount");
    if (billingAccount != null)
        context.put("billingAccount", billingAccount);
  
    orderPaymentPreferences = UtilMisc.toIterator(orderHeader.getRelated("OrderPaymentPreference"));
    if (orderPaymentPreferences != null) {
        paymentMethods = new ArrayList();
        while (orderPaymentPreferences.hasNext()) {
            opp = orderPaymentPreferences.next();
            paymentMethod = opp.getRelatedOne("PaymentMethod");
            if (paymentMethod != null) {
                paymentMethods.add(paymentMethod);
            } else {
                paymentMethodType = opp.getRelatedOne("PaymentMethodType");
                if (paymentMethodType != null) {
                    context.put("paymentMethodType", paymentMethodType);
                }
            }
        }
        context.put("paymentMethods", paymentMethods);
    }

    webSiteId = CatalogWorker.getWebSiteId(request);
    
    productStore = ProductStoreWorker.getProductStore(request);
    payToPartyId = productStore.getString("payToPartyId");
    paymentAddress =  PaymentWorker.getPaymentAddress(delegator, payToPartyId);    
    if (paymentAddress != null) context.put("paymentAddress", paymentAddress);  
       
    orderShipmentPreferences = UtilMisc.toIterator(orderHeader.getRelated("OrderShipmentPreference"));
    if (orderShipmentPreferences != null && orderShipmentPreferences.hasNext()) {
        shipmentPreference = orderShipmentPreferences.next();
        context.put("carrierPartyId", shipmentPreference.getString("carrierPartyId"));
        context.put("shipmentMethodTypeId", shipmentPreference.getString("shipmentMethodTypeId"));       
        shipmentMethodType = delegator.findByPrimaryKey("ShipmentMethodType", UtilMisc.toMap("shipmentMethodTypeId", shipmentPreference.getString("shipmentMethodTypeId")));
        context.put("shipMethDescription", shipmentMethodType.getString("description"));       
        context.put("shippingInstructions", shipmentPreference.getString("shippingInstructions"));
        context.put("maySplit", shipmentPreference.getBoolean("maySplit"));
        context.put("giftMessage", shipmentPreference.getString("giftMessage"));
        context.put("isGift", shipmentPreference.getBoolean("isGift"));
        context.put("trackingNumber", shipmentPreference.getString("trackingNumber"));
    }
    
    // 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(orderItems);
    if (orderItemPOIter != null && orderItemPOIter.hasNext()) {
        orderItemPo = orderItemPOIter.next();
        context.put("customerPoNumber", orderItemPo.getString("correspondingPoId"));
    }
    
    // check if there are returnable items
    returned = 0.00;
    totalItems = 0.00;    
    oii = orderItems.iterator();
    while (oii.hasNext()) {
        oitem = oii.next();
        totalItems += oitem.getDouble("quantity").doubleValue();
        ritems = oitem.getRelated("ReturnItem");
        if (ritems != null) {
            rii = ritems.iterator();
            while (rii.hasNext()) {
                ritem = rii.next();
                rh = ritem.getRelatedOne("ReturnHeader");
                if (!rh.getString("statusId").equals("RETURN_CANCELLED")) {
	                returned += ritem.getDouble("returnQuantity").doubleValue();
	            }
            }           
        }
    }
    if (totalItems > returned) {
        context.put("returnLink", "Y");
    }    
}

⌨️ 快捷键说明

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