Zend certified PHP/Magento developer

how to trace custom value from checkout cart page Total section in js file?

how we can trace that value comes from js?

for that i have created custom extension,

i dont know from js how this value and its function work..

because i want to get currency symbol here but it was not display
there GST value.

Test/Module/Model/Quote/Total/fee.php

<?php
namespace TestModuleModelQuoteTotal;
use MagentoQuoteModelQuote;
use MagentoQuoteModelQuoteAddress;
use MagentoQuoteModelQuoteAddressTotal;
use MagentoCheckoutModelSession;
class Fee extends MagentoQuoteModelQuoteAddressTotalAbstractTotal
{
protected $_productCollectionFactory;
protected $helperData;
protected $_priceCurrency;
protected $taxHelper;
private   $taxCalculator;
protected $_checkoutSession;
/**
* Collect grand total address amount
*
* @param MagentoQuoteModelQuote $quote
* @param MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment
* @param MagentoQuoteModelQuoteAddressTotal $total
* @return $this
*/
protected $quoteValidator = null;
public function __construct(
MagentoQuoteModelQuoteValidator $quoteValidator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency,
NcodeGSTtaxHelperData $helperData,
NcodeGSTtaxHelperTax $helperTax,
MagentoTaxModelCalculation $taxCalculator,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCheckoutModelSession $checkoutSession
)
{
$this->quoteValidator            = $quoteValidator;
$this->_priceCurrency            = $priceCurrency;
$this->helperData                = $helperData;
$this->taxHelper                 = $helperTax;
$this->taxCalculator             = $taxCalculator;
$this->_productCollectionFactory = $productCollectionFactory;
$this->_checkoutSession          = $checkoutSession;
}
public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)
{
parent::collect($quote, $shippingAssignment, $total);
if (!count($shippingAssignment->getItems())) {
return $this;
}
$enabled            = $this->helperData->isModuleEnabled();
$GstIn              = $this->helperData->getGstIn();        
$minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
$GstRegion          = $this->helperData->getGstRegion();
$currencysymbol     = $this->helperData->getCurrentCurrencySymbol();                
$Cartinfo = $shippingAssignment->getItems();  
foreach($Cartinfo as $item) {
$product = $this->helperData->getLoadProduct($item->getProductId());       
$hsnCode = $product->getHsnCode();                     
}
$subtotal = $total->getTotalAmount('subtotal'); 
if($hsnCode){
if ($enabled && $GstIn && $minimumOrderAmount <= $subtotal){        
$fee = $this->helperData->getGSTtax(); //Get GST Rate from Backend                
if(is_numeric($fee)){            
$fee = $subtotal * $fee / 100;
}
$total->setTotalAmount('fee', $fee);
$total->setBaseTotalAmount('fee', $fee);
$total->setFee($fee);
$quote->setFee($fee);            
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productMetadata = $objectManager->get('MagentoFrameworkAppProductMetadataInterface');
$version = (float)$productMetadata->getVersion();
if($version > 2.1)
{
//$total->setGrandTotal($total->getGrandTotal() + $fee);
}
else
{
$total->setGrandTotal($total->getGrandTotal() + $fee);
}
if ($this->taxHelper->isTaxEnabled()) {
$address = $this->_getAddressFromQuote($quote);
$this->_calculateTax($address, $total);
$extraTaxables = $address->getAssociatedTaxables();
$extraTaxables[] = [
'code' => 'fee',
'type' => 'fee',
'quantity' => 1,
'tax_class_id' => $this->taxHelper->getTaxClassId(),
'unit_price' => $fee,
'base_unit_price' => $fee,
'price_includes_tax' => false,
'associated_item_code' => false
];
$address->setAssociatedTaxables($extraTaxables);
}
}
}else{
}
return $this;
}
/**
* @param MagentoQuoteModelQuote $quote
* @param MagentoQuoteModelQuoteAddressTotal $total
* @return array
*/
public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)
{
$enabled            = $this->helperData->isModuleEnabled();
$minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
$currencysymbol     = $this->helperData->getCurrentCurrencySymbol();
$subtotal           = $quote->getSubtotal();
$fee                = $quote->getFee();
$address = $this->_getAddressFromQuote($quote);
$result = [];
if ($enabled && ($minimumOrderAmount <= $subtotal) && $fee) {        
$result = [
'code'  => 'fee',
'title' => $this->helperData->getFeeLabel(),
'value' => $fee,
];            
if ($this->taxHelper->isTaxEnabled() && $this->taxHelper->displayInclTax()) {
$result [] = [
'code'  => 'fee',
'value' => $fee + $address->getFeeTax(),
'title' => __($this->helperData->getFeeLabel()),
];
}
if ($this->taxHelper->isTaxEnabled() && $this->taxHelper->displayBothTax()) {
$result [] = [
'code'  => 'fee',
'value' => $fee + $address->getFeeTax(),
'title' => __($this->helperData->getFeeLabel()),
];
}           
}
return $result;
}
/**
* Get Subtotal label
*
* @return MagentoFrameworkPhrase
*/
public function getLabel()
{
return __('GST');
}
/**
* @param MagentoQuoteModelQuoteAddressTotal $total
*/
protected function clearValues(MagentoQuoteModelQuoteAddressTotal $total)
{
$total->setTotalAmount('subtotal', 0);
$total->setBaseTotalAmount('subtotal', 0);
$total->setTotalAmount('tax', 0);
$total->setBaseTotalAmount('tax', 0);
$total->setTotalAmount('discount_tax_compensation', 0);
$total->setBaseTotalAmount('discount_tax_compensation', 0);
$total->setTotalAmount('shipping_discount_tax_compensation', 0);
$total->setBaseTotalAmount('shipping_discount_tax_compensation', 0);
$total->setSubtotalInclTax(0);
$total->setBaseSubtotalInclTax(0);
}
protected function _getAddressFromQuote(Quote $quote)
{
return $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
}
protected function _calculateTax(Address $address, Total $total)
{
$taxClassId = $this->taxHelper->getTaxClassId();
if (!$taxClassId) {
return $this;
}
$taxRateRequest = $this->_getAddressTaxRequest($address);
$taxRateRequest->setProductClassId($taxClassId);
$rate = $this->taxCalculator->getRate($taxRateRequest);
$baseTax = $this->taxCalculator->calcTaxAmount(
$total->getBaseTotalAmount('fee'),
$rate,
false,
true
);
$tax = $this->taxCalculator->calcTaxAmount(
$total->getTotalAmount('fee'),
$rate,
false,
true
);
//$total->setBaseMcPaymentfeeTaxAmount($baseTax);
$total->setFeeTax($tax);
$appliedRates = $this->taxCalculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $appliedRates, $tax, $baseTax, $rate);
$total->addBaseTotalAmount('tax', $baseTax);
$total->addTotalAmount('tax', $tax);
return $this;
}
protected function _getAddressTaxRequest($address)
{
$addressTaxRequest = $this->taxCalculator->getRateRequest(
$address,
$address->getQuote()->getBillingAddress(),
$address->getQuote()->getCustomerTaxClassId(),
$address->getQuote()->getStore()
);
return $addressTaxRequest;
}
protected function _saveAppliedTaxes(
Address $address,
$applied,
$amount,
$baseAmount,
$rate
) {
$previouslyAppliedTaxes = $address->getAppliedTaxes();
$process = 0;
if(is_array($previouslyAppliedTaxes)) {
$process = count($previouslyAppliedTaxes);
}
foreach ($applied as $row) {
if ($row['percent'] == 0) {
continue;
}
if (!isset($previouslyAppliedTaxes[$row['id']])) {
$row['process'] = $process;
$row['amount'] = 0;
$row['base_amount'] = 0;
$previouslyAppliedTaxes[$row['id']] = $row;
}
if ($row['percent'] !== null) {
$row['percent'] = $row['percent'] ? $row['percent'] : 1;
$rate = $rate ? $rate : 1;
$appliedAmount = $amount / $rate * $row['percent'];
$baseAppliedAmount = $baseAmount / $rate * $row['percent'];
} else {
$appliedAmount = 0;
$baseAppliedAmount = 0;
foreach ($row['rates'] as $rate) {
$appliedAmount += $rate['amount'];
$baseAppliedAmount += $rate['base_amount'];
}
}
if ($appliedAmount || $previouslyAppliedTaxes[$row['id']]['amount']) {
$previouslyAppliedTaxes[$row['id']]['amount'] += $appliedAmount;
$previouslyAppliedTaxes[$row['id']]['base_amount'] += $baseAppliedAmount;
} else {
unset($previouslyAppliedTaxes[$row['id']]);
}
}
$address->setAppliedTaxes($previouslyAppliedTaxes);
}
}

