<?php

//region urusan tanggal-menanggal
date_default_timezone_set('asia/jakarta');
$date = new DateTime(date("Y-m-d")); // Y-m-d
$date->add(new DateInterval('P30D'));
//endregion

$config["coTransaksiUi"] = array(
    "582" => array(
        "transaksiMode"          => "forward",
        "icon"                   => "fa fa-opencart",
        "label"                  => "POS sales",
        "place"                  => "branch",
        "steps"                  => array(
            1 => array(
                "runCoreAkunting"      => false, //matikan akunting
//                "runCoreAkunting"      => true, //nyalakan akunting
                "label"                => "invoice",
                "actionLabel"          => "create invoice",
                "source"               => "",
                "target"               => "582", // membuat penjualan
                "userGroup"            => "o_seller",
                "stateLabel"           => "paid",
                "stateColor"           => "#009900",
                "stateCaption"         => "complete by",
                "allowJoin"            => true,
                "settlementMainFields" => array(
                    "dtime"        => array(
                        "label" => "tanggal",
                    ),
                    "no_global"    => array(
                        "label" => "invoice",
                        "attr"  => "class='text-right'",
                    ),
                    "customerName" => array(
                        "label" => "konsumen",
                    ),
                    "harga_nett2"  => array(
                        "label"     => "penjualan",
                        "format"    => "formatField_he_format",
                        "sumFields" => true,
                        "attr"      => "width='60px' class='text-right'",
                    ),
                ),
                "settlementItemFields" => array(
                    "kode"          => array(
                        "label" => "kode",
                    ),
                    "nama"          => array(
                        "label" => "produk",
                    ),
                    "qty"           => array(
                        "label"  => "jml",
                        "format" => "formatField_he_format",
                        "attr"   => "width='40px'",
                    ),
                    "harga"         => array(
                        "label"  => "harga",
                        "format" => "formatField_he_format",
                        "attr"   => "width='60px' class='text-right'",
                    ),
                    "sub_jual_nppn" => array(
                        "label"  => "sub",
                        "format" => "formatField_he_format",
                        "attr"   => "width='60px' class='text-right'",
                    ),
                ),
            ),
        ),
        "template"               => "template/transaksi.html",
        "selectorModel"          => "MdlProduk",
        "selectorSrcModel"       => "MdlProduk",
        "autoCreateOrderId"      => true,
        "previewValidate"        => false,

        /* -------------------------------------
         * untuk menmabahkan btn tmpSave pada shoping cart
         * -------------------------------------*/
        "tmpSave" => array(
            "mdlName" => "MdlTmpDiskon",
            "exeTarget" => "_shoppingCart/tmpSave/582",
            "btnLabel" => "simpan sementara",
            "btnIcon" => "fa-save",
        ),
        "reqDiskon" => array(
            "mdlName" => "MdlTmpDiskon",
            "exeTarget" => "_shoppingCart/tmpSave/582",
            "btnLabel" => "permintaan diskon tambahan",
            "btnIcon" => "fa-bullhorn",
        ),

        "selectedPrice"          => array(
            "model"     => "MdlHargaProduk",
            "label"     => array(
                "jual",
                "hpp",
                "harga_list",
                "jual_nppn",
                "ppv",
                "disc"
            ),
            "key_label" => array(
                 "harga_list" => "harga",// yang dipakai shoppingcart harga list
//               "jual" => "harga",
               "hpp" => "hpp",
            ),
            "mainSrc"   => "harga_list",
            // "mainSrc"   => "jual",
        ),
        "lockerCheck"            => array(
            "enabled"      => false,
            "mdlName"      => "MdlLockerStock",
            "jenis"        => "produk",
            "jenis_locker" => "stock",
        ),
        "selectorFilters"        => array(
            "toko_id=tokoID", // mengambil dari $this->session->login(cabang_id) JANGAN LUPA DIGANTI YA..
            //            "cabang_id=placeID", // mengambil dari $this->session->login(cabang_id) JANGAN LUPA DIGANTI YA..
            //            "gudang_id=gudangID", // mengambil dari $this->session->login(cabang_id) JANGAN LUPA DIGANTI YA..
            //            "jumlah>.0",
            //            "state=.active",
            //            "oleh_id=.0",
        ),
        "selectorSrcFilters"     => array(
            // "cabang_id=cabang_id", // mengambil dari $this->session->login(cabang_id) JANGAN LUPA DIGANTI YA..
            // "jumlah>.0",
            // "state=.active",
            // "gudang_id=gudang_id",
            "toko_id=toko_id",
        ),
        "selectorSrcParamFields" => array(
            "id" => "produk_id",
            //            // "nama"   => "nama",
            //            // "jumlah" => "jumlah",
            //            // "moq"    => "moq",
            //            // "satuan" => "satuan",
        ),
        // ----
        "selectorCaller"         => "_selectorItem/selectItem",// bikin shopping cart background
        "selectorLabel"          => "item / barcode",
        "selectorDefaultMinValue"=> "1",
        "selectorParamFields"    => array(
            "id"          => "id",
            "kode"        => "kode",
            "nama"        => "nama",
            "jumlah"      => "jumlah",
            "moq"         => "moq",
            "satuan"      => "satuan",
            "barcode"     => "barcode",
            "folder_id"   => "folder_id",
            "folder_nama" => "folder_nama",
            "coa_code"    => "coa_code",
        ),
        "selectorViewedFields"   => array(
            // "nama",
            // "no_part",
            "jumlah",
            "satuan",
        ),

        "selectorFields"         => array("id", "nama", "satuan", "barcode", 'ppn'),

        "selectorSocketNumpad"   => array(
            "targetURL" => "Numpad/index",
            "inParams" => array(//==bacanya dari model yang terlibat, bukan items ataupun out_details
                "id" => "id",
                "min" => "minValue",
            ),
        ),

        "selectorSocket" => array(
            "targetURL" => "_processSelectProduct/select",
            "inParams" => array(//==bacanya dari model yang terlibat, bukan items ataupun out_details
                "id" => "id",
                "min" => "minValue",
            ),
        ),

        "barcodeSettings"        => array(
            "srcModel"  => "MdlProduk",
            "srcColumn" => "barcode",
        ),

        // "selectorProcessor" => "_processSelectProductStock/select",
        // "itemSwapper" => "_processSelectProductStock/multiSelect",

        "selectorProcessor"    => "_processSelectProduct/select",
        "itemSwapper"          => "_processSelectProduct/multiSelect",
        // ------------------------------------
        "swappedKeys"          => array("pihakID", "pihakName"),
//        "selectorApkToWeb"       => array(
//            "id_cust"     => "pihakID",
//            "nm_cust"     => "pihakName",
//            "apk_version" => "apk_version",
//            "id"          => "apk_trid",
//        ),
        // --------------------------------
        "editHandlerMethod"    => "select",
        "pihakModel"           => "MdlCustomer",
        "pihakCaller"          => "_selectorPihak/selectPihak",
        "pihakLabel"           => "customer",
        "pihakFilters"         => array(
            "toko_id=toko_id",
        ),
        "pihakProcessor"       => "_processPihak/select",
        "shortHistoryFields"   => array(
            "jenis_label"    => "activity",
            "dtime"          => "date",
            "customers_nama" => "customer",
            "nomer"          => "receipt number",
            "tagihan"        => "nilai",
            "oleh_nama"      => "person",
            "trash_4"        => "status",
            //            "harga"          => "nilai",
            //            "disc"           => "discount",
            //            "ppn"            => "ppn",
            //            "grand_total"    => "jml. total",
        ),
        "compactHistoryFields" => array(
            "customers_nama"  => "customer",
            "transaksi_nilai" => "amount",
        ),
        "glanceHistoryFields"  => array(
            "customers_nama"  => "customer",
            "oleh_nama"       => "person",
            "transaksi_nilai" => "amount",
        ),
        "defaultViewMode"      => "thumbnail",
        "pihakFields"          => array("id", "nama"),
        "historyFields"        => array(
            1 => array(
                "dtime"          => "tanggal",
                "oleh_nama"      => "pic",
                "customers_nama" => "konsumen",
                "nomer_top"      => "nomer order",
                "harga"          => "Nilai Bruto",
                "diskon_tambahan_nilai"           => "potongan",
                "ppn"            => "Include PPN",
                "grand_total"    => "Nilai Netto",
                "grand_total"    => "Nilai Netto",
//                "bayar"          => "bayar",
//                "kembali"          => "kembali",
//                "print_label"    => "tool",
            ),
//            2 => array(
//                // "jenis_label"    => "activity",
//                "dtime"          => "tanggal",
//                "oleh_nama"      => "pic",
//                "customers_nama" => "konsumen",
//                // "review_details" => "review",
//                "nomer_top"      => "nomer order",
//                "nomer"          => "nomer prepacking",
//                "harga"          => "nilai",
//                //                "disc"           => "discount",
//                // "nett1" => "sub amount",
//                //                "ppn"            => "ppn",
//                // "print_nvalas"   => "tool",
//                "grand_total"    => "jml. total",
//                "print_label"    => "tool",
//                "action_label"   => "action",
//            ),
//
//            3 => array(
//                // "jenis_label"    => "activity",
//                "dtime"          => "tanggal",
//                "oleh_nama"      => "pic",
//                "customers_nama" => "konsumen",
//                // "review_details" => "review",
//                "nomer_top"      => "nomer order",
//                "nomer"          => "nomer packinglist",
//                "harga"          => "nilai",
//                //                "disc"           => "discount",
//                // "nett1" => "sub amount",
//                //                "ppn"            => "ppn",
//                // "print_nvalas"   => "tool",
////                "grand_total"    => "jml. total",
////                "print_label"    => "tool",
////                "action_label"   => "action",
//            ),
//            4 => array(
//                // "jenis_label"    => "activity",
//                "dtime"          => "tanggal",
//                "oleh_nama"      => "pic",
//                "customers_nama" => "konsumen",
//                // "review_details" => "review",
//                "nomer_top"      => "nomer order",
//                "nomer"          => "nomer invoice",
//                "harga"          => "nilai",
//                //                "disc"           => "discount",
//                // "nett1" => "sub amount",
//                //                "ppn"            => "ppn",
//                // "print_nvalas"   => "tool",
////                "grand_total"    => "jml. total",
////                "print_label"    => "tool",
////                "action_label"   => "action",
//            ),
        ),
        "extHistoryFields"     => array(
            1 => array(
                // "review_details" => "id",
                "print_label"  => "nomer",//baca gerbang nomer transaksi
                "action_label" => "id",//baca gerbang id
            ),
            2 => array(
                // "review_details" => "id",
                "print_label"  => "nomer",//baca gerbang nomer transaksi
                "action_label" => "id",//baca gerbang id
            ),
        ),

        /* ----------------------------
         * kalau nambah fiels di shoping cart harus dipangil manual di contorler _shopingCart
         * ------------*/
        "shoppingCartFields"                => array(
            1 => array(
                "barcode"            => "<small class='hidden-xs hidden-sm'><r>(ESC)</r></small><br>SKU",
                "nama"               => "<small class='hidden-xs hidden-sm'><r>(SHIFT+ESC)</r></small><br>ITEMS",
                "qty_unit"           => "<small class='hidden-xs hidden-sm'><r>(SHIFT+PLUS)</r></small><br>QTY",
                "satuan_factor_nama" => "UoM",//unutk satuan
            ),
        ),
        "shoppingCartFieldSrc"              => array(
            "kode"               => "kode",
            "no_part"            => "no_part",
            "nama"               => "nama",
            "label"              => "label",
            "satuan"             => "satuan",
            "satuan_id"          => "satuan_id",
            "ppn"                => "harga*(11/100)",
            "moq"                => "moq",
            "satuan_factor_id"   => "satuan_id",
            "satuan_factor_nama" => "satuan",
            "satuan_factor_qty"  => ".1",
            "ppn_produk"         => "ppn_produk",

            //-------
            "barcode"            => "barcode",
            "folder_id"          => "folder_id",
            "folder_nama"        => "folder_nama",
            "coa_code"           => "coa_code",
            //-------

            //            "berat_gross"   => "berat_gross",
            //            "lebar_gross"   => "lebar_gross",
            //            "panjang_gross" => "panjang_gross",
            //            "tinggi_gross"  => "tinggi_gross",
            //            "volume_gross"  => "volume_gross",
        ),
        "shoppingCartNumFields"             => array(
            1 => array(
                "harga_jual" => "h.jual",
                //                "disc" => "disc",
                //                "ppn" => "PPN",
                "discPersen" => "disc (%)",
                "discNilai"  => "disc (Rp)",
                "harga_disc" => "h.satuan",
                // "ppnPersen"  => "ppn (%)",
                // "ppn"        => "ppn",
                // "harga_disc" => "harga (Rp)<br><span class='text-red'>excl</span> ppn",
                // "harga_nppn" => "harga (Rp)<br>incl ppn",
            ),
//            2 => array(
//                "harga_jual" => "harga jual",
//                //                "disc" => "disc",
//                //                "ppn" => "PPN",
//                "discPersen" => "diskon (%)",
//                "discNilai"  => "diskon (Rp)",
//                "harga_disc" => "harga net",
//            ),

        ),
        "shoppingCartMinFields"             => array(
            1 => array(
                "moq" => "moq",
            ),
        ),
        "shoppingCartEditableFields"        => array(
            1 => array(
//                 "jml",
//                 "produk_ord_jml",
                "qty_unit",
//                "satuan_factor_nama",
                //                "disc_percent",
                // "discPersen",
                // "disc",
//                 "bayar",
            ),
        ),
        "shoppingCartSumFields"             => array(
            1 => array(
                "harga_jual"            => "(BELUM TERMASUK POTONGAN) Bruto Jual ",
                "discNilai"            => "Total Diskon Produk",
//                "harga_nett2"            => "bruto",
                "diskon_tambahan_persen" => "diskon member <r>(%)</r>",
                "diskon_tambahan_nilai"  => "diskon member <r>(Rp)</r>",
                "add_disc"            => "Additional Diskon",
//                "harga_nett2"            => "total belanja",
                "grand_total"            => "Grand Total",
                "cashback_nilai"         => "cashback",
                "point_transaksi"        => "point",
            ),
        ),
        "shoppingCartHideSubamount"         => array(
            1 => false,
            2 => true,
        ),
        "shoppingCartFieldValidators"       => array(
            "jml"   => "quantity",
            "harga" => "price",
        ),
        "shoppingCartFieldMidValidators"    => array(
            "jml"   => "quantity",
            "harga" => "price",
            // "hpp"   => "hpp",
        ),
        "shoppingCartRowValidators"         => array(
            "pihakID"   => "konsumen",
            // "pihakName"   => "konsumen belum dipilih",
            "harga_net" => "harga_net",
        ),
        "shoppingCartRowMidValidators"      => array(
            // "hpp"         => "hpp",
            // "harga_nett2" => "harga_nett2",
            // "tagihan"     => "tagihan",
        ),
        "shoppingCartRowOptionalValidators" => array(
            "paymentMethod" => array(
                "cash" => array(
                    "bayar" => "Jumlah dibayar harus di isi",
                ),
//                "debit_card" => array(
//                    "appr_code" => "<r><b>APPR.CODE</b></r> dari EDC wajib di isi",
//                ),
//                "credit_card" => array(
//                    "appr_code" => "<r><b>APPR.CODE</b></r> dari EDC wajib di isi",
//                ),
            ),
        ),
        "shopingCartItemOptionFields"       => array(
            1 => array(
                "satuan_factor_nama" => array(
                    "mdlName"           => "MdlProdukSatuanRelasi",
                    "usedFields"        => array(
                        "satuan_id"   => "satuan_factor_id",
                        "satuan_nama" => "satuan_factor_nama",
                        "qty"         => "satuan_factor_qty",
                    ),
                    "methode"           => "lookUpRelasiSatuan",
                    "keySrc"            => "satuan_id",
                    "targetSession"     => "items3",
                    "selectorProcessor" => "_processSelectProduct/selectFactorSatuan/582",
                ),
            ),
        ),//untuk pilihan option
        "shopingCartExtendView"             => array(
            1 => array(
                "dpp" => "dpp",
                "ppn" => "ppn",
            ),
            2 => array(
                "dpp" => "dpp",
                "ppn" => "ppn",
            ),
        ),

        //        "shoppingCartRowValidatorsByStepComparison" => array(
        //            2 => array(
        //                "source" => array(
        //                    "key" => "nilai_credit",
        //                    "label" => "total transaksi",
        //                ),
        //                "target" => array(
        //                    "key" => "kredit_limit_sisa",
        //                    "label" => "kredit available",
        //                ),
        //            ),
        //        ),

        "shoppingCartAmountValue"   => array(
            1 => "jml*harga",
            2 => "sub_harga",
        ),
        "shopingcartNumFieldHidden" => array(
            1 => array(
                "ppnPersen"  => "true", // globalPPN lihat di library/Layout
                "ppn"        => "true",
                "harga_disc" => "true",
                "hpp_nppn"   => "true",
            ),
        ),
        "shoppingCartKeyUpEvents"   => array(
            1 => array(
                "discPersen" => "document.getElementById('{disc}').value=addCommas(((parseFloat(removeCommas(this.value))*parseFloat(removeCommas(document.getElementById('{harga}').innerHTML)))/100))",
                "disc"       => "document.getElementById('{discPersen}').value=((parseFloat(removeCommas(this.value))/parseFloat(removeCommas(document.getElementById('{harga}').innerHTML)))*100)", //,this.value=addCommas(removeCommas(this.value))
            ),
        ),

        "pairPajak"                 => "true", //akan baca dari config item
        "extTool"                   => array(
            "label"     => "Otorisasi Diskon",
            "url"       => "/debug/tools/c.php",
            "field_id"  => "add_disc",
            "sentField" => "hargas",
            "sentParam" => "items",
            "gotParam"  => "items",
            "gotField"  => "harga",
            "externSrc" => "pihakID",
            "backUrl"   => "_processSelectProduct/updateValues",
        ),

//        "lockerCheckWarnOnly" => true,

        "receiptElements"           => array(
            "customerDetails" => array(
                "elementType" => "dataModel",
                "inputType" => "hidden",
                "label" => "customer details",
                "mdlName" => "MdlCustomer",
                "mdlFilter" => array("id=pihakID"),
                "key" => "id",
                "labelSrc" => "nama",
                "usedFields" => array(
                    "nama" => "name",
                    "npwp" => "tax-ID",
                    "alamat_1" => "address",
                    "tlp_1" => "phone",
                ),
                "editPoints" => array(1),
            ),

            "paymentMethod" => array(
                "elementType" => "dataModel",
                "label" => "payment method",
                "inputType" => "radio",
                "mdlName" => "MdlPaymentMethod",
                "key" => "id",
                "labelSrc" => "name",
                "usedFields" => array(
                    "name" => "method",
                ),
                "defaultValue" => "cash",
                "editPoints" => array(1,),
            ),
        ),
        "relativeElements"          => array(
            "paymentMethod" => array(
                "cash" => array(
                    "cash_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "hidden",
                        "label" => "receive on account",
                        "mdlName" => "MdlBankAccount_cash",
                        "mdlFilter" => array(
                            "cabang_id=placeID",
                        ),
                        "key" => "id",
                        "labelSrc" => "nama",
                        "usedFields" => array(
                            "nama" => "account",
                        ),
                        "editPoints" => array(1,),
                    ),
                ),

                "qris" => array(
                    "online_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "receive on account",
                        "mdlName" => "MdlBankAccount_online",
                        "mdlFilter" => array(
                            "cabang_id=placeID",
                        ),
                        "key" => "id",
                        "labelSrc" => "nama",
                        "usedFields" => array(
                            "nama" => "account",
                        ),
                        "editPoints" => array(1,),
                    ),
                ),

                "debit_card" => array(
                    "debit_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "Jenis Kartu Debit",
                        "mdlName" => "MdlDebitType",
                        "key" => "id",
                        "labelSrc" => "name",
                        "usedFields" => array(
                            "name" => "",
                        ),
                        "editPoints" => array(1,),
                    ),
                    "cash_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "receive on account",
                        "mdlName" => "MdlBankAccount_in",
                        "mdlFilter" => array(
                            "cabang_id=placeID",
                        ),
                        "key" => "id",
                        "labelSrc" => "nama",
                        "usedFields" => array(
                            "nama" => "",
                        ),
                        "editPoints" => array(1,),
                    ),
                ),
                "credit_card" => array(
                    "credit_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "Jenis Kartu Kredit",
                        "mdlName" => "MdlCreditCard",
                        "key" => "id",
                        "labelSrc" => "name",
                        "usedFields" => array(
                            "name" => "",
                        ),
                        "editPoints" => array(1,),
                    ),
                    "cash_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "receive on account",
                        "mdlName" => "MdlBankAccount_in",
                        "mdlFilter" => array(
                            "cabang_id=placeID",
                        ),
                        "key" => "id",
                        "labelSrc" => "nama",
                        "usedFields" => array(
                            "nama" => "",
                        ),
                        "editPoints" => array(1,),
                    ),
                ),
            ),
        ),
        "additionalRows"            => array(
            "paymentMethod" => array(
                "cash" => array(
                    "credit_amount" => array(
                        "label" => "credit amount",
                        "defaultValue" => "creditAmount+0",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "add_disc" => array(
                        "label" => "diskon tambahan (RP)&nbsp;<sup><r>*optional</r></sup>",
                        "defaultValue" => ".0",
                        "maxValue" => "(harga_nett2*50/100)",
                        "keyupAction" => "document.getElementById('grand_total').value= addCommas(parseFloat(removeCommas(document.getElementById('harga_nett2').value))-parseFloat(this.value))",
                        "addPoints" => array(1,),
                    ),
                    "diskon_member" => array(
                        "label" => "Diskon Member",
                        "defaultValue" => "diskon_tambahan_nilai",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    //diskon_tambahan_nilai = disc member
                    "total_harus_dibayar" => array(
                        "label" => "Total Harus di Bayar",
                        "defaultValue" => "grand_total",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "bayar" => array(
                        "label" => "<i class='fa fa-money text-bold text-primary'>&nbsp;&nbsp; BAYAR TUNAI</i><br>",
                        "defaultValue" => ".0",
                        "maxValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)*100",
                        "minValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)",
                        "keyupAction" => "
                            var gt= removeCommas(document.getElementById('total_harus_dibayar').value);
                            var bayar = removeCommas(this.value);
                            var kembali = document.getElementById('kembali');
                                kembali.value= (parseFloat(bayar)-parseFloat(gt))*1>0 ? addCommas( ( parseFloat(bayar)- (parseFloat(gt)) ) ) : 0;
                            if( parseFloat(bayar)*1 < parseFloat(gt)*1 ){
                                kembali.style.color='red';
                                kembali.style.fontWeight='700';
                                $('#btnProcess').attr('disabled', true);
                            }
                            else{
                                kembali.style.color='green';
                                kembali.style.fontWeight='700';
                                $('#btnProcess').attr('disabled', false);
                            }
                            $(this).val(addCommas(bayar));",
                        "keyPressAction" => "",
                        "addPoints" => array(1),
                    ),
                    "kembali" => array(
                        "label" => "kembali",
                        "defaultValue" => "bayar-grand_total",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                ),
                "qris" => array(
                    "bayar" => array(
                        "label" => "qris",
                        "defaultValue" => "grand_total",
                        'disabled' => "disabled",
                        "maxValue" => "",
                        "minValue" => "grand_total",
                        "keyPressAction" => "",
                        "addPoints" => array(1),
                    ),
                ),
                "debit_card" => array(
                    "credit_amount" => array(
                        "label" => "credit amount",
                        "defaultValue" => "creditAmount+0",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "add_disc" => array(
                        "label" => "diskon tambahan (RP)&nbsp;<sup><r>*optional</r></sup>",
                        "defaultValue" => ".0",
                        "maxValue" => "(harga_nett2*50/100)",
                        "keyupAction" => "document.getElementById('grand_total').value= addCommas(parseFloat(removeCommas(document.getElementById('harga_nett2').value))-parseFloat(this.value))",
                        "addPoints" => array(1,),
                    ),

                    "diskon_member" => array(
                        "label" => "Diskon Member",
                        "defaultValue" => "diskon_tambahan_nilai",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),

//                    "bayar" => array(
//                        "label" => "<span onclick=\"$('#bayar').val(10000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>10.000</span> <span onclick=\"$('#bayar').val(20000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>20.000</span> <span onclick=\"$('#bayar').val(50000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>50.000</span> <span onclick=\"$('#bayar').val(100000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>100.000</span> dibayar",
//                        "defaultValue" => ".0",
//                        "maxValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)*100",
//                        "minValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)",
//                        "keyupAction" => "
//                            var gt= removeCommas(document.getElementById('grand_total').value);
//                            var bayar = removeCommas(this.value);
//                            var add_disc = removeCommas(document.getElementById('add_disc').value);
//                            var kembali = document.getElementById('kembali');
//                                kembali.value= (parseFloat(bayar)-parseFloat(gt))*1>0 ? addCommas( ( parseFloat(bayar)- (parseFloat(gt)) ) ) : 0;
//                            if( parseFloat(bayar) < (parseFloat(gt)-parseFloat(add_disc)) ){
//                                kembali.style.color='red';
//                                kembali.style.fontWeight='700';
//                                $('#btnProcess').attr('disabled', true);
//                            }
//                            else{
//                                kembali.style.color='green';
//                                kembali.style.fontWeight='700';
//                                $('#btnProcess').attr('disabled', false);
//                            }
//                            $(this).val(addCommas(bayar));",
//                        "keyPressAction" => "",
//                        "addPoints" => array(1),
//                    ),

                    "bayar" => array(
                        "label" => "<i class='fa fa-credit-card text-bold text-green'>&nbsp;&nbsp; KARTU DEBET</i>",
                        "defaultValue" => "harga_nett1-add_disc",
                        'disabled' => "disabled",
                        "maxValue" => "",
                        "minValue" => "grand_total",
                        "keyPressAction" => "",
                        "addPoints" => array(1),
                    ),
                    "kembali" => array(
                        "label" => "<s>kembali</s>",
                        "defaultValue" => "0",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "card_number" => array(
                        "label" => "NO KARTU <sup><r>(optional)</r></sup>",
                        "defaultValue" => "",
                        "keyupAction" => "",
//                        'disabled' => "disabled",
                        "addPoints" => array(1),
                    ),
                    "appr_code" => array(
                        "label" => "APPR.CODE <sup><r>(optional kode sukses dari EDC)</r></sup>",
                        "defaultValue" => "",
                        "keyupAction" => "",
//                        'disabled' => "disabled",
                        "addPoints" => array(1),
                    ),
                ),
                "credit_card" => array(
                    "credit_amount" => array(
                        "label" => "credit amount",
                        "defaultValue" => "creditAmount+0",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "add_disc" => array(
                        "label" => "diskon tambahan (RP)&nbsp;<sup><r>*optional</r></sup>",
                        "defaultValue" => ".0",
                        "maxValue" => "(harga_nett2*50/100)",
                        "keyupAction" => "document.getElementById('grand_total').value= addCommas(parseFloat(removeCommas(document.getElementById('harga_nett2').value))-parseFloat(this.value))",
                        "addPoints" => array(1,),
                    ),
                    "diskon_member" => array(
                        "label" => "Diskon Member",
                        "defaultValue" => "diskon_tambahan_nilai",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
//                    "bayar" => array(
//                        "label" => "<span onclick=\"$('#bayar').val(10000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>10.000</span> <span onclick=\"$('#bayar').val(20000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>20.000</span> <span onclick=\"$('#bayar').val(50000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>50.000</span> <span onclick=\"$('#bayar').val(100000).trigger('keyup').trigger('mouseout');\" class='btn btn-xs btn-warning'>100.000</span> dibayar",
//                        "defaultValue" => ".0",
//                        "maxValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)*100",
//                        "minValue" => "(grand_total-diskon_tambahan_nilai-add_disc-creditAmount)",
//                        "keyupAction" => "
//                            var gt= removeCommas(document.getElementById('grand_total').value);
//                            var bayar = removeCommas(this.value);
//                            var add_disc = removeCommas(document.getElementById('add_disc').value);
//                            var kembali = document.getElementById('kembali');
//                                kembali.value= (parseFloat(bayar)-parseFloat(gt))*1>0 ? addCommas( ( parseFloat(bayar)- (parseFloat(gt)) ) ) : 0;
//                            if( parseFloat(bayar) < (parseFloat(gt)-parseFloat(add_disc)) ){
//                                kembali.style.color='red';
//                                kembali.style.fontWeight='700';
//                                $('#btnProcess').attr('disabled', true);
//                            }
//                            else{
//                                kembali.style.color='green';
//                                kembali.style.fontWeight='700';
//                                $('#btnProcess').attr('disabled', false);
//                            }
//                            $(this).val(addCommas(bayar));",
//                        "keyPressAction" => "",
//                        "addPoints" => array(1),
//                    ),

                    "bayar" => array(
                        "label" => "<i class='fa fa-credit-card text-bold text-red'>&nbsp;&nbsp; KARTU KREDIT</i>",
                        "defaultValue" => "harga_nett1-add_disc",
                        'disabled' => "disabled",
                        "maxValue" => "",
                        "minValue" => "grand_total",
                        "keyPressAction" => "",
                        "addPoints" => array(1),
                    ),
                    "kembali" => array(
                        "label" => "<s>kembali</s>",
                        "defaultValue" => "0",
                        "keyupAction" => "",
                        'disabled' => "disabled",
                        "addPoints" => array(1,),
                    ),
                    "card_number" => array(
                        "label" => "NO KARTU <sup><r>(optional)</r></sup>",
                        "defaultValue" => "",
                        "keyupAction" => "",
//                        'disabled' => "disabled",
                        "addPoints" => array(1),
                    ),
                    "appr_code" => array(
                        "label" => "APPR.CODE <sup><r>(optional kode sukses dari EDC)</r></sup>",
                        "defaultValue" => "",
                        "keyupAction" => "",
//                        'disabled' => "disabled",
                        "addPoints" => array(1),
                    ),
                )
            ),
        ),

        // "pairMakers"        => array(
        //     1 => array(
        //         "stokProduk" => array(
        //             "helperName"   => "he_cek_stock_produk_locker",
        //             "functionName" => "cekStockProdukLocker",
        //             "params"       => array(
        //                 "toko_id"   => "tokoID",
        //                 "gudang_id" => "gudang2ID",
        //                 "state"     => ".active",
        //             ),
        //         ),
        //     ),
        //     2 => array(
        //         // "kredit_limit" => array(
        //         //     "helperName"   => "he_cek_kredit_limit_customer",
        //         //     "functionName" => "cekKreditLimit",
        //         //     "params"       => array(
        //         //         "id"      => "pihakID",
        //         //         "toko_id" => "tokoID",
        //         //         //                        "state" => ".active",
        //         //     ),
        //         // ),
        //         "stokProduk"   => array(
        //             "helperName"   => "he_cek_stock_produk_locker",
        //             "functionName" => "cekStockProdukLocker",
        //             "params"       => array(
        //                 "toko_id"   => "tokoID",
        //                 "gudang_id" => "gudang2ID",
        //                 "cabang_id" => "cabangID",
        //                 "state"     => ".active",
        //             ),
        //         ),
        //     ),
        // ),
        // "pairInjectors"     => array(
        //     1 => array(
        //         "stokProduk" => array(
        //             "items" => array(
        //                 "targetKey"    => "id",
        //                 "targetColumn" => "stok",
        //             ),
        //         ),
        //     ),
        //     2 => array(
        //         "stokProduk" => array(
        //             "items" => array(
        //                 "targetKey"    => "id",
        //                 "targetColumn" => "stok",
        //             ),
        //         ),
        //     ),
        // ),
//        "connectTo"         => "110",
//        "connectoValidate"  => array(
//            2 => "ppn",
//        ),

        "clonerTransaction"         => array(
            1 => array(
                "main"      => array(
                    "cloner"        => false,
                    "validate_gate" => "ppn",
                ),
                "resetGate" => array(
                    // "items2_sum",
                    // "receiptSumFields2",
                    // "receiptDetailFields2",
                ),
            ),
        ),
        "replacerConnectTo"         => array(
            "efaktur_source" => "nomer",
            "place2ID"       => "placeID",
            "gudang2ID"      => "gudangID",
            "place2Name"     => "placeName",
            "cabang2ID"      => "cabangID",
            "cabang2Name"    => "cabangName",
        ),
        "rejected"                  => true,//untuk pembatalan transksi di ijinkan setelah habis step
        "rejectValidate"            => array(
            "settlement_id=.0",
            "trash_4=.0",
        ),
        "rejectMainField"           => array(
            "dtime"                 => "tanggal",
            "nomer"                 => "nomer",
            "customerDetails__nama" => "konsumen",
            "olehName"              => "kasir",
            "cash_account__nama"    => "payment",
        ),

//        "rejectDetilField" => array(
//            2 => array(
//                "kode"           => "kode",
//                "nama"           => "produk",
//                "merek_nama"     => "merek",
//                "satuan"         => "satuan",
//                "jml"            => "qty",
//                "harga"          => "harga",
//                "disc_percent"   => "disc (%)",
//                "disc"           => "disc (Rp)",
//                "sub_harga_disc" => "subtotal",
//            ),
//        ),

        "rejectedTraget"            => "982",
        "checkReturnStatus"         => "true",
        "pairRegistries"            => array(
            "main",
        ),

//        "requestCode"             => array(
//            "masterCode"       => "581",
//            "stateCode"        => "581r",
//            "stepNumber"       => "1",
//            "allowMultiSelect" => false,
//        ),
//        "kreditLimitValidate"     => array(
//            2 => array(
//                "label" => "Sisa kredit konsumen tidak cukup untuk menyelesaikan transaksi ini.",
//            ),
//        ),
//        "qtyItemValidate"         => array(
//            2 => array(
//                "enabled" => true,
//            ),
//        ),
//        "updateDueDate"           => array(
//            2 => array(
//                "source" => array(
//                    "top" => "key",
//                ),
//                "target" => array(
//                    "dueDate" => "value",
//                ),
//            ),
//        ),
//        "validateDueDate"         => array(
//            2 => true,
//        ),
        //------ untuk view daftar piutang dagang
//        "pairedViewPiutangDagang" => array(
//            "enabled"     => true,
//            "targetJenis" => "749",
//            "mdlName"     => "MdlPaymentSource",
//            "filter"      => array(
//                //                "target_jenis=749",
//                //                "sisa>0",
//            ),
//            "metode"      => array(
//                "0" => "transaksi",
//                "1" => "konsumen",
//            ),
//        ),

        //untuk settlement format paymentsource denga extrnBlobValue
        "connectSettlement"       => array(
            "modul" => "settlement",
            "target" => "758",
            "targetPayment" => "759",
            "btnLabel" => "Settlement",
        ),

        "settlementFields"        => array(
            "dtime" => "tanggal",
//            "fulldate"        => "tanggal",
            "customers_nama" => "konsumen",
            "nomer" => "invoice",
            "trash_4" => "status",
            "oleh_nama"       => "kasir",
            "transaksi_nilai" => "nilai",
        ),

        "previewCtr"              => "Create",

        "allowedMainEdit"         => array(1),

        //----
        "connectToEdit"           => array(
//            1 => array(
//                "enabled"   => true,
//                "connectTo" => "582re",
//                "label"     => "EDIT SALES ORDER",
//            ),
        ),
        "connectToReject"         => array(
//            1 => array(
//                "enabled"   => true,
//                "connectTo" => "580rrj",
//                "label"     => "REJECT SALES ORDER",
//            ),
//            2 => array(
//                "enabled"   => true,
//                "connectTo" => "580rj",
//                "label"     => "REJECT SALES",
//            ),
        ),
        "usedMaps"                => false,
        "validasiMaps"            => "Maps/validitasLokasi",
        "checkingReturn"          => array(
            "enable" => true,
            "filters" => array(
                "jenis=982r",
                "status_4=11",
            )
        ),
        "validasiHpp"                => true,
    ),
    "982" => array(
        "transaksiMode" => "reverse",
        "icon" => "fa fa-rotate-left",
        "label" => "sales return",
        "place" => "center",
        "steps" => array(
            1 => array(
                "runCoreAkunting"      => false, //matikan akunting
//                "runCoreAkunting"      => true, //nyalakan akunting
                "label" => "sales return",
                "actionLabel" => "save return",
                "source" => "",
                "target" => "982",
                "userGroup" => "o_seller",
                "stateLabel" => "sales return",
                "stateColor" => "red",
                "stateCaption" => "returned by",
            ),
//            2 => array(
//                "runCoreAkunting" => false,
//                "label" => "sales return approval",
//                "actionLabel" => "approve & create return",
//                "source" => "982r",
//                "target" => "982",
//                //                "userGroup"    => "o_kasir",
//                "userGroup" => "o_holding",
//                "stateLabel" => "approved & create return",
//                "stateColor" => "#ff7700",
//                "stateCaption" => "approved & create return",
//                "settlementMainFields" => array(
//                    "dtime" => array(
//                        "label" => "tanggal",
//                    ),
//                    "no_global" => array(
//                        "label" => "invoice",
//                        // "format" => "formatField",
//                        "attr" => "class='text-right'",
//                    ),
//                    "customerName" => array(
//                        "label" => "konsumen",
//                    ),
//                    "harga_nett2" => array(
//                        "label" => "return",
//                        "format" => "formatField",
//                        "sumFields" => true,
//                        "attr" => "width='60px' class='text-right'",
//                    ),
//                ),
//                "settlementItemFields" => array(
//                    "kode" => array(
//                        "label" => "kode",
//                    ),
//                    "nama" => array(
//                        "label" => "produk",
//                    ),
//                    "qty" => array(
//                        "label" => "jml",
//                        "format" => "formatField",
//                        "attr" => "width='40px'",
//                    ),
//                    "harga" => array(
//                        "label" => "harga",
//                        "format" => "formatField",
//                        "attr" => "width='60px' class='text-right'",
//                    ),
//                    "sub_jual" => array(
//                        "label" => "sub",
//                        "format" => "formatField",
//                        "attr" => "width='60px' class='text-right'",
//                    ),
//                ),
//            ),
        ),
        "template" => "template/transaksi_retur.html",
        "selectorModel" => "MdlNotaItem",
        "selectorSrcModel" => "MdlNotaItem",
        "selectedPrice" => array(
            //            "model" => "MdlHargaProduk",
            //            "label" => "hpp",
        ),
        "lockerCheck" => array(
            "enabled" => false,
            "mdlName" => "MdlLockerStockSales",
            "jenis" => "produk",
            "jenis_locker" => "sales",
        ),
        "selectorFilters" => array(
            "transaksi.returned=.0",
            "transaksi.jenis=.582",
            "transaksi.customers_id=pihakID",
            "transaksi.cabang_id=placeID",
            "transaksi.trash_4=0",
        ),
        "selectorCaller" => "_selectorItem/selectItem",// bikin shopping cart background
        "selectorLabel" => "item",
        "selectorParamFields" => array(
            "id" => "id",
            "nama" => "nomer",
            //            "satuan" => "satuan",
            //            "jumlah"=>"jumlah",
        ),
        "selectorViewedFields" => array(
            "nomer", "dtime",
        ),
        "selectorProcessor" => "_processSelectNotaItem/select",
        "selectorView" => "_selectorReturn",
        "editHandlerMethod" => "edit",
        "pihakModel" => "MdlCustomer",
        "pihakCaller" => "_selectorPihak/selectPihak",
        "pihakLabel" => "customer",
        "pihakMainValueSrc" => array(
            "ppnFactor" => "ppn",
        ),
        "pihakProcessor" => "_processPihak/select",
        "shortHistoryFields" => array(
            "jenis_label" => "activity",
            "dtime" => "date",
            "customers_nama" => "customer",
            "nomer_top" => "sales number",
            "nomer" => "return number",
            "oleh_nama" => "person",
        ),
        "compactHistoryFields" => array(
            "jenis_label" => "activity",
            "dtime" => "date",
            "customers_nama" => "customer",
            "nomer" => "receipt number",
            "oleh_nama" => "person",
        ),
        "selectorFields" => array("id", "nama", "satuan"),
        "pihakFields" => array("id", "nama"),
        // --
        "shoppingCart" => array(
            "initPrices" => "jual",
        ),
        "shoppingCartFieldSrc" => array(

            "nama" => "produk_nama",
            "code" => "produk_kode",
            "label" => "produk_label",
            "satuan" => "satuan",

            //"berat"  => "berat",
            //"lebar"  => "lebar",
            //"panjang"=> "panjang",
            //"tinggi" => "tinggi",
            //"volume" => "volume",

            //"berat_gross"   => "berat_gross",
            //"lebar_gross"   => "lebar_gross",
            //"panjang_gross" => "panjang_gross",
            //"tinggi_gross"  => "tinggi_gross",
            //"volume_gross"  => "volume_gross",

        ),
        "shoppingCartFields" => array(
            1 => array(
                "kode" => "barcode",
                "nama" => "produk",
                "satuan" => "satuan",
                "jml" => "qty",
                "jml_return" => "qty return",
            ),
            2 => array(
                "kode" => "barcode",
                "nama" => "produk",
                "satuan" => "satuan",
                "jml" => "qty",
                "jml_return" => "qty return",
            ),
        ),
        "shoppingCartNumFields" => array(
            1 => array(
                "harga_nett2" => "price",
            ),
            2 => array(
                "harga_nett2" => "price",
            ),
        ),
        "shoppingCartEditableFields" => array(
            1 => array(
//                "jml",
//                "jml_return",
            ),

//            2 => array(
//                "jml",
//            ),

        ),
        "shoppingCartAmountValue" => array(
            1 => "(jml*harga_nett2)",
            2 => "(jml*harga_nett2)",
        ),
        "shoppingCartFieldValidators" => array(
            "jml" => "quantity",
            "harga" => "price",
        ),
        "shoppingCartRowValidators" => array(
            "pihakID" => "customer ID",
            "pihakName" => "customer name",
        ),
        "shoppingCartSumFields" => array(
            1 => array(
                "harga_nett1" => "total belanja",
                "disc" => "total potongan produk / konsumen",
                "add_disc" => "potongan tambahan",
                "grand_total" => "Total yang di kembalikan ke konsumen",
                "cashback_nilai" => "cashback",
                "point_nilai" => "point",
            ),
            2 => array(
                "jual_nppn" => "amount",
                "disc" => "discount",
                "harga_nett2" => "total",
                "add_disc" => "additional disc",
                "harga_nett3" => "grand total",
            ),
        ),
        //wajib req otp sebelum nombol lanjutkan return
        "returnOTP" => "true",
        "reqReturnOTP" => array(
            "mdlName" => "MdlTmpDiskon",
        ),
//        "shoppingCartReceiptSumFields" => array(
//            1 => array(
//                "harga_nett2" => "total",
//                "add_disc" => "additional disc",
//                "harga_nett3" => "grand total",
//            ),
//            2 => array(
//                "harga_nett2" => "total",
//                "add_disc" => "additional disc",
//                "harga_nett3" => "grand total",
//            ),
//        ),
        // --
        "receiptElements" => array(
            "customerDetails" => array(
                "elementType" => "dataModel",
                "inputType" => "radio",
                "label" => "customer details",
                "mdlName" => "MdlCustomer",
                "mdlFilter" => array("id=pihakID"),
                "key" => "id",
                "labelSrc" => "nama",
                "usedFields" => array(
                    "nama" => "name",
                    "npwp" => "tax-ID",
                    "alamat_1" => "address",
                    "tlp_1" => "phone",
                ),
                "editPoints" => array(1,),
            ),
            "returnMethod" => array(
                "elementType" => "dataModel",
                "inputType" => "radio",
                "label" => "return method",
                "mdlName" => "MdlReturnMethod",
                "key" => "id",
//                "defaultValue" => "credit",
                "labelSrc" => "name",
                "usedFields" => array(
                    "name" => "method",
                ),
                "editPoints" => array(1,),
            ),
//            "reasonDetails" => array(
//                "elementType" => "dataModel",
//                "inputType" => "radio",
//                "label" => "ALASAN PEMBATALAN",
//                "mdlName" => "MdlAlasanBatal",
//                "mdlFilter" => array(),
//                "key" => "id",
//                "labelSrc" => "nilai",
//                "usedFields" => array(
//                    "nilai" => "Alasan",
//                ),
//                "editPoints" => array(1, 2, 3, 4),
//            ),
        ),
        "relativeElements" => array(
            "returnMethod" => array(
                "cash" => array(
                    "cash_account" => array(
                        "elementType" => "dataModel",
                        "inputType" => "radio",
                        "label" => "cash account to take from",
                        "mdlName" => "MdlBankAccount_cash_and_in",
                        "mdlFilter" => array(
                            "cabang_id=placeID",
                        ),
                        "key" => "id",
                        "labelSrc" => "nama",
                        "usedFields" => array(
                            "nama" => "account",
                        ),
                        "editPoints" => array(1, 2,),
                    ),
                ),
            ),
        ),
        "availPayments" => array(
            "inherit" => array(
                "label" => "inherit",
                "valueGate" => "nilai_inherit",
                "valueSrc" => "grand_total",
            ),
        ),
        "referenceFields" => array(
            "referenceID" => "transaksi_id",
            "referenceJenis" => "jenis",
            "referenceNomer" => "nomer",
            "paymentMethod" => "pembayaran",
        ),
        "referenceJenisTr" => "582",
        "shoppingCartRowMidValidators" => array(
//            "hpp" => "hpp",
        ),
        "shoppingCartRowMidItemValidators" => array(
//            "hpp" => "hpp",
        ),
        "pairPajak" => "true",
        "previewCtr" => "Create",
    ),
);
?>