<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once "Modul_Controller.php";

class Transaksi extends Modul_Controller
{
    public function __construct()
    {
        parent::__construct();

        /* ----------------------------------------------------------------------------------
          * loader cunstruk yg wajib ada
          * variabel-variabel bisa langsung dipangil, apa saja yang ada bisa dilihat didalamnya
          * ----------------------------------------------------------------------------------*/
        // require_once "_construct_file.php";

    }

    public function index()
    {
        // arrPrint($_SESSION);
        $cCode = $this->cCode;
        // cekKuning($cCode);
        if (isset($_SESSION[$cCode])) {
            // cekKuning("shopping-cart (creator)");
            arrprint($_SESSION[$cCode]);
        }
        else {
            die("the gate index you want to debug has not been formed yet!");
        }
    }

    public function index_OLD()
    {
        $starttime = microtime(true);
        if (!isset($this->session->login['id'])) {
            redirect(base_url() . "Login");
        }

        $sesionReplacer = replaceSession();
        $jenisTr = $this->uri->segment(3);
        $cCode = "_TR_" . $this->jenisTr;
        $paymentConfig = isset($this->configUi[$jenisTr]['paymentConfig']) ? $this->configUi[$jenisTr]['paymentConfig'] : false;
        $historyFields = isset($this->configUi[$jenisTr]['shortHistoryFields']) ? $this->configUi[$jenisTr]['shortHistoryFields'] : array();
        $kepoinFields = isset($this->configUi[$jenisTr]['shortKepoinFields']) ? $this->configUi[$jenisTr]['shortKepoinFields'] : array();
        $pairRegistries = isset($this->configUi[$jenisTr]['pairRegistries']) ? $this->configUi[$jenisTr]['pairRegistries'] : array();
        $shoppingCartPerTransaksi = isset($this->configUi[$jenisTr]['shoppingCartPerTransaksi']) ? $this->configUi[$jenisTr]['shoppingCartPerTransaksi'] : 0;
        $shoppingCartPerTransaksiBtn = isset($this->configUi[$jenisTr]['shoppingCartPerTransaksiBtn']) ? $this->configUi[$jenisTr]['shoppingCartPerTransaksiBtn'] : 0;
        //        $historyFieldsExt = isset($this->configUi[$jenisTr]["extHistoryFields"][$selectedSTep]) ? $this->configUi[$jenisTr]["extHistoryFields"][$selectedSTep] : array();
        $connectTo = isset($this->configUi[$jenisTr]['connectTo']) ? $this->configUi[$jenisTr]['connectTo'] : "";
        $mb = New MobileDetect();
        $isMob = $mb->isMobile();
        if ($isMob) {
            $historyFields = isset($this->configUi[$jenisTr]['compactHistoryFields']) ? $this->configUi[$jenisTr]['compactHistoryFields'] : array();
        }

        $prePreFields = $historyFields;
        $prePreFields['state'] = "status";
        $prePreFields['action'] = "action";
        $kepoinFields['action'] = "action";
        $swapJenisTr = isset($this->configUi[$jenisTr]['requestCode']['masterCode']) ? $this->configUi[$jenisTr]['requestCode']['masterCode'] : array();
        $arrayOnprePre = array();
        if (sizeof($swapJenisTr) > 0) {
            $steps = $this->configUi[$swapJenisTr]['steps'];
            $arrFilters = array();
            if (sizeof($steps) > 1) {
                $this->load->model("MdlTransaksi");
                $tr = new MdlTransaksi();
                $stepCodes = array();
                $jmlStep = count($steps);
                $tr->setFilters(array());
                if (isset($this->accessList[$swapJenisTr]) && sizeof($this->accessList) > 0) {
                    $indsteps = "(";
                    foreach ($this->accessList[$swapJenisTr] 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) {
                        if (sizeof($this->jenisTr) > 0) {
                        }
                        $tr->addFilter("next_step_code in $indsteps");
                    }
                    else {
                        //                        $tr->addFilter("next_step_code in $indsteps");
                        $tr->addFilter("next_step_code!=''");
                        $tr->addFilter("transaksi.oleh_id='" . $this->session->login['id'] . "'");
                    }
                }
                else {

                }
                $tr->addFilter("div_id='" . $this->session->login['div_id'] . "'");
                $tr->addFilter("jenis_top='" . $steps[1]['target'] . "'");
                $tr->addFilter("next_substep_code<>''");
                $tr->addFilter("sub_step_number>0");
                $tr->addFilter("valid_qty>0");

                $tmpHist = $tr->lookupRecentUndoneEntries_joined($sesionReplacer)->result();

                if (sizeof($tmpHist) > 0) {
                    $arrTransID = array();
                    $arrTransTopID = array();
                    $arrIdsHist = array();
                    $arrTransHist = array();
                    foreach ($tmpHist as $row) {
                        $arrTransID[] = $row->id;
                        $arrTransTopID[] = $row->id_top;
                        $indexingRegistryData = blobdecode($row->indexing_registry);
                        $indeReg[$row->id] = $indexingRegistryData['main'];
                        //arrPrint($indexingRegistryData);
                        //arrPrint($indeReg);
                        if ($row->ids_his != "") {
                            $hist = blobDecode($row->ids_his);
                            foreach ($hist as $hisSpec) {
                                $arrIdsHist[$row->id][$hisSpec['step']] = array(
                                    "step" => $hisSpec['step'],
                                    "trID" => $hisSpec['trID'],
                                    "nomer" => $hisSpec['nomer'],
                                );
                                $arrTransHist[] = $hisSpec['trID'];
                            }
                        }
                    }
                    //                    arrPrint(sizeof($indeReg));
                    //matiHere("ikiii");
                    $tmpReg_result = array();
                    $trReg = new MdlTransaksi();
                    $trReg->setFilters(array());
                    //                    $trReg->addFilter("param='main'");
                    //                    $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");//ini diganti pakai indexing
                    $trReg->addFilter("id in ('" . implode("','", $indeReg) . "')");
                    $tmpReg = $trReg->lookupRegistries()->result();

                    if (sizeof($tmpReg) > 0) {
                        foreach ($tmpReg as $regRow) {
                            $param = $regRow->param;
                            $tmpReg_result[$regRow->transaksi_id][$param] = blobDecode($regRow->values);
                        }
                    }
                    foreach ($tmpHist as $row) {
                        if (sizeof($pairRegistries) > 0) {
                            //                            $trReg = new MdlTransaksi();
                            //                            $trReg->setFilters(array());
                            //                            $trReg->addFilter("param in ('" . implode("','", $pairRegistries) . "')");
                            //                            $trReg->addFilter("transaksi_id='" . $row->transaksi_id . "'");
                            //                            $tmpReg = $trReg->lookupRegistries()->result();
                            //                            if (sizeof($tmpReg) > 0) {
                            //                                foreach ($tmpReg as $regRow) {
                            //                                    $param = $regRow->param;
                            //                                    $$param = blobDecode($regRow->values);
                            //                                }
                            //                                foreach ($pairRegistries as $eReg) {
                            //                                    foreach ($$eReg as $k => $v) {
                            //                                        if (!isset($row->$k)) {
                            //                                            $row->$k = $v;
                            //                                        }
                            //                                    }
                            //                                }
                            //                            }
                            if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->id]))) {
                                foreach ($tmpReg_result[$row->id] as $param => $eReg) {
                                    foreach ($eReg as $k => $v) {
                                        if (!isset($row->$k)) {
                                            $row->$k = $v;
                                        }
                                    }
                                }
                            }
                        }

                        $tmp = array();
                        foreach ($historyFields as $fName => $fLabel) {
                            $tmp[$fName] = isset($row->$fName) ? formatField($fName, $row->$fName) : formatField($fName, 0);
                        }
                        $showPoStatus = isset($this->config->item('heTransaksi_ui')[$swapJenisTr]['showPoStatus']) ? $this->config->item('heTransaksi_ui')[$swapJenisTr]['showPoStatus'] : array();
                        $cekStateLocation = ($this->session->login['cabang_id'] > 0) ? "cabang" : "pusat";

                        if ($row->sub_step_number > 0) {
                            $tmp['state'] = "<div class='panel panel-warning' style='padding: 3px;margin-bottom: 5px;' ><span style='color:" . $this->configUi[$swapJenisTr]['steps'][$row->sub_step_number]['stateColor'] . "'>" . $this->configUi[$swapJenisTr]['steps'][$row->sub_step_number]['stateLabel'] . "</span>";
                            $tmp['state'] .= "<br>" . createStateSign($row->sub_step_number, $row->step_avail) . "</div>";

                            // cek PO
                            $arrTransactionSource = array();
                            $id_master = $row->id_master;
                            $id_top1 = $row->id_top;
                            $this->load->model("MdlTransaksi");
                            $l = new MdlTransaksi();
                            $l->setFilters(array());
                            $l->addFilter("transaksi_data.valid_qty>0");
                            $l->addFilter("id_master='" . $id_master . "'");
                            $l->addFilter("jenis_master='" . $swapJenisTr . "'");
                            $l->addFilter("link_id=0");
                            $tmpTS = $l->lookupJoined()->result();
                            // showLast_query("kuning");
                            // matiHere(__LINE__);
                            $arrsub_step_number = array();
                            $arrstep_avail = array();
                            $arrext_blob = array();
                            $arrjenis_master = array();
                            $arrtransaksi_no = array();
                            $arrketerangan = array();

                            if (sizeof($tmpTS) > 0) {
                                foreach ($tmpTS as $kk => $arVL) {
                                    $id = $arVL->id;
                                    $id_master = $arVL->id_master;
                                    $id_top2 = $arVL->id_top;
                                    $produk_id = $arVL->produk_id;
                                    $arrTransactionSource[$id_top1] = $produk_id;
                                    $arrsub_step_number[$id_top1] = $arVL->sub_step_number;
                                    $arrstep_avail[$id_top1] = $arVL->step_avail;
                                    $arrext_blob[$id_top1][$kk] = isset($arVL->ext_blob) ? ($arVL->ext_blob != "" ? blobDecode($arVL->ext_blob) : "") : "";
                                }

                                if (sizeof($arrext_blob[$id_top1]) > 0) {
                                    foreach ($arrext_blob[$id_top1] as $ky => $aVal) {
                                        if ($aVal != "") {
                                            foreach ($arrext_blob[$id_top1][$ky]['static'] as $numb => $numData) {
                                                $arrtransaksi_no[$id_top1][$numb] = formatField("nomer", $numb);
                                                $arrjenis_master[$id_top1][$numb] = $numData['jenis'];
                                                $arrketerangan[$id_top1][$numb] = $numData['keterangan'];
                                            }
                                        }
                                    }
                                }
                            }

                            if ($arrext_blob[$id_top1][$ky] != "") {
                                $tmp['state'] .= "<div class='panel panel-danger bg-green' style='padding: 3px;margin-bottom: 5px;'>";
                                if ($cekStateLocation == "cabang") {
                                    $tmp['state'] .= "<div><b>diproses oleh PUSAT</b></div>";
                                }
                                if (sizeof($arrtransaksi_no[$id_top1]) > 0) {
                                    foreach ($arrtransaksi_no[$id_top1] as $numb_) {
                                        $tmp['state'] .= "<div><span class='fa fa-check-circle text-warning'></span> " . $numb_ . "</div>";
                                    }
                                }
                                $tmp['state'] .= "</div>";
                            }

                        }
                        else {
                            $tmp['state'] = "<span style='color:#777777'>canceled</span>";
                        }

                        $tmp['action'] = "";
                        // arrPrintWebs($row);
                        $nextStepNum = ($row->next_substep_num);

                        $currentStepNum = ($row->sub_step_number);
                        $currentStepCode = ($row->jenis);
                        $nextStepCode = ($row->next_step_code);

                        if ($row->sub_step_number > 0) {
                            $allowFollowup = true;
                            $actionLabel = "review " . $this->configUi[$swapJenisTr]['steps'][$currentStepNum]['label'];
                        }

                        if (isset($this->configUi[$swapJenisTr]['steps'][$nextStepNum])) {
                            if (isset($this->accessList[$jenisTr])) {
                                if (isset($this->accessList[$swapJenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"])) {
                                    $allowFollowup = $this->accessList[$swapJenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"];
                                    $actionLabel = $this->configUi[$swapJenisTr]['steps'][$nextStepNum]['actionLabel'];
                                }
                            }
                            else {
                                if (in_array($this->configUi[$swapJenisTr]['steps'][$nextStepNum]['userGroup'], $this->session->login['membership'])) {
                                    $allowFollowup = true;
                                    $actionLabel = $this->configUi[$swapJenisTr]['steps'][$nextStepNum]['actionLabel'];
                                }
                                else {
                                    $allowFollowup = true;
                                    $actionLabel = "review " . $this->configUi[$swapJenisTr]['steps'][$currentStepNum]['label'];
                                }
                            }
                        }

                        if ($allowFollowup) {

                            $allowJoin = isset($this->configUi[$swapJenisTr]["steps"][$nextStepNum]['allowJoin']) && $this->configUi[$swapJenisTr]["steps"][$nextStepNum]['allowJoin'] == true ? $this->configUi[$swapJenisTr]["steps"][$nextStepNum]['allowJoin'] : false;
                            $stepLabel = isset($this->configUi[$swapJenisTr]['steps'][$nextStepNum]['label']) ? $this->configUi[$swapJenisTr]['steps'][$nextStepNum]['label'] : "";
                            $isCancelPacking = isset($this->configUi[$swapJenisTr]['steps'][$nextStepNum]['isCancelPacking']) ? $this->configUi[$swapJenisTr]['steps'][$nextStepNum]['isCancelPacking'] : false;
                            $allowCancel = isset($this->configUi[$swapJenisTr]['steps'][$nextStepNum]['allowCancel']) ? $this->configUi[$swapJenisTr]['steps'][$nextStepNum]['allowCancel'] : false;

                            $targetFollowupLink = $isCancelPacking == true ? "followupCancelPackingPrePreview" : "followupPrePreview";
                            $followupLink = "document.getElementById('result').src=('" . base_url() . "Transaksi/$targetFollowupLink/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";

                            $tmp['action'] = "<div class='input-group'>";
                            $tmp['action'] .= "<a id='" . $row->transaksi_id . "' class='btn btn-primary btn-block' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                            if ($allowJoin) {
                                $tmp['action'] .= "<span class='input-group-addon'>";
                                $tmp['action'] .= "<a title='process many items at once' href='" . base_url() . "Transaksi/viewIncomplete/" . $this->jenisTr . "/$currentStepNum'><span class='fa fa-dedent'></span></a>";
                                $tmp['action'] .= "</span class='input-group-addon'>";
                            }
                            $tmp['action'] .= "</div class='input-group'>";

                            if ($allowCancel) {
                                $tmp['action'] .= "<div class='input-group'>";
                                $tmp['action'] .= "<a id='" . $row->transaksi_id . "' class='btn btn-primary btn-block' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                                if ($allowJoin) {
                                    $tmp['action'] .= "<span class='input-group-addon'>";
                                    $tmp['action'] .= "<a title='process many items at once' href='" . base_url() . "Transaksi/viewIncomplete/" . $this->jenisTr . "/$currentStepNum'><span class='fa fa-dedent'></span></a>";
                                    $tmp['action'] .= "</span class='input-group-addon'>";
                                }
                                $tmp['action'] .= "</div class='input-group'>";
                            }
                        }
                        else {

                        }
                        $arrayOnprePre[] = $tmp;
                    }

                }

            }
            else {
                $arrayOnprePre = array();
            }

        }
        else {
            $arrayOnprePre = array();
        }


        //region lookup on-going transactions
        $progressFields = $historyFields;
        $progressFields['state'] = "status";
        $progressFields['action'] = "action";
        $steps = $this->configUi[$jenisTr]['steps'];

        $arrayOnprogressTransaksi = array();
        $arrayOnprogressTransaksiKoloms = array();
        $arrFilters = array();
        $settleBtnShow = false;
        if (sizeof($steps) > 1) {

            $this->load->model("MdlTransaksi");
            $tr = new MdlTransaksi();
            $stepCodes = array();
            $jmlStep = count($steps);

            if (isset($this->accessList[$jenisTr]) && sizeof($this->accessList) > 0) {
                $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("transaksi.next_step_code in $indsteps");
                }
                else {
                    $tr->addFilter("transaksi.oleh_id='" . $this->session->login['id'] . "'");
                }
            }
            else {

            }

            $tr->addFilter("div_id='" . $this->session->login['div_id'] . "'");
            $tr->addFilter("jenis_top='" . $steps[1]['target'] . "'");
            $tr->addFilter("transaksi_data.next_substep_code<>''");
            $tr->addFilter("transaksi_data.sub_step_number>0");
            $tr->addFilter("transaksi_data.valid_qty>0");
            /* ----------------------------------------------
             * limit diatur pada MODEL incomplete transaksi
             * ----------------------------------------------*/
            $tmpHist = $tr->lookupRecentUndoneEntries_joined($sesionReplacer)->result();
            // showLast_query("orange");
            // cekHere(sizeof($tmpHist));
            $arrayOnprogress = array();
            if (sizeof($tmpHist) > 0) {
                $arrTransID = array();
                $arrTransTopID = array();
                $arrIdsHist = array();
                $arrTransHist = array();
                $arrNextAction = array();
                foreach ($tmpHist as $row) {
                    $arrTransID[] = $row->transaksi_id;
                    $arrTransTopID[] = $row->id_top;
                    $arrNextAction[$row->transaksi_id] = array(
                        "next_step_num" => $row->next_substep_num,
                        "next_step_code" => $row->next_substep_code,
                    );
                    if ($row->ids_his != "") {
                        $hist = blobDecode($row->ids_his);
                        foreach ($hist as $hisSpec) {
                            $arrIdsHist[$row->id][$hisSpec['step']] = array(
                                "step" => $hisSpec['step'],
                                "trID" => $hisSpec['trID'],
                                "nomer" => $hisSpec['nomer'],
                            );
                            $arrTransHist[] = $hisSpec['trID'];
                        }
                    }
                }
                $tmpReg_result = array();
                $trReg = new MdlTransaksi();
                $trReg->setFilters(array());
                $trReg->addFilter("param='main'");
                $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
                $tmpReg = $trReg->lookupRegistries()->result();

                if (sizeof($tmpReg) > 0) {
                    foreach ($tmpReg as $regRow) {
                        $param = $regRow->param;
                        $tmpReg_result[$regRow->transaksi_id][$param] = blobDecode($regRow->values);
                    }
                }

                $arrNextPIC = callNextPIC($arrNextAction);

                if (sizeof($arrIdsHist) > 0) {
                    $tr = new MdlTransaksi();
                    $tr->setFilters(array());
                    $tr->addFilter("id in ('" . implode("','", $arrTransHist) . "')");
                    $tmpTransHist = $tr->lookupAll()->result();


                    if (sizeof($tmpTransHist) > 0) {
                        foreach ($tmpTransHist as $histSpec) {
                            $tmpTransHist_result[$histSpec->id] = array(
                                "oleh_id" => $histSpec->oleh_id,
                                "oleh_nama" => $histSpec->oleh_nama,
                            );
                        }
                    }

                    foreach ($arrIdsHist as $trID => $histSpec) {
                        foreach ($histSpec as $step => $detailSpec) {
                            if (array_key_exists($detailSpec['trID'], $tmpTransHist_result)) {
                                $detailSpec['main'] = $tmpTransHist_result[$detailSpec['trID']];
                            }
                            $arrTransMainHist[$trID][$step] = $detailSpec;
                        }
                    }
                }

                foreach ($tmpHist as $row) {
                    if (sizeof($pairRegistries) > 0) {
                        if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->transaksi_id]))) {
                            foreach ($tmpReg_result[$row->transaksi_id] as $param => $eReg) {
                                foreach ($eReg as $k => $v) {
                                    if (!isset($row->$k)) {
                                        $row->$k = $v;
                                    }
                                }
                            }
                        }
                    }

                    $tmp = array();
                    foreach ($historyFields as $fName => $fLabel) {

                        if (is_array($fLabel)) {
                            $hisStep = $fLabel['step'];
                            $hisKey = $fLabel['key'];
                            //                                $tNomer = $id_hist[$hisStep][$hisKey];

                            if (isset($row->ids_his)) {
                                $returnVal = showHistoriGlobalNumbers($row->ids_his, $hisStep, true);
                                if ($returnVal == "") {
                                    $tmp[$fName] = "-";
                                }
                                else {
                                    $tmp[$fName] = $returnVal;
                                }
                            }
                            else {
                                $tmp[$fName] = "-";
                            }
                        }
                        else {
                            $tmp[$fName] = isset($row->$fName) ? formatField($fName, $row->$fName) : formatField($fName, 0);
                        }
                    }

                    if (sizeof($row->cancel_packing_source_id) > 0) {
                        arrPrint($row->cancel_packing_source_id);
                        $trx = new MdlTransaksi();
                        $trx->addFilter("id='" . $row->cancel_packing_source_id . "'");
                        $tmpTrx = $trx->lookupAll()->result();

                        //                        $tmp['nomer_top'] = $tmpTrx[0]->nomer;
                        $tmp['nomer_top'] = formatField("nomer_top", $tmpTrx[0]->nomer);
                        //                        arrPrint($tmpTrx[0]->nomer);
                    }


                    if ($row->sub_step_number > 0) {
                        $tmp['state'] = "<span style='color:" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateColor'] . "'>" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateLabel'] . "</span>";
                        $tmp['state'] .= "<br>" . createStateSign($row->sub_step_number, $row->step_avail);
                    }
                    else {
                        $tmp['state'] = "<span style='color:#777777'>canceled</span>";
                    }


                    $tmp['next_pic'] = "-";
                    if (sizeof($arrNextPIC) > 0) {
                        if (isset($arrNextPIC[$row->next_substep_code][$row->next_substep_num])) {
                            $next_pic = "";
                            $nob = 1;
                            foreach ($arrNextPIC[$row->next_substep_code][$row->next_substep_num] as $spec) {
                                if ($row->cabang_id == $spec['cabang_id']) {

                                    if ($next_pic == "") {
                                        $next_pic = "$nob. " . $spec['nama'];
                                    }
                                    else {
                                        $nob++;
                                        $next_pic = $next_pic . "<br>" . "$nob. " . $spec['nama'];
                                    }

                                }

                            }
                            $tmp['next_pic'] = $next_pic;
                            //                            cekHitam($next_pic);
                        }
                    }


                    $tmp['action'] = "";
                    $nextStepNum = ($row->next_substep_num);
                    $currentStepNum = ($row->sub_step_number);
                    $currentStepCode = ($row->jenis);
                    $nextStepCode = ($row->next_step_code);


                    if ($row->sub_step_number > 0) {
                        //                        cekHere("koq");
                        $allowFollowup = true;
                        $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                    }

                    if (isset($this->configUi[$jenisTr]['steps'][$nextStepNum])) {
                        if (isset($this->accessList[$jenisTr])) {
                            if (isset($this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"])) {
                                $allowFollowup = $this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"];
                                $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];
                            }


                        }
                        else {
                            if (in_array($this->configUi[$jenisTr]['steps'][$nextStepNum]['userGroup'], $this->session->login['membership'])) {
                                $allowFollowup = true;
                                $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];
                            }
                            else {
                                $allowFollowup = true;
                                $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                            }
                        }
                    }
                    $req_cancel_qty = $row->req_cancel_qty != '' ? $row->req_cancel_qty : 0;
                    $valid_qty = $row->valid_qty != '' ? $row->valid_qty : 0;

                    //                    cekHere($valid_qty);
                    if ($allowFollowup) {
                        $allowJoin = isset($this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin']) && $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] == true ? $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] : false;
                        $stepLabel = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['label']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['label'] : "";
                        $isCancelPacking = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking'] : false;
                        $allowCancel = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel'] : false;

                        $targetFollowupLink = $isCancelPacking == true ? "followupCancelPackingPrePreview" : "followupPrePreview";
                        $followupLink = "top.$('#result').load('" . base_url() . "Transaksi/$targetFollowupLink/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";

                        if ($allowJoin) {
                            $tmp['action'] = "<div class='input-group btna-group-justified'>";
                            $tmp['action'] .= "<a id='allowFollowup_" . $row->transaksi_id . "' class='btn btn-primary btn-block text-capitalize' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                            $tmp['action'] .= "<span class='input-group-addon'>";
                            $tmp['action'] .= "<a title='process many items at once' href='" . base_url() . "Transaksi/viewIncomplete/" . $this->jenisTr . "/$currentStepNum'><span class='fa fa-dedent'></span></a>";
                            $tmp['action'] .= "</span class='input-group-addon'>";
                            $tmp['action'] .= "</div class='input-group'>";
                        }
                        else {
                            $tmp['action'] .= "<a id='allowFollowup_" . $row->transaksi_id . "' class='btn btn-primary btn-block text-capitalize' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                        }

                        if ($req_cancel_qty > 0 && $valid_qty == 0) {
                            $tmp['action'] = "<div class='btn-group' role='group' aria-label='cancel packing on progress'>";
                            $tmp['action'] .= "<button type='button' disabled class='btn btn-warning' title='sedang dalam process cancel packing' href='JavaScript:void(0)'>menuggu approve cancel</button>";
                            $tmp['action'] .= "</div>";
                        }

                    }
                    else {

                    }
                    $arrayOnprogress[] = $tmp;

                }
            }


        }
        else {

            if (!$paymentConfig) {
                $arrayOnprogress = array();
            }
            else {

                $targetJenis = $this->uri->segment(3);
                heInitCart($targetJenis);
                //==dapatkan srcJenis
                $paymentSources = null != ($this->config->item("payment_source")) ? $this->config->item("payment_source") : array();
                $readerDueDate = isset($this->configUi[$targetJenis]['dueDateReader']) ? $this->configUi[$targetJenis]['dueDateReader'] : false;
                $settleBtnShow = isset($this->configUi[$targetJenis]["settlementBtn"]) ? $this->configUi[$targetJenis]["settlementBtn"] : false;
                if (sizeof($paymentSources) > 0) {
                    foreach ($paymentSources as $src => $mainSpecs) {
                        if (sizeof($mainSpecs) > 0) {
                            foreach ($mainSpecs as $step => $sSpecTemp) {
                                $sCtr = 0;
                                foreach ($sSpecTemp as $sSpec) {
                                    if (isset($sSpec['jenisTarget']) && $sSpec['jenisTarget'] == $targetJenis) {
                                        $srcJenis = $sSpec['jenisSrc'];
                                        $rawSrcJenis = $src;
                                        $srcIndex = $sCtr;
                                        $srcStep = $step;
                                    }
                                    else {
                                        $srcJenis = isset($sSpec['jenisSrc']) ? $sSpec['jenisSrc'] : "";
                                        $rawSrcJenis = "";
                                        $step = "";
                                        $srcIndex = "";
                                        $srcStep = "";
                                    }
                                }
                                $sCtr++;
                            }
                        }
                    }
                }

                $defItemLabels = array(
                    "extern_nama" => isset($paymentSources[$rawSrcJenis][$srcStep][$srcIndex]['externSrc']['extLabel']) ? $paymentSources[$rawSrcJenis][$srcStep][$srcIndex]['externSrc']['extLabel'] : "",
                    "tagihan" => "due amount",
                    "terbayar" => "paid",
                    "diskon" => "discount",
                    "sisa" => "due remain",
                    "tagihan_valas" => "due amount",
                    "terbayar_valas" => "paid",
                    "diskon_valas" => "discount",
                    "sisa_valas" => "due remain",
                );
                $itemLabels = (isset($this->configUi[$targetJenis]["shoppingCartReferenceExternFields"])) ? $this->configUi[$targetJenis]["shoppingCartReferenceExternFields"] : $defItemLabels;
                // $itemLabels["due_date"] = "due date";
                // $itemLabels["aging"] = "aging(days)";
                // $itemLabels["over_due"] = "over due";

                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $tr->addFilter("transaksi_payment_source.cabang_id='" . $this->session->login['cabang_id'] . "'");
                if ($targetJenis == "759") {
                    $tr->addFilter("oleh_id='" . $this->session->login['id'] . "'");//ditambahin ini untuk filter kasir aka penerima pembayaran
                    $this->db->where('date(dtime)', $filterDateFirst);
                }

                $tr->addFilter("sisa>0");

                // $this->db->select(array('fulldate'));
                $this->db->order_by('id', 'asc');
                // $this->db->limit(1);
                $tmpSrc_0 = $tr->lookupPaymentSrcByJenis($targetJenis)->row();
                $filterDateFirst = formatTanggal($tmpSrc_0->dtime, 'Y-m-d');
//                 cekBiru($filterDateFirst);
                // arrPrintPink($tmpSrc_0);
//                showLast_query("biru");
//                $this->db->where('date(dtime)',$filterDateFirst);

                $tmpSrc = $tmpSrc_01 = $tr->lookupPaymentSrcByJenis($targetJenis)->result();
                // showLast_query("hitam");
                // $tmpSrc = $tr->lookupPaymentSrcByJenis($targetJenis)->result();
                // showLast_query("lime");
                // arrPrintPink($tmpSrc);

                $tmpSrcDue = array();
                $dueEmployee = array();
                if ($readerDueDate) {
                    $tr->setFilters(array());
                    $tr->addFilter("status='1'");
                    $tmpSrcDue = $tr->lookupAllDueDate()->result();
                    $tempDataDues = array();
                    $validDate = array();
                    foreach ($tmpSrcDue as $tmpSrcDue_tmp) {
                        $tempDataDues[$tmpSrcDue_tmp->customers_id][] = array(
                            "due_date" => $tmpSrcDue_tmp->due_date,
                            "aging_dtime" => $tmpSrcDue_tmp->dtime,
                        );
                    }
                    $dtime_now = strtotime(date("Y-m-d"));
                    foreach ($tempDataDues as $cus_id => $tempDataDues_0) {
                        $dueVal = array();
                        $dtimeVal = array();
                        foreach ($tempDataDues_0 as $dtime_val) {
                            $keyIndex = strtotime($dtime_val['due_date']);
                            $dueVal[] = $keyIndex;
                            $dtimeVal[$keyIndex] = array(
                                "due_date" => $dtime_val['due_date'],
                                "aging" => $dtime_val['aging_dtime'],
                            );
                        }
                        asort($dueVal);
                        $key_index = $dueVal['0'];
                        $date_due = $dtimeVal[$key_index]['due_date'];
                        $aging = $dtimeVal[$key_index]['aging'];
                        if ($dtime_now > $key_index) {
                            $dueEmployee[$cus_id] = array(
                                "due_date" => formatField("dtime", $date_due),
                                "over_due" => umurDay($date_due) > 0 ? umurDay($date_due) : "0",
                                "aging" => umurDay($aging) > 0 ? umurDay($aging) : "0",
                            );
                        }
                    }
                }
                $items = array();
                $externs = array();
                $tagihans = array();
                $terbayars = array();
                $sisas = array();
                $diskons = array();
                $tagihans_valas = array();
                $terbayars_valas = array();
                $sisas_valas = array();
                $diskons_valas = array();
                $srcLabel = "";
                if (sizeof($tmpSrc) > 0) {
                    foreach ($tmpSrc as $row) {
                        $tmp = array();
                        $classMarking = "";
                        if (isset($dueEmployee[$row->extern_id])) {
                            $classMarking = "bg-danger";
                        }

                        if (!in_array($row->extern_id, $externs)) {
                            if (!isset($tagihans[$row->extern_id])) {
                                $tagihans[$row->extern_id] = 0;
                                $terbayars[$row->extern_id] = 0;
                                $diskons[$row->extern_id] = 0;
                                $sisas[$row->extern_id] = 0;
                                $tagihans_valas[$row->extern_id] = 0;
                                $terbayars_valas[$row->extern_id] = 0;
                                $sisas_valas[$row->extern_id] = 0;
                                $diskons_valas[$row->extern_id] = 0;
                            }

                            $tmp = (array)$row;
                            $tmp["link"] = base_url() . get_class($this) . "/selectPaymentSrc/$targetJenis/" . $row->extern_id;
                            $tmp["due_date"] = isset($dueEmployee[$row->extern_id]['due_date']) ? formatField("dtime", $dueEmployee[$row->extern_id]['due_date']) : "-";
                            $tmp["aging"] = isset($dueEmployee[$row->extern_id]['aging']) ? $dueEmployee[$row->extern_id]['aging'] : "-";
                            $tmp["over_due"] = isset($dueEmployee[$row->extern_id]['over_due']) ? $dueEmployee[$row->extern_id]['over_due'] : "-";
                            $tmp["class_marking"] = $classMarking;
                            $items[$row->extern_id] = $tmp;
                            $externs[] = $row->extern_id;
                            $externName = $row->extern_nama;
                        }
                        $tagihans[$row->extern_id] += isset($row->tagihan) ? $row->tagihan : 0;
                        $terbayars[$row->extern_id] += isset($row->terbayar) ? $row->terbayar : 0;
                        $sisas[$row->extern_id] += isset($row->sisa) ? $row->sisa : 0;
                        $diskons[$row->extern_id] += isset($row->diskon) ? $row->diskon : 0;
                        $tagihans_valas[$row->extern_id] += isset($row->tagihan_valas) ? $row->tagihan_valas : 0;
                        $terbayars_valas[$row->extern_id] += isset($row->terbayar_valas) ? $row->terbayar_valas : 0;
                        $sisas_valas[$row->extern_id] += isset($row->sisa_valas) ? $row->sisa_valas : 0;
                        $diskons_valas[$row->extern_id] += isset($row->diskon_valas) ? $row->diskon_valas : 0;
                        $srcLabel = $row->label;
                    }
                    foreach ($items as $externID => $iSpec) {
                        $items[$externID]['tagihan'] = $tagihans[$externID];
                        $items[$externID]['terbayar'] = $terbayars[$externID];
                        $items[$externID]['diskon'] = $diskons[$externID];
                        $items[$externID]['sisa'] = $sisas[$externID];
                        $items[$externID]['tagihan_valas'] = $tagihans_valas[$externID];
                        $items[$externID]['terbayar_valas'] = $terbayars_valas[$externID];
                        $items[$externID]['diskon_valas'] = $diskons_valas[$externID];
                        $items[$externID]['sisa_valas'] = $sisas_valas[$externID];
                    }
                }
                $arrayOnprogress = $items;

                if (is_array($shoppingCartPerTransaksi)) {
                    $arrayOnprogressTransaksi = $tmpSrc_01;
                    $arrayOnprogressTransaksiKoloms = $shoppingCartPerTransaksi;
                }

            }
        }
        //endregion

        $arrayOnProgressView = array();
        if (strlen($connectTo) > 0) {

            $tr2 = new MdlTransaksi();
            $tr2->setFilters(array());
            // $tr2->addFilter("cabang_id='" . CB_ID_PUSAT . "'");
            // $tr2->addFilter("sisa>0");

            // if(strlen($targetJenis) > 0){
            // cekHitam("connected to :: $connectTo");
            if (isset($connectTo)) {
                $condite = "jenis='$connectTo'";
                // $tr2->addFilter("jenis_master='$connectTo' and link_id='0' and gudang_id<>'0' and next_step_code>'0' AND `sub_step_number` > '0' and gudang_id<>'0'");
                $tr2->addFilter("jenis_master='$connectTo'");
                $tr2->addFilter("link_id='0'");
                $tr2->addFilter("gudang_id<>'0'");
                $tr2->addFilter("next_step_code>'0'");
                $tr2->addFilter("sub_step_number>'0'");
                $tr2->addFilter("gudang_id<>'0'");
                // $tmpSrc2 = $tr2->lookupByCondition($condite)->result();
                $this->db->group_by("id_master");
                $tmpSrc2 = $tr2->lookupJoined()->result();
                // showLast_query("lime");
                // arrPrintPink(sizeof($tmpSrc2));
                // arrPrintPink($tmpSrc2);
                // arrPrintWebs($kepoinFields);

                // foreach ($historyFields as $fName => $fLabel) {
                //     $arrayOnProgressView[$fName] = isset($tmpSrc2->$fName) ? formatField($fName, $tmpSrc2->$fName) : formatField($fName, 0);
                // }
                $tmp2 = array();
                $arrNextAction = array();
                foreach ($tmpSrc2 as $src2s) {
                    $arrNextAction[$src2s->transaksi_id] = array(
                        "next_step_num" => $src2s->next_substep_num,
                        "next_step_code" => $src2s->next_substep_code,
                    );
                }
                $arrNextPIC = callNextPIC($arrNextAction);
                //arrPrint($arrNextPIC);
                foreach ($tmpSrc2 as $src2s) {
                    //                    arrPrint($src2s);
                    foreach ($kepoinFields as $fName => $fLabel) {
                        // $tmp2Datas[$fName] = $src2s->$fName;
                        $tmp2Datas[$fName] = isset($src2s->$fName) ? formatField($fName, $src2s->$fName) : formatField($fName, 0);
                    }

                    $tmp2Datas['next_pic'] = "-";
                    if (sizeof($arrNextPIC) > 0) {
                        //                        cekHere("next_substepcode " . $src2s->next_substep_code);
                        //                        cekHere("next_substepnum " . $src2s->next_substep_num);
                        if (isset($arrNextPIC[$src2s->next_substep_code][$src2s->next_substep_num])) {

                            $next_pic = "-";
                            $nob = 1;
                            foreach ($arrNextPIC[$src2s->next_substep_code][$src2s->next_substep_num] as $spec) {
                                if ($src2s->cabang_id == $spec['cabang_id']) {

                                    if ($next_pic == "-") {
                                        $next_pic = "$nob. " . $spec['nama'];
                                    }
                                    else {
                                        $nob++;
                                        $next_pic = $next_pic . "<br>" . "$nob. " . $spec['nama'];
                                    }

                                }
                            }
                            $tmp2Datas['next_pic'] = $next_pic;

                        }
                    }

                    $tmp2[] = $tmp2Datas;
                }
            }
            $arrayOnProgressView = $tmp2;
        }


        $this->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();

        /* --------------------------------------
         * settlement
         * --------------------------------------*/
        $jenisTr = $this->jenisTr;
        $sesNama = my_name();
        $confSettlement = $this->config->item('settlement');
        $warning = "";
        if ($confSettlement['restrictions'] == true) {
            $condites = array(
                "date(dtime)<" => dtimeNow('Y-m-d'),
            );
            $this->db->where($condites);
            $mySettlementDatas = $tr->callMyTransaksi(my_id(), my_cabang_id());
            // showLast_query("lime");
            $jmlOldTransaksi = sizeof($mySettlementDatas);
            // cekPink($jmlOldTransaksi);

            if ($jmlOldTransaksi > 0) {
                // cekHitam();
                $alerts = array(
                    "type" => "error",
                    "title" => "Peringatan!",
                    "html" => "Hi $sesNama, Masih ada setelmen belum diselesaikan, silahkan diselesaikan terlebih dahulu",
                    // "allowOutsideClick" => true,
                    // "allowEscapeKey" => false,
                    // "confirmButtonText" => "Settlement",
                );

                $warning = swalAlertSettlement($alerts, $jenisTr);
            }
            // echo $warning;
        }
        // -----------end off settlement--------

        //region lookup histories
        //session replacer
        if (sizeof($sesionReplacer) > 0) {
            $tr->addFilter("transaksi.cabang_id='" . $this->session->login['cabang_id'] . "'");
            $tr->addFilter("gudang_id='" . $this->session->login['gudang_id'] . "'");
        }
        $tr->addFilter("jenis_master='" . $this->jenisTr . "'");
        //        $tr->addFilter("next_step_code=''");
        if (sizeof($arrFilters) > 0) {
        }
        else {
            /* -------------------------------------
             * hidupkan kalai ingin memfilter oleh yg login
             * ---------------------------*/
            // $tr->addFilter("transaksi.oleh_id='" . $this->session->login['id'] . "'");
        }

        $limitHistory = 5;
        $this->db->select("id, id_master,dtime");
        $this->db->limit($limitHistory);
        $this->db->order_by("id", "desc");
        $tmpHist_0 = $tr->lookupAll()->result();

        // showLast_query("lime");

        $tr->setFilters(array());


        // cekBiru($tmpHist_0);
        // cekBiru($tmpHist);
        //die();
        $arrayHistory = array();
        if (sizeof($tmpHist_0) > 0) {
            $master = "(";
            foreach ($tmpHist_0 as $row0) {
                $master .= "'$row0->id_master',";
            }
            $master = rtrim($master, ",");
            $master .= ")";
            //           // ambil dari id master
            $trHis = new MdlTransaksi();
            if (strlen($master) > 2) {
                $trHis->addFilter("id_master in $master");
            }

            $tmpHist = $trHis->lookupRecentHistories($limitHistory)->result();
            // showLast_query("orange");
            $arrTransID = array();
            $arrTransTopID = array();
            $arrIdsHist = array();
            $arrTransHist = array();
            $arrNextAction = array();
            foreach ($tmpHist as $row) {
                $arrTransID[] = $row->id;
                $arrTransTopID[] = $row->id_top;
                //                $arrNextAction[$row->id] = array(
                //                    "next_step_num" => $row->next_step_num,
                //                    "next_step_code" => $row->next_step_code,
                //                );
                if ($row->ids_his != "") {
                    $hist = blobDecode($row->ids_his);
                    foreach ($hist as $hisSpec) {
                        $arrIdsHist[$row->id][$hisSpec['step']] = array(
                            "step" => $hisSpec['step'],
                            "trID" => $hisSpec['trID'],
                            "nomer" => $hisSpec['nomer'],
                        );
                        $arrTransHist[] = $hisSpec['trID'];
                    }
                }
            }
            $tmpReg_result = array();
            $trReg = new MdlTransaksi();
            $trReg->setFilters(array());
            $trReg->addFilter("param='main'");
            $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
            $tmpReg = $trReg->lookupRegistries()->result();

            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $regRow) {
                    $param = $regRow->param;
                    $tmpReg_result[$regRow->transaksi_id][$param] = blobDecode($regRow->values);
                }
            }
            if (sizeof($arrIdsHist) > 0) {
                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $tr->addFilter("id in ('" . implode("','", $arrTransHist) . "')");
                $tmpTransHist = $tr->lookupAll()->result();


                if (sizeof($tmpTransHist) > 0) {
                    foreach ($tmpTransHist as $histSpec) {
                        $tmpTransHist_result[$histSpec->id] = array(
                            "oleh_id" => $histSpec->oleh_id,
                            "oleh_nama" => $histSpec->oleh_nama,
                        );
                    }
                }

                foreach ($arrIdsHist as $trID => $histSpec) {
                    foreach ($histSpec as $step => $detailSpec) {
                        if (array_key_exists($detailSpec['trID'], $tmpTransHist_result)) {
                            $detailSpec['main'] = $tmpTransHist_result[$detailSpec['trID']];
                        }
                        $arrTransMainHist[$trID][$step] = $detailSpec;
                    }
                }
            }

            //            arrprintWebs($tmpHist);

            foreach ($tmpHist as $row) {
                if (sizeof($pairRegistries) > 0) {
                    if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->id]))) {
                        foreach ($tmpReg_result[$row->id] as $param => $eReg) {
                            foreach ($eReg as $k => $v) {
                                if (!isset($row->$k)) {
                                    $row->$k = $v;
                                }
                            }
                        }
                    }
                }
                $tmp = array();
                $tmp['dtime'] = $row->dtime;
                foreach ($historyFields as $fName => $fLabel) {
                    if (is_array($fLabel)) {
                        $hisStep = $fLabel['step'];
                        $hisKey = $fLabel['key'];

                        if (isset($row->ids_his)) {
                            $returnVal = showHistoriGlobalNumbers($row->ids_his, $hisStep, true);
                            if ($returnVal == "") {
                                $tmp[$fName] = "-";
                            }
                            else {
                                $tmp[$fName] = $returnVal;
                            }
                        }
                        else {
                            $tmp[$fName] = "-";
                        }
                    }
                    else {
                        $tmp[$fName] = isset($row->$fName) ? formatField($fName, $row->$fName) : formatField($fName, 0);
                    }
                }
                $tmp['next_pic'] = "-";


                $arrayHistory[] = $tmp;
            }
        }


        //arrPrint($arrayHistory);
        //endregion


        //region link to add new transaction

        //tambahin hak akses custom

        if (placeCanMakeTrans($this->session->login['membership'], $this->session->login['cabang_id'], $this->session->login['gudang_id'], $this->jenisTr)) {
            //        if (in_array($this->configUi[$jenisTr]["steps"][1]['userGroup'], $this->session->login['membership'])) {
            $createIndexes = (null != $this->config->item("transaksi_createIndex")) ? $this->config->item("transaksi_createIndex") : array();
            $isDisableMakeTrans = isset($this->configUi[$this->jenisTr]['isDisableMakeTrans']) ? $this->configUi[$this->jenisTr]['isDisableMakeTrans'] : false;
            if (array_key_exists($this->jenisTr, $createIndexes)) {
                $targetUrl = base_url() . $createIndexes[$this->jenisTr] . "/" . $this->jenisTr;
            }
            else {
                $targetUrl = base_url() . "Transaksi/createForm/" . $this->jenisTr;
            }

            if ($isDisableMakeTrans) {
                $addLink = null;
                //                $_SESSION['errMsg'] = "test error dari 1982";
                //                arrPrint( $this->session->errMsg );
            }
            else {
                $addLink = array(
                    "link" => $targetUrl,
                    "label" => "<span class='glyphicon glyphicon-plus'></span> create new " . $this->configUi[$jenisTr]["steps"][1]['label'],
                );
            }

        }
        else {
            $addLink = null;
        }
        //endregion

        //region generate activity reports
        $this->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();
        $tr->addFilter("transaksi.cabang_id='" . $this->session->login['cabang_id'] . "'");
        $tr->addFilter("jenis_master='" . $this->jenisTr . "'");
        $tr->addFilter("month(dtime)='" . date("m") . "'");
        $tr->addFilter("year(dtime)='" . date("Y") . "'");
        $tr->addFilter("day(dtime)='" . date("d") . "'");
        if (sizeof($tmpHist_0) > 0) {
            if (strlen($master) > 2) {
                $tr->addFilter("id_master in $master");
            }
        }


        $tmpRecap = $tr->lookupAll()->result();
        //                cekHijau($this->db->last_query());
        //                arrprint(sizeof($tmpRecap));
        //arrPrint($tmpRecap);
        $sumFields = isset($this->config->item("heTransaksi_layout")[$this->jenisTr]['reportSumFields']) ? $this->config->item("heTransaksi_layout")[$this->jenisTr]['reportSumFields'] : array();
        $arrayRecap = array();

        foreach ($this->configUi[$this->jenisTr]['steps'] as $stepSpec) {
            $recapCodes[$stepSpec['target']] = "<a href='" . base_url() . get_class($this) . "/viewHistory/" . $this->jenisTr . "/" . $stepSpec['target'] . "'>" . $stepSpec['label'] . "</a>";
        }
        $recapProp = array();
        $entities = array();
        if (sizeof($tmpRecap) > 0) {
            foreach ($tmpRecap as $row) {
                //cekHere($row->id);

                if (isset($sumFields) && sizeof($sumFields) > 0) {
                    foreach ($sumFields as $idField => $nameField) {
                        if (!array_key_exists($row->$idField, $entities)) {
                            $entities[$row->$idField] = $row->$nameField;
                        }
                        if (!isset($recapProp[$row->jenis][$row->$idField])) {
                            $recapProp[$row->jenis][$row->$idField] = array(
                                "freq" => 0,
                                "value" => 0,
                            );
                        }
                        $recapProp[$row->jenis][$row->$idField]['freq'] += 1;
                        $recapProp[$row->jenis][$row->$idField]['value'] += $row->transaksi_nilai;
                    }
                }
            }
        }


        if (sizeof($entities) > 0) {
            foreach ($entities as $eID => $eName) {
                $tmp = array();
                $tmp["name"] = $eName;
                foreach ($recapCodes as $cID => $cName) {
                    $fieldValue = isset($recapProp[$cID][$eID]['value']) ? $recapProp[$cID][$eID]['value'] : 0;
                    $tmp[$cID] = "<span class='btn-block text-right'>" . number_format($fieldValue) . "</span>";
                }
                $arrayRecap[] = $tmp;
            }
        }

        $recapLabels['name'] = isset($this->config->item('heTransaksi_ui')[$this->jenisTr]['pihakLabel']) ? $this->config->item('heTransaksi_ui')[$this->jenisTr]['pihakLabel'] : "label";
        $recapLabels = $recapLabels + $recapCodes;
        //endregion

        $mobileSupport = isset($this->configUi[$this->jenisTr]["mobileSupport"]) ? $this->configUi[$this->jenisTr]["mobileSupport"] : false;

        //region prepare params to viewer
        $data = array(
            "mode" => $this->uri->segment(2),
            "isMobile" => $isMob,
            "mobileSupport" => $mobileSupport,
            "errMsg" => $this->session->errMsg,
            "template" => $this->configUi[$jenisTr]["template"],
            "title" => $this->configUi[$jenisTr]["label"],
            "subTitle" => $this->configUi[$jenisTr]["steps"][1]['label'],
            "jenisTr" => $jenisTr,
            "trName" => $this->configUi[$jenisTr]["label"],
            'addLink' => $addLink,
            //            "historyTitle" => "<span class='glyphicon glyphicon-time'></span> " . $this->configUi[$jenisTr]["label"] . " histories",
            "historyTitle" => "<span class='glyphicon glyphicon-time'></span> recent " . $this->configUi[$jenisTr]["label"] . " histories",
            "arrayHistoryLabels" => array("dtime" => "time") + $historyFields,
            "arrayHistory" => $arrayHistory,
            "onprogressTitle" => "<span class='glyphicon glyphicon-alert'></span> incomplete " . $this->configUi[$jenisTr]["label"],
            "arrayProgressLabels" => $progressFields,
            "arrayOnProgressToPay" => $paymentConfig,
            "stepHistoryFields" => array(),
            // ---
            "onprogressViewTitle" => "<span class='fa fa-eye'></span> show incomplete step " . $this->configUi[$jenisTr]["label"],
            // "arrayProgressViewLabels" => $progressFields,
            "arrayOnProgressView" => $arrayOnProgressView,
            "connectTo" => $connectTo,
            "kepoinFields" => $kepoinFields,
            //--
            "itemLabels" => isset($itemLabels) ? $itemLabels : "",
            "srcLabel" => isset($srcLabel) ? $srcLabel : "",
            "arrayOnProgress" => $arrayOnprogress,
            "arrayOnProgressTransaksi" => $arrayOnprogressTransaksi,
            "arrayOnProgressTransaksiKoloms" => $arrayOnprogressTransaksiKoloms,
            "shoppingCartPerTransaksiBtn" => $shoppingCartPerTransaksiBtn,
            "entities" => $entities,
            //            "recapTitle" => "<span class='fa fa-newspaper-o'></span> today " . $this->configUi[$jenisTr]["label"] . " reports (" . date("F Y") . ")",
            "recapTitle" => "<span class='fa fa-newspaper-o'></span> today " . $this->configUi[$jenisTr]["label"] . " reports",
            "arrayRecapLabels" => $recapLabels,
            "arrayRecap" => $arrayRecap,
            "warning" => $warning,
            "showBtnSettlement" => $settleBtnShow,

        );
        //endregion

        $this->load->view("transaksi", $data);

    }

    public function validate()
    {
        $fieldOpnameEntryValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartFieldOpnameEntryValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartFieldOpnameEntryValidators"] : array();
        $fieldOpnameValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartFieldOpnameValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartFieldOpnameValidators"] : array();

        $fieldValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartFieldValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartFieldValidators"] : array();
        $rowValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartRowValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartRowValidators"] : array();
        $rowNumValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartRowNumValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartRowNumValidators"] : array();
        $rowOptValidatorRules = isset($this->configUi[$this->jenisTr]["shoppingCartRowOptionalValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartRowOptionalValidators"] : array();
        $validateReceiveElement = isset($this->configUi[$this->jenisTr]["validateReceiveElement"][1]) ? $this->configUi[$this->jenisTr]["validateReceiveElement"][1] : array();
        $appletConfigs = isset($this->configUi[$this->jenisTr]['applets']) ? $this->configUi[$this->jenisTr]['applets'] : array();
        $elementConfigs = isset($this->configUi[$this->jenisTr]['receiptElements']) ? $this->configUi[$this->jenisTr]['receiptElements'] : array();
        $relElementConfigs = isset($this->configUi[$this->jenisTr]['relativeElements']) ? $this->configUi[$this->jenisTr]['relativeElements'] : array();
        $availPayments = isset($this->configUi[$this->jenisTr]['availPayments']) ? $this->configUi[$this->jenisTr]['availPayments'] : array();
        $validateAdditional = isset($this->configUi[$this->jenisTr]['shopingCartAddValidator']['additional']) ? $this->configUi[$this->jenisTr]['shopingCartAddValidator']['additional'] : array();
        $fieldValidatorsComparison = isset($this->configUi[$this->jenisTr]['shoppingCartFieldValidatorsComparison']) ? $this->configUi[$this->jenisTr]['shoppingCartFieldValidatorsComparison'] : array();

        $fieldValidatorPairedItem = isset($this->configUi[$this->jenisTr]["shoppingCartValidatorsPairedItem"]) ? $this->configUi[$this->jenisTr]["shoppingCartValidatorsPairedItem"] : array();
        $unionValidateComparison = isset($this->configUi[$this->jenisTr]["shopingCartUnionComparison"]) ? $this->configUi[$this->jenisTr]["shopingCartUnionComparison"] : array();
        $unionValidate = isset($this->configUi[$this->jenisTr]["shoppingCartUnionValidators"]) ? $this->configUi[$this->jenisTr]["shoppingCartUnionValidators"] : array();
        $balanceValidate = isset($this->configUi[$this->jenisTr]["shoppingCartBalanceValidate"]) ? $this->configUi[$this->jenisTr]["shoppingCartBalanceValidate"] : array();
        $previewCtr = isset($this->configUi[$this->jenisTr]["previewCtr"]) ? $this->configUi[$this->jenisTr]["previewCtr"] : matiHere('controller preview belum diset');


        $cCode = $this->cCode;
        $this->pairSesionValidate(1);
        $rawPrevURL = isset($_GET['rawPrev']) ? $_GET['rawPrev'] : "";
        // mati_disini(__CLASS__ . " $cCode");
        //==iterasi untuk memasukkan element relatif
        if (isset($_SESSION[$cCode]['main_elements']) && sizeof($_SESSION[$cCode]['main_elements']) > 0) {
            //            //cekBiru("hendak memeriksa relative impacts");
            foreach ($_SESSION[$cCode]['main_elements'] as $eName => $eSpec) {
                //                //cekBiru("memeriksa $eName:");
                if (array_key_exists($eName, $relElementConfigs)) {
                    //                    //cekHijau("$eName memiliki relative impacts");
                    $currentValue = "";
                    switch ($eSpec['elementType']) {
                        case "dataModel":
                            $currentValue = $eSpec['key'];
                            break;
                        case "dataField":
                            $currentValue = $eSpec['value'];
                            break;
                    }
                    if (array_key_exists($currentValue, $relElementConfigs[$eName])) {
                        //                        //cekHijau("memenuhi syarat");
                        //===daftarkan ke elementConfig
                        if (sizeof($relElementConfigs[$eName][$currentValue]) > 0) {
                            //                            //cekMerah("memeriksa $eName, $currentValue");
                            //                            $rcCtr = 0;
                            foreach ($relElementConfigs[$eName][$currentValue] as $rcID => $rcSpec) {
                                //                                $elKey = $eName . "_" . $currentValue . "_" . $rcID;
                                $elKey = $rcID;
                                $elementConfigs[$elKey] = $relElementConfigs[$eName][$currentValue][$rcID];
                                //                                $rcCtr++;
                            }
                        }

                    }
                    else {
                        //                        //cekMerah("TIDAK memenuhi syarat");
                    }
                }
            }
        }
        $arrySegment = $this->uri->segment_array();
        if (isset($_SESSION[$cCode]['mode']['edit']) && sizeof($_SESSION[$cCode]['mode']['edit']) > 0) {
            $prevAction = $previewCtr . "/editPreview";
            $main_id = "/" . $_SESSION[$cCode]['mode']['edit'];
        }
        else {
            if (isset($_SESSION[$cCode]['mode']['cancel']) && sizeof($_SESSION[$cCode]['mode']['cancel']) > 0) {
                $prevAction = "Transaksi/preCancelPackingPreview";
                $main_id = "/" . $_SESSION[$cCode]['mode']['cancel'];
            }
            else {
                $prevAction = $previewCtr . "/preview";
                $main_id = "";
            }
        }
// mati_disini($prevAction);

        $errMsgs = array();
        $errLines = array();
        $errFields = array();
        $errRows = array();
        $errErrorException = array();
        if (sizeof($rowValidatorRules) > 0) {

            foreach ($rowValidatorRules as $field => $label) {
                if (!isset($_SESSION[$cCode]['main'][$field])) {
                    $errMsgs[] = "$label wajib diisi";

                    $errRows[] = $field;
                }

            }

        }
        if (sizeof($rowNumValidatorRules) > 0) {

            foreach ($rowNumValidatorRules as $field => $label) {
                if (!isset($_SESSION[$cCode]['main'][$field])) {
                    $errMsgs[] = "$label wajib dilengkapi";

                    $errRows[] = $field;
                }
                else {
                    if (0 + ($_SESSION[$cCode]['main'][$field]) < 0.1) {
                        $errMsgs[] = "$label should be a number";

                        $errRows[] = $field;
                    }
                }

            }

        }
        if (sizeof($rowOptValidatorRules) > 0) {
            foreach ($rowOptValidatorRules as $srcName => $srcSpec) {
                foreach ($srcSpec as $value => $pair) {
                    if (isset($_SESSION[$cCode]['main'][$srcName]) && $_SESSION[$cCode]['main'][$srcName] == $value) {
                        foreach ($pair as $k => $v) {
                            if (!isset($_SESSION[$cCode]['main'][$k])) {
                                $errMsgs[] = "$k is required";

                                $errRows[] = $k;
                            }
                        }
                    }
                }
            }
        }
        if (sizeof($fieldValidatorRules) > 0) {

            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                foreach ($_SESSION[$cCode]['items'] as $xid => $iSpec) {
                    $id = $iSpec['id'];
                    $nama = htmlspecialchars($iSpec['name']);
                    if ((isset($iSpec['disabled']) && $iSpec['disabled'] == "0") || !isset($iSpec['disabled'])) {
                        if (!isset($errFields[$id])) {
                            $errFields[$id] = array();
                        }
                        foreach ($fieldValidatorRules as $field => $label) {
                            if (!isset($iSpec[$field])) {
                                $errMsgs[] = "$label wajib diisi";
                                $errLines[] = $id;
                                $errFields[$id][] = $field;
                            }
                            if (!is_numeric($iSpec[$field])) {
                                $errMsgs[] = "$label must be a valid number";
                                $errLines[] = $id;
                                $errFields[$id][] = $field;
                            }
                            if ((int)$iSpec[$field] < 0.5) {
                                $errMsgs[] = "$label must be > 0";
                                $errLines[] = $id;
                                $errFields[$id][] = $field;
                            }
                        }
                    }

                }
            }

        }
        if (sizeof($elementConfigs) > 0) {
            foreach ($elementConfigs as $eName => $aSpec) {
                if (!isset($_SESSION[$cCode]['main_elements'][$eName])) {
                    if ((isset($aSpec['noValidate'])) && ($aSpec['noValidate'] == true)) {
                    }
                    else {
                        $errMsgs[] = ($aSpec['label'] . " wajib dipilih!");
                        echo "<script>";
                        echo "if(top.document.getElementById('elTitle_$eName')){top.document.getElementById('elTitle_$eName').className='box-headers text-red text-left'};";
                        echo "</script>\n";
                    }
                }
                else {
                    switch ($aSpec['elementType']) {
                        case "dataModel":
                            if (isset($validateReceiveElement[$eName]) && sizeof($validateReceiveElement[$eName])) {
                                $valid = 0;
                                $check = array();
                                foreach ($validateReceiveElement[$eName] as $tLabel => $textWarning) {
                                    if (strlen($_SESSION[$cCode]['main'][$eName . '__' . $tLabel]) > 10) {
                                    }
                                    else {
                                        $check[] = $tLabel;
                                    }
                                }
                                if (sizeof($check) > 1) {
                                    $errMsgs[] = ("Harap lengkapi salah satu NPWP/KTP diBillingDetails customer");
                                    foreach ($check as $nLabel) {
                                        $errMsgs[] = ("lengkapi $nLabel!");
                                    }
                                }
                            }

                            if (strlen($_SESSION[$cCode]['main_elements'][$eName]['key']) < 0.5) {
                                $errMsgs[] = ("element " . $aSpec['label'] . " must be filled with one entry!");
                                echo "<script>";
                                echo "if(top.document.getElementById('elTitle_$eName')){top.document.getElementById('elTitle_$eName').className='box-headers text-red text-left'};";
                                echo "</script>\n";
                            }
                            else {
                                echo "<script>";
                                echo "if(top.document.getElementById('elTitle_$eName')){top.document.getElementById('elTitle_$eName').className='box-headers bg-grey text-left'};";
                                echo "</script>\n";
                            }
                            break;
                        case "dataField":
                            if (strlen($_SESSION[$cCode]['main_elements'][$eName]['value']) < 0.5) {
                                if ((isset($aSpec['noValidate'])) && ($aSpec['noValidate'] == true)) {
                                }
                                else {
                                    $errMsgs[] = ($aSpec['label'] . " must be filled with one entry!***");
                                    echo "<script>";
                                    echo "if(top.document.getElementById('elTitle_$eName')){top.document.getElementById('elTitle_$eName').className='box-headers text-red text-left'};";
                                    echo "</script>\n";
                                }

                            }
                            else {
                                echo "<script>";
                                echo "if(top.document.getElementById('elTitle_$eName')){top.document.getElementById('elTitle_$eName').className='box-headers bg-grey text-left'};";
                                echo "</script>\n";
                            }
                            break;
                    }

                }
            }
        }
        if (sizeof($fieldValidatorsComparison) > 0) {
            $result = array();
            $labels = array();
            foreach ($fieldValidatorsComparison as $field => $label) {
                $labels[$label] = $field;
                $result[$label] = isset($_SESSION[$cCode]['main'][$field]) ? $_SESSION[$cCode]['main'][$field] : 0;
            }

            if (round($result["sumber"], 2) != round($result["target"], 2)) {
                $labelSrc = isset($labels["sumber"]) ? $labels["sumber"] : "";
                $labelTarget = isset($labels["target"]) ? $labels["target"] : "";
                $errMsgs[] = "Nilai total tidak sama dari nilai akumulasi nota yang dipilih.";
                $errRows[] = "test";
            }


        }
        if (sizeof($unionValidateComparison) > 0) {
            $result = array();
            $labels = array();
            $validate = 0;
            $val = array();
            $valsValidate = array();

            foreach ($unionValidateComparison as $fieldData) {

                if (isset($_SESSION[$cCode]['main']["nilai_entry"])) {
                    if ($_SESSION[$cCode]['main']["nilai_entry"] > 0) {

                    }
                    else {
                        if ($_SESSION[$cCode]['main']["nilai_entry"] == 0) {
                            unset($_SESSION[$cCode]['main']["nilai_entry"]);
                        }
                        else {

                            if (sizeof($unionValidate) > 0) {

                                foreach ($unionValidate as $fieldUnion) {
                                    $validateUnion = 0;
                                    foreach ($fieldUnion as $field => $fieldLabel) {
                                        if (isset($_SESSION[$cCode]['main'][$field]) && $_SESSION[$cCode]['main'][$field] > 0) {

                                        }
                                        else {
                                            $validateUnion++;

                                        }
                                    }
                                    if (sizeof($fieldUnion) == $validateUnion) {
                                        $errMsgs[] = $fieldData["nilai_entry"];
                                    }
                                }
                            }
                            else {
                                $errMsgs[] = $fieldData["nilai_entry"];
                            }
                        }

                    }
                }
                else {
                    if (sizeof($unionValidate) > 0) {

                        foreach ($unionValidate as $fieldUnion) {
                            $validateUnion = 0;
                            $err = array();
                            foreach ($fieldUnion as $field => $fieldLabel) {
                                if (isset($_SESSION[$cCode]['main'][$field]) && $_SESSION[$cCode]['main'][$field] > 0) {

                                }
                                else {
                                    $validateUnion++;
                                    $err[] = $fieldLabel;

                                }
                            }
                            if (sizeof($err) == sizeof($fieldUnion)) {
                                $errMsgs[] = "metode pembayaran tidak ada yang dipilih, silahkan periksa kembali";
                            }
                        }
                    }
                    else {
                        $errMsgs[] = $fieldData["nilai_entry"];
                    }
                }

                foreach ($fieldData as $field => $label) {

                    //                    if (isset($_SESSION[$cCode]['main'][$field]) && ($_SESSION[$cCode]['main'][$field] > 0)) {
                    if (isset($_SESSION[$cCode]['main'][$field])) {
                        //cekHere("ada $field dan nilai $field tidak sama dengan nol ");
                        $validate++;
                        $val["source"] = $field;
                        $valsValidate["source"][] = $field;
                    }
                    else {
                        //cekHere("TIDAK ada $field  ");
                        $val["target"] = $field;
                        $valsValidate["target"][] = $field;
                    }
                }

            }
            //arrPrint($unionValidateComparison);
            //arrPrint($valsValidate);


            if (array_key_exists("source", $val)) {
                $cekval = $val["target"];
                if (!isset($_SESSION[$cCode]['main'][$cekval])) {
                    foreach ($unionValidateComparison as $data) {
                        //                        //cekHere(":: sampai sini $cekval :: " . $data[$cekval]);
                        if (isset($data[$cekval])) {
                            $errMsgs[] = $data[$cekval];
                            $errErrorException[] = $data[$cekval];
                        }
                    }
                }
                //arrPrint($errMsgs);
            }
            // arrPrint($valsValidate);
            if (!isset($valsValidate["source"]) || (sizeof($valsValidate["source"]) == 0)) {
                // mati_disini("tidak memilih cash account, credit note, uang muka");
                //  $errMsgs[] = "cash account, credit note, uang muka tidak ada yang dipilih.";
            }

        }
        if (sizeof($fieldValidatorPairedItem) > 0) {
            $label = $this->configUi[$this->jenisTr]["label"];
            $source = isset($_SESSION[$cCode][$fieldValidatorPairedItem['sumber']]) ? $_SESSION[$cCode][$fieldValidatorPairedItem['sumber']] : "";
            $target = isset($_SESSION[$cCode][$fieldValidatorPairedItem['target']]) ? $_SESSION[$cCode][$fieldValidatorPairedItem['target']] : "";
            if (sizeof($source) > 0) {
                foreach ($source as $pID => $pSpec) {
                    $pTarget = isset($target[$pID]) ? $target[$pID] : array();

                    if (!array_key_exists($pID, $target)) {
                        $errMsgs[] = "$label " . $pSpec['name'] . " is required.";
                    }
                    if (isset($pTarget['jml']) && isset($pSpec['jml'])) {
                        if ($pTarget['jml'] < $pSpec['jml']) {
                            $errMsgs[] = "konversi " . $pSpec['name'] . " salah. silahkan cek ulang jumlah konversinya.";
                        }
                        $jml_satuan = $pTarget['jml'] / $pSpec['jml'];
                        $jml_satuan_ex = explode(".", $jml_satuan);
                        if (sizeof($jml_satuan_ex) > 1) {
                            $errMsgs[] = "konversi " . $pSpec['name'] . " salah. silahkan cek ulang jumlah konversinya.";
                        }
                    }
                }
            }
        }
        if (sizeof($fieldOpnameValidatorRules) > 0) {
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                foreach ($_SESSION[$cCode]['items'] as $xid => $iSpec) {
                    $id = $iSpec['id'];
                    $name = htmlspecialchars($iSpec['nama']);
                    if ((isset($iSpec['disabled']) && $iSpec['disabled'] == "0") || !isset($iSpec['disabled'])) {
                        foreach ($fieldOpnameValidatorRules as $field => $label) {
                            if (isset($iSpec['qty_selisih']) && ($iSpec['qty_selisih'] > 0)) {
                                if ((int)$iSpec[$field] <= 0) {
                                    $errMsgs[] = "$label $name must be > 0";
                                    $errLines[] = $id;
                                    $errFields[$id][] = $field;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (sizeof($fieldOpnameEntryValidatorRules) > 0) {
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                $no = 0;
                foreach ($_SESSION[$cCode]['items'] as $xid => $iSpec) {
                    $no++;
                    $id = $iSpec['id'];
                    $kode = $iSpec['produk_kode'];
                    $label = $iSpec['label'];

                    $name = htmlspecialchars($iSpec['nama']);
                    if ((isset($iSpec['disabled']) && $iSpec['disabled'] == "0") || !isset($iSpec['disabled'])) {
                        foreach ($fieldOpnameEntryValidatorRules as $field => $label) {
                            if (!isset($iSpec[$field]) && ($iSpec['stok'] > 0)) {
                                $errMsgs[] = "$label $name harus diketik ulang, baris nomer $no.";
                                $errLines[] = $id;
                                $errFields[$id][] = $field;

                            }
                        }
                    }

                    $stokBuku = isset($iSpec->stok) ? $iSpec->stok : 0;
                    $stokOpname = $iSpec->qty_opname;
                    $selisih = $stokOpname - $stokBuku;
                    $stokBukuHitung = $iSpec->qty_opname - $iSpec->qty_debet + $iSpec->qty_kredit;
                    if ($selisih < 0) {
                        if ($selisih != $iSpec->qty_kredit) {
                            $msg = "Produk $label $kode SALAH. Silahkan diperiksa baris nomer $no.";
                            $errMsgs[] = $msg;
                        }
                    }
                    elseif ($selisih > 0) {
                        if ($selisih != $iSpec->qty_debet) {
                            $msg = "Produk $label $kode SALAH. Silahkan diperiksa baris nomer $no.";
                            $errMsgs[] = $msg;
                        }
                    }
                    elseif ($stokBukuHitung != $stokBuku) {
                        $msg = "Produk $label $kode SALAH. Silahkan diperiksa baris nomer $no.";
                        $errMsgs[] = $msg;
                    }
                    //                    else{
                    //                        mati_disini("Produk $label $kode SALAH. Silahkan diperiksa baris nomer $no.");
                    //                    }
                }
            }
        }

        //region validate additional
        if (sizeof($validateAdditional) > 0) {
            $selectedAdd = $_SESSION[$cCode]["main"]["additional"];
            if (isset($validateAdditional[$selectedAdd])) {
                $valKey = $validateAdditional[$selectedAdd];
                if ($_SESSION[$cCode]["main"][$valKey] == 0) {
                    $errMsgs[] = "additional kurs must be filled or select none on additional for additional kurs 0 ";
                }
            }

        }
        //        matiHEre();

        //endregion

        if (sizeof($balanceValidate) > 0) {
            foreach ($balanceValidate as $kk => $kSpec) {
                if ($kk == "key") {
                    $debet = $kSpec[0];
                    $kredit = $kSpec[1];
                    $debetNilai = isset($_SESSION[$cCode]['main'][$debet]) ? $_SESSION[$cCode]['main'][$debet] : 0;
                    $kreditNilai = isset($_SESSION[$cCode]['main'][$kredit]) ? $_SESSION[$cCode]['main'][$kredit] : 0;
                    if ($debetNilai != $kreditNilai) {
                        $errMsgs[] = $balanceValidate['label'];
                    }
                }
            }
        }
        // arrPrintBlue($_SESSION[$cCode]['tableIn_detail']);
        // mati_disini(__LINE__);
        // always validation active
        $gateNameDetail = "tableIn_detail";
        if (!isset($_SESSION[$cCode][$gateNameDetail]) || sizeof($_SESSION[$cCode][$gateNameDetail]) == 0) {

            $msg = "Transaksi gagal dilanjutkan karena rincian transaksi kosong.<br>Silahkan merubah qty/unit price dahulu dan masukkan data yang benar supaya transaksi bisa dilanjutkan. @" . __LINE__ . __METHOD__;
            mati_disini($msg);
        }
        else {
            foreach ($_SESSION[$cCode][$gateNameDetail] as $spec) {
                if (!isset($spec['valid_qty'])) {
                    $hidden_msg = "<br><span style='color:#ffffff;'>gerbang valid_qty tidak ada</span>";
                    $msg = "Transaksi gagal dilanjutkan karena rincian transaksi kosong.<br>Silahkan merubah qty/unit price dahulu dan masukkan data yang benar supaya transaksi bisa dilanjutkan. $hidden_msg";
                    mati_disini($msg);
                }
                else {
                    if ($spec['valid_qty'] == 0) {
                        $hidden_msg = "<br><span style='color:#ffffff;'>gerbang valid_qty bernilai 0</span>";
                        $msg = "Transaksi gagal dilanjutkan karena rincian transaksi kosong.<br>Silahkan merubah qty/unit price dahulu dan masukkan data yang benar supaya transaksi bisa dilanjutkan. $hidden_msg";
                        mati_disini($msg);
                    }
                }
            }
        }


        /* ------------------------------
         * validasi stok saat mau produksi
         * ------------------------------*/
        $mains = $_SESSION[$cCode];

        $items2_sum = isset($mains['items2_sum']) ? $mains['items2_sum'] : "";
        switch ($this->jenisTr) {
            case "776":

                $kurangStoks = array();
                $hasil = "";
                $no = 0;
                foreach ($items2_sum as $pId => $item) {

                    $nama = $item['nama'];
                    $sisa = $item['stok'] - $item['jml'];

                    if ($sisa < 0) {
                        $no++;
                        $kurangStoks[$pId] = $sisa;
                        //
                        $sisa_f = $sisa * -1;
                        $nama_f = htmlspecialchars($nama);
                        $var = "<span class='font-size-0-7'>$no. $nama_f: <span class='text-bold'>$sisa_f</span></span>";
                        if ($hasil == "") {
                            $hasil = "$var";
                        }
                        else {
                            $hasil = "$hasil<br>$var";
                        }
                    }
                }


                if (sizeof($kurangStoks) > 0) {
                    // //cekhitam(sizeof($kurangStoks));
                    $alerts = array("type" => "warning",
                        "title" => "Persediaan tidak cukup",
                        "html" => $hasil,
                    );
                    echo swalAlert($alerts);
                    die();
                }

                break;
            case "1982":
                break;
            case "961":
            case "967":
                $items = $mains['items'];
                $kurangStoks = array();
                $hasil = "";
                $no = 0;
                foreach ($items as $pId => $item) {
                    if (isset($item['stok'])) {
                        $nama = $item['nama'];
                        $sisa = $item['stok'] - $item['jml'];

                        if ($sisa < 0) {
                            $no++;
                            $kurangStoks[$pId] = $sisa;

                            $sisa_f = $sisa * -1;
                            $stok_f = $item['stok'];
                            $jml_f = $item['jml'];
                            $nama_f = htmlspecialchars($nama);
                            $var = "<span class='font-size-0-7'>$no. <span style='font-weight:bold;'>$nama_f</span>, stok tersedia $stok_f, jumlah input <span style='font-weight:bold;'>$jml_f</span> melebihi stok yang tersedia. Silahkan dikoreksi lagi.</span>";
                            if ($hasil == "") {
                                $hasil = "$var";
                            }
                            else {
                                $hasil = "$hasil<br>$var";
                            }
                        }
                    }
                }
                if (sizeof($kurangStoks) > 0) {

                    $alerts = array("type" => "warning",
                        "title" => "Insufficient stock",
                        "html" => $hasil,
                    );
                    echo swalAlert($alerts);
                    die();
                }

                break;
            case "749":
                if ($_SESSION[$cCode]['main']['lebih_bayar'] <= 0) {
                    //                    matiHEre("iki opoo ".$_SESSION[$cCode]['main']['lebih_bayar']);
                    $_SESSION[$cCode]['main']['nilai_cash'] = $_SESSION[$cCode]['main']['nilai_entry'];
                    //arrPrint($errErrorException);
                    if (sizeof($errErrorException) > 0) {
                        foreach ($errErrorException as $errKey => $errVal) {
                            if (array_key_exists($errKey, $errMsgs)) {
                                unset($errMsgs[$errKey]);
                            }
                        }
                    }

                }

                break;
        }

        if (sizeof($errMsgs) > 0) {
            $_SESSION['errMsg'] = implode("<br>", $errMsgs);

            if (sizeof($errLines) > 0) {
                $_SESSION['errLines'] = $errLines;
            }

            if (sizeof($errFields) > 0) {
                $_SESSION['errFields'] = $errFields;
            }


            echo lgShowAlert($_SESSION['errMsg']);
            die();
        }
        else {

            // mati_disini("LOLOS, tidak kena VALIDATE :: $prevAction");
            // $shoppingCart =  base_url() . $this->modul . "/" . $prevAction . "/" . $this->jenisTr . "?rawPrev=$rawPrevURL";

            $actionTarget = "top.BootstrapDialog.show({
                                title:'preview',
                                message: " . 'top.$' . "('<div></div>').load('" . base_url() . $this->modul . "/" . $prevAction . "/" . $this->jenisTr . "?rawPrev=$rawPrevURL'),
                                draggable:false,
                                size:top.BootstrapDialog.SIZE_WIDE,
                                type:top.BootstrapDialog.TYPE_DEFAULT,
                                closable:true,
                                }
                             );";

            echo "<script>top.close_holdon();$actionTarget</script>";

        }
    }

    public function pairSesionValidate($step)
    {
        // matiHEre(__LINE__);
        $fieldItemValueRules = isset($this->configUi[$this->jenisTr]["shopingCartValidatePairSession"][$step]) ? $this->configUi[$this->jenisTr]["shopingCartValidatePairSession"][$step] : array();
        $fieldValidate = isset($this->configUi[$this->jenisTr]["shopingCartValidatePairSession"][$step]["validate"]) ? $this->configUi[$this->jenisTr]["shopingCartValidatePairSession"][$step]["validate"] : array();
        $cCode = $this->cCode;
        // $this->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";
        // mati_disini();
        // arrPrint($fieldItemValueRules);
        // matiHEre();
        if (sizeof($fieldItemValueRules) > 0) {
            $source = $fieldItemValueRules['source'];
            $target = $fieldItemValueRules['target'];
            $sourceData = $_SESSION[$cCode][$source];
            $targetData = $_SESSION[$cCode][$target];
            $fieldsSource = $fieldValidate["source"];
            $fieldstarget = $fieldValidate["target"];
            //            arrPrint($targetData);
            $errMsgs = array();
            foreach ($targetData as $Cid => $tmpData) {
                $tmpError = array();
                foreach ($tmpData as $PID => $tmpVal) {
                    $sourceVal = $sourceData[$PID][$fieldsSource];
                    $targetVal = $tmpVal[$fieldstarget];
                    $minVal = $sourceVal + $sourceVal * 0.025;
                    if ($sourceVal > $targetVal) {
                        //                        $errMsgs[] = "Harga jual ".$sourceData[$PID]['nama']." di ".$cab[$Cid]." lebih rendah dari HPP, silahkan diperbaiki<br>";
                        //                        $tmpError[] = "harga jual ".$sourceData[$PID]['nama']." di ".$cab[$cid]." lebih rendah dari HPP! harga jual harus lebih besar  2,5% dari ".formatfield("nilai",$sourceVal)." ( sebesar ".formatField("nilai",$minVal)." ) harga yang dimasukan saat ini sebesar (".formatField("nilai",$targetVal).") silahkan diperbaiki<br>";
                        $errMsgs[] = "harga jual " . $sourceData[$PID]['nama'] . " lebih rendah dari HPP! harga jual harus lebih besar  2,5% dari " . formatfield("nilai", $sourceVal) . " ( sebesar " . formatField("nilai", $minVal) . " ) harga yang dimasukan saat ini sebesar (" . formatField("nilai", $targetVal) . ") silahkan diperbaiki<br>";
                        // cekHitam($cab[$Cid] . " " . $sourceData[$PID]['nama']);
                    }

                }
                //                $errMsgs[]=$tmpError;
            }
            //arrPrint($errMsgs);
            //            matiHEre();
            if (sizeof($errMsgs) > 0) {
                $_SESSION['errMsg'] = implode("<br>", $errMsgs);
                //                foreach($errMsgs as $errMsg){
                //                    $_SESSION['errMsg'] = implode("<br>", $errMsg);
                //                    echo lgShowAlert($_SESSION['errMsg']);
                //                }

                //                foreach()
                echo lgShowAlert($_SESSION['errMsg']);
                die();
            }

        }
        //        matiHere();
    }

    // public function validate2()
    // {
    //     $cCode = $this->cCode;
    //
    //     $validationRules = isset($this->configUi[$this->jenisTr]['validationRules']) ? $this->configUi[$this->jenisTr]['validationRules'] : array();
    //
    //
    //     $msgWarning = array();
    //     if (isset($validationRules)) {
    //         foreach ($validationRules as $gateName => $gSpec) {
    //             if (isset($_SESSION[$cCode][$gateName])) {
    //                 foreach ($_SESSION[$cCode][$gateName] as $eKey => $eSpec) {
    //                     if (isset($gSpec['target']) && isset($eSpec[$gSpec['target']]) && $eSpec[$gSpec['target']] > 0) {
    //                         if ($eSpec[$gSpec['source']] > $eSpec[$gSpec['target']]) {
    //
    //                             $msg = $gSpec['target'] . " " . $eSpec['nama'] . " tidak cukup.";
    //                             $msgWarning[$eSpec['id']] = array(
    //                                 "id" => "trItems_" . $eSpec['id'],
    //                                 "label" => $msg,
    //                             );
    //                         }
    //                     }
    //                     else {
    //                         $msg = $gSpec['target'] . " " . $eSpec['nama'] . " tidak cukup.";
    //                         $msgWarning[$eSpec['id']] = array(
    //                             "id" => "trItems_" . $eSpec['id'],
    //                             "label" => $msg,
    //                         );
    //                     }
    //                 }
    //             }
    //         }
    //     }
    //
    //     return $msgWarning;
    // }

    public function viewUndoneItems_modul()
    {
        // cekOrange($this->uri->segment_array());
        // cekBiru($this->jenisTr);
        // matiHere();
        $jenisTr = $this->jenisTr;
        $cCode = $this->cCode;
        $historyFields = $this->configUi[$jenisTr]['shortHistoryFields'];
        $pairRegistries = isset($this->configUi[$jenisTr]['pairRegistries']) ? $this->configUi[$jenisTr]['pairRegistries'] : array();
        $dueDateAllow = isset($this->configUi[$jenisTr]['updateDueDate']) ? $this->configUi[$jenisTr]['updateDueDate'] : array();
        $mb = New MobileDetect();
        $isMob = $mb->isMobile();
        if ($isMob) {
            $historyFields = isset($this->configUi[$jenisTr]['compactHistoryFields']) ? $this->configUi[$jenisTr]['compactHistoryFields'] : array();
        }
        $glanceHistoryFields = isset($this->configUi[$jenisTr]['glanceHistoryFields']) ? $this->configUi[$jenisTr]['glanceHistoryFields'] : array("nomer" => "receipt no");
        $glanceHistoryFields2 = array("nomer" => "receipt no"); //init;
        $selectorProcessor = base_url() . $this->configUi[$jenisTr]['selectorProcessor'] . "/$jenisTr";

        //region lookup on-going transactions
        $arrayOnprogress = array();
        $progressFields = $historyFields;

        $progressFields['jenis_label'] = "activity";
        //        $progressFields['nomer'] = "receipt number";
        $progressFields['oleh_nama'] = "started by";
        $progressFields['state'] = "status";
        $progressFields['action'] = "action";

        $steps = $this->configUi[$jenisTr]['steps'];

        $this->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();
        $registryFields = $tr->getRegistryFields();
        if (sizeof($steps) > 1) {

            // cekMerah($this->accessList);
            $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='" . $this->session->login['id'] . "'");
                }
            }
            else {
                foreach ($steps as $stepNumber => $stepSpec) {
                    if ($stepNumber < $jmlStep) {
                        $stepCodes[] = $stepSpec['target'];
                    }

                }
            }

        }


        // $tr->addFilter("div_id='" . (isset($this->session->login['div_id']) ? $this->session->login['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->session->login['membership']) > 0) {
                $this->db->group_start();
                $mCtr = 0;
                foreach ($this->session->login['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();
        // cekLime($this->db->last_query());
        // cekMerah($tmpHist);
        //region due date
        $tr->setFilters(array());
        $listedDue = $tr->lookupAllDueDate()->result();
        $arrDue = array();
        $overDue = array();
        foreach ($listedDue as $dueData) {

            $due_date = strtotime($dueData->due_date);
            $date_now = strtotime(date("Y-m-d"));
            if ($due_date < $date_now) {
                $arrDue[$dueData->transaksi_id] = array(
                    "due_date" => $dueData->due_date,
                    "aging" => umurDay($dueData->due_date),
                );
            }

        }
        //arrPrint($arrDue);
        //arrPrint($tmpHist);
        //endregion
        $arrOver_due = array();


        if (sizeof($tmpHist) > 0) {
            $arrTransID = array();
            $arrTransTopID = array();
            $arrIdsHist = array();
            $arrTransHist = array();
            $tmpReg_result = array();
            foreach ($tmpHist as $row) {
                $arrTransID[] = $row->transaksi_id;
                $arrTransTopID[] = $row->id_top;

                if ($row->ids_his != "") {
                    $hist = blobDecode($row->ids_his);
                    foreach ($hist as $hisSpec) {
                        $arrIdsHist[$row->id][$hisSpec['step']] = array(
                            "step" => $hisSpec['step'],
                            "trID" => $hisSpec['trID'],
                            "nomer" => $hisSpec['nomer'],
                        );
                        $arrTransHist[] = $hisSpec['trID'];
                    }
                }

                $filterField = array("main");
                if (sizeof($registryFields) > 0) {
                    foreach ($registryFields as $param) {
                        if (in_array($param, $filterField)) {
                            $tmpReg_result[$row->transaksi_id][$param] = blobDecode($row->$param);
                        }
                    }
                }
            }

            //            $trReg = new MdlTransaksi();
            //            $trReg->setFilters(array());
            //            $trReg->addFilter("param='main'");
            //            $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
            //            $tmpReg = $trReg->lookupRegistries()->result();
            //            if (sizeof($tmpReg) > 0) {
            //                foreach ($tmpReg as $regRow) {
            //                    $param = $regRow->param;
            //                    $tmpReg_result[$regRow->transaksi_id][$param] = blobDecode($regRow->values);
            //                }
            //            }

            if (sizeof($arrIdsHist) > 0) {
                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $tr->addFilter("id in ('" . implode("','", $arrTransHist) . "')");
                $tmpTransHist = $tr->lookupAll()->result();


                if (sizeof($tmpTransHist) > 0) {
                    foreach ($tmpTransHist as $histSpec) {
                        $tmpTransHist_result[$histSpec->id] = array(
                            "oleh_id" => $histSpec->oleh_id,
                            "oleh_nama" => $histSpec->oleh_nama,
                        );
                    }
                }

                foreach ($arrIdsHist as $trID => $histSpec) {
                    foreach ($histSpec as $step => $detailSpec) {
                        if (array_key_exists($detailSpec['trID'], $tmpTransHist_result)) {
                            $detailSpec['main'] = $tmpTransHist_result[$detailSpec['trID']];
                        }
                        $arrTransMainHist[$trID][$step] = $detailSpec;
                    }
                }
            }
            $configUiJenis = $this->configUi[$jenisTr];
            $numb = 0;
            foreach ($tmpHist as $row) {
                $step_current = $row->step_current;

                if (sizeof($pairRegistries) > 0) {
                    if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->transaksi_id]))) {
                        foreach ($tmpReg_result[$row->transaksi_id] as $param => $eReg) {
                            foreach ($eReg as $k => $v) {
                                if (!isset($row->$k)) {
                                    $row->$k = $v;
                                }
                            }
                        }
                    }
                }

                $tmp = array();
                $numb++;

                foreach ($historyFields as $fName => $fLabel) {

                    if (isset($row->$fName)) {
                        if (is_numeric($row->$fName)) {
                            if (!isset($sumFooter[$fName])) {
                                $sumFooter[$fName] = 0;
                            }
                            $sumFooter[$fName] += $row->$fName;
                        }
                    }

                    if (is_array($fLabel)) {
                        $hisStep = $fLabel['step'];
                        $hisKey = $fLabel['key'];
                        //                                $tNomer = $id_hist[$hisStep][$hisKey];

                        if (isset($row->ids_his)) {
                            $returnVal = showHistoriGlobalNumbers($row->ids_his, $hisStep, true);
                            if ($returnVal == "") {
                                $tmp[$fName] = "-";
                            }
                            else {
                                $tmp[$fName] = $returnVal;
                            }
                        }
                        else {
                            $tmp[$fName] = "-";
                        }
                    }
                    else {
                        $tmp[$fName] = isset($row->$fName) ? formatField_he_format($fName, $row->$fName) : formatField_he_format($fName, 0);
                    }

                    if ($fName == "no") {
                        $tmp[$fName] = formatField_he_format($fName, $numb);
                    }
                }

                if ($row->sub_step_number > 0) {
                    // $tmp['state'] = "<span style='color:" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateColor'] . "'>" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateLabel'] . "</span>";
                    // $tmp['state'] .= "<br>" . createStateSign($row->sub_step_number, $row->step_avail, $jenisTr);

                    $tmp['state'] = createStateHorizontal($row->sub_step_number, $row->step_avail, $jenisTr);
                }
                else {
                    $tmp['state'] = "<span style='color:#777777'>canceled</span>";
                }

                // matiHere();
                $tmp['action'] = "";
                $nextStepNum = ($row->next_substep_num);
                $currentStepNum = ($row->sub_step_number);
                $nextStepCode = ($row->next_step_code);
                $allowJoin = isset($this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin']) && $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] == true ? $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] : false;

                /*button followUp*/
                $allowFollowup = false;
                if ($row->sub_step_number > 0) {
                    //                    if (placeCanFollowupTrans($this->session->login['membership'], $this->session->login['cabang_id'], $this->session->login['gudang_id'], $this->jenisTr, $currentStepNum)) {
                    //                        //                        if (in_array($this->configUi[$jenisTr]['steps'][$currentStepNum]['userGroup'], $this->session->login['membership'])) {
                    //                        $allowFollowup = true;
                    //                        $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                    //                    }
                    $allowFollowup = true;
                    $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                }

                if (isset($this->configUi[$jenisTr]['steps'][$nextStepNum])) {
                    if (isset($this->accessList[$jenisTr])) {
                        if (isset($this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"])) {
                            $allowFollowup = $this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"];
                            $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];
                        }


                    }
                    else {

                        if (placeCanFollowupTrans(my_memberships(), my_cabang_id(), my_gudang_id(), $this->jenisTr, $nextStepNum, "", $configUiJenis)) {
                            //                        if (in_array($this->configUi[$jenisTr]['steps'][$nextStepNum]['userGroup'], $this->session->login['membership'])) {
                            $allowFollowup = true;
                            $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];

                        }
                    }

                }

                if ($allowFollowup) {
                    $stepLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['label'];
                    $isCancelPacking = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking'] : false;
                    $allowCancel = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel'] : false;

                    $targetFollowupLink = $isCancelPacking == true ? "followupCancelPackingPrePreview" : "followupPrePreview";
                    //                    $followupLink = "top.$('#result').load('" . base_url() . "Transaksi/followupPrePreview/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";
                    // $followupLink = "disableShopCart();top.$('#result').load('" . base_url() . $this->modul . "/Transaksi/$targetFollowupLink/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";
                    $followupLink = "disableShopCart();top.$('#result').load('" . base_url() . $this->modul . "/FollowUp/$targetFollowupLink/" . $this->jenisTr . DIRECTORY_SEPARATOR . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";
                    //                        $tmp['action'] = "<a class='btn btn-primary btn-block' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                    $tmp['action'] = "<div class='input-group'>";
                    $tmp['action'] .= "<a class='btn btn-primary btn-block' title='turn this entry into $stepLabel' data-toggle='tooltip' href='JavaScript:void(0)' onClick =\"top.open_holdon();$followupLink\"><span class='glyphicon glyphicon-ok'></span> " . $actionLabel . "</a>";
                    if ($allowJoin) {
                        $tmp['action'] .= "<span class='input-group-addon'>";
                        $tmp['action'] .= "<a title='process many items at once' href='" . base_url() . "Transaksi/viewIncomplete/" . $this->jenisTr . "/$currentStepNum'><span class='fa fa-dedent'></span></a>";
                        $tmp['action'] .= "</span class='input-group-addon'>";
                    }
                }
                //                $arrayOnprogress[] = $tmp;
                //                if (isset($arrDue[$row->transaksi_id]) && $arrDue[$row->transaksi_id]['aging'] > 0) {
                //                    cekhere($row->transaksi_id);
                //                    $arrOver_due[] = $tmp;
                //                } else {
                $arrayOnprogress[] = $tmp;
                //                }
            }
        }


        //endregion

        //region lookup on-going from connected requests

        if (!isset($_SESSION['undoneQty'])) {
            $_SESSION['undoneQty'] = array();
        }
        if (!isset($_SESSION['undoneQty'][$this->jenisTr])) {
            $_SESSION['undoneQty'][$this->jenisTr] = 0;
        }
        $progress2Fields = array();
        $arrayOnprogress2 = array();
        $reqFormTarget = "";
        $needToClear = false;
        $allowMultiSelect = false;
        if (isset($this->configUi[$jenisTr]['requestCode'])) {
            $masterRefCode = $this->configUi[$jenisTr]['requestCode']['masterCode'];
            $stateRefCode = $this->configUi[$jenisTr]['requestCode']['stateCode'];
            $stateRefNum = $this->configUi[$jenisTr]['requestCode']['stepNumber'];
            $progress2Fields = isset($this->configUi[$masterRefCode]['shortHistoryFields']) ? $this->configUi[$masterRefCode]['shortHistoryFields'] : "";
            //            $glanceHistoryFields2 = isset($this->configUi[$masterRefCode]['glanceHistoryFields']) ? $this->configUi[$masterRefCode]['glanceHistoryFields'] + array("select" => "select") : array("nomer" => "receipt no");
            $glanceHistoryFields2 = isset($this->configUi[$masterRefCode]['glanceHistoryFields']) ? $this->configUi[$masterRefCode]['glanceHistoryFields'] : array("nomer" => "receipt no");
            $reqFormTarget = base_url() . get_class($this) . "/swapFrom/$jenisTr";


            $this->load->model("MdlTransaksi");
            $tr = new MdlTransaksi();
            $tr->addFilter("transaksi.cabang_id='" . $this->session->login['cabang_id'] . "'");
            $tr->addFilter("transaksi.jenis_master='" . $masterRefCode . "'");
            $tr->addFilter("transaksi.jenis='" . $stateRefCode . "'");
            //            $tr->addFilter("transaksi.step_number='" . $stateRefNum . "'");
            $tr->addFilter("transaksi.step_current='" . $stateRefNum . "'");
            $tmpByReq = $tr->lookupRecentHistories()->result();

            $needToClear = false;
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                $needToClear = true;
            }
            $_SESSION['undoneQty'][$this->jenisTr] = sizeof($tmpByReq);

            if (sizeof($tmpByReq) > 0) {

                $allowMultiSelect = isset($this->configUi[$jenisTr]['requestCode']['allowMultiSelect']) ? $this->configUi[$jenisTr]['requestCode']['allowMultiSelect'] : false;

                $reqCtr = 0;
                foreach ($tmpByReq as $row) {
                    $reqCtr++;
                    $tmp = array();
                    $inputType = $allowMultiSelect == true ? "checkbox" : "radio";
                    //                    $clickEvent = "onclick=\"return false;\"";
                    $clickEvent = "";
                    if ($inputType == "radio" && !$needToClear) {
                        //                        $clickEvent="onclick=\"document.getElementById('btnConnect').innerHTML='Clear the list to process one of entries above';document.getElementById('btnConnect').disabled=true;document.getElementById('fAsNew').submit()\"";
                        $clickEvent = "onclick=\"document.getElementById('fAsNew').submit()\"";
                    }
                    $tmp['select'] = "<input type=$inputType name='trID[]' value='" . $row->id . "' id='select_" . $reqCtr . "' $clickEvent>";
                    foreach ($historyFields as $fName => $fLabel) {
                        //                        $tmp[$fName] = formatField_he_format($fName, $row->$fName);
                        $tmp[$fName] = isset($row->$fName) ? $row->$fName : "";
                    }


                    $arrayOnprogress2[] = $tmp;
                }
            }
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                $needToClear = true;
            }

        }


        //endregion

        $sumFooterResult = array();
        if (isset($sumFooter) && sizeof($sumFooter) > 0) {
            foreach ($sumFooter as $key => $val) {

                $sumFooterResult[$key] = formatField_he_format($key, $val);
            }
        }
        // cekOrange($progressFields);
        $data = array(
            "mode" => $this->uri->segment(3),
            "isMobile" => $isMob,
            //            "arrayProgressLabels" => $_SESSION["opt_" . $this->jenisTr]['opt']['viewMode'] == "list" ? $progressFields : $glanceHistoryFields,
            //            "arrayProgress2Labels" => $_SESSION["opt_" . $this->jenisTr]['opt']['viewMode'] == "list" ? $progress2Fields : $glanceHistoryFields2,
            "arrayProgressLabels" => $progressFields,
            "arrayProgress2Labels" => $glanceHistoryFields2,
            "arrayOnProgress" => $arrayOnprogress,
            "arrayOnProgress2" => $arrayOnprogress2,
            "needToClear" => $needToClear,
            "reqFormTarget" => $reqFormTarget,
            "allowMultiSelect" => $allowMultiSelect,
            "overDue" => $arrOver_due,
            "clearCartTarget" => base_url() . "_shoppingCart/reset/" . $this->jenisTr,
            "sumFooter" => $sumFooterResult,
        );

        $this->load->view("transaksi", $data);

    }

    public function viewUndoneItems()
    {
        $jenisTr = $this->jenisTr;
        $cCode = $this->cCode;

        $historyFields = $this->configUi[$jenisTr]['shortHistoryFields'];
        $pairRegistries = isset($this->configUi[$jenisTr]['pairRegistries']) ? $this->configUi[$jenisTr]['pairRegistries'] : array();
        $dueDateAllow = isset($this->configUi[$jenisTr]['updateDueDate']) ? $this->configUi[$jenisTr]['updateDueDate'] : array();
        $mb = New MobileDetect();
        $isMob = $mb->isMobile();
        if ($isMob) {
            $historyFields = isset($this->configUi[$jenisTr]['compactHistoryFields']) ? $this->configUi[$jenisTr]['compactHistoryFields'] : array();
        }
        $glanceHistoryFields = isset($this->configUi[$jenisTr]['glanceHistoryFields']) ? $this->configUi[$jenisTr]['glanceHistoryFields'] : array("nomer" => "receipt no");
        $glanceHistoryFields2 = array("nomer" => "receipt no"); //init;
        $selectorProcessor = base_url() . $this->configUi[$jenisTr]['selectorProcessor'] . "/$jenisTr";

        //region lookup on-going transactions
        $arrayOnprogress = array();
        $progressFields = $historyFields;

        $progressFields['jenis_label'] = "activity";
        //        $progressFields['nomer'] = "receipt number";
        $progressFields['oleh_nama'] = "started by";
        $progressFields['state'] = "status";
        $progressFields['action'] = "action";

        $steps = $this->configUi[$jenisTr]['steps'];

        $this->load->model("MdlTransaksi");
        $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='" . $this->session->login['id'] . "'");
                }
            }
            else {
                foreach ($steps as $stepNumber => $stepSpec) {
                    if ($stepNumber < $jmlStep) {
                        $stepCodes[] = $stepSpec['target'];
                    }

                }
            }

        }


        $tr->addFilter("div_id='" . $this->session->login['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->session->login['membership']) > 0) {
                $this->db->group_start();
                $mCtr = 0;
                foreach ($this->session->login['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($this->session->login['cabang_id'], $this->session->login['gudang_id'])->result();
        $tmpHist = $tr->lookupUndoneEntries_joined(replaceSession())->result();
        // cekLime($this->db->last_query());

        //region due date
        $tr->setFilters(array());
        $listedDue = $tr->lookupAllDueDate()->result();
        $arrDue = array();
        $overDue = array();
        foreach ($listedDue as $dueData) {

            $due_date = strtotime($dueData->due_date);
            $date_now = strtotime(date("Y-m-d"));
            if ($due_date < $date_now) {
                $arrDue[$dueData->transaksi_id] = array(
                    "due_date" => $dueData->due_date,
                    "aging" => umurDay($dueData->due_date),
                );
            }

        }
        //arrPrint($arrDue);
        //arrPrint($tmpHist);
        //endregion
        $arrOver_due = array();


        if (sizeof($tmpHist) > 0) {
            $arrTransID = array();
            $arrTransTopID = array();
            $arrIdsHist = array();
            $arrTransHist = array();
            foreach ($tmpHist as $row) {
                $arrTransID[] = $row->transaksi_id;
                $arrTransTopID[] = $row->id_top;

                if ($row->ids_his != "") {
                    $hist = blobDecode($row->ids_his);
                    foreach ($hist as $hisSpec) {
                        $arrIdsHist[$row->id][$hisSpec['step']] = array(
                            "step" => $hisSpec['step'],
                            "trID" => $hisSpec['trID'],
                            "nomer" => $hisSpec['nomer'],
                        );
                        $arrTransHist[] = $hisSpec['trID'];
                    }
                }
            }
            $tmpReg_result = array();
            $trReg = new MdlTransaksi();
            $trReg->setFilters(array());
            // $trReg->addFilter("param='main'");
            // $trReg->addFilter("transaksi_id in ('" . implode("','", $arrTransID) . "')");
            // $tmpReg = $trReg->lookupRegistries()->result();

            $fieldDataRegistries = $trReg->getFields();
            $fDataRegistries = $fieldDataRegistries['dataRegistry'];
            $fieldBlock = array(
                "transaksi_id",
            );
            // $arrChilddata = $arrDiff_key = array_diff_key($arrUpd, array_flip($arrBlock));
            $paramRegistries = array_diff($fDataRegistries, $fieldBlock);
            $tmpReg = $trReg->lookupBaseDataRegistries($arrTransID)->result();
            // showLast_query("kuning");
            // arrPrintPink($paramRegistries);
            // arrPrintPink($tmpReg);
            // matiDisini(__LINE__);

            if (sizeof($tmpReg) > 0) {
                foreach ($tmpReg as $regRow) {
                    // $param = $regRow->param;
                    foreach ($paramRegistries as $param) {

                        $regValue = blobDecode($regRow->$param);
                        // $tmpReg_result[$regRow->transaksi_id][$param] = blobDecode($regRow->$param);
                        $regParams[$param] = $regValue;
                        $tmpReg_result[$regRow->transaksi_id] = array_filter($regParams);
                    }
                }
            }
            // arrPrint($tmpReg_result);
            // matiDisini(__LINE__);
            if (sizeof($arrIdsHist) > 0) {
                $tr = new MdlTransaksi();
                $tr->setFilters(array());
                $tr->addFilter("id in ('" . implode("','", $arrTransHist) . "')");
                $tmpTransHist = $tr->lookupAll()->result();


                if (sizeof($tmpTransHist) > 0) {
                    foreach ($tmpTransHist as $histSpec) {
                        $tmpTransHist_result[$histSpec->id] = array(
                            "oleh_id" => $histSpec->oleh_id,
                            "oleh_nama" => $histSpec->oleh_nama,
                        );
                    }
                }

                foreach ($arrIdsHist as $trID => $histSpec) {
                    foreach ($histSpec as $step => $detailSpec) {
                        if (array_key_exists($detailSpec['trID'], $tmpTransHist_result)) {
                            $detailSpec['main'] = $tmpTransHist_result[$detailSpec['trID']];
                        }
                        $arrTransMainHist[$trID][$step] = $detailSpec;
                    }
                }
            }

            $numb = 0;
            foreach ($tmpHist as $row) {
                $step_current = $row->step_current;
                if (sizeof($pairRegistries) > 0) {
                    if ((sizeof($tmpReg_result) > 0) && (isset($tmpReg_result[$row->transaksi_id]))) {
                        foreach ($tmpReg_result[$row->transaksi_id] as $param => $eReg) {
                            foreach ($eReg as $k => $v) {
                                if (!isset($row->$k)) {
                                    $row->$k = $v;
                                }
                            }
                        }
                    }
                }

                $tmp = array();
                $numb++;

                foreach ($historyFields as $fName => $fLabel) {

                    if (isset($row->$fName)) {
                        if (is_numeric($row->$fName)) {
                            if (!isset($sumFooter[$fName])) {
                                $sumFooter[$fName] = 0;
                            }
                            $sumFooter[$fName] += $row->$fName;
                        }
                    }

                    if (is_array($fLabel)) {
                        $hisStep = $fLabel['step'];
                        $hisKey = $fLabel['key'];
                        //                                $tNomer = $id_hist[$hisStep][$hisKey];

                        if (isset($row->ids_his)) {
                            $returnVal = showHistoriGlobalNumbers_he_misc($row->ids_his, $hisStep, true);
                            if ($returnVal == "") {
                                $tmp[$fName] = "-";
                            }
                            else {
                                $tmp[$fName] = $returnVal;
                            }
                        }
                        else {
                            $tmp[$fName] = "-";
                        }
                    }
                    else {
                        $tmp[$fName] = isset($row->$fName) ? formatField_he_format($fName, $row->$fName) : formatField_he_format($fName, 0);
                    }

                    if ($fName == "no") {
                        $tmp[$fName] = formatField_he_format($fName, $numb);
                    }
                }
                // matiDisini(__LINE__);
                if ($row->sub_step_number > 0) {
                    // $tmp['state'] = "<span style='color:" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateColor'] . "'>" . $this->configUi[$jenisTr]['steps'][$row->sub_step_number]['stateLabel'] . "</span>";
                    // $tmp['state'] .= "<br>" . createStateSign($row->sub_step_number, $row->step_avail, $jenisTr);
                    $tmp['state'] = createStateHorizontal($row->sub_step_number, $row->step_avail, $jenisTr);
                }
                else {
                    $tmp['state'] = "<span style='color:#777777'>canceled</span>";
                }


                $tmp['action'] = "";
                $nextStepNum = ($row->next_substep_num);
                $currentStepNum = ($row->sub_step_number);
                $nextStepCode = ($row->next_step_code);
                $allowJoin = isset($this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin']) && $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] == true ? $this->configUi[$jenisTr]["steps"][$nextStepNum]['allowJoin'] : false;


                $allowFollowup = false;
                if ($row->sub_step_number > 0) {
                    //                    if (placeCanFollowupTrans($this->session->login['membership'], $this->session->login['cabang_id'], $this->session->login['gudang_id'], $this->jenisTr, $currentStepNum)) {
                    //                        //                        if (in_array($this->configUi[$jenisTr]['steps'][$currentStepNum]['userGroup'], $this->session->login['membership'])) {
                    //                        $allowFollowup = true;
                    //                        $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                    //                    }
                    $allowFollowup = true;
                    $actionLabel = "review " . $this->configUi[$jenisTr]['steps'][$currentStepNum]['label'];
                }

                if (isset($this->configUi[$jenisTr]['steps'][$nextStepNum])) {
                    if (isset($this->accessList[$jenisTr])) {
                        if (isset($this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"])) {
                            $allowFollowup = $this->accessList[$jenisTr][$nextStepNum][$nextStepCode]["allowFollowUp"];
                            $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];
                        }


                    }
                    else {
                        if (placeCanFollowupTrans($this->session->login['membership'], $this->session->login['cabang_id'], $this->session->login['gudang_id'], $this->jenisTr, $nextStepNum)) {
                            //                        if (in_array($this->configUi[$jenisTr]['steps'][$nextStepNum]['userGroup'], $this->session->login['membership'])) {
                            $allowFollowup = true;
                            $actionLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['actionLabel'];

                        }
                    }

                }

                if ($allowFollowup) {
                    $stepLabel = $this->configUi[$jenisTr]['steps'][$nextStepNum]['label'];
                    $isCancelPacking = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['isCancelPacking'] : false;
                    $allowCancel = isset($this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel']) ? $this->configUi[$jenisTr]['steps'][$nextStepNum]['allowCancel'] : false;

                    $targetFollowupLink = $isCancelPacking == true ? "followupCancelPackingPrePreview" : "followupPrePreview";
                    //                    $followupLink = "top.$('#result').load('" . base_url() . "Transaksi/followupPrePreview/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";
                    $followupLink = "disableShopCart();top.$('#result').load('" . base_url() . $this->modul . "/FollowUp/$targetFollowupLink/$jenisTr/" . $row->transaksi_id . "/$nextStepNum/" . $row->sub_step_number . "');";
                    //                        $tmp['action'] = "<a class='btn btn-primary btn-block' title='turn this entry into $stepLabel' href='JavaScript:void(0)' onClick =\"$followupLink\">" . $actionLabel . "</a>";
                    $tmp['action'] = "<div class='input-group'>";
                    $tmp['action'] .= "<a class='btn btn-primary btn-block' title='turn this entry into $stepLabel' data-toggle='tooltip' href='JavaScript:void(0)' onClick =\"top.open_holdon();$followupLink\"><span class='glyphicon glyphicon-ok'></span> " . $actionLabel . "</a>";
                    if ($allowJoin) {
                        $tmp['action'] .= "<span class='input-group-addon'>";
                        $tmp['action'] .= "<a title='process many items at once' href='" . base_url() . "Transaksi/viewIncomplete/" . $this->jenisTr . "/$currentStepNum'><span class='fa fa-dedent'></span></a>";
                        $tmp['action'] .= "</span class='input-group-addon'>";
                    }
                }
                //                $arrayOnprogress[] = $tmp;
                //                if (isset($arrDue[$row->transaksi_id]) && $arrDue[$row->transaksi_id]['aging'] > 0) {
                //                    cekhere($row->transaksi_id);
                //                    $arrOver_due[] = $tmp;
                //                } else {
                $arrayOnprogress[] = $tmp;
                //                }
            }
        }


        //endregion

        //region lookup on-going from connected requests

        if (!isset($_SESSION['undoneQty'])) {
            $_SESSION['undoneQty'] = array();
        }
        if (!isset($_SESSION['undoneQty'][$this->jenisTr])) {
            $_SESSION['undoneQty'][$this->jenisTr] = 0;
        }
        $progress2Fields = array();
        $arrayOnprogress2 = array();
        $reqFormTarget = "";
        $needToClear = false;
        $allowMultiSelect = false;
        if (isset($this->configUi[$jenisTr]['requestCode'])) {
            $masterRefCode = $this->configUi[$jenisTr]['requestCode']['masterCode'];
            $stateRefCode = $this->configUi[$jenisTr]['requestCode']['stateCode'];
            $stateRefNum = $this->configUi[$jenisTr]['requestCode']['stepNumber'];
            $progress2Fields = isset($this->configUi[$masterRefCode]['shortHistoryFields']) ? $this->configUi[$masterRefCode]['shortHistoryFields'] : "";
            //            $glanceHistoryFields2 = isset($this->configUi[$masterRefCode]['glanceHistoryFields']) ? $this->configUi[$masterRefCode]['glanceHistoryFields'] + array("select" => "select") : array("nomer" => "receipt no");
            $glanceHistoryFields2 = isset($this->configUi[$masterRefCode]['glanceHistoryFields']) ? $this->configUi[$masterRefCode]['glanceHistoryFields'] : array("nomer" => "receipt no");
            $reqFormTarget = base_url() . get_class($this) . "/swapFrom/$jenisTr";


            $this->load->model("MdlTransaksi");
            $tr = new MdlTransaksi();
            $tr->addFilter("transaksi.cabang_id='" . $this->session->login['cabang_id'] . "'");
            $tr->addFilter("transaksi.jenis_master='" . $masterRefCode . "'");
            $tr->addFilter("transaksi.jenis='" . $stateRefCode . "'");
            //            $tr->addFilter("transaksi.step_number='" . $stateRefNum . "'");
            $tr->addFilter("transaksi.step_current='" . $stateRefNum . "'");
            $tmpByReq = $tr->lookupRecentHistories()->result();

            $needToClear = false;
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                $needToClear = true;
            }
            $_SESSION['undoneQty'][$this->jenisTr] = sizeof($tmpByReq);

            if (sizeof($tmpByReq) > 0) {

                $allowMultiSelect = isset($this->configUi[$jenisTr]['requestCode']['allowMultiSelect']) ? $this->configUi[$jenisTr]['requestCode']['allowMultiSelect'] : false;

                $reqCtr = 0;
                foreach ($tmpByReq as $row) {
                    $reqCtr++;
                    $tmp = array();
                    $inputType = $allowMultiSelect == true ? "checkbox" : "radio";
                    //                    $clickEvent = "onclick=\"return false;\"";
                    $clickEvent = "";
                    if ($inputType == "radio" && !$needToClear) {
                        //                        $clickEvent="onclick=\"document.getElementById('btnConnect').innerHTML='Clear the list to process one of entries above';document.getElementById('btnConnect').disabled=true;document.getElementById('fAsNew').submit()\"";
                        $clickEvent = "onclick=\"document.getElementById('fAsNew').submit()\"";
                    }
                    $tmp['select'] = "<input type=$inputType name='trID[]' value='" . $row->id . "' id='select_" . $reqCtr . "' $clickEvent>";
                    foreach ($historyFields as $fName => $fLabel) {
                        //                        $tmp[$fName] = formatField_he_format($fName, $row->$fName);
                        $tmp[$fName] = isset($row->$fName) ? $row->$fName : "";
                    }


                    $arrayOnprogress2[] = $tmp;
                }
            }
            if (isset($_SESSION[$cCode]['items']) && sizeof($_SESSION[$cCode]['items']) > 0) {
                $needToClear = true;
            }

        }


        //endregion


        $sumFooterResult = array();
        if (isset($sumFooter) && sizeof($sumFooter) > 0) {
            foreach ($sumFooter as $key => $val) {

                $sumFooterResult[$key] = formatField_he_format($key, $val);
            }
        }

        $data = array(
            "mode" => "viewUndoneItems",
            "isMobile" => $isMob,

            //            "arrayProgressLabels" => $_SESSION["opt_" . $this->jenisTr]['opt']['viewMode'] == "list" ? $progressFields : $glanceHistoryFields,
            //            "arrayProgress2Labels" => $_SESSION["opt_" . $this->jenisTr]['opt']['viewMode'] == "list" ? $progress2Fields : $glanceHistoryFields2,
            "arrayProgressLabels" => $progressFields,
            "arrayProgress2Labels" => $glanceHistoryFields2,
            "arrayOnProgress" => $arrayOnprogress,
            "arrayOnProgress2" => $arrayOnprogress2,
            "needToClear" => $needToClear,
            "reqFormTarget" => $reqFormTarget,
            "allowMultiSelect" => $allowMultiSelect,
            "overDue" => $arrOver_due,
            "clearCartTarget" => base_url() . $this->modul . "/_shoppingCart/reset/" . $this->jenisTr,

            "sumFooter" => $sumFooterResult,
            "jenisTr" => $jenisTr,
        );

        $this->load->view("transaksi", $data);

    }

    /* ------------------------
     * kalau mau ngeprint lewat sini dulu
     * -------------------*/
    public function viewResume()
    {
        // cekBiru(url_segment());
        // arrPrint($this->session->login);
        $globalVars = array();
        $no = $this->uri->segment(5);
        // $this->jenisTr = explode(".", $no)[0];
        // $cCode = "_TR_" . $this->jenisTr;
        $this->load->config("heAccounting");
        $accountChildsLinks = $this->config->item("accountChildsLinks");


        // cekMerah("$no");
        // matiDisini(__LINE__);
        $this->load->model("MdlTransaksi");
        $trep = $trs = $tr = new MdlTransaksi();
        $tr->addFilter("nomer='$no'");
        $tmp1 = $tr->lookupAll()->row();
        // showLast_query("lime");
        $jenisMasterTrans = $tmp1->jenis_master;
        $transaksiID = $tmp1->id;
        $cabang_nama = isset($tmp1->cabang_nama) ? $tmp1->cabang_nama : "";
        $jenis_label = isset($tmp1->jenis_label) ? $tmp1->jenis_label : "";
        $nomer = $tmp1->nomer;
        $deskripsi = $tmp1->deskripsi;
        // $indexing_registry = blobDecode($tmp1->indexing_registry);
        // arrPrintPink($indexing_registry);
        //region swap from registry
        // matiDisini();
        // cekBiru(__LINE__);
        // $tr = new MdlTransaksi();
        // $tr->addFilter("param='main'");
        // $tmpReg = $tr->lookupRegistriesByNumber($no)->result();
        // $tmpReg = $tr->lookupBaseRegistries($indexing_registry['main'])->result();
        $tmpReg = $tr->lookupBaseDataRegistries($transaksiID)->row();
        // showLast_query("lime");

        $main = blobDecode($tmpReg->main);
        // $items = blobDecode($tmpReg->items);
        $tmpEP = $items = blobDecode($tmpReg->items);

        // arrPrint($tmp1);
        // arrPrint($tmpReg);
        // arrPrint($items);
        // matiDisini(__LINE__);

        // if (sizeof($tmpReg) > 0) {
        //     foreach ($tmpReg as $row) {
        //         $var = $row->param;
        //         $$var = unserialize(base64_decode($row->values));
        //     }
        // }
        //endregion

        //region signatures
        $signNumbers = array();
        $signValues = array();
        $signExtValues = array();
        // $trs = new MdlTransaksi();
        $trs->setFilters(array());
        $masterID = isset($tmp1->id_master) ? $tmp1->id_master : 0;
        $tmpSign = $trs->lookupSignaturesByMasterID($masterID)->result();
        // matiDisini(__LINE__);
        $arrCounters = blobDecode($tmp1->counters);
        $urutCounters = NULL;
        if (sizeof($arrCounters) > 0) {
            $key2 = $tmp1->jenis . "|" . $tmp1->cabang_id;
            $urutCounters = digit_5($arrCounters["stepCode|placeID"][$key2]);
        }
        if ($urutCounters != NULL) {
            $urutCounters = "-$urutCounters";
        }

        if (isset($this->configUi[$tmp1->jenis_master]['resumeFieldNames'])) {
            $resumeFields = $this->configUi[$tmp1->jenis_master]['resumeFieldNames']['selectFields'];
            $resumeTitle = $this->configUi[$tmp1->jenis_master]['resumeFieldNames']['title'];
            $resumeName = isset($tmp1->$resumeFields) ? $tmp1->$resumeFields : "";
        }
        else {
            $resumeTitle = "";
            $resumeName = "";
        }

        $arrSignName = array();
        if (sizeof($tmpSign) > 0) {
            foreach ($tmpSign as $ii => $row) {
                $signValues['sign_' . $row->transaksi_id . '_' . $row->step_number] = array(
                    "title" => isset($this->configUi[$tmp1->jenis_master]['steps'][$row->step_number]['label']) ? $this->configUi[$tmp1->jenis_master]['steps'][$row->step_number]['label'] : "",
                    "label" => isset($this->configUi[$tmp1->jenis_master]['steps'][$row->step_number]['stateCaption']) ? $this->configUi[$tmp1->jenis_master]['steps'][$row->step_number]['stateCaption'] : "",
                    "dtime" => $row->dtime,
                    "nomer" => formatField_he_format("nomer_nolink", $row->nomer),
                    "nomer_orig" => $row->nomer,
                    "oleh" => isset($row->oleh_nama) ? $row->oleh_nama : "",
                    "caption_department" => isset($this->config->item("userGroup")[$row->group_code]) ? $this->config->item("userGroup")[$row->group_code] : "",
                    "prev_id" => isset($row->prev_id) ? $row->prev_id : 0,
                    "link_id" => isset($row->transaksi_id) ? $row->transaksi_id : 0,
                );
                $arrSignName[$ii] = array(
                    "nama" => $row->oleh_nama,
                    "dtime" => $row->dtime,
                );
            }
        }
        $signStr = "";
        //endregion

        // cekBiru(__LINE__);
        //entry points
        // $trep = new MdlTransaksi();
        $tmpEP = array();
        // $tmpEP = $trep->lookupEntryPoints_joined($masterID)->result();
        // $condites = array(
        //     "id_master" => $masterID,
        //     "link_id >" => 0,
        // );
        $tmpEP = $trep->lookupSignatures($masterID)->result();

        // cekBiru($this->db->last_query());
        // arrPrintWebs($tmpEP);
        // matiDisini(__LINE__);
        $epValues = array();
        if (sizeof($tmpEP) > 0) {
            foreach ($tmpEP as $ii => $row) {
                $epValues['sign_' . $row->id_master . '_' . $row->step_number] = array(
                    // "title"              => isset($this->configUi[$deskripsi->jenis_master]['steps'][$deskripsi->step_number]['label']) ? $this->configUi[$row->jenis_master]['steps'][$row->step_number]['label'] : "",
                    "cabang_nama" => $cabang_nama,
                    // "label"       => $row->label,
                    "dtime" => $row->dtime,
                    // "dtime"              => isset($arrSignName[$ii]['dtime']) ? $arrSignName[$ii]['dtime'] : $row->dtime,
                    "nomer" => formatField_he_format("nomer_nolink", $nomer),
                    "nomer_orig" => $nomer,
                    "oleh" => isset($arrSignName[$ii]['nama']) ? $arrSignName[$ii]['nama'] : $row->oleh_nama,
                    // "caption_department" => "text",
                    "deskripsi" => $row->deskripsi,
                    "link_id" => $row->link_id,
                );
            }
        }
        // arrPrintPink($signValues);
        // arrPrint($epValues);
        foreach ($signValues as $singKey => $signValue) {
            $epDatas = $epValues[$singKey];
            $singDatas = $signValue + $epDatas;
            $signArray[$singKey] = $singDatas;
        }
// arrPrintWebs($signArray);
//         $signArray = sizeof($epValues) > 0 ? $epValues : $signValues;
        if (sizeof($signArray) > 0) {
            $signStr .= "<div class='panel'>";
            $signStr .= "<h4 class='text-blue'><span class='fa fa-sign-in'></span> entry points </h4>";
            $signStr .= "<h5 class='text-blue'><span class='fa fa-tasks'></span> $resumeTitle  $resumeName</h5>";
            $signStr .= "<table class='table table-condensed'>";
            $signStr .= "<tr bgcolor='#f0f0f0'>";
            $signStr .= "<td class='text-muted'>date</td>";
            $signStr .= "<td class='text-muted'>title</td>";
            $signStr .= "<td class='text-muted'>branch</td>";
            $signStr .= "<td class='text-muted'>signature number</td>";
            $signStr .= "<td class='text-muted'>person</td>";
            $signStr .= "<td class='text-muted'>tool</td>";
            foreach ($signArray as $k => $sSpec) {

                $signDeskripsi = isset($sSpec['deskripsi']) ? " (" . $sSpec['deskripsi'] . ")" : "";
                $nomerOrig = $sSpec['nomer_orig'];
                $nomerOrigEx = explode("_", $nomerOrig);
                $nomerOrigNota = $nomerOrigEx[0];

                $signStr .= "<tr>";
                $signStr .= "<td>" . formatField_he_format("date_time", $sSpec['dtime']);
                $signStr .= "</td>";
                $signStr .= "<td>" . ($sSpec['title']);
                $signStr .= "</td>";
                $signStr .= "<td>" . (isset($sSpec['cabang_nama']) ? $sSpec['cabang_nama'] : "-");
                $signStr .= "</td>";
                $signStr .= "<td>" . ($sSpec['nomer']) . $signDeskripsi;
                $signStr .= "</td>";
                $signStr .= "<td>";
                $signStr .= ("<span class='fa fa-user'></span> " . $sSpec['oleh'] . "");
                $signStr .= "</td>";

                $signStr .= "<td>";
                $signStr .= formatField_he_format("print_label", $nomerOrigNota, "888");
                $signStr .= "</td>";

                $signStr .= "</tr>";
            }
            $signStr .= "</table class='table table-condensed'>";
            $signStr .= "</div class='panel'>";
        }

        $mems = isset($this->session->login['membership']) ? $this->session->login['membership'] : array();
        $allowedView = $this->config->item('userGroup_jurnal') != null ? $this->config->item('userGroup_jurnal') : array();
//        $rekeningAlias = $this->config->item('accountAlias') != null ? $this->config->item('accountAlias') : array();
        $rekeningAlias = fetchAccountStructureAlias();


        $lItems = array();
        $headers = array();
        $arrCabang = array();
        if (array_intersect($allowedView, $mems)) {
            $this->load->model("Coms/ComJurnal");
            $this->load->model("Mdls/MdlCabang");

            $cb = New MdlCabang();
            $tmpCb = $cb->lookupAll()->result();
            $arrCabang = array();
            if (sizeof($tmpCb) > 0) {
                foreach ($tmpCb as $spec) {
                    $arrCabang[$spec->id] = $spec->nama;
                }
            }

            $j = new ComJurnal();
            $j->addFilter("transaksi_no='$no'");
            if ($this->session->login['cabang_id'] == CB_ID_PUSAT) {

            }
            else {
                // dimatikan dulu untuk checking jurnal lengkapnya...........
                //                $j->addFilter("cabang_id='" . $this->session->login['cabang_id'] . "'");
            }
            //            $j->setSortBy(array("kolom" => "urut", "mode" => "ASC"));
            $tmp = $j->lookupAll()->result();
            $headers = array(
                "dtime" => "date",
                "rekening" => "account",
                "debet" => "debet",
                "kredit" => "kredit",
            );
            $lItems = array();
            if (sizeof($tmp) > 0) {
                /* ---------------------------------------
                 * array link untuk mengarahkan ke halaman mutasi yg dikendaki
                 * -----------------------------------*/

                //region Description
                $mutasiLinks = array();
                foreach ($accountChildsLinks as $rekNama => $rekLink) {
                    $mutasiLinks[$rekNama] = $rekLink . "/" . $main['pihakID'] . "?o=" . $main['cabangID'] . "&trID=$transaksiID";
                }
                //endregion

                foreach ($tmp as $row) {
                    $defLink = "Ledger/viewMoves_l1/Rekening/" . $row->rekening . "?o=" . $row->cabang_id . "&trID=$transaksiID";

                    $rekening_alias = isset($rekeningAlias[$row->rekening]) ? $rekeningAlias[$row->rekening] : $row->rekening;
                    if ($row->debet > 0 || $row->kredit > 0) {
                        //$strLink = key_exists($row->rekening, $mutasiLinks) ? $mutasiLinks[$row->rekening] : $defLink;
                        $strLink = $defLink;
                        $lItems[$row->cabang_id][$row->urut][] = array(
                            "dtime" => $row->dtime,
                            "rekening" => $row->debet > 0 ? $rekening_alias : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $rekening_alias,
                            "debet" => $row->debet > 0 ? $row->debet : "",
                            "kredit" => $row->kredit > 0 ? $row->kredit : "",
                            "link" => base_url() . $strLink,
                        );
                    }
                }
                //                arrPrint($lItems);
                ksort($lItems);
            }


        }

        $mb = New MobileDetect();
        $isMob = $mb->isMobile();
        $mobMode = $isMob == true ? "1" : "0";

        $printSettings = isset($this->configLayout[$jenisMasterTrans]['allowPrint']['1']) ? $this->configLayout[$jenisMasterTrans]['allowPrint']['1'] : array();
        $printLocation = isset($this->configLayout[$jenisMasterTrans]['printLocation']) ? $this->configLayout[$jenisMasterTrans]['printLocation'] : "Transaksi/viewReceipt/";

        if (sizeof($tmpSign) > 0) {
            if (isset($printSettings['size'])) {
                switch ($printSettings['size']) {
                    case "normal":
                        $receiptLink = "top.popBig('" . base_url() . $this->modul . "/" . $printLocation . $this->jenisTr . "/$no?mobMode=$mobMode&st=1');";
                        break;
                    case "small":
                        $receiptLink = "top.popSmall('" . base_url() . $this->modul . "/" . $printLocation . $this->jenisTr . "/$no?mobMode=$mobMode&st=2');";
                        break;
                    default:
                        //                                cekkuning("size: UNKNOWN");
                        break;
                }
            }
            else {
                $receiptLink = "top.popBig('" . base_url() . $this->modul . "/" . $printLocation . $this->jenisTr . "/$no?mobMode=$mobMode&st=3');";
            }
        }
        // else {
        //     $receiptLink = "top.popBig('" . url_sanhistory() . "public/pembelian/printnable_ci.php?Mode=" . $this->jenisTr . "&no=$no&st=4');";
        // }

        $data = array(
            "mode" => "viewResume",
            "title" => $no,
            "headers" => $headers,
            "main" => isset($main) ? $main : array(),
            "items" => $lItems,
            "receiptLink" => $receiptLink,
            "signStr" => $signStr,
            "cabangData" => $arrCabang,
            "urutCounter" => $urutCounters,
            "underMaintenance" => underConstruction(),
        );
        $this->load->view("transaksi", $data);
    }

    public function viewResumeDetails()
    {

        $selectedID = $this->uri->segment(5);

        $this->load->model("MdlTransaksi");
        $tr = new MdlTransaksi();
        $tr->setFilters(array());
        $tr->addFilter("transaksi_data.trash='0'");
        $joinedTrans = $tr->lookupJoinedByID($selectedID)->result()[0];

        $jenisTr = $joinedTrans->jenis_master;
        $pairRegistries = isset($this->configUi[$jenisTr]['pairRegistries']) ? $this->configUi[$jenisTr]['pairRegistries'] : array();
        $receiptElemets = isset($this->configUi[$jenisTr]["receiptElements"]) ? $this->configUi[$jenisTr]["receiptElements"] : array();
        $receiptDetailCompactListlabel = isset($this->configLayout[$jenisTr]["reviewDetailCompactListsLabel"]) ? $this->configLayout[$jenisTr]["reviewDetailCompactListsLabel"] : array();
        $receiptDetailCompactListlabel2 = isset($this->configLayout[$jenisTr]["reviewDetailCompactListsLabel2"]) ? $this->configLayout[$jenisTr]["reviewDetailCompactListsLabel2"] : array();
        $receiptCompactDetailsSum = isset($this->configLayout[$jenisTr]["reviewCompactListDetailSum"]) ? $this->configLayout[$jenisTr]["reviewCompactListDetailSum"] : array();
        $receiptCompactDetailsSum2 = isset($this->configLayout[$jenisTr]["reviewCompactListDetailSum2"]) ? $this->configLayout[$jenisTr]["reviewCompactListDetailSum2"] : array();
        $receiptMainLabel = isset($this->configLayout[$jenisTr]["reviewMainCompactListsLabel"]) ? $this->configLayout[$jenisTr]["reviewMainCompactListsLabel"] : array();
        $reviewCompactListSum = isset($this->configLayout[$jenisTr]["reviewCompactListSum"]) ? $this->configLayout[$jenisTr]["reviewCompactListSum"] : array();
        $reviewAddRows = isset($this->configLayout[$jenisTr]["reviewAddRows"]) ? $this->configLayout[$jenisTr]["reviewAddRows"] : array();
        $reviewSign = isset($this->configLayout[$jenisTr]["reviewSign"][$joinedTrans->step_number]) ? $this->configLayout[$jenisTr]["reviewSign"][$joinedTrans->step_number] : array();

        $d_start = backCustomDate(30, $joinedTrans->fulldate);
        $d_stop = $joinedTrans->fulldate;

        $tr->setFilters(array());
        $tr->addFilter("transaksi_id='$selectedID'");
        $tmpReg = $tr->lookupDataRegistries()->result();

        $mainElements = array();

        $mainData = array();
        $receiptDetailFields = array();
        $receiptSumFields = array();
        $masterItems = array();
        $masterItems2_sum = array();
        foreach ($tmpReg as $regData) {
            foreach ($regData as $key_reg => $val_reg) {
                switch ($key_reg) {
                    case "main":
                        $mainData = blobDecode($val_reg);
                        break;
                    case "items":
                        $masterItems_0 = blobDecode($val_reg);
                        foreach ($masterItems_0 as $pId => $masterItem) {
                            if (isset($masterItem['nett1']) && ($masterItem['nett1'] > 0)) {
                                $ppn_key = $masterItem['ppn'] / $masterItem['nett1'];
                            }
                            else {
                                $ppn_key = 0;
                            }
                            $addItem['harganppn'] = $masterItem['harga'] + ($masterItem['harga'] * $ppn_key);
                            $masterItems[$pId] = $masterItem + $addItem;
                        }
                        break;
                    case "items2_sum":
                        $masterItems2_sum = blobDecode($val_reg);
                        //                    foreach ($masterItems_0 as $pId => $masterItem) {
                        //                        $ppn_key = $masterItem['ppn'] / $masterItem['nett1'];
                        //                        $addItem['harganppn'] = $masterItem['harga'] + ($masterItem['harga'] * $ppn_key);
                        //                        $masterItems[$pId] = $masterItem + $addItem;
                        //                    }
                        break;
                    case "main_elements"://
                        $mainElements = blobDecode($val_reg);
                        break;
                    case "receiptDetailFields"://
                        $receiptDetailFields = blobDecode($val_reg);
                        break;
                    case "receiptSumFields"://
                        $receiptSumFields = blobDecode($val_reg);
                        break;
                }
            }

        }
        switch ($joinedTrans->produk_jenis) {
            case "produk":
                $link = base_url() . "Ledger/viewMoveDetails/RekeningPembantuProduk/persediaan produk/";
                break;
            case "supplies":
                $link = base_url() . "Ledger/viewMoveDetails/RekeningPembantuSupplies/persediaan supplies/";
                break;
            default:
                $link = NULL;
                break;
        }


        $sumQty = array();
        $arrItemsLink = array();
        if (sizeof($masterItems) > 0) {
            $qty_sum = 0;
            foreach ($masterItems as $data) {
                $qty_sum += $data["qty"];

                if ($link != NULL) {
                    $arrItemsLink[$data['id']] = $link . $data['id'] . "?o=" . $data['cabangID'] . "&trID=" . $joinedTrans->transaksi_id . "&date1=$d_start&date2=$d_stop";
                }
            }
            $sumQty["qty"] = $qty_sum;
        }
        $mainData = $mainData + $sumQty + (array)$joinedTrans;

        //region signatures
        $signNumbers = array();
        $signValues = array();
        $signExtValues = array();
        $trs = new MdlTransaksi();
        $trs->setFilters(array());
        $tmpSign = $trs->lookupSignaturesByMasterID($joinedTrans->id_master)->result();

        $signHeader = array();
        if (sizeof($tmpSign) > 0) {
            foreach ($tmpSign as $row) {
                $signValues['sign_' . $row->step_number] = array(
                    "label" => isset($this->configUi[$joinedTrans->jenis_master]['steps'][$row->step_number]['stateCaption']) ? $this->configUi[$joinedTrans->jenis_master]['steps'][$row->step_number]['stateCaption'] : "",
                    "contents" => isset($row->oleh_nama) ? $row->oleh_nama : "",
                    "caption_department" => isset($this->config->item("userGroup")[$row->group_code]) ? $this->config->item("userGroup")[$row->group_code] : "",
                );
            }
        }
        //endregion


        $data = array(
            "mode" => $this->uri->segment(3),
            "mainFields" => $mainData,
            "items" => $masterItems,
            "items2_sum" => $masterItems2_sum,
            "itemsLabel" => $receiptDetailCompactListlabel,
            "itemsLabel2" => $receiptDetailCompactListlabel2,
            "mainSumDetailsFieldsLabel" => $receiptCompactDetailsSum,
            "mainSumDetailsFieldsLabel2" => $receiptCompactDetailsSum2,
            "mainSumFieldsLabel" => $reviewCompactListSum,
            "mainFieldsLabel" => $receiptMainLabel,
            "mainElements" => $mainElements,
            "receiptSumFields" => $receiptSumFields,
            "reviewAddRows" => $reviewAddRows,
            "sign" => $signValues,
            "reviewSign" => $reviewSign,

            "itemsLink" => $arrItemsLink,
            "itemsKolomLink" => array("nama", "produk_kode"),
            "underMaintenance" => underConstruction(),
        );

        $this->load->view("transaksi", $data);

    }

}
