JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://underscorejs.org/underscore-min.js"></script>

JavaScript

$(function() {
    var countriesMock = {
        DE: [
            {
            name: 'Domestic',
            code: "D",
            rates: [0, 7, 19]},
        {
            name: 'EU',
            code: "EU",
            rates: [0, 0, 0]},
        {
            name: 'Foreign',
            code: "F",
            rates: [0, 0, 0]}

        ]
    };

    console.log(gen(countriesMock, null, [{id: 'DE', isEU:true}]));

    function gen(countryZones, labels, countries) {
        var vatMatrix = {};
    _.each(countryZones, genVatsForCountry);
    return vatMatrix;

    function genVatsForCountry(zones, countryCode) {

        var context = {
            zones: zones,
            countryCode: countryCode
        }

        vatMatrix[countryCode] = {
            productTypes: [],
            vats: []
        };
        
        var taxTypes = ['P', 'S'];
        _.each(taxTypes, genVatsForTaxType, context);

    }

    function genVatsForTaxType(taxType, tindex) {
        var context = _.extend(this, {
            taxType: taxType,
            tindex: tindex
        });

        _.each(context.zones, genVatsForZone, context);
    }

    function genVatsForZone(zone, zindex) {

        var context = _.extend(this, {
            zone: zone,
            zindex: zindex,
            productTypeId: 1
        });
        
        vatTypes = isEU(context.countryCode) ? ['PD', 'SV'] : ['PDSV'];
        _.each(vatTypes, genVatsForVatType, context);

    }

    function genVatsForVatType(vatType, vindex) { 

        var context = _.extend(this, {
            vatType: vatType,
            vindex: vindex
        });
                
        _.each(context.zone.rates, getVatsForEachRate, context);

    }

    function getVatsForEachRate(rate, rindex) {
         
        var context = this;
        registerProductType();
        
        var curRate = getCurrentRate();
        vatMatrix[context.countryCode].vats.push({
            vatCode: getVatCode(curRate),
            place:...