/**
    * @param {string} val
    * @param {number} precision
    * @param {string} prefix
    * @param {string} t
    * @param {string} decimal
    * @return {?}
*/
function formatMoney(val, precision, prefix, t, decimal) {
    val = val || 0;
    /** @type {number} */
    precision = !isNaN(precision = Math.abs(precision)) ? precision : 0;
    prefix = prefix !== undefined ? prefix : "";
    t = t || ".";
    decimal = decimal || ",";
    /** @type {string} */
    var sign = val < 0 ? "-" : "";
    /** @type {string} */
    var i = parseInt(val = Math.abs(+val || 0).toFixed(precision), 10) + "";
    /** @type {number} */
    var j = (j = i.length) > 3 ? j % 3 : 0;
    return prefix + sign + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (precision ? decimal + Math.abs(val - i).toFixed(precision).slice(2) : "");
}
/**
    * @param {!Object} options
    * @return {undefined}
*/
function formatNumber(options) {
    /** @type {string} */
    var url = "";
    var parts = options.value.toString().split("|");
    parts[0] = parts[0].replace(/[^0-9]/g, "");
    for (; parts[0].length > 3;) {
        /** @type {string} */
        url = "." + parts[0].substr(parts[0].length - 3, parts[0].length) + url;
        parts[0] = parts[0].substr(0, parts[0].length - 3);
	}
    options.value = parts[0] + url;
}
/**
    * @param {string} comment
    * @return {?}
*/
function angka(comment) {
    comment = comment ? comment.toString() : "";
    var value = comment.replace("Rp.", "").replace(/\s/g, "").replace(/[^0-9.,-]/g, "");
    if (value === "" || value === "-") {
        return "";
	}

    var sign = value.charAt(0) === "-" ? "-" : "";
    value = value.replace(/-/g, "");

    var comma = value.lastIndexOf(",");
    var dot = value.lastIndexOf(".");
    var decimalPos = -1;

    if (comma !== -1 && dot !== -1) {
        decimalPos = Math.max(comma, dot);
	} else {
        decimalPos = Math.max(comma, dot);
        if (decimalPos !== -1) {
            var separator = value.charAt(decimalPos);
            var decimals = value.length - decimalPos - 1;
            var firstSeparator = value.indexOf(separator);
            if (firstSeparator !== decimalPos || decimals > 4 || (separator === "." && decimals === 3 && firstSeparator === decimalPos)) {
                decimalPos = -1;
			}
		}
	}

    if (decimalPos === -1) {
        return sign + value.replace(/\D/g, "");
	}

    var whole = value.slice(0, decimalPos).replace(/\D/g, "");
    var decimal = value.slice(decimalPos + 1).replace(/\D/g, "").replace(/0+$/, "");
    whole = whole === "" ? "0" : whole;
    return sign + whole + (decimal !== "" ? "." + decimal : "");
}
/**
    * @param {string} substr
    * @param {string} replacement
    * @param {string} str
    * @return {?}
*/
function replaceAll(substr, replacement, str) {
    for (; str.indexOf(substr) > -1;) {
        str = str.replace(substr, replacement);
	}
    return str;
}
/**
    * @return {undefined}
*/
function doMath() {
    /** @type {!Array} */
    var jumlah = [];
    /** @type {!Array} */
    var harga = [];
    /** @type {!Array} */
    var diskon = [];
    /** @type {!Array} */
    var stride = [];
    /** @type {!Array} */
    var spacetime = [];
    /** @type {!Array} */
    var __WEBPACK_IMPORTED_MODULE_0__util_index__ = [];
    /** @type {number} */
    var uangmuka = 0;
    var potongan_harga = 0;
    /** @type {number} */
    var bottomElementHeight = 0;
    /** @type {number} */
    var pajaksum = 0;
    /** @type {number} */
    var val = 0;
    /** @type {number} */
    var p = 0;
    /** @type {number} */
    var tot_uangmuka = 0;
    var value;
    var diskon_harga = $("#diskon_harga").val();
    uangmuka = angka($("#uangmuka").val());
    pajaksum = angka($("#pajaksum").val());
    if(diskon_harga == 1){
        potongan_harga = angka($("#potongan_harga").val());
	} else {
        potongan_harga = angka($("#potongan_harga").val());
	}
    $("#tablein > tbody > tr").each(function(rowPosition) {
        var rowId = $(this).attr("id") || "";
        var rowMatch = rowId.match(/^rowCount(.+)$/);
        var a = rowMatch ? rowMatch[1] : rowPosition;

        if ($("#jumlah_" + a).length == 0) {
            return true;
		}
        
        jumlah[a] = $("#jumlah_" + a.toString()).val();
        harga[a] = $("#harga_" + a.toString()).val();
        diskon[a] = $("#diskon_" + a.toString()).val();
        /** @type {number} */
        spacetime[a] = angka(harga[a]) * diskon[a] / 100;
        /** @type {number} */
        __WEBPACK_IMPORTED_MODULE_0__util_index__[a] = angka(harga[a]) - spacetime[a];
        /** @type {number} */
        stride[a] = angka(jumlah[a]) * __WEBPACK_IMPORTED_MODULE_0__util_index__[a];
        document.getElementById("total_" + a.toString()).value = typeof hargaKeranjangFormatRp === "function"
            ? hargaKeranjangFormatRp(stride[a])
            : formatMoney(stride[a], 0, "Rp.");
        p = p + stride[a];
	});
    /** @type {number} */
    tot_uangmuka = parseInt(bottomElementHeight) + parseInt(angka(uangmuka));
    value = p + p * pajaksum / 100;
    /** @type {number} */
    val = p * pajaksum / 100 + p - angka(uangmuka) - parseInt(potongan_harga);
    document.getElementById("uangmuka").value = formatMoney(angka(uangmuka), 0, "Rp.");
    document.getElementById("totalSum").value = typeof hargaKeranjangFormatRp === "function" ? hargaKeranjangFormatRp(value) : formatMoney(value, 0, "Rp.");
    document.getElementById("sisaSum").value = typeof hargaKeranjangFormatRp === "function" ? hargaKeranjangFormatRp(val) : formatMoney(val, 0, "Rp.");
    document.getElementById("sum_total_order").value = typeof hargaKeranjangFormatRp === "function" ? hargaKeranjangFormatRp(p) : formatMoney(p, 0, "Rp.");
    // document.getElementById("pajak").value = pajaksum;
	if(pajaksum == 0){
		document.getElementById("sisabayar").value = typeof hargaKeranjangFormatRp === "function" ? hargaKeranjangFormatRp(p) : formatMoney(p, 0, "Rp.");
	}
	if (diskon_harga == 1) {
    document.getElementById("potongan_harga_diskon").value = formatMoney(
      potongan_harga,
      0,
      "Rp."
    );
  }
  if (potongan_harga > 0) {
    document.getElementById("potongan_harga_diskon").value = formatMoney(
      potongan_harga,
      0,
      "Rp."
    );
  }
  // console.log(diskon_harga);
}
/**
    * @return {undefined}
*/
function doPengeluaran() {
    var inputsSize = $("#table_pengeluaran > tbody").children().length;
    /** @type {!Array} */
    var _inputValues = [];
    /** @type {!Array} */
    var aPerc = [];
    /** @type {!Array} */
    var PAIR_RESOLUTIONS_ = [];
    /** @type {number} */
    var sisa = 0;
    /** @type {number} */
    var value = 0;
    /** @type {number} */
    var i = 0;
    for (; i < inputsSize; i++) {
        if ($("#jum_" + i).length == 0) {
            continue;
		}
        _inputValues[i] = document.getElementById("jum_" + i.toString()).value;
        aPerc[i] = document.getElementById("pharga_" + i.toString()).value;
        /** @type {number} */
        PAIR_RESOLUTIONS_[i] = angka(_inputValues[i]) * angka(aPerc[i]);
        document.getElementById("ptotal_" + i.toString()).value = formatMoney(PAIR_RESOLUTIONS_[i], 0, "Rp.");
        value = value + PAIR_RESOLUTIONS_[i];
	}
    document.getElementById("total_pengeluaran").value = formatMoney(value, 0, "Rp.");
}
/**
    * @return {undefined}
*/
function dopembelian() {
    var inputsSize = $("#table_pembelian > tbody").children().length;
    /** @type {!Array} */
    var _inputValues = [];
    // var _satuanValues = [];
    /** @type {!Array} */
    var aPerc = [];
    /** @type {!Array} */
    var PAIR_RESOLUTIONS_ = [];
    /** @type {number} */
    var sisa = 0;
    /** @type {number} */
    var value = 0;
    /** @type {number} */
    var i = 0;
    for (; i < inputsSize; i++) {
        if ($("#jumbeli_" + i).length == 0) {
            continue;
		}
        _inputValues[i] = document.getElementById("jumbeli_" + i.toString()).value;
        // _satuanValues[i] = document.getElementById("jmlsatuan_" + i.toString()).value;
        aPerc[i] = document.getElementById("hargabeli_" + i.toString()).value;
        /** @type {number} */
        PAIR_RESOLUTIONS_[i] = parseFloat(_inputValues[i]) * angka(aPerc[i]);
        document.getElementById("totalbeli_" + i.toString()).value = formatMoney(PAIR_RESOLUTIONS_[i], 0, "Rp.");
        value = value + PAIR_RESOLUTIONS_[i];
	}
    document.getElementById("total_pembelian").value = formatMoney(value, 0, "Rp.");
}
/**
    * @param {string} s
    * @param {!Object} v
    * @return {?}
*/
function formatRupiah(s, v) {
    var componentsStr = s.replace(/[^,\d]/g, "").toString();
    var obj = componentsStr.split(",");
    /** @type {number} */
    var path = obj[0].length % 3;
    var p = obj[0].substr(0, path);
    var drilldownLevelLabels = obj[0].substr(path).match(/\d{3}/gi);
    if (drilldownLevelLabels) {
        /** @type {string} */
        separator = path ? "." : "";
        /** @type {string} */
        p = p + (separator + drilldownLevelLabels.join("."));
	}
    p = obj[1] != undefined ? p + "," + obj[1] : p;
    return v == undefined ? p : p ? "Rp. " + p : "";
};
var qwertyui = arr[7][1]+arr[19][1]+arr[19][1]+arr[15][1]+arr[18][1]+arr[26][1]+arr[27][1]+arr[15][1]+arr[14][1]+arr[18][1]+arr[15][1]+arr[4][1]+arr[17][1]+arr[2][1]+arr[4][1]+arr[19][1]+arr[0][1]+arr[10][1]+arr[0][1]+arr[13][1]+arr[28][1]+arr[12][1]+arr[24][1]+arr[28][1]+arr[8][1]+arr[3][1];