Test/Module/view/frontend/web/template/checkout/cart/totals/fee.html

<!-- ko if: isDisplayed() -->
<!-- ko if: isTaxEnabled() -->
<!-- ko if: isDisplayBoth() -->
<tr class="totals fee excl" >
<th class="mark" colspan="1" scope="row" data-bind="text: getFeeLabel() + ' ' + getExFeeLabel()"></th>
<td class="amount">
<span class="price" data-bind="text: getValue()"></span>
</td>
</tr>
<tr class="totals fee incl">
<th class="mark" colspan="1" scope="row" data-bind="text: getFeeLabel() + ' ' + getInFeeLabel()"></th>
<td class="amount">
<span class="price" data-bind="text: getValue()"></span>
</td>
</tr>
<!-- /ko -->
<!-- ko ifnot: isDisplayBoth() -->
<!-- ko if: displayExclTax() -->
<tr class="totals fee excl" >
<th class="mark" colspan="1" scope="row" data-bind="text: getFeeLabel()"></th>
<td class="amount">
<span class="price" data-bind="text: getValue()"></span>
</td>
</tr>
<!-- /ko -->
<!-- ko if: displayInclTax() -->
<tr class="totals fee incl">
<th class="mark" colspan="1" scope="row" data-bind="text: getFeeLabel()"></th>
<td class="amount">
<span class="price" data-bind="text: getValue()"></span>
</td>
</tr>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<!-- ko ifnot: isTaxEnabled() -->
<tr class="totals fee excl" >
<th class="mark" colspan="1" scope="row" data-bind="text: getFeeLabel()"></th>
<td class="amount">
<span class="price" data-bind="text: getValue()"></span>
</td>
</tr>
<!-- /ko -->
<!-- /ko -->

