Debug School

rakesh kumar
rakesh kumar

Posted on • Updated on

How to explore the dynamic handling of price display based on different scales (e.g., crore, lakh, thousand) in PHP

        <span>
    <i class="{{ ($platform == 'koo') ? '' : 'fab fa-' . $platform }}" style="{{ ($platform == 'koo') ? 'font-size: 15px; color: black;' : '' }}">

    @if($platform == 'koo')
            <img src="{{ url('assets/images/koo-favicon.webp') }}" width="20" style="margin-left: -9px;">
            @elseif($platform == 'scoopit')
            <img src="{{ url('assets/images/scoopit-favicon.webp') }}" width="20" style="margin-left: -9px;">
            @elseif($platform == 'slashdot')
            <img src="{{ url('assets/images/slashdot-favicon.webp') }}" width="20" style="margin-left: -9px;">
            @elseif($platform == 'roposo')
            <img src="{{ url('assets/images/roposo-favicon.webp') }}" width="20" style="margin-left: -9px;">
            @elseif($platform == 'chingari')
            <img src="{{ url('assets/images/chingari-favicon.webp') }}" width="20" style="margin-left: -9px;">             
            @elseif($platform == 'mitron')
            <img src="{{ url('assets/images/mitron-favicon.webp') }}" width="20" style="margin-left: -9px;">             
            @endif
        &nbsp;&nbsp;<b>{{ ucfirst($platform) }} :</b>
    </i>&nbsp;&nbsp;&nbsp;
    @php
        if ($price >= 10000000) {
            $shortPrice = number_format(($price / 10000000), 1) . ' Cr';
        } elseif ($price >= 100000) {
            $shortPrice = number_format(($price / 100000), 1) . ' Lakh';
        } elseif ($price >= 1000) {
            $shortPrice = number_format(($price / 1000), 1) . ' K';
        } else {
            $shortPrice = $price;
        }
    @endphp
    {{ $shortPrice }}  {{ (!empty($item->currency) || $item->currency === []) ? $item->currency : '' }} <select>
        @for ($i = 1; $i <= 10; $i++)
            <option value="{{ $i }}">{{ $i }}</option>
        @endfor
    </select>
</span><br>
Enter fullscreen mode Exit fullscreen mode

In javascript

for (var i = 0; i < nonNullSocialPrices.length; i += 4) {             
                html += '<div class="row">';              
                for (var j = 0; j < 4 && i + j < nonNullSocialPrices.length; j++) {
                    var site = nonNullSocialPrices[i + j].site.trim();
                    var site_url = nonNullSocialSites[i + j].site_url.trim();
                    console.log(site_url)
                    var cartSocialsObject = JSON.parse(item.latest_cart_socials);
                    var hasPrice = item.latest_cart_socials && Object.keys(cartSocialsObject).includes(site);
                    html += '<div class="col-md-3">';
                    var price = nonNullSocialPrices[i + j].price;
                    if (price >= 10000000) {
                        var shortPrice = (price / 10000000).toFixed(1) + ' Cr';
                    } else if (price >= 100000) {
                        var shortPrice = (price / 100000).toFixed(1) + ' Lakh';
                    } else if (price >= 1000) {
                        var shortPrice = (price / 1000).toFixed(1) + ' K';
                    } else {
                        var shortPrice = price;
                    }  
Enter fullscreen mode Exit fullscreen mode
   if (hasPrice && itemadminid==isLoggeddata ) { 
    html += '<a href="' + site_url + '" target="_blank" style="color: black; font-size: 16px;">';
    html += '<i class="fas fa-cart-plus"></i> <span data-site="' + site + '">' + site + '</span>: ' + shortPrice;
    html += '</a>';

} else if (isAdded && itemadminid==isLoggeddata) {
    // Show the 'not added' icon in red with a checkbox and add a link with the site_url

    html += '<input type="checkbox" name="socialSite" data-id="' + item.id + '" value="' + site_url + '" data-site="' + site + '" class="socialSite ' + (isAdded &&  hasPrice && itemadminid==isLoggeddata? 'hideCheckboxes' : '') + '">';
    html += ' <a href="' + site_url + '" target="_blank" style="color: black; font-size: 16px;"><span data-site="' + site + '">' + site + '</span>: </a>' + shortPrice;
} else {
    // Add a link with the site_url for the social site name
    html += '<a href="' + site_url + '" target="_blank" style="color: black; font-size: 16px;">';
    // Just display the checkbox and social site name
    html += '<input type="checkbox" name="socialSite" data-id="' + item.id + '" value="' + site_url + '" data-site="' + site + '" class="socialSite ' + (isAdded && hasPrice && itemadminid==isLoggeddata ? 'hideCheckboxes' : '') + '">';
    html += ' <span data-site="' + site + '">' + site + '</span>: ' + shortPrice;
    html += '</a>';
}
                    html += '</div>';
                } // Display each social site

                html += '</div>';
            }
        }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)