2011-03-28 18:47:50 -07:00
jQuery ( document ) . ready ( function ( ) {
var lastsel ; //used for Double Click Row Selection.
2011-03-29 16:16:42 -07:00
var numColWidth = 100 ;
2011-03-30 16:12:16 -07:00
var currencies = { } ;
var currenciesList = [ ] ;
$ . ajax ( {
url : '/currencies/jsonlist' ,
async : false ,
dataType : 'json' ,
success : function ( data ) {
currencies = data ;
}
} ) ;
2011-03-30 22:15:52 -07:00
// console.log(currencies);
2011-03-30 16:12:16 -07:00
$ . each ( currencies , function ( key , obj ) {
currenciesList [ key ] = obj . name ;
} ) ;
2011-03-28 18:47:50 -07:00
jQuery ( "#grid" ) . jqGrid ( {
url : '/jobs/build_jobs_json/' ,
datatype : "json" ,
mtype : 'GET' ,
colNames : [
//'id',
2011-03-30 22:54:07 -07:00
'Status' , 'Sale Cat.' , 'Shipment Cat.' , 'Job Number' , 'CMC POs' , 'Customer' , 'Description' , 'Customer O/N' , 'Order Received' , 'Supplier Ref' ,
2011-03-30 16:12:16 -07:00
'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' ,
2011-03-28 18:47:50 -07:00
'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 : [
2011-03-30 22:15:52 -07:00
{
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"
}
} ,
2011-03-30 16:12:16 -07:00
{
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"
}
} ,
2011-03-28 18:47:50 -07:00
{
name : 'title' ,
index : 'title' ,
width : 100 ,
editable : false
} ,
2011-03-30 22:54:07 -07:00
{
name : 'purchase_orders' ,
index : 'purchase_orders' ,
width : 100 ,
editable : false
} ,
2011-03-28 18:47:50 -07:00
{
name : 'customer' ,
index : 'customer' ,
width : 400 ,
2011-03-28 21:19:59 -07:00
editable : false ,
sortable : false
2011-03-28 18:47:50 -07:00
} ,
{
2011-03-30 16:12:16 -07:00
name : 'comments' ,
index : 'comments' ,
width : 200 ,
editable : true ,
edittype : "textarea" ,
2011-03-28 18:47:50 -07:00
} ,
{
2011-03-30 16:12:16 -07:00
name : 'customer_order_number' ,
index : 'customer_order_number' ,
2011-03-28 18:47:50 -07:00
width : 100 ,
editable : true
} ,
{
name : 'date_order_received' ,
index : 'date_order_received' ,
2011-03-29 16:16:42 -07:00
width : 100 ,
2011-03-28 18:47:50 -07:00
editable : true ,
sorttype : "date"
} ,
2011-03-30 16:12:16 -07:00
{
name : 'supplier_reference' ,
index : 'supplier_reference' ,
width : 100 ,
editable : true
} ,
2011-03-28 18:47:50 -07:00
{
name : 'date_order_placed_on_principle' ,
index : 'date_order_placed_on_principle' ,
2011-03-29 16:16:42 -07:00
width : 150 ,
2011-03-28 18:47:50 -07:00
editable : true ,
sorttype : "date"
} ,
{
name : 'date_scheduled_ex_works' ,
index : 'date_scheduled_ex_works' ,
2011-03-29 16:16:42 -07:00
width : 130 ,
2011-03-28 18:47:50 -07:00
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' ,
2011-03-29 16:16:42 -07:00
width : 100 ,
2011-03-28 18:47:50 -07:00
editable : true ,
edittype : "select" ,
editoptions : {
value : "Customer:Customer;CMC:CMC"
}
} ,
{
name : 'company_gross_sales_aud' ,
index : 'company_gross_sales_aud' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-30 16:12:16 -07:00
editable : true ,
formatter : 'currency'
2011-03-28 18:47:50 -07:00
} ,
{
name : 'net_sales_aud' ,
index : 'net_sales_aud' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-30 16:12:16 -07:00
editable : true ,
formatter : 'currency'
2011-03-28 18:47:50 -07:00
} ,
{
name : 'gross_profit_aud' ,
index : 'gross_profit_aud' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-30 16:12:16 -07:00
editable : true ,
formatter : 'currency'
2011-03-28 18:47:50 -07:00
} ,
{
name : 'ato_exchange_rate' ,
index : 'ato_exchange_rate' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gst' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-30 16:12:16 -07:00
editable : true ,
edittype : "select" ,
formatter : "select" ,
editoptions : {
value : "1:YES;0:NO"
}
2011-03-28 18:47:50 -07:00
} ,
{
name : 'currency_id' ,
index : 'currency_id' ,
2011-03-30 16:12:16 -07:00
width : 180 ,
editable : true ,
edittype : "select" ,
formatter : "select" ,
editoptions : {
value : currenciesList
}
2011-03-28 18:47:50 -07:00
} ,
{
name : 'gst_amount' ,
index : 'gst_amount' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_commisions' ,
index : 'gross_commisions' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'invoiced_amount_inc_gst' ,
index : 'invoiced_amount_inc_gst' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'net_export_sales_aud' ,
index : 'net_export_sales_aud' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_profit_exports_aud' ,
index : 'gross_profit_exports_aud' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gp_percent' ,
index : 'gp_percent' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_australian_sales_foreign_currency' ,
index : 'gross_australian_sales_foreign_currency' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'net_australian_sales_foreign_currency' ,
index : 'net_australian_sales_foreign_currency' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_profit_value_australian_sales_foreign_currency' ,
index : 'gross_profit_value_australian_sales_foreign_currency' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_export_sales_foreign_currency' ,
index : 'gross_export_sales_foreign_currency' ,
2011-03-29 16:16:42 -07:00
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'net_export_sales_foreign_currency' ,
index : 'net_export_sales_foreign_currency' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_profit_value_after_discount_exports_foreign_currency' ,
index : 'gross_profit_value_after_discount_exports_foreign_currency' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'gross_commissions' ,
index : 'gross_commissions' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
{
name : 'net_commissions' ,
index : 'net_commissions' ,
2011-03-29 16:16:42 -07:00
width : numColWidth ,
2011-03-28 18:47:50 -07:00
editable : true
} ,
] ,
// viewrecords: true,
2011-03-30 22:15:52 -07:00
gridview : true ,
2011-03-28 21:19:59 -07:00
rowNum : 500 ,
2011-03-29 16:16:42 -07:00
height : '700px' ,
2011-03-28 18:47:50 -07:00
caption : "Jobs" ,
editurl : "/jobs/ajax_edit" ,
onSelectRow : function ( rowid ) {
if ( typeof ( lastsel ) != undefined ) {
if ( rowid && rowid !== lastsel ) {
2011-03-30 22:34:29 -07:00
$ ( this ) . jqGrid ( 'saveRow' , lastsel , false , false , false ) ;
2011-03-28 18:47:50 -07:00
$ ( this ) . jqGrid ( 'editRow' , rowid , true , pickdates ) ;
}
}
lastsel = rowid ;
2011-03-30 22:15:52 -07:00
} ,
gridComplete : function ( ) {
setJobStatus ( ) ;
2011-03-28 18:47:50 -07:00
}
} ) ;
$ ( "#editButton" ) . click ( function ( ) {
var gr = jQuery ( "#grid" ) . jqGrid ( 'getGridParam' , 'selrow' ) ;
if ( gr != null ) {
jQuery ( "#grid" ) . jqGrid ( 'editRow' , gr , true , pickdates ) ;
}
} ) ;
2011-03-30 22:15:52 -07:00
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 ;
}
2011-03-28 18:47:50 -07:00
2011-03-30 22:15:52 -07:00
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 ) ;
2011-03-28 18:47:50 -07:00
2011-03-30 22:15:52 -07:00
}
2011-03-28 18:47:50 -07:00
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"
} ) ;
}
} ) ;