jQuery(document).ready(function(){ var lastsel; //used for Double Click Row Selection. var numColWidth = 100; var currencies = {}; var currenciesList = []; $.ajax({ url: '/currencies/jsonlist', async: false, dataType: 'json', success: function(data) { currencies = data; } }); // console.log(currencies); $.each(currencies, function(key, obj) { currenciesList[key] = obj.name; }); jQuery("#grid").jqGrid({ url:'/jobs/build_jobs_json/', datatype: "json", mtype: 'GET', colNames:[ //'id', 'Status', 'Sale Cat.','Shipment Cat.','Job Number','CMC POs', 'Customer','Description','Customer O/N','Order Received','Supplier Ref', 'Order Placed Principle','date_scheduled_ex_works','date_order_sent_to_customer','Freight Paid By', 'company_gross_sales_aud','net_sales_aud','gross_profit_aud','ato_exchange_rate', 'gst','Sale Currency','gst_amount','gross_commisions','invoiced_amount_inc_gst','net_export_sales_aud', 'gross_profit_exports_aud','gp_percent','gross_australian_sales_foreign_currency','net_australian_sales_foreign_currency', 'gross_profit_value_australian_sales_foreign_currency','gross_export_sales_foreign_currency','net_export_sales_foreign_currency', 'gross_profit_value_after_discount_exports_foreign_currency','gross_commissions','net_commissions' ], jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id" }, colModel:[ { name:'job_status', index:'job_status', width:130, editable:true, edittype:"select", editoptions:{ value: "ORDER RECEIVED FROM CUSTOMER:ORDER RECEIVED FROM CUSTOMER; ORDER PLACED ON PRINCIPLE - WAITING ON DELIVERY:ORDER PLACED ON PRINCIPLE - WAITING ON DELIVERY;"+ "GOODS SHIPPED TO CUSTOMER - CMC WAITING ON PAYMENT:GOODS SHIPPED TO CUSTOMER - CMC WAITING ON PAYMENT; WAITING ON PAYMENT AND ANOTHER DELIVERY:WAITING ON PAYMENT AND ANOTHER DELIVERY;"+ "GOODS DELIVERED TO CUSTOMER & PAID IN FULL:GOODS DELIVERED TO CUSTOMER & PAID IN FULL; PAID IN FULL WAITING ON DELIVERY:PAID IN FULL WAITING ON DELIVERY; JOB CANCELLED:JOB CANCELLED;"+ "JOB ON HOLD:JOB ON HOLD; CUSTOMER TO PAY 100% WITH ORDER:CUSTOMER TO PAY 100% WITH ORDER" } }, { name:'sale_category', index:'sale_category', width:130, editable:true, edittype:"select", editoptions:{ value:"INDENT:INDENT;STOCK:STOCK;COMMISSION:COMMISSION;SERVICE:SERVICE" } }, { name:'shipment_category', index:'shipment_category', width:130, editable:true, edittype:"select", editoptions:{ value:"AUSTRALIA:AUSTRALIA;EXPORT:EXPORT;DIRECT-INTL:DIRECT-INTL;DIRECT-AUST:DIRECT-AUST;NO-SHIP:NO-SHIP" } }, { name:'title', index:'title', width:100, editable:false }, { name:'purchase_orders', index:'purchase_orders', width:100, editable:false }, { name:'customer', index:'customer', width:400, editable:false, sortable: false }, { name:'comments', index:'comments', width:200, editable:true, edittype:"textarea", }, { name:'customer_order_number', index:'customer_order_number', width:100, editable:true }, { name:'date_order_received', index:'date_order_received', width:100, editable:true, sorttype:"date" }, { name:'supplier_reference', index:'supplier_reference', width:100, editable:true }, { name:'date_order_placed_on_principle', index:'date_order_placed_on_principle', width:150, editable:true, sorttype:"date" }, { name:'date_scheduled_ex_works', index:'date_scheduled_ex_works', width:130, editable:true, sorttype:"date" }, { name:'date_order_sent_to_customer', index:'date_order_sent_to_customer', width:200, editable:true, sorttype:"date" }, { name:'domestic_freight_paid_by', index:'domestic_freight_paid_by', width:100, editable:true, edittype:"select", editoptions:{ value:"Customer:Customer;CMC:CMC" } }, { name:'company_gross_sales_aud', index:'company_gross_sales_aud', width:numColWidth, editable:true, formatter: 'currency' }, { name:'net_sales_aud', index:'net_sales_aud', width:numColWidth, editable:true, formatter: 'currency' }, { name:'gross_profit_aud', index:'gross_profit_aud', width:numColWidth, editable:true, formatter: 'currency' }, { name:'ato_exchange_rate', index:'ato_exchange_rate', width:numColWidth, editable:true }, { name:'gst', width:numColWidth, editable:true, edittype:"select", formatter: "select", editoptions: { value: "1:YES;0:NO" } }, { name:'currency_id', index:'currency_id', width:180, editable:true, edittype:"select", formatter: "select", editoptions: { value: currenciesList } }, { name:'gst_amount', index:'gst_amount', width:numColWidth, editable:true }, { name:'gross_commisions', index:'gross_commisions', width:numColWidth, editable:true }, { name:'invoiced_amount_inc_gst', index:'invoiced_amount_inc_gst', width:numColWidth, editable:true }, { name:'net_export_sales_aud', index:'net_export_sales_aud', width:numColWidth, editable:true }, { name:'gross_profit_exports_aud', index:'gross_profit_exports_aud', width:numColWidth, editable:true }, { name:'gp_percent', index:'gp_percent', width:numColWidth, editable:true }, { name:'gross_australian_sales_foreign_currency', index:'gross_australian_sales_foreign_currency', width:numColWidth, editable:true }, { name:'net_australian_sales_foreign_currency', index:'net_australian_sales_foreign_currency', width:numColWidth, editable:true }, { name:'gross_profit_value_australian_sales_foreign_currency', index:'gross_profit_value_australian_sales_foreign_currency', width:numColWidth, editable:true }, { name:'gross_export_sales_foreign_currency', index:'gross_export_sales_foreign_currency', editable:true }, { name:'net_export_sales_foreign_currency', index:'net_export_sales_foreign_currency', width:numColWidth, editable:true }, { name:'gross_profit_value_after_discount_exports_foreign_currency', index:'gross_profit_value_after_discount_exports_foreign_currency', width:numColWidth, editable:true }, { name:'gross_commissions', index:'gross_commissions', width:numColWidth, editable:true }, { name:'net_commissions', index:'net_commissions', width:numColWidth, editable:true }, ], // viewrecords: true, gridview: true, rowNum: 500, height: '700px', caption:"Jobs", editurl:"/jobs/ajax_edit", onSelectRow: function(rowid){ if(typeof(lastsel) != undefined) { if(rowid && rowid!==lastsel){ $(this).jqGrid('saveRow',lastsel, false, false,false); $(this).jqGrid('editRow', rowid, true, pickdates); } } lastsel = rowid; }, gridComplete: function() { setJobStatus(); } }); $("#editButton").click(function(){ var gr = jQuery("#grid").jqGrid('getGridParam','selrow'); if(gr != null) { jQuery("#grid").jqGrid('editRow', gr, true, pickdates); } }); function setJobStatus() { var jobStatusList = $("#grid").jqGrid('getCol', 'job_status', true); $.each(jobStatusList, function() { if(this.value) { //The Job Status has been set. addJobStatus(this.id, this.value); console.log(this.id +":"+ this.value); } }); return true; } function addJobStatus(id, status) { var color; //American spelling for Var Names. switch(status) { case "ORDER RECEIVED FROM CUSTOMER": color = "white"; break; case "ORDER PLACED ON PRINCIPLE - WAITING ON DELIVERY": color = "white"; break; case "GOODS SHIPPED TO CUSTOMER - CMC WAITING ON PAYMENT": color = "yellow"; break; case "WAITING ON PAYMENT AND ANOTHER DELIVERY": color = "yellow"; break; case "GOODS DELIVERED TO CUSTOMER & PAID IN FULL": color = "light-blue"; break; case "PAID IN FULL WAITING ON DELIVERY": color = "magenta"; break; case "JOB CANCELLED": color = "red"; break; case "JOB ON HOLD": color = "red"; break; case "CUSTOMER TO PAY 100% WITH ORDER": color = "brown"; break; default: color = "white"; break; } $("#"+id).removeClass('ui-widget-content').addClass(color); console.log(id+":"+color); } function pickdates(id){ jQuery("#"+id+"_date_order_received","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_order_placed_on_principle","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_scheduled_ex_works","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_order_sent_to_customer","#grid").datepicker({ dateFormat:"yy-mm-dd" }); } });