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

📄 findreturn.bsh

📁 国外的一套开源CRM
💻 BSH
字号:
/*
 *  Copyright (c) 2001-2004 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.3 $
 *@since      3.0
 */

import java.util.*;
import java.sql.Timestamp;
import org.ofbiz.base.util.*;
import org.ofbiz.entity.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.entity.condition.*;

delegator = request.getAttribute("delegator");

// get the return statuses
returnStatuses = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", "ORDER_RETURN_STTS"), UtilMisc.toList("sequenceId", "description"));
context.put("returnStatuses", returnStatuses);

// current selected status
currentStatusId = request.getParameter("returnStatusId");
if (currentStatusId != null && currentStatusId.length() > 0) {
    currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", currentStatusId));
    context.put("currentStatus", currentStatus);
}

// create the fromDate for calendar
fromCal = Calendar.getInstance();
fromCal.setTime(new java.util.Date());
//fromCal.set(Calendar.DAY_OF_WEEK, fromCal.getActualMinimum(Calendar.DAY_OF_WEEK));
fromCal.set(Calendar.HOUR_OF_DAY, fromCal.getActualMinimum(Calendar.HOUR_OF_DAY));
fromCal.set(Calendar.MINUTE, fromCal.getActualMinimum(Calendar.MINUTE));
fromCal.set(Calendar.SECOND, fromCal.getActualMinimum(Calendar.SECOND));
fromCal.set(Calendar.MILLISECOND, fromCal.getActualMinimum(Calendar.MILLISECOND));
fromTs = new Timestamp(fromCal.getTimeInMillis());
fromStr = fromTs.toString();
fromStr = fromStr.substring(0, fromStr.indexOf('.'));
context.put("fromDateStr", fromStr);

// create the thruDate for calendar
toCal = Calendar.getInstance();
toCal.setTime(new java.util.Date());
//toCal.set(Calendar.DAY_OF_WEEK, toCal.getActualMaximum(Calendar.DAY_OF_WEEK));
toCal.set(Calendar.HOUR_OF_DAY, toCal.getActualMaximum(Calendar.HOUR_OF_DAY));
toCal.set(Calendar.MINUTE, toCal.getActualMaximum(Calendar.MINUTE));
toCal.set(Calendar.SECOND, toCal.getActualMaximum(Calendar.SECOND));
toCal.set(Calendar.MILLISECOND, toCal.getActualMaximum(Calendar.MILLISECOND));
toTs = new Timestamp(toCal.getTimeInMillis());
toStr = toTs.toString();
context.put("thruDateStr", toStr);

// set the page parameters
viewIndex = 1;
try {
    viewIndex = Integer.valueOf((String) request.getParameter("VIEW_INDEX")).intValue();
} catch (Exception e) {
    viewIndex = 1;
}
context.put("viewIndex", viewIndex);

viewSize = 20;
try {
    viewSize = Integer.valueOf((String) request.getParameter("VIEW_SIZE")).intValue();
} catch (Exception e) {
    viewSize = 20;
}
context.put("viewSize", viewSize);

// get the lookup flag
lookupFlag = request.getParameter("lookupFlag");

// blank param list
paramList = "";

returnHeaderList = null;
returnHeaderListSize = 0;
lowIndex = 0;
highIndex = 0;

