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

📄 receiveinventory.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 (jaz@ofbiz.org)
 *@version    $Revision: 1.6 $
 *@since      2.2
 */
 
import org.ofbiz.entity.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.base.util.*;

delegator = request.getAttribute("delegator");
facilityId = request.getParameter("facilityId"); 
purchaseOrderId = request.getParameter("purchaseOrderId");
productId = request.getParameter("productId");
shipmentId = request.getParameter("shipmentId");

facility = null;
if (facilityId != null) {
    facility = delegator.findByPrimaryKey("Facility", UtilMisc.toMap("facilityId", facilityId));
}

purchaseOrder = null;
if (purchaseOrderId != null && purchaseOrderId.length() > 0) {
    purchaseOrder = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", purchaseOrderId));
    if (purchaseOrder != null && !"PURCHASE_ORDER".equals(purchaseOrder.getString("orderTypeId"))) {
        purchaseOrder = null;
    }
}

product = null;
if (productId != null) {  
    product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));      
}

shipments = null;
if (purchaseOrder != null && shipmentId == null) {
    issuances = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("orderId", purchaseOrderId));    
    if (issuances != null) {
        shipments = new TreeSet();
        issueIter = issuances.iterator();
        while (issueIter.hasNext()) {
            issuance = issueIter.next();
            shipment = issuance.getRelatedOne("Shipment");
            shipments.add(shipment);
        }        
    }
}

shipment = null;
if (shipmentId != null && !shipmentId.equals("_NA_")) {
    shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
}

shippedQuantities = new HashMap();
purchaseOrderItems = null;
if (purchaseOrder != null) {
    if (product != null) {
        purchaseOrderItems = purchaseOrder.getRelated("OrderItem", UtilMisc.toMap("productId", productId), null);
    } else if (shipment != null) {
        orderItems = purchaseOrder.getRelated("OrderItem");
        issuances = shipment.getRelated("ItemIssuance", UtilMisc.toMap("orderId", purchaseOrderId), null);
        issueIter = issuances.iterator();
        exprs = new ArrayList();
        while (issueIter.hasNext()) {
            issuance = issueIter.next();
            exprs.add(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, issuance.getString("orderItemSeqId")));
            double issuanceQty = issuance.getDouble("quantity").doubleValue();
            if (shippedQuantities.containsKey(issuance.getString("orderItemSeqId"))) {
                issuanceQty += ((Double)shippedQuantities.get(issuance.getString("orderItemSeqId"))).doubleValue();
            }
            shippedQuantities.put(issuance.getString("orderItemSeqId"), issuanceQty);
        }               
        purchaseOrderItems = EntityUtil.filterByOr(orderItems, exprs);
    } else {    
        purchaseOrderItems = purchaseOrder.getRelated("OrderItem");
    }
}
receivedQuantities = new HashMap();
if (purchaseOrderItems != null && purchaseOrderItems.size() > 0) {
    context.put("firstOrderItem", EntityUtil.getFirst(purchaseOrderItems));
    context.put("purchaseOrderItemsSize", purchaseOrderItems.size());
    itemsIter = purchaseOrderItems.iterator();
    while (itemsIter.hasNext()) {
        totalReceived = 0.0;
        thisItem = itemsIter.next();
        receipts = thisItem.getRelated("ShipmentReceipt");
        if (receipts != null && receipts.size() > 0) {
            recIter = receipts.iterator();
            while (recIter.hasNext()) {
                rec = recIter.next();
                if (shipment != null) {
                    if (rec.getString("shipmentId") == null || 
                        !rec.getString("shipmentId").equals(shipment.getString("shipmentId"))) {
                        continue;
                    }
                }
                accepted = rec.getDouble("quantityAccepted");
                rejected = rec.getDouble("quantityRejected");
                if (accepted != null)
                    totalReceived += accepted.doubleValue();
                if (rejected != null)
                    totalReceived += rejected.doubleValue();                                            
            }            
        }
        receivedQuantities.put(thisItem.getString("orderItemSeqId"), new Double(totalReceived));        
    }
}

receivedItems = null;
if (purchaseOrder != null) {
    receivedItems = delegator.findByAnd("ShipmentReceipt", UtilMisc.toMap("orderId", purchaseOrderId));
    context.put("receivedItems", receivedItems);
}

String invalidProductId = null;
if (productId != null && productId.length() > 0 && product == null) {
    invalidProductId = "No product found with product ID: [" + productId + "]";
    context.put("invalidProductId", invalidProductId);
}

// reject reasons
rejectReasons = delegator.findAll("RejectionReason");

// inv item types
inventoryItemTypes = delegator.findAll("InventoryItemType");

// facilities
facilities = delegator.findAll("Facility");
    
context.put("facilityId", facilityId);
context.put("facility", facility);
context.put("purchaseOrder", purchaseOrder);
context.put("product", product);
context.put("shipments", shipments);
context.put("shipment", shipment);
context.put("shippedQuantities", shippedQuantities);
context.put("purchaseOrderItems", purchaseOrderItems);
context.put("receivedQuantities", receivedQuantities);
context.put("rejectReasons", rejectReasons);
context.put("inventoryItemTypes", inventoryItemTypes);
context.put("facilities", facilities);
    

⌨️ 快捷键说明

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