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
...@@ -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,11 +32,21 @@ function recalcRow(el) ...@@ -32,11 +32,21 @@ 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);
}
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); console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
var ptsCell = row.querySelector(".rev_pts"); var ptsCell = row.querySelector(".rev_pts");
...@@ -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,17 +39,27 @@ function recalcRow(el) ...@@ -26,17 +39,27 @@ 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);
}
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); console.log("Calculated =>", "PTS:", pts, "PTD:", ptd, "PTR:", ptr);
var ptsCell = row.querySelector(".rev_pts"); var ptsCell = row.querySelector(".rev_pts");
...@@ -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