Couple of script cleanups

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@667321 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Scott Gray
2008-06-13 03:17:38 +00:00
parent 48efd1ded8
commit 5e72bbacc3
3 changed files with 75 additions and 109 deletions
@@ -25,25 +25,22 @@ import java.sql.Timestamp;
import java.text.*;
// The view mode - Day, Week, or Month
String viewMode = parameters.get("viewMode");
if (UtilValidate.isEmpty(viewMode)) {
viewMode = "W";
parameters.put("viewMode", viewMode);
}
viewMode = parameters.viewMode ?: "W";
parameters.viewMode = viewMode;
// Prepare vars for mode-specific date calculations
String startParam = parameters.get("start");
if(startParam == null) {
startParam = parameters.start;
if(!startParam) {
start = nowTimestamp.clone();
} else {
start = new Timestamp(Long.parseLong(startParam));
}
int numPeriods = 24;
int periodType = Calendar.HOUR;
Timestamp getFrom = null;
Timestamp prev = null;
Timestamp next = null;
Timestamp end = null;
numPeriods = 24;
periodType = Calendar.HOUR;
getFrom = null;
prev = null;
next = null;
end = null;
if ("D".equals(viewMode)) {
// Day view
@@ -55,22 +52,22 @@ if ("D".equals(viewMode)) {
// Week view
start = UtilDateTime.getWeekStart(start, timeZone, locale);
getFrom = new Timestamp(start.getTime());
prev = UtilDateTime.getDayStart(start,-7, timeZone, locale);
next = UtilDateTime.getDayStart(start,7, timeZone, locale);
prev = UtilDateTime.getDayStart(start, -7, timeZone, locale);
next = UtilDateTime.getDayStart(start, 7, timeZone, locale);
end = UtilDateTime.getDayStart(start,6, timeZone, locale);
numPeriods = 7;
periodType = Calendar.DATE;
} else {
// Month view
start = UtilDateTime.getMonthStart(start, timeZone, locale);
Calendar tempCal = UtilDateTime.toCalendar(start, timeZone, locale);
int firstWeekNum = tempCal.get(Calendar.WEEK_OF_YEAR);
globalContext.put("firstWeekNum", new Integer(firstWeekNum));
tempCal = UtilDateTime.toCalendar(start, timeZone, locale);
firstWeekNum = tempCal.get(Calendar.WEEK_OF_YEAR);
globalContext.firstWeekNum = firstWeekNum;
numPeriods = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
prev = UtilDateTime.getDayStart(start, -1, timeZone, locale);
next = UtilDateTime.getDayStart(start, numPeriods+1, timeZone, locale);
end = UtilDateTime.getDayStart(start, numPeriods, timeZone, locale);
int prevMonthDays = tempCal.get(Calendar.DAY_OF_WEEK) - tempCal.getFirstDayOfWeek();
prevMonthDays = tempCal.get(Calendar.DAY_OF_WEEK) - tempCal.getFirstDayOfWeek();
if (prevMonthDays < 0) {
prevMonthDays = 7 + prevMonthDays;
}
@@ -78,23 +75,23 @@ if ("D".equals(viewMode)) {
numPeriods += prevMonthDays;
getFrom = new Timestamp(tempCal.getTimeInMillis());
periodType = Calendar.DATE;
globalContext.put("end", end);
globalContext.end = end;
}
List entityExprList = UtilMisc.toList(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"),
EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"), EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_MAINTENANCE"));
String fixedAssetId = parameters.get("fixedAssetId");
if (UtilValidate.isNotEmpty(fixedAssetId)) {
entityExprList = [EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"),
EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"), EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_MAINTENANCE")];
fixedAssetId = parameters.fixedAssetId;
if (fixedAssetId) {
entityExprList.add(EntityCondition.makeCondition("fixedAssetId", EntityOperator.EQUALS, fixedAssetId));
globalContext.put("fixedAssetId", fixedAssetId);
globalContext.put("addlParam", "&fixedAssetId=" + fixedAssetId);
globalContext.fixedAssetId = fixedAssetId;
globalContext.addlParam = "&fixedAssetId=" + fixedAssetId;
}
serviceCtx = UtilMisc.toMap("userLogin", userLogin, "start", getFrom, "numPeriods", new Integer(numPeriods), "periodType", new Integer(periodType));
serviceCtx.putAll(UtilMisc.toMap("entityExprList", entityExprList, "locale", locale, "timeZone", timeZone));
serviceCtx = [userLogin : userLogin, start : getFrom, numPeriods : numPeriods, periodType : periodType];
serviceCtx.putAll([entityExprList : entityExprList, locale : locale, timeZone : timeZone]);
result = dispatcher.runSync("getWorkEffortEventsByPeriod", serviceCtx);
globalContext.put("periods", result.get("periods"));
globalContext.put("maxConcurrentEntries", result.get("maxConcurrentEntries"));
globalContext.periods = result.periods;
globalContext.maxConcurrentEntries = result.maxConcurrentEntries;
globalContext.put("start", start);
globalContext.put("prev", prev);
globalContext.put("next", next);
globalContext.start = start;
globalContext.prev = prev;
globalContext.next = next;
@@ -28,82 +28,50 @@ import java.text.DateFormat;
import java.text.*;
import java.text.NumberFormat;
decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
ZERO = BigDecimal.ZERO;
// @param GenericValue invoice - The Invoice entity to find payment applications for
if (!invoice) return;
invoiceId = request.getParameter("invoiceId") ?: context.invoiceId;
invoice = delegator.findByPrimaryKey("Invoice", [invoiceId : invoiceId]);
tabButtonItem = context.tabButtonItem;
invoiceItems = []; // to pass back to the screeen with payment applications added
if (invoice) {
// retrieve related applications with null itemnumber
invoiceAppl = null;
invoiceAppls = delegator.findByAnd("PaymentApplication", [invoiceId : invoiceId, invoiceItemSeqId : null]);
invoiceAppls.each { invoiceAppl ->
itemmap = [:];
itemmap.invoiceId = invoiceId;
itemmap.invoiceItemSeqId = invoiceAppl.invoiceItemSeqId;
itemmap.total = InvoiceWorker.getInvoiceTotalBd(invoice).doubleValue();
itemmap.paymentApplicationId = invoiceAppl.paymentApplicationId;
itemmap.paymentId = invoiceAppl.paymentId;
itemmap.billingAccountId = invoiceAppl.billingAccountId;
itemmap.taxAuthGeoId = invoiceAppl.taxAuthGeoId;
itemmap.amountToApply = invoiceAppl.amountApplied;
itemmap.amountApplied = invoiceAppl.amountApplied;
invoiceItems.add(itemmap);
}
// retrieve related applications with an existing itemnumber
invoice.getRelated("InvoiceItem").each { item ->
BigDecimal itemTotal = null;
if (item.amount != null) {
if (item.quantity == null || item.getBigDecimal("quantity").compareTo(ZERO) == 0) {
itemTotal = item.getBigDecimal("amount");
} else {
itemTotal = item.getBigDecimal("amount").multiply(item.getBigDecimal("quantity"));
}
}
// get relation payment applications for every item(can be more than 1 per item number)
paymentApplications = item.getRelated("PaymentApplication");
if (paymentApplications) {
paymentApplications.each { paymentApplication ->
itemmap = [:];
itemmap.putAll(item);
itemmap.total = NumberFormat.getInstance(locale).format(itemTotal);
itemmap.paymentApplicationId = paymentApplication.paymentApplicationId;
itemmap.paymentId = paymentApplication.paymentId;
itemmap.toPaymentId = paymentApplication.toPaymentId;
itemmap.amountApplied = paymentApplication.getBigDecimal("amountApplied");
itemmap.amountToApply = paymentApplication.getBigDecimal("amountApplied");
itemmap.billingAccountId = paymentApplication.billingAccountId;
itemmap.taxAuthGeoId = paymentApplication.taxAuthGeoId;
invoiceItems.add(itemmap);
}
}
/*
// create an extra line for input when not completely applied but not in the overview
if (tabButtonItem.equals("invoiceOverview") != true &&
(paymentApplications == null || paymentApplications.size() == 0
|| (applied < itemTotal && appliedAmount < invoiceAmount))) {
Map itemmap = new HashMap();
itemmap.putAll(item);
itemmap.put("total",itemTotal);
itemmap.put("paymentApplicationId","");
itemmap.put("paymentId","");
itemmap.put("amountToApply", NumberFormat.getNumberInstance(locale).format(itemTotal - applied));
itemmap.put("billingAccountId","");
itemmap.put("taxAuthGeoId","");
invoiceItems.add(itemmap);
}
*/
}
context.invoice = invoice;
context.invoiceId = invoiceId;
invoiceApplications = []; // to pass back to the screen with payment applications added
// retrieve related applications with null itemnumber
invoiceAppls = invoice.getRelated("PaymentApplication", [invoiceItemSeqId : null]);
invoiceAppls.each { invoiceAppl ->
itemmap = [:];
itemmap.invoiceId = invoiceAppl.invoiceId;
itemmap.invoiceItemSeqId = invoiceAppl.invoiceItemSeqId;
itemmap.total = InvoiceWorker.getInvoiceTotalBd(invoice).doubleValue();
itemmap.paymentApplicationId = invoiceAppl.paymentApplicationId;
itemmap.paymentId = invoiceAppl.paymentId;
itemmap.billingAccountId = invoiceAppl.billingAccountId;
itemmap.taxAuthGeoId = invoiceAppl.taxAuthGeoId;
itemmap.amountToApply = invoiceAppl.amountApplied;
itemmap.amountApplied = invoiceAppl.amountApplied;
invoiceApplications.add(itemmap);
}
if(invoiceItems) context.invoiceApplications = invoiceItems;
// retrieve related applications with an existing itemnumber
invoice.getRelated("InvoiceItem").each { item ->
BigDecimal itemTotal = null;
if (item.amount != null) {
if (!item.quantity) {
itemTotal = item.getBigDecimal("amount");
} else {
itemTotal = item.getBigDecimal("amount").multiply(item.getBigDecimal("quantity"));
}
}
// get relation payment applications for every item(can be more than 1 per item number)
item.getRelated("PaymentApplication").each { paymentApplication ->
itemmap = [:];
itemmap.putAll(item);
itemmap.total = NumberFormat.getInstance(locale).format(itemTotal);
itemmap.paymentApplicationId = paymentApplication.paymentApplicationId;
itemmap.paymentId = paymentApplication.paymentId;
itemmap.toPaymentId = paymentApplication.toPaymentId;
itemmap.amountApplied = paymentApplication.getBigDecimal("amountApplied");
itemmap.amountToApply = paymentApplication.getBigDecimal("amountApplied");
itemmap.billingAccountId = paymentApplication.billingAccountId;
itemmap.taxAuthGeoId = paymentApplication.taxAuthGeoId;
invoiceApplications.add(itemmap);
}
}
if (invoiceApplications) context.invoiceApplications = invoiceApplications;
@@ -529,6 +529,7 @@ under the License.
<set field="tabButtonItem" value="editInvoiceApplications"/>
<set field="invoiceId" from-field="parameters.invoiceId"/>
<entity-one entity-name="Invoice" value-name="invoice"/>
<script location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/CreateApplicationList.groovy"/>
<script location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy"/>
<set field="invoiceAmount" value="${bsh:org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotalBd(invoice)}"/>