Files
2015-09-30 21:00:10 +02:00

1 line
5.7 KiB
JavaScript

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 r=new RegExp(t,"i"),i=$(this).children("span.name").text();if(r.test(i)){$(this).show();var a=i.toLowerCase()==t.toLowerCase(),o=1==$("li.customer:visible").length;console.log(a,o),a?$(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()),r=".sale_price_int";"Ekstern"===$("#id_customer_typeahead").val()&&(r=".sale_price_ext");var i=Number($(this).find(r).text());t+=e*i}),0===t&&(t=""),$("span.total_text").html(t)}$(document).ready(function(){function t(t){var e=n;for(var r in t.products)if(null===e.get(r)){e.addSeries({data:[],id:r,name:r});var i=e.get(r);_.each(t.products[r],function(t){i.addPoint({id:t[0],x:t[0],y:t[1]})})}else{var i=e.get(r);_.each(t.products[r],function(t){null===e.get(t[0])&&i.addPoint({id:t[0],x:t[0],y:t[1]})})}}function e(){$.ajax({url:s,dataType:"json",success:function(r){t(r),setTimeout(function(){e()},15e3)},cache:!1})}if($("a[data-dismiss=alert]").click(function(){$(this).parent().parent().parent().slideUp()}),setTimeout(function(){$("a[data-dismiss=alert]").parent().parent().parent().slideUp()},5e3),$("h2").tooltip({placement:"right"}),$("img.customer").tooltip(),$("a.product").tooltip(),$("#footer .credits .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"),r=Number(t.val())+1;t.val(r),e.html(r),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")}),$("#stats").length>0){var r=[],i="/stats/products/",a="/stats/orders/",o="/stats/orders/hourly",s="/stats/orders/products_realtime";$.getJSON(a,function(t){var e="order_chart",i={chart:{renderTo:e,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:"Fordeling av ordre på person"},tooltip:{formatter:function(){return"<b>"+this.point.name+"</b>: "+Highcharts.numberFormat(this.percentage,1)+" %"}},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return"<b>"+this.point.name+"</b>: "+this.y}}}},series:[{type:"pie",name:"Orders",data:t}]};r.push(new Highcharts.Chart(i))}),$.getJSON(i,function(t){var e=t.response.products;for(var i in e){var a="product_chart"+e[i].product.id,o=e[i].counts,s={chart:{renderTo:a,plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:e[i].product.name},tooltip:{formatter:function(){return"<b>"+this.point.name+"</b>: "+Highcharts.numberFormat(this.percentage,1)+" %"}},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,color:"#000000",connectorColor:"#000000",formatter:function(){return"<b>"+this.point.name+"</b>: "+this.y}}}},series:[{type:"pie",name:"Orders",data:o}]};r.push(new Highcharts.Chart(s))}}),$.getJSON(o,function(t){var e="order_hourly_chart",i={chart:{renderTo:e,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}]};r.push(new Highcharts.Chart(i))});var n=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:{}});r.push(n),e()}var l=$(".inventory-report-form #id_start_time");l.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){c.datepicker("setStartDate",t.date)});var c=$(".inventory-report-form #id_end_time");if(c.datepicker({language:"nb",format:"yyyy-mm-dd",todayHighlight:!0,weekStart:1,endDate:new Date}).on("changeDate",function(t){l.datepicker("setEndDate",t.date)}),$("#user-profile").length){var d="/stats/products/by_user/",u=$("#user-profile").attr("data-user-id");$.getJSON(d+u,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})})}});