Hari
%-HJam
%MMenit
%SDetik
')); }); }); function getExtension(filename) { var parts = filename.split('.'); return parts[parts.length - 1]; } function isImage(filename) { var ext = getExtension(filename); switch (ext.toLowerCase()) { case 'jpg': case 'gif': case 'png': case 'jpeg': case '': return true; } return false; } //Date Range Picker var newURL = window.location.protocol + "://" + window.location.host + "/" + window.location.pathname; var pathArray = window.location.pathname.split( '/' ); var segment_1 = pathArray[1]; var segment_2 = pathArray[2]; var segment_3 = pathArray[3]; var segment_4 = pathArray[4]; var segment_5 = pathArray[5]; if (segment_1 == 'business') { // SEARCH ---------------------------------------------------- var search = {}; search.form = $('#search-top'); search.typingTimer; //timer identifier search.typingInterval = 1500; //time in ms, 5 second for example search.query = ''; //on keyup, start the countdown search.form.find('[data-role="search-input"]').keyup(function(){ search.query = $(this).val(); search.category = search.form.find('[data-role="search-category"]').val(); clearTimeout(search.typingTimer); search.form.find('[data-role="search-result"]').addClass('hidden'); search.form.find('[data-role="search-loader"]').removeClass('fa-search'); search.form.find('[data-role="search-loader"]').addClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').addClass('fa-spin'); search.typingTimer = setTimeout(getResult, search.typingInterval); }); search.form.find('[data-role="search-category"]').change(function(){ search.category = $(this).val(); search.query = search.form.find('[data-role="search-input"]').val(); clearTimeout(search.typingTimer); search.form.find('[data-role="search-result"]').addClass('hidden'); search.form.find('[data-role="search-loader"]').removeClass('fa-search'); search.form.find('[data-role="search-loader"]').addClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').addClass('fa-spin'); search.typingTimer = setTimeout(getResult, search.typingInterval); }); //on keydown, clear the countdown search.form.find('[data-role="search-input"]').keydown(function () { clearTimeout(search.typingTimer); search.form.find('[data-role="search-loader"]').addClass('fa-search'); search.form.find('[data-role="search-loader"]').removeClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').removeClass('fa-spin'); }); function getResult() { if( search.query.length >= 3 ) { $.get($.URL.Base('member/search/navbar-result'),{ q: search.query, c: search.category, entries: 2 }).done(function(response){ search.form.find('[data-role="search-result"]').removeClass('hidden'); search.form.find('[data-role="search-loader"]').addClass('fa-search'); search.form.find('[data-role="search-loader"]').removeClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').removeClass('fa-spin'); var result = response.result.data; search.form.find('[data-role="search-result-item"]').remove(); search.form.find('[data-role="search-query"]').html(search.query); search.form.find('[data-role="search-result-products"]').addClass('hidden'); search.form.find('[data-role="search-result-business"]').addClass('hidden'); search.form.find('[data-role="search-result-articles"]').addClass('hidden'); search.form.find('[data-role="search-result-products"]').removeClass('hidden').attr('href', $.URL.Base('member/search/result') + '/?q=' + search.query + '&c=products'); search.form.find('[data-role="search-result-products-numbers"]').html(result.products.num_rows); search.form.find('[data-role="search-result-business"]').removeClass('hidden').attr('href', $.URL.Base('member/search/result') + '/?q=' + search.query + '&c=business'); search.form.find('[data-role="search-result-business-numbers"]').html(result.business.num_rows); search.form.find('[data-role="search-result-articles"]').removeClass('hidden').attr('href', $.URL.Base('member/search/result') + '/?q=' + search.query + '&c=articles'); search.form.find('[data-role="search-result-articles-numbers"]').html(result.articles.num_rows); var resultItemTpl = search.form.find('[data-pattern="search-result-item"]').clone(); resultItemTpl.attr('data-role', 'search-result-item').removeAttr('data-pattern').removeClass('hidden').addClass('result-item'); if(result.products.num_rows > 0) { $.each(result.products.latest, function(index, product){ var resultItem = resultItemTpl.clone(); resultItem.attr('href', product.url); resultItem.find('[data-role="search-picture"]').attr('src', product.image); resultItem.find('[data-role="search-name"]').html(product.name); resultItem.find('[data-role="search-type"]').html('Products'); search.form.find('[data-pattern="search-result-item"]').before(resultItem); }); } if(result.business.num_rows > 0) { $.each(result.business.latest, function(index, business){ var resultItem = resultItemTpl.clone(); resultItem.attr('href', business.url); resultItem.find('[data-role="search-picture"]').attr('src', business.logo); resultItem.find('[data-role="search-name"]').html(business.title); resultItem.find('[data-role="search-type"]').html('Business'); search.form.find('[data-pattern="search-result-item"]').before(resultItem); }); } if(result.articles.num_rows > 0) { $.each(result.articles.latest, function(index, article){ var resultItem = resultItemTpl.clone(); resultItem.attr('href', article.url); resultItem.find('[data-role="search-picture"]').attr('src', article.image); resultItem.find('[data-role="search-name"]').html(article.title); resultItem.find('[data-role="search-type"]').html('Articles'); search.form.find('[data-pattern="search-result-item"]').before(resultItem); }); } search.form.find('[data-role="search-query-url"]').attr('href', $.URL.Base('member/search/result') + '/?q=' + search.query + '&c=all'); }); } else { search.form.find('[data-role="search-loader"]').addClass('fa-search'); search.form.find('[data-role="search-loader"]').removeClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').removeClass('fa-spin'); search.form.find('[data-role="search-result"]').addClass('hidden'); } } $('#page-wrapper').click(function(){ search.form.find('[data-role="search-loader"]').addClass('fa-search'); search.form.find('[data-role="search-loader"]').removeClass('fa-circle-o-notch'); search.form.find('[data-role="search-loader"]').removeClass('fa-spin'); search.form.find('[data-role="search-result"]').addClass('hidden'); }); $('input[name="wallet_time"]').daterangepicker({ autoUpdateInput: false, locale: { cancelLabel: 'Clear' } }); $('input[name="wallet_time"]').on('apply.daterangepicker', function(ev, picker) { $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY')); }); $('input[name="wallet_time"]').on('cancel.daterangepicker', function(ev, picker) { $(this).val(''); }); $('[data-target="#walletExportModal"]').on('click', function(){ document.getElementById("myFormExportWallet").reset(); }); $('[data-action="export-wallet"]').on('click', function () { $('#walletExportModal').modal('hide'); }); } //add collapse to all tags hiden and showed by select mystuff $('#time-collapse').addClass('collapse'); //on change hide all divs linked to select and show only linked to selected option $('#time-selector').change(function(){ //Saves in a variable the wanted div var selector = '#time-collapse' if ($('#time-selector').val() == 'PERIODIC') { document.getElementById("time-collapse").style.display = ""; $('#time-collapse').collapse('show'); }else { $('#time-collapse').collapse('hide'); } }); //manager customer page if(segment_4 == 'business_customer') { if((segment_5 == undefined) || ($.isNumeric(segment_5) == false)) { $(document).ready(function(){ var start = moment().startOf('month'); var end = moment(); var startDate = moment().startOf('month').format('YYYY-MM-DD'); var endDate = moment().format('YYYY-MM-DD'); function cb(start, end) { $('#customer-date').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); } //call function getTotalCustomer(); getTransactionAverage(); getRevenueAverage(); $('#customer-date').daterangepicker({ startDate: start, endDate: end, autoUpdateInput: false, timePicker: false, locale: { format: 'DD/MM/YYYY', cancelLabel: 'Clear' }, },cb); cb(start, end); $('#customer-date').on('apply.daterangepicker', function(ev, picker) { $(this).val(picker.startDate.format('MMMM D, YYYY') + ' - ' + picker.endDate.format('MMMM D, YYYY')); //triger function getTotalCustomer(picker.startDate.format('YYYY-MM-DD'), picker.endDate.format('YYYY-MM-DD')); getTransactionAverage(picker.startDate.format('YYYY-MM-DD'), picker.endDate.format('YYYY-MM-DD')); getRevenueAverage(picker.startDate.format('YYYY-MM-DD'),picker.endDate.format('YYYY-MM-DD')); }); $('#customer-date').on('cancel.daterangepicker', function(ev, picker) { cb(start, end); }); }); } else { //customer detail $(document).ready(function() { lifeTimeValue(segment_5); getTotalTransaction(segment_5); getTotalTransactionItems(segment_5); getLifeTimeValueAverage(segment_5); getCustomerDetail(segment_5); // getCustomerTransaction(segment_5); }); } //function getTotalCustomer function getTotalCustomer(startDate = '',endDate = '') { var iboxTotalCustomer = $('#post-report').find('#ibox-total-customer'); iboxTotalCustomer.find('#total-customer').html('-'); //ajax Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/get-total-customer'), data:{ 'dateStart':startDate, 'dateEnd':endDate, }, type: 'POST' }).success(function(response){ if(response.success) { iboxTotalCustomer.find('#total-customer').html(response.data.total); } },'json'); }); } //function getTransactionAverage function getTransactionAverage(startDate = '', endDate = '') { var iboxTransactionAverage = $('#post-report').find('#ibox-transaction-average'); iboxTransactionAverage.find('#transaction-average').html('-'); //ajax Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/get-transaction-average'), data:{ 'dateStart':startDate, 'dateEnd':endDate, }, type: 'POST' }).success(function(response){ if(response.success) { iboxTransactionAverage.find('#transaction-average').html(response.data.all+'x'); } },'json'); }); } //function getRevenueAverage function getRevenueAverage(startDate = '', endDate = '') { var iboxRevenueAverage = $('#post-report').find('#ibox-revenue-average'); iboxRevenueAverage.find('#revenue-average').html('-'); //ajax Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/get-revenue-average'), data:{ 'dateStart':startDate, 'dateEnd':endDate, }, type: 'POST' }).success(function(response){ if(response.success) { var total = response.data.revenue.total.amount; var symbol = response.data.revenue.total.currency.symbol; iboxRevenueAverage.find('#revenue-average').html(formatIdr(total.toString(),symbol)); } },'json'); }); } /* Fungsi formatIdr */ function formatIdr(angka, prefix){ var number_string = angka.replace(/[^,\d]/g, ''), split = number_string.split(','), sisa = split[0].length % 3, rupiah = split[0].substr(0, sisa), ribuan = split[0].substr(sisa).match(/\d{3}/gi); // tambahkan titik jika yang di input sudah menjadi angka ribuan if(ribuan){ separator = sisa ? '.' : ''; rupiah += separator + ribuan.join('.'); } rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah; return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : ''); } function lifeTimeValue(idCustomer) { var iboxLtv = $('.winget-customer').find('#ibox-ltv'); iboxLtv.find('#ltv').html('-'); Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/life-time-value'), data:{ 'idCustomer':idCustomer }, type: 'POST' }).success(function(response){ if(response.success) { var total = response.data.lifetime_amount.total.amount; var symbol = response.data.lifetime_amount.total.currency.symbol; iboxLtv.find('#ltv').html(formatIdr(total.toString(),symbol)); } },'json'); }); } function getTotalTransaction(idCustomer) { var iboxTrx = $('.winget-customer').find('#ibox-trx'); iboxTrx.find('#trx').html('-'); Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/get-transaction-average'), data:{ 'idCustomer':idCustomer }, type: 'POST' }).success(function(response){ if(response.success) { iboxTrx.find('#trx').html(response.data.all+'x'); } },'json'); }); } function getTotalTransactionItems(idCustomer) { var iboxTrx = $('.winget-customer').find('#ibox-trx-item'); iboxTrx.find('#trx-item').html('-'); Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/total-transaction-items'), data:{ 'idCustomer':idCustomer }, type: 'POST' }).success(function(response){ if(response.success) { iboxTrx.find('#trx-item').html(response.data.total+' pcs'); } },'json'); }); } function getLifeTimeValueAverage(idCustomer) { var iboxRevAvg = $('.winget-customer').find('#ibox-rev-avg'); iboxRevAvg.find('#rev-avg').html('-'); Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/life-time-value-average'), data:{ 'idCustomer':idCustomer }, type: 'POST' }).success(function(response){ if(response.success) { var total = response.data.lifetime_amount.total.amount; var symbol = response.data.lifetime_amount.total.currency.symbol; iboxRevAvg.find('#rev-avg').html(formatIdr(total.toString(),symbol)); } },'json'); }); } function getCustomerDetail(idCustomer) { var contentCustomerDetail = $('.customer-detail').find('.content-customer-detail'); var nameCustomer = contentCustomerDetail.find('.name-customer'); var joinCustomer = contentCustomerDetail.find('.customer-join'); var contentContactCustomer = contentCustomerDetail.find('.content-contact-customer'); var emailCustomer = contentContactCustomer.find('#email-customer'); var genderCustomer = contentContactCustomer.find('#gender-customer'); var phoneCustomer = contentContactCustomer.find('#phone-customer'); var addressCustomer = contentContactCustomer.find('#address-customer'); Pace.track(function () { $.ajax({ url : $.URL.Base('business/'+ $.URI.segment(2) +'/ajax/get-customers'), data:{ 'idCustomer':idCustomer }, type: 'POST' }).success(function(response){ if(response.success) { // console.log(response.data); //customer name nameCustomer.find('h3').html(response.data.nameFirst+' '+response.data.nameLast); //customer join joinCustomer.find('span').html(moment(response.data.recordCreateTimestamp).format('DD MMMM, YYYY')); //email customer emailCustomer.find('p').html(response.data.email); //gender customer genderCustomer.find('p').html((response.data.gender == 'MALE') ? 'Pria':'Wanita'); //phone customer phoneCustomer.find('p').html(response.data.phoneCellPrimary); //address customer var address = response.data.address + '