class clsMarkup{
constructor(strName,douCost,douMarkup,strType){
this.Name = strName;
this.Cost = douCost;
this.Markup = douMarkup;
this.Name = strName;
switch(strType){
case "cost" : this.Answer = strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit " +" and it's profit is "+this.MarkProfit1(douCost,douMarkup)+" " +" bahts/unit.";
break;
case "price" : this.Answer = strName+"' s price is " + this.MarkupPrice(douCost,douMarkup)+" bahts/unit " +" and it's profit is "+this.MarkProfit2(douCost,douMarkup)+" " +" bahts/unit.";
break;
case "both" :this.Answer = "By using markup by cost, "+strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit. "
+"By using markup by price, it's price is "+this.MarkupPrice(douCost,douMarkup)+" " +" bahts/unit."
+" (profit difference = "+this.MarkDiff(douCost,douMarkup)+" bahts/unit).";
break;
default : this.Answer = "By using markup by cost, "+strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit. "
+"By using markup by price is"+this.MarkupPrice(douCost,douMarkup)+" " +" bahts/unit."
+" (profit difference = " +this.MarkDiff(douCost,douMarkup)+" bahts/unit).";
}
}
MarkupCost(douCost,douMarkup){
var strCost = new clsFormNum('%Markup by cost',douCost*(1+douMarkup/100),2,'bahts/units','');
return strCost.Val;
}
MarkupPrice(douCost,douMarkup){
var strPrice = new clsFormNum('%Markup by price',douCost/(1-douMarkup/100),2,'bahts/units','');
return strPrice.Val;
}
MarkProfit1(douCost,douMarkup){
var strProfit1 = new clsFormNum('ProfitC',(douCost*(1+douMarkup/100))-douCost,2,'bahts/units','');
return strProfit1.Val;
}
MarkProfit2(douCost,douMarkup){
var strProfit2 = new clsFormNum('ProfitP',(douCost/(1-douMarkup/100))-douCost,2,'bahts/units','');
return strProfit2.Val;
}
MarkDiff(douCost,douMarkup){
var strDiff = new clsFormNum('Profit Diff',(douCost/(1-douMarkup/100))-(douCost*(1+douMarkup/100)),2,'bahts/units','');
return strDiff.Val;
}
}
..
function CheckName(strID,strType,intMin,intMax,strNameAlert){
var InpName = document.getElementById(strID);
strInpName = InpName.value;
var arrTemp=[];
arrTemp = strID.split("@");
let objStr = new clsChkStr(arrTemp[1],strInpName,strType,intMin,intMax,strNameAlert);
if(objStr.Check==false){
alert(objStr.CheckText);
InpName.value="";
}
}
function CheckNum(strID,douMin,douMax,strUnit,strNameAlert){
var InpNum = document.getElementById(strID);
douNum = InpNum.value;
var arrTemp=[];
arrTemp = strID.split("@");
if(arrTemp[1]=="Price"){
douMin = douPriceMin;
}
let objNum = new clsChkNum(arrTemp[1],douNum,douMin,douMax,strUnit,strNameAlert);
if(objNum.Check==false){
alert(objNum.CheckText);
InpNum.value="";
}
if(arrTemp[1]=="VC"){
ChangePriceLimit(douNum,douMax);
}
}
function CalMarkup(){
var objInput = {};
objInput.Name = document.getElementById("inp@Name").value;
objInput.Cost = parseFloat(document.getElementById("inp@Cost").value);
objInput.Markup = parseFloat(document.getElementById("inp@Markup").value);
let objType = new clsRadioBut("radType");
var docResult = document.getElementById("outResult");
let objMarkup = new clsMarkup(objInput.Name,objInput.Cost, objInput.Markup,objType.Val);
docResult.innerText = objMarkup.Answer;
}
..
tr>
<td>Product Name (3-15 letters)</td>
<td><input type="text" id="inp@Name" onchange="CheckName('inp@Name','A',3,15,'Product Name')" class="SimpleText"></td>
</tr>
<tr>
<td>Cost (0-1000 bahts)</td>
<td><input type="number" id="inp@Cost" onchange="CheckNum('inp@Cost',0,1000,'bahts','Cost')" class="SimpleText ShowNumber"></td>
</tr>
<tr>
<td>%Markup (0-100%)</td>
<td><input type="number" id="inp@Markup" onchange="CheckNum('inp@Markup',0,100,'%','Markup')" class="SimpleText ShowNumber"></td>
</tr>
<tr>
<td>Calculation Type</td>
<td>
<label><input type="radio" id="inpMarkupAmount" name="redType" value="cost" checked>%Markup by Cost</label>
<label><input type="radio" id="inpMarkupPrice" name="redType" value="price">%Markup by Price</label>
<label><input type="radio" id="inpMarkupPrice" name="redType" value="both">Both</label>
</td>
</tr>
<tr></tr>
<tr>
<td></td><td><label onclick="CalMarkup()" class="Button">Calculation</td>
</tr>
</table>
</form>
</div>
<div>
<h2>Calculation Result</h2>
<p id="outResult"></p>
</div>
</div>
ใส่ฟอนแบบไหน ลงรูปยังไงการคำนวนในการเขียนโปรแกรม
constructor(strName,douCost,douMarkup,strType){
this.Name = strName;
this.Cost = douCost;
this.Markup = douMarkup;
this.Name = strName;
switch(strType){
case "cost" : this.Answer = strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit " +" and it's profit is "+this.MarkProfit1(douCost,douMarkup)+" " +" bahts/unit.";
break;
case "price" : this.Answer = strName+"' s price is " + this.MarkupPrice(douCost,douMarkup)+" bahts/unit " +" and it's profit is "+this.MarkProfit2(douCost,douMarkup)+" " +" bahts/unit.";
break;
case "both" :this.Answer = "By using markup by cost, "+strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit. "
+"By using markup by price, it's price is "+this.MarkupPrice(douCost,douMarkup)+" " +" bahts/unit."
+" (profit difference = "+this.MarkDiff(douCost,douMarkup)+" bahts/unit).";
break;
default : this.Answer = "By using markup by cost, "+strName+"' s price is " + this.MarkupCost(douCost,douMarkup)+" bahts/unit. "
+"By using markup by price is"+this.MarkupPrice(douCost,douMarkup)+" " +" bahts/unit."
+" (profit difference = " +this.MarkDiff(douCost,douMarkup)+" bahts/unit).";
}
}
MarkupCost(douCost,douMarkup){
var strCost = new clsFormNum('%Markup by cost',douCost*(1+douMarkup/100),2,'bahts/units','');
return strCost.Val;
}
MarkupPrice(douCost,douMarkup){
var strPrice = new clsFormNum('%Markup by price',douCost/(1-douMarkup/100),2,'bahts/units','');
return strPrice.Val;
}
MarkProfit1(douCost,douMarkup){
var strProfit1 = new clsFormNum('ProfitC',(douCost*(1+douMarkup/100))-douCost,2,'bahts/units','');
return strProfit1.Val;
}
MarkProfit2(douCost,douMarkup){
var strProfit2 = new clsFormNum('ProfitP',(douCost/(1-douMarkup/100))-douCost,2,'bahts/units','');
return strProfit2.Val;
}
MarkDiff(douCost,douMarkup){
var strDiff = new clsFormNum('Profit Diff',(douCost/(1-douMarkup/100))-(douCost*(1+douMarkup/100)),2,'bahts/units','');
return strDiff.Val;
}
}
..
function CheckName(strID,strType,intMin,intMax,strNameAlert){
var InpName = document.getElementById(strID);
strInpName = InpName.value;
var arrTemp=[];
arrTemp = strID.split("@");
let objStr = new clsChkStr(arrTemp[1],strInpName,strType,intMin,intMax,strNameAlert);
if(objStr.Check==false){
alert(objStr.CheckText);
InpName.value="";
}
}
function CheckNum(strID,douMin,douMax,strUnit,strNameAlert){
var InpNum = document.getElementById(strID);
douNum = InpNum.value;
var arrTemp=[];
arrTemp = strID.split("@");
if(arrTemp[1]=="Price"){
douMin = douPriceMin;
}
let objNum = new clsChkNum(arrTemp[1],douNum,douMin,douMax,strUnit,strNameAlert);
if(objNum.Check==false){
alert(objNum.CheckText);
InpNum.value="";
}
if(arrTemp[1]=="VC"){
ChangePriceLimit(douNum,douMax);
}
}
function CalMarkup(){
var objInput = {};
objInput.Name = document.getElementById("inp@Name").value;
objInput.Cost = parseFloat(document.getElementById("inp@Cost").value);
objInput.Markup = parseFloat(document.getElementById("inp@Markup").value);
let objType = new clsRadioBut("radType");
var docResult = document.getElementById("outResult");
let objMarkup = new clsMarkup(objInput.Name,objInput.Cost, objInput.Markup,objType.Val);
docResult.innerText = objMarkup.Answer;
}
..
tr>
<td>Product Name (3-15 letters)</td>
<td><input type="text" id="inp@Name" onchange="CheckName('inp@Name','A',3,15,'Product Name')" class="SimpleText"></td>
</tr>
<tr>
<td>Cost (0-1000 bahts)</td>
<td><input type="number" id="inp@Cost" onchange="CheckNum('inp@Cost',0,1000,'bahts','Cost')" class="SimpleText ShowNumber"></td>
</tr>
<tr>
<td>%Markup (0-100%)</td>
<td><input type="number" id="inp@Markup" onchange="CheckNum('inp@Markup',0,100,'%','Markup')" class="SimpleText ShowNumber"></td>
</tr>
<tr>
<td>Calculation Type</td>
<td>
<label><input type="radio" id="inpMarkupAmount" name="redType" value="cost" checked>%Markup by Cost</label>
<label><input type="radio" id="inpMarkupPrice" name="redType" value="price">%Markup by Price</label>
<label><input type="radio" id="inpMarkupPrice" name="redType" value="both">Both</label>
</td>
</tr>
<tr></tr>
<tr>
<td></td><td><label onclick="CalMarkup()" class="Button">Calculation</td>
</tr>
</table>
</form>
</div>
<div>
<h2>Calculation Result</h2>
<p id="outResult"></p>
</div>
</div>