<?php


if (isset($isSettlement) && ($isSettlement == true)) {

    $strByTrans = "";
    $strByMenu = "";
    $strByPym = "";
    $strByBahan = "";

    if (isset($headerByTransaksi) && sizeof($headerByTransaksi) > 0) {
        if (isset($settlementByTransaksi) && sizeof($settlementByTransaksi) > 0) {
            $itemTrans = (isset($settlementByTransaksiProduk) && sizeof($settlementByTransaksiProduk) > 0) ? $settlementByTransaksiProduk : array();

            // $strByTrans .= "<h3>$labelByTransaksi</h3>";
            // $strByTrans .= "<style type='text/css'>
            // .form-control{
            //     height: 1px !important;
            //     padding: 3px 2px !important;
            // }
            // </style>";

            $total = 0;
            foreach ($settlementByTransaksi as $trNomor => $spec) {
                $total += $spec['validGrandTotal'];

                $strByTrans .= "<div class='table-responsive no-padding no-border dataTable compact'>";

                if (isset($headerMainByTransaksi) && sizeof($headerMainByTransaksi) > 0) {
                    foreach ($headerMainByTransaksi as $key => $val) {
                        $mhVal = isset($spec[$key]) ? $spec[$key] : "";
                        if ($val == NULL) {
                            $strByTrans .= formatField_he_format($key, $mhVal);
                        }
                        else {
                            $strByTrans .= "$val : " . formatField_he_format($key, $mhVal);
                        }
                        $strByTrans .= "<br>";
                    }
                }

                //region header per-transaksi
                $strByTrans .= "<table class='table table-condensed no-padding table-bordered no-margin'>";
                $strByTrans .= "<tr class='bg-grey-2 text-uppercase'>";
                $strByTrans .= "<th style='width:0.5%;' class='text-center'>";
                $strByTrans .= "No.";
                $strByTrans .= "</th>";
                foreach ($headerByTransaksi as $key => $val) {
                    $strByTrans .= "<th class='text-muted text-center'>";
                    $strByTrans .= $val;
                    $strByTrans .= "</th>";
                }
                $strByTrans .= "</tr>";

                if (isset($itemTrans[$trNomor]) && sizeof($itemTrans[$trNomor]) > 0) {
                    $no_itr = 0;
                    foreach ($itemTrans[$trNomor] as $iSpec) {
                        $no_itr++;

                        $strByTrans .= "<tr>";
                        $strByTrans .= "<td style='text-align: right;'>$no_itr</td>";

                        foreach ($headerByTransaksi as $key => $val) {
                            $colVal = isset($iSpec[$key]) ? formatField_he_format($key, $iSpec[$key]) : "";
                            $strByTrans .= "<td>$colVal</td>";
                        }
                        $strByTrans .= "</tr>";
                    }
                }

                if (isset($summaryByTransaksi) && sizeof($summaryByTransaksi) > 0) {
                    foreach ($summaryByTransaksi as $key => $val) {
                        $colspan = sizeof($headerByTransaksi);
                        $sumVal = isset($spec[$key]) ? $spec[$key] : "0";

                        $strByTrans .= "<tr>";
                        $strByTrans .= "<td style='text-align: right;' colspan='$colspan'>$val</td>";
                        $strByTrans .= "<td>" . formatField_he_format($key, $sumVal) . "</td>";
                        $strByTrans .= "</tr>";
                    }
                }

                $strByTrans .= "</table>";
                //endregion


                $strByTrans .= "</div>";
                $strByTrans .= "<br>";

            }

            $strByTrans .= "<div style='color:#000000;font-size:18px;' class='alert alert-warning'>";
            $strByTrans .= "<div><span sstyle='color:#000000;font-size:18px;'>TOTAL BILL: </span><span class='pull-right'>" . formatField_he_format("debet", sizeof($settlementByTransaksi)) . "</span></div>";
            $strByTrans .= "<div><span sstyle='color:#000000;font-size:18px;'>TOTAL BY NOTA/BILL: </span><span class='pull-right'>" . formatField_he_format("debet", $total) . "</span></div>";
            $strByTrans .= "</div>";
            $strByTrans .= "<br><br>";

        }
    }

    if (isset($settlementByMenu) && sizeof($settlementByMenu) > 0) {
        if (isset($headerByMenu) && sizeof($headerByMenu) > 0) {
            $strByMenu .= "<div class='table-responsive no-padding no-border'>";
            $strByMenu .= "<h3>$labelByMenu</h3>";
            $strByMenu .= "<table class='table table-condensed no-padding table-bordered no-margin'>";
            $strByMenu .= "<tr class='bg-grey-2 text-uppercase'>";
            $strByMenu .= "<th style='width:0.5%;' class='text-center'>";
            $strByMenu .= "No.";
            $strByMenu .= "</th>";
            foreach ($headerByMenu as $key => $val) {
                $strByMenu .= "<th class='text-muted text-center'>";
                $strByMenu .= $val;
                $strByMenu .= "</th>";
            }
        }
        $strByMenu .= "<tr class='bg-grey-2 text-uppercase'>";

        $no_menu = 0;
        $total_menu = array();
        foreach ($settlementByMenu as $mSpec) {
            $no_menu++;
            $strByMenu .= "<tr>";
            $strByMenu .= "<td style='text-align: right;'>$no_menu</td>";

            foreach ($headerByMenu as $key => $val) {

                $colVal = isset($mSpec[$key]) ? formatField_he_format($key, $mSpec[$key]) : "";
                $strByMenu .= "<td>$colVal</td>";

                if (isset($mSpec[$key]) && is_numeric($mSpec[$key])) {
                    if (!isset($total_menu[$key])) {
                        $total_menu[$key] = 0;
                    }
                    $total_menu[$key] += $mSpec[$key];
                }
            }
            $strByMenu .= "</tr>";
        }
        $strByMenu .= "<tr>";
        $strByMenu .= "<td style='text-align: right;' colspan='2'>TOTAL</td>";
        foreach ($headerByMenu as $key => $val) {
            if (isset($total_menu[$key])) {
                $colVal = formatField_he_format($key, $total_menu[$key]);
                $strByMenu .= "<td>$colVal</td>";
            }
        }
        $strByMenu .= "</tr>";
        $strByMenu .= "</table class='table table-condensed no-padding table-bordered no-margin'>";
        $strByMenu .= "</div class='table-responsive no-padding no-border'>";
        $strByMenu .= "<br>";
    }

    if (isset($settlementByPayment) && sizeof($settlementByPayment) > 0) {
        if (isset($headerByPayment) && sizeof($headerByPayment) > 0) {
            $strByPym .= "<div class='table-responsive no-padding no-border'>";
            $strByPym .= "<h3>$labelByPayment</h3>";
            $strByPym .= "<table class='table table-condensed no-padding table-bordered no-margin'>";
            $strByPym .= "<tr class='bg-grey-2 text-uppercase'>";
            $strByPym .= "<th style='width:0.5%;' class='text-center'>";
            $strByPym .= "No.";
            $strByPym .= "</th>";
            foreach ($headerByPayment as $key => $val) {
                $strByPym .= "<th class='text-muted text-center'>";
                $strByPym .= $val;
                $strByPym .= "</th>";
            }
        }
        $strByPym .= "<tr class='bg-grey-2 text-uppercase'>";

        $no_menu = 0;
        $total_menu = array();
        foreach ($settlementByPayment as $mSpec) {
            $no_menu++;
            $strByPym .= "<tr>";
            $strByPym .= "<td style='text-align: right;'>$no_menu</td>";

            foreach ($headerByPayment as $key => $val) {

                $colVal = isset($mSpec[$key]) ? formatField_he_format($key, $mSpec[$key]) : "";
                $strByPym .= "<td>$colVal</td>";

                if (isset($mSpec[$key]) && is_numeric($mSpec[$key])) {
                    if (!isset($total_menu[$key])) {
                        $total_menu[$key] = 0;
                    }
                    $total_menu[$key] += $mSpec[$key];
                }
            }
            $strByPym .= "</tr>";
        }
        $strByPym .= "<tr>";
        $strByPym .= "<td style='text-align: right;' colspan='2'>TOTAL</td>";
        foreach ($headerByPayment as $key => $val) {
            if (isset($total_menu[$key])) {
                $colVal = formatField_he_format($key, $total_menu[$key]);
                $strByPym .= "<td>$colVal</td>";
            }
        }
        $strByPym .= "</tr>";
        $strByPym .= "</table class='table table-condensed no-padding table-bordered no-margin'>";
        $strByPym .= "</div class='table-responsive no-padding no-border'>";
        $strByPym .= "<br>";
    }

    if (isset($settlementByBahan) && sizeof($settlementByBahan) > 0) {
        if (isset($headerByBahan) && sizeof($headerByBahan) > 0) {
            $strByBahan .= "<div class='table-responsive no-padding no-border'>";
            $strByBahan .= "<h3>$labelByBahan</h3>";
            $strByBahan .= "<table class='table table-condensed no-padding table-bordered no-margin'>";
            $strByBahan .= "<tr class='bg-grey-2 text-uppercase'>";
            $strByBahan .= "<th style='width:0.5%;' class='text-center'>";
            $strByBahan .= "No.";
            $strByBahan .= "</th>";
            foreach ($headerByBahan as $key => $val) {
                $strByBahan .= "<th class='text-muted text-center'>";
                $strByBahan .= $val;
                $strByBahan .= "</th>";
            }
        }
        $strByBahan .= "<tr class='bg-grey-2 text-uppercase'>";

        $no_menu = 0;
        $total_menu = array();
        foreach ($settlementByBahan as $mSpec) {
            $no_menu++;
            $strByBahan .= "<tr>";
            $strByBahan .= "<td style='text-align: right;'>$no_menu</td>";

            foreach ($headerByBahan as $key => $val) {

                $colVal = isset($mSpec[$key]) ? formatField_he_format($key, $mSpec[$key]) : "";
                $strByBahan .= "<td>$colVal</td>";

                if (isset($mSpec[$key]) && is_numeric($mSpec[$key])) {
                    if (!isset($total_menu[$key])) {
                        $total_menu[$key] = 0;
                    }
                    $total_menu[$key] += $mSpec[$key];
                }
            }
            $strByBahan .= "</tr>";
        }
        $strByBahan .= "<tr>";
        $strByBahan .= "<td style='text-align: right;' colspan='3'>TOTAL</td>";
        foreach ($headerByBahan as $key => $val) {
            if (isset($total_menu[$key])) {
                $colVal = formatField_he_format($key, $total_menu[$key]);
                $strByBahan .= "<td>$colVal</td>";
            }
        }
        $strByBahan .= "</tr>";
        $strByBahan .= "</table class='table table-condensed no-padding table-bordered no-margin'>";
        $strByBahan .= "</div class='table-responsive no-padding no-border'>";
    }

    echo $strByTrans;
    echo $strByMenu;
    echo $strByPym;
    echo $strByBahan;

}
else {
    // arrPrintPink($items);
    if (isset($items)) {

        if (isset($fixedNoteTop)) {
            echo "<div class='alert alert-danger' style='margin-top: 0px;font-size: 15px;'>";
            echo "<span>$fixedNoteTop</span>";
            echo "</div>";
        }
        $showItems = isset($showItems) && strlen($showItems) > 0 && $showItems == "false" ? false : "true";
        if (sizeof($items) > 0) {
            $jmlKolomHeader = sizeof($itemLabels) + 2;

            $jmlItems = count($items);
            $jmlQtys = 0;
            $grandTotalRp = isset($main['grand_total']) ? number_format($main['grand_total']) : 0;

            foreach($items as $k => $rItems){
                $jmlQtys += $rItems['qty_unit'];
            }

            echo $info_member_style;

            echo "<div class='no-padding no-border'>";
            echo "<style>table.dataTable.compact tbody th, table.dataTable.compact tbody td { padding: 0px 0px; }</style>";
            echo "<style>table.dataTable.compact tbody td > input, table.dataTable.compact tbody td > span, table.dataTable.compact tbody td > select { border: 0px !important; }</style>";
            echo "<table class='table table-condensed no-padding table-bordered no-margin dataTable compact'>";
            echo "<thead>";

            //region clear shoping cart
            if (!$avoidRemove) {
                echo "<tr class='bg-grey-2'>";
                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";
                echo "<span class='pull-left'>";
                echo "<button id='btn_clear_shopping_cart' type='button' class='text-red btn btn-xs' title='remove ALL ITEMS' data-toggle='tooltip' data-placement='right' onclick=\"confirm_alert_result('Attention !!!','Remove all items on shopping cart?','$resetLink','YES CLEAR');\"><i class='fa fa-trash'> </i> Clear Shoping Cart</button>";
                echo "</span>";
                echo "</td>";
                echo "</tr>";
            }
            //endregion

            //region clear shoping cart
//            if ($selectAll) {
//                echo "<tr class='bg-grey-2'>";
//                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";
//                echo "<span class='pull-left'>";
//                echo "<label>Select All <input type='checkbox' id='select_all' class='select2'></label> ";
//                echo "</span>";
//                echo "<div class='text-red text-bold text-center fa-2x'> SILAHKAN CENTANG PRODUK YANG AKAN DI BATALKAN </div>";
//                echo "</td>";
//                echo "</tr>";
//            }
            //endregion

            /*===============header shoping cart======================*/
            if (isset($itemLabels)) {
                if (sizeof($itemLabels) && (is_array($itemLabels)) && $showItems) {
                    echo "<tr class='bg-grey-2 text-uppercase'>";
                    echo "<th style='width:5px;' class='text-center'>";
                    echo "URUT";
                    echo "</th>";
                    foreach ($itemLabels as $key => $label) {
                        if($key=="jml" || $key=="qty" || $key=="qty_unit"){
                            echo "<th style='max-width:5px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="barcode"){
                            echo "<th style='min-width:70px;max-width:80px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="nama"){
                            echo "<th style='min-width:150px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="satuan_factor_nama"){
                            echo "<th style='min-width:12px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        else{
                            echo "<th style='min-width:50px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                    }
                    if (!$avoidRemove) {
                        // echo "<th style='width:1%;' class='text-muted text-center'>";
                        // echo "x";
                        // echo "</th>";
                    }
                    echo "</tr>";
                }
            }

            echo "</thead>";

            /*===============body shoping cart=======================================*/
            $no = 0;

            echo "<tbody>";
            foreach ($items as $iSpec) {
                if ($showItems) {

                    $iID = $iSpec['id'];
                    $rowRemove = "";
//                    if ($selectAll) {
//                        $rowRemove .= "<input type='checkbox' class='checkbox_prd' id='chkPrd_".$iSpec['id']."' name='produk_id[".$iSpec['id']."]'>";
//                    }
//                    else{
                        $rowRemove = "<a href='javascript:void(0);' class='btn btn-xs bg-red text-white' title='remove this item' data-toggle='tooltip' data-placement='left' onclick=\"document.getElementById('result').src='" . $iSpec['removeTarget'] . "';setTimeout( function(){ $('#shopping_cart').trigger('change') }, 1500);\"><i class='fa fa-close'></i></a>";
//                    }


                    $no++;
                    $bgColor = "transparent";
                    if (isset($_SESSION['errLines'])) {
                        if (in_array($iSpec['id'], $_SESSION["errLines"])) {
                            $bgColor = "#ffff77";
                        }
                    }

                    echo "<tr id='tr_" . $iSpec['id'] . "' bgcolor=$bgColor>";
                    echo "<td style='vertical-align:middle; width:15px;' class='text-center'>";
                    echo "<span class='text-bold'>$rowRemove &nbsp; $no</span>";
                    echo "</td>";

                    $colCtr = 0;
                    $queryParams = "";
                    $colID = array();
                    $listMode = array();
                    $readOnly = array();
                    $qtyParam = "";
                    if (isset($itemLabels['jml'])) {
                        $qtyParam = "+document.getElementById('jml_$no').value";
                    }
                    if (isset($itemLabels['qty_unit'])) {
                        $qtyParam = "+removeCommas(document.getElementById('qty_unit_$no').value)";
                    }
                    foreach ($itemLabels as $key => $label) {
                        if (isset($optionItemField[$key])) {
                            $listMode[$key] = "option";
                        }
                        else {
                            $listMode[$key] = "input";
                        }
                        $keyupEvent[$key] = "";
                        $keyUpStr[$key] = "";
                        if (array_key_exists($key, $keyUpEvents)) {
                            if (sizeof($selectedPrices) > 0) {
                                $keyupEvent[$key] = $keyUpEvents[$key];
                                foreach ($selectedPrices as $k => $v) {
                                    $nameLabel = $k . "_" . $no;
                                    $keyupEvent[$key] = str_replace("{" . $k . "}", $nameLabel, $keyupEvent[$key]);
                                }
                                foreach ($itemLabels as $k => $v) {
                                    $nameLabel = $k . "_" . $no;
                                    $keyupEvent[$key] = str_replace("{" . $k . "}", $nameLabel, $keyupEvent[$key]);
                                }
                            }
                            if (isset($keyupAction) && $keyupAction == true) {
                                $keyupEvent[$key] = $keyUpEvents[$key];
                                foreach ($selectedPrices as $k => $v) {
                                    $nameLabel = $k . "_" . $no;
                                    $keyupEvent[$key] = str_replace("{" . $k . "}", $nameLabel, $keyupEvent[$key]);
                                }
                                foreach ($itemLabels as $k => $v) {
                                    $nameLabel = $k . "_" . $no;
                                    $keyupEvent[$key] = str_replace("{" . $k . "}", $nameLabel, $keyupEvent[$key]);
                                }
                            }
                        }
                        else {
                        }
                        if (strlen($keyupEvent[$key]) > 2) {
                            $keyUpStr[$key] = " onkeyup=\"" . $keyupEvent[$key] . "\" ";
                        }
                        if (in_array($key, $editableFields)) {
                            $readOnly[$key] = "";
                            if (isset($iSpec["jml"]) && $iSpec["jml"] < 1) {
                                $readOnly[$key] = "readonly_xz";
                            }
                            if (isset($paramsForceEditable[$key])) {
                                if ($paramsForceEditable[$key] == true) {

                                }
                                else {
                                    $readOnly[$key] = "readonly_xxz";
                                    $listMode[$key] = "text";
                                }
                            }
                        }
                        else {
                            $readOnly[$key] = "readonly_xxz";
                            $listMode[$key] = "text";
                        }
                        $colID[$key] = $key . "_" . $no;
                        if ($listMode[$key] == "input") {
                            $queryParams .= "&$key='+removeCommas(document.getElementById('" . $colID[$key] . "').value)+'";
                        }
                    }
                    $tabIndex = 1000;
                    foreach ($itemLabels as $key => $label) {
                        $colCtr++;
                        $color = "343434";
                        if (isset($_SESSION['errFields'][$iSpec['id']])) {
                            if (in_array($key, $_SESSION['errFields'][$iSpec['id']])) {
                                $color = "#dd3300";
                            }
                        }
                        echo "<td>";
                        $colID = $key . "_" . $no;
                        $keyID = $key;
                        $noID = $no;
                        $tabIndexNum = $colCtr . $no;
                        $fieldVal = "";

                        $js_tr_free_prod = ($key=="nama" && isset($free_items[$iID])) || ($key=="nama" && isset($iSpec['free_produk_note']) && $iSpec['free_produk_note']!='' ) ? "<i onclick=\"$('#tr_free_prod_$iID').toggleClass('in out')\" title='click untuk melihat diskon' class='fa fa-gift text-yellow'></i>&nbsp;" : "";

                        if (substr($key, 0, 1) == "*") {
                            $key_p = str_replace("*", "", $key);
                            $key_ex = explode("#", $key_p);
                            $pair_name = $key_ex[0];
                            $pair_key = $key_ex[1];
                            $pair_key_val = $iSpec[$pair_key];
                            if (sizeof($key_ex) > 1) {
                                $fieldVal = isset($pairedValue[$pair_name][$pair_key_val]) ? $pairedValue[$pair_name][$pair_key_val] : "0";
                            }
                            else {
                                $fieldVal = isset($pairedValue[$pair_name]) ? $pairedValue[$pair_name] : "0";
                            }
                        }
                        else {
                            if (isset($iSpec[$key])) {
                                if (is_numeric($iSpec[$key])) {
                                    $fieldVal = $iSpec[$key] + 0;
                                }
                                else {
                                    $fieldVal = $iSpec[$key];
                                }
                            }
                        }
                        if (sizeof($minValues) > 0) {
                            $moq = isset($minValues['moq'][$iID]) ? $minValues['moq'][$iID] : 0;
                            $validateKey_up = true;
                        }
                        else {
                            $moq = 0;
                            $validateKey_up = false;
                        }
                        $keyupData = (($key == "qty" || $key == "jml") && $validateKey_up == true) ? "onkeydown=\"if(parseInt(removeCommas(this.value))<$moq){setTimeout(function(){ this.value='" . $iSpec[$key] . "'}, 1000);} \"" : "";

                        switch ($listMode[$key]) {
                            case "input":
                                echo "<input type='number' tabindex=" . ($tabIndex + $noID) . " min='$moq' autocomplete='off' " . $readOnly[$key] . " keyid=$keyID noid=$noID id_jml=$iID id=$colID  class='form-control text-center text-bold' style='background:#00ff8a;color:$color;' value='" . $fieldVal . "' onclick=\"this.select();$(this).parent().parent().css('background-color','yellow');\" " . $keyUpStr[$key] . " ";

                                $baseInputName = isset($unionSelectors['base']) ? "document.getElementById('" . $unionSelectors['base'] . "_" . $no . "')" : "this";

                                $pemicuGerbangAsli = "onblur=\"$(this).parent().parent().css('background-color', 'white');if(removeCommas(this.value)!=removeCommas(this.defaultValue)){hiliteDiv(this);getData('" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams','result');} \" $keyupData";
                                $pemicuGerbangAsli .= "onmouseout=\"if(removeCommas(this.value)!=removeCommas(this.defaultValue)){hiliteDiv(this);document.getElementById('result').src='" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams';}\" ";

                                $pemicuGerbang = "onblur=\"$(this).parent().parent().css('background-color', 'white');if(removeCommas($baseInputName.value(!=removeCommas($baseInputName.defaultValue)){hiliteDiv($baseInputName);getData('" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams','result');}\" $keyupData ";
                                $pemicuGerbang .= "onmouseout=\"if(removeCommas($baseInputName.value)!=removeCommas($baseInputName.defaultValue)){hiliteDiv($baseInputName);getData('" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams','result');}\" ";

                                $pemicuGerbangUnion = "onchange=\"if(removeCommas($baseInputName.value!=$baseInputName.defaultValue)){hiliteDiv($baseInputName);getData('" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams','result');} \" ";

                                if (isset($unionSelectors['base'])) {
                                    if ($unionSelectors['base'] == $key) {//==jadi acuan kiriman
                                        echo str_replace("this", $baseInputName, $pemicuGerbang);
                                    }
                                    else {
                                        if (in_array($key, $unionSelectors['members'])) {//==jadi member union, tidak memicu perubahan gerbang
                                            echo $pemicuGerbangUnion;
                                        }
                                        else {//==biasa aja, memicu perubahan gerbang
                                            echo $pemicuGerbangAsli;
                                        }
                                    }
                                }
                                else {
                                    echo $pemicuGerbangAsli;
                                }

                                if (isset($keyupAction) && $keyupAction == true) {
                                    echo "onkeyup=\"document.getElementById('result').src='" . $iSpec['editTarget'] . "'$qtyParam+'$queryParams';\"";
                                }
                                else {
                                    echo "onkeyup=\"delay_v2( function(){ $('#shopping_cart').trigger('change') }, 400, this );\"";
                                }
                                echo ">";

                                $tabIndex += $tabIndex;

                                break;
                            case "text":
                                if (is_numeric($fieldVal)) {
                                    echo "<span numeric keyid=$keyID noid=$noID id=$colID class='form-control text-bold text-right' style='color:$color;background-color: transparent!important;'>" . ( $keyID == 'barcode' ? $fieldVal : number_format($fieldVal) ) . "</span>";
                                }
                                else {
                                    if (strlen($fieldVal) > 35) {
                                        $fieldVal_f = substr($iSpec[$key], 0, 35) . '...';
                                        echo "<span panjang35 keyid=$keyID noid=$noID id=$colID title='".trim($fieldVal)."' class='form-control text-bold text-left text-uppercase' style='color:$color;border:0px;white-space: nowrap;background-color: transparent!important;'>$js_tr_free_prod " . formatField_he_format($key, $fieldVal_f) . "</span>";
                                    }
                                    else {
                                        echo "<span panjang34 keyid=$keyID noid=$noID id=$colID class='form-control text-bold text-left text-uppercase' style='color:$color;border:0px;white-space: nowrap;background-color: transparent!important;'>$js_tr_free_prod " . formatField_he_format($key, $fieldVal) . "</span>";
                                    }
                                }
                                break;

                            case "option":
                                $keyOptionIndex = $optionItemField[$key]["keySrc"];
                                $qparams = blobEncode($optionItemField[$key]["usedFields"]);
                                $processorTargetOption = MODUL_PATH . "" . $optionItemField[$key]["selectorProcessor"];
                                $actionTrigger = "onchange=\"document.getElementById('result').src='" . $processorTargetOption . "/?pid=$iID&key=$keyOptionIndex&jml=".$iSpec['jml']."&qty_unit=".$iSpec['qty_unit']."&qparams=$qparams&value='+this.value;\" ";
                                $optionField = "<select onblur=\"console.log('test blur');$(this).parent().parent().css('background-color', 'white');\" onfocus=\"console.log('test focus');$(this).parent().parent().css('background-color','yellow')\" keyid=$keyID noid=$noID name='$colID' id='$colID' style='background:#00ff8a;' class='form-control text-bold' $actionTrigger>";
                                $prevData = isset($items3[$iID]) ? $items3[$iID] : "";
                                foreach ($items3[$iID][$key] as $iiD2 => $iiData) {
                                    $selected = $iSpec["satuan_factor_id"] == $iiD2 ? "selected" : "";
                                    $optionField .= "<option value='" . $iiD2 . "' $selected >$iiData[$key] <span style=\"font-size:1em ;margin:0px 2px 0px 2px;color:#0056cd;\" pull-right class='text-blue'>(Isi " . $iiData["satuan_factor_qty"] . ")</span></option>";
                                }
                                $optionField .= "</select>";
                                echo $optionField;
                                break;
                        }
                        echo "</td>";


                    }

                    //region remover per row
                    if (!$avoidRemove) {
//                         echo "<td width='1%'>";
//                         echo "<a class='text-red btn' title='remove this item' data-toggle='tooltip' data-placement='left' onclick=\"document.getElementById('result').src='" . $iSpec['removeTarget'] . "';\"><span class='glyphicon glyphicon-remove'></span></a>";
//                         echo "</td>";
                    }
                    //endregion

                    echo "</tr>";

                    if( isset($free_items[$iID]) ){

                        foreach($free_items[$iID] as $idDiskon => $rowDiskon){
                            $freeLabelCol = count($itemLabels);
                            echo "<tr id='tr_free_prod_$iID' class='collapse in'>";

                            echo "<td style='padding: 2px;font-size: 12px;' colspan='2' class='text-center'>";
                            echo "<span class='text-bold text-green form-controlx'><i class='fa fa-gift'></i> Get Free Produk <i class='fa fa-check-circle'></i></span>";
                            echo "</td>";

                            echo "<td style='padding: 2px;font-size: 12px;' colspan='$freeLabelCol' class='text-left'>";
                            echo "<span style='font-size: 12px;' class='text-bold text-green form-controls text-capitalize'> &nbsp; &nbsp; &nbsp; " . $rowDiskon['free_qty'] . "x " . $rowDiskon['free_produk_nama'] . "</span> &nbsp; &nbsp; &nbsp; <span>".$rowDiskon['free_produk_note']."</span>";
                            echo "</td>";

                            echo "</tr>";
                        }

                    }
                    else if( isset($iSpec['free_produk_note']) && $iSpec['free_produk_note']!=""){

                        $freeLabelCol = count($itemLabels);

                        if(!$isMobile && !$onPreOrderOnly){
                            echo "<tr id='tr_free_prod_$iID' class='collapse in'>";

                        echo "<td style='padding: 2px;font-size: 12px;' colspan='2' class='text-center'>";
                        echo "<span style='font-family: monospace;' class='text-bold text-default form-controlx'><i class='fa fa-gift text-red blink'></i> Ada Diskon Produk <i class='fa fa-gift text-red blink'></i></span>";
                        echo "</td>";

                        echo "<td style='padding: 2px;font-size: 12px;' colspan='$freeLabelCol' class='text-left'>";
                            echo "<span style='font-size: 12px;font-family: monospace;' class='text-bolds text-default text-capitalize'> &nbsp; <b><r>INFORMASI DISKON PRODUK:</r></b>  " . $iSpec['free_produk_note']."</span>";
                        echo "</td>";

                        echo "</tr>";
                        }
                        else{
                            echo "<tr id='tr_free_prod_$iID' class='collapse'>";

                            echo "<td style='padding: 2px;font-size: 12px;' colspan='".($freeLabelCol+1)."' class='text-left'>";
                            echo "<span style='font-size: 12px;font-family: monospace;' class='text-bolds text-default text-capitalize'><b><r>INFORMASI DISKON PRODUK:</r></b><br>" . $iSpec['free_produk_note']."</span>";
                            echo "</td>";

                            echo "</tr>";
                    }


                    }
                    else{

                    }

                    if ($noteEnabled == true) {
                        $colspan2 = $imageEnable == true ? 1 : -1;
                        $colspan = sizeof($itemLabels) - $colspan2;
                        echo "<tr>";
                        echo "<td>&nbsp;</td>";
                        echo "<td colspan='" . $colspan . "'>";
                        $noteVal = isset($iSpec['note']) ? $iSpec['note'] : "";
                        if (isset($noteType)) {
                            switch ($noteType) {
                                case "textarea":
                                    echo "<textarea class='form-control' placeholder='write notes here'
                                onblur=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                onmouseout=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                >$noteVal</textarea>";
                                    break;
                                case "text":
                                default:
                                    echo "<input type=text class='form-control' value='$noteVal' placeholder='write notes here'
                                onblur=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                onmouseout=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                >";
                                    break;
                            }
                        }

                        echo "</td>";
                        if ($imageEnable == true) {
                            echo "<td colspan='2'>";
                            $imageVal = isset($iSpec['images']) ? $iSpec['images'] : "";
                            if (isset($imageType)) {
                                switch ($imageType) {
                                    case "images":

                                        $file_e = "";
                                        $file = isset($iSpec['images']) ? $iSpec['images'] : "";
                                        $file_e = urlencode($file);
                                        echo "<div class='input-groups'>";
                                        if (strlen($imageVal) > 0) {
                                            $modals = array(
                                                "title" => "Attachment " . $iSpec['nama'],
                                                "body"  => array($file),
                                            );
                                            $modal_e = urlencode(blobEncode($modals));
                                            $modal_l = base_url() . "Katalog/modal/$modal_e";

                                            echo "<a href='$modal_l' data-toggle='modal' data-target='#myModal'><img src='$file' class='img-rounder' height='50px' style='float: right;'></a>";
                                            echo "<input type='hidden' name='img_$iID' value='$file'>";
                                        }

                                        echo "<form class='input-group' id='myForm_$iID' method='post' enctype='multipart/form-data' action='$imageRecorder/$iID?valValue=$file_e' target='result'>";

                                        echo "<input type='file' id='file-upload' style='border: none;' name='file' class='file' onchange=\"document.getElementById('myForm_$iID').submit();swal({'text':'uploading image ... ... ',showConfirmButton: false,timer:5000,});\">";

                                        echo "</form>";
                                        echo "</div>";

                                        break;
                                    case "text":
                                    default:
                                        echo "<input type=text class='form-control' value='$noteVal'
                                onblur=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                onmouseout=\"if(this.value!=this.defaultValue){hiliteDiv(this);document.getElementById('result').src='" . $noteRecorder . "?val='+encodeURIComponent(this.value)+'&iid=$iID';}\"
                                >";
                                        break;
                                }
                            }
                            echo "</td>";
                        }
                        echo "</tr>";
                    }
                    if ($pairedItemEnabled == true) {
                        if (sizeof($pairedItemField) > 0) {
                            $listModePairedItem = array();
                            $readOnlyPairedItem = array();
                            foreach ($pairedItemField as $key => $label) {
                                $listModePairedItem[$key] = "input";
                                if (in_array($key, $editableFields)) {
                                    $readOnlyPairedItem[$key] = "";
                                    if (isset($iSpec["jml"]) && $iSpec["jml"] < 1) {
                                        $readOnlyPairedItem[$key] = "readonly_x";
                                    }
                                }
                                else {
                                    $readOnlyPairedItem[$key] = "readonly_xx";
                                    $listModePairedItem[$key] = "text";
                                }
                            }
                        }
                        echo "<tr>";
                        echo "<td>&nbsp;</td>";
                        $c_itemLabels = sizeof($itemLabels);
                        $c_pairedItemField = sizeof($pairedItemField);
                        $c_colspan = ($c_itemLabels - $c_pairedItemField + 1);
                        echo "<td colspan='" . $c_colspan . "'>";
                        //==pairedItems, if any
                        if (isset($selItems) && sizeof($selItems) > 0) {
                            echo "<select
                                title='Choose one of the following...'
                                data-header='Ketik Nama/Kode/Folder/Barcode'
                                data-size='10'
                                data-container='body'
                                class='picker_$iID selectpicker form-control select2 show-tick'
                                data-style='btn-primary'
                                data-live-search='true'
                                classs='form-control'
                                onchange=\"document.getElementById('result').src='" . $pairedItemRecorder . "?val='+(this.value)+'&iid=$iID'\"
                                >";

                            asort($selItems);

                            foreach ($selItems as $piID => $piName) {
                                if ($piID != $iSpec['id']) {
                                    $selectedState = (isset($pairedItems[$iID]) && ($piID == $pairedItems[$iID]['id'])) ? "selected" : "";
                                    $selItemsKodes = isset($selItemsKode[$piID]) ? $selItemsKode[$piID] : "-";
                                    $selItemsFolders = isset($selItemsFolder[$piID]) ? $selItemsFolder[$piID] : "-";
                                    $selItemsKeterangans = isset($selItemsKeterangan[$piID]) ? $selItemsKeterangan[$piID] : "-";
                                    $selItemsBarcodes = isset($selItemsBarcode[$piID]) ? $selItemsBarcode[$piID] : "-";
                                    echo "<option data-subtext='$selItemsKodes' data-tokens='$piID $selItemsFolders $selItemsKeterangans $selItemsBarcodes' value='$piID' $selectedState>$piName </option>";
                                }
                            }
                            echo "</select>";
                        }

                        echo "</td>";

                        echo "<script> $('.picker_$iID').selectpicker(); </script>";

                        if (sizeof($pairedItemField) > 0) {
                            foreach ($pairedItemField as $key => $label) {
                                $pairedItems2ID = isset($pairedItems[$iID]['id']) ? $pairedItems[$iID]['id'] : 0;
                                $pairedItems2Qty = isset($pairedItems[$iID]['jml']) ? $pairedItems[$iID]['jml'] : 0;
                                $fieldVal = isset($pairedItems[$iID][$key]) ? $pairedItems[$iID][$key] : "";
                                echo "<td>";
                                switch ($listMode[$key]) {
                                    case "input":
                                        echo "<input type='number' class='form-control text-right' value='" . $pairedItems2Qty . "' min='0' autocomplete='off'
                                    onblur=\"document.getElementById('result').src='" . $pairedItemRecorder . "?newQty='+(this.value)+'&iid=$iID&val=$pairedItems2ID&spc=1';\"
                                    onmouseout06=\"document.getElementById('result').src='" . $pairedItemRecorder . "?newQty='+(this.value)+'&iid=$iID&val=$pairedItems2ID&spc=1';\"
                                    >";
                                        break;
                                    case "text":
                                        if (is_numeric($fieldVal)) {
                                            echo "<span class='form-control text-right' style='color:$color;background:#f0f0f0;'>" . number_format($fieldVal) . "</span>";
                                        }
                                        else {
                                            echo "<span class='form-control text-left' style='color:$color;border:0px;'>" . str_replace(" ", "&nbsp;", $fieldVal) . "</span>";
                                        }
                                        break;
                                }
                                echo "</td>";
                            }
                        }
                        echo "</tr>";
                    }
                }
            }
            //region items2, kalau salah satunya untuk produksi dan konversi
            if (isset($items2) && sizeof($items2) > 0) {
                echo "<tr class='bg-info'>";
                echo "<td colspan='$jmlKolomHeader'>";
                echo "<div class='panel no-margin'>"; // anakan table
                echo "<table class='table table-condensed table-striped no-padding no-border'>";
                if (sizeof($itemLabels2) && (is_array($itemLabels2)) && $showItems) {
                    echo "<tr>";
                    echo "<td class='text-muted bg-grey-1 text-center'>";
                    echo "No";
                    echo "</td>";
                    foreach ($itemLabels2 as $key => $label) {
                        echo "<td class='text-muted bg-grey-1 text-center text-capitalize'>";
                        echo $label;
                        echo "</td>";
                    }
                    echo "</tr>";
                }
                $no = 0;
                $kurangStoks = array();
                foreach ($items2 as $iSpec) {
                    $iID = $iSpec['id'];
                    $no++;
                    $bgColor = "transparent";
                    if (isset($items2_sum_kurang) && is_array($items2_sum_kurang)) {
                        if (isset($items2_sum_kurang[$iID])) {
                            $bgColor = "yellow";
                        }
                    }
                    if (isset($_SESSION['errLines'])) {
                        if (in_array($iSpec['id'], $_SESSION["errLines"])) {
                            $bgColor = "#ffff77";
                        }
                    }
                    echo "<tr id='tr_" . $iSpec['id'] . "' bgcolor=$bgColor>";
                    echo "<td width='5%'>";
                    echo $no;
                    echo ".</td>";
                    $colCtr = 0;
                    $queryParams = "";
                    foreach ($itemLabels2 as $key => $label) {
                        $colID = $key . "_" . $no;
                        $queryParams .= "&$key='+document.getElementById('$colID').value+'";
                    }
                    foreach ($itemLabels2 as $key => $label) {
                        $colCtr++;
                        $color = "343434";
                        if (isset($_SESSION['errFields'][$iSpec['id']])) {
                            if (in_array($key, $_SESSION['errFields'][$iSpec['id']])) {
                                $color = "#dd3300";
                            }
                        }
                        $cAlign = is_numeric($iSpec[$key]) ? "text-right" : "text-left";
                        if ($key == "sisa") {
                            if ($iSpec[$key] < 0) {
                                $kurangStoks[$iSpec['nama']] = $iSpec['sisa'];
                                $cAlign .= " text-red text-bold";
                            }
                            else {
                                $cAlign .= "";
                            }
                        }
                        echo "<td class='$cAlign'>";
                        $tabIndexNum = $colCtr . $no;
                        if (is_numeric($iSpec[$key])) {
                            echo formatField_he_format($key, $iSpec[$key]);
                        }
                        else {
                            echo $iSpec[$key];
                        }
                        echo "</td>";
                    }
                    echo "</tr>";
                }
                echo "</table>";
                echo "</div>"; // anakan table
                echo "</td>";
                echo "</tr>";
            }
            //endregion items2, kalau salah satunya untuk produksi dan konversi
            echo "</tbody>";

//            echo "</table class='table'>";
//
//            echo "<table class='table table-condensed no-padding table-bordered no-margin dataTable compact'>";
            /*=============================sumrows============================*/
            if (isset($sumRows) && sizeof($sumRows) > 0) {
                $nr = 0;
                foreach ($sumRows as $key => $label) {
                    $val = 0;
                    $nr++;
                    $bottom_borderless = $nr < sizeof($sumRows) ? "bottom-borderlessx" : "";
                    if (isset($main[$key]) && $main[$key] > 0) {
                        $val = $main[$key];
                    }
                    else {
                        if (isset($addValues[$key]) && $addValues[$key] > 0) {
                            $val = $addValues[$key];
                        }
                    }
                    if ($showItems) {
                        echo "<tr class=''>";
                        echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right $bottom_borderless valign-m text-uppercase text-bold text-muted'>$label &nbsp; &nbsp; &nbsp;</td>";
                        echo "<td colspan='3' class='right-borderlessx'>";
                        echo "<input type='text' id='$key' class='form-control text-right text-bold' readonly value='" . number_format($val) . "' >";
                        echo "</td>";
                        echo "</tr>";
                    }
                }
            }
            if (isset($sumRows2) && sizeof($sumRows2) > 0) {
                echo "<tr bgcolor='#e0e0e0'>";
                echo "<td colspan='" . (sizeof($itemLabels2) + 1) . "' class='text-left text-muted'><span class='fa fa-cog'></span> additional fees</td>";
                echo "</td>";
                echo "</tr>";
                $nr = 0;
                foreach ($sumRows2 as $key => $label) {
                    $nr++;
                    $bottom_borderless = $nr < sizeof($sumRows2) ? "bottom-borderless" : "";
                    echo "<tr bgcolor='#f0f0f5'>";
                    echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right bottom-borderless valign-m text-uppercase'>$label</td>";
                    echo "<td>";
                    echo $sumSpec2[$key];
                    echo "</td>";
                    echo "</tr>";
                }
            }

            if (sizeof($addRows) > 0 && !$onPreOrderOnly ) {
                $nr = 0;
                foreach ($addRowLabels as $k => $label) {
                    $nr++;
                    $bottom_borderless = $nr < sizeof($addRowLabels) ? "bottom-borderless" : "";
                    $rowHide = isset($addRowHiddens[$k]) ? $addRowHiddens[$k] : "";

                    echo "<tr addRows class='$rowHide'>";
                    echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right $bottom_borderless valign-m text-uppercase text-bold text-muted'>$label &nbsp; &nbsp; &nbsp;</td>";
                    echo "<td colspan='2' class='text-right'>";
                    echo $addRows[$k];
                    echo "</td>";
                    echo "</tr>";

                }
            }

            //region clear shoping cart
            if (!$avoidRemove) {
                echo "<tr class='bg-grey-2'>";
                // echo "<td>&nbsp;</td>";
                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";

                echo "<span class='pull-left'>";
                echo "<button style='margin: 3px;' id='btn_clear_shopping_cart' type='button' class='text-red btn btn-xs' title='remove ALL ITEMS' data-toggle='tooltip' data-placement='right' onclick=\"confirm_alert_result('Attention !!!','Remove all items on shopping cart?','$resetLink','YES CLEAR');\"><i class='fa fa-trash'> </i> Clear Shoping Cart</button>";
                echo "</span>";
//                if (isset($main['oto_diskon'])) {
//                    echo "<input id='r_oto_diskon' class='hidden' value='" . $main['oto_diskon'] . "'>";
//                }
//                 arrPrintPink($tmpSaver);
                if (sizeof($tmpSaver) > 0) {
                    $link_tmpSave = MODUL_PATH . $tmpSaver["exeTarget"];
                    $link_reqDiskon = MODUL_PATH . $reqDiskon["exeTarget"];
                    echo "&nbsp;<button style='margin: 3px;' type='button' id='tmp_save' class='btn btn-md btn-primary pull-right' onclick=\"btn_result('$link_tmpSave');\"><i class='fa " . $tmpSaver['btnIcon'] . "'>&nbsp;</i> " . $tmpSaver['btnLabel'] . "</button>";
//                    if (sizeof($reqDiskon) > 0) {
//                        echo "<button type='button' id='req_diskon' class='btn btn-warning' onclick=\"btn_result('$link_reqDiskon');\"><i class='fa " . $reqDiskon['btnIcon'] . "'>&nbsp;</i> " . $reqDiskon['btnLabel'] . "</button>&nbsp;";
//                    }
                }
                echo "<span id='btn_kalkulasi' class='pusll-left hidden'>";
                echo "<button type='button' class='btn btn-danger text-normal' titles='kalkulasi' data-toggle='tooltip' data-placement='right' onclick=\"fillBoxes()\"><i class='fa fa-refresh fa-spin'></i> <i id='kalkulasi'></i> Update View</button>";
                echo "</span>";
                echo "</td>";
                echo "</tr>";
            }
            //endregion
            $info_customer = 1;
            if ($info_customer && !$onPreOrderOnly) {
                echo "<tr class='bg-grey'>";
                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";
                echo "<div class='text-left bg-grey' style='hheight: 80px;margin: 6px;'><div>$str_customer-</div></div>";
                echo "</td>";
                echo "</tr>";
            }

            echo "</table class='table'>";
            echo "</div class='table-responsive'>";

            if (isset($fixedNote)) {
                echo "<div class='alert alert-danger' style='margin-top: 10px;font-size: 15px;'>";
                echo "<span>$fixedNote</span>";
                echo "</div>";
            }
            if (sizeof($elements) > 0 && !$onPreOrderOnly) {
                echo "<div class='panel-body hiddenss table-responsive'>";
                echo "<div class='row'>";
                echo "<div class='col-md-12'>";
                echo "<h4 class='text-blue text-left'>Please fill in details below (element)</h4>";
                echo "</div class='col-md-12'>";
                echo "</div class='row'>";
                echo "<div class='col-lg-12 no-padding text-center' style='text-align:center;'>";
                $elCtr = 0;
                foreach ($elements as $eName => $pSpec) {
                    $elCtr++;
                    if (isset($pSpec['type']) && ($pSpec['type'] == "hidden")) {
                        // type hidden tidak perlu tampil di ui //
                    }
                    else {

                        if ($isMobile) {
                            //region penampil untuk elemen pada shopingcart
                            echo "<div class='col-md-6 col-lg-6 col-xs-12' style='border:2px #e1ece6 solid;margin:0px;background:" . $pSpec['bgColor'] . "'>";
                            echo "<div id='elTitle_$eName' class='text-left text-muted text-bold text-capitalize'>";

                            echo $pSpec['label'] . " ";
                            if (isset($elementConfigs[$eName]['autoSelect']) && $elementConfigs[$eName]['autoSelect']) {

                            }
                            else {
                                echo "<a href='javascript:void(0)' onclick=\"hiliteDiv(this);document.getElementById('result').src='" . $elementResetTarget . "$eName';\"><span class='fa fa-eraser'></span></a>";
                            }
                            echo "<span class='pull-right'><sup>" . $pSpec['editStr'] . "&nbsp;" . $pSpec['addStr'] . "</sup></span>";
                            echo "</div class='box-title'>";

                            if (isset($elementConfigs[$eName]['warningLabel']) && $elementConfigs[$eName]['warningLabel']) {
                                echo "<div class='col-md-12'>" . $elementConfigs[$eName]['warningLabel'] . "</div>";
                            }

                            echo "<div class=''>&nbsp;</div>";
                            echo $pSpec['string'];
                            echo "</div>";
                            //endregion
                        }
                        else {
                            //region penampil untuk elemen pada shopingcart
                            if ($elCtr % 2 == 0) {
                            }
                            else {
                                echo "<div class='col-lg-12 no-padding'>";
                                echo "<div class='row row-eq-height'>";
                            }
                            echo "<div class='col-md-6 col-lg-6 col-xs-12' style='border:2px #e1ece6 solid;margin:0px;background:" . $pSpec['bgColor'] . "'>";

                            echo "<div id='elTitle_$eName' class='text-left text-muted text-bold text-capitalize'>";

                            echo $pSpec['label'] . " ";
                            if (isset($elementConfigs[$eName]['autoSelect']) && $elementConfigs[$eName]['autoSelect']) {

                            }
                            else {
                                echo "<a href='javascript:void(0)' onclick=\"hiliteDiv(this);document.getElementById('result').src='" . $elementResetTarget . "$eName';\"><span class='fa fa-eraser'></span></a>";
                            }
                            echo "<span class='pull-right'><sup>" . $pSpec['editStr'] . "&nbsp;" . $pSpec['addStr'] . "</sup></span>";
                            echo "</div class='box-title'>";

                            if (isset($elementConfigs[$eName]['warningLabel']) && $elementConfigs[$eName]['warningLabel']) {
                                echo "<div class='col-md-12'>" . $elementConfigs[$eName]['warningLabel'] . "</div>";
                            }

                            echo "<div class=''>&nbsp;</div>";
                            echo $pSpec['string'];

                            echo "</div>";
                            if ($elCtr % 2 == 0) {
                                echo "</div>";
                                echo "</div>";
                            }
                            //endregion
                        }
                    }
                }

                echo "</div class='row'>";

                if (isset($showScheme) && sizeof($showScheme) > 0) {

                    echo "<div class='clearfix'><hr></div>";
                    echo "<div class='col-md-12 no-padding'>";
                    echo "<div class='text-center text-danger text-bold'>-- SKEMA PINJAMAN ANDA --</div>";
                    echo "<div class='text-center text-danger text-bold meta'>generator skema hanya berlaku untuk single kreditur</div>";
                    echo "<div class='text-center text-danger text-bold'> ========================================== </div>";

                    //header skema
                    echo "<div class='col-md-12 no-padding'>";

                    echo "<span class='col-md-2 text-left text-bold no-padding'>Nama Pemegang Saham </span>
                <span class='text-left col-md-9 no-padding text-capitalize'>: " . $headerScheme['nama'] . "</span>";

                    //                $headerScheme = array(
                    //                    "nama" => "$nmPemengangSaham",
                    //                    "jml_pinjaman" => "$nilai_pinjaman",
                    //                    "bunga_tahunan" => "$rate_bunga",
                    //                    "awal_meminjam" => "$awal_pinjaman",
                    //                    "pelunasan_pinjaman" => "$jatuh_tempo",
                    //                    "lama_pinjaman" => "$total_hari hari ($total_bulan bln)",
                    //                );

                    echo "<span class='col-md-2 text-left text-bold no-padding'>Jumlah Pinjaman </span>      <span class='text-left col-md-9 no-padding'>: " . number_format($headerScheme['jml_pinjaman']) . "</span>";
                    echo "<span class='col-md-2 text-left text-bold no-padding'>Bunga Tahunan </span>        <span class='text-left col-md-9 no-padding'>: " . $headerScheme['bunga_tahunan'] . "%</span>";
                    echo "<span class='col-md-2 text-left text-bold no-padding'>Awal Meminjam </span>        <span class='text-left col-md-9 no-padding'>: " . $headerScheme['awal_meminjam'] . "</span>";
                    echo "<span class='col-md-2 text-left text-bold no-padding'>Pelunasan Pinjaman </span>   <span class='text-left col-md-9 no-padding'>: " . $headerScheme['pelunasan_pinjaman'] . "</span>";
                    echo "<span class='col-md-2 text-left text-bold no-padding'>Lama Pinjaman </span>        <span class='text-left col-md-9 no-padding'>: " . $headerScheme['lama_pinjaman'] . "</span>";

                    echo "</div>";
                    echo "<div class='clearfix'>&nbsp;</div>";
                    echo "<div><table id='main_table' class='table datatable table-bordered table-hover table-striped'><thead>";
                    echo "<tr>  <th width='1%'>No</th>
                            <th>Periode</th>
                            <th>jml hari / periode</th>
                            <th>Pokok Pinjaman</th>
                            <th>Rate Bunga</th>
                            <th>Nilai Bunga</th>
                            <th>PPh23</th>
                            <th>bunga setelah dipotong PPh</th>
                      </tr>";

                    echo "</thead><tbody>";

                    $total_bunga = 0;
                    $total_pph23 = 0;
                    $total_bunga_pph23 = 0;
                    $total_hari = 0;
                    $no = 1;

                    foreach ($showScheme as $thnbln => $pinjaman) {

                        $setBackground = isset($pinjaman['silangan']) ? $pinjaman['silangan'] : "merah";
                        $bgColor = " ";

                        switch ($setBackground) {
                            default:
                            case "merah":
                                $bgColor = "bg-white";
                                break;
                            case "hijau":
                                $bgColor = "bg-success";
                                break;
                            case "berjalan":
                                $bgColor = "bg-warning";
                                break;
                        }

                        echo "  <tr>
                                <td class='$bgColor'>$no</td>
                                <td class='$bgColor'>" . date('F Y', strtotime($pinjaman['thnbln'] . '-01')) . "</td>
                                <td class='$bgColor'>" . $pinjaman['jml_hari_dbln'] . "</td>
                                <td class='$bgColor'>" . number_format($pinjaman['nilai_pinjaman'], 0) . "</td>
                                <td class='$bgColor'>" . $pinjaman['rate_bunga'] . "%</td>
                                <td class='$bgColor'>" . number_format($pinjaman['nilai_bunga'], 0) . "</td>
                                <td class='$bgColor'>" . number_format($pinjaman['nilai_pph23'], 0) . "</td>
                                <td class='$bgColor'>" . number_format($pinjaman['nett_bunga'], 0) . "</td>
                            </tr>";

                        $no++;

                        $total_bunga += $pinjaman['nilai_bunga'] * 1;
                        $total_pph23 += $pinjaman['nilai_pph23'] * 1;
                        $total_bunga_pph23 += $pinjaman['nett_bunga'] * 1;
                        $total_hari += $pinjaman['jml_hari_dbln'] * 1;
                    }

                    echo "<tfoot>
                        <tr>
                            <td>-</td>
                            <td>-</td>
                            <td>" . $total_hari . "</td>
                            <td>-</td>
                            <td>-</td>
                            <td>" . number_format($total_bunga, 0) . "</td>
                            <td>" . number_format($total_pph23, 0) . "</td>
                            <td>" . number_format($total_bunga_pph23, 0) . "</td>
                        </tr>
                    </tfoot>";

                    echo "</tbody>
                        </table>
                        </div>";
                    echo "<div class='clearfix'>&nbsp;</div>";
                    echo "<div class='text-left'>Keterangan:</div>";
                    echo "<div class='text-left'> - periode dengan background hijau akan otomatis dibuatkan <span class='text-capitalize text-bold'>request loan interest</span> sesaat setelah request pinjaman diapprove </div>";
                    echo "</div>";
                }

            }

            // items element
            if ( sizeof($itemElements) > 0 && !$onPreOrderOnly ) {
                echo "<div class='panel-body table-responsive'>";
                echo "<div class='row'>";
                echo "<div class='col-md-12'>";
                echo "<h4 class='text-blue text-left'>Please fill in details below (itemsElement)</h4>";
                echo "</div class='col-md-12'>";
                echo "</div class='row'>";
                echo "<div class='col-lg-12 no-padding text-center' style='text-align:center;'>";
                $elCtr = 0;
                foreach ($itemElements as $eName => $pSpec) {
                    $elCtr++;
                    if (isset($pSpec['type']) && ($pSpec['type'] == "hidden")) {
                        // type hidden tidak perlu tampil di ui //
                    }
                    else {

                        if ($isMobile) {

                        }
                        else {

                            //region penampil untuk elemen pada shopingcart
                            if ($elCtr % 2 == 0) {
                            }
                            else {
                                echo "<div class='col-lg-12 no-padding'>";
                                echo "<div class='row row-eq-height'>";
                            }
                            echo "<div class='col-md-6 col-lg-6' style='border:2px #e1ece6 solid;margin:0px;background:" . $pSpec['bgColor'] . "'>";
                            echo "<div id='elTitle_$eName' class='text-left text-muted text-bold text-capitalize'>";
                            echo $pSpec['label'] . " ";
                            if (isset($itemElementConfigs[0]['autoSelect']) && $itemElementConfigs[0]['autoSelect']) {
                            }
                            else {
                                $helpName = $pSpec['helpName'];
                                echo "<a href='javascript:void(0)' onclick=\"hiliteDiv(this);document.getElementById('result').src='" . $itemElementResetTarget . "$eName/$helpName';\"><span class='fa fa-eraser'></span></a>";
                            }
                            echo "<span class='pull-right'><sup>" . $pSpec['editStr'] . "&nbsp;" . $pSpec['addStr'] . "</sup></span>";
                            echo "</div class='box-title'>";

                            if (isset($itemElementConfigs[0]['warningLabel']) && $itemElementConfigs[0]['warningLabel']) {
                                echo "<div class='col-md-12'>" . $itemElementConfigs[0]['warningLabel'] . "</div>";
                            }

                            echo "<div class=''>&nbsp;</div>";
                            $strSpec = $pSpec['string'];
                            /*-----------------------------
                             * penampil element kirimna dari controler
                             * -----------------------*/
                            echo $pSpec['string'];
                            echo "</div>";


                            if ($elCtr % 2 == 0) {
                                echo "</div>";
                                echo "</div>";
                            }
                            //endregion
                        }
                    }
                }
                echo "</div class='row'>";
            }
            if (sizeof($inputs) > 0) {
                echo "<div class='col-lg-12 no-padding' style='margin-top:5px;'>";
                echo "<div class='alert alert-info-dot'>";
                echo "<h4 class='text-left'>additional values</h4>";
                echo "<table class='table table-condensed'>";
                echo "<tr>";
                foreach ($inputs as $eName => $eStr) {
                    echo "<td class='text-muted'>";
                    echo $inputLabels[$eName];
                    echo "</td>";
                }
                echo "</tr>";
                echo "<tr>";
                foreach ($inputs as $eName => $eStr) {
                    echo "<td>";
                    echo $eStr;
                    echo "</td>";
                }
                echo "</div>";
                echo "</div>";
                echo "</tr>";
                echo "</table class='table table-condensed'>";
                echo "</div class='panel-default'>";
                echo "</div class='panel'>";
            }
            if (isset($previewJurnal) && sizeof($previewJurnal) > 0) {
                $headersJurnal = $previewJurnal['header'];
                foreach ($previewJurnal['jurnal'] as $cabangID => $subItems) {
                    if (sizeof($subItems) > 0) {
                        $cabangNama = isset($previewJurnal['cabang'][$cabangID]) ? $previewJurnal['cabang'][$cabangID] : "";

                        echo "<h4 class='text-blue' style='text-align: left;margin-top: 10px;'><span class='fa fa-book'></span> preview journal entries ($cabangNama)</h4>";

                        echo "<div class='tabel table-responsive'>";
                        echo "<table class='table table-condensed'>";

                        echo "<tr bgcolor='#f0f0f0'>";
                        foreach ($headersJurnal as $key => $label) {
                            echo "<td>";
                            echo "$label";
                            echo "</td>";
                        }
                        echo "</tr>";

                        foreach ($subItems as $iSpec) {
                            echo "<tr>";
                            foreach ($headersJurnal as $key => $label) {
                                echo "<td style='text-align: left;'>";
                                echo formatField_he_format($key, $iSpec[$key]);
                                echo "</td>";
                                if (is_numeric($iSpec[$key])) {
                                    if (!isset($total[$cabangID][$key])) {
                                        $total[$cabangID][$key] = 0;
                                    }
                                    $total[$cabangID][$key] += $iSpec[$key];
                                }
                            }
                            echo "</tr>";
                        }

                        echo "<tr style='font-size: 15px;font-weight: bold;'>";
                        foreach ($headersJurnal as $key => $label) {
                            echo "<td>";
                            if (isset($total[$cabangID][$key])) {
                                echo formatField_he_format($key, $total[$cabangID][$key]);
                            }
                            echo "</td>";
                        }
                        echo "</tr>";

                        echo "</table>";
                        echo "</div>";

                    }
                    else {
                        echo "<div class='text-center text-warning'>";
                        echo "- no journal affected by this transaction -<br><br>";
                        echo "</div class='text-center text-warning'>";
                    }
                }
            }

//            if ($selectAll) {
//                echo "<button href='' type='submit'>GENERATE</button>";
//                echo "</form>";
//            }

            if ($selectAll) {
//                echo "\n<script>
//                 console.log('JS nya jalan gak di sini....');
//
//                 $('#select_all').on('change', function(){
//                     if( $(this).is(':checked') ){
//                        $('.checkbox_prd').prop('checked', true)
//                     }
//                     else{
//                        $('.checkbox_prd').prop('checked', false)
//                     }
//                 });
//
//                 $('.checkbox_prd').on('change', function(){
//                        var arrCheckBoxed = $('.checkbox_prd');
//                        jQuery.each(arrCheckBoxed, function(a,b){
//                            if( $(b).is(':checked') ){
//                                console.log( $(this).attr('id') );
//                            }
//                        })
//                 })
//
//                 </script>";
            }

            else{

//                echo "<script>
////                        setTimeout( function(){
////                            top.checkerAddDiskonValidation()
////                            top.shoppingCartChangeTrigger()
////                        },1000)
//                    </script>";
            }

        }
        else {

            echo "<div class='no-padding no-border'>";
            echo "<style>table.dataTable.compact tbody th, table.dataTable.compact tbody td { padding: 0px 0px; }</style>";
            echo "<style>table.dataTable.compact tbody td > input, table.dataTable.compact tbody td > span, table.dataTable.compact tbody td > select { border: 0px !important; }</style>";
            echo "<table class='table table-condensed no-padding table-bordered no-margin dataTable compact'>";
            echo "<thead>";

            if (!$avoidRemove) {
                echo "<tr class='bg-grey-2'>";
                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";
                echo "<span class='pull-left'>";
                echo "<r><b>ANDA BELUM MEMILIH PRODUK, SILAHKAN MEMILIH PRODUK DARI FORM SKU & NAMA ITEM DIBAWAH</b></r>";
                echo "</span>";
                echo "</td>";
                echo "</tr>";
            }
            if (isset($itemLabels)) {
                if (sizeof($itemLabels) && (is_array($itemLabels)) && $showItems) {
                    echo "<tr class='bg-grey-2 text-uppercase'>";
                    echo "<th style='width:5px;' class='text-muted text-center'>";
                    echo "NO";
                    echo "</th>";
                    foreach ($itemLabels as $key => $label) {
                        if($key=="jml" || $key=="qty" || $key=="qty_unit"){
                            echo "<th style='max-width:5px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="barcode"){
                            echo "<th style='min-width:70px;max-width:80px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="nama"){
                            echo "<th style='min-width:150px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        elseif($key=="satuan_factor_nama"){
                            echo "<th style='min-width:12px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                        else{
                            echo "<th style='min-width:50px;white-space: nowrap;' class='$key text-muted text-center'>";
                            echo $label;
                            echo "</th>";
                        }
                    }
                    echo "</tr>";
                }
            }

            echo "</thead>";
            echo "<tbody>";

            echo "<tr class='bg-grey-2 text-uppercase'>";
            echo "<th style='width:5px;' class='text-muted text-center'>";
            echo "1";
            echo "</th>";
            foreach ($itemLabels as $key => $label) {
                if($key=="jml" || $key=="qty" || $key=="qty_unit"){
                    echo "<th style='max-width:5px;white-space: nowrap;' class='$key text-muted text-center'>";
                    echo "0";
                    echo "</th>";
                }
                elseif($key=="barcode"){
                    echo "<th style='min-width:70px;max-width:80px;white-space: nowrap;' class='$key text-muted text-center'>";
                    echo "123456789";
                    echo "</th>";
                }
                elseif($key=="nama"){
                    echo "<th style='min-width:150px;white-space: nowrap;' class='$key text-muted text-center'>";
                    echo "<span class='text-link' onclick=\"$('#itemKeyword').focus();$('#itemKeyword').click()\">SILAHKAN PILIH PRODUK</span>";
                    echo "</th>";
                }
                elseif($key=="satuan_factor_nama"){
                    echo "<th style='min-width:12px;white-space: nowrap;' class='$key text-muted text-center'>";
                    echo "n/a";
                    echo "</th>";
                }
                else{
                    echo "<th style='min-width:50px;white-space: nowrap;' class='$key text-muted text-center'>";
                    echo "0";
                    echo "</th>";
                }
            }
            echo "</tr>";
            echo "</tbody>";

            if (isset($sumRows) && sizeof($sumRows) > 0) {
                $nr = 0;
                foreach ($sumRows as $key => $label) {
                    $val = 0;
                    $nr++;
                    $bottom_borderless = $nr < sizeof($sumRows) ? "bottom-borderless" : "";
                    if (isset($main[$key]) && $main[$key] > 0) {
                        $val = $main[$key];
                    }
                    else {
                        if (isset($addValues[$key]) && $addValues[$key] > 0) {
                            $val = $addValues[$key];
                        }
                    }
                    if ($showItems) {
                        echo "<tr class=''>";
                        echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right $bottom_borderless valign-m text-uppercase text-bold text-muted'>$label &nbsp; &nbsp; &nbsp;</td>";
                        echo "<td colspan='3' class='right-borderless'>";
                        echo "<input type='text' id='$key' class='form-control text-right text-bold' readonly value='" . number_format($val) . "' >";
                        echo "</td>";
                        echo "</tr>";
                    }
                }
            }
            if (isset($sumRows2) && sizeof($sumRows2) > 0) {
                echo "<tr bgcolor='#e0e0e0'>";
                echo "<td colspan='" . (sizeof($itemLabels2) + 1) . "' class='text-left text-muted'><span class='fa fa-cog'></span> additional fees</td>";
                echo "</td>";
                echo "</tr>";
                $nr = 0;
                foreach ($sumRows2 as $key => $label) {
                    $nr++;
                    $bottom_borderless = $nr < sizeof($sumRows2) ? "bottom-borderless" : "";

                    echo "<tr bgcolor='#f0f0f5'>";
                    echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right bottom-borderless valign-m text-uppercase'>$label</td>";
                    echo "<td>";
                    echo $sumSpec2[$key];
                    echo "</td>";
                    echo "</tr>";
                }
            }
            if (sizeof($addRows) > 0) {
                $nr = 0;
                foreach ($addRowLabels as $k => $label) {
                    $nr++;
                    $bottom_borderless = $nr < sizeof($addRowLabels) ? "bottom-borderless" : "";
                    $rowHide = isset($addRowHiddens[$k]) ? $addRowHiddens[$k] : "";
                    echo "<tr addRows class='$rowHide'>";
                    echo "<td colspan='" . sizeof($itemLabels) . "' class='text-right $bottom_borderless valign-m text-uppercase text-bold text-muted'>$label &nbsp; &nbsp; &nbsp;</td>";
                    echo "<td colspan='2' class='text-right'>";
                    echo $addRows[$k];
                    echo "</td>";
                    echo "</tr>";
                }
            }

            $info_customer = 1;
            if ($info_customer) {
                echo "<tr class='bg-grey'>";
                // echo "<td>&nbsp;</td>";
                echo "<td colspan='" . (sizeof($itemLabels) + 2) . "'>";
                // echo "<div class='text-left bg-grey' style='height: 80px;'>info tentang <b class='text-uppercase'>$customer_nama</b><div>$str_customer</div></div>";
                echo "<div class='text-left bg-grey' style='hheight: 80px;'><div>$str_customer</div></div>";
                echo "</td>";
                echo "</tr>";
            }

            echo "</table class='table'>";
            echo "</div class='table-responsive'>";

            //================
//            echo "<div class='panel-body'>";
//            echo "<div class='text-danger'>";
//            echo "- <strong>you have not chosen any item yet</strong> -<br>";
//            echo "<small>you can do so by selecting items from available selectors</small><br>";
//            echo "</div class='text-warning'>";
//            echo "</div class='panel-body'>";
        }
        $sessionCleares = array("errLines", "errFields", "errMsg");
        foreach ($sessionCleares as $s) {
            if (isset($_SESSION[$s])) {
                unset($_SESSION[$s]);
            }
        }
        if(isset($cellID)){
            echo "\n<script>
                var rows_tr_$cellID = $('tr#tr_$cellID').addClass('bg-yellow');
                setTimeout(function() {
                   $(rows_tr_$cellID).removeClass('bg-yellow');
                }, 2000);
            </script>\n";
        }

        echo "<script>

            $(\"#addNewSKU\").on('keydown', delay_v2(function(e){
                if(e.which==13){
                    e.preventDefault();
                    detailproduk();
                }
            },100));

            function cariProduk(){
                var url = $('#selector_caller').val();
                var produk = $('#addNewSKU').val();
                var qty_produk = $('#addNewQty').val();
                top.HoldOn.open()
                $.ajax({
                    type: 'get',
                    url: url,
                    success: function(response) {
                        top.$('.viewmodal').html(response).show();
                        top.$('#testingmodal').modal('show');
                        top.$('#tablePencarianProduk').dataTable()
                        top.$('#tablePencarianProduk_filter input').val(produk).focus().trigger('keyup')
                        console.log('masuk dari pencarian produk');
                        top.HoldOn.close()
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        console.error(xhr.status + ' ' + xhr.responseText + ' ' + thrownError);
                    }
                });
            }

            function detailproduk(){
                var url = $('#selector_caller').val();
                var barcode_action_url = $('#barcode_action_url').val();
                var produk = $('#addNewSKU').val();
                var qty_produk = $('#addNewQty').val();

                if(produk!='' && produk!=null){
//                    top.HoldOn.open()
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: {
                            search: produk,
                            qty_produk: qty_produk,
                        },
                        success: function(response) {
                            top.$('.viewmodal').html(response).show();
                            top.$('#testingmodal').modal('show');
                            top.$('#tablePencarianProduk').dataTable()
                            top.$('#tablePencarianProduk_filter input').val(produk).focus().trigger('keyup')
                            console.log('masuk dari banyak produk');
//                            top.HoldOn.close()
                        },
                        error: function(xhr, ajaxOptions, thrownError) {
//                            console.error(xhr.status + ' ' + xhr.responseText + ' ' + thrownError);
                        }
                    });

                }
                else{
                    cariProduk()
                }
            }

            $('#addNewSKU').focus();

            $(this).keydown(function (e) {
                if (e.keyCode == 27) { //escape
                    e.preventDefault();
                    $('#addNewSKU').focus().trigger('click');
                }
            });
            $(this).keydown(function (e) {
                if (e.shiftKey && e.keyCode == 27) { //SHIFT + ESC
                    e.preventDefault();
                    $('#addNewProduk').focus().trigger('click');
                }
            });
            $(this).keydown(function (e) {
                if (e.shiftKey && e.keyCode == 107) { //SHIFT + PLUS
                    e.preventDefault();
                    $('#addNewQty').focus().trigger('click');
                }
            });

            $('#addNewQty').keydown(function(e){
                if( e.key*1 >= 0 && e.key != ' ' ){

                }
                else{
                    e.preventDefault();
                    console.log('hanya boleh angka');
                    console.log('this.value: ' + this.value);
                    $(this).val( this.value * 1 )
                }
            })

        </script>";

        //buat ngecek otorisasi penurunan qty produk
//        arrPrint($_SESSION[$cCode]['items']);
//        if( !empty($_SESSION[$cCode]['items']) ){
//            $tmp_oto_qty_unit = array();
//            foreach($_SESSION[$cCode]['items'] as $p_id => $k_val){
//
//                if(isset($k_val['oto_qty_unit']) && $k_val['oto_qty_unit']==1 &&
//                    $k_val['qty_unit_before']==$k_val['qty_unit'] &&
//                    $k_val['qty_unit_target'] < $k_val['qty_unit']){
//
//                    cekMerah('masih perlu otorisasi perubahan qty_unit dari ' . $k_val['qty_unit'] . ' ke ' . $k_val['qty_unit_target']);
//
//                    $p_nama = $k_val['nama'];
//                    $tmp_oto_qty_unit[$p_id] = $p_nama;
//
////            "oto_qty_unit_set" => $oto_qty_unit_set,
////            "qty_unit_before_set" => $qty_unit_before_set,
////            "qty_unit_target_set" => $qty_unit_target_set,
////            "shoppingcart_order_id" => $shoppingcart_order_id,
//
//                    $oto_qty_unit_set = 1;
//                    $qty_unit_before_set = $k_val['qty_unit'];
//                    $qty_unit_target_set = $k_val['qty_unit_target'];
//                    $cCode_set = $cCode;
//                    $id_set = $p_id;
//                    $gate_set = "items";
//                    $shoppingcart_order_id = $_SESSION[$cCode]['main']['shoppingcart_order_id'];
//
////                    echo "<script>
////                        if(typeof intervalOtoQty != 'undefined'){ clearInterval(intervalOtoQty) }
////                        var intervalOtoQty = setInterval( function(){
////                            top.$.ajax({
////                                url: '". base_url() . $this->modul ."/_shoppingCart/checkOtoQty/".$this->jenisTr."',
////                                method: 'post',
////                                data: {
////                                    'oto_qty_unit_set': $oto_qty_unit_set,
////                                    'qty_unit_before_set': $qty_unit_before_set,
////                                    'qty_unit_target_set': $qty_unit_target_set,
////                                    'cCode_set': '$cCode_set',
////                                    'gate_set': '$gate_set',
////                                    'id_set': '$id_set',
////                                    'jenisTr': '".$this->jenisTr."',
////                                    'shoppingcart_order_id': $shoppingcart_order_id,
////                                },
////                                success: function(a){
////                                    jsonData = JSON.parse(a);
////                                    if(jsonData.status){
////                                        if( top.$('#refresh_shoppingcart').length ){
////                                            top.$('#refresh_shoppingcart').trigger('click');
////                                        }
////                                    }
////                                    else{
////                                        console.log('reason: ' + jsonData.reason);
////                                        window.location.reload()
////                                    }
////                                }
////                            })
////                        }, 5000);
////                    </script>
////                    ";
//                }
//                else{
//                    //ada perubahan qty naik, request di batalkan
//                    unset($_SESSION[$cCode]['items'][$p_id]['oto_qty_unit']);
//                    unset($_SESSION[$cCode]['items'][$p_id]['qty_unit_target']);
//                    unset($_SESSION[$cCode]['items'][$p_id]['qty_unit_before']);
////                    echo "<script>
////                            if(typeof intervalOtoQty != 'undefined'){ clearInterval(intervalOtoQty) }
////                            console.log('session oto qty unit di hapus');
////                            console.log('intervalOtoQty oto qty unit di hapus');
////                        </script>
////                    ";
//                }
//            }
//
//            $total_produk_oto = count($tmp_oto_qty_unit);
//
//            if($total_produk_oto){
////                echo "<script>
////                    setTimeout( function(){
////                        top.$('.container-custom-button').html(\"<a data-toggle='modal' data-target='#myModal' href='".base_url()."login/formQtyOtorisasi' class='btn btn-md btn-danger'> <i class='fa fa-warning text-yellow blink'></i>  Menunggu Approval perubahan QTY <span class='badge badge-yellow'>$total_produk_oto</span></a>\");
////                    }, 500);
////                    </script>
////                    ";
//            }
//            else{
////                echo "<script>
////                    setTimeout( function(){
////                        top.$('.container-custom-button').html('');
////                    }, 500);
////                    </script>
////                    ";
//            }
//
//        }

//        if($lockTransaksi){
//            echo "<script>
//                        top.swal({
//                            title: 'Transaksi Terkunci',
//                            html: 'transaksi Anda masih terkunci karena ada $lockTransaksi return/cancel yang belum di approve...<br><br>' +
//                            \"<r>tunggu hingga di approve, atau segeralah minta untuk di approve sebelum melanjutkan transaksi selanjutnya.</r>\" +
//                            \"<span id='trLocker' class='hidden'></span>\",
//                            type: 'warning',
//                            showConfirmButton: false,
//                            allowOutsideClick: false,
//                            onOpen: function(){
//                                console.log('swal tlah ter buka.... swal tlah terbuka.... horee... horeee... hatiiiii.... ku gembiraaaa');
//                            }
//                        });
//                        swal.showLoading();
//                  </script>";
//        }
//        else{
//            echo "<script>
//                    if( top.$('#trLocker').length ){
//                        swal.close();
//                    }
//                  </script>";
//        }
        //=========================================
    }

}