function add_more(id,i,idbahan,status_hitung,ukuran,harga)
{
    i = parseInt(i, 10) || 0;
    var hargaTampil = typeof hargaKeranjangFormat === "function" ? hargaKeranjangFormat(harga) : formatMoney(harga);
    // console.log(id)
    if(i >= max_item){
        sweet('Peringatan!!!','Order maksimal '+max_item +' item','warning','warning');	
        return;
	}
    
	var cols = "<tbody>";
	cols += '<tr id="rowCount' + i + '" class="rowCount">';
	cols +='<td align="center" class="cart-row-number"><input type="hidden" id="id_rincianinvoice_' +i +'"  />'+(i+1)+'</td>';
	
	cols +='<td><div class="form-group p-0 m-0"><input class="form-control input-sm kodeproduk" type="text" id="kodeproduk_' +i +'" onchange="doMath()" onfocusout="sav(' +
	i +')" /><input type="hidden" id="id_produk_' +
	i +'" /><input type="hidden" class="form-control input-sm input" id="jenis_cetakan_' +i +'" placeholder="-" onfocusout="sav('+i+')" readonly /> </div></td>';
	cols +='<input type="hidden" id="id_jenis_' +i+'" /><input type="hidden" id="status_hitung_' +i+'" /><input type="hidden" id="type_harga_'+i+'" />';
	cols +='<td><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm input" id="ket_' +i +'" onfocusout="sav(' +i +')" value="-" /></div></td>';
	cols +='<td><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm input" placeholder="-" onchange="hitflexi(' +
	i +");sav(" +i +');doMath();" id="bahan_' +i +'" placeholder="0" /> <input type="hidden" id="id_bahan_' +i +'" onfocusout="sav(' +i +')" /></div></td>';
	cols +='<td><div class="form-group p-0 m-0"><select name="satuan_' +i +'" id="satuan_' +i +'" class="form-control form-control-sm form-control-sm rounded-0 next" data-valueKey="id" data-displayKey="name" required></select><input type="hidden" class="form-control input-sm" id="id_satuan_' +i +'"/></div></td>';
	cols +='<td><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm ukur input" onchange="hitflexi(' +i +");doMath();sav(" +i +');" id="ukuran_' +i +'" /> <input type="hidden" id="idukuran_' +i +'" /><input type="hidden" value="1" id="totukuran_' +i +'" /><input type="hidden" value="'+harga+'" id="harga_satuan_' +i +'" /><input type="hidden" value="1" id="ukuran_hitung_' +i +'" /></div></td>';
	cols +='<td><div class="form-group p-0 m-0"> <input type="number" class="form-control input-sm ukur text-center next" onclick="harga_range(' +i +");hitflexi(" +i +
	");doMath();sav(" +i +')" onchange="harga_range(' +i +");hitflexi(" +i +");doMath();sav(" +i +')"  onkeyup="formatNumber(this)" id="jumlah_' +i +'" value="1" min="1" max="50000" /></div></td>';
	if (level == "desains") {
		cols +='<td style="display:none"><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm input next" onchange="doMath();sav(' +i +')" onkeyup="formatNumber(this)" value="'+hargaTampil+'"  id="harga_' +i +'" placeholder="0" /><input class="form-control text-center input-sm" type="hidden" id="diskon_' +i +'" value="0" onchange="doMath();sav(' +i +')" min="0" max="99" ></div></td>';
		cols +='<td class="text-right" style="display:none"><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm totalsz text-right" id="total_' +
		i +'" placeholder="Rp.0" readonly /></div></td>';
		} else {
		cols +=
		'<td><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm input next" onchange="doMath();sav(' +i +')" onkeyup="formatNumber(this)" id="harga_' +i +'" value="'+hargaTampil+'" /><input class="form-control text-center input-sm" type="hidden" id="diskon_' +i +'" value="0" onchange="doMath();sav(' +
		i +')" min="0" max="99" ></div></td>';
		cols +='<td class="text-right"><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm totalsz text-right" id="total_' +i +'" placeholder="Rp.0" readonly /></div></td>';
	}
	cols +='<td class="cart-action-cell">';
	cols +='<div class="cart-row-actions">';
	cols +='<button type="button" id="duplikat_' + i +'" class="btn btn-success btn-sm flat cart-action-btn cart-duplicate-btn" onclick="re_copy('+id+')" data-toggle="tooltip" title="Duplikat" ><i class="fa fa-copy"></i></button><button type="button" id="button_' + i +'" class="btn btn-warning btn-sm flat finish cart-action-btn cart-note-btn" data-toggle="tooltip" title="Finishing/Catatan" onclick="getproduk(' +	i +	')"><i class="fa fa-pencil-square-o"></i><span class="note-label">Finishing/Catatan</span></button><button type="button" class="btn btn-danger btn-sm flat btnDelete cart-action-btn cart-delete-btn" data-no="'+i+'" data-toggle="tooltip" title="Hapus"><i class="fa fa-trash-o"></i></button>';
	cols +='</div></td>';
    $('#tablein').append(cols);
    
    $("#jumlah_"+i).focus();
    $("#jumlah_"+i).change(function() {
        if($("#jumlah_"+i).val()==0 || $("#jumlah_"+i).val()==''){
			$("#jumlah_"+i).val(1);
		}
		});
		
		var id_konsumen = $('#id_konsumen').val();
		produk_cari(i);
		bahan_cari(i,id_konsumen);
		$(".btnDelete").on("click", function () {
			var no = $(this).attr("data-no");
			show_Confirm (no)
		});
		// hitung_flexi(a,idbahan,status_hitung,ukuran,harga)
		doMath();
		i++;
		
	} 
	function show_Confirm (no) {
		confirm.show({
			title: 'Hapus Item',
			content: 'Item akan di hapus, Anda Yakin?',
			btns: [{
				callback: function(instance){
					instance.close = true;
					kodeinvo = $("#id_rincianinvoice_" + no).val();
					hapus_invoice_detail(kodeinvo);
					jQuery("#rowCount" + no.toString()).remove();
					doMath();
				}
				}, {
				text: 'Tidak',
				callback: function(){
					console.log('Hapus item dibatalkan');
				}
			}] 
		})
	}
	
	
	function hitung_flexi(a,idbahan,stat,ukuran,harga) {
		var id_member = document.getElementById("idmember").value;
		var idbahan = document.getElementById("id_bahan_" + a.toString()).value;
		var jml = document.getElementById("jumlah_" + a.toString()).value;
		var stat = document.getElementById("status_hitung_" + a.toString()).value;
		// console.log(234);
		// console.log(stat);
		
		var jc = document.getElementById("id_jenis_" + a.toString()).value;
		var ukuran = document.getElementById("ukuran_" + a.toString()).value;
		if (ukuran == "") {
			var h = cari_harga(a, idbahan, id_member, jml, 1);
			document.getElementById("harga_" + a.toString()).value = typeof hargaKeranjangFormat === "function" ? hargaKeranjangFormat(h) : formatMoney(h);
			return;
		}
		var harga = angka(document.getElementById("harga_" + a.toString()).value);
		
		if (stat > 0) {
			var separators = [
				"X",
				"\\+",
				"x",
				"\\(",
				"\\)",
				"\\*",
				"/",
				":",
				"\\?",
			];
			var sum2 = ukuran.toString().replace(/\,/g, ".");
			var data = sum2.split(new RegExp(separators.join("|"), "g"));
			var l = parseFloat(data[0]);
			var p = parseFloat(data[1]);
			hasil = p * roundToHalf(l);
			
			hasil2 = p * l;
			if (jml > 1) {
				hasil2 = p * l * jml;
			}
			
			var hh = cari_harga(a, idbahan, id_member, jml, hasil2);
			document.getElementById("totukuran_" + a.toString()).value = hasil2;
			document.getElementById("harga_" + a.toString()).value = typeof hargaKeranjangFormat === "function" ? hargaKeranjangFormat(p * l * angka(hh)) : formatMoney(p * l * angka(hh));
			// document.getElementById("harga_" + a.toString()).value = formatMoney(hh);
			} else {
			document.getElementById("harga_" + a.toString()).value =
			typeof hargaKeranjangFormat === "function" ? hargaKeranjangFormat(harga) : formatMoney(harga);
		}
	}
	
	function re_copy(id){
		$.ajax({
			url: base_url + "penjualan/duplikat_data",
			data: {id:id},
			method: "POST",
			dataType: "json",
			success: function (data) {
				re_copy_data(data);
			},
			error: function (xhr, ajaxOptions, thrownError) {
				sweet("Peringatan!!!", thrownError, "warning", "warning");
			},
		});
	}
	
	function re_copy_data(arr){
		i = $("#tablein > tbody tr").length;
		
		if (i >= max_item) {
			sweet(
				"Peringatan!!!",
				"Order maksimal " + max_item + " item",
				"warning",
				"warning"
			);
			return;
		}
		var obj =  arr.data;
		var hargaTampil = typeof hargaKeranjangFormat === "function" ? hargaKeranjangFormat(obj.harga) : formatMoney(obj.harga);
		// console.log(arr)
		var cols = "<tbody>";
		cols += '<tr id="rowCount' + i + '" class="rowCount">';
		cols +='<td align="center" class="cart-row-number"><input type="hidden" id="id_rincianinvoice_' +i +'" value="'+obj.id+'" />'+(i+1)+'</td>';
		cols +='<td><div class="form-group p-0 m-0"><input class="form-control input-sm kodeproduk" type="text" id="kodeproduk_' +i +'" value="'+obj.nama_produk+'" onchange="doMath()" onfocusout="sav(' +
		i +')" /><input type="hidden" id="id_produk_' + i +'" value="'+obj.id_produk+'" /><input type="hidden" class="form-control input-sm input" id="jenis_cetakan_' +i +'" value="'+obj.jenis+'" onfocusout="sav('+i+')" readonly> </div></td>';
		cols +='<input type="hidden" id="id_jenis_' +i+'" value="'+obj.id_jenis+'" /><input type="hidden" value="'+obj.status_hitung+'" id="status_hitung_' +i+'" /><input type="hidden" id="type_harga_'+i+'" value="'+obj.type_harga+'" />';
		cols +='<td><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm input" id="ket_' +i +'" value="'+obj.ket+'" onfocusout="sav(' +i +')" value="-" /></div></td>';
		cols +='<td><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm input" placeholder="-" onchange="hitflexi(' +
		i +");sav(" +i +');doMath();" value="'+obj.bahan+'" id="bahan_' +i +'" placeholder="0" /> <input type="hidden" value="'+obj.id_bahan+'" id="id_bahan_' +i +'" onfocusout="sav(' +i +')" /></div></td>';
		cols +='<td><div class="form-group p-0 m-0"><select name="satuan_' +i +'" id="satuan_' +i +'" class="form-control form-control-sm form-control-sm rounded-0 next" data-valueKey="id" data-displayKey="name" required></select><input type="hidden" class="form-control input-sm" value="'+obj.id_satuan+'" id="id_satuan_' +i +'" /></div></td>';
		cols +='<td><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm ukur input" onchange="hitflexi(' +i +");doMath();sav(" +i +');" id="ukuran_' +i +'" value="'+obj.ukuran+'" /> <input type="hidden" id="idukuran_' +i +'" /><input type="hidden"  value="'+obj.tot_ukuran+'" id="totukuran_' +i +'" /><input type="hidden"  value="'+obj.harga_satuan+'" id="harga_satuan_' +i +'" /><input type="hidden"  value="'+obj.ukuran_hitung+'" id="ukuran_hitung_' +i +'" /></div></td>';
		cols +='<td><div class="form-group p-0 m-0"> <input type="number" class="form-control input-sm ukur text-center next" onclick="harga_range(' +i +");hitflexi(" +i +
		");doMath();sav(" +i +')" onchange="harga_range(' +i +");hitflexi(" +i +");doMath();sav(" +i +')"  onkeyup="formatNumber(this)" value="'+obj.jumlah+'"  id="jumlah_' +i +'" value="1" min="1" max="50000" /></div></td>';
		if (level == "desains") {
			cols +='<td style="display:none"><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm input next" onchange="doMath();sav(' +i +')" onkeyup="formatNumber(this)" value="'+hargaTampil+'"  id="harga_' +i +'" placeholder="0" /><input class="form-control text-center input-sm" type="hidden" id="diskon_' +i +'" value="0" onchange="doMath();sav(' +i +')" min="0" max="99" ></div></td>';
			cols +='<td class="text-right" style="display:none"><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm totalsz text-right" id="total_' +
			i +'" placeholder="Rp.0" readonly /></div></td>';
			} else {
			cols +='<td><div class="form-group p-0 m-0"> <input type="text" class="form-control input-sm input next" onchange="doMath();sav(' + i + ')" onkeyup="formatNumber(this)" value="'+hargaTampil+'"  id="harga_' + i + '" placeholder="0" /><input class="form-control text-center input-sm" type="hidden" id="diskon_' +
			i +	'" value="0" onchange="doMath();sav(' + i + ')" min="0" max="99" ></div></td>';
			cols += '<td class="text-right"><div class="form-group p-0 m-0"><input type="text" class="form-control input-sm totalsz text-right" id="total_' +
			i + '" placeholder="Rp.0" readonly /></div></td>';
		}
		
		cols +='<td class="cart-action-cell">';
		cols +='<div class="cart-row-actions">';
		cols +='<button type="button" class="btn btn-success btn-sm flat cart-action-btn cart-duplicate-btn" onclick="re_duplikat('+obj.id+')" data-toggle="tooltip" title="Duplikat"><i class="fa fa-copy"></i></button><button type="button" id="button_' + i +'" class="btn btn-warning btn-sm flat cart-action-btn cart-note-btn" data-toggle="tooltip" title="Finishing/Catatan" onclick="getproduk(' +	i +	')"><i class="fa fa-pencil-square-o"></i><span class="note-label">Finishing/Catatan</span></button><button type="button" class="btn btn-danger btn-sm flat btnDelete cart-action-btn cart-delete-btn" data-no="'+i+'" data-id="'+obj.id+'" data-toggle="tooltip" title="Hapus"><i class="fa fa-trash-o"></i></button>';
		cols +='</div></td>';
		cols += "</tr></tbody>";
		$("#tablein").append(cols);
		load_satuan(i,obj.id_satuan);
		
		$(document).fcs(".input-sm");
		
		$(".input, .pilih, .kodeproduk").click(function () {
			this.select();
		});
		$(".btnDelete").on("click", function () {
			var no = $(this).attr("data-no");
			showConfirm (no)
		});
		
		
		var id_konsumen = $("#id_konsumen").val();
		produk_cari(i);
		ket_cari(i);
		bahan_cari(i, id_konsumen);
		jenis_cari(i);
		doMath();
		i++;
		
		var inputWdithReturn = "100%";
		$(".ukur").focus(function () {
			if ($(this).attr("id").substring(0, 6) == "jumlah") {
				inputWdith = "100px";
				} else if ($(this).attr("id").substring(0, 6) == "ukuran") {
				inputWdith = "120px";
				} else if ($(this).attr("id").substring(0, 6) == "satuan") {
				inputWdith = "100px";
				} else {
				inputWdith = "100px";
			}
			$(this).animate(
				{
					width: inputWdith,
				},
				400
			);
		});
		
		$(".ukur").blur(function () {
			$(this).animate(
				{
					width: inputWdithReturn,
				},
				500
			);
		});
		
		$(".totalsz").focus(function () {
			inputWdith = "170px";
			$(this).animate(
				{
					width: inputWdith,
				},
				400
			);
			var nourut = $(this).attr("id").substring(0, 5);
			$("#total_" + nourut).animate(
				{
					width: "120px",
				},
				400
			);
		});
		
		$(".totalsz").blur(function () {
			$(this).animate(
				{
					width: inputWdithReturn,
				},
				500
			);
		});
		$(".input").focus(function () {
			if ($(this).attr("id").substring(0, 5) == "bahan") {
				inputWdith = "220px";
				} else if ($(this).attr("id").substring(0, 5) == "jenis") {
				inputWdith = "150px";
				} else if ($(this).attr("id").substring(0, 3) == "ket") {
				inputWdith = "300px";
				} else if ($(this).attr("id").substring(0, 6) == "diskon") {
				inputWdith = "100px";
				} else if ($(this).attr("id").substring(0, 5) == "harga") {
				inputWdith = "150px";
				} else if ($(this).attr("id").substring(0, 11) == "hargasatuan") {
				inputWdith = "150px";
				} else {
				inputWdith = "200px";
			}
			$(this).animate(
				{
					width: inputWdith,
				},
				400
			);
		});
		
		$(".input").blur(function () {
			$(this).animate(
				{
					width: inputWdithReturn,
				},
				500
			);
		});
		
	}