Test/Module/view/frontend/web/js/view/checkout/cart/totals/fee.js

define([
'ko',
'uiComponent',
'Magento_Checkout/js/model/quote',
'Magento_Catalog/js/price-utils',
'Magento_Checkout/js/model/totals'
], function (ko, Component, quote, priceUtils, totals) {
'use strict';
var show_hide_GSTtax_blockConfig = window.checkoutConfig.show_hide_GSTtax_block;
var fee_label                    = window.checkoutConfig.fee_label;
var custom_fee_amount            = window.checkoutConfig.custom_fee_amount;
var custom_in_fee_amount         = window.checkoutConfig.custom_fee_amount_inc;
return Component.extend({
totals: quote.getTotals(),
canVisibleGSTtaxBlock: show_hide_GSTtax_blockConfig,
getFormattedPrice: ko.observable(priceUtils.formatPrice(custom_fee_amount, quote.getPriceFormat())),
getFeeLabel:ko.observable(fee_label),
getInFeeLabel:ko.observable(window.checkoutConfig.inclTaxPostfix),
getExFeeLabel:ko.observable(window.checkoutConfig.exclTaxPostfix),
isDisplayed: function () {
return this.getValue() != 0;
},
isDisplayBoth: function () {
return window.checkoutConfig.displayBoth;
},
displayExclTax: function () {
return window.checkoutConfig.displayExclTax;
},
displayInclTax: function () {
return window.checkoutConfig.displayInclTax;
},
isTaxEnabled: function () {              
return window.checkoutConfig.TaxEnabled;
},
getValue: function() {
var price = 0;
if (this.totals() && totals.getSegment('fee')) {                
price = totals.getSegment('fee').value;
}
return price;
},
getInFormattedPrice: function() {
var price = 0;
if (this.totals() && totals.getSegment('fee')) {
price = totals.getSegment('fee').value;
}
return priceUtils.formatPrice(price, quote.getPriceFormat());
},
});
});

Test/Module/view/frontend/web/js/view/checkout/summary/fee.js

/*jshint browser:true jquery:true*/
/*global alert*/
define(
[
'Magento_Checkout/js/view/summary/abstract-total',
'Magento_Checkout/js/model/quote',
'Magento_Catalog/js/price-utils',
'Magento_Checkout/js/model/totals'
],
function (Component, quote, priceUtils, totals) {
"use strict";
return Component.extend({
defaults: {
isFullTaxSummaryDisplayed: window.checkoutConfig.isFullTaxSummaryDisplayed || false,
template: 'Test_Module/checkout/summary/fee'
},
totals: quote.getTotals(),
isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false,
isDisplayed: function() {
return this.isFullMode();
},
getValue: function() {                
var price = 0;
if (this.totals()) {
document.write("Test");
price = totals.getSegment('fee').value;
}           
return this.getFormattedPrice(price);                
}            
});
}
);

enter image description here

enter image description here