if (lookupFlag != null) {
    showAll = request.getParameter("showAll") != null ? request.getParameter("showAll") : "N";
    paramList = paramList + "&lookupFlag=" + lookupFlag + "&showAll=" + showAll;

    // the lookup entity name
    entityName = "ReturnHeader";
    lookupErrorMessage = null;

    // define the main condition & expression list
    andExprs = new ArrayList();
    mainCond = null;

    // check for a returnId (happens in some browsers)
    returnId = request.getParameter("returnId");
    if (returnId != null && returnId.length() > 0) {
        paramList = paramList + "&returnId=" + returnId;
        andExprs.add(new EntityExpr("returnId", EntityOperator.EQUALS, returnId));
    }

    // find the returns for party
    partyId = request.getParameter("partyId");
    userLoginId = request.getParameter("userLoginId");
    if (userLoginId != null && userLoginId.length() > 0) {
        requestedUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId));
        if (requestedUserLogin != null) {
            partyId = requestedUserLogin.getString("partyId");
        } else {
            lookupErrorMessage = "No userLogin found for userLoginId: " + userLoginId;
        }
    }

    if (partyId != null && partyId.length() > 0) {
        paramList = paramList + "&partyId=" + partyId;
        andExprs.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
    }

    // filter on billing account
    billAcct = request.getParameter("billingAccountId");
    if (billAcct != null && billAcct.length() > 0) {
        paramList = paramList + "&billingAccountId=" + billAcct;
        andExprs.add(new EntityExpr("billingAccountId", EntityOperator.EQUALS, billAcct));
    }

    // filter on status
    returnStatus = request.getParameter("returnStatusId");
    if (!"ANY".equals(returnStatus)) {
        paramList = paramList + "&returnStatusId=" + returnStatus;
        andExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, returnStatus));
    }

    // filter on date
    minDate = request.getParameter("minDate");
    if (minDate != null && minDate.length() > 8) {
        minDate = minDate.trim();
        if (minDate.length() < 14) minDate = minDate + " " + "00:00:00.000";
        paramList = paramList + "&minDate=" + minDate;
        andExprs.add(new EntityExpr("entryDate", EntityOperator.GREATER_THAN_EQUAL_TO, ObjectType.simpleTypeConvert(minDate, "Timestamp", null, null)));
    }
    maxDate = request.getParameter("maxDate");
    if (maxDate != null && maxDate.length() > 8) {
        maxDate = maxDate.trim();
        if (maxDate.length() < 14) maxDate = maxDate + " " + "23:59:59.999";
        paramList = paramList + "&maxDate=" + maxDate;
        andExprs.add(new EntityExpr("entryDate", EntityOperator.LESS_THAN_EQUAL_TO, ObjectType.simpleTypeConvert(maxDate, "Timestamp", null, null)));
    }

    Debug.log("Find return exprs : " + andExprs);

    // build the main condition
    if (andExprs.size() > 0 || showAll.equalsIgnoreCase("Y")) mainCond = new EntityConditionList(andExprs, EntityOperator.AND);

    // do the lookup
    if (lookupErrorMessage == null && mainCond != null) {
        // sorting by return entry date newest first
        List orderBy = UtilMisc.toList("-entryDate");

        // set distinct on so we only get one row per order
        EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);

        // using list iterator
        EntityListIterator orli = delegator.findListIteratorByCondition(entityName, mainCond, null, null, orderBy, findOpts);

        // get the indexes for the partial list
        lowIndex = (((viewIndex - 1) * viewSize) + 1);
        highIndex = viewIndex * viewSize;

        // attempt to get the full size
        orli.last();
        returnHeaderListSize = orli.currentIndex();
        if (highIndex > returnHeaderListSize) {
            highIndex = returnHeaderListSize;
        }

        // get the partial list for this page
        orli.first();
        if (returnHeaderListSize > 0) {
            returnHeaderList = orli.getPartialList(lowIndex, viewSize);
        } else {
            returnHeaderList = new ArrayList();
        }

        // close the list iterator
        orli.close();
    } else {
        returnHeaderList = new ArrayList();
        returnHeaderListSize = 0;
    }

    context.put("returnHeaderList", returnHeaderList);
    context.put("returnHeaderListSize", returnHeaderListSize);

    if (lookupErrorMessage != null) {
        context.put("lookupErrorMessage", lookupErrorMessage);
    }
}

context.put("paramList", paramList);
context.put("highIndex", highIndex);
context.put("lowIndex", lowIndex);

⌨️ 快捷键说明

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