<?php

class Transaksional
{
    protected $toko_id;
    protected $cabang_id;
    protected $gudang_id;
    //-------
    protected $configUiModul;
    protected $configLayoutModul;
    protected $configCoreModul;
    protected $configValuesModul;
    protected $configCoreMaster;
    protected $jenisTr;
    protected $jenisTrReference;
    protected $jenisTrMaster;
    protected $modul;
    protected $cCode;
    protected $cCodeData;
    protected $stepNum;
    protected $stepNumCurrent;
    protected $masterTargetStepNum;
    protected $childTargetStepNum;
    protected $transaksiNumber;
    protected $accessList;
    protected $sessionLogin;

    //region setter dan getter
    public function getJenisTrReference()
    {
        return $this->jenisTrReference;
    }

    public function setJenisTrReference($jenisTrReference)
    {
        $this->jenisTrReference = $jenisTrReference;
    }

    public function getJenisTrMaster()
    {
        return $this->jenisTrMaster;
    }

    public function setJenisTrMaster($jenisTrMaster)
    {
        $this->jenisTrMaster = $jenisTrMaster;
    }

    public function getCabangId()
    {
        return $this->cabang_id;
    }

    public function setCabangId($cabang_id)
    {
        $this->cabang_id = $cabang_id;
    }

    public function getGudangId()
    {
        return $this->gudang_id;
    }

    public function setGudangId($gudang_id)
    {
        $this->gudang_id = $gudang_id;
    }

    public function getSessionLogin()
    {
        return $this->sessionLogin;
    }

    public function setSessionLogin($sessionLogin)
    {
        $this->sessionLogin = $sessionLogin;
    }

    public function getAccessList()
    {
        return $this->accessList;
    }

    public function setAccessList($accessList)
    {
        $this->accessList = $accessList;
    }

    public function getMasterTargetStepNum()
    {
        return $this->masterTargetStepNum;
    }

    public function setMasterTargetStepNum($masterTargetStepNum)
    {
        $this->masterTargetStepNum = $masterTargetStepNum;
    }

    public function getChildTargetStepNum()
    {
        return $this->childTargetStepNum;
    }

    public function setChildTargetStepNum($childTargetStepNum)
    {
        $this->childTargetStepNum = $childTargetStepNum;
    }

    public function getStepNum()
    {
        return $this->stepNum;
    }

    public function setStepNum($stepNum)
    {
        $this->stepNum = $stepNum;
    }

    public function getStepNumCurrent()
    {
        return $this->stepNumCurrent;
    }

    public function setStepNumCurrent($stepNumCurrent)
    {
        $this->stepNumCurrent = $stepNumCurrent;
    }

    public function getTransaksiNumber()
    {
        return $this->transaksiNumber;
    }

    public function setTransaksiNumber($transaksiNumber)
    {
        $this->transaksiNumber = $transaksiNumber;
    }

    public function getConfigUiModul()
    {
        return $this->configUiModul;
    }

    public function setConfigUiModul($configUiModul)
    {
        $this->configUiModul = $configUiModul;
    }

    public function getConfigLayoutModul()
    {
        return $this->configLayoutModul;
    }

    public function setConfigLayoutModul($configLayoutModul)
    {
        $this->configLayoutModul = $configLayoutModul;
    }

    public function getConfigCoreModul()
    {
        return $this->configCoreModul;
    }

    public function setConfigCoreModul($configCoreModul)
    {
        $this->configCoreModul = $configCoreModul;
    }

    public function getConfigValuesModul()
    {
        return $this->configValuesModul;
    }

    public function setConfigValuesModul($configValuesModul)
    {
        $this->configValuesModul = $configValuesModul;
    }

    public function getConfigCoreMaster()
    {
        return $this->configCoreMaster;
    }

    public function setConfigCoreMaster($configCoreMaster)
    {
        $this->configCoreMaster = $configCoreMaster;
    }

    public function getJenisTr()
    {
        return $this->jenisTr;
    }

    public function setJenisTr($jenisTr)
    {
        $this->jenisTr = $jenisTr;
    }

    public function getModul()
    {
        return $this->modul;
    }

    public function setModul($modul)
    {
        $this->modul = $modul;
    }

    public function getCCode()
    {
        return $this->cCode;
    }

    public function setCCode($cCode)
    {
        $this->cCode = $cCode;
    }

    public function getCCodeData()
    {
        return $this->cCodeData;
    }

    public function setCCodeData($cCodeData)
    {
        $this->cCodeData = $cCodeData;
    }

    public function getTokoId()
    {
        return $this->toko_id;
    }

    public function setTokoId($toko_id)
    {
        $this->toko_id = $toko_id;
    }

    //endregion

    public function __construct()
    {
        // parent::__construct();
        $this->CI =& get_instance();


    }


    public function gerbang_transaksi($toko_id, $transaksi_jenis, $array_data)
    {
        $CI =& get_instance();
        $CI->load->library("FieldCalculator");
        $cal = new FieldCalculator();

        $array_datas = blobDecode($array_data);

        cekBiru("$toko_id ***** $transaksi_jenis");
        arrPrintPink($array_datas);
        // $items = $array_datas["items"];

        $arrItems = isset($array_datas["items"]) ? $array_datas["items"] : array();
        // id_produk => qty

        $arrTrID = isset($array_datas['trs']) ? $array_datas['trs'] : array();

        $arrMain = isset($array_datas["main"]) ? $array_datas["main"] : array();

        $cCode = "_TR_" . $transaksi_jenis;
        // $toko_id = my_toko_id();

        // matiHere(__LINE__);

        $selectorModel = $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['selectorModel'];
        $selectorSrcModel = $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['selectorSrcModel'];

        $CI->load->model("Mdls/" . $selectorSrcModel);
        $b = new $selectorSrcModel();


        $itemNumLabels = isset($CI->config->item('heTransaksi_ui')[$transaksi_jenis]['shoppingCartNumFields'][1]) ? $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['shoppingCartNumFields'][1] : array();
        $priceConfig = isset($CI->config->item('heTransaksi_ui')[$transaksi_jenis]['selectedPrice']) ? $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['selectedPrice'] : array();
        $lockerConfig = isset($CI->config->item('heTransaksi_ui')[$transaksi_jenis]['lockerCheck']) ? $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['lockerCheck'] : array();
        $subAmountConfig = isset($CI->config->item('heTransaksi_ui')[$transaksi_jenis]['shoppingCartAmountValue'][1]) ? $CI->config->item('heTransaksi_ui')[$transaksi_jenis]['shoppingCartAmountValue'][1] : null;

        if (sizeof($arrItems) > 0) {
            arrPrintWebs($arrItems);
            foreach ($arrItems as $id => $jmlParam) {

                $tmpB = $b->lookupByID($id)->result();
                cekHere($CI->db->last_query());
                arrPrint($tmpB);

                $jml = $jmlParam;
                if (sizeof($tmpB) > 0) {
                    foreach ($tmpB as $row) {
                        $satuan = strlen($row->satuan) > 0 ? $row->satuan : "n/a";
                        $tmpJml = $jmlParam;
                        if (isset($lockerConfig['enabled']) && $lockerConfig['enabled'] == true) {
                            cekMerah("masuk locker config");

                            $mdlName = $lockerConfig['mdlName'];
                            $this->load->model("Mdls/" . $mdlName);
                            $c = new $mdlName();
                            $c->addFilter("produk_id='$id'");
                            $c->addFilter("state='active'");
                            $c->addFilter("cabang_id=" . $this->session->login['cabang_id']);
                            $c->addFilter("gudang_id=" . $this->session->login['gudang_id']);
                            $tmpC = $c->lookupAll($id)->result();
                            cekHere($this->db->last_query() . " " . __LINE__);


                            if (sizeof($tmpC) > 0) {
                                arrPrint($tmpC);
                                foreach ($tmpC as $row) {
                                    $satuan = strlen($row->satuan) > 0 ? $row->satuan : "n/a";
                                    $nama = $row->nama;

                                    $jml_now = $row->jumlah;
                                    if (!array_key_exists($id, $_SESSION[$cCode]["items"])) {
                                        $jml_sudah_diambil = 0;
                                        $jml_diperlukan = 1;
                                        $jml_nambah = 1;
                                    }
                                    else {
                                        if (isset($_GET['newQty'])) {
                                            $jml_sudah_diambil = $_SESSION[$cCode]["items"][$id]['jml'];
                                            $jml_diperlukan = $_GET['newQty'];
                                            $jml_nambah = $jml_diperlukan - $jml_sudah_diambil;
                                        }
                                        else {
                                            $jml_sudah_diambil = $_SESSION[$cCode]["items"][$id]['jml'];
                                            $jml_diperlukan = $jml_sudah_diambil + $jml;
                                            $jml_nambah = $jml;
                                        }
                                    }
                                    //  region validasi stok
                                    if ($jml_nambah > $jml_now) {
                                        echo "<script>top.alert('stok $nama tidak cukup. (perlu $jml_diperlukan, nambah $jml_nambah stok $jml_now)')";
                                        echo "</script>";
                                        die();
                                    }
                                    //  endregion validasi stok


                                    $this->db->trans_start();

                                    //  region update locker active
                                    $where = array(
                                        "id" => $row->id,
                                    );
                                    $data_active = array(
                                        "jumlah" => $jml_now - $jml_nambah,
                                        "state" => "active",
                                    );
                                    $c->updateData($where, $data_active);
                                    cekHere($this->db->last_query());
                                    //  endregion update locker active


                                    //  region locker hold
                                    $array_hold_sebelumnya = $c->cekLoker($this->session->login['cabang_id'], $id, "hold", $this->session->login["id"], "0", $this->session->login['gudang_id']);
                                    if (sizeof($array_hold_sebelumnya) > 0) {
                                        $where = array(
                                            "id" => $array_hold_sebelumnya["id"],
                                        );
                                        $data_hold = array(
                                            "jumlah" => $array_hold_sebelumnya['jumlah'] + $jml_nambah,
                                        );
                                        $c->updateData($where, $data_hold);
                                        cekHere($this->db->last_query());
                                    }
                                    else {
                                        $data_hold = array(
                                            "jenis" => "produk",
                                            "cabang_id" => $this->session->login['cabang_id'],
                                            "produk_id" => $id,
                                            "nama" => $nama,
                                            "satuan" => $row->satuan,
                                            "state" => "hold",
                                            "jumlah" => $jml_nambah,
                                            "oleh_id" => $this->session->login["id"],
                                            "oleh_nama" => $this->session->login['nama'],
                                            "gudang_id" => $this->session->login['gudang_id'],
                                        );
                                        $c->addData($data_hold);
                                        cekHere($this->db->last_query());
                                    }
                                    //  endregion locker hold


                                    $this->db->trans_complete() or die("Gagal bro");

                                    $tmpJml = $jml_diperlukan;

                                }
                            }
                            else {
                                mati_disini("tidak ditemukan item " . $row->nama . " di locker stock.");
                            }

                        }

                        /* ----------------------------------------------------------------------------------------------
                         * memasukan session items
                         * ----------------------------------------------------------------------------------------------*/
                        $fieldSrcs = isset($CI->config->item("heTransaksi_ui")[$CI->jenisTr]['shoppingCartFieldSrc']) ? $CI->config->item("heTransaksi_ui")[$transaksi_jenis]['shoppingCartFieldSrc'] : array("nama" => "nama");
                        if (!array_key_exists($id, $_SESSION[$cCode]["items"])) {
                            $tmp = array(
                                "handler" => $CI->uri->segment(1) . "/" . $CI->uri->segment(2),
                                "id" => $id,
                                "jml" => $tmpJml,
                                "harga" => 0,
                                "subtotal" => 0,
                            );

                            if (sizeof($priceConfig) > 0) {
                                $mdlName = $priceConfig['model'];
                                $CI->load->model("Mdls/" . $mdlName);
                                $h = new $mdlName();
                                $h->addFilter("produk_id='$id'");
                                $h->addFilter("status='1'");
                                //                                $h->addFilter("jenis_value='" . $priceConfig["label"] . "'");
                                $h->addFilter("jenis_value in ('" . implode("','", $priceConfig["label"]) . "')");
                                $h->addFilter("toko_id=" . $toko_id);
                                $tmpH = $h->lookupAll($id)->result();
                                cekMerah($CI->db->last_query());

                                if (sizeof($tmpH) > 0) {
                                    $rawPrices = array();
                                    foreach ($tmpH as $hSpec) {
                                        foreach ($priceConfig['key_label'] as $key => $val) {
                                            if ($key == $hSpec->jenis_value) {
                                                $rawPrices[$key] = isset($hSpec->nilai) ? $hSpec->nilai : 0;
                                            }
                                        }
                                    }
                                    $prices = normalizePrices("produk", $rawPrices);
                                    if (sizeof($prices) > 0) {
                                        foreach ($prices as $k => $v) {
                                            $tmp[$k] = $v;
                                        }
                                        $tmp['harga'] = isset($tmp[$priceConfig['mainSrc']]) ? $tmp[$priceConfig['mainSrc']] : 0;
                                    }
                                }

                            }

                            foreach ($fieldSrcs as $key => $src) {
                                $tmpEx = $cal->multiExplode($src);
                                arrPrint($tmpEx);
                                if (sizeof($tmpEx) > 1) {//===berarti mengandung karakter simbol perhitungan
                                    cekBiru("$key perhitungan");
                                    $newSrc = $src;
                                    foreach ($tmpEx as $key2 => $val2) {
                                        echo "$key2 - $val2 <br>";
                                        if (!is_numeric($val2)) {
                                            if (isset($tmp[$val2]) && $tmp[$val2] > 0) {
                                                $newSrc = str_replace($val2, $tmp[$val2], $newSrc);
                                            }
                                            else {
                                                $newSrc = str_replace($val2, 0, $newSrc);
                                            }
                                        }

                                    }
                                    cekBiru("$$src -> $newSrc -> " . $cal->calculate($newSrc));
                                    $tmp[$key] = $cal->calculate($newSrc);
                                }
                                else {
                                    cekBiru("$key BUKAN perhitungan");
                                    $tmp[$key] = $row->$src;
                                }


                            }

                            //===perhitungan subtotal
                            $cal = new FieldCalculator();


                            if (sizeof($arrMain) > 0) {
                                foreach ($arrMain as $key => $val) {
                                    $_SESSION[$cCode][$key] = $val;
                                }
                            }

                            if ($subAmountConfig != null) {
                                $tmpEx = $cal->multiExplode($subAmountConfig);
                                if (sizeof($tmpEx) > 1) {
                                    $newSrc = $subAmountConfig;
                                    foreach ($tmpEx as $key2 => $val2) {
                                        if (isset($tmp[$val2])) {
                                            $newSrc = str_replace($val2, $tmp[$val2], $newSrc);
                                            cekKuning("$val2 direplace dengan " . $tmp[$val2]);
                                        }
                                        else {
                                            $newSrc = str_replace($val2, "0", $newSrc);
                                            cekKuning("$val2 direplace dengan NOL");
                                        }

                                    }
                                    $subtotal = $cal->calculate($newSrc);
                                    cekHijau("subtotal dari perhitungan $subAmountConfig $newSrc");

                                }
                                else {
                                    $subtotal = 0;
                                    cekHijau("subtotal dari perhitungan yang gak ada");
                                }
                            }
                            else {
                                $subtotal = 0;
                                cekHijau("subtotal NOL");
                            }
                            $tmp["subtotal"] = $subtotal;
                            $_SESSION[$cCode]["items"][$id] = $tmp;

                            //                    die();
                        }
                        else {
                            if (isset($_GET['newQty'])) {
                                $_SESSION[$cCode]["items"][$id]['jml'] = $_GET['newQty'];
                                $_SESSION[$cCode]["items"][$id]['subtotal'] = ($_SESSION[$cCode]["items"][$id]['jml'] * $_SESSION[$cCode]["items"][$id]['harga']);
                            }
                            else {
                                $_SESSION[$cCode]["items"][$id]['jml'] += $jml;
                                $_SESSION[$cCode]["items"][$id]['subtotal'] = ($_SESSION[$cCode]["items"][$id]['jml'] * $_SESSION[$cCode]["items"][$id]['harga']);
                            }

                            if (sizeof($itemNumLabels) > 0) {
                                echo("iterating subNums.. @" . __LINE__);
                                foreach ($itemNumLabels as $key => $label) {
                                    if (isset($_GET[$key]) && $_GET[$key] > 0) {
                                        $newValue = $_GET[$key];
                                        $tmp[$key] = $newValue;
                                        $_SESSION[$cCode]["items"][$id][$key] = $newValue;
                                        echo "replacing value for $key with " . $newValue . "<br>";
                                    }

                                }

                                foreach ($itemNumLabels as $key => $label) {
                                    $_SESSION[$cCode]["items"][$id]["sub_" . $key] = ($_SESSION[$cCode]["items"][$id][$key] * $_SESSION[$cCode]["items"][$id]["jml"]);
                                }
                                $_SESSION[$cCode]["items"][$id]['sub_nett'] = ($_SESSION[$cCode]["items"][$id]['nett'] * $_SESSION[$cCode]["items"][$id]['jml']);

                                $_SESSION[$cCode]["items"][$id]['subtotal'] = ($_SESSION[$cCode]["items"][$id]['jml'] * $_SESSION[$cCode]["items"][$id]['harga']);
                            }


                        }
                    }

                    if (sizeof($_SESSION[$cCode]["items"]) > 0) {
                        $_SESSION[$cCode]["main"]['harga'] = 0;
                        $_SESSION[$cCode]['out_master']['harga'] = 0;

                        /*
                         * akumulasi item ke main
                         * */
                        foreach ($_SESSION[$cCode]["items"] as $id => $iSpec) {
                            $_SESSION[$cCode]["main"]['harga'] += ($iSpec['jml'] * $iSpec['harga']);
                            $_SESSION[$cCode]['out_master']['harga'] += ($iSpec['jml'] * $iSpec['harga']);
                        }
                    }

                }
                else {
                    cekMerah("tidak ada itemnya!");
                    die();
                }

            }
        }

        if (sizeof($arrTrID) > 0) {
            $_SESSION[$cCode]["main"]['references'] = $arrTrID;
            $_SESSION[$cCode]['out_master']['references'] = $arrTrID;
        }
        if (isset($_GET['singleRefID']) && strlen($_GET['singleRefID']) > 0) {
            $_SESSION[$cCode]["main"]['singleReference'] = $_GET['singleRefID'];
            $_SESSION[$cCode]['out_master']['singleReference'] = $_GET['singleRefID'];
        }

    }

    public function wizard_startup()
    {
        /* ------------------------------------------------
        *  companu profile cek
        * ------------------------------------------------*/
        // return true;
        $this->CI->load->model("Mdls/MdlCompany");
        $cp = new MdlCompany();
        $cp->setTokoId(my_toko_id());

        $cpSrc = $cp->callDatas();
// cekhitam($this->CI->db->last_query());
        $neracaStatus = $cpSrc->neraca_ok;

        $cp_koloms = array(
            "bank_ok" => array(
                "label" => "bank",
                "link" => "Data/add/Bank/bank",
                "link_tipe" => "modal",
            ),
            "bank_account_ok" => array(
                "label" => "bank rekening",
                "link" => "Data/add/BankAccount_in/bank_account",
                "link_tipe" => "modal",
            ),
            "vendor_ok" => array(
                "label" => "vendor",
                "icon" => "fa-truck",
                "link" => "Data/add/Supplier/vendor",
                "link_tipe" => "modal",
            ),
            "produk_ok" => array(
                "label" => "produk",
                "link" => "Converter/index/formProduk"
            ),
            "customer_ok" => array(
                "label" => "konsumen",
                "icon" => "fa-user",
                "link" => "Converter/index/formCustomer",
            ),
            // "stok_ok"         => array(
            //     "label" => "persediaan",
            //     "link"  => "Converter/index/formSuppliesRek",
            // ),
            "neraca_ok" => array(
                "label" => "neraca",
                "icon" => "fa-balance-scale",
                // "link" => "Neraca/viewBalanceSheet",
                "link" => "TransaksiPindahBuku/index",
            ),
        );

        $link_now = "";
        $vas_ok = array();
        $strFree = "";
        $nom = 0;
        $next_on = 1;
        $neraca_link = $cp_koloms['neraca_ok']['link'];
        foreach ($cp_koloms as $cp_kolom => $cp_datum) {
            $nom++;
            $ok = $cpSrc->$cp_kolom;
            $badge_done = $ok == 1 ? "badge-green" : "";
            $var_ok[$cp_kolom] = $ok;

            if (isset($cp_datum['link_tipe']) && ($cp_datum['link_tipe'] == "modal")) {
                $link_data = isset($cp_datum['link']) ? base_url() . $neraca_link : "#";
            }
            else {

                $link_data = isset($cp_datum['link']) ? base_url() . $cp_datum['link'] : "#";
            }

            if ($nom == 1 && $ok == 1) {
                $next_ok = "text-red";
            }
            else {
                $next_ok = "text-red";
            }

            $next_ok = ($nom + $ok) == ($next_on + 1) ? "" : "text-red";
            // if(($nom + $ok) == ($next_on + 1)){
            if ($ok == 0 && (($nom + $ok) == ($next_on + 1))) {
                $text_color = "text-grey";
                $link_data_f = "#";
            }
            else {
                $text_color = "";
                $link_now = $link_data_f = $link_data;
            }

            $next_on = $nom + $ok;

            // $text_color = $ok == 0 ? "text-grey" : "";

            $cp_label = $cp_datum["label"];
            $cp_icon = isset($cp_datum['icon']) ? $cp_datum['icon'] : 'fa-database';
            $strFree .= "<a href='$link_data_f' title='go to $cp_label' data-toggle='tooltip' class='btn btn-app text-uppercase active $next_ok $text_color'><span class='badge $badge_done'>$nom</span><i class='fa $cp_icon'></i>$cp_label</a>";
        }

        $vars['html'] = $strFree;
        $vars['link_now'] = $link_now;
        $vars['step_status'] = $var_ok;

        return $vars;

    }

    //  undone items, transaksi yang belum selesai
    public function viewUndoneItems()
    {
        $jenisTr = ($this->jenisTr != NULL) ? $this->jenisTr : mati_disini("kode master transaksi belum diset, silahkan hubungi admin.");
        $steps = $this->CI->configUiModul[$jenisTr]["steps"];


        $tr = New MdlTransaksi();

        if (sizeof($steps) > 1) {
            $stepCodes = array();
            $jmlStep = count($steps);
            if (isset($this->accessList[$jenisTr]) && sizeof($this->accessList) > 0) {
                $arrFilters = array();
                $indsteps = "(";
                foreach ($this->accessList[$jenisTr] as $stepNumber => $stepSpec) {
                    if ($stepNumber <= $jmlStep) {
                        foreach ($stepSpec as $targetCode => $filters) {
                            $indsteps .= "'$targetCode',";
                            $stepCodes[] = $targetCode;
                            if ($filters['allowFollowUp'] == "true") {
                                $arrFilters["allowFollowUp"][] = $targetCode;
                            }
                        }
                    }
                }
                $indsteps = rtrim($indsteps, ",");
                $indsteps .= ")";
                if (sizeof($arrFilters) > 0) {
                    $tr->addFilter("next_step_code in $indsteps");
                }
                else {
                    $tr->addFilter("transaksi.oleh_id='" . my_id() . "'");
                }
            }
            else {
                foreach ($steps as $stepNumber => $stepSpec) {
                    if ($stepNumber < $jmlStep) {
                        $stepCodes[] = $stepSpec["target"];
                    }
                }
            }
        }

        $tr->addFilter("div_id=" . my_div_id());
        $tr->addFilter("jenis_top='" . $steps[1]["target"] . "'");
        $tr->addFilter("next_substep_code<>''");
        $tr->addFilter("sub_step_number>0");
        if (isset($this->accessList[$jenisTr]) && sizeof($this->accessList) > 0) {
        }
        else {
            if (sizeof($this->sessionLogin['membership']) > 0) {
                $this->db->group_start();
                $mCtr = 0;
                foreach ($this->sessionLogin['membership'] as $gID) {
                    if ($mCtr == 0) {
                        $this->db->where(array("next_subgroup_code" => $gID));
                    }
                    else {
                        $this->db->or_where(array("next_subgroup_code" => $gID));
                    }
                    $mCtr++;
                }
                $this->db->group_end();
            }
        }
        $tmpHist = $tr->lookupUndoneEntries_joined(replaceSession())->result();

        $undoneResult = array();
        if (sizeof($tmpHist) > 0) {
            $arrTransID = array();
            foreach ($tmpHist as $row) {
                $arrTransID[$row->transaksi_id] = $row->transaksi_id;
            }

            $tmpReg_result = array();
            $trReg = new MdlTransaksi();
            $trReg->setFilters(array());
            $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
            $tmpReg = $trReg->lookupDataRegistries()->result();
            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $regRow) {
                    foreach ($regRow as $k_reg => $v_reg) {
                        switch ($k_reg) {
                            case "main":
                                $tmpReg_result[$regRow->transaksi_id][$k_reg] = ($k_reg != NULL) ? blobDecode($v_reg) : array();
                                break;
                            case "items":
                                $tmpReg_result[$regRow->transaksi_id][$k_reg] = ($k_reg != NULL) ? blobDecode($v_reg) : array();
                                break;
                        }
                    }
                }
            }
            foreach ($tmpHist as $ii => $row) {
                if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->id]))) {
                    foreach ($tmpReg_result[$row->id] as $param => $eReg) {
                        switch ($param) {
                            case "main":
                                foreach ($eReg as $k => $v) {
                                    if (!isset($row->$k)) {
                                        $row->$k = $v;
                                    }
                                }
                                break;
                            case "items":
                                $row->$param = $eReg;
                                break;
                        }

                    }
                }

                $undoneResult[$ii] = $row;
            }
        }
        return $undoneResult;
    }

    public function viewUndoneItemsConnectedRequest()
    {
        $jenisTr = ($this->jenisTr != NULL) ? $this->jenisTr : mati_disini("kode master transaksi belum diset, silahkan hubungi admin.");
        $steps = $this->CI->configUiModul[$jenisTr]["steps"];


        $tr = New MdlTransaksi();
        $tr->addFilter("transaksi.toko_id=" . $this->toko_id);
        $tr->addFilter("transaksi.cabang_id=" . $this->cabang_id);
        $tr->addFilter("transaksi.jenis_master=" . $this->jenisTrMaster);
        $tr->addFilter("transaksi.jenis=" . $this->jenisTrReference);
        $tr->addFilter("transaksi.step_current=" . $this->stepNumCurrent);
        $tmpHist = $tr->lookupRecentHistories()->result();

        $undoneResult = array();
        if (sizeof($tmpHist) > 0) {
            $arrTransID = array();
            foreach ($tmpHist as $row) {
                $arrTransID[$row->transaksi_id] = $row->transaksi_id;
            }

            $tmpReg_result = array();
            $trReg = new MdlTransaksi();
            $trReg->setFilters(array());
            $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
            $tmpReg = $trReg->lookupDataRegistries()->result();
            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $regRow) {
                    foreach ($regRow as $k_reg => $v_reg) {
                        switch ($k_reg) {
                            case "main":
                                $tmpReg_result[$regRow->transaksi_id][$k_reg] = ($k_reg != NULL) ? blobDecode($v_reg) : array();
                                break;
                            case "items":
                                $tmpReg_result[$regRow->transaksi_id][$k_reg] = ($k_reg != NULL) ? blobDecode($v_reg) : array();
                                break;
                        }
                    }
                }
            }
            foreach ($tmpHist as $ii => $row) {
                if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->id]))) {
                    foreach ($tmpReg_result[$row->id] as $param => $eReg) {
                        switch ($param) {
                            case "main":
                                foreach ($eReg as $k => $v) {
                                    if (!isset($row->$k)) {
                                        $row->$k = $v;
                                    }
                                }
                                break;
                            case "items":
                                $row->$param = $eReg;
                                break;
                        }

                    }
                }

                $undoneResult[$ii] = $row;
            }
        }
        return $undoneResult;
    }


    //-------------------------------------
    public function setterValidate($location = "")
    {
        $msg_code = "kode cCode belum disett, silahkan segera hubungi admin. $location";
        $msg_jenistr = "kode jenisTransaksi belum disett, silahkan segera hubungi admin. $location";
        $msg_modul = "modul transaksi belum disett, silahkan segera hubungi admin. $location";
        $msg_config_ui = "konfigurasi UI belum disett, silahkan segera hubungi admin. $location";
        $msg_config_values = "konfigurasi nilai atau values belum disett, silahkan segera hubungi admin. $location";
        $msg_config_layout = "konfigurasi layout belum disett, silahkan segera hubungi admin. $location";
        $msg_config_core_master = "konfigurasi master core belum disett, silahkan segera hubungi admin. $location";
        $msg_session = "konfigurasi session data belum disett, silahkan segera hubungi admin. $location";

        $this->cCode == NULL ? mati_disini($msg_code) : "";
        $this->jenisTr == NULL ? mati_disini($msg_jenistr) : "";
        $this->modul == NULL ? mati_disini($msg_modul) : "";
        $this->configUiModul == NULL ? mati_disini($msg_config_ui) : "";
        $this->configValuesModul == NULL ? mati_disini($msg_config_values) : "";
        $this->configLayoutModul == NULL ? mati_disini($msg_config_layout) : "";
        $this->configCoreMaster == NULL ? mati_disini($msg_config_core_master) : "";
        $this->cCodeData == NULL ? mati_disini($msg_session) : "";
    }

    //-buildTable--------------------------
    public function buildTableRekening()
    {
        $cCode = $this->cCode;
        $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"] : NULL;
        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"] : false;
        $core = isset($this->configCoreMaster[$this->modul][$transaksiMode]) ? $this->configCoreMaster[$this->modul][$transaksiMode] : array();
        //region build table rekening
        if ($runCoreAkunting == true) {
            $buildTablesMaster = isset($core['components']['master']) ? $core['components']['master'] : array();
            $buildTablesDetail = isset($core['components']['detail']) ? $core['components']['detail'] : array();
            $addMasterTables = array(
                "rugilaba",
                "laba ditahan",
                "rugilaba lain lain",
            );
            foreach ($addMasterTables as $trek) {
                $buildTablesMaster[] = array(
                    "comName" => "RugiLaba",
                    "loop" => array(
                        "$trek" => .0,
                    ),
                );
            }
            if (sizeof($buildTablesMaster) > 0) {
                $bCtr = 0;
                foreach ($buildTablesMaster as $buildTablesMaster_specs) {
                    $bCtr++;
                    $mdlName = $buildTablesMaster_specs['comName'];
                    if (substr($mdlName, 0, 1) == "{") {
                        $mdlName = trim($mdlName, "{");
                        $mdlName = trim($mdlName, "}");
                        $mdlName = str_replace($mdlName, $this->cCodeData[$cCode]["main"][$mdlName], $mdlName);
                    }
                    else {
                        cekkuning("TIDAK mengandung kurawal");
                    }

                    $mdlName = "Com" . $mdlName;
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();

                    if (isset($buildTablesMaster_specs['loop']) && sizeof($buildTablesMaster_specs['loop']) > 0) {
                        foreach ($buildTablesMaster_specs['loop'] as $key => $val) {
                            if (substr($key, 0, 1) == "{") {
                                $oldParam = $buildTablesMaster_specs['loop'][$key];
//                                cekHere($oldParam);
                                unset($buildTablesMaster_specs['loop'][$key]);
                                $key = trim($key, "{");
                                $key = trim($key, "}");
                                $key = str_replace($key, $this->cCodeData[$cCode]["main"][$key], $key);
                                $buildTablesMaster_specs['loop'][$key] = $oldParam;
                            }
                        }
                    }

                    if (method_exists($m, "getTableNameMaster")) {
                        if (sizeof($m->getTableNameMaster())) {
                            $m->buildTables($buildTablesMaster_specs);
                        }
                    }
                }
            }
            if (sizeof($buildTablesDetail) > 0) {
                foreach ($buildTablesDetail as $buildTablesDetail_specs) {
                    foreach ($this->cCodeData[$cCode]["items"] as $itemSpec) {
                        $mdlName = $buildTablesDetail_specs['comName'];
//                        cekLime($mdlName);
                        if (substr($mdlName, 0, 1) == "{") {
                            $mdlName = trim($mdlName, "{");
                            $mdlName = trim($mdlName, "}");
                            $mdlName = str_replace($mdlName, $itemSpec[$mdlName], $mdlName);
                        }
                        $mdlName = "Com" . $mdlName;
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();

                        if (isset($buildTablesDetail_specs['loop']) && sizeof($buildTablesDetail_specs['loop']) > 0) {
                            foreach ($buildTablesDetail_specs['loop'] as $key => $val) {
                                if (substr($key, 0, 1) == "{") {
                                    $oldParam = $buildTablesDetail_specs['loop'][$key];
                                    unset($buildTablesDetail_specs['loop'][$key]);
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $itemSpec[$key], $key);
                                    $buildTablesDetail_specs['loop'][$key] = $oldParam;
                                }
                            }
                        }
                        if (method_exists($m, "getTableNameMaster")) {
                            if (sizeof($m->getTableNameMaster())) {
                                $m->buildTables($buildTablesDetail_specs);
                            }
                        }
                    }
                }
            }
        }
        //endregion

    }

    public function buildTableRekeningNS()
    {
        $cCode = $this->cCode;
        $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"] : NULL;
        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"] : false;
        $core = isset($this->configCoreMaster[$this->modul][$transaksiMode]) ? $this->configCoreMaster[$this->modul][$transaksiMode] : array();
        //region build table rekening
        if ($runCoreAkunting == true) {
            $buildTablesMaster = isset($core['components']['master']) ? $core['components']['master'] : array();
            $buildTablesDetail = isset($core['components']['detail']) ? $core['components']['detail'] : array();
            $addMasterTables = array(
                "rugilaba",
                "laba ditahan",
                "rugilaba lain lain",
            );
            foreach ($addMasterTables as $trek) {
                $buildTablesMaster[] = array(
                    "comName" => "RugiLaba",
                    "loop" => array(
                        "$trek" => .0,
                    ),
                );
            }
            if (sizeof($buildTablesMaster) > 0) {
                $bCtr = 0;
                foreach ($buildTablesMaster as $buildTablesMaster_specs) {
                    $bCtr++;
                    $mdlName = $buildTablesMaster_specs['comName'];
                    if (substr($mdlName, 0, 1) == "{") {
                        $mdlName = trim($mdlName, "{");
                        $mdlName = trim($mdlName, "}");
                        $mdlName = str_replace($mdlName, $this->cCodeData[$cCode]["main"][$mdlName], $mdlName);
                    }
                    else {
                        cekkuning("TIDAK mengandung kurawal");
                    }

                    $mdlName = "Com" . $mdlName;
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();
                    if (isset($buildTablesMaster_specs['loop']) && sizeof($buildTablesMaster_specs['loop']) > 0) {
                        foreach ($buildTablesMaster_specs['loop'] as $key => $val) {
                            if (substr($key, 0, 1) == "{") {
                                $oldParam = $buildTablesMaster_specs['loop'][$key];
                                $buildTablesMaster_specs['loop'][$key] = array();
                                $key = trim($key, "{");
                                $key = trim($key, "}");
                                $key = str_replace($key, $this->cCodeData[$cCode]["main"][$key], $key);
                                $buildTablesMaster_specs['loop'][$key] = $oldParam;
                            }
                        }
                    }
                    if (method_exists($m, "getTableNameMaster")) {
                        if (sizeof($m->getTableNameMaster())) {
                            $m->buildTables($buildTablesMaster_specs);
                        }
                    }
                }
            }
            if (sizeof($buildTablesDetail) > 0) {
                foreach ($buildTablesDetail as $buildTablesDetail_specs) {
                    foreach ($this->cCodeData[$cCode]["items"] as $itemSpec) {
                        $mdlName = $buildTablesDetail_specs['comName'];
                        if (substr($mdlName, 0, 1) == "{") {
                            $mdlName = trim($mdlName, "{");
                            $mdlName = trim($mdlName, "}");
                            $mdlName = str_replace($mdlName, $itemSpec[$mdlName], $mdlName);
                        }
                        $mdlName = "Com" . $mdlName;
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();
                        if (isset($buildTablesDetail_specs['loop']) && sizeof($buildTablesDetail_specs['loop']) > 0) {
                            foreach ($buildTablesDetail_specs['loop'] as $key => $val) {
                                if (substr($key, 0, 1) == "{") {
                                    $oldParam = $buildTablesDetail_specs['loop'][$key];
                                    unset($buildTablesDetail_specs['loop'][$key]);
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $itemSpec[$key], $key);
                                    $buildTablesDetail_specs['loop'][$key] = $oldParam;
                                }
                            }
                        }
                        if (method_exists($m, "getTableNameMaster")) {
                            if (sizeof($m->getTableNameMaster())) {
                                $m->buildTables($buildTablesDetail_specs);
                            }
                        }
                    }
                }
            }
        }
        //endregion
    }
    //-save--------------------------
    public function save()
    {

        $location = "(library " . get_class($this) . ", method " . __FUNCTION__ . ")";
        $this->setterValidate($location);

        $cCode = $this->cCode;
        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
        $machineID = $this->cCodeData[$cCode]["main"]["machineID"];

        $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"] : NULL;
        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["runCoreAkunting"] : false;
        $core = isset($this->configCoreMaster[$this->modul][$transaksiMode]) ? $this->configCoreMaster[$this->modul][$transaksiMode] : array();

        $corePreProcParam = isset($this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor']) ? $this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor'] : false;
        $coreRequiredParam = isset($this->configCoreMaster[$this->modul]['requiredParam']) ? $this->configCoreMaster[$this->modul]['requiredParam'] : array();
        $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["target"] : NULL;
        $relOptionConfigs = isset($this->configUiModul[$this->jenisTr]['relativeOptions']) ? $this->configUiModul[$this->jenisTr]['relativeOptions'] : array();

        $relOptionConfigs = isset($this->configUiModul[$this->jenisTr]['relativeOptions']) ? $this->configUiModul[$this->jenisTr]['relativeOptions'] : array();
        $validationTableInMaster = isset($this->configUiModul[$this->jenisTr]['validationTableInMaster']) ? $this->configUiModul[$this->jenisTr]['validationTableInMaster'] : false;
        $inputLabels = array();
        $inputAuthConfigs = array();

        $this->CI->load->library("FieldCalculator");
        $cal = new FieldCalculator();

        $rawPrevURL = isset($_GET['rawPrev']) ? $_GET['rawPrev'] : "";
        $prevUrl = blobDecode($rawPrevURL);



        /* ------------------------------
         * TRANSAKSIONAL TERJADI DI DALAM SINI
         * $dieForDebug = false; --------> kondisi normal transaksi bisa lanjot
         * untuk mematikan transksi di jadikan true
         * ------------------------*/
        $dieForDebug = false;
//        $dieForDebug = true;
        if (isset($this->cCodeData[$cCode])) {
            if (!isset($this->cCodeData[$cCode]["items"])) {
                die("belum ada item yang dipilih");
            }
            else {
                if (sizeof($this->cCodeData[$cCode]["items"]) < 1) {
                    die("belum ada item yang dipilih");
                }
            }

//            cekHere("now processing your transaction..<br>");

            //region PREPROCC-----
            //region pre-processors (item)
            if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['preProc']['detail']) ? $this->cCodeData[$cCode]['revert']['preProc']['detail'] : array();
            }
            else {
                $iterator = isset($core['preProcessor'][$jenisTrTarget]['detail']) ? $core['preProcessor'][$jenisTrTarget]['detail'] : array();
            }

            if (sizeof($iterator) > 0) {
                $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
                cekHere("ITEM NUM LABELS");

                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];

                        cekHere("sub-preproc: $comName, initializing values <br>");
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                            $tmpOutParams[$cCtr] = array();
                            $id = $xid;
                            $subParams = array();

                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {
                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['static'][$key] = $realValue;
                                }
                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$this->stepNum]["label"] . " oleh " . $this->cCodeData[$cCode][$srcGateName][$id]['nama'];
                            }

                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr][] = $subParams;
                                $comName = $tComSpec['comName'];
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                cekHere("sub preproc #: $comName, sending values ".__LINE__."<br>");

                                $mdlName = "Pre" . ucfirst($comName);
                                $this->CI->load->model("Preprocs/" . $mdlName);
                                $m = new $mdlName($resultParams);

                                if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                    $tobeExecuted = true;
                                }
                                else {
                                    $tobeExecuted = false;
                                }

                                if ($tobeExecuted) {
                                    $m->pair(0, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $gotParams = $m->exec();
                                    cekmerah("gotparams dari pre-proc $comName");
                                    if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                                        foreach ($gotParams as $gateName => $paramSpec) {
                                            cekBiru(":: getParams inject ke $gateName ::");
                                            if (!isset($this->cCodeData[$cCode][$gateName])) {
                                                $this->cCodeData[$cCode][$gateName] = array();
                                            }
                                            else {
                                                //                                    cekhijau("NOT building the session: $gateName");
                                            }
                                            foreach ($paramSpec as $id => $gSpec) {
                                                if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                                    $this->cCodeData[$cCode][$gateName][$id] = array();
                                                }
                                                if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                                    if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                        foreach ($gSpec as $key => $val) {
//                                                            cekHere(":: injecte ke $gateName, ::: $key diisi dengan $val");
                                                            $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                        }
                                                    }
                                                }
                                                //==inject gotParams to child gate
                                                if (isset($this->cCodeData[$cCode][$srcGateName][$id])) {
                                                    if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                        foreach ($gSpec as $key => $val) {
                                                            $this->cCodeData[$cCode][$srcGateName][$id][$key] = $val;
                                                        }
                                                    }
                                                }
                                                if (sizeof($itemNumLabels) > 0) {
                                                    foreach ($itemNumLabels as $key => $label) {
                                                        if (isset($this->cCodeData[$cCode][$gateName][$id][$key])) {
                                                            $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else {
                                    cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                }
                            }
                        }
                    }
                }
                else {
                    //cekKuning("sub-preproc is not set");
                }

                $this->CI->load->helper("he_value_builder");
//                fillValues_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
                $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $this->cCodeData[$cCode]["main"]["ppnFactor"], $this->cCodeData[$cCode]);
                //region injector gerbang value untuk pembatalan ppv dan selisih
                if (isset($this->cCodeData[$cCode]["revert"]["preProc"]["replacer"])) {
                    $replace = $this->cCodeData[$cCode]["revert"]["preProc"]["replacer"];
                    $tempCalculate = array(
                        "selisih" => ($this->cCodeData[$cCode]["main"]["hpp"] + $this->cCodeData[$cCode]["main"]["ppn"]) - ($this->cCodeData[$cCode]["main"]["nett"] + $this->cCodeData[$cCode]["main"]["ppv"]),
                        "hpp_nppv" => $this->cCodeData[$cCode]["main"]["hpp"],
                        "hpp_nppn" => $this->cCodeData[$cCode]["main"]["hpp"] + $this->cCodeData[$cCode]["main"]["ppn"],
                    );
                    foreach ($replace['recalculate'] as $iKey => $gate) {
                        $this->cCodeData[$cCode]["main"][$gate] = $tempCalculate[$gate];
                    }
                }
                //endregion
            }
            else {
                cekHitam("no sub-pre-processor defined. skipping preprocessor..<br>");
            }
            //endregion
            //region pre-processors (master)
            if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['preProc']['master']) ? $this->cCodeData[$cCode]['revert']['preProc']['master'] : array();
            }
            else {
                $iterator = isset($core['preProcessor'][$jenisTrTarget]['master']) ? $core['preProcessor'][$jenisTrTarget]['master'] : array();
            }
            if (sizeof($iterator) > 0) {
                $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                        $subParams = array();

                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode]["main"], $this->cCodeData[$cCode]["main"], 0);
                                $subParams['static'][$key] = $realValue;
                            }
                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . $this->cCodeData[$cCode]["main"]['oleh_nama'];
                        }
                        $tmpOutParams[$cCtr] = $subParams;

                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);

                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            $m->pair(0, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();

                            if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                                foreach ($gotParams as $gateName => $gSpec) {
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }

                                    //==inject gotParams to child gate
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }

                                    //cekMerah("REBUILDING VALUES..");
                                    if (sizeof($itemNumLabels) > 0) {
                                        //cekHijau("REBUILDING SUBS FOR ITEMS");
                                        foreach ($itemNumLabels as $key => $label) {
                                            //cekHere("$id === $key => $label");
                                            if (isset($this->cCodeData[$cCode]["main"][$key])) {
                                                $this->cCodeData[$cCode]["main"]['sub_' . $key] = ($this->cCodeData[$cCode]["main"]['jml'] * $this->cCodeData[$cCode]["main"][$key]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }
                    }
                }
                else {
                    //cekKuning("sub-preproc is not set");
                }
                $this->CI->load->helper("he_value_builder");
//                fillValues_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
                $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr],  $this->cCodeData[$cCode]["main"]["ppnFactor"], $this->cCodeData[$cCode]);
            }
            else {
                cekHitam("no main-pre-processor defined. skipping preprocessor..<br>");
            }
            //endregion

            //region VALIDATOR, masih dari sumber session cCode
            $this->CI->load->library("Validator");
            $vd = new Validator();
            $vd->setCCode($this->cCode);
            $vd->setConfigUiJenis($this->configUiModul[$this->jenisTr]);
            $vd->setSessionData($this->cCodeData[$cCode]);
            $step = $this->cCodeData[$cCode]["main"]['step_number'];
            $vd->midValidateSessionData($step);
            $vd->unionValidateSessionData();
            //endregion

            if (isset($this->configUiModul[$this->jenisTr]["steps"][2])) {
                $nextProp = array(
                    "num" => 2,
                    "code" => $this->configUiModul[$this->jenisTr]["steps"][2]["target"],
                    "label" => $this->configUiModul[$this->jenisTr]["steps"][2]["label"],
                    "groupID" => $this->configUiModul[$this->jenisTr]["steps"][2]['userGroup'],
                );
            }
            else {
                $nextProp = array(
                    "num" => 0,
                    "code" => "",
                    "label" => "",
                    "groupID" => "",
                );
            }
            //endregion

            //region dynamic counters

            //region penomoran receipt
            $this->CI->load->model("CustomCounter");
            $cn = new CustomCounter("transaksi");
            $cn->setType("transaksi");
            $configCustomParams = $this->configValuesModul[$this->jenisTr]["counters"];

            if (sizeof($configCustomParams) > 0) {
                $cContent = array();
                foreach ($configCustomParams as $i => $cRawParams) {
                    $cParams = explode("|", $cRawParams);
                    $cValues = array();
                    foreach ($cParams as $param) {
                        $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                    }
                    $cRawValues = implode("|", $cValues[$i]);
                    $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                    $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                    switch ($paramSpec["id"]) {
                        case 0: //===counter type is new
                            $addData = array(
                                "toko_id" => $tokoID,
                                "toko_nama" => $tokoNama,
                            );
                            $paramKeyRaw = print_r($cParams, true);
                            $paramValuesRaw = print_r($cValues[$i], true);
                            $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                            break;
                        default: //===counter to be updated
                            $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                            break;
                    }
                }
            }

            $appliedCounters = base64_encode(serialize($cContent));
            $appliedCounters_inText = print_r($cContent, true);

            $cn = new CustomCounter("transaksi");
            $cn->setType("transaksi");
            $counterForNumber = array($this->configValuesModul[$this->jenisTr]["formatNota"]);
            foreach ($counterForNumber as $i => $c0RawParams) {
                $c0Params = explode(",", $c0RawParams);
                foreach($c0Params as $k=>$cRawParams){
                    $dParams = explode("|", $cRawParams);
                    if(count($dParams)>1){
                        if (!in_array($cRawParams, $this->configValuesModul[$this->jenisTr]["counters"])) {
                            die(__LINE__ . "( $cRawParams ) Used number should be registered in counters config as well");
                        }
                    }
                }
            }

            $tmpNomorNota="";
            $arrNomorNota=array();
            foreach ($counterForNumber as $i => $c0RawParams) {
                $c0Params = explode(",", $c0RawParams);
                $c0Values = array();
                foreach($c0Params as $k=>$cRawParams){
                    $arrRawParams = explode("|", $cRawParams);
                    if(sizeof($arrRawParams)>1){
                        $cRawParamsValues = array();
                        foreach($arrRawParams as $key){
                            $cRawParamsValues[$key] = $this->cCodeData[$cCode]['main'][$key];
                        }
                        $cRawParamsValuesK = implode("|", array_keys($cRawParamsValues));
                        $cRawParamsValuesV = implode("|", $cRawParamsValues);
                        $arrNomorNota[] = digit_4($cContent[$cRawParamsValuesK][$cRawParamsValuesV]);
                    }
                    else{
                        $cRawParamsValuesK = $arrRawParams[0];
                        $cRawParamsValuesV = $this->cCodeData[$cCode]['main'][$arrRawParams[0]];
                        if($arrRawParams[0]=="fulldate"){
                            $arrNomorNota[] = $arrRawParams[0]."|".date("mY", strtotime($cRawParamsValuesV));
                        }
                        elseif($arrRawParams[0]=="stepCode"){
                            $arrNomorNota[] = $cRawParamsValuesV; //ini harus ori tidak boleh di masking/ diformat
//                            $arrNomorNota[] = digit_4($cContent[$cRawParamsValuesK][$cRawParamsValuesV]);
                        }
                        elseif($arrRawParams[0]=="placeID"){
                            $arrNomorNota[] = digit_2($cRawParamsValuesV);
                        }
                        elseif($arrRawParams[0]=="customerID"){
                            $arrNomorNota[] = digit_4($cRawParamsValuesV);
                        }
                        elseif($arrRawParams[0]=="olehID"){
                            $arrNomorNota[] = digit_4($cRawParamsValuesV);
                        }
                        elseif($arrRawParams[0]=="supplierID"){
                            $arrNomorNota[] = digit_4($cRawParamsValuesV);
                        }
                        elseif($arrRawParams[0]=="machineID"){
                            if($cRawParamsValuesV!=""){
                                $arrNomorNota[] = substr($cRawParamsValuesV,-4);
                            }
                            else{
                                $arrNomorNota[] = substr(MACHINE_ID,-4);
                            }
                        }
                        else{
                            $arrNomorNota[] = $cRawParamsValuesV;
                        }
                    }
                }
            }

            $stepNumber = 1;
            $tmpNomorNota = implode("-", $arrNomorNota);
            //endregion penomoran receipt

            if($cCode=="_TR_582"){
                $preNomorNota = isset($this->cCodeData[$cCode]["main"]['pre_numbering']) ? $this->cCodeData[$cCode]["main"]['pre_numbering'] : die("numbering gagal terbentuk");
                if($tmpNomorNota!=$preNomorNota){
                    $script  = "<script>
                                    top.swal('TRANSAKSI GAGAL', 'Kami mendeteksi Perilaku yang tidak benar pada Aplikasi POS, Silahkan klik disini <a onclick=\'top.window.location.reload()\' href=\'javascript:void(0)\'>reload <i class=\'fa fa-refresh\'></i></a> untuk me-refresh browser Anda.<br><br><br><small>$tmpNomorNota != $preNomorNota</small><br>LINE: ".__LINE__."', 'warning');
                                </script>";
                    die($script);
                }
            }

            //matiHere("cCode: $cCode || " . $tmpNomorNota . " <br> " . $preNomorNota);

            //region addition on master

            $addValues = array(
                "counters" => $appliedCounters,
                'counters_intext' => $appliedCounters_inText,
                'nomer' => $tmpNomorNota,
                'dtime' => date("Y-m-d H:i:s"),
                'fulldate' => date("Y-m-d"),
                "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                "step_number" => 1,
                "step_current" => 1,
                "next_step_num" => $nextProp["num"],
                "next_step_code" => $nextProp["code"],
                "next_step_label" => $nextProp["label"],
                "next_group_code" => $nextProp["groupID"],
                "tail_number" => 1,
                "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


            );
            foreach ($addValues as $key => $val) {
                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
            }
            //endregion

            //
            //region addition on detail
            $addSubValues = array(
                "sub_step_number" => 1,
                "sub_step_current" => 1,
                "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                "next_substep_num" => $nextProp["num"],
                "next_substep_code" => $nextProp["code"],
                "next_substep_label" => $nextProp["label"],
                "next_subgroup_code" => $nextProp["groupID"],
                "sub_tail_number" => 1,
                "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


            );
            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                foreach ($addSubValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                }
            }
            //endregion

            //endregion

            //region numbering tambahan
            $this->CI->load->library("CounterNumber");
            $ccn = new CounterNumber();
            $ccn->setCCode($this->cCode);
            $ccn->setJenisTr($this->jenisTr);
            $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
            $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
            $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);

            if(isset($this->cCodeData[$cCode]["items2_sum"])){
                $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
            }

            $new_counter = $ccn->getCounterNumber();

            cekHitam("jenistr yang disett dari create " . $this->jenisTr);

            if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                foreach ($new_counter["main"] as $ckey => $cval) {
                    $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                    $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                }
            }
            if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                foreach ($new_counter["items"] as $ikey => $iSpec) {
                    foreach ($iSpec as $iikey => $iival) {
                        $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                    }
                }
            }
            if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                    foreach ($iSpec as $iikey => $iival) {
                        $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                    }
                }
            }
            //endregion

//            arrPrintPink($new_counter);
            //endregion

            //region MENULIS TRANSAKSIONAL
            if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {

                $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 0;

                $tr = new MdlTransaksi();
                $tr->addFilter("transaksi.cabang_id='" . $this->cCodeData[$cCode]["tableIn_master"]['cabang_id'] . "'");
                $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                cekHitam($this->CI->db->last_query());
                $epID = $tr->writeMainEntries_entryPoint($insertID, $insertID, $this->cCodeData[$cCode]["tableIn_master"]);
                $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                if ($insertID < 1) {
                    die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                }

                //==transaksi_id dan nomor nota diinject kan ke gate utama
                $injectors = array(
                    "transaksi_id" => $insertID,
                    "nomer" => $tmpNomorNota,
                    "nomer2" => isset($tmpNomorNotaAlias) ? $tmpNomorNotaAlias : "",
                );
                $arrInjectorsTarget = array(
                    "items",
                    "items2_sum",
                    "rsltItems",
                );
                foreach ($injectors as $key => $val) {
                    $this->cCodeData[$cCode]["main"][$key] = $val;
                    foreach ($arrInjectorsTarget as $target) {
                        if (isset($this->cCodeData[$cCode][$target])) {
                            foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                if (isset($this->cCodeData[$cCode][$target][$id])) {
                                    $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                }
                            }
                        }
                    }
                }

                //===signature
                $dwsign = $tr->writeSignature($insertID, array(
                    "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                    "step_number" => 1,
                    "step_code" => $this->jenisTr,
                    "step_name" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"],
                    "group_code" => $this->configUiModul[$this->jenisTr]["steps"][1]['userGroup'],
                    "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                    "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                    "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'],
                    "transaksi_id" => $insertID,
                )) or die("Failed to write signature");

                $idHis = array(
                    $stepNumber => array(
                        "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                        "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                        "step" => $stepNumber,
                        "trID" => $insertID,
                        "nomer" => $tmpNomorNota,
                        "nomer2" => isset($tmpNomorNotaAlias) ? $tmpNomorNotaAlias : "",
                        "counters" => $appliedCounters,
                        // "counters_intext" => $appliedCounters_inText,
                    ),
                );
                $idHis_blob = blobEncode($idHis);
                $idHis_intext = print_r($idHis, true);
                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array("id" => $insertID), array(
                    "next_step_num" => $nextProp["num"],
                    "next_step_code" => $nextProp["code"],
                    "next_step_label" => $nextProp["label"],
                    "next_group_code" => $nextProp["groupID"],

                    //===references
                    "id_master" => $insertID,
                    "id_top" => $insertID,
                    "ids_prev" => "",
                    "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                    "nomers_prev" => "",
                    "jenises_prev" => "",
                    "ids_his" => $idHis_blob,

                )) or die("Failed to update tr next-state!");
                cekHijau($this->CI->db->last_query());
                $addValues = array(
                    //===references
                    "id_master" => $insertID,
                    "id_top" => $insertID,
                    "ids_prev" => "",
                    "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                    "nomers_prev" => "",
                    "jenises_prev" => "",
                    "ids_his" => $idHis_blob,
                );
                foreach ($addValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

            }
            if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                $inserMainValues = array();
                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'])) {
                    $inserMainValues = array();
                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                        if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                            $dd = $tr->writeMainValues($insertID, array(
                                "key" => $key,
                                "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                            ));
                            $inserMainValues[] = $dd;
                        }
                    }
                }
                if (sizeof($inserMainValues) > 0) {
                    $arrBlob = blobEncode($inserMainValues);
                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                $inserMainValues = array();
                foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                    $inserMainValues[] = $dd;
                }
                if (sizeof($inserMainValues) > 0) {
                    $arrBlob = blobEncode($inserMainValues);
                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                    $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                    $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                    $tr->writeMainApplets($insertID, array(
                        "mdl_name" => $amdl,
                        "key" => $aSpec['key'],
                        "label" => $aSpec['labelValue'],
                        "description" => $aSpec['description'],
                    ));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                    $tr->writeMainElements($insertID, array(
                        "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                        "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                        "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                        "name" => $aSpec['name'],
                        "label" => $aSpec["label"],
                        "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                        "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                    ));
                    //==nebeng bikin inputLabels
                    $currentValue = "";
                    switch ($aSpec['elementType']) {
                        case "dataModel":
                            $currentValue = $aSpec['key'];
                            break;
                        case "dataField":
                            $currentValue = $aSpec["value"];
                            break;
                    }
                    if (array_key_exists($elName, $relOptionConfigs)) {
                        if (isset($relOptionConfigs[$elName][$currentValue])) {
                            if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
                                foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
                                    $inputLabels[$oValueName] = $oValSpec["label"];
                                    if (isset($oValSpec['auth'])) {
                                        if (isset($oValSpec['auth']["groupID"])) {
                                            $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
                        }
                    }
                }
            }
            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                $insertIDs = array();
                $insertDeIDs = array();
                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                    if ($insertDetailID < 1) {
                        die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                    }
                    else {
                        $insertIDs[] = $insertDetailID;
                        $insertDeIDs[$insertID][] = $insertDetailID;
                    }
                    if ($epID != 999) {
                        $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                        if ($insertEpID < 1) {
                            die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                        }
                        else {
                            $insertIDs[] = $insertEpID;
                            $insertDeIDs[$epID][] = $insertEpID;
                        }
                    }
                    cekUngu($this->CI->db->last_query());
                }
                if (sizeof($insertIDs) == 0) {
                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                }
                else {
                    $indexing_details = array();
                    foreach ($insertDeIDs as $key => $numb) {
                        $indexing_details[$key] = $numb;
                    }
                    foreach ($indexing_details as $k => $arrID) {
                        $arrBlob = blobEncode($arrID);
                        $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                        cekOrange($this->CI->db->last_query());
                    }
                }
            }
            else {
                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                    $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                    if ($epID != 999) {
                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                    }
                    cekUngu($this->CI->db->last_query());
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $insertDetailID;
                    if ($epID != 999) {
                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                        $insertIDs[] = $dd;
                        $mongoList['detail'][] = $dd;
                    }
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $dd;
                    if ($epID != 999) {
                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                    }
                    cekUngu($this->CI->db->last_query());
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                            if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                $dd = $tr->writeDetailValues($insertID, array(
                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                ));
                                $insertIDs[$pID][] = $dd;
                            }
                        }
                    }
                }
                if (sizeof($insertIDs) > 0) {
                    $arrBlob = blobEncode($insertIDs);
                    $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                        $insertIDs = array();
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                            $insertIDs[] = $dd;
                        }
                    }
                }
            }

            $steps = $this->configUiModul[$this->jenisTr]["steps"];

            //endregion

            //region COMPONENT-----
            if ($runCoreAkunting == true) {
                //region processing sub-components, if in single step geser ke CLI
                $componentGate['detail'] = array();
                $componentConfig['detail'] = array();
                //==filter nilai, jika NOL tidak dikirim, sesuai config==
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                $filterNeeded = false;
                $comsLocation = isset($this->configValuesModul[$this->jenisTr]['componentsLocation']['detail']) ? $this->configValuesModul[$this->jenisTr]['componentsLocation']['detail'] : "Coms";
                $comsPrefix = isset($this->configValuesModul[$this->jenisTr]['componentsPrefix']['detail']) ? $this->configValuesModul[$this->jenisTr]['componentsPrefix']['detail'] : "Com";
                $componentsDetailLoop = isset($this->configValuesModul[$this->jenisTr]['componentsDetailLoop']) ? $this->configValuesModul[$this->jenisTr]['componentsDetailLoop'] : true;

                if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                    $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal']['detail']) ? $this->cCodeData[$cCode]['revert']['jurnal']['detail'] : array();
                    $revertedTarget = $this->cCodeData[$cCode]["main"]['pihakExternID'];
                }
                else {
                    if (isset($this->cCodeData[$cCode]['componentsBuilder'][1]['detail'])) {
                        $iterator = $this->cCodeData[$cCode]['componentsBuilder'][1]['detail'];
                    }
                    else {
                        $iterator = isset($core['components']['detail']) ? $core['components']['detail'] : array();
                    }
                    $revertedTarget = "";
                }
                $componentConfig['detail'] = $iterator;

                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $tmpOutParams[$cCtr] = array();
                        $gg = 0;
                        $srcGateName = $tComSpec['srcGateName'];
                        if ($componentsDetailLoop == true) {
                            foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                $comName = $tComSpec['comName'];
                                if (substr($comName, 0, 1) == "{") {
                                    $comName = trim($comName, "{");
                                    $comName = trim($comName, "}");
                                    $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                                }

                                $mdlName = "$comsPrefix" . ucfirst($comName);
                                if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                                    $filterNeeded = true;
                                }
                                else {
                                    $filterNeeded = false;
                                }
                                cekHere("sub-component: [$comsLocation] $comName, initializing values <br>") ;

                                $subParams = array();

                                if (isset($tComSpec['loop'])) {
                                    foreach ($tComSpec['loop'] as $key => $value) {
                                        if (substr($key, 0, 1) == "{") {
                                            $key = trim($key, "{");
                                            $key = trim($key, "}");
                                            $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$id][$key], $key);
                                        }

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                        $subParams['loop'][$key] = $realValue;

                                        if ($filterNeeded) {
                                            if ($subParams['loop'][$key] == 0) {
                                                unset($subParams['loop'][$key]);
                                            }
                                        }
                                    }
                                }
                                if (isset($tComSpec['static'])) {
                                    foreach ($tComSpec['static'] as $key => $value) {
                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                        $subParams['static'][$key] = $realValue;
                                    }
                                    if (!isset($subParams['static']["transaksi_id"])) {
                                        $subParams['static']["transaksi_id"] = $insertID;
                                    }
                                    if (!isset($subParams['static']["transaksi_no"])) {
                                        $subParams['static']["transaksi_no"] = $insertNum;
                                    }

                                    $subParams['static']["fulldate"] = date("Y-m-d");
                                    $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                                    if (strlen($revertedTarget) > 1) {
                                        $subParams['static']['reverted_target'] = $revertedTarget;
                                    }
                                }

                                if (sizeof($subParams) > 0) {
//                                cekhitam("subparam ada isinya");
                                    if ($filterNeeded) {
                                        if (isset($subParams['loop']) && sizeof($subParams['loop']) > 0) {
                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }
                                    }
                                    else {
                                        $tmpOutParams[$cCtr][] = $subParams;
                                    }
                                }
                                else {
                                    cekhitam("subparam TIDAK ada isinya");
                                }
                            }
                        }
                        else {
                            foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                                if ($cCtr == $id) {
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    $comName = $tComSpec['comName'];
                                    if (substr($comName, 0, 1) == "{") {
                                        $comName = trim($comName, "{");
                                        $comName = trim($comName, "}");

                                        $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                                    }

                                    $mdlName = "$comsPrefix" . ucfirst($comName);
                                    if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                                        $filterNeeded = true;
                                    }
                                    else {
                                        $filterNeeded = false;
                                    }
                                    cekHere("sub-component: [$comsLocation] $comName, initializing values <br>") ;

                                    $subParams = array();

                                    if (isset($tComSpec['loop'])) {
                                        foreach ($tComSpec['loop'] as $key => $value) {

                                            if (substr($key, 0, 1) == "{") {
                                                $key = trim($key, "{");
                                                $key = trim($key, "}");

                                                $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$id][$key], $key);
                                            }

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                            $subParams['loop'][$key] = $realValue;

                                            if ($filterNeeded) {
                                                if ($subParams['loop'][$key] == 0) {
                                                    unset($subParams['loop'][$key]);
                                                }
                                            }
                                        }
                                    }
                                    if (isset($tComSpec['static'])) {
                                        foreach ($tComSpec['static'] as $key => $value) {
                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                            $subParams['static'][$key] = $realValue;

                                        }
                                        if (!isset($subParams['static']["transaksi_id"])) {
                                            $subParams['static']["transaksi_id"] = $insertID;
                                        }
                                        if (!isset($subParams['static']["transaksi_no"])) {
                                            $subParams['static']["transaksi_no"] = $insertNum;
                                        }

                                        $subParams['static']["fulldate"] = date("Y-m-d");
                                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                                        if (strlen($revertedTarget) > 1) {
                                            $subParams['static']['reverted_target'] = $revertedTarget;
                                        }
                                    }

                                    if (sizeof($subParams) > 0) {

                                        if ($filterNeeded) {
                                            if (isset($subParams['loop']) && sizeof($subParams['loop']) > 0) {
                                                $tmpOutParams[$cCtr][] = $subParams;
                                            }
                                        }
                                        else {
                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }
                                    }
                                    else {
                                        cekhitam("subparam TIDAK ada isinya");
                                    }
                                }
                            }
                        }

                        $componentGate['detail'][$cCtr] = $subParams;
                    }


                    foreach ($iterator as $cCtr => $tComSpec) {
                        $srcGateName = $tComSpec['srcGateName'];
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $comName = $tComSpec['comName'];
                            if (substr($comName, 0, 1) == "{") {
                                $comName = trim($comName, "{");
                                $comName = trim($comName, "}");
                                $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                            }
                        }
                        cekHere("sub component: [$comsLocation] $comName, sending values ".__LINE__."<br>") ;

                        $mdlName = "$comsPrefix" . ucfirst($comName);
                        $this->CI->load->model("$comsLocation/" . $mdlName);
                        $m = new $mdlName();
                        //===filter value nol, jika harus difilter

                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {

                            //----- kiriman gerbang
                            if (method_exists($m, "setTableInMaster")) {
                                $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                            }
                            if (method_exists($m, "setDetail")) {
                                $m->setDetail($this->cCodeData[$cCode][$srcGateName]);
                            }
                            if (method_exists($m, "setJenisTr")) {
                                $m->setJenisTr($this->jenisTr);
                            }
                            //----- kiriman gerbang
                            $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            cekBiru($this->CI->db->last_query());
                        }
                        else {
                            cekMerah("$comName tidak eksekusi");
                        }

                    }
                }
                else {
                    cekKuning("subcomponents is not set");
                }
                //endregion

                //region processing main components, if in single step
                $componentGate['master'] = array();
                $componentConfig['master'] = array();
                //==filter nilai, jika NOL tidak dikirim, sesuai config==
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                    $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal']['master']) ? $this->cCodeData[$cCode]['revert']['jurnal']['master'] : array();
                }
                else {
                    if (isset($this->cCodeData[$cCode]['componentsBuilder'][1]['master'])) {
                        $iterator = $this->cCodeData[$cCode]['componentsBuilder'][1]['master'];
                    }
                    else {
                        $iterator = isset($core['components']['master']) ? $core['components']['master'] : array();
                    }
                }

                if (sizeof($iterator) > 0) {
                    $componentConfig['master'] = $iterator;
                    $cCtr = 0;
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $cCtr++;
                        $comName = $tComSpec['comName'];
                        if (substr($comName, 0, 1) == "{") {
                            $comName = trim($comName, "{");
                            $comName = trim($comName, "}");
                            $comName = str_replace($comName, $this->cCodeData[$cCode]["main"][$comName], $comName);
                        }
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        cekHere("component # $cCtr: $comName<br>") ;

                        $dSpec = $this->cCodeData[$cCode][$srcGateName];
                        $tmpOutParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {
                                if (substr($key, 0, 1) == "{") {
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $this->cCodeData[$cCode]["main"][$key], $key);
                                }
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['loop'][$key] = $realValue;
                            }
                        }
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['static'][$key] = $realValue;
                            }
                            if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                $tmpOutParams['static']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                $tmpOutParams['static']["transaksi_no"] = $insertNum;
                            }
                            $tmpOutParams['static']["urut"] = $cCtr;
                            $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                        }

                        if (isset($tComSpec['static2'])) {
                            foreach ($tComSpec['static2'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                $tmpOutParams['static2'][$key] = $realValue;
                            }
                            if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                $tmpOutParams['static2']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                            }
                            $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                        }

                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();

                        //===filter value nol, jika harus difilter
                        $tobeExecuted = true;
                        if (in_array($mdlName, $compValidators)) {
                            $loopParams = isset($tmpOutParams['loop']) ? $tmpOutParams['loop'] : array();
                            if (sizeof($loopParams) > 0) {
                                foreach ($loopParams as $key => $val) {
                                    cekmerah("$comName : $key = $val ");
                                    if ($val == 0) {
                                        unset($tmpOutParams['loop'][$key]);
                                    }
                                }
                            }
                            if (sizeof($tmpOutParams['loop']) < 1) {
                                $tobeExecuted = false;
                            }
                        }
                        if ($tobeExecuted) {
                            //----- kiriman gerbang untuk counter mutasi rekening
                            if (method_exists($m, "setTableInMaster")) {
                                $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                            }
                            if (method_exists($m, "setMain")) {
                                $m->setMain($this->cCodeData[$cCode]["main"]);
                            }
                            if (method_exists($m, "setJenisTr")) {
                                $m->setJenisTr($this->jenisTr);
                            }
                            //----- kiriman gerbang untuk counter mutasi rekening
                            $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }
                        $componentGate['master'][$cCtr] = $tmpOutParams;
                    }
                }
                else {
                    cekKuning("components is not set");
                }
                //endregion
            }
            else {
                cekHitam("TIDAK ADA COMPONENT");
            }
            //endregion

            //region POST PROCC-----
            //region processing sub-post-processors, always
            if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['postProc']['detail']) ? $this->cCodeData[$cCode]['revert']['postProc']['detail'] : array();
            }
            else {
                $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail'] : array();
            }

            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    cekHere("[$cCtr] sub-postProcessor: $comName, gate: $srcGateName, initializing values <br>") ;
                    $tmpOutParams[$cCtr] = array();
                    if (isset($this->cCodeData[$cCode][$srcGateName]) && (sizeof($this->cCodeData[$cCode][$srcGateName]) > 0)) {
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                            $id = $xid;
                            $subParams = array();
                            if (isset($tComSpec['loop'])) {
                                foreach ($tComSpec['loop'] as $key => $value) {
                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['loop'][$key] = $realValue;
                                }
                            }
                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {
                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['static'][$key] = $realValue;
                                }
                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $insertID;
                                }
                                if (!isset($subParams['static']["transaksi_no"])) {
                                    $subParams['static']["transaksi_no"] = $insertNum;
                                }
                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                if (isset($this->cCodeData[$cCode]['revert']['postProc']['detail'])) {
                                    $subParams['static']["reverted_target"] = $this->cCodeData[$cCode]["main"]['pihakExternID'];
                                }
                                $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                            }
                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr][] = $subParams;
                            }
                        }
                    }
                }
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    if (isset($this->cCodeData[$cCode][$srcGateName])) {
                        cekHere("[$cCtr] sub-postProcessor: $comName, sending values ".__LINE__."<br>") ;
                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();
                        $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    }
                }
            }
            else {
                cekHitam("TIDAK ADA SETUP SUB-POSTPROC");
            }
            //endregion

            //region relesaese connected payment source dan marking trash transaksi
            if (isset($this->cCodeData[$cCode]["revert"]["connectedPaymentsource"]) && $this->cCodeData[$cCode]["revert"]["connectedPaymentsource"] == true) {
                $keyRel = $this->cCodeData[$cCode]["main"]["referenceID"];
                $keyRelRef = $this->cCodeData[$cCode]["main"]["pihakExternID"];
                $relPaymentSrc = isset($this->CI->config->item("payment_source")[$keyRelRef]) ? $this->CI->config->item("payment_source")[$keyRelRef] : array();
                if (sizeof($relPaymentSrc) > 0) {
                    $this->CI->load->model("Mdls/MdlPaymentSource");
                    $m = new MdlPaymentSource();
                    $m->addFilter("transaksi_id='$keyRel'");
                    $tmpRelPay = $m->lookupAll()->result();
                    $paymentRelUsed = array(
                        "cabang_id" => "placeID",
                        "extern_id" => "id",
                        "extern_nama" => "name",
                        "label" => ".hutang biaya",
                        "target_jenis" => "jenisTr",
                        "transaksi_id" => "refID",
                        "terbayar" => "nilai_bayar",
                        "sisa" => "new_sisa",
                        "ppn" => "valid_ppn",
                        "extern_nilai2" => "valid_dpp",
                    );
                    if (sizeof($tmpRelPay) > 0) {
                        $tmpOutParams = array();
                        $iterator = array();
                        foreach ($tmpRelPay as $indexKey => $relData) {
                            $tmp = array();
                            foreach ($paymentRelUsed as $key => $keyGate) {
                                if ($key == "terbayar") {
                                    $val = $relData->sisa;
                                }
                                else {
                                    if ($key == "sisa") {
                                        $val = "-" . $relData->sisa;
                                    }
                                    else {
                                        $val = $relData->$key;
                                    }
                                }
                                $tmp["static"][$key] = $val;
                                $tmp["static"]["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                            }
                            $iterator[$indexKey]["loop"] = array();
                            $iterator[$indexKey]["comName"] = "PaymentSrcItem";
                            if (sizeof($tmp) > 0) {
                                $tmpOutParams[$indexKey][] = $tmp;
                            }
                        }
                        foreach ($iterator as $cCtr => $tComSpec) {
                            $comName = $tComSpec['comName'];
                            cekHere("sub-postProcessor: $comName, sending values <br>") ;
                            $mdlName = "Com" . ucfirst($comName);
                            $this->CI->load->model("Coms/" . $mdlName);
                            $m = new $mdlName();
                            $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }
                    }
                    cekLime("yuk direset paymentsource**");
                }
            }
            //endregion

            //region processing main-post-processors, always
            if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['postProc']['detail']) ? $this->cCodeData[$cCode]['revert']['postProc']['master'] : array();
            }
            else {
                $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master'] : array();
            }

            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    cekHere("post-processor: $comName<br>LINE: " . __LINE__) ;

                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                    $tmpOutParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['loop'][$key] = $realValue;
                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static'][$key] = $realValue;
                        }
                        if (!isset($tmpOutParams['static']["transaksi_id"])) {
                            $tmpOutParams['static']["transaksi_id"] = $insertID;
                        }
                        if (!isset($tmpOutParams['static']["transaksi_no"])) {
                            $tmpOutParams['static']["transaksi_no"] = $insertNum;
                        }
                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                    }
                    if (isset($tComSpec['static2'])) {
                        foreach ($tComSpec['static2'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                            $tmpOutParams['static2'][$key] = $realValue;
                        }
                        if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                            $tmpOutParams['static2']["transaksi_id"] = $insertID;
                        }
                        if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                            $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                        }

                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'];
                    }

                    //lgShowError("Ada kesalahan",);
                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();

                    cekBiru("kiriman komponem $comName");
                    $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
            }
            else {
                cekHitam("TIDAK ADA SETUP MAIN-POSTPROC");
            }
            //endregion
            //endregion

            //region nulis uangMukaSource
            /*dimatiin geser ke ComUangmukaSourceDetail karena ada di items.
            /*revisi tanggal 27 mei 2020 subject digeser ke vendor dari jenis transaksi misal uangmuka asuransi,uang muka pembelian ->uang muka.
             *
             */
            $stepNum = 1;
            $stepCode = $this->configUiModul[$this->jenisTr]['steps'][$stepNum]['target'];
            $uangMukaSources = $this->CI->config->item("uang_muka");

            if (array_key_exists($stepCode, $uangMukaSources)) {
                cekMerah(":: starting UANG MUKA  SOURCE");
                //            matiHere();
                $uangMukaConfigs = isset($uangMukaSources[$stepCode][$stepNum]) ? $uangMukaSources[$stepCode][$stepNum] : array();
                if (sizeof($uangMukaConfigs) > 0) {
                    $cekPreValue = "";
                    $this->load->model("Mdls/MdlPaymentUangMuka");
                    $l = new MdlPaymentUangMuka();
                    foreach ($uangMukaConfigs as $uangMukaSrcConfig) {
                        $valueSrc = $uangMukaSrcConfig['valueSrc'];
                        $externSrc = $uangMukaSrcConfig['externSrc'];
                        $l->addFilter("extern_id='" . $this->cCodeData[$cCode]['main'][$externSrc['id']] . "'");
                        $l->addFilter("extern_label2='" . $externSrc['extLabel'] . "'");
                        $l->addFilter("extern_id='" . $this->cCodeData[$cCode]['main']['placeID'] . "'");
                        $tmpUm = $l->lookupAll()->result();
                        if (sizeof($tmpUm) > 0) {
                            //update here broo
                            $preTagihan = $tmpUm[0]->tagihan;
                            $preSisa = $tmpUm[0]->sisa;
                            $newTahigan = $preTagihan + $this->cCodeData[$cCode]['main'][$valueSrc];
                            $newsisa = $preSisa + $this->cCodeData[$cCode]['main'][$valueSrc];
                            $update = array(
                                "tagihan" => $newTahigan,
                                "sisa" => $newsisa,
                            );
                            $where = array(
                                "extern_id" => $this->cCodeData[$cCode]['main'][$externSrc['id']],
                                "extern_label2" => $externSrc['extLabel'],//pembeda vendor dan customer lihat di heTransaksi_misc ->uang muka
                            );
                            $tr->updateUangMukaSrc($where, $update);
                            cekHitam($this->db->last_query());
                        }
                        else {
                            //insertbaru brooo
                            $tr->writeUangMukaSrc($insertID, array(
                                "jenis" => $stepCode,
                                "target_jenis" => $uangMukaSrcConfig['jenisTarget'],
                                "reference_jenis" => $uangMukaSrcConfig['jenisSrc'],
                                "extern_id" => $this->cCodeData[$cCode]['main'][$externSrc['id']],
                                "extern_nama" => $this->cCodeData[$cCode]['main'][$externSrc['nama']],
                                "nomer" => "",
                                "note" => "",
                                "label" => $uangMukaSrcConfig['label'],
                                "tagihan" => $this->cCodeData[$cCode]['main'][$valueSrc],
                                "terbayar" => 0,
                                "sisa" => $this->cCodeData[$cCode]['main'][$valueSrc],
                                "cabang_id" => $this->cCodeData[$cCode]['main']['placeID'],
                                "cabang_nama" => $this->cCodeData[$cCode]['main']['placeName'],
                                "oleh_id" => $this->session->login['id'],
                                "oleh_nama" => $this->session->login['nama'],
                                "dtime" => date("Y-m-d H:i:s"),
                                "fulldate" => date("Y-m-d"),
                                "extern_label2" => $externSrc['extLabel'],
                            ));
                        }
                    }
                }
                else {
                    cekLime("not write uang muka");
                }
            }
            else {
                cekMerah("not write uang muka");
            }
            //endregion

            //region updater main transaksi rejection jurnal next step exist
            $mongUpdateList = array();
            if (isset($core['relativeComponets']) && $core['relativeComponets'] == true) {
//            if (isset($this->configValuesModul[$this->jenisTr]['relativeComponets']) && $this->configValuesModul[$this->jenisTr]['relativeComponets'] == true) {

                $tr->setFilters(array());
                $tr->addFilter("id = '" . $this->cCodeData[$cCode]["main"]["referenceID"] . "'");
                $tempData = $tr->lookupAll()->result();
                $refMasterID = $tempData[0]->id_master;
                $refMasterJenis = $tempData[0]->jenis_master;
                $nextStepCode = $tempData[0]->next_step_code;
                $mainStepCode = $tempData[0]->jenis;
                $stepnum = $tempData[0]->step_number;
                $stepnumAvail = $tempData[0]->step_avail;
                if (($stepnumAvail - $stepnum) > 0) {
                    $this->CI->load->model("Coms / ComTransaksi_jurnal_revert");
                    $r = new ComTransaksi_jurnal_revert();
                    $outParams = array(
                        "refID" => $refMasterID,
                        "main_code" => $mainStepCode,
                        "next_code" => $nextStepCode,
                        "step_num" => $stepnum,
                    );
                    $r->pair($outParams) or die("Tidak berhasil memasang  values pada komponen: $comName / " . $this->jenisTr . " / " . __FUNCTION__ . " / " . __LINE__);
                    $r->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName / " . $this->jenisTr . " / " . __FUNCTION__ . " / " . __LINE__);

                    //marking main transaksi trash4
                    $udpate = array(
                        "trash_4" => "1",
                    );
                    $tr->setFilters(array());
                    $dupState = $tr->updateData(array(
                        "id" => $this->cCodeData[$cCode]["main"]["referenceID"],
                    ), $udpate) or die("Failed to update tr next - state!");
//                    cekHijau("UPDATE transaksi step sebelumnya...");
//                    cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                    //update validqty 0 supaya gak bisa difollowup
                    $td = new MdlTransaksi();
                    $td->setFilters(array());
                    $rslt = $td->lookupJoinedByID($this->cCodeData[$cCode]["main"]["referenceID"])->result();
                    if (sizeof($rslt) > 0) {
                        foreach ($rslt as $rsltSpec) {
                            if (array_key_exists($rsltSpec->produk_id, $this->cCodeData[$cCode]["items"])) {
                                $arrData_detail["valid_qty"] = 0;
                                $tr = new MdlTransaksi();
                                $tr->setFilters(array());
                                $tr->setTableName($tr->getTableNames()['detail']);
                                $dupState = $tr->updateData(array(
                                    "transaksi_id" => $this->cCodeData[$cCode]["main"]["referenceID"],
                                    "produk_id" => $rsltSpec->produk_id,
                                ), $arrData_detail) or die("Failed to update tr next - state!");
//                                cekKuning("UPDATE transaksi data...");
//                                cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                            }
                        }
                    }

                    $dwsign = $tr->writeSignature($refMasterID, array(
                        "prev_id" => "",
                        "nomer" => "pembatalan jurnal",
                        "step_number" => " - " . $stepnum, // ini minus step number
                        "step_code" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["target"],
                        "step_name" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["label"],
                        "group_code" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]['userGroup'],
                        "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                        "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                        "keterangan" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["label"] . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'],
                        //            "transaksi_id" => $no,
                    )) or die("Failed to write signature");
//                    cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    //                    matiHere();
                }
                else {
                    //marking main transaksi trash4
                    $udpate = array(
                        "trash_4" => "1",
                    );
                    $tr->setFilters(array());
                    $dupState = $tr->updateData(array(
                        "id" => $this->cCodeData[$cCode]["main"]["referenceID"],
                    ), $udpate) or die("Failed to update tr next - state!");
//                    cekHijau("UPDATE transaksi step sebelumnya...");
//                    cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    //update validqty 0 supaya gak bisa difollowup
                    $arrData_detail["valid_qty"] = $new_valid_qty;
                    $td = new MdlTransaksi();
                    $td->setFilters(array());
                    $rslt = $td->lookupJoinedByID($this->cCodeData[$cCode]["main"]["referenceID"])->result();
                    if (sizeof($rslt) > 0) {
                        foreach ($rslt as $rsltSpec) {
                            if (array_key_exists($rsltSpec->produk_id, $this->cCodeData[$cCode]["items"])) {
                                $arrData_detail["valid_qty"] = 0;
                                $tr = new MdlTransaksi();
                                $tr->setFilters(array());
                                $tr->setTableName($tr->getTableNames()['detail']);
                                $dupState = $tr->updateData(array(
                                    "transaksi_id" => $this->cCodeData[$cCode]["main"]["referenceID"],
                                    "produk_id" => $rsltSpec->produk_id,
                                ), $arrData_detail) or die("Failed to update tr next - state!");
//                                cekKuning("UPDATE transaksi data...");
//                                cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                            }
                        }
                    }

                    $dwsign = $tr->writeSignature($refMasterID, array(
                        "prev_id" => "",
                        "nomer" => "pembatalan jurnal",
                        "step_number" => " - " . $stepnum, // ini minus step number
                        "step_code" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["target"],
                        "step_name" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["label"],
                        "group_code" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]['userGroup'],
                        "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                        "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                        "keterangan" => $this->configUiModul[$refMasterJenis]["steps"][abs($stepnum)]["label"] . " oleh " . $this->cCodeData[$cCode]["tableIn_master"]['oleh_nama'],
                    )) or die("Failed to write signature");
//                    cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
//
                    //                    matiHEre("uhuu");
//
                }
            }

            //endregion

            // region berlaku pembatalan transaksi bila ada config revertStep di model MdlRevertJurnal (true)
            if (isset($this->cCodeData[$cCode]["main"]['pihakExternRevertStep']) && ($this->cCodeData[$cCode]["main"]['pihakExternRevertStep'] == true)) {
                $referenceNextProp = (isset($this->cCodeData[$cCode]["main"]['referenceNextProp']) && (sizeof($this->cCodeData[$cCode]["main"]['referenceNextProp']) > 0)) ? $this->cCodeData[$cCode]["main"]['referenceNextProp'] : array();
                if (sizeof($referenceNextProp) > 0) {
                    // update transaksi reference, step sebelumnya menjadi aktif lagi
                    $tr = new MdlTransaksi();
                    $tr->setFilters(array());
                    $dupState = $tr->updateData(array("id" => $referenceNextProp['trID']), array(
                        "next_step_code" => $referenceNextProp["code"],
                        "next_step_label" => $referenceNextProp["label"],
                        "next_group_code" => $referenceNextProp["groupID"],
                        "next_step_num" => $referenceNextProp["num"],
                        "step_current" => $referenceNextProp['step_num'],

                    )) or die("Failed to update tr next-state!");
                    cekHijau("BATAL :: " . $this->CI->db->last_query() . " -- " . $this->CI->db->affected_rows());
                    $mongUpdateList['update']["main"][] = array(
                        "where" => array("id" => $referenceNextProp['trID']),
                        "value" => array(
                            "next_step_code" => $referenceNextProp["code"],
                            "next_step_label" => $referenceNextProp["label"],
                            "next_group_code" => $referenceNextProp["groupID"],
                            "next_step_num" => $referenceNextProp["num"],
                            "step_current" => $referenceNextProp['step_num'],
                        ),
                    );


                    // update transaksi data reference, step sebelumnya menjadi aktif lagi
                    $tr = new MdlTransaksi();
                    $tr->setFilters(array());
                    $tr->addFilter("trash='0'");
                    $tr->addFilter("transaksi_id='" . $referenceNextProp['trID'] . "'");
                    $tr->setTableName($tr->getTableNames()['detail']);
                    $detailTmp = $tr->lookupAll()->result();
                    $detailData = array();
                    foreach ($detailTmp as $dTmpSpec) {
                        $detailData[$dTmpSpec->produk_id] = array(
                            "valid_qty" => $dTmpSpec->valid_qty,
                        );
                    }
                    cekOrange($referenceNextProp['detailGate']);
                    if (isset($this->cCodeData[$cCode][$referenceNextProp['detailGate']]) && ($this->cCodeData[$cCode][$referenceNextProp['detailGate']] != NULL)) {
                        foreach ($this->cCodeData[$cCode][$referenceNextProp['detailGate']] as $itemsSpec) {
                            $valid_qty = isset($detailData[$itemsSpec["id"]]['valid_qty']) ? $detailData[$itemsSpec["id"]]['valid_qty'] : 0;
                            $valid_qty_new = $valid_qty + $itemsSpec['qty'];

                            $tr = new MdlTransaksi();
                            $tr->setFilters(array());
                            $tr->setTableName($tr->getTableNames()['detail']);
                            $ddupState = $tr->updateData(
                                array(
                                    "transaksi_id" => $referenceNextProp['trID'],
                                    "trash" => 0,
                                    "produk_id" => $itemsSpec["id"],
                                ), array(
                                "next_substep_code" => $referenceNextProp["code"],
                                "next_substep_label" => $referenceNextProp["label"],
                                "next_subgroup_code" => $referenceNextProp["groupID"],
                                "next_substep_num" => $referenceNextProp["num"],
                                "sub_step_current" => $referenceNextProp['step_num'],
                                "valid_qty" => $valid_qty_new,

                            )) or die("Failed to update tr next-state!");
                            cekHijau("BATAL :: " . $this->CI->db->last_query() . " -- " . $this->CI->db->affected_rows());

                        }
                    }
                }
            }
            // endregion

            //region nulis paymentSource
            $stepCode = $this->configUiModul[$this->jenisTr]["steps"][1]["target"];
            $paymentSources = $this->CI->config->item("payment_source");
            if (array_key_exists($stepCode, $paymentSources)) {
                $payConfigs = $paymentSources[$stepCode];
                if (sizeof($payConfigs) > 0) {
                    foreach ($payConfigs[1] as $paymentSrcConfig) {
                        $valueSrc = $paymentSrcConfig['valueSrc'];
                        $externSrc = $paymentSrcConfig['externSrc'];
                        $tr->writePaymentSrc($insertID, array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                            "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => isset($this->cCodeData[$cCode]["main"][$valueSrc]) ? $this->cCodeData[$cCode]["main"][$valueSrc] : 0,
                            "terbayar" => 0,
                            "sisa" => isset($this->cCodeData[$cCode]["main"][$valueSrc]) ? $this->cCodeData[$cCode]["main"][$valueSrc] : 0,
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                            "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                            "toko_id" => $this->cCodeData[$cCode]["main"]['tokoID'],
                            "toko_nama" => $this->cCodeData[$cCode]["main"]["tokoNama"],

                            "machine_id"    => isset($this->cCodeData[$cCode]["main"]['machineID']) ? $this->cCodeData[$cCode]["main"]['machineID'] : "none",
                            "cpu_info"      => isset($this->cCodeData[$cCode]["main"]['CPU_INFO']) ? $this->cCodeData[$cCode]["main"]['CPU_INFO'] : "none",
                            "com_name"      => isset($this->cCodeData[$cCode]["main"]['COM_INFO']) ? $this->cCodeData[$cCode]["main"]['COM_INFO'] : "none",

                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id"      => (isset($externSrc['valasId']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama"    => (isset($externSrc['valasLabel']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai"   => (isset($externSrc['valasValue']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : 0,
                            "tagihan_valas" => (isset($externSrc['valasTagihan']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : 0,
                            "terbayar_valas"=> (isset($externSrc['valasTerbayar']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']] : 0,
                            "sisa_valas"    => (isset($externSrc['valasSisa']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : 0,
                            "extern_label2" => (isset($externSrc['extern_label2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_label2']] : "",
                            "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : 0,
                            "extern_date2"  => (isset($externSrc['extern_date2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_date2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_date2']] : 0,
                            //-----
                            "seller_id" => (isset($externSrc['seller_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_id']] : "",
                            "seller_nama" => (isset($externSrc['seller_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_nama']] : "",
                            "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                            "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                        ));
                        cekMerah($this->CI->db->last_query());
                    }
                }
            }
            else {
                cekMerah("TIDAK nulis paymentSrc");
            }
            //endregion

            //region nulis paymentAntiSource
            $stepCode = $this->configUiModul[$this->jenisTr]["steps"][1]["target"];
            $paymentSources = $this->CI->config->item("payment_antiSource") != null ? $this->CI->config->item("payment_antiSource") : array();
            if (array_key_exists($stepCode, $paymentSources)) {
                cekHitam(":: starting PAYMENT ANTI SOURCE");
                $payConfigs = $paymentSources[$stepCode];
                if (sizeof($payConfigs) > 0) {
                    foreach ($payConfigs as $paymentSrcConfig) {
                        $valueSrc = $paymentSrcConfig['valueSrc'];
                        $externSrc = $paymentSrcConfig['externSrc'];
                        $tr->writePaymentAntiSrc($insertID, array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                            "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "terbayar" => 0,
                            "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "toko_id" => $this->cCodeData[$cCode]["main"]['tokoID'],
                            "toko_nama" => $this->cCodeData[$cCode]["main"]["tokoNama"],
                            "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                            "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                            "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                            "terbayar_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']] : '',
                            "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                            "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                            "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                        ));
                        //cekMerah($this->CI->db->last_query());
                    }
                }
            }
            else {
                //cekMerah("TIDAK nulis paymentSrc");
            }
            //endregion

            //region MENULIS KE REGISTRY
            if (isset($core['components']) && sizeof($core['components'])) {
                $jurnalIndex = $core['components'];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["jurnal"]) && sizeof($this->cCodeData[$cCode]["revert"]["jurnal"]) > 0) {
                    $jurnalIndex = $this->cCodeData[$cCode]["revert"]["jurnal"];
                }
                else {
                    $jurnalIndex = array();
                }
            }
            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget])) {
                $jurnalPostProc = $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["postProc"]) && sizeof($this->cCodeData[$cCode]["revert"]["postProc"]) > 0) {
                    $jurnalPostProc = $this->cCodeData[$cCode]["revert"]["postProc"];
                }
                else {
                    $jurnalPostProc = array();
                }
            }
            //------------
            if (isset($core['preProcessor'][$jenisTrTarget]) && sizeof($core['preProcessor'][$jenisTrTarget])) {
                $jurnalPreProc = $core['preProcessor'][$jenisTrTarget];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["preProc"]) && sizeof($this->cCodeData[$cCode]["revert"]["preProc"]) > 0) {
                    $jurnalPreProc = $this->cCodeData[$cCode]["revert"]["preProc"];
                }
                else {
                    $jurnalPreProc = array();
                }
            }
            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget])) {
                $coreBuilder = $this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget];
            }
            else {
                $coreBuilder = array();
            }
            //------------
            $baseRegistries = array(
                "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                'items_elements' => isset($this->cCodeData[$cCode]['items_elements']) ? $this->cCodeData[$cCode]['items_elements'] : array(),
                'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                "receiptDetailFields" => isset($this->configLayout[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailFields'][1] : array(),
                "receiptSumFields" => isset($this->configLayout[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptSumFields'][1] : array(),
                "receiptDetailFields2" => isset($this->configLayout[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                "receiptDetailSrcFields" => isset($this->configLayout[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                "receiptSumFields2" => isset($this->configLayout[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayout[$this->jenisTr]['receiptSumFields2'][1] : array(),
                "jurnal_index" => $jurnalIndex,
                "postProcessor" => $jurnalPostProc,
                "preProcessor" => $jurnalPreProc,
                "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                "itemPrice" => isset($this->cCodeData[$cCode]['itemPrice']) ? $this->cCodeData[$cCode]['itemPrice'] : array(),
                "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                "requiredParam" => (isset($coreRequiredParam[$this->jenisTr]) && sizeof($coreRequiredParam[$this->jenisTr]) > 0) ? $coreRequiredParam[$this->jenisTr] : array(),
                //-----
                "coreBuilder" => $coreBuilder,
                'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                //-----
            );
            $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
            showLast_query("biru");
            //endregion

            //region extended steps
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $iKey => $iVal) {
                    if ($iVal > 0) {
                        cekbiru("evaluating $iKey ($iVal) for paymentSrc..");
                        $stepCode = $this->jenisTr . "_";
                        $paymentSources = $this->CI->config->item("payment_source");

                        if (array_key_exists($stepCode, $paymentSources)) {
                            $payConfigs = $paymentSources[$stepCode];
                            cekbiru("$stepCode registered");

                            //===kalau melibatkan payment-source
                            if (sizeof($payConfigs) > 0) {
                                foreach ($payConfigs as $paymentSrcConfig) {
                                    if ($paymentSrcConfig['valueSrc'] == $iKey) {
                                        cekhijau($paymentSrcConfig['valueSrc'] . " / $iKey akan dieksekusi");
                                        $valueSrc = $paymentSrcConfig['valueSrc'];
                                        $externSrc = $paymentSrcConfig['externSrc'];
                                        if ($tr->paymentSrcExistsInMaster($insertID, $stepCode, $paymentSrcConfig["label"])) {
                                            cekhijau($paymentSrcConfig["label"] . " pada $stepCode $insertID sudah ada, tidak perlu ditulis");
                                        }
                                        else {
                                            cekhijau($paymentSrcConfig["label"] . " pada $stepCode $insertID BELUM ada, ditulis sekarang");
                                            $tr->writePaymentSrc($insertID, array(
                                                "_key" => $iKey,
                                                "jenis" => $stepCode,
                                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                                "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                                "label" => $paymentSrcConfig["label"],
                                                "tagihan" => $this->cCodeData[$cCode]['main_inputs'][$valueSrc],
                                                "terbayar" => 0,
                                                "sisa" => $this->cCodeData[$cCode]['main_inputs'][$valueSrc],
                                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                                "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                                                "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                                                "dtime" => dtimeNow(),
                                                "fulldate" => dtimeNow("Y-m-d"),
                                                "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                                                "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                                                "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                                                "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                                                "terbayar_valas" => 0,
                                                "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                                            ));
                                        }
                                        //									cekMerah("paySrc: ".$this->CI->db->last_query());
                                    }
                                    else {
                                        cekmerah($paymentSrcConfig['valueSrc'] . " / $iKey tidak untuk dieksekusi");
                                    }
                                }
                            }
                        }
                        else {
                            cekbiru("$stepCode NOT registered");
                        }

                        //==periksa apakah mainInput memerlukan auth
                        if (array_key_exists($iKey, $inputAuthConfigs)) {
                            $gID = $inputAuthConfigs[$iKey];
                            if (strlen($gID) > 0) {
                                cekhijau("input $iKey bernilai $iVal memerlukan auth dari $gID");
                                $trA = new MdlTransaksi();
                                if ($trA->extStepExistsInMaster($insertID, $iKey)) {
                                    cekhijau("extStep SUDAH terdaftar, sekarang nggak akan ditulis");
                                }
                                else {
                                    cekhijau("extStep belum terdaftar, sekarang hendak ditulis");
                                    $trA->writeExtStep($insertID, array(
                                        "master_id" => $insertID,
                                        "transaksi_id" => $insertID,
                                        "_key" => $iKey,
                                        "_label" => $inputLabels[$iKey],
                                        "_value" => $iVal,
                                        "group_id" => $gID,
                                        "state" => "0",
                                        "proposed_by" => $this->cCodeData[$cCode]["main"]['olehID'],
                                        "proposed_dtime" => date("Y-m-d H:i:s"),
                                        "done_by",
                                        "done_dtime",
                                    ));
                                    cekhijau($this->CI->db->last_query());
                                }
                            }

                        }
                    }

                }
            }
            //endregion

            $arrFreeProduk = array();
            if( isset($this->cCodeData[$cCode]['free_items']) ){
                foreach($this->cCodeData[$cCode]['free_items'] as $rowPrd ){
                    foreach($rowPrd as $diskon_id => $rowDiskon){
                        $arrFreeProduk[$diskon_id] = array(
                            "diskon_id" => $diskon_id,
                            "produk_id" => $rowDiskon['ori_produk_id'],
                            "produk_nama" => $this->cCodeData[$cCode]['items'][$rowDiskon['ori_produk_id']]['nama'],
                            "free_produk_id" => $rowDiskon['free_produk_id'],
                            "free_produk_nama" => $rowDiskon['free_produk_nama'],
                            "free_qty" => $rowDiskon['free_qty'],
                            "kelipatan" => $rowDiskon['kelipatan'],
                            "quota_global" => $rowDiskon['quota_global'],
                            "quota_used" => $rowDiskon['quota_used'],
                            "date" => $rowDiskon['date'],
                            "settlement" => 1,
                            "transaksi_id" => $insertID,
                            "transaksi_no" => $tmpNomorNota,
                            "toko_id" => $tokoID,
                            "oleh_id" => $this->cCodeData[$cCode]['main']['olehID'],
                            "oleh_nama" => $this->cCodeData[$cCode]['main']['olehName'],
                            "customer_id" => $this->cCodeData[$cCode]['main']['customerID'],
                            "customer_nama" => $this->cCodeData[$cCode]['main']['customerName'],
                        );
                    }
                }

                $this->CI->load->library("Curl");
                $curl = New Curl();

                $url = apiDiskonProduk()['saveFreeProduk'];
                $writer = $curl->sendPost($url, $arrFreeProduk);
            }

            $outResultLib = array(
                "sessionData" => $this->cCodeData[$cCode],
                "tmpNomerNota" => $tmpNomorNota,
                "transaksiId" => $insertID,
                "url" => $url,
            );

            $masterID = $insertID;

            //region connecting antar cabang
            $connector = isset($this->configUiModul[$this->jenisTr]['connectTo']) ? $this->configUiModul[$this->jenisTr]['connectTo'] : "";
            $preReplacer = isset($this->configUiModul[$this->jenisTr]['replacerConnectTo']) ? $this->configUiModul[$this->jenisTr]['replacerConnectTo'] : array();
            if (strlen($connector) > 0) {
                cekMerah(":: CONNECTING BEGIN... " . __LINE__);

                if (isset($this->configUiModul[$this->jenisTr]['connectoValidate']['1'])) {
                    $validateValueConnector = $this->configUiModul[$this->jenisTr]['connectoValidate']['1'];
                    $preVal = $this->cCodeData[$cCode]["main"][$validateValueConnector];
                    $stepNum = $preVal > 0 ? $steps : array();//array kosong untuk nglewatin step biar gak jalan connectingnya karena nilai yang dicari 0 kasusnya cash in advance ppn sudah masuk pusat tidak perlu diterbitkan auto dorong ppn ke pusat
                }
                else {
                    $stepNum = $steps;
                }

                if (sizeof($stepNum) == 1) {

                    if (!array_key_exists($connector, $this->configUiModul)) {
                        die("kode connector tidak dikenali!");
                    }
                    if (sizeof($this->configUiModul[$connector]["steps"]) < 2) {

                        $paramForce = isset($this->configUiModul[$connector]['connectToForce']) ? isset($this->configUiModul[$connector]['connectToForce']) : false;
                        if ($paramForce) {
                            // die("konfigurasi connector harus memiliki step lebih dari satu!/ tambahakan connectToForce='true' untuk mengijinkan");
                        }
                        else {
                            die("konfigurasi connector harus memiliki step lebih dari satu!*$connector");
                        }

                    }

                    $oldCode = $cCode;
                    $cCode = "_TR_" . $connector;

                    if (isset($this->cCodeData[$cCode])) {
                        $this->cCodeData[$cCode] = array();
                    }

                    /*
                     *inisiasi session baru bair gak kosong session ccode yang baru 29/9/2022
                     */
//                    $this->cCodeData[$cCode] = array(
//                        "main" => isset($_SESSION[$oldCode]["main"]) ? $_SESSION[$oldCode]["main"] : array(),
//                        "items" => isset($_SESSION[$oldCode]["items"]) ? $_SESSION[$oldCode]["items"] : array(),
//                        "items2" => isset($_SESSION[$oldCode]["items2"]) ? $_SESSION[$oldCode]["items2"] : array(),
//                        "items2_sum" => isset($_SESSION[$oldCode]["items2_sum"]) ? $_SESSION[$oldCode]["items2_sum"] : array(),
//                        "items3" => isset($_SESSION[$oldCode]["items3"]) ? $_SESSION[$oldCode]["items3"] : array(),
//                        "items3_sum" => isset($_SESSION[$oldCode]["items3_sum"]) ? $_SESSION[$oldCode]["items3_sum"] : array(),
//                        "items4_sum" => isset($_SESSION[$oldCode]["items4_sum"]) ? $_SESSION[$oldCode]["items4_sum"] : array(),
//                        "items_noapprove" => isset($_SESSION[$oldCode]['items_noapprove']) ? $_SESSION[$oldCode]['items_noapprove'] : array(),
//                        "tableIn_master" => isset($_SESSION[$oldCode]["tableIn_master"]) ? $_SESSION[$oldCode]["tableIn_master"] : array(),
//                        "tableIn_detail" => isset($_SESSION[$oldCode]["tableIn_detail"]) ? $_SESSION[$oldCode]["tableIn_detail"] : array(),
//                        "rsltItems" => isset($_SESSION[$oldCode]['rsltItems']) ? $_SESSION[$oldCode]['rsltItems'] : array(),
//                        "tableIn_detail_rsltItems" => isset($_SESSION[$oldCode]['tableIn_detail_rsltItems']) ? $_SESSION[$oldCode]['tableIn_detail_rsltItems'] : array(),
//                        "tableIn_master_values" => isset($_SESSION[$oldCode]['tableIn_master_values']) ? $_SESSION[$oldCode]['tableIn_master_values'] : array(),
//                        "tableIn_detail_values" => isset($_SESSION[$oldCode]['tableIn_detail_values']) ? $_SESSION[$oldCode]['tableIn_detail_values'] : array(),
//                        "tableIn_detail_values_rsltItems" => isset($_SESSION[$oldCode]['tableIn_detail_values_rsltItems']) ? $_SESSION[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
//                    );

                    $this->cCodeData[$cCode] = array(
                        "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                        "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                        "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                        "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                        "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                        "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                        "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                        "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                        "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                        "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                        "rsltItems" => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                        "tableIn_detail_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                        "tableIn_master_values" => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                        "tableIn_detail_values" => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                        "tableIn_detail_values_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                    );

                    //region detector cloner dalam satu cabang
                    $oldStep = $this->cCodeData[$oldCode]["main"]["step_number"];
                    $clonerTransaction = isset($this->configUiModul[$this->jenisTr]['clonerTransaction'][$oldStep]) ? $this->configUiModul[$this->jenisTr]['clonerTransaction'][$oldStep] : array();
                    //endregion

                    if (sizeof($clonerTransaction) && isset($clonerTransaction["main"]['cloner'])) {

                        $replacerTableinDetail = array(
                            "dtime" => "dtime",
                            "produk_id" => "id",
                            "produk_kode" => "kode",
                            "produk_label" => "label",
                            "produk_nama" => "nama",
                            "produk_ord_jml" => "jml",
                            "produk_ord_hrg" => "harga1",
                            "satuan" => "satuan",
                            "produk_jenis" => "produk_jenis",
                            "harga" => "harga1",
                            "valid_qty" => "produk_ord_jml",
                        );
                        $replacerStepItems2 = array(
                            "sub_tail_number" => "",
                            "sub_tail_code" => "",
                            "sub_step_avail" => "",
                            "sub_step_current" => "",
                            "sub_step_number" => "",
                            "next_substep_num" => "",
                            "next_substep_code" => "",
                            "next_substep_label" => "",
                            "next_subgroup_code" => "",
                        );

                        $itesmNewTmp = array();
                        if (isset($this->cCodeData[$oldCode]["items2"]) && sizeof($this->cCodeData[$oldCode]["items2"]) > 0) {
                            foreach ($this->cCodeData[$oldCode]["items2"] as $indexItems2) {
                                foreach ($indexItems2 as $itemsDetail) {
                                    $itesmNewTmp[$itemsDetail["id"]] = array_merge($itemsDetail, $replacerStepItems2);
                                    foreach ($replacerTableinDetail as $selCol => $xAlias) {
                                        $this->cCodeData[$oldCode]['tableIn_detail2'][$itemsDetail["id"]][$selCol] = $itemsDetail[$selCol];
                                    }
                                    foreach ($replacerStepItems2 as $stepItems2 => $tempItems2Val) {
                                        $this->cCodeData[$oldCode]['tableIn_detail2'][$itemsDetail["id"]][$stepItems2] = $tempItems2Val;
                                    }
                                }
                            }
                        }
                        else {
                            $itesmNewTmp = $this->cCodeData[$oldCode]["items"];

                        }
                        if (sizeof($itesmNewTmp) > 0) {
                            $itesmNew = array();
                            foreach ($itesmNewTmp as $itemsID => $itemData) {
                                if (isset($itemData['harga'])) {
                                    $itemData['harga'] = isset($itemData['produk_ord_hrg']) ? $itemData['produk_ord_hrg'] : $itemData['harga'];
                                }
                                $itesmNew[$itemsID] = $itemData;
                            }
                        }


                        //region itemsToMaster
                        $itemTomasterStatic = isset($clonerTransaction['staticItemToMaster']) ? $clonerTransaction['staticItemToMaster'] : array();
                        $itemToMaster = isset($clonerTransaction['itemToMaster']) ? $clonerTransaction['itemToMaster'] : array();
                        if (sizeof($itemToMaster) > 0) {
                            foreach ($this->cCodeData[$oldCode]["items"] as $itemsTemp) {
                                foreach ($itemToMaster as $colItems => $aliasMaster) {
                                    if (isset($itemsTemp[$colItems])) {
                                        $this->cCodeData[$oldCode]["main"][$aliasMaster] = $itemsTemp[$colItems];
                                        $this->cCodeData[$oldCode]["tableIn_master"][$aliasMaster] = $itemsTemp[$colItems];
                                    }
                                }
                            }
                            if (sizeof($itemTomasterStatic) > 0) {
                                foreach ($itemTomasterStatic as $kolStatic => $valStatic) {
                                    $this->cCodeData[$oldCode]["main"][$kolStatic] = $valStatic;
                                    $this->cCodeData[$oldCode]["tableIn_master"][$kolStatic] = $valStatic;
                                }
                            }
                        }
                        //endregion

                        if ($clonerTransaction["main"]['cloner']) {
                            $this->cCodeData[$oldCode] = array(
                                "main" => $this->cCodeData[$oldCode]["main"],
                                "items" => $itesmNew,
                                "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                                "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                                "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                                "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                                // ---
                                "tableIn_master" => $this->cCodeData[$oldCode]["tableIn_master"],
                                "tableIn_detail" => isset($this->cCodeData[$oldCode]['tableIn_detail2']) ? $this->cCodeData[$oldCode]['tableIn_detail2'] : $this->cCodeData[$oldCode]["tableIn_detail"],
                                'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                                "rsltItems" => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                                'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                                "tableIn_detail_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                                "main_add_values" => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                                "main_add_fields" => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                                "main_elements" => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                                //
                                "tableIn_master_values" => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                                "tableIn_detail_values" => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                                "tableIn_detail_values_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                                'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                            );
                        }
                        else {
                            $this->cCodeData[$oldCode] = array(
                                "main" => $this->cCodeData[$oldCode]["main"],
                                "items" => $this->cCodeData[$oldCode]["items"],
                                "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                                "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                                "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                                "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                                // -------------
                                "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                                "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                                'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                                "rsltItems" => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                                'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                                //----------------
                                "tableIn_detail_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                                "tableIn_master_values" => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                                "tableIn_detail_values" => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                                "tableIn_detail_values_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                                'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                            );
                        }


                        $masterReplacers = array(
                            "inv" => $tmpNomorNota,
                            "jenis_master" => $connector,
                            "jenis_top" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis_label" => $this->configUiModul[$connector]["steps"][1]["label"],
                            "transaksi_jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "div_id" => my_div_id(),
                            "div_nama" => my_div_nama(),
                            "step_avail" => sizeof($this->configUiModul[$connector]["steps"]),
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]["target"] : "",
                            "next_step_label" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]["label"] : "",
                            "next_group_code" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]['userGroup'] : "",
                            "next_step_num" => isset($this->configUiModul[$connector]["steps"][2]) ? 2 : "0",
                        );
                        $masterReplacersO = array(
                            "jenisTr" => $connector,
                            "div_id" => my_div_id(),
                            "jenisTrMaster" => $connector,
                            "jenisTrTop" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis_label" => $this->configUiModul[$connector]["steps"][1]["label"],
                            "transaksi_jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "stepCode" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData[$oldCode]["main"]['nomer'] : "",
                        );
                    }
                    else {
                        $this->cCodeData[$oldCode] = array(
                            "main" => $this->cCodeData[$oldCode]["main"],
                            "items" => $this->cCodeData[$oldCode]["items"],
                            "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                            "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                            "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                            "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                            // -------------
                            "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                            "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                            'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                            "rsltItems" => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                            'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                            //----------------
                            "tableIn_detail_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                            'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                            "tableIn_master_values" => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                            "tableIn_detail_values" => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                            "tableIn_detail_values_rsltItems" => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                            'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                            'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                        );
                        $masterReplacers = array(
                            "inv" => $tmpNomorNota,
                            "jenis_master" => $connector,
                            "jenis_top" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis_label" => $this->configUiModul[$connector]["steps"][1]["label"],
                            "transaksi_jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "cabang_id" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$oldCode]["tableIn_master"]['cabang2_id'],
                            "cabang_nama" => isset($preReplacer['cabang2Name']) ? $preReplacer['cabang2Name'] : $this->cCodeData[$oldCode]["tableIn_master"]['cabang2_nama'],
                            "cabang2_id" => $this->cCodeData[$oldCode]["tableIn_master"]['cabang_id'],
                            "cabang2_nama" => $this->cCodeData[$oldCode]["tableIn_master"]['cabang_nama'],
                            // -----------------
                            "gudang_id" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData[$oldCode]["tableIn_master"]['gudang2_id'],
                            "gudang_nama" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$oldCode]["tableIn_master"]['gudang2_nama'],
                            "gudang2_id" => isset($this->cCodeData[$oldCode]["tableIn_master"]['gudang_id']) ? $this->cCodeData[$oldCode]["tableIn_master"]['gudang_id'] : "",
                            "gudang2_nama" => isset($this->cCodeData[$oldCode]["tableIn_master"]['gudang_nama']) ? $this->cCodeData[$oldCode]["tableIn_master"]['gudang_nama'] : "",
                            // -------------------
                            "step_avail" => sizeof($this->configUiModul[$connector]["steps"]),
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]["target"] : "",
                            "next_step_label" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]["label"] : "",
                            "next_group_code" => isset($this->configUiModul[$connector]["steps"][2]) ? $this->configUiModul[$connector]["steps"][2]['userGroup'] : "",
                            "next_step_num" => isset($this->configUiModul[$connector]["steps"][2]) ? 2 : "0",
                        );
                        $masterReplacersO = array(
                            "jenisTr" => $connector,
                            "jenisTrMaster" => $connector,
                            "jenisTrTop" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "jenis_label" => $this->configUiModul[$connector]["steps"][1]["label"],
                            "transaksi_jenis" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "stepCode" => $this->configUiModul[$connector]["steps"][1]["target"],
                            "placeID" => isset($preReplacer['place2ID']) ? $preReplacer['place2ID'] : $this->cCodeData[$oldCode]["main"]['place2ID'],
                            "placeName" => isset($preReplacer['place2Name']) ? $preReplacer['place2Name'] : $this->cCodeData[$oldCode]["main"]['place2Name'],
                            "place2ID" => $this->cCodeData[$oldCode]["main"]['placeID'],
                            "place2Name" => $this->cCodeData[$oldCode]["main"]['placeName'],
                            // -----------------
                            "cabangID" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$oldCode]["main"]['place2ID'],
                            "cabangName" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$oldCode]["main"]['place2Name'],
                            "cabang2ID" => $this->cCodeData[$oldCode]["main"]['placeID'],
                            "cabang2Name" => $this->cCodeData[$oldCode]["main"]['placeName'],
                            // -----------------
                            "gudang2ID" => $this->cCodeData["main"]['gudangID'],
                            "gudang2Name" => $this->cCodeData["main"]['gudangName'],
                            "gudangID" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData["main"]['gudang2ID'],
                            "gudangName" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData["main"]['gudang2Name'],
                            "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData["main"]['nomer'] : "",
                        );
                    }

                    //==replace pertama

                    foreach ($masterReplacersO as $key => $val) {
                        $this->cCodeData[$cCode]["main"][$key] = $val;
                    }

                    foreach ($masterReplacers as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }

                    //region penomoran receipt #2
                    //<editor-fold desc=" ==========penomoran">
                    $this->CI->load->model("CustomCounter");
                    $cn = new CustomCounter("transaksi");
                    $cn->setType("transaksi");

                    $counterForNumber = array($this->configValuesModul[$connector]["formatNota"]);
                    if (!in_array($counterForNumber[0], $this->configValuesModul[$connector]["counters"])) {
                        die(__LINE__ . " Used number should be registered in counters config as well");
                    }

                    foreach ($counterForNumber as $i => $cRawParams) {
                        $cParams = explode("|", $cRawParams);
                        $cValues = array();
                        foreach ($cParams as $param) {
                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        }
                        $cRawValues = implode("|", $cValues[$i]);
                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                    }

                    $tmpNomorNota2 = $paramSpec["paramString"];

                    //endregion

                    //region dynamic counters #2
                    $cn = new CustomCounter("transaksi");
                    $cn->setType("transaksi");
                    $configCustomParams = $this->configValuesModul[$connector]["counters"];
                    if (sizeof($configCustomParams) > 0) {
                        $cContent = array();
                        foreach ($configCustomParams as $i => $cRawParams) {
                            $cParams = explode("|", $cRawParams);
                            $cValues = array();
                            foreach ($cParams as $param) {
                                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                            }
                            $cRawValues = implode("|", $cValues[$i]);
                            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                            $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                            switch ($paramSpec["id"]) {
                                case 0: //===counter type is new
                                    $addData = array(
                                        "toko_id" => $tokoID,
                                        "toko_nama" => $tokoNama,
                                    );
                                    $paramKeyRaw = print_r($cParams, true);
                                    $paramValuesRaw = print_r($cValues[$i], true);
                                    $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                    break;
                                default: //===counter to be updated
                                    $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                    break;
                            }
                        }
                    }
                    $appliedCounters2 = base64_encode(serialize($cContent));
                    $appliedCounters_inText2 = print_r($cContent, true);
                    //endregion

                    //region numbering tambahan
                    $this->CI->load->library("CounterNumber");
                    $ccn = new CounterNumber();
                    $ccn->setCCode($cCode);
                    $ccn->setJenisTr($connector);
                    $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                    $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                    $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                    $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                    $new_counter = $ccn->getCounterNumber();
                    cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                    if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                        foreach ($new_counter["main"] as $ckey => $cval) {
                            $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                            $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                        }
                    }
                    if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                        foreach ($new_counter["items"] as $ikey => $iSpec) {
                            foreach ($iSpec as $iikey => $iival) {
                                $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                            }
                        }
                    }
                    if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                        foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                            foreach ($iSpec as $iikey => $iival) {
                                $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                            }
                        }
                    }
                    //endregion

                    $addValues = array(
                        "counters" => $appliedCounters,
                        'counters_intext' => $appliedCounters_inText,
                        'nomer' => $tmpNomorNota,
                        'dtime' => date("Y-m-d H:i:s"),
                        'fulldate' => date("Y-m-d"),
                    );
                    foreach ($addValues as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }
                    //===cloning nota cab1 ke cab2
                    //===daftar perbedaan
                    //== referensi_id, inv, jenis, nomer, counters, counters_inText, cabang_id, cabang_nama, cabang2_id, cabang2_nama,
                    //==replace kedua
                    $masterReplacers = array(
                        "nomer" => $tmpNomorNota2,
                        "counters" => $appliedCounters2,
                        "counters_intext" => $appliedCounters_inText2,
                    );
                    foreach ($masterReplacers as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }

                    if ($validationTableInMaster != false) {
                        // arrPrint($validationTableInMaster);
                        foreach ($validationTableInMaster as $itemKolom => $kolomNilaiValidasi) {
                            if (!isset($this->cCodeData[$cCode]["tableIn_master"][$itemKolom])) {
                                lgShowWarning("transaksi gagal", "$itemKolom tidak terdeteksi");
                                matiDisini("$itemKolom belum dikirim");
                            }

                            $nilai_kolom_ygdicek = $this->cCodeData[$cCode]["tableIn_master"][$itemKolom];
                            $validator = "$nilai_kolom_ygdicek $kolomNilaiValidasi";

                            if ($nilai_kolom_ygdicek == 0) {
                                // if ($validator) {
                                //     matiDisini(__LINE__ . " kena validasi $nilai_kolom_ygdicek . $kolomNilaiValidasi ** $validator");
                                lgShowWarning("transaksi gagal", "$itemKolom tidak terdeteksi");
                                matiDisini("$itemKolom terdeteksi 0");
                            }
                        }

                    }
                    //===cloning detail/items cabang1 ke cabang2
                    //===yang direplace: sub_step_number, sub_step_current, sub_step_avail, next_substep_num, next_substep_code, next_substep_label, next_subgroup_code
                    $detailReplacers = array(
                        "sub_step_avail" => sizeof($this->configUiModul[$connector]["steps"]),
                        "sub_step_current" => 1,
                        "sub_step_number" => 1,
                        "next_substep_num" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_num'],
                        "next_substep_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_code'],
                        "next_substep_label" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_label'],
                        "next_subgroup_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_group_code'],
                    );
                    // arrPrintWebs($detailReplacers);
                    // arrPrint($this->cCodeData[$oldCode]["tableIn_detail"]);

                    
                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                           foreach($detailReplacers as $key =>$val){
                               $this->cCodeData[$cCode]["tableIn_detail"][$k][$key]=$val;
                           }
                            // foreach ($dSpec as $key => $val) {
                            //     // ceklime($key);
                            //     $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                            // }
                        }
                    }
                    // arrPrint($this->cCodeData[$cCode]["tableIn_detail"]);
                    // matiHere(__LINE__);
                    //region ----------write transaksi & transaksi_data #2
                    if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                        $tr = new MdlTransaksi();
                        $tr->addFilter("transaksi . cabang_id = '" . $this->cCodeData[$cCode]["main"]['cabang_id'] . "'");
                        $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                        cekHitam($this->CI->db->last_query());
                        // matiHEre();
                        $epID = $tr->writeMainEntries_entryPoint($insertID, $insertID, $this->cCodeData[$cCode]["tableIn_master"]);

                        $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                        $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                        if ($insertID < 1) {
                            die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                        }
                    }
                    // matiHEre();

                    if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                        foreach ($this->cCodeData[$cCode]['tableIn_master_values'] as $key => $val) {
                            $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                            $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                        cekkuning("main_inputs detected");
                        foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                            $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                            //                            cekkuning("making a clone for input key $key / $val");
                            //                            $subInputInsertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                            $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                            $tr->writeMainElements($insertID, array(
                                "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                "name" => $aSpec['name'],
                                "label" => $aSpec["label"],
                                "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                "contents_intext" => isset($aSpec['contents_intext']) ? print_r($aSpec['contents_intext'], true) : "",

                            ));
                        }
                    }

                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                        $insertIDs = array();
                        $insertDeIDs = array();
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                            arrPrint($dSpec);
                            $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                            cekBiru($this->CI->db->last_query());
                            if ($insertDetailID < 1) {
                                die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                            }
                            else {
                                $insertIDs[] = $insertDetailID;
                                $insertDeIDs[$insertID][] = $insertDetailID;
                            }
                            if ($epID != 999) {
                                $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                if ($insertEpID < 1) {
                                    die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                }
                                else {
                                    $insertIDs[] = $insertEpID;
                                    $insertDeIDs[$epID][] = $insertEpID;
                                }
                            }
                        }
// matiHEre();
                        if (sizeof($insertIDs) == 0) {
                            die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong . "));
                        }
                        else {
                            $indexing_details = array();
                            foreach ($insertDeIDs as $key => $numb) {
                                $indexing_details[$key] = $numb;
                            }

                            foreach ($indexing_details as $k => $arrID) {
                                $arrBlob = blobEncode($arrID);
                                $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id = $k");
                                cekOrange($this->CI->db->last_query());
                            }
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                            $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                            if ($epID != 999) {
                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                            }
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                    if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                        $insertIDs[$pID][] = $tr->writeDetailValues($insertID, array(
                                            "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                            "produk_id" => $pID,
                                            "key" => $key,
                                            "value" => $dSpec[$src],
                                        ));
                                    }
                                }
                            }
                        }
                        if (sizeof($insertIDs) > 0) {
                            $arrBlob = blobEncode($insertIDs);
                            $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id = $insertID");
                        }
                    }

                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                    $insertIDs[] = $tr->writeDetailValues($insertID, array(
                                        "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                        "produk_id" => $pID,
                                        "key" => $key,
                                        "value" => $dSpec[$src],
                                    ));
                                }
                            }


                        }
                    }


                    // arrPrint($this->cCodeData[$cCode]["main"]);
                    // matiHEre();
                    $idHis = array(
                        $stepNumber => array(
                            "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                            "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                            "step" => $stepNumber,
                            "trID" => $insertID,
                            "nomer" => $tmpNomorNota2,
                            "counters" => $appliedCounters2,
                            "counters_intext" => $appliedCounters_inText2,
                        ),
                    );
                    $idHis_blob = blobEncode($idHis);
                    $idHis_intext = print_r($idHis, true);

                    $tr = new MdlTransaksi();
                    $dupState = $tr->updateData(array("id" => $insertID), array(
                        "id_master" => $masterID,
                        "id_top" => $insertID,
                        "ids_his" => $idHis_blob,
                        "ids_his_intext" => $idHis_intext,

                    )) or die("Failed to update tr next - state!");

                    $baseRegistries = array(
                        "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                        "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                        "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                        "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                        "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                        "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                        "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                        "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                        'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                        'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                        'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                        'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                        'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                        'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                        'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                        "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                        "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                        'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                        'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                        'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                        'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                        'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                        'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                        'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                        'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                        'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                        'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                        'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                        'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                        'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                        "receiptDetailFields" => isset($this->configLayoutModul[$connector]['receiptDetailFields'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields'][1] : array(),
                        "receiptSumFields" => isset($this->configLayoutModul[$connector]['receiptSumFields'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields'][1] : array(),
                        "receiptDetailFields2" => isset($this->configLayoutModul[$connector]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields2'][1] : array(),
                        "receiptSumFields2" => isset($this->configLayoutModul[$connector]['receiptSumFields2'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields2'][1] : array(),
                        "jurnal_index" => $jurnalIndex,
                        "postProcessor" => $jurnalPostProc,
                        "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                        "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                        "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                        //-----
                        "coreBuilder" => isset($coreBuilder) ? $coreBuilder : array(),
                        'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                        'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                        'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                        //-----
                    );
                    $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));

                    //endregion

                    //region nulis paymentSource
                    $stepCode = $this->configUiModul[$connector]["steps"][1]["target"];
                    $paymentSources = $this->CI->config->item("payment_source");

                    if (array_key_exists($stepCode, $paymentSources)) {

                        $payConfigs = $paymentSources[$stepCode];

                        if (sizeof($payConfigs) > 0) {
                            foreach ($payConfigs[1] as $paymentSrcConfig) {

                                $valueSrc = $paymentSrcConfig['valueSrc'];
                                $externSrc = $paymentSrcConfig['externSrc'];
                                $tr->writePaymentSrc($insertID, array(
                                    "jenis" => $connector,
                                    "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                    "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                    "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                    "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                    "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    "label" => $paymentSrcConfig["label"],
                                    "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                    "terbayar" => 0,
                                    "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                    "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                    "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                    "toko_id" => $this->cCodeData[$cCode]["main"]['toko_id'],
                                    "toko_nama" => $this->cCodeData[$cCode]["main"]['toko_nama'],
                                    "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                                    "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                                    "dtime" => date("Y-m-d H:i:s"),
                                    "fulldate" => date("Y-m-d"),
                                    "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                                    "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                                    "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                                    "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                                    "terbayar_valas" => 0,
                                    "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                                    "extern_label2" => (isset($externSrc['extern_label2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_label2']] : "",
                                    "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : 0,
                                    "extern_date2" => (isset($externSrc['extern_date2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_date2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_date2']] : 0,
                                ));
                                cekMerah($this->CI->db->last_query());
                            }
                        }


                    }
                    else {
                        //cekMerah("TIDAK nulis paymentSrc");
                    }
                    //endregion

                    //region nulis paymentAntiSource
                    //                    $stepCode = $connector;
                    $stepCode = $this->configUiModul[$connector]["steps"][1]["target"];
                    $paymentSources = $this->CI->config->item("payment_antiSource");
                    if (array_key_exists($stepCode, $paymentSources)) {

                        $payConfigs = $paymentSources[$stepCode];
                        if (sizeof($payConfigs) > 0) {
                            foreach ($payConfigs as $paymentSrcConfig) {
                                $valueSrc = $paymentSrcConfig['valueSrc'];
                                $externSrc = $paymentSrcConfig['externSrc'];
                                $tr->writePaymentAntiSrc($insertID, array(
                                    "jenis" => $connector,
                                    "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                    "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                    "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                    "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                    "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    "label" => $paymentSrcConfig["label"],
                                    "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                    "terbayar" => 0,
                                    "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                    "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                    "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                    "toko_id" => $this->cCodeData[$cCode]["main"]['tokoID'],
                                    "toko_nama" => $this->cCodeData[$cCode]["main"]["tokoNama"],
                                    "oleh_id" => $this->cCodeData[$cCode]["main"]['olehID'],
                                    "oleh_nama" => $this->cCodeData[$cCode]["main"]['olehName'],
                                    "dtime" => date("Y-m-d H:i:s"),
                                    "fulldate" => date("Y-m-d"),
                                ));
                                //cekMerah($this->CI->db->last_query());
                            }
                        }
                    }
                    else {
                        //cekMerah("TIDAK nulis paymentSrc");
                    }
                    //endregion

                    $outResultLib["sessionDataConnecting"] = $this->cCodeData[$cCode];
                    $outResultLib["tmpNomerNotaConnecting"] = $tmpNomorNota2;
                    $outResultLib["transaksiIdConnecting"] = $insertID;

                }
                else {
                    cekMerah("to be delayed to connect to $connector");
                }
            }
            else {
                //cekKuning("not connecting to any tCode");
            }

            //endregion

            validateAllBalances($tokoID);

            // cekHere( isset($this->cCodeData[$cCode]['free_items']) );
            //mentransaksikan free produk ke server main


        }

        // commit dan log ada di controller
        // pembersih session, redirect, ada di controller

        return $outResultLib;
    }

    //-doFollowup--------------------------
    public function doFollowup()
    {
        $location = "(library " . get_class($this) . ", method " . __FUNCTION__ . ")";
        $this->setterValidate($location);

        $cCode = $this->cCode;
        $transaksiID_reference = $no = $this->transaksiNumber;
        $stepNum = $this->stepNum;
        $stepNumCurrent = $this->stepNumCurrent;


        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $core = isset($this->configCoreMaster[$this->modul][$transaksiMode]) ? $this->configCoreMaster[$this->modul][$transaksiMode] : array();
        $coreRequiredParam = isset($this->configCoreMaster[$this->modul]['requiredParam']) ? $this->configCoreMaster[$this->modul]['requiredParam'] : array();
        $corePreProcParam = isset($this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor']) ? $this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor'] : array();
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["runCoreAkunting"] : false;
        $paramPatchers = $this->CI->config->item('heTransaksi_paramPatchers') != null ? $this->CI->config->item('heTransaksi_paramPatchers') : array();
        $paramForceFillers = $this->CI->config->item('heTransaksi_paramForceFillers') != null ? $this->CI->config->item('heTransaksi_paramForceFillers') : array();
        $componentConfig = isset($componentConfig) ? $componentConfig : array();

        // arrPrint($this->cCodeData[$cCode]);
        // matiHEre("$transaksiMode");
        
        $this->CI->load->library("FieldCalculator");
        $this->CI->load->model("MdlTransaksi");

        $cal = new FieldCalculator();

        $stepNowParameter = array();
        $tr = new MdlTransaksi();
        $tr->addFilter("transaksi.id in (" . implode(",", explode("-", $no)) . ")");
        $tr->addFilter("transaksi.step_number='" . $stepNumCurrent . "'");
        $tr->addFilterJoin("transaksi_data.trash='0'");
        $tmpTr = $tr->lookupJoined()->result();
        if (sizeof($tmpTr) > 0) {
            $this->jenisTr = $tmpTr[0]->jenis_master;
            $cCode = "_TR_" . $this->jenisTr;

            //region session init
            if (!isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = array(
                    "items" => array(),
                    "main" => array(),
                );
            }
            if (!isset($this->cCodeData[$cCode]["main"])) {
                $this->cCodeData[$cCode]["main"] = array();
            }
            if (!isset($this->cCodeData[$cCode]["items"])) {
                $this->cCodeData[$cCode]["items"] = array();
            }
            $this->cCodeData[$cCode]['rsltItems'] = array();
            $this->cCodeData[$cCode]['rsltItems2'] = array();
            //endregion
// arrPrint($this->cCodeData[$cCode]["main"]);
            $tokoID = $this->cCodeData[$cCode]["main"]["tokoID"];
            // matiHEre($tokoID);
            $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
            $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"] : NULL;
            $detailValuesConfig = isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues']) ? $this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] : array();
            $additionalData = isset($this->configUiModul[$this->jenisTr]["addDetailData"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["addDetailData"][$stepNum] : array();
            $additionalDataPriceConf = isset($this->configUiModul[$this->jenisTr]["updatePrice"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["updatePrice"][$stepNum] : false;

            $masterID = $this->cCodeData[$cCode]["main"]["masterID"];
            $topID = $tmpTr[0]->id_top;
            $tmpNomorNota = $tmpTr[0]->nomer;
            $origJenis = $tmpTr[0]->jenis_master;
            $trID = $tmpTr[0]->transaksi_id;


            $totalSteps = sizeof($this->configUiModul[$this->jenisTr]["steps"]);


            //==references, previous entry
            $prevProp = array(
                "id" => $tmpTr[0]->transaksi_id,
                "jenis" => $tmpTr[0]->jenis,
                "nomer" => $tmpTr[0]->nomer,
            );


            //------
            $stepNowParameter = array(
                "next_step_code" => $tmpTr[0]->next_step_code,
                "next_step_label" => $tmpTr[0]->next_step_label,
                "next_group_code" => $tmpTr[0]->next_group_code,
                "next_step_num" => $tmpTr[0]->next_step_num,
                "step_current" => $tmpTr[0]->step_current,
            );


            $tmpVal_main = $tr->lookupMainValuesByTransID($trID)->result();
            $tmpVal_detail = $tr->lookupDetailValuesByTransID($trID)->result();
            $mainValues = array();
            if (sizeof($tmpVal_main) > 0) {
                foreach ($tmpVal_main as $row) {
                    $mainValues[$row->key] = $row->value;
                }
            }
            $detailValues = array();
            if (sizeof($tmpVal_detail) > 0) {
                foreach ($tmpVal_detail as $row) {
                    $detailValues[$row->produk_id][$row->key] = $row->value;
                }
            }


            $main = array();
            $items = array();
            $prevIDs = array();
            $prevNos = array();
            foreach ($tmpTr as $row) {
                $items[$row->produk_id] = array(
                    "id" => $row->produk_id,
                    "nama" => $row->produk_nama,
                    "jml" => $row->produk_ord_jml,
                    "harga" => $row->produk_ord_hrg,
                    "valid_qty" => $row->valid_qty,
                    "transaksi_id" => $row->transaksi_id,
                    "nomer" => $row->nomer,
                );

                if ($row->valid_qty > 0) {
                    cekHitam("ok lanjut");
                }
                else {
                    if (isset($this->cCodeData[$cCode]["items"][$row->produk_id])) {
                        matiHere("Followed up already. Please close and refresh your browser " . $row->produk_nama . " " . $row->produk_id);//kalo session active ya harus dimatiin biar gak dobel
                    }
                }

                if (!in_array($row->transaksi_id, $prevIDs)) {
                    $prevIDs[] = $row->transaksi_id;
                }
                if (!in_array($row->nomer, $prevNos)) {
                    $prevNos[] = $row->nomer;
                }
                if (sizeof($detailValuesConfig) > 0) {
                    cekHere("detail values ada..<br>");
                    foreach ($detailValuesConfig as $key => $src) {
                        echo "$key akan ambil nilai dari $src<br>";

                        if (isset($detailValues[$row->produk_id][$key])) {

                            $items[$row->produk_id][$key] = $detailValues[$row->produk_id][$key];
                        }
                        else {
                            if (isset($row->$key)) {

                                $items[$row->produk_id][$key] = $row->$key;
                            }
                        }
                        echo "dan sekarang nilainya: " . $items[$row->produk_id][$key] . "<br>";
                    }
                }
            }

        }
        else {
            $masterID = 0;
            $tmpNomorNota = "XXXX";
            $origJenis = 0;
            $topID = 0;
            die(lgShowAlert("No such receipt ID: $no!"));
        }


        //region ongkir dll diselipkan ke masterGates
        if (isset($this->configValuesModul[$this->jenisTr]['externalValues']) && sizeof($this->configValuesModul[$this->jenisTr]['externalValues']) > 0) {
            foreach ($this->configValuesModul[$this->jenisTr]['externalValues'] as $exKey => $exSpec) {
                if ($exSpec['useAt'] == $stepNum) {
                    if (isset($exSpec['mdlName']) && strlen($exSpec['mdlName']) > 3) {
                        $this->cCodeData[$cCode]["main"][$exKey . "_src"] = $_POST[$exKey . "_src"];
                        if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey . "_src"])) {
                            $this->cCodeData[$cCode]['main_add_values'][$exKey . "_src"] = $_POST[$exKey . "_src"];
                        }
                    }
                    $this->cCodeData[$cCode]["main"][$exKey] = $_POST[$exKey];
                    if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey])) {
                        $this->cCodeData[$cCode]['main_add_values'][$exKey] = $_POST[$exKey];
                    }

                    if ($exSpec['taxFactor'] > 0) {
                        $this->cCodeData[$cCode]["main"][$exKey . "_tax"] = $_POST[$exKey . "_tax"];
                        if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey . "_tax"])) {
                            $this->cCodeData[$cCode]['main_add_values'][$exKey . "_tax"] = $_POST[$exKey . "_tax"];
                        }
                    }
                }
            }
        }
        //endregion

        //region baca seting optional step
        if (isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField']) && strlen($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField']) > 0) {

            $criteriaField = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField'];
            if (isset($this->cCodeData[$cCode]["main"][$criteriaField]) && $this->cCodeData[$cCode]["main"][$criteriaField] > 0) {
                echo "nextstepnum normal<br>";
                $nextStepNum = ($stepNum + 1);
                $useAdditionalStep = true;
            }
            else {
                echo "nextstepnum hampir normal<br>";
                $useAdditionalStep = false;
                $nextStepNum = ($stepNum + 2);
            }
        }
        else {
            echo "nextstepnum TIDAK normal<br>";
            $useAdditionalStep = false;
            $nextStepNum = ($stepNum + 1);
            echo "yaitu $nextStepNum<br>";
        }
        //endregion

        //region pembulatan replacer disini
        $injectBulat = isset($this->configValuesModul[$this->jenisTr]['valuePembulatan'][$stepNum]) ? $this->configValuesModul[$this->jenisTr]['valuePembulatan'][$stepNum] : array();
        if (sizeof($injectBulat) > 0) {
            echo "<script>top.writeProgress('PEMBULATAN', 'HEAD');</script>";
            $selectedSource = $injectBulat['source'];
            $injectSource = makeDppBulat($this->cCodeData[$cCode]["main"][$selectedSource]);
            foreach ($injectBulat['replacer'] as $k => $fields) {
                $this->cCodeData[$cCode]["main"][$fields] = $injectSource[$k];
                echo "<script>top.writeProgress('PEMBULATAN ($fields)');</script>";
            }
        }
        //endregion

        // region PRE-PROCESSOR

        //region pre-processors (item)
        if (isset($core['preProcessor'][$jenisTrTarget]['detail'])) {
            $iterator = isset($core['preProcessor'][$jenisTrTarget]['detail']) ? $core['preProcessor'][$jenisTrTarget]['detail'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNum]) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNum] : array();
            echo "ITEM NUM LABELS";

            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('PERSIAPAN PRE-PROCESSOR...', 'HEAD');</script>";
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
//                        if (isset($corePreProcParam[$comName]) && ($corePreProcParam[$comName] == true)) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo __LINE__ . " :: sub-preproc: $comName, initializing values <br>";

                    foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                        $tmpOutParams[$cCtr] = array();
                        $id = $xid;
                        $subParams = array();

                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['static'][$key] = $realValue;

                            }

                            if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                                foreach ($paramPatchers[$comName] as $k => $v) {
                                    if (!isset($subParams['static'][$k])) {
                                        $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                    }
                                }
                            }
                            if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                                $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                                foreach ($paramForceFillers[$comName] as $k => $v) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }

                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                        }

                        if (sizeof($subParams) > 0) {
                            $tmpOutParams[$cCtr][] = $subParams;
                        }


                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                        echo "sub preproc #$it: $comName, sending values <br>";

                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);
                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();
                            cekHitam(":: PRE-PROCC -> GOTNAME, ITERATING...");
                            arrprint($gotParams);
                            if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                                foreach ($gotParams as $gateName => $paramSpec) {

                                    if (!isset($this->cCodeData[$cCode][$gateName])) {
                                        $this->cCodeData[$cCode][$gateName] = array();
                                        //                                    cekhijau("building the session: $gateName");
                                    }
                                    else {
                                        //                                    cekhijau("NOT building the session: $gateName");
                                    }

                                    foreach ($paramSpec as $id => $gSpec) {
                                        //                                        $id = $gSpec["id"];
                                        if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            $this->cCodeData[$cCode][$gateName][$id] = array();
                                        }

                                        if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                foreach ($gSpec as $key => $val) {
                                                    $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                }
                                            }
                                        }
                                        //==inject gotParams to child gate
                                        if ($gateName == $srcGateName) {
                                            if (isset($this->cCodeData[$cCode][$srcGateName][$id])) {
                                                if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                    foreach ($gSpec as $key => $val) {
                                                        $this->cCodeData[$cCode][$srcGateName][$id][$key] = $val;
                                                    }
                                                }
                                            }
                                        }

                                        //cekMerah("REBUILDING VALUES..");
                                        if (sizeof($itemNumLabels) > 0) {
                                            //cekHijau("REBUILDING SUBS FOR ITEMS");
                                            foreach ($itemNumLabels as $key => $label) {
                                                //cekHere("$id === $key => $label");
                                                $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                //                                        die();
                                            }
                                        }
                                    }
                                    //                                    arrPrint($this->cCodeData[$cCode][$gateName]);die();
                                }
                            }
                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }
                    }

                    $this->CI->load->helper("he_value_builder");
//                    fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
                    $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);

//                        }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $this->cCodeData[$cCode]["main"]["ppnFactor"], $this->cCodeData[$cCode]);
        }
        else {
            echo("no processor defined. skipping preprocessor..<br>");
        }

        //endregion

        //region pre-processors (master)
        if (isset($core['preProcessor'][$jenisTrTarget]['master'])) {
            $iterator = isset($core['preProcessor'][$jenisTrTarget]['master']) ? $core['preProcessor'][$jenisTrTarget]['master'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();

            echo "ITEM NUM LABELS";
//             arrPrint($iterator);
// matiHEre(__LINE__);
            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('PERSIAPAN PRE-PROCESSOR...', 'HEAD');</script>";
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
//                        if (isset($corePreProcParam[$comName]) && ($corePreProcParam[$comName] == true)) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                    $switchResultParams = isset($tComSpec['switchResultParams']) ? $tComSpec['switchResultParams'] : false;

                    echo "master-preproc: $comName, initializing values <br>";
                    $tmpOutParams[$cCtr] = array();

                    $subParams = array();
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $subParams['static'][$key] = $realValue;
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }

                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }
                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr] = $subParams;
                    }


                    $mdlName = "Pre" . ucfirst($comName);
                    $this->CI->load->model("Preprocs/" . $mdlName);
                    $m = new $mdlName($resultParams);


                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }

                    if ($tobeExecuted) {
                        $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $gotParams = $m->exec();

                        cekbiru("gotparams dari $comName");
                        arrprint($gotParams);

                        if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                            cekhijau("ada gotparam, sekarang mau replace");
                            foreach ($gotParams as $gateName => $gSpec) {

                                if ($switchResultParams == true) {
                                    foreach ($gSpec as $id => $ggSpec) {
                                        if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            $this->cCodeData[$cCode][$gateName][$id] = array();
                                        }
                                        if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            if (is_array($ggSpec) && sizeof($ggSpec) > 0) {
                                                foreach ($ggSpec as $key => $val) {
                                                    $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                }
                                            }
                                        }
                                        //cekMerah("REBUILDING VALUES..");
                                        if (sizeof($itemNumLabels) > 0) {
                                            //cekHijau("REBUILDING SUBS FOR ITEMS");
                                            foreach ($itemNumLabels as $key => $label) {
                                                //cekHere("$id === $key => $label");
                                                if (isset($this->cCodeData[$cCode][$gateName][$id][$key])) {
                                                    $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                }
                                            }
                                        }
                                    }
                                }
                                else {
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                cekbiru("injecting param $key with $val");
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                    //==inject gotParams to child gate
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                }

                            }
                        }
                        else {
                            cekmerah("TIDAK ada gotparam, tidak perlu replace");
                        }

                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }

//                        }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $this->cCodeData[$cCode]["main"]["ppnFactor"], $this->cCodeData[$cCode]);
        }
        else {
            echo("no processor defined. skipping preprocessor..<br>");
        }

        //endregion
        // endregion PRE-PROCESSOR

        //region pre-proc value injector items2 items2_sum dari gerbang main
        $injectValues = isset($core['preInjectValue'][$stepNum]) ? $core['preInjectValue'][$stepNum] : array();
        if (sizeof($injectValues) > 0) {
            $iterator = isset($core['preInjectValue'][$stepNum]['master']) ? $core['preInjectValue'][$stepNum]['master'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                    $tmpOutParams[$cCtr] = array();
                    $subParams = array();

                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $subParams['static'][$key] = $realValue;
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }

                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr] = $subParams;
                    }


                    $mdlName = "Pre" . ucfirst($comName);
                    $this->CI->load->model("Preprocs/" . $mdlName);
                    $m = new $mdlName($resultParams);
                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }

                    if ($tobeExecuted) {
                        $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $gotParams = $m->exec();
                        if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                            foreach ($gotParams as $gateName => $gSpec) {
                                if ($gateName == "main") {
                                    foreach ($gSpec as $key => $val) {
                                        $this->cCodeData[$cCode]["main"][$key] = $val;
                                    }
                                }
                                if ($gateName == "items2") {
                                    foreach ($this->cCodeData[$cCode]["items2"] as $k => $tmpSes) {
                                        foreach ($gSpec as $key => $val) {
                                            foreach ($tmpSes as $y => $sesData) {
                                                if (array_key_exists($key, $sesData)) {
                                                    $this->cCodeData[$cCode]["items2"][$k][$y][$key] = $val;
                                                }
                                            }
                                        }
                                    }
                                }
                                if ($gateName == "items2_sum") {
                                    foreach ($this->cCodeData[$cCode]["items2_sum"] as $k => $tmpSes) {
                                        foreach ($gSpec as $key => $val) {
                                            $this->cCodeData[$cCode]["items2_sum"][$k][$key] = $val;
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            cekmerah("TIDAK ada gotparam, tidak perlu replace");
                        }
                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);
        }
        //endregion

        //region VALIDATOR masih session
        $step = $this->cCodeData[$cCode]["main"]['step_number'];
        $this->CI->load->library("Validator");
        $va = new Validator();
        $va->setConfigUiJenis($this->configUiModul[$this->jenisTr]);
        $va->setCCode($this->cCode);
        $va->setSessionData($this->cCodeData[$cCode]);
        $va->midValidateSessionData($step);
        $va->unionValidateSessionData();
        //endregion

        //region update step2an
        if (isset($this->configUiModul[$this->jenisTr]["steps"][$nextStepNum])) {//===masih ada langkah selanjutnya
            echo "authorizing to next step..<br>";
            $nextProp = array(
                "num" => $nextStepNum,
                "code" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]["target"],
                "label" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]["label"],
                "groupID" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]['userGroup'],
            );
        }
        else {//==ini step terakhir, tulis komponen jika ada
            $nextProp = array(
                "num" => 0,
                "code" => "",
                "label" => "",
                "groupID" => "",
            );
        }
        //endregion

        $dwsign = $tr->writeSignature($masterID, array(
            "nomer" => $tmpNomorNota,
            "step_number" => $stepNum,
            "step_code" => $this->configUiModul[$origJenis]["steps"][$stepNum]["target"],
            "step_name" => $this->configUiModul[$origJenis]["steps"][$stepNum]["label"],
            "group_code" => $this->configUiModul[$origJenis]["steps"][$stepNum]['userGroup'],
            "oleh_id" => my_id(),
            "oleh_nama" => my_name(),
            "keterangan" => $this->configUiModul[$origJenis]["steps"][$stepNum]["label"] . " oleh " . my_name(),
            "transaksi_id" => $masterID,
        )) or die("Failed to write signature");

        //region update step terdahulu
        $tr = new MdlTransaksi();
        $dupState = $tr->updateData(array("id" => $topID), array(
            "next_step_code" => $nextProp["code"],
            "next_step_label" => $nextProp["label"],
            "next_group_code" => $nextProp["groupID"],
            "next_step_num" => $nextProp["num"],
            "step_current" => $stepNum,
            "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,

        )) or die("Failed to update tr next-state!");
//        $mongUpdateList['update']["main"][] = array(
//            "where" => array("id" => "$topID"),
//            "value" => array(
//                "next_step_code" => $nextProp["code"],
//                "next_step_label" => $nextProp["label"],
//                "next_group_code" => $nextProp["groupID"],
//                "next_step_num" => $nextProp["num"],
//                "step_current" => $stepNum,
//            ),
//        );
//        cekHijau($this->CI->db->last_query());

        //-------------------------------------------------
        $tr = new MdlTransaksi();
        $dupState = $tr->updateData(array("id" => $trID), array(
            "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,
        )) or die("Failed to update tr next-state!");
//        $mongUpdateList['update']["main"][] = array(
//            "where" => array("id" => "$trID"),
//            "value" => array(
//                "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,
//            ),
//        );

        //endregion

        //==prepare kloningan
        $tCode = $this->configUiModul[$origJenis]["steps"][$stepNum]["target"];
        $tCodeName = $this->configUiModul[$origJenis]["steps"][$stepNum]["label"];
        $masterReplacers = array(
            "inv" => $tmpNomorNota,
            "jenis" => $tCode,
            "jenis_label" => $tCodeName,
            "transaksi_jenis" => $tCode,
            "cabang_id" => selectedTransactionSession() ? $this->cCodeData[$cCode]["main"]["cabangID"] : my_cabang_id(),
            "cabang_nama" => selectedTransactionSession() ? $this->cCodeData[$cCode]["main"]["cabangName"] : my_cabang_name(),
            "oleh_id" => my_id(),
            "oleh_nama" => my_name(),
            "step_current" => "0",
            "step_number" => $stepNum,
            "next_step_code" => $nextProp["code"],
            "next_step_label" => $nextProp["label"],
            "next_group_code" => $nextProp["groupID"],
            //===references
            "id_master" => $masterID,
            "id_top" => $topID,
            "ids_prev" => base64_encode(serialize($prevIDs)),
            "nomer_top2" => isset($this->cCodeData[$cCode]["main"]["nomer_top2"]) ? $this->cCodeData[$cCode]["main"]["nomer_top2"] : "",
            "nomer_top" => isset($this->cCodeData[$cCode]["tableIn_master"]["nomer_top"]) ? $this->cCodeData[$cCode]["tableIn_master"]["nomer_top"] : "",
            "nomers_prev" => base64_encode(serialize($prevNos)),
            "jenises_prev" => base64_encode(serialize(array($prevProp['jenis']))),
            // "jenises_prev_intext" => print_r(array($prevProp['jenis']), true),
            "tail_number" => $stepNum,
            "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
        );

        foreach ($masterReplacers as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }

        $childTableRepaclers = array(
            "sub_step_number" => $stepNum,
            "sub_step_current" => $stepNum,
            "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
            "next_substep_num" => $nextProp["num"],
            "next_substep_code" => $nextProp["code"],
            "next_substep_label" => $nextProp["label"],
            "next_subgroup_code" => $nextProp["groupID"],
        );
        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
            foreach ($childTableRepaclers as $key => $val) {
                $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
            }
        }

        $masterReplacersO = array(
            "jenisTr" => $tCode,
            "jenisTrName" => $tCodeName,
            "olehID" => my_id(),
            "olehName" => my_name(),
            "stepNumber" => $stepNum,
            "stepCode" => $tCode,
        );
        foreach ($masterReplacersO as $key => $val) {
            $this->cCodeData[$cCode]["main"][$key] = $val;
        }

        //region menimbulkan nilai tagihan
        $unpaidList = null != $this->CI->config->item("tr_unpaidList") ? $this->CI->config->item("tr_unpaidList") : array();
        if (in_array($tCode, $unpaidList)) {
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_tagihan"] = $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai"];
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_terbayar"] = 0;
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_sisa"] = ($this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_tagihan"] - $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_terbayar"]);
        }
        else {
            //cekMerah("TIDAK NULIS TAGIHANN");
        }
        //endregion

//        //region penomoran receipt #1
//        $this->CI->load->model("CustomCounter");
//        $cn = new CustomCounter("transaksi");
//        $cn->setType("transaksi");
//        $counterForNumber = array($this->configValuesModul[$origJenis]["formatNota"]);
//        if (!in_array($counterForNumber[0], $this->configValuesModul[$origJenis]["counters"])) {
//            arrPrint($counterForNumber);
//            matiHere("error line ".__LINE__ . " Used number should be registered in counters config as well");
//        }
//
//        foreach ($counterForNumber as $i => $cRawParams) {
//            $cParams = explode("|", $cRawParams);
//            $cValues = array();
//            foreach ($cParams as $param) {
//                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
//            }
//            $cRawValues = implode("|", $cValues[$i]);
//            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
//        }
//        $tmpNomorNota2 = $paramSpec["paramString"];
//        $tmpNomorNota2Alias = formatNota("nomer_nolink", $tmpNomorNota2);
//        //endregion
//
//        //region dynamic counters #1
//        echo "<script>top.writeProgress('sedang membuat penomoran');</script>";
//
//        $cn = new CustomCounter("transaksi");
//        $cn->setType("transaksi");
//        $configCustomParams = $this->configValuesModul[$origJenis]["counters"];
//        $configCustomParams[] = "stepCode";
//        if (sizeof($configCustomParams) > 0) {
//            $cContent = array();
//            foreach ($configCustomParams as $i => $cRawParams) {
//                $cParams = explode("|", $cRawParams);
//                $cValues = array();
//                foreach ($cParams as $param) {
//                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
//                }
//                $cRawValues = implode("|", $cValues[$i]);
//                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
//
//                $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
//                switch ($paramSpec["id"]) {
//                    case 0: //===counter type is new
//                        $addData = array(
//                            "toko_id" => $tokoID,
//                            "toko_nama" => $tokoNama,
//                        );
//                        $paramKeyRaw = print_r($cParams, true);
//                        $paramValuesRaw = print_r($cValues[$i], true);
//                        $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
//                        break;
//                    default: //===counter to be updated
//                        $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
//                        break;
//                }
//                //echo "<hr>";
//            }
//        }
//        $appliedCounters2 = base64_encode(serialize($cContent));
//        $appliedCounters_inText2 = print_r($cContent, true);


        /*
         * =============
         */

        //region penomoran receipt
        $this->CI->load->model("CustomCounter");
        $cn = new CustomCounter("transaksi");
        $cn->setType("transaksi");
        $configCustomParams = $this->configValuesModul[$origJenis]["counters"];

        if (sizeof($configCustomParams) > 0) {
            $cContent = array();
            foreach ($configCustomParams as $i => $cRawParams) {
                $cParams = explode("|", $cRawParams);
                $cValues = array();
                foreach ($cParams as $param) {
                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                }
                $cRawValues = implode("|", $cValues[$i]);
                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                switch ($paramSpec["id"]) {
                    case 0: //===counter type is new
                        $addData = array(
                            "toko_id" => $tokoID,
                            "toko_nama" => $tokoNama,
                        );
                        $paramKeyRaw = print_r($cParams, true);
                        $paramValuesRaw = print_r($cValues[$i], true);
                        $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                        break;
                    default: //===counter to be updated
                        $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                        break;
                }
            }
        }

        $appliedCounters2 = base64_encode(serialize($cContent));
        $appliedCounters_inText2 = print_r($cContent, true);

        $cn = new CustomCounter("transaksi");
        $cn->setType("transaksi");
        $counterForNumber = array($this->configValuesModul[$origJenis]["formatNota"]);
        foreach ($counterForNumber as $i => $c0RawParams) {
            $c0Params = explode(",", $c0RawParams);
            foreach($c0Params as $k=>$cRawParams){
                $dParams = explode("|", $cRawParams);
                if(count($dParams)>1){
                    if (!in_array($cRawParams, $this->configValuesModul[$origJenis]["counters"])) {
                        die(__LINE__ . "( $cRawParams ) Used number should be registered in counters config as well");
                    }
                }
            }
        }

        $tmpNomorNota2="";
        $arrNomorNota=array();
        foreach ($counterForNumber as $i => $c0RawParams) {
            $c0Params = explode(",", $c0RawParams);
            $c0Values = array();
            foreach($c0Params as $k=>$cRawParams){
                $arrRawParams = explode("|", $cRawParams);
                if(sizeof($arrRawParams)>1){
                    $cRawParamsValues = array();
                    foreach($arrRawParams as $key){
                        $cRawParamsValues[$key] = $this->cCodeData[$cCode]['main'][$key];
                    }
                    $cRawParamsValuesK = implode("|", array_keys($cRawParamsValues));
                    $cRawParamsValuesV = implode("|", $cRawParamsValues);
                    $arrNomorNota[] = digit_4($cContent[$cRawParamsValuesK][$cRawParamsValuesV]);
                }
                else{
                    $cRawParamsValuesK = $arrRawParams[0];
                    $cRawParamsValuesV = $this->cCodeData[$cCode]['main'][$arrRawParams[0]];
                    if($arrRawParams[0]=="fulldate"){
                        $arrNomorNota[] = $arrRawParams[0]."|".date("mY", strtotime($cRawParamsValuesV));
                    }
                    elseif($arrRawParams[0]=="stepCode"){
                        $arrNomorNota[] = $cRawParamsValuesV; //ini harus ori tidak boleh di masking/ diformat
//                            $arrNomorNota[] = digit_4($cContent[$cRawParamsValuesK][$cRawParamsValuesV]);
                    }
                    elseif($arrRawParams[0]=="placeID"){
                        $arrNomorNota[] = digit_2($cRawParamsValuesV);
                    }
                    elseif($arrRawParams[0]=="customerID"){
                        $arrNomorNota[] = digit_4($cRawParamsValuesV);
                    }
                    elseif($arrRawParams[0]=="olehID"){
                        $arrNomorNota[] = digit_4($cRawParamsValuesV);
                    }
                    elseif($arrRawParams[0]=="supplierID"){
                        $arrNomorNota[] = digit_4($cRawParamsValuesV);
                    }
                    else{
                        $arrNomorNota[] = $cRawParamsValuesV;
                    }
                }
            }
        }

        $stepNumber = 1;
        $tmpNomorNota2 = implode("-", $arrNomorNota);
        $tmpNomorNota2Alias = formatNota("nomer_nolink", $tmpNomorNota2);
        //endregion penomoran receipt


        //endregion

        $masterReplacers = array(
            "nomer" => $tmpNomorNota2,
            "nomer2" => $tmpNomorNota2Alias,
            "counters" => $appliedCounters2,
            "counters_intext" => $appliedCounters_inText2,
        );
        foreach ($masterReplacers as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }

        $addValues = array(
            "counters" => $appliedCounters2,
            'counters_intext' => $appliedCounters_inText2,
            'nomer' => $tmpNomorNota2,
            'nomer2' => $tmpNomorNota2Alias,
            'dtime' => date("Y-m-d H:i:s"),
            'fulldate' => date("Y-m-d"),
        );
        // arrPrint($addValues);
        // matiHEre();
        foreach ($addValues as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }
        //endregion

        //region numbering tambahan
        $this->CI->load->library("CounterNumber");
        $ccn = new CounterNumber();
        $ccn->setCCode($this->cCode);
        $ccn->setJenisTr($this->jenisTr);
        $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
        $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
        $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
        $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
        $new_counter = $ccn->getCounterNumber();
        cekHitam("jenistr yang disett dari create " . $this->jenisTr);


        if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
            foreach ($new_counter["main"] as $ckey => $cval) {
                $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                $this->cCodeData[$cCode]["main"][$ckey] = $cval;
            }
        }
        if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
            foreach ($new_counter["items"] as $ikey => $iSpec) {
                foreach ($iSpec as $iikey => $iival) {
                    $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                }
            }
        }
        if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
            foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                foreach ($iSpec as $iikey => $iival) {
                    $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                }
            }
        }
        //endregion

        //region TRANSAKSIONAL
        if (sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
            $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
            $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 0;

            $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
            $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);

            $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
            $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
            if ($insertID < 1) {
                die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
            }


            if (isset($this->cCodeData[$cCode]["tableIn_master"]['ids_his'])) {
                $idHis_decode = blobDecode($this->cCodeData[$cCode]["tableIn_master"]['ids_his']);
                $idHis_decode[$stepNum] = array(
                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                    "step" => $stepNum,
                    "trID" => $insertID,
                    "nomer" => $tmpNomorNota2,
                    "counters" => $appliedCounters2,
                    // "counters_intext" => $appliedCounters_inText2,
                );

                $idHis_blob = blobEncode($idHis_decode);

                $this->cCodeData[$cCode]["tableIn_master"]['ids_his'] = $idHis_blob;

                $tr = new MdlTransaksi();
                $dup = $tr->updateData(array("id" => $insertID), array(
                    "ids_his" => $idHis_blob,
                    // "ids_his_intext" => $idHis_intext,

                )) or die("Failed to update tr next-state!");
                cekUngu($this->CI->db->last_query());
            }
            if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                $inserMainValues = array();

                foreach ($this->cCodeData[$cCode]['tableIn_master_values'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                    $inserMainValues[] = $dd;

                }
                if (sizeof($inserMainValues) > 0) {
                    $arrBlob = blobEncode($inserMainValues);
                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));

                }
            }
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));

                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                    $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                }
            }

            if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                    $tr->writeMainElements($insertID, array(
                        "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                        "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                        "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                        "name" => $aSpec['name'],
                        "label" => $aSpec["label"],
                        "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                        // "contents_intext" => isset($aSpec['contents_intext']) ? print_r($aSpec['contents_intext'], true) : "",

                    ));
                }
            }
            else {
                //                cekMerah("TAK ada mainElements");
            }

            if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                            cekHijau("tableIn_detail: produk_jenis: $pID");
                            cekHijau("insertID: $insertID: $pID");
                            arrPrint($this->cCodeData[$cCode]["tableIn_detail"]);
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                            ));
                            $insertIDs[$pID][] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }
                    }
                }
                if (sizeof($insertIDs) > 0) {
                    $arrBlob = blobEncode($insertIDs);
                    $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                            $insertIDs[] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }
                    }


                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detail_rsltItems'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detail_rsltItems'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail_rsltItems'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                            $insertIDs[$pID][] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }
                    }


                }
            }


            //region update validQty pada step sebelumnya yang di-refer
            $seluruhnya = true;
            $prevTrID = 0;
            $arrvalidQtySisa = array();
            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                $closedRequest = isset($this->configValuesModul[$origJenis]['closedRequest'][$stepNum]['enabled']) ? $this->configValuesModul[$origJenis]['closedRequest'][$stepNum]['enabled'] : false;
                $insertIDs = array();
                $insertDeIDs = array();
                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $iID => $dSpec) {
                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                    if ($insertDetailID < 1) {
                        die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                    }
                    else {
                        $insertIDs[] = $insertDetailID;
                        $insertDeIDs[$insertID][] = $insertDetailID;
                        //$mongoList['detail'][] = $insertDetailID;

                    }

                    if ($epID != 999) {
                        $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                        if ($insertEpID < 1) {
                            die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                        }
                        else {
                            $insertIDs[] = $insertEpID;
                            $insertDeIDs[$epID][] = $insertEpID;
                            //$mongoList['detail'][] = $insertDetailID;
                        }
                    }
                    cekHitam("EXTRACTED ITEMS... [$iID]");
                    echo "<script>top.writeProgress('" . strtoupper($dSpec['produk_nama']) . "');</script>";


                    if (isset($this->cCodeData[$cCode]['extractedItems'])) {
                        if (array_key_exists($iID, $this->cCodeData[$cCode]['extractedItems'])) {
                            $itemFulfilledJml = 0;
                            foreach ($this->cCodeData[$cCode]['extractedItems'][$iID] as $triID => $triSpec) {
                                $prevTrID = $triSpec['transaksi_id'];
                                $tru = new MdlTransaksi();
                                $tru->setFilters(array());
                                $tru->setTableName($tru->getTableNames()['detail']);
                                //----------------------------------------------------------
                                if ($triSpec['valid_qty'] >= $dSpec['produk_ord_jml']) {
                                    $newValidQty = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                    //                                    cekmerah("validQty dikurangi oleh produk_ord_jml, yaitu " . $dSpec['produk_ord_jml']);
                                }
                                else {
                                    $newValidQty = ($triSpec['valid_qty'] - $triSpec['valid_qty']);
                                    //                                    cekmerah("validQty dikurangi oleh triSpec,  myaitu " . $triSpec['valid_qty']);
                                }
                                //----------------------------------------------------------
                                $newValidQtyNotApprove = 0;
                                if ($closedRequest == true) {
                                    cekPink2("closed Request enabled, request: " . $triSpec['valid_qty'] . ", approve: " . $dSpec['produk_ord_jml'] . ", newValidQty: " . $newValidQty);
                                    if ($triSpec['valid_qty'] >= $dSpec['produk_ord_jml']) {
                                        $newValidQty = 0;
                                        $newValidQtyNotApprove = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);

                                    }
                                    //                                    else{
                                    //                                        $newValidQty = 0;
                                    //                                        $newValidQtyNotApprove = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                    //                                    }
                                    cekPink2("new valid qty: $newValidQty, valid qty not approve: $newValidQtyNotApprove");
                                }
                                //----------------------------------------------------------


                                $itemFulfilledJml += $newValidQty;
                                //                                $newValidQty = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                $updateContents = array(
                                    "valid_qty" => $newValidQty,
                                );
                                if ($newValidQty < 1) {
                                    $childPrevRepaclers = array(
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                        "sub_tail_number" => $stepNum,
                                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                                    );
                                    foreach ($childPrevRepaclers as $key => $val) {
                                        $updateContents[$key] = $val;
                                    }
                                }
                                else {//==kalau ada yang tidak habis, berarti TIDAK seluruhnya yang dilanjutkan pada step berikutnya
                                    $seluruhnya = false;
                                    $arrvalidQtySisa[$iID] = $newValidQty;
                                }
                                $dupState = $tru->updateData(array(
                                    "produk_id" => $iID,
                                    "id" => $triID,
                                    "transaksi_id" => $triSpec['transaksi_id'],
                                ), $updateContents) or die("Failed to update previous detail entries!");
                                cekHijau($this->CI->db->last_query());

                                $mongUpdateList['update']['detail'][] = array(
                                    "where" => array(
                                        //                                        "transaksi_id" => $triSpec['transaksi_id'],
                                        "id" => "$triID",
                                        //                                        "produk_id" => $iID,
                                    ),
                                    "value" => $updateContents,
                                );
                                unset($tru);
                            }
                        }
                        //                        else{
                        //                            if($closedRequest == true){
                        //
                        //                            }
                        //                        }
                    }
                }

                if ($closedRequest == true) {
                    if (isset($this->cCodeData[$cCode]['extractedItems'])) {
                        foreach ($this->cCodeData[$cCode]['extractedItems'] as $iIDex => $exSpec) {
                            if (!array_key_exists($iIDex, $this->cCodeData[$cCode]["tableIn_detail"])) {
                                foreach ($exSpec as $trDataID => $trdSpec) {
                                    $tru = new MdlTransaksi();
                                    $tru->setFilters(array());
                                    $tru->setTableName($tru->getTableNames()['detail']);
                                    $updateContents = array(
                                        "valid_qty" => 0,
                                        "valid_qty_no_approve" => $trdSpec['qty'],
                                    );
                                    $childPrevRepaclers = array(
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                        "sub_tail_number" => $stepNum,
                                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                                    );
                                    foreach ($childPrevRepaclers as $key => $val) {
                                        $updateContents[$key] = $val;
                                    }
                                    $dupState = $tru->updateData(array(
                                        "produk_id" => $iIDex,
                                        "id" => $trDataID,
                                        "transaksi_id" => $trdSpec['transaksi_id'],
                                    ), $updateContents) or die("Failed to update previous detail entries!");
                                    //                                    cekHijau($this->CI->db->last_query());
                                    $mongUpdateList['update']['detail'][] = array(
                                        "where" => array(
                                            //                                            "transaksi_id" => $trdSpec['transaksi_id'],
                                            "id" => "$trDataID",
                                            //                                            "produk_id" => $iIDex,
                                        ),
                                        "value" => $updateContents,
                                    );
                                    unset($tru);
                                }
                            }
                        }
                    }
                }
                if (sizeof($insertIDs) == 0) {
                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                }
                else {
                    $indexing_details = array();
                    foreach ($insertDeIDs as $key => $numb) {
                        $indexing_details[$key] = $numb;
                    }
                    foreach ($indexing_details as $k => $arrID) {
                        arrPrint($arrID);
                        $arrBlob = blobEncode($arrID);
                        $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                        cekOrange($this->CI->db->last_query());
                    }
                }

                //-------------
                $lastStepPartialApprove = isset($this->configUiModul[$this->jenisTr]['lastStepPartialApprove']) ? $this->configUiModul[$this->jenisTr]['lastStepPartialApprove'] : false;
                if ($lastStepPartialApprove == true) {
                    cekKuning(__LINE__ . " $lastStepPartialApprove :: $totalSteps");
                    if ($totalSteps == 2) {
                        if (sizeof($arrvalidQtySisa) > 0) {
                            cekPink("ada valid qty yang tersisa");
                            $tr = new MdlTransaksi();
                            $dupState = $tr->updateData(array("id" => $topID), $stepNowParameter) or die("Failed to update tr next-state!");
                            cekHitam(__LINE__ . " ## 2 step, dan step akhir partial, YESS...");
                            showLast_query("orange");
                        }
                    }
                }
            }
            else {
                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
            }

            if ($seluruhnya) {
                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array("id" => $prevTrID), array(
                    "tail_number" => $stepNum,
                    "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                    "status_4" => $this->cCodeData[$cCode]["main"]['status_4'],
                    "trash_4" => $this->cCodeData[$cCode]["main"]['trash_4'],
                )) or die("Failed to update tr next-state!");
                cekHijau(":: UOPDATE transaksi dengan trID -> $prevTrID");
                $mongUpdateList['update']["main"][] = array(
                    "where" => array(
                        "id" => "$prevTrID",
                    ),
                    "value" => array(
                        "tail_number" => $stepNum,
                        "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                        "status_4" => $this->cCodeData[$cCode]["main"]['status_4'],
                        "trash_4" => $this->cCodeData[$cCode]["main"]['trash_4'],
                    ),
                );
                cekHijau($this->CI->db->last_query());
            }
            //endregion

            //region cloner items to item_child
            if (sizeof($additionalData) > 0) {
                echo "<script>top.writeProgress('CLONING ITEMS TO ITEM CHILD...','head');</script>";
                cekHitam("ini data");
                $dataMdl = $additionalData["mdlName"];
                $this->CI->load->model("Mdls/" . $dataMdl);
                $da = new $dataMdl();
                $arrColl = $da->getFields();
                $selectedCol = array();
                foreach ($arrColl as $colSpec) {
                    $selectedCol[] = $colSpec['kolom'];
                }

                if (isset($this->cCodeData[$cCode]['items_child']) && sizeof($this->cCodeData[$cCode]['items_child'])) {
                    $gateData = isset($this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['gate']) ? $this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['gate'] : "detail";

                    $arrBlacklist = array(
                        "jml", "max_jml", "qty",
                    );
                    if (isset($this->cCodeData[$cCode]["items2_sum"])) {
                        unset($this->cCodeData[$cCode]["items2_sum"]);
                        unset($this->cCodeData[$cCode]["items2"]);
                        unset($this->cCodeData[$cCode]["tableIn_detail_values2_sum"]);
                    }
                    foreach ($this->cCodeData[$cCode]['items_child'] as $mainProdsID => $defData) {
                        if ($gateData == "detail") {
                            $itemsMain = isset($this->cCodeData[$cCode]["items"][$mainProdsID]) ? $this->cCodeData[$cCode]["items"][$mainProdsID] : array();
                        }
                        else {
                            $forceMainToItems = isset($this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['changeToItems'][$gateData]) ? $this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['changeToItems'][$gateData] : array();
                            if (sizeof($forceMainToItems) > 0) {
                                foreach ($forceMainToItems as $key1 => $key2) {
                                    $keyForce = strlen($key2) > 2 ? $key2 : $key1;
                                    $itemsMain[$key1] = isset($this->cCodeData[$cCode]["main"][$keyForce]) ? $this->cCodeData[$cCode]["main"][$keyForce] : "";
                                }
                                $itemsMain["jml"] = "1";
                                $itemsMain["qty"] = "1";
                                $itemsMain["max_jml"] = "1";
                            }
                            else {
                                matiHEre("detil aset gagal di tulis!");
                            }

                        }

                        $arrChilds = array_diff_key($itemsMain, array_flip($arrBlacklist));

                        $arrNew = array();
                        if (sizeof($itemsMain) > 0) {
                            foreach ($defData as $inID => $detil_child) {
                                $paramDetil = array_replace($arrChilds, $detil_child);
                                if (array_key_exists("id", $paramDetil)) {
                                    $paramDetil["parent_id"] = $paramDetil["id"];
                                    if (!isset($paramDetil["folders"]) || $paramDetil["folders"] == 0) {
                                        $paramDetil["folders"] = $paramDetil["pihakMainId"];
                                        $paramDetil["keterangan"] = $paramDetil["pihakMainName"];
                                    }
                                    unset($paramDetil["id"]);
                                }
                                $tmpData = array();
                                foreach ($selectedCol as $i => $coloum) {
                                    if (isset($paramDetil[$coloum])) {
                                        $tmpData[$coloum] = $paramDetil[$coloum];
                                    }
                                }

                                if (isset($paramDetil["subtotal"])) {
                                    $paramDetil["subtotal"] = $paramDetil["jml"] * $paramDetil["harga"];
                                }

                                $insertDataID = $da->addData($tmpData, $da->getTableName()) or die(lgShowError("Gagal menulis pengajuan data", __FILE__));

                                $paramDetil["id"] = $insertDataID;
                                echo "<script>top.writeProgress('PENGAJUAN DATA (TRID:$insertDataID)');</script>";
                                $this->cCodeData[$cCode]["items2_sum"][$insertDataID] = $paramDetil;
                                $this->cCodeData[$cCode]["items2"][$mainProdsID][$insertDataID] = $paramDetil;
                            }
                        }
                    }
                }
            }

            //endregion

            //region updater price
            if ($additionalDataPriceConf) {
                if (isset($this->cCodeData[$cCode]['itemPrice']) && sizeof($this->cCodeData[$cCode]['itemPrice']) > 0) {
                    $dComsName = isset($this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['DComs']) ? $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['DComs'] : "";
                    $replacerFields = isset($this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['fieldReplacer']) ? $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['fieldReplacer'] : array();

                    if (sizeof($replacerFields) > 0) {
                        foreach ($this->cCodeData[$cCode]['itemPrice'] as $Cid => $cData) {
                            foreach ($cData as $pID => $tmpField) {
                                foreach ($tmpField as $field => $value) {
                                    if (isset($replacerFields[$field])) {
                                        $source = $replacerFields[$field];
                                        $valReplacer = $this->cCodeData[$cCode]["items"][$pID][$source];
//                                        cekLime("replace $field $value => $valReplacer");
                                        $this->cCodeData[$cCode]['itemPrice'][$Cid][$pID][$field] = $valReplacer;
                                    }
                                }

                                //arrPrint($tmpField);
                            }
                        }
                    }

                    $this->CI->load->model("DComs/" . $dComsName);
                    echo "sub-postProcessor: $dComsName, sending values <br>";
                    $d = new $dComsName();

                    $d->pair($this->cCodeData[$cCode]['itemPrice']) or die("Tidak berhasil memasang  values pada dcoms-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $d->exec() or die("Gagal saat berusaha  exec values pada DComs: $dComsName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
            }

            //endregion


            if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $iID => $dSpec) {
                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $dd;

                    if ($epID != 999) {
                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                        $insertIDs[] = $dd;

                    }
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $iID => $dSpec) {
                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $dd;

                    if ($epID != 999) {
                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                        $insertIDs[] = $dd;

                    }

                }
            }


            if (isset($this->configUiModul[$this->jenisTr]['updateDueDate'][$stepNum])) {
                $dueDateConf = $this->configUiModul[$this->jenisTr]['updateDueDate'][$stepNum];
                $sourceDue = $dueDateConf['source'];
                $targetDue = $dueDateConf["target"];
                $datenow = date("Y-m-d");
                foreach ($sourceDue as $key => $val) {
                    $indexVal = isset($this->cCodeData[$cCode]['main_elements'][$key][$val]) ? $this->cCodeData[$cCode]['main_elements'][$key][$val] : 14;
                    $dueDate = dueDate($datenow, $indexVal);
                }
                $fieldDue = $tr->getFields()["dueDate"];
                $dataDue = array();
                foreach ($fieldDue as $kol) {
                    if (isset($this->cCodeData[$cCode]["tableIn_master"][$kol])) {
                        $dataDue[$kol] = $this->cCodeData[$cCode]["tableIn_master"][$kol];
                    }
                }
                $dataDue['due_date'] = $dueDate;
                $validateDue = validateDueDate($this->cCodeData[$cCode]["main"]['customerID'], $this->cCodeData[$cCode]["main"]['dtime']);


                if ($validateDue['allow_create'] == "true") {
                    if (isset($this->cCodeData[$cCode]["main"]['piutang_dagang']) && $this->cCodeData[$cCode]["main"]['piutang_dagang'] > 0) {

                        $tr->writeDueDate($insertID, $dataDue);

                    }
                }
                else {
                    $allowedOver = validateOverDue($this->cCodeData[$cCode]["main"]['customerID']);
                    if ($allowedOver['status'] == "allowed") {

                    }
                    else {
                        //                        matiHere($validateDue['error']);//matiin transaksi sudah over due
                    }
                    //                    arrPrint()
                    //                    matiHere($validateDue['error']);//matiin transaksi sudah over due
                }

                //update main elementnya
                foreach ($targetDue as $keyTarget => $valTarget) {
                    cekHItam($keyTarget . "[$valTarget] => " . $dueDate);
                    $this->cCodeData[$cCode]['main_elements'][$keyTarget][$valTarget] = $dueDate;
                    $this->cCodeData[$cCode]["main"]['dueDate'] = $dueDate;
                }
            }


            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget])) {
                $coreBuilder = $this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget];
            }
            else {
                $coreBuilder = array();
            }
            //------------

            $baseRegistries = array(
                "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                'items_noapprove' => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),

                'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),

                "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNum] : array(),
                "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][$stepNum] : array(),
                "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][$stepNum] : array(),
                "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][$stepNum] : array(),
                "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][$stepNum] : array(),
                "jurnal_index" => isset($core['components']) ? $core['components'] : array(),
                "preProcessor" => isset($core['preProcessor'][$jenisTrTarget]) ? $core['preProcessor'][$jenisTrTarget] : array(),
                "postProcessor" => isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget] : array(),
                "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                "requiredParam" => (isset($coreRequiredParam[$this->jenisTr]) && sizeof($coreRequiredParam[$this->jenisTr]) > 0) ? $coreRequiredParam[$this->jenisTr] : array(),
                "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                //-----
                "coreBuilder" => $coreBuilder,
                'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                //-----
            );

            $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
            $mongRegID = $doWriteReg;
            echo "<script>top.writeProgress('MENULIS KE-REGISTRY....');</script>";
        }
        else {
            die(lgShowAlert("Transaksi gagal disimpan, silahkan cek kembali transaksi ini."));
        }
        //endregion
        // region POST-PROCESSOR

        //region processing sub-post-processors, always
        $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail'] : array();
        if (sizeof($iterator) > 0) {
            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "sub-postProcessor: $comName, initializing values <br>";
                echo "<script>top.writeProgress('MENYIAPKAN DATA SUB-PROCESSORS UNTUK DIKIRIM...', 'head');</script>";

                $tmpOutParams[$cCtr] = array();
                foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                    $subParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                            $subParams['loop'][$key] = $realValue;
                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                            $subParams['static'][$key] = $realValue;
                            cekBiru("$key diisi dengan $realValue");
                        }

                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                cekorange(":: $k diisikan dengan " . $subParams['static'][$k]);
                            }
                        }

                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }

                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr][] = $subParams;
                    }
                }
            }

            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "sub-postProcessor: $comName, sending values <br>";

                $mdlName = "Com" . ucfirst($comName);
                $this->CI->load->model("Coms/" . $mdlName);
                $m = new $mdlName();

                $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                showLast_query("lime");
            }
        }
        //endregion

        //region processing main-post-processors, always
        $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master'] : array();
        // arrPrintWebs($iterator);
        if (sizeof($iterator) > 0) {
            echo "<script>top.writeProgress('MEMPROSES MAIN-PROCESSORS...', 'head');</script>";
            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "post-processor: $comName<br>";

                $dSpec = $this->cCodeData[$cCode][$srcGateName];
                $tmpOutParams = array();
                if (isset($tComSpec['loop'])) {
                    foreach ($tComSpec['loop'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                        $tmpOutParams['loop'][$key] = $realValue;

                    }
                }
                if (isset($tComSpec['static'])) {
                    //cekHere("DISINI OIII");
                    foreach ($tComSpec['static'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                        $tmpOutParams['static'][$key] = $realValue;

                    }
                    if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                        foreach ($paramPatchers[$comName] as $k => $v) {
                            if (!isset($tmpOutParams['static'][$k])) {
                                $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                    }
                    if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                        $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                        foreach ($paramForceFillers[$comName] as $k => $v) {
                            $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
                        }
                    }
                    $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                    $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                    $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                }
                if (isset($tComSpec['static2'])) {
                    //cekHere("DISINI OIII");
                    foreach ($tComSpec['static2'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                        $tmpOutParams['static2'][$key] = $realValue;

                    }
                    if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                        foreach ($paramPatchers[$comName] as $k => $v) {
                            if (!isset($subParams['static'][$k])) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                    }
                    if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                        $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                        foreach ($paramForceFillers[$comName] as $k => $v) {
                            $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                        }
                    }
                    $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                    $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                    $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                }


                $mdlName = "Com" . ucfirst($comName);
                $this->CI->load->model("Coms/" . $mdlName);
                $m = new $mdlName();

                $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
            }
        }
        //endregion

        // COMPONENT
        if ($runCoreAkunting == true) {
            //region ----------subcomponents GESER KE CLI
            $iterator = isset($core['components']['detail']) ? $core['components']['detail'] : array();
            $componentConfig['detail'] = $iterator;
            if (sizeof($iterator) > 0) {
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                $filterNeeded = false;
                if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                    $filterNeeded = true;
                }
                foreach ($iterator as $cCtr => $tComSpec) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];

                    echo "sub-component: $comName, $srcGateName, initializing values <br>";
                    $tmpOutParams[$cCtr] = array();
                    foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                        $comName = $tComSpec['comName'];
                        if (substr($comName, 0, 1) == "{") {
                            $comName = trim($comName, "{");
                            $comName = trim($comName, "}");
                            $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                            $tComSpec['comName'] = $comName;
                            $iterator[$cCtr]['comName'] = $comName;
                        }

                        $filterNeeded = false;
                        $mdlName = "Com" . ucfirst($comName);
                        if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                            $filterNeeded = true;
                        }


                        $subParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {
                                if (substr($key, 0, 1) == "{") {
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$id][$key], $key);
                                }
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['loop'][$key] = $realValue;
                                cekKuning("LOOP: $key diisi dengan $realValue");

                                if ($filterNeeded) {
                                    if ($subParams['loop'][$key] == 0) {
                                        unset($subParams['loop'][$key]);
                                    }
                                }
                            }
                        }
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['static'][$key] = $realValue;
//                                cekKuning("STATIC: $key diisi dengan $realValue");
                            }
                            if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                                foreach ($paramPatchers[$comName] as $k => $v) {
                                    if (!isset($subParams['static'][$k])) {
                                        $subParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                        cekOrange("fill :: $comName :: $k => " . $subParams['static'][$k]);
                                    }
                                }
                            }
                            if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                                //                            cekOrange("comName:: $comName");
                                $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                                foreach ($paramForceFillers[$comName] as $k => $v) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                    cekOrange("fillforce :: $comName :: $k => " . $subParams['static'][$k]);
                                }
                            }
                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                        }
//                        cekHitam("cetak subParams");
//                        arrPrint($subParams);
                        if (sizeof($subParams) > 0) {
                            if ($filterNeeded) {
                                if (isset($subParams['loop']) && sizeof($subParams['loop']) > 0) {
                                    $tmpOutParams[$cCtr][] = $subParams;
                                }
                            }
                            else {
                                $tmpOutParams[$cCtr][] = $subParams;
                            }
                        }
                    }
                    $componentGate['detail'][$cCtr] = $subParams;
                }


                $it = 0;
                foreach ($iterator as $cCtr => $tComSpec) {
                    $it++;
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];

                    echo "sub component #$it: $comName, sending values <br>";

                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();


                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }


                    if ($tobeExecuted) {
                        //----- kiriman gerbang
                        if (method_exists($m, "setTableInMaster")) {
                            $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                        }
                        if (method_exists($m, "setDetail")) {
                            $m->setDetail($this->cCodeData[$cCode][$srcGateName]);
                        }
                        if (method_exists($m, "setJenisTr")) {
                            $m->setJenisTr($this->jenisTr);
                        }
                        //----- kiriman gerbang
                        $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        showLast_query("lime");
                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }
                }
            }
            else {
                //cekKuning("subcomponents is not set");
            }
            //endregion

            //region ----------components
            $componentGate['master'] = array();
            $componentConfig['master'] = array();
            if (isset($core['relativeComponets']) && $core['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal'][$stepNum]['master']) ? $this->cCodeData[$cCode]['revert']['jurnal'][$stepNum]['master'] : array();
            }
            else {
                if (isset($this->cCodeData[$cCode]['componentsBuilder'][$stepNum]['master'])) {
                    // matiHEre(__LINE__);
                    $iterator = $this->cCodeData[$cCode]['componentsBuilder'][$stepNum]['master'];
                }
                elseif (isset($core['components']['master'])) {
                    // matiHere(__LINE__);
                    $iterator = $core['components']['master'];
                }
                else {
                    // arrPrint($core);
                    $iterator = array();
                }
            }

            // arrPrint($core);
            // arrPrint($core['components']['master']);
            // matiHere(__LINE__);
            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('KOMPONEN...', 'head');</script>";
                $componentConfig['master'] = $iterator;

                $it = 0;
                //==filter nilai, jika NOL tidak dikirim, sesuai config==
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                foreach ($iterator as $cCtr => $tComSpec) {
                    $it++;
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo "component #$it: $comName :: $srcGateName <br>";

                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                    $tmpOutParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {
                            if (substr($key, 0, 1) == "{") {
                                $key = trim($key, "{");
                                $key = trim($key, "}");
                                $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$key], $key);
                            }
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            if ($key != null) {
                                $tmpOutParams['loop'][$key] = $realValue;
                            }
                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static'][$key] = $realValue;
//                            cekHijau(":: NORMAL :: $key => $realValue ::");
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
//                            cekHijau(":: masuk ke PATCHER ::");
                            foreach ($paramPatchers[$comName] as $k => $v) {
//                                cekHijau(":: ada yang mau di-PATCHER ::");
//                                arrPrint($tmpOutParams['static']);
                                if (!isset($tmpOutParams['static'][$k])) {
                                    $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                    cekHijau(":: PATCHER :: $key => $realValue ::");
                                }

                            }
                        }
                        else {
                            cekMerah(":: TIDAK TERMASUK PATCHER ::");
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                cekHijau(":: FORCEFILL :: $key => $realValue ::");
                            }
                        }
                        $tmpOutParams['static']["urut"] = $cCtr;
                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }
                    if (isset($tComSpec['static2'])) {
                        foreach ($tComSpec['static2'] as $key => $value) {

                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static2'][$key] = $realValue;

                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                    }

                    //lgShowError("Ada kesalahan",);
                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();

                    //===filter value nol, jika harus difilter
                    $tobeExecuted = true;

                    if (in_array($mdlName, $compValidators)) {

                        $loopParams = isset($tmpOutParams['loop']) ? $tmpOutParams['loop'] : array();
                        if (sizeof($loopParams) > 0) {
                            foreach ($loopParams as $key => $val) {
                                cekmerah("$comName : $key = $val ");
                                if ($val == 0) {
                                    unset($tmpOutParams['loop'][$key]);
                                }
                            }
                        }
                        if (sizeof($tmpOutParams['loop']) < 1) {
                            $tobeExecuted = false;
                        }

                    }


                    if ($tobeExecuted) {
//                        cekBiru("kiriman komponen $comName");
//                        arrPrint($tmpOutParams);
                        //----- kiriman gerbang untuk counter mutasi rekening
                        if (method_exists($m, "setTableInMaster")) {
                            $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                        }
                        if (method_exists($m, "setMain")) {
                            $m->setMain($this->cCodeData[$cCode]["main"]);
                        }
                        if (method_exists($m, "setJenisTr")) {
                            $m->setJenisTr($this->jenisTr);
                        }
                        //----- kiriman gerbang untuk counter mutasi rekening
                        $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    }
                    else {
                        cekBiru("komponem $comName tidak memenuhi syarat untuk ditulis");
                    }

                    $componentGate['master'][$cCtr] = $tmpOutParams;
                }
            }
            else {
                //cekKuning("components is not set");
            }

            //endregion
        }
        // matiHere(__LINE__);

        //region nulis paymentSource
        $stepCode = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"];
        $paymentSources = $this->CI->config->item("payment_source");

        if (array_key_exists($stepCode, $paymentSources)) {
            $payConfigs = isset($paymentSources[$stepCode][$stepNum]) ? $paymentSources[$stepCode][$stepNum] : array();
            if (sizeof($payConfigs) > 0) {
                foreach ($payConfigs as $paymentSrcConfig) {
                    $valueSrc = $paymentSrcConfig['valueSrc'];
                    $externSrc = $paymentSrcConfig['externSrc'];
                    if (isset($paymentSrcConfig['model'])) {
                        $mdlName = $paymentSrcConfig['model'];
                        $this->CI->load->model("Mdls/$mdlName");
                        $pMdl = New $mdlName();
                        $pTmpMdl = $pMdl->lookupAll()->result();
                        $pTmpMdlResult = array();
                        if (sizeof($pTmpMdl) > 0) {
                            foreach ($pTmpMdl as $pTmpMdlSpec) {
                                $pTmpMdlResult[$pTmpMdlSpec->id] = $pTmpMdlSpec;
                            }
                        }
                    }
                    else {
                        $pTmpMdlResult = array();
                    }

                    if (isset($this->cCodeData[$cCode]["main"][$valueSrc]) && $this->cCodeData[$cCode]["main"][$valueSrc] > 0) {
                        if (isset($externSrc['extern_label2'])) {
                            //cek ada isinya atau kosong
                            $cek = strlen($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']]) > 4 ? "" : matiHere("jenis biaya tidak dikenali " . __LINE__);//
                        }
                        $arrPymSrc = array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => isset($this->cCodeData[$cCode]["main"][$externSrc["id"]]) ? $this->cCodeData[$cCode]["main"][$externSrc["id"]] : "",
                            "extern_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['nama']]) ? $this->cCodeData[$cCode]["main"][$externSrc['nama']] : "",
                            "nomer" => $tmpNomorNota2,
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "terbayar" => 0,
                            "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "toko_id" => my_toko_id(),
                            "toko_nama" => my_toko_nama(),
                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id" => isset($externSrc['valasId']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama" => isset($externSrc['valasLabel']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai" => isset($externSrc['valasValue']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                            "tagihan_valas" => isset($externSrc['valasTagihan']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                            "terbayar_valas" => 0,
                            "sisa_valas" => isset($externSrc['valasSisa']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                            //                            "extern_label2" => isset($this->cCodeData[$cCode]["main"]['pihakMainName']) ? $this->cCodeData[$cCode]["main"]['pihakMainName'] : "",
                            "extern_label2" => (isset($externSrc['extern_label2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_label2']] : "",

                            "ppn" => (isset($externSrc['ppn']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn']] : "",
                            "ppn_approved" => (isset($externSrc['ppn_approved']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn_approved']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn_approved']] : 0,
                            "ppn_sisa" => (isset($externSrc['ppn']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn']] : "",
                            "ppn_status" => (isset($externSrc['ppn_status'])) ? $externSrc['ppn_status'] : 0,
                            "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : 0,
                            "extern_date2" => (isset($externSrc['extern_date2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_date2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_date2']] : "",
                            "pph_23" => (isset($externSrc['pph_23']) && ($this->cCodeData[$cCode]["main"][$externSrc['pph_23']])) ? $this->cCodeData[$cCode]["main"][$externSrc['pph_23']] : "",

                            "npwp" => (isset($externSrc['npwp']) && ($this->cCodeData[$cCode]["main"][$externSrc['npwp']])) ? $this->cCodeData[$cCode]["main"][$externSrc['npwp']] : "",
                            "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                            "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                            "ppn_pph_faktor" => (isset($externSrc['ppn_pph_faktor']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn_pph_faktor']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn_pph_faktor']] : "",
                            "extern_jenis" => (isset($externSrc['extern_jenis']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_jenis']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_jenis']] : "",
                            "extern_nilai3" => (isset($externSrc['extern_nilai3']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai3']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai3']] : "",
                            "extern_nilai4" => (isset($externSrc['extern_nilai4']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai4']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai4']] : "",
                            "extern_nilai5" => (isset($externSrc['extern_nilai5']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai5']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai5']] : "",

                            //                            "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : "",
                            "payment_locked" => (isset($externSrc['payment_locked']) && ($this->cCodeData[$cCode]["main"][$externSrc['payment_locked']])) ? $this->cCodeData[$cCode]["main"][$externSrc['payment_locked']] : 0,
                            "cash_account" => (isset($externSrc['cash_account']) && ($this->cCodeData[$cCode]["main"][$externSrc['cash_account']])) ? $this->cCodeData[$cCode]["main"][$externSrc['cash_account']] : 0,
                            "cash_account_nama" => (isset($externSrc['cash_account_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['cash_account_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['cash_account_nama']] : 0,
                            "seller_id" => (isset($externSrc['seller_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_id']] : "",
                            "seller_nama" => (isset($externSrc['seller_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_nama']] : "",
                            "suppliers_id" => (isset($externSrc['suppliers_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['suppliers_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['suppliers_id']] : "",
                            "suppliers_nama" => (isset($externSrc['suppliers_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['suppliers_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['suppliers_nama']] : "",
                            "dpp_ppn" => (isset($externSrc['dpp_ppn']) && ($this->cCodeData[$cCode]["main"][$externSrc['dpp_ppn']])) ? $this->cCodeData[$cCode]["main"][$externSrc['dpp_ppn']] : "",
                            "keterangan" => (isset($externSrc['keterangan']) && ($this->cCodeData[$cCode]["main"][$externSrc['keterangan']])) ? $this->cCodeData[$cCode]["main"][$externSrc['keterangan']] : "",

                        );
                        // arrPrintWebs($arrPymSrc);
                        $tr->writePaymentSrc($insertID, $arrPymSrc);

                    }


                    cekMerah($this->CI->db->last_query());
                }
            }
        }
        else {
            cekMerah("TIDAK nulis paymentSrc");
        }

        //cek additional step
        $addPaymentSource = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['additionalStep']['shippingService']) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]['additionalStep']['shippingService'] : array();
        //endregion

        //region nulis paymentAntiSource
        $stepCode = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"];
        $paymentSources = $this->CI->config->item("payment_antiSource");
        if (array_key_exists($stepCode, $paymentSources)) {
            cekMerah(":: starting PAYMENT ANTI SOURCE");
            $payConfigs = $paymentSources[$stepCode];
            if (sizeof($payConfigs) > 0) {
                foreach ($payConfigs as $paymentSrcConfig) {
                    //					$paymentSrcConfig = $paymentSources[$stepCode];
                    $valueSrc = $paymentSrcConfig['valueSrc'];
                    $externSrc = $paymentSrcConfig['externSrc'];
                    $tr->writePaymentAntiSrc($insertID, array(
                        "jenis" => $stepCode,
                        "target_jenis" => $paymentSrcConfig['jenisTarget'],
                        "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                        "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                        "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                        "nomer" => $tmpNomorNota2,
                        "label" => $paymentSrcConfig["label"],
                        "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                        "terbayar" => 0,
                        "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                        "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                        "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                        "oleh_id" => my_id(),
                        "oleh_nama" => my_name(),
                        "toko_id" => my_toko_id(),
                        "toko_nama" => my_toko_nama(),
                        "dtime" => date("Y-m-d H:i:s"),
                        "fulldate" => date("Y-m-d"),
                        "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                        "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                    ));
                    cekMerah($this->CI->db->last_query());
                }
            }
        }
        else {
            //cekMerah("TIDAK nulis paymentSrc");
        }
        //endregion

        validateBalancesComparison("", $componentConfig);
        validateAllBalances($tokoID);

        $outResultLib = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $insertID,
        );

        //region connecting antar cabang
        $steps = isset($this->configUiModul[$origJenis]["steps"]) ? $this->configUiModul[$origJenis]["steps"] : array();
        $connector = isset($this->configUiModul[$origJenis]['connectTo']) ? $this->configUiModul[$origJenis]['connectTo'] : "";
        $preReplacer = isset($this->configUiModul[$this->jenisTr]['replacerConnectTo']) ? $this->configUiModul[$this->jenisTr]['replacerConnectTo'] : array();
        $validateValueConnector = isset($this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum]) ? $this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum] : array();

        if (strlen($connector) > 0) {
            cekMerah("to be connected to $connector |$stepNum|" . sizeof($steps));
            if (isset($this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum])) {
                $validateValueConnector = $this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum];
                $preVal = $this->cCodeData[$cCode]["main"][$validateValueConnector];
                $stepNum = $preVal > 0 ? $stepNum : "1000";//1000 untuk nglewatin step biar gak jalan connectingnya karena nilai yang dicari 0 kasusnya cash in advance ppn sudah masuk pusat tidak perlu diterbitkan auto dorong ppn ke pusat
            }

            if ($stepNum == sizeof($steps)) {
                cekMerah("NOW CONNECTING to $connector");
                //----------------
                $configUiMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiUi");
                $configCoreMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiCore");
                $configLayoutMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiLayout");
                $configValuesMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiValues");

                // matiHEre(__LINE__);
                if (sizeof($configUiMasterModulJenis) == 0) {
                    die("kode connector tidak dikenali!");
                }
                if (sizeof($configUiMasterModulJenis["steps"]) < 2) {
                    die("konfigurasi connector harus memiliki step lebih dari satu!");
                }

                $oldCode = $cCode;
                $cCode = "_TR_" . $connector;

                $this->cCodeData[$cCode] = array();
                $this->cCodeData[$cCode] = array(
                    "main" => $this->cCodeData[$oldCode]["main"],
                    "items" => $this->cCodeData[$oldCode]["items"],
                    "items2" => $this->cCodeData[$oldCode]["items2"],
                    "items2_sum" => $this->cCodeData[$oldCode]["items2_sum"],
                    "items3" => $this->cCodeData[$oldCode]["items3"],
                    "items3_sum" => $this->cCodeData[$oldCode]["items3_sum"],
                    "items4_sum" => $this->cCodeData[$oldCode]["items4_sum"],
                    "items_noapprove" => $this->cCodeData[$oldCode]['items_noapprove'],
                    "tableIn_master" => $this->cCodeData[$oldCode]["tableIn_master"],
                    "tableIn_detail" => $this->cCodeData[$oldCode]["tableIn_detail"],
                    "rsltItems" => $this->cCodeData[$oldCode]['rsltItems'],
                    "tableIn_detail_rsltItems" => $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'],
                    "tableIn_master_values" => $this->cCodeData[$oldCode]['tableIn_master_values'],
                    "tableIn_detail_values" => $this->cCodeData[$oldCode]['tableIn_detail_values'],
                    "tableIn_detail_values_rsltItems" => $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'],
                );

                //==replace pertama
                $masterReplacersO = array(
                    "jenisTr" => $connector,
                    "jenisTrMaster" => $connector,
                    "jenisTrTop" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis_label" => $configUiMasterModulJenis["steps"][1]["label"],
                    "transaksi_jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "stepCode" => $configUiMasterModulJenis["steps"][1]["target"],
                    "placeID" => isset($preReplacer['place2ID']) ? $preReplacer['place2ID'] : $this->cCodeData[$cCode]["main"]['place2ID'],
                    "placeName" => isset($preReplacer['place2Name']) ? $preReplacer['place2Name'] : $this->cCodeData[$cCode]["main"]['place2Name'],
                    "place2ID" => $this->cCodeData[$cCode]["main"]['placeID'],
                    "place2Name" => $this->cCodeData[$cCode]["main"]['placeName'],
                    "cabangID" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$cCode]["main"]['place2ID'],
                    "cabangName" => isset($preReplacer['place2Name']) ? $preReplacer['place2Name'] : $this->cCodeData[$cCode]["main"]['place2Name'],
                    "cabang2ID" => $this->cCodeData[$cCode]["main"]['placeID'],
                    "cabang2Name" => $this->cCodeData[$cCode]["main"]['placeName'],
                    "gudang2ID" => $this->cCodeData[$cCode]["main"]['gudangID'],
                    "gudang2Name" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "gudangID" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData[$cCode]["main"]['gudang2ID'],
                    "gudangName" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$cCode]["main"]['gudang2Name'],
                    "pihakID" => isset($this->cCodeData[$cCode]["main"]['placeID']) ? $this->cCodeData[$cCode]["main"]['placeID'] : "",
                    "pihakName" => isset($this->cCodeData[$cCode]["main"]['placeName']) ? $this->cCodeData[$cCode]["main"]['placeName'] : "",
                    "pihakName2" => $this->cCodeData[$cCode]["main"]['placeName'],
                    "gudang" => $this->cCodeData[$cCode]["main"]['gudangID'],
                    "gudang__name" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "gudang__label" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData[$cCode]["main"]['nomer'] : "",
                );
                foreach ($masterReplacersO as $key => $val) {
                    $this->cCodeData[$cCode]["main"][$key] = $val;
                }
                $masterReplacers = array(
                    "inv" => $tmpNomorNota,
                    "jenis_master" => $connector,
                    "jenis_top" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis_label" => $configUiMasterModulJenis["steps"][1]["label"],
                    "transaksi_jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "cabang_id" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$cCode]["tableIn_master"]['cabang2_id'],
                    "cabang_nama" => isset($preReplacer['cabang2Name']) ? $preReplacer['cabang2Name'] : $this->cCodeData[$cCode]["tableIn_master"]['cabang2_nama'],
                    "cabang2_id" => $this->cCodeData[$cCode]["tableIn_master"]['cabang_id'],
                    "cabang2_nama" => $this->cCodeData[$cCode]["tableIn_master"]['cabang_nama'],
                    "gudang_id" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData[$cCode]["tableIn_master"]['gudang2_id'],
                    "gudang_nama" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$cCode]["tableIn_master"]['gudang2_nama'],
                    "gudang2_id" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_id'],
                    "gudang2_nama" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],
                    "gudang" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_id'],
                    "gudang__name" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],
                    "gudang__label" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],
                    "step_avail" => sizeof($configUiMasterModulJenis["steps"]),
                    "step_current" => 1,
                    "step_number" => 1,
                    "next_step_code" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]["target"] : "",
                    "next_step_label" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]["label"] : "",
                    "next_group_code" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]['userGroup'] : "",
                    "next_step_num" => isset($configUiMasterModulJenis["steps"][2]) ? 2 : "0",
                    "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData[$cCode]["main"]['nomer'] : "",
                    //===references
                    //                    "id_master"            => $masterID,
                    //                    "id_top"               => $topID,
                    //                    "ids_prev"             => base64_encode(serialize(array($prevProp["id"]))),
                    //                    "ids_prev_intext"      => print_r(array($prevProp["id"], true)),
                    //                    "nomer_top"            => $this->cCodeData[$cCode]["main"]['nomer'],
                    //                    "nomers_prev"          => base64_encode(serialize(array($prevProp['nomer']))),
                    //                    "nomers_prev_intext"   => print_r(array($prevProp['nomer'], true)),
                    //                    "jenis_top"            => $this->jenisTr,
                    //                    "jenises_prev"        => base64_encode(serialize(array($prevProp['jenis']))),
                    //                    "jenises_prev_intext" => print_r(array($prevProp['jenis'], true)),
                );

                foreach ($masterReplacers as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

                //region penomoran receipt #2
                //<editor-fold desc="==========penomoran">
                $this->CI->load->model("CustomCounter");
                $cn = new CustomCounter("transaksi");
                $cn->setType("transaksi");

                $counterForNumber = array($configValuesMasterModulJenis["formatNota"]);
                if (!in_array($counterForNumber[0], $configValuesMasterModulJenis["counters"])) {
                    die(__LINE__ . " Used number should be registered in counters config as well");
                }

                foreach ($counterForNumber as $i => $cRawParams) {
                    $cParams = explode("|", $cRawParams);
                    $cValues = array();
                    foreach ($cParams as $param) {
                        $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                    }
                    $cRawValues = implode("|", $cValues[$i]);
                    $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                }

                $tmpNomorNota2 = $paramSpec["paramString"];
                $tmpNomorNota2Alias = formatNota("nomer_nolink", $tmpNomorNota2);
                //endregion

                //region dynamic counters #2
                // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                $cn = new CustomCounter("transaksi");
                $cn->setType("transaksi");
                $configCustomParams = $configValuesMasterModulJenis["counters"];
                $configCustomParams[] = "stepCode";
                if (sizeof($configCustomParams) > 0) {
                    $cContent = array();
                    foreach ($configCustomParams as $i => $cRawParams) {
                        $cParams = explode("|", $cRawParams);
                        $cValues = array();
                        foreach ($cParams as $param) {
                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        }
                        $cRawValues = implode("|", $cValues[$i]);
                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                        $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                        switch ($paramSpec["id"]) {
                            case 0: //===counter type is new
                                $addData = array(
                                    "toko_id" => $tokoID,
                                    "toko_nama" => $tokoNama
                                );
                                $paramKeyRaw = print_r($cParams, true);
                                $paramValuesRaw = print_r($cValues[$i], true);
                                $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                break;
                            default: //===counter to be updated
                                $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                break;
                        }
                    }
                }
                $appliedCounters2 = base64_encode(serialize($cContent));
                $appliedCounters_inText2 = print_r($cContent, true);
                //endregion

                //region numbering tambahan
                $this->CI->load->library("CounterNumber");
                $ccn = new CounterNumber();
                $ccn->setCCode($cCode);
                $ccn->setJenisTr($connector);
                $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                $new_counter = $ccn->getCounterNumber();
                cekHitam("jenistr yang disett dari create " . $this->jenisTr);

                if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                    foreach ($new_counter["main"] as $ckey => $cval) {
                        $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                        $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                    }
                }
                if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                    foreach ($new_counter["items"] as $ikey => $iSpec) {
                        foreach ($iSpec as $iikey => $iival) {
                            $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                        }
                    }
                }
                if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                    foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                        foreach ($iSpec as $iikey => $iival) {
                            $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                        }
                    }
                }
                //endregion

                $addValues = array(
                    "counters" => $appliedCounters2,
                    'counters_intext' => $appliedCounters_inText2,
                    'nomer' => $tmpNomorNota2,
                    'nomer2' => $tmpNomorNota2Alias,
                    'dtime' => date("Y-m-d H:i:s"),
                    'fulldate' => date("Y-m-d"),
                );
                foreach ($addValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

                //===cloning nota cab1 ke cab2
                //===daftar perbedaan
                //== referensi_id, inv, jenis, nomer, counters, counters_inText, cabang_id, cabang_nama, cabang2_id, cabang2_nama,

                //==replace kedua
                $masterReplacers = array(
                    "nomer" => $tmpNomorNota2,
                    "nomer2" => $tmpNomorNota2Alias,
                    "counters" => $appliedCounters2,
                    "counters_intext" => $appliedCounters_inText2,
                );
                foreach ($masterReplacers as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

                //===cloning detail/items cabang1 ke cabang2
                //===yang direplace: sub_step_number, sub_step_current, sub_step_avail, next_substep_num, next_substep_code, next_substep_label, next_subgroup_code
                $detailReplacers = array(
                    "sub_step_avail" => sizeof($configUiMasterModulJenis["steps"]),
                    "sub_step_current" => 1,
                    "sub_step_number" => 1,
                    "next_substep_num" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_num'],
                    "next_substep_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_code'],
                    "next_substep_label" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_label'],
                    "next_subgroup_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_group_code'],
                );
                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                        foreach ($dSpec as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                        }
                    }
                }
                else {
                    //                    cekmerah("GAGAL tulis rincian transaksi kedua");
                }


                //region ----------write transaksi & transaksi_data #2
                if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                    $tr = new MdlTransaksi();
                    $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                    $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                    cekUngu($this->CI->db->last_query());
                    $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                    $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                    $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                    //$mongoListConnect["main"] = array($insertID, $epID);
                    cekmerah("tulis transaksi kedua :: trID $insertID");
                    cekmerah($this->CI->db->last_query());
                    if ($insertID < 1) {
                        die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                    }
                }
                else {
                    cekmerah("GAGAL tulis transaksi kedua");
                }
                if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                    $inserMainValues = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_master_values'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        $inserMainValues[] = $dd;
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                    if (sizeof($inserMainValues) > 0) {
                        $arrBlob = blobEncode($inserMainValues);
                        $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                    foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                    foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        $inserMainValues[] = $dd;
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                    //                    cekMerah("ada mainElements");
                    foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                        $tr->writeMainElements($insertID, array(
                            "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                            "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                            "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                            "name" => $aSpec['name'],
                            "label" => $aSpec["label"],
                            "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                            "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                        ));
                    }
                }
                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                    $insertIDs = array();
                    $insertDeIDs = array();
                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                        $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                        if ($insertDetailID < 1) {
                            die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                        }
                        else {
                            $insertIDs[] = $insertDetailID;
                            $insertDeIDs[$insertID][] = $insertDetailID;
                            //$mongoListConnect['detail'][] = $insertDetailID;
                        }
                        if ($epID != 999) {
                            $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                            if ($insertEpID < 1) {
                                die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                            }
                            else {
                                $insertIDs[] = $insertEpID;
                                $insertDeIDs[$epID][] = $insertEpID;
                                //$mongoListConnect['detail'][] = $insertEpID;
                            }
                        }
                    }
                    if (sizeof($insertIDs) == 0) {
                        die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                    }
                    else {
                        $indexing_details = array();
                        foreach ($insertDeIDs as $key => $numb) {
                            $indexing_details[$key] = $numb;
                        }

                        foreach ($indexing_details as $k => $arrID) {
                            $arrBlob = blobEncode($arrID);
                            $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                            cekOrange($this->CI->db->last_query());
                        }
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                    $insertIDs = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                        $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                        //$mongoListConnect['detail'] = $insertIDs;
                        if ($epID != 999) {
                            $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                            //$mongoListConnect['detail'] = //$mongoListConnect['detail'] = $insertIDs;;
                        }
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                    $insertIDs = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                        if (isset($configValuesMasterModulJenis["tableIn"]['detailValues'])) {
                            foreach ($configValuesMasterModulJenis["tableIn"]['detailValues'] as $key => $src) {
                                //                                $insertIDs[$pID][] = $tr->writeDetailValues($insertID, array(
                                //                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                //                                    "produk_id" => $pID,
                                //                                    "key" => $key,
                                //                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                                //                                ));
                                $dd = $tr->writeDetailValues($insertID, array(
                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                                ));
                                $insertIDs[] = $dd;
                                //$mongoListConnect['detailValues'][] = $dd;

                            }
                        }
                    }
                    if (sizeof($insertIDs) > 0) {
                        $arrBlob = blobEncode($insertIDs);
                        $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                        if (isset($configValuesMasterModulJenis["tableIn"]['detailValues2_sum'])) {
                            foreach ($configValuesMasterModulJenis["tableIn"]['detailValues2_sum'] as $key => $src) {
                                $insertIDs[] = $tr->writeDetailValues($insertID, array(
                                    "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => $dSpec[$src],
                                ));

                            }
                        }
                    }
                }

                //
                //region nulis paymentSource
                $stepCode = $configUiMasterModulJenis["steps"][1]["target"];
                $paymentSources = $this->CI->config->item("payment_source");
                if (array_key_exists($stepCode, $paymentSources)) {

                    $payConfigs = $paymentSources[$stepCode];
                    if (sizeof($payConfigs) > 0) {
                        foreach ($payConfigs as $paymentSrcConfig) {
                            //					$paymentSrcConfig = $paymentSources[$stepCode];
                            $valueSrc = $paymentSrcConfig['valueSrc'];
                            $externSrc = $paymentSrcConfig['externSrc'];
                            $tr->writePaymentSrc($insertID, array(
                                "jenis" => $stepCode,
                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                "nomer" => $tmpNomorNota2,
                                "label" => $paymentSrcConfig["label"],
                                "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "terbayar" => 0,
                                "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "toko_id" => my_toko_id(),
                                "toko_nama" => my_toko_name(),
                                "dtime" => date("Y-m-d H:i:s"),
                                "fulldate" => date("Y-m-d"),
                                "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                                "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                                "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                                "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                                "terbayar_valas" => 0,
                                "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                            ));
                        }
                    }

                }
                else {
                    //cekMerah("TIDAK nulis paymentSrc");
                }
                //endregion


                //region nulis paymentAntiSource

                $stepCode = $configUiMasterModulJenis["steps"][1]["target"];
                $paymentSources = $this->CI->config->item("payment_antiSource");
                if (array_key_exists($stepCode, $paymentSources)) {
                    $payConfigs = $paymentSources[$stepCode];
                    if (sizeof($payConfigs) > 0) {
                        foreach ($payConfigs as $paymentSrcConfig) {
                            $valueSrc = $paymentSrcConfig['valueSrc'];
                            $externSrc = $paymentSrcConfig['externSrc'];
                            $tr->writePaymentAntiSrc($insertID, array(
                                "jenis" => $stepCode,
                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                "nomer" => $tmpNomorNota2,
                                "label" => $paymentSrcConfig["label"],
                                "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "terbayar" => 0,
                                "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "toko_id" => my_toko_id(),
                                "toko_nama" => my_toko_nama(),
                                "dtime" => date("Y-m-d H:i:s"),
                                "fulldate" => date("Y-m-d"),
                            ));
                        }
                    }
                }
                else {
                    //cekMerah("TIDAK nulis paymentSrc");
                }
                //endregion


                $idHis_decode[$stepNum] = array(
                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                    "step" => $stepNum,
                    "trID" => $insertID,
                    "nomer" => $tmpNomorNota2,
                    "nomer2" => $tmpNomorNota2Alias,
                    "counters" => $appliedCounters2,
                    "counters_intext" => $appliedCounters_inText2,
                );
                $idHis_blob = blobEncode($idHis_decode);
                $idHis_intext = print_r($idHis_decode, true);

                $this->cCodeData[$cCode]["tableIn_master"]['ids_his'] = $idHis_blob;
                $this->cCodeData[$cCode]["tableIn_master"]['ids_his_intext'] = $idHis_intext;

                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array("id" => $insertID), array(
                    "id_master" => $masterID,
                    "id_top" => $insertID,
                    "ids_his" => $idHis_blob,
                    "ids_his_intext" => $idHis_intext,
                )) or die("Failed to update tr next-state!");


                $baseRegistries = array(
                    "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                    "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                    "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                    "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                    "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                    "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                    "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                    "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                    "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                    "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                    "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                    'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                    'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                    'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                    'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                    'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                    'items_noapprove' => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                    'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                    'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                    'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                    "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                    "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                    'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                    'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                    'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                    'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                    'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                    'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                    'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                    'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                    'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                    'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                    'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                    'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                    'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                    "receiptDetailFields" => isset($this->configLayoutModul[$connector]['receiptDetailFields'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields'][1] : array(),
                    "receiptSumFields" => isset($this->configLayoutModul[$connector]['receiptSumFields'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields'][1] : array(),
                    "receiptDetailFields2" => isset($this->configLayoutModul[$connector]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields2'][1] : array(),
                    "receiptSumFields2" => isset($this->configLayoutModul[$connector]['receiptSumFields2'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields2'][1] : array(),
                    "receiptDetailSrcFields" => isset($this->configLayoutModul[$connector]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$connector]['receiptDetailSrcFields'][1] : array(),
                    "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                    "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                    "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                    "jurnal_index" => isset($this->cCodeData[$cCode]['jurnal_index']) ? $this->cCodeData[$cCode]['jurnal_index'] : array(),
                    "postProcessor" => isset($this->cCodeData[$cCode]['postProcessor']) ? $this->cCodeData[$cCode]['postProcessor'] : array(),
                    "preProcessor" => isset($this->cCodeData[$cCode]['preProcessor']) ? $this->cCodeData[$cCode]['preProcessor'] : array(),
                    "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                    "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                    //-----
                    "coreBuilder" => isset($coreBuilder) ? $coreBuilder : array(),
                    'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                    'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                    'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                    //-----
                );
                $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                $mongRegIDConnect = $doWriteReg;
                //endregion


                //==================================================================================================
                //==MENULIS LOCKER TRANSAKSI ACTIVE=================================================================
                $this->CI->load->model("Mdls/MdlLockerTransaksi");
                $lt = New MdlLockerTransaksi();
                $lt->execLocker($this->cCodeData[$cCode]["main"], $nextProp["num"], NULL, $insertID);
                //==================================================================================================

                $outResultLib["sessionDataConnecting"] = $this->cCodeData[$cCode];
                $outResultLib["tmpNomerNotaConnecting"] = $tmpNomorNota2;
                $outResultLib["transaksiIdConnecting"] = $insertID;

            }
            else {
                cekMerah("to be delayed to connect to $connector");
            }
        }
        else {
            //cekKuning("not connecting to any tCode");
        }
        //endregion


        //region nulis ke data jika ada
        $addTodata = isset($this->configUiModul[$this->jenisTr]["addData"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["addData"][$stepNum] : array();
        if (sizeof($addTodata) > 0) {
            $gateData = isset($this->cCodeData[$cCode][$addTodata["gate"]]) ? $this->cCodeData[$cCode][$addTodata["gate"]] : array();
            $selectedFields = $addTodata["fieldName"];
            $dataMdl = $addTodata["MdlNameMain"];
            $this->CI->load->model("DComs/" . $dataMdl);
            $d = new $dataMdl();
            $childMdl = $addTodata["MdlNameChild"];
            $d = new $dataMdl();
            if (sizeof($gateData) > 0) {
                $outparams = array();
                $ctr = 0;
                foreach ($gateData as $gateValues) {
                    $params = array();
                    $ctr++;
                    foreach ($selectedFields as $colum => $gate_collom) {
                        $params['static'][$colum] = $gateValues[$gate_collom];
                    }
                    if ($masterID != "") {
                        $params['static']['transaksi_id_request_bunga'] = $masterID;
                    }
                    if ($insertID != "") {
                        $params['static']['transaksi_id'] = $insertID;
                    }
                    if ($this->session->login['nama_login'] != "") {
                        $params['static']['nama_login'] = $this->session->login['nama_login'];
                    }
                    if (my_id() != "") {
                        $params['static']['pihakid'] = my_id();
                    }
                    if ($tmpNomorNota2 != "") {
                        $params['static']['tmpNomorNota2'] = $tmpNomorNota2;
                    }
                    $outparams[] = $params + array("MdlName" => $childMdl);
                }

                if (sizeof($outparams) > 0) {
                    $d->pair($outparams) or die("Tidak berhasil memasang  values pada post-processor: $dataMdl/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $d->exec() or die("Gagal saat berusaha  exec values pada post-processor: $dataMdl/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
                else {
                    matiHEre("error on insert data");
                }
            }
        }

        //endregion


        return $outResultLib;
    }

    //-doRevert--------------------------
    public function doRevert()
    {
        $location = "(library " . get_class($this) . ", method " . __FUNCTION__ . ")";
        $this->setterValidate($location);

        $transaksiID_reference = $no = $this->transaksiNumber;
        $jenisTr_con = $jenisTr = $this->jenisTr;
        $masterTargetStepNum_con = $masterTargetStepNum = $this->masterTargetStepNum;
        $childTargetStepNum_con = $childTargetStepNum = $this->childTargetStepNum;
        $stepNumCurrent_son = $stepNumCurrent = $this->stepNumCurrent;
        $cCode = $this->cCode;

        $rejectException = $this->CI->config->item('heTransaksi_rejectException') != NULL ? $this->CI->config->item('heTransaksi_rejectException') : array();
        $referenceRevertConfigs = isset($this->configUiModul[$jenisTr]['referenceRevert']) ? $this->configUiModul[$jenisTr]['referenceRevert'] : array();
        $prepConfigs = null != $this->CI->config->item('hePreProcessors') ? $this->CI->config->item('hePreProcessors') : array();
        $postConfigs = null != $this->CI->config->item('hePostProcessors') ? $this->CI->config->item('hePostProcessors') : array();

        //region swap from registry, transaksi yang dibuka saat ini
        $this->CI->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();
        $tmpReg = $tr->lookupDataRegistriesByMasterID($no)->result();
        cekmerah($this->CI->db->last_query());
        if (sizeof($tmpReg) > 0) {
            foreach ($tmpReg as $row) {
                foreach ($row as $key_reg => $val_reg) {
                    if ($key_reg != "transaksi_id") {
                        $var = $key_reg;
                        $$var = unserialize(base64_decode($val_reg));
                    }
                }
            }
        }
        //endregion

        //region swap from main transaksi, transaksi yang dibuka saat ini
        $tr = new MdlTransaksi();
        $tr->setFilters(array());
        $tr->addFilter("id='$no'");
        $tmpTr = $tr->lookupMainTransaksi()->result();
        cekOrange($this->CI->db->last_query());
        $currentInsertID = $insertID = $tmpTr[0]->id;
        $currentMasterID = $tmpTr[0]->id_master;
        $currentNomer = $insertNum = $tmpTr[0]->nomer;
        $thisStepNumber = $tmpTr[0]->step_number;
        //endregion


        // jika ada connecting antar-cabang...
        cekHitam("jenisTr -> $jenisTr");
        cekhitam("checking dulu connecting antar cabang... (connecto transaksi_ui)");
        $connector = isset($this->configUiModul[$jenisTr]['connectTo']) ? $this->configUiModul[$jenisTr]['connectTo'] : "";
        $mongListUpadte = array();
        $mongoList = array();
        if (strlen($connector) > 0) {
            cekUngu(":: ADA CONNECTING :: connector-> $connector ::");
            cekBiru("bila ada normal, yang membatalkan pihak source/sumber/asal...");


            //region update step2an di masternya
            $nextMasterStep = $stepNumCurrent;
            $nextProp = array(
                "num" => $nextMasterStep,
                "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
            );
            echo "nextMasterStep: $nextMasterStep<br>";
            arrPrint($nextProp);

            //update masternya, transaksi TOP
            if ($tmpTr[0]->id_top != $no) {
                $arrData = array(
                    "next_step_code" => $nextProp["code"],
                    "next_step_label" => $nextProp["label"],
                    "next_group_code" => $nextProp["groupID"],
                    "next_step_num" => $nextProp["num"],
                    "step_current" => $masterTargetStepNum,
                    "step_number" => $masterTargetStepNum,
                );
                $arrData_detail = array(
                    "next_substep_code" => $nextProp["code"],
                    "next_substep_label" => $nextProp["label"],
                    "next_subgroup_code" => $nextProp["groupID"],
                    "next_substep_num" => $nextProp["num"],
                    "sub_step_current" => $masterTargetStepNum,
                    "sub_step_number" => $masterTargetStepNum,
                );
            }
            else {
                $arrData = array(
                    "next_step_code" => $nextProp["code"],
                    "next_step_label" => $nextProp["label"],
                    "next_group_code" => $nextProp["groupID"],
                    "next_step_num" => $nextProp["num"],
                    "step_current" => $masterTargetStepNum,
                    "step_number" => $childTargetStepNum,
                    "trash_4" => "1",
                    "cancel_dtime" => date("Y-m-d H:i:s"),
                    "cancel_name" => my_id(),
                    "cancel_id" => my_name(),
                );
                $arrData_detail = array(
                    "next_substep_code" => $nextProp["code"],
                    "next_substep_label" => $nextProp["label"],
                    "next_subgroup_code" => $nextProp["groupID"],
                    "next_substep_num" => $nextProp["num"],
                    //            "sub_step_current" => 0,
                    "sub_step_number" => 0,
                );
            }
            $tr = new MdlTransaksi();
            $dupState = $tr->updateData(array(
                "id" => $tmpTr[0]->id_top,
            ), $arrData) or die("Failed to update tr next-state!");
            cekHijau("UPDATE transaksi step sebelumnya...");
            cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
            //endregion

            //region update step transaksi 1 step sebelumnya (detail)
            if (sizeof($tmpTr) > 0) {
                $arrPrevID = $tmpTr[0]->ids_prev != null ? blobDecode($tmpTr[0]->ids_prev) : array($tmpTr[0]->id_top);
                arrPrint($arrPrevID);
                foreach ($arrPrevID as $prevID) {
                    $tb = new MdlTransaksi();
                    $tb->setFilters(array());
                    $dupState = $tb->updateData(array(
                        "id" => $prevID,
                    ), array(
                        "status_4" => "11",
                    )) or die("Failed to update tr next-state!");

                    $mongListUpadte['update']["main"][] = array(
                        "where" => array(
                            "id" => $prevID,
                        ),
                        "value" => array("status_4" => "11",),
                    );
                    cekKuning("UPDATE transaksi 1 step sebelumnya...");
                    cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");


                    $td = new MdlTransaksi();
                    $td->setFilters(array());
                    $rslt = $td->lookupJoinedByID($prevID)->result();
                    if (sizeof($rslt) > 0) {
                        foreach ($rslt as $rsltSpec) {
                            if (array_key_exists($rsltSpec->produk_id, $items)) {
                                $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];

                                if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                    $new_valid_qty = $rsltSpec->valid_qty;

                                }
                                else {
                                    $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                }

                                $arrData_detail["valid_qty"] = $new_valid_qty;
                                $tr = new MdlTransaksi();
                                $tr->setFilters(array());
                                $tr->setTableName($tr->getTableNames()['detail']);
                                $dupState = $tr->updateData(array(
                                    "transaksi_id" => $prevID,
                                    "produk_id" => $rsltSpec->produk_id,
                                ), $arrData_detail) or die("Failed to update tr next-state!");

                                cekKuning("UPDATE transaksi data...");
                                cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                            }
                        }
                    }

                }
            }
            //endregion

            //region update step yang sebelumnya aktif, transaksi yang dibuka sekarang
            // cekUngu($tmpTr[0]->id_top);
            // cekUngu("$no");
            // if ($tmpTr[0]->id_top != $no) {
            $tp = new MdlTransaksi();
            $dupState = $tp->updateData(array(
                "id" => $no,
                "step_number" => $stepNumCurrent,
            ), array(
                "step_number" => $childTargetStepNum,
                "trash_4" => "1",
                "cancel_dtime" => date("Y-m-d H:i:s"),
                "cancel_name" => my_name(),
                "cancel_id" => my_id(),

            )) or die("Failed to update tr next-state!");

            cekLime("UPDATE transaksi ini... yang dibuka sekarang...");
            cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

            $to = new MdlTransaksi();
            $to->setFilters(array());
            $to->setTableName($to->getTableNames()['detail']);
            $dupState = $to->updateData(array(
                "transaksi_id" => $no,
            ), array(
                "next_substep_code" => $nextProp["code"],
                "next_substep_label" => $nextProp["label"],
                "next_subgroup_code" => $nextProp["groupID"],
                "next_substep_num" => $nextProp["num"],
                //            "sub_step_current" => 0,
                "sub_step_number" => 0,
            )) or die("Failed to update tr next-state!");

            cekLime("UPDATE transaksi data...");
            cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
            // }
            //endregion

            //region sesuaikan signature untuk cloningan, ikut minus
            //        $dwsign = $tr->writeSignature($no, array(
            $dwsign = $tr->writeSignature($tmpTr[0]->id_top, array(
                "prev_id" => $no,
                "nomer" => "rejection",
                "step_number" => $childTargetStepNum,
                // ini minus step number
                "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["target"],
                "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"],
                "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]['userGroup'],
                "oleh_id" => my_id(),
                "oleh_nama" => my_name(),
                "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                //            "transaksi_id" => $no,
            )) or die("Failed to write signature");
            $mongoList['sign'][] = $dwsign;
            cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
            //endregion

            // region netralisasi payment source
            $tr = New MdlTransaksi();
            $tr->setFilters(array());
            $tr->addFilter("sisa>0");
            $paymentSrc = $tr->lookupPaymentSrcByTransID($no)->result();
            cekBiru($this->CI->db->last_query());
            if (sizeof($paymentSrc) > 0) {
                //            arrPrint($paymentSrc);
                foreach ($paymentSrc as $pSpec) {
                    if ($pSpec->terbayar == 0) {
                        $where = array(
                            "id" => $pSpec->id,
                            "transaksi_id" => $pSpec->transaksi_id,
                        );
                        $data = array(
                            "sisa" => 0,
                            "returned" => $pSpec->sisa,
                            "sisa_valas" => 0,
                            "returned_valas" => $pSpec->sisa_valas,
                        );

                        $tra = New MdlTransaksi();
                        $tra->setFilters(array());
                        $tra->updatePaymentSrc($where, $data);
                        cekUngu(":: mereject payment source bila ada...");
                        cekUngu($this->CI->db->last_query());
                    }
                    else {
                        mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                    }
                }
            }
            else {
                cekBiru(":: tidak ada payment source... ::");
            }
            // endregion netralisasi payment source

            // region netralisasi extended step
            $tr = New MdlTransaksi();
            $tr->setFilters(array());
            $exTmp = $tr->lookupExtStepByTrID($no);
            if (sizeof($exTmp) > 0) {
                foreach ($exTmp as $exSpec) {

                    $tra = New MdlTransaksi();
                    $tra->setFilters(array());
                    $tra->rejectExtStepByID($exSpec["id"]);
                    $mongListUpadte['update']['extra'][] = array(
                        "where" => array(
                            "id" => $exSpec["id"],
                        ),
                        "value" => array(
                            "state" => "-1",
                        ),
                    );
                    cekUngu(":: mereject extended step bila ada...");
                    cekUngu($this->CI->db->last_query());
                }
            }
            else {
                cekBiru(":: tidak ada extended step... ::");
            }

            // endregion netralisasi extended step

            //==entry point
            if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {

                if (isset($this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent])) {
                    if ($this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["enabled"] == true) {
                        $masterID = $currentMasterID;
                        $connecTo = $this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["connectTo"];
                        cekHijau("START menjalankan REJECT... [$masterID] [$connecTo]");
                        if ($connecTo == NULL) {
                            mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                        }
                        $oldCode = $cCode;
                        $cCode = "_TR_" . $connecTo;
                        $this->cCodeData[$cCode] = array(
                            "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                            "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                            "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                            "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                            "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                            "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                            "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                            "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                            "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                            "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                            "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                            'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                            'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                            'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                            'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                            'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                            'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                            'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                            'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                            "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                            "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                            'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                            'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                            'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                            'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                            'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                            'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                            'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                            'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                            'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                            'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                            'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                            'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                            'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                            "receiptDetailFields" => isset($this->configLayout[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailFields'][1] : array(),
                            "receiptSumFields" => isset($this->configLayout[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptSumFields'][1] : array(),
                            "receiptDetailFields2" => isset($this->configLayout[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                            "receiptDetailSrcFields" => isset($this->configLayout[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayout[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                            "receiptSumFields2" => isset($this->configLayout[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayout[$this->jenisTr]['receiptSumFields2'][1] : array(),
                            "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                            "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                            "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                            "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                            "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                            "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                            "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                            "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                        );
                        // masuk ke gerbang TableInMaster, tabel transaksi
                        $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                            "jenis_master" => $this->jenisTr,
                            "jenis_top" => $connecTo,
                            "jenis" => $connecTo,
                            "jenis_label" => $this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "transaksi_jenis" => $connecTo,
                            "step_avail" => 1,
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => "",
                            "next_step_label" => "",
                            "next_group_code" => "",
                            "next_step_num" => "0",
                            "trash_4" => 1,
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),
                            "deskripsi" => "rejection",

                        );
                        // masuk ke gerbang main
                        $masterReplacersO = array(
                            "stepCode" => $connecTo,
                            "jenisTrTop" => $connecTo,
                            "jenisTrName" => $this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["label"],
//                        "inv" => $tmpNomorNota,
                            "jenis_master" => $this->jenisTr,
                            "jenis_top" => $connecTo,
                            "jenis" => $connecTo,
                            "jenis_label" => $this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "transaksi_jenis" => $connecTo,
                            "stepCode" => $connecTo,
                            "jenisTrTop" => $connecTo,
                            "jenisTrName" => $this->configUiModul[$jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "step_avail" => 1,
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => "",
                            "next_step_label" => "",
                            "next_group_code" => "",
                            "next_step_num" => "0",
                        );
                        foreach ($masterReplacersO as $key => $val) {
                            $this->cCodeData[$cCode]["main"][$key] = $val;
                        }
                        foreach ($masterReplacers as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }

                        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];

                        //region penomoran receipt
                        $this->CI->load->model("CustomCounter");
                        $cn = new CustomCounter("transaksi");
                        $cn->setType("transaksi");
                        $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaReject']);
                        if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersReject'])) {
                            die(__LINE__ . " Used number should be registered in counters config as well");
                        }
                        echo "<div style='background:#ff7766;'>";
                        foreach ($counterForNumber as $i => $cRawParams) {
                            $cParams = explode("|", $cRawParams);
                            $cValues = array();
                            foreach ($cParams as $param) {
                                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                            }
                            $cRawValues = implode("|", $cValues[$i]);
                            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                        }
                        echo "</div style='background:#ff7766;'>";

                        $stepNumber = 1;
                        $tmpNomorNota = $paramSpec["paramString"];
                        $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                        $nextProp = array(
                            "num" => 0,
                            "code" => "",
                            "label" => "",
                            "groupID" => "",
                        );
                        //endregion

                        //region dynamic counters
                        $cn = new CustomCounter("transaksi");
                        $cn->setType("transaksi");
                        $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersReject'];
                        arrPrintHijau($configCustomParams);
                        $configCustomParams[] = "stepCode";
                        //arrPrint($configCustomParams);
                        if (sizeof($configCustomParams) > 0) {
                            $cContent = array();
                            foreach ($configCustomParams as $i => $cRawParams) {
                                $cParams = explode("|", $cRawParams);
                                $cValues = array();
                                foreach ($cParams as $param) {
                                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                }
                                $cRawValues = implode("|", $cValues[$i]);
                                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                                switch ($paramSpec["id"]) {
                                    case 0: //===counter type is new
                                        $addData = array(
                                            "toko_id" => $tokoID,
                                            "toko_nama" => $tokoNama,
                                        );
                                        $paramKeyRaw = print_r($cParams, true);
                                        $paramValuesRaw = print_r($cValues[$i], true);
                                        $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                        break;
                                    default: //===counter to be updated
                                        $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                        break;
                                }
                                //echo "<hr>";
                            }
                        }
                        $appliedCounters = base64_encode(serialize($cContent));
                        $appliedCounters_inText = print_r($cContent, true);
                        //mati_disini();

                        //
                        //region addition on master
                        $addValues = array(
                            "counters" => $appliedCounters,
                            'counters_intext' => $appliedCounters_inText,
                            'nomer' => $tmpNomorNota,
                            'nomer2' => $tmpNomorNotaAlias,
                            'dtime' => date("Y-m-d H:i:s"),
                            'fulldate' => date("Y-m-d"),
                            "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                            "step_number" => 1,
                            "step_current" => 1,
                            "next_step_num" => $nextProp["num"],
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],
                            "tail_number" => 1,
                            "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],
                        );
                        foreach ($addValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        //endregion

                        //region addition on detail
                        $addSubValues = array(
                            "sub_step_number" => 1,
                            "sub_step_current" => 1,
                            "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                            "next_substep_num" => $nextProp["num"],
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "sub_tail_number" => 1,
                            "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                        );
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                            foreach ($addSubValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                            }
                        }
                        //endregion

                        //endregion

                        //region numbering tambahan
                        $this->CI->load->library("CounterNumber");
                        $ccn = new CounterNumber();
                        $ccn->setCCode($cCode);
                        $ccn->setJenisTr($this->jenisTr);
                        $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                        $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                        $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                        $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                        $new_counter = $ccn->getCounterNumber();
                        cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                        if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                            foreach ($new_counter["main"] as $ckey => $cval) {
                                $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                                $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                            }
                        }
                        if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                            foreach ($new_counter["items"] as $ikey => $iSpec) {
                                foreach ($iSpec as $iikey => $iival) {
                                    $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                                }
                            }
                        }
                        if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                            foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                                foreach ($iSpec as $iikey => $iival) {
                                    $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                                }
                            }
                        }
                        //endregion

                        $addValues = array(
                            "counters" => $appliedCounters,
                            'counters_intext' => $appliedCounters_inText,
                            'nomer' => $tmpNomorNota,
                            'nomer2' => $tmpNomorNotaAlias,
                            'dtime' => date("Y-m-d H:i:s"),
                            'fulldate' => date("Y-m-d"),
                        );
                        foreach ($addValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        $masterReplacers = array(
                            "nomer" => $tmpNomorNota,
                            "nomer2" => $tmpNomorNotaAlias,
                            "counters" => $appliedCounters,
                            "counters_intext" => $appliedCounters_inText,
                        );
                        foreach ($masterReplacers as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        $detailReplacers = array(
                            "sub_step_avail" => 1,
                            "sub_step_current" => 1,
                            "sub_step_number" => 1,
                            "next_substep_num" => "",
                            "next_substep_code" => "",
                            "next_substep_label" => "",
                            "next_subgroup_code" => "",
                        );


                        if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                                foreach ($dSpec as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                                }
                            }
                        }
                        $itemsReplacers = array(
                            "next_substep_num" => "",
                            "next_substep_code" => "",
                            "next_substep_label" => "",
                            "next_subgroup_code" => "",
                        );
                        if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                            foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                                foreach ($dSpec as $key => $val) {
                                    $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                                }
                            }
                        }

                        //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                        if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                            $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                            $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 1;
                            $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;

                            $tr = new MdlTransaksi();
                            $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                            $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                            cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                            $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                            $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                            $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                            if ($insertID < 1) {
                                die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                            }
                            $mongoList["main"] = array($insertID, $epID);
                            //==transaksi_id dan nomor nota diinject kan ke gate utama
                            $injectors = array(
                                "transaksi_id" => $insertID,
                                "nomer" => $tmpNomorNota,
                                "nomer2" => $tmpNomorNotaAlias,
                            );
                            $arrInjectorsTarget = array(
                                "items",
                                "items2_sum",
                                "rsltItems",
                            );
                            foreach ($injectors as $key => $val) {
                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                foreach ($arrInjectorsTarget as $target) {
                                    if (isset($this->cCodeData[$cCode][$target])) {
                                        foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                            $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                            if (isset($this->cCodeData[$cCode][$target][$id])) {
                                                $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                            }
                                        }
                                    }
                                }
                            }

                            //===signature
                            $dwsign = $tr->writeSignature($insertID, array(
                                "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "step_number" => 1,
                                "step_code" => $connecTo,
                                "step_name" => $this->configUiModul[$jenisTr]["connectToEdit"][1]["label"],
                                "group_code" => "",
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "keterangan" => $this->configUiModul[$jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                                "transaksi_id" => $masterID,
                                "deskripsi" => "edit transaksi",
                                "cabang_id" => my_cabang_id(),
                                "cabang_nama" => my_cabang_name(),
                                "current_transaksi_id" => $masterID,
                                "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            )) or die("Failed to write signature");
                            showLast_query("kuning");

                            $idHis = array(
                                $stepNumber => array(
                                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                    "step" => $stepNumber,
                                    "trID" => $insertID,
                                    "nomer" => $tmpNomorNota,
                                    "nomer2" => $tmpNomorNotaAlias,
                                    "counters" => $appliedCounters,
                                    "counters_intext" => $appliedCounters_inText,
                                ),
                            );
                            $idHis_blob = blobEncode($idHis);
                            $idHis_intext = print_r($idHis, true);
                            $tr = new MdlTransaksi();
                            $dupState = $tr->updateData(array("id" => $insertID), array(
                                "next_step_num" => $nextProp["num"],
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],

                                //===references
//                            "id_master" => $insertID,
                                "id_master" => $masterID,// milik transkasiID yang diedit
                                "id_top" => $insertID,
                                "ids_prev" => "",
                                "ids_prev_intext" => "",
                                "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "nomers_prev" => "",
                                "nomers_prev_intext" => "",
                                "jenises_prev" => "",
                                "jenises_prev_intext" => "",
                                "ids_his" => $idHis_blob,
                                "ids_his_intext" => $idHis_intext,

                            )) or die("Failed to update tr next-state!");
                            cekHijau($this->CI->db->last_query());

                            $addValues = array(
                                //===references
                                "id_master" => $insertID,
                                "id_top" => $insertID,
                                "ids_prev" => "",
                                "ids_prev_intext" => "",
                                "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "nomers_prev" => "",
                                "nomers_prev_intext" => "",
                                "jenises_prev" => "",
                                "jenises_prev_intext" => "",
                                "ids_his" => $idHis_blob,
                                "ids_his_intext" => $idHis_intext,
                            );
                            foreach ($addValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }

                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                            $inserMainValues = array();
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'])) {
                                //matiHEre("hooppp");
                                $inserMainValues = array();
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                    if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                        $dd = $tr->writeMainValues($insertID, array(
                                            "key" => $key,
                                            "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                        ));

                                        $inserMainValues[] = $dd;
                                        $mongoList['mainValues'][] = $dd;
                                    }
                                }
                            }

                            if (sizeof($inserMainValues) > 0) {
                                $arrBlob = blobEncode($inserMainValues);
                                $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                            }

                        }
                        if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                            $inserMainValues = array();
                            foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                                $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                $inserMainValues[] = $dd;
                                $mongoList['mainValues'][] = $dd;
                            }

                            if (sizeof($inserMainValues) > 0) {
                                $arrBlob = blobEncode($inserMainValues);
                                $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                                $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));

                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                                $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                                $tr->writeMainApplets($insertID, array(
                                    "mdl_name" => $amdl,
                                    "key" => $aSpec['key'],
                                    "label" => $aSpec['labelValue'],
                                    "description" => $aSpec['description'],
                                ));
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                                $tr->writeMainElements($insertID, array(
                                    "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                    "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                    "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                    "name" => $aSpec['name'],
                                    "label" => $aSpec["label"],
                                    "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                    "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                                ));
                            }
                        }
                        if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                            $insertIDs = array();
                            $insertDeIDs = array();
                            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                                $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                if ($insertDetailID < 1) {
                                    die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                                }
                                else {
                                    $insertIDs[] = $insertDetailID;
                                    $insertDeIDs[$insertID][] = $insertDetailID;
                                    $mongoList['detail'][] = $insertDetailID;
                                }
                                if ($epID != 999) {
                                    $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                    if ($insertEpID < 1) {
                                        die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                    }
                                    else {
                                        $insertIDs[] = $insertEpID;
                                        $insertDeIDs[$epID][] = $insertEpID;
                                        $mongoList['detail'][] = $insertEpID;
                                    }
                                }
                                cekUngu($this->CI->db->last_query());
                            }
                            if (sizeof($insertIDs) == 0) {
                                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                            }
                            else {
                                $indexing_details = array();
                                foreach ($insertDeIDs as $key => $numb) {
                                    $indexing_details[$key] = $numb;
                                }
                                foreach ($indexing_details as $k => $arrID) {
                                    $arrBlob = blobEncode($arrID);
                                    $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                    cekOrange($this->CI->db->last_query());
                                }
                            }
                        }
                        else {
                            die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                                $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                                $mongoList['detail'] = $insertIDs;
                                if ($epID != 999) {
                                    $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                    $mongoList['detail'] = $insertIDs;
                                }
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                                $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                $insertIDs[] = $insertDetailID;
                                $mongoList['detail'][] = $insertDetailID;
                                if ($epID != 999) {
                                    $dd = $tr->writeDetailEntries($epID, $dSpec);
                                    $insertIDs[] = $dd;
                                    $mongoList['detail'][] = $dd;
                                }
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                                $dd = $tr->writeDetailEntries($insertID, $dSpec);
                                $insertIDs[] = $dd;
                                $mongoList['detil'][] = $dd;
                                if ($epID != 999) {
                                    $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                    $mongoList['detil'] = $insertIDs;
                                }
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                        if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                            $dd = $tr->writeDetailValues($insertID, array(
                                                "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                                "produk_id" => $pID,
                                                "key" => $key,
                                                "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                            ));
                                            $insertIDs[$pID][] = $dd;

                                        }
                                    }
                                }
                            }
                            if (sizeof($insertIDs) > 0) {
                                $arrBlob = blobEncode($insertIDs);
                                $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                    $insertIDs = array();
                                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                        $dd = $tr->writeDetailValues($insertID, array(
                                            "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                            "produk_id" => $pID,
                                            "key" => $key,
                                            "value" => $dSpec[$src],
                                        ));
                                        $insertIDs[] = $dd;
                                        $mongoList['detailValues'][] = $dd;
                                    }
                                }
                            }
                        }
                        //endregion

                        $baseRegistries = array(
                            "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                            "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                            "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                            "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                            "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                            "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                            "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                            "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                            "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                            "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                            "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                            'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                            'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                            'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                            'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                            'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                            'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                            'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                            'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                            "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                            "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                            'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                            'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                            'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                            'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                            'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                            'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                            'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                            'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                            'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                            'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                            'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                            'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                            'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                            "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                            "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                            "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                            "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                            "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                            "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                            "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                            "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                            "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                            "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                            "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                            "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                            "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                            //----
                            'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                            'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                            //----
                        );
                        $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                        showLast_query("hijau");
                        cekHijau("SELESAI menjalankan EDITOR...");
                    }
                }
                else {
                    $tableIn_master['trash_4'] = 1;
                    $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                    $tableIn_master['cancel_name'] = my_name();
                    $tableIn_master['cancel_id'] = my_id();
                    $tableIn_master['deskripsi'] = "rejection";
                    $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);

                    if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                        $insertIDs = array();
                        foreach ($tableIn_detail as $dSpec) {
                            if ($epID != 999) {
                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);

                            }
                        }
                    }
                }

            }
            $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
            $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
            $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
            $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
            $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
            $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();

            //===if rollback is needed
            //rollback preproc, master
            if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                $iterator = isset($core['preProcessor'][$jenisTr_component]['master']) ? $core['preProcessor'][$jenisTr_component]['master'] : array();
                if (sizeof($iterator) > 0) {
                    $it = 0;
                    cekbiru("ada iterator pre-proc master");
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $it++;
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'] . "_reverse";
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                        echo "reverse master-preproc: $comName, initializing values <br>";
                        $tmpOutParams[$cCtr] = array();
                        $subParams = array();
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $subParams['static'][$key] = $realValue;
                            }

                            if (array_key_exists($oriComName, $prepConfigs)) {
                                if (sizeof($prepConfigs[$oriComName]) > 0) {
                                    foreach ($prepConfigs[$oriComName] as $key => $src) {
                                        $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                    }
                                }
                            }

                            if (!isset($subParams['static']["transaksi_id"])) {
                                $subParams['static']["transaksi_id"] = $no;
                            }
                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                        }
                        if (sizeof($subParams) > 0) {
                            $tmpOutParams[$cCtr] = $subParams;
                        }


                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);

                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();
                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }

                    }
                }
            }
            else {
                cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
            }
            //rollback preproc, detail
            if (isset($core['preProcessor'][$jenisTr_component]['detail'])) {
                $iterator = isset($core['preProcessor'][$jenisTr_component]['detail']) ? $core['preProcessor'][$jenisTr_component]['detail'] : array();
                if (sizeof($iterator) > 0) {
                    $it = 0;
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $it++;
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'] . "_reverse";
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "reverse preproc (detail): $comName, initializing values <br>";
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                            $tmpOutParams[$cCtr] = array();
                            $id = $xid;
                            $subParams = array();

                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {
                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['static'][$key] = $realValue;
                                }

                                if (array_key_exists($oriComName, $prepConfigs)) {
                                    cekhitam("terdapat di dalam prepConfig");
                                    if (sizeof($prepConfigs[$oriComName]) > 0) {
                                        foreach ($prepConfigs[$oriComName] as $key => $src) {
                                            $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                        }
                                    }
                                }
                                else {
                                    cekhitam("TIDAK terdapat di dalam prepConfig");
                                }
                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $no;
                                }


                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                            }

                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr][] = $subParams;
                            }


                            $comName = $tComSpec['comName'] . "_reverse";
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                            echo "sub preproc #$it: $comName, sending values <br>";

                            $mdlName = "Pre" . ucfirst($comName);
                            $this->CI->load->model("Preprocs/" . $mdlName);
                            $m = new $mdlName($resultParams);

                            if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                $tobeExecuted = true;
                            }
                            else {
                                $tobeExecuted = false;
                            }

                            if ($tobeExecuted) {
                                $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                $gotParams = $m->exec();
                            }
                            else {
                                cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                            }
                        }
                    }
                }
            }
            else {
                cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
            }
            //rollback postproc, master
            if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "rollback main post-processor: $comName<br>";

                        $dSpec = $this->cCodeData[$cCode][$srcGateName];
                        $tmpOutParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['loop'][$key] = $realValue;

                            }
                        }
                        if (isset($tComSpec['static'])) {
                            //cekHere("DISINI OIII");
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['static'][$key] = $realValue;

                            }
                            if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                $tmpOutParams['static']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                $tmpOutParams['static']["transaksi_no"] = $insertNum;
                            }

                            $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();


                        }
                        if (isset($tComSpec['static2'])) {
                            //cekHere("DISINI OIII");
                            foreach ($tComSpec['static2'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                $tmpOutParams['static2'][$key] = $realValue;

                            }
                            if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                $tmpOutParams['static2']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                            }

                            $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                        }


                        if (array_key_exists($oriComName, $postConfigs)) {
                            if (sizeof($postConfigs[$oriComName]) > 0) {
                                foreach ($postConfigs[$oriComName] as $key) {
                                    $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                    cekbiru("oldVal: $oldVal");
                                    $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                    cekHijau("newVal: $newVal");
                                    //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                    $tmpOutParams['static'][$key] = $newVal;
                                }
                            }
                        }

                        //lgShowError("Ada kesalahan",);
                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();

                        cekBiru("kiriman rollback main-postproc $comName");
                        arrPrint($tmpOutParams);
                        $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                    }
                }
            }
            else {
                cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
            }
            //rollback postproc, detail
            if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {
                $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "rollback sub-postProcessor: $comName, initializing values <br>";
                        //                arrPrint($this->cCodeData[$cCode][$srcGateName]);
                        $tmpOutParams[$cCtr] = array();
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                            $subParams = array();
                            if (isset($tComSpec['loop'])) {
                                foreach ($tComSpec['loop'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                    $subParams['loop'][$key] = $realValue;

                                }
                            }
                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                    $subParams['static'][$key] = $realValue;
                                    //                                cekBiru("$key diisi dengan $realValue");

                                }

                                if (array_key_exists($oriComName, $postConfigs)) {
                                    //                                cekhitam("terdapat di dalam postConfig");
                                    if (sizeof($postConfigs[$oriComName]) > 0) {
                                        foreach ($postConfigs[$oriComName] as $key) {
                                            //                                        $replVal=makeValue($src,$this->cCodeData[$cCode][$srcGateName][$cnt],$this->cCodeData[$cCode][$srcGateName][$cnt],0);
                                            //                                        cekbiru("$key akan direplace dengan nilai $replVal");
                                            //                                        $subParams['static'][$key]=$replVal;

                                            $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                            cekbiru("oldVal2: $oldVal");
                                            $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                            cekHijau("newVal2: $newVal");
                                            $subParams['static'][$key] = $newVal;
                                            //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                            //                                        $tmpOutParams['static'][$key]=$newVal;
                                        }
                                    }
                                }
                                else {
                                    //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                }

                                //                            $subParams['static']["transaksi_id"] = $insertID;
                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $no;
                                }
                                if (!isset($subParams['static']["transaksi_no"])) {
                                    $subParams['static']["transaksi_no"] = $no;
                                }
                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = "rollback of $no";
                            }


                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr][] = $subParams;
                            }
                        }
                    }

                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "sub-postProcessor: $comName, sending values <br>";

                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();


                        cekBiru("kiriman rollback detail-postproc $comName");
                        arrPrint($tmpOutParams[$cCtr]);
                        $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    }
                }
            }
            else {
                cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
            }


            //region cancel transaksi yang stanby di pihak ke-2
            $tb = new MdlTransaksi();
            $tb->setFilters(array());
            $tb->addFilter("id_master='" . $tmpTr[0]->id_master . "'");
            $tb->addFilter("jenis_master='$connector'");
            $trTmp = $tb->lookupAll()->result();
            if (sizeof($trTmp) > 0) {

                $connectorID = $trTmp[0]->id;
                if ($connectorID > 0) {

                    $tb = new MdlTransaksi();
                    $tb->setFilters(array());
                    $dupState = $tb->updateData(array(
                        "id" => $connectorID,
                    ), array(
                        "status_4" => "11",
                        "trash_4" => "1",
                        "cancel_dtime" => date("Y-m-d H:i:s"),
                        "cancel_name" => my_name(),
                        "cancel_id" => my_id(),

                    )) or die("Failed to update tr next-state!");

                    cekHitam("UPDATE transaksi connector -- selanjutnya yang digenerate by system");
                    cekHitam($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                    $to = new MdlTransaksi();
                    $to->setFilters(array());
                    $to->setTableName($to->getTableNames()['detail']);
                    $dupState = $to->updateData(array(
                        "transaksi_id" => $connectorID,
                    ), array(
                        "next_substep_code" => "",
                        "next_substep_label" => "",
                        "next_subgroup_code" => "",
                        "next_substep_num" => 0,
                        //            "sub_step_current" => 0,
                        "sub_step_number" => 0,
                    )) or die("Failed to update tr next-state!");

                    cekHitam("UPDATE transaksi data connector -- selanjutnya yang digenerate by system");
                    cekHitam($this->CI->dblast_query() . " [" . $this->CI->dbaffected_rows() . "]");
                }
            }
            //endregion

        }
        else {
            cekUngu(":: CHECK CONNECTING MUNDUR :: $jenisTr ::");

//            $origTCode = heGetOriginTCode_orig($jenisTr); // mencari transaksi yang connecto 110
            $origTCode = heGetOriginTCode_orig_he_stepping($jenisTr, $this->configUi); // mencari transaksi yang connecto ke $jenisTr
            cekMerah("origTCode: $origTCode");

            if (strlen($origTCode) > 2) {
                cekMerah("origTCode: $origTCode, ADA CONNECTING MUNDUR...");
                cekBiru("bila tidak normal, yang membatalkan pihak target/tujuan...");
                cekBiru("dan ada connecting ke belakang...");
                cekKuning("[$origTCode] step transaksi ini " . $thisStepNumber);

                if ($thisStepNumber == 1) {

                    //region transaksi connector -> 583 / 759
                    $arrSteps = isset($this->configUiModul[$origTCode]["steps"]) ? $this->configUiModul[$origTCode]["steps"] : "";
                    $lastCode = $origTCode;
                    if (sizeof($arrSteps) > 0) {
                        foreach ($arrSteps as $stSpec) {
                            $lastCode = $stSpec["target"];
                        }
                    }
                    if (sizeof($rejectException) > 0 && (!in_array($lastCode, $rejectException["code"]))) {
                        $tb = new MdlTransaksi();
                        $tb->setFilters(array());
                        $tb->addFilter("id_master='" . $tmpTr[0]->id_master . "'");
                        $tb->addFilter("jenis_master='$origTCode'");
                        $tb->addFilter("jenis='$lastCode'");
                        $tb->setSortBy(array("kolom" => "id", "mode" => "DESC"));
                        $trTmp = $tb->lookupAll()->result();
                    }
                    else {
                        $trTmp = array();
                    }
                    cekHere($this->CI->db->last_query() . " --> [" . count($trTmp) . "]");

                    if (sizeof($trTmp) > 0) {
                        cekHere(":: BENER BENER CONNECTING ANTAR INSTANSI - PUSAT -> CABANG ::");

                        $jenisTr = $origTCode;
                        $stepNumCurrent = $trTmp[0]->step_number;

                        cekHere("jenisTR $jenisTr, idTR " . $trTmp[0]->id);


                        //region swap from registry
                        $tr = new MdlTransaksi();
                        $tmpReg = $tr->lookupDataRegistriesByMasterID($trTmp[0]->id)->result();
                        cekmerah($this->CI->db->last_query());
                        if (sizeof($tmpReg) > 0) {
                            foreach ($tmpReg as $row) {
                                foreach ($row as $key_reg => $val_reg) {
                                    if ($key_reg != "transaksi_id") {
                                        $var = $key_reg;
                                        $$var = unserialize(base64_decode($val_reg));
                                    }
                                }
                            }
                        }
                        //        arrPrint($items);
                        //endregion

                        $nextMasterStep = $stepNumCurrent;
                        $nextProp = array(
                            "num" => $nextMasterStep,
                            "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                            "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                            "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
                        );
                        echo __LINE__ . " :: nextMasterStep: $nextMasterStep<br>";
                        arrPrint($nextProp);

                        $arrData = array(
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],
                            "next_step_num" => $nextProp["num"],
                            "step_current" => $masterTargetStepNum,
                            "step_number" => $childTargetStepNum,
                            "trash_4" => "1",
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),
                        );
                        $arrData_detail = array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            //            "sub_step_current" => 0,
                            "sub_step_number" => 0,
                        );

                        //region update step transaksi connector dan TOP-nya
                        if (sizeof($trTmp) > 0) {
                            cekUngu(":: trID -> " . $trTmp[0]->id);

                            //region update transaksi connector-nya
                            $prevID = $trTmp[0]->id;
                            $tc = new MdlTransaksi();
                            $tc->setFilters(array());
                            $dupState = $tc->updateData(array(
                                "id" => $prevID,
                            ), $arrData) or die("Failed to update tr next-state!");
                            cekKuning("UPDATE transaksi connector...");
                            cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                            $mongListUpadte['update']["main"][] = array(
                                "where" => array(
                                    "id" => $prevID,
                                ),
                                "value" => $arrData,
                            );
                            $td = new MdlTransaksi();
                            $td->setFilters(array());
                            $rslt = $td->lookupJoinedByID($prevID)->result();
                            if (sizeof($rslt) > 0) {
                                foreach ($rslt as $rsltSpec) {
                                    if (array_key_exists($rsltSpec->produk_id, $items)) {
                                        $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];

                                        if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                            $new_valid_qty = $rsltSpec->valid_qty;
                                            //                                mati_disini("undo/reject/delete gagal karena valid_qty melebihi produk_ord_jml");
                                        }
                                        else {
                                            $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                        }


                                        $arrData_detail["valid_qty"] = $new_valid_qty;
                                        $arrData_detail["sub_step_number"] = 0;
                                        $tr = new MdlTransaksi();
                                        $tr->setFilters(array());
                                        $tr->setTableName($tr->getTableNames()['detail']);
                                        $dupState = $tr->updateData(array(
                                            "transaksi_id" => $prevID,
                                            "produk_id" => $rsltSpec->produk_id,
                                        ), $arrData_detail) or die("Failed to update tr next-state!");
                                        $mongListUpadte['update']['detail'][] = array(
                                            "where" => array(
                                                "transaksi_id" => $prevID,
                                                "produk_id" => $rsltSpec->produk_id,
                                            ),
                                            "value" => $arrData_detail,
                                        );
                                        cekKuning("UPDATE transaksi data...");
                                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                                    }
                                }
                            }
                            //endregion


                            //region update transaksi ID TOP, transaksi induk-nya
                            $arrData = array(
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],
                                "next_step_num" => $nextProp["num"],
                                //                            "step_current" => $masterTargetStepNum,
                                //                            "step_number" => $masterTargetStepNum,
                                //                            "trash_4" => "1",
                                "step_current" => $nextProp["num"] - 1,
                                "step_number" => $nextProp["num"] - 1,
                            );
                            $arrData_detail = array(
                                "next_substep_code" => $nextProp["code"],
                                "next_substep_label" => $nextProp["label"],
                                "next_subgroup_code" => $nextProp["groupID"],
                                "next_substep_num" => $nextProp["num"],
                                //                            "sub_step_current" => $masterTargetStepNum,
                                //                            "sub_step_number" => $masterTargetStepNum,
                                "sub_step_current" => $nextProp["num"] - 1,
                                "sub_step_number" => $nextProp["num"] - 1,
                            );
                            $prevID = $trTmp[0]->id_top;
                            $tc = new MdlTransaksi();
                            $tc->setFilters(array());
                            $dupState = $tc->updateData(array(
                                "id" => $prevID,
                            ), $arrData) or die("Failed to update tr next-state!");
                            $mongListUpadte['update']["main"][] = array(
                                "where" => array("id" => $prevID,),
                                "value" => $arrData,
                            );
                            cekLime("UPDATE transaksi 1 step sebelumnya...");
                            cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                            $td = new MdlTransaksi();
                            $td->setFilters(array());
                            $rslt = $td->lookupJoinedByID($prevID)->result();
                            if (sizeof($rslt) > 0) {
                                foreach ($rslt as $rsltSpec) {
                                    if (array_key_exists($rsltSpec->produk_id, $items)) {
                                        $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];

                                        if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                            $new_valid_qty = $rsltSpec->valid_qty;
                                            //                                mati_disini("undo/reject/delete gagal karena valid_qty melebihi produk_ord_jml");
                                        }
                                        else {
                                            $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                        }


                                        $arrData_detail["valid_qty"] = $new_valid_qty;
                                        $tr = new MdlTransaksi();
                                        $tr->setFilters(array());
                                        $tr->setTableName($tr->getTableNames()['detail']);
                                        $dupState = $tr->updateData(array(
                                            "transaksi_id" => $prevID,
                                            "produk_id" => $rsltSpec->produk_id,
                                        ), $arrData_detail) or die("Failed to update tr next-state!");
                                        $mongListUpadte['update']['detail'][] = array(
                                            "where" => array(
                                                "transaksi_id" => $prevID,
                                                "produk_id" => $rsltSpec->produk_id,
                                            ),
                                            "value" => $arrData_detail,
                                        );
                                        cekLime("UPDATE transaksi data...");
                                        cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                                    }
                                }
                            }
                            //endregion


                        }

                        //endregion

                        //region sesuaikan signature untuk cloningan, ikut minus
                        //        $dwsign = $tr->writeSignature($no, array(
                        $dwsign = $tb->writeSignature($trTmp[0]->id, array(
                            "prev_id" => $trTmp[0]->id,
                            "nomer" => "rejection",
                            "step_number" => $childTargetStepNum, // ini minus step number
                            "step_code" => $this->configUiModul[$origTCode]["steps"][abs($childTargetStepNum)]["target"],
                            "step_name" => $this->configUiModul[$origTCode]["steps"][abs($childTargetStepNum)]["label"],
                            "group_code" => $this->configUiModul[$origTCode]["steps"][abs($childTargetStepNum)]['userGroup'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "keterangan" => $this->configUiModul[$origTCode]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                            //            "transaksi_id" => $no,
                        )) or die("Failed to write signature");
                        $mongoList['sign'][] = $dwsign;
                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        //endregion

                        // region netralisasi payment source
                        $tr = New MdlTransaksi();
                        $tr->setFilters(array());
                        $tr->addFilter("sisa>0");
                        $paymentSrc = $tr->lookupPaymentSrcByTransID($trTmp[0]->id)->result();
                        cekBiru($this->CI->db->last_query());
                        if (sizeof($paymentSrc) > 0) {
                            //            arrPrint($paymentSrc);
                            foreach ($paymentSrc as $pSpec) {
                                if ($pSpec->terbayar == 0) {
                                    $where = array(
                                        "id" => $pSpec->id,
                                        "transaksi_id" => $pSpec->transaksi_id,
                                    );
                                    $data = array(
                                        "sisa" => 0,
                                        "returned" => $pSpec->sisa,
                                        "sisa_valas" => 0,
                                        "returned_valas" => $pSpec->sisa_valas,
                                    );

                                    $tra = New MdlTransaksi();
                                    $tra->setFilters(array());
                                    $tra->updatePaymentSrc($where, $data);
                                    cekUngu(":: mereject payment source bila ada...");
                                    cekUngu($this->CI->db->last_query());
                                }
                                else {
                                    mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                                }
                            }
                        }
                        else {
                            cekBiru(":: tidak ada payment source... ::");
                        }
                        // endregion netralisasi payment source

                        // region netralisasi extended step
                        $tr = New MdlTransaksi();
                        $tr->setFilters(array());
                        $exTmp = $tr->lookupExtStepByTrID($trTmp[0]->id);
                        if (sizeof($exTmp) > 0) {
                            foreach ($exTmp as $exSpec) {
                                $tra = New MdlTransaksi();
                                $tra->setFilters(array());
                                $tra->rejectExtStepByID($exSpec["id"]);
                                $mongListUpadte['update']['extra'][] = array(
                                    "where" => array(
                                        "id" => $exSpec["id"],
                                    ),
                                    "value" => array(
                                        "state" => "-1",
                                    ),
                                );
                                cekUngu(":: mereject extended step bila ada...");
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        else {
                            cekBiru(":: tidak ada extended step... ::");
                        }

                        // endregion netralisasi extended step

                        //==entry point
                        if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                            if (isset($this->configUiJenis["connectToReject"][$stepNumCurrent])) {
                                if ($this->configUiJenis["connectToReject"][$stepNumCurrent]["enabled"] == true) {
                                    $masterID = $currentMasterID;
                                    $connecTo = $this->configUiJenis["connectToReject"][$stepNumCurrent]["connectTo"];
                                    cekHijau("START menjalankan REJECT... [$masterID] [$connecTo]");
                                    if ($connecTo == NULL) {
                                        mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                                    }
                                    $oldCode = $cCode;
                                    $cCode = "_TR_" . $connecTo;
                                    $this->cCodeData[$cCode] = array(
                                        "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                                        "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                                        "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                                        "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                                        "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                                        "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                                        "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                                        "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                                        "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                                        "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                                        "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                                        'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                                        'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                                        'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                                        'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                                        'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                                        'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                                        'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                                        'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                                        "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                                        "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                                        'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                                        'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                                        'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                                        'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                                        'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                                        'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                                        'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                                        'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                                        'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                                        'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                                        'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                                        'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                        'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                        "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                        "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                        "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                        "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                        "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                        "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                        "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                        "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                        "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                                        "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                                        "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                                        "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                                        "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                                    );
                                    // masuk ke gerbang TableInMaster, tabel transaksi
                                    $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                                        "jenis_master" => $this->jenisTr,
                                        "jenis_top" => $connecTo,
                                        "jenis" => $connecTo,
                                        "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                        "transaksi_jenis" => $connecTo,
                                        "step_avail" => 1,
                                        "step_current" => 1,
                                        "step_number" => 1,
                                        "next_step_code" => "",
                                        "next_step_label" => "",
                                        "next_group_code" => "",
                                        "next_step_num" => "0",
                                        "trash_4" => 1,
                                        "cancel_dtime" => date("Y-m-d H:i:s"),
                                        "cancel_name" => my_name(),
                                        "cancel_id" => my_id(),
                                        "deskripsi" => "rejection",
                                        "oleh_id" => my_id(),
                                        "oleh_nama" => my_name()
                                    );
                                    // masuk ke gerbang main
                                    $masterReplacersO = array(
                                        "stepCode" => $connecTo,
                                        "jenisTrTop" => $connecTo,
                                        "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
//                        "inv" => $tmpNomorNota,
                                        "jenis_master" => $this->jenisTr,
                                        "jenis_top" => $connecTo,
                                        "jenis" => $connecTo,
                                        "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                        "transaksi_jenis" => $connecTo,
                                        "stepCode" => $connecTo,
                                        "jenisTrTop" => $connecTo,
                                        "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                        "step_avail" => 1,
                                        "step_current" => 1,
                                        "step_number" => 1,
                                        "next_step_code" => "",
                                        "next_step_label" => "",
                                        "next_group_code" => "",
                                        "next_step_num" => "0",
                                        "olehID" => my_id(),
                                        "olehName" => my_name()
                                    );
                                    foreach ($masterReplacersO as $key => $val) {
                                        $this->cCodeData[$cCode]["main"][$key] = $val;
                                    }
                                    foreach ($masterReplacers as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                    }

                                    $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                                    $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];

                                    //region penomoran receipt
                                    $this->CI->load->model("CustomCounter");
                                    $cn = new CustomCounter("transaksi");
                                    $cn->setType("transaksi");
                                    $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaReject']);
                                    if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersReject'])) {
                                        die(__LINE__ . " Used number should be registered in counters config as well");
                                    }
                                    echo "<div style='background:#ff7766;'>";
                                    foreach ($counterForNumber as $i => $cRawParams) {
                                        $cParams = explode("|", $cRawParams);
                                        $cValues = array();
                                        foreach ($cParams as $param) {
                                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                        }
                                        $cRawValues = implode("|", $cValues[$i]);
                                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                    }
                                    echo "</div style='background:#ff7766;'>";

                                    $stepNumber = 1;
                                    $tmpNomorNota = $paramSpec["paramString"];
                                    $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                                    $nextProp = array(
                                        "num" => 0,
                                        "code" => "",
                                        "label" => "",
                                        "groupID" => "",
                                    );
                                    //endregion

                                    //region dynamic counters
                                    // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                                    $cn = new CustomCounter("transaksi");
                                    $cn->setType("transaksi");
                                    $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersReject'];
                                    arrPrintHijau($configCustomParams);
                                    $configCustomParams[] = "stepCode";
                                    //arrPrint($configCustomParams);
                                    if (sizeof($configCustomParams) > 0) {
                                        $cContent = array();
                                        foreach ($configCustomParams as $i => $cRawParams) {
                                            $cParams = explode("|", $cRawParams);
                                            $cValues = array();
                                            foreach ($cParams as $param) {
                                                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                            }
                                            $cRawValues = implode("|", $cValues[$i]);
                                            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                            $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                                            switch ($paramSpec["id"]) {
                                                case 0: //===counter type is new
                                                    $addData = array(
                                                        "toko_id" => $tokoID,
                                                        "toko_nama" => $tokoNama,
                                                    );
                                                    $paramKeyRaw = print_r($cParams, true);
                                                    $paramValuesRaw = print_r($cValues[$i], true);
                                                    $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                                    break;
                                                default: //===counter to be updated
                                                    $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                                    break;
                                            }
                                            //echo "<hr>";
                                        }
                                    }
                                    $appliedCounters = base64_encode(serialize($cContent));
                                    $appliedCounters_inText = print_r($cContent, true);
                                    //mati_disini();
//arrPrintPink($cContent);
                                    //
                                    //region addition on master


                                    $addValues = array(
                                        "counters" => $appliedCounters,
                                        'counters_intext' => $appliedCounters_inText,
                                        'nomer' => $tmpNomorNota,
                                        'nomer2' => $tmpNomorNotaAlias,
                                        'dtime' => date("Y-m-d H:i:s"),
                                        'fulldate' => date("Y-m-d"),
                                        "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                        "step_number" => 1,
                                        "step_current" => 1,
                                        "next_step_num" => $nextProp["num"],
                                        "next_step_code" => $nextProp["code"],
                                        "next_step_label" => $nextProp["label"],
                                        "next_group_code" => $nextProp["groupID"],
                                        "tail_number" => 1,
                                        "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                                    );
                                    foreach ($addValues as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                    }
                                    //endregion

                                    //
                                    //region addition on detail
                                    $addSubValues = array(
                                        "sub_step_number" => 1,
                                        "sub_step_current" => 1,
                                        "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                        "next_substep_num" => $nextProp["num"],
                                        "next_substep_code" => $nextProp["code"],
                                        "next_substep_label" => $nextProp["label"],
                                        "next_subgroup_code" => $nextProp["groupID"],
                                        "sub_tail_number" => 1,
                                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                                    );
                                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                                        foreach ($addSubValues as $key => $val) {
                                            $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                                        }
                                    }
                                    //endregion
                                    // </editor-fold>
                                    //endregion

                                    //region numbering tambahan
                                    $this->CI->load->library("CounterNumber");
                                    $ccn = new CounterNumber();
                                    $ccn->setCCode($cCode);
                                    $ccn->setJenisTr($this->jenisTr);
                                    $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                                    $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                                    $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                                    $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                                    $new_counter = $ccn->getCounterNumber();
                                    cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                                    if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                                        foreach ($new_counter["main"] as $ckey => $cval) {
                                            $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                                            $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                                        }
                                    }
                                    if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                                        foreach ($new_counter["items"] as $ikey => $iSpec) {
                                            foreach ($iSpec as $iikey => $iival) {
                                                $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                                            }
                                        }
                                    }
                                    if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                                        foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                                            foreach ($iSpec as $iikey => $iival) {
                                                $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                                            }
                                        }
                                    }
                                    //endregion

                                    $addValues = array(
                                        "counters" => $appliedCounters,
                                        'counters_intext' => $appliedCounters_inText,
                                        'nomer' => $tmpNomorNota,
                                        'nomer2' => $tmpNomorNotaAlias,
                                        'dtime' => date("Y-m-d H:i:s"),
                                        'fulldate' => date("Y-m-d"),
                                    );
                                    foreach ($addValues as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                    }
                                    $masterReplacers = array(
                                        "nomer" => $tmpNomorNota,
                                        "nomer2" => $tmpNomorNotaAlias,
                                        "counters" => $appliedCounters,
                                        "counters_intext" => $appliedCounters_inText,
                                    );
                                    foreach ($masterReplacers as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                    }
                                    $detailReplacers = array(
                                        "sub_step_avail" => 1,
                                        "sub_step_current" => 1,
                                        "sub_step_number" => 1,
                                        "next_substep_num" => "",
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                    );
                                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                                            foreach ($dSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                                            }
                                        }
                                    }
                                    $itemsReplacers = array(
                                        "next_substep_num" => "",
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                    );
                                    if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                                        foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                                            foreach ($dSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                                            }
                                        }
                                    }

                                    //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                                    if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                                        $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                                        $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 1;// dibatalkan
                                        $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;

                                        $tr = new MdlTransaksi();
                                        $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                                        $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                                        cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                                        $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                                        $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                                        $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                                        if ($insertID < 1) {
                                            die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                                        }
                                        $mongoList["main"] = array($insertID, $epID);
                                        //==transaksi_id dan nomor nota diinject kan ke gate utama
                                        $injectors = array(
                                            "transaksi_id" => $insertID,
                                            "nomer" => $tmpNomorNota,
                                            "nomer2" => $tmpNomorNotaAlias,
                                        );
                                        $arrInjectorsTarget = array(
                                            "items",
                                            "items2_sum",
                                            "rsltItems",
                                        );
                                        foreach ($injectors as $key => $val) {
                                            $this->cCodeData[$cCode]["main"][$key] = $val;
                                            foreach ($arrInjectorsTarget as $target) {
                                                if (isset($this->cCodeData[$cCode][$target])) {
                                                    foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                                        $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                                        if (isset($this->cCodeData[$cCode][$target][$id])) {
                                                            $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        //===signature
                                        $dwsign = $tr->writeSignature($insertID, array(
                                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                            "step_number" => 1,
                                            "step_code" => $connecTo,
                                            "step_name" => $this->configUiJenis["connectToEdit"][1]["label"],
                                            "group_code" => "",
                                            "oleh_id" => my_id(),
                                            "oleh_nama" => my_name(),
                                            "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                                            "transaksi_id" => $masterID,
                                            "deskripsi" => "edit transaksi",
                                            "cabang_id" => my_cabang_id(),
                                            "cabang_nama" => my_cabang_nama(),
                                            "current_transaksi_id" => $masterID,
                                            "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                        )) or die("Failed to write signature");
                                        showLast_query("kuning");
                                        $mongoList['sign'][] = $dwsign;
                                        $idHis = array(
                                            $stepNumber => array(
                                                "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                                "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                                "step" => $stepNumber,
                                                "trID" => $insertID,
                                                "nomer" => $tmpNomorNota,
                                                "nomer2" => $tmpNomorNotaAlias,
                                                "counters" => $appliedCounters,
                                                "counters_intext" => $appliedCounters_inText,
                                            ),
                                        );
                                        $idHis_blob = blobEncode($idHis);
                                        $idHis_intext = print_r($idHis, true);
                                        $tr = new MdlTransaksi();
                                        $dupState = $tr->updateData(array("id" => $insertID), array(
                                            "next_step_num" => $nextProp["num"],
                                            "next_step_code" => $nextProp["code"],
                                            "next_step_label" => $nextProp["label"],
                                            "next_group_code" => $nextProp["groupID"],

                                            //===references
//                            "id_master" => $insertID,
                                            "id_master" => $masterID,// milik transkasiID yang diedit
                                            "id_top" => $insertID,
                                            "ids_prev" => "",
                                            "ids_prev_intext" => "",
                                            "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                            "nomers_prev" => "",
                                            "nomers_prev_intext" => "",
                                            "jenises_prev" => "",
                                            "jenises_prev_intext" => "",
                                            "ids_his" => $idHis_blob,
                                            "ids_his_intext" => $idHis_intext,

                                        )) or die("Failed to update tr next-state!");
                                        cekHijau($this->CI->db->last_query());

                                        $addValues = array(
                                            //===references
                                            "id_master" => $insertID,
                                            "id_top" => $insertID,
                                            "ids_prev" => "",
                                            "ids_prev_intext" => "",
                                            "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                            "nomers_prev" => "",
                                            "nomers_prev_intext" => "",
                                            "jenises_prev" => "",
                                            "jenises_prev_intext" => "",
                                            "ids_his" => $idHis_blob,
                                            "ids_his_intext" => $idHis_intext,
                                        );
                                        foreach ($addValues as $key => $val) {
                                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                        }

                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                                        $inserMainValues = array();
                                        if (isset($this->configCore[$this->jenisTr]["tableIn"]['mainValues'])) {
                                            //matiHEre("hooppp");
                                            $inserMainValues = array();
                                            foreach ($this->configCore[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                                if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                                    $dd = $tr->writeMainValues($insertID, array(
                                                        "key" => $key,
                                                        "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                                    ));

                                                    $inserMainValues[] = $dd;
                                                    $mongoList['mainValues'][] = $dd;
                                                }
                                            }
                                        }

                                        if (sizeof($inserMainValues) > 0) {
                                            $arrBlob = blobEncode($inserMainValues);
                                            $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                        }

                                    }
                                    if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                                        $inserMainValues = array();
                                        foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                                            $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                            $inserMainValues[] = $dd;
                                            $mongoList['mainValues'][] = $dd;
                                        }

                                        if (sizeof($inserMainValues) > 0) {
                                            $arrBlob = blobEncode($inserMainValues);
                                            $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                                        foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                                            $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                            //                    cekkuning("making a clone for input key $key / $val");
                                            //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                                            //                    $replacers=array(
                                            //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                                            //                    );
                                            //                    foreach($replacers as $key=>$val){
                                            //                        $tmpTableIn[$key]=$val;
                                            //                    }
                                            //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                                        foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                                            $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                                        foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                                            $tr->writeMainApplets($insertID, array(
                                                "mdl_name" => $amdl,
                                                "key" => $aSpec['key'],
                                                "label" => $aSpec['labelValue'],
                                                "description" => $aSpec['description'],
                                            ));
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                                        foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                                            $tr->writeMainElements($insertID, array(
                                                "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                                "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                                "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                                "name" => $aSpec['name'],
                                                "label" => $aSpec["label"],
                                                "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                                "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                                            ));
                                            //==nebeng bikin inputLabels
//                                $currentValue = "";
//                                switch ($aSpec['elementType']) {
//                                    case "dataModel":
//                                        $currentValue = $aSpec['key'];
//                                        break;
//                                    case "dataField":
//                                        $currentValue = $aSpec["value"];
//                                        break;
//                                }
//                                if (array_key_exists($elName, $relOptionConfigs)) {
//                                    //					cekhijau("$eName terdaftar pada relInputs");
//
//
//                                    if (isset($relOptionConfigs[$elName][$currentValue])) {
//                                        if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
//                                            foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
//                                                $inputLabels[$oValueName] = $oValSpec["label"];
//                                                if (isset($oValSpec['auth'])) {
//                                                    if (isset($oValSpec['auth']["groupID"])) {
//                                                        $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
//                                                    }
//                                                }
//                                            }
//                                        }
//                                    }
//                                    else {
//                                        //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
//                                    }
//
//                                }

                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {

                                        $insertIDs = array();
                                        $insertDeIDs = array();
                                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                                            $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                            if ($insertDetailID < 1) {
                                                die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                                            }
                                            else {
                                                $insertIDs[] = $insertDetailID;
                                                $insertDeIDs[$insertID][] = $insertDetailID;
                                                $mongoList['detail'][] = $insertDetailID;
                                            }
                                            if ($epID != 999) {
                                                $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                                if ($insertEpID < 1) {
                                                    die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                                }
                                                else {
                                                    $insertIDs[] = $insertEpID;
                                                    $insertDeIDs[$epID][] = $insertEpID;
                                                    $mongoList['detail'][] = $insertEpID;
                                                }
                                            }
                                            cekUngu($this->CI->db->last_query());
                                        }


                                        if (sizeof($insertIDs) == 0) {
                                            die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                                        }
                                        else {
                                            $indexing_details = array();
                                            foreach ($insertDeIDs as $key => $numb) {
                                                $indexing_details[$key] = $numb;
                                            }

                                            foreach ($indexing_details as $k => $arrID) {
                                                $arrBlob = blobEncode($arrID);
                                                $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                                cekOrange($this->CI->db->last_query());
                                            }
                                        }
                                    }
                                    else {
                                        die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                                        $insertIDs = array();
                                        foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                                            $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                                            $mongoList['detail'] = $insertIDs;
                                            if ($epID != 999) {
                                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                                $mongoList['detail'] = $insertIDs;
                                            }
                                            cekUngu($this->CI->db->last_query());
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                                        $insertIDs = array();
                                        foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                                            $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                            $insertIDs[] = $insertDetailID;
                                            $mongoList['detail'][] = $insertDetailID;
                                            if ($epID != 999) {
                                                $dd = $tr->writeDetailEntries($epID, $dSpec);
                                                $insertIDs[] = $dd;
                                                $mongoList['detail'][] = $dd;
                                            }
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                                        $insertIDs = array();
                                        foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                                            $dd = $tr->writeDetailEntries($insertID, $dSpec);
                                            $insertIDs[] = $dd;
                                            $mongoList['detil'][] = $dd;
                                            if ($epID != 999) {
                                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                                $mongoList['detil'] = $insertIDs;
                                            }
                                            cekUngu($this->CI->db->last_query());
                                        }
                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {

                                        $insertIDs = array();
                                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                                            if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues'])) {
                                                foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                                    if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                                        $dd = $tr->writeDetailValues($insertID, array(
                                                            "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                                            "produk_id" => $pID,
                                                            "key" => $key,
                                                            "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                                        ));
                                                        $insertIDs[$pID][] = $dd;
                                                        $mongoList['detailValues'][] = $dd;

                                                    }
                                                }
                                            }
                                        }

                                        if (sizeof($insertIDs) > 0) {
                                            $arrBlob = blobEncode($insertIDs);
                                            $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                                        }

                                    }
                                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                                            if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                                $insertIDs = array();
                                                foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                                    $dd = $tr->writeDetailValues($insertID, array(
                                                        "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                                        "produk_id" => $pID,
                                                        "key" => $key,
                                                        "value" => $dSpec[$src],
                                                    ));
                                                    $insertIDs[] = $dd;
                                                    $mongoList['detailValues'][] = $dd;
                                                }
                                            }
                                        }
                                    }
                                    //endregion

                                    $baseRegistries = array(
                                        "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                                        "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                                        "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                                        "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                                        "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                                        "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                                        "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                                        "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                                        "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                                        "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                                        "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                                        'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                                        'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                                        'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                                        'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                                        'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                                        'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                                        'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                                        'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                                        "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                                        "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                                        'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                                        'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                                        'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                                        'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                                        'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                                        'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                                        'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                                        'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                                        'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                                        'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                                        'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                                        'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                        'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                        "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                        "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                        "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                        "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                        "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                        "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                        "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                        "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                        "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                                        "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                                        "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                                        "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                                        "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                                        //----
                                        'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                                        'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                                        //----
                                    );
                                    $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                                    showLast_query("hijau");
                                    cekHijau("SELESAI menjalankan EDITOR...");
                                }
                            }
                            else {
                                $tableIn_master['trash_4'] = 1;
                                $tableIn_master['cancel_id'] = my_id();
                                $tableIn_master['cancel_name'] = my_name();
                                $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                                $tableIn_master['deskripsi'] = "rejection";
                                $epID = $tr->writeMainEntries_entryPoint($trTmp[0]->id, $tableIn_master['id_master'], $tableIn_master);
//                                $mongoList["main"][] = $epID;
                                if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                                    $insertIDs = array();
                                    foreach ($tableIn_detail as $dSpec) {
                                        if ($epID != 999) {
                                            $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
//                                            $mongoList['detail'] = $insertIDs;

                                        }
                                    }
                                }
                            }
                        }
                        cekKuning("stepNumCurrent -> $stepNumCurrent, jenisTR -> $jenisTr");
                        $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
                        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
                        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
                        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
                        $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();

                        //===if rollback is needed
                        //rollback preproc, master
                        if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                            $iterator = isset($core['preProcessor'][$jenisTr_component]['master']) ? $core['preProcessor'][$jenisTr_component]['master'] : array();
                            if (sizeof($iterator) > 0) {
                                $it = 0;
                                cekbiru("ada iterator pre-proc master");
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $it++;
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'] . "_reverse";
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                                    echo "reverse master-preproc: $comName, initializing values <br>";
                                    $tmpOutParams[$cCtr] = array();
                                    $subParams = array();

                                    if (isset($tComSpec['static'])) {
                                        foreach ($tComSpec['static'] as $key => $value) {
                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $subParams['static'][$key] = $realValue;
                                        }

                                        if (array_key_exists($oriComName, $prepConfigs)) {
                                            if (sizeof($prepConfigs[$oriComName]) > 0) {
                                                foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                    $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                                }
                                            }
                                        }

                                        if (!isset($subParams['static']["transaksi_id"])) {
                                            $subParams['static']["transaksi_id"] = $no;
                                        }


                                        $subParams['static']["fulldate"] = date("Y-m-d");
                                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                    }
                                    if (sizeof($subParams) > 0) {
                                        $tmpOutParams[$cCtr] = $subParams;
                                    }


                                    $mdlName = "Pre" . ucfirst($comName);
                                    $this->CI->load->model("Preprocs/" . $mdlName);
                                    $m = new $mdlName($resultParams);

                                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                        $tobeExecuted = true;
                                    }
                                    else {
                                        $tobeExecuted = false;
                                    }

                                    if ($tobeExecuted) {
                                        arrprint($tmpOutParams[$cCtr]);
                                        $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                        $gotParams = $m->exec();
                                    }
                                    else {
                                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                    }

                                }
                            }
                            else {
                                cekHitam(":: tidak ada config preproc master yang harus rollback ::");
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
                        }
                        //rollback preproc, detail
                        if (isset($core['preProcessor'][$jenisTr_component]['detail'])) {
                            //            cekbiru("ada config pre-proc detail $stepNumCurrent");
                            $iterator = isset($core['preProcessor'][$jenisTr_component]['detail']) ? $core['preProcessor'][$jenisTr_component]['detail'] : array();
                            //            arrprint($iterator);
                            if (sizeof($iterator) > 0) {
                                $it = 0;
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $it++;
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'] . "_reverse";
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "reverse preproc (detail): $comName, initializing values <br>";
                                    foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                                        $tmpOutParams[$cCtr] = array();
                                        //                        $id = $dSpec["id"];
                                        $id = $xid;
                                        $subParams = array();

                                        if (isset($tComSpec['static'])) {
                                            foreach ($tComSpec['static'] as $key => $value) {

                                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                                $subParams['static'][$key] = $realValue;

                                            }

                                            if (array_key_exists($oriComName, $prepConfigs)) {
                                                cekhitam("terdapat di dalam prepConfig");
                                                if (sizeof($prepConfigs[$oriComName]) > 0) {
                                                    foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                        $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                                    }
                                                }
                                            }
                                            else {
                                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                            }
                                            if (!isset($subParams['static']["transaksi_id"])) {
                                                $subParams['static']["transaksi_id"] = $no;
                                            }


                                            $subParams['static']["fulldate"] = date("Y-m-d");
                                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                            $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                        }

                                        if (sizeof($subParams) > 0) {

                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }


                                        $comName = $tComSpec['comName'] . "_reverse";
                                        $srcGateName = $tComSpec['srcGateName'];
                                        $srcRawGateName = $tComSpec['srcRawGateName'];
                                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                        echo "sub preproc #$it: $comName, sending values <br>";

                                        $mdlName = "Pre" . ucfirst($comName);
                                        $this->CI->load->model("Preprocs/" . $mdlName);
                                        $m = new $mdlName($resultParams);


                                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                            $tobeExecuted = true;
                                        }
                                        else {
                                            $tobeExecuted = false;
                                        }

                                        if ($tobeExecuted) {

                                            //                            arrprint($tmpOutParams[$cCtr]);

                                            $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                            $gotParams = $m->exec();

                                            //                            cekbiru("gotparams");
                                            //                            arrprint($gotParams);

                                        }
                                        else {
                                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                        }

                                    }
                                }
                            }
                            else {
                                cekHitam(":: tidak ada config preproc detail yang harus rollback ::");
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
                        }

                        //rollback postproc, master
                        if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                            $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                            if (sizeof($iterator) > 0) {
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "rollback main post-processor: $comName [$srcGateName]<br>";

                                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                                    $tmpOutParams = array();
                                    if (isset($tComSpec['loop'])) {
                                        foreach ($tComSpec['loop'] as $key => $value) {
                                            //                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $realValue = makeValue($value, $$srcGateName, $$srcGateName, 0);
                                            $tmpOutParams['loop'][$key] = $realValue;
                                        }
                                    }
                                    if (isset($tComSpec['static'])) {
                                        //cekHere("DISINI OIII");
                                        foreach ($tComSpec['static'] as $key => $value) {
                                            //                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $realValue = makeValue($value, $$srcGateName, $$srcGateName, 0);
                                            $tmpOutParams['static'][$key] = $realValue;
                                        }
                                        if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                            $tmpOutParams['static']["transaksi_id"] = $insertID;
                                        }
                                        if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                            $tmpOutParams['static']["transaksi_no"] = $insertNum;
                                        }

                                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                    }
                                    if (isset($tComSpec['static2'])) {
                                        //cekHere("DISINI OIII");
                                        foreach ($tComSpec['static2'] as $key => $value) {
                                            //                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                            $realValue = makeValue($value, $$srcGateName, $$srcGateName, 0);
                                            $tmpOutParams['static2'][$key] = $realValue;
                                        }
                                        if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                            $tmpOutParams['static2']["transaksi_id"] = $insertID;
                                        }
                                        if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                            $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                                        }

                                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                                    }


                                    if (array_key_exists($oriComName, $postConfigs)) {
                                        if (sizeof($postConfigs[$oriComName]) > 0) {
                                            foreach ($postConfigs[$oriComName] as $key) {
                                                $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                                cekbiru("oldVal: $oldVal");
                                                $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                cekHijau("newVal: $newVal");

                                                $tmpOutParams['static'][$key] = $newVal;
                                            }
                                        }
                                    }

                                    //lgShowError("Ada kesalahan",);
                                    $mdlName = "Com" . ucfirst($comName);
                                    $this->CI->load->model("Coms/" . $mdlName);
                                    $m = new $mdlName();

                                    cekBiru("kiriman rollback main-postproc $comName");
                                    arrPrint($tmpOutParams);
                                    $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                                }
                            }
                            else {
                                cekHitam(":: tidak ada config postproc master yang harus rollback ::");
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
                        }
                        //rollback postproc, detail

                        if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {
                            $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                            if (sizeof($iterator) > 0) {
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "rollback sub-postProcessor: $comName, initializing values <br>";

                                    $tmpOutParams[$cCtr] = array();
                                    foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                                        $subParams = array();
                                        if (isset($tComSpec['loop'])) {
                                            foreach ($tComSpec['loop'] as $key => $value) {
                                                $gateItems = $$srcGateName;
                                                //                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                                $realValue = makeValue($value, $gateItems[$cnt], $gateItems[$cnt], 0);
                                                $subParams['loop'][$key] = $realValue;
                                            }
                                        }
                                        if (isset($tComSpec['static'])) {
                                            foreach ($tComSpec['static'] as $key => $value) {
                                                $gateItems = $$srcGateName;
                                                //                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                                $realValue = makeValue($value, $gateItems[$cnt], $gateItems[$cnt], 0);
                                                $subParams['static'][$key] = $realValue;
                                            }

                                            if (array_key_exists($oriComName, $postConfigs)) {
                                                if (sizeof($postConfigs[$oriComName]) > 0) {
                                                    foreach ($postConfigs[$oriComName] as $key) {
                                                        $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                                        cekbiru("oldVal2: $oldVal");
                                                        $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                        cekHijau("newVal2: $newVal");
                                                        $subParams['static'][$key] = $newVal;
                                                    }
                                                }
                                            }
                                            else {
                                                //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                            }

                                            //                            $subParams['static']["transaksi_id"] = $insertID;
                                            if (!isset($subParams['static']["transaksi_id"])) {
                                                $subParams['static']["transaksi_id"] = $no;
                                            }
                                            if (!isset($subParams['static']["transaksi_no"])) {
                                                $subParams['static']["transaksi_no"] = $no;
                                            }
                                            $subParams['static']["fulldate"] = date("Y-m-d");
                                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                            $subParams['static']["keterangan"] = "rollback of $no";
                                        }


                                        if (sizeof($subParams) > 0) {
                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }
                                    }
                                }

                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "sub-postProcessor: $comName, sending values <br>";

                                    $mdlName = "Com" . ucfirst($comName);
                                    $this->CI->load->model("Coms/" . $mdlName);
                                    $m = new $mdlName();


                                    cekBiru("kiriman rollback detail-postproc $comName");
                                    arrPrint($tmpOutParams[$cCtr]);
                                    $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                }
                            }
                            else {
                                cekHitam(":: tidak ada config postproc detail yang harus rollback ::");
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
                        }


                        //region transaksi stanby di pihak tujuan...
                        $nextMasterStep = $stepNumCurrent_son;
                        $childTargetStepNum = $childTargetStepNum_con;
                        $jenisTr = $jenisTr_con;
                        $nextProp = array(
                            "num" => $nextMasterStep,
                            "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                            "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                            "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
                        );

                        //region swap from registry, transaksi yang dibuka saat ini
                        $tr = new MdlTransaksi();
                        $tmpReg = $tr->lookupDataRegistriesByMasterID($no)->result();
                        cekmerah($this->CI->db->last_query());
                        if (sizeof($tmpReg) > 0) {
                            foreach ($tmpReg as $row) {
                                foreach ($row as $key_reg => $val_reg) {
                                    if ($key_reg != "transaksi_id") {
                                        $var = $key_reg;
                                        $$var = unserialize(base64_decode($val_reg));
                                    }
                                }
                            }
                        }
                        //endregion

                        //region swap from main transaksi, transaksi yang dibuka saat ini
                        $tr = new MdlTransaksi();
                        $tr->setFilters(array());
                        $tr->addFilter("id='$no'");
                        $tmpTr = $tr->lookupMainTransaksi()->result();
                        cekOrange($this->CI->db->last_query());
                        //endregion

                        //region transaksi yang stanby di pihak ke-2
                        $tb = new MdlTransaksi();
                        $tb->setFilters(array());
                        $dupState = $tb->updateData(array(
                            "id" => $no,
                        ), array(
                            "status_4" => "11",
                            "trash_4" => "1",
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),

                        )) or die("Failed to update tr next-state!");
                        cekHitam("UPDATE transaksi yang stanby di pihak ke-2");
                        cekHitam($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                        $to = new MdlTransaksi();
                        $to->setFilters(array());
                        $to->setTableName($to->getTableNames()['detail']);
                        $dupState = $to->updateData(array(
                            "transaksi_id" => $no,
                        ), array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            //            "sub_step_current" => 0,
                            "sub_step_number" => 0,
                        )) or die("Failed to update tr next-state!");
//                        $mongListUpadte['update']["main"][] = array(
//                            "where" => array(
//                                "transaksi_id" => $no,
//                            ),
//                            "value" => array(
//                                "next_substep_code" => $nextProp["code"],
//                                "next_substep_label" => $nextProp["label"],
//                                "next_subgroup_code" => $nextProp["groupID"],
//                                "next_substep_num" => $nextProp["num"],
//                                //            "sub_step_current" => 0,
//                                "sub_step_number" => 0,
//                            ),
//                        );
                        cekHitam("UPDATE transaksi data yang stanby di pihak ke-2");
                        cekHitam($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        //endregion

                        //region sesuaikan signature untuk cloningan, ikut minus
                        //        $dwsign = $tr->writeSignature($no, array(
                        $dwsign = $tr->writeSignature($no, array(
                            "prev_id" => $no,
                            "nomer" => "rejection",
                            "step_number" => $childTargetStepNum, // ini minus step number
                            "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["target"],
                            "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"],
                            "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]['userGroup'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                        )) or die("Failed to write signature");
//                        $mongoList['sign'][] = $dwsign;
                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        //endregion

                        //==entry point
                        if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                            $tableIn_master['trash_4'] = 1;
                            $tableIn_master['cancel_id'] = my_id();
                            $tableIn_master['cancel_name'] = my_name();
                            $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                            $tableIn_master['deskripsi'] = "rejection";
                            $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);
                            $mongoList["main"][] = $epID;

                            if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                                $insertIDs = array();
                                foreach ($tableIn_detail as $dSpec) {
                                    if ($epID != 999) {
                                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                        $mongoList['detail'] = $insertIDs;
                                    }
                                }
                            }
                        }

                        //endregion

                    }
                    else {
                        cekMerah(":: CONNECTING, SATU INSTANSI (PUSAT DOANG / CABANG DOANG)::");
                        cekHitam(":: jenisTR > $jenisTr, jenis_master > $jenisTr, id_master > " . $tmpTr[0]->id_master . " ::");
                        //                    mati_disini(":: transaksi gagal karena transaksi yang dimaksud tidak valid.");


                        //region :: update ID-nya sendiri...

                        //region update step2an di masternya
                        $nextMasterStep = $stepNumCurrent;
                        $nextProp = array(
                            "num" => $nextMasterStep,
                            "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                            "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                            "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
                        );
                        echo "nextMasterStep: $nextMasterStep<br>";
//                        arrPrint($nextProp);
//                        cekKuning($masterTargetStepNum);
                        //update masternya, transaksi TOP
                        if ($tmpTr[0]->id_top != $no) {
                            $arrData = array(
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],
                                "next_step_num" => $nextProp["num"],
                                "step_current" => $masterTargetStepNum,
                                "step_number" => $masterTargetStepNum,
                            );
                            $arrData_detail = array(
                                "next_substep_code" => $nextProp["code"],
                                "next_substep_label" => $nextProp["label"],
                                "next_subgroup_code" => $nextProp["groupID"],
                                "next_substep_num" => $nextProp["num"],
                                "sub_step_current" => $masterTargetStepNum,
                                "sub_step_number" => $masterTargetStepNum,
                                //                "valid_qty" => $new_valid_qty,
                            );
                        }
                        else {
                            $arrData = array(
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],
                                "next_step_num" => $nextProp["num"],
                                "step_current" => $masterTargetStepNum,
                                "step_number" => $masterTargetStepNum,
                                //                        "step_number" => $childTargetStepNum,
                                "trash_4" => "1",
                            );
                            $arrData_detail = array(
                                "next_substep_code" => $nextProp["code"],
                                "next_substep_label" => $nextProp["label"],
                                "next_subgroup_code" => $nextProp["groupID"],
                                "next_substep_num" => $nextProp["num"],
                                //            "sub_step_current" => 0,
                                "sub_step_number" => 0,
                            );
                        }
                        $tr = new MdlTransaksi();
                        $dupState = $tr->updateData(array(
                            //                "id" => $no,
                            "id" => $tmpTr[0]->id_top,
                        ), $arrData) or die("Failed to update tr next-state!");

                        cekHijau("UPDATE transaksi step sebelumnya...");
                        cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        //endregion

                        //region update step transaksi 1 step sebelumnya (detail)
                        if (sizeof($tmpTr) > 0) {
                            $arrPrevID = $tmpTr[0]->ids_prev != null ? blobDecode($tmpTr[0]->ids_prev) : array($tmpTr[0]->id_top);
                            foreach ($arrPrevID as $prevID) {
                                $tb = new MdlTransaksi();
                                $tb->setFilters(array());
                                $dupState = $tb->updateData(array(
                                    "id" => $prevID,
                                ), array(
                                    "status_4" => "11",
                                )) or die("Failed to update tr next-state!");

                                cekKuning("UPDATE transaksi 1 step sebelumnya...");
                                cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");


                                $td = new MdlTransaksi();
                                $td->setFilters(array());
                                $rslt = $td->lookupJoinedByID($prevID)->result();
                                if (sizeof($rslt) > 0) {
                                    foreach ($rslt as $rsltSpec) {
                                        if (array_key_exists($rsltSpec->produk_id, $items)) {
                                            $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                            if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                                $new_valid_qty = $rsltSpec->valid_qty;
                                            }
                                            else {
                                                $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                            }

                                            $arrData_detail["valid_qty"] = $new_valid_qty;
                                            $tr = new MdlTransaksi();
                                            $tr->setFilters(array());
                                            $tr->setTableName($tr->getTableNames()['detail']);
                                            $dupState = $tr->updateData(array(
                                                "transaksi_id" => $prevID,
                                                "produk_id" => $rsltSpec->produk_id,
                                            ), $arrData_detail) or die("Failed to update tr next-state!");

                                            cekKuning("UPDATE transaksi data...");
                                            cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                                        }
                                    }
                                }

                            }
                        }
                        //endregion

                        //region update step yang sebelumnya aktif, transaksi yang dibuka sekarang
                        // if ($tmpTr[0]->id_top != $no) {
                        $tp = new MdlTransaksi();
                        $dupState = $tp->updateData(array(
                            "id" => $no,
                            "step_number" => $stepNumCurrent,
                        ), array(
                            "step_number" => $masterTargetStepNum,
                            //                    "step_number" => $childTargetStepNum,
                            "trash_4" => "1",
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),

                        )) or die("Failed to update tr next-state!");

                        cekLime("UPDATE transaksi ini... yang dibuka sekarang...");
                        cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                        $to = new MdlTransaksi();
                        $to->setFilters(array());
                        $to->setTableName($to->getTableNames()['detail']);
                        $dupState = $to->updateData(array(
                            "transaksi_id" => $no,
                        ), array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            //            "sub_step_current" => 0,
                            "sub_step_number" => 0,
                        )) or die("Failed to update tr next-state!");

                        cekLime("UPDATE transaksi data...");
                        cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        // }
                        //endregion

                        //region sesuaikan signature untuk cloningan, ikut minus
                        $dwsign = $tr->writeSignature($tmpTr[0]->id_top, array(
                            "prev_id" => $no,
                            "nomer" => "rejection",
                            "step_number" => $childTargetStepNum, // ini minus step number
                            "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["target"],
                            "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"],
                            "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]['userGroup'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                            //            "transaksi_id" => $no,
                        )) or die("Failed to write signature");

                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        //endregion

                        // region netralisasi payment source
                        $tr = New MdlTransaksi();
                        $tr->setFilters(array());
                        $tr->addFilter("sisa>0");
                        $paymentSrc = $tr->lookupPaymentSrcByTransID($no)->result();
                        cekBiru($this->CI->db->last_query());
                        if (sizeof($paymentSrc) > 0) {
                            //            arrPrint($paymentSrc);
                            foreach ($paymentSrc as $pSpec) {
                                if ($pSpec->terbayar == 0) {
                                    $where = array(
                                        "id" => $pSpec->id,
                                        "transaksi_id" => $pSpec->transaksi_id,
                                    );
                                    $data = array(
                                        "sisa" => 0,
                                        "returned" => $pSpec->sisa,
                                        "sisa_valas" => 0,
                                        "returned_valas" => $pSpec->sisa_valas,
                                    );

                                    $tra = New MdlTransaksi();
                                    $tra->setFilters(array());
                                    $tra->updatePaymentSrc($where, $data);
                                    cekUngu(":: mereject payment source bila ada...");
                                    cekUngu($this->CI->db->last_query());
                                }
                                else {
                                    mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                                }
                            }
                        }
                        else {
                            cekBiru(":: tidak ada payment source... ::");
                        }
                        // endregion netralisasi payment source

                        // region netralisasi extended step
                        $tr = New MdlTransaksi();
                        $tr->setFilters(array());
                        $exTmp = $tr->lookupExtStepByTrID($no);
                        if (sizeof($exTmp) > 0) {
                            foreach ($exTmp as $exSpec) {
                                $tra = New MdlTransaksi();
                                $tra->setFilters(array());
                                $tra->rejectExtStepByID($exSpec["id"]);

                                cekUngu(":: mereject extended step bila ada...");
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        else {
                            cekBiru(":: tidak ada extended step... ::");
                        }

                        // endregion netralisasi extended step


                        //region entry point
                        if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                            $tableIn_master['trash_4'] = 1;
                            $tableIn_master['cancel_id'] = my_id();
                            $tableIn_master['cancel_name'] = my_name();
                            $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                            $tableIn_master['deskripsi'] = "rejection";
                            $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);
                            $mongoList["main"][] = $epID;
                            //                        cekHitam($this->CI->db->last_query());
                            if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                                $insertIDs = array();
                                foreach ($tableIn_detail as $dSpec) {
                                    if ($epID != 999) {
                                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                        $mongoList['detil'] = $insertIDs;
                                        //                                    cekHitam($this->CI->db->last_query());
                                    }
                                }
                            }
                        }
                        //endregion

                        $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
                        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
                        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
                        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
                        $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();

                        //===if rollback is needed
                        //rollback preproc, master
                        if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                            //            cekbiru("ada config pre-proc master $stepNumCurrent");
                            $iterator = isset($core['preProcessor'][$jenisTr_component]['master']) ? $core['preProcessor'][$jenisTr_component]['master'] : array();
                            //            arrprint($iterator);
                            if (sizeof($iterator) > 0) {
                                $it = 0;
                                cekbiru("ada iterator pre-proc master");
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $it++;
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'] . "_reverse";
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                                    echo "reverse master-preproc: $comName, initializing values <br>";
                                    $tmpOutParams[$cCtr] = array();


                                    $subParams = array();

                                    if (isset($tComSpec['static'])) {
                                        foreach ($tComSpec['static'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $subParams['static'][$key] = $realValue;

                                        }

                                        if (array_key_exists($oriComName, $prepConfigs)) {
                                            if (sizeof($prepConfigs[$oriComName]) > 0) {
                                                foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                    $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                                }
                                            }
                                        }

                                        if (!isset($subParams['static']["transaksi_id"])) {
                                            $subParams['static']["transaksi_id"] = $no;
                                        }


                                        $subParams['static']["fulldate"] = date("Y-m-d");
                                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                    }
                                    if (sizeof($subParams) > 0) {
                                        $tmpOutParams[$cCtr] = $subParams;
                                    }


                                    $mdlName = "Pre" . ucfirst($comName);
                                    $this->CI->load->model("Preprocs/" . $mdlName);
                                    $m = new $mdlName($resultParams);


                                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                        $tobeExecuted = true;
                                    }
                                    else {
                                        $tobeExecuted = false;
                                    }

                                    if ($tobeExecuted) {
                                        $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                        $gotParams = $m->exec();
                                    }
                                    else {
                                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                    }
                                }
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
                        }
                        //rollback preproc, detail
                        if (isset($core['preProcessor'][$jenisTr_component]['detail'])) {
                            $iterator = isset($core['preProcessor'][$jenisTr_component]['detail']) ? $core['preProcessor'][$jenisTr_component]['detail'] : array();
                            if (sizeof($iterator) > 0) {
                                $it = 0;
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $it++;
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'] . "_reverse";
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "reverse preproc (detail): $comName, initializing values <br>";
                                    foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                                        $tmpOutParams[$cCtr] = array();
                                        $id = $xid;
                                        $subParams = array();
                                        if (isset($tComSpec['static'])) {
                                            foreach ($tComSpec['static'] as $key => $value) {

                                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                                $subParams['static'][$key] = $realValue;

                                            }

                                            if (array_key_exists($oriComName, $prepConfigs)) {
                                                cekhitam("terdapat di dalam prepConfig");
                                                if (sizeof($prepConfigs[$oriComName]) > 0) {
                                                    foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                        $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                                    }
                                                }
                                            }
                                            else {
                                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                            }
                                            if (!isset($subParams['static']["transaksi_id"])) {
                                                $subParams['static']["transaksi_id"] = $no;
                                            }


                                            $subParams['static']["fulldate"] = date("Y-m-d");
                                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                            $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                        }
                                        if (sizeof($subParams) > 0) {

                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }


                                        $comName = $tComSpec['comName'] . "_reverse";
                                        $srcGateName = $tComSpec['srcGateName'];
                                        $srcRawGateName = $tComSpec['srcRawGateName'];
                                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                        echo "sub preproc #$it: $comName, sending values <br>";

                                        $mdlName = "Pre" . ucfirst($comName);
                                        $this->CI->load->model("Preprocs/" . $mdlName);
                                        $m = new $mdlName($resultParams);


                                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                            $tobeExecuted = true;
                                        }
                                        else {
                                            $tobeExecuted = false;
                                        }

                                        if ($tobeExecuted) {
                                            $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                            $gotParams = $m->exec();
                                        }
                                        else {
                                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                        }

                                    }
                                }
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
                        }
                        //rollback postproc, master
                        if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                            //            cekbiru("ada config pre-proc master $stepNumCurrent");
                            $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                            if (sizeof($iterator) > 0) {
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "rollback main post-processor: $comName<br>";

                                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                                    $tmpOutParams = array();
                                    if (isset($tComSpec['loop'])) {
                                        foreach ($tComSpec['loop'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $tmpOutParams['loop'][$key] = $realValue;

                                        }
                                    }
                                    if (isset($tComSpec['static'])) {
                                        //cekHere("DISINI OIII");
                                        foreach ($tComSpec['static'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            $tmpOutParams['static'][$key] = $realValue;

                                        }
                                        if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                            $tmpOutParams['static']["transaksi_id"] = $insertID;
                                        }
                                        if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                            $tmpOutParams['static']["transaksi_no"] = $insertNum;
                                        }

                                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();


                                    }
                                    if (isset($tComSpec['static2'])) {
                                        //cekHere("DISINI OIII");
                                        foreach ($tComSpec['static2'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                            $tmpOutParams['static2'][$key] = $realValue;

                                        }
                                        if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                            $tmpOutParams['static2']["transaksi_id"] = $insertID;
                                        }
                                        if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                            $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                                        }

                                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                                    }


                                    if (array_key_exists($oriComName, $postConfigs)) {
                                        if (sizeof($postConfigs[$oriComName]) > 0) {
                                            foreach ($postConfigs[$oriComName] as $key) {
                                                $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                                cekbiru("oldVal: $oldVal");
                                                $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                cekHijau("newVal: $newVal");
                                                //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                                $tmpOutParams['static'][$key] = $newVal;
                                            }
                                        }
                                    }

                                    //lgShowError("Ada kesalahan",);
                                    $mdlName = "Com" . ucfirst($comName);
                                    $this->CI->load->model("Coms/" . $mdlName);
                                    $m = new $mdlName();

                                    cekBiru("kiriman rollback main-postproc $comName");
                                    arrPrint($tmpOutParams);
                                    $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                                }
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
                        }
                        //rollback postproc, detail
                        if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {
                            $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                            if (sizeof($iterator) > 0) {
                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "rollback sub-postProcessor: $comName, initializing values <br>";
                                    //                arrPrint($this->cCodeData[$cCode][$srcGateName]);
                                    $tmpOutParams[$cCtr] = array();
                                    foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                                        $subParams = array();
                                        if (isset($tComSpec['loop'])) {
                                            foreach ($tComSpec['loop'] as $key => $value) {

                                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                                $subParams['loop'][$key] = $realValue;

                                            }
                                        }
                                        if (isset($tComSpec['static'])) {
                                            foreach ($tComSpec['static'] as $key => $value) {

                                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                                $subParams['static'][$key] = $realValue;
                                                //                                cekBiru("$key diisi dengan $realValue");

                                            }

                                            if (array_key_exists($oriComName, $postConfigs)) {
                                                //                                cekhitam("terdapat di dalam postConfig");
                                                if (sizeof($postConfigs[$oriComName]) > 0) {
                                                    foreach ($postConfigs[$oriComName] as $key) {
                                                        //                                        $replVal=makeValue($src,$this->cCodeData[$cCode][$srcGateName][$cnt],$this->cCodeData[$cCode][$srcGateName][$cnt],0);
                                                        //                                        cekbiru("$key akan direplace dengan nilai $replVal");
                                                        //                                        $subParams['static'][$key]=$replVal;

                                                        $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                                        cekbiru("oldVal2: $oldVal");
                                                        $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                        cekHijau("newVal2: $newVal");
                                                        $subParams['static'][$key] = $newVal;
                                                        //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                                        //                                        $tmpOutParams['static'][$key]=$newVal;
                                                    }
                                                }
                                            }
                                            else {
                                                //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                            }

                                            //                            $subParams['static']["transaksi_id"] = $insertID;
                                            if (!isset($subParams['static']["transaksi_id"])) {
                                                $subParams['static']["transaksi_id"] = $no;
                                            }
                                            if (!isset($subParams['static']["transaksi_no"])) {
                                                $subParams['static']["transaksi_no"] = $no;
                                            }
                                            $subParams['static']["fulldate"] = date("Y-m-d");
                                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                            $subParams['static']["keterangan"] = "rollback of $no";
                                        }


                                        if (sizeof($subParams) > 0) {
                                            $tmpOutParams[$cCtr][] = $subParams;
                                        }
                                    }
                                }

                                foreach ($iterator as $cCtr => $tComSpec) {
                                    $oriComName = $tComSpec['comName'];
                                    $comName = $tComSpec['comName'];
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    echo "sub-postProcessor: $comName, sending values <br>";

                                    $mdlName = "Com" . ucfirst($comName);
                                    $this->CI->load->model("Coms/" . $mdlName);
                                    $m = new $mdlName();


                                    cekBiru("kiriman rollback detail-postproc $comName");
                                    arrPrint($tmpOutParams[$cCtr]);
                                    $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                }
                            }
                        }
                        else {
                            cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
                        }
                        //endregion

                    }
                    //endregion
                }
                else {
                    // hanya mundur 1 langkah di pihak target

                    //region update step2an di masternya
                    $nextMasterStep = $stepNumCurrent;
                    $nextProp = array(
                        "num" => $nextMasterStep,
                        "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                        "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                        "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
                    );
                    echo "nextMasterStep: $nextMasterStep<br>";
//                    arrPrint($nextProp);
//                    cekKuning($masterTargetStepNum);
                    //update masternya, transaksi TOP
                    if ($tmpTr[0]->id_top != $no) {
                        $arrData = array(
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],
                            "next_step_num" => $nextProp["num"],
                            "step_current" => $masterTargetStepNum,
                            "step_number" => $masterTargetStepNum,
                        );
                        $arrData_detail = array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            "sub_step_current" => $masterTargetStepNum,
                            "sub_step_number" => $masterTargetStepNum,
                            //                "valid_qty" => $new_valid_qty,
                        );
                    }
                    else {
                        $arrData = array(
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],
                            "next_step_num" => $nextProp["num"],
                            "step_current" => $masterTargetStepNum,
                            "step_number" => $masterTargetStepNum,
                            //                        "step_number" => $childTargetStepNum,
                            "trash_4" => "1",
                            "cancel_dtime" => dtime("Y-m-d H:i:s"),
                            "cancel_id" => my_id(),
                            "cancel_name" => my_name(),
                        );
                        $arrData_detail = array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            //            "sub_step_current" => 0,
                            "sub_step_number" => 0,
                        );
                    }
                    $tr = new MdlTransaksi();
                    $dupState = $tr->updateData(array(
                        //                "id" => $no,
                        "id" => $tmpTr[0]->id_top,
                    ), $arrData) or die("Failed to update tr next-state!");
                    $mongListUpadte['update']["main"][] = array(
                        "where" => array(
                            "id" => $tmpTr[0]->id_top
                        ),
                        "value" => $arrData,
                    );
                    cekHijau("UPDATE transaksi step sebelumnya...");
                    cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    //endregion

                    //region update step transaksi 1 step sebelumnya (detail)
                    if (sizeof($tmpTr) > 0) {
                        $arrPrevID = $tmpTr[0]->ids_prev != null ? blobDecode($tmpTr[0]->ids_prev) : array($tmpTr[0]->id_top);
//                        arrPrint($arrPrevID);
                        foreach ($arrPrevID as $prevID) {
                            $tb = new MdlTransaksi();
                            $tb->setFilters(array());
                            $dupState = $tb->updateData(array(
                                "id" => $prevID,
                            ), array(
                                "status_4" => "11",
                            )) or die("Failed to update tr next-state!");
                            $mongListUpadte['update']["main"][] = array(
                                "where" => array(
                                    "id" => $prevID
                                ),
                                "value" => array(
                                    "status_4" => "11",
                                ),
                            );
                            cekKuning("UPDATE transaksi 1 step sebelumnya...");
                            cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                            $td = new MdlTransaksi();
                            $td->setFilters(array());
                            $rslt = $td->lookupJoinedByID($prevID)->result();
                            if (sizeof($rslt) > 0) {
                                foreach ($rslt as $rsltSpec) {
                                    if (array_key_exists($rsltSpec->produk_id, $items)) {
                                        $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                        //                            cekHitam(":: $prevID :: $rsltSpec->valid_qty :: " . $items[$rsltSpec->produk_id]['qty'] . " :: $new_valid_qty ::");

                                        if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                            $new_valid_qty = $rsltSpec->valid_qty;
                                            //                                mati_disini("undo/reject/delete gagal karena valid_qty melebihi produk_ord_jml");
                                        }
                                        else {
                                            $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                        }
                                        //                            cekHitam("ROLLBACK... :: valid_qty-> " . $rsltSpec->valid_qty . " :: kembali-> " . $items[$rsltSpec->produk_id]['qty'] . " :: " . $new_valid_qty);

                                        $arrData_detail["valid_qty"] = $new_valid_qty;
                                        $tr = new MdlTransaksi();
                                        $tr->setFilters(array());
                                        $tr->setTableName($tr->getTableNames()['detail']);
                                        $dupState = $tr->updateData(array(
                                            "transaksi_id" => $prevID,
                                            "produk_id" => $rsltSpec->produk_id,
                                        ), $arrData_detail) or die("Failed to update tr next-state!");
                                        $mongListUpadte['update']['detail'][] = array(
                                            "where" => array(
                                                "transaksi_id" => $prevID,
                                                "produk_id" => $rsltSpec->produk_id,
                                            ),
                                            "value" => $arrData_detail,
                                        );
                                        cekKuning("UPDATE transaksi data...");
                                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                                    }
                                }
                            }

                        }
                    }
                    //endregion

                    //region update step yang sebelumnya aktif, transaksi yang dibuka sekarang
                    $tp = new MdlTransaksi();
                    $dupState = $tp->updateData(array(
                        "id" => $no,
                        "step_number" => $stepNumCurrent,
                    ), array(
                        "step_number" => $masterTargetStepNum,
                        //                    "step_number" => $childTargetStepNum,
                        "trash_4" => "1",
                        "cancel_dtime" => date("Y-m-d H:i:s"),
                        "cancel_name" => my_name(),
                        "cancel_id" => my_id(),

                    )) or die("Failed to update tr next-state!");

                    $mongListUpadte['update']["main"][] = array(
                        "where" => array(
                            "id" => $no,
                            "step_number" => $stepNumCurrent,
                        ),
                        "value" => array(
                            "step_number" => $masterTargetStepNum,
                            //                    "step_number" => $childTargetStepNum,
                            "trash_4" => "1",
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),
                        ),
                    );
                    cekLime("UPDATE transaksi ini... yang dibuka sekarang...");
                    cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
//arrPrintWebs($mongListUpadte);
                    $to = new MdlTransaksi();
                    $to->setFilters(array());
                    $to->setTableName($to->getTableNames()['detail']);
                    $dupState = $to->updateData(array(
                        "transaksi_id" => $no,
                    ), array(
                        "next_substep_code" => $nextProp["code"],
                        "next_substep_label" => $nextProp["label"],
                        "next_subgroup_code" => $nextProp["groupID"],
                        "next_substep_num" => $nextProp["num"],
                        //            "sub_step_current" => 0,
                        "sub_step_number" => 0,
                    )) or die("Failed to update tr next-state!");
                    $mongListUpadte['update']['detail'][] = array(
                        "where" => array(
                            "transaksi_id" => $no, "id" => $no,
                        ),
                        "value" => array(
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "next_substep_num" => $nextProp["num"],
                            //            "sub_step_current" => 0,
                            "sub_step_number" => 0,
                        ),
                    );
                    cekLime("UPDATE transaksi data...");
                    cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                    //endregion

                    //region sesuaikan signature untuk cloningan, ikut minus
                    //        $dwsign = $tr->writeSignature($no, array(
                    $dwsign = $tr->writeSignature($tmpTr[0]->id_top, array(
                        "prev_id" => $no,
                        "nomer" => "rejection",
                        "step_number" => $childTargetStepNum, // ini minus step number
                        "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["target"],
                        "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"],
                        "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]['userGroup'],
                        "oleh_id" => my_id(),
                        "oleh_nama" => my_name(),
                        "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                        //            "transaksi_id" => $no,
                    )) or die("Failed to write signature");
                    $mongoList['sign'][] = $dwsign;
                    cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    //endregion

                    // region netralisasi payment source
                    $tr = New MdlTransaksi();
                    $tr->setFilters(array());
                    $tr->addFilter("sisa>0");
                    $paymentSrc = $tr->lookupPaymentSrcByTransID($no)->result();
                    cekBiru($this->CI->db->last_query());
                    if (sizeof($paymentSrc) > 0) {
                        //            arrPrint($paymentSrc);
                        foreach ($paymentSrc as $pSpec) {
                            if ($pSpec->terbayar == 0) {
                                $where = array(
                                    "id" => $pSpec->id,
                                    "transaksi_id" => $pSpec->transaksi_id,
                                );
                                $data = array(
                                    "sisa" => 0,
                                    "returned" => $pSpec->sisa,
                                    "sisa_valas" => 0,
                                    "returned_valas" => $pSpec->sisa_valas,
                                );

                                $tra = New MdlTransaksi();
                                $tra->setFilters(array());
                                $tra->updatePaymentSrc($where, $data);
                                cekUngu(":: mereject payment source bila ada...");
                                cekUngu($this->CI->db->last_query());
                            }
                            else {
                                mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                            }
                        }
                    }
                    else {
                        cekBiru(":: tidak ada payment source... ::");
                    }
                    // endregion netralisasi payment source

                    // region netralisasi extended step
                    $tr = New MdlTransaksi();
                    $tr->setFilters(array());
                    $exTmp = $tr->lookupExtStepByTrID($no);
                    if (sizeof($exTmp) > 0) {
                        foreach ($exTmp as $exSpec) {

                            $tra = New MdlTransaksi();
                            $tra->setFilters(array());
                            $tra->rejectExtStepByID($exSpec["id"]);
                            $mongListUpadte['update']['extra'][] = array(
                                "where" => array(
                                    "id" => $exSpec["id"],
                                ),
                                "value" => array(
                                    "state" => "-1",
                                ),
                            );
                            cekUngu(":: mereject extended step bila ada...");
                            cekUngu($this->CI->db->last_query());
                        }
                    }
                    else {
                        cekBiru(":: tidak ada extended step... ::");
                    }

                    // endregion netralisasi extended step

                    //==entry point
                    if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                        if (isset($this->configUiJenis["connectToReject"][$stepNumCurrent])) {
                            if ($this->configUiJenis["connectToReject"][$stepNumCurrent]["enabled"] == true) {
                                $masterID = $currentMasterID;
                                $connecTo = $this->configUiJenis["connectToReject"][$stepNumCurrent]["connectTo"];
                                cekHijau("START menjalankan REJECT... [$masterID] [$connecTo]");
                                if ($connecTo == NULL) {
                                    mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                                }
                                $oldCode = $cCode;
                                $cCode = "_TR_" . $connecTo;
                                $this->cCodeData[$cCode] = array(
                                    "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                                    "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                                    "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                                    "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                                    "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                                    "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                                    "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                                    "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                                    "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                                    "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                                    "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                                    'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                                    'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                                    'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                                    'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                                    'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                                    'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                                    'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                                    'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                                    "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                                    "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                                    'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                                    'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                                    'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                                    'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                                    'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                                    'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                                    'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                                    'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                                    'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                                    'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                                    'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                                    'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                    'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                    "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                    "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                    "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                    "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                    "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                    "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                    "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                    "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                    "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                                    "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                                    "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                                    "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                                    "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                                );
                                // masuk ke gerbang TableInMaster, tabel transaksi
                                $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                                    "jenis_master" => $this->jenisTr,
                                    "jenis_top" => $connecTo,
                                    "jenis" => $connecTo,
                                    "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                    "transaksi_jenis" => $connecTo,
                                    "step_avail" => 1,
                                    "step_current" => 1,
                                    "step_number" => 1,
                                    "next_step_code" => "",
                                    "next_step_label" => "",
                                    "next_group_code" => "",
                                    "next_step_num" => "0",
                                    "trash_4" => 1,
                                    "cancel_dtime" => date("Y-m-d H:i:s"),
                                    "cancel_name" => my_name(),
                                    "cancel_id" => my_id(),
                                    "deskripsi" => "rejection",
                                    "oleh_id" => my_id(),
                                    "oleh_nama" => my_name()
                                );
                                // masuk ke gerbang main
                                $masterReplacersO = array(
                                    "stepCode" => $connecTo,
                                    "jenisTrTop" => $connecTo,
                                    "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
//                        "inv" => $tmpNomorNota,
                                    "jenis_master" => $this->jenisTr,
                                    "jenis_top" => $connecTo,
                                    "jenis" => $connecTo,
                                    "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                    "transaksi_jenis" => $connecTo,
                                    "stepCode" => $connecTo,
                                    "jenisTrTop" => $connecTo,
                                    "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                    "step_avail" => 1,
                                    "step_current" => 1,
                                    "step_number" => 1,
                                    "next_step_code" => "",
                                    "next_step_label" => "",
                                    "next_group_code" => "",
                                    "next_step_num" => "0",
                                    "olehID" => my_id(),
                                    "olehName" => my_name()
                                );
                                foreach ($masterReplacersO as $key => $val) {
                                    $this->cCodeData[$cCode]["main"][$key] = $val;
                                }
                                foreach ($masterReplacers as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                }

                                $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                                $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];

                                //region penomoran receipt
                                $this->CI->load->model("CustomCounter");
                                $cn = new CustomCounter("transaksi");
                                $cn->setType("transaksi");
                                $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaReject']);
                                if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersReject'])) {
                                    die(__LINE__ . " Used number should be registered in counters config as well");
                                }
                                echo "<div style='background:#ff7766;'>";
                                foreach ($counterForNumber as $i => $cRawParams) {
                                    $cParams = explode("|", $cRawParams);
                                    $cValues = array();
                                    foreach ($cParams as $param) {
                                        $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                    }
                                    $cRawValues = implode("|", $cValues[$i]);
                                    $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                }
                                echo "</div style='background:#ff7766;'>";

                                $stepNumber = 1;
                                $tmpNomorNota = $paramSpec["paramString"];
                                $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                                $nextProp = array(
                                    "num" => 0,
                                    "code" => "",
                                    "label" => "",
                                    "groupID" => "",
                                );
                                //endregion

                                //region dynamic counters
                                // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                                $cn = new CustomCounter("transaksi");
                                $cn->setType("transaksi");
                                $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersReject'];
                                arrPrintHijau($configCustomParams);
                                $configCustomParams[] = "stepCode";
                                //arrPrint($configCustomParams);
                                if (sizeof($configCustomParams) > 0) {
                                    $cContent = array();
                                    foreach ($configCustomParams as $i => $cRawParams) {
                                        $cParams = explode("|", $cRawParams);
                                        $cValues = array();
                                        foreach ($cParams as $param) {
                                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                        }
                                        $cRawValues = implode("|", $cValues[$i]);
                                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                        $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                                        switch ($paramSpec["id"]) {
                                            case 0: //===counter type is new
                                                $addData = array(
                                                    "toko_id" => $tokoID,
                                                    "toko_nama" => $tokoNama,
                                                );
                                                $paramKeyRaw = print_r($cParams, true);
                                                $paramValuesRaw = print_r($cValues[$i], true);
                                                $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                                break;
                                            default: //===counter to be updated
                                                $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                                break;
                                        }
                                        //echo "<hr>";
                                    }
                                }
                                $appliedCounters = base64_encode(serialize($cContent));
                                $appliedCounters_inText = print_r($cContent, true);
                                //mati_disini();
//arrPrintPink($cContent);
                                //
                                //region addition on master


                                $addValues = array(
                                    "counters" => $appliedCounters,
                                    'counters_intext' => $appliedCounters_inText,
                                    'nomer' => $tmpNomorNota,
                                    'nomer2' => $tmpNomorNotaAlias,
                                    'dtime' => date("Y-m-d H:i:s"),
                                    'fulldate' => date("Y-m-d"),
                                    "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                    "step_number" => 1,
                                    "step_current" => 1,
                                    "next_step_num" => $nextProp["num"],
                                    "next_step_code" => $nextProp["code"],
                                    "next_step_label" => $nextProp["label"],
                                    "next_group_code" => $nextProp["groupID"],
                                    "tail_number" => 1,
                                    "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                                );
                                foreach ($addValues as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                }
                                //endregion

                                //
                                //region addition on detail
                                $addSubValues = array(
                                    "sub_step_number" => 1,
                                    "sub_step_current" => 1,
                                    "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                    "next_substep_num" => $nextProp["num"],
                                    "next_substep_code" => $nextProp["code"],
                                    "next_substep_label" => $nextProp["label"],
                                    "next_subgroup_code" => $nextProp["groupID"],
                                    "sub_tail_number" => 1,
                                    "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                                );
                                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                                    foreach ($addSubValues as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                                    }
                                }
                                //endregion
                                // </editor-fold>
                                //endregion

                                //region numbering tambahan
                                $this->CI->load->library("CounterNumber");
                                $ccn = new CounterNumber();
                                $ccn->setCCode($cCode);
                                $ccn->setJenisTr($this->jenisTr);
                                $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                                $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                                $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                                $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                                $new_counter = $ccn->getCounterNumber();
                                cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                                if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                                    foreach ($new_counter["main"] as $ckey => $cval) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                                        $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                                    }
                                }
                                if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                                    foreach ($new_counter["items"] as $ikey => $iSpec) {
                                        foreach ($iSpec as $iikey => $iival) {
                                            $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                                        }
                                    }
                                }
                                if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                                    foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                                        foreach ($iSpec as $iikey => $iival) {
                                            $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                                        }
                                    }
                                }
                                //endregion

                                $addValues = array(
                                    "counters" => $appliedCounters,
                                    'counters_intext' => $appliedCounters_inText,
                                    'nomer' => $tmpNomorNota,
                                    'nomer2' => $tmpNomorNotaAlias,
                                    'dtime' => date("Y-m-d H:i:s"),
                                    'fulldate' => date("Y-m-d"),
                                );
                                foreach ($addValues as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                }
                                $masterReplacers = array(
                                    "nomer" => $tmpNomorNota,
                                    "nomer2" => $tmpNomorNotaAlias,
                                    "counters" => $appliedCounters,
                                    "counters_intext" => $appliedCounters_inText,
                                );
                                foreach ($masterReplacers as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                }
                                $detailReplacers = array(
                                    "sub_step_avail" => 1,
                                    "sub_step_current" => 1,
                                    "sub_step_number" => 1,
                                    "next_substep_num" => "",
                                    "next_substep_code" => "",
                                    "next_substep_label" => "",
                                    "next_subgroup_code" => "",
                                );
                                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                                        foreach ($dSpec as $key => $val) {
                                            $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                                        }
                                    }
                                }
                                $itemsReplacers = array(
                                    "next_substep_num" => "",
                                    "next_substep_code" => "",
                                    "next_substep_label" => "",
                                    "next_subgroup_code" => "",
                                );
                                if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                                    foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                                        foreach ($dSpec as $key => $val) {
                                            $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                                        }
                                    }
                                }

                                //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                                if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                                    $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                                    $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 1;// dibatalkan
                                    $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;

                                    $tr = new MdlTransaksi();
                                    $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                                    $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                                    cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                                    $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                                    $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                                    $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                                    if ($insertID < 1) {
                                        die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                                    }
                                    $mongoList["main"] = array($insertID, $epID);
                                    //==transaksi_id dan nomor nota diinject kan ke gate utama
                                    $injectors = array(
                                        "transaksi_id" => $insertID,
                                        "nomer" => $tmpNomorNota,
                                        "nomer2" => $tmpNomorNotaAlias,
                                    );
                                    $arrInjectorsTarget = array(
                                        "items",
                                        "items2_sum",
                                        "rsltItems",
                                    );
                                    foreach ($injectors as $key => $val) {
                                        $this->cCodeData[$cCode]["main"][$key] = $val;
                                        foreach ($arrInjectorsTarget as $target) {
                                            if (isset($this->cCodeData[$cCode][$target])) {
                                                foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                                    $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                                    if (isset($this->cCodeData[$cCode][$target][$id])) {
                                                        $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    //===signature
                                    $dwsign = $tr->writeSignature($insertID, array(
                                        "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                        "step_number" => 1,
                                        "step_code" => $connecTo,
                                        "step_name" => $this->configUiJenis["connectToEdit"][1]["label"],
                                        "group_code" => "",
                                        "oleh_id" => my_id(),
                                        "oleh_nama" => my_name(),
                                        "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                                        "transaksi_id" => $masterID,
                                        "deskripsi" => "edit transaksi",
                                        "cabang_id" => my_cabang_id(),
                                        "cabang_nama" => my_cabang_nama(),
                                        "current_transaksi_id" => $masterID,
                                        "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    )) or die("Failed to write signature");
                                    showLast_query("kuning");
                                    $mongoList['sign'][] = $dwsign;
                                    $idHis = array(
                                        $stepNumber => array(
                                            "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                            "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                            "step" => $stepNumber,
                                            "trID" => $insertID,
                                            "nomer" => $tmpNomorNota,
                                            "nomer2" => $tmpNomorNotaAlias,
                                            "counters" => $appliedCounters,
                                            "counters_intext" => $appliedCounters_inText,
                                        ),
                                    );
                                    $idHis_blob = blobEncode($idHis);
                                    $idHis_intext = print_r($idHis, true);
                                    $tr = new MdlTransaksi();
                                    $dupState = $tr->updateData(array("id" => $insertID), array(
                                        "next_step_num" => $nextProp["num"],
                                        "next_step_code" => $nextProp["code"],
                                        "next_step_label" => $nextProp["label"],
                                        "next_group_code" => $nextProp["groupID"],

                                        //===references
//                            "id_master" => $insertID,
                                        "id_master" => $masterID,// milik transkasiID yang diedit
                                        "id_top" => $insertID,
                                        "ids_prev" => "",
                                        "ids_prev_intext" => "",
                                        "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                        "nomers_prev" => "",
                                        "nomers_prev_intext" => "",
                                        "jenises_prev" => "",
                                        "jenises_prev_intext" => "",
                                        "ids_his" => $idHis_blob,
                                        "ids_his_intext" => $idHis_intext,

                                    )) or die("Failed to update tr next-state!");
                                    cekHijau($this->CI->db->last_query());

                                    $addValues = array(
                                        //===references
                                        "id_master" => $insertID,
                                        "id_top" => $insertID,
                                        "ids_prev" => "",
                                        "ids_prev_intext" => "",
                                        "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                        "nomers_prev" => "",
                                        "nomers_prev_intext" => "",
                                        "jenises_prev" => "",
                                        "jenises_prev_intext" => "",
                                        "ids_his" => $idHis_blob,
                                        "ids_his_intext" => $idHis_intext,
                                    );
                                    foreach ($addValues as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                    }

                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                                    $inserMainValues = array();
                                    if (isset($this->configCore[$this->jenisTr]["tableIn"]['mainValues'])) {
                                        //matiHEre("hooppp");
                                        $inserMainValues = array();
                                        foreach ($this->configCore[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                            if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                                $dd = $tr->writeMainValues($insertID, array(
                                                    "key" => $key,
                                                    "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                                ));

                                                $inserMainValues[] = $dd;
                                                $mongoList['mainValues'][] = $dd;
                                            }
                                        }
                                    }

                                    if (sizeof($inserMainValues) > 0) {
                                        $arrBlob = blobEncode($inserMainValues);
                                        $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                    }

                                }
                                if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                                    $inserMainValues = array();
                                    foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                        $inserMainValues[] = $dd;
                                        $mongoList['mainValues'][] = $dd;
                                    }

                                    if (sizeof($inserMainValues) > 0) {
                                        $arrBlob = blobEncode($inserMainValues);
                                        $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                                    foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                                        $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                        //                    cekkuning("making a clone for input key $key / $val");
                                        //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                                        //                    $replacers=array(
                                        //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                                        //                    );
                                        //                    foreach($replacers as $key=>$val){
                                        //                        $tmpTableIn[$key]=$val;
                                        //                    }
                                        //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                                    foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                                        $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                                    foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                                        $tr->writeMainApplets($insertID, array(
                                            "mdl_name" => $amdl,
                                            "key" => $aSpec['key'],
                                            "label" => $aSpec['labelValue'],
                                            "description" => $aSpec['description'],
                                        ));
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                                    foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                                        $tr->writeMainElements($insertID, array(
                                            "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                            "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                            "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                            "name" => $aSpec['name'],
                                            "label" => $aSpec["label"],
                                            "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                            "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                                        ));
                                        //==nebeng bikin inputLabels
//                                $currentValue = "";
//                                switch ($aSpec['elementType']) {
//                                    case "dataModel":
//                                        $currentValue = $aSpec['key'];
//                                        break;
//                                    case "dataField":
//                                        $currentValue = $aSpec["value"];
//                                        break;
//                                }
//                                if (array_key_exists($elName, $relOptionConfigs)) {
//                                    //					cekhijau("$eName terdaftar pada relInputs");
//
//
//                                    if (isset($relOptionConfigs[$elName][$currentValue])) {
//                                        if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
//                                            foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
//                                                $inputLabels[$oValueName] = $oValSpec["label"];
//                                                if (isset($oValSpec['auth'])) {
//                                                    if (isset($oValSpec['auth']["groupID"])) {
//                                                        $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
//                                                    }
//                                                }
//                                            }
//                                        }
//                                    }
//                                    else {
//                                        //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
//                                    }
//
//                                }

                                    }
                                }
                                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {

                                    $insertIDs = array();
                                    $insertDeIDs = array();
                                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                                        $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                        if ($insertDetailID < 1) {
                                            die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                                        }
                                        else {
                                            $insertIDs[] = $insertDetailID;
                                            $insertDeIDs[$insertID][] = $insertDetailID;
                                            $mongoList['detail'][] = $insertDetailID;
                                        }
                                        if ($epID != 999) {
                                            $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                            if ($insertEpID < 1) {
                                                die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                            }
                                            else {
                                                $insertIDs[] = $insertEpID;
                                                $insertDeIDs[$epID][] = $insertEpID;
                                                $mongoList['detail'][] = $insertEpID;
                                            }
                                        }
                                        cekUngu($this->CI->db->last_query());
                                    }


                                    if (sizeof($insertIDs) == 0) {
                                        die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                                    }
                                    else {
                                        $indexing_details = array();
                                        foreach ($insertDeIDs as $key => $numb) {
                                            $indexing_details[$key] = $numb;
                                        }

                                        foreach ($indexing_details as $k => $arrID) {
                                            $arrBlob = blobEncode($arrID);
                                            $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                            cekOrange($this->CI->db->last_query());
                                        }
                                    }
                                }
                                else {
                                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                                    $insertIDs = array();
                                    foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                                        $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                                        $mongoList['detail'] = $insertIDs;
                                        if ($epID != 999) {
                                            $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                            $mongoList['detail'] = $insertIDs;
                                        }
                                        cekUngu($this->CI->db->last_query());
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                                    $insertIDs = array();
                                    foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                                        $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                        $insertIDs[] = $insertDetailID;
                                        $mongoList['detail'][] = $insertDetailID;
                                        if ($epID != 999) {
                                            $dd = $tr->writeDetailEntries($epID, $dSpec);
                                            $insertIDs[] = $dd;
                                            $mongoList['detail'][] = $dd;
                                        }
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                                    $insertIDs = array();
                                    foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                                        $dd = $tr->writeDetailEntries($insertID, $dSpec);
                                        $insertIDs[] = $dd;
                                        $mongoList['detil'][] = $dd;
                                        if ($epID != 999) {
                                            $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                            $mongoList['detil'] = $insertIDs;
                                        }
                                        cekUngu($this->CI->db->last_query());
                                    }
                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {

                                    $insertIDs = array();
                                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                                        if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues'])) {
                                            foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                                if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                                    $dd = $tr->writeDetailValues($insertID, array(
                                                        "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                                        "produk_id" => $pID,
                                                        "key" => $key,
                                                        "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                                    ));
                                                    $insertIDs[$pID][] = $dd;
                                                    $mongoList['detailValues'][] = $dd;

                                                }
                                            }
                                        }
                                    }

                                    if (sizeof($insertIDs) > 0) {
                                        $arrBlob = blobEncode($insertIDs);
                                        $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                                    }

                                }
                                if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                                        if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                            $insertIDs = array();
                                            foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                                $dd = $tr->writeDetailValues($insertID, array(
                                                    "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                                    "produk_id" => $pID,
                                                    "key" => $key,
                                                    "value" => $dSpec[$src],
                                                ));
                                                $insertIDs[] = $dd;
                                                $mongoList['detailValues'][] = $dd;
                                            }
                                        }
                                    }
                                }
                                //endregion

                                $baseRegistries = array(
                                    "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                                    "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                                    "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                                    "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                                    "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                                    "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                                    "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                                    "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                                    "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                                    "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                                    "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                                    'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                                    'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                                    'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                                    'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                                    'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                                    'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                                    'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                                    'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                                    "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                                    "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                                    'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                                    'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                                    'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                                    'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                                    'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                                    'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                                    'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                                    'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                                    'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                                    'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                                    'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                                    'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                    'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                    "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                    "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                    "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                    "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                    "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                    "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                    "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                    "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                    "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                                    "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                                    "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                                    "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                                    "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                                    //----
                                    'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                                    'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                                    //----
                                );
                                $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                                showLast_query("hijau");
                                cekHijau("SELESAI menjalankan EDITOR...");
                            }
                        }
                        else {
                            $tableIn_master['trash_4'] = 1;
                            $tableIn_master['cancel_id'] = my_id();
                            $tableIn_master['cancel_name'] = my_name();
                            $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                            $tableIn_master['deskripsi'] = "rejection";
                            $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);
                            $mongoList["main"][] = $epID;

                            if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                                $insertIDs = array();
                                foreach ($tableIn_detail as $dSpec) {
                                    if ($epID != 999) {
                                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                        $mongoList['detail'] = $insertIDs;
                                    }
                                }
                            }
                        }
                    }

                    $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
                    $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                    $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
                    $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
                    $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
                    $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();

                    //===if rollback is needed
                    //rollback preproc, master
                    if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                        //            cekbiru("ada config pre-proc master $stepNumCurrent");
                        $iterator = isset($core[$jenisTr]['preProcessor'][$jenisTr_component]['master']) ? $core[$jenisTr]['preProcessor'][$jenisTr_component]['master'] : array();
                        //            arrprint($iterator);
                        if (sizeof($iterator) > 0) {
                            $it = 0;
                            cekbiru("ada iterator pre-proc master");
                            foreach ($iterator as $cCtr => $tComSpec) {
                                $it++;
                                $oriComName = $tComSpec['comName'];
                                $comName = $tComSpec['comName'] . "_reverse";
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                                echo "reverse master-preproc: $comName, initializing values <br>";
                                $tmpOutParams[$cCtr] = array();


                                $subParams = array();

                                if (isset($tComSpec['static'])) {
                                    foreach ($tComSpec['static'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                        $subParams['static'][$key] = $realValue;

                                    }

                                    if (array_key_exists($oriComName, $prepConfigs)) {
                                        if (sizeof($prepConfigs[$oriComName]) > 0) {
                                            foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                            }
                                        }
                                    }

                                    if (!isset($subParams['static']["transaksi_id"])) {
                                        $subParams['static']["transaksi_id"] = $no;
                                    }


                                    $subParams['static']["fulldate"] = date("Y-m-d");
                                    $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                }
                                if (sizeof($subParams) > 0) {
                                    $tmpOutParams[$cCtr] = $subParams;
                                }


                                $mdlName = "Pre" . ucfirst($comName);
                                $this->CI->load->model("Preprocs/" . $mdlName);
                                $m = new $mdlName($resultParams);


                                if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                    $tobeExecuted = true;
                                }
                                else {
                                    $tobeExecuted = false;
                                }

                                if ($tobeExecuted) {
                                    arrprint($tmpOutParams[$cCtr]);
                                    $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $gotParams = $m->exec();


                                }
                                else {
                                    cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                }

                            }
                        }
                    }
                    else {
                        cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
                    }
                    //rollback preproc, detail
                    if (isset($core[$jenisTr]['preProcessor'][$jenisTr_component]['detail'])) {
                        //            cekbiru("ada config pre-proc detail $stepNumCurrent");
                        $iterator = isset($core[$jenisTr]['preProcessor'][$jenisTr_component]['detail']) ? $core[$jenisTr]['preProcessor'][$jenisTr_component]['detail'] : array();
                        //            arrprint($iterator);
                        if (sizeof($iterator) > 0) {
                            $it = 0;
                            foreach ($iterator as $cCtr => $tComSpec) {
                                $it++;
                                $oriComName = $tComSpec['comName'];
                                $comName = $tComSpec['comName'] . "_reverse";
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                echo "reverse preproc (detail): $comName, initializing values <br>";
                                foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                                    $tmpOutParams[$cCtr] = array();
                                    //                        $id = $dSpec["id"];
                                    $id = $xid;
                                    $subParams = array();

                                    if (isset($tComSpec['static'])) {
                                        foreach ($tComSpec['static'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                            $subParams['static'][$key] = $realValue;

                                        }

                                        if (array_key_exists($oriComName, $prepConfigs)) {
                                            cekhitam("terdapat di dalam prepConfig");
                                            if (sizeof($prepConfigs[$oriComName]) > 0) {
                                                foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                    $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                                }
                                            }
                                        }
                                        else {
                                            cekhitam("TIDAK terdapat di dalam prepConfig");
                                        }
                                        if (!isset($subParams['static']["transaksi_id"])) {
                                            $subParams['static']["transaksi_id"] = $no;
                                        }


                                        $subParams['static']["fulldate"] = date("Y-m-d");
                                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                    }

                                    if (sizeof($subParams) > 0) {

                                        $tmpOutParams[$cCtr][] = $subParams;
                                    }


                                    $comName = $tComSpec['comName'] . "_reverse";
                                    $srcGateName = $tComSpec['srcGateName'];
                                    $srcRawGateName = $tComSpec['srcRawGateName'];
                                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                    echo "sub preproc #$it: $comName, sending values <br>";

                                    $mdlName = "Pre" . ucfirst($comName);
                                    $this->CI->load->model("Preprocs/" . $mdlName);
                                    $m = new $mdlName($resultParams);


                                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                        $tobeExecuted = true;
                                    }
                                    else {
                                        $tobeExecuted = false;
                                    }

                                    if ($tobeExecuted) {

                                        //                            arrprint($tmpOutParams[$cCtr]);

                                        $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                        $gotParams = $m->exec();

                                        //                            cekbiru("gotparams");
                                        //                            arrprint($gotParams);

                                    }
                                    else {
                                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                    }

                                }
                            }
                        }
                    }
                    else {
                        cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
                    }
                    //rollback postproc, master
                    if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                        //            cekbiru("ada config pre-proc master $stepNumCurrent");
                        $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                        if (sizeof($iterator) > 0) {
                            foreach ($iterator as $cCtr => $tComSpec) {
                                $oriComName = $tComSpec['comName'];
                                $comName = $tComSpec['comName'];
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                echo "rollback main post-processor: $comName<br>";

                                $dSpec = $this->cCodeData[$cCode][$srcGateName];
                                $tmpOutParams = array();
                                if (isset($tComSpec['loop'])) {
                                    foreach ($tComSpec['loop'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                        $tmpOutParams['loop'][$key] = $realValue;

                                    }
                                }
                                if (isset($tComSpec['static'])) {
                                    //cekHere("DISINI OIII");
                                    foreach ($tComSpec['static'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                        $tmpOutParams['static'][$key] = $realValue;

                                    }
                                    if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                        $tmpOutParams['static']["transaksi_id"] = $insertID;
                                    }
                                    if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                        $tmpOutParams['static']["transaksi_no"] = $insertNum;
                                    }

                                    $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                                    $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();


                                }
                                if (isset($tComSpec['static2'])) {
                                    //cekHere("DISINI OIII");
                                    foreach ($tComSpec['static2'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                        $tmpOutParams['static2'][$key] = $realValue;

                                    }
                                    if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                        $tmpOutParams['static2']["transaksi_id"] = $insertID;
                                    }
                                    if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                        $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                                    }

                                    $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                                    $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                                    $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                                }


                                if (array_key_exists($oriComName, $postConfigs)) {
                                    if (sizeof($postConfigs[$oriComName]) > 0) {
                                        foreach ($postConfigs[$oriComName] as $key) {
                                            $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                            cekbiru("oldVal: $oldVal");
                                            $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                            cekHijau("newVal: $newVal");
                                            //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                            $tmpOutParams['static'][$key] = $newVal;
                                        }
                                    }
                                }

                                //lgShowError("Ada kesalahan",);
                                $mdlName = "Com" . ucfirst($comName);
                                $this->CI->load->model("Coms/" . $mdlName);
                                $m = new $mdlName();

                                cekBiru("kiriman rollback main-postproc $comName");
                                arrPrint($tmpOutParams);
                                $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                            }
                        }
                    }
                    else {
                        cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
                    }
                    //rollback postproc, detail
                    if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {

                        $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                        if (sizeof($iterator) > 0) {
                            foreach ($iterator as $cCtr => $tComSpec) {
                                $oriComName = $tComSpec['comName'];
                                $comName = $tComSpec['comName'];
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                echo "rollback sub-postProcessor: $comName, initializing values <br>";
                                //                arrPrint($this->cCodeData[$cCode][$srcGateName]);
                                $tmpOutParams[$cCtr] = array();
                                foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                                    $subParams = array();
                                    if (isset($tComSpec['loop'])) {
                                        foreach ($tComSpec['loop'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                            $subParams['loop'][$key] = $realValue;

                                        }
                                    }
                                    if (isset($tComSpec['static'])) {
                                        foreach ($tComSpec['static'] as $key => $value) {

                                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                            $subParams['static'][$key] = $realValue;
                                            //                                cekBiru("$key diisi dengan $realValue");

                                        }

                                        if (array_key_exists($oriComName, $postConfigs)) {
                                            //                                cekhitam("terdapat di dalam postConfig");
                                            if (sizeof($postConfigs[$oriComName]) > 0) {
                                                foreach ($postConfigs[$oriComName] as $key) {
                                                    //                                        $replVal=makeValue($src,$this->cCodeData[$cCode][$srcGateName][$cnt],$this->cCodeData[$cCode][$srcGateName][$cnt],0);
                                                    //                                        cekbiru("$key akan direplace dengan nilai $replVal");
                                                    //                                        $subParams['static'][$key]=$replVal;

                                                    $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                                    cekbiru("oldVal2: $oldVal");
                                                    $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                    cekHijau("newVal2: $newVal");
                                                    $subParams['static'][$key] = $newVal;
                                                    //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                                    //                                        $tmpOutParams['static'][$key]=$newVal;
                                                }
                                            }
                                        }
                                        else {
                                            //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                        }

                                        //                            $subParams['static']["transaksi_id"] = $insertID;
                                        if (!isset($subParams['static']["transaksi_id"])) {
                                            $subParams['static']["transaksi_id"] = $no;
                                        }
                                        if (!isset($subParams['static']["transaksi_no"])) {
                                            $subParams['static']["transaksi_no"] = $no;
                                        }
                                        $subParams['static']["fulldate"] = date("Y-m-d");
                                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                        $subParams['static']["keterangan"] = "rollback of $no";
                                    }


                                    if (sizeof($subParams) > 0) {
                                        $tmpOutParams[$cCtr][] = $subParams;
                                    }
                                }
                            }

                            foreach ($iterator as $cCtr => $tComSpec) {
                                $oriComName = $tComSpec['comName'];
                                $comName = $tComSpec['comName'];
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                echo "sub-postProcessor: $comName, sending values <br>";

                                $mdlName = "Com" . ucfirst($comName);
                                $this->CI->load->model("Coms/" . $mdlName);
                                $m = new $mdlName();


                                cekBiru("kiriman rollback detail-postproc $comName");
                                arrPrint($tmpOutParams[$cCtr]);
                                $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            }
                        }
                    }
                    else {
                        cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
                    }
//mati_disini(__LINE__);
                }

            }
            else {
                cekBiru("yang membatalkan pihak source/sumber...");
                cekBiru("TIDAK ADA CONNECTING MUNDUR...");
//mati_disini(__LINE__);

                //region update step2an di masternya
                $nextMasterStep = $stepNumCurrent;
                $nextProp = array(
                    "num" => $nextMasterStep,
                    "code" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["target"] : "",
                    "label" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"]) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]["label"] : "",
                    "groupID" => isset($this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup']) ? $this->configUiModul[$jenisTr]["steps"][$nextMasterStep]['userGroup'] : "",
                );
                echo "nextMasterStep: $nextMasterStep<br>";
                arrPrint($nextProp);
                cekKuning($masterTargetStepNum);
                //update masternya, transaksi TOP
                if ($tmpTr[0]->id_top != $no) {
                    $arrData = array(
                        "next_step_code" => $nextProp["code"],
                        "next_step_label" => $nextProp["label"],
                        "next_group_code" => $nextProp["groupID"],
                        "next_step_num" => $nextProp["num"],
                        "step_current" => $masterTargetStepNum,
                        "step_number" => $masterTargetStepNum,
                    );
                    $arrData_detail = array(
                        "next_substep_code" => $nextProp["code"],
                        "next_substep_label" => $nextProp["label"],
                        "next_subgroup_code" => $nextProp["groupID"],
                        "next_substep_num" => $nextProp["num"],
                        "sub_step_current" => $masterTargetStepNum,
                        "sub_step_number" => $masterTargetStepNum,
                        //                "valid_qty" => $new_valid_qty,
                    );
                }
                else {
                    $arrData = array(
                        "next_step_code" => $nextProp["code"],
                        "next_step_label" => $nextProp["label"],
                        "next_group_code" => $nextProp["groupID"],
                        "next_step_num" => $nextProp["num"],
                        "step_current" => $masterTargetStepNum,
                        "step_number" => $masterTargetStepNum,
                        //                        "step_number" => $childTargetStepNum,
                        "trash_4" => "1",
                        "cancel_id" => my_id(),
                        "cancel_name" => my_name(),
                        "cancel_dtime" => date("Y-m-d H:i:s"),

                    );
                    $arrData_detail = array(
                        "next_substep_code" => $nextProp["code"],
                        "next_substep_label" => $nextProp["label"],
                        "next_subgroup_code" => $nextProp["groupID"],
                        "next_substep_num" => $nextProp["num"],
                        //            "sub_step_current" => 0,
                        "sub_step_number" => 0,
                    );
                }
                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array(
                    //                "id" => $no,
                    "id" => $tmpTr[0]->id_top,
                ), $arrData) or die("Failed to update tr next-state!");
                $mongListUpadte['update']["main"][] = array(
                    "where" => array(
                        "id" => $tmpTr[0]->id_top
                    ),
                    "value" => $arrData,
                );
                cekHijau("UPDATE transaksi step sebelumnya...");
                cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                //endregion

                //region update step transaksi 1 step sebelumnya (detail)
                if (sizeof($tmpTr) > 0) {
                    $arrPrevID = $tmpTr[0]->ids_prev != null ? blobDecode($tmpTr[0]->ids_prev) : array($tmpTr[0]->id_top);
                    arrPrint($arrPrevID);
                    foreach ($arrPrevID as $prevID) {
                        $tb = new MdlTransaksi();
                        $tb->setFilters(array());
                        $dupState = $tb->updateData(array(
                            "id" => $prevID,
                        ), array(
                            "status_4" => "11",
                        )) or die("Failed to update tr next-state!");
                        $mongListUpadte['update']["main"][] = array(
                            "where" => array(
                                "id" => $prevID
                            ),
                            "value" => array(
                                "status_4" => "11",
                            ),
                        );
                        cekKuning("UPDATE transaksi 1 step sebelumnya...");
                        cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");


                        $td = new MdlTransaksi();
                        $td->setFilters(array());
                        $rslt = $td->lookupJoinedByID($prevID)->result();
                        if (sizeof($rslt) > 0) {
                            foreach ($rslt as $rsltSpec) {
                                if (array_key_exists($rsltSpec->produk_id, $items)) {
                                    $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                    //                            cekHitam(":: $prevID :: $rsltSpec->valid_qty :: " . $items[$rsltSpec->produk_id]['qty'] . " :: $new_valid_qty ::");

                                    if ($new_valid_qty > $rsltSpec->produk_ord_jml) {
                                        $new_valid_qty = $rsltSpec->valid_qty;
                                        //                                mati_disini("undo/reject/delete gagal karena valid_qty melebihi produk_ord_jml");
                                    }
                                    else {
                                        $new_valid_qty = $rsltSpec->valid_qty + $items[$rsltSpec->produk_id]['qty'];
                                    }
                                    //                            cekHitam("ROLLBACK... :: valid_qty-> " . $rsltSpec->valid_qty . " :: kembali-> " . $items[$rsltSpec->produk_id]['qty'] . " :: " . $new_valid_qty);

                                    $arrData_detail["valid_qty"] = $new_valid_qty;
                                    $tr = new MdlTransaksi();
                                    $tr->setFilters(array());
                                    $tr->setTableName($tr->getTableNames()['detail']);
                                    $dupState = $tr->updateData(array(
                                        "transaksi_id" => $prevID,
                                        "produk_id" => $rsltSpec->produk_id,
                                    ), $arrData_detail) or die("Failed to update tr next-state!");
                                    $mongListUpadte['update']['detail'][] = array(
                                        "where" => array(
                                            "transaksi_id" => $prevID,
                                            "produk_id" => $rsltSpec->produk_id,
                                        ),
                                        "value" => $arrData_detail,
                                    );
                                    cekKuning("UPDATE transaksi data...");
                                    cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                                }
                            }
                        }

                    }
                }
                //endregion

                //region update step yang sebelumnya aktif, transaksi yang dibuka sekarang
                $tp = new MdlTransaksi();
                $dupState = $tp->updateData(array(
                    "id" => $no,
                    "step_number" => $stepNumCurrent,
                ), array(
                    "step_number" => $masterTargetStepNum,
                    //                    "step_number" => $childTargetStepNum,
                    "trash_4" => "1",
                    "cancel_dtime" => date("Y-m-d H:i:s"),
                    "cancel_name" => my_name(),
                    "cancel_id" => my_id(),

                )) or die("Failed to update tr next-state!");

                $mongListUpadte['update']["main"][] = array(
                    "where" => array(
                        "id" => $no,
                        "step_number" => $stepNumCurrent,
                    ),
                    "value" => array(
                        "step_number" => $masterTargetStepNum,
                        //                    "step_number" => $childTargetStepNum,
                        "trash_4" => "1",
                        "cancel_dtime" => date("Y-m-d H:i:s"),
                        "cancel_name" => my_name(),
                        "cancel_id" => my_id(),
                    ),
                );
                cekLime("UPDATE transaksi ini... yang dibuka sekarang...");
                cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                $to = new MdlTransaksi();
                $to->setFilters(array());
                $to->setTableName($to->getTableNames()['detail']);
                $dupState = $to->updateData(array(
                    "transaksi_id" => $no,
                ), array(
                    "next_substep_code" => $nextProp["code"],
                    "next_substep_label" => $nextProp["label"],
                    "next_subgroup_code" => $nextProp["groupID"],
                    "next_substep_num" => $nextProp["num"],
                    //            "sub_step_current" => 0,
                    "sub_step_number" => 0,
                )) or die("Failed to update tr next-state!");
                $mongListUpadte['update']['detail'][] = array(
                    "where" => array(
                        "transaksi_id" => $no, "id" => $no,
                    ),
                    "value" => array(
                        "next_substep_code" => $nextProp["code"],
                        "next_substep_label" => $nextProp["label"],
                        "next_subgroup_code" => $nextProp["groupID"],
                        "next_substep_num" => $nextProp["num"],
                        //            "sub_step_current" => 0,
                        "sub_step_number" => 0,
                    ),
                );
                cekLime("UPDATE transaksi data...");
                cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

                //endregion

                //region sesuaikan signature untuk cloningan, ikut minus
                //        $dwsign = $tr->writeSignature($no, array(
                $dwsign = $tr->writeSignature($tmpTr[0]->id_top, array(
                    "prev_id" => $no,
                    "nomer" => "rejection",
                    "step_number" => $childTargetStepNum, // ini minus step number
                    "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["target"],
                    "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"],
                    "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]['userGroup'],
                    "oleh_id" => my_id(),
                    "oleh_nama" => my_name(),
                    "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($childTargetStepNum)]["label"] . " oleh " . my_name(),
                    //            "transaksi_id" => $no,
                )) or die("Failed to write signature");
                $mongoList['sign'][] = $dwsign;
                cekKuning($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                //endregion

                // region netralisasi payment source
                $tr = New MdlTransaksi();
                $tr->setFilters(array());
                $tr->addFilter("sisa>0");
                $paymentSrc = $tr->lookupPaymentSrcByTransID($no)->result();
                cekBiru($this->CI->db->last_query());
                if (sizeof($paymentSrc) > 0) {
                    //            arrPrint($paymentSrc);
                    foreach ($paymentSrc as $pSpec) {
                        if ($pSpec->terbayar == 0) {
                            $where = array(
                                "id" => $pSpec->id,
                                "transaksi_id" => $pSpec->transaksi_id,
                            );
                            $data = array(
                                "sisa" => 0,
                                "returned" => $pSpec->sisa,
                                "sisa_valas" => 0,
                                "returned_valas" => $pSpec->sisa_valas,
                            );

                            $tra = New MdlTransaksi();
                            $tra->setFilters(array());
                            $tra->updatePaymentSrc($where, $data);
                            cekUngu(":: mereject payment source bila ada...");
                            cekUngu($this->CI->db->last_query());
                        }
                        else {
                            mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                        }
                    }
                }
                else {
                    cekBiru(":: tidak ada payment source... ::");
                }
                // endregion netralisasi payment source

                // region netralisasi extended step
                $tr = New MdlTransaksi();
                $tr->setFilters(array());
                $exTmp = $tr->lookupExtStepByTrID($no);
                if (sizeof($exTmp) > 0) {
                    foreach ($exTmp as $exSpec) {

                        $tra = New MdlTransaksi();
                        $tra->setFilters(array());
                        $tra->rejectExtStepByID($exSpec["id"]);
                        $mongListUpadte['update']['extra'][] = array(
                            "where" => array(
                                "id" => $exSpec["id"],
                            ),
                            "value" => array(
                                "state" => "-1",
                            ),
                        );
                        cekUngu(":: mereject extended step bila ada...");
                        cekUngu($this->CI->db->last_query());
                    }
                }
                else {
                    cekBiru(":: tidak ada extended step... ::");
                }

                // endregion netralisasi extended step

                //==entry point
                if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                    if (isset($this->configUiJenis["connectToReject"][$stepNumCurrent])) {
                        if ($this->configUiJenis["connectToReject"][$stepNumCurrent]["enabled"] == true) {
                            $masterID = $currentMasterID;
                            $connecTo = $this->configUiJenis["connectToReject"][$stepNumCurrent]["connectTo"];
                            cekHijau("START menjalankan REJECT... [$masterID] [$connecTo]");
                            if ($connecTo == NULL) {
                                mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                            }
                            $oldCode = $cCode;
                            $cCode = "_TR_" . $connecTo;
                            $this->cCodeData[$cCode] = array(
                                "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                                "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                                "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                                "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                                "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                                "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                                "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                                "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                                "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                                "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                                "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                                'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                                'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                                'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                                'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                                'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                                'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                                'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                                'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                                "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                                "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                                'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                                'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                                'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                                'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                                'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                                'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                                'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                                'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                                'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                                "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                                "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                                "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                                "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                                "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                            );
                            // masuk ke gerbang TableInMaster, tabel transaksi
                            $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                                "jenis_master" => $this->jenisTr,
                                "jenis_top" => $connecTo,
                                "jenis" => $connecTo,
                                "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                "transaksi_jenis" => $connecTo,
                                "step_avail" => 1,
                                "step_current" => 1,
                                "step_number" => 1,
                                "next_step_code" => "",
                                "next_step_label" => "",
                                "next_group_code" => "",
                                "next_step_num" => "0",
                                "trash_4" => 1,
                                "cancel_dtime" => date("Y-m-d H:i:s"),
                                "cancel_name" => my_name(),
                                "cancel_id" => my_id(),
                                "deskripsi" => "rejection",
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name()
                            );
                            // masuk ke gerbang main
                            $masterReplacersO = array(
                                "stepCode" => $connecTo,
                                "jenisTrTop" => $connecTo,
                                "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
//                        "inv" => $tmpNomorNota,
                                "jenis_master" => $this->jenisTr,
                                "jenis_top" => $connecTo,
                                "jenis" => $connecTo,
                                "jenis_label" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                "transaksi_jenis" => $connecTo,
                                "stepCode" => $connecTo,
                                "jenisTrTop" => $connecTo,
                                "jenisTrName" => $this->configUiJenis["connectToReject"][$stepNumCurrent]["label"],
                                "step_avail" => 1,
                                "step_current" => 1,
                                "step_number" => 1,
                                "next_step_code" => "",
                                "next_step_label" => "",
                                "next_group_code" => "",
                                "next_step_num" => "0",
                                "olehID" => my_id(),
                                "olehName" => my_name()
                            );
                            foreach ($masterReplacersO as $key => $val) {
                                $this->cCodeData[$cCode]["main"][$key] = $val;
                            }
                            foreach ($masterReplacers as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }

                            $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                            $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];

                            //region penomoran receipt
                            $this->CI->load->model("CustomCounter");
                            $cn = new CustomCounter("transaksi");
                            $cn->setType("transaksi");
                            $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaReject']);
                            if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersReject'])) {
                                die(__LINE__ . " Used number should be registered in counters config as well");
                            }
                            echo "<div style='background:#ff7766;'>";
                            foreach ($counterForNumber as $i => $cRawParams) {
                                $cParams = explode("|", $cRawParams);
                                $cValues = array();
                                foreach ($cParams as $param) {
                                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                }
                                $cRawValues = implode("|", $cValues[$i]);
                                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                            }
                            echo "</div style='background:#ff7766;'>";

                            $stepNumber = 1;
                            $tmpNomorNota = $paramSpec["paramString"];
                            $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                            $nextProp = array(
                                "num" => 0,
                                "code" => "",
                                "label" => "",
                                "groupID" => "",
                            );
                            //endregion

                            //region dynamic counters
                            // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                            $cn = new CustomCounter("transaksi");
                            $cn->setType("transaksi");
                            $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersReject'];
//                            arrPrintHijau($configCustomParams);
                            $configCustomParams[] = "stepCode";
                            //arrPrint($configCustomParams);
                            if (sizeof($configCustomParams) > 0) {
                                $cContent = array();
                                foreach ($configCustomParams as $i => $cRawParams) {
                                    $cParams = explode("|", $cRawParams);
                                    $cValues = array();
                                    foreach ($cParams as $param) {
                                        $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                    }
                                    $cRawValues = implode("|", $cValues[$i]);
                                    $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                    $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                                    switch ($paramSpec["id"]) {
                                        case 0: //===counter type is new
                                            $addData = array(
                                                "toko_id" => $tokoID,
                                                "toko_nama" => $tokoNama,
                                            );
                                            $paramKeyRaw = print_r($cParams, true);
                                            $paramValuesRaw = print_r($cValues[$i], true);
                                            $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                            break;
                                        default: //===counter to be updated
                                            $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                            break;
                                    }
                                    //echo "<hr>";
                                }
                            }
                            $appliedCounters = base64_encode(serialize($cContent));
                            $appliedCounters_inText = print_r($cContent, true);
                            //mati_disini();

                            //
                            //region addition on master


                            $addValues = array(
                                "counters" => $appliedCounters,
                                'counters_intext' => $appliedCounters_inText,
                                'nomer' => $tmpNomorNota,
                                'nomer2' => $tmpNomorNotaAlias,
                                'dtime' => date("Y-m-d H:i:s"),
                                'fulldate' => date("Y-m-d"),
                                "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                "step_number" => 1,
                                "step_current" => 1,
                                "next_step_num" => $nextProp["num"],
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],
                                "tail_number" => 1,
                                "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                            );
                            foreach ($addValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }
                            //endregion

                            //
                            //region addition on detail
                            $addSubValues = array(
                                "sub_step_number" => 1,
                                "sub_step_current" => 1,
                                "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                                "next_substep_num" => $nextProp["num"],
                                "next_substep_code" => $nextProp["code"],
                                "next_substep_label" => $nextProp["label"],
                                "next_subgroup_code" => $nextProp["groupID"],
                                "sub_tail_number" => 1,
                                "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                            );
                            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                                foreach ($addSubValues as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                                }
                            }
                            //endregion
                            // </editor-fold>
                            //endregion

                            //region numbering tambahan
                            $this->CI->load->library("CounterNumber");
                            $ccn = new CounterNumber();
                            $ccn->setCCode($cCode);
                            $ccn->setJenisTr($this->jenisTr);
                            $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                            $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                            $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                            $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                            $new_counter = $ccn->getCounterNumber();
                            cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                            if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                                foreach ($new_counter["main"] as $ckey => $cval) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                                    $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                                }
                            }
                            if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                                foreach ($new_counter["items"] as $ikey => $iSpec) {
                                    foreach ($iSpec as $iikey => $iival) {
                                        $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                                    }
                                }
                            }
                            if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                                foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                                    foreach ($iSpec as $iikey => $iival) {
                                        $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                                    }
                                }
                            }
                            //endregion

                            $addValues = array(
                                "counters" => $appliedCounters,
                                'counters_intext' => $appliedCounters_inText,
                                'nomer' => $tmpNomorNota,
                                'nomer2' => $tmpNomorNotaAlias,
                                'dtime' => date("Y-m-d H:i:s"),
                                'fulldate' => date("Y-m-d"),
                            );
                            foreach ($addValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }
                            $masterReplacers = array(
                                "nomer" => $tmpNomorNota,
                                "nomer2" => $tmpNomorNotaAlias,
                                "counters" => $appliedCounters,
                                "counters_intext" => $appliedCounters_inText,
                            );
                            foreach ($masterReplacers as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }
                            $detailReplacers = array(
                                "sub_step_avail" => 1,
                                "sub_step_current" => 1,
                                "sub_step_number" => 1,
                                "next_substep_num" => "",
                                "next_substep_code" => "",
                                "next_substep_label" => "",
                                "next_subgroup_code" => "",
                            );
                            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                                    foreach ($dSpec as $key => $val) {
                                        $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                                    }
                                }
                            }
                            $itemsReplacers = array(
                                "next_substep_num" => "",
                                "next_substep_code" => "",
                                "next_substep_label" => "",
                                "next_subgroup_code" => "",
                            );
                            if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                                foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                                    foreach ($dSpec as $key => $val) {
                                        $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                                    }
                                }
                            }

                            //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                            if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                                $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                                $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 1;// dibatalkan
                                $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;

                                $tr = new MdlTransaksi();
                                $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                                $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                                cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                                $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                                $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                                $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                                if ($insertID < 1) {
                                    die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                                }
                                $mongoList["main"] = array($insertID, $epID);
                                //==transaksi_id dan nomor nota diinject kan ke gate utama
                                $injectors = array(
                                    "transaksi_id" => $insertID,
                                    "nomer" => $tmpNomorNota,
                                    "nomer2" => $tmpNomorNotaAlias,
                                );
                                $arrInjectorsTarget = array(
                                    "items",
                                    "items2_sum",
                                    "rsltItems",
                                );
                                foreach ($injectors as $key => $val) {
                                    $this->cCodeData[$cCode]["main"][$key] = $val;
                                    foreach ($arrInjectorsTarget as $target) {
                                        if (isset($this->cCodeData[$cCode][$target])) {
                                            foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                                $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                                if (isset($this->cCodeData[$cCode][$target][$id])) {
                                                    $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                                }
                                            }
                                        }
                                    }
                                }

                                //===signature
                                $dwsign = $tr->writeSignature($insertID, array(
                                    "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    "step_number" => 1,
                                    "step_code" => $connecTo,
                                    "step_name" => $this->configUiJenis["connectToEdit"][1]["label"],
                                    "group_code" => "",
                                    "oleh_id" => my_id(),
                                    "oleh_nama" => my_name(),
                                    "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                                    "transaksi_id" => $masterID,
                                    "deskripsi" => "edit transaksi",
                                    "cabang_id" => my_cabang_id(),
                                    "cabang_nama" => my_cabang_nama(),
                                    "current_transaksi_id" => $masterID,
                                    "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                )) or die("Failed to write signature");
                                showLast_query("kuning");
                                $mongoList['sign'][] = $dwsign;
                                $idHis = array(
                                    $stepNumber => array(
                                        "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                        "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                        "step" => $stepNumber,
                                        "trID" => $insertID,
                                        "nomer" => $tmpNomorNota,
                                        "nomer2" => $tmpNomorNotaAlias,
                                        "counters" => $appliedCounters,
                                        "counters_intext" => $appliedCounters_inText,
                                    ),
                                );
                                $idHis_blob = blobEncode($idHis);
                                $idHis_intext = print_r($idHis, true);
                                $tr = new MdlTransaksi();
                                $dupState = $tr->updateData(array("id" => $insertID), array(
                                    "next_step_num" => $nextProp["num"],
                                    "next_step_code" => $nextProp["code"],
                                    "next_step_label" => $nextProp["label"],
                                    "next_group_code" => $nextProp["groupID"],

                                    //===references
//                            "id_master" => $insertID,
                                    "id_master" => $masterID,// milik transkasiID yang diedit
                                    "id_top" => $insertID,
                                    "ids_prev" => "",
                                    "ids_prev_intext" => "",
                                    "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    "nomers_prev" => "",
                                    "nomers_prev_intext" => "",
                                    "jenises_prev" => "",
                                    "jenises_prev_intext" => "",
                                    "ids_his" => $idHis_blob,
                                    "ids_his_intext" => $idHis_intext,

                                )) or die("Failed to update tr next-state!");
                                cekHijau($this->CI->db->last_query());

                                $addValues = array(
                                    //===references
                                    "id_master" => $insertID,
                                    "id_top" => $insertID,
                                    "ids_prev" => "",
                                    "ids_prev_intext" => "",
                                    "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                    "nomers_prev" => "",
                                    "nomers_prev_intext" => "",
                                    "jenises_prev" => "",
                                    "jenises_prev_intext" => "",
                                    "ids_his" => $idHis_blob,
                                    "ids_his_intext" => $idHis_intext,
                                );
                                foreach ($addValues as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                                }

                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                                $inserMainValues = array();
                                if (isset($this->configCore[$this->jenisTr]["tableIn"]['mainValues'])) {
                                    //matiHEre("hooppp");
                                    $inserMainValues = array();
                                    foreach ($this->configCore[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                        if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                            $dd = $tr->writeMainValues($insertID, array(
                                                "key" => $key,
                                                "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                            ));

                                            $inserMainValues[] = $dd;
                                            $mongoList['mainValues'][] = $dd;
                                        }
                                    }
                                }

                                if (sizeof($inserMainValues) > 0) {
                                    $arrBlob = blobEncode($inserMainValues);
                                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                }

                            }
                            if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                                $inserMainValues = array();
                                foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                    $inserMainValues[] = $dd;
                                    $mongoList['mainValues'][] = $dd;
                                }

                                if (sizeof($inserMainValues) > 0) {
                                    $arrBlob = blobEncode($inserMainValues);
                                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                                foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                                    $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                    //                    cekkuning("making a clone for input key $key / $val");
                                    //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                                    //                    $replacers=array(
                                    //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                                    //                    );
                                    //                    foreach($replacers as $key=>$val){
                                    //                        $tmpTableIn[$key]=$val;
                                    //                    }
                                    //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                                foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                                    $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                                foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                                    $tr->writeMainApplets($insertID, array(
                                        "mdl_name" => $amdl,
                                        "key" => $aSpec['key'],
                                        "label" => $aSpec['labelValue'],
                                        "description" => $aSpec['description'],
                                    ));
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                                foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                                    $tr->writeMainElements($insertID, array(
                                        "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                        "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                        "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                        "name" => $aSpec['name'],
                                        "label" => $aSpec["label"],
                                        "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                        "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                                    ));
                                    //==nebeng bikin inputLabels
//                                $currentValue = "";
//                                switch ($aSpec['elementType']) {
//                                    case "dataModel":
//                                        $currentValue = $aSpec['key'];
//                                        break;
//                                    case "dataField":
//                                        $currentValue = $aSpec["value"];
//                                        break;
//                                }
//                                if (array_key_exists($elName, $relOptionConfigs)) {
//                                    //					cekhijau("$eName terdaftar pada relInputs");
//
//
//                                    if (isset($relOptionConfigs[$elName][$currentValue])) {
//                                        if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
//                                            foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
//                                                $inputLabels[$oValueName] = $oValSpec["label"];
//                                                if (isset($oValSpec['auth'])) {
//                                                    if (isset($oValSpec['auth']["groupID"])) {
//                                                        $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
//                                                    }
//                                                }
//                                            }
//                                        }
//                                    }
//                                    else {
//                                        //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
//                                    }
//
//                                }

                                }
                            }
                            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {

                                $insertIDs = array();
                                $insertDeIDs = array();
                                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                    if ($insertDetailID < 1) {
                                        die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                                    }
                                    else {
                                        $insertIDs[] = $insertDetailID;
                                        $insertDeIDs[$insertID][] = $insertDetailID;
                                        $mongoList['detail'][] = $insertDetailID;
                                    }
                                    if ($epID != 999) {
                                        $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                        if ($insertEpID < 1) {
                                            die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                        }
                                        else {
                                            $insertIDs[] = $insertEpID;
                                            $insertDeIDs[$epID][] = $insertEpID;
                                            $mongoList['detail'][] = $insertEpID;
                                        }
                                    }
                                    cekUngu($this->CI->db->last_query());
                                }


                                if (sizeof($insertIDs) == 0) {
                                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                                }
                                else {
                                    $indexing_details = array();
                                    foreach ($insertDeIDs as $key => $numb) {
                                        $indexing_details[$key] = $numb;
                                    }

                                    foreach ($indexing_details as $k => $arrID) {
                                        $arrBlob = blobEncode($arrID);
                                        $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                        cekOrange($this->CI->db->last_query());
                                    }
                                }
                            }
                            else {
                                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                                $insertIDs = array();
                                foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                                    $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                                    $mongoList['detail'] = $insertIDs;
                                    if ($epID != 999) {
                                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                        $mongoList['detail'] = $insertIDs;
                                    }
                                    cekUngu($this->CI->db->last_query());
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                                $insertIDs = array();
                                foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                    $insertIDs[] = $insertDetailID;
                                    $mongoList['detail'][] = $insertDetailID;
                                    if ($epID != 999) {
                                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                                        $insertIDs[] = $dd;
                                        $mongoList['detail'][] = $dd;
                                    }
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                                $insertIDs = array();
                                foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                                    $insertIDs[] = $dd;
                                    $mongoList['detil'][] = $dd;
                                    if ($epID != 999) {
                                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                        $mongoList['detil'] = $insertIDs;
                                    }
                                    cekUngu($this->CI->db->last_query());
                                }
                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {

                                $insertIDs = array();
                                foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                                    if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues'])) {
                                        foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                            if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                                $dd = $tr->writeDetailValues($insertID, array(
                                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                                    "produk_id" => $pID,
                                                    "key" => $key,
                                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                                ));
                                                $insertIDs[$pID][] = $dd;
                                                $mongoList['detailValues'][] = $dd;

                                            }
                                        }
                                    }
                                }

                                if (sizeof($insertIDs) > 0) {
                                    $arrBlob = blobEncode($insertIDs);
                                    $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                                }

                            }
                            if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                                foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                                    if (isset($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                        $insertIDs = array();
                                        foreach ($this->configCore[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                            $dd = $tr->writeDetailValues($insertID, array(
                                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                                "produk_id" => $pID,
                                                "key" => $key,
                                                "value" => $dSpec[$src],
                                            ));
                                            $insertIDs[] = $dd;
                                            $mongoList['detailValues'][] = $dd;
                                        }
                                    }
                                }
                            }
                            //endregion

                            $baseRegistries = array(
                                "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                                "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                                "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                                "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                                "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                                "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                                "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                                "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                                "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                                "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                                "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                                'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                                'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                                'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                                'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                                'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                                'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                                'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                                'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                                "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                                "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                                'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                                'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                                'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                                'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                                'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                                'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                                'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                                'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                                'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                                "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                                "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                                "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                                "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                                "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                                "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                                "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                                "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                                "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                                "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                                "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                                "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                                "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                                //----
                                'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                                'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                                //----
                            );
                            $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                            showLast_query("hijau");
                            cekHijau("SELESAI menjalankan EDITOR...");
                        }
                    }
                    else {
                        $tableIn_master['trash_4'] = 1;
                        $tableIn_master['cancel_id'] = my_id();
                        $tableIn_master['cancel_name'] = my_name();
                        $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                        $tableIn_master['deskripsi'] = "rejection";
                        $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);
                        $mongoList["main"][] = $epID;
                        if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                            $insertIDs = array();
                            foreach ($tableIn_detail as $dSpec) {
                                if ($epID != 999) {
                                    $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                    $mongoList['detail'] = $insertIDs;
                                }
                            }
                        }
                    }
                }

                $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
                $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
                $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
                $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
                $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();

                //===if rollback is needed
                //rollback preproc, master
                if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                    $iterator = isset($core['preProcessor'][$jenisTr_component]['master']) ? $core['preProcessor'][$jenisTr_component]['master'] : array();
                    if (sizeof($iterator) > 0) {
                        $it = 0;
                        cekbiru("ada iterator pre-proc master");
                        foreach ($iterator as $cCtr => $tComSpec) {
                            $it++;
                            $oriComName = $tComSpec['comName'];
                            $comName = $tComSpec['comName'] . "_reverse";
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                            echo "reverse master-preproc: $comName, initializing values <br>";
                            $tmpOutParams[$cCtr] = array();


                            $subParams = array();

                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                    $subParams['static'][$key] = $realValue;

                                }

                                if (array_key_exists($oriComName, $prepConfigs)) {
                                    if (sizeof($prepConfigs[$oriComName]) > 0) {
                                        foreach ($prepConfigs[$oriComName] as $key => $src) {
                                            $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                        }
                                    }
                                }

                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $no;
                                }


                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                            }
                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr] = $subParams;
                            }


                            $mdlName = "Pre" . ucfirst($comName);
                            $this->CI->load->model("Preprocs/" . $mdlName);
                            $m = new $mdlName($resultParams);


                            if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                $tobeExecuted = true;
                            }
                            else {
                                $tobeExecuted = false;
                            }

                            if ($tobeExecuted) {
                                arrprint($tmpOutParams[$cCtr]);
                                $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                $gotParams = $m->exec();


                            }
                            else {
                                cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                            }

                        }
                    }
                }
                else {
                    cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
                }
                //rollback preproc, detail
                if (isset($core['preProcessor'][$jenisTr_component]['detail'])) {
                    $iterator = isset($core['preProcessor'][$jenisTr_component]['detail']) ? $core['preProcessor'][$jenisTr_component]['detail'] : array();
                    if (sizeof($iterator) > 0) {
                        $it = 0;
                        foreach ($iterator as $cCtr => $tComSpec) {
                            $it++;
                            $oriComName = $tComSpec['comName'];
                            $comName = $tComSpec['comName'] . "_reverse";
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            echo "reverse preproc (detail): $comName, initializing values <br>";
                            foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                                $tmpOutParams[$cCtr] = array();
                                //                        $id = $dSpec["id"];
                                $id = $xid;
                                $subParams = array();

                                if (isset($tComSpec['static'])) {
                                    foreach ($tComSpec['static'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                        $subParams['static'][$key] = $realValue;

                                    }

                                    if (array_key_exists($oriComName, $prepConfigs)) {
                                        cekhitam("terdapat di dalam prepConfig");
                                        if (sizeof($prepConfigs[$oriComName]) > 0) {
                                            foreach ($prepConfigs[$oriComName] as $key => $src) {
                                                $subParams['static'][$key] = makeValue($src, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                            }
                                        }
                                    }
                                    else {
                                        cekhitam("TIDAK terdapat di dalam prepConfig");
                                    }
                                    if (!isset($subParams['static']["transaksi_id"])) {
                                        $subParams['static']["transaksi_id"] = $no;
                                    }


                                    $subParams['static']["fulldate"] = date("Y-m-d");
                                    $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                                }

                                if (sizeof($subParams) > 0) {

                                    $tmpOutParams[$cCtr][] = $subParams;
                                }


                                $comName = $tComSpec['comName'] . "_reverse";
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                echo "sub preproc #$it: $comName, sending values <br>";

                                $mdlName = "Pre" . ucfirst($comName);
                                $this->CI->load->model("Preprocs/" . $mdlName);
                                $m = new $mdlName($resultParams);


                                if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                    $tobeExecuted = true;
                                }
                                else {
                                    $tobeExecuted = false;
                                }

                                if ($tobeExecuted) {

                                    //                            arrprint($tmpOutParams[$cCtr]);

                                    $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $gotParams = $m->exec();

                                    //                            cekbiru("gotparams");
                                    //                            arrprint($gotParams);

                                }
                                else {
                                    cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                }

                            }
                        }
                    }
                }
                else {
                    cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
                }
                //rollback postproc, master
                if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                    $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                    if (sizeof($iterator) > 0) {
                        foreach ($iterator as $cCtr => $tComSpec) {
                            $oriComName = $tComSpec['comName'];
                            $comName = $tComSpec['comName'];
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            echo "rollback main post-processor: $comName<br>";

                            $dSpec = $this->cCodeData[$cCode][$srcGateName];
                            $tmpOutParams = array();
                            if (isset($tComSpec['loop'])) {
                                foreach ($tComSpec['loop'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                    $tmpOutParams['loop'][$key] = $realValue;

                                }
                            }
                            if (isset($tComSpec['static'])) {
                                //cekHere("DISINI OIII");
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                    $tmpOutParams['static'][$key] = $realValue;

                                }
                                if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                    $tmpOutParams['static']["transaksi_id"] = $insertID;
                                }
                                if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                    $tmpOutParams['static']["transaksi_no"] = $insertNum;
                                }

                                $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                                $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();


                            }
                            if (isset($tComSpec['static2'])) {
                                //cekHere("DISINI OIII");
                                foreach ($tComSpec['static2'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                    $tmpOutParams['static2'][$key] = $realValue;

                                }
                                if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                    $tmpOutParams['static2']["transaksi_id"] = $insertID;
                                }
                                if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                    $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                                }

                                $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                                $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                                $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                            }


                            if (array_key_exists($oriComName, $postConfigs)) {
                                if (sizeof($postConfigs[$oriComName]) > 0) {
                                    foreach ($postConfigs[$oriComName] as $key) {
                                        $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                        cekbiru("oldVal: $oldVal");
                                        $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                        cekHijau("newVal: $newVal");
                                        //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                        $tmpOutParams['static'][$key] = $newVal;
                                    }
                                }
                            }

                            //lgShowError("Ada kesalahan",);
                            $mdlName = "Com" . ucfirst($comName);
                            $this->CI->load->model("Coms/" . $mdlName);
                            $m = new $mdlName();

                            cekBiru("kiriman rollback main-postproc $comName");
                            arrPrint($tmpOutParams);
                            $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                        }
                    }
                }
                else {
                    cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
                }
                //rollback postproc, detail
                if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {
                    $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                    if (sizeof($iterator) > 0) {
                        foreach ($iterator as $cCtr => $tComSpec) {
                            $oriComName = $tComSpec['comName'];
                            $comName = $tComSpec['comName'];
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            echo "rollback sub-postProcessor: $comName, initializing values <br>";
                            //                arrPrint($this->cCodeData[$cCode][$srcGateName]);
                            $tmpOutParams[$cCtr] = array();
                            foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                                $subParams = array();
                                if (isset($tComSpec['loop'])) {
                                    foreach ($tComSpec['loop'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                        $subParams['loop'][$key] = $realValue;

                                    }
                                }
                                if (isset($tComSpec['static'])) {
                                    foreach ($tComSpec['static'] as $key => $value) {

                                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                                        $subParams['static'][$key] = $realValue;
                                        //                                cekBiru("$key diisi dengan $realValue");

                                    }

                                    if (array_key_exists($oriComName, $postConfigs)) {
                                        //                                cekhitam("terdapat di dalam postConfig");
                                        if (sizeof($postConfigs[$oriComName]) > 0) {
                                            foreach ($postConfigs[$oriComName] as $key) {
                                                //                                        $replVal=makeValue($src,$this->cCodeData[$cCode][$srcGateName][$cnt],$this->cCodeData[$cCode][$srcGateName][$cnt],0);
                                                //                                        cekbiru("$key akan direplace dengan nilai $replVal");
                                                //                                        $subParams['static'][$key]=$replVal;

                                                $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                                cekbiru("oldVal2: $oldVal");
                                                $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                cekHijau("newVal2: $newVal");
                                                $subParams['static'][$key] = $newVal;
                                                //                                $tmpOutParams['static'][$key]=makeValue($src,$this->cCodeData[$cCode][$srcGateName],$this->cCodeData[$cCode][$srcGateName],0);
                                                //                                        $tmpOutParams['static'][$key]=$newVal;
                                            }
                                        }
                                    }
                                    else {
                                        //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                    }

                                    //                            $subParams['static']["transaksi_id"] = $insertID;
                                    if (!isset($subParams['static']["transaksi_id"])) {
                                        $subParams['static']["transaksi_id"] = $no;
                                    }
                                    if (!isset($subParams['static']["transaksi_no"])) {
                                        $subParams['static']["transaksi_no"] = $no;
                                    }
                                    $subParams['static']["fulldate"] = date("Y-m-d");
                                    $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $subParams['static']["keterangan"] = "rollback of $no";
                                }


                                if (sizeof($subParams) > 0) {
                                    $tmpOutParams[$cCtr][] = $subParams;
                                }
                            }
                        }

                        foreach ($iterator as $cCtr => $tComSpec) {
                            $oriComName = $tComSpec['comName'];
                            $comName = $tComSpec['comName'];
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            echo "sub-postProcessor: $comName, sending values <br>";

                            $mdlName = "Com" . ucfirst($comName);
                            $this->CI->load->model("Coms/" . $mdlName);
                            $m = new $mdlName();


                            cekBiru("kiriman rollback detail-postproc $comName");
                            arrPrint($tmpOutParams[$cCtr]);
                            $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }
                    }
                }
                else {
                    cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
                }

            }

        }


        if (sizeof($referenceRevertConfigs) > 0) {
            if (isset($referenceRevertConfigs['enabled']) && ($referenceRevertConfigs['enabled'] == true)) {

                $arrQtyRevert = array();
                foreach ($items as $spec) {
                    $arrQtyRevert[$spec["id"]] = $spec['qty'];
                }

                $referenceID = $this->cCodeData[$cCode]["main"][$referenceRevertConfigs['referenceID']];
                cekHitam(":: $referenceID ::");

                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $refTr = $tr->lookupDetailTransaksi($referenceID)->result();
                if (sizeof($refTr) > 0) {
                    foreach ($refTr as $spec) {
                        $qty = isset($arrQtyRevert[$spec->produk_id]) ? $arrQtyRevert[$spec->produk_id] : 0;
                        $data = array(
                            "valid_qty" => $spec->valid_qty + $qty,
                            "req_cancel_qty" => $spec->req_cancel_qty - $qty,
                        );
                        $where = array(
                            "produk_id" => $spec->produk_id,
                            "transaksi_id" => $spec->transaksi_id,
                        );
                        $to = new MdlTransaksi();
                        $to->setFilters(array());
                        $to->setTableName($to->getTableNames()['detail']);
                        $dupState = $to->updateData($where, $data);
                        $mongListUpadte['update']['detail'][] = array(
                            "where" => $where,
                            "value" => $data,
                        );
                        cekPink2($this->CI->dblast_query());
                    }
                }

                //arrPrint($arrQtyRevert);
            }
        }


        //==================================================================================================
        $this->CI->load->model("Mdls/MdlTransaksiLaporan");
        $lt = New MdlTransaksiLaporan();
        $dataTransaksiLaporan = array(
            "transaksi_id" => $currentInsertID,
            "master_id" => $currentMasterID,
            "nomer" => $currentNomer,
            "metode" => "reject",
        );
        $lt->addData($dataTransaksiLaporan);
        showLast_query("ungu");
        //==================================================================================================
        //==MENGUPDATE LOCKER TRANSAKSI ====================================================================
        $this->CI->load->model("Mdls/MdlLockerTransaksi");
        $lt = New MdlLockerTransaksi();
        $lt->execLocker($this->cCodeData[$cCode]["main"], $nextProp["num"], $transaksiID_reference, NULL);
        //==================================================================================================

        $libResult = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $insertID,
        );
        return $libResult;
    }

    //-doRevertAll--------------------------
    public function doRevertAll()
    {
        $location = "(library " . get_class($this) . ", method " . __FUNCTION__ . ")";
        $this->setterValidate($location);


        $transaksiID_reference = $no = $this->transaksiNumber;
        $jenisTr_con = $jenisTr = $this->jenisTr;
        $stepNumCurrent = $stepNumCurrent = $masterTargetStepNum = $childTargetStepNum = $this->stepNumCurrent;
        $cCode = $this->cCode;

        $prepConfigs = null != $this->CI->config->item('hePreProcessors') ? $this->CI->config->item('hePreProcessors') : array();
        $postConfigs = null != $this->CI->config->item('hePostProcessors') ? $this->CI->config->item('hePostProcessors') : array();
        $postDeniedConfigs = null != $this->CI->config->item('hePostProcessorsDenied') ? $this->CI->config->item('hePostProcessorsDenied') : array();


        // region transaksi yang dibuka
        $this->CI->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();
        $tr->setFilters(array());
        $tr->addFilter("id='$no'");
        $tmpTr = $tr->lookupMainTransaksi()->result();
        //        cekOrange($this->CI->db->last_query());
        $insertID = $tmpTr[0]->id;
        $insertNum = $tmpTr[0]->nomer;
        $masterID = $tmpTr[0]->id_master;
        // endregion transaksi yang dibuka
        cekHitam("trID: $insertID, masterID: $masterID");

        //region membaca transaksi berdasarkan masterID
        $trm = new MdlTransaksi();
        $trm->setFilters(array());
        $trm->addFilter("id_master='$masterID'");
        $trm->addFilter("link_id='0'");
        $trm->addFilter("trash_4='0'");
        $tmpTrm = $trm->lookupMainTransaksi()->result();
        showLast_query("biru");
        $indexReg = array();
        $arrMainDataTrans = array();
        $arrMainDataTransID = array();
        $arrTrIDs = array();
        $regParam = array(
            "main",
            "items",
            "tableIn_master",
            "tableIn_detail",
        );
        foreach ($tmpTrm as $tmpTrmSpec) {
            $arrMainDataTransID[$tmpTrmSpec->id] = array(
                "step" => $tmpTrmSpec->step_number,
                "jenisTr" => $tmpTrmSpec->jenis_master,
                "transaksi_id" => $tmpTrmSpec->id,
                "nomer" => $tmpTrmSpec->nomer,
            );
//            $indexRegTmp = blobDecode($tmpTrmSpec->indexing_registry);
//            foreach ($indexRegTmp as $key => $val) {
//                if (in_array($key, $regParam)) {
//                    $indexReg[] = $val;
//                }
//            }
            $arrTrIDs[$tmpTrmSpec->id] = $tmpTrmSpec->id;
        }
        //endregion

        krsort($arrMainDataTransID);

        //region swap from registry
        $tr = new MdlTransaksi();
        $tr->setFilters(array());
//        $tr->addFilter("transaksi_id in ('" . implode("','", $indexReg) . "')");
        $tr->addFilter("transaksi_id in ('" . implode("','", $arrTrIDs) . "')");
        $tmpReg = $tr->lookupDataRegistries()->result();
        //        cekmerah($this->CI->db->last_query());

        $tmpRegData = array();
        if (sizeof($tmpReg) > 0) {
            foreach ($tmpReg as $row) {
                foreach ($row as $key_reg => $val_reg) {
                    if (in_array($key_reg, $regParam)) {
                        $tmpRegData[$row->transaksi_id][$key_reg] = $val_reg;
                    }
                }

            }
        }
        //endregion


        $nextProp = array(
            "num" => 0,
            "code" => "",
            "label" => "",
            "groupID" => "",
        );
        $mongListUpadte = array();
        $mongoList = array();
        foreach ($arrMainDataTransID as $arrMainDataTransIDSpec) {

            $no = $arrMainDataTransIDSpec['transaksi_id'];
            $stepNumCurrent = $arrMainDataTransIDSpec['step'];
            $jenisTr = $arrMainDataTransIDSpec['jenisTr'];
            cekUngu(":: trID yang dibatalkan $no ::");
            $tp = new MdlTransaksi();
            $tp->addFilter("id='$no'");
            $tpTmp = $tp->lookupAll()->result();
            $currentMasterID = $tpTmp[0]->id_master;


            cekHitam("MENGEMBALIKAN PRE & POST UNTUK STEP $stepNumCurrent");

            $arrData = array(
                "next_step_code" => $nextProp["code"],
                "next_step_label" => $nextProp["label"],
                "next_group_code" => $nextProp["groupID"],
                "next_step_num" => $nextProp["num"],
                "step_current" => $stepNumCurrent,
                //                "step_number" => $stepNumCurrent,
                "trash_4" => "1",
                "cancel_dtime" => date("Y-m-d H:i:s"),
                "cancel_name" => my_name(),
                "cancel_id" => my_id(),
            );
            $arrData_detail = array(
                "next_substep_code" => $nextProp["code"],
                "next_substep_label" => $nextProp["label"],
                "next_subgroup_code" => $nextProp["groupID"],
                "next_substep_num" => $nextProp["num"],
                "sub_step_number" => 0,
            );

            foreach ($tmpRegData[$no] as $key_reg => $val_reg) {

                $var = $key_reg;
                $$var = blobDecode($val_reg);
            }


            //region update step yang sebelumnya aktif, transaksi yang dibuka sekarang
            $tp = new MdlTransaksi();
            $dupState = $tp->updateData(array(
                "id" => $no,
            ), $arrData) or die("Failed to update tr next-state!");
            $mongListUpadte['update']["main"][] = array(
                "where" => array("id" => $no,),
                "value" => $arrData,
            );
            cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

            $to = new MdlTransaksi();
            $to->setFilters(array());
            $to->setTableName($to->getTableNames()['detail']);
            $dupState = $to->updateData(array(
                "transaksi_id" => $no,
                "trash" => 0,
            ), $arrData_detail) or die("Failed to update tr next-state!");
            $mongListUpadte['update']['detail'][] = array(
                "where" => array(
                    "transaksi_id" => $no,
                    "trash" => 0,
                ),
                "value" => $arrData_detail,
            );
            cekLime($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");

            //endregion


            //region sesuaikan signature untuk cloningan, ikut minus
            $arrSign = array(
                "prev_id" => $no,
                "nomer" => "rejection",
                "step_number" => -$stepNumCurrent, // ini minus step number
                "step_code" => $this->configUiModul[$jenisTr]["steps"][abs($stepNumCurrent)]["target"],
                "step_name" => $this->configUiModul[$jenisTr]["steps"][abs($stepNumCurrent)]["label"],
                "group_code" => $this->configUiModul[$jenisTr]["steps"][abs($stepNumCurrent)]['userGroup'],
                "oleh_id" => my_id(),
                "oleh_nama" => my_name(),
                "keterangan" => $this->configUiModul[$jenisTr]["steps"][abs($stepNumCurrent)]["label"] . " oleh " . my_name(),
            );
            $dwsign = $tr->writeSignature($tmpTr[0]->id_top, $arrSign) or die("Failed to write signature");
            $mongoList['sign'][] = $dwsign;
            cekPink2($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
            //endregion


            // region netralisasi payment source
            $tr = New MdlTransaksi();
            $tr->setFilters(array());
            $tr->addFilter("sisa>0");
            $paymentSrc = $tr->lookupPaymentSrcByTransID($no)->result();
            cekBiru($this->CI->db->last_query());
            if (sizeof($paymentSrc) > 0) {
                foreach ($paymentSrc as $pSpec) {
                    if ($pSpec->terbayar == 0) {
                        $where = array(
                            "id" => $pSpec->id,
                            "transaksi_id" => $pSpec->transaksi_id,
                        );
                        $data = array(
                            "sisa" => 0,
                            "returned" => $pSpec->sisa,
                            "sisa_valas" => 0,
                            "returned_valas" => $pSpec->sisa_valas,
                            "cancel_id" => my_id(),
                            "cancel_name" => my_name(),
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                        );

                        $tra = New MdlTransaksi();
                        $tra->setFilters(array());
                        $tra->updatePaymentSrc($where, $data);
                        cekUngu(":: mereject payment source bila ada...");
                        cekUngu($this->CI->db->last_query());
                    }
                    else {
                        mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                    }
                }
            }
            else {
                cekBiru(":: tidak ada payment source... ::");
            }
            // endregion netralisasi payment source

            // region netralisasi extended step
            $tr = New MdlTransaksi();
            $tr->setFilters(array());
            $exTmp = $tr->lookupExtStepByTrID($no);
            if (sizeof($exTmp) > 0) {
                foreach ($exTmp as $exSpec) {

                    $tra = New MdlTransaksi();
                    $tra->setFilters(array());
                    $tra->rejectExtStepByID($exSpec["id"]);
                    $mongListUpadte['update']['extra'][] = array(
                        "where" => array(
                            "id" => $exSpec["id"],
                        ),
                        "value" => array(
                            "state" => "-1",
                        ),
                    );
                    cekUngu(":: mereject extended step bila ada...");
                    cekUngu($this->CI->db->last_query());
                }
            }
            else {
                cekBiru(":: tidak ada extended step... ::");
            }

            // endregion netralisasi extended step

            // region menulis entry point
            if (isset($tableIn_master) && sizeof($tableIn_master) > 0) {
                if (isset($this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent])) {
                    if ($this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["enabled"] == true) {
                        $masterID = $currentMasterID;
                        $connecTo = $this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["connectTo"];
                        cekHijau("START menjalankan REJECT ALL... [$masterID] [$connecTo]");
                        if ($connecTo == NULL) {
                            mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                        }
                        $oldCode = $cCode;
                        $cCode = "_TR_" . $connecTo;
                        $this->cCodeData[$cCode] = array(
                            "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                            "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                            "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                            "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                            "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                            "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                            "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                            "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                            "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                            "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                            "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                            'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                            'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                            'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                            'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                            'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                            'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                            'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                            'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                            "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                            "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                            'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                            'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                            'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                            'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                            'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                            'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                            'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                            'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                            'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                            'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                            'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                            'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                            'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                            "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                            "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                            "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                            "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                            "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                            "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                            "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                            "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                            "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                            "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                            "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                            "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                            "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                        );
                        // masuk ke gerbang TableInMaster, tabel transaksi
                        $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                            "jenis_master" => $this->jenisTr,
                            "jenis_top" => $connecTo,
                            "jenis" => $connecTo,
                            "jenis_label" => $this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "transaksi_jenis" => $connecTo,
                            "step_avail" => 1,
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => "",
                            "next_step_label" => "",
                            "next_group_code" => "",
                            "next_step_num" => "0",
                            "trash_4" => 1,
                            "cancel_dtime" => date("Y-m-d H:i:s"),
                            "cancel_name" => my_name(),
                            "cancel_id" => my_id(),
                            "deskripsi" => "rejection",
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name()
                        );
                        // masuk ke gerbang main
                        $masterReplacersO = array(
                            "stepCode" => $connecTo,
                            "jenisTrTop" => $connecTo,
                            "jenisTrName" => $this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["label"],
//                        "inv" => $tmpNomorNota,
                            "jenis_master" => $this->jenisTr,
                            "jenis_top" => $connecTo,
                            "jenis" => $connecTo,
                            "jenis_label" => $this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "transaksi_jenis" => $connecTo,
                            "stepCode" => $connecTo,
                            "jenisTrTop" => $connecTo,
                            "jenisTrName" => $this->configUiModul[$this->jenisTr]["connectToReject"][$stepNumCurrent]["label"],
                            "step_avail" => 1,
                            "step_current" => 1,
                            "step_number" => 1,
                            "next_step_code" => "",
                            "next_step_label" => "",
                            "next_group_code" => "",
                            "next_step_num" => "0",
                            "olehID" => my_id(),
                            "olehName" => my_name(),
                        );
                        foreach ($masterReplacersO as $key => $val) {
                            $this->cCodeData[$cCode]["main"][$key] = $val;
                        }
                        foreach ($masterReplacers as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }

                        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
                        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];

                        //region penomoran receipt
                        $this->CI->load->model("CustomCounter");
                        $cn = new CustomCounter("transaksi");
                        $cn->setType("transaksi");
                        $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaReject']);
                        if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersReject'])) {
                            die(__LINE__ . " Used number should be registered in counters config as well");
                        }
                        echo "<div style='background:#ff7766;'>";
                        foreach ($counterForNumber as $i => $cRawParams) {
                            $cParams = explode("|", $cRawParams);
                            $cValues = array();
                            foreach ($cParams as $param) {
                                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                            }
                            $cRawValues = implode("|", $cValues[$i]);
                            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                        }
                        echo "</div style='background:#ff7766;'>";

                        $stepNumber = 1;
                        $tmpNomorNota = $paramSpec["paramString"];
                        $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                        $nextProp = array(
                            "num" => 0,
                            "code" => "",
                            "label" => "",
                            "groupID" => "",
                        );
                        //endregion

                        //region dynamic counters
                        // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                        $cn = new CustomCounter("transaksi");
                        $cn->setType("transaksi");
                        $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersReject'];
                        arrPrintHijau($configCustomParams);
                        $configCustomParams[] = "stepCode";
                        //arrPrint($configCustomParams);
                        if (sizeof($configCustomParams) > 0) {
                            $cContent = array();
                            foreach ($configCustomParams as $i => $cRawParams) {
                                $cParams = explode("|", $cRawParams);
                                $cValues = array();
                                foreach ($cParams as $param) {
                                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                                }
                                $cRawValues = implode("|", $cValues[$i]);
                                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                                $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                                switch ($paramSpec["id"]) {
                                    case 0: //===counter type is new
                                        $addData = array(
                                            "toko_id" => $tokoID,
                                            "toko_nama" => $tokoNama,
                                        );
                                        $paramKeyRaw = print_r($cParams, true);
                                        $paramValuesRaw = print_r($cValues[$i], true);
                                        $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                        showLast_query("biru");
                                        break;
                                    default: //===counter to be updated
                                        $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                        break;
                                }
                                //echo "<hr>";
                            }
                        }
                        $appliedCounters = base64_encode(serialize($cContent));
                        $appliedCounters_inText = print_r($cContent, true);
//                        mati_disini();
//arrPrintPink($cContent);
                        //
                        //region addition on master


                        $addValues = array(
                            "counters" => $appliedCounters,
                            'counters_intext' => $appliedCounters_inText,
                            'nomer' => $tmpNomorNota,
                            'nomer2' => $tmpNomorNotaAlias,
                            'dtime' => date("Y-m-d H:i:s"),
                            'fulldate' => date("Y-m-d"),
                            "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                            "step_number" => 1,
                            "step_current" => 1,
                            "next_step_num" => $nextProp["num"],
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],
                            "tail_number" => 1,
                            "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                        );
                        foreach ($addValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        //endregion

                        //
                        //region addition on detail
                        $addSubValues = array(
                            "sub_step_number" => 1,
                            "sub_step_current" => 1,
                            "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                            "next_substep_num" => $nextProp["num"],
                            "next_substep_code" => $nextProp["code"],
                            "next_substep_label" => $nextProp["label"],
                            "next_subgroup_code" => $nextProp["groupID"],
                            "sub_tail_number" => 1,
                            "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                        );
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                            foreach ($addSubValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                            }
                        }
                        //endregion
                        // </editor-fold>
                        //endregion

                        $addValues = array(
                            "counters" => $appliedCounters,
                            'counters_intext' => $appliedCounters_inText,
                            'nomer' => $tmpNomorNota,
                            'nomer2' => $tmpNomorNotaAlias,
                            'dtime' => date("Y-m-d H:i:s"),
                            'fulldate' => date("Y-m-d"),
                        );
                        foreach ($addValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        $masterReplacers = array(
                            "nomer" => $tmpNomorNota,
                            "nomer2" => $tmpNomorNotaAlias,
                            "counters" => $appliedCounters,
                            "counters_intext" => $appliedCounters_inText,
                        );
                        foreach ($masterReplacers as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }
                        $detailReplacers = array(
                            "sub_step_avail" => 1,
                            "sub_step_current" => 1,
                            "sub_step_number" => 1,
                            "next_substep_num" => "",
                            "next_substep_code" => "",
                            "next_substep_label" => "",
                            "next_subgroup_code" => "",
                        );
                        if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                                foreach ($dSpec as $key => $val) {
                                    $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                                }
                            }
                        }
                        $itemsReplacers = array(
                            "next_substep_num" => "",
                            "next_substep_code" => "",
                            "next_substep_label" => "",
                            "next_subgroup_code" => "",
                        );
                        if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                            foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                                foreach ($dSpec as $key => $val) {
                                    $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                                }
                            }
                        }

                        //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                        if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                            $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                            $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 1;// dibatalkan
                            $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;

                            $tr = new MdlTransaksi();
                            $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                            $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                            cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                            $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                            $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                            $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                            if ($insertID < 1) {
                                die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                            }
                            $mongoList["main"] = array($insertID, $epID);
                            //==transaksi_id dan nomor nota diinject kan ke gate utama
                            $injectors = array(
                                "transaksi_id" => $insertID,
                                "nomer" => $tmpNomorNota,
                                "nomer2" => $tmpNomorNotaAlias,
                            );
                            $arrInjectorsTarget = array(
                                "items",
                                "items2_sum",
                                "rsltItems",
                            );
                            foreach ($injectors as $key => $val) {
                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                foreach ($arrInjectorsTarget as $target) {
                                    if (isset($this->cCodeData[$cCode][$target])) {
                                        foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                            $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                            if (isset($this->cCodeData[$cCode][$target][$id])) {
                                                $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                            }
                                        }
                                    }
                                }
                            }

                            //===signature
                            $dwsign = $tr->writeSignature($insertID, array(
                                "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "step_number" => 1,
                                "step_code" => $connecTo,
                                "step_name" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
                                "group_code" => "",
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                                "transaksi_id" => $masterID,
                                "deskripsi" => "edit transaksi",
                                "cabang_id" => my_cabang_id(),
                                "cabang_nama" => my_cabang_name(),
                                "current_transaksi_id" => $masterID,
                                "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            )) or die("Failed to write signature");
                            showLast_query("kuning");
                            $mongoList['sign'][] = $dwsign;
                            $idHis = array(
                                $stepNumber => array(
                                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                    "step" => $stepNumber,
                                    "trID" => $insertID,
                                    "nomer" => $tmpNomorNota,
                                    "nomer2" => $tmpNomorNotaAlias,
                                    "counters" => $appliedCounters,
                                    "counters_intext" => $appliedCounters_inText,
                                ),
                            );
                            $idHis_blob = blobEncode($idHis);
                            $idHis_intext = print_r($idHis, true);
                            $tr = new MdlTransaksi();
                            $dupState = $tr->updateData(array("id" => $insertID), array(
                                "next_step_num" => $nextProp["num"],
                                "next_step_code" => $nextProp["code"],
                                "next_step_label" => $nextProp["label"],
                                "next_group_code" => $nextProp["groupID"],

                                //===references
//                            "id_master" => $insertID,
                                "id_master" => $masterID,// milik transkasiID yang diedit
                                "id_top" => $insertID,
                                "ids_prev" => "",
                                "ids_prev_intext" => "",
                                "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "nomers_prev" => "",
                                "nomers_prev_intext" => "",
                                "jenises_prev" => "",
                                "jenises_prev_intext" => "",
                                "ids_his" => $idHis_blob,
                                "ids_his_intext" => $idHis_intext,

                            )) or die("Failed to update tr next-state!");
                            cekHijau($this->CI->db->last_query());

                            $addValues = array(
                                //===references
                                "id_master" => $insertID,
                                "id_top" => $insertID,
                                "ids_prev" => "",
                                "ids_prev_intext" => "",
                                "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                                "nomers_prev" => "",
                                "nomers_prev_intext" => "",
                                "jenises_prev" => "",
                                "jenises_prev_intext" => "",
                                "ids_his" => $idHis_blob,
                                "ids_his_intext" => $idHis_intext,
                            );
                            foreach ($addValues as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                            }

                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                            $inserMainValues = array();
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'])) {
                                //matiHEre("hooppp");
                                $inserMainValues = array();
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                    if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                        $dd = $tr->writeMainValues($insertID, array(
                                            "key" => $key,
                                            "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                        ));

                                        $inserMainValues[] = $dd;
                                        $mongoList['mainValues'][] = $dd;
                                    }
                                }
                            }

                            if (sizeof($inserMainValues) > 0) {
                                $arrBlob = blobEncode($inserMainValues);
                                $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                            }

                        }
                        if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                            $inserMainValues = array();
                            foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                                $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                $inserMainValues[] = $dd;
                                $mongoList['mainValues'][] = $dd;
                            }

                            if (sizeof($inserMainValues) > 0) {
                                $arrBlob = blobEncode($inserMainValues);
                                $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                                $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                                //                    cekkuning("making a clone for input key $key / $val");
                                //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                                //                    $replacers=array(
                                //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                                //                    );
                                //                    foreach($replacers as $key=>$val){
                                //                        $tmpTableIn[$key]=$val;
                                //                    }
                                //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                                $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                                $tr->writeMainApplets($insertID, array(
                                    "mdl_name" => $amdl,
                                    "key" => $aSpec['key'],
                                    "label" => $aSpec['labelValue'],
                                    "description" => $aSpec['description'],
                                ));
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                            foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                                $tr->writeMainElements($insertID, array(
                                    "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                    "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                    "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                    "name" => $aSpec['name'],
                                    "label" => $aSpec["label"],
                                    "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                    "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                                ));
                                //==nebeng bikin inputLabels
//                                $currentValue = "";
//                                switch ($aSpec['elementType']) {
//                                    case "dataModel":
//                                        $currentValue = $aSpec['key'];
//                                        break;
//                                    case "dataField":
//                                        $currentValue = $aSpec["value"];
//                                        break;
//                                }
//                                if (array_key_exists($elName, $relOptionConfigs)) {
//                                    //					cekhijau("$eName terdaftar pada relInputs");
//
//
//                                    if (isset($relOptionConfigs[$elName][$currentValue])) {
//                                        if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
//                                            foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
//                                                $inputLabels[$oValueName] = $oValSpec["label"];
//                                                if (isset($oValSpec['auth'])) {
//                                                    if (isset($oValSpec['auth']["groupID"])) {
//                                                        $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
//                                                    }
//                                                }
//                                            }
//                                        }
//                                    }
//                                    else {
//                                        //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
//                                    }
//
//                                }

                            }
                        }
                        if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {

                            $insertIDs = array();
                            $insertDeIDs = array();
                            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                                $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                if ($insertDetailID < 1) {
                                    die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                                }
                                else {
                                    $insertIDs[] = $insertDetailID;
                                    $insertDeIDs[$insertID][] = $insertDetailID;
                                    $mongoList['detail'][] = $insertDetailID;
                                }
                                if ($epID != 999) {
                                    $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                    if ($insertEpID < 1) {
                                        die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                    }
                                    else {
                                        $insertIDs[] = $insertEpID;
                                        $insertDeIDs[$epID][] = $insertEpID;
                                        $mongoList['detail'][] = $insertEpID;
                                    }
                                }
                                cekUngu($this->CI->db->last_query());
                            }


                            if (sizeof($insertIDs) == 0) {
                                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                            }
                            else {
                                $indexing_details = array();
                                foreach ($insertDeIDs as $key => $numb) {
                                    $indexing_details[$key] = $numb;
                                }

                                foreach ($indexing_details as $k => $arrID) {
                                    $arrBlob = blobEncode($arrID);
                                    $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                    cekOrange($this->CI->db->last_query());
                                }
                            }
                        }
                        else {
                            die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                                $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                                $mongoList['detail'] = $insertIDs;
                                if ($epID != 999) {
                                    $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                    $mongoList['detail'] = $insertIDs;
                                }
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                                $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                                $insertIDs[] = $insertDetailID;
                                $mongoList['detail'][] = $insertDetailID;
                                if ($epID != 999) {
                                    $dd = $tr->writeDetailEntries($epID, $dSpec);
                                    $insertIDs[] = $dd;
                                    $mongoList['detail'][] = $dd;
                                }
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                                $dd = $tr->writeDetailEntries($insertID, $dSpec);
                                $insertIDs[] = $dd;
                                $mongoList['detil'][] = $dd;
                                if ($epID != 999) {
                                    $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                    $mongoList['detil'] = $insertIDs;
                                }
                                cekUngu($this->CI->db->last_query());
                            }
                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {

                            $insertIDs = array();
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                        if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                            $dd = $tr->writeDetailValues($insertID, array(
                                                "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                                "produk_id" => $pID,
                                                "key" => $key,
                                                "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                            ));
                                            $insertIDs[$pID][] = $dd;
                                            $mongoList['detailValues'][] = $dd;

                                        }
                                    }
                                }
                            }

                            if (sizeof($insertIDs) > 0) {
                                $arrBlob = blobEncode($insertIDs);
                                $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                            }

                        }
                        if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                            foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                    $insertIDs = array();
                                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                        $dd = $tr->writeDetailValues($insertID, array(
                                            "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                            "produk_id" => $pID,
                                            "key" => $key,
                                            "value" => $dSpec[$src],
                                        ));
                                        $insertIDs[] = $dd;
                                        $mongoList['detailValues'][] = $dd;
                                    }
                                }
                            }
                        }
                        //endregion

                        $baseRegistries = array(
                            "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                            "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                            "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                            "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                            "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                            "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                            "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                            "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                            "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                            "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                            "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                            'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                            'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                            'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                            'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                            'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                            'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                            'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                            'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                            "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                            "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                            'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                            'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                            'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                            'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                            'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                            'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                            'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                            'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                            'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                            'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                            'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                            'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                            'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                            "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                            "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                            "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                            "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                            "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                            "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                            "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                            "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                            "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                            "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                            "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                            "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                            "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                            //----
                            'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                            'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                            //----
                        );
                        $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                        showLast_query("hijau");
                        cekHijau("SELESAI menjalankan REJECT ALL...");
                    }
                }
                else {
                    $tableIn_master['trash_4'] = 1;
                    $tableIn_master['deskripsi'] = "rejection";
                    $tableIn_master['cancel_dtime'] = date("Y-m-d H:i:s");
                    $tableIn_master['cancel_name'] = my_name();
                    $tableIn_master['cancel_id'] = my_id();
                    $epID = $tr->writeMainEntries_entryPoint($no, $tableIn_master['id_master'], $tableIn_master);
                    $mongoList["main"][] = $epID;
                    showLast_query("pink");
                    if (isset($tableIn_detail) && sizeof($tableIn_detail) > 0) {
                        $insertIDs = array();
                        foreach ($tableIn_detail as $dSpec) {
                            if ($epID != 999) {
                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                $mongoList['detail'] = $insertIDs;
                                showLast_query("pink2");
                            }
                        }
                    }
                }
            }
            // endregion menulis entry point


            $jenisTr_component = isset($this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"]) ? $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["target"] : NULL;
            $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
            $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
            $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
            $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["runCoreAkunting"] : false;
            $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();


//mati_disini("jenisTr target $jenisTr_component");
            //rollback preproc, master
            if (isset($core['preProcessor'][$jenisTr_component]['master'])) {
                $iterator = isset($core['preProcessor'][$jenisTr_component]['master']) ? $core['preProcessor'][$jenisTr_component]['master'] : array();
                if (sizeof($iterator) > 0) {
                    $it = 0;
                    cekbiru("ada iterator pre-proc master");
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $it++;
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'] . "_reverse";
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                        $gateItems = $$srcGateName;

                        echo "reverse master-preproc: $comName, initializing values <br>";
                        $tmpOutParams[$cCtr] = array();


                        $subParams = array();

                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $gateItems, $gateItems, 0);
                                $subParams['static'][$key] = $realValue;

                            }

                            if (array_key_exists($oriComName, $prepConfigs)) {
                                if (sizeof($prepConfigs[$oriComName]) > 0) {
                                    foreach ($prepConfigs[$oriComName] as $key => $src) {
                                        $subParams['static'][$key] = makeValue($src, $gateItems, $gateItems, 0);
                                    }
                                }
                            }

                            if (!isset($subParams['static']["transaksi_id"])) {
                                $subParams['static']["transaksi_id"] = $no;
                            }


                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                        }
                        if (sizeof($subParams) > 0) {
                            $tmpOutParams[$cCtr] = $subParams;
                        }


                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);


                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            arrprint($tmpOutParams[$cCtr]);
                            $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();


                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }

                    }
                }
            }
            else {
                cekbiru("TIDAK ada config pre-proc master $jenisTr :: $stepNumCurrent");
            }
            //rollback preproc, detail
            if (isset($core['preProcessor'][$jenisTr_component]['detail'])) {
                $iterator = isset($core['preProcessor'][$jenisTr_component]['detail']) ? $core['preProcessor'][$jenisTr_component]['detail'] : array();
                if (sizeof($iterator) > 0) {
                    $it = 0;
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $it++;
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'] . "_reverse";
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $gateItems = $$srcGateName;

                        echo "reverse preproc (detail): $comName, initializing values <br>";
                        foreach ($gateItems as $xid => $dSpec) {
                            $tmpOutParams[$cCtr] = array();
                            //                        $id = $dSpec["id"];
                            $id = $xid;
                            $subParams = array();

                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $gateItems[$id], $gateItems[$id], 0);
                                    $subParams['static'][$key] = $realValue;

                                }

                                if (array_key_exists($oriComName, $prepConfigs)) {
                                    cekhitam("terdapat di dalam prepConfig");
                                    if (sizeof($prepConfigs[$oriComName]) > 0) {
                                        foreach ($prepConfigs[$oriComName] as $key => $src) {
                                            $subParams['static'][$key] = makeValue($src, $gateItems[$id], $gateItems[$id], 0);
                                        }
                                    }
                                }
                                else {
                                    cekhitam("TIDAK terdapat di dalam prepConfig");
                                }
                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $no;
                                }


                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = "rollingback " . $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();
                            }

                            if (sizeof($subParams) > 0) {

                                $tmpOutParams[$cCtr][] = $subParams;
                            }


                            $comName = $tComSpec['comName'] . "_reverse";
                            $srcGateName = $tComSpec['srcGateName'];
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                            echo "sub preproc #$it: $comName, sending values <br>";

                            $mdlName = "Pre" . ucfirst($comName);
                            $this->CI->load->model("Preprocs/" . $mdlName);
                            $m = new $mdlName($resultParams);


                            if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                $tobeExecuted = true;
                            }
                            else {
                                $tobeExecuted = false;
                            }

                            if ($tobeExecuted) {

                                //                            arrprint($tmpOutParams[$cCtr]);

                                $m->pair($no, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                $gotParams = $m->exec();

                                //                            cekbiru("gotparams");
                                //                            arrprint($gotParams);

                            }
                            else {
                                cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                            }

                        }
                    }
                }
            }
            else {
                cekbiru("TIDAK ada config pre-proc detail $jenisTr :: $stepNumCurrent");
            }
            //rollback postproc, master
            if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'])) {
                $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['master'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $gateItems = $$srcGateName;

                        echo "rollback main post-processor: $comName<br>";
                        if (!in_array($comName, $postDeniedConfigs)) {

                            $dSpec = $gateItems;
                            $tmpOutParams = array();
                            if (isset($tComSpec['loop'])) {
                                foreach ($tComSpec['loop'] as $key => $value) {

                                    $realValue = makeValue($value, $gateItems, $gateItems, 0);
                                    $tmpOutParams['loop'][$key] = $realValue;

                                }
                            }
                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $gateItems, $gateItems, 0);
                                    $tmpOutParams['static'][$key] = $realValue;

                                }
                                if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                    $tmpOutParams['static']["transaksi_id"] = $insertID;
                                }
                                if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                    $tmpOutParams['static']["transaksi_no"] = $insertNum;
                                }

                                $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                                $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $tmpOutParams['static']["keterangan"] = $this->configUiModul[$jenisTr]["steps"][$stepNumCurrent]["label"] . " nomor " . $no . " oleh " . my_name();


                            }
                            if (isset($tComSpec['static2'])) {

                                foreach ($tComSpec['static2'] as $key => $value) {

                                    $realValue = makeValue($value, $gateItems[$cCtr], $gateItems[$cCtr], 0);
                                    $tmpOutParams['static2'][$key] = $realValue;

                                }
                                if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                    $tmpOutParams['static2']["transaksi_id"] = $insertID;
                                }
                                if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                    $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                                }

                                $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                                $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                                $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                            }

                            if (array_key_exists($oriComName, $postConfigs)) {
                                if (sizeof($postConfigs[$oriComName]) > 0) {
                                    foreach ($postConfigs[$oriComName] as $key) {
                                        $oldVal = isset($tmpOutParams['static'][$key]) ? $tmpOutParams['static'][$key] : 0;
                                        cekbiru("oldVal: $oldVal");
                                        $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                        cekHijau("newVal: $newVal");
                                        $tmpOutParams['static'][$key] = $newVal;
                                    }
                                }
                            }


                            $mdlName = "Com" . ucfirst($comName);
                            $this->CI->load->model("Coms/" . $mdlName);
                            $m = new $mdlName();

                            cekBiru("kiriman rollback main-postproc $comName");

                            $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);

                        }
                        else {
                            cekHitam("$comName denied");
                        }

                    }
                }
            }
            else {
                cekbiru("TIDAK ada config post-proc master $jenisTr :: $stepNumCurrent");
            }
            //rollback postproc, detail
            if (isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'])) {
                $iterator = isset($this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail']) ? $this->configValuesModul[$jenisTr]['postProcessor'][$jenisTr_component]['detail'] : array();
                if (sizeof($iterator) > 0) {
                    cekHitam("cetak iterator :: $jenisTr :: $stepNumCurrent ||");
                    //                    arrPrintWebs($iterator);
                    $iteratorAdd = array();
                    foreach ($iterator as $cCtr => $tComSpec) {
                        if (isset($tComSpec['static']['state']) && ($tComSpec['static']['state'] == '.hold')) {
                            if (isset($tComSpec['static']['oleh_id']) && ($tComSpec['static']['oleh_id'] != '.0')) {
                                // bila state == .hold dan oleh_id != .0, maka dibuatkan ::
                                // HOLD, +QTY, oleh_id dan ACTIVE, -QTY
                                $tComSpecAddHold = $tComSpec;
                                $tComSpecAddActive = $tComSpec;
                                $staticReplaceHold = array(
                                    "jumlah" => "qty",
                                    "transaksi_no" => ".0",
                                );
                                $staticReplaceActive = array(
                                    "jumlah" => "-qty",
                                    "transaksi_id" => ".0",
                                    "nomer" => ".0",
                                    "state" => ".active",
                                    "oleh_id" => ".0",
                                    "oleh_nama" => "",
                                    "transaksi_no" => ".0",
                                );
                                foreach ($staticReplaceHold as $k_rpc => $v_rpc) {
                                    $tComSpecAddHold['static'][$k_rpc] = $v_rpc;
                                }
                                foreach ($staticReplaceActive as $k_rpc => $v_rpc) {
                                    $tComSpecAddActive['static'][$k_rpc] = $v_rpc;
                                }

                                $iteratorAdd[101] = $tComSpecAddHold; // postprocc hold by orang
                                $iteratorAdd[102] = $tComSpecAddActive; // postprocc active
                            }
                        }
                    }

                    if (sizeof($iteratorAdd) > 0) {
                        foreach ($iteratorAdd as $ii => $spec) {
                            $iterator[$ii] = $spec;
                        }
                    }
                    //                    arrPrintWebs($iterator);
                    //
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $gateItems = $$srcGateName;

                        echo "rollback sub-postProcessor: $comName, initializing values <br>";
                        if (!in_array($comName, $postDeniedConfigs)) {

                            $tmpOutParams[$cCtr] = array();
                            foreach ($gateItems as $cnt => $dSpec) {

                                $subParams = array();
                                if (isset($tComSpec['loop'])) {
                                    foreach ($tComSpec['loop'] as $key => $value) {

                                        $realValue = makeValue($value, $gateItems[$cnt], $gateItems[$cnt], 0);
                                        $subParams['loop'][$key] = $realValue;

                                    }
                                }
                                if (isset($tComSpec['static'])) {
                                    foreach ($tComSpec['static'] as $key => $value) {

                                        $realValue = makeValue($value, $gateItems[$cnt], $gateItems[$cnt], 0);
                                        $subParams['static'][$key] = $realValue;

                                    }

                                    if (array_key_exists($oriComName, $postConfigs)) {

                                        if (sizeof($postConfigs[$oriComName]) > 0) {
                                            foreach ($postConfigs[$oriComName] as $key) {

                                                $oldVal = isset($subParams['static'][$key]) ? $subParams['static'][$key] : 0;
                                                $newVal = $oldVal < 0 ? abs($oldVal) : -($oldVal);
                                                $subParams['static'][$key] = $newVal;

                                            }
                                        }
                                    }
                                    else {
                                        //                                cekhitam("TIDAK terdapat di dalam prepConfig");
                                    }


                                    if (!isset($subParams['static']["transaksi_id"])) {
                                        $subParams['static']["transaksi_id"] = $no;
                                    }
                                    if (!isset($subParams['static']["transaksi_no"])) {
                                        $subParams['static']["transaksi_no"] = $no;
                                    }
                                    $subParams['static']["fulldate"] = date("Y-m-d");
                                    $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                    $subParams['static']["keterangan"] = "rollback of $no";
                                }


                                if (sizeof($subParams) > 0) {
                                    $tmpOutParams[$cCtr][] = $subParams;
                                }
                            }
                        }
                        else {
                            cekHitam("$comName denied");
                        }
                    }

                    foreach ($iterator as $cCtr => $tComSpec) {
                        $oriComName = $tComSpec['comName'];
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "sub-postProcessor: $comName, sending values <br>";
                        if (!in_array($comName, $postDeniedConfigs)) {

                            $mdlName = "Com" . ucfirst($comName);
                            $this->CI->load->model("Coms/" . $mdlName);
                            $m = new $mdlName();


                            cekBiru("kiriman rollback detail-postproc $comName");
                            arrPrint($tmpOutParams[$cCtr]);
                            $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }
                        else {
                            cekHitam("$comName denied");
                        }
                    }
                }
            }
            else {
                cekbiru("TIDAK ada config post-proc detail $jenisTr :: $stepNumCurrent");
            }

            //            mati_disini();
            //==================================================================================================
            $this->CI->load->model("Mdls/MdlTransaksiLaporan");
            $lt = New MdlTransaksiLaporan();
            $dataTransaksiLaporan = array(
                "transaksi_id" => $no,
                "master_id" => $masterID,
                "nomer" => $arrMainDataTransIDSpec['nomer'],
                "metode" => "reject",
            );
            $lt->addData($dataTransaksiLaporan);
            showLast_query("ungu");
        }


        //==================================================================================================
        //==MENGUPDATE LOCKER TRANSAKSI ====================================================================
        $this->CI->load->model("Mdls/MdlLockerTransaksi");
        $lt = New MdlLockerTransaksi();
        $lt->execLocker($this->cCodeData[$cCode]["main"], $nextProp["num"], $transaksiID_reference, NULL);
        //==================================================================================================

        $libResult = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $insertID,
        );
        return $libResult;
    }

    public function doEdit()
    {
        $location = "(library " . get_class($this) . ", method " . __FUNCTION__ . ")";
        $this->setterValidate($location);

        //region marking
        $cCode = $this->cCode;
        $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
        $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][1]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][1]["runCoreAkunting"] : false;
        $core = isset($this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode]) ? $this->CI->config->item('heTransaksi_core')[$this->modul][$transaksiMode] : array();
        $corePreProcParam = isset($this->CI->config->item('heTransaksi_core')[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor']) ? $this->CI->config->item('heTransaksi_core')[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor'] : false;
        $coreRequiredParam = isset($this->CI->config->item('heTransaksi_core')[$this->modul]['requiredParam']) ? $this->CI->config->item('heTransaksi_core')[$this->modul]['requiredParam'] : array();
        $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][1]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][1]["target"] : NULL;
        $relOptionConfigs = isset($this->configUiModul[$this->jenisTr]['relativeOptions']) ? $this->configUiModul[$this->jenisTr]['relativeOptions'] : array();
        $inputLabels = array();
        $inputAuthConfigs = array();

        $this->CI->load->library("FieldCalculator");
        $cal = new FieldCalculator();

        if (isset($this->cCodeData[$cCode])) {

            $this->CI->load->model("MdlTransaksi");

            if (!isset($this->cCodeData[$cCode]["items"])) {
                die("belum ada item yang dipilih");
            }
            else {
                if (sizeof($this->cCodeData[$cCode]["items"]) < 1) {
                    die("belum ada item yang dipilih");
                }
            }
            echo("now processing your transaction..<br>");

            $tmpNomer = $this->cCodeData[$cCode]["main"]["nomer"];

            //region set trash registry, transaksi, transaksi data, payment source, extend step, lockerstok
            if (isset($this->cCodeData[$cCode]['mode']['edit']) && sizeof($this->cCodeData[$cCode]['mode']['edit']) > 0) {
                $transaksiID_reference = $masterID = $this->cCodeData[$cCode]['mode']['edit'];
                $trTrash = new MdlTransaksi();
                $where = "transaksi_id='$masterID'";

                // mulai update transaksi_registry lama ke trash 1
//                $dataTrash = array("trash" => "1");
//                $trTrash->setFilters(array());
//                $trTrash->setTableName("transaksi_registry");
//                $updateReistry = $trTrash->updateData($where, $dataTrash) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  updte  params registries"));
//                cekHijau($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                $trTrash->setFilters(array());
                $trTrash->addFilter("transaksi_id='$masterID'");
                $trTrashTmp = $trTrash->lookupDataRegistries()->result();
//                arrPrint($trTrashTmp);
                if (sizeof($trTrashTmp) > 0) {
                    foreach ($trTrashTmp as $dataReg) {
                        $arrDataReg = (array)$dataReg;
                        $arrDataReg['trash'] = 1;
                        $updateReistry = $trTrash->writeDataRegistriesHistory($arrDataReg);
                        cekBiru($this->CI->db->last_query());
                    }
                }


                if ($updateReistry) {
                    $trTrash->setFilters(array());
                    $trTrash->setTableName("transaksi_data");
                    $dataItems = array(
                        "valid_qty" => "0",
                        "trash" => "1",
                        "sub_step_number" => "",
                        "sub_step_current" => "",
                        "sub_step_avail" => "",
                        "next_substep_num" => "",
                    );
                    $updateItems = $trTrash->updateData($where, $dataItems) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  updte  params registries"));
                    cekHitam($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                }

//                mati_disini("TEST EDIT...");

                // region netralisasi payment source
                $tr = New MdlTransaksi();
                $tr->setFilters(array());
                $paymentSrc = $tr->lookupPaymentSrcByTransID($masterID)->result();
                cekBiru($this->CI->db->last_query());
                if (sizeof($paymentSrc) > 0) {
                    //                    arrPrint($paymentSrc);
                    foreach ($paymentSrc as $pSpec) {
                        if ($pSpec->terbayar == 0) {
                            $where = array(
                                "id" => $pSpec->id,
                                "transaksi_id" => $pSpec->transaksi_id,
                            );
                            $data = array(
                                "sisa" => 0,
                                "returned" => $pSpec->sisa,
                                "sisa_valas" => 0,
                                "returned_valas" => $pSpec->sisa_valas,
                            );

                            $tra = New MdlTransaksi();
                            $tra->setFilters(array());
                            $tra->updatePaymentSrc($where, $data);
                            cekUngu(":: mereject payment source bila ada...");
                            cekUngu($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                        }
                        else {
                            mati_disini("transaksi gagal karena " . $pSpec->_key . " telah diterima oleh finance.");
                        }
                    }
                }
                else {
                    cekBiru(":: tidak ada payment source... ::");
                }
                // endregion netralisasi payment source

                // region netralisasi extended step
                $tr = New MdlTransaksi();
                $tr->setFilters(array());
                $exTmp = $tr->lookupExtStepByTrID($masterID);
                cekUngu($this->CI->db->last_query());
                if (sizeof($exTmp) > 0) {
                    foreach ($exTmp as $exSpec) {
                        $tra = New MdlTransaksi();
                        $tra->setFilters(array());
                        $tra->rejectExtStepByID($exSpec["id"]);
                        cekUngu(":: mereject extended step bila ada...");
                        cekUngu($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    }
                }
                else {
                    cekBiru(":: tidak ada extended step... ::");
                }
                // endregion netralisasi extended step

                // region reverse locket stok FG or SUpplies
                $this->CI->load->model("Mdls/MdlLockerStock");
                $this->CI->load->model("Mdls/MdlLockerStockSupplies");

                $fg = New MdlLockerStock();
                $fg->addFilter("state='hold'");
                $fg->addFilter("transaksi_id='$masterID'");
                $fgTmp = $fg->lookupAll()->result();
                cekUngu($this->CI->db->last_query());
                if (sizeof($fgTmp) > 0) {
                    $fgLocker = array();
                    foreach ($fgTmp as $fgSpec) {
                        $fgLocker[] = array(
                            "loop" => array(),
                            "static" => array(
                                "cabang_id" => $fgSpec->cabang_id,
                                "jenis" => $fgSpec->jenis,
                                "state" => "hold",
                                "jumlah" => -$fgSpec->jumlah,
                                "produk_id" => $fgSpec->produk_id,
                                "nama" => $fgSpec->nama,
                                "satuan" => $fgSpec->satuan,
                                "oleh_id" => "0",
                                "oleh_nama" => "0",
                                "transaksi_id" => $fgSpec->transaksi_id,
                                "nomer" => $fgSpec->nomer,
                                "gudang_id" => $fgSpec->gudang_id,
                            ),
                        );
                        $this->CI->load->model("Coms/ComLockerStock");
                        $m = New ComLockerStock();
                        $m->pair($fgLocker) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        cekBiru($this->CI->db->last_query());
                    }
                }
                else {
                    cekHitam("FG locker $masterID, kosong...");
                }


                $sp = New MdlLockerStockSupplies();
                $sp->addFilter("state='hold'");
                $sp->addFilter("transaksi_id='$masterID'");
                $spTmp = $sp->lookupAll()->result();
                cekOrange($this->CI->db->last_query());
                if (sizeof($spTmp) > 0) {
                    $spLocker = array();
                    foreach ($spTmp as $spSpec) {
                        $spLocker[] = array(
                            "loop" => array(),
                            "static" => array(
                                "cabang_id" => $spSpec->cabang_id,
                                "jenis" => $spSpec->jenis,
                                "state" => "hold",
                                "jumlah" => -$spSpec->jumlah,
                                "produk_id" => $spSpec->produk_id,
                                "nama" => $spSpec->nama,
                                "satuan" => $spSpec->satuan,
                                "oleh_id" => "0",
                                "oleh_nama" => "0",
                                "transaksi_id" => $spSpec->transaksi_id,
                                "nomer" => $spSpec->nomer,
                                "gudang_id" => $spSpec->gudang_id,
                            ),
                        );
                        $this->CI->load->model("Coms/ComLockerStockSupplies");
                        $mp = New ComLockerStockSupplies();
                        $mp->pair($spLocker) or die("Tidak berhasil memasang  values pada post-processor:");
                        $mp->exec() or die("Gagal saat berusaha  exec values pada post-processor:");
                        cekBiru($this->CI->db->last_query());
                    }
                }
                else {
                    cekHitam("SP locker $masterID, kosong...");
                }
                // endregion reverse locket stok FG or SUpplies


            }

            //endregion


            $ppnFactor = isset($this->cCodeData[$cCode]["main"]["ppnFactor"]) ? $this->cCodeData[$cCode]["main"]["ppnFactor"] : matiHere("gagal menghitung ppn silahkan refresh atau relogin");

            //region pre-processors (item)
            if (isset($configCore[$this->jenisTr]['relativeComponets']) && $configCore[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['preProc']['detail']) ? $this->cCodeData[$cCode]['revert']['preProc']['detail'] : array();
            }
            else {
                $iterator = isset($core['preProcessor'][$jenisTrTarget]['detail']) ? $core['preProcessor'][$jenisTrTarget]['detail'] : array();
            }

            if (sizeof($iterator) > 0) {
//                $iterator = isset($this->configCore[$this->jenisTr]['preProcessor'][$jenisTrTarget]['detail']) ? $this->configCore[$this->jenisTr]['preProcessor'][$jenisTrTarget]['detail'] : array();
                $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
                echo "ITEM NUM LABELS";

                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];

                        echo "sub-preproc: $comName, initializing values <br>";

                        foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                            $tmpOutParams[$cCtr] = array();

                            //                            $id = $dSpec["id"];
                            $id = $xid;
                            $subParams = array();

                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['static'][$key] = $realValue;

                                }

                                if (!isset($subParams['static']["transaksi_id"])) {
                                    //									$subParams['static']["transaksi_id"] = $masterID;
                                }


                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name();
                            }
//                            cekLime(":: cetak preprocc... $comName :: $srcGateName ::");
//                            arrPrint($subParams);
                            //mati_disini();
                            if (sizeof($subParams) > 0) {
                                $tmpOutParams[$cCtr][] = $subParams;


                                $comName = $tComSpec['comName'];
                                $srcGateName = $tComSpec['srcGateName'];
                                $srcRawGateName = $tComSpec['srcRawGateName'];
                                $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                                //                                echo "sub preproc #$it: $comName, sending values <br>";

                                $mdlName = "Pre" . ucfirst($comName);
                                $this->CI->load->model("Preprocs/" . $mdlName);
                                $m = new $mdlName($resultParams);


                                if (sizeof($tmpOutParams[$cCtr]) > 0) {
                                    $tobeExecuted = true;
                                }
                                else {
                                    $tobeExecuted = false;
                                }

                                if ($tobeExecuted) {
                                    $m->pair(0, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                                    $gotParams = $m->exec();

                                    cekmerah("gotparams dari pre-proc $comName");
                                    arrprint($gotParams);


                                    if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor

                                        foreach ($gotParams as $gateName => $paramSpec) {
                                            cekBiru(":: getParams inject ke $gateName ::");
                                            if (!isset($this->cCodeData[$cCode][$gateName])) {
                                                $this->cCodeData[$cCode][$gateName] = array();
                                                //                                    cekhijau("building the session: $gateName");
                                            }
                                            else {
                                                //                                    cekhijau("NOT building the session: $gateName");
                                            }

                                            foreach ($paramSpec as $id => $gSpec) {
                                                //										$id=$gSpec["id"];


                                                if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                                    $this->cCodeData[$cCode][$gateName][$id] = array();
                                                }


                                                if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                                    if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                        foreach ($gSpec as $key => $val) {
                                                            cekHere(":: injecte ke $gateName, ::: $key diisi dengan $val");
                                                            $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                        }

                                                    }
                                                }
                                                //==inject gotParams to child gate
                                                cekHitam("srcGateName = $srcGateName :: " . __LINE__);
                                                if (isset($this->cCodeData[$cCode][$srcGateName][$id])) {
                                                    if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                        foreach ($gSpec as $key => $val) {
                                                            $this->cCodeData[$cCode][$srcGateName][$id][$key] = $val;
                                                        }

                                                    }
                                                }

                                                //cekMerah("REBUILDING VALUES..");
                                                if (sizeof($itemNumLabels) > 0) {
                                                    //cekHijau("REBUILDING SUBS FOR ITEMS");
                                                    foreach ($itemNumLabels as $key => $label) {
                                                        //cekHere("$id === $key => $label");
                                                        if (isset($this->cCodeData[$cCode][$gateName][$id][$key])) {
                                                            $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                        }
                                                        //                                        die();
                                                    }
                                                }
                                            }
                                            //                                    arrPrint($items);die();
                                        }


                                    }

                                }
                                else {
                                    cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                                }


                            }
                        }
                    }
                }
                else {
                    //cekKuning("sub-preproc is not set");
                }

                $this->CI->load->helper("he_value_builder");
//                fillValues_he_value_builder($this->jenisTr, 1, 1, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $ppnFactor);
                $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, 1, 1, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $ppnFactor, $this->cCodeData[$cCode]);
            }
            else {
                echo("no processor defined. skipping preprocessor..<br>");
            }
            //endregion

            //region pre-processors (master)
            if (isset($configCore[$this->jenisTr]['relativeComponets']) && $configCore[$this->jenisTr]['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['preProc']['master']) ? $this->cCodeData[$cCode]['revert']['preProc']['master'] : array();
            }
            else {
                $iterator = isset($core['preProcessor'][$jenisTrTarget]['master']) ? $core['preProcessor'][$jenisTrTarget]['master'] : array();
            }
            if (sizeof($iterator) > 0) {
//                $iterator = isset($this->configCore[$this->jenisTr]['preProcessor'][$jenisTrTarget]['detail']) ? $this->configCore[$this->jenisTr]['preProcessor'][$jenisTrTarget]['master'] : array();
                $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                        $subParams = array();

                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode]["main"], $this->cCodeData[$cCode]["main"], 0);
                                $subParams['static'][$key] = $realValue;

                            }

                            if (!isset($subParams['static']["transaksi_id"])) {
                                //									$subParams['static']["transaksi_id"] = $masterID;
                            }

                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name();
                        }
                        $tmpOutParams[$cCtr] = $subParams;

                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);


                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            $m->pair(0, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();

                            cekbiru("gotparams dari pre-proc $comName");
                            arrprint($gotParams);

                            if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                                foreach ($gotParams as $gateName => $gSpec) {
                                    //										$id=$gSpec["id"];
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                    //==inject gotParams to child gate
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                    //cekMerah("REBUILDING VALUES..");
                                    if (sizeof($itemNumLabels) > 0) {
                                        //cekHijau("REBUILDING SUBS FOR ITEMS");
                                        foreach ($itemNumLabels as $key => $label) {
                                            //cekHere("$id === $key => $label");
                                            if (isset($this->cCodeData[$cCode]["main"][$key])) {
                                                $this->cCodeData[$cCode]["main"]['sub_' . $key] = ($this->cCodeData[$cCode]["main"]['jml'] * $this->cCodeData[$cCode]["main"][$key]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }
                    }
                }
                else {
                    //cekKuning("sub-preproc is not set");
                }

                $this->CI->load->helper("he_value_builder");
//                fillValues_he_value_builder($this->jenisTr, 1, 1, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $ppnFactor);
                $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, 1, 1, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $ppnFactor, $this->cCodeData[$cCode]);
            }
            else {
                echo("no processor defined. skipping preprocessor..<br>");
            }
            //endregion


            $this->CI->load->library("Validator");
            $vd = new Validator();
            $vd->setCCode($this->cCode);
            $vd->setConfigUiJenis($this->configUiModul[$this->jenisTr]);
            $vd->setSessionData($this->cCodeData[$cCode]);
            $step = $this->cCodeData[$cCode]["main"]['step_number'];
            $vd->midValidate($step);
            $vd->unionValidate();

            //===finalisasi sebelum masuk tabel beneran
            //===isinya ada pembentukan nomor nota dll


            //
            //region penomoran receipt
            //            //<editor-fold desc="==========penomoran">
            //            $this->CI->load->model("CustomCounter");
            //            $cn = new CustomCounter("transaksi");
            //            $cn->setType("transaksi");
            //
            //            $counterForNumber = array($this->configValuesModul[$this->jenisTr]["formatNota"]);
            //            if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]["counters"])) {
            //                die("Used number should be registered in counters config as well");
            //            }
            //            echo "<div style='background:#ff7766;'>";
            //            foreach ($counterForNumber as $i => $cRawParams) {
            //                $cParams = explode("|", $cRawParams);
            //                $cValues = array();
            //                foreach ($cParams as $param) {
            //                    //                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
            //                    //                    echo "filling $param with " . $this->cCodeData[$cCode]["main"][$param] . "<br>";
            //                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
            //                    //                    echo "filling $param with " . $this->cCodeData[$cCode]["main"][$param] . "<br>";
            //                }
            //                $cRawValues = implode("|", $cValues[$i]);
            //                $paramSpec = $cn->getNewCount($cParams, $cValues[$i]);
            //
            //            }
            //            echo "</div style='background:#ff7766;'>";
            //
            //            $stepNumber = 1;
            //
            //            $tmpNomorNota = $paramSpec["paramString"];
            //
            //            //            $this->cCodeData[$cCode]["tableIn_master"]['nomer'] = $tmpNomorNota;
            //
            //
            if (isset($this->configUiModul[$this->jenisTr]["steps"][2])) {
                $nextProp = array(
                    "num" => 2,
                    "code" => $this->configUiModul[$this->jenisTr]["steps"][2]["target"],
                    "label" => $this->configUiModul[$this->jenisTr]["steps"][2]["label"],
                    "groupID" => $this->configUiModul[$this->jenisTr]["steps"][2]['userGroup'],
                );
            }
            else {
                $nextProp = array(
                    "num" => 0,
                    "code" => "",
                    "label" => "",
                    "groupID" => "",
                );
            }

            //endregion off

            //region dynamic counters

            //region addition on master
            $addValues = array(

                "status_edit" => 1,
                "edit_id" => my_id(),
                "edit_name" => my_name(),
                "edit_dtime" => date("Y-m-d H:i:s"),
                //                "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


            );
            foreach ($addValues as $key => $val) {
                $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
            }
            //endregion

            //
            //region addition on detail
            $addSubValues = array(
                "sub_step_number" => 1,
                "sub_step_current" => 1,
                "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                "next_substep_num" => $nextProp["num"],
                "next_substep_code" => $nextProp["code"],
                "next_substep_label" => $nextProp["label"],
                "next_subgroup_code" => $nextProp["groupID"],
                "sub_tail_number" => 1,
                "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


            );
            foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                foreach ($addSubValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                }
            }
            //endregion
            // </editor-fold>
            //endregion


            //
            //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
            if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $tr->setTableName("transaksi");
                $updateMain = $tr->updateData("id='$masterID'", $addValues);
                cekHijau($this->CI->db->last_query());

                $injectors = array(
                    "transaksi_id" => $masterID,
                    //                    "nomer" => $tmpNomorNota,
                );
                $arrInjectorsTarget = array(
                    "items",
                    "items2_sum",
                    "rsltItems",
                );
                foreach ($injectors as $key => $val) {
                    $this->cCodeData[$cCode]["main"][$key] = $val;
                    foreach ($arrInjectorsTarget as $target) {
                        if (isset($this->cCodeData[$cCode][$target])) {
                            foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                if (isset($this->cCodeData[$cCode][$target][$id])) {
                                    $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                }
                            }
                        }
                    }
                }


                $addValues = array(

                    //===references
                    "id_master" => $masterID,
                    "id_top" => $masterID,
                    "ids_prev" => "",
                    "ids_prev_intext" => "",
                    "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                    "nomers_prev" => "",
                    "nomers_prev_intext" => "",
                    //                    "jenis_top"           => $this->jenisTr,
                    "jenises_prev" => "",
                    "jenises_prev_intext" => "",
                    //

                );
                foreach ($addValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

            }
            if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {

                if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'])) {
                    foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                        if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                            $tr->setTableName("transaksi_values");
                            $tr->updateData("transaksi_id='$masterID'", array(
                                "key" => $key,
                                "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                            ));
                            cekHitam($this->CI->db->last_query());
                        }
                    }
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                    $tr->setTableName("transaksi_values");
                    $tr->updateData("transaksi_id='$masterID'", array("key" => $key, "value" => $val));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                    $tr->setTableName("transaksi_values");
                    $tr->updateData("transaksi_id='$masterID'", array("key" => $key, "value" => $val));
                    //                    cekkuning("making a clone for input key $key / $val");
                    //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                    //                    $replacers=array(
                    //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                    //                    );
                    //                    foreach($replacers as $key=>$val){
                    //                        $tmpTableIn[$key]=$val;
                    //                    }
                    //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                $tr->setTableName("transaksi_fields");
                foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                    $tr->writeMainFields("transaksi_id='$masterID'", array("key" => $key, "value" => $val));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                $tr->setTableName("transaksi_applets");
                foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {

                    $tr->updateData("transaksi_id='$masterID'", array(
                        "mdl_name" => $amdl,
                        "key" => $aSpec['key'],
                        "label" => $aSpec['labelValue'],
                        "description" => $aSpec['description'],
                    ));
                }
            }
            if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                $tr->setTableName("transaksi_element");
                foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {

                    $tr->updateData("transaksi_id='$masterID'", array(
                        "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                        "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                        "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                        "name" => $aSpec['name'],
                        "label" => $aSpec["label"],
                        "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                        "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                    ));


                    //==nebeng bikin inputLabels
                    $currentValue = "";
                    switch ($aSpec['elementType']) {
                        case "dataModel":
                            $currentValue = $aSpec['key'];
                            break;
                        case "dataField":
                            $currentValue = $aSpec["value"];
                            break;
                    }
                    if (array_key_exists($elName, $relOptionConfigs)) {
                        //					cekhijau("$eName terdaftar pada relInputs");


                        if (isset($relOptionConfigs[$elName][$currentValue])) {
                            if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
                                foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
                                    $inputLabels[$oValueName] = $oValSpec["label"];
                                    if (isset($oValSpec['auth'])) {
                                        if (isset($oValSpec['auth']["groupID"])) {
                                            $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
                        }

                    }

                }
            }
            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                $insertIDs = array();
                $insertDeIDs = array();
                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                    $insertDetailID = $tr->writeDetailEntries($masterID, $dSpec);
                    cekUngu($this->CI->db->last_query() . " [" . $this->CI->db->affected_rows() . "]");
                    $insertIDs[] = $insertDetailID;
                    $insertDeIDs[$masterID][] = $insertDetailID;
                }
                if (sizeof($insertIDs) == 0) {
                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                }
                else {
                    $indexing_details = array();
                    foreach ($insertDeIDs as $key => $numb) {
                        $indexing_details[$key] = $numb;
                    }

                    foreach ($indexing_details as $k => $arrID) {
                        $arrBlob = blobEncode($arrID);
                        $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                        cekOrange($this->CI->db->last_query());
                    }
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {

                    $insertIDs[] = $tr->writeDetailEntries($masterID, $dSpec);

                    cekUngu($this->CI->db->last_query());
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                $insertIDs = array();
                $tr->setTableName("transaksi_data");
                foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                    $$tr->updateData("transaksi_id='$masterID'", $dSpec);

                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                //                $insertIDs = array();
                $tr->setTableName("transaksi_data");
                foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                    $insertIDs[] = $tr->updateData("transaksi_id='$masterID'", $dSpec);
                    //                    if ($epID != 999) {
                    //                        $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                    //                    }
                    cekUngu($this->CI->db->last_query());
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                $tr->setTableName("transaksi_data_values");
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                            if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                $tr->updateData("transaksi_id='$masterID'", array(
                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => $dSpec[$src],
                                ));

                            }
                        }
                    }


                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                            $insertIDs[] = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                        }
                    }


                }
            }
            //endregion


            //===components akan langsung dieksekusi jika steps-nya tidak pakai approval
            $steps = $this->configUiModul[$this->jenisTr]["steps"];

            if ($runCoreAkunting == true) {
                //region processing sub-components, if in single step
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                $filterNeeded = false;

                //region processing sub-components
                if (isset($core['relativeComponets']) && $core['relativeComponets'] == true) {
                    $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal']['detail']) ? $this->cCodeData[$cCode]['revert']['jurnal']['detail'] : array();
                    $revertedTarget = $this->cCodeData[$cCode]["main"]['pihakExternID'];
                }
                else {
                    $iterator = isset($core['components']['detail']) ? $core['components']['detail'] : array();
                    $revertedTarget = "";
                }
//                $iterator = isset($this->configCore[$this->jenisTr]['components'][$jenisTrTarget]['detail']) ? $this->configCore[$this->jenisTr]['components'][$jenisTrTarget]['detail'] : array();
                if (sizeof($iterator) > 0) {
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $tmpOutParams[$cCtr] = array();

                        $srcGateName = $tComSpec['srcGateName'];
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $comName = $tComSpec['comName'];
                            if (substr($comName, 0, 1) == "{") {
                                $comName = trim($comName, "{");
                                $comName = trim($comName, "}");
                                //                            $comName = str_replace($comName, $this->cCodeData[$cCode]["main"][$comName], $comName);
                                $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                            }
                            cekHitam(":: $comName ::");
                            $mdlName = "Com" . ucfirst($comName);
                            if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                                $filterNeeded = true;
                            }
                            else {
                                $filterNeeded = false;
                            }
                            echo "sub-component: $comName, initializing values <br>";
                            //                        cekHitam(__LINE__);
                            //                        $tmpOutParams[$cCtr] = array();

                            //                        cekhitam("$comName filterneeded: $filterNeeded");
                            //                        cekhitam("mau mengiterasi $srcGateName");
                            //                        cekhitam("telah mengiterasi $srcGateName");
                            //
                            $subParams = array();
                            if (isset($tComSpec['loop'])) {
                                foreach ($tComSpec['loop'] as $key => $value) {
                                    cekMerah(":: $key => $value ::");
                                    if (substr($key, 0, 1) == "{") {
                                        $key = trim($key, "{");
                                        $key = trim($key, "}");
                                        //                                    $key = str_replace($key, $this->cCodeData[$cCode]["main"][$key], $key);
                                        $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$id][$key], $key);
                                    }

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['loop'][$key] = $realValue;

                                    if ($filterNeeded) {
                                        if ($subParams['loop'][$key] == 0) {
                                            unset($subParams['loop'][$key]);
                                        }
                                    }
                                }
                            }
                            if (isset($tComSpec['static'])) {
                                foreach ($tComSpec['static'] as $key => $value) {

                                    $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                    $subParams['static'][$key] = $realValue;

                                }
                                if (!isset($subParams['static']["transaksi_id"])) {
                                    $subParams['static']["transaksi_id"] = $insertID;
                                }
                                if (!isset($subParams['static']["transaksi_no"])) {
                                    $subParams['static']["transaksi_no"] = $insertNum;
                                }

                                $subParams['static']["fulldate"] = date("Y-m-d");
                                $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                                $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                            }
                            //arrPrint($subParams);
                            if (sizeof($subParams) > 0) {
                                arrprint($subParams);
                                cekhitam("subparam ada isinya");
                                if ($filterNeeded) {
                                    if (isset($subParams['loop']) && sizeof($subParams['loop']) > 0) {
                                        $tmpOutParams[$cCtr][] = $subParams;
                                    }
                                }
                                else {
                                    $tmpOutParams[$cCtr][] = $subParams;
                                }
                            }
                            else {
                                cekhitam("subparam TIDAK ada isinya");
                            }
                        }
                    }
                    //cekHitam("cetak tmpOutParams");
                    //arrPrint($tmpOutParams);
                    //cekHitam();
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $srcGateName = $tComSpec['srcGateName'];
                        foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {

                            $srcRawGateName = $tComSpec['srcRawGateName'];
                            $comName = $tComSpec['comName'];
                            if (substr($comName, 0, 1) == "{") {
                                $comName = trim($comName, "{");
                                $comName = trim($comName, "}");
                                $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                                //                        $comName = str_replace($comName, $this->cCodeData[$cCode]["main"][$comName], $comName);
                            }
                        }
                        echo "sub component: $comName, sending values <br>";

                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();
                        //===filter value nol, jika harus difilter
                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            cekMerah("$comName dieksekusiii");
                            arrPrint($tmpOutParams[$cCtr]);
                            $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }
                        else {
                            cekMerah("$comName tidak eksekusi");
                        }

                    }
                }
                else {
                    //cekKuning("subcomponents is not set");
                }
                //endregion

                //endregion

                //region processing main components, if in single step
                //==filter nilai, jika NOL tidak dikirim, sesuai config==
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
//                $iterator = isset($this->configCore[$this->jenisTr]['components'][$jenisTrTarget]['master']) ? $this->configCore[$this->jenisTr]['components'][$jenisTrTarget]['master'] : array();
                if (isset($core['relativeComponets']) && $core['relativeComponets'] == true) {
                    $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal']['master']) ? $this->cCodeData[$cCode]['revert']['jurnal']['master'] : array();
                }
                else {
                    $iterator = isset($core['components']['master']) ? $core['components']['master'] : array();
                }

                if (sizeof($iterator) > 0) {

                    $cCtr = 0;
                    foreach ($iterator as $cCtr => $tComSpec) {
                        $cCtr++;
                        $comName = $tComSpec['comName'];
                        if (substr($comName, 0, 1) == "{") {
                            $comName = trim($comName, "{");
                            $comName = trim($comName, "}");
                            $comName = str_replace($comName, $this->cCodeData[$cCode]["main"][$comName], $comName);
                        }
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        echo "component # $cCtr: $comName<br>";

                        $dSpec = $this->cCodeData[$cCode][$srcGateName];
                        $tmpOutParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {

                                if (substr($key, 0, 1) == "{") {
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $this->cCodeData[$cCode]["main"][$key], $key);
                                }

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['loop'][$key] = $realValue;
                                //                            cekKuning("LOOP $key diisi dengan $realValue");
                            }
                        }
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                                $tmpOutParams['static'][$key] = $realValue;

                            }
                            if (!isset($tmpOutParams['static']["transaksi_id"])) {
                                $tmpOutParams['static']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static']["transaksi_no"])) {
                                $tmpOutParams['static']["transaksi_no"] = $insertNum;
                            }

                            $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                        }

                        if (isset($tComSpec['static2'])) {
                            //cekHere("DISINI OIII");
                            foreach ($tComSpec['static2'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                                $tmpOutParams['static2'][$key] = $realValue;

                            }
                            if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                                $tmpOutParams['static2']["transaksi_id"] = $insertID;
                            }
                            if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                                $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                            }

                            $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                            $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                            $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                        }

                        //lgShowError("Ada kesalahan",);
                        $mdlName = "Com" . ucfirst($comName);
                        $this->CI->load->model("Coms/" . $mdlName);
                        $m = new $mdlName();

                        //===filter value nol, jika harus difilter
                        $tobeExecuted = true;

                        if (in_array($mdlName, $compValidators)) {

                            $loopParams = isset($tmpOutParams['loop']) ? $tmpOutParams['loop'] : array();
                            if (sizeof($loopParams) > 0) {
                                foreach ($loopParams as $key => $val) {
                                    cekmerah("$comName : $key = $val ");
                                    if ($val == 0) {
                                        unset($tmpOutParams['loop'][$key]);
                                    }
                                }
                            }
                            if (sizeof($tmpOutParams['loop']) < 1) {
                                $tobeExecuted = false;
                            }

                        }

                        if ($tobeExecuted) {

                            //cekBiru("kiriman komponem $comName");
                            //                        arrPrint($tmpOutParams);
                            $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        }


                    }
                }
                else {
                    //cekKuning("components is not set");
                }


                //endregion

            }

            //region processing sub-post-processors, always
            $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail'] : array();
            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo "sub-postProcessor: $comName, initializing values <br>";
                    $tmpOutParams[$cCtr] = array();
                    foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                        $id = $dSpec["id"];
                        $subParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['loop'][$key] = $realValue;

                            }
                        }
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['static'][$key] = $realValue;

                            }
                            if (!isset($subParams['static']["transaksi_id"])) {
                                $subParams['static']["transaksi_id"] = $masterID;
                            }
                            if (!isset($subParams['static']["transaksi_no"])) {
                                $subParams['static']["transaksi_no"] = $this->cCodeData[$cCode]["main"]['nomer'];
                            }
                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $this->cCodeData[$cCode]["main"]['nomer'] . " oleh " . my_name();
                        }

                        if (sizeof($subParams) > 0) {
                            $tmpOutParams[$cCtr][] = $subParams;
                        }
                    }
                }

                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo "sub-postProcessor: $comName, sending values <br>";

                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();


                    //                                        arrprint($tmpOutParams[$cCtr]);
                    //                                        matiHere();

                    $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
            }
            //endregion

            //region processing main-post-processors, always
            $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master'] : array();
            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo "post-processor: $comName<br>";

                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                    $tmpOutParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {

                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['loop'][$key] = $realValue;

                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {

                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static'][$key] = $realValue;

                        }
                        if (!isset($tmpOutParams['static']["transaksi_id"])) {
                            $tmpOutParams['static']["transaksi_id"] = $insertID;
                        }
                        if (!isset($tmpOutParams['static']["transaksi_no"])) {
                            $tmpOutParams['static']["transaksi_no"] = $insertNum;
                        }

                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                    }
                    if (isset($tComSpec['static2'])) {
                        //cekHere("DISINI OIII");
                        foreach ($tComSpec['static2'] as $key => $value) {

                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                            $tmpOutParams['static2'][$key] = $realValue;

                        }
                        if (!isset($tmpOutParams['static2']["transaksi_id"])) {
                            $tmpOutParams['static2']["transaksi_id"] = $insertID;
                        }
                        if (!isset($tmpOutParams['static2']["transaksi_no"])) {
                            $tmpOutParams['static2']["transaksi_no"] = $insertNum;
                        }

                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                    }

                    //lgShowError("Ada kesalahan",);
                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();

                    //cekBiru("kiriman komponem $comName");
                    //                    arrPrint($tmpOutParams);
                    $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);


                }
            }
            else {

            }
            //endregion


            //region nulis paymentSource
            $stepCode = $this->configUiModul[$this->jenisTr]["steps"][1]["target"];
            $paymentSources = $this->CI->config->item("payment_source");
            $insertID = $masterID;
            if (array_key_exists($stepCode, $paymentSources)) {

                $payConfigs = $paymentSources[$stepCode];
                if (sizeof($payConfigs) > 0) {
                    foreach ($payConfigs as $paymentSrcConfig) {
                        $valueSrc = $paymentSrcConfig['valueSrc'];
                        $externSrc = $paymentSrcConfig['externSrc'];
                        arrPrint($externSrc);
                        $tr->writePaymentSrc($insertID, array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                            "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => isset($this->cCodeData[$cCode]["main"][$valueSrc]) ? $this->cCodeData[$cCode]["main"][$valueSrc] : 0,
                            "terbayar" => 0,
                            "sisa" => isset($this->cCodeData[$cCode]["main"][$valueSrc]) ? $this->cCodeData[$cCode]["main"][$valueSrc] : 0,
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id" => (isset($externSrc['valasId']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama" => (isset($externSrc['valasLabel']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai" => (isset($externSrc['valasValue']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : 0,
                            "tagihan_valas" => (isset($externSrc['valasTagihan']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : 0,
                            "terbayar_valas" => (isset($externSrc['valasTerbayar']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']] : 0,
                            "sisa_valas" => (isset($externSrc['valasSisa']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']])) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : 0,

                        ));
                        cekMerah($this->CI->db->last_query());
                    }
                }


            }
            else {
                //cekMerah("TIDAK nulis paymentSrc");
            }
            //endregion

            //region nulis paymentAntiSource
            $stepCode = $this->configUiModul[$this->jenisTr]["steps"][1]["target"];
            $paymentSources = $this->CI->config->item("payment_antiSource") != null ? $this->CI->config->item("payment_antiSource") : array();
            $insertID = $masterID;
            if (array_key_exists($stepCode, $paymentSources)) {
                cekHitam(":: starting PAYMENT ANTI SOURCE");
                $payConfigs = $paymentSources[$stepCode];
                if (sizeof($payConfigs) > 0) {
                    foreach ($payConfigs as $paymentSrcConfig) {
                        $valueSrc = $paymentSrcConfig['valueSrc'];
                        $externSrc = $paymentSrcConfig['externSrc'];
                        $tr->writePaymentAntiSrc($insertID, array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                            "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "terbayar" => 0,
                            "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                            "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                            "terbayar_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTerbayar']] : '',
                            "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',

                        ));
                        //cekMerah($this->CI->db->last_query());
                    }
                }


            }
            else {
                //cekMerah("TIDAK nulis paymentSrc");
            }
            //endregion

            //====registri value-gate
            if (isset($core['components']) && sizeof($core['components'])) {
                $jurnalIndex = $core['components'];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["jurnal"]) && sizeof($this->cCodeData[$cCode]["revert"]["jurnal"]) > 0) {
                    $jurnalIndex = $this->cCodeData[$cCode]["revert"]["jurnal"];
                }
                else {
                    $jurnalIndex = array();
                }
            }
            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget])) {
                $jurnalPostProc = $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["postProc"]) && sizeof($this->cCodeData[$cCode]["revert"]["postProc"]) > 0) {
                    $jurnalPostProc = $this->cCodeData[$cCode]["revert"]["postProc"];
                }
                else {
                    $jurnalPostProc = array();
                }
            }
            //------------
            if (isset($core['preProcessor'][$jenisTrTarget]) && sizeof($core['preProcessor'][$jenisTrTarget])) {
                $jurnalPreProc = $core['preProcessor'][$jenisTrTarget];
            }
            else {
                if (isset($this->cCodeData[$cCode]["revert"]["preProc"]) && sizeof($this->cCodeData[$cCode]["revert"]["preProc"]) > 0) {
                    $jurnalPreProc = $this->cCodeData[$cCode]["revert"]["preProc"];
                }
                else {
                    $jurnalPreProc = array();
                }
            }
            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget])) {
                $coreBuilder = $this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget];
            }
            else {
                $coreBuilder = array();
            }
            //------------

            //====registri value-gate
            $baseRegistries = array(
                "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                "jurnal_index" => $jurnalIndex,
                "postProcessor" => $jurnalPostProc,
                'componentsBuilder' => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                'jurnalItems' => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                'items_komposisi' => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                'revert' => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                "preProcessor" => $jurnalPreProc,
                "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                'items_noapprove' => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                'receiptDetailSrcFields' => isset($this->cCodeData[$cCode]['receiptDetailSrcFields']) ? $this->cCodeData[$cCode]['receiptDetailSrcFields'] : array(),
                //----
                "itemPrice" => isset($this->cCodeData[$cCode]['itemPrice']) ? $this->cCodeData[$cCode]['itemPrice'] : array(),
                "itemPrice_sum" => isset($this->cCodeData[$cCode]['ifillValuestemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                "requiredParam" => (isset($coreRequiredParam[$this->jenisTr]) && sizeof($coreRequiredParam[$this->jenisTr]) > 0) ? $coreRequiredParam[$this->jenisTr] : array(),
                'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                "coreBuilder" => $coreBuilder,
                'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                //----
            );
            // mengupdate ke tabel registry (transaksi_data_registry)
            $where_registry = array(
                "transaksi_id" => $masterID
            );
            $doWriteReg = $tr->updateDataRegistry($where_registry, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  update base params into registries"));
            cekOrange($this->CI->db->last_query());


            //========extended steps (if any)
            //region extended steps
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $iKey => $iVal) {
                    if ($iVal > 0) {

                        cekbiru("evaluating $iKey ($iVal) for paymentSrc..");
                        $stepCode = $this->jenisTr . "_";
                        $paymentSources = $this->CI->config->item("payment_source");


                        if (array_key_exists($stepCode, $paymentSources)) {
                            $payConfigs = $paymentSources[$stepCode];
                            cekbiru("$stepCode registered");


                            //===kalau melibatkan payment-source
                            if (sizeof($payConfigs) > 0) {
                                foreach ($payConfigs as $paymentSrcConfig) {
                                    if ($paymentSrcConfig['valueSrc'] == $iKey) {
                                        cekhijau($paymentSrcConfig['valueSrc'] . "/$iKey akan dieksekusi");
                                        $valueSrc = $paymentSrcConfig['valueSrc'];
                                        $externSrc = $paymentSrcConfig['externSrc'];
                                        if ($tr->paymentSrcExistsInMaster($insertID, $stepCode, $paymentSrcConfig["label"])) {
                                            cekhijau($paymentSrcConfig["label"] . " pada $stepCode $insertID sudah ada, tidak perlu ditulis");
                                        }
                                        else {
                                            cekhijau($paymentSrcConfig["label"] . " pada $stepCode $insertID BELUM ada, ditulis sekarang");
                                            $tr->writePaymentSrc($insertID, array(
                                                "_key" => $iKey,
                                                "jenis" => $stepCode,
                                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                                "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                                                "label" => $paymentSrcConfig["label"],
                                                "tagihan" => $this->cCodeData[$cCode]['main_inputs'][$valueSrc],
                                                "terbayar" => 0,
                                                "sisa" => $this->cCodeData[$cCode]['main_inputs'][$valueSrc],
                                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                                "oleh_id" => my_id(),
                                                "oleh_nama" => my_name(),
                                                "dtime" => date("Y-m-d H:i:s"),
                                                "fulldate" => date("Y-m-d"),
                                                "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                                                "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                                                "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                                                "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                                                "terbayar_valas" => 0,
                                                "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                                            ));
                                        }
                                        //									cekMerah("paySrc: ".$this->CI->db->last_query());

                                    }
                                    else {
                                        cekmerah($paymentSrcConfig['valueSrc'] . "/$iKey tidak untuk dieksekusi");
                                    }
                                }
                            }

                        }
                        else {
                            cekbiru("$stepCode NOT registered");
                        }


                        //==periksa apakah mainInput memerlukan auth
                        if (array_key_exists($iKey, $inputAuthConfigs)) {
                            $gID = $inputAuthConfigs[$iKey];
                            if (strlen($gID) > 0) {
                                cekhijau("input $iKey bernilai $iVal memerlukan auth dari $gID");
                                $trA = new MdlTransaksi();
                                $exTmp = $trA->extStepExistsInMaster($insertID, $iKey);
                                cekhijau($this->CI->db->last_query());
                                if ($exTmp) {
                                    cekhijau("extStep SUDAH terdaftar, sekarang nggak akan ditulis");
                                }
                                else {
                                    cekhijau("extStep belum terdaftar, sekarang hendak ditulis");
                                    $trA->writeExtStep($insertID, array(
                                        "master_id" => $insertID,
                                        "transaksi_id" => $insertID,
                                        "_key" => $iKey,
                                        "_label" => $inputLabels[$iKey],
                                        "_value" => $iVal,
                                        "group_id" => $gID,
                                        "state" => "0",
                                        "proposed_by" => my_id(),
                                        "proposed_dtime" => date("Y-m-d H:i:s"),
                                        "done_by",
                                        "done_dtime",
                                    ));
                                    cekhijau($this->CI->db->last_query());
                                }
                            }

                        }
                    }

                }
            }
            //endregion
            //======================================

            $pakai_ini = 0;
            if ($pakai_ini == 1) {
                //region signature
                $tr = new MdlTransaksi();
                $dataSign = array(
                    "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                    "step_number" => 1,
                    "step_code" => $this->jenisTr,
                    "step_name" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"],
                    "group_code" => $this->configUiModul[$this->jenisTr]["steps"][1]['userGroup'],
                    "oleh_id" => my_id(),
                    "oleh_nama" => my_name(),
                    "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                    "transaksi_id" => $insertID,
                    "deskripsi" => "edit transaksi",
                    "cabang_id" => my_cabang_id(),
                    "cabang_nama" => my_cabang_name(),
                    "current_transaksi_id" => $masterID,
                    "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                );
                $dwsign = $tr->writeSignature($insertID, $dataSign) or die("Failed to write signature");
                //endregion
            }


            //==================================================================================================
            //==MENULIS LOCKER TRANSAKSI ACTIVE=================================================================
            $this->CI->load->model("Mdls/MdlLockerTransaksi");
            $lt = New MdlLockerTransaksi();
            $lt->execLocker($this->cCodeData[$cCode]["main"], $nextProp["num"], $transaksiID_reference, NULL);
            //==================================================================================================

            //======================================
            // menulis transaksi baru, transaksi hasil edit
            if (isset($this->configUiModul[$this->jenisTr]["connectToEdit"][1])) {
                if ($this->configUiModul[$this->jenisTr]["connectToEdit"][1]["enabled"] == true) {
                    cekHijau("START menjalankan EDITOR...");
                    $connecTo = $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["connectTo"];
                    if ($connecTo == NULL) {
                        mati_disini("kode edit transaksi tidak dikenali. segera hubungi admin.");
                    }
                    $oldCode = $cCode;
                    $cCode = "_TR_" . $connecTo;
                    $this->cCodeData[$cCode] = array(
                        "main" => isset($this->cCodeData[$oldCode]["main"]) ? $this->cCodeData[$oldCode]["main"] : array(),
                        "items" => isset($this->cCodeData[$oldCode]["items"]) ? $this->cCodeData[$oldCode]["items"] : array(),
                        "items2" => isset($this->cCodeData[$oldCode]["items2"]) ? $this->cCodeData[$oldCode]["items2"] : array(),
                        "items2_sum" => isset($this->cCodeData[$oldCode]["items2_sum"]) ? $this->cCodeData[$oldCode]["items2_sum"] : array(),
                        "itemSrc" => isset($this->cCodeData[$oldCode]["itemSrc"]) ? $this->cCodeData[$oldCode]["itemSrc"] : array(),
                        "itemSrc_sum" => isset($this->cCodeData[$oldCode]["itemSrc_sum"]) ? $this->cCodeData[$oldCode]["itemSrc_sum"] : array(),
                        "items3" => isset($this->cCodeData[$oldCode]["items3"]) ? $this->cCodeData[$oldCode]["items3"] : array(),
                        "items3_sum" => isset($this->cCodeData[$oldCode]["items3_sum"]) ? $this->cCodeData[$oldCode]["items3_sum"] : array(),
                        "items4" => isset($this->cCodeData[$oldCode]["items4"]) ? $this->cCodeData[$oldCode]["items4"] : array(),
                        "items4_sum" => isset($this->cCodeData[$oldCode]["items4_sum"]) ? $this->cCodeData[$oldCode]["items4_sum"] : array(),
                        "items5_sum" => isset($this->cCodeData[$oldCode]["items5_sum"]) ? $this->cCodeData[$oldCode]["items5_sum"] : array(),
                        'items6_sum' => isset($this->cCodeData[$oldCode]['items6_sum']) ? $this->cCodeData[$oldCode]['items6_sum'] : array(),
                        'items7_sum' => isset($this->cCodeData[$oldCode]['items7_sum']) ? $this->cCodeData[$oldCode]['items7_sum'] : array(),
                        'items8_sum' => isset($this->cCodeData[$oldCode]['items8_sum']) ? $this->cCodeData[$oldCode]['items8_sum'] : array(),
                        'items9_sum' => isset($this->cCodeData[$oldCode]['items9_sum']) ? $this->cCodeData[$oldCode]['items9_sum'] : array(),
                        'items10_sum' => isset($this->cCodeData[$oldCode]['items10_sum']) ? $this->cCodeData[$oldCode]['items10_sum'] : array(),
                        'rsltItems' => isset($this->cCodeData[$oldCode]['rsltItems']) ? $this->cCodeData[$oldCode]['rsltItems'] : array(),
                        'rsltItems2' => isset($this->cCodeData[$oldCode]['rsltItems2']) ? $this->cCodeData[$oldCode]['rsltItems2'] : array(),
                        'rsltItems3' => isset($this->cCodeData[$oldCode]['rsltItems3']) ? $this->cCodeData[$oldCode]['rsltItems3'] : array(),
                        "tableIn_master" => isset($this->cCodeData[$oldCode]["tableIn_master"]) ? $this->cCodeData[$oldCode]["tableIn_master"] : array(),
                        "tableIn_detail" => isset($this->cCodeData[$oldCode]["tableIn_detail"]) ? $this->cCodeData[$oldCode]["tableIn_detail"] : array(),
                        'tableIn_detail2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail2_sum'] : array(),
                        'tableIn_detail_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'] : array(),
                        'tableIn_detail_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_rsltItems2'] : array(),
                        'tableIn_master_values' => isset($this->cCodeData[$oldCode]['tableIn_master_values']) ? $this->cCodeData[$oldCode]['tableIn_master_values'] : array(),
                        'tableIn_detail_values' => isset($this->cCodeData[$oldCode]['tableIn_detail_values']) ? $this->cCodeData[$oldCode]['tableIn_detail_values'] : array(),
                        'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'] : array(),
                        'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems2'] : array(),
                        'tableIn_detail_values2_sum' => isset($this->cCodeData[$oldCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$oldCode]['tableIn_detail_values2_sum'] : array(),
                        'main_add_values' => isset($this->cCodeData[$oldCode]['main_add_values']) ? $this->cCodeData[$oldCode]['main_add_values'] : array(),
                        'main_add_fields' => isset($this->cCodeData[$oldCode]['main_add_fields']) ? $this->cCodeData[$oldCode]['main_add_fields'] : array(),
                        'main_elements' => isset($this->cCodeData[$oldCode]['main_elements']) ? $this->cCodeData[$oldCode]['main_elements'] : array(),
                        'main_inputs' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                        'main_inputs_orig' => isset($this->cCodeData[$oldCode]['main_inputs']) ? $this->cCodeData[$oldCode]['main_inputs'] : array(),
                        "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                        "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                        "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                        "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                        "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                        "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                        "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                        "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                        "revert" => isset($this->cCodeData[$oldCode]['revert']) ? $this->cCodeData[$oldCode]['revert'] : array(),
                        "items_komposisi" => isset($this->cCodeData[$oldCode]['items_komposisi']) ? $this->cCodeData[$oldCode]['items_komposisi'] : array(),
                        "items_noapprove" => isset($this->cCodeData[$oldCode]['items_noapprove']) ? $this->cCodeData[$oldCode]['items_noapprove'] : array(),
                        "jurnalItems" => isset($this->cCodeData[$oldCode]['jurnalItems']) ? $this->cCodeData[$oldCode]['jurnalItems'] : array(),
                        "componentsBuilder" => isset($this->cCodeData[$oldCode]['componentsBuilder']) ? $this->cCodeData[$oldCode]['componentsBuilder'] : array(),
                    );
                    // masuk ke gerbang TableInMaster, tabel transaksi
                    $masterReplacers = array(
//                        "inv" => $tmpNomorNota,
                        "jenis_master" => $this->jenisTr,
                        "jenis_top" => $connecTo,
                        "jenis" => $connecTo,
                        "jenis_label" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
                        "transaksi_jenis" => $connecTo,
                        "step_avail" => 1,
                        "step_current" => 1,
                        "step_number" => 1,
                        "next_step_code" => "",
                        "next_step_label" => "",
                        "next_group_code" => "",
                        "next_step_num" => "0",
                        "trash_4" => "2",
                    );
                    // masuk ke gerbang main
                    $masterReplacersO = array(
                        "stepCode" => $connecTo,
                        "jenisTrTop" => $connecTo,
                        "jenisTrName" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
//                        "inv" => $tmpNomorNota,
                        "jenis_master" => $this->jenisTr,
                        "jenis_top" => $connecTo,
                        "jenis" => $connecTo,
                        "jenis_label" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
                        "transaksi_jenis" => $connecTo,
                        "stepCode" => $connecTo,
                        "jenisTrTop" => $connecTo,
                        "jenisTrName" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
                        "step_avail" => 1,
                        "step_current" => 1,
                        "step_number" => 1,
                        "next_step_code" => "",
                        "next_step_label" => "",
                        "next_group_code" => "",
                        "next_step_num" => "0",
                    );
                    foreach ($masterReplacersO as $key => $val) {
                        $this->cCodeData[$cCode]["main"][$key] = $val;
                    }
                    foreach ($masterReplacers as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }

                    //region penomoran receipt
                    $this->CI->load->model("CustomCounter");
                    $cn = new CustomCounter("transaksi");
                    $cn->setType("transaksi");
                    $counterForNumber = array($this->configValuesModul[$this->jenisTr]['formatNotaEdit']);
                    if (!in_array($counterForNumber[0], $this->configValuesModul[$this->jenisTr]['countersEdit'])) {
                        die(__LINE__ . " Used number should be registered in counters config as well");
                    }
                    echo "<div style='background:#ff7766;'>";
                    foreach ($counterForNumber as $i => $cRawParams) {
                        $cParams = explode("|", $cRawParams);
                        $cValues = array();
                        foreach ($cParams as $param) {
                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        }
                        $cRawValues = implode("|", $cValues[$i]);
                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                    }
                    echo "</div style='background:#ff7766;'>";

                    $stepNumber = 1;
                    $tmpNomorNota = $paramSpec["paramString"];
                    $tmpNomorNotaAlias = formatNota("nomer_nolink", $tmpNomorNota);
                    $nextProp = array(
                        "num" => 0,
                        "code" => "",
                        "label" => "",
                        "groupID" => "",
                    );
                    //endregion

                    //region dynamic counters
                    // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                    $cn = new CustomCounter("transaksi");
                    $cn->setType("transaksi");
                    $configCustomParams = $this->configValuesModul[$this->jenisTr]['countersEdit'];
                    arrPrintHijau($configCustomParams);
                    $configCustomParams[] = "stepCode";
                    //arrPrint($configCustomParams);
                    if (sizeof($configCustomParams) > 0) {
                        $cContent = array();
                        foreach ($configCustomParams as $i => $cRawParams) {
                            $cParams = explode("|", $cRawParams);
                            $cValues = array();
                            foreach ($cParams as $param) {
                                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                            }
                            $cRawValues = implode("|", $cValues[$i]);
                            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
                            $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                            switch ($paramSpec["id"]) {
                                case 0: //===counter type is new
                                    $addData = array(
                                        "toko_id" => $tokoID,
                                        "toko_nama" => $tokoNama,
                                    );
                                    $paramKeyRaw = print_r($cParams, true);
                                    $paramValuesRaw = print_r($cValues[$i], true);
                                    $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                    break;
                                default: //===counter to be updated
                                    $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                    break;
                            }
                            //echo "<hr>";
                        }
                    }
                    $appliedCounters = base64_encode(serialize($cContent));
                    $appliedCounters_inText = print_r($cContent, true);
                    //mati_disini();
//arrPrintPink($cContent);
                    //
                    //region addition on master


                    $addValues = array(
                        "counters" => $appliedCounters,
                        'counters_intext' => $appliedCounters_inText,
                        'nomer' => $tmpNomorNota,
                        'nomer2' => $tmpNomorNotaAlias,
                        'dtime' => date("Y-m-d H:i:s"),
                        'fulldate' => date("Y-m-d"),
                        "step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                        "step_number" => 1,
                        "step_current" => 1,
                        "next_step_num" => $nextProp["num"],
                        "next_step_code" => $nextProp["code"],
                        "next_step_label" => $nextProp["label"],
                        "next_group_code" => $nextProp["groupID"],
                        "tail_number" => 1,
                        "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                    );
                    foreach ($addValues as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }
                    //endregion

                    //
                    //region addition on detail
                    $addSubValues = array(
                        "sub_step_number" => 1,
                        "sub_step_current" => 1,
                        "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
                        "next_substep_num" => $nextProp["num"],
                        "next_substep_code" => $nextProp["code"],
                        "next_substep_label" => $nextProp["label"],
                        "next_subgroup_code" => $nextProp["groupID"],
                        "sub_tail_number" => 1,
                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][1]["target"],


                    );
                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
                        foreach ($addSubValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
                        }
                    }
                    //endregion
                    // </editor-fold>
                    //endregion

                    //region numbering tambahan
                    $this->CI->load->library("CounterNumber");
                    $ccn = new CounterNumber();
                    $ccn->setCCode($cCode);
                    $ccn->setJenisTr($this->jenisTr);
                    $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                    $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                    $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                    $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                    $new_counter = $ccn->getCounterNumber();
                    cekHitam("jenistr yang disett dari create " . $this->jenisTr);
                    if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                        foreach ($new_counter["main"] as $ckey => $cval) {
                            $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                            $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                        }
                    }
                    if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                        foreach ($new_counter["items"] as $ikey => $iSpec) {
                            foreach ($iSpec as $iikey => $iival) {
                                $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                            }
                        }
                    }
                    if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                        foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                            foreach ($iSpec as $iikey => $iival) {
                                $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                            }
                        }
                    }
                    //endregion

                    $addValues = array(
                        "counters" => $appliedCounters,
                        'counters_intext' => $appliedCounters_inText,
                        'nomer' => $tmpNomorNota,
                        'nomer2' => $tmpNomorNotaAlias,
                        'dtime' => date("Y-m-d H:i:s"),
                        'fulldate' => date("Y-m-d"),
                    );
                    foreach ($addValues as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }
                    $masterReplacers = array(
                        "nomer" => $tmpNomorNota,
                        "nomer2" => $tmpNomorNotaAlias,
                        "counters" => $appliedCounters,
                        "counters_intext" => $appliedCounters_inText,
                    );
                    foreach ($masterReplacers as $key => $val) {
                        $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                    }
                    $detailReplacers = array(
                        "sub_step_avail" => 1,
                        "sub_step_current" => 1,
                        "sub_step_number" => 1,
                        "next_substep_num" => "",
                        "next_substep_code" => "",
                        "next_substep_label" => "",
                        "next_subgroup_code" => "",
                    );
                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                            foreach ($dSpec as $key => $val) {
                                $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                            }
                        }
                    }
                    $itemsReplacers = array(
                        "next_substep_num" => "",
                        "next_substep_code" => "",
                        "next_substep_label" => "",
                        "next_subgroup_code" => "",
                    );
                    if (isset($this->cCodeData[$cCode]["items"]) && sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                        foreach ($this->cCodeData[$cCode]["items"] as $k => $dSpec) {
                            foreach ($dSpec as $key => $val) {
                                $this->cCodeData[$cCode]["items"][$k][$key] = isset($itemsReplacers[$key]) ? $itemsReplacers[$key] : $val;
                            }
                        }
                    }

                    //region ----------write transaksi, transaksi_data, main_fields, main_values, main_applets, etc
                    if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                        $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
                        $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 2;
                        $this->cCodeData[$cCode]["tableIn_master"]['cli'] = 1;
                        arrPrintHijau($this->cCodeData[$cCode]["tableIn_master"]);
                        $tr = new MdlTransaksi();
                        $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                        $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                        cekHitam("[$insertID] :: " . $this->CI->db->last_query());
                        $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                        $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                        $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                        if ($insertID < 1) {
                            die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                        }
                        $mongoList["main"] = array($insertID, $epID);
                        //==transaksi_id dan nomor nota diinject kan ke gate utama
                        $injectors = array(
                            "transaksi_id" => $insertID,
                            "nomer" => $tmpNomorNota,
                            "nomer2" => $tmpNomorNotaAlias,
                        );
                        $arrInjectorsTarget = array(
                            "items",
                            "items2_sum",
                            "rsltItems",
                        );
                        foreach ($injectors as $key => $val) {
                            $this->cCodeData[$cCode]["main"][$key] = $val;
                            foreach ($arrInjectorsTarget as $target) {
                                if (isset($this->cCodeData[$cCode][$target])) {
                                    foreach ($this->cCodeData[$cCode][$target] as $xid => $iSpec) {
                                        $id = isset($iSpec["id"]) && $iSpec["id"] > 0 ? $iSpec["id"] : $xid;
                                        if (isset($this->cCodeData[$cCode][$target][$id])) {
                                            $this->cCodeData[$cCode][$target][$id][$key] = $val;
                                        }
                                    }
                                }
                            }
                        }

                        //===signature
                        $dwsign = $tr->writeSignature($insertID, array(
                            "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "step_number" => 1,
                            "step_code" => $connecTo,
                            "step_name" => $this->configUiModul[$this->jenisTr]["connectToEdit"][1]["label"],
                            "group_code" => "",
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                            "transaksi_id" => $masterID,
                            "deskripsi" => "edit transaksi",
                            "cabang_id" => my_cabang_id(),
                            "cabang_nama" => my_cabang_name(),
                            "current_transaksi_id" => $masterID,
                            "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                        )) or die("Failed to write signature");
                        showLast_query("kuning");
                        $mongoList['sign'][] = $dwsign;
                        $idHis = array(
                            $stepNumber => array(
                                "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                                "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                                "step" => $stepNumber,
                                "trID" => $insertID,
                                "nomer" => $tmpNomorNota,
                                "nomer2" => $tmpNomorNotaAlias,
                                "counters" => $appliedCounters,
                                "counters_intext" => $appliedCounters_inText,
                            ),
                        );
                        $idHis_blob = blobEncode($idHis);
                        $idHis_intext = print_r($idHis, true);
                        $tr = new MdlTransaksi();
                        $dupState = $tr->updateData(array("id" => $insertID), array(
                            "next_step_num" => $nextProp["num"],
                            "next_step_code" => $nextProp["code"],
                            "next_step_label" => $nextProp["label"],
                            "next_group_code" => $nextProp["groupID"],

                            //===references
//                            "id_master" => $insertID,
                            "id_master" => $masterID,// milik transkasiID yang diedit
                            "id_top" => $insertID,
                            "ids_prev" => "",
                            "ids_prev_intext" => "",
                            "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "nomers_prev" => "",
                            "nomers_prev_intext" => "",
                            "jenises_prev" => "",
                            "jenises_prev_intext" => "",
                            "ids_his" => $idHis_blob,
                            "ids_his_intext" => $idHis_intext,

                        )) or die("Failed to update tr next-state!");
                        cekHijau($this->CI->db->last_query());

                        $addValues = array(
                            //===references
                            "id_master" => $insertID,
                            "id_top" => $insertID,
                            "ids_prev" => "",
                            "ids_prev_intext" => "",
                            "nomer_top" => $this->cCodeData[$cCode]["main"]['nomer'],
                            "nomers_prev" => "",
                            "nomers_prev_intext" => "",
                            "jenises_prev" => "",
                            "jenises_prev_intext" => "",
                            "ids_his" => $idHis_blob,
                            "ids_his_intext" => $idHis_intext,
                        );
                        foreach ($addValues as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                        }

                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                        $inserMainValues = array();
                        if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'])) {
                            //matiHEre("hooppp");
                            $inserMainValues = array();
                            foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['mainValues'] as $key => $src) {
                                if (isset($this->cCodeData[$cCode]['tableIn_master_values'][$key])) {
                                    $dd = $tr->writeMainValues($insertID, array(
                                        "key" => $key,
                                        "value" => $this->cCodeData[$cCode]['tableIn_master_values'][$key],
                                    ));

                                    $inserMainValues[] = $dd;
                                    $mongoList['mainValues'][] = $dd;
                                }
                            }
                        }

                        if (sizeof($inserMainValues) > 0) {
                            $arrBlob = blobEncode($inserMainValues);
                            $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                        }

                    }
                    if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                        $inserMainValues = array();
                        foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                            $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                            $inserMainValues[] = $dd;
                            $mongoList['mainValues'][] = $dd;
                        }

                        if (sizeof($inserMainValues) > 0) {
                            $arrBlob = blobEncode($inserMainValues);
                            $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                            $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                            //                    cekkuning("making a clone for input key $key / $val");
                            //                    $tmpTableIn=$this->cCodeData[$cCode]["tableIn_master"];
                            //                    $replacers=array(
                            //                        "nomer"=>$this->cCodeData[$cCode]["tableIn_master"]['nomer']."_$key",
                            //                    );
                            //                    foreach($replacers as $key=>$val){
                            //                        $tmpTableIn[$key]=$val;
                            //                    }
                            //                    $subInputInsertID = $tr->writeMainEntries($tmpTableIn);
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                            $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['main_applets']) && sizeof($this->cCodeData[$cCode]['main_applets']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_applets'] as $amdl => $aSpec) {
                            $tr->writeMainApplets($insertID, array(
                                "mdl_name" => $amdl,
                                "key" => $aSpec['key'],
                                "label" => $aSpec['labelValue'],
                                "description" => $aSpec['description'],
                            ));
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                        foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                            $tr->writeMainElements($insertID, array(
                                "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                                "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                                "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                                "name" => $aSpec['name'],
                                "label" => $aSpec["label"],
                                "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                                "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                            ));


                            //==nebeng bikin inputLabels
                            $currentValue = "";
                            switch ($aSpec['elementType']) {
                                case "dataModel":
                                    $currentValue = $aSpec['key'];
                                    break;
                                case "dataField":
                                    $currentValue = $aSpec["value"];
                                    break;
                            }
                            if (array_key_exists($elName, $relOptionConfigs)) {
                                //					cekhijau("$eName terdaftar pada relInputs");


                                if (isset($relOptionConfigs[$elName][$currentValue])) {
                                    if (sizeof($relOptionConfigs[$elName][$currentValue]) > 0) {
                                        foreach ($relOptionConfigs[$elName][$currentValue] as $oValueName => $oValSpec) {
                                            $inputLabels[$oValueName] = $oValSpec["label"];
                                            if (isset($oValSpec['auth'])) {
                                                if (isset($oValSpec['auth']["groupID"])) {
                                                    $inputAuthConfigs[$oValueName] = $oValSpec['auth']["groupID"];
                                                }
                                            }
                                        }
                                    }
                                }
                                else {
                                    //						cekKuning("option $currentValue pada $eName TIDAK ada pilihannya");
                                }

                            }

                        }
                    }
                    if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {

                        $insertIDs = array();
                        $insertDeIDs = array();
                        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                            $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                            if ($insertDetailID < 1) {
                                die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                            }
                            else {
                                $insertIDs[] = $insertDetailID;
                                $insertDeIDs[$insertID][] = $insertDetailID;
                                $mongoList['detail'][] = $insertDetailID;
                            }
                            if ($epID != 999) {
                                $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                                if ($insertEpID < 1) {
                                    die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                                }
                                else {
                                    $insertIDs[] = $insertEpID;
                                    $insertDeIDs[$epID][] = $insertEpID;
                                    $mongoList['detail'][] = $insertEpID;
                                }
                            }
                            cekUngu($this->CI->db->last_query());
                        }


                        if (sizeof($insertIDs) == 0) {
                            die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                        }
                        else {
                            $indexing_details = array();
                            foreach ($insertDeIDs as $key => $numb) {
                                $indexing_details[$key] = $numb;
                            }

                            foreach ($indexing_details as $k => $arrID) {
                                $arrBlob = blobEncode($arrID);
                                $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                                cekOrange($this->CI->db->last_query());
                            }
                        }
                    }
                    else {
                        die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $dSpec) {
                            $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                            $mongoList['detail'] = $insertIDs;
                            if ($epID != 999) {
                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                $mongoList['detail'] = $insertIDs;
                            }
                            cekUngu($this->CI->db->last_query());
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                            $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                            $insertIDs[] = $insertDetailID;
                            $mongoList['detail'][] = $insertDetailID;
                            if ($epID != 999) {
                                $dd = $tr->writeDetailEntries($epID, $dSpec);
                                $insertIDs[] = $dd;
                                $mongoList['detail'][] = $dd;
                            }
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $dSpec) {
                            $dd = $tr->writeDetailEntries($insertID, $dSpec);
                            $insertIDs[] = $dd;
                            $mongoList['detil'][] = $dd;
                            if ($epID != 999) {
                                $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                                $mongoList['detil'] = $insertIDs;
                            }
                            cekUngu($this->CI->db->last_query());
                        }
                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {

                        $insertIDs = array();
                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                                    if (isset($this->cCodeData[$cCode]["tableIn_detail"][$pID])) {
                                        $dd = $tr->writeDetailValues($insertID, array(
                                            "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                            "produk_id" => $pID,
                                            "key" => $key,
                                            "value" => isset($dSpec[$src]) ? $dSpec[$src] : "0",
                                        ));
                                        $insertIDs[$pID][] = $dd;
                                        $mongoList['detailValues'][] = $dd;

                                    }
                                }
                            }
                        }

                        if (sizeof($insertIDs) > 0) {
                            $arrBlob = blobEncode($insertIDs);
                            $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                        }

                    }
                    if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                        foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                            if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                                $insertIDs = array();
                                foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                                    $dd = $tr->writeDetailValues($insertID, array(
                                        "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                        "produk_id" => $pID,
                                        "key" => $key,
                                        "value" => $dSpec[$src],
                                    ));
                                    $insertIDs[] = $dd;
                                    $mongoList['detailValues'][] = $dd;
                                }
                            }
                        }
                    }
                    //endregion

                    $baseRegistries = array(
                        "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                        "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                        "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                        "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                        "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                        "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                        "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                        "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                        "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                        "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                        "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                        'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                        'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                        'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                        'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                        'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                        'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                        'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                        'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                        "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                        "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                        'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                        'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                        'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                        'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                        'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                        'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                        'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                        'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                        'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                        'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                        'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                        'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                        'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                        "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][1] : array(),
                        "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][1] : array(),
                        "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][1] : array(),
                        "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][1] : array(),
                        "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][1] : array(),
                        "jurnal_index" => isset($jurnalIndex) ? $jurnalIndex : array(),
                        "postProcessor" => isset($jurnalPostProc) ? $jurnalPostProc : array(),
                        "preProcessor" => isset($jurnalPreProc) ? $jurnalPreProc : array(),
                        "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                        "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                        "items_noapprove" => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                        "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                        "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                        //----
                        'mainOriginal' => isset($this->cCodeData[$cCode]['mainOriginal']) ? $this->cCodeData[$cCode]['mainOriginal'] : array(),
                        'itemsOriginal' => isset($this->cCodeData[$cCode]['itemsOriginal']) ? $this->cCodeData[$cCode]['itemsOriginal'] : array(),
                        //----
                    );
                    $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                    cekHijau("SELESAI menjalankan EDITOR...");
                }
            }
            else {
                $pakai_ini = 1;
                if ($pakai_ini == 1) {
                    //region signature
                    $tr = new MdlTransaksi();
                    $dataSign = array(
                        "nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                        "step_number" => 1,
                        "step_code" => $this->jenisTr,
                        "step_name" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"],
                        "group_code" => $this->configUiModul[$this->jenisTr]["steps"][1]['userGroup'],
                        "oleh_id" => my_id(),
                        "oleh_nama" => my_name(),
                        "keterangan" => $this->configUiModul[$this->jenisTr]["steps"][1]["label"] . " oleh " . my_name(),
                        "transaksi_id" => $insertID,
                        "deskripsi" => "edit transaksi",
                        "cabang_id" => my_cabang_id(),
                        "cabang_nama" => my_cabang_name(),
                        "current_transaksi_id" => $masterID,
                        "current_nomer" => $this->cCodeData[$cCode]["main"]['nomer'],
                    );
                    $dwsign = $tr->writeSignature($insertID, $dataSign) or die("Failed to write signature");
                    //endregion
                }
            }
            //======================================


            $outResultLib = array(
                "sessionData" => $this->cCodeData[$cCode],
                "tmpNomerNota" => $tmpNomer,
                "transaksiId" => $masterID,
                "masterId" => $masterID,
                "tmpNomerNotaEdit" => $tmpNomorNota,
                "transaksiIdEdit" => $insertID,
            );
            return $outResultLib;
        }
        else {
            die("the gate index you want to debug has not been formed yet!");
        }
    }

    // ekstrak data yang akan diedit dari followup preview
    public function doPreEdit()
    {
        $this->CI->load->model("MdlTransaksi");
        $this->CI->load->library("FieldCalculator");
        $this->CI->load->helper("he_angka");

//        $no = rtrim($this->uri->segment(5), "-");
//        $stepNumber = $this->uri->segment(6);
//        $currentStepNum = $this->uri->segment(7);
//        $rawBuilderURL = blobEncode(current_url());
        $no = $this->transaksiNumber;
        $stepNumber = $this->stepNum;
        $currentStepNum = $this->stepNumCurrent;
        $cCode = $this->cCode;
        $editMode = array(
            "edit" => "$no",
        );


        $tr = new MdlTransaksi();
        $tr->addFilter("transaksi.id in (" . implode(",", explode("-", $no)) . ")");
        $tmpTr = $tr->lookupJoined()->result();


        $signNumbers = array();
        $trs = new MdlTransaksi();
        $trs->setFilters(array());
        $tmpSign = $trs->lookupSignaturesByMasterID($no)->result();
        if (sizeof($tmpSign) > 0) {
            $sCtr = 0;
            foreach ($tmpSign as $row) {
                $signNumbers[$sCtr] = "" . $row->step_number;
                $sCtr++;
            }
        }
        $rawItems = array();

        //region detail elements of preview
        if (sizeof($tmpTr) > 0) {
            $this->jenisTr = $tmpTr[0]->jenis_master;
//            $cCode = "_TR_" . $this->jenisTr;
            if (isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = null;
                unset($this->cCodeData[$cCode]);
            }

            //region session init
            if (!isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = array(
                    "items" => array(),
                    "main" => array(),
                );
            }
            if (!isset($this->cCodeData[$cCode]["main"])) {
                $this->cCodeData[$cCode]["main"] = array();
            }
            if (!isset($this->cCodeData[$cCode]["items"])) {
                $this->cCodeData[$cCode]["items"] = array();
            }
            //endregion

            $trID = $tmpTr[0]->transaksi_id;
            $itemLabels = isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNumber]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNumber] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNumber] : array();
            $subAmountConfig = isset($this->configUiModul[$this->jenisTr]['shoppingCartAmountValue'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartAmountValue'][$stepNumber] : null;
            $measurementDetails = isset($this->configUiModul[$this->jenisTr]["receiptMesurementRows"]) ? $this->configUiModul[$this->jenisTr]["receiptMesurementRows"] : array();
            $masterID = $tmpTr[0]->id_master;
            $topID = $tmpTr[0]->id_top;
            $tmpNomorNota = $tmpTr[0]->nomer;
            $origJenis = $tmpTr[0]->jenis_master;
            $currentStepNum = $tmpTr[0]->step_number;
            $afterTargetStepNum = ($currentStepNum + 1);


            //==periksa apakah ada ganjalan
            $trA = new MdlTransaksi();
            $extSteps = $trA->lookupExtSteps($trID);
//            if (sizeof($extSteps) > 0) {
//                cekmerah("ada ganjalan step sebanyak " . sizeof($extSteps));
//            }
//            else {
//                cekhijau("TAK ada ganjalan step");
//            }

            $paySrcs = $trA->lookupPaymentSrcs($trID, $this->jenisTr . "_");
//            if (sizeof($paySrcs) > 0) {
//                cekmerah("ada ganjalan paymentSrc sebanyak " . sizeof($paySrcs));
//            }
//            else {
//                cekhijau("TAK ada ganjalan paymentSrc");
//            }


            $allowEdit = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowEdit']) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowEdit'] : false;
            $editableFields = isset($this->configUiModul[$this->jenisTr]['shoppingCartEditableFields'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartEditableFields'][$stepNumber] : array();


            //region valid items
            $tr = new MdlTransaksi();
            $tr->addFilter("transaksi.id in (" . implode(",", explode("-", $no)) . ")");
            $tr->addFilterJoin("valid_qty>0");
            $tmpTr = $tr->lookupJoined()->result();
            //            cekhitam($this->CI->db->last_query());


            $extractedItems = array();//==untuk urusan update transaksi referer
            $validItems = array();
            $validItemSends = array();
            if (sizeof($tmpTr) > 0) {
                foreach ($tmpTr as $row) {
                    if (!isset($validItems[$row->produk_id])) {
                        $validItems[$row->produk_id] = 0;
                    }
                    if (!isset($validItemSends[$row->produk_id])) {
                        $validItemSends[$row->produk_id] = 0;
                    }
                    $validItems[$row->produk_id] += $row->valid_qty;
                    $validItemSends[$row->produk_id] += $row->produk_ord_jml - $row->valid_qty;

                    if (!isset($extractedItems[$row->produk_id])) {
                        $extractedItems[$row->produk_id] = array();
                    }
                    $extractedItems[$row->produk_id][$row->id_detail] = array(
                        "id" => $row->id_detail,
                        "produk_id" => $row->produk_id,
                        "qty" => $row->produk_ord_jml,
                        "valid_qty" => $row->valid_qty,
                        "transaksi_id" => $row->transaksi_id,
                        "sent_qty" => $row->produk_ord_jml - $row->valid_qty,
                    );
                }
            }
            else {
                cekmerah("TIDAK ada yang mau diekstrak");
            }

            //endregion

            //region tabel2 tarikan untuk kolom2 nilai (hpp, ppn, dll)
            $tmpVal_main = $tr->lookupMainValuesByTransID($trID)->result();
            $tmpVal_detail = $tr->lookupDetailValuesByTransID($trID)->result();
            $mainValues = array();
            if (sizeof($tmpVal_main) > 0) {
                foreach ($tmpVal_main as $row) {
                    $mainValues[$row->key] = $row->value;
                }
            }
            $detailValues = array();
            if (sizeof($tmpVal_detail) > 0) {
                foreach ($tmpVal_detail as $row) {
                    $detailValues[$row->produk_id][$row->key] = $row->value;
                }
            }

            //endregion


            //region take from registries
            //==ambil value-gate
            $trr = new MdlTransaksi();
            $trr->setFilters(array());
            $trr->addFilter("transaksi_id='$no'");
            $tmpReg = $trr->lookupDataRegistries()->result();
            cekKuning($this->CI->db->last_query());

            $mainOriginal = array();
            $itemsOriginal = array();
            $main = array();
            $items = array();
            $items2 = array();
            $items2_sum = array();
            $items3 = array();
            $items3_sum = array();
            $items4 = array();
            $items4_sum = array();
            $itemsSrc = array();
            $itemsSrc_sum = array();
            $rsltItems = array();
            $rsltItems2 = array();
            $masterGates = array();
            $childGates = array();
            $childGates2 = array();
            $childGates2_sum = array();
            $childGatesRsltItems = array();
            $childGatesRsltItems2 = array();
            $masterTableInParams = array();
            $childTableInParams = array();
            $childTableInParamsRsltItems = array();
            $childTableInParamsRsltItems2 = array();
            $masterTableInValueParams = array();
            $childTableInValueParams = array();
            $childTableInValueParamsRsltItems = array();
            $childTableInValueParamsRsltItems2 = array();
            $masterAddValues = array();
            $masterAddFields = array();
            $mainElements = array();
            $mainInputs = array();
            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $row) {
                    foreach ($row as $key_reg => $val_reg) {
                        if ($key_reg != "transaksi_id") {
                            switch ($key_reg) {
                                case "main"://
                                    $main = $main + unserialize(base64_decode($val_reg));
                                    $mainOriginal = $main;
                                    break;
                                case "items"://
                                    $items = $items + unserialize(base64_decode($val_reg));
                                    $itemsOriginal = $items;
                                    break;
                                case "items2"://
                                    $items2 = $items2 + unserialize(base64_decode($val_reg));
                                    break;
                                case "items3"://
                                    $items3 = $items3 + unserialize(base64_decode($val_reg));
                                    break;
                                case "items3_sum"://
                                    $items3_sum = $items3_sum + unserialize(base64_decode($val_reg));
                                    break;
                                case "items4"://
                                    $items4 = $items4 + unserialize(base64_decode($val_reg));
                                    break;
                                case "items4_sum"://
                                    $items4_sum = $items4_sum + unserialize(base64_decode($val_reg));
                                    break;
                                case "itemsSrc"://
                                    $itemsSrc = $itemsSrc + unserialize(base64_decode($val_reg));
                                    break;
                                case "itemsSrc_sum"://
                                    $itemsSrc_sum = $itemsSrc_sum + unserialize(base64_decode($val_reg));
                                    break;
                                case "rsltItems"://
                                    $rsltItems = $rsltItems + unserialize(base64_decode($val_reg));
                                    break;
                                case "rsltItems2"://
                                    $rsltItems2 = $rsltItems2 + unserialize(base64_decode($val_reg));
                                    break;
                                case "items2_sum"://
                                    $items2_sum = $items2_sum + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_master"://
                                    $masterTableInParams = $masterTableInParams + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail"://
                                    $childTableInParams = $childTableInParams + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail_rsltItems"://
                                    $childTableInParamsRsltItems = $childTableInParamsRsltItems + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail_rsltItems2"://
                                    $childTableInParamsRsltItems2 = $childTableInParamsRsltItems2 + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_master_values"://
                                    $masterTableInValueParams = $masterTableInValueParams + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail_values"://
                                    $childTableInValueParams = $childTableInValueParams + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail_values_rsltItems"://
                                    $childTableInValueParamsRsltItems = $childTableInValueParamsRsltItems + unserialize(base64_decode($val_reg));
                                    break;
                                case "tableIn_detail_values_rsltItems2"://
                                    $childTableInValueParamsRsltItems2 = $childTableInValueParamsRsltItems2 + unserialize(base64_decode($val_reg));
                                    break;
                                case "main_add_values"://
                                    $masterAddValues = $masterAddValues + unserialize(base64_decode($val_reg));
                                    break;
                                case "main_add_fields"://
                                    $masterAddFields = $masterAddFields + unserialize(base64_decode($val_reg));
                                    break;
                                case "main_elements"://
                                    $mainElements = unserialize(base64_decode($val_reg));
                                    break;
                                case "main_inputs"://
                                    $mainInputs = unserialize(base64_decode($val_reg));
                                    break;

                                case "item_price"://
                                    $item_price = unserialize(base64_decode($val_reg));
                                    break;
                                case "itemPrice"://
                                    $itemPrice = unserialize(base64_decode($val_reg));
                                    break;
                                case "coreBuilder"://
                                    $coreBuilder = unserialize(base64_decode($val_reg));
                                    break;
                                case "diskon_event"://
                                    $diskon_event = unserialize(base64_decode($val_reg));
                                    break;
                                case "cashback_event"://
                                    $cashback_event = unserialize(base64_decode($val_reg));
                                    break;
                            }
                        }
                    }
                }
            }
            else {
                die("Cannot read the registry entries from $masterID!");
            }
            //endregion


            $masterReplacers = array(
                "jenisTrMaster" => $this->jenisTr,
                "jenisTrTop" => $masterTableInParams['jenis_top'],
                "harga" => 0,
                "masterID" => $masterID,
            );
            foreach ($masterReplacers as $key => $src) {
                $main[$key] = $src;
                $mainValues[$key] = $src;
                $masterGates[$key] = $src;
            }


            //==revalidate items
            $cal = new FieldCalculator();
            if (sizeof($items) > 0) {
                foreach ($items as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $tipeSize = isset($iSpec['detilSize']) && sizeof($iSpec['detilSize']) > 0 ? $iSpec['detilSize'] : "";
                    if (array_key_exists($id, $validItems)) {
                        $items[$id]['jml'] = $validItems[$id];
                        $items[$id]['max_jml'] = $validItems[$id];
                        $items[$id]['sent_jml'] = $validItemSends[$id];
                        if (sizeof($editableFields) > 0) {
                            foreach ($editableFields as $fName) {
                                $items[$id]["max_$fName"] = isset($iSpec[$fName]) ? $iSpec[$fName] : 0;
                            }
                        }
                        if (sizeof($measurementDetails)) {
                            if (in_array($stepNumber, $measurementDetails["allowView"]) && isset($measurementDetails[$tipeSize])) {
                                $selectedColl = $measurementDetails[$tipeSize];
                                foreach ($selectedColl as $colSelected => $tempHelper) {
                                    foreach ($tempHelper as $newKey => $heAngka) {
                                        $items[$id][$newKey] = $heAngka($iSpec[$colSelected]);
                                    }
                                }
                            }
                        }
                    }
                    else {
                        unset($items[$id]);
                        unset($childGates[$id]);
                        unset($childTableInParams[$id]);
                        unset($childTableInValueParams[$id]);
                    }
                }
            }


            //region session-swapper
            $swappers = array(
                "main" => $main,
                "items" => $items,
                "items2" => $items2,
                "items2_sum" => $items2_sum,
                "items3" => $items3,
                "items3_sum" => $items3_sum,
                "items4" => $items4,
                "items4_sum" => $items4_sum,
                "itemsSrc" => $itemsSrc,
                "itemsSrc_sum" => $itemsSrc_sum,
                "rsltItems" => $rsltItems,
                "rsltItems2" => $rsltItems2,
                "extractedItems" => $extractedItems,
                "tableIn_master" => $masterTableInParams,
                "tableIn_detail" => $childTableInParams,
                "tableIn_detail_rsltItems" => $childTableInParamsRsltItems,
                "tableIn_detail_rsltItems2" => $childTableInParamsRsltItems2,
                "tableIn_master_values" => $masterTableInValueParams,
                "tableIn_detail_values" => $childTableInValueParams,
                "tableIn_detail_values_rsltItems" => $childTableInValueParamsRsltItems,
                "tableIn_detail_values_rsltItems2" => $childTableInValueParamsRsltItems2,
                "main_add_values" => $masterAddValues,
                "main_add_fields" => $masterAddFields,
                "main_elements" => $mainElements,
                "main_inputs" => $mainInputs,
                "extSteps" => $extSteps,
                "paySrcs" => $paySrcs,
                "mode" => $editMode,
                "mainOriginal" => $mainOriginal,
                "itemsOriginal" => $itemsOriginal,
                //-----
                "item_price" => $item_price,
                "itemPrice" => $itemPrice,
                "coreBuilder" => $coreBuilder,
                "diskon_event" => $diskon_event,
                "cashback_event" => $cashback_event,
            );
            foreach ($swappers as $targetVar => $src) {
                $this->cCodeData[$cCode][$targetVar] = $src;
            }
            //endregion


            //==init replacer
            //==recover nilai HARGA master
            $this->cCodeData[$cCode]["main"]['harga'] = 0;
            if (sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                foreach ($this->cCodeData[$cCode]["items"] as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $this->cCodeData[$cCode]["main"]['harga'] += ($iSpec['jml'] * $iSpec['harga']);
                }
            }
        }
        else {
            die(lgShowAlert("No such transaction. You may want to refresh the browser to re-fetch actual content."));
        }
//cekHitam($cCode);
//arrPrintKuning($this->cCodeData[$cCode]);
//        $link = MODUL_PATH . "Create/index/" . $this->jenisTr;
        $libResult = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $no,
        );


//        mati_disini(__LINE__ . " == " . __FUNCTION__);
//        topRedirect($link);
//        die();
        return $libResult;


    }

    public function followupPrePreview()
    {
        $srcIdTr = $no = $this->transaksiNumber;
        $stepNumber = $this->stepNum;
        $currentStepNum = $this->stepNumCurrent;
        // matiHEre($no);
//        $rawBuilderURL = url_cleanup(blobEncode(current_url()));
//
//
//

        $this->CI->load->model("MdlTransaksi");

        //region read items from existing model
        $tr = new MdlTransaksi();
        $tr->addFilter("transaksi_id in (" . implode(",", explode("-", $no)) . ")");
        $tmpTr = $tr->lookupJoined()->result();
        cekBiru($this->CI->db->last_query());
        //        arrprint($tr->getFilters());
        //endregion

        $cancelPackingId = isset($tmpTr[0]->cancel_packing_source_id) ? $tmpTr[0]->cancel_packing_source_id : 0;
        $tmpTrCancelPacking = array();
        $id_top_source_cancel_packing = array();
        if ($cancelPackingId > 0) {
            $tr->setFilters(array());
            $tr->addFilter("transaksi_id in (" . implode(",", explode("-", $cancelPackingId)) . ")");
            $tmpTrCancelPacking = $tr->lookupJoined()->result();
            $id_top_source_cancel_packing = $tmpTrCancelPacking[0]->id_top;
        }

        $signNumbers = array();
        $trs = new MdlTransaksi();
        $trs->setFilters(array());
        $tmpSign = $trs->lookupSignaturesByMasterID($no)->result();
        if (sizeof($tmpSign) > 0) {
            $sCtr = 0;
            foreach ($tmpSign as $row) {
                $signNumbers[$sCtr] = "" . $row->step_number;
                $sCtr++;
            }
        }

        $rawItems = array();
        if (sizeof($tmpTr) > 0) {
            $jenisTr = $this->jenisTr = $tmpTr[0]->jenis_master;
            $cCode = $this->cCode;
            $tokoID = $tmpTr[0]->toko_id;

            $configUi = $this->configUiModul;
            $configCore = $this->configCoreModul;
            $configLayout = $this->configLayoutModul;
            $configValues = $this->configValuesModul;

            /* -------------------
             * settlement
             * -------------------*/
            $confSettlement = $this->CI->config->item('settlement');
            $warning = "";
            if ($confSettlement['restrictions'] == true) {
                $condites = array(
                    "date(dtime)<" => dtimeNow('Y-m-d'),
                );
                $this->db->where($condites);
                $mySettlementDatas = $trs->callMyTransaksi(my_id(), my_cabang_id());
                $jmlOldTransaksi = sizeof($mySettlementDatas);

                if ($jmlOldTransaksi > 0) {
                    $alerts = array(
                        "type" => "error",
                        "title" => "Peringatan!",
                        "html" => "Masih ada setelmen belum diselesaikan, silahkan diselesaikan terlebih dahulu",
                        // "allowOutsideClick" => true,
                        // "allowEscapeKey" => false,
                        // "confirmButtonText" => "Settlement",
                    );
                    $warning = swalAlertSettlement($alerts, $jenisTr);
                }
                echo $warning;
            }
            // -------------------

            if (isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = null;
                unset($this->cCodeData[$cCode]);
            }

            //region session init
            if (!isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = array(
                    "items" => array(),
                    "main" => array(),
                );
            }
            if (!isset($this->cCodeData[$cCode]["main"])) {
                $this->cCodeData[$cCode]["main"] = array();
            }
            if (!isset($this->cCodeData[$cCode]["items"])) {
                $this->cCodeData[$cCode]["items"] = array();
            }
            //endregion

            $trID = $tmpTr[0]->transaksi_id;
            $itemLabels = isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNumber]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNumber] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNumber] : array();
            $subAmountConfig = isset($this->configUiModul[$this->jenisTr]['shoppingCartAmountValue'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartAmountValue'][$stepNumber] : null;
            $measurementDetails = isset($this->configUiModul[$this->jenisTr]["receiptMesurementRows"]) ? $this->configUiModul[$this->jenisTr]["receiptMesurementRows"] : array();
            $validatePaymentLocker = isset($this->configUiModul[$this->jenisTr]["validatePaymentSource"][$stepNumber]) ? $this->configUiModul[$this->jenisTr]["validatePaymentSource"][$stepNumber] : array();
            $itemsChild = isset($this->configUiModul[$this->jenisTr]["shopingCartDetailFields"][$stepNumber]['fields']) ? $this->configUiModul[$this->jenisTr]["shopingCartDetailFields"][$stepNumber]['fields'] : array();//dipake detil pembelian aset
            $updatePrice = isset($this->configUiModul[$this->jenisTr]["updatePrice"][$stepNumber]) ? $this->configUiModul[$this->jenisTr]["updatePrice"][$stepNumber] : false;                                             //dipake add price pembelian aset
            $priceInjectorItems = isset($this->configUiModul[$this->jenisTr]["priceInjectorItems"][$stepNumber]) ? $this->configUiModul[$this->jenisTr]["priceInjectorItems"][$stepNumber] : array();
            $masterID = $tmpTr[0]->id_master;
            $topID = $tmpTr[0]->id_top;
            $tmpNomorNota = $tmpTr[0]->nomer;
            $origJenis = $tmpTr[0]->jenis_master;
            $currentStepNum = $tmpTr[0]->step_number;
            $afterTargetStepNum = ($currentStepNum + 1);


            //region periksa locker value;
            $tempLocker = array();
            $tempBtnUndo = array();
            if (sizeof($validatePaymentLocker) > 0) {
                $mdlName = "Mdls/" . $validatePaymentLocker;
                $this->load->model($mdlName);
                $l = new $validatePaymentLocker();
                $l->addFilter("transaksi_id='$no'");
                $l->addFilter("state='active'");
                $l->addFilter("nilai > 0");
                $tempLocker = $l->lookupAll()->result();
                if (sizeof($tempLocker) > 0) {
                    $tempBtnUndo = array(
                        "allowedUndone" => false,//tidak boleh di undo/reject
                        "allowedFollow" => false,//boleh di followup
                    );
                }
                else {
//                    arrPrint($this->config->item('payment_source')[$this->jenisTr]);
//                    cekKuning(":: $currentStepNum ::");
                    $jnTarget = isset($this->config->item('payment_source')[$this->jenisTr][$currentStepNum][0]['jenisTarget']) ? $this->config->item('payment_source')[$this->jenisTr][$currentStepNum][0]['jenisTarget'] : "";
//                    cekHitam(":: ** $jnTarget ** ::");
                    $tempBtnUndo = array(
                        "allowedUndone" => true,// boleh di undo/reject
                        "allowedFollow" => true,//tidak boleh di followup
                        "label" => isset($this->configUiModul[$jnTarget]["label"]) ? $this->configUiModul[$jnTarget]["label"] : "",
                    );
                }
            }
            //endregion


            //==periksa apakah ada ganjalan
            $trA = new MdlTransaksi();
            $extSteps = $trA->lookupExtSteps($masterID);
            if (sizeof($extSteps) > 0) {
                cekmerah("ada ganjalan step sebanyak " . sizeof($extSteps));
            }
            else {
                cekhijau("TAK ada ganjalan step");
            }
            $paySrcs = $trA->lookupPaymentSrcs($masterID, $this->jenisTr . "_");
            if (sizeof($paySrcs) > 0) {
                cekmerah("ada ganjalan paymentSrc sebanyak " . sizeof($paySrcs));
            }
            else {
                cekhijau("TAK ada ganjalan paymentSrc");
            }


            $allowEdit = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowEdit']) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowEdit'] : false;
            $allowCancel = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowCancel']) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNumber]['allowCancel'] : false;
            $editableFields = isset($this->configUiModul[$this->jenisTr]['shoppingCartEditableFields'][$stepNumber]) ? $this->configUiModul[$this->jenisTr]['shoppingCartEditableFields'][$stepNumber] : array();


            //region valid items
            $this->CI->load->model("MdlTransaksi");
            $tr = new MdlTransaksi();
            $tr->addFilter("transaksi_id in (" . implode(",", explode("-", $no)) . ")");
            $tr->addFilter("sub_step_number='" . $currentStepNum . "'");
            $tr->addFilter("next_substep_code='" . $this->configUiModul[$this->jenisTr]["steps"][$stepNumber]["target"] . "'");
            $tr->addFilter("next_substep_num='$stepNumber'");
            $tr->addFilter("valid_qty>0");
            $tmpTr = $tr->lookupJoined()->result();


            $id_top = isset($tmpTr[0]->id_top) ? $tmpTr[0]->id_top : "";
            $tmpTrPacked = array();
            // dibawa ini dimatikan karena tidak dibutuhkan di teguh
            // dipakai untuk mencari qty dicancel/direturn/dikirimkan
            //            if ($id_top != "") {
            //                $idTr = isset($tmpTr[0]->id) ? $tmpTr[0]->id : "";
            //                $trPack = new MdlTransaksi();
            //                $trPack->setFilters(array());
            //                $trPack->addFilter("id_top in (" . implode(",", explode("-", $id_top)) . ")");
            //                $trPack->addFilter("valid_qty>0");
            //                $tmpTrPacked = $trPack->lookupJoined()->result();
            //            }

            $tmpTrPrePacked = array();
            if (sizeof($id_top_source_cancel_packing) > 0) {
                $trPrePack = new MdlTransaksi();
                $trPrePack->setFilters(array());
                $trPrePack->addFilter("id_top in (" . implode(",", explode("-", $id_top_source_cancel_packing)) . ")");
                $trPrePack->addFilter("valid_qty>0");
                $trPrePack->addFilter("trash_4<1");
                $tmpTrPrePacked = $trPrePack->lookupJoined()->result();
            }
            else {
                if ($tmpTr[0]->cancel_packing_source_id == "") {
                    //mati_disini("TENGAH");
                }
                else {
                    //mati_disini("BAWAH");
                    $trPrePack = new MdlTransaksi();
                    $trPrePack->setFilters(array());
                    $trPrePack->addFilter("cancel_packing_source_id in (" . implode(",", explode("-", $no)) . ")");
                    $trPrePack->addFilter("valid_qty>0");
                    $trPrePack->addFilter("trash_4<1");
                    $tmpTrPrePacked = $trPrePack->lookupJoined()->result();
                }
            }


            $arrPreTmp__ = array();
            foreach ($tmpTrPrePacked as $y => $dd) {
                if (!isset($arrPreTmp__[$dd->jenis][$dd->produk_id])) {
                    $arrPreTmp__[$dd->jenis][$dd->produk_id] = 0;
                }
                $arrPreTmp__[$dd->jenis][$dd->produk_id] += $dd->produk_ord_jml;
            }

            $arrTmp__ = array();
            if (sizeof($tmpTrPacked) > 0) {
                foreach ($tmpTrPacked as $y => $dd) {
                    if (!isset($arrTmp__[$dd->jenis][$dd->produk_id])) {
                        $arrTmp__[$dd->jenis][$dd->produk_id] = 0;
                    }
                    $arrTmp__[$dd->jenis][$dd->produk_id] += $dd->produk_ord_jml;
                }
            }


            $extractedItems = array();//==untuk urusan update transaksi referer
            $validItems = array();
            $validItemSends = array();
            $validItemReqCancels = array();
            $validItemCancels = array();
            $validItemPreCancels = array();
            $validItemSents = array();
            if (sizeof($tmpTr) > 0) {
                cekmerah("ada yang mau diekstrak @" . __LINE__);
                foreach ($tmpTr as $row) {
                    if (!isset($validItems[$row->produk_id])) {
                        $validItems[$row->produk_id] = 0;
                    }
                    if (!isset($validItemSends[$row->produk_id])) {
                        $validItemSends[$row->produk_id] = 0;
                    }
                    if (!isset($validItemCancels[$row->produk_id])) {
                        $validItemCancels[$row->produk_id] = 0;
                    }
                    if (!isset($validItemReqCancels[$row->produk_id])) {
                        $validItemReqCancels[$row->produk_id] = 0;
                    }
                    if (!isset($validItemPackeds[$row->produk_id])) {
                        $validItemPackeds[$row->produk_id] = 0;
                    }
                    if (!isset($validItemPreCancels[$row->produk_id])) {
                        $validItemPreCancels[$row->produk_id] = 0;
                    }

                    $validItems[$row->produk_id] += isset($row->valid_qty) ? $row->valid_qty : 0;
                    $validItemSends[$row->produk_id] += isset($arrTmp__['582spd'][$row->produk_id]) ? $arrTmp__['582spd'][$row->produk_id] : 0;
                    $validItemCancels[$row->produk_id] += isset($row->cancel_qty) ? $row->cancel_qty : 0;
                    $validItemReqCancels[$row->produk_id] += isset($row->req_cancel_qty) ? $row->req_cancel_qty : 0;
                    $validItemPreCancels[$row->produk_id] += isset($arrPreTmp__['1982'][$row->produk_id]) ? $arrPreTmp__['1982'][$row->produk_id] : 0;
                    $validItemPackeds[$row->produk_id] += isset($arrTmp__['582pkd'][$row->produk_id]) ? $arrTmp__['582pkd'][$row->produk_id] : 0;

                    if (!isset($extractedItems[$row->produk_id])) {
                        $extractedItems[$row->produk_id] = array();
                    }
                    $extractedItems[$row->produk_id][$row->id] = array(
                        "id" => $row->id,
                        "produk_id" => $row->produk_id,
                        "qty" => $row->produk_ord_jml,
                        "valid_qty" => $row->valid_qty,
                        "transaksi_id" => $row->transaksi_id,
                        "packed_qty" => isset($arrTmp__['582pkd'][$row->produk_id]) ? $arrTmp__['582pkd'][$row->produk_id] : 0,
                        "sent_qty" => isset($arrTmp__['582spd'][$row->produk_id]) ? $arrTmp__['582spd'][$row->produk_id] : 0,
                        "req_cancel_qty" => isset($arrPreTmp__['1982'][$row->produk_id]) ? $arrPreTmp__['1982'][$row->produk_id] : 0,
                        "cancel_qty" => $row->cancel_qty,
                        "outstanding" => $row->produk_ord_jml - ($row->produk_ord_jml - $row->valid_qty),
                    );
                }
            }
            else {
                cekmerah("TIDAK ada yang mau diekstrak");
            }
            //endregion


            //region tabel2 tarikan untuk kolom2 nilai (hpp, ppn, dll)
            $tmpVal_main = $tr->lookupMainValuesByTransID($trID)->result();
            $tmpVal_detail = $tr->lookupDetailValuesByTransID($trID)->result();
            $mainValues = array();
            if (sizeof($tmpVal_main) > 0) {
                foreach ($tmpVal_main as $row) {
                    $mainValues[$row->key] = $row->value;
                }
            }
            $detailValues = array();
            if (sizeof($tmpVal_detail) > 0) {
                foreach ($tmpVal_detail as $row) {
                    $detailValues[$row->produk_id][$row->key] = $row->value;
                }
            }
            //endregion


            //region take from registries
            $trr = new MdlTransaksi();
            $trr->setFilters(array());
            $trr->addFilter("trash='0'");
            $tmpReg = $tr->lookupDataRegistriesByMasterID($srcIdTr)->row();

            $main = array();
            $items = array();
            $items2 = array();
            $items2_sum = array();
            $items3 = array();
            $items3_sum = array();
            $rsltItems = array();
            $rsltItems2 = array();
            $masterGates = array();
            $childGates = array();
            $childGates2 = array();
            $childGates2_sum = array();
            $childGatesRsltItems = array();
            $childGatesRsltItems2 = array();
            $masterTableInParams = array();
            $childTableInParams = array();
            $childTableInParamsRsltItems = array();
            $childTableInParamsRsltItems2 = array();
            $masterTableInValueParams = array();
            $childTableInValueParams = array();
            $childTableInValueParamsRsltItems = array();
            $childTableInValueParamsRsltItems2 = array();
            $masterAddValues = array();
            $masterAddFields = array();
            $mainElements = array();
            $mainInputs = array();
            $diskon_event = array();
            $cashback_event = array();
            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $param => $row) {
                    switch ($param) {
                        case "main"://
                            $main = $main + unserialize(base64_decode($row));
                            break;
                        case "items"://
                            $items = $items + unserialize(base64_decode($row));
                            break;
                        case "items2"://
                            $items2 = $items2 + unserialize(base64_decode($row));
                            break;
                        case "rsltItems"://
                            $rsltItems = $rsltItems + unserialize(base64_decode($row));
                            break;
                        case "rsltItems2"://
                            $rsltItems2 = $rsltItems2 + unserialize(base64_decode($row));
                            break;
                        case "items2_sum"://
                            $items2_sum = $items2_sum + unserialize(base64_decode($row));
                            break;
                        case "items3"://
                            $items3 = $items3 + unserialize(base64_decode($row));
                            break;
                        case "items3_sum"://
                            $items3_sum = $items3_sum + unserialize(base64_decode($row));
                            break;
                        case "tableIn_master"://
                            $masterTableInParams = $masterTableInParams + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail"://
                            $childTableInParams = $childTableInParams + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail_rsltItems"://
                            $childTableInParamsRsltItems = $childTableInParamsRsltItems + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail_rsltItems2"://
                            $childTableInParamsRsltItems2 = $childTableInParamsRsltItems2 + unserialize(base64_decode($row));
                            break;
                        case "tableIn_master_values"://
                            $masterTableInValueParams = $masterTableInValueParams + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail_values"://
                            $childTableInValueParams = $childTableInValueParams + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail_values_rsltItems"://
                            $childTableInValueParamsRsltItems = $childTableInValueParamsRsltItems + unserialize(base64_decode($row));
                            break;
                        case "tableIn_detail_values_rsltItems2"://
                            $childTableInValueParamsRsltItems2 = $childTableInValueParamsRsltItems2 + unserialize(base64_decode($row));
                            break;
                        case "main_add_values"://
                            $masterAddValues = $masterAddValues + unserialize(base64_decode($row));
                            break;
                        case "main_add_fields"://
                            $masterAddFields = $masterAddFields + unserialize(base64_decode($row));
                            break;
                        case "main_elements"://
                            $mainElements = unserialize(base64_decode($row));
                            break;
                        case "main_inputs"://
                            $mainInputs = unserialize(base64_decode($row));
                            break;
                        case "diskon_event"://
                            $diskon_event = unserialize(base64_decode($row));
                            break;
                        case "cashback_event"://
                            $cashback_event = unserialize(base64_decode($row));
                            break;
                    }
                }
            }
            else {
                mati_disini("Cannot read the registry entries from $masterID!");
            }
            //endregion


            //region replacer Downpayment avail
            if (isset($mainInputs['dp'])) {
                if (isset($this->configUiModul[$this->jenisTr]["updateDownpayment"][$stepNumber])) {
                    $this->CI->load->model("Coms/ComLockerValue");
                    $mi = new ComLockerValue();
                    $mi->addFilter("produk_id='" . $main["masterID"] . "'");
                    $mainInputAvail = $mi->fetchBalances("downpayment");
                    $lockerVal = $mainInputAvail[0]->nilai;
                    $mainValTmp_dp = $main['dp_value'];
                    $mainValTmp_dp_ppn = $main['dp_ppn_value'];

                    if (isset($main['valid_dp']) && $main['valid_dp'] > 0) {
                        $validate = round($mainInputAvail[0]->nilai - $mainValTmp_dp, 2);
                        if ($lockerVal > 0) {
                            $valnew = $main['new_net1'] - $lockerVal > 0 ? 0 : $main['new_net1'];
                            $main['dp_value'] = $valnew;
                            $main['dp_ppn_value'] = $valnew * 10 / 100;
                        }
                        else {
                            $main['dp_value'] = 0;
                            $main['dp_ppn_value'] = 0;
                        }

                        if ($validate > 0) {
                            $mainInputs['dp'] = $mainInputAvail[0]->nilai;
                        }
                        else {
                            if ($validate < 0) {
                                if (isset($main['valid_dp']) && $main['valid_dp'] > 0) {
                                    $main['downpayment'] = $mainInputs['dp'];
                                    $mainInputs['downpayment'] = $mainInputs['dp'];
                                    $main['total_ui'] = $masterTableInValueParams['tagihan'] - $masterTableInValueParams['dp_ppn_value'];
                                }
                                unset($mainInputs['dp']);
                            }
                        }
                    }
                    else {
                        $main['dp_value'] = 0;
                        $main['dp_ppn_value'] = 0;
                        unset ($mainInputs['dp']);
                    }

                    if (!isset($main['valid_dp'])) {
                        $main['valid_dp'] = $mainInputAvail[0]->nilai;
                    }
                }
            }
            else {
                if (isset($main['valid_dp']) && $main['valid_dp'] > 0) {
                    $main['downpayment'] = $main['dp'];
                    $mainInputs['downpayment'] = $main['dp'];
                    $main['total_ui'] = $masterTableInValueParams['new_net1'] - $main['valid_dp'];
                }
            }
            //endregion

            $masterReplacers = array(
                "jenisTrMaster" => $this->jenisTr,
                "jenisTrTop" => $masterTableInParams['jenis_top'],
                "harga" => 0,
                "masterID" => $masterID,
            );
            foreach ($masterReplacers as $key => $src) {
                $main[$key] = $src;
                $mainValues[$key] = $src;
                $masterGates[$key] = $src;
            }


            //==revalidate items
            $this->CI->load->library("FieldCalculator");
            $this->CI->load->helper("he_angka");
            $cal = new FieldCalculator();


            $itemChildData = array();
            $arrHpp = array();
            if (sizeof($items) > 0) {
                $listedItemsIDs = "(";
                foreach ($items as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $listedItemsIDs .= "'$id',";
                    $tipeSize = isset($iSpec['detilSize']) && sizeof($iSpec['detilSize']) > 0 ? $iSpec['detilSize'] : "";

                    if (array_key_exists($id, $validItems)) {
                        $items[$id]['jml'] = $validItems[$id];
                        //                        $items[$id]['jml'] = $validItems[$id]-(int)$validItemPreCancels[$id];
                        $items[$id]['max_jml'] = $validItems[$id];
                        //                        $items[$id]['max_jml'] = $validItems[$id]-(int)$validItemPreCancels[$id];
                        $items[$id]['packed_jml'] = $validItemPackeds[$id];
                        $items[$id]['sent_jml'] = $validItemSends[$id];
                        $items[$id]['cancel_jml'] = $validItemCancels[$id];
                        $items[$id]['req_cancel_jml'] = $validItemPreCancels[$id];
                        if (sizeof($editableFields) > 0) {
                            foreach ($editableFields as $fName) {
                                $items[$id]["max_$fName"] = isset($iSpec[$fName]) ? $iSpec[$fName] : 0;
                            }
                        }

                        if (sizeof($measurementDetails)) {
                            if (in_array($stepNumber, $measurementDetails["allowView"]) && isset($measurementDetails[$tipeSize])) {
                                $selectedColl = $measurementDetails[$tipeSize];
                                foreach ($selectedColl as $colSelected => $tempHelper) {
                                    //                                    cekHitam("$heAngka");

                                    foreach ($tempHelper as $newKey => $heAngka) {
                                        cekHitam($newKey);
                                        $items[$id][$newKey] = $heAngka($iSpec[$colSelected]);
                                    }
                                    //
                                }
                            }

                        }


                        if ($subAmountConfig != null) {
                            $tmpEx = $cal->multiExplode($subAmountConfig);
                            if (sizeof($tmpEx) > 1) {
                                //                            echo lgShowAlert("menghitung subtotal pakai rumus $subAmountConfig di step ke # $stepNumber");
                                $newSrc = $subAmountConfig;
                                foreach ($tmpEx as $key2 => $val2) {
                                    if (isset($items[$id][$val2])) {
                                        $newSrc = str_replace($val2, $items[$id][$val2], $newSrc);

                                    }
                                    else {
                                        if (isset($tmp[$val2])) {
                                            $newSrc = str_replace($val2, $items[$val2], $newSrc);

                                        }
                                        else {
                                            $newSrc = str_replace($val2, "0", $newSrc);

                                        }
                                    }


                                }
                                $subtotal = $cal->calculate($newSrc);


                            }
                            else {
                                //                            echo lgShowAlert("memasang subtotal dari $subAmountConfig");
                                $subtotal = $items[$id][$subAmountConfig];

                            }
                        }
                        else {
                            //                        echo lgShowAlert("tidak mengapa-apakan subtotal");
                            $subtotal = 0;

                        }

                        $items[$id]['subtotal'] = $subtotal;
                        //region item child
                        if (sizeof($itemsChild) > 0) {
                            for ($x = 1; $x <= $validItems[$id]; $x++) {
                                foreach ($itemsChild as $col => $col_label) {
                                    $itemChildData[$id][$x][$col] = isset($items[$id][$col]) ? $items[$id][$col] : "";
                                    $itemChildData[$id][$x]["jml"] = 1;
                                    $itemChildData[$id][$x]["qty"] = 1;
                                    $itemChildData[$id][$x]["folders"] = $main['pihakMainID'];
                                }

                            }
                            //                            arrPrint($itemsChild);
                            //                        foreach ($itemsChild as )
                        }

                        //endregion


                    }
                    else {
                        cekUngu(":: masuk sini, UNSET semua ::");
                        unset($items[$id]);
                        unset($childGates[$id]);
                        unset($childTableInParams[$id]);
                        unset($childTableInValueParams[$id]);

                    }

                    if (!isset($arrHpp[$xid])) {
                        $arrHpp[$xid] = array();
                    }
                    $arrHpp[$xid] = isset($iSpec) ? $iSpec : array();
                }
                $listedItemsIDs = rtrim($listedItemsIDs, ",");
                $listedItemsIDs .= ")";
                if ($updatePrice) {
                    $extenMdl = $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNumber]['mdlName'];
                    $extenFields = $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNumber]['fields'];
                    $this->CI->load->model("Mdls/" . $extenMdl);
                    $pr = new $extenMdl();
                    $pr->addFilter("produk_id in $listedItemsIDs");
                    $tmpPrice = $pr->lookUpAll()->result();

                    $externPriceDataTmp = array();
                    if (sizeof($tmpPrice) > 0) {
                        foreach ($tmpPrice as $tmpPrice0) {
                            $externPriceDataTmp[$tmpPrice0->cabang_id][$tmpPrice0->produk_id][$tmpPrice0->jenis_value] = $tmpPrice0->nilai;
                            $externPriceDataTmp[$tmpPrice0->cabang_id][$tmpPrice0->produk_id]['harga_jual_old'] = $tmpPrice0->jenis_value == "jual" ? $tmpPrice0->nilai * 1 : 0;
                        }
                    }
                    else {
                        $this->CI->load->model("Mdls/MdlCabang");
                        $c = new MdlCabang();
                        $tnpC = $c->lookUpAll()->result();
                        $cab = array();
                        foreach ($tnpC as $tmp) {
                            $cab[$tmp->id] = $tmp->nama;
                        }
                        $cab[CB_ID_PUSAT] = "PUSAT";
                        foreach ($cab as $cabang_id => $cabang_nama) {
                            foreach ($validItems as $prod_id => $itemms) {
                                foreach ($extenFields as $field_key => $field_val) {
                                    $externPriceDataTmp[$cabang_id][$prod_id][$field_val] = 0;
                                    $externPriceDataTmp[$cabang_id][$prod_id]['harga_jual_old'] = 0;
                                }
                            }
                        }
                    }

                    $finalItemPrice = array();
                    $finalItemPriceSum = array();
                    if (sizeof($externPriceDataTmp) > 0) {
                        foreach ($items as $pidMaster => $tmpDataItems) {
                            foreach ($externPriceDataTmp as $cID => $tmp) {
                                if (isset($tmp[$pidMaster])) {
                                    foreach ($extenFields as $field) {
                                        $valFinal = isset($tmpPriceData[$field]) ? $tmpPriceData[$field] : 0;
                                        if ($pidMaster > 0) {
                                            $finalItemPrice[$cID][$pidMaster][$field] = $valFinal;
                                            $finalItemPrice[$cID][$pidMaster]['harga_jual_old'] = isset($tmpPriceData['jual']) ? $tmpPriceData['jual'] * 1 : 0;
                                        }
                                    }
                                }
                                else {
                                    foreach ($extenFields as $field) {
                                        if ($pidMaster > 0) {
                                            $finalItemPrice[$cID][$pidMaster][$field] = 0;
                                            $finalItemPrice[$cID][$pidMaster]['harga_jual_old'] = 0;
                                        }
                                    }
                                }
                                foreach ($tmp as $pID => $tmpPriceData) {
                                    foreach ($extenFields as $field) {
                                        $valFinal = isset($tmpPriceData[$field]) ? $tmpPriceData[$field] : 0;
                                        if ($pID > 0) {
                                            $finalItemPrice[$cID][$pID][$field] = $valFinal;
                                            $finalItemPrice[$cID][$pID]['harga_jual_old'] = (isset($tmpPriceData['jual']) ? $tmpPriceData['jual'] * 1 : 0);
                                        }
                                    }
                                }
                            }
                        }
                        //-----------------
                        if (sizeof($finalItemPrice) > 0) {

                            $nom = 0;
                            foreach ($finalItemPrice as $cID => $cSpec) {
                                foreach ($cSpec as $pID => $pSpec) {

                                    $items[$pID]['price_setting'][$cID] = $pSpec;


                                    $nom++;
                                    foreach ($pSpec as $key => $val) {
                                        $finalItemPriceSum[$nom][$key] = $val;
                                        $finalItemPriceSum[$nom]["id"] = $pID;
                                    }
                                }
                            }
                        }
                        //-----------------
                    }
                    $this->CI->load->model("Mdls/MdlHargaJual");
                    $c = new MdlHargaJual();
                    $c->setItems($arrHpp);
                    $tnpC = $c->callHargaJual(array_keys($items));
                    $finalHargaJual = $tnpC;
                }
                /* ============ HargaJual ============*/

            }


            //region session-swapper
            $swappers = array(
                "main" => $main,
                "items" => $items,
                "items2" => $items2,
                "items2_sum" => $items2_sum,
                "items3" => $items3,
                "items3_sum" => $items3_sum,
                "items_child" => $itemChildData,
                "rsltItems" => $rsltItems,
                "rsltItems2" => $rsltItems2,
                "extractedItems" => $extractedItems,
                "tableIn_master" => $masterTableInParams,
                "tableIn_detail" => $childTableInParams,
                "tableIn_detail_rsltItems" => $childTableInParamsRsltItems,
                "tableIn_detail_rsltItems2" => $childTableInParamsRsltItems2,
                "tableIn_master_values" => $masterTableInValueParams,
                "tableIn_detail_values" => $childTableInValueParams,
                "tableIn_detail_values_rsltItems" => $childTableInValueParamsRsltItems,
                "tableIn_detail_values_rsltItems2" => $childTableInValueParamsRsltItems2,
                "main_add_values" => $masterAddValues,
                "main_add_fields" => $masterAddFields,
                "main_elements" => $mainElements,
                "main_inputs" => $mainInputs,
                "extSteps" => $extSteps,
                "paySrcs" => $paySrcs,
                "lockerPayment" => $tempBtnUndo,
                "itemPrice" => $finalItemPrice,
                "itemPrice_sum" => $finalItemPriceSum,
                "itemHargaJual" => $finalHargaJual,
                "diskon_event" => $diskon_event,
                "cashback_event" => $cashback_event,
            );
            // arrPrint($swappers);
            // matiHEre(__LINE__." || ".__FUNCTION__);
            foreach ($swappers as $targetVar => $src) {
                $this->cCodeData[$cCode][$targetVar] = $src;
            }
            //endregion


            //==init replacer
            arrPrint( $this->cCodeData[$cCode]);
            //==recover nilai HARGA master
            $this->cCodeData[$cCode]["main"]['harga'] = 0;


            //==default load dari nota, maka dianggap langsung done
            $this->cCodeData[$cCode]["main"]['status_4'] = 1;
            $this->cCodeData[$cCode]["main"]['trash_4'] = 0;
            if (sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                foreach ($this->cCodeData[$cCode]["items"] as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $this->cCodeData[$cCode]["main"]['harga'] += ($iSpec['jml'] * $iSpec['harga']);

                }
            }

            // matiHEre($cCode." || ". __LINE__." function ".__FUNCTION__);
            $this->CI->load->helper("he_value_builder");
//            resetValues($this->jenisTr);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $currentStepNum, $stepNumber, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], $this->cCodeData[$cCode]["main"]["ppnFactor"], $this->cCodeData[$cCode]);


            $outResultLib = array(
                "sessionData" => $this->cCodeData[$cCode],
//                "tmpNomerNota" => $tmpNomorNota,
//                "transaksiId" => $insertID,
            );
            return $outResultLib;

        }
        else {
            die(lgShowAlert("No such transaction. You may want to refresh the browser to re-fetch actual content."));
        }

    }

    //  ekstrak data yang akan dicancel/closed dari followup preview
    public function doPreCancelPacking()
    {
        $no = $this->transaksiNumber;
        $stepNumber = $this->stepNum;
        $currentStepNum = $this->stepNumCurrent;
        $cCode = $this->cCode;
        $editMode = array(//            "edit" => "$no",
        );
        $cancelMode = array(
            "cancel" => "$no",
        );
        $this->CI->load->model("MdlTransaksi");

        $tr = new MdlTransaksi();
        $tr->addFilter("id in (" . implode(",", explode("-", $no)) . ")");
        $tmpTr = $tr->lookupJoined();

        $signNumbers = array();
        $trs = new MdlTransaksi();
        $trs->setFilters(array());
        $tmpSign = $trs->lookupSignaturesByMasterID($no)->result();
        if (sizeof($tmpSign) > 0) {
            $sCtr = 0;
            foreach ($tmpSign as $row) {
                $signNumbers[$sCtr] = "" . $row->step_number;
                $sCtr++;
            }
        }

        $rawItems = array();
        cekHere("no: $no ::: $targetJenisTr");
        //region detail elements of preview
        if (sizeof($tmpTr) > 0) {

            if (isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = null;
                unset($this->cCodeData[$cCode]);
            }

            //region session init
            if (!isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = array(
                    "items" => array(),
                    "main" => array(),
                );
            }
            if (!isset($this->cCodeData[$cCode]["main"])) {
                $this->cCodeData[$cCode]["main"] = array();
            }
            if (!isset($this->cCodeData[$cCode]["items"])) {
                $this->cCodeData[$cCode]["items"] = array();
            }
            //endregion

            $trID = $tmpTr[0]->transaksi_id;
            $itemLabels = isset($this->configLayoutModul[$targetJenisTr]['receiptDetailFields'][$stepNumber]) ? $this->configLayoutModul[$targetJenisTr]['receiptDetailFields'][$stepNumber] : array();
            $itemNumLabels = isset($this->configUiModul[$targetJenisTr]['shoppingCartNumFields'][$stepNumber]) ? $this->configUiModul[$targetJenisTr]['shoppingCartNumFields'][$stepNumber] : array();
            $subAmountConfig = isset($this->configUiModul[$targetJenisTr]['shoppingCartAmountValue'][$stepNumber]) ? $this->configUiModul[$targetJenisTr]['shoppingCartAmountValue'][$stepNumber] : null;
            $measurementDetails = isset($this->configUiModul[$targetJenisTr]["receiptMesurementRows"]) ? $this->configUiModul[$targetJenisTr]["receiptMesurementRows"] : array();
            $xCancelConfig = isset($this->configUiModul[$targetJenisTr]["xShipmentConfig"][$currentStepNum]) ? $this->configUiModul[$targetJenisTr]["xShipmentConfig"][$currentStepNum] : array();


            $currentID = $tmpTr[0]->transaksi_id;
            $masterID = $tmpTr[0]->id_master;
            $topID = $tmpTr[0]->id_top;
            $tmpNomorNota = $tmpTr[0]->nomer;
            $origJenis = $tmpTr[0]->jenis_master;
            $cCodeOrig = "_TR_" . $origJenis;
            $currentStepNum = $tmpTr[0]->step_number;
            $afterTargetStepNum = (1);


            if (isset($this->cCodeData[$cCodeOrig])) {
                $this->cCodeData[$cCodeOrig] = null;
                unset($this->cCodeData[$cCodeOrig]);
            }

            //==periksa apakah ada ganjalan
            $trA = new MdlTransaksi();
            $extSteps = $trA->lookupExtSteps($trID);
            if (sizeof($extSteps) > 0) {
                cekmerah("ada ganjalan step sebanyak " . sizeof($extSteps));
            }
            else {
                cekhijau("TAK ada ganjalan step");
            }

            $paySrcs = $trA->lookupPaymentSrcs($trID, $this->jenisTr . "_");
            if (sizeof($paySrcs) > 0) {
                cekmerah("ada ganjalan paymentSrc sebanyak " . sizeof($paySrcs));
            }
            else {
                cekhijau("TAK ada ganjalan paymentSrc");
            }

            $allowEdit = isset($this->configUiModul[$targetJenisTr]["steps"][$stepNumber]['allowEdit']) ? $this->configUiModul[$targetJenisTr]["steps"][$stepNumber]['allowEdit'] : false;
            $editableFields = isset($this->configUiModul[$targetJenisTr]['shoppingCartEditableFields'][$stepNumber]) ? $this->configUiModul[$targetJenisTr]['shoppingCartEditableFields'][$stepNumber] : array();

            //region valid items
            $tr = new MdlTransaksi();
            $tr->addFilter("id in (" . implode(",", explode("-", $no)) . ")");
            $tr->addFilterJoin("valid_qty>0");
            $tmpTr = $tr->lookupJoined();
            showLast_query("biru");
            $id_top = isset($tmpTr[0]->id_top) ? $tmpTr[0]->id_top : "";

            //region prepacked
            $tmpTrPrePacked = array();
            $trPrePack = new MdlTransaksi();
            $trPrePack->setFilters(array());
            $trPrePack->addFilter("cancel_packing_source_id in (" . implode(",", explode("-", $no)) . ")");
            $trPrePack->addFilterJoin("valid_qty>0");
            $trPrePack->addFilter("trash_4<1");
            $tmpTrPrePacked = $trPrePack->lookupJoined();
//            showLast_query("merah");
//            cekMerah("ada " . sizeof($tmpTrPrePacked));

            $arrPreTmp__ = array();
            if (sizeof($tmpTrPrePacked) > 0) {
                foreach ($tmpTrPrePacked as $y => $dd) {
                    if (!isset($arrPreTmp__[$dd->jenis][$dd->produk_id])) {
                        $arrPreTmp__[$dd->jenis][$dd->produk_id] = 0;
                    }
                    $arrPreTmp__[$dd->jenis][$dd->produk_id] += $dd->produk_ord_jml;
                }
            }
            //endregion prepacked

            //region packed
            $tmpTrPacked = array();
            $trPack = new MdlTransaksi();
            $trPack->setFilters(array());
            $trPack->addFilter("id_top in (" . implode(",", explode("-", $id_top)) . ")");
            $trPack->addFilterJoin("valid_qty>0");
            $tmpTrPacked = $trPack->lookupJoined();
//            showLast_query("kuning");
//            cekKuning("ada " . sizeof($tmpTrPacked));

            $arrTmp__ = array();
            if (sizeof($tmpTrPacked) > 0) {

                foreach ($tmpTrPacked as $y => $dd) {
                    if (!isset($arrTmp__[$dd->jenis][$dd->produk_id])) {
                        $arrTmp__[$dd->jenis][$dd->produk_id] = 0;
                    }
                    $arrTmp__[$dd->jenis][$dd->produk_id] += $dd->produk_ord_jml;
                }
            }
            //endregion packed

            //            arrPrint($arrTmp__);

            $extractedItems = array();//==untuk urusan update transaksi referer
            $validItems = array();
            $validItemSends = array();
            $validItemReqCancels = array();
            $validItemCancels = array();
            $validItemPreCancels = array();
            $validItemPackeds = array();

            if (sizeof($tmpTr) > 0) {
//                cekmerah("ada yang mau diekstrak");
                //                arrPrint($tmpTr);
                $shipment = isset($xCancelConfig['shipment']) ? $xCancelConfig['shipment'] : "";
                $packing = isset($xCancelConfig['packing']) ? $xCancelConfig['packing'] : "";
                $cancel = isset($xCancelConfig['cancel']) ? $xCancelConfig['cancel'] : "";

                foreach ($tmpTr as $row) {
                    if (!isset($validItems[$row->produk_id])) {
                        $validItems[$row->produk_id] = 0;
                    }
                    if (!isset($validItemSends[$row->produk_id])) {
                        $validItemSends[$row->produk_id] = 0;
                    }
                    if (!isset($validItemCancels[$row->produk_id])) {
                        $validItemCancels[$row->produk_id] = 0;
                    }
                    if (!isset($validItemReqCancels[$row->produk_id])) {
                        $validItemReqCancels[$row->produk_id] = 0;
                    }
                    if (!isset($validItemPackeds[$row->produk_id])) {
                        $validItemPackeds[$row->produk_id] = 0;
                    }
                    if (!isset($validItemPreCancels[$row->produk_id])) {
                        $validItemPreCancels[$row->produk_id] = 0;
                    }

                    $validItems[$row->produk_id] += $row->valid_qty;
                    //                    $validItemSends[$row->produk_id] += $row->produk_ord_jml - $row->cancel_qty - $row->valid_qty;
                    //                    $validItemSends[$row->produk_id] += isset($arrTmp__['582spd'][$row->produk_id]) ? $arrTmp__['582spd'][$row->produk_id] : 0; // ini jumlah yang sudah dikirim atau GRN
                    $validItemSends[$row->produk_id] += isset($arrTmp__[$shipment][$row->produk_id]) ? $arrTmp__[$shipment][$row->produk_id] : 0; // ini jumlah yang sudah dikirim atau GRN
                    $validItemReqCancels[$row->produk_id] += isset($row->req_cancel_qty) ? $row->req_cancel_qty : 0;
                    $validItemCancels[$row->produk_id] += isset($row->cancel_qty) ? $row->cancel_qty : 0;
                    //                    $validItemPreCancels[$row->produk_id] += isset($arrPreTmp__['1982'][$row->produk_id]) ? $arrPreTmp__['1982'][$row->produk_id] : 0; // ini jumlah yang sudah direquest cancel item
                    $validItemPreCancels[$row->produk_id] += isset($arrPreTmp__[$cancel][$row->produk_id]) ? $arrPreTmp__[$cancel][$row->produk_id] : 0; // ini jumlah yang sudah direquest cancel item
                    //                    $validItemPackeds[$row->produk_id] += isset($arrTmp__['582pkd'][$row->produk_id]) ? $arrTmp__['582pkd'][$row->produk_id] : 0; // ini jumlah prepacking
                    $validItemPackeds[$row->produk_id] += isset($arrTmp__[$packing][$row->produk_id]) ? $arrTmp__[$packing][$row->produk_id] : 0; // ini jumlah prepacking

                    if (!isset($extractedItems[$row->produk_id])) {
                        $extractedItems[$row->produk_id] = array();
                    }

                    $extractedItems[$row->produk_id][$row->id_detail] = array(
                        "id" => $row->id_detail,
                        "produk_id" => $row->produk_id,
                        "qty" => $row->produk_ord_jml,
                        "valid_qty" => $row->valid_qty,
                        "transaksi_id" => $row->transaksi_id,
                        //                        "packed_qty" => isset($arrTmp__['582pkd'][$row->produk_id]) ? $arrTmp__['582pkd'][$row->produk_id] : 0, // ini jumlah prepacking
                        "packed_qty" => isset($arrTmp__[$packing][$row->produk_id]) ? $arrTmp__[$packing][$row->produk_id] : 0, // ini jumlah prepacking
                        "cancel_qty" => $row->cancel_qty,
                        "req_cancel_qty" => $row->req_cancel_qty,
                        "sent_qty" => $row->produk_ord_jml - $row->cancel_qty - $row->valid_qty,
                        "outstanding" => $row->produk_ord_jml - ($row->produk_ord_jml - $row->valid_qty),
                    );
                }
//                arrPrintWebs($extractedItems);
            }
            else {
                cekmerah("TIDAK ada yang mau diekstrak");
            }
            //endregion

            //region tabel2 tarikan untuk kolom2 nilai (hpp, ppn, dll)
            $tmpVal_main = $tr->lookupMainValuesByTransID($trID)->result();
            $tmpVal_detail = $tr->lookupDetailValuesByTransID($trID)->result();
            $mainValues = array();
            if (sizeof($tmpVal_main) > 0) {
                foreach ($tmpVal_main as $row) {
                    $mainValues[$row->key] = $row->value;
                }
            }
            $detailValues = array();
            if (sizeof($tmpVal_detail) > 0) {
                foreach ($tmpVal_detail as $row) {
                    $detailValues[$row->produk_id][$row->key] = $row->value;
                }
            }
            //endregion

            //region take from registries
            //==ambil value-gate
            $trr = new MdlTransaksi();
            $trr->setFilters(array());
            $trr->addFilter("transaksi_id in (" . implode(",", explode("-", $no)) . ")");
            $tmpReg = $trr->lookupDataRegistries()->result();
            //            cekKuning(__LINE__ . " " . $this->db->last_query());

            $main = array();
            $items = array();
            $items2 = array();
            $items2_sum = array();
            $rsltItems = array();
            $rsltItems2 = array();
            $masterGates = array();
            $childGates = array();
            $childGates2 = array();
            $childGates2_sum = array();
            $childGatesRsltItems = array();
            $childGatesRsltItems2 = array();
            $masterTableInParams = array();
            $childTableInParams = array();
            $childTableInParamsRsltItems = array();
            $childTableInParamsRsltItems2 = array();
            $masterTableInValueParams = array();
            $childTableInValueParams = array();
            $childTableInValueParamsRsltItems = array();
            $childTableInValueParamsRsltItems2 = array();
            $masterAddValues = array();
            $masterAddFields = array();
            $mainElements = array();
            $mainInputs = array();
            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $row) {
                    foreach ($row as $key_reg => $val_reg) {
                        switch ($key_reg) {
                            case "main"://
                                $main = $main + unserialize(base64_decode($val_reg));
                                break;
                            case "items"://
                                $items = $items + unserialize(base64_decode($val_reg));
                                break;
                            case "items2"://
                                $items2 = $items2 + unserialize(base64_decode($val_reg));
                                break;
                            case "rsltItems"://
                                $rsltItems = $rsltItems + unserialize(base64_decode($val_reg));
                                break;
                            case "rsltItems2"://
                                $rsltItems2 = $rsltItems2 + unserialize(base64_decode($val_reg));
                                break;
                            case "items2_sum"://
                                $items2_sum = $items2_sum + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_master"://
                                $masterTableInParams = $masterTableInParams + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail"://
                                $childTableInParams = $childTableInParams + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail_rsltItems"://
                                $childTableInParamsRsltItems = $childTableInParamsRsltItems + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail_rsltItems2"://
                                $childTableInParamsRsltItems2 = $childTableInParamsRsltItems2 + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_master_values"://
                                $masterTableInValueParams = $masterTableInValueParams + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail_values"://
                                $childTableInValueParams = $childTableInValueParams + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail_values_rsltItems"://
                                $childTableInValueParamsRsltItems = $childTableInValueParamsRsltItems + unserialize(base64_decode($val_reg));
                                break;
                            case "tableIn_detail_values_rsltItems2"://
                                $childTableInValueParamsRsltItems2 = $childTableInValueParamsRsltItems2 + unserialize(base64_decode($val_reg));
                                break;
                            case "main_add_values"://
                                $masterAddValues = $masterAddValues + unserialize(base64_decode($val_reg));
                                break;
                            case "main_add_fields"://
                                $masterAddFields = $masterAddFields + unserialize(base64_decode($val_reg));
                                break;
                            case "main_elements"://
                                $mainElements = unserialize(base64_decode($val_reg));
                                break;
                            case "main_inputs"://
                                $mainInputs = unserialize(base64_decode($val_reg));
                                break;
                        }
                    }
                }
            }
            else {
                die("Cannot read the registry entries from $masterID!");
            }
            //endregion

            $masterReplacers = array(
                "jenisTrMaster" => $targetJenisTr,
                "jenisTrTop" => $targetJenisTr,
                "harga" => 0,
                "masterID" => $masterID,
                "currentID" => $currentID,
            );
            foreach ($masterReplacers as $key => $src) {
                $main[$key] = $src;
                $mainValues[$key] = $src;
                $masterGates[$key] = $src;
            }

            //==revalidate items
            $this->CI->load->library("FieldCalculator");
            $this->CI->load->helper("he_angka");
            $cal = new FieldCalculator();

            if (sizeof($items) > 0) {
                foreach ($items as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $items[$id]['handler'] = $this->modul . "/" . "_processSelectNotaItem";
                    $tipeSize = isset($iSpec['detilSize']) && sizeof($iSpec['detilSize']) > 0 ? $iSpec['detilSize'] : "";
                    if (array_key_exists($id, $validItems)) {
                        //                        $items[$id]['jml'] = $validItems[$id]-(int)$validItemPreCancels[$id];//orig
                        $items[$id]['jml'] = $validItems[$id];
                        $items[$id]['max_jml'] = (int)$validItems[$id] + (int)$validItemSends[$id] + (int)$validItemPackeds[$id] + (int)$validItemCancels[$id] + (int)$validItemReqCancels[$id];
                        $items[$id]['sent_jml'] = $validItemSends[$id];
                        $items[$id]['packed_jml'] = $validItemPackeds[$id];
                        $items[$id]['cancel_jml'] = $validItemCancels[$id];
                        $items[$id]['req_cancel_jml'] = $validItemPreCancels[$id];

                        if (sizeof($editableFields) > 0) {
                            foreach ($editableFields as $fName) {
                                $items[$id]["max_$fName"] = isset($iSpec[$fName]) ? $iSpec[$fName] : 0;
                            }
                        }
                        if (sizeof($measurementDetails)) {
                            if (in_array($stepNumber, $measurementDetails["allowView"]) && isset($measurementDetails[$tipeSize])) {
                                $selectedColl = $measurementDetails[$tipeSize];
                                foreach ($selectedColl as $colSelected => $tempHelper) {
                                    foreach ($tempHelper as $newKey => $heAngka) {
                                        cekHitam($newKey);
                                        $items[$id][$newKey] = $heAngka($iSpec[$colSelected]);
                                    }
                                }
                            }
                        }
                    }
                    else {
                        unset($items[$id]);
                        unset($childGates[$id]);
                        unset($childTableInParams[$id]);
                        unset($childTableInValueParams[$id]);
                    }
                }
            }

            //region session-swapper
            $swappers = array(
                "main" => $main,
                "items" => $items,
                "items2" => $items2,
                "items2_sum" => $items2_sum,
                "rsltItems" => $rsltItems,
                "rsltItems2" => $rsltItems2,
                "extractedItems" => $extractedItems,
                "tableIn_master" => $masterTableInParams,
                "tableIn_detail" => $childTableInParams,
                "tableIn_detail_rsltItems" => $childTableInParamsRsltItems,
                "tableIn_detail_rsltItems2" => $childTableInParamsRsltItems2,
                "tableIn_master_values" => $masterTableInValueParams,
                "tableIn_detail_values" => $childTableInValueParams,
                "tableIn_detail_values_rsltItems" => $childTableInValueParamsRsltItems,
                "tableIn_detail_values_rsltItems2" => $childTableInValueParamsRsltItems2,
                "main_add_values" => $masterAddValues,
                "main_add_fields" => $masterAddFields,
                "main_elements" => $mainElements,
                "main_inputs" => $mainInputs,
                "extSteps" => $extSteps,
                "paySrcs" => $paySrcs,
                "mode" => $cancelMode,
            );
            foreach ($swappers as $targetVar => $src) {
                $this->cCodeData[$cCode][$targetVar] = $src;
            }
            //endregion

            //==init replacer
            //==recover nilai HARGA master
            $this->cCodeData[$cCode]["main"]['harga'] = 0;
            if (sizeof($this->cCodeData[$cCode]["items"]) > 0) {
                foreach ($this->cCodeData[$cCode]["items"] as $xid => $iSpec) {
                    $id = $iSpec["id"];
                    $this->cCodeData[$cCode]["main"]['harga'] += ($iSpec['jml'] * $iSpec['harga']);
                }
            }
        }
        else {
            die(lgShowAlert("No such transaction. You may want to refresh the browser to re-fetch actual content."));
        }

        $libResult = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $no,
        );


//        mati_disini(__LINE__ . " == " . __FUNCTION__);
//        topRedirect($link);
//        die();
        return $libResult;

    }

    public function doCancelPacking()
    {
        $cCode = $this->cCode;
        $transaksiID_reference = $no = $this->transaksiNumber;
        $stepNum = $this->stepNum;
        $stepNumCurrent = $this->stepNumCurrent;

        $transaksiMode = isset($this->configUiModul[$this->jenisTr]["transaksiMode"]) ? $this->configUiModul[$this->jenisTr]["transaksiMode"] : mati_disini("Mode transaksi silahkan diseting di coTransaksiUi " . $this->jenisTr);
        $core = isset($this->configCoreMaster[$this->modul][$transaksiMode]) ? $this->configCoreMaster[$this->modul][$transaksiMode] : array();
        $coreRequiredParam = isset($this->configCoreMaster[$this->modul]['requiredParam']) ? $this->configCoreMaster[$this->modul]['requiredParam'] : array();
        $corePreProcParam = isset($this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor']) ? $this->configCoreMaster[$this->modul]['requiredParam'][$this->jenisTr]['preProcessor'] : array();
        $runCoreAkunting = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]["runCoreAkunting"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["runCoreAkunting"] : false;
        $paramPatchers = $this->CI->config->item('heTransaksi_paramPatchers') != null ? $this->CI->config->item('heTransaksi_paramPatchers') : array();
        $paramForceFillers = $this->CI->config->item('heTransaksi_paramForceFillers') != null ? $this->CI->config->item('heTransaksi_paramForceFillers') : array();


        $this->CI->load->library("FieldCalculator");
        $this->CI->load->model("MdlTransaksi");


        $cal = new FieldCalculator();


        $stepNowParameter = array();
        $tr = new MdlTransaksi();
        $tr->addFilter("transaksi.id in (" . implode(",", explode("-", $no)) . ")");
        $tr->addFilter("transaksi.step_number='" . $stepNumCurrent . "'");
        $tr->addFilterJoin("transaksi_data.trash='0'");
        $tmpTr = $tr->lookupJoined()->result();
        if (sizeof($tmpTr) > 0) {
            $this->jenisTr = $tmpTr[0]->jenis_master;
            $cCode = "_TR_" . $this->jenisTr;

            //region session init
            if (!isset($this->cCodeData[$cCode])) {
                $this->cCodeData[$cCode] = array(
                    "items" => array(),
                    "main" => array(),
                );
            }
            if (!isset($this->cCodeData[$cCode]["main"])) {
                $this->cCodeData[$cCode]["main"] = array();
            }
            if (!isset($this->cCodeData[$cCode]["items"])) {
                $this->cCodeData[$cCode]["items"] = array();
            }
            $this->cCodeData[$cCode]['rsltItems'] = array();
            $this->cCodeData[$cCode]['rsltItems2'] = array();
            //endregion

            $tokoID = $this->cCodeData[$cCode]["main"]['tokoID'];
            $tokoNama = $this->cCodeData[$cCode]["main"]["tokoNama"];
            $jenisTrTarget = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"]) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"] : NULL;
            $detailValuesConfig = isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues']) ? $this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] : array();
            $additionalData = isset($this->configUiModul[$this->jenisTr]["addDetailData"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["addDetailData"][$stepNum] : array();
            $additionalDataPriceConf = isset($this->configUiModul[$this->jenisTr]["updatePrice"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["updatePrice"][$stepNum] : false;

            $masterID = $this->cCodeData[$cCode]["main"]["masterID"];
            $topID = $tmpTr[0]->id_top;
            $tmpNomorNota = $tmpTr[0]->nomer;
            $origJenis = $tmpTr[0]->jenis_master;
            $trID = $tmpTr[0]->transaksi_id;

            $totalSteps = sizeof($this->configUiModul[$this->jenisTr]["steps"]);
            //==references, previous entry
            $prevProp = array(
                "id" => $tmpTr[0]->transaksi_id,
                "jenis" => $tmpTr[0]->jenis,
                "nomer" => $tmpTr[0]->nomer,
            );
            //------
            $stepNowParameter = array(
                "next_step_code" => $tmpTr[0]->next_step_code,
                "next_step_label" => $tmpTr[0]->next_step_label,
                "next_group_code" => $tmpTr[0]->next_group_code,
                "next_step_num" => $tmpTr[0]->next_step_num,
                "step_current" => $tmpTr[0]->step_current,
            );


            $tmpVal_main = $tr->lookupMainValuesByTransID($trID)->result();
            $tmpVal_detail = $tr->lookupDetailValuesByTransID($trID)->result();
            $mainValues = array();
            if (sizeof($tmpVal_main) > 0) {
                foreach ($tmpVal_main as $row) {
                    $mainValues[$row->key] = $row->value;
                }
            }
            $detailValues = array();
            if (sizeof($tmpVal_detail) > 0) {
                foreach ($tmpVal_detail as $row) {
                    $detailValues[$row->produk_id][$row->key] = $row->value;
                }
            }


            $main = array();
            $items = array();
            $prevIDs = array();
            $prevNos = array();
            foreach ($tmpTr as $row) {
                $items[$row->produk_id] = array(
                    "id" => $row->produk_id,
                    "nama" => $row->produk_nama,
                    "jml" => $row->produk_ord_jml,
                    "harga" => $row->produk_ord_hrg,
                    "valid_qty" => $row->valid_qty,
                    "transaksi_id" => $row->transaksi_id,
                    "nomer" => $row->nomer,
                );

                if ($row->valid_qty > 0) {
                    cekHitam("ok lanjut");
                }
                else {
                    if (isset($this->cCodeData[$cCode]["items"][$row->produk_id])) {
                        matiHere("Followed up already. Please close and refresh your browser " . $row->produk_nama . " " . $row->produk_id);//kalo session active ya harus dimatiin biar gak dobel
                    }
                }

                if (!in_array($row->transaksi_id, $prevIDs)) {
                    $prevIDs[] = $row->transaksi_id;
                }
                if (!in_array($row->nomer, $prevNos)) {
                    $prevNos[] = $row->nomer;
                }
                if (sizeof($detailValuesConfig) > 0) {
                    echo "detail values ada..<br>";
                    foreach ($detailValuesConfig as $key => $src) {
                        echo "$key akan ambil nilai dari $src<br>";

                        if (isset($detailValues[$row->produk_id][$key])) {

                            $items[$row->produk_id][$key] = $detailValues[$row->produk_id][$key];
                        }
                        else {
                            if (isset($row->$key)) {

                                $items[$row->produk_id][$key] = $row->$key;
                            }
                        }
                        echo "dan sekarang nilainya: " . $items[$row->produk_id][$key] . "<br>";
                    }
                }
            }

        }
        else {
            $masterID = 0;
            $tmpNomorNota = "XXXX";
            $origJenis = 0;
            $topID = 0;
            die(lgShowAlert("No such receipt ID: $no!"));
        }


        //region ongkir dll diselipkan ke masterGates
        if (isset($this->configValuesModul[$this->jenisTr]['externalValues']) && sizeof($this->configValuesModul[$this->jenisTr]['externalValues']) > 0) {
            foreach ($this->configValuesModul[$this->jenisTr]['externalValues'] as $exKey => $exSpec) {
                if ($exSpec['useAt'] == $stepNum) {
                    if (isset($exSpec['mdlName']) && strlen($exSpec['mdlName']) > 3) {
                        $this->cCodeData[$cCode]["main"][$exKey . "_src"] = $_POST[$exKey . "_src"];
                        if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey . "_src"])) {
                            $this->cCodeData[$cCode]['main_add_values'][$exKey . "_src"] = $_POST[$exKey . "_src"];
                        }
                    }
                    $this->cCodeData[$cCode]["main"][$exKey] = $_POST[$exKey];
                    if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey])) {
                        $this->cCodeData[$cCode]['main_add_values'][$exKey] = $_POST[$exKey];
                    }

                    if ($exSpec['taxFactor'] > 0) {
                        $this->cCodeData[$cCode]["main"][$exKey . "_tax"] = $_POST[$exKey . "_tax"];
                        if (isset($this->cCodeData[$cCode]['main_add_values'][$exKey . "_tax"])) {
                            $this->cCodeData[$cCode]['main_add_values'][$exKey . "_tax"] = $_POST[$exKey . "_tax"];
                        }
                    }
                }
            }
        }
        //endregion


        //region baca seting optional step
        if (isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField']) && strlen($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField']) > 0) {

            $criteriaField = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]['optCriteriaField'];
            if (isset($this->cCodeData[$cCode]["main"][$criteriaField]) && $this->cCodeData[$cCode]["main"][$criteriaField] > 0) {
                echo "nextstepnum normal<br>";
                $nextStepNum = ($stepNum + 1);
                $useAdditionalStep = true;
            }
            else {
                echo "nextstepnum hampir normal<br>";
                $useAdditionalStep = false;
                $nextStepNum = ($stepNum + 2);
            }
        }
        else {
            echo "nextstepnum TIDAK normal<br>";
            $useAdditionalStep = false;
            $nextStepNum = ($stepNum + 1);
            echo "yaitu $nextStepNum<br>";
        }
        //endregion


        //region pembulatan replacer disini
        $injectBulat = isset($this->configValuesModul[$this->jenisTr]['valuePembulatan'][$stepNum]) ? $this->configValuesModul[$this->jenisTr]['valuePembulatan'][$stepNum] : array();
        if (sizeof($injectBulat) > 0) {
            echo "<script>top.writeProgress('PEMBULATAN', 'HEAD');</script>";
            $selectedSource = $injectBulat['source'];
            $injectSource = makeDppBulat($this->cCodeData[$cCode]["main"][$selectedSource]);
            foreach ($injectBulat['replacer'] as $k => $fields) {
                $this->cCodeData[$cCode]["main"][$fields] = $injectSource[$k];
                echo "<script>top.writeProgress('PEMBULATAN ($fields)');</script>";
            }
        }
        //endregion


        //update/swap valid_qty to cancel_qty
        $trTrash = new MdlTransaksi();
        $trTrash->setFilters(array());
        $trTrash->addFilter("id in (" . implode(",", explode("-", $cancel_packing_source_id)) . ")");
        //        $trTrash->addFilter("valid_qty>0 OR req_cancel_qty>0");
        $tmpTrS = $trTrash->lookupJoined()->result();
        $trCancel = array();
        if (sizeof($tmpTrS) > 0) {
            foreach ($tmpTrS as $row) {
                $trCancel['valid_qty'][$row->produk_id] = $row->valid_qty;
                $trCancel['cancel_qty'][$row->produk_id] = $row->cancel_qty;
                $trCancel['req_cancel_qty'][$row->produk_id] = $row->req_cancel_qty;
            }
        }
        $bQty = array();
        foreach ($tmpTr as $row) {
            if (!isset($bQty[$row->produk_id])) {
                $bQty[$row->produk_id] = 0;
            }
            $bQty[$row->produk_id] += $row->valid_qty;
        }
        if (sizeof($tmpTr) > 0) {
            foreach ($tmpTr as $row) {
                $dataItems = array();
                $where = array(
                    "transaksi_id" => $cancel_packing_source_id,
                    "produk_id" => $row->produk_id,
                );

                $req_cancel_qty_b4 = isset($trCancel['req_cancel_qty'][$row->produk_id]) ? $trCancel['req_cancel_qty'][$row->produk_id] : 0;
                $valid_qty_b4 = isset($trCancel['valid_qty'][$row->produk_id]) ? $trCancel['valid_qty'][$row->produk_id] : 0;
                $cancel_qty_b4 = isset($bQty[$row->produk_id]) ? $bQty[$row->produk_id] : 0;

                cekHijau("req_cancel_qty_b4: " . $req_cancel_qty_b4);
                cekHijau("valid_qty_b4: " . $valid_qty_b4);
                cekHijau("cancel_qty_b4: " . $cancel_qty_b4);

                $req_cancel_qty_af = (int)$req_cancel_qty_b4 - (int)$cancel_qty_b4;
                $cancel_qty_af = (int)$cancel_qty_b4 + (int)$req_cancel_qty_b4;

                if ($valid_qty_b4 > 0) {
                    $dataItems = array(
                        "cancel_qty" => $cancel_qty_af,
                        "req_cancel_qty" => $req_cancel_qty_af,
                    );

                    cekOrange("valid QTY masih ada");

                }
                else {
                    $dataItems = array(
                        "cancel_qty" => $cancel_qty_af,
                        "req_cancel_qty" => $req_cancel_qty_af,
                        "sub_step_number" => '',
                        "next_substep_code" => '',
                    );
                    cekOrange("valid QTY kosong boss, marking sub_step_number");
                }


                $trTrash->setTableName("transaksi_data");
                $trTrash->setFilters(array());
                $updateItems = $trTrash->updateData($where, $dataItems) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  updte  params registries"));
                cekHitam($this->db->last_query());
                cekHere($row->id . " - " . $row->produk_id);
                cekHere("cancel_packing_source_id " . $row->cancel_packing_source_id);
                arrPrint($where);

            }
        }



        // region PRE-PROCESSOR

        //region pre-processors (item)
        if (isset($core['preProcessor'][$jenisTrTarget]['detail'])) {
            $iterator = isset($core['preProcessor'][$jenisTrTarget]['detail']) ? $core['preProcessor'][$jenisTrTarget]['detail'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNum]) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'][$stepNum] : array();
            echo "ITEM NUM LABELS";

            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('PERSIAPAN PRE-PROCESSOR...', 'HEAD');</script>";
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
//                        if (isset($corePreProcParam[$comName]) && ($corePreProcParam[$comName] == true)) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo __LINE__ . " :: sub-preproc: $comName, initializing values <br>";

                    foreach ($this->cCodeData[$cCode][$srcGateName] as $xid => $dSpec) {
                        $tmpOutParams[$cCtr] = array();
                        $id = $xid;
                        $subParams = array();

                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {

                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['static'][$key] = $realValue;

                            }

                            if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                                foreach ($paramPatchers[$comName] as $k => $v) {
                                    if (!isset($subParams['static'][$k])) {
                                        $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                    }
                                }
                            }
                            if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                                $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                                foreach ($paramForceFillers[$comName] as $k => $v) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }

                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                        }

                        if (sizeof($subParams) > 0) {
                            $tmpOutParams[$cCtr][] = $subParams;
                        }


                        $comName = $tComSpec['comName'];
                        $srcGateName = $tComSpec['srcGateName'];
                        $srcRawGateName = $tComSpec['srcRawGateName'];
                        $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();

                        echo "sub preproc #$it: $comName, sending values <br>";

                        $mdlName = "Pre" . ucfirst($comName);
                        $this->CI->load->model("Preprocs/" . $mdlName);
                        $m = new $mdlName($resultParams);
                        if (sizeof($tmpOutParams[$cCtr]) > 0) {
                            $tobeExecuted = true;
                        }
                        else {
                            $tobeExecuted = false;
                        }

                        if ($tobeExecuted) {
                            $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                            $gotParams = $m->exec();
                            cekHitam(":: PRE-PROCC -> GOTNAME, ITERATING...");
                            arrprint($gotParams);
                            if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                                foreach ($gotParams as $gateName => $paramSpec) {

                                    if (!isset($this->cCodeData[$cCode][$gateName])) {
                                        $this->cCodeData[$cCode][$gateName] = array();
                                        //                                    cekhijau("building the session: $gateName");
                                    }
                                    else {
                                        //                                    cekhijau("NOT building the session: $gateName");
                                    }

                                    foreach ($paramSpec as $id => $gSpec) {
                                        //                                        $id = $gSpec["id"];
                                        if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            $this->cCodeData[$cCode][$gateName][$id] = array();
                                        }

                                        if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                foreach ($gSpec as $key => $val) {
                                                    $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                }
                                            }
                                        }
                                        //==inject gotParams to child gate
                                        if ($gateName == $srcGateName) {
                                            if (isset($this->cCodeData[$cCode][$srcGateName][$id])) {
                                                if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                                    foreach ($gSpec as $key => $val) {
                                                        $this->cCodeData[$cCode][$srcGateName][$id][$key] = $val;
                                                    }
                                                }
                                            }
                                        }

                                        //cekMerah("REBUILDING VALUES..");
                                        if (sizeof($itemNumLabels) > 0) {
                                            //cekHijau("REBUILDING SUBS FOR ITEMS");
                                            foreach ($itemNumLabels as $key => $label) {
                                                //cekHere("$id === $key => $label");
                                                $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                //                                        die();
                                            }
                                        }
                                    }
                                    //                                    arrPrint($this->cCodeData[$cCode][$gateName]);die();
                                }
                            }
                        }
                        else {
                            cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                        }
                    }

                    $this->CI->load->helper("he_value_builder");
//                    fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
                    $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);

//                        }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);
        }
        else {
            echo("no processor defined. skipping preprocessor..<br>");
        }

        //endregion

        //region pre-processors (master)
        if (isset($core['preProcessor'][$jenisTrTarget]['master'])) {
            $iterator = isset($core['preProcessor'][$jenisTrTarget]['master']) ? $core['preProcessor'][$jenisTrTarget]['master'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();

            echo "ITEM NUM LABELS";

            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('PERSIAPAN PRE-PROCESSOR...', 'HEAD');</script>";
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
//                        if (isset($corePreProcParam[$comName]) && ($corePreProcParam[$comName] == true)) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                    $switchResultParams = isset($tComSpec['switchResultParams']) ? $tComSpec['switchResultParams'] : false;

                    echo "master-preproc: $comName, initializing values <br>";
                    $tmpOutParams[$cCtr] = array();

                    $subParams = array();
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $subParams['static'][$key] = $realValue;
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }

                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }
                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr] = $subParams;
                    }


                    $mdlName = "Pre" . ucfirst($comName);
                    $this->CI->load->model("Preprocs/" . $mdlName);
                    $m = new $mdlName($resultParams);


                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }

                    if ($tobeExecuted) {
                        $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $gotParams = $m->exec();

                        cekbiru("gotparams dari $comName");
                        arrprint($gotParams);

                        if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                            cekhijau("ada gotparam, sekarang mau replace");
                            foreach ($gotParams as $gateName => $gSpec) {

                                if ($switchResultParams == true) {
                                    foreach ($gSpec as $id => $ggSpec) {
                                        if (!isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            $this->cCodeData[$cCode][$gateName][$id] = array();
                                        }
                                        if (isset($this->cCodeData[$cCode][$gateName][$id])) {
                                            if (is_array($ggSpec) && sizeof($ggSpec) > 0) {
                                                foreach ($ggSpec as $key => $val) {
                                                    $this->cCodeData[$cCode][$gateName][$id][$key] = $val;
                                                }
                                            }
                                        }
                                        //cekMerah("REBUILDING VALUES..");
                                        if (sizeof($itemNumLabels) > 0) {
                                            //cekHijau("REBUILDING SUBS FOR ITEMS");
                                            foreach ($itemNumLabels as $key => $label) {
                                                //cekHere("$id === $key => $label");
                                                if (isset($this->cCodeData[$cCode][$gateName][$id][$key])) {
                                                    $this->cCodeData[$cCode][$gateName][$id]['sub_' . $key] = ($this->cCodeData[$cCode][$gateName][$id]['jml'] * $this->cCodeData[$cCode][$gateName][$id][$key]);
                                                }
                                            }
                                        }
                                    }
                                }
                                else {
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                cekbiru("injecting param $key with $val");
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                    //==inject gotParams to child gate
                                    if (isset($this->cCodeData[$cCode]["main"])) {
                                        if (is_array($gSpec) && sizeof($gSpec) > 0) {
                                            foreach ($gSpec as $key => $val) {
                                                $this->cCodeData[$cCode]["main"][$key] = $val;
                                            }
                                        }
                                    }
                                }

                            }
                        }
                        else {
                            cekmerah("TIDAK ada gotparam, tidak perlu replace");
                        }

                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }

//                        }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);
        }
        else {
            echo("no processor defined. skipping preprocessor..<br>");
        }

        //endregion

        // endregion PRE-PROCESSOR


        //region pre-proc value injector items2 items2_sum dari gerbang main
        $injectValues = isset($core['preInjectValue'][$stepNum]) ? $core['preInjectValue'][$stepNum] : array();
        if (sizeof($injectValues) > 0) {
            $iterator = isset($core['preInjectValue'][$stepNum]['master']) ? $core['preInjectValue'][$stepNum]['master'] : array();
            $itemNumLabels = isset($this->configUiModul[$this->jenisTr]['shoppingCartNumFields']) ? $this->configUiModul[$this->jenisTr]['shoppingCartNumFields'] : array();
            if (sizeof($iterator) > 0) {
                foreach ($iterator as $cCtr => $tComSpec) {
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    $resultParams = isset($tComSpec['resultParams']) ? $tComSpec['resultParams'] : array();
                    $tmpOutParams[$cCtr] = array();
                    $subParams = array();

                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $subParams['static'][$key] = $realValue;
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }

                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr] = $subParams;
                    }


                    $mdlName = "Pre" . ucfirst($comName);
                    $this->CI->load->model("Preprocs/" . $mdlName);
                    $m = new $mdlName($resultParams);
                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }

                    if ($tobeExecuted) {
                        $m->pair($masterID, $tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada pre-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $gotParams = $m->exec();
                        if (sizeof($gotParams) > 0) {//==gotParams means result from preprocessor
                            foreach ($gotParams as $gateName => $gSpec) {
                                if ($gateName == "main") {
                                    foreach ($gSpec as $key => $val) {
                                        $this->cCodeData[$cCode]["main"][$key] = $val;
                                    }
                                }
                                if ($gateName == "items2") {
                                    foreach ($this->cCodeData[$cCode]["items2"] as $k => $tmpSes) {
                                        foreach ($gSpec as $key => $val) {
                                            foreach ($tmpSes as $y => $sesData) {
                                                if (array_key_exists($key, $sesData)) {
                                                    $this->cCodeData[$cCode]["items2"][$k][$y][$key] = $val;
                                                }
                                            }
                                        }
                                    }
                                }
                                if ($gateName == "items2_sum") {
                                    foreach ($this->cCodeData[$cCode]["items2_sum"] as $k => $tmpSes) {
                                        foreach ($gSpec as $key => $val) {
                                            $this->cCodeData[$cCode]["items2_sum"][$k][$key] = $val;
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            cekmerah("TIDAK ada gotparam, tidak perlu replace");
                        }
                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }
                }
            }
            else {
                //cekKuning("sub-preproc is not set");
            }


            $this->CI->load->helper("he_value_builder");
//            fillValues_he_value_builder($this->jenisTr, $stepNumCurrent, $stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr]);
            $this->cCodeData[$cCode] = fillValuesSessionData_he_value_builder($this->jenisTr, $this->stepNum, $this->stepNum, $this->configCoreModul[$this->jenisTr], $this->configUiModul[$this->jenisTr], $this->configValuesModul[$this->jenisTr], "", $this->cCodeData[$cCode]);
        }
        //endregion


        //region VALIDATOR masih session
        $step = $this->cCodeData[$cCode]["main"]['step_number'];
        $this->CI->load->library("Validator");
        $va = new Validator();
        $va->setConfigUiJenis($this->configUiModul[$this->jenisTr]);
        $va->setCCode($this->cCode);
        $va->setSessionData($this->cCodeData[$cCode]);
        $va->midValidateSessionData($step);
        $va->unionValidateSessionData();
        //endregion


        //region update step2an
        if (isset($this->configUiModul[$this->jenisTr]["steps"][$nextStepNum])) {//===masih ada langkah selanjutnya
            echo "authorizing to next step..<br>";
            $nextProp = array(
                "num" => $nextStepNum,
                "code" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]["target"],
                "label" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]["label"],
                "groupID" => $this->configUiModul[$this->jenisTr]["steps"][$nextStepNum]['userGroup'],
            );
        }
        else {//==ini step terakhir, tulis komponen jika ada
            $nextProp = array(
                "num" => 0,
                "code" => "",
                "label" => "",
                "groupID" => "",
            );
        }
        //endregion


        $dwsign = $tr->writeSignature($masterID, array(
            "nomer" => $tmpNomorNota,
            "step_number" => $stepNum,
            "step_code" => $this->configUiModul[$origJenis]["steps"][$stepNum]["target"],
            "step_name" => $this->configUiModul[$origJenis]["steps"][$stepNum]["label"],
            "group_code" => $this->configUiModul[$origJenis]["steps"][$stepNum]['userGroup'],
            "oleh_id" => my_id(),
            "oleh_nama" => my_name(),
            "keterangan" => $this->configUiModul[$origJenis]["steps"][$stepNum]["label"] . " oleh " . my_name(),
            "transaksi_id" => $masterID,
        )) or die("Failed to write signature");


        //region update step terdahulu
        $tr = new MdlTransaksi();
        $dupState = $tr->updateData(array("id" => $topID), array(
            "next_step_code" => $nextProp["code"],
            "next_step_label" => $nextProp["label"],
            "next_group_code" => $nextProp["groupID"],
            "next_step_num" => $nextProp["num"],
            "step_current" => $stepNum,
            "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,

        )) or die("Failed to update tr next-state!");
//        $mongUpdateList['update']["main"][] = array(
//            "where" => array("id" => "$topID"),
//            "value" => array(
//                "next_step_code" => $nextProp["code"],
//                "next_step_label" => $nextProp["label"],
//                "next_group_code" => $nextProp["groupID"],
//                "next_step_num" => $nextProp["num"],
//                "step_current" => $stepNum,
//            ),
//        );
//        cekHijau($this->CI->db->last_query());

        //-------------------------------------------------
        $tr = new MdlTransaksi();
        $dupState = $tr->updateData(array("id" => $trID), array(
            "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,
        )) or die("Failed to update tr next-state!");
//        $mongUpdateList['update']["main"][] = array(
//            "where" => array("id" => "$trID"),
//            "value" => array(
//                "partial" => isset($this->cCodeData[$cCode]["main"]["partial"]) ? $this->cCodeData[$cCode]["main"]["partial"] : 0,
//            ),
//        );

        //endregion


        //==prepare kloningan
        $tCode = $this->configUiModul[$origJenis]["steps"][$stepNum]["target"];
        $tCodeName = $this->configUiModul[$origJenis]["steps"][$stepNum]["label"];
        $masterReplacers = array(
            "inv" => $tmpNomorNota,
            "jenis" => $tCode,
            "jenis_label" => $tCodeName,
            "transaksi_jenis" => $tCode,
            "cabang_id" => selectedTransactionSession() ? $this->cCodeData[$cCode]["main"]["cabangID"] : my_cabang_id(),
            "cabang_nama" => selectedTransactionSession() ? $this->cCodeData[$cCode]["main"]["cabangName"] : my_cabang_name(),
            "oleh_id" => my_id(),
            "oleh_nama" => my_name(),
            "step_current" => "0",
            "step_number" => $stepNum,
            "next_step_code" => $nextProp["code"],
            "next_step_label" => $nextProp["label"],
            "next_group_code" => $nextProp["groupID"],
            //===references
            "id_master" => $masterID,
            "id_top" => $topID,
            "ids_prev" => base64_encode(serialize($prevIDs)),
            "nomer_top2" => isset($this->cCodeData[$cCode]["main"]["nomer_top2"]) ? $this->cCodeData[$cCode]["main"]["nomer_top2"] : "",
            "nomer_top" => isset($this->cCodeData[$cCode]["tableIn_master"]["nomer_top"]) ? $this->cCodeData[$cCode]["tableIn_master"]["nomer_top"] : "",
            "nomers_prev" => base64_encode(serialize($prevNos)),
            "jenises_prev" => base64_encode(serialize(array($prevProp['jenis']))),
            // "jenises_prev_intext" => print_r(array($prevProp['jenis']), true),
            "tail_number" => $stepNum,
            "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
        );

        foreach ($masterReplacers as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }

        $childTableRepaclers = array(
            "sub_step_number" => $stepNum,
            "sub_step_current" => $stepNum,
            "sub_step_avail" => sizeof($this->configUiModul[$this->jenisTr]["steps"]),
            "next_substep_num" => $nextProp["num"],
            "next_substep_code" => $nextProp["code"],
            "next_substep_label" => $nextProp["label"],
            "next_subgroup_code" => $nextProp["groupID"],
        );
        foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $id => $dSpec) {
            foreach ($childTableRepaclers as $key => $val) {
                $this->cCodeData[$cCode]["tableIn_detail"][$id][$key] = $val;
            }
        }


        $masterReplacersO = array(
            "jenisTr" => $tCode,
            "jenisTrName" => $tCodeName,
            "olehID" => my_id(),
            "olehName" => my_name(),
            "stepNumber" => $stepNum,
            "stepCode" => $tCode,
        );
        foreach ($masterReplacersO as $key => $val) {
            $this->cCodeData[$cCode]["main"][$key] = $val;
        }

        //region menimbulkan nilai tagihan
        $unpaidList = null != $this->CI->config->item("tr_unpaidList") ? $this->CI->config->item("tr_unpaidList") : array();
        if (in_array($tCode, $unpaidList)) {
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_tagihan"] = $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai"];
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_terbayar"] = 0;
            $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_sisa"] = ($this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_tagihan"] - $this->cCodeData[$cCode]["tableIn_master"]["transaksi_nilai_terbayar"]);
        }
        else {
            //cekMerah("TIDAK NULIS TAGIHANN");
        }
        //endregion

        //region penomoran receipt #1
        $this->CI->load->model("CustomCounter");
        $cn = new CustomCounter("transaksi");
        $cn->setType("transaksi");
        $counterForNumber = array($this->configValuesModul[$origJenis]["formatNota"]);
        if (!in_array($counterForNumber[0], $this->configValuesModul[$origJenis]["counters"])) {
            die(__LINE__ . " Used number should be registered in counters config as well");
        }

        foreach ($counterForNumber as $i => $cRawParams) {
            $cParams = explode("|", $cRawParams);
            $cValues = array();
            foreach ($cParams as $param) {
                $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
            }
            $cRawValues = implode("|", $cValues[$i]);
            $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);
        }
        $tmpNomorNota2 = $paramSpec["paramString"];
        $tmpNomorNota2Alias = formatNota("nomer_nolink", $tmpNomorNota2);
        //endregion

        //region dynamic counters #1
        echo "<script>top.writeProgress('sedang membuat penomoran');</script>";

        $cn = new CustomCounter("transaksi");
        $cn->setType("transaksi");
        $configCustomParams = $this->configValuesModul[$origJenis]["counters"];
        $configCustomParams[] = "stepCode";
        if (sizeof($configCustomParams) > 0) {
            $cContent = array();
            foreach ($configCustomParams as $i => $cRawParams) {
                $cParams = explode("|", $cRawParams);
                $cValues = array();
                foreach ($cParams as $param) {
                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                }
                $cRawValues = implode("|", $cValues[$i]);
                $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                switch ($paramSpec["id"]) {
                    case 0: //===counter type is new
                        $addData = array(
                            "toko_id" => $tokoID,
                            "toko_nama" => $tokoNama,
                        );
                        $paramKeyRaw = print_r($cParams, true);
                        $paramValuesRaw = print_r($cValues[$i], true);
                        $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                        break;
                    default: //===counter to be updated
                        $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                        break;
                }
                //echo "<hr>";
            }
        }
        $appliedCounters2 = base64_encode(serialize($cContent));
        $appliedCounters_inText2 = print_r($cContent, true);


        $masterReplacers = array(
            "nomer" => $tmpNomorNota2,
            "nomer2" => $tmpNomorNota2Alias,
            "counters" => $appliedCounters2,
            "counters_intext" => $appliedCounters_inText2,
        );
        foreach ($masterReplacers as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }

        $addValues = array(
            "counters" => $appliedCounters2,
            'counters_intext' => $appliedCounters_inText2,
            'nomer' => $tmpNomorNota2,
            'nomer2' => $tmpNomorNota2Alias,
            'dtime' => date("Y-m-d H:i:s"),
            'fulldate' => date("Y-m-d"),
        );
        foreach ($addValues as $key => $val) {
            $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
        }

        // </editor-fold>
        //endregion

        //region numbering tambahan
        $this->CI->load->library("CounterNumber");
        $ccn = new CounterNumber();
        $ccn->setCCode($this->cCode);
        $ccn->setJenisTr($this->jenisTr);
        $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
        $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
        $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
        $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
        $new_counter = $ccn->getCounterNumber();
        cekHitam("jenistr yang disett dari create " . $this->jenisTr);


        if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
            foreach ($new_counter["main"] as $ckey => $cval) {
                $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                $this->cCodeData[$cCode]["main"][$ckey] = $cval;
            }
        }
        if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
            foreach ($new_counter["items"] as $ikey => $iSpec) {
                foreach ($iSpec as $iikey => $iival) {
                    $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                }
            }
        }
        if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
            foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                foreach ($iSpec as $iikey => $iival) {
                    $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                }
            }
        }
        //endregion


        //region TRANSAKSIONAL
        if (sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
            $this->cCodeData[$cCode]["tableIn_master"]['status_4'] = 11;
            $this->cCodeData[$cCode]["tableIn_master"]['trash_4'] = 0;

            $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
            $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);

            $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
            $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
            if ($insertID < 1) {
                die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
            }


            if (isset($this->cCodeData[$cCode]["tableIn_master"]['ids_his'])) {
                $idHis_decode = blobDecode($this->cCodeData[$cCode]["tableIn_master"]['ids_his']);
                $idHis_decode[$stepNum] = array(
                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                    "step" => $stepNum,
                    "trID" => $insertID,
                    "nomer" => $tmpNomorNota2,
                    "counters" => $appliedCounters2,
                    // "counters_intext" => $appliedCounters_inText2,
                );

                $idHis_blob = blobEncode($idHis_decode);

                $this->cCodeData[$cCode]["tableIn_master"]['ids_his'] = $idHis_blob;

                $tr = new MdlTransaksi();
                $dup = $tr->updateData(array("id" => $insertID), array(
                    "ids_his" => $idHis_blob,
                    // "ids_his_intext" => $idHis_intext,

                )) or die("Failed to update tr next-state!");
                cekUngu($this->CI->db->last_query());
            }
            if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                $inserMainValues = array();

                foreach ($this->cCodeData[$cCode]['tableIn_master_values'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                    $inserMainValues[] = $dd;

                }
                if (sizeof($inserMainValues) > 0) {
                    $arrBlob = blobEncode($inserMainValues);
                    $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));

                }
            }
            if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                    $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));

                }
            }
            if (isset($this->cCodeData[$cCode]['main_add_fields']) && sizeof($this->cCodeData[$cCode]['main_add_fields']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_add_fields'] as $key => $val) {
                    $tr->writeMainFields($insertID, array("key" => $key, "value" => $val));
                }
            }

            if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                    $tr->writeMainElements($insertID, array(
                        "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                        "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                        "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                        "name" => $aSpec['name'],
                        "label" => $aSpec["label"],
                        "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                        // "contents_intext" => isset($aSpec['contents_intext']) ? print_r($aSpec['contents_intext'], true) : "",

                    ));
                }
            }
            else {
                //                cekMerah("TAK ada mainElements");
            }

            if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                            ));
                            $insertIDs[$pID][] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }

                    }
                }
                if (sizeof($insertIDs) > 0) {
                    $arrBlob = blobEncode($insertIDs);
                    $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detailValues2_sum'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                            $insertIDs[] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }
                    }


                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) > 0) {
                foreach ($this->cCodeData[$cCode]['tableIn_detail_rsltItems'] as $pID => $dSpec) {
                    if (isset($this->configValuesModul[$this->jenisTr]["tableIn"]['detail_rsltItems'])) {
                        foreach ($this->configValuesModul[$this->jenisTr]["tableIn"]['detail_rsltItems'] as $key => $src) {
                            $dd = $tr->writeDetailValues($insertID, array(
                                "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail_rsltItems'][$pID]['produk_jenis'],
                                "produk_id" => $pID,
                                "key" => $key,
                                "value" => $dSpec[$src],
                            ));
                            $insertIDs[$pID][] = $dd;
                            //$mongoList['detailValues'][] = $dd;
                        }
                    }


                }
            }


            //region update validQty pada step sebelumnya yang di-refer
            $seluruhnya = true;
            $prevTrID = 0;
            $arrvalidQtySisa = array();
            if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                $closedRequest = isset($this->configValuesModul[$origJenis]['closedRequest'][$stepNum]['enabled']) ? $this->configValuesModul[$origJenis]['closedRequest'][$stepNum]['enabled'] : false;
                $insertIDs = array();
                $insertDeIDs = array();
                foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $iID => $dSpec) {
                    $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                    if ($insertDetailID < 1) {
                        die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                    }
                    else {
                        $insertIDs[] = $insertDetailID;
                        $insertDeIDs[$insertID][] = $insertDetailID;
                        //$mongoList['detail'][] = $insertDetailID;

                    }

                    if ($epID != 999) {
                        $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                        if ($insertEpID < 1) {
                            die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                        }
                        else {
                            $insertIDs[] = $insertEpID;
                            $insertDeIDs[$epID][] = $insertEpID;
                            //$mongoList['detail'][] = $insertDetailID;
                        }
                    }
                    cekHitam("EXTRACTED ITEMS... [$iID]");
                    echo "<script>top.writeProgress('" . strtoupper($dSpec['produk_nama']) . "');</script>";


                    if (isset($this->cCodeData[$cCode]['extractedItems'])) {
                        if (array_key_exists($iID, $this->cCodeData[$cCode]['extractedItems'])) {
                            $itemFulfilledJml = 0;
                            foreach ($this->cCodeData[$cCode]['extractedItems'][$iID] as $triID => $triSpec) {
                                $prevTrID = $triSpec['transaksi_id'];
                                $tru = new MdlTransaksi();
                                $tru->setFilters(array());
                                $tru->setTableName($tru->getTableNames()['detail']);
                                //----------------------------------------------------------
                                if ($triSpec['valid_qty'] >= $dSpec['produk_ord_jml']) {
                                    $newValidQty = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                    //                                    cekmerah("validQty dikurangi oleh produk_ord_jml, yaitu " . $dSpec['produk_ord_jml']);
                                }
                                else {
                                    $newValidQty = ($triSpec['valid_qty'] - $triSpec['valid_qty']);
                                    //                                    cekmerah("validQty dikurangi oleh triSpec,  myaitu " . $triSpec['valid_qty']);
                                }
                                //----------------------------------------------------------
                                $newValidQtyNotApprove = 0;
                                if ($closedRequest == true) {
                                    cekPink2("closed Request enabled, request: " . $triSpec['valid_qty'] . ", approve: " . $dSpec['produk_ord_jml'] . ", newValidQty: " . $newValidQty);
                                    if ($triSpec['valid_qty'] >= $dSpec['produk_ord_jml']) {
                                        $newValidQty = 0;
                                        $newValidQtyNotApprove = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);

                                    }
                                    //                                    else{
                                    //                                        $newValidQty = 0;
                                    //                                        $newValidQtyNotApprove = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                    //                                    }
                                    cekPink2("new valid qty: $newValidQty, valid qty not approve: $newValidQtyNotApprove");
                                }
                                //----------------------------------------------------------


                                $itemFulfilledJml += $newValidQty;
                                //                                $newValidQty = ($triSpec['valid_qty'] - $dSpec['produk_ord_jml']);
                                $updateContents = array(
                                    "valid_qty" => $newValidQty,
                                );
                                if ($newValidQty < 1) {
                                    $childPrevRepaclers = array(
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                        "sub_tail_number" => $stepNum,
                                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                                    );
                                    foreach ($childPrevRepaclers as $key => $val) {
                                        $updateContents[$key] = $val;
                                    }
                                }
                                else {//==kalau ada yang tidak habis, berarti TIDAK seluruhnya yang dilanjutkan pada step berikutnya
                                    $seluruhnya = false;
                                    $arrvalidQtySisa[$iID] = $newValidQty;
                                }
                                $dupState = $tru->updateData(array(
                                    "produk_id" => $iID,
                                    "id" => $triID,
                                    "transaksi_id" => $triSpec['transaksi_id'],
                                ), $updateContents) or die("Failed to update previous detail entries!");
                                cekHijau($this->CI->db->last_query());

                                $mongUpdateList['update']['detail'][] = array(
                                    "where" => array(
                                        //                                        "transaksi_id" => $triSpec['transaksi_id'],
                                        "id" => "$triID",
                                        //                                        "produk_id" => $iID,
                                    ),
                                    "value" => $updateContents,
                                );
                                unset($tru);
                            }
                        }
                        //                        else{
                        //                            if($closedRequest == true){
                        //
                        //                            }
                        //                        }
                    }
                }

                if ($closedRequest == true) {
                    if (isset($this->cCodeData[$cCode]['extractedItems'])) {
                        foreach ($this->cCodeData[$cCode]['extractedItems'] as $iIDex => $exSpec) {
                            if (!array_key_exists($iIDex, $this->cCodeData[$cCode]["tableIn_detail"])) {
                                foreach ($exSpec as $trDataID => $trdSpec) {
                                    $tru = new MdlTransaksi();
                                    $tru->setFilters(array());
                                    $tru->setTableName($tru->getTableNames()['detail']);
                                    $updateContents = array(
                                        "valid_qty" => 0,
                                        "valid_qty_no_approve" => $trdSpec['qty'],
                                    );
                                    $childPrevRepaclers = array(
                                        "next_substep_code" => "",
                                        "next_substep_label" => "",
                                        "next_subgroup_code" => "",
                                        "sub_tail_number" => $stepNum,
                                        "sub_tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                                    );
                                    foreach ($childPrevRepaclers as $key => $val) {
                                        $updateContents[$key] = $val;
                                    }
                                    $dupState = $tru->updateData(array(
                                        "produk_id" => $iIDex,
                                        "id" => $trDataID,
                                        "transaksi_id" => $trdSpec['transaksi_id'],
                                    ), $updateContents) or die("Failed to update previous detail entries!");
                                    //                                    cekHijau($this->CI->db->last_query());
                                    $mongUpdateList['update']['detail'][] = array(
                                        "where" => array(
                                            //                                            "transaksi_id" => $trdSpec['transaksi_id'],
                                            "id" => "$trDataID",
                                            //                                            "produk_id" => $iIDex,
                                        ),
                                        "value" => $updateContents,
                                    );
                                    unset($tru);
                                }
                            }
                        }
                    }
                }
                if (sizeof($insertIDs) == 0) {
                    die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                }
                else {
                    $indexing_details = array();
                    foreach ($insertDeIDs as $key => $numb) {
                        $indexing_details[$key] = $numb;
                    }
                    foreach ($indexing_details as $k => $arrID) {
                        arrPrint($arrID);
                        $arrBlob = blobEncode($arrID);
                        $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                        cekOrange($this->CI->db->last_query());
                    }
                }

                //-------------
                $lastStepPartialApprove = isset($this->configUiModul[$this->jenisTr]['lastStepPartialApprove']) ? $this->configUiModul[$this->jenisTr]['lastStepPartialApprove'] : false;
                if ($lastStepPartialApprove == true) {
                    cekKuning(__LINE__ . " $lastStepPartialApprove :: $totalSteps");
                    if ($totalSteps == 2) {
                        if (sizeof($arrvalidQtySisa) > 0) {
                            cekPink("ada valid qty yang tersisa");
                            $tr = new MdlTransaksi();
                            $dupState = $tr->updateData(array("id" => $topID), $stepNowParameter) or die("Failed to update tr next-state!");
                            cekHitam(__LINE__ . " ## 2 step, dan step akhir partial, YESS...");
                            showLast_query("orange");
                        }
                    }
                }
            }
            else {
                die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
            }

            if ($seluruhnya) {
                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array("id" => $prevTrID), array(
                    "tail_number" => $stepNum,
                    "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                    "status_4" => $this->cCodeData[$cCode]["main"]['status_4'],
                    "trash_4" => $this->cCodeData[$cCode]["main"]['trash_4'],
                )) or die("Failed to update tr next-state!");
                cekHijau(":: UOPDATE transaksi dengan trID -> $prevTrID");
                $mongUpdateList['update']["main"][] = array(
                    "where" => array(
                        "id" => "$prevTrID",
                    ),
                    "value" => array(
                        "tail_number" => $stepNum,
                        "tail_code" => $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"],
                        "status_4" => $this->cCodeData[$cCode]["main"]['status_4'],
                        "trash_4" => $this->cCodeData[$cCode]["main"]['trash_4'],
                    ),
                );
                cekHijau($this->CI->db->last_query());
            }
            //endregion

            //region cloner items to item_child
            if (sizeof($additionalData) > 0) {
                echo "<script>top.writeProgress('CLONING ITEMS TO ITEM CHILD...','head');</script>";
                cekHitam("ini data");
                $dataMdl = $additionalData["mdlName"];
                $this->CI->load->model("Mdls/" . $dataMdl);
                $da = new $dataMdl();
                $arrColl = $da->getFields();
                $selectedCol = array();
                foreach ($arrColl as $colSpec) {
                    $selectedCol[] = $colSpec['kolom'];
                }

                if (isset($this->cCodeData[$cCode]['items_child']) && sizeof($this->cCodeData[$cCode]['items_child'])) {
                    $gateData = isset($this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['gate']) ? $this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['gate'] : "detail";

                    $arrBlacklist = array(
                        "jml", "max_jml", "qty",
                    );
                    if (isset($this->cCodeData[$cCode]["items2_sum"])) {
                        unset($this->cCodeData[$cCode]["items2_sum"]);
                        unset($this->cCodeData[$cCode]["items2"]);
                        unset($this->cCodeData[$cCode]["tableIn_detail_values2_sum"]);
                    }
                    foreach ($this->cCodeData[$cCode]['items_child'] as $mainProdsID => $defData) {
                        if ($gateData == "detail") {
                            $itemsMain = isset($this->cCodeData[$cCode]["items"][$mainProdsID]) ? $this->cCodeData[$cCode]["items"][$mainProdsID] : array();
                        }
                        else {
                            $forceMainToItems = isset($this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['changeToItems'][$gateData]) ? $this->configUiModul[$this->jenisTr]['shopingCartDetailFields'][$stepNum]['changeToItems'][$gateData] : array();
                            if (sizeof($forceMainToItems) > 0) {
                                foreach ($forceMainToItems as $key1 => $key2) {
                                    $keyForce = strlen($key2) > 2 ? $key2 : $key1;
                                    $itemsMain[$key1] = isset($this->cCodeData[$cCode]["main"][$keyForce]) ? $this->cCodeData[$cCode]["main"][$keyForce] : "";
                                }
                                $itemsMain["jml"] = "1";
                                $itemsMain["qty"] = "1";
                                $itemsMain["max_jml"] = "1";
                            }
                            else {
                                matiHEre("detil aset gagal di tulis!");
                            }

                        }

                        $arrChilds = array_diff_key($itemsMain, array_flip($arrBlacklist));

                        $arrNew = array();
                        if (sizeof($itemsMain) > 0) {
                            foreach ($defData as $inID => $detil_child) {
                                $paramDetil = array_replace($arrChilds, $detil_child);
                                if (array_key_exists("id", $paramDetil)) {
                                    $paramDetil["parent_id"] = $paramDetil["id"];
                                    if (!isset($paramDetil["folders"]) || $paramDetil["folders"] == 0) {
                                        $paramDetil["folders"] = $paramDetil["pihakMainId"];
                                        $paramDetil["keterangan"] = $paramDetil["pihakMainName"];
                                    }
                                    unset($paramDetil["id"]);
                                }
                                $tmpData = array();
                                foreach ($selectedCol as $i => $coloum) {
                                    if (isset($paramDetil[$coloum])) {
                                        $tmpData[$coloum] = $paramDetil[$coloum];
                                    }
                                }

                                if (isset($paramDetil["subtotal"])) {
                                    $paramDetil["subtotal"] = $paramDetil["jml"] * $paramDetil["harga"];
                                }

                                $insertDataID = $da->addData($tmpData, $da->getTableName()) or die(lgShowError("Gagal menulis pengajuan data", __FILE__));

                                $paramDetil["id"] = $insertDataID;
                                echo "<script>top.writeProgress('PENGAJUAN DATA (TRID:$insertDataID)');</script>";
                                $this->cCodeData[$cCode]["items2_sum"][$insertDataID] = $paramDetil;
                                $this->cCodeData[$cCode]["items2"][$mainProdsID][$insertDataID] = $paramDetil;
                            }
                        }
                    }
                }
            }

            //endregion

            //region updater price
            if ($additionalDataPriceConf) {
                if (isset($this->cCodeData[$cCode]['itemPrice']) && sizeof($this->cCodeData[$cCode]['itemPrice']) > 0) {
                    $dComsName = isset($this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['DComs']) ? $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['DComs'] : "";
                    $replacerFields = isset($this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['fieldReplacer']) ? $this->configUiModul[$this->jenisTr]["itemPrice"][$stepNum]['fieldReplacer'] : array();

                    if (sizeof($replacerFields) > 0) {
                        foreach ($this->cCodeData[$cCode]['itemPrice'] as $Cid => $cData) {
                            foreach ($cData as $pID => $tmpField) {
                                foreach ($tmpField as $field => $value) {
                                    if (isset($replacerFields[$field])) {
                                        $source = $replacerFields[$field];
                                        $valReplacer = $this->cCodeData[$cCode]["items"][$pID][$source];
//                                        cekLime("replace $field $value => $valReplacer");
                                        $this->cCodeData[$cCode]['itemPrice'][$Cid][$pID][$field] = $valReplacer;
                                    }
                                }

                                //arrPrint($tmpField);
                            }
                        }
                    }

                    $this->CI->load->model("DComs/" . $dComsName);
                    echo "sub-postProcessor: $dComsName, sending values <br>";
                    $d = new $dComsName();

                    $d->pair($this->cCodeData[$cCode]['itemPrice']) or die("Tidak berhasil memasang  values pada dcoms-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $d->exec() or die("Gagal saat berusaha  exec values pada DComs: $dComsName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
            }

            //endregion


            if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $iID => $dSpec) {
                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $dd;

                    if ($epID != 999) {
                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                        $insertIDs[] = $dd;

                    }
                }
            }
            if (isset($this->cCodeData[$cCode]['tableIn_detail2']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2']) > 0) {
                $insertIDs = array();
                foreach ($this->cCodeData[$cCode]['tableIn_detail2'] as $iID => $dSpec) {
                    $dd = $tr->writeDetailEntries($insertID, $dSpec);
                    $insertIDs[] = $dd;

                    if ($epID != 999) {
                        $dd = $tr->writeDetailEntries($epID, $dSpec);
                        $insertIDs[] = $dd;

                    }

                }
            }


            if (isset($this->configUiModul[$this->jenisTr]['updateDueDate'][$stepNum])) {
                $dueDateConf = $this->configUiModul[$this->jenisTr]['updateDueDate'][$stepNum];
                $sourceDue = $dueDateConf['source'];
                $targetDue = $dueDateConf["target"];
                $datenow = date("Y-m-d");
                foreach ($sourceDue as $key => $val) {
                    $indexVal = isset($this->cCodeData[$cCode]['main_elements'][$key][$val]) ? $this->cCodeData[$cCode]['main_elements'][$key][$val] : 14;
                    $dueDate = dueDate($datenow, $indexVal);
                }
                $fieldDue = $tr->getFields()["dueDate"];
                $dataDue = array();
                foreach ($fieldDue as $kol) {
                    if (isset($this->cCodeData[$cCode]["tableIn_master"][$kol])) {
                        $dataDue[$kol] = $this->cCodeData[$cCode]["tableIn_master"][$kol];
                    }
                }
                $dataDue['due_date'] = $dueDate;
                $validateDue = validateDueDate($this->cCodeData[$cCode]["main"]['customerID'], $this->cCodeData[$cCode]["main"]['dtime']);


                if ($validateDue['allow_create'] == "true") {
                    if (isset($this->cCodeData[$cCode]["main"]['piutang_dagang']) && $this->cCodeData[$cCode]["main"]['piutang_dagang'] > 0) {

                        $tr->writeDueDate($insertID, $dataDue);

                    }
                }
                else {
                    $allowedOver = validateOverDue($this->cCodeData[$cCode]["main"]['customerID']);
                    if ($allowedOver['status'] == "allowed") {

                    }
                    else {
                        //                        matiHere($validateDue['error']);//matiin transaksi sudah over due
                    }
                    //                    arrPrint()
                    //                    matiHere($validateDue['error']);//matiin transaksi sudah over due
                }

                //update main elementnya
                foreach ($targetDue as $keyTarget => $valTarget) {
                    cekHItam($keyTarget . "[$valTarget] => " . $dueDate);
                    $this->cCodeData[$cCode]['main_elements'][$keyTarget][$valTarget] = $dueDate;
                    $this->cCodeData[$cCode]["main"]['dueDate'] = $dueDate;
                }
            }


            //------------
            if (isset($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget]) && sizeof($this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget])) {
                $coreBuilder = $this->configValuesModul[$this->jenisTr]['coreBuilder'][$jenisTrTarget];
            }
            else {
                $coreBuilder = array();
            }
            //------------

            $baseRegistries = array(
                "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                'items_noapprove' => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),

                'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),

                "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                "receiptDetailFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields'][$stepNum] : array(),
                "receiptSumFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields'][$stepNum] : array(),
                "receiptDetailFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailFields2'][$stepNum] : array(),
                "receiptSumFields2" => isset($this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptSumFields2'][$stepNum] : array(),
                "receiptDetailSrcFields" => isset($this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][$stepNum]) ? $this->configLayoutModul[$this->jenisTr]['receiptDetailSrcFields'][$stepNum] : array(),
                "jurnal_index" => isset($core['components']) ? $core['components'] : array(),
                "preProcessor" => isset($core['preProcessor'][$jenisTrTarget]) ? $core['preProcessor'][$jenisTrTarget] : array(),
                "postProcessor" => isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget] : array(),
                "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                "requiredParam" => (isset($coreRequiredParam[$this->jenisTr]) && sizeof($coreRequiredParam[$this->jenisTr]) > 0) ? $coreRequiredParam[$this->jenisTr] : array(),
                "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                //-----
                "coreBuilder" => $coreBuilder,
                'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                //-----
            );

            $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
            $mongRegID = $doWriteReg;
            echo "<script>top.writeProgress('MENULIS KE-REGISTRY....');</script>";
        }
        else {
            die(lgShowAlert("Transaksi gagal disimpan, silahkan cek kembali transaksi ini."));
        }
        //endregion

        // region POST-PROCESSOR

        //region processing sub-post-processors, always
        $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['detail'] : array();
        if (sizeof($iterator) > 0) {
            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "sub-postProcessor: $comName, initializing values <br>";
                echo "<script>top.writeProgress('MENYIAPKAN DATA SUB-PROCESSORS UNTUK DIKIRIM...', 'head');</script>";

                $tmpOutParams[$cCtr] = array();
                foreach ($this->cCodeData[$cCode][$srcGateName] as $cnt => $dSpec) {
                    $subParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                            $subParams['loop'][$key] = $realValue;
                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cnt], $this->cCodeData[$cCode][$srcGateName][$cnt], 0);
                            $subParams['static'][$key] = $realValue;
                            cekBiru("$key diisi dengan $realValue");
                        }

                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                cekorange(":: $k diisikan dengan " . $subParams['static'][$k]);
                            }
                        }

                        $subParams['static']["fulldate"] = date("Y-m-d");
                        $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }

                    if (sizeof($subParams) > 0) {
                        $tmpOutParams[$cCtr][] = $subParams;
                    }
                }
            }

            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "sub-postProcessor: $comName, sending values <br>";

                $mdlName = "Com" . ucfirst($comName);
                $this->CI->load->model("Coms/" . $mdlName);
                $m = new $mdlName();

                $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                showLast_query("lime");
            }
        }


        //</editor-fold>
        //endregion

        //region processing main-post-processors, always
        $iterator = isset($this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master']) ? $this->configValuesModul[$this->jenisTr]['postProcessor'][$jenisTrTarget]['master'] : array();
        if (sizeof($iterator) > 0) {
            echo "<script>top.writeProgress('MEMPROSES MAIN-PROCESSORS...', 'head');</script>";
            foreach ($iterator as $cCtr => $tComSpec) {
                $comName = $tComSpec['comName'];
                $srcGateName = $tComSpec['srcGateName'];
                $srcRawGateName = $tComSpec['srcRawGateName'];
                echo "post-processor: $comName<br>";

                $dSpec = $this->cCodeData[$cCode][$srcGateName];
                $tmpOutParams = array();
                if (isset($tComSpec['loop'])) {
                    foreach ($tComSpec['loop'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                        $tmpOutParams['loop'][$key] = $realValue;

                    }
                }
                if (isset($tComSpec['static'])) {
                    //cekHere("DISINI OIII");
                    foreach ($tComSpec['static'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                        $tmpOutParams['static'][$key] = $realValue;

                    }
                    if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                        foreach ($paramPatchers[$comName] as $k => $v) {
                            if (!isset($tmpOutParams['static'][$k])) {
                                $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                    }
                    if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                        $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                        foreach ($paramForceFillers[$comName] as $k => $v) {
                            $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
                        }
                    }
                    $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                    $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                    $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                }
                if (isset($tComSpec['static2'])) {
                    //cekHere("DISINI OIII");
                    foreach ($tComSpec['static2'] as $key => $value) {

                        $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$cCtr], $this->cCodeData[$cCode][$srcGateName][$cCtr], 0);
                        $tmpOutParams['static2'][$key] = $realValue;

                    }
                    if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                        foreach ($paramPatchers[$comName] as $k => $v) {
                            if (!isset($subParams['static'][$k])) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                    }
                    if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                        $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                        foreach ($paramForceFillers[$comName] as $k => $v) {
                            $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                        }
                    }
                    $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                    $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                    $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                }


                $mdlName = "Com" . ucfirst($comName);
                $this->CI->load->model("Coms/" . $mdlName);
                $m = new $mdlName();

                $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                $m->exec() or die("Gagal saat berusaha  exec values pada post-processor: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
            }
        }
        //endregion

        // endregion


        // COMPONENT
        if ($runCoreAkunting == true) {
            //region ----------subcomponents GESER KE CLI
            $iterator = isset($core['components']['detail']) ? $core['components']['detail'] : array();
            $componentConfig['detail'] = $iterator;
            if (sizeof($iterator) > 0) {
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                $filterNeeded = false;
                if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                    $filterNeeded = true;
                }
                foreach ($iterator as $cCtr => $tComSpec) {
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];

                    echo "sub-component: $comName, $srcGateName, initializing values <br>";
                    $tmpOutParams[$cCtr] = array();
                    foreach ($this->cCodeData[$cCode][$srcGateName] as $id => $dSpec) {
                        $comName = $tComSpec['comName'];
                        if (substr($comName, 0, 1) == "{") {
                            $comName = trim($comName, "{");
                            $comName = trim($comName, "}");
                            $comName = str_replace($comName, $this->cCodeData[$cCode][$srcGateName][$id][$comName], $comName);
                            $tComSpec['comName'] = $comName;
                            $iterator[$cCtr]['comName'] = $comName;
                        }

                        $filterNeeded = false;
                        $mdlName = "Com" . ucfirst($comName);
                        if (in_array($mdlName, $compValidators)) {//perlu validasi filter
                            $filterNeeded = true;
                        }


                        $subParams = array();
                        if (isset($tComSpec['loop'])) {
                            foreach ($tComSpec['loop'] as $key => $value) {
                                if (substr($key, 0, 1) == "{") {
                                    $key = trim($key, "{");
                                    $key = trim($key, "}");
                                    $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$id][$key], $key);
                                }
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['loop'][$key] = $realValue;
                                cekKuning("LOOP: $key diisi dengan $realValue");

                                if ($filterNeeded) {
                                    if ($subParams['loop'][$key] == 0) {
                                        unset($subParams['loop'][$key]);
                                    }
                                }
                            }
                        }
                        if (isset($tComSpec['static'])) {
                            foreach ($tComSpec['static'] as $key => $value) {
                                $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName][$id], $this->cCodeData[$cCode][$srcGateName][$id], 0);
                                $subParams['static'][$key] = $realValue;
//                                cekKuning("STATIC: $key diisi dengan $realValue");
                            }
                            if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                                foreach ($paramPatchers[$comName] as $k => $v) {
                                    if (!isset($subParams['static'][$k])) {
                                        $subParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                        cekOrange("fill :: $comName :: $k => " . $subParams['static'][$k]);
                                    }
                                }
                            }
                            if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                                //                            cekOrange("comName:: $comName");
                                $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                                foreach ($paramForceFillers[$comName] as $k => $v) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                    cekOrange("fillforce :: $comName :: $k => " . $subParams['static'][$k]);
                                }
                            }
                            $subParams['static']["fulldate"] = date("Y-m-d");
                            $subParams['static']["dtime"] = date("Y-m-d H:i:s");
                            $subParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                        }
//                        cekHitam("cetak subParams");
//                        arrPrint($subParams);
                        if (sizeof($subParams) > 0) {
                            if ($filterNeeded) {
                                if (isset($subParams['loop']) && sizeof($subParams['loop']) > 0) {
                                    $tmpOutParams[$cCtr][] = $subParams;
                                }
                            }
                            else {
                                $tmpOutParams[$cCtr][] = $subParams;
                            }
                        }
                    }
                    $componentGate['detail'][$cCtr] = $subParams;
                }


                $it = 0;
                foreach ($iterator as $cCtr => $tComSpec) {
                    $it++;
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];

                    echo "sub component #$it: $comName, sending values <br>";

                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();


                    if (sizeof($tmpOutParams[$cCtr]) > 0) {
                        $tobeExecuted = true;
                    }
                    else {
                        $tobeExecuted = false;
                    }


                    if ($tobeExecuted) {
                        //----- kiriman gerbang
                        if (method_exists($m, "setTableInMaster")) {
                            $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                        }
                        if (method_exists($m, "setDetail")) {
                            $m->setDetail($this->cCodeData[$cCode][$srcGateName]);
                        }
                        if (method_exists($m, "setJenisTr")) {
                            $m->setJenisTr($this->jenisTr);
                        }
                        //----- kiriman gerbang
                        $m->pair($tmpOutParams[$cCtr]) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        showLast_query("lime");
                    }
                    else {
                        cekBiru("sub-komponem $comName tidak memenuhi syarat untuk ditulis");
                    }
                }
            }
            else {
                //cekKuning("subcomponents is not set");
            }

            //endregion

            //region ----------components
            $componentGate['master'] = array();
            $componentConfig['master'] = array();
            if (isset($core['relativeComponets']) && $core['relativeComponets'] == true) {
                $iterator = isset($this->cCodeData[$cCode]['revert']['jurnal'][$stepNum]['master']) ? $this->cCodeData[$cCode]['revert']['jurnal'][$stepNum]['master'] : array();
            }
            else {
                if (isset($this->cCodeData[$cCode]['componentsBuilder'][$stepNum]['master'])) {
                    $iterator = $this->cCodeData[$cCode]['componentsBuilder'][$stepNum]['master'];
                }
                elseif (isset($core['components']['master'])) {
                    $iterator = $core['components']['master'];
                }
                else {
                    $iterator = array();
                }
            }

            if (sizeof($iterator) > 0) {
                echo "<script>top.writeProgress('KOMPONEN...', 'head');</script>";
                $componentConfig['master'] = $iterator;

                $it = 0;
                //==filter nilai, jika NOL tidak dikirim, sesuai config==
                $compValidators = ($this->CI->config->item('transaksi_value_required_components') != null) ? $this->CI->config->item('transaksi_value_required_components') : array();
                foreach ($iterator as $cCtr => $tComSpec) {
                    $it++;
                    $comName = $tComSpec['comName'];
                    $srcGateName = $tComSpec['srcGateName'];
                    $srcRawGateName = $tComSpec['srcRawGateName'];
                    echo "component #$it: $comName :: $srcGateName <br>";

                    $dSpec = $this->cCodeData[$cCode][$srcGateName];
                    $tmpOutParams = array();
                    if (isset($tComSpec['loop'])) {
                        foreach ($tComSpec['loop'] as $key => $value) {
                            if (substr($key, 0, 1) == "{") {
                                $key = trim($key, "{");
                                $key = trim($key, "}");
                                $key = str_replace($key, $this->cCodeData[$cCode][$srcGateName][$key], $key);
                            }
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            if ($key != null) {
                                $tmpOutParams['loop'][$key] = $realValue;
                            }
                        }
                    }
                    if (isset($tComSpec['static'])) {
                        foreach ($tComSpec['static'] as $key => $value) {
                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static'][$key] = $realValue;
//                            cekHijau(":: NORMAL :: $key => $realValue ::");
                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
//                            cekHijau(":: masuk ke PATCHER ::");
                            foreach ($paramPatchers[$comName] as $k => $v) {
//                                cekHijau(":: ada yang mau di-PATCHER ::");
//                                arrPrint($tmpOutParams['static']);
                                if (!isset($tmpOutParams['static'][$k])) {
                                    $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                    cekHijau(":: PATCHER :: $key => $realValue ::");
                                }

                            }
                        }
                        else {
                            cekMerah(":: TIDAK TERMASUK PATCHER ::");
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $tmpOutParams['static'][$k] = isset($$v) ? $$v : "_v";
//                                cekHijau(":: FORCEFILL :: $key => $realValue ::");
                            }
                        }
                        $tmpOutParams['static']["urut"] = $cCtr;
                        $tmpOutParams['static']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();
                    }
                    if (isset($tComSpec['static2'])) {
                        foreach ($tComSpec['static2'] as $key => $value) {

                            $realValue = makeValue($value, $this->cCodeData[$cCode][$srcGateName], $this->cCodeData[$cCode][$srcGateName], 0);
                            $tmpOutParams['static2'][$key] = $realValue;

                        }
                        if (isset($paramPatchers[$comName]) && sizeof($paramPatchers[$comName]) > 0) {
                            foreach ($paramPatchers[$comName] as $k => $v) {
                                if (!isset($subParams['static'][$k])) {
                                    $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                                }
                            }
                        }
                        if (isset($paramForceFillers[$comName]) && sizeof($paramForceFillers[$comName]) > 0) {
                            $jenis = $this->cCodeData[$cCode]["main"]['jenis'];
                            foreach ($paramForceFillers[$comName] as $k => $v) {
                                $subParams['static'][$k] = isset($$v) ? $$v : "_v";
                            }
                        }
                        $tmpOutParams['static2']["fulldate"] = date("Y-m-d");
                        $tmpOutParams['static2']["dtime"] = date("Y-m-d H:i:s");
                        $tmpOutParams['static2']["keterangan"] = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["label"] . " nomor " . $tmpNomorNota . " oleh " . my_name();


                    }

                    //lgShowError("Ada kesalahan",);
                    $mdlName = "Com" . ucfirst($comName);
                    $this->CI->load->model("Coms/" . $mdlName);
                    $m = new $mdlName();

                    //===filter value nol, jika harus difilter
                    $tobeExecuted = true;

                    if (in_array($mdlName, $compValidators)) {

                        $loopParams = isset($tmpOutParams['loop']) ? $tmpOutParams['loop'] : array();
                        if (sizeof($loopParams) > 0) {
                            foreach ($loopParams as $key => $val) {
                                cekmerah("$comName : $key = $val ");
                                if ($val == 0) {
                                    unset($tmpOutParams['loop'][$key]);
                                }
                            }
                        }
                        if (sizeof($tmpOutParams['loop']) < 1) {
                            $tobeExecuted = false;
                        }

                    }


                    if ($tobeExecuted) {
//                        cekBiru("kiriman komponen $comName");
//                        arrPrint($tmpOutParams);
                        //----- kiriman gerbang untuk counter mutasi rekening
                        if (method_exists($m, "setTableInMaster")) {
                            $m->setTableInMaster($this->cCodeData[$cCode]["tableIn_master"]);
                        }
                        if (method_exists($m, "setMain")) {
                            $m->setMain($this->cCodeData[$cCode]["main"]);
                        }
                        if (method_exists($m, "setJenisTr")) {
                            $m->setJenisTr($this->jenisTr);
                        }
                        //----- kiriman gerbang untuk counter mutasi rekening
                        $m->pair($tmpOutParams) or die("Tidak berhasil memasang  values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                        $m->exec() or die("Gagal saat berusaha  exec values pada komponen: $comName/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    }
                    else {
                        cekBiru("komponem $comName tidak memenuhi syarat untuk ditulis");
                    }

                    $componentGate['master'][$cCtr] = $tmpOutParams;
                }
            }
            else {
                //cekKuning("components is not set");
            }

            //endregion
        }


        //region nulis paymentSource
        $stepCode = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"];
        $paymentSources = $this->CI->config->item("payment_source");
        if (array_key_exists($stepCode, $paymentSources)) {
            $payConfigs = isset($paymentSources[$stepCode][$stepNum]) ? $paymentSources[$stepCode][$stepNum] : array();
            if (sizeof($payConfigs) > 0) {

                foreach ($payConfigs as $paymentSrcConfig) {
                    $valueSrc = $paymentSrcConfig['valueSrc'];
                    $externSrc = $paymentSrcConfig['externSrc'];
                    if (isset($paymentSrcConfig['model'])) {
                        $mdlName = $paymentSrcConfig['model'];
                        $this->CI->load->model("Mdls/$mdlName");
                        $pMdl = New $mdlName();
                        $pTmpMdl = $pMdl->lookupAll()->result();
                        $pTmpMdlResult = array();
                        if (sizeof($pTmpMdl) > 0) {
                            foreach ($pTmpMdl as $pTmpMdlSpec) {
                                $pTmpMdlResult[$pTmpMdlSpec->id] = $pTmpMdlSpec;
                            }
                        }
                    }
                    else {
                        $pTmpMdlResult = array();
                    }

                    if (isset($this->cCodeData[$cCode]["main"][$valueSrc]) && $this->cCodeData[$cCode]["main"][$valueSrc] > 0) {
                        if (isset($externSrc['extern_label2'])) {
                            //cek ada isinya atau kosong
                            $cek = strlen($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']]) > 4 ? "" : matiHere("jenis biaya tidak dikenali " . __LINE__);//
                        }
                        $arrPymSrc = array(
                            "jenis" => $stepCode,
                            "target_jenis" => $paymentSrcConfig['jenisTarget'],
                            "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                            "extern_id" => isset($this->cCodeData[$cCode]["main"][$externSrc["id"]]) ? $this->cCodeData[$cCode]["main"][$externSrc["id"]] : "",
                            "extern_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['nama']]) ? $this->cCodeData[$cCode]["main"][$externSrc['nama']] : "",
                            "nomer" => $tmpNomorNota2,
                            "label" => $paymentSrcConfig["label"],
                            "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "terbayar" => 0,
                            "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                            "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                            "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                            "oleh_id" => my_id(),
                            "oleh_nama" => my_name(),
                            "toko_id" => my_toko_id(),
                            "toko_nama" => my_toko_nama(),
                            "dtime" => date("Y-m-d H:i:s"),
                            "fulldate" => date("Y-m-d"),
                            "valas_id" => isset($externSrc['valasId']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                            "valas_nama" => isset($externSrc['valasLabel']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                            "valas_nilai" => isset($externSrc['valasValue']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                            "tagihan_valas" => isset($externSrc['valasTagihan']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                            "terbayar_valas" => 0,
                            "sisa_valas" => isset($externSrc['valasSisa']) && isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                            //                            "extern_label2" => isset($this->cCodeData[$cCode]["main"]['pihakMainName']) ? $this->cCodeData[$cCode]["main"]['pihakMainName'] : "",
                            "extern_label2" => (isset($externSrc['extern_label2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_label2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_label2']] : "",

                            "ppn" => (isset($externSrc['ppn']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn']] : "",
                            "ppn_approved" => (isset($externSrc['ppn_approved']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn_approved']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn_approved']] : 0,
                            "ppn_sisa" => (isset($externSrc['ppn']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn']] : "",
                            "ppn_status" => (isset($externSrc['ppn_status'])) ? $externSrc['ppn_status'] : 0,
                            "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : 0,
                            "extern_date2" => (isset($externSrc['extern_date2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_date2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_date2']] : "",
                            "pph_23" => (isset($externSrc['pph_23']) && ($this->cCodeData[$cCode]["main"][$externSrc['pph_23']])) ? $this->cCodeData[$cCode]["main"][$externSrc['pph_23']] : "",

                            "npwp" => (isset($externSrc['npwp']) && ($this->cCodeData[$cCode]["main"][$externSrc['npwp']])) ? $this->cCodeData[$cCode]["main"][$externSrc['npwp']] : "",
                            "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                            "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                            "ppn_pph_faktor" => (isset($externSrc['ppn_pph_faktor']) && ($this->cCodeData[$cCode]["main"][$externSrc['ppn_pph_faktor']])) ? $this->cCodeData[$cCode]["main"][$externSrc['ppn_pph_faktor']] : "",
                            "extern_jenis" => (isset($externSrc['extern_jenis']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_jenis']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_jenis']] : "",
                            "extern_nilai3" => (isset($externSrc['extern_nilai3']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai3']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai3']] : "",
                            "extern_nilai4" => (isset($externSrc['extern_nilai4']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai4']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai4']] : "",
                            "extern_nilai5" => (isset($externSrc['extern_nilai5']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai5']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai5']] : "",
                            "npwp" => (isset($externSrc['npwp']) && ($this->cCodeData[$cCode]["main"][$externSrc['npwp']])) ? $this->cCodeData[$cCode]["main"][$externSrc['npwp']] : "",
                            //                            "extern_nilai2" => (isset($externSrc['extern_nilai2']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern_nilai2']] : "",
                            "payment_locked" => (isset($externSrc['payment_locked']) && ($this->cCodeData[$cCode]["main"][$externSrc['payment_locked']])) ? $this->cCodeData[$cCode]["main"][$externSrc['payment_locked']] : 0,
                            "cash_account" => (isset($externSrc['cash_account']) && ($this->cCodeData[$cCode]["main"][$externSrc['cash_account']])) ? $this->cCodeData[$cCode]["main"][$externSrc['cash_account']] : 0,
                            "cash_account_nama" => (isset($externSrc['cash_account_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['cash_account_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['cash_account_nama']] : 0,
                            "seller_id" => (isset($externSrc['seller_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_id']] : "",
                            "seller_nama" => (isset($externSrc['seller_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['seller_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['seller_nama']] : "",
                            "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                            "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",

                        );
                        $tr->writePaymentSrc($insertID, $arrPymSrc);

                    }


                    cekMerah($this->CI->db->last_query());
                }
            }

        }
        else {
            cekMerah("TIDAK nulis paymentSrc");
        }

        // matiHere("hoopppp");
        //cek additional step
        $addPaymentSource = isset($this->configUiModul[$this->jenisTr]["steps"][$stepNum]['additionalStep']['shippingService']) ? $this->configUiModul[$this->jenisTr]["steps"][$stepNum]['additionalStep']['shippingService'] : array();
        //        arrPrint($addPaymentSource);
        //endregion

        //region nulis paymentAntiSource
        $stepCode = $this->configUiModul[$this->jenisTr]["steps"][$stepNum]["target"];
        $paymentSources = $this->CI->config->item("payment_antiSource");
        if (array_key_exists($stepCode, $paymentSources)) {
            cekMerah(":: starting PAYMENT ANTI SOURCE");
            $payConfigs = $paymentSources[$stepCode];
            if (sizeof($payConfigs) > 0) {
                foreach ($payConfigs as $paymentSrcConfig) {
                    //					$paymentSrcConfig = $paymentSources[$stepCode];
                    $valueSrc = $paymentSrcConfig['valueSrc'];
                    $externSrc = $paymentSrcConfig['externSrc'];
                    $tr->writePaymentAntiSrc($insertID, array(
                        "jenis" => $stepCode,
                        "target_jenis" => $paymentSrcConfig['jenisTarget'],
                        "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                        "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                        "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                        "nomer" => $tmpNomorNota2,
                        "label" => $paymentSrcConfig["label"],
                        "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                        "terbayar" => 0,
                        "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                        "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                        "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                        "oleh_id" => my_id(),
                        "oleh_nama" => my_name(),
                        "toko_id" => my_toko_id(),
                        "toko_nama" => my_toko_nama(),
                        "dtime" => date("Y-m-d H:i:s"),
                        "fulldate" => date("Y-m-d"),
                        "extern2_id" => (isset($externSrc['extern2_id']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_id']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_id']] : "",
                        "extern2_nama" => (isset($externSrc['extern2_nama']) && ($this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']])) ? $this->cCodeData[$cCode]["main"][$externSrc['extern2_nama']] : "",
                    ));
                    cekMerah($this->CI->db->last_query());
                }
            }

        }
        else {
            //cekMerah("TIDAK nulis paymentSrc");
        }
        //endregion


        validateBalancesComparison("", $componentConfig);
        validateAllBalances($tokoID);

        $outResultLib = array(
            "sessionData" => $this->cCodeData[$cCode],
            "tmpNomerNota" => $tmpNomorNota,
            "transaksiId" => $insertID,
        );


        //region connecting antar cabang
        $steps = isset($this->configUiModul[$origJenis]["steps"]) ? $this->configUiModul[$origJenis]["steps"] : array();
        $connector = isset($this->configUiModul[$origJenis]['connectTo']) ? $this->configUiModul[$origJenis]['connectTo'] : "";
        $preReplacer = isset($this->configUiModul[$this->jenisTr]['replacerConnectTo']) ? $this->configUiModul[$this->jenisTr]['replacerConnectTo'] : array();
        $validateValueConnector = isset($this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum]) ? $this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum] : array();


        if (strlen($connector) > 0) {
            cekMerah("to be connected to $connector |$stepNum|" . sizeof($steps));

            if (isset($this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum])) {
                $validateValueConnector = $this->configUiModul[$this->jenisTr]['connectoValidate'][$stepNum];
                $preVal = $this->cCodeData[$cCode]["main"][$validateValueConnector];
                $stepNum = $preVal > 0 ? $stepNum : "1000";//1000 untuk nglewatin step biar gak jalan connectingnya karena nilai yang dicari 0 kasusnya cash in advance ppn sudah masuk pusat tidak perlu diterbitkan auto dorong ppn ke pusat
            }

            if ($stepNum == sizeof($steps)) {
                cekMerah("NOW CONNECTING to $connector");
                //----------------
                $configUiMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiUi");
                $configCoreMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiCore");
                $configLayoutMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiLayout");
                $configValuesMasterModulJenis = loadConfigModulJenis_he_misc($connector, "coTransaksiValues");

                if (sizeof($configUiMasterModulJenis) == 0) {
                    die("kode connector tidak dikenali!");
                }
                if (sizeof($configUiMasterModulJenis["steps"]) < 2) {
                    die("konfigurasi connector harus memiliki step lebih dari satu!");
                }


                $oldCode = $cCode;
                $cCode = "_TR_" . $connector;

                $this->cCodeData[$cCode] = array();
                $this->cCodeData[$cCode] = array(
                    "main" => $this->cCodeData[$oldCode]["main"],
                    "items" => $this->cCodeData[$oldCode]["items"],
                    "items2" => $this->cCodeData[$oldCode]["items2"],
                    "items2_sum" => $this->cCodeData[$oldCode]["items2_sum"],
                    "items3" => $this->cCodeData[$oldCode]["items3"],
                    "items3_sum" => $this->cCodeData[$oldCode]["items3_sum"],
                    "items4_sum" => $this->cCodeData[$oldCode]["items4_sum"],
                    "items_noapprove" => $this->cCodeData[$oldCode]['items_noapprove'],

                    "tableIn_master" => $this->cCodeData[$oldCode]["tableIn_master"],
                    "tableIn_detail" => $this->cCodeData[$oldCode]["tableIn_detail"],

                    "rsltItems" => $this->cCodeData[$oldCode]['rsltItems'],
                    "tableIn_detail_rsltItems" => $this->cCodeData[$oldCode]['tableIn_detail_rsltItems'],

                    "tableIn_master_values" => $this->cCodeData[$oldCode]['tableIn_master_values'],
                    "tableIn_detail_values" => $this->cCodeData[$oldCode]['tableIn_detail_values'],
                    "tableIn_detail_values_rsltItems" => $this->cCodeData[$oldCode]['tableIn_detail_values_rsltItems'],
                );

                //==replace pertama
                $masterReplacersO = array(
                    "jenisTr" => $connector,
                    "jenisTrMaster" => $connector,
                    "jenisTrTop" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis_label" => $configUiMasterModulJenis["steps"][1]["label"],
                    "transaksi_jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "stepCode" => $configUiMasterModulJenis["steps"][1]["target"],
                    "placeID" => isset($preReplacer['place2ID']) ? $preReplacer['place2ID'] : $this->cCodeData[$cCode]["main"]['place2ID'],
                    "placeName" => isset($preReplacer['place2Name']) ? $preReplacer['place2Name'] : $this->cCodeData[$cCode]["main"]['place2Name'],
                    "place2ID" => $this->cCodeData[$cCode]["main"]['placeID'],
                    "place2Name" => $this->cCodeData[$cCode]["main"]['placeName'],
                    "cabangID" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$cCode]["main"]['place2ID'],
                    "cabangName" => isset($preReplacer['place2Name']) ? $preReplacer['place2Name'] : $this->cCodeData[$cCode]["main"]['place2Name'],
                    "cabang2ID" => $this->cCodeData[$cCode]["main"]['placeID'],
                    "cabang2Name" => $this->cCodeData[$cCode]["main"]['placeName'],
                    //
                    "gudang2ID" => $this->cCodeData[$cCode]["main"]['gudangID'],
                    "gudang2Name" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "gudangID" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData[$cCode]["main"]['gudang2ID'],
                    "gudangName" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$cCode]["main"]['gudang2Name'],
                    "pihakID" => isset($this->cCodeData[$cCode]["main"]['placeID']) ? $this->cCodeData[$cCode]["main"]['placeID'] : "",
                    "pihakName" => isset($this->cCodeData[$cCode]["main"]['placeName']) ? $this->cCodeData[$cCode]["main"]['placeName'] : "",
                    "pihakName2" => $this->cCodeData[$cCode]["main"]['placeName'],
                    "gudang" => $this->cCodeData[$cCode]["main"]['gudangID'],
                    "gudang__name" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "gudang__label" => $this->cCodeData[$cCode]["main"]['gudangName'],
                    "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData[$cCode]["main"]['nomer'] : "",

                );
                foreach ($masterReplacersO as $key => $val) {
                    $this->cCodeData[$cCode]["main"][$key] = $val;
                    //                    $this->cCodeData[$cCode]["main"][$key] = $val;
                }
                $masterReplacers = array(
                    //                    "referensi_id" => $masterID, (dimatikan)
                    "inv" => $tmpNomorNota,
                    "jenis_master" => $connector,
                    "jenis_top" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "jenis_label" => $configUiMasterModulJenis["steps"][1]["label"],
                    "transaksi_jenis" => $configUiMasterModulJenis["steps"][1]["target"],
                    "cabang_id" => isset($preReplacer['cabang2ID']) ? $preReplacer['cabang2ID'] : $this->cCodeData[$cCode]["tableIn_master"]['cabang2_id'],
                    "cabang_nama" => isset($preReplacer['cabang2Name']) ? $preReplacer['cabang2Name'] : $this->cCodeData[$cCode]["tableIn_master"]['cabang2_nama'],
                    "cabang2_id" => $this->cCodeData[$cCode]["tableIn_master"]['cabang_id'],
                    "cabang2_nama" => $this->cCodeData[$cCode]["tableIn_master"]['cabang_nama'],
                    "gudang_id" => isset($preReplacer['gudang2ID']) ? $preReplacer['gudang2ID'] : $this->cCodeData[$cCode]["tableIn_master"]['gudang2_id'],
                    "gudang_nama" => isset($preReplacer['gudang2Name']) ? $preReplacer['gudang2Name'] : $this->cCodeData[$cCode]["tableIn_master"]['gudang2_nama'],
                    "gudang2_id" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_id'],
                    "gudang2_nama" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],
                    "gudang" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_id'],
                    "gudang__name" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],
                    "gudang__label" => $this->cCodeData[$cCode]["tableIn_master"]['gudang_nama'],

                    "step_avail" => sizeof($configUiMasterModulJenis["steps"]),
                    "step_current" => 1,
                    "step_number" => 1,
                    "next_step_code" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]["target"] : "",
                    "next_step_label" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]["label"] : "",
                    "next_group_code" => isset($configUiMasterModulJenis["steps"][2]) ? $configUiMasterModulJenis["steps"][2]['userGroup'] : "",
                    "next_step_num" => isset($configUiMasterModulJenis["steps"][2]) ? 2 : "0",
                    "efaktur_source" => isset($preReplacer['efaktur_source']) ? $this->cCodeData[$cCode]["main"]['nomer'] : "",
                    //===references
                    //                    "id_master"            => $masterID,
                    //                    "id_top"               => $topID,
                    //                    "ids_prev"             => base64_encode(serialize(array($prevProp["id"]))),
                    //                    "ids_prev_intext"      => print_r(array($prevProp["id"], true)),
                    //                    "nomer_top"            => $this->cCodeData[$cCode]["main"]['nomer'],
                    //                    "nomers_prev"          => base64_encode(serialize(array($prevProp['nomer']))),
                    //                    "nomers_prev_intext"   => print_r(array($prevProp['nomer'], true)),
                    //                    "jenis_top"            => $this->jenisTr,
                    //                    "jenises_prev"        => base64_encode(serialize(array($prevProp['jenis']))),
                    //                    "jenises_prev_intext" => print_r(array($prevProp['jenis'], true)),
                );

                foreach ($masterReplacers as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }


                //region penomoran receipt #2
                //<editor-fold desc="==========penomoran">
                $this->CI->load->model("CustomCounter");
                $cn = new CustomCounter("transaksi");
                $cn->setType("transaksi");

                $counterForNumber = array($configValuesMasterModulJenis["formatNota"]);
                if (!in_array($counterForNumber[0], $configValuesMasterModulJenis["counters"])) {
                    die(__LINE__ . " Used number should be registered in counters config as well");
                }

                foreach ($counterForNumber as $i => $cRawParams) {
                    $cParams = explode("|", $cRawParams);
                    $cValues = array();
                    foreach ($cParams as $param) {
                        //                    $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        //                    echo "filling $param with " . $this->cCodeData[$cCode]["main"][$param] . "<br>";
                        $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        //                    echo "filling $param with " . $this->cCodeData[$cCode]["main"][$param] . "<br>";
                    }
                    $cRawValues = implode("|", $cValues[$i]);
                    $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                }

                $tmpNomorNota2 = $paramSpec["paramString"];
                $tmpNomorNota2Alias = formatNota("nomer_nolink", $tmpNomorNota2);

                //</editor-fold>
                //endregion

                //region dynamic counters #2
                // <editor-fold defaultstate="collapsed" desc="==========__init+update dynamic-counters ">
                $cn = new CustomCounter("transaksi");
                $cn->setType("transaksi");
                $configCustomParams = $configValuesMasterModulJenis["counters"];
                $configCustomParams[] = "stepCode";
                if (sizeof($configCustomParams) > 0) {
                    $cContent = array();
                    foreach ($configCustomParams as $i => $cRawParams) {
                        $cParams = explode("|", $cRawParams);
                        $cValues = array();
                        foreach ($cParams as $param) {
                            $cValues[$i][$param] = $this->cCodeData[$cCode]["main"][$param];
                        }
                        $cRawValues = implode("|", $cValues[$i]);
                        $paramSpec = $cn->getNewCount($cParams, $cValues[$i], $tokoID);

                        $cContent[$cRawParams][$cRawValues] = $paramSpec["value"];
                        switch ($paramSpec["id"]) {
                            case 0: //===counter type is new
                                $addData = array(
                                    "toko_id" => $tokoID,
                                    "toko_nama" => $tokoNama
                                );
                                $paramKeyRaw = print_r($cParams, true);
                                $paramValuesRaw = print_r($cValues[$i], true);
                                $cn->writeNewCount($cParams, $cValues[$i], $paramKeyRaw, $paramValuesRaw, $addData);
                                break;
                            default: //===counter to be updated
                                $cn->updateCount($paramSpec["id"], $paramSpec["value"]);
                                break;
                        }
                        //echo "<hr>";
                    }
                }
                $appliedCounters2 = base64_encode(serialize($cContent));
                $appliedCounters_inText2 = print_r($cContent, true);
                // </editor-fold>
                //endregion

                //region numbering tambahan
                $this->CI->load->library("CounterNumber");
                $ccn = new CounterNumber();
                $ccn->setCCode($cCode);
                $ccn->setJenisTr($connector);
                $ccn->setTransaksiGate($this->cCodeData[$cCode]["tableIn_master"]);
                $ccn->setMainGate($this->cCodeData[$cCode]["main"]);
                $ccn->setItemsGate($this->cCodeData[$cCode]["items"]);
                $ccn->setItems2SumGate($this->cCodeData[$cCode]["items2_sum"]);
                $new_counter = $ccn->getCounterNumber();
                cekHitam("jenistr yang disett dari create " . $this->jenisTr);


                if (isset($new_counter["main"]) && sizeof($new_counter["main"]) > 0) {
                    foreach ($new_counter["main"] as $ckey => $cval) {
                        $this->cCodeData[$cCode]["tableIn_master"][$ckey] = $cval;
                        $this->cCodeData[$cCode]["main"][$ckey] = $cval;
                    }
                }
                if (isset($new_counter["items"]) && sizeof($new_counter["items"]) > 0) {
                    foreach ($new_counter["items"] as $ikey => $iSpec) {
                        foreach ($iSpec as $iikey => $iival) {
                            $this->cCodeData[$cCode]["items"][$ikey][$iikey] = $iival;
                        }
                    }
                }
                if (isset($new_counter["items2_sum"]) && sizeof($new_counter["items2_sum"]) > 0) {
                    foreach ($new_counter["items2_sum"] as $ikey => $iSpec) {
                        foreach ($iSpec as $iikey => $iival) {
                            $this->cCodeData[$cCode]["items2_sum"][$ikey][$iikey] = $iival;
                        }
                    }
                }
                //endregion

                $addValues = array(
                    "counters" => $appliedCounters2,
                    'counters_intext' => $appliedCounters_inText2,
                    'nomer' => $tmpNomorNota2,
                    'nomer2' => $tmpNomorNota2Alias,
                    'dtime' => date("Y-m-d H:i:s"),
                    'fulldate' => date("Y-m-d"),
                );
                foreach ($addValues as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

                //===cloning nota cab1 ke cab2
                //===daftar perbedaan
                //== referensi_id, inv, jenis, nomer, counters, counters_inText, cabang_id, cabang_nama, cabang2_id, cabang2_nama,

                //==replace kedua
                $masterReplacers = array(
                    "nomer" => $tmpNomorNota2,
                    "nomer2" => $tmpNomorNota2Alias,
                    "counters" => $appliedCounters2,
                    "counters_intext" => $appliedCounters_inText2,
                );
                foreach ($masterReplacers as $key => $val) {
                    $this->cCodeData[$cCode]["tableIn_master"][$key] = $val;
                }

                //===cloning detail/items cabang1 ke cabang2
                //===yang direplace: sub_step_number, sub_step_current, sub_step_avail, next_substep_num, next_substep_code, next_substep_label, next_subgroup_code
                $detailReplacers = array(
                    "sub_step_avail" => sizeof($configUiMasterModulJenis["steps"]),
                    "sub_step_current" => 1,
                    "sub_step_number" => 1,
                    "next_substep_num" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_num'],
                    "next_substep_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_code'],
                    "next_substep_label" => $this->cCodeData[$cCode]["tableIn_master"]['next_step_label'],
                    "next_subgroup_code" => $this->cCodeData[$cCode]["tableIn_master"]['next_group_code'],

                );
                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                    //                    cekmerah("tulis rincian transaksi kedua");
                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $k => $dSpec) {
                        foreach ($dSpec as $key => $val) {
                            $this->cCodeData[$cCode]["tableIn_detail"][$k][$key] = isset($detailReplacers[$key]) ? $detailReplacers[$key] : $val;
                        }
                    }
                }
                else {
                    //                    cekmerah("GAGAL tulis rincian transaksi kedua");
                }


                //region ----------write transaksi & transaksi_data #2
                if (isset($this->cCodeData[$cCode]["tableIn_master"]) && sizeof($this->cCodeData[$cCode]["tableIn_master"]) > 0) {
                    $tr = new MdlTransaksi();
                    $tr->addFilter("transaksi.cabang_id='" . my_cabang_id() . "'");
                    $insertID = $tr->writeMainEntries($this->cCodeData[$cCode]["tableIn_master"]);
                    cekUngu($this->CI->db->last_query());
                    $epID = $tr->writeMainEntries_entryPoint($insertID, $masterID, $this->cCodeData[$cCode]["tableIn_master"]);
                    $insertNum = $this->cCodeData[$cCode]["tableIn_master"]['nomer'];
                    $this->cCodeData[$cCode]["main"]['nomer'] = $insertNum;
                    //$mongoListConnect["main"] = array($insertID, $epID);
                    cekmerah("tulis transaksi kedua :: trID $insertID");
                    cekmerah($this->CI->db->last_query());
                    if ($insertID < 1) {
                        die("Gagal saat berusaha  write transaction entry pada " . __FILE__ . " baris " . __LINE__);
                    }
                }
                else {
                    cekmerah("GAGAL tulis transaksi kedua");
                }
                if (isset($this->cCodeData[$cCode]['tableIn_master_values']) && sizeof($this->cCodeData[$cCode]['tableIn_master_values']) > 0) {
                    $inserMainValues = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_master_values'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        $inserMainValues[] = $dd;
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                    if (sizeof($inserMainValues) > 0) {
                        $arrBlob = blobEncode($inserMainValues);
                        $this->CI->db->query("UPDATE transaksi SET indexing_main_values = '$arrBlob' WHERE id=$insertID");
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_add_values']) && sizeof($this->cCodeData[$cCode]['main_add_values']) > 0) {
                    foreach ($this->cCodeData[$cCode]['main_add_values'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_inputs']) && sizeof($this->cCodeData[$cCode]['main_inputs']) > 0) {
                    foreach ($this->cCodeData[$cCode]['main_inputs'] as $key => $val) {
                        $dd = $tr->writeMainValues($insertID, array("key" => $key, "value" => $val));
                        $inserMainValues[] = $dd;
                        //$mongoListConnect['mainValues'][] = $dd;
                    }
                }
                if (isset($this->cCodeData[$cCode]['main_elements']) && sizeof($this->cCodeData[$cCode]['main_elements']) > 0) {
                    //                    cekMerah("ada mainElements");
                    foreach ($this->cCodeData[$cCode]['main_elements'] as $elName => $aSpec) {
                        $tr->writeMainElements($insertID, array(
                            "mdl_name" => isset($aSpec['mdl_name']) ? $aSpec['mdl_name'] : "",
                            "key" => isset($aSpec['key']) ? $aSpec['key'] : 0,
                            "value" => isset($aSpec["value"]) ? $aSpec["value"] : "",
                            "name" => $aSpec['name'],
                            "label" => $aSpec["label"],
                            "contents" => isset($aSpec['contents']) ? $aSpec['contents'] : "",
                            "contents_intext" => isset($aSpec['contents_intext']) ? $aSpec['contents_intext'] : "",

                        ));
                    }
                }
                if (isset($this->cCodeData[$cCode]["tableIn_detail"]) && sizeof($this->cCodeData[$cCode]["tableIn_detail"]) > 0) {
                    $insertIDs = array();
                    $insertDeIDs = array();
                    foreach ($this->cCodeData[$cCode]["tableIn_detail"] as $dSpec) {
                        $insertDetailID = $tr->writeDetailEntries($insertID, $dSpec);
                        if ($insertDetailID < 1) {
                            die("Gagal saat berusaha write transaction detail entry pada " . __FILE__ . " baris " . __LINE__);
                        }
                        else {
                            $insertIDs[] = $insertDetailID;
                            $insertDeIDs[$insertID][] = $insertDetailID;
                            //$mongoListConnect['detail'][] = $insertDetailID;
                        }
                        if ($epID != 999) {
                            $insertEpID = $tr->writeDetailEntries($epID, $dSpec);
                            if ($insertEpID < 1) {
                                die("Gagal saat berusaha write transaction detail entry point pada " . __FILE__ . " baris " . __LINE__);
                            }
                            else {
                                $insertIDs[] = $insertEpID;
                                $insertDeIDs[$epID][] = $insertEpID;
                                //$mongoListConnect['detail'][] = $insertEpID;
                            }
                        }
                    }
                    if (sizeof($insertIDs) == 0) {
                        die(lgShowAlert("Transaksi gagal disimpan karena rincian transaksi kosong."));
                    }
                    else {
                        $indexing_details = array();
                        foreach ($insertDeIDs as $key => $numb) {
                            $indexing_details[$key] = $numb;
                        }

                        foreach ($indexing_details as $k => $arrID) {
                            $arrBlob = blobEncode($arrID);
                            $this->CI->db->query("UPDATE transaksi SET indexing_details = '$arrBlob' WHERE id=$k");
                            cekOrange($this->CI->db->last_query());
                        }
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail2_sum']) > 0) {
                    $insertIDs = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_detail2_sum'] as $dSpec) {
                        $insertIDs[] = $tr->writeDetailEntries($insertID, $dSpec);
                        //$mongoListConnect['detail'] = $insertIDs;
                        if ($epID != 999) {
                            $insertIDs[] = $tr->writeDetailEntries($epID, $dSpec);
                            //$mongoListConnect['detail'] = //$mongoListConnect['detail'] = $insertIDs;;
                        }
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail_values']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values']) > 0) {
                    $insertIDs = array();
                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values'] as $pID => $dSpec) {
                        if (isset($configValuesMasterModulJenis["tableIn"]['detailValues'])) {
                            foreach ($configValuesMasterModulJenis["tableIn"]['detailValues'] as $key => $src) {
                                //                                $insertIDs[$pID][] = $tr->writeDetailValues($insertID, array(
                                //                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                //                                    "produk_id" => $pID,
                                //                                    "key" => $key,
                                //                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                                //                                ));
                                $dd = $tr->writeDetailValues($insertID, array(
                                    "produk_jenis" => $this->cCodeData[$cCode]["tableIn_detail"][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => isset($dSpec[$src]) ? $dSpec[$src] : 0,
                                ));
                                $insertIDs[] = $dd;
                                //$mongoListConnect['detailValues'][] = $dd;

                            }
                        }
                    }
                    if (sizeof($insertIDs) > 0) {
                        $arrBlob = blobEncode($insertIDs);
                        $this->CI->db->query("UPDATE transaksi SET indexing_detail_values = '$arrBlob' WHERE id=$insertID");
                    }
                }
                if (isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) && sizeof($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) > 0) {
                    foreach ($this->cCodeData[$cCode]['tableIn_detail_values2_sum'] as $pID => $dSpec) {
                        if (isset($configValuesMasterModulJenis["tableIn"]['detailValues2_sum'])) {
                            foreach ($configValuesMasterModulJenis["tableIn"]['detailValues2_sum'] as $key => $src) {
                                $insertIDs[] = $tr->writeDetailValues($insertID, array(
                                    "produk_jenis" => $this->cCodeData[$cCode]['tableIn_detail2_sum'][$pID]['produk_jenis'],
                                    "produk_id" => $pID,
                                    "key" => $key,
                                    "value" => $dSpec[$src],
                                ));

                            }
                        }
                    }
                }

                //
                //region nulis paymentSource
                $stepCode = $configUiMasterModulJenis["steps"][1]["target"];
                $paymentSources = $this->CI->config->item("payment_source");
                if (array_key_exists($stepCode, $paymentSources)) {

                    $payConfigs = $paymentSources[$stepCode];
                    if (sizeof($payConfigs) > 0) {
                        foreach ($payConfigs as $paymentSrcConfig) {
                            //					$paymentSrcConfig = $paymentSources[$stepCode];
                            $valueSrc = $paymentSrcConfig['valueSrc'];
                            $externSrc = $paymentSrcConfig['externSrc'];
                            $tr->writePaymentSrc($insertID, array(
                                "jenis" => $stepCode,
                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                "nomer" => $tmpNomorNota2,
                                "label" => $paymentSrcConfig["label"],
                                "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "terbayar" => 0,
                                "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "toko_id" => my_toko_id(),
                                "toko_nama" => my_toko_name(),
                                "dtime" => date("Y-m-d H:i:s"),
                                "fulldate" => date("Y-m-d"),
                                "valas_id" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasId']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasId']] : '',
                                "valas_nama" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasLabel']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasLabel']] : '',
                                "valas_nilai" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasValue']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasValue']] : '',
                                "tagihan_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasTagihan']] : '',
                                "terbayar_valas" => 0,
                                "sisa_valas" => isset($this->cCodeData[$cCode]["main"][$externSrc['valasSisa']]) ? $this->cCodeData[$cCode]["main"][$externSrc['valasSisa']] : '',
                            ));
                        }
                    }

                }
                else {
                    //cekMerah("TIDAK nulis paymentSrc");
                }
                //endregion


                //region nulis paymentAntiSource

                $stepCode = $configUiMasterModulJenis["steps"][1]["target"];
                $paymentSources = $this->CI->config->item("payment_antiSource");
                if (array_key_exists($stepCode, $paymentSources)) {
                    $payConfigs = $paymentSources[$stepCode];
                    if (sizeof($payConfigs) > 0) {
                        foreach ($payConfigs as $paymentSrcConfig) {
                            $valueSrc = $paymentSrcConfig['valueSrc'];
                            $externSrc = $paymentSrcConfig['externSrc'];
                            $tr->writePaymentAntiSrc($insertID, array(
                                "jenis" => $stepCode,
                                "target_jenis" => $paymentSrcConfig['jenisTarget'],
                                "reference_jenis" => $paymentSrcConfig['jenisSrc'],
                                "extern_id" => $this->cCodeData[$cCode]["main"][$externSrc["id"]],
                                "extern_nama" => $this->cCodeData[$cCode]["main"][$externSrc['nama']],
                                "nomer" => $tmpNomorNota2,
                                "label" => $paymentSrcConfig["label"],
                                "tagihan" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "terbayar" => 0,
                                "sisa" => $this->cCodeData[$cCode]["main"][$valueSrc],
                                "cabang_id" => $this->cCodeData[$cCode]["main"]['placeID'],
                                "cabang_nama" => $this->cCodeData[$cCode]["main"]['placeName'],
                                "oleh_id" => my_id(),
                                "oleh_nama" => my_name(),
                                "toko_id" => my_toko_id(),
                                "toko_nama" => my_toko_nama(),
                                "dtime" => date("Y-m-d H:i:s"),
                                "fulldate" => date("Y-m-d"),
                            ));
                        }
                    }
                }
                else {
                    //cekMerah("TIDAK nulis paymentSrc");
                }
                //endregion


                $idHis_decode[$stepNum] = array(
                    "olehID" => $this->cCodeData[$cCode]["main"]['olehID'],
                    "olehName" => $this->cCodeData[$cCode]["main"]['olehName'],
                    "step" => $stepNum,
                    "trID" => $insertID,
                    "nomer" => $tmpNomorNota2,
                    "nomer2" => $tmpNomorNota2Alias,
                    "counters" => $appliedCounters2,
                    "counters_intext" => $appliedCounters_inText2,
                );
                $idHis_blob = blobEncode($idHis_decode);
                $idHis_intext = print_r($idHis_decode, true);

                $this->cCodeData[$cCode]["tableIn_master"]['ids_his'] = $idHis_blob;
                $this->cCodeData[$cCode]["tableIn_master"]['ids_his_intext'] = $idHis_intext;

                $tr = new MdlTransaksi();
                $dupState = $tr->updateData(array("id" => $insertID), array(
                    "id_master" => $masterID,
                    "id_top" => $insertID,
                    "ids_his" => $idHis_blob,
                    "ids_his_intext" => $idHis_intext,
                )) or die("Failed to update tr next-state!");


                $baseRegistries = array(
                    "main" => isset($this->cCodeData[$cCode]["main"]) ? $this->cCodeData[$cCode]["main"] : array(),
                    "items" => isset($this->cCodeData[$cCode]["items"]) ? $this->cCodeData[$cCode]["items"] : array(),
                    "items2" => isset($this->cCodeData[$cCode]["items2"]) ? $this->cCodeData[$cCode]["items2"] : array(),
                    "items2_sum" => isset($this->cCodeData[$cCode]["items2_sum"]) ? $this->cCodeData[$cCode]["items2_sum"] : array(),
                    "itemSrc" => isset($this->cCodeData[$cCode]["itemSrc"]) ? $this->cCodeData[$cCode]["itemSrc"] : array(),
                    "itemSrc_sum" => isset($this->cCodeData[$cCode]["itemSrc_sum"]) ? $this->cCodeData[$cCode]["itemSrc_sum"] : array(),
                    "items3" => isset($this->cCodeData[$cCode]["items3"]) ? $this->cCodeData[$cCode]["items3"] : array(),
                    "items3_sum" => isset($this->cCodeData[$cCode]["items3_sum"]) ? $this->cCodeData[$cCode]["items3_sum"] : array(),
                    "items4" => isset($this->cCodeData[$cCode]["items4"]) ? $this->cCodeData[$cCode]["items4"] : array(),
                    "items4_sum" => isset($this->cCodeData[$cCode]["items4_sum"]) ? $this->cCodeData[$cCode]["items4_sum"] : array(),
                    "items5_sum" => isset($this->cCodeData[$cCode]["items5_sum"]) ? $this->cCodeData[$cCode]["items5_sum"] : array(),
                    'items6_sum' => isset($this->cCodeData[$cCode]['items6_sum']) ? $this->cCodeData[$cCode]['items6_sum'] : array(),
                    'items7_sum' => isset($this->cCodeData[$cCode]['items7_sum']) ? $this->cCodeData[$cCode]['items7_sum'] : array(),
                    'items8_sum' => isset($this->cCodeData[$cCode]['items8_sum']) ? $this->cCodeData[$cCode]['items8_sum'] : array(),
                    'items9_sum' => isset($this->cCodeData[$cCode]['items9_sum']) ? $this->cCodeData[$cCode]['items9_sum'] : array(),
                    'items10_sum' => isset($this->cCodeData[$cCode]['items10_sum']) ? $this->cCodeData[$cCode]['items10_sum'] : array(),
                    'items_noapprove' => isset($this->cCodeData[$cCode]['items_noapprove']) ? $this->cCodeData[$cCode]['items_noapprove'] : array(),
                    'rsltItems' => isset($this->cCodeData[$cCode]['rsltItems']) ? $this->cCodeData[$cCode]['rsltItems'] : array(),
                    'rsltItems2' => isset($this->cCodeData[$cCode]['rsltItems2']) ? $this->cCodeData[$cCode]['rsltItems2'] : array(),
                    'rsltItems3' => isset($this->cCodeData[$cCode]['rsltItems3']) ? $this->cCodeData[$cCode]['rsltItems3'] : array(),
                    "tableIn_master" => isset($this->cCodeData[$cCode]["tableIn_master"]) ? $this->cCodeData[$cCode]["tableIn_master"] : array(),
                    "tableIn_detail" => isset($this->cCodeData[$cCode]["tableIn_detail"]) ? $this->cCodeData[$cCode]["tableIn_detail"] : array(),
                    'tableIn_detail2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail2_sum'] : array(),
                    'tableIn_detail_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems'] : array(),
                    'tableIn_detail_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_rsltItems2'] : array(),
                    'tableIn_master_values' => isset($this->cCodeData[$cCode]['tableIn_master_values']) ? $this->cCodeData[$cCode]['tableIn_master_values'] : array(),
                    'tableIn_detail_values' => isset($this->cCodeData[$cCode]['tableIn_detail_values']) ? $this->cCodeData[$cCode]['tableIn_detail_values'] : array(),
                    'tableIn_detail_values_rsltItems' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems'] : array(),
                    'tableIn_detail_values_rsltItems2' => isset($this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2']) ? $this->cCodeData[$cCode]['tableIn_detail_values_rsltItems2'] : array(),
                    'tableIn_detail_values2_sum' => isset($this->cCodeData[$cCode]['tableIn_detail_values2_sum']) ? $this->cCodeData[$cCode]['tableIn_detail_values2_sum'] : array(),
                    'main_add_values' => isset($this->cCodeData[$cCode]['main_add_values']) ? $this->cCodeData[$cCode]['main_add_values'] : array(),
                    'main_add_fields' => isset($this->cCodeData[$cCode]['main_add_fields']) ? $this->cCodeData[$cCode]['main_add_fields'] : array(),
                    'main_elements' => isset($this->cCodeData[$cCode]['main_elements']) ? $this->cCodeData[$cCode]['main_elements'] : array(),
                    'main_inputs' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                    'main_inputs_orig' => isset($this->cCodeData[$cCode]['main_inputs']) ? $this->cCodeData[$cCode]['main_inputs'] : array(),
                    "receiptDetailFields" => isset($this->configLayoutModul[$connector]['receiptDetailFields'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields'][1] : array(),
                    "receiptSumFields" => isset($this->configLayoutModul[$connector]['receiptSumFields'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields'][1] : array(),
                    "receiptDetailFields2" => isset($this->configLayoutModul[$connector]['receiptDetailFields2'][1]) ? $this->configLayoutModul[$connector]['receiptDetailFields2'][1] : array(),
                    "receiptSumFields2" => isset($this->configLayoutModul[$connector]['receiptSumFields2'][1]) ? $this->configLayoutModul[$connector]['receiptSumFields2'][1] : array(),
                    "receiptDetailSrcFields" => isset($this->configLayoutModul[$connector]['receiptDetailSrcFields'][1]) ? $this->configLayoutModul[$connector]['receiptDetailSrcFields'][1] : array(),
                    "items_komposisi" => isset($this->cCodeData[$cCode]['items_komposisi']) ? $this->cCodeData[$cCode]['items_komposisi'] : array(),
                    "componentsBuilder" => isset($this->cCodeData[$cCode]['componentsBuilder']) ? $this->cCodeData[$cCode]['componentsBuilder'] : array(),
                    "jurnalItems" => isset($this->cCodeData[$cCode]['jurnalItems']) ? $this->cCodeData[$cCode]['jurnalItems'] : array(),
                    "jurnal_index" => isset($this->cCodeData[$cCode]['jurnal_index']) ? $this->cCodeData[$cCode]['jurnal_index'] : array(),
                    "postProcessor" => isset($this->cCodeData[$cCode]['postProcessor']) ? $this->cCodeData[$cCode]['postProcessor'] : array(),
                    "preProcessor" => isset($this->cCodeData[$cCode]['preProcessor']) ? $this->cCodeData[$cCode]['preProcessor'] : array(),
                    "revert" => isset($this->cCodeData[$cCode]['revert']) ? $this->cCodeData[$cCode]['revert'] : array(),
                    "itemPrice_sum" => isset($this->cCodeData[$cCode]['itemPrice_sum']) ? $this->cCodeData[$cCode]['itemPrice_sum'] : array(),
                    //-----
                    "coreBuilder" => isset($coreBuilder) ? $coreBuilder : array(),
                    'diskon_event' => isset($this->cCodeData[$cCode]['diskon_event']) ? $this->cCodeData[$cCode]['diskon_event'] : array(),
                    'cashback_event' => isset($this->cCodeData[$cCode]['cashback_event']) ? $this->cCodeData[$cCode]['cashback_event'] : array(),
                    'free_items' => isset($this->cCodeData[$cCode]['free_items']) ? $this->cCodeData[$cCode]['free_items'] : array(),
                    //-----
                );
                $doWriteReg = $tr->writeDataRegistries($insertID, $baseRegistries) or die(lgShowError("Ada kesalahan", "Gagal saat berusaha  write base params into registries"));
                $mongRegIDConnect = $doWriteReg;
                //endregion


                //==================================================================================================
                //==MENULIS LOCKER TRANSAKSI ACTIVE=================================================================
                $this->CI->load->model("Mdls/MdlLockerTransaksi");
                $lt = New MdlLockerTransaksi();
                $lt->execLocker($this->cCodeData[$cCode]["main"], $nextProp["num"], NULL, $insertID);
                //==================================================================================================

                $outResultLib["sessionDataConnecting"] = $this->cCodeData[$cCode];
                $outResultLib["tmpNomerNotaConnecting"] = $tmpNomorNota2;
                $outResultLib["transaksiIdConnecting"] = $insertID;

            }
            else {
                cekMerah("to be delayed to connect to $connector");
            }
        }
        else {
            //cekKuning("not connecting to any tCode");
        }
        //endregion


        //region nulis ke data jika ada
        $addTodata = isset($this->configUiModul[$this->jenisTr]["addData"][$stepNum]) ? $this->configUiModul[$this->jenisTr]["addData"][$stepNum] : array();
        if (sizeof($addTodata) > 0) {
            $gateData = isset($this->cCodeData[$cCode][$addTodata["gate"]]) ? $this->cCodeData[$cCode][$addTodata["gate"]] : array();
            $selectedFields = $addTodata["fieldName"];
            $dataMdl = $addTodata["MdlNameMain"];
            $this->CI->load->model("DComs/" . $dataMdl);
            $d = new $dataMdl();
            $childMdl = $addTodata["MdlNameChild"];
            $d = new $dataMdl();
            if (sizeof($gateData) > 0) {
                $outparams = array();
                $ctr = 0;
                foreach ($gateData as $gateValues) {
                    $params = array();
                    $ctr++;
                    foreach ($selectedFields as $colum => $gate_collom) {
                        $params['static'][$colum] = $gateValues[$gate_collom];
                    }
                    if ($masterID != "") {
                        $params['static']['transaksi_id_request_bunga'] = $masterID;
                    }
                    if ($insertID != "") {
                        $params['static']['transaksi_id'] = $insertID;
                    }
                    if ($this->session->login['nama_login'] != "") {
                        $params['static']['nama_login'] = $this->session->login['nama_login'];
                    }
                    if (my_id() != "") {
                        $params['static']['pihakid'] = my_id();
                    }
                    if ($tmpNomorNota2 != "") {
                        $params['static']['tmpNomorNota2'] = $tmpNomorNota2;
                    }
                    $outparams[] = $params + array("MdlName" => $childMdl);
                }

                if (sizeof($outparams) > 0) {
                    $d->pair($outparams) or die("Tidak berhasil memasang  values pada post-processor: $dataMdl/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                    $d->exec() or die("Gagal saat berusaha  exec values pada post-processor: $dataMdl/" . $this->jenisTr . "/" . __FUNCTION__ . "/" . __LINE__);
                }
                else {
                    matiHEre("error on insert data");
                }
            }
        }

        //endregion


        return $outResultLib;

    }
}
