Commit c031f855 authored by SABURI PATEKAR's avatar SABURI PATEKAR

Fixed the issue where entering only the Stockist Margin was incorrectly

setting Revised PTD and Revised PTR values. Also resolved the problem
where Revised PTR/PTS/PTD values entered during RFQ approval were not
being saved correctly in the db
parent 072067d8
...@@ -113,6 +113,7 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -113,6 +113,7 @@ public class ReqForQuotationAprv extends ValidatorEJB {
Boolean tranFlag = false; Boolean tranFlag = false;
String processRequestResult = ""; String processRequestResult = "";
String updatedDistMargin = "", updatedStkMargin="", updatedRetMargin=""; String updatedDistMargin = "", updatedStkMargin="", updatedRetMargin="";
String revisedPTR="", revisedPTD="", revisedPTS="";
try { try {
UserInfoBean userInfo = new UserInfoBean(); UserInfoBean userInfo = new UserInfoBean();
...@@ -139,7 +140,8 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -139,7 +140,8 @@ public class ReqForQuotationAprv extends ValidatorEJB {
roleCodeSign = checkNull(genericUtility.getColumnValue("role_code__sign", dom, "1")); roleCodeSign = checkNull(genericUtility.getColumnValue("role_code__sign", dom, "1"));
BaseLogger.log("3", null, null, "objName[" + objName + "]"); BaseLogger.log("3", null, null, "objName[" + objName + "]");
//Added by Saburi - 08/04/2026
//Added by Saburi - 11/04/2026
if (roleCodeSign.equalsIgnoreCase("VHB_QUOT")) if (roleCodeSign.equalsIgnoreCase("VHB_QUOT"))
{ {
String updateWfStatusSql = "update SALES_QUOT_REQ set WF_STATUS = 'A' where tran_id = ?"; String updateWfStatusSql = "update SALES_QUOT_REQ set WF_STATUS = 'A' where tran_id = ?";
...@@ -160,24 +162,59 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -160,24 +162,59 @@ public class ReqForQuotationAprv extends ValidatorEJB {
if (updatedRateFetchRS.next()) if (updatedRateFetchRS.next())
{ {
String transInfoXML = updatedRateFetchRS.getString(1)== null ? "" :updatedRateFetchRS.getString(1); String transInfoXML = updatedRateFetchRS.getString(1)== null ? "" :updatedRateFetchRS.getString(1);
BaseLogger.log("3", null, null, "transInfoXML 160[" + transInfoXML + "]"); BaseLogger.log("3", null, null, "transInfoXML 160[" + transInfoXML + "]");
if (transInfoXML != null && transInfoXML.trim().length() > 0) if (transInfoXML != null && transInfoXML.trim().length() > 0)
{
detailDom = genericUtility.parseString(transInfoXML);
BaseLogger.log("3", null, null, "detailDom 165[" + detailDom + "]");
}
itemCode = genericUtility.getColumnValue("item_code", detailDom);
updatedDistMargin = genericUtility.getColumnValue("phy_attrib_13", detailDom);
updatedStkMargin = genericUtility.getColumnValue("phy_attrib_14", detailDom);
updatedRetMargin = genericUtility.getColumnValue("phy_attrib_15", detailDom);
BaseLogger.log("3", null, null, "updatedDistMargin [" + updatedDistMargin + "]");
BaseLogger.log("3", null, null, "updatedStkMargin [" + updatedStkMargin + "]");
BaseLogger.log("3", null, null, "updatedRetMargin [" + updatedRetMargin + "]");
String specialRateStr = genericUtility.getColumnValue("rate_quot", detailDom);
double specialRate = Double.parseDouble(specialRateStr);
double revisedDist = Double.parseDouble(updatedDistMargin);
double revisedStock = Double.parseDouble(updatedStkMargin);
double revisedRet = Double.parseDouble(updatedRetMargin);
double calcPTS = (specialRate / 100) * (100 - revisedStock);
double calcPTD = (specialRate / 100) * (100 - revisedDist);
double calcPTR = (specialRate / 100) * (100 - revisedRet);
revisedPTS = String.format("%.2f", calcPTS);
revisedPTD = String.format("%.2f", calcPTD);
revisedPTR = String.format("%.2f", calcPTR);
BaseLogger.log("3", null, null, "FINAL revisedPTR [" + revisedPTR + "]");
BaseLogger.log("3", null, null, "FINAL revisedPTS [" + revisedPTS + "]");
BaseLogger.log("3", null, null, "FINAL revisedPTD [" + revisedPTD + "]");
String updateRevisedValue = "UPDATE SALES_QUOT_REQ_DET SET REVISED_PTS=?, REVISED_PTR=?, REVISED_PTD=? WHERE ITEM_CODE=?";
PreparedStatement updatePstmt = conn.prepareStatement(updateRevisedValue);
updatePstmt.setString(1, checkNull(revisedPTS));
updatePstmt.setString(2, checkNull(revisedPTR));
updatePstmt.setString(3, checkNull(revisedPTD));
updatePstmt.setString(4, itemCode);
int updateCnt = updatePstmt.executeUpdate();
BaseLogger.log("3", null, null, "ITEM updated for updateRevisedValue 211[" + itemCode + "] Count: " + updateCnt);
if (updatePstmt != null)
{ {
detailDom = genericUtility.parseString(transInfoXML); updatePstmt.close();
BaseLogger.log("3", null, null, "detailDom 165[" + detailDom + "]"); updatePstmt = null;
} }
// Fetching Updated Management Approved Rate
updatedDistMargin = genericUtility.getColumnValue("phy_attrib_13", detailDom);
BaseLogger.log("3", null, null, "updatedDistMargin 174[" + updatedDistMargin + "]");
updatedStkMargin = genericUtility.getColumnValue("phy_attrib_14", detailDom);
BaseLogger.log("3", null, null, "updatedStkMargin 176[" + updatedStkMargin + "]");
updatedRetMargin = genericUtility.getColumnValue("phy_attrib_15", detailDom);
BaseLogger.log("3", null, null, "updatedRetMargin 179[" + updatedRetMargin + "]");
} }
} }
...@@ -199,7 +236,8 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -199,7 +236,8 @@ public class ReqForQuotationAprv extends ValidatorEJB {
updatedRateFetchPSTMT.setString(2, refSer); updatedRateFetchPSTMT.setString(2, refSer);
updatedRateFetchRS = updatedRateFetchPSTMT.executeQuery(); updatedRateFetchRS = updatedRateFetchPSTMT.executeQuery();
if (updatedRateFetchRS.next()) { if (updatedRateFetchRS.next())
{
String transInfoXML = updatedRateFetchRS.getString(1)== null ? "" :updatedRateFetchRS.getString(1); String transInfoXML = updatedRateFetchRS.getString(1)== null ? "" :updatedRateFetchRS.getString(1);
BaseLogger.log("3", null, null, "transInfoXML[" + transInfoXML + "]"); BaseLogger.log("3", null, null, "transInfoXML[" + transInfoXML + "]");
...@@ -210,19 +248,72 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -210,19 +248,72 @@ public class ReqForQuotationAprv extends ValidatorEJB {
// Fetching Updated Management Approved Rate // Fetching Updated Management Approved Rate
updatedRate = genericUtility.getColumnValue("rate_quot", detailDom); updatedRate = genericUtility.getColumnValue("rate_quot", detailDom);
BaseLogger.log("3", null, null, "uppdatedRate[" + updatedRate + "]"); BaseLogger.log("3", null, null, "uppdatedRate VHB_MNGMNT[" + updatedRate + "]");
//Added by Saburi-11/04/2026
itemCode = genericUtility.getColumnValue("item_code", detailDom);
updatedDistMargin = genericUtility.getColumnValue("phy_attrib_13", detailDom); updatedDistMargin = genericUtility.getColumnValue("phy_attrib_13", detailDom);
BaseLogger.log("3", null, null, "updatedDistMargin 214[" + updatedDistMargin + "]"); updatedStkMargin = genericUtility.getColumnValue("phy_attrib_14", detailDom);
updatedRetMargin = genericUtility.getColumnValue("phy_attrib_15", detailDom);
updatedStkMargin = genericUtility.getColumnValue("phy_attrib_14", detailDom);
BaseLogger.log("3", null, null, "updatedStkMargin 217[" + updatedStkMargin + "]"); BaseLogger.log("3", null, null, "VHB_MNGMNT updatedDistMargin [" + updatedDistMargin + "]");
BaseLogger.log("3", null, null, "VHB_MNGMNT updatedStkMargin [" + updatedStkMargin + "]");
BaseLogger.log("3", null, null, "VHB_MNGMNT updatedRetMargin [" + updatedRetMargin + "]");
String specialRateStr = genericUtility.getColumnValue("rate_quot", detailDom);
double specialRate = Double.parseDouble(specialRateStr);
double revisedDist = Double.parseDouble(updatedDistMargin);
double revisedStock = Double.parseDouble(updatedStkMargin);
double revisedRet = Double.parseDouble(updatedRetMargin);
double calcPTS = (specialRate / 100) * (100 - revisedStock);
double calcPTD = (specialRate / 100) * (100 - revisedDist);
double calcPTR = (specialRate / 100) * (100 - revisedRet);
revisedPTS = String.format("%.2f", calcPTS);
revisedPTD = String.format("%.2f", calcPTD);
revisedPTR = String.format("%.2f", calcPTR);
BaseLogger.log("3", null, null, "FINAL VHB_MNGMNT revisedPTR [" + revisedPTR + "]");
BaseLogger.log("3", null, null, "FINAL VHB_MNGMNT revisedPTS [" + revisedPTS + "]");
BaseLogger.log("3", null, null, "FINAL VHB_MNGMNT revisedPTD [" + revisedPTD + "]");
String updateRevisedValue = "UPDATE SALES_QUOT_REQ_DET SET REVISED_PTS=?, REVISED_PTR=?, REVISED_PTD=? WHERE ITEM_CODE=?";
PreparedStatement updatePstmt = conn.prepareStatement(updateRevisedValue);
updatePstmt.setString(1, checkNull(revisedPTS));
updatePstmt.setString(2, checkNull(revisedPTR));
updatePstmt.setString(3, checkNull(revisedPTD));
updatePstmt.setString(4, itemCode);
int updateCnt = updatePstmt.executeUpdate();
BaseLogger.log("3", null, null, "ITEM updated for VHB_MNGMNT updateRevisedValue [" + itemCode + "] Count: " + updateCnt);
if (updatePstmt != null)
{
updatePstmt.close();
updatePstmt = null;
}
updatedRetMargin = genericUtility.getColumnValue("phy_attrib_15", detailDom); String updateItemSql = "UPDATE ITEM SET PHY_ATTRIB_13 = ?, PHY_ATTRIB_14 = ?, PHY_ATTRIB_15 = ? WHERE ITEM_CODE = ?";
BaseLogger.log("3", null, null, "updatedRetMargin 220[" + updatedRetMargin + "]"); PreparedStatement updateItemPstmt = conn.prepareStatement(updateItemSql);
}
// Added by Gagan B. on 31-MAR-26: for fetching updated Special Rate from OST -- END updateItemPstmt.setString(1, checkNull(updatedDistMargin)); // PHY_ATTRIB_13
updateItemPstmt.setString(2, checkNull(updatedStkMargin)); // PHY_ATTRIB_14
updateItemPstmt.setString(3, checkNull(updatedRetMargin)); // PHY_ATTRIB_15
updateItemPstmt.setString(4, itemCode);
int updateCount = updateItemPstmt.executeUpdate();
BaseLogger.log("3", null, null, "ITEM updated for itemCode VHB_MNGMNT[" + itemCode + "] Count: " + updateCount);
if (updateItemPstmt != null)
{
updateItemPstmt.close();
updateItemPstmt = null;
}
}
} }
System.out.println("enterprises::::: =[" + enterprises1 + "]" + " tran_id::" + tranID); System.out.println("enterprises::::: =[" + enterprises1 + "]" + " tran_id::" + tranID);
...@@ -412,14 +503,33 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -412,14 +503,33 @@ public class ReqForQuotationAprv extends ValidatorEJB {
BaseLogger.log("3", null, null, "distMargin::" + distMargin + " stockMargin::" + stockMargin BaseLogger.log("3", null, null, "distMargin::" + distMargin + " stockMargin::" + stockMargin
+ " revisedPtd:: " + retailMargin + "rate:: " + rate + "]"); + " revisedPtd:: " + retailMargin + "rate:: " + rate + "]");
BigDecimal revisedPtr = rateBD.divide(hundred.multiply(hundred.subtract(retailMarginBD)), 6, BigDecimal revisedPtr = BigDecimal.ZERO;
RoundingMode.HALF_UP); BigDecimal revisedPts = BigDecimal.ZERO;
BigDecimal revisedPtd = BigDecimal.ZERO;
// PTR
BigDecimal ptrDenominator = hundred.multiply(hundred.subtract(retailMarginBD));
if (ptrDenominator.compareTo(BigDecimal.ZERO) != 0) {
revisedPtr = rateBD.divide(ptrDenominator, 6, RoundingMode.HALF_UP);
} else {
BaseLogger.log("3", null, null, "PTR division skipped (denominator zero)");
}
BigDecimal revisedPts = rateBD.divide(hundred.multiply(hundred.subtract(stockMarginBD)), 6, // PTS
RoundingMode.HALF_UP); BigDecimal ptsDenominator = hundred.multiply(hundred.subtract(stockMarginBD));
if (ptsDenominator.compareTo(BigDecimal.ZERO) != 0) {
revisedPts = rateBD.divide(ptsDenominator, 6, RoundingMode.HALF_UP);
} else {
BaseLogger.log("3", null, null, "PTS division skipped (denominator zero)");
}
BigDecimal revisedPtd = rateBD.divide(hundred.multiply(hundred.subtract(distMarginBD)), 6, // PTD
RoundingMode.HALF_UP); BigDecimal ptdDenominator = hundred.multiply(hundred.subtract(distMarginBD));
if (ptdDenominator.compareTo(BigDecimal.ZERO) != 0) {
revisedPtd = rateBD.divide(ptdDenominator, 6, RoundingMode.HALF_UP);
} else {
BaseLogger.log("3", null, null, "PTD division skipped (denominator zero)");
}
BaseLogger.log("3", null, null, "revisedPtr::" + revisedPtr + " revisedPts::" + revisedPts BaseLogger.log("3", null, null, "revisedPtr::" + revisedPtr + " revisedPts::" + revisedPts
+ " revisedPtd::" + revisedPtd); + " revisedPtd::" + revisedPtd);
...@@ -591,7 +701,8 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -591,7 +701,8 @@ public class ReqForQuotationAprv extends ValidatorEJB {
BaseLogger.log("3", null, null, BaseLogger.log("3", null, null,
"RFQ Detail rate update count: " + updateDetCount); "RFQ Detail rate update count: " + updateDetCount);
} }
// Added by Saburi - 06/04/2026
//Added by Saburi - 09/04/2026
String updateItemSql = "UPDATE ITEM SET PHY_ATTRIB_13 = ?, PHY_ATTRIB_14 = ?, PHY_ATTRIB_15 = ? WHERE ITEM_CODE = ?"; String updateItemSql = "UPDATE ITEM SET PHY_ATTRIB_13 = ?, PHY_ATTRIB_14 = ?, PHY_ATTRIB_15 = ? WHERE ITEM_CODE = ?";
PreparedStatement updateItemPstmt = conn.prepareStatement(updateItemSql); PreparedStatement updateItemPstmt = conn.prepareStatement(updateItemSql);
...@@ -602,7 +713,7 @@ public class ReqForQuotationAprv extends ValidatorEJB { ...@@ -602,7 +713,7 @@ public class ReqForQuotationAprv extends ValidatorEJB {
int updateCount = updateItemPstmt.executeUpdate(); int updateCount = updateItemPstmt.executeUpdate();
BaseLogger.log("3", null, null, "ITEM updated for itemCode [" + itemCode + "] Count: " + updateCount); BaseLogger.log("3", null, null, "ITEM updated for itemCode 622[" + itemCode + "] Count: " + updateCount);
if (updateItemPstmt != null) if (updateItemPstmt != null)
{ {
......
...@@ -15,7 +15,7 @@ function recalcRow(el) ...@@ -15,7 +15,7 @@ function recalcRow(el)
console.log("------ recalcRow triggered ------"); console.log("------ recalcRow triggered ------");
console.log("Triggered element ID:", el.id); console.log("Triggered element ID:", el.id);
var row = el.parentNode.parentNode; var row = el.closest("tr");
console.log("Row found:", row); console.log("Row found:", row);
...@@ -32,12 +32,22 @@ function recalcRow(el) ...@@ -32,12 +32,22 @@ function recalcRow(el)
var ret = parseFloat(retEl ? retEl.value : 0) || 0; var ret = parseFloat(retEl ? retEl.value : 0) || 0;
console.log("Values =>", "rate:", rate, "dist:", dist, "stock:", stock, "ret:", ret); console.log("Values =>", "rate:", rate, "dist:", dist, "stock:", stock, "ret:", ret);
var pts = 0, ptd = 0, ptr = 0;
var pts = (rate / 100) * (100 - stock); if (stockEl.value !== "")
var ptd = (rate / 100) * (100 - dist); {
var ptr = (rate / 100) * (100 - ret); pts = (rate / 100) * (100 - stock);
}
console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
if (distEl.value !== "")
{
ptd = (rate / 100) * (100 - dist);
}
if (retEl.value !== "")
{
ptr = (rate / 100) * (100 - ret);
}
console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
var ptsCell = row.querySelector(".rev_pts"); var ptsCell = row.querySelector(".rev_pts");
var ptdCell = row.querySelector(".rev_ptd"); var ptdCell = row.querySelector(".rev_ptd");
...@@ -203,7 +213,7 @@ font-weight: 600; ...@@ -203,7 +213,7 @@ font-weight: 600;
</head> </head>
<body> <body onload="recalcAllRows()">
<div> <div>
<xsl:apply-templates select="//Detail1"/> <xsl:apply-templates select="//Detail1"/>
...@@ -303,29 +313,43 @@ font-weight: 600; ...@@ -303,29 +313,43 @@ font-weight: 600;
<th>Revised: Price To Stockist</th> <th>Revised: Price To Stockist</th>
<th>Revised: Price To Distributor</th> <th>Revised: Price To Distributor</th>
<th>Revised: Price To Retailer</th> <th>Revised: Price To Retailer</th>
<th>Distributor Margin</th>
<th>Stockist Margin</th> <th>Stockist Margin</th>
<th>Distributor Margin</th>
<th>Retailer Margin</th> <th>Retailer Margin</th>
<th>Remarks</th> <th>Remarks</th>
</tr> </tr>
<xsl:for-each select="//Detail2"> <xsl:for-each select="//Detail2">
<xsl:variable name="phy_attrib_13" select="number(phy_attrib_13)"/> <xsl:variable name="phy_attrib_13"
<xsl:variable name="phy_attrib_14" select="number(phy_attrib_14)"/> select="number(phy_attrib_13[.!=''])"/>
<xsl:variable name="phy_attrib_15" select="number(phy_attrib_15)"/>
<xsl:variable name="phy_attrib_14"
select="number(phy_attrib_14[.!=''])"/>
<xsl:variable name="phy_attrib_15"
select="number(phy_attrib_15[.!=''])"/>
<!-- Special Rate --> <!-- Special Rate -->
<xsl:variable name="quotRate" select="number(rate_quot)"/> <xsl:variable name="quotRate" select="number(rate_quot)"/>
<!-- Calculations --> <!-- Calculations -->
<xsl:variable name="calc_rev_pts" <!-- <xsl:variable name="revised_pts"
select="($quotRate div 100) * (100 - $phy_attrib_14)"/> select="($quotRate div 100) * (100 - $phy_attrib_14)"/> -->
<!-- <xsl:variable name="revised_ptd"
select="($quotRate div 100) * (100 - $phy_attrib_13)"/> -->
<!-- <xsl:variable name="revised_ptr"
select="($quotRate div 100) * (100 - $phy_attrib_15)"/> -->
<xsl:variable name="revised_pts"
select="(number($quotRate) div 100) * (100 - number($phy_attrib_14))"/>
<xsl:variable name="calc_rev_ptd" <xsl:variable name="revised_ptd"
select="($quotRate div 100) * (100 - $phy_attrib_13)"/> select="(number($quotRate) div 100) * (100 - number($phy_attrib_13))"/>
<xsl:variable name="calc_rev_ptr" <xsl:variable name="revised_ptr"
select="($quotRate div 100) * (100 - $phy_attrib_15)"/> select="(number($quotRate) div 100) * (100 - number($phy_attrib_15))"/>
<xsl:variable name="dbID"> <xsl:variable name="dbID">
<xsl:value-of select="@dbID" /> <xsl:value-of select="@dbID" />
...@@ -377,48 +401,98 @@ font-weight: 600; ...@@ -377,48 +401,98 @@ font-weight: 600;
<td class="right"><xsl:value-of select="format-number(ptr, '#,##0.00')"/></td> <td class="right"><xsl:value-of select="format-number(ptr, '#,##0.00')"/></td>
<td class="right rev_pts"> <td class="right rev_pts">
<xsl:value-of select="format-number(number($calc_rev_pts), '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_pts = $revised_pts)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_pts, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_pts"
name="Detail2.{normalize-space(@domID)}.revised_pts"
value="{$revised_pts}"
ISCHANGED="true"/>
</td> </td>
<td class="right rev_ptd"> <td class="right rev_ptd">
<xsl:value-of select="format-number(number($calc_rev_ptd), '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_ptd = $revised_ptd)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_ptd, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_ptd"
name="Detail2.{normalize-space(@domID)}.revised_ptd"
value="{$revised_ptd}"
ISCHANGED="true"/>
</td> </td>
<td class="right rev_ptr"> <td class="right rev_ptr">
<xsl:value-of select="format-number(number($calc_rev_ptr), '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_ptr = $revised_ptr)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_ptr, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_ptr"
name="Detail2.{normalize-space(@domID)}.revised_ptr"
value="{$revised_ptr}"
ISCHANGED="true"/>
</td> </td>
<td class="right"> <td class="right">
<input class="inputRate" <input class="inputRate"
id="Detail2.{normalize-space(@domID)}.phy_attrib_13" id="Detail2.{normalize-space(@domID)}.phy_attrib_14"
name="Detail2.{normalize-space(@domID)}.phy_attrib_13" name="Detail2.{normalize-space(@domID)}.phy_attrib_14"
value="{phy_attrib_13}" value="{phy_attrib_14}"
ISCHANGED="true" ISCHANGED="true"
isServerCallOnChange="true" isServerCallOnChange="true"
onfocus="gotFocus(this)" onfocus="gotFocus(this)"
onblur="gotBlur(this); recalcRow(this);" onblur="gotBlur(this); recalcRow(this);"
onkeyup="return autoCaps(this)" onkeyup="return autoCaps(this)"
onkeydown="return onKeyDownFun(this,event)" onkeydown="return onKeyDownFun(this,event)"
title="Distributor Margin" title="Stockist Margin"
maxlength="1000"/> maxlength="1000"/>
</td> </td>
<td class="right"> <td class="right">
<input class="inputRate" <input class="inputRate"
id="Detail2.{normalize-space(@domID)}.phy_attrib_14" id="Detail2.{normalize-space(@domID)}.phy_attrib_13"
name="Detail2.{normalize-space(@domID)}.phy_attrib_14" name="Detail2.{normalize-space(@domID)}.phy_attrib_13"
value="{phy_attrib_14}" value="{phy_attrib_13}"
ISCHANGED="true" ISCHANGED="true"
isServerCallOnChange="true" isServerCallOnChange="true"
onfocus="gotFocus(this)" onfocus="gotFocus(this)"
onblur="gotBlur(this); recalcRow(this);" onblur="gotBlur(this); recalcRow(this);"
onkeyup="return autoCaps(this)" onkeyup="return autoCaps(this)"
onkeydown="return onKeyDownFun(this,event)" onkeydown="return onKeyDownFun(this,event)"
title="Stockist Margin" title="Distributor Margin"
maxlength="1000"/> maxlength="1000"/>
</td> </td>
<td class="right"> <td class="right">
<input class="inputRate" <input class="inputRate"
id="Detail2.{normalize-space(@domID)}.phy_attrib_15" id="Detail2.{normalize-space(@domID)}.phy_attrib_15"
......
...@@ -9,13 +9,26 @@ ...@@ -9,13 +9,26 @@
<head> <head>
<script type="text/javascript"> <script type="text/javascript">
function getValue(el)
{
if (!el) return 0;
var val = el.value;
if (!val || val.trim() === "") return 0;
var num = parseFloat(val);
return isNaN(num) ? 0 : num;
}
function recalcRow(el) function recalcRow(el)
{ {
console.log("------ recalcRow triggered ------"); console.log("------ recalcRow triggered ------");
console.log("Triggered element ID:", el.id); console.log("Triggered element ID:", el.id);
var row = el.parentNode.parentNode; var row = el.closest("tr");
console.log("Row found:", row); console.log("Row found:", row);
...@@ -26,18 +39,28 @@ function recalcRow(el) ...@@ -26,18 +39,28 @@ function recalcRow(el)
console.log("Elements:", rateEl, distEl, stockEl, retEl); console.log("Elements:", rateEl, distEl, stockEl, retEl);
var rate = parseFloat(rateEl ? rateEl.value : 0) || 0; var rate = getValue(rateEl);
var dist = parseFloat(distEl ? distEl.value : 0) || 0; var dist = getValue(distEl);
var stock = parseFloat(stockEl ? stockEl.value : 0) || 0; var stock = getValue(stockEl);
var ret = parseFloat(retEl ? retEl.value : 0) || 0; var ret = getValue(retEl);
console.log("Values =>", "rate:", rate, "dist:", dist, "stock:", stock, "ret:", ret); console.log("Values =>", "rate:", rate, "dist:", dist, "stock:", stock, "ret:", ret);
var pts = 0, ptd = 0, ptr = 0;
var pts = (rate / 100) * (100 - stock); if (stockEl.value !== "")
var ptd = (rate / 100) * (100 - dist); {
var ptr = (rate / 100) * (100 - ret); pts = (rate / 100) * (100 - stock);
}
console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
if (distEl.value !== "")
{
ptd = (rate / 100) * (100 - dist);
}
if (retEl.value !== "")
{
ptr = (rate / 100) * (100 - ret);
}
console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
var ptsCell = row.querySelector(".rev_pts"); var ptsCell = row.querySelector(".rev_pts");
var ptdCell = row.querySelector(".rev_ptd"); var ptdCell = row.querySelector(".rev_ptd");
...@@ -226,7 +249,7 @@ text-align: left !important; ...@@ -226,7 +249,7 @@ text-align: left !important;
</head> </head>
<body> <body onload="recalcAllRows()">
<div> <div>
<xsl:apply-templates select="//Detail1"/> <xsl:apply-templates select="//Detail1"/>
...@@ -326,28 +349,33 @@ text-align: left !important; ...@@ -326,28 +349,33 @@ text-align: left !important;
<th>Revised: Price To Stockist</th> <th>Revised: Price To Stockist</th>
<th>Revised: Price To Distributor</th> <th>Revised: Price To Distributor</th>
<th>Revised: Price To Retailer</th> <th>Revised: Price To Retailer</th>
<th>Distributor margin</th>
<th>Stockist Margin</th> <th>Stockist Margin</th>
<th>Distributor margin</th>
<th>Retailer Margin</th> <th>Retailer Margin</th>
<th>Remarks</th> <th>Remarks</th>
</tr> </tr>
<xsl:for-each select="//Detail2"> <xsl:for-each select="//Detail2">
<xsl:variable name="phy_attrib_13" select="number(phy_attrib_13)"/> <xsl:variable name="phy_attrib_13"
<xsl:variable name="phy_attrib_14" select="number(phy_attrib_14)"/> select="number(phy_attrib_13[.!=''])"/>
<xsl:variable name="phy_attrib_15" select="number(phy_attrib_15)"/>
<xsl:variable name="phy_attrib_14"
select="number(phy_attrib_14[.!=''])"/>
<xsl:variable name="phy_attrib_15"
select="number(phy_attrib_15[.!=''])"/>
<!-- Special Rate --> <!-- Special Rate -->
<xsl:variable name="quotRate" select="number(rate_quot)"/> <xsl:variable name="quotRate" select="number(rate_quot)"/>
<!-- Calculations --> <!-- Calculations -->
<xsl:variable name="calc_rev_pts" <xsl:variable name="revised_pts"
select="($quotRate div 100) * (100 - $phy_attrib_14)"/> select="($quotRate div 100) * (100 - $phy_attrib_14)"/>
<xsl:variable name="calc_rev_ptd" <xsl:variable name="revised_ptd"
select="($quotRate div 100) * (100 - $phy_attrib_13)"/> select="($quotRate div 100) * (100 - $phy_attrib_13)"/>
<xsl:variable name="calc_rev_ptr" <xsl:variable name="revised_ptr"
select="($quotRate div 100) * (100 - $phy_attrib_15)"/> select="($quotRate div 100) * (100 - $phy_attrib_15)"/>
<xsl:variable name="dbID"> <xsl:variable name="dbID">
...@@ -427,44 +455,91 @@ text-align: left !important; ...@@ -427,44 +455,91 @@ text-align: left !important;
<td class="right"><xsl:value-of select="format-number(ptr,'#,##0.00')"/></td> <td class="right"><xsl:value-of select="format-number(ptr,'#,##0.00')"/></td>
<td class="right rev_pts"> <td class="right rev_pts">
<xsl:value-of select="format-number($calc_rev_pts, '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_pts = $revised_pts)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_pts, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_pts"
name="Detail2.{normalize-space(@domID)}.revised_pts"
value="{$revised_pts}"
ISCHANGED="true"/>
</td> </td>
<td class="right rev_ptd"> <td class="right rev_ptd">
<xsl:value-of select="format-number($calc_rev_ptd, '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_ptd = $revised_ptd)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_ptd, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_ptd"
name="Detail2.{normalize-space(@domID)}.revised_ptd"
value="{$revised_ptd}"
ISCHANGED="true"/>
</td> </td>
<td class="right rev_ptr"> <td class="right rev_ptr">
<xsl:value-of select="format-number($calc_rev_ptr, '#,##0.00')"/> <span>
<xsl:choose>
<xsl:when test="not($revised_ptr = $revised_ptr)">
<xsl:text>0.00</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($revised_ptr, '#,##0.00')"/>
</xsl:otherwise>
</xsl:choose>
</span>
<input type="hidden"
id="Detail2.{normalize-space(@domID)}.revised_ptr"
name="Detail2.{normalize-space(@domID)}.revised_ptr"
value="{$revised_ptr}"
ISCHANGED="true"/>
</td> </td>
<td class="right"> <td class="right">
<input class="inputRate" <input class="inputRate"
id="Detail2.{normalize-space(@domID)}.phy_attrib_13" id="Detail2.{normalize-space(@domID)}.phy_attrib_14"
name="Detail2.{normalize-space(@domID)}.phy_attrib_13" name="Detail2.{normalize-space(@domID)}.phy_attrib_14"
value="{phy_attrib_13}" value="{phy_attrib_14}"
ISCHANGED="true" ISCHANGED="true"
isServerCallOnChange="true" isServerCallOnChange="true"
onfocus="gotFocus(this)" onfocus="gotFocus(this)"
onblur="recalcRow(this)" onblur="recalcRow(this)"
onkeyup="return autoCaps(this)" onkeyup="return autoCaps(this)"
onkeydown="return onKeyDownFun(this,event)" onkeydown="return onKeyDownFun(this,event)"
title="Distributor Margin" title="Stockist Margin"
maxlength="1000"/> maxlength="1000"/>
</td> </td>
<td class="right"> <td class="right">
<input class="inputRate" <input class="inputRate"
id="Detail2.{normalize-space(@domID)}.phy_attrib_14" id="Detail2.{normalize-space(@domID)}.phy_attrib_13"
name="Detail2.{normalize-space(@domID)}.phy_attrib_14" name="Detail2.{normalize-space(@domID)}.phy_attrib_13"
value="{phy_attrib_14}" value="{phy_attrib_13}"
ISCHANGED="true" ISCHANGED="true"
isServerCallOnChange="true" isServerCallOnChange="true"
onfocus="gotFocus(this)" onfocus="gotFocus(this)"
onblur="recalcRow(this)" onblur="recalcRow(this)"
onkeyup="return autoCaps(this)" onkeyup="return autoCaps(this)"
onkeydown="return onKeyDownFun(this,event)" onkeydown="return onKeyDownFun(this,event)"
title="Stockist Margin" title="Distributor Margin"
maxlength="1000"/> maxlength="1000"/>
</td> </td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment