function enable_all_customers(){$("li.customer").each(function(t){$(this).removeClass("marked"),$(this).show()})}function filter_customers(t){setTimeout(function(){$("li.customer").each(function(e){var i=new RegExp(t,"i"),a=$(this).children("span.name").text();if(i.test(a)){$(this).show();var s=a.toLowerCase()==t.toLowerCase(),n=1==$("li.customer:visible").length;console.log(s,n),s?$(this).addClass("marked"):$(this).removeClass("marked")}else $(this).hide(),$(this).removeClass("marked")})},50)}function enable_all_products(){$("li.product").each(function(t){$(this).removeClass("marked"),$(this).show()})}function reset_qtys(){$(".qty").each(function(t){$(this).html("0")}),$("input[name$=amount]").each(function(t){$(this).val("0")})}function update_total(){var t=0;$("li.product").each(function(){var e=Number($(this).find("[name$=amount]").val()),i=".sale_price_int";"Ekstern"===$("#id_customer_typeahead").val()&&(i=".sale_price_ext");var a=Number($(this).find(i).text());t+=e*a}),0===t&&(t=""),$("span.total_text").html(t)}$(document).ready(function(){var t=$("a[data-dismiss=alert]");t.click(function(){$(this).parent().parent().parent().slideUp()}),setTimeout(function(){t.parent().parent().parent().slideUp()},5e3),$("h2").tooltip({placement:"right"}),$("img.customer").tooltip(),$("a.product").tooltip(),$(".love").tooltip(),$("#id_customer_typeahead").keyup(function(t){filter_customers(t.target.value)}),$("li.customer").click(function(){enable_all_customers(),$(this).addClass("marked");var t=$(this).children("span.name").text();$("#id_customer_typeahead").val(t);var e=$(this).children("span.id").text();$("#id_customer option, #id_user option").removeAttr("selected"),""===e?$("#id_customer option:first-child, #id_user option:first-child").attr("selected","selected"):$("#id_customer option[value="+e+"], #id_user option[value="+e+"]").attr("selected","selected"),update_total(this)}),Highcharts.setOptions({credits:{enabled:!1}}),$("#register li.product").click(function(){$(this).addClass("marked");var t=$(this).children("input[name$=amount]"),e=$(this).children(".qty"),i=Number(t.val())+1;t.val(i),e.html(i),update_total(this)}),$("#register button[type=reset]").click(function(){$("#id_customer option").removeAttr("selected"),$("#id_customer_typeahead").val(""),$("span.total_text").html(""),enable_all_customers(),enable_all_products(),reset_qtys()}),$(".toggle-infrequent-users").on("click",function(t){t.preventDefault(),$("li.customer.infrequent").toggleClass("hidden"),$(".users-description .infrequent-users").toggleClass("hidden"),"Vis alle"===$(this).text()?$(this).text("Skjul gamliser"):$(this).text("Vis alle")});var e=$(".inventory-report-form #id_start_time");e.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){i.datepicker("setStartDate",t.date)});var i=$(".inventory-report-form #id_end_time");i.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){e.datepicker("setEndDate",t.date)})}); $(document).ready(function(){var t=$("#user-profile");if(t.length){var e="/stats/products/by_user/",r=$("#user-profile").attr("data-user-id");$.getJSON(e+r,function(t){t.hasOwnProperty("error")||$(".profile-stats-orderline").highcharts({title:{text:!1},xAxis:{type:"datetime"},yAxis:{title:{text:"Kjøp"}},plotOptions:{series:{marker:{radius:3}}},series:t})})}}); function productFormatter(){return""+this.point.name+": "+Highcharts.numberFormat(this.percentage,1)+" %"}function parse_products_realtime_data(t,r){for(var e in t.products){null===r.get(e)&&r.addSeries({data:[],id:e,name:e});var o=r.get(e);_.each(t.products[e],function(t){null===r.get(t[0])&&o.addPoint({id:t[0],x:t[0],y:t[1]})})}}function get_products_realtime_data(){$.ajax({url:products_realtime_url,dataType:"json",success:function(t){parse_products_realtime_data(t,products_realtime_chart),setTimeout(function(){get_products_realtime_data()},15e3)},cache:!1})}function renderProductCharts(t){for(var r in t){var e="product_chart"+t[r].id,o=t[r].counts;o=_.map(o,function(t){return[t.full_name,t.amount_total]}),new Highcharts.Chart({chart:{renderTo:e,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:t[r].name},tooltip:{formatter:productFormatter},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return""+this.point.name+": "+this.y}}}},series:[{type:"pie",name:"Orders",data:o}]})}}function renderOrdersChart(t){var r="order_chart";new Highcharts.Chart({chart:{renderTo:r,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:"Fordeling av ordre på person"},tooltip:{formatter:function(){return""+this.point.name+": "+Highcharts.numberFormat(this.percentage,1)+" %"}},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return""+this.point.name+": "+this.y}}}},series:[{type:"pie",name:"Orders",data:t}]})}function renderOrdersHourlyChart(t){var r="order_hourly_chart";new Highcharts.Chart({chart:{renderTo:r,type:"column"},title:{text:"Ordre - time for time"},tooltip:{formatter:function(){return this.y+" stk"}},yAxis:{title:{text:"Ordre"}},xAxis:{title:{text:"Tid (h)"},labels:{formatter:function(){return this.value+":00"}}},plotOptions:{column:{minPointLength:3},series:{groupPadding:0,pointPadding:.05}},series:[{name:"Ordre",data:t.hourly}]})}var products=null,products_realtime_chart=null,products_url="/api/products/",products_stat_url="/api/products/group_by_user",order_url="/stats/orders/",order_hourly_url="/stats/orders/hourly",products_realtime_url="/stats/orders/products_realtime";$(document).ready(function(){$("#stats").length>0&&($.getJSON(products_stat_url,function(t){products=t,renderProductCharts(t)}),$.getJSON(order_url,renderOrdersChart),$.getJSON(order_hourly_url,renderOrdersHourlyChart),products_realtime_chart=new Highcharts.Chart({chart:{renderTo:"products_realtime_chart"},title:{text:"Produkter solgt over tid"},xAxis:{type:"datetime"},yAxis:{title:{text:"Antall solgt"}},plotOptions:{series:{marker:{radius:3}}},series:{}}),get_products_realtime_data())});