DataObjects/Person.php
[Pman.Xtuple] / Pman.Dialog.XtupleSalesOrder.bjs
1 {
2     "name" : "Pman.Dialog.XtupleSalesOrder",
3     "parent" : "",
4     "title" : "",
5     "path" : "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Dialog.XtupleSalesOrder.bjs",
6     "permname" : "",
7     "modOrder" : "001",
8     "items" : [
9         {
10             "listeners" : {
11                 "|show" : "function () {\n       this.layout.getRegion('center').showPanel(0);\n}"
12             },
13             "modal" : true,
14             "collapsible" : false,
15             "title" : "Edit / Create Sales Order",
16             "xtype" : "LayoutDialog",
17             "width" : 1050,
18             "$ xns" : "Roo",
19             "closable" : true,
20             "resizable" : true,
21             "height" : 620,
22             "items" : [
23                 {
24                     "alwaysShowTabs" : true,
25                     "xtype" : "LayoutRegion",
26                     "$ xns" : "Roo",
27                     "tabPosition" : "top",
28                     "* prop" : "center",
29                     "items" : [
30                         {
31                             "xtype" : "Toolbar",
32                             "$ xns" : "Roo",
33                             "* prop" : "toolbar",
34                             "items" : [
35                                 {
36                                     "xtype" : "Fill",
37                                     "$ xns" : "Roo.Toolbar"
38                                 },
39                                 {
40                                     "listeners" : {
41                                         "click" : "function ()\n{\n    var id = 1* _this.form.findField('cohead_id').getValue();\n    if (!id) {\n        Roo.MessageBox.alert(\"Error\", \"Save Sales order first\");\n        return;\n    \n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/cohead',\n            method : 'GET',\n            params : {\n                cohead_id :  id,\n                _excel : 1\n            },\n            success : function() {\n\n            }\n        })\n            \n            \n   \n}"
42                                     },
43                                     "text" : "Download Excel",
44                                     "xtype" : "Button",
45                                     "cls" : "x-btn-text-icon",
46                                     "$ icon" : "rootURL + '/Pman/templates/images/spreadsheet.gif'",
47                                     "$ xns" : "Roo.Toolbar"
48                                 },
49                                 {
50                                     "listeners" : {
51                                         "click" : "function ()\n{\n    var id = 1* _this.form.findField('cohead_id').getValue();\n    if (!id) {\n        Roo.MessageBox.alert(\"Error\", \"Save Sales order first\");\n        return;\n    \n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/cohead',\n            method : 'GET',\n            params : {\n                cohead_id :  id,\n                _print : 1\n            },\n            success : function() {\n\n            }\n        })\n            \n            \n   \n}"
52                                     },
53                                     "text" : "Print",
54                                     "xtype" : "Button",
55                                     "cls" : "x-btn-text-icon",
56                                     "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
57                                     "$ xns" : "Roo.Toolbar"
58                                 },
59                                 {
60                                     "listeners" : {
61                                         "click" : "function (_self, e)\n{\n\n    _this.addShipmentBtn.fireEvent('click');\n   \n}"
62                                     },
63                                     "text" : "Add Shipment",
64                                     "hidden" : true,
65                                     "xtype" : "Button",
66                                     "cls" : "x-btn-text-icon",
67                                     "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
68                                     "$ xns" : "Roo.Toolbar"
69                                 },
70                                 {
71                                     "listeners" : {
72                                         "click" : "function (_self, e)\n{\n\n   Pman.Dialog.XtupleCustomer.show({\n         cust_id : _this.form.findField('cohead_cust_id').getValue()\n  }); \n}"
73                                     },
74                                     "text" : "Edit Customer",
75                                     "xtype" : "Button",
76                                     "cls" : "x-btn-text-icon",
77                                     "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
78                                     "$ xns" : "Roo.Toolbar"
79                                 },
80                                 {
81                                     "listeners" : {
82                                         "click" : "function (_self, e)\n{\n\n        _this.addInvoiceBtn.fireEvent('click');\n   \n}"
83                                     },
84                                     "text" : "Add Invoice",
85                                     "hidden" : true,
86                                     "xtype" : "Button",
87                                     "cls" : "x-btn-text-icon",
88                                     "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
89                                     "$ xns" : "Roo.Toolbar"
90                                 },
91                                 {
92                                     "listeners" : {
93                                         "render" : "function (_self, e)\n{\n    _this.voidBtn = _self;\n}",
94                                         "click" : "function (_self, e)\n{\n     var p = {         \n         cohead_id : _this.form.findField('cohead_id').getValue() \n     };\n    function call() {\n\n            \n       new Pman.Request({\n            mask : 'Sending',\n            url: baseURL + '/Roo/cohead',\n            method : 'POST',\n            params :  p,\n            success : function()\n            {\n                _this.callback();\n                 if ( _this.data.cohead_status == 'X') {\n                  _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});\n          \n                    return;\n                 }\n\n \n                _this.dialog.hide();\n            }\n       });\n   }\n\n  \n   if (_this.data.cohead_status == 'X') {\n        p._unvoid = 1;\n        call();\n        return;\n    }\n    \n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want to void this?\", function(r) {\n    \n        if (r !='yes') {\n            return;\n        }\n        p._void = 1;\n        call();       \n\n      \n    });\n\n}"
95                                     },
96                                     "text" : "Void",
97                                     "xtype" : "Button",
98                                     "$ xns" : "Roo.Toolbar"
99                                 },
100                                 {
101                                     "listeners" : {
102                                         "render" : "function (_self)\n{\n   _this.closeBtn = _self;\n}",
103                                         "click" : "function (_self, e)\n{\n    var p = {          cohead_id : _this.form.findField('cohead_id').getValue() };\n    \n    var close = 1;\n    if (_this.data.cohead_status == 'C') {\n        p._reopen = 1;\n        close = 0;\n        } else {\n                p._close = 1;\n        }\n        \n   new Pman.Request({\n    url: baseURL + '/Roo/cohead',\n    method : 'POST',\n    params :  p,\n    mask : 'Sending',\n    success : function()\n    {\n           _this.callback();\n          if (!close) {\n            _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});\n          \n            return;\n          }\n       \n        _this.dialog.hide();\n    }\n   });\n    \n}"
104                                     },
105                                     "text" : "Completed",
106                                     "xtype" : "Button",
107                                     "$ xns" : "Roo.Toolbar"
108                                 }
109                             ]
110                         }
111                     ]
112                 },
113                 {
114                     "listeners" : {
115                         "activate" : "function (_self)\n{\n    // we need to reload to find out the subtotal.\n    if (!_this.data || !_this.data.cohead_id) {\n        return;\n    }\n    new Pman.Request({\n        method : 'GET',\n        url : baseURL + '/Roo/cohead',\n        params : { \n            _id : _this.data.cohead_id\n        },\n        success : function(res) {\n            _this.form.findField('cohead_subtotal').setValue(res.data.cohead_subtotal);\n            _this.form.findField('cohead_tax').setValue(res.data.cohead_tax);\n            _this.form.findField('cohead_uninvoiced').setValue(res.data.cohead_uninvoiced);\n            _this.form.findField('cohead_unshipped').setValue(res.data.cohead_unshipped);\n           _this.form.findField('cohead_pretax_discount').setValue(res.data.cohead_pretax_discount); \n            _this.form.findField('cohead_total').recalc(); \n            _this.form.findField('cohead_misc').recalc(); \n        }\n    });\n}"
116                     },
117                     "region" : "center",
118                     "xtype" : "ContentPanel",
119                     "title" : "Order Details",
120                     "$ xns" : "Roo",
121                     "items" : [
122                         {
123                             "listeners" : {
124                                 "actionfailed" : "function (_self, action)\n{\n    if (action.failureType == 'client') {\n        Roo.MessageBox.alert(\"Error\", \"Fill in all the required fields\");\n    }\n    if (action.failureType == 'server') {    \n        Roo.log(action);\n        Roo.MessageBox.alert(\"Error\", action.result.errorMsg);\n    }\n    _this.dialog.layout.getRegion('center').showPanel(0);\n}",
125                                 "|actioncomplete" : "function(_self,action)\n{\n    if (action.type == 'setdata') {\n        // clear the stock level cache...\n        _this.stockcache = [];\n        \n        _this.form.findField('billto_email').setValue('');\n        \n        _this.reversalBtn.hide();\n        \n        if (_this.data.cohead_id) {\n           this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});\n           \n           return;\n        }\n        _this.dialog.setTitle(\"Edit New Sales Order\");\n       \n        _this.closeBtn.hide();\n        _this.voidBtn.hide();\n        _this.saveBtn.show();\n            \n        if(_this.data.cohead_billto_cntct_id_cntct_id){\n            _this.form.findField('billto_address').update();\n            \r\n            _this.form.setValues({\r\n                cohead_billto_cntct_id: _this.data.cohead_billto_cntct_id_cntct_id,\r\n                cohead_billto_cntct_id_cntct_name : _this.data.cohead_billto_cntct_id_cntct_name,\r\n                _shipto_same : 1,\n                _same_as_order : 1\n                \r\n            }); \r\n        }\n         \n       return;\n    }\n    if (action.type == 'load') {\n         \n        \n        _this.data = action.result.data;\n\n        if (!_this.data.cohead_shipto_id && _this.data.shipto_id*1 > 0) {\n            _this.form.findField('cohead_shipto_id').setValue(_this.data.shipto_id);\n            _this.form.findField('cohead_shipto_id_shipto_name').setValue(_this.data.cohead_shipto_cntct_id_cntct_name);\n        \n        }\n        \n        \n        _this.dataloading = true;\n        if (_this.data.cohead_shipto_cntct_id == _this.data.cohead_billto_cntct_id) {\n            this.findField('_shipto_same').setValue(1);\n              Roo.log(\"set shipto 1\");\n        } else {\n          this.findField('_shipto_same').setValue(0);\n           Roo.log(\"set shipto 0\");\n        }\n        _this.dataloading = false;          \n        \n        \n        this.findField('billto_address').update();\n        this.findField('shipto_address').update();        \n        _this.dialog.setTitle(\"Edit Sales Order - \" + this.findField('cohead_number').getValue());\n         \n        \n        if (_this.data.cohead_status == 'C') {\n            _this.closeBtn.show();\n            _this.closeBtn.setText('Re-open');\n             _this.voidBtn.hide();\n             _this.saveBtn.hide();\n             _this.reversalBtn.show();\n        }  else  if (_this.data.cohead_status == 'X') {\n            _this.closeBtn.hide(); \n             _this.voidBtn.show(); \n             _this.voidBtn.setText(\"Un-void / Re-open\"); \n             _this.saveBtn.hide();\n        } else {\n            // it's open\n             _this.closeBtn.show(); \n            _this.closeBtn.setText('Complete and Close');             \n             _this.voidBtn.setText(\"Void\");             \n             _this.voidBtn.show(); \n             _this.saveBtn.show();        \n        }\n        \n         _this.form.findField('cohead_misc_per').update();\n       \n       // finally override the value for discount...\n       if ((''+ _this.data.cohead_misc_descrip).length) {\n            _this.form.findField('cohead_misc_descrip').setValue(_this.data.cohead_misc_descrip);\n       }\n       \n       // update the stockcache...\n\n       new Pman.Request({\n            url : baseURL + '/Roo/cohead',\n            method : 'GET',\n            params : {\n                _stockLevel : _this.data.cohead_id\n            },\n            success : function(res) \n            {\n                for (var i in res.data) {\n                   \n                    if(typeof(_this.stockcache[res.data[i].item]) == 'undefined'){\n                        _this.stockcache[res.data[i].item] = res.data[i];\n                    }\n                }\n            }\n        });\n       \n        return;\n    }\n    if (action.type =='submit') {\n    \n\n        var id = _this.form.findField('cohead_id').getValue() * 1;\n        if (id < 1) {\n\n            _this.data.cohead_id = action.result.data.cohead_id;\n             this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});\n            return;\n        }\n    \n        _this.dialog.hide();\n    \n         if (_this.callback) {\n            _this.callback.call(_this, _this.form.getValues());\n         }\n         _this.form.reset();\n         return;\n    }\n}\n",
126                                 "|rendered" : "function (form)\n{\n    _this.form= form;\n}\n"
127                             },
128                             "$ url" : "baseURL + '/Roo/cohead.php'",
129                             "xtype" : "Form",
130                             "method" : "POST",
131                             "style" : "margin:10px;",
132                             "$ xns" : "Roo.form",
133                             "items" : [
134                                 {
135                                     "xtype" : "Column",
136                                     "width" : 435,
137                                     "$ xns" : "Roo.form",
138                                     "items" : [
139                                         {
140                                             "style" : "width:420px",
141                                             "legend" : "Order",
142                                             "xtype" : "FieldSet",
143                                             "labelWidth" : 120,
144                                             "$ xns" : "Roo.form",
145                                             "items" : [
146                                                 {
147                                                     "xtype" : "Column",
148                                                     "labelWidth" : 100,
149                                                     "width" : 410,
150                                                     "$ xns" : "Roo.form",
151                                                     "items" : [
152                                                         {
153                                                             "xtype" : "Row",
154                                                             "labelWidth" : 100,
155                                                             "width" : 400,
156                                                             "$ xns" : "Roo.form",
157                                                             "items" : [
158                                                                 {
159                                                                     "fieldLabel" : "Order#",
160                                                                     "emptyText" : "Automatic",
161                                                                     "xtype" : "TextField",
162                                                                     "allowBlank" : true,
163                                                                     "readOnly" : true,
164                                                                     "width" : 120,
165                                                                     "$ xns" : "Roo.form",
166                                                                     "name" : "cohead_number"
167                                                                 },
168                                                                 {
169                                                                     "style" : "float:left",
170                                                                     "xtype" : "Row",
171                                                                     "labelWidth" : 50,
172                                                                     "width" : 150,
173                                                                     "$ xns" : "Roo.form",
174                                                                     "items" : [
175                                                                         {
176                                                                             "fieldLabel" : "Cust#",
177                                                                             "xtype" : "TextField",
178                                                                             "allowBlank" : true,
179                                                                             "readOnly" : true,
180                                                                             "width" : 110,
181                                                                             "$ xns" : "Roo.form",
182                                                                             "name" : "cohead_cust_id_cust_number"
183                                                                         }
184                                                                     ]
185                                                                 }
186                                                             ]
187                                                         },
188                                                         {
189                                                             "listWidth" : 400,
190                                                             "triggerAction" : "all",
191                                                             "forceSelection" : true,
192                                                             "fieldLabel" : "Customer",
193                                                             "selectOnFocus" : true,
194                                                             "pageSize" : 20,
195                                                             "hiddenName" : "cohead_cust_id",
196                                                             "minChars" : 2,
197                                                             "valueField" : "cust_id",
198                                                             "xtype" : "TextField",
199                                                             "readOnly" : true,
200                                                             "typeAhead" : true,
201                                                             "editable" : false,
202                                                             "width" : 300,
203                                                             "$ xns" : "Roo.form",
204                                                             "name" : "cohead_cust_id_cust_name",
205                                                             "qtip" : "Select custinfo",
206                                                             "queryParam" : "query[cust_name]",
207                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>",
208                                                             "loadingText" : "Searching..."
209                                                         },
210                                                         {
211                                                             "fieldLabel" : "Customer PO#",
212                                                             "xtype" : "TextField",
213                                                             "$ xns" : "Roo.form",
214                                                             "width" : 150,
215                                                             "name" : "cohead_custponumber"
216                                                         },
217                                                         {
218                                                             "format" : "Y-m-d",
219                                                             "fieldLabel" : "Ordered",
220                                                             "xtype" : "DateField",
221                                                             "allowBlank" : false,
222                                                             "width" : 100,
223                                                             "$ xns" : "Roo.form",
224                                                             "name" : "cohead_orderdate"
225                                                         },
226                                                         {
227                                                             "xtype" : "Row",
228                                                             "labelWidth" : 100,
229                                                             "width" : 500,
230                                                             "$ xns" : "Roo.form",
231                                                             "items" : [
232                                                                 {
233                                                                     "format" : "Y-m-d",
234                                                                     "fieldLabel" : "Target Delivery",
235                                                                     "xtype" : "DateField",
236                                                                     "allowBlank" : false,
237                                                                     "width" : 100,
238                                                                     "$ xns" : "Roo.form",
239                                                                     "name" : "cohead_targetdate"
240                                                                 },
241                                                                 {
242                                                                     "hideLabels" : true,
243                                                                     "xtype" : "Row",
244                                                                     "$ xns" : "Roo.form",
245                                                                     "items" : [
246                                                                         {
247                                                                             "listeners" : {
248                                                                                 "check" : "function (_self, checked)\n{\n    if(checked){\n        _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());\n    }\n}"
249                                                                             },
250                                                                             "inputValue" : 1,
251                                                                             "xtype" : "Checkbox",
252                                                                             "boxLabel" : "same as order",
253                                                                             "$ xns" : "Roo.form",
254                                                                             "name" : "_same_as_order"
255                                                                         }
256                                                                     ]
257                                                                 }
258                                                             ]
259                                                         },
260                                                         {
261                                                             "listWidth" : 400,
262                                                             "triggerAction" : "all",
263                                                             "fieldLabel" : "Supply From",
264                                                             "forceSelection" : true,
265                                                             "selectOnFocus" : true,
266                                                             "pageSize" : 200,
267                                                             "displayField" : "location_name",
268                                                             "emptyText" : "Supply From",
269                                                             "hiddenName" : "cohead_location_src",
270                                                             "minChars" : 2,
271                                                             "valueField" : "location_id",
272                                                             "xtype" : "ComboBox",
273                                                             "allowBlank" : false,
274                                                             "typeAhead" : false,
275                                                             "editable" : true,
276                                                             "width" : 300,
277                                                             "$ xns" : "Roo.form",
278                                                             "name" : "cohead_location_src_location_name",
279                                                             "qtip" : "Select terms",
280                                                             "queryParam" : "query[location_name]",
281                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>",
282                                                             "loadingText" : "Searching...",
283                                                             "items" : [
284                                                                 {
285                                                                     "listeners" : {
286                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n     o.params.location_netable = 1;\n      o.params.location_restrict = 0;\n      o.params._notinternalcompany = 1;\n}\n"
287                                                                     },
288                                                                     "xtype" : "Store",
289                                                                     "remoteSort" : true,
290                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
291                                                                     "$ xns" : "Roo.data",
292                                                                     "* prop" : "store",
293                                                                     "items" : [
294                                                                         {
295                                                                             "$ url" : "baseURL + '/Roo/location.php'",
296                                                                             "xtype" : "HttpProxy",
297                                                                             "method" : "GET",
298                                                                             "$ xns" : "Roo.data",
299                                                                             "* prop" : "proxy"
300                                                                         },
301                                                                         {
302                                                                             "id" : "location_id",
303                                                                             "root" : "data",
304                                                                             "xtype" : "JsonReader",
305                                                                             "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
306                                                                             "$ xns" : "Roo.data",
307                                                                             "* prop" : "reader",
308                                                                             "totalProperty" : "total"
309                                                                         }
310                                                                     ]
311                                                                 }
312                                                             ]
313                                                         }
314                                                     ]
315                                                 }
316                                             ]
317                                         },
318                                         {
319                                             "style" : "width:420px",
320                                             "legend" : "Details",
321                                             "xtype" : "FieldSet",
322                                             "labelWidth" : 100,
323                                             "$ xns" : "Roo.form",
324                                             "items" : [
325                                                 {
326                                                     "xtype" : "Column",
327                                                     "labelWidth" : 100,
328                                                     "width" : 420,
329                                                     "$ xns" : "Roo.form",
330                                                     "items" : [
331                                                         {
332                                                             "listWidth" : 400,
333                                                             "triggerAction" : "all",
334                                                             "forceSelection" : true,
335                                                             "selectOnFocus" : true,
336                                                             "fieldLabel" : "Terms",
337                                                             "pageSize" : 20,
338                                                             "xtype" : "ComboBox",
339                                                             "emptyText" : "Select terms",
340                                                             "minChars" : 2,
341                                                             "valueField" : "terms_id",
342                                                             "displayField" : "terms_descrip",
343                                                             "hiddenName" : "cohead_terms_id",
344                                                             "allowBlank" : false,
345                                                             "typeAhead" : true,
346                                                             "editable" : false,
347                                                             "$ xns" : "Roo.form",
348                                                             "width" : 300,
349                                                             "qtip" : "Select terms",
350                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>",
351                                                             "queryParam" : "query[terms_descrip]",
352                                                             "name" : "cohead_terms_id_terms_descrip",
353                                                             "loadingText" : "Searching...",
354                                                             "items" : [
355                                                                 {
356                                                                     "listeners" : {
357                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
358                                                                     },
359                                                                     "xtype" : "Store",
360                                                                     "remoteSort" : true,
361                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'terms_descrip' }",
362                                                                     "$ xns" : "Roo.data",
363                                                                     "* prop" : "store",
364                                                                     "items" : [
365                                                                         {
366                                                                             "$ url" : "baseURL + '/Roo/terms.php'",
367                                                                             "method" : "GET",
368                                                                             "xtype" : "HttpProxy",
369                                                                             "$ xns" : "Roo.data",
370                                                                             "* prop" : "proxy"
371                                                                         },
372                                                                         {
373                                                                             "id" : "terms_id",
374                                                                             "root" : "data",
375                                                                             "xtype" : "JsonReader",
376                                                                             "$ xns" : "Roo.data",
377                                                                             "$ fields" : "[{\"name\":\"terms_id\",\"type\":\"int\"},\"terms_descrip\"]",
378                                                                             "* prop" : "reader",
379                                                                             "totalProperty" : "total"
380                                                                         }
381                                                                     ]
382                                                                 }
383                                                             ]
384                                                         },
385                                                         {
386                                                             "alwaysQuery" : true,
387                                                             "listWidth" : 400,
388                                                             "triggerAction" : "all",
389                                                             "fieldLabel" : "Sales Rep",
390                                                             "forceSelection" : true,
391                                                             "selectOnFocus" : true,
392                                                             "pageSize" : 80,
393                                                             "displayField" : "salesrep_name",
394                                                             "emptyText" : "Select salesrep",
395                                                             "hiddenName" : "cohead_display_salesrep_id",
396                                                             "minChars" : 2,
397                                                             "valueField" : "salesrep_id",
398                                                             "xtype" : "ComboBox",
399                                                             "allowBlank" : true,
400                                                             "typeAhead" : true,
401                                                             "editable" : false,
402                                                             "width" : 300,
403                                                             "$ xns" : "Roo.form",
404                                                             "name" : "cohead_display_salesrep_id_salesrep_name",
405                                                             "qtip" : "Select salesrep",
406                                                             "queryParam" : "query[salesrep_name]",
407                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
408                                                             "loadingText" : "Searching...",
409                                                             "items" : [
410                                                                 {
411                                                                     "listeners" : {
412                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
413                                                                     },
414                                                                     "xtype" : "Store",
415                                                                     "remoteSort" : true,
416                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
417                                                                     "$ xns" : "Roo.data",
418                                                                     "* prop" : "store",
419                                                                     "items" : [
420                                                                         {
421                                                                             "$ url" : "baseURL + '/Roo/salesrep.php'",
422                                                                             "method" : "GET",
423                                                                             "xtype" : "HttpProxy",
424                                                                             "$ xns" : "Roo.data",
425                                                                             "* prop" : "proxy"
426                                                                         },
427                                                                         {
428                                                                             "id" : "salesrep_id",
429                                                                             "root" : "data",
430                                                                             "xtype" : "JsonReader",
431                                                                             "$ xns" : "Roo.data",
432                                                                             "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
433                                                                             "* prop" : "reader",
434                                                                             "totalProperty" : "total"
435                                                                         }
436                                                                     ]
437                                                                 }
438                                                             ]
439                                                         },
440                                                         {
441                                                             "alwaysQuery" : true,
442                                                             "listWidth" : 400,
443                                                             "triggerAction" : "all",
444                                                             "fieldLabel" : "Staff I.C.",
445                                                             "forceSelection" : true,
446                                                             "selectOnFocus" : true,
447                                                             "pageSize" : 80,
448                                                             "displayField" : "salesrep_name",
449                                                             "emptyText" : "Select Staff",
450                                                             "hiddenName" : "cohead_salesrep_id",
451                                                             "minChars" : 2,
452                                                             "valueField" : "salesrep_id",
453                                                             "xtype" : "ComboBox",
454                                                             "allowBlank" : false,
455                                                             "typeAhead" : true,
456                                                             "editable" : false,
457                                                             "width" : 300,
458                                                             "$ xns" : "Roo.form",
459                                                             "name" : "cohead_salesrep_id_salesrep_name",
460                                                             "qtip" : "Select salesrep",
461                                                             "queryParam" : "query[salesrep_name]",
462                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
463                                                             "loadingText" : "Searching...",
464                                                             "items" : [
465                                                                 {
466                                                                     "listeners" : {
467                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
468                                                                     },
469                                                                     "xtype" : "Store",
470                                                                     "remoteSort" : true,
471                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
472                                                                     "$ xns" : "Roo.data",
473                                                                     "* prop" : "store",
474                                                                     "items" : [
475                                                                         {
476                                                                             "$ url" : "baseURL + '/Roo/salesrep.php'",
477                                                                             "method" : "GET",
478                                                                             "xtype" : "HttpProxy",
479                                                                             "$ xns" : "Roo.data",
480                                                                             "* prop" : "proxy"
481                                                                         },
482                                                                         {
483                                                                             "id" : "salesrep_id",
484                                                                             "root" : "data",
485                                                                             "xtype" : "JsonReader",
486                                                                             "$ xns" : "Roo.data",
487                                                                             "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
488                                                                             "* prop" : "reader",
489                                                                             "totalProperty" : "total"
490                                                                         }
491                                                                     ]
492                                                                 }
493                                                             ]
494                                                         },
495                                                         {
496                                                             "fieldLabel" : "Order Comments",
497                                                             "xtype" : "TextArea",
498                                                             "width" : 300,
499                                                             "$ xns" : "Roo.form",
500                                                             "name" : "cohead_ordercomments",
501                                                             "height" : 80
502                                                         }
503                                                     ]
504                                                 }
505                                             ]
506                                         },
507                                         {
508                                             "style" : "width:420px",
509                                             "xtype" : "FieldSet",
510                                             "legend" : "Billing",
511                                             "$ xns" : "Roo.form",
512                                             "items" : [
513                                                 {
514                                                     "xtype" : "Column",
515                                                     "labelWidth" : 50,
516                                                     "width" : 420,
517                                                     "$ xns" : "Roo.form",
518                                                     "items" : [
519                                                         {
520                                                             "listeners" : {
521                                                                 "add" : "function (combo)\n{\n  \n  Pman.Dialog.XtupleQuickContact.show( \n            {\n              _id : id,\n              customer_id : _this.form.findField('cohead_cust_id').getValue()\n            },\n            \n            function (data) {\n               \n                for(var i in  data) {\n                    \n                    _this.data['cohead_billto_cntct_id_' + i] =  data[i];\n                }\n                \n                _this.form.findField('billto_address').update();\n                // fill in the select box..\n                _this.form.setValues( {\n                    cohead_billto_cntct_id : data.cntct_id,\n                    cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ \n                            data.cntct_last_name\n                    \n                });\n            }\n        );\n        //  Pman.Dialog.XtupleCustomer.show(\n            //{ cust_id : _this.form.findField('cohead_cust_id').getValue() }, \n            //function(data) {\n        // refresh the data in the pulldown..\n    //    }); \n\n}",
522                                                                 "beforeselect" : "function (combo, record, index)\n{\n    // set _this.data values ..\n\n    // just add everything...\n    for(var i in record.data) {\n        _this.data['cohead_billto_cntct_id_' + i] = record.data[i];\n    }\n    \n    _this.form.findField('billto_address').update();\n    \n    \n \n}"
523                                                             },
524                                                             "alwaysQuery" : true,
525                                                             "listWidth" : 400,
526                                                             "triggerAction" : "all",
527                                                             "fieldLabel" : "Bill To (select)",
528                                                             "forceSelection" : true,
529                                                             "selectOnFocus" : true,
530                                                             "pageSize" : 20,
531                                                             "displayField" : "cntct_name",
532                                                             "emptyText" : "Select cntct",
533                                                             "hiddenName" : "cohead_billto_cntct_id",
534                                                             "minChars" : 2,
535                                                             "valueField" : "cntct_id",
536                                                             "xtype" : "ComboBox",
537                                                             "allowBlank" : false,
538                                                             "typeAhead" : true,
539                                                             "editable" : true,
540                                                             "width" : 300,
541                                                             "$ xns" : "Roo.form",
542                                                             "name" : "cohead_billto_cntct_id_cntct_name",
543                                                             "qtip" : "Select cntct",
544                                                             "queryParam" : "query[cntct_name]",
545                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>",
546                                                             "loadingText" : "Searching...",
547                                                             "items" : [
548                                                                 {
549                                                                     "listeners" : {
550                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    o.params._customer_id = _this.data.cohead_cust_id;\n}\n"
551                                                                     },
552                                                                     "xtype" : "Store",
553                                                                     "remoteSort" : true,
554                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
555                                                                     "$ xns" : "Roo.data",
556                                                                     "* prop" : "store",
557                                                                     "items" : [
558                                                                         {
559                                                                             "$ url" : "baseURL + '/Roo/cntct.php'",
560                                                                             "method" : "GET",
561                                                                             "xtype" : "HttpProxy",
562                                                                             "$ xns" : "Roo.data",
563                                                                             "* prop" : "proxy"
564                                                                         },
565                                                                         {
566                                                                             "id" : "cntct_id",
567                                                                             "root" : "data",
568                                                                             "xtype" : "JsonReader",
569                                                                             "$ xns" : "Roo.data",
570                                                                             "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
571                                                                             "* prop" : "reader",
572                                                                             "totalProperty" : "total"
573                                                                         }
574                                                                     ]
575                                                                 }
576                                                             ]
577                                                         },
578                                                         {
579                                                             "listeners" : {
580                                                                 "render" : "function (_self)\n{\n   Roo.log(this.el)\n   \n   \n   \n   this.el.on('click', function() { \n       var id = _this.form.findField('cohead_billto_cntct_id').getValue();\n        Pman.Dialog.XtupleQuickContact.show( \n            {\n              _id : id,\n              customer_id : _this.form.findField('cohead_cust_id').getValue()\n            },\n            \n            function (data) {\n            \n                for(var i in  data) {\n                    \n                    _this.data['cohead_billto_cntct_id_' + i] =  data[i];\n                }\n                \n                _this.form.findField('billto_address').update();\n                // fill in the select box..\n                _this.form.setValues( {\n                    cohead_billto_cntct_id : data.cntct_id,\n                    cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ \n                            data.cntct_last_name\n                    \n                });\n                \n                        \n                Roo.log(data);\n            }\n        );\n   \n        Roo.log(\"Click text\");\n        \n        \n     });\n}"
581                                                             },
582                                                             "fieldLabel" : "or enter Address",
583                                                             "xtype" : "TextArea",
584                                                             "$ update" : "function() {\n\n    var c = ['first_name', 'last_name' ] ;\n    var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];\n    var v = [];\n    Roo.each(c, function(e) {\n        if (_this.data['cohead_billto_cntct_id_cntct_' +e].length) { \n            v.push(_this.data['cohead_billto_cntct_id_cntct_' +e]);\n        }\n    });\n    Roo.each(a, function(e) {\n        if (_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {\n            v.push(_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e]);\n        }\n    });\n\n    this.setValue(v.join(\"\\n\"));\n    \n    if(_this.data.cohead_billto_cntct_id_cntct_email.length){\n        _this.form.findField('billto_email').setValue(_this.data.cohead_billto_cntct_id_cntct_email);\n    }\n}\n",
585                                                             "readOnly" : true,
586                                                             "$ xns" : "Roo.form",
587                                                             "name" : "billto_address"
588                                                         },
589                                                         {
590                                                             "fieldLabel" : "Email",
591                                                             "xtype" : "DisplayField",
592                                                             "$ valueRenderer" : "function(v)\n{\n \n    return v ? String.format('<a href=\"mailto:{0}\" target=\"_blank\">{0}</a>',v) : '';\n}",
593                                                             "$ xns" : "Roo.form",
594                                                             "name" : "billto_email"
595                                                         }
596                                                     ]
597                                                 }
598                                             ]
599                                         }
600                                     ]
601                                 },
602                                 {
603                                     "xtype" : "Column",
604                                     "style" : "margin-left:10px",
605                                     "width" : 435,
606                                     "$ xns" : "Roo.form",
607                                     "items" : [
608                                         {
609                                             "legend" : "Price Details",
610                                             "xtype" : "FieldSet",
611                                             "style" : "width:420px",
612                                             "labelWidth" : 50,
613                                             "$ xns" : "Roo.form",
614                                             "items" : [
615                                                 {
616                                                     "labelAlign" : "right",
617                                                     "xtype" : "Column",
618                                                     "labelWidth" : 300,
619                                                     "width" : 420,
620                                                     "$ xns" : "Roo.form",
621                                                     "items" : [
622                                                         {
623                                                             "labelAlign" : "top",
624                                                             "xtype" : "Row",
625                                                             "labelSeparator" : "&nbsp;",
626                                                             "width" : 500,
627                                                             "$ xns" : "Roo.form",
628                                                             "items" : [
629                                                                 {
630                                                                     "listeners" : {
631                                                                         "beforequery" : "function (combo, query, forceAll, cancel, e)\n{\n    Roo.log('beforequery');\n   \n    if (_this.form.findField('cohead_number').getValue().length) {\n        Roo.MessageBox.alert(\"Error\", \"You can not change the currency of this order\");\n        if (query) {\n            query.cancel = true;\n        }\n        return false;\n    }\n}"
632                                                                     },
633                                                                     "listWidth" : 400,
634                                                                     "triggerAction" : "all",
635                                                                     "fieldLabel" : "Currency",
636                                                                     "forceSelection" : true,
637                                                                     "selectOnFocus" : true,
638                                                                     "pageSize" : 20,
639                                                                     "displayField" : "curr_name",
640                                                                     "emptyText" : "Select curr_name",
641                                                                     "hiddenName" : "cohead_curr_id",
642                                                                     "minChars" : 2,
643                                                                     "valueField" : "curr_id",
644                                                                     "xtype" : "ComboBox",
645                                                                     "allowBlank" : false,
646                                                                     "typeAhead" : true,
647                                                                     "editable" : false,
648                                                                     "width" : 285,
649                                                                     "$ xns" : "Roo.form",
650                                                                     "name" : "cohead_curr_id_curr_name",
651                                                                     "qtip" : "Select Currency",
652                                                                     "queryParam" : "query[curr_name]",
653                                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>",
654                                                                     "loadingText" : "Searching...",
655                                                                     "items" : [
656                                                                         {
657                                                                             "listeners" : {
658                                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n   \n}\n"
659                                                                             },
660                                                                             "xtype" : "Store",
661                                                                             "remoteSort" : true,
662                                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'curr_symbol' }",
663                                                                             "$ xns" : "Roo.data",
664                                                                             "* prop" : "store",
665                                                                             "items" : [
666                                                                                 {
667                                                                                     "$ url" : "baseURL + '/Roo/curr_symbol.php'",
668                                                                                     "method" : "GET",
669                                                                                     "xtype" : "HttpProxy",
670                                                                                     "$ xns" : "Roo.data",
671                                                                                     "* prop" : "proxy"
672                                                                                 },
673                                                                                 {
674                                                                                     "id" : "curr_id",
675                                                                                     "root" : "data",
676                                                                                     "xtype" : "JsonReader",
677                                                                                     "$ xns" : "Roo.data",
678                                                                                     "$ fields" : "[{\"name\":\"curr_id\",\"type\":\"int\"},\"curr_symbol\"]",
679                                                                                     "* prop" : "reader",
680                                                                                     "totalProperty" : "total"
681                                                                                 }
682                                                                             ]
683                                                                         }
684                                                                     ]
685                                                                 },
686                                                                 {
687                                                                     "fieldLabel" : "Products",
688                                                                     "xtype" : "NumberField",
689                                                                     "cls" : "roo-align-right",
690                                                                     "readOnly" : true,
691                                                                     "allowDecimals" : true,
692                                                                     "decimalPrecision" : 3,
693                                                                     "width" : 100,
694                                                                     "$ xns" : "Roo.form",
695                                                                     "name" : "cohead_subtotal"
696                                                                 }
697                                                             ]
698                                                         },
699                                                         {
700                                                             "labelAlign" : "top",
701                                                             "xtype" : "Row",
702                                                             "labelSeparator" : "&nbsp;",
703                                                             "width" : 500,
704                                                             "$ xns" : "Roo.form",
705                                                             "items" : [
706                                                                 {
707                                                                     "listeners" : {
708                                                                         "select" : "function (combo, record, index)\n{\n     _this.form.findField('cohead_tax').setValue(\n             parseFloat(record.data.taxzone_rate) * \n             parseFloat(_this.form.findField('cohead_subtotal').getValue())\n     );\n      _this.form.findField('cohead_total').recalc();\n}"
709                                                                     },
710                                                                     "listWidth" : 400,
711                                                                     "triggerAction" : "all",
712                                                                     "fieldLabel" : "Tax Zone",
713                                                                     "forceSelection" : true,
714                                                                     "selectOnFocus" : true,
715                                                                     "pageSize" : 20,
716                                                                     "displayField" : "taxzone_descrip",
717                                                                     "emptyText" : "Select taxtype",
718                                                                     "hiddenName" : "cohead_taxzone_id",
719                                                                     "minChars" : 2,
720                                                                     "valueField" : "taxzone_id",
721                                                                     "xtype" : "ComboBox",
722                                                                     "allowBlank" : false,
723                                                                     "typeAhead" : true,
724                                                                     "editable" : false,
725                                                                     "width" : 285,
726                                                                     "$ xns" : "Roo.form",
727                                                                     "name" : "cohead_taxzone_id_taxzone_descrip",
728                                                                     "qtip" : "Select taxtype",
729                                                                     "queryParam" : "query[taxzone_descrip]",
730                                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>",
731                                                                     "loadingText" : "Searching...",
732                                                                     "items" : [
733                                                                         {
734                                                                             "listeners" : {
735                                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    \n    o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d'); \n    Roo.log(\"with date?\" + o.params.with_date);\n    \n    \n}\n"
736                                                                             },
737                                                                             "xtype" : "Store",
738                                                                             "remoteSort" : true,
739                                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'taxzone_descrip' }",
740                                                                             "$ xns" : "Roo.data",
741                                                                             "* prop" : "store",
742                                                                             "items" : [
743                                                                                 {
744                                                                                     "$ url" : "baseURL + '/Roo/taxzone.php'",
745                                                                                     "xtype" : "HttpProxy",
746                                                                                     "method" : "GET",
747                                                                                     "$ xns" : "Roo.data",
748                                                                                     "* prop" : "proxy"
749                                                                                 },
750                                                                                 {
751                                                                                     "id" : "taxzone_id",
752                                                                                     "root" : "data",
753                                                                                     "xtype" : "JsonReader",
754                                                                                     "$ fields" : "[{\"name\":\"taxzone_id\",\"type\":\"int\"},\"taxzone_descrip\"]",
755                                                                                     "$ xns" : "Roo.data",
756                                                                                     "* prop" : "reader",
757                                                                                     "totalProperty" : "total"
758                                                                                 }
759                                                                             ]
760                                                                         }
761                                                                     ]
762                                                                 },
763                                                                 {
764                                                                     "fieldLabel" : "Tax",
765                                                                     "xtype" : "NumberField",
766                                                                     "cls" : "roo-align-right",
767                                                                     "readOnly" : true,
768                                                                     "allowDecimals" : true,
769                                                                     "decimalPrecision" : 3,
770                                                                     "width" : 100,
771                                                                     "$ xns" : "Roo.form",
772                                                                     "name" : "cohead_tax"
773                                                                 }
774                                                             ]
775                                                         },
776                                                         {
777                                                             "fieldLabel" : "Pre Tax discount",
778                                                             "xtype" : "NumberField",
779                                                             "cls" : "roo-align-right",
780                                                             "readOnly" : true,
781                                                             "allowDecimals" : true,
782                                                             "decimalPrecision" : 3,
783                                                             "width" : 100,
784                                                             "$ xns" : "Roo.form",
785                                                             "name" : "cohead_pretax_discount"
786                                                         },
787                                                         {
788                                                             "labelAlign" : "top",
789                                                             "xtype" : "Row",
790                                                             "labelSeparator" : "&nbsp;",
791                                                             "width" : 500,
792                                                             "$ xns" : "Roo.form",
793                                                             "items" : [
794                                                                 {
795                                                                     "fieldLabel" : "Discount after Tax  Description",
796                                                                     "xtype" : "TextField",
797                                                                     "width" : 230,
798                                                                     "$ xns" : "Roo.form",
799                                                                     "name" : "cohead_misc_descrip"
800                                                                 },
801                                                                 {
802                                                                     "listeners" : {
803                                                                         "keyup" : "function (_self, e)\n{\n    var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());\n    var tax = parseFloat(_this.form.findField('cohead_tax').getValue());\n    var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());\n    \n    var n = this.getValue();\n    var discount = parseFloat(n * (pv + tax + pd) * 0.01);\n    \n    _this.form.findField('cohead_posttax_discount').setValue(discount);\n\n    _this.form.findField('cohead_total').recalc();\n    _this.form.findField('cohead_misc').recalc();\n    var val = discount * -1.0;\n     if (val > 0) {\n        _this.form.findField('cohead_misc_descrip').setValue(\"Discount of \" + val.toFixed(1)+'%');\n    }\n   \n    \n}"
804                                                                     },
805                                                                     "fieldLabel" : "%",
806                                                                     "xtype" : "NumberField",
807                                                                     "$ update" : "function() {\n    var m = _this.form.findField('cohead_misc_per');\n    var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());\n    var tax = parseFloat(_this.form.findField('cohead_tax').getValue());\n    var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());\n    \n    var discount = parseFloat(_this.form.findField('cohead_posttax_discount').getValue());\n    \n    if (discount > 0.0) {\n        this.setValue(0);        \n        return;\n    }\n    if (pv < 0) {\n        this.setValue(0);        \n        return;\n    }\n    var val = ((discount) / (pv + tax + pd)) * -100;\n    \n    //Roo.log(\"update discount?\" + val);\n    this.setValue(val.toFixed(1));\n    \n     if (val > 0.0) {\n        _this.form.findField('cohead_misc_descrip').setValue(\"Discount of \" + val.toFixed(1)+'%');\n    \n    }\n    \n   \n}\n",
808                                                                     "cls" : "roo-align-right",
809                                                                     "allowDecimals" : true,
810                                                                     "decimalPrecision" : 1,
811                                                                     "width" : 35,
812                                                                     "$ xns" : "Roo.form",
813                                                                     "name" : "cohead_misc_per"
814                                                                 },
815                                                                 {
816                                                                     "listeners" : {
817                                                                         "keyup" : "function (_self, e)\n{\n   _this.form.findField('cohead_misc_per').update();\n    _this.form.findField('cohead_total').recalc();\n    _this.form.findField('cohead_misc').recalc();\n}"
818                                                                     },
819                                                                     "fieldLabel" : "&nbsp;",
820                                                                     "xtype" : "NumberField",
821                                                                     "cls" : "roo-align-right",
822                                                                     "allowDecimals" : true,
823                                                                     "decimalPrecision" : 3,
824                                                                     "width" : 100,
825                                                                     "$ xns" : "Roo.form",
826                                                                     "name" : "cohead_posttax_discount"
827                                                                 }
828                                                             ]
829                                                         },
830                                                         {
831                                                             "fieldLabel" : "Total",
832                                                             "$ recalc" : "function() {\n    var d = _this.form.getValues();\n    this.setValue( \n                parseFloat(d.cohead_subtotal) + \n                parseFloat(d.cohead_pretax_discount) + \n                parseFloat(d.cohead_posttax_discount) + \n                parseFloat(d.cohead_tax) + \n                parseFloat(d.cohead_freight));\n}\n",
833                                                             "xtype" : "NumberField",
834                                                             "cls" : "roo-align-right",
835                                                             "readOnly" : true,
836                                                             "allowDecimals" : true,
837                                                             "decimalPrecision" : 3,
838                                                             "width" : 100,
839                                                             "$ xns" : "Roo.form",
840                                                             "name" : "cohead_total"
841                                                         },
842                                                         {
843                                                             "listeners" : {
844                                                                 "keyup" : "function (_self, e)\n{\n    _this.form.findField('cohead_total').recalc();\n}"
845                                                             },
846                                                             "fieldLabel" : "Shipping",
847                                                             "xtype" : "NumberField",
848                                                             "cls" : "roo-align-right",
849                                                             "allowDecimals" : true,
850                                                             "decimalPrecision" : 3,
851                                                             "width" : 100,
852                                                             "$ xns" : "Roo.form",
853                                                             "name" : "cohead_freight"
854                                                         },
855                                                         {
856                                                             "fieldLabel" : "Unshipped Total",
857                                                             "xtype" : "NumberField",
858                                                             "cls" : "roo-align-right",
859                                                             "readOnly" : true,
860                                                             "allowDecimals" : true,
861                                                             "decimalPrecision" : 3,
862                                                             "width" : 100,
863                                                             "$ xns" : "Roo.form",
864                                                             "name" : "cohead_unshipped"
865                                                         },
866                                                         {
867                                                             "fieldLabel" : "Uninvoiced Total",
868                                                             "xtype" : "NumberField",
869                                                             "cls" : "roo-align-right",
870                                                             "readOnly" : true,
871                                                             "allowDecimals" : true,
872                                                             "decimalPrecision" : 3,
873                                                             "width" : 100,
874                                                             "$ xns" : "Roo.form",
875                                                             "name" : "cohead_uninvoiced"
876                                                         }
877                                                     ]
878                                                 }
879                                             ]
880                                         },
881                                         {
882                                             "style" : "width:420px",
883                                             "xtype" : "FieldSet",
884                                             "legend" : "Shipping",
885                                             "$ xns" : "Roo.form",
886                                             "items" : [
887                                                 {
888                                                     "xtype" : "Column",
889                                                     "labelWidth" : 50,
890                                                     "width" : 420,
891                                                     "$ xns" : "Roo.form",
892                                                     "items" : [
893                                                         {
894                                                             "xtype" : "Row",
895                                                             "labelSeparator" : "&nbsp;",
896                                                             "$ xns" : "Roo.form",
897                                                             "items" : [
898                                                                 {
899                                                                     "listeners" : {
900                                                                         "check" : "function (_self, checked)\n{\n   if (!_this.form) {\n       return;\n   }\n   \n   if (_this.dataloading) {\n   \n       return;\n   }\n   \n   \n   if (checked) {\n   \n        // copy the cohead_billto_cntct_id\n        for (var i in _this.data) {\n            if (!i.match(/^cohead_billto_cntct_id/)) {\n                continue;\n            }\n            var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');\n            _this.data[ni] = _this.data[i];\n        }\n         _this.form.findField('shipto_address').update();\n         _this.form.setValues( {\n                cohead_shipto_cntct_id : _this.data.cohead_shipto_cntct_id,\n                cohead_shipto_cntct_id_cntct_name : _this.data.cohead_shipto_cntct_id_cntct_first_name + ' ' + \n                        _this.data.cohead_shipto_cntct_id_cntct_last_name \n                        \n                \n            });\n\n   \n    } else {\n         for (var i in _this.data) {\n            if (!i.match(/^cohead_billto_cntct_id/)) {\n                continue;\n            }\n            var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');\n            \n            _this.data[ni] = '';\n        }\n         _this.form.findField('shipto_address').update();\n         \n        _this.form.setValues( {\n                cohead_shipto_cntct_id : '',\n                cohead_shipto_cntct_id_cntct_name : '' \n                \n                \n            });\n    }\n    \n}"
901                                                                     },
902                                                                     "xtype" : "Checkbox",
903                                                                     "boxLabel" : "Same as Billing",
904                                                                     "$ xns" : "Roo.form",
905                                                                     "name" : "_shipto_same"
906                                                                 }
907                                                             ]
908                                                         },
909                                                         {
910                                                             "listeners" : {
911                                                                 "add" : "function (combo)\n{\n Pman.Dialog.XtupleQuickContact.show( \n            {\n              _id : id,\n              customer_id : _this.form.findField('cohead_cust_id').getValue()\n            },\n            \n            function (data) {\n               \n                for(var i in  data) {\n                    \n                    _this.data['cohead_shipto_cntct_id_' + i] =  data[i];\n                }\n                \n                _this.form.findField('shipto_address').update();\n                // fill in the select box..\n                _this.form.setValues( {\n                    cohead_shipto_cntct_id : data.cntct_id,\n                    cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ \n                            data.cntct_last_name\n                    \n                });\n            }\n        ); \n}",
912                                                                 "beforeselect" : "function (combo, record, index)\n{\n   \n    // just add everything...\n    for(var i in record.data) {\n        //Roo.log('cohead_shipto_cntct_id_' + i +' ='  + record.data[i]);\n        _this.data['cohead_shipto_cntct_id_' + i] = record.data[i];\n    }\n\n    _this.form.findField('shipto_address').update();\n    \n \n}"
913                                                             },
914                                                             "alwaysQuery" : true,
915                                                             "listWidth" : 400,
916                                                             "triggerAction" : "all",
917                                                             "fieldLabel" : "Ship to",
918                                                             "forceSelection" : true,
919                                                             "selectOnFocus" : true,
920                                                             "pageSize" : 20,
921                                                             "displayField" : "cntct_name",
922                                                             "emptyText" : "Select ship to",
923                                                             "hiddenName" : "cohead_shipto_cntct_id",
924                                                             "minChars" : 2,
925                                                             "valueField" : "cntct_id",
926                                                             "xtype" : "ComboBox",
927                                                             "allowBlank" : false,
928                                                             "typeAhead" : true,
929                                                             "editable" : true,
930                                                             "width" : 300,
931                                                             "$ xns" : "Roo.form",
932                                                             "name" : "cohead_shipto_cntct_id_cntct_name",
933                                                             "qtip" : "Select shiptoinfo",
934                                                             "queryParam" : "query[cntct_name]",
935                                                             "tpl" : "<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>",
936                                                             "loadingText" : "Searching...",
937                                                             "items" : [
938                                                                 {
939                                                                     "listeners" : {
940                                                                         "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    o.params._customer_id = _this.data.cohead_cust_id;\n}\n"
941                                                                     },
942                                                                     "xtype" : "Store",
943                                                                     "remoteSort" : true,
944                                                                     "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
945                                                                     "$ xns" : "Roo.data",
946                                                                     "* prop" : "store",
947                                                                     "items" : [
948                                                                         {
949                                                                             "$ url" : "baseURL + '/Roo/cntct.php'",
950                                                                             "method" : "GET",
951                                                                             "xtype" : "HttpProxy",
952                                                                             "$ xns" : "Roo.data",
953                                                                             "* prop" : "proxy"
954                                                                         },
955                                                                         {
956                                                                             "id" : "cntct_id",
957                                                                             "root" : "data",
958                                                                             "xtype" : "JsonReader",
959                                                                             "$ xns" : "Roo.data",
960                                                                             "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
961                                                                             "* prop" : "reader",
962                                                                             "totalProperty" : "total"
963                                                                         }
964                                                                     ]
965                                                                 }
966                                                             ]
967                                                         },
968                                                         {
969                                                             "listeners" : {
970                                                                 "render" : "function (_self)\n{\n   Roo.log(this.el)\n   \n   \n   \n   this.el.on('click', function() { \n       var id = _this.form.findField('cohead_shipto_cntct_id').getValue();\n        Pman.Dialog.XtupleQuickContact.show( \n            {\n              _id : id,\n              customer_id : _this.form.findField('cohead_cust_id').getValue()\n            },\n            \n            function (data) {\n            \n                for(var i in  data) {\n                    \n                    _this.data['cohead_shipto_cntct_id_' + i] =  data[i];\n                }\n                \n                _this.form.findField('shipto_address').update();\n                // fill in the select box..\n                _this.form.setValues( {\n                    cohead_shipto_cntct_id : data.cntct_id,\n                    cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ \n                            data.cntct_last_name\n                    \n                });\n                \n                        \n                //Roo.log(data);\n            }\n        );\n   \n      //  Roo.log(\"Click text\");\n        \n        \n     });\n}"
971                                                             },
972                                                             "fieldLabel" : "Address",
973                                                             "xtype" : "TextArea",
974                                                             "$ update" : "function() {\n\n    var c = ['first_name', 'last_name' ] ;\n    var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];\n    var v = [];\n    \n    if (_this.data['cohead_shipto_vend_name'] && _this.data['cohead_shipto_vend_name'].length) {\n         v.push(_this.data['cohead_shipto_vend_name']);\n    }\n        if (_this.data['cohead_shipto_vendaddr_code'] && _this.data['cohead_shipto_vendaddr_code'].length) {\n         v.push(_this.data['cohead_shipto_vendaddr_code']);\n    }\n    Roo.each(c, function(e) {\n        if (_this.data['cohead_shipto_cntct_id_cntct_' +e] && \n            _this.data['cohead_shipto_cntct_id_cntct_' +e].length) {\n            v.push(_this.data['cohead_shipto_cntct_id_cntct_' +e]);\n        }\n    });\n    Roo.each(a, function(e) {\n        if (_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e] && \n            _this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e].length) { \n            v.push(_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e]);\n        }\n    });\n\n    this.setValue(v.join(\"\\n\"));\n}\n",
975                                                             "readOnly" : true,
976                                                             "width" : 300,
977                                                             "$ xns" : "Roo.form",
978                                                             "name" : "shipto_address"
979                                                         },
980                                                         {
981                                                             "fieldLabel" : "Shipment Comments",
982                                                             "xtype" : "TextArea",
983                                                             "$ xns" : "Roo.form",
984                                                             "width" : 300,
985                                                             "name" : "cohead_shipcomments"
986                                                         }
987                                                     ]
988                                                 }
989                                             ]
990                                         }
991                                     ]
992                                 },
993                                 {
994                                     "xtype" : "Hidden",
995                                     "$ xns" : "Roo.form",
996                                     "name" : "cohead_id"
997                                 },
998                                 {
999                                     "xtype" : "Hidden",
1000                                     "$ xns" : "Roo.form",
1001                                     "name" : "cohead_shipto_id"
1002                                 },
1003                                 {
1004                                     "xtype" : "Hidden",
1005                                     "$ xns" : "Roo.form",
1006                                     "name" : "cohead_shipto_id_shipto_name"
1007                                 },
1008                                 {
1009                                     "xtype" : "Hidden",
1010                                     "$ xns" : "Roo.form",
1011                                     "name" : "cohead_max_linenumber"
1012                                 },
1013                                 {
1014                                     "xtype" : "Hidden",
1015                                     "$ xns" : "Roo.form",
1016                                     "name" : "cohead_cust_id"
1017                                 },
1018                                 {
1019                                     "$ recalc" : "function() {\n    var d = _this.form.getValues();\n    this.setValue( \n        parseFloat(d.cohead_pretax_discount) + \n        parseFloat(d.cohead_posttax_discount) );\n}\n",
1020                                     "xtype" : "Hidden",
1021                                     "$ xns" : "Roo.form",
1022                                     "name" : "cohead_misc"
1023                                 },
1024                                 {
1025                                     "xtype" : "Hidden",
1026                                     "$ xns" : "Roo.form",
1027                                     "name" : "taxzone_rate"
1028                                 }
1029                             ]
1030                         }
1031                     ]
1032                 },
1033                 {
1034                     "listeners" : {
1035                         "deactivate" : "function (_self)\n{\n    if(_this.grid){\n        _this.grid.stopEditing();\n    }\n}",
1036                         "|activate" : "function() {\n    _this.panel = this;\n    \n    try { if (MODULE.isBuilder) {\n        return;\n    } } catch(e) { }\n    \n    var id = _this.form.findField('cohead_id').getValue() * 1;\n    if (id < 1) {\n        Roo.MessageBox.alert(\"Save First\", \"Save the order first, before adding items\");\n        _this.dialog.layout.getRegion('center').showPanel(0);\n        return;\n    }\n    \n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    \n         //if (_this.form.findField('cohead_cust_id_cust_name').getValue() == 'Bloom and Grow HK') {\n         //   _this.xferAll.show();\n        // \n        // } else {\n        //     _this.xferAll.hide();\n        // }\n     }\n    \n}"
1037                     },
1038                     "fitToframe" : true,
1039                     "background" : true,
1040                     "region" : "center",
1041                     "title" : "Order Items",
1042                     "xtype" : "GridPanel",
1043                     "fitContainer" : true,
1044                     "$ xns" : "Roo",
1045                     "tableName" : "coitem",
1046                     "items" : [
1047                         {
1048                             "listeners" : {
1049                                 "beforeedit" : "function (e)\n{\n    // we can only edit if nothing is assigned to shipping or invoices..\n    \n    var rec = e.record\n\n    if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0 || (rec.data.shipitem_shipped - rec.data.coitem_qtyshipped) > 0 ) {\n        Roo.MessageBox.alert(\"Error\", \"That item has been shipped, has a draft shipment  or invoices - void the shipments/invoices first\");\n        e.cancel = true;\n        return;\n    }\n    \n    if (rec.data.coitem_subnumber * 1 > 0) {\n        Roo.log(\"Edit container event\");\n        Roo.log(e); // if it's a tab.. \n\n        \n        switch(e.field) {\n            // allow editing of source / destination..\n            case 'coitem_shipto_id':\n            case 'coitem_location_src':            \n                return;\n            default : \n                break;\n        }\n        Roo.MessageBox.alert(\"Error\", \"That is a kit item, edit the container.\");\n        e.cancel = true;\n        return;\n    }\n    // zero off values..\n    //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {\n    //        e.value ='';\n    //    }\n    //    if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {\n    //        e.value ='';\n    //    }\n    \n    if (rec.data.item_type == 'K' && e.field == 'item_number') {\n        // you can not change the product type on kits' as it messing things up..\n        Roo.MessageBox.alert(\"Error\", \"That is a kit item,if you need to change it, delete it first.\");\n        e.cancel = true;\n        return;\n    }\n    \n}",
1050                                 "|render" : "function() \n{\n    _this.grid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    \n    if (_this.panel.active) {\n       this.footer.onClick('first');\n    }\n}",
1051                                 "celldblclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    var rec = this.ds.getAt(rowIndex);\n    var di = this.cm.getDataIndex(columnIndex);\n    if (di != 'avail_qty') {\n        return;\n    }\n    \n    Pman.Dialog.XtupleInvHistory.show({\n        itemsite_item_id_item_number   : rec.data.item_number,\n       // itemsite_item_id_item_descript1 : rec.data.item_descrip1,\n        location_name : rec.data.coitem_location_src_location_name,\n        location_descrip : rec.data.coitem_location_src_location_descrip,\n        \n        invhist_transdate : _this.form.findField('cohead_targetdate').getValue() \n    }); \n    \n}",
1052                                 "afteredit" : "function (e)\n{\n    Roo.log('afteredit:' + e.record.data.coitem_linenumber);\n\n    \n   // if ( e.record && e.record.data.coitem_id) {\n        // as we disable update to the display on the ajax callback to \n        // allow editing flow to continue, and not refresh - we can only update\n        // these values after something has actually been edited.\n        // e.record.set('coitem_id', e.record.data.coitem_id);\n        // e.record.set('coitem_status', e.record.data.coitem_status);\n   // }\n    \n    if (e.field == 'item_number' || e.originalValue == e.value) {\n        // afterselect handles this...\n        return;\n    }\n    if (e.field == 'item_descrip1') {\n        e.record.set('coitem_memo', e.value);\n    }\n    var rate = _this.form.findField('taxzone_rate').getValue();\n    switch(e.field) {\n        case 'coitem_linedisc':\n           \n            var cp = parseFloat(e.record.data.coitem_custprice);\n           \n            if (isNaN(cp) || cp == 0.0) {\n                break;\n            }\n            \n            var dis = parseFloat(e.value);\n           \n            if (isNaN(dis)) {\n                break;\n            }\n            \n            e.record.set(\n                'coitem_price',\n                Math.max(0,cp * ((100.0 -  parseInt(e.value))/ 100.0) )  \n            );\n            \n           // donot need to set the subtotal here, coz we will render it automatically\n           // e.record.set(\n           //     'coitem_subtotal',\n           //      e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord\n           // );\n            break;\n        \n        case  'coitem_price': // SELL@ price\n\n             var cp = parseFloat(e.record.data.coitem_custprice);\n             // list price is < price -- update it..\n             if (isNaN(cp) || cp == 0.0 || cp < e.value) {\n                e.record.set('coitem_custprice', e.value);\n                cp = e.value;\n             }\n             // update the discount calc.\n             \n             e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( e.value / cp) * 100.0)));  \n             \n             // donot need to set the subtotal here, coz we will render it automatically\n             //e.record.set(\n             //   'coitem_subtotal',\n              //   e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord\n             //);\n             break;\n        \n        case 'coitem_custprice':\n            // modified customer price...\n            // just modify the discount.. -- leave the entered price the same..\n              var sp =  parseFloat(e.record.data.coitem_price);\n              var cp = parseFloat(e.value);\n              if (isNaN(cp) || cp == 0.0 || cp < e.value) {\n                    break;\n              }\n              \n             e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  \n             \n             break;\n             \n        case 'coitem_custprice_tax':\n              var cp = parseFloat(e.value / ( 1 + rate * 1 ));\n              var sp =  parseFloat(e.record.data.coitem_price);\n              \n              if (isNaN(cp) || cp == 0.0) {\n                    break;\n              }\n              e.record.set('coitem_custprice', cp);\n              e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  \n             \n             break; \n             \n         case  'coitem_price_tax':\n\n             var cp = parseFloat(e.record.data.coitem_custprice);\n             var sp = parseFloat(e.value / ( 1 + rate * 1 ));\n             if (isNaN(cp) || cp == 0.0 || cp < sp) {\n                e.record.set('coitem_custprice', sp);\n                cp = sp;\n             }\n             e.record.set('coitem_price', sp);\n             e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  \n             \n             break;\n      \n    }\n    \n     \n    \n    \n    var doupdate = function() { \n       if (!e.record.updatePending) {\n            Roo.log('doupdate...'  + e.record.data.coitem_linenumber);\n            Roo.log(e.record);\n            e.record.commit();\n            return;\n        }\n       Roo.log('doupdate pending...'   + e.record.data.coitem_linenumber);\n        // wait until it's not peding an update..\n        doupdate.defer(500);\n    }\n\n    if(e.record.data.coitem_id * 1 < 1 && !e.record.isInserting){ // insert\n        e.record.isInserting = 1;\n        e.record.isUpdating = 0;\n        doupdate();\n        return;\n    }\n    \n    // update\n    if(!e.record.isInserting && !e.record.isUpdating){\n        e.record.isUpdating = 1;\n        doupdate();\n        return;\n    }\n    \n    if(!e.record.updatePending){\n        e.record.updatePending = 1;\n        doupdate();\n        return;\n    }\n    Roo.log(\"got to end without doing an update?\"  + e.record.data.coitem_linenumber);\n    \n}\n",
1053                                 "rowclass" : "function (gridview, rowcfg)\n{\n    if (rowcfg.record.data.coitem_status == 'C' &&\n        rowcfg.record.data.shipitem_shipped * 1 < 1) {\n        \n        rowcfg.rowClass = 'strikethrough';\n    }\n     if (rowcfg.record.data.coitem_status == 'X'  ) {\n        \n        rowcfg.rowClass = 'strikethrough';\n    }\n    \n    if (!rowcfg.record.data.coitem_id) { \n            rowcfg.rowClass = 'dragon-not-saved';\n    }\n    \n    \n   // Roo.log(rowcfg);\n//    shipitem_shipped\n}"
1054                             },
1055                             "autoExpandColumn" : "item_descrip1",
1056                             "xtype" : "EditorGrid",
1057                             "loadMask" : true,
1058                             "$ loadAvail" : "function() {\n    \n    \n    this.ds.each(function(r) {\n        \n        if(!r.data.item_number.length){\n            return;\n        }\n        \n        if(typeof(_this.stockcache[r.data.item_number]) != 'undefined'){\n        \n            r.set('avail_qty', _this.stockcache[r.data.item_number].qty);\n            if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {\n                r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);\n            }\n            return;\n        }\n        \n        var q = [];\n        \n        q.push( { \n            item : r.data.item_number, \n            loc: r.data.coitem_location_src_location_name,\n            id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')\n         } );\n         \n         new Pman.Request({\n            url : baseURL + '/Roo/itemloc',\n            method : 'POST',\n            params : {\n                _availqty : Roo.encode(q),\n                curr_name : _this.form.findField('cohead_curr_id').el.dom.value\n            },\n            success : function(res) \n            {\n                for (var i in res.data) {\n                   _this.stockcache[res.data[i].item] = res.data[i];\n                }\n                r.set('avail_qty', _this.stockcache[r.data.item_number].qty);\n                if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {\n                    r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);\n                }\n                //_this.grid.ds.fireEvent(\"update\", _this.grid.ds, r, Roo.data.Record.EDIT);\n                return\n            }\n        });\n    });\n        \n                \n}\n",
1059                             "clicksToEdit" : 1,
1060                             "$ xns" : "Roo.grid",
1061                             "* prop" : "grid",
1062                             "items" : [
1063                                 {
1064                                     "listeners" : {
1065                                         "tabend" : "function (_self)\n{\n    _this.addItemBtn.fireEvent('click', _this.addItemBtn);\n}",
1066                                         "beforeeditnext" : "function (eventdata)\n{\n    \n    return;\n    // this does not work, as the reload effect cancels editng.\n    var rec = _this.grid.ds.getAt(eventdata.cell[0]);\n    if (rec.data.coitem_subnumber *1 < 0 ) {\n        return;\n    }\n    var r = eventdata.cell[0] + 1;\n\n    while (true) {\n        if (r > _this.grid.ds.getCount()-1 ) {\n            eventdata.cell = false;\n            return;\n        }\n        rec =  _this.grid.ds.getAt(r);\n        if (rec.data.coitem_subnumber *1 < 0 ) {\n           eventdata.cell = [ r, eventdata.cell[1] ];\n           return;\n        }\n        r++;\n    }\n    \n    \n \n\n}"
1067                                     },
1068                                     "xtype" : "CellSelectionModel",
1069                                     "$ xns" : "Roo.grid",
1070                                     "* prop" : "sm",
1071                                     "enter_is_tab" : true
1072                                 },
1073                                 {
1074                                     "pageSize" : 100,
1075                                     "xtype" : "PagingToolbar",
1076                                     "emptyMsg" : "No Items",
1077                                     "$ xns" : "Roo",
1078                                     "displayInfo" : true,
1079                                     "$ updateSummary" : "function() {\n    var f = this;\n    new Pman.Request({\n        url : baseURL + '/Roo/Coitem',\n        method : 'GET',\n        params : {\n            _totals : 1,\n            coitem_cohead_id : _this.form.findField('cohead_id').getValue()\n        },\n        success : function(d) {\n            //Roo.log(d);\n            f.displayEl.update(String.format(\n                \"{0} items |  Subtotal: {2} | Tax: {3} | List Discount {4} | Total : {1}{5}\",\n                d.data.total_qty,\n                _this.form.findField('cohead_curr_id').el.dom.value,\n                d.data.total_sub,\n                d.data.total_tax,\n                d.data.total_list_discount,                \n                d.data.total_total\n            ));\n                \n        }\n    });\n}\n",
1080                                     "* prop" : "footer",
1081                                     "items" : [
1082                                         {
1083                                             "listeners" : {
1084                                                 "click" : "function (_self, e)\n{\n    new Pman.Request({\n        url : baseURL + '/Roo/Cohead',\n        method : 'GET',\n        params : {\n            _fill_shipto : _this.form.findField('cohead_id').getValue()\n        },\n        success : function() {\n            _this.grid.footer.onClick('first');\n        }\n    });\n}"
1085                                             },
1086                                             "text" : "Fill empty Ship To",
1087                                             "xtype" : "Button",
1088                                             "$ xns" : "Roo.Toolbar"
1089                                         },
1090                                         {
1091                                             "listeners" : {
1092                                                 "click" : "function (_self, e)\n{\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure?<BR>\"+\n        \"This will set all the locations to match the Sales Order - and remove all old locations.\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                url : baseURL + '/Roo/Cohead',\n                method : 'GET',\n                params : {\n                    _fill_location : _this.form.findField('cohead_id').getValue(),\n                    _location_id : _this.form.findField('cohead_location_src').getValue()\n                },\n                success : function() {\n                    _this.grid.footer.onClick('first');\n                }\n            });\n    });\n    \n}"
1093                                             },
1094                                             "text" : "Update Location to match S/O",
1095                                             "xtype" : "Button",
1096                                             "$ xns" : "Roo.Toolbar"
1097                                         },
1098                                         {
1099                                             "listeners" : {
1100                                                 "toggle" : "function (_self, pressed)\n{\n    this.setText(pressed ? \"Prices exc GST\" : \"Prices with GST\");\n    var cm = _this.grid.getColumnModel();\n\n    cm.setHidden(cm.getIndexByDataIndex('coitem_price_tax'), pressed ? false : true);\n    cm.setHidden(cm.getIndexByDataIndex('coitem_custprice_tax'), pressed ? false : true);\n    cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal_tax'), pressed ? false : true);\n    \n    cm.setHidden(cm.getIndexByDataIndex('coitem_price'), pressed ? true : false);\n    cm.setHidden(cm.getIndexByDataIndex('coitem_custprice'), pressed ? true : false);\n    cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal'), pressed ? true : false);\n    return;\n}",
1101                                                 "render" : "function (_self)\n{\n    _this.showgstBtn = _self;\n}"
1102                                             },
1103                                             "text" : "Prices with GST",
1104                                             "enableToggle" : true,
1105                                             "minWidth" : 100,
1106                                             "xtype" : "Button",
1107                                             "$ xns" : "Roo.Toolbar"
1108                                         }
1109                                     ]
1110                                 },
1111                                 {
1112                                     "listeners" : {
1113                                         "|beforeload" : "function (_self,o) {\n\n    try {\n       this.removeAll();\n   } catch (e) { }\n   \n\n    if (!_this.data || !_this.data.cohead_id) {\n        return false;\n    }\n    o.params = o.params || {};\n    \n    o.params.coitem_cohead_id = _this.data.cohead_id;\n    o.params._without_list_discount =1;\n    //o.params.limit = 999;\n\n    \n}",
1114                                         "update" : "function (_self, rec, operation)\n    {\n   \n   if (operation !=  Roo.data.Record.COMMIT) {\n       return;\n   }\n\n   // row has been updated..\n   // if the qty + item has been filled in, we should try and save it..\n \n    \n    var setRecord = function(){\n    \n         Roo.log(\"Clearing update?\"  + rec.data.coitem_linenumber);\n        rec.updatePending = 0;\n        if(rec.isInserting){\n            rec.isInserting = 0;\n            return;\n        }\n        rec.isUpdating = 0;\n\n    }\n    if (!(rec.data.coitem_itemsite_id * 1) || !(rec.data.coitem_qtyord*1)) {\n        setRecord();\n        return;\n    }\n    var     doCommit = function() {\n         Roo.log(\"Sending  data?\"  + rec.data.coitem_linenumber);\n        \n        new Pman.Request({\n            url : baseURL+'/Roo/coitem',\n            method : 'POST',\n            params : rec.data,\n            success: function(res)\n            {\n                try {\n                    var row = _this.grid.ds.indexOf(rec);\n                    Roo.get(_this.grid.view.getRow(row)).removeClass('dragon-not-saved');\n                } catch(e) {\n                    Roo.log(e);\n                }\n                    \n                \n                 Roo.log(\"GOT success: \"  + rec.data.coitem_linenumber);\n                //Roo.log(\"GOT success\");\n                // update the data...\n                \n                if (rec.data.item_type == 'K') {\n                     Roo.log(\"Kit??\");\n                    _this.grid.ds.load({});\n                    \n                    return;\n                }\n                \n                // why is this here.??\n                \n                if (_this.grid.activeEditor) {\n                     rec.editing = true;\n                     \n                     \n                 } \n                 \n                rec.set('coitem_id', res.data.coitem_id);\n                rec.set('coitem_status', res.data.coitem_status);\n                 \n                \n                rec.dirty = false;\n                delete rec.modified;\n                try {\n                    _this.grid.footer.updateSummary();          \n                    _this.grid.loadAvail();\n                } catch (e) { }\n                \n\n                setRecord();\n            },\n            failure : function(res)\n            {\n                setRecord();\n                Roo.MessageBox.alert(\"Error\", res.errorMsg ? res.errorMsg : \"Error updating\");\n            }\n            \n            \n        });\n      } ; \n   \n    \n    doCommit();\n    \n    \n    \n}\n   \n  ",
1115                                         "load" : "function (_self, records, options)\n{\n    // need to fetch availablity from master data..\n    // build a list of what to ask..\n\n    // query: ITEM CODE - LOCATION\n    _this.grid.footer.updateSummary();\n    _this.grid.loadAvail.defer(100, _this.grid);\n\n    \n    \n    \n}"
1116                                     },
1117                                     "xtype" : "Store",
1118                                     "remoteSort" : true,
1119                                     "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
1120                                     "$ xns" : "Roo.data",
1121                                     "* prop" : "dataSource",
1122                                     "items" : [
1123                                         {
1124                                             "$ url" : "baseURL + '/Roo/coitem.php'",
1125                                             "xtype" : "HttpProxy",
1126                                             "method" : "GET",
1127                                             "$ xns" : "Roo.data",
1128                                             "* prop" : "proxy"
1129                                         },
1130                                         {
1131                                             "id" : "coitem_id",
1132                                             "root" : "data",
1133                                             "xtype" : "JsonReader",
1134                                             "$ fields" : "[\n    {\n        'name': 'coitem_linenumber',\n        'type': 'int'\n    },\n    {\n        'name': 'coitem_itemsite_id',\n        'type': 'int'\n    },\n    {\n        'name': 'coitem_qtyord'\n    },\n    {\n        'name': 'coitem_unitcost'\n    },\n    {\n        'name': 'coitem_price'\n    },\n    {\n        'name': 'coitem_custprice'\n    },\n    {\n        'name': 'coitem_qtyreturned'\n    },\n    {\n        'name': 'coitem_prcost'\n    },\n    {\n        'name': 'coitem_price_uom_id',\n        'type': 'int'\n    },\n    {\n        'name': 'coitem_qtyreserved'\n    }\n]",
1135                                             "$ xns" : "Roo.data",
1136                                             "* prop" : "reader",
1137                                             "# builderCfg" : "{\"cols\":[{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"},{\"table\":\"coitem\",\"column\":\"coitem_itemsite_id\",\"columnshort\":\"coitem_itemsite_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"itemsite_id\",\"deps\":[{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_item_id\",\"columnshort\":\"itemsite_item_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_warehous_id\",\"columnshort\":\"itemsite_warehous_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_qtyonhand\",\"columnshort\":\"itemsite_qtyonhand\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_reorderlevel\",\"columnshort\":\"itemsite_reorderlevel\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordertoqty\",\"columnshort\":\"itemsite_ordertoqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_cyclecountfreq\",\"columnshort\":\"itemsite_cyclecountfreq\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_datelastcount\",\"columnshort\":\"itemsite_datelastcount\",\"ctype\":\"date\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_datelastused\",\"columnshort\":\"itemsite_datelastused\",\"ctype\":\"date\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_loccntrl\",\"columnshort\":\"itemsite_loccntrl\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_safetystock\",\"columnshort\":\"itemsite_safetystock\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_minordqty\",\"columnshort\":\"itemsite_minordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_multordqty\",\"columnshort\":\"itemsite_multordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_leadtime\",\"columnshort\":\"itemsite_leadtime\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_abcclass\",\"columnshort\":\"itemsite_abcclass\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_issuemethod\",\"columnshort\":\"itemsite_issuemethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_controlmethod\",\"columnshort\":\"itemsite_controlmethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_active\",\"columnshort\":\"itemsite_active\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_plancode_id\",\"columnshort\":\"itemsite_plancode_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_costcat_id\",\"columnshort\":\"itemsite_costcat_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_eventfence\",\"columnshort\":\"itemsite_eventfence\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_sold\",\"columnshort\":\"itemsite_sold\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_stocked\",\"columnshort\":\"itemsite_stocked\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_freeze\",\"columnshort\":\"itemsite_freeze\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location_id\",\"columnshort\":\"itemsite_location_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_useparams\",\"columnshort\":\"itemsite_useparams\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_useparamsmanual\",\"columnshort\":\"itemsite_useparamsmanual\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_soldranking\",\"columnshort\":\"itemsite_soldranking\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createpr\",\"columnshort\":\"itemsite_createpr\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location\",\"columnshort\":\"itemsite_location\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location_comments\",\"columnshort\":\"itemsite_location_comments\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_notes\",\"columnshort\":\"itemsite_notes\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_perishable\",\"columnshort\":\"itemsite_perishable\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_nnqoh\",\"columnshort\":\"itemsite_nnqoh\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_autoabcclass\",\"columnshort\":\"itemsite_autoabcclass\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordergroup\",\"columnshort\":\"itemsite_ordergroup\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_disallowblankwip\",\"columnshort\":\"itemsite_disallowblankwip\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_maxordqty\",\"columnshort\":\"itemsite_maxordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_mps_timefence\",\"columnshort\":\"itemsite_mps_timefence\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createwo\",\"columnshort\":\"itemsite_createwo\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_warrpurc\",\"columnshort\":\"itemsite_warrpurc\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_autoreg\",\"columnshort\":\"itemsite_autoreg\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_costmethod\",\"columnshort\":\"itemsite_costmethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_value\",\"columnshort\":\"itemsite_value\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordergroup_first\",\"columnshort\":\"itemsite_ordergroup_first\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_supply_itemsite_id\",\"columnshort\":\"itemsite_supply_itemsite_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_planning_type\",\"columnshort\":\"itemsite_planning_type\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_wosupply\",\"columnshort\":\"itemsite_wosupply\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_posupply\",\"columnshort\":\"itemsite_posupply\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_lsseq_id\",\"columnshort\":\"itemsite_lsseq_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_cosdefault\",\"columnshort\":\"itemsite_cosdefault\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createsopr\",\"columnshort\":\"itemsite_createsopr\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createsopo\",\"columnshort\":\"itemsite_createsopo\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_dropship\",\"columnshort\":\"itemsite_dropship\",\"ctype\":\"bool\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"coitem\",\"column\":\"coitem_qtyord\",\"columnshort\":\"coitem_qtyord\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Qty\"},{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"},{\"table\":\"coitem\",\"column\":\"coitem_price\",\"columnshort\":\"coitem_price\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Price\"},{\"table\":\"coitem\",\"column\":\"coitem_custprice\",\"columnshort\":\"coitem_custprice\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Cust Price\"},{\"table\":\"coitem\",\"column\":\"coitem_qtyreturned\",\"columnshort\":\"coitem_qtyreturned\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#Returned\"},{\"table\":\"coitem\",\"column\":\"coitem_prcost\",\"columnshort\":\"coitem_prcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"prcost?\"},{\"table\":\"coitem\",\"column\":\"coitem_price_uom_id\",\"columnshort\":\"coitem_price_uom_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"uom_id\",\"deps\":[{\"table\":\"uom\",\"column\":\"coitem_price_uom_id_uom_name\",\"columnshort\":\"uom_name\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"uom\",\"column\":\"coitem_price_uom_id_uom_descrip\",\"columnshort\":\"uom_descrip\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"uom\",\"column\":\"coitem_price_uom_id_uom_item_weight\",\"columnshort\":\"uom_item_weight\",\"ctype\":\"bool\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"Unit of\"},{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}],\"cols_ex\":[\"coitem_price_uom_id_uom_descrip\"],\"table\":\"coitem\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
1138                                             "totalProperty" : "total"
1139                                         }
1140                                     ]
1141                                 },
1142                                 {
1143                                     "xtype" : "Toolbar",
1144                                     "$ xns" : "Roo",
1145                                     "* prop" : "toolbar",
1146                                     "items" : [
1147                                         {
1148                                             "listeners" : {
1149                                                 "|click" : "function()\n{\n   \n    Roo.log(\"add presed\");\n     \n    // work out last \n    var grid = _this.grid;\n    var err = false;\n    grid.ds.each(function(r) {\n        if (r.data.coitem_qtyord < 1) { \n            Roo.MessageBox.alert(\"Error\", \"you must fill in a quantity for \" + r.data.item_number);\n            err = true;\n            return true;\n        }\n        \n    });\n    if (err) {\n        return;\n    }\n    \n\n//    var last = 0;\n    var last = _this.form.findField('cohead_max_linenumber').getValue();   \n    last++; \n    if(last == 99999){\n        last++;\n    }\n    \n\n    _this.form.findField('cohead_max_linenumber').setValue(last);    \n    \n    // this should be getting the previous row..??\n     var ct  =    _this.grid.ds.getCount();\n     var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;\n     \n     function lastor(k,d,kk) {\n        var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();\n        return lastrow ? lastrow.data[kk] : def;\n     }\n    \n    // uses form defaults or last row value.\n    var nr = _this.grid.ds.reader.newRow({\n        coitem_linenumber : last,\n        item_number : '',\n        item_descrip1 : '',\n        coitem_qtyord : 0,\n        coitem_cohead_id : _this.form.findField('cohead_id').getValue(),\n        coitem_qtyshipped : 0,\n        coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),\n        coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),\n        coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),\n        coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name'),\n        coitem_unitcost_in_order_cur  : 0,\n        coitem_taxtype_id : _this.data.default_taxtype_id,\n        coitem_taxtype_id_taxtype_name : 'Taxable',\n        coitem_status : '',\n        avail_qty : 0\n                \n    });\n    grid.stopEditing();\n    grid.ds.insert(grid.ds.getCount(), nr); \n    grid.startEditing(grid.ds.getCount()-1, 1); // type..\n    nr.updatePending = 0;\n    nr.isUpdating = 0;\n    nr.isInserting =0;\n    \n}\n",
1150                                                 "render" : "function (_self)\n{\n    _this.addItemBtn = _self;\n}"
1151                                             },
1152                                             "text" : "Add",
1153                                             "xtype" : "Button",
1154                                             "cls" : "x-btn-text-icon",
1155                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
1156                                             "$ xns" : "Roo.Toolbar"
1157                                         },
1158                                         {
1159                                             "listeners" : {
1160                                                 "click" : "function (_self, e)\n{\n    var last = _this.form.findField('cohead_max_linenumber').getValue();    \r\n    last++;\r\n    _this.form.findField('cohead_max_linenumber').setValue(last); \n\n    var ct  =    _this.grid.ds.getCount();\r\n    var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;\r\n         \r\n    function lastor(k,d,kk) {\r\n       var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();\r\n       return lastrow ? lastrow.data[kk] : def;\r\n    }\n    \n    var cohead_cust_id = _this.form.findField('cohead_cust_id').getValue();\n    var cohead_id = _this.form.findField('cohead_id').getValue();\n    \n    Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cohead_cust_id, cohead_id : cohead_id} , function(res) {\n\n        _this.grid.stopEditing();\n\n        if (_this.grid.ds.getCount() > 0) {\n            var lr = _this.grid.ds.getAt(_this.grid.ds.getCount()-1);\n            if (!lr.data.coitem_itemsite_id) {\n                lr.set('coitem_itemsite_id', res.item_itemsite_id_itemsite_id);\n                lr.set('item_number',  res.item_number);\n                lr.set('item_descrip1', res.item_descrip1);                                \n                lr.set('coitem_listprice', res.item_price);                \n                lr.set('coitem_price', res.item_price);                                \n                lr.set('coitem_custprice', res.item_price);                \n                return;\n            }\n        }\n        \n        \n        \n        var nr = _this.grid.ds.reader.newRow({\n            coitem_linenumber : last,\n            coitem_itemsite_id : res.item_itemsite_id_itemsite_id,\n            item_number : res.item_number,\n            item_descrip1 : res.item_descrip1,\n            coitem_qtyord : 0,\n            coitem_cohead_id : _this.form.findField('cohead_id').getValue(),\n            coitem_qtyshipped : 0,\n            coitem_listprice : res.item_price,\n            coitem_price : res.item_price,\n            coitem_custprice : res.item_price,\n            avail_qty : 0,\n            coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),\n            coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),\n            coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),\n            coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name')\n                    \n        });\n        _this.grid.ds.insert(_this.grid.ds.getCount(), nr); \n\n   }); \n}"
1161                                             },
1162                                             "text" : "Find Products",
1163                                             "xtype" : "Button",
1164                                             "cls" : "x-btn-text-icon",
1165                                             "$ icon" : "rootURL + '/Pman/templates/images/search.gif'",
1166                                             "$ xns" : "Roo.Toolbar"
1167                                         },
1168                                         {
1169                                             "listeners" : {
1170                                                 "|click" : "function()\n{\n    // work out last \n    new Pman.Request({\n        url : baseURL + '/Roo/coitem',\n        mask : 'Loading Data',\n        method: 'GET',\n        params : {\n\n            _hk_xfer :_this.form.findField('cohead_id').getValue()\n        },\n        success : function() {\n            _this.grid.ds.load({});\n        }\n    \n    });\n}\n",
1171                                                 "render" : "function (_self)\n{\n    _this.xferAll  = _self;\n}"
1172                                             },
1173                                             "text" : "Xfer all stock to HK",
1174                                             "hidden" : true,
1175                                             "xtype" : "Button",
1176                                             "cls" : "x-btn-text-icon",
1177                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
1178                                             "$ xns" : "Roo.Toolbar"
1179                                         },
1180                                         {
1181                                             "listeners" : {
1182                                                 "click" : "function (_self, e)\n{\n   var c    = _this.grid.getSelectionModel().getSelectedCell();\n   if (!c) {\n        Roo.MessageBox.alert(\"Error\", \"Select item to show history (you can also double click on the #avail number) \");\n        return;\n   }\n   \n    var rec = _this.grid.ds.getAt(c[0]);\n\n  Pman.Dialog.XtupleInvHistory.show({\n        itemsite_item_id_item_number   : rec.data.item_number,\n       // itemsite_item_id_item_descript1 : rec.data.item_descrip1,\n        location_name : rec.data.coitem_location_src_location_name,\n        location_descrip : rec.data.coitem_location_src_location_descrip,\n        \n        \n        invhist_transdate : _this.form.findField('cohead_targetdate').getValue() \n    }); \n    \n   \n}"
1183                                             },
1184                                             "text" : "Show Inventory History",
1185                                             "xtype" : "Button",
1186                                             "$ xns" : "Roo.Toolbar"
1187                                         },
1188                                         {
1189                                             "xtype" : "Separator",
1190                                             "$ xns" : "Roo.Toolbar"
1191                                         },
1192                                         {
1193                                             "text" : "Apply % Discount of : ",
1194                                             "xtype" : "TextItem",
1195                                             "$ xns" : "Roo.Toolbar"
1196                                         },
1197                                         {
1198                                             "listeners" : {
1199                                                 "render" : "function (_self)\n{\n    _this._applyDiscount = _self;\n}"
1200                                             },
1201                                             "xtype" : "TextField",
1202                                             "$ xns" : "Roo.form",
1203                                             "width" : 40
1204                                         },
1205                                         {
1206                                             "listeners" : {
1207                                                 "click" : "function (_self, e)\n{\n    var val =  parseFloat(_this._applyDiscount.getValue());\n    \n    var factor = (100.0 - val)/100.0;\n    \n    _this.grid.ds.each(function(rec) {\n        if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {\n            return;\n        }\n    \n        rec.set('coitem_price', rec.data.coitem_custprice * factor);\n        rec.set('coitem_linedisc', val);\n        rec.set('coitem_subtotal', rec.data.coitem_price  & rec.data.ordqty);\n        rec.commit();\n    \n    });\n    \n    \n}"
1208                                             },
1209                                             "text" : "Apply To All",
1210                                             "xtype" : "Button",
1211                                             "$ xns" : "Roo.Toolbar"
1212                                         },
1213                                         {
1214                                             "listeners" : {
1215                                                 "click" : "function (_self, e)\n{\n\n    if (!(1* _this.form.findField('cohead_id').getValue())) {\n        Roo.MessageBox.alert(\"Error\", \"save the order first\");\n    }\n    \n\n   Pman.Dialog.Image.show(\n       {\n            timeout : 60000,\n            _url : baseURL+'/Xtuple/Import/SalesOrder',\n            onid : _this.form.findField('cohead_id').getValue()\n        \n       },\n       function (data) {\n\n            Roo.MessageBox.alert(\"Notice\", \"Uploaded\");\n            _this.grid.footer.onClick('first');\n\n       }\n   );\n}"
1216                                             },
1217                                             "text" : "Import",
1218                                             "xtype" : "Button",
1219                                             "$ xns" : "Roo.Toolbar"
1220                                         },
1221                                         {
1222                                             "xtype" : "Fill",
1223                                             "$ xns" : "Roo.Toolbar"
1224                                         },
1225                                         {
1226                                             "listeners" : {
1227                                                 "|click" : "function()\n{\n     _this.grid.stopEditing();\n    // check that no shipments or invoices are done..\n    var rc = _this.grid.getSelectionModel().getSelectedCell();\n    \n    var rec = _this.grid.ds.getAt(rc[0]);\n    \n    if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {\n        Roo.MessageBox.alert(\"Error\", \"That item has been shipped or invoices - void the shipments/invoices first\");\n        return;\n    }\n   if (rec.data.coitem_subnumber*1  > 0) {\n        Roo.MessageBox.alert(\"Error\", \"Delete the kit item that that belongs to.\");\n        return;\n    }\n    if (!rec.data.coitem_id) {\n        _this.grid.ds.remove(rec);\n        return;\n    }\n    function remove()\n    {\n    \n        new  Pman.Request({\n            url : baseURL + '/Roo/coitem',\n            method : 'POST',\n            params : {\n                _delete : rec.data.coitem_id\n            \n            },\n            success : function() {\n                if (rec.data.item_type == 'K') {\n                    _this.grid.ds.load({});\n                    return;\n                }\n                _this.grid.ds.remove(rec);\n            }\n        \n        });\n    }\n    if (rec.data_qtyord * 1 < 1) {\n        remove();\n    }\n    \n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want to delete that line?\", function(r)\n    {\n        if (r != 'yes') {\n            return;\n        }\n        remove();\n    \n    });\n\n    \n    \n}\n        "
1228                                             },
1229                                             "text" : "Delete",
1230                                             "xtype" : "Button",
1231                                             "cls" : "x-btn-text-icon",
1232                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
1233                                             "$ xns" : "Roo.Toolbar"
1234                                         },
1235                                         {
1236                                             "listeners" : {
1237                                                 "|click" : "function()\n{\n     _this.grid.stopEditing();\n    // check that no shipments or invoices are done..\n    var ids = [];\n    _this.grid.ds.each(function(rec) {\n    \n\n    \n        if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {\n            //Roo.MessageBox.alert(\"Error\", \"That item has been shipped or invoices - void the shipments/invoices first\");\n            return;\n        }\n        if (rec.data.item_type == 'K') {\n            return;\n        }\n\n       if (rec.data.coitem_subnumber*1  > 0) {\n            //Roo.MessageBox.alert(\"Error\", \"Delete the kit item that that belongs to.\");\n            return;\n        }\n        if (!rec.data.coitem_id) {\n            _this.grid.ds.remove(rec);\n            return;\n        }\n        ids.push(rec.data.coitem_id);\n    });\n    function remove()\n    {\n    \n        new  Pman.Request({\n            url : baseURL + '/Roo/coitem',\n            method : 'POST',\n            params : {\n                _delete : ids.join(',')\n            \n            },\n            success : function() {\n\n                _this.grid.footer.onClick('first');\n            }\n        \n        });\n    }\n//    if (rec.data_qtyord * 1 < 1) {\n//        remove();\n//    }\n    \n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want to delete everything?\", function(r)\n    {\n        if (r != 'yes') {\n            return;\n        }\n        remove();\n    \n    });\n\n    \n    \n}\n        "
1238                                             },
1239                                             "text" : "Delete All",
1240                                             "xtype" : "Button",
1241                                             "cls" : "x-btn-text-icon",
1242                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
1243                                             "$ xns" : "Roo.Toolbar"
1244                                         }
1245                                     ]
1246                                 },
1247                                 {
1248                                     "xtype" : "ColumnModel",
1249                                     "header" : "Item#",
1250                                     "width" : 40,
1251                                     "$ renderer" : "function(v,x,r) {\n\n    if (r.data.coitem_subnumber * 1 > 0) {\n         return String.format('{0}.{1}', v,r.data.coitem_subnumber);\n     }\n     return String.format('{0}', v);\n  }",
1252                                     "$ xns" : "Roo.grid",
1253                                     "* prop" : "colModel[]",
1254                                     "dataIndex" : "coitem_linenumber",
1255                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}"
1256                                 },
1257                                 {
1258                                     "xtype" : "ColumnModel",
1259                                     "header" : "Item Code",
1260                                     "width" : 75,
1261                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
1262                                     "$ xns" : "Roo.grid",
1263                                     "* prop" : "colModel[]",
1264                                     "dataIndex" : "item_number",
1265                                     "items" : [
1266                                         {
1267                                             "xtype" : "GridEditor",
1268                                             "$ xns" : "Roo.grid",
1269                                             "* prop" : "editor",
1270                                             "items" : [
1271                                                 {
1272                                                     "listeners" : {
1273                                                         "beforeselect" : "function (combo, record, index)\n{\n  // set _this.data values ..\n  var ar = _this.grid.activeEditor.record;\n//  Roo.log('beforeselect');\n  \n  \n  (function() { \n     //  Roo.log('beforeselect-cb');\n      ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);\n      ar.set('coitem_listprice', record.data.item_listprice);\n      ar.set('coitem_price', record.data.item_price);\n      ar.set('coitem_custprice', record.data.item_price);\n      ar.set('coitem_itemsite_id', record.data.itemsite_id);\n      ar.set('item_number', record.data.itemsite_item_id_item_number);\n     ar.set('item_type', record.data.itemsite_item_id_item_type);\n      ar.set('avail_qty', 0);\n      ar.commit();\n  }).defer(100);\n  \n}"
1274                                                     },
1275                                                     "listWidth" : 400,
1276                                                     "triggerAction" : "all",
1277                                                     "forceSelection" : true,
1278                                                     "selectOnFocus" : true,
1279                                                     "pageSize" : 20,
1280                                                     "displayField" : "itemsite_item_id_item_number",
1281                                                     "emptyText" : "Select item",
1282                                                     "hiddenName" : "itemsite_item_id_item_number",
1283                                                     "minChars" : 2,
1284                                                     "valueField" : "item_number",
1285                                                     "xtype" : "ComboBox",
1286                                                     "allowBlank" : false,
1287                                                     "typeAhead" : false,
1288                                                     "editable" : true,
1289                                                     "$ xns" : "Roo.form",
1290                                                     "* prop" : "field",
1291                                                     "name" : "item_number",
1292                                                     "qtip" : "Select item",
1293                                                     "queryParam" : "query[number]",
1294                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{itemsite_item_id_item_number}</b> ${item_price:toFixed(2)}- {itemsite_item_id_item_descrip1} </div>",
1295                                                     "loadingText" : "Searching...",
1296                                                     "items" : [
1297                                                         {
1298                                                             "listeners" : {
1299                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    o.params.customer_id = _this.form.findField('cohead_cust_id').getValue();\n    o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue();\n    //o.params.shipto_cust_id = _this.data.cohead_cust_id;\n    // set more here\n}\n"
1300                                                             },
1301                                                             "xtype" : "Store",
1302                                                             "remoteSort" : true,
1303                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'item_number' }",
1304                                                             "$ xns" : "Roo.data",
1305                                                             "* prop" : "store",
1306                                                             "items" : [
1307                                                                 {
1308                                                                     "$ url" : "baseURL + '/Roo/itemsite.php'",
1309                                                                     "xtype" : "HttpProxy",
1310                                                                     "method" : "GET",
1311                                                                     "$ xns" : "Roo.data",
1312                                                                     "* prop" : "proxy"
1313                                                                 },
1314                                                                 {
1315                                                                     "id" : "shipto_id",
1316                                                                     "root" : "data",
1317                                                                     "xtype" : "JsonReader",
1318                                                                     "$ fields" : "[{\"name\":\"item_id\",\"type\":\"int\"},\"item_number\"]",
1319                                                                     "$ xns" : "Roo.data",
1320                                                                     "* prop" : "reader",
1321                                                                     "totalProperty" : "total"
1322                                                                 }
1323                                                             ]
1324                                                         }
1325                                                     ]
1326                                                 }
1327                                             ]
1328                                         }
1329                                     ]
1330                                 },
1331                                 {
1332                                     "xtype" : "ColumnModel",
1333                                     "header" : "From",
1334                                     "width" : 75,
1335                                     "$ renderer" : "function(v,x,r) { \n    return String.format('{0}', r.data.coitem_location_src_location_name); \n}",
1336                                     "$ xns" : "Roo.grid",
1337                                     "* prop" : "colModel[]",
1338                                     "dataIndex" : "coitem_location_src",
1339                                     "items" : [
1340                                         {
1341                                             "xtype" : "GridEditor",
1342                                             "$ xns" : "Roo.grid",
1343                                             "* prop" : "editor",
1344                                             "items" : [
1345                                                 {
1346                                                     "listeners" : {
1347                                                         "beforeselect" : "function (combo, record, index)\n{\n  // set _this.data values ..\n  var ar = _this.grid.activeEditor.record;\n  \n  \n  \n  //Roo.log('beforeselect');\n \n /*\n  (function() { \n     //  Roo.log('beforeselect-cb');\n      ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);\n      ar.set('coitem_price', record.data.item_listprice);\n      ar.set('coitem_custprice', record.data.item_price);\n       ar.set('coitem_itemsite_id', record.data.itemsite_id);\n      ar.set('item_number', record.data.itemsite_item_id_item_number);\n\n      ar.commit();\n  }).defer(100);\n  */\n}"
1348                                                     },
1349                                                     "alwaysQuery" : true,
1350                                                     "listWidth" : 400,
1351                                                     "triggerAction" : "all",
1352                                                     "forceSelection" : true,
1353                                                     "selectOnFocus" : true,
1354                                                     "pageSize" : 20,
1355                                                     "displayField" : "location_name",
1356                                                     "emptyText" : "Select location",
1357                                                     "hiddenName" : "coitem_location_src",
1358                                                     "minChars" : 2,
1359                                                     "valueField" : "location_id",
1360                                                     "xtype" : "ComboBox",
1361                                                     "allowBlank" : false,
1362                                                     "typeAhead" : false,
1363                                                     "editable" : true,
1364                                                     "$ xns" : "Roo.form",
1365                                                     "* prop" : "field",
1366                                                     "name" : "coitem_location_src_location_name",
1367                                                     "qtip" : "Select item",
1368                                                     "queryParam" : "query[location_name]",
1369                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>",
1370                                                     "loadingText" : "Searching...",
1371                                                     "items" : [
1372                                                         {
1373                                                             "listeners" : {
1374                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    \n    var row = _this.grid.activeEditor.record;\n    \n    o.params['query[item_itemsite_id]'] = row.data.coitem_itemsite_id;\n    // need to know the date to calc the est. delivery time..\n    //o.params['query[avail_when]'] = _this.form.findField('cohead_targetdate').getValue().format('Y-m-d');\n    //o.params.location_netable = 1;\n    o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue(); \n    \n     o.params.location_restrict = 0;\n    o.params._notinternalcompany = 1;\n    \n  //  _this.grid;\n\n//    o.params.itemsite_id = _this.form.findField('cohead_cust_id').getValue();\n    //o.params.shipto_cust_id = _this.data.cohead_cust_id;\n    // set more here\n}\n"
1375                                                             },
1376                                                             "xtype" : "Store",
1377                                                             "remoteSort" : true,
1378                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
1379                                                             "$ xns" : "Roo.data",
1380                                                             "* prop" : "store",
1381                                                             "items" : [
1382                                                                 {
1383                                                                     "$ url" : "baseURL + '/Roo/location.php'",
1384                                                                     "xtype" : "HttpProxy",
1385                                                                     "method" : "GET",
1386                                                                     "$ xns" : "Roo.data",
1387                                                                     "* prop" : "proxy"
1388                                                                 },
1389                                                                 {
1390                                                                     "id" : "shipto_id",
1391                                                                     "root" : "data",
1392                                                                     "xtype" : "JsonReader",
1393                                                                     "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
1394                                                                     "$ xns" : "Roo.data",
1395                                                                     "* prop" : "reader",
1396                                                                     "totalProperty" : "total"
1397                                                                 }
1398                                                             ]
1399                                                         }
1400                                                     ]
1401                                                 }
1402                                             ]
1403                                         }
1404                                     ]
1405                                 },
1406                                 {
1407                                     "xtype" : "ColumnModel",
1408                                     "header" : "To",
1409                                     "width" : 75,
1410                                     "$ renderer" : "function(v,x,r) { \n    return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); \n}",
1411                                     "$ xns" : "Roo.grid",
1412                                     "* prop" : "colModel[]",
1413                                     "dataIndex" : "coitem_shipto_id",
1414                                     "items" : [
1415                                         {
1416                                             "xtype" : "GridEditor",
1417                                             "$ xns" : "Roo.grid",
1418                                             "* prop" : "editor",
1419                                             "items" : [
1420                                                 {
1421                                                     "listeners" : {
1422                                                         "add" : "function (combo)\n{\n\n   Pman.Dialog.XtupleCustomer.show({ cust_id : _this.form.findField('cohead_cust_id').getValue() }, function(data) {\n        // refresh the data in the pulldown..\n    }); \n}",
1423                                                         "beforeselect" : "function (combo, record, index)\n{\n\n    var v = [];\n    for(var i = 1; i <4; i++) {\n        _this.data['cohead_shiptoaddress'+  i] = record.data['cntct_addr_id_addr_line'+i];\n    }\n    _this.form.findField('shipto_address').update();\n    \n \n}"
1424                                                     },
1425                                                     "alwaysQuery" : true,
1426                                                     "listWidth" : 400,
1427                                                     "triggerAction" : "all",
1428                                                     "forceSelection" : true,
1429                                                     "selectOnFocus" : true,
1430                                                     "pageSize" : 20,
1431                                                     "displayField" : "shipto_name",
1432                                                     "emptyText" : "Select cntct",
1433                                                     "hiddenName" : "cohead_shipto_id",
1434                                                     "minChars" : 2,
1435                                                     "valueField" : "shipto_id",
1436                                                     "xtype" : "ComboBox",
1437                                                     "allowBlank" : false,
1438                                                     "typeAhead" : false,
1439                                                     "editable" : false,
1440                                                     "width" : 300,
1441                                                     "$ xns" : "Roo.form",
1442                                                     "* prop" : "field",
1443                                                     "name" : "coitem_shipto_id_shipto_name",
1444                                                     "qtip" : "Select shipto",
1445                                                     "queryParam" : "query[shipto_name]",
1446                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>",
1447                                                     "loadingText" : "Searching...",
1448                                                     "items" : [
1449                                                         {
1450                                                             "listeners" : {
1451                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    o.params.shipto_cust_id = _this.data.cohead_cust_id; \n    //o.params['query[with_shipinfo]'] = 1;\n    // set more here\n}\n"
1452                                                             },
1453                                                             "xtype" : "Store",
1454                                                             "remoteSort" : true,
1455                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'shipto_name' }",
1456                                                             "$ xns" : "Roo.data",
1457                                                             "* prop" : "store",
1458                                                             "items" : [
1459                                                                 {
1460                                                                     "$ url" : "baseURL + '/Roo/shiptoinfo.php'",
1461                                                                     "xtype" : "HttpProxy",
1462                                                                     "method" : "GET",
1463                                                                     "$ xns" : "Roo.data",
1464                                                                     "* prop" : "proxy"
1465                                                                 },
1466                                                                 {
1467                                                                     "id" : "shipto_id",
1468                                                                     "root" : "data",
1469                                                                     "xtype" : "JsonReader",
1470                                                                     "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
1471                                                                     "$ xns" : "Roo.data",
1472                                                                     "* prop" : "reader",
1473                                                                     "totalProperty" : "total"
1474                                                                 }
1475                                                             ]
1476                                                         }
1477                                                     ]
1478                                                 }
1479                                             ]
1480                                         }
1481                                     ]
1482                                 },
1483                                 {
1484                                     "xtype" : "ColumnModel",
1485                                     "header" : "Item Description",
1486                                     "width" : 150,
1487                                     "$ renderer" : "function(v,x,r) { \n\n    if (r.data.coitem_memo && r.data.coitem_memo.length) {\n        return String.format('{0}', r.data.coitem_memo);\n        if (r.data.coitem_memo != v) {\n            r.set('item_descrip1', r.data.coitem_memo);\n        }\n        \n    }\n    if (v && v.length > 49) {\n        return String.format('<span style=\"color:orange\" qtip=\"line may be too long to print\">{0}</span>', v);\n    }\n    \n    return String.format('{0}', v); \n    \n}",
1488                                     "$ xns" : "Roo.grid",
1489                                     "* prop" : "colModel[]",
1490                                     "dataIndex" : "item_descrip1",
1491                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_itemsite_id\",\"columnshort\":\"coitem_itemsite_id\",\"ctype\":\"int4\",\"desc\":\"\",\"maps_to\":\"itemsite_id\",\"deps\":[{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_item_id\",\"columnshort\":\"itemsite_item_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_warehous_id\",\"columnshort\":\"itemsite_warehous_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_qtyonhand\",\"columnshort\":\"itemsite_qtyonhand\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_reorderlevel\",\"columnshort\":\"itemsite_reorderlevel\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordertoqty\",\"columnshort\":\"itemsite_ordertoqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_cyclecountfreq\",\"columnshort\":\"itemsite_cyclecountfreq\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_datelastcount\",\"columnshort\":\"itemsite_datelastcount\",\"ctype\":\"date\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_datelastused\",\"columnshort\":\"itemsite_datelastused\",\"ctype\":\"date\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_loccntrl\",\"columnshort\":\"itemsite_loccntrl\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_safetystock\",\"columnshort\":\"itemsite_safetystock\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_minordqty\",\"columnshort\":\"itemsite_minordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_multordqty\",\"columnshort\":\"itemsite_multordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_leadtime\",\"columnshort\":\"itemsite_leadtime\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_abcclass\",\"columnshort\":\"itemsite_abcclass\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_issuemethod\",\"columnshort\":\"itemsite_issuemethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_controlmethod\",\"columnshort\":\"itemsite_controlmethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_active\",\"columnshort\":\"itemsite_active\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_plancode_id\",\"columnshort\":\"itemsite_plancode_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_costcat_id\",\"columnshort\":\"itemsite_costcat_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_eventfence\",\"columnshort\":\"itemsite_eventfence\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_sold\",\"columnshort\":\"itemsite_sold\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_stocked\",\"columnshort\":\"itemsite_stocked\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_freeze\",\"columnshort\":\"itemsite_freeze\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location_id\",\"columnshort\":\"itemsite_location_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_useparams\",\"columnshort\":\"itemsite_useparams\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_useparamsmanual\",\"columnshort\":\"itemsite_useparamsmanual\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_soldranking\",\"columnshort\":\"itemsite_soldranking\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createpr\",\"columnshort\":\"itemsite_createpr\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location\",\"columnshort\":\"itemsite_location\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_location_comments\",\"columnshort\":\"itemsite_location_comments\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_notes\",\"columnshort\":\"itemsite_notes\",\"ctype\":\"text\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_perishable\",\"columnshort\":\"itemsite_perishable\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_nnqoh\",\"columnshort\":\"itemsite_nnqoh\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_autoabcclass\",\"columnshort\":\"itemsite_autoabcclass\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordergroup\",\"columnshort\":\"itemsite_ordergroup\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_disallowblankwip\",\"columnshort\":\"itemsite_disallowblankwip\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_maxordqty\",\"columnshort\":\"itemsite_maxordqty\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_mps_timefence\",\"columnshort\":\"itemsite_mps_timefence\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createwo\",\"columnshort\":\"itemsite_createwo\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_warrpurc\",\"columnshort\":\"itemsite_warrpurc\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_autoreg\",\"columnshort\":\"itemsite_autoreg\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_costmethod\",\"columnshort\":\"itemsite_costmethod\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_value\",\"columnshort\":\"itemsite_value\",\"ctype\":\"numeric\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_ordergroup_first\",\"columnshort\":\"itemsite_ordergroup_first\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_supply_itemsite_id\",\"columnshort\":\"itemsite_supply_itemsite_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_planning_type\",\"columnshort\":\"itemsite_planning_type\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_wosupply\",\"columnshort\":\"itemsite_wosupply\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_posupply\",\"columnshort\":\"itemsite_posupply\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_lsseq_id\",\"columnshort\":\"itemsite_lsseq_id\",\"ctype\":\"int4\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_cosdefault\",\"columnshort\":\"itemsite_cosdefault\",\"ctype\":\"bpchar\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createsopr\",\"columnshort\":\"itemsite_createsopr\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_createsopo\",\"columnshort\":\"itemsite_createsopo\",\"ctype\":\"bool\",\"desc\":\"\"},{\"table\":\"itemsite\",\"column\":\"coitem_itemsite_id_itemsite_dropship\",\"columnshort\":\"itemsite_dropship\",\"ctype\":\"bool\",\"desc\":\"\"}],\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
1492                                     "items" : [
1493                                         {
1494                                             "xtype" : "GridEditor",
1495                                             "$ xns" : "Roo.grid",
1496                                             "* prop" : "editor",
1497                                             "items" : [
1498                                                 {
1499                                                     "xtype" : "TextField",
1500                                                     "allowBlank" : false,
1501                                                     "$ xns" : "Roo.form",
1502                                                     "* prop" : "field"
1503                                                 }
1504                                             ]
1505                                         }
1506                                     ]
1507                                 },
1508                                 {
1509                                     "align" : "right",
1510                                     "xtype" : "ColumnModel",
1511                                     "header" : "Status",
1512                                     "width" : 50,
1513                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
1514                                     "$ xns" : "Roo.grid",
1515                                     "* prop" : "colModel[]",
1516                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
1517                                     "dataIndex" : "coitem_status"
1518                                 },
1519                                 {
1520                                     "align" : "right",
1521                                     "xtype" : "ColumnModel",
1522                                     "header" : "Qty",
1523                                     "width" : 40,
1524                                     "$ renderer" : "function(v,x,r) { \n    var v = parseInt(v);\n    //var aq = parseInt(r.data.avail_qty);\n    //aq = isNaN(aq) ? 0 : aq;\n   \n    var rate = _this.form.findField('taxzone_rate').getValue();\n    r.data.coitem_subtotal =  v * r.data.coitem_price;\n    r.data.coitem_subtotal_tax = v * r.data.coitem_price * ( 1 + rate * 1);\n    return String.format('{0}', v); \n    \n}",
1525                                     "$ xns" : "Roo.grid",
1526                                     "* prop" : "colModel[]",
1527                                     "dataIndex" : "coitem_qtyord",
1528                                     "items" : [
1529                                         {
1530                                             "xtype" : "GridEditor",
1531                                             "$ xns" : "Roo.grid",
1532                                             "* prop" : "editor",
1533                                             "items" : [
1534                                                 {
1535                                                     "listeners" : {
1536                                                         "focus" : "function (_self)\n{\n    if (this.value == 0) {\n        this.el.dom.value = '';\n    }\n}"
1537                                                     },
1538                                                     "minValue" : 1,
1539                                                     "style" : "text-align:right",
1540                                                     "xtype" : "NumberField",
1541                                                     "allowDecimals" : false,
1542                                                     "decimalPrecision" : 0,
1543                                                     "$ xns" : "Roo.form",
1544                                                     "* prop" : "field"
1545                                                 }
1546                                             ]
1547                                         }
1548                                     ]
1549                                 },
1550                                 {
1551                                     "align" : "right",
1552                                     "xtype" : "ColumnModel",
1553                                     "header" : "Sell @",
1554                                     "width" : 70,
1555                                     "$ renderer" : "function(v,x,r) { \n\n    var rate = _this.form.findField('taxzone_rate').getValue();\n    r.data.coitem_subtotal = v * r.data.coitem_qtyord;\n    r.data.coitem_subtotal_tax = v * ( 1 + rate * 1 ) * r.data.coitem_qtyord;\n    r.data.coitem_price_tax = v * ( 1 + rate * 1 );\n    if (parseInt(v) < 1) {\n        return String.format('<b style=\"color:red;\">{0}</b>', Roo.util.Format.number(v,3)); \n    }\n    \n    \n    //r.set('coitem_subtotal', v * r.data.coitem_qtyord);\n    \n    return  String.format('{0}', Roo.util.Format.number(v,3)); \n}",
1556                                     "$ xns" : "Roo.grid",
1557                                     "* prop" : "colModel[]",
1558                                     "dataIndex" : "coitem_price",
1559                                     "items" : [
1560                                         {
1561                                             "xtype" : "GridEditor",
1562                                             "$ xns" : "Roo.grid",
1563                                             "* prop" : "editor",
1564                                             "items" : [
1565                                                 {
1566                                                     "listeners" : {
1567                                                         "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1568                                                     },
1569                                                     "minValue" : 0,
1570                                                     "style" : "text-align:right",
1571                                                     "xtype" : "NumberField",
1572                                                     "decimalPrecision" : 3,
1573                                                     "$ xns" : "Roo.form",
1574                                                     "* prop" : "field"
1575                                                 }
1576                                             ]
1577                                         }
1578                                     ]
1579                                 },
1580                                 {
1581                                     "align" : "right",
1582                                     "hidden" : true,
1583                                     "xtype" : "ColumnModel",
1584                                     "header" : "Sell @w/GST",
1585                                     "width" : 70,
1586                                     "$ renderer" : "function(v,x,r) { \n    \n    if (parseInt(v) < 1) {\n        return String.format('<b style=\"color:red;\">{0}</b>', Roo.util.Format.number(v,3)); \n    }\n    \n    return  String.format('{0}', Roo.util.Format.number(v,3)); \n}",
1587                                     "$ xns" : "Roo.grid",
1588                                     "* prop" : "colModel[]",
1589                                     "dataIndex" : "coitem_price_tax",
1590                                     "items" : [
1591                                         {
1592                                             "xtype" : "GridEditor",
1593                                             "$ xns" : "Roo.grid",
1594                                             "* prop" : "editor",
1595                                             "items" : [
1596                                                 {
1597                                                     "listeners" : {
1598                                                         "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1599                                                     },
1600                                                     "minValue" : 0,
1601                                                     "style" : "text-align:right",
1602                                                     "xtype" : "NumberField",
1603                                                     "decimalPrecision" : 3,
1604                                                     "$ xns" : "Roo.form",
1605                                                     "* prop" : "field"
1606                                                 }
1607                                             ]
1608                                         }
1609                                     ]
1610                                 },
1611                                 {
1612                                     "align" : "right",
1613                                     "xtype" : "ColumnModel",
1614                                     "header" : "Disc%",
1615                                     "width" : 50,
1616                                     "$ renderer" : "function(v,x,r) { \n\n    // coitem_custprice = coitem_price * ((100 - coitem_disc)/ 100) \n    \n    //                      12 * (( 100 - 0) / 100)\n    // coitem_custprice / coitem_price = ((100 - coitem_disc)/ 100) \n    // 100 - ((coitem_custprice / coitem_price) * 100)  = coitem_disc\n    //                             100 -  97 =        100 -3 \n\n   // r.data.coitem_linedisc = 100 - (\n    //           (parseFloat(r.data.coitem_custprice) /\n     //               parseFloat(r.data.coitem_price)\n       //        ) * 100.00);\n    var fl = parseFloat(r.data.coitem_linedisc);\n    if ( isNaN(fl) || fl == 0.0 || r.data.coitem_price > r.data.coitem_custprice)  {\n        return '';\n    }\n    return  String.format('<span style=\"color:green\">{0}%</span>', Roo.util.Format.number( r.data.coitem_linedisc,2)); \n}",
1617                                     "$ xns" : "Roo.grid",
1618                                     "* prop" : "colModel[]",
1619                                     "dataIndex" : "coitem_linedisc",
1620                                     "items" : [
1621                                         {
1622                                             "xtype" : "GridEditor",
1623                                             "$ xns" : "Roo.grid",
1624                                             "* prop" : "editor",
1625                                             "items" : [
1626                                                 {
1627                                                     "listeners" : {
1628                                                         "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1629                                                     },
1630                                                     "minValue" : 0,
1631                                                     "style" : "text-align:right",
1632                                                     "xtype" : "NumberField",
1633                                                     "decimalPrecision" : 2,
1634                                                     "$ xns" : "Roo.form",
1635                                                     "maxValue" : 100,
1636                                                     "* prop" : "field"
1637                                                 }
1638                                             ]
1639                                         }
1640                                     ]
1641                                 },
1642                                 {
1643                                     "align" : "right",
1644                                     "xtype" : "ColumnModel",
1645                                     "header" : "List Price",
1646                                     "width" : 70,
1647                                     "$ renderer" : "function(v,x,r) { \n    \n    var rate = _this.form.findField('taxzone_rate').getValue();\n    r.data.coitem_custprice_tax = v * ( 1 + rate * 1 );\n    \n    var tip = 'No WRP available';\n    if ((r.data.coitem_wrpprice * 1) > 0) {\n        tip = \"WRP : \" + Roo.util.Format.number(r.data.coitem_wrpprice,3);\n    }\n    // less than zero, show as red..\n    if (parseFloat(v) < 1) {\n        return String.format('<b qtip=\"{1}\" style=\"color:red;\">{0}</b>', \n            Roo.util.Format.number(v,3), tip); \n    }\n    if (r.data.customer_price_each != v) {\n          return String.format('<b qtip=\"{1}\" style=\"color:pink;\">{0}</b>', \n            Roo.util.Format.number(v,3), \n            \"List Price = \" +  Roo.util.Format.number(r.data.customer_price_each,3)\n        ); \n    }\n    \n    \n    \n    //r.data.coitem_subtotal = v * r.data.coitem_qtyord;\n    \n    //r.set('coitem_subtotal', v * r.data.coitem_qtyord);\n    \n    return  String.format('<span qtip=\"{1}\">{0}</span>', Roo.util.Format.number(v,3), tip); \n}",
1648                                     "$ xns" : "Roo.grid",
1649                                     "* prop" : "colModel[]",
1650                                     "dataIndex" : "coitem_custprice",
1651                                     "items" : [
1652                                         {
1653                                             "xtype" : "GridEditor",
1654                                             "$ xns" : "Roo.grid",
1655                                             "* prop" : "editor",
1656                                             "items" : [
1657                                                 {
1658                                                     "listeners" : {
1659                                                         "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1660                                                     },
1661                                                     "minValue" : 0,
1662                                                     "style" : "text-align:right",
1663                                                     "xtype" : "NumberField",
1664                                                     "decimalPrecision" : 3,
1665                                                     "$ xns" : "Roo.form",
1666                                                     "* prop" : "field"
1667                                                 }
1668                                             ]
1669                                         }
1670                                     ]
1671                                 },
1672                                 {
1673                                     "align" : "right",
1674                                     "hidden" : true,
1675                                     "xtype" : "ColumnModel",
1676                                     "header" : "List Price w/GST",
1677                                     "width" : 70,
1678                                     "$ renderer" : "function(v,x,r) { \n    var rate = _this.form.findField('taxzone_rate').getValue();\n    var tip = 'No WRP available';\n    if ((r.data.coitem_wrpprice * 1) > 0) {\n        tip = \"WRP : \" + Roo.util.Format.number(r.data.coitem_wrpprice,3);\n    }\n    \n    if (parseFloat(v) < 1) {\n        return String.format('<b qtip=\"{1}\" style=\"color:red;\">{0}</b>', \n            Roo.util.Format.number(v,3), tip); \n    }\n    if (r.data.customer_price_each != v) {\n          return String.format('<b qtip=\"{1}\" style=\"color:pink;\">{0}</b>', \n            Roo.util.Format.number(v,3), \n            \"List Price = \" +  Roo.util.Format.number(r.data.customer_price_each * ( 1 + rate * 1 ),3)\n        ); \n    }\n    \n    return  String.format('<span qtip=\"{1}\">{0}</span>', Roo.util.Format.number(v,3), tip); \n}",
1679                                     "$ xns" : "Roo.grid",
1680                                     "* prop" : "colModel[]",
1681                                     "dataIndex" : "coitem_custprice_tax",
1682                                     "items" : [
1683                                         {
1684                                             "xtype" : "GridEditor",
1685                                             "$ xns" : "Roo.grid",
1686                                             "* prop" : "editor",
1687                                             "items" : [
1688                                                 {
1689                                                     "listeners" : {
1690                                                         "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1691                                                     },
1692                                                     "minValue" : 0,
1693                                                     "style" : "text-align:right",
1694                                                     "xtype" : "NumberField",
1695                                                     "decimalPrecision" : 3,
1696                                                     "$ xns" : "Roo.form",
1697                                                     "* prop" : "field"
1698                                                 }
1699                                             ]
1700                                         }
1701                                     ]
1702                                 },
1703                                 {
1704                                     "align" : "right",
1705                                     "xtype" : "ColumnModel",
1706                                     "header" : "SubTotal",
1707                                     "width" : 70,
1708                                     "$ renderer" : "function(v) {\n\n    if (parseInt(v) < 1) {\n        return String.format('<b style=\"color:red;\">{0}</b>', Roo.util.Format.number(v,2)); \n    }\n\n    \n\n return Roo.util.Format.number( v, 2);\n  }",
1709                                     "$ xns" : "Roo.grid",
1710                                     "* prop" : "colModel[]",
1711                                     "dataIndex" : "coitem_subtotal"
1712                                 },
1713                                 {
1714                                     "align" : "right",
1715                                     "hidden" : true,
1716                                     "xtype" : "ColumnModel",
1717                                     "header" : "SubTotal w/GST",
1718                                     "width" : 70,
1719                                     "$ renderer" : "function(v,x,r) { \n   \n    if (parseInt(v) < 1) {\n        return String.format('<b style=\"color:red;\">{0}</b>', Roo.util.Format.number(v,2)); \n    }\n    \n    return  String.format('{0}', Roo.util.Format.number(v,2)); \n}",
1720                                     "$ xns" : "Roo.grid",
1721                                     "* prop" : "colModel[]",
1722                                     "dataIndex" : "coitem_subtotal_tax"
1723                                 },
1724                                 {
1725                                     "align" : "right",
1726                                     "xtype" : "ColumnModel",
1727                                     "header" : "Unit Cost",
1728                                     "width" : 50,
1729                                     "$ renderer" : "function(v) { return Roo.util.Format.number( v, 2); }",
1730                                     "$ xns" : "Roo.grid",
1731                                     "* prop" : "colModel[]",
1732                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
1733                                     "dataIndex" : "coitem_unitcost_in_order_cur"
1734                                 },
1735                                 {
1736                                     "align" : "right",
1737                                     "xtype" : "ColumnModel",
1738                                     "header" : "Taxed",
1739                                     "width" : 50,
1740                                     "$ renderer" : "function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); }",
1741                                     "$ xns" : "Roo.grid",
1742                                     "* prop" : "colModel[]",
1743                                     "dataIndex" : "coitem_taxtype_id",
1744                                     "items" : [
1745                                         {
1746                                             "xtype" : "GridEditor",
1747                                             "$ xns" : "Roo.grid",
1748                                             "* prop" : "editor",
1749                                             "items" : [
1750                                                 {
1751                                                     "listWidth" : 400,
1752                                                     "triggerAction" : "all",
1753                                                     "forceSelection" : true,
1754                                                     "selectOnFocus" : true,
1755                                                     "pageSize" : 20,
1756                                                     "displayField" : "taxtype_name",
1757                                                     "emptyText" : "Select Tax Type",
1758                                                     "hiddenName" : "coitem_taxtype_id",
1759                                                     "minChars" : 2,
1760                                                     "valueField" : "taxtype_id",
1761                                                     "xtype" : "ComboBox",
1762                                                     "allowBlank" : false,
1763                                                     "typeAhead" : true,
1764                                                     "editable" : false,
1765                                                     "width" : 40,
1766                                                     "$ xns" : "Roo.form",
1767                                                     "* prop" : "field",
1768                                                     "name" : "coitem_taxtype_id_taxtype_name",
1769                                                     "qtip" : "Select taxtype",
1770                                                     "queryParam" : "query[taxtype_id]",
1771                                                     "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>",
1772                                                     "loadingText" : "Searching...",
1773                                                     "items" : [
1774                                                         {
1775                                                             "listeners" : {
1776                                                                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    \n    \n}\n"
1777                                                             },
1778                                                             "xtype" : "Store",
1779                                                             "remoteSort" : true,
1780                                                             "$ sortInfo" : "{ direction : 'ASC', field: 'taxtype_name' }",
1781                                                             "$ xns" : "Roo.data",
1782                                                             "* prop" : "store",
1783                                                             "items" : [
1784                                                                 {
1785                                                                     "$ url" : "baseURL + '/Roo/taxtype.php'",
1786                                                                     "xtype" : "HttpProxy",
1787                                                                     "method" : "GET",
1788                                                                     "$ xns" : "Roo.data",
1789                                                                     "* prop" : "proxy"
1790                                                                 },
1791                                                                 {
1792                                                                     "id" : "taxtype_id",
1793                                                                     "root" : "data",
1794                                                                     "xtype" : "JsonReader",
1795                                                                     "$ fields" : "[{\"name\":\"taxtype_id\",\"type\":\"int\"},\"taxtype_name\"]",
1796                                                                     "$ xns" : "Roo.data",
1797                                                                     "* prop" : "reader",
1798                                                                     "totalProperty" : "total"
1799                                                                 }
1800                                                             ]
1801                                                         }
1802                                                     ]
1803                                                 }
1804                                             ]
1805                                         }
1806                                     ]
1807                                 },
1808                                 {
1809                                     "align" : "right",
1810                                     "xtype" : "ColumnModel",
1811                                     "header" : "#avail",
1812                                     "width" : 50,
1813                                     "$ renderer" : "function(v,x,r) { \n\n    var oq  = parseInt(r.data.coitem_qtyord);\n    var aq = parseInt(r.data.avail_qty);\n    var sq = parseInt(r.data.coitem_qtyshipped);\n    aq = isNaN(aq) ? 0 : aq;\n    oq = isNaN(oq) ? 0 : oq;\n    sq = isNaN(sq) ? 0 : sq;\n    \n    var unshipped = oq - sq;\n    \n    if ( aq < 0 || (unshipped > 0  &&  aq < unshipped))  {\n       return String.format('<b style=\"color:red;\">{0}</b>', parseInt(aq));\n    }\n     \n    return String.format('{0}', aq); \n    \n}",
1814                                     "$ xns" : "Roo.grid",
1815                                     "* prop" : "colModel[]",
1816                                     "dataIndex" : "avail_qty"
1817                                 },
1818                                 {
1819                                     "align" : "right",
1820                                     "xtype" : "ColumnModel",
1821                                     "header" : "#reserved",
1822                                     "width" : 50,
1823                                     "$ renderer" : "function(v,x,r) { \n\n    \n    var vv = parseInt(v);\n    vv = isNaN(vv) ? 0 : vv;\n    \n    var ov = parseInt(r.data.coitem_qtyord);\n    ov = isNaN(ov) ? 0 : ov;\n    \n    var qs = parseInt(r.data.coitem_qtyshipped);\n    qs = isNaN(qs) ? 0 : qs;\n    \n    \n    \n    if (vv < ov) {\n        // not enough reserved yet.\n        return String.format('<b style=\"background-color:red;color:yellow\">{0}</b>', vv - qs);\n    }\n    \n    return String.format('{0}', vv -  qs); \n    \n}",
1824                                     "$ xns" : "Roo.grid",
1825                                     "* prop" : "colModel[]",
1826                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
1827                                     "dataIndex" : "shipitem_shipped"
1828                                 },
1829                                 {
1830                                     "align" : "right",
1831                                     "xtype" : "ColumnModel",
1832                                     "header" : "#shipped",
1833                                     "width" : 50,
1834                                     "$ renderer" : "function(v,x,r) { \n    \n    var vv = parseInt(v);\n    vv = isNaN(vv) ? 0 : vv;\n    \n    var ov = parseInt(r.data.coitem_qtyord);\n    ov = isNaN(ov) ? 0 : ov;\n    \n\n    if (vv != ov) {\n        // not enought shipped.\n        // or too many shipped.\n        return String.format('<b style=\"background-color:red;color:yellow\">{0}</b>',  vv);\n    }\n\n    \n    \n    return String.format('{0}', vv); \n    \n}",
1835                                     "$ xns" : "Roo.grid",
1836                                     "* prop" : "colModel[]",
1837                                     "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
1838                                     "dataIndex" : "coitem_qtyshipped"
1839                                 },
1840                                 {
1841                                     "align" : "right",
1842                                     "xtype" : "ColumnModel",
1843                                     "header" : "#invoiced",
1844                                     "width" : 50,
1845                                     "$ renderer" : "function(v,x,r) { \n    \n    var vv = parseInt(v);\n    vv = isNaN(vv) ? 0 : vv;\n    \n    var ov = parseInt(r.data.coitem_qtyord);\n    ov = isNaN(ov) ? 0 : ov;\n    \n\n    if (vv !=ov) {\n            return String.format('<b style=\"background-color:red;color:yellow\">{0}</b>', vv); \n    }\n    return String.format('{0}', vv); \n    \n}",
1846                                     "$ xns" : "Roo.grid",
1847                                     "* prop" : "colModel[]",
1848                                     "dataIndex" : "cobill_billed"
1849                                 }
1850                             ]
1851                         }
1852                     ]
1853                 },
1854                 {
1855                     "listeners" : {
1856                         "activate" : "function (_self)\n{\n    _this.shipinvtab = _self;\n}"
1857                     },
1858                     "region" : "center",
1859                     "xtype" : "NestedLayoutPanel",
1860                     "title" : "Shipments / Invoices",
1861                     "$ xns" : "Roo",
1862                     "items" : [
1863                         {
1864                             "xtype" : "BorderLayout",
1865                             "$ xns" : "Roo",
1866                             "* prop" : "layout",
1867                             "items" : [
1868                                 {
1869                                     "xtype" : "LayoutRegion",
1870                                     "$ xns" : "Roo",
1871                                     "* prop" : "center",
1872                                     "titlebar" : true
1873                                 },
1874                                 {
1875                                     "title" : "Reserve Stock / Shipments",
1876                                     "xtype" : "LayoutRegion",
1877                                     "$ xns" : "Roo",
1878                                     "* prop" : "north",
1879                                     "height" : 250
1880                                 },
1881                                 {
1882                                     "listeners" : {
1883                                         "|activate" : "function() {\n    _this.shippanel = this;\n    if (_this.shipgrid) {\n        _this.shipgrid.ds.load({});\n    }\n}"
1884                                     },
1885                                     "background" : false,
1886                                     "fitToframe" : true,
1887                                     "region" : "north",
1888                                     "title" : "shiphead",
1889                                     "xtype" : "GridPanel",
1890                                     "fitContainer" : true,
1891                                     "$ xns" : "Roo",
1892                                     "# builderCfg" : "{\"cols\":[{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"shiphead_shipvia\"],\"table\":\"shiphead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
1893                                     "tableName" : "shiphead",
1894                                     "items" : [
1895                                         {
1896                                             "listeners" : {
1897                                                 "rowdblclick" : "function (_self, rowIndex, e)\n{\n    var rec = this.ds.getAt(rowIndex);\n    if (!rec.json.shiphead_shipdate.length) {\n         Roo.MessageBox.alert(\"Error\", \"You can not edit voided shipments, create a new one, and use the restore feature\");\n         return;\n     }\n\n   Pman.Dialog.XtupleShipment.show({\n        shiphead_id : rec.data.shiphead_id\n\n    }, function() {\n        _self.ds.load({});\n    \n    });\n   \n}\n",
1898                                                 "|render" : "function() \n{\n    _this.shipgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.shippanel.active) {\n       this.ds.load({});\n    }\n}"
1899                                             },
1900                                             "autoExpandColumn" : "shiphead_shipvia",
1901                                             "xtype" : "Grid",
1902                                             "loadMask" : true,
1903                                             "$ xns" : "Roo.grid",
1904                                             "* prop" : "grid",
1905                                             "# builderCfg" : "{\"cols\":[{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"shiphead_shipvia\"],\"table\":\"shiphead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
1906                                             "items" : [
1907                                                 {
1908                                                     "xtype" : "RowSelectionModel",
1909                                                     "singleSelect" : true,
1910                                                     "$ xns" : "Roo.grid",
1911                                                     "* prop" : "sm"
1912                                                 },
1913                                                 {
1914                                                     "listeners" : {
1915                                                         "beforeload" : "function (_self, options)\n{\n     options.params = options.params || {};\n     options.params.shiphead_order_id = _this.form.findField('cohead_id').getValue() * 1;\n    if (options.params.shiphead_order_id < 1) {\n        return false;\n    }\n}"
1916                                                     },
1917                                                     "remoteSort" : true,
1918                                                     "xtype" : "Store",
1919                                                     "$ sortInfo" : "{ field : 'shiphead_shipvia', direction: 'ASC' }",
1920                                                     "$ xns" : "Roo.data",
1921                                                     "* prop" : "dataSource",
1922                                                     "# builderCfg" : "{\"cols\":[{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"shiphead_shipvia\"],\"table\":\"shiphead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
1923                                                     "items" : [
1924                                                         {
1925                                                             "$ url" : "baseURL + '/Roo/shiphead.php'",
1926                                                             "method" : "GET",
1927                                                             "xtype" : "HttpProxy",
1928                                                             "$ xns" : "Roo.data",
1929                                                             "* prop" : "proxy"
1930                                                         },
1931                                                         {
1932                                                             "id" : "id",
1933                                                             "root" : "data",
1934                                                             "xtype" : "JsonReader",
1935                                                             "$ xns" : "Roo.data",
1936                                                             "$ fields" : "[\n    {\n        'name': 'shiphead_number',\n        'type': 'string'\n    },\n    {\n        'name': 'shiphead_shipvia',\n        'type': 'string'\n    },\n    {\n        'name': 'shiphead_shipdate',\n        'type': 'date'\n    },\n    {\n        'name': 'shiphead_sfstatus'\n    },\n    {\n        'name': 'shiphead_tracknum',\n        'type': 'string'\n    }\n]",
1937                                                             "* prop" : "reader",
1938                                                             "totalProperty" : "total",
1939                                                             "# builderCfg" : "{\"cols\":[{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"shiphead_shipvia\"],\"table\":\"shiphead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}"
1940                                                         }
1941                                                     ]
1942                                                 },
1943                                                 {
1944                                                     "xtype" : "Toolbar",
1945                                                     "$ xns" : "Roo",
1946                                                     "* prop" : "toolbar",
1947                                                     "items" : [
1948                                                         {
1949                                                             "listeners" : {
1950                                                                 "|click" : "function()\n{\n     var sel  = _this.shipgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a shipment\");\n        return;\n    }\n    if (sel.data.shiphead_shipped) {\n        Roo.MessageBox.alert(\"Error\", \"Shipment is already confirmed\");\n        return;\n    }\n    \n    \n    // check current status of shipment..\n    \n        \n    new Pman.Request({ \n           mask : 'Sending',\n        url : baseURL + '/Roo/shiphead',\n        method : 'POST',\n        timeout : 90000,\n        params : {\n            shiphead_id : sel.data.shiphead_id,\n            _confirm : 1\n        },\n        success : function() {\n            _this.shipgrid.ds.load({});\n        }\n    });\n         \n     \n}"
1951                                                             },
1952                                                             "text" : "Confirm Shipment",
1953                                                             "xtype" : "Button",
1954                                                             "cls" : "x-btn-text-icon",
1955                                                             "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
1956                                                             "$ xns" : "Roo.Toolbar"
1957                                                         },
1958                                                         {
1959                                                             "listeners" : {
1960                                                                 "|click" : "function()\n{\n     var sel  = _this.shipgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a shipment\");\n        return;\n    }\n\n    \n    // check current status of shipment..\n    \n        \n   new Pman.Download({\n        url : baseURL + '/Roo/shiphead',\n        method : 'GET',\n        params : {\n           _download :sel.data.shiphead_id\n             \n        }\n    });\n         \n     \n}"
1961                                                             },
1962                                                             "text" : "Download (as xls)",
1963                                                             "xtype" : "Button",
1964                                                             "cls" : "x-btn-text-icon",
1965                                                             "$ icon" : "rootURL + '/Pman/templates/images/save.gif'",
1966                                                             "$ xns" : "Roo.Toolbar"
1967                                                         },
1968                                                         {
1969                                                             "listeners" : {
1970                                                                 "click" : "function ()\n{\n    var sel  = _this.shipgrid.getSelectionModel().getSelected();\r\n    if (!sel) {\r\n        Roo.MessageBox.alert(\"Error\", \"Select a shipment\");\r\n        return;\r\n    }\r\n    // check current status of shipment..\n \n        new Pman.Download({\n            url : baseURL + '/Xtuple/Print',\n            method : 'GET',\n            params : {\n                template : 'picking-slip',\n                param : \"shiphead_id:integer='\" + sel.data.shiphead_id + \"'\",\n                filename : 'picking-slip-' + sel.data.shiphead_number\n            },\n            success : function() {\n\n            }\n        })\n            \n            \n   \n}"
1971                                                             },
1972                                                             "text" : "Print Picking Slip",
1973                                                             "xtype" : "Button",
1974                                                             "cls" : "x-btn-text-icon",
1975                                                             "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
1976                                                             "$ xns" : "Roo.Toolbar"
1977                                                         },
1978                                                         {
1979                                                             "listeners" : {
1980                                                                 "click" : "function ()\n{\n    var sel  = _this.shipgrid.getSelectionModel().getSelected();\r\n    if (!sel) {\r\n        Roo.MessageBox.alert(\"Error\", \"Select a shipment\");\r\n        return;\r\n    }\r\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Xtuple/Print',\n            method : 'GET',\n            params : {\n                template : 'delivery-note-',\n                param : \"shiphead_id:integer='\" + sel.data.shiphead_id + \"'\",\n                filename : 'delivery-note-' + sel.data.shiphead_number\n            },\n            success : function() {\n\n            }\n        })\n            \n            \n   \n}"
1981                                                             },
1982                                                             "text" : "Print Delivery Note",
1983                                                             "xtype" : "Button",
1984                                                             "cls" : "x-btn-text-icon",
1985                                                             "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
1986                                                             "$ xns" : "Roo.Toolbar"
1987                                                         },
1988                                                         {
1989                                                             "listeners" : {
1990                                                                 "|click" : "function()\n{\n    var s = _this.shipgrid.getSelectionModel().getSelected();\n    \n    if(!s || s.data.shiphead_id * 1 < 1){\n        Roo.MessageBox.alert('Error', 'Please select a shipment');\n        return;\n    }\n    \n    new Pman.Request({\n        method: 'POST',\n        url: baseURL+ '/Roo/shiphead',\n        params : {\n            shiphead_id : s.data.shiphead_id,\n            _send_delivery : 1\n        },\n        success : function() {\n            Roo.MessageBox.alert('Notice', 'SENT');\n        }\n    });\n    \n}\n"
1991                                                             },
1992                                                             "text" : "Send Delivery Email",
1993                                                             "xtype" : "Button",
1994                                                             "cls" : "x-btn-text-icon",
1995                                                             "$ icon" : "Roo.rootURL + 'images/default/dd/email.gif'",
1996                                                             "$ xns" : "Roo.Toolbar"
1997                                                         },
1998                                                         {
1999                                                             "xtype" : "Fill",
2000                                                             "$ xns" : "Roo.Toolbar"
2001                                                         },
2002                                                         {
2003                                                             "listeners" : {
2004                                                                 "|click" : "function()\n{   \n    if (!_this.form.findField('cohead_id').getValue()) {\n        Roo.MessageBox.alert(\"Error\", \"Save Order first\");\n        return;\n    }\n    var rv = _this.form.getFieldValues();\n    \n    Pman.Dialog.XtupleShipmentNew.show({\n            shiphead_order_id : rv.cohead_id,\n            shiphead_shipdate :  _this.form.findField('cohead_targetdate').getValue().format('Y-m-d')\n        },\n        function() { \n             _this.shipgrid.ds.load({});\n        }\n    );\n}",
2005                                                                 "render" : "function (_self)\n{\n  _this.addShipmentBtn = _self;\n}"
2006                                                             },
2007                                                             "text" : "Add",
2008                                                             "xtype" : "Button",
2009                                                             "cls" : "x-btn-text-icon",
2010                                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2011                                                             "$ xns" : "Roo.Toolbar"
2012                                                         },
2013                                                         {
2014                                                             "listeners" : {
2015                                                                 "|click" : "function()\n{\n    var sel  = _this.shipgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a shipment\");\n        return;\n    }\n    // check current status of shipment..\n    \n    var msg = sel.data.shiphead_shipped ? \n        \"Are you sure you want to un-confirm that shipment? - It will remove items from unposted invoices\" : \n        \"Are you sure you want to void that shipment?\";\n    \n    Roo.MessageBox.confirm(\"Are you sure\", msg,\n        function(r) {\n            if (r != 'yes') {\n                return;\n            }\n            new Pman.Request({\n                mask : 'Sending',\n                 timeout : 90000,\n                url : baseURL + '/Roo/shiphead',\n                method : 'POST',\n                \n                params : {\n                    shiphead_id : sel.data.shiphead_id,\n                    _void : 1\n                },\n                success : function() {\n                    _this.shipgrid.ds.load({});\n                }\n            })\n            \n        }\n    );\n            \n            \n    \n    \n    \n}\n        "
2016                                                             },
2017                                                             "text" : "Void / Unconfirm",
2018                                                             "xtype" : "Button",
2019                                                             "cls" : "x-btn-text-icon",
2020                                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2021                                                             "$ xns" : "Roo.Toolbar"
2022                                                         }
2023                                                     ]
2024                                                 },
2025                                                 {
2026                                                     "xtype" : "ColumnModel",
2027                                                     "header" : "number",
2028                                                     "width" : 80,
2029                                                     "$ renderer" : "function(v,x,r) {\n    if (r.json.shiphead_shipdate.length) {\n         return String.format('{0}', v); \n     }\n     return String.format('<s>{0}</s>', v); \n }",
2030                                                     "$ xns" : "Roo.grid",
2031                                                     "* prop" : "colModel[]",
2032                                                     "dataIndex" : "shiphead_number",
2033                                                     "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2034                                                 },
2035                                                 {
2036                                                     "xtype" : "ColumnModel",
2037                                                     "header" : "From Location",
2038                                                     "width" : 100,
2039                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2040                                                     "$ xns" : "Roo.grid",
2041                                                     "* prop" : "colModel[]",
2042                                                     "dataIndex" : "shiphead_location_id_location_name"
2043                                                 },
2044                                                 {
2045                                                     "xtype" : "ColumnModel",
2046                                                     "header" : "Ship to",
2047                                                     "width" : 100,
2048                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2049                                                     "$ xns" : "Roo.grid",
2050                                                     "* prop" : "colModel[]",
2051                                                     "dataIndex" : "shiphead_shipto_id_shipto_name"
2052                                                 },
2053                                                 {
2054                                                     "xtype" : "ColumnModel",
2055                                                     "header" : "shipdate",
2056                                                     "width" : 75,
2057                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
2058                                                     "$ xns" : "Roo.grid",
2059                                                     "* prop" : "colModel[]",
2060                                                     "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
2061                                                     "dataIndex" : "shiphead_shipdate"
2062                                                 },
2063                                                 {
2064                                                     "xtype" : "ColumnModel",
2065                                                     "header" : "Status",
2066                                                     "width" : 50,
2067                                                     "$ renderer" : "function(v,x,r) { \n\n\n\n  \n    if (r.json.shiphead_shipdate.length) {\n    \n        if (r.json.shiphead_shipped) {\n            return \"Confirmed\";\n        }\n    \n         return '<span style=\"color:red\">Draft</span>';\n    }\n     \n    return 'VOID';\n   \n\n}",
2068                                                     "$ xns" : "Roo.grid",
2069                                                     "* prop" : "colModel[]",
2070                                                     "dataIndex" : "shiphead_sfstatus",
2071                                                     "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2072                                                 },
2073                                                 {
2074                                                     "xtype" : "ColumnModel",
2075                                                     "header" : "shipvia",
2076                                                     "width" : 200,
2077                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2078                                                     "$ xns" : "Roo.grid",
2079                                                     "* prop" : "colModel[]",
2080                                                     "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}",
2081                                                     "dataIndex" : "shiphead_shipvia"
2082                                                 },
2083                                                 {
2084                                                     "xtype" : "ColumnModel",
2085                                                     "header" : "tracknum",
2086                                                     "width" : 200,
2087                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2088                                                     "$ xns" : "Roo.grid",
2089                                                     "* prop" : "colModel[]",
2090                                                     "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
2091                                                     "dataIndex" : "shiphead_tracknum"
2092                                                 }
2093                                             ]
2094                                         }
2095                                     ]
2096                                 },
2097                                 {
2098                                     "listeners" : {
2099                                         "|activate" : "function() {\n    _this.invpanel = this;\n    if (_this.invgrid) {\n        _this.invgrid.ds.load({});\n    }\n}"
2100                                     },
2101                                     "fitToframe" : true,
2102                                     "background" : false,
2103                                     "region" : "center",
2104                                     "title" : "Invoices",
2105                                     "xtype" : "GridPanel",
2106                                     "fitContainer" : true,
2107                                     "$ xns" : "Roo",
2108                                     "tableName" : "cobmisc",
2109                                     "items" : [
2110                                         {
2111                                             "listeners" : {
2112                                                 "|rowdblclick" : "function (_self, rowIndex, e)\n{\n\n    var ri = this.ds.getAt(rowIndex);\n    if ( ri.data.cobmisc_id < 0) { // skip summary row..\n        return;\n    }\n    var rv = _this.form.getFieldValues();\n   Pman.Dialog.XtupleInvoice.show({\n        cobmisc_id : ri.data.cobmisc_id,\n        // below parms for add credit memo\n        cmdata : {\n            cm_cust_id : rv.cohead_cust_id,\n            cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,\n            cm_curr_id : rv.cohead_curr_id,\n            cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,\n            cm_terms_id : rv.cohead_terms_id,\n            cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,\n            cm_salesrep_id : rv.cohead_salesrep_id,\n            cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,\n            cm_docdate : new Date(),\n            cm_taxzone_id : rv.cohead_taxzone_id,\n            cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,\n            cm_billto_cntct_id : rv.cohead_billto_cntct_id,\n            cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,\n            cm_location_src : rv.cohead_location_src,\n            cm_location_src_location_name : rv.cohead_location_src_location_name,\n            cm_billto_address : rv.billto_address\n        }\n    },\n        function() { \n         _this.invgrid.ds.load({});\n    });\n   \n}\n\n",
2113                                                 "|render" : "function() \n{\n    _this.invgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.invpanel.active) {\n       this.ds.load({});\n    }\n}"
2114                                             },
2115                                             "autoExpandColumn" : "invchead_invcnumber",
2116                                             "xtype" : "Grid",
2117                                             "loadMask" : true,
2118                                             "$ xns" : "Roo.grid",
2119                                             "* prop" : "grid",
2120                                             "# builderCfg" : "{\"cols\":[{\"table\":\"invchead\",\"column\":\"invchead_invcnumber\",\"columnshort\":\"invchead_invcnumber\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"invchead_invcnumber\"],\"table\":\"invchead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2121                                             "items" : [
2122                                                 {
2123                                                     "listeners" : {
2124                                                         "beforeload" : "function (_self, options)\n{\n\n    options.params = options.params || {};\n    options.params.cobmisc_cohead_id = _this.form.findField('cohead_id').getValue() * 1;\n    if (options.params.cobmisc_cohead_id < 1) {\n        return false;\n    }\n    \n    options.params._with_other_payment = 1;\n    //options.params['query[invchead_ordernumber]']  = _this.form.findField('cohead_number').getValue()\n    \n}",
2125                                                         "load" : "function (_self, records, options)\n{\n    var total = 0;\n    var done = 0;\n    var totalic = 0.0;\n    var totalfreight = 0.0;    \n    var totalmisc = 0.0;        \n    var totaltax = 0.0;        \n   \n    Roo.each(records, function(r)\n    {\n        if(r.data.cobmisc_id > 1){\n            done += parseInt(r.data.cobmisc_qty);\n            totalic += parseFloat(r.data.cobmisc_itemcost).toFixed(2)*1;        \n            totalmisc += parseFloat(r.data.cobmisc_misc).toFixed(2)*1;        \n            totalfreight += parseFloat(r.data.cobmisc_freight).toFixed(2)*1;                \n            totaltax += parseFloat(r.data.cobmisc_tax).toFixed(2)*1;                \n            total = parseInt(r.data.cobmisc_total_qty);\n        }\n       \n    });\n    \n    _this.shipinvtab.layout.getRegion('center').getPanel(0).setTitle(\n        (total == done) ?\n             \"Invoices (Complete)\" : \n            (\"Invoices prepared for \" +    done + '/' + total)\n    );\n\n    \n    var frtotal = (parseFloat(_this.form.findField('cohead_freight').getValue())  - totalfreight).toFixed(2);\n    var misctotal = (parseFloat(_this.form.findField('cohead_misc').getValue()) - totalmisc).toFixed(2);\n    var ictotal =  (parseFloat(_this.form.findField('cohead_subtotal').getValue()) - totalic).toFixed(2);\n    var taxtotal =  (parseFloat(_this.form.findField('cohead_tax').getValue())  - totaltax).toFixed(2);\n    var remtotal = frtotal*1 + misctotal*1 + ictotal*1 + taxtotal*1;\n    \n    var nr = this.reader.newRow({\n        cobmisc_id : -1,\n        cobmisc_invchead_id_invchead_invcnumber : \"Total Remaining\",\n        cobmisc_qty : total - done,\n        cobmisc_freight :frtotal,\n        cobmisc_misc : misctotal,        \n        cobmisc_itemcost  : ictotal,             \n        cobmisc_tax : taxtotal,\n        cobmisc_total : remtotal\n\n        \n    });\n    // do we need to add it somehow??\n    _this.invgrid.ds.add(nr);\n}"
2126                                                     },
2127                                                     "xtype" : "Store",
2128                                                     "remoteSort" : true,
2129                                                     "$ sortInfo" : "{ field : 'invchead_invcnumber', direction: 'ASC' }",
2130                                                     "$ xns" : "Roo.data",
2131                                                     "* prop" : "dataSource",
2132                                                     "items" : [
2133                                                         {
2134                                                             "$ url" : "baseURL + '/Roo/cobmisc.php'",
2135                                                             "xtype" : "HttpProxy",
2136                                                             "method" : "GET",
2137                                                             "$ xns" : "Roo.data",
2138                                                             "* prop" : "proxy"
2139                                                         },
2140                                                         {
2141                                                             "id" : "id",
2142                                                             "root" : "data",
2143                                                             "xtype" : "JsonReader",
2144                                                             "$ fields" : "[\n    {\n        'name': 'invchead_invcnumber',\n        'type': 'string'\n    },\n    {\n        'name': 'invchead_invcdate',\n        'type': 'date'\n    }\n]",
2145                                                             "$ xns" : "Roo.data",
2146                                                             "* prop" : "reader",
2147                                                             "# builderCfg" : "{\"cols\":[{\"table\":\"invchead\",\"column\":\"invchead_invcnumber\",\"columnshort\":\"invchead_invcnumber\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"},{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}],\"cols_ex\":[\"invchead_invcnumber\"],\"table\":\"invchead\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2148                                                             "totalProperty" : "total"
2149                                                         }
2150                                                     ]
2151                                                 },
2152                                                 {
2153                                                     "xtype" : "Toolbar",
2154                                                     "$ xns" : "Roo",
2155                                                     "* prop" : "toolbar",
2156                                                     "items" : [
2157                                                         {
2158                                                             "listeners" : {
2159                                                                 "|click" : "function ()\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    // check current status of shipment..\n    \n    Roo.MessageBox.confirm(\"Are you sure\", \"Are you sure you want to Post that invoice?\",\n        function(r) {\n            if (r != 'yes') {\n                return;\n            }\n            new Pman.Request({\n               mask : 'Sending',\n                url : baseURL + '/Roo/cobmisc',\n                method : 'POST',\n                params : {\n                    cobmisc_id : sel.data.cobmisc_id,\n                    _post : 1\n                },\n                success : function() {\n                    _this.invgrid.ds.load({});\n                }\n            })\n            \n        }\n    );\n            \n            \n   \n}"
2160                                                             },
2161                                                             "text" : "Post Invoice",
2162                                                             "xtype" : "Button",
2163                                                             "cls" : "x-btn-text-icon",
2164                                                             "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
2165                                                             "$ xns" : "Roo.Toolbar"
2166                                                         },
2167                                                         {
2168                                                             "text" : "Print",
2169                                                             "xtype" : "Button",
2170                                                             "cls" : "x-btn-text-icon",
2171                                                             "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
2172                                                             "$ xns" : "Roo.Toolbar",
2173                                                             "items" : [
2174                                                                 {
2175                                                                     "xtype" : "Menu",
2176                                                                     "$ xns" : "Roo.menu",
2177                                                                     "* prop" : "menu",
2178                                                                     "items" : [
2179                                                                         {
2180                                                                             "listeners" : {
2181                                                                                 "click" : "function ()\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n                _print : 1\n            },\n            success : function() {\n\n            }\n        })\n            \n            \n   \n}"
2182                                                                             },
2183                                                                             "text" : "Print Standard Invoice",
2184                                                                             "xtype" : "Item",
2185                                                                             "$ xns" : "Roo.menu"
2186                                                                         },
2187                                                                         {
2188                                                                             "listeners" : {
2189                                                                                 "click" : "function (_self, e)\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n                _print : 'cn'\n                \n            },\n            success : function() {\n\n            }\n        })\n            \n          \n} "
2190                                                                             },
2191                                                                             "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
2192                                                                             "text" : "Print Chinese Invoice With GST in line item",
2193                                                                             "xtype" : "Item",
2194                                                                             "$ xns" : "Roo.menu"
2195                                                                         },
2196                                                                         {
2197                                                                             "listeners" : {
2198                                                                                 "click" : "function (_self, e)\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n                _print : 'cn-gst'\n                \n            },\n            success : function() {\n\n            }\n        })\n            \n          \n} "
2199                                                                             },
2200                                                                             "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
2201                                                                             "text" : "Print Chinese Invoice",
2202                                                                             "xtype" : "Item",
2203                                                                             "$ xns" : "Roo.menu"
2204                                                                         },
2205                                                                         {
2206                                                                             "listeners" : {
2207                                                                                 "click" : "function (_self, e)\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n                _print : 'au-gst'\n                \n            },\n            success : function() {\n\n            }\n        })\n            \n          \n} "
2208                                                                             },
2209                                                                             "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2210                                                                             "text" : "Print Aus - GST included Invoice",
2211                                                                             "xtype" : "Item",
2212                                                                             "$ xns" : "Roo.menu"
2213                                                                         },
2214                                                                         {
2215                                                                             "listeners" : {
2216                                                                                 "click" : "function (_self, e)\n{\n  var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n\n                _print : 'au-net',\n               ts: Math.random()\n            }\n        })\n\n\n}"
2217                                                                             },
2218                                                                             "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2219                                                                             "text" : "Print Bambini Pronto Invoice",
2220                                                                             "xtype" : "Item",
2221                                                                             "$ xns" : "Roo.menu"
2222                                                                         },
2223                                                                         {
2224                                                                             "listeners" : {
2225                                                                                 "click" : "function (_self, e)\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if (!sel.data.cobmisc_invchead_id) {\n        Roo.MessageBox.alert(\"Error\", \"Invoice has not been posted\");\n        return;\n    }\n    // check current status of shipment..\n\n        new Pman.Download({\n            url : baseURL + '/Roo/invchead',\n            method : 'GET',\n            params : {\n                invchead_id : sel.data.cobmisc_invchead_id,\n                _print : 'au-proforma'\n                \n            },\n            success : function() {\n\n            }\n        })\n            \n          \n} "
2226                                                                             },
2227                                                                             "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2228                                                                             "text" : "Print Bambini Pro Forma Invoice",
2229                                                                             "xtype" : "Item",
2230                                                                             "$ xns" : "Roo.menu"
2231                                                                         },
2232                                                                         {
2233                                                                             "listeners" : {
2234                                                                                 "click" : "function (_self, e)\n{\n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    \n    Pman.Dialog.XtupleDiscountOfInvoice.show({invchead_id : sel.data.cobmisc_invchead_id}, function(){\n\n    });\n}"
2235                                                                             },
2236                                                                             "$ hidden" : "!( baseURL.match(/au\\.php$/)) ",
2237                                                                             "text" : "Print Shipping / Commercial Invoice",
2238                                                                             "xtype" : "Item",
2239                                                                             "$ xns" : "Roo.menu"
2240                                                                         }
2241                                                                     ]
2242                                                                 }
2243                                                             ]
2244                                                         },
2245                                                         {
2246                                                             "text" : "Payments / Refunds / Credit Memos",
2247                                                             "xtype" : "Button",
2248                                                             "cls" : "x-btn-text-icon",
2249                                                             "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
2250                                                             "$ xns" : "Roo.Toolbar",
2251                                                             "items" : [
2252                                                                 {
2253                                                                     "xtype" : "Menu",
2254                                                                     "$ xns" : "Roo.menu",
2255                                                                     "* prop" : "menu",
2256                                                                     "items" : [
2257                                                                         {
2258                                                                             "listeners" : {
2259                                                                                 "click" : "function(_self,e)\n    {\n    \n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel || sel.data.cobmisc_id < 1) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    if(!sel.data.cobmisc_posted){\n        Roo.MessageBox.alert(\"Error\", \"This invoice has not been posted!\");\n        return;\n    }\n    if(sel.data.cobmisc_outstanding == 0){\n        Roo.MessageBox.alert(\"Error\", \"There is no any outstanding of this invoice!\");\n        return;\n    }\n    \n    var cust_id = _this.form.findField('cohead_cust_id').getValue();\n    if(!cust_id){\n        return;\n    }\n    var data = {\n        cashrcpt_amount : sel.data.cobmisc_outstanding,\n        cashrcpt_cust_id : cust_id,\n        cashrcpt_aropen_id : sel.data.cobmisc_aropen_id_aropen_id,\n        cashrcpt_distdate : new Date(),\n        cashrcpt_fundstype : 'C',\n        cashrcpt_curr_id : sel.data.cobmisc_curr_id_curr_id,\n        cashrcpt_curr_id_curr_name : sel.data.cobmisc_curr_id_curr_name,\n        cashrcpt_usecustdeposit : true,\n        cashrcpt_docdate : new Date(),\n        cashrcpt_salescat_id : -1,\n        cashrcpt_applydate : new Date(),\n        cashrcpt_discount : 0\n    };\n    Pman.Dialog.XtupleReceivePayment.show( data , function() {\n        _this.invgrid.ds.load({});\n    }); \n}\n"
2260                                                                             },
2261                                                                             "text" : "Receive Payment",
2262                                                                             "xtype" : "Item",
2263                                                                             "cls" : "x-btn-text-icon",
2264                                                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2265                                                                             "$ xns" : "Roo.menu"
2266                                                                         },
2267                                                                         {
2268                                                                             "listeners" : {
2269                                                                                 "click" : "function(_self,e)\n{\n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {\n        Roo.MessageBox.alert(\"Error\", \"Select a credit memo\");\n        return;\n    }\n    if(!sel.data.cobmisc_posted){\n        Roo.MessageBox.alert(\"Error\", \"The invoice that credit memo has been applied to has been not posted\");\n        return;\n    }\n    var cust_id = _this.form.findField('cohead_cust_id').getValue();\n    if(!cust_id){\n        return;\n    }\n    \n    if(!sel.data.cobmisc_outstanding || sel.data.cobmisc_outstanding == 0){\n        Roo.MessageBox.alert(\"Error\", \"The amount of this credit memo is 0!\");\n        return;\n    }\n    \n    var d = _this.form.getFieldValues();\n    \n    var data = {\n        'checkhead_recip_id' : cust_id,\n        'checkhead_recip_type' : 'C',\n        'checkhead_checkdate' : new Date(),\n        'checkhead_amount' : sel.data.cobmisc_outstanding,\n        'remaining_total' : sel.data.cobmisc_outstanding,\n        'checkhead_curr_id' : d.cohead_curr_id,\n        'checkhead_curr_id_curr_name' : d.cohead_curr_id_curr_name,\n        'checkhead_misc' : true,\n        'aropen_id' : sel.data.cobmisc_cobapply_aropen_id,\n    \t'cmhead_number' : sel.data.cobmisc_invchead_id_invchead_invcnumber,\n\t'cust_name' : d.cohead_cust_id_cust_name,\n\t'_create_and_post' : 1\n\n    };\n    \n    \n    Pman.Dialog.XtupleMiscellaneousCheck.show( data , function() {\n        _this.invgrid.ds.load({});\n   }); \n}\n"
2270                                                                             },
2271                                                                             "text" : "Issue Refund",
2272                                                                             "xtype" : "Item",
2273                                                                             "cls" : "x-btn-text-icon",
2274                                                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2275                                                                             "$ xns" : "Roo.menu"
2276                                                                         },
2277                                                                         {
2278                                                                             "xtype" : "Separator",
2279                                                                             "$ xns" : "Roo.menu"
2280                                                                         },
2281                                                                         {
2282                                                                             "listeners" : {
2283                                                                                 "click" : "function(_self,e)\n{\n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel || sel.data.cobmisc_cashrcpt_id * 1 < 1) {\n        Roo.MessageBox.alert(\"Error\", \"Select a Receive Payment\");\n        return;\n    }\n    \n    Roo.MessageBox.confirm(\"Confirm\", \"Voiding receipt will mean you will have to re-enter the receipt refund - \" + \n                    \"please take note of the details so you can enter it again correctly later.\", function(r) {\n                            \n        if (r !='yes') {\n            return;\n        }\n        new Pman.Request({\n            url : baseURL + '/Roo/cashrcpt',\n            method : 'POST',\n            params : {\n                cashrcpt_id : sel.data.cobmisc_cashrcpt_id,\n                _void : 1\n            },\n            success : function() \n            {\n                _this.invgrid.ds.load({});\n            \n            }\n        });\n    \n   })\n    \n     \n}\n"
2284                                                                             },
2285                                                                             "text" : "Void Payment",
2286                                                                             "xtype" : "Item",
2287                                                                             "cls" : "x-btn-text-icon",
2288                                                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2289                                                                             "$ xns" : "Roo.menu"
2290                                                                         },
2291                                                                         {
2292                                                                             "listeners" : {
2293                                                                                 "click" : "function(_self,e)\n{\n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel || sel.data.cobmisc_checkhead_id * 1 < 1) {\n        Roo.MessageBox.alert(\"Error\", \"Select a Miscellaneours Check\");\n        return;\n    }\n    \n    Roo.MessageBox.confirm(\"Confirm\", \"Voiding refund will mean you will have to re-enter the receipt refund - \" + \n                    \"please take note of the details so you can enter it again correctly later.\", function(r) {\n                            \n        if (r !='yes') {\n            return;\n        }\n        new Pman.Request({\n            url : baseURL + '/Roo/checkhead',\n            method : 'POST',\n            params : {\n                checkhead_id : sel.data.cobmisc_checkhead_id,\n                _voidPosted : 1\n            },\n            success : function() \n            {\n                _this.invgrid.ds.load({});\n            \n            }\n        });\n    \n   })\n    \n     \n}\n"
2294                                                                             },
2295                                                                             "text" : "Void Refund",
2296                                                                             "xtype" : "Item",
2297                                                                             "cls" : "x-btn-text-icon",
2298                                                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2299                                                                             "$ xns" : "Roo.menu"
2300                                                                         },
2301                                                                         {
2302                                                                             "listeners" : {
2303                                                                                 "click" : "function(_self,e)\n{\n    var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {\n        Roo.MessageBox.alert(\"Error\", \"Select a credit memo\");\n        return;\n    }\n    \n    if(sel.data.cobmisc_posted){\n        Roo.MessageBox.alert(\"Error\", \"You cann't void this credit memo, since the invoice that credit memo has been applied to has been posted\");\n        return;\n    }\n    \n    if (sel.data.cobmisc_cobapply_id < 1) {\n        Roo.MessageBox.alert(\"Error\", \"invaild credit memo\");\n        return;\n    }\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure want to void this applied credit memo, \" + \n                \"it will also void all the check that belongs to this credit memo \", function(r) {\n                            \n        if (r !='yes') {\n            return;\n        }\n        new Pman.Request({\n            url : baseURL + '/Roo/cobapply',\n            method : 'POST',\n            params : {\n                _delete : sel.data.cobmisc_cobapply_id,\n                _void : 1\n            },\n            success : function() \n            {\n                _this.invgrid.ds.load({});\n            \n            }\n        });\n    \n   })\n     \n}\n"
2304                                                                             },
2305                                                                             "text" : "Void Credit Memo",
2306                                                                             "xtype" : "Item",
2307                                                                             "cls" : "x-btn-text-icon",
2308                                                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2309                                                                             "$ xns" : "Roo.menu"
2310                                                                         }
2311                                                                     ]
2312                                                                 }
2313                                                             ]
2314                                                         },
2315                                                         {
2316                                                             "xtype" : "Fill",
2317                                                             "$ xns" : "Roo.Toolbar"
2318                                                         },
2319                                                         {
2320                                                             "listeners" : {
2321                                                                 "|click" : "function ()\n{\n\n    if (!_this.form.findField('cohead_id').getValue()) {\n        Roo.MessageBox.alert(\"Error\", \"Save Order first\");\n        return;\n    }\n    \n    var rv = _this.form.getFieldValues();\n    \n   \n   Pman.Dialog.XtupleInvoice.show({\n        cobmisc_cohead_id : rv.cohead_id,\n        cobmisc_shipdate :  _this.form.findField('cohead_targetdate').getValue(),\n        cobmisc_invcdate :  _this.form.findField('cohead_targetdate').getValue(),\n        cobmisc_curr_id : rv.cohead_curr_id,\n        cobmisc_curr_id_curr_name : rv.cohead_curr_id_curr_name,\n        // below parms for add credit memo\n        cmdata : {\n            cm_cust_id : rv.cohead_cust_id,\n            cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,\n            cm_curr_id : rv.cohead_curr_id,\n            cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,\n            cm_terms_id : rv.cohead_terms_id,\n            cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,\n            cm_salesrep_id : rv.cohead_salesrep_id,\n            cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,\n            cm_docdate : new Date(),\n            cm_taxzone_id : rv.cohead_taxzone_id,\n            cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,\n            cm_billto_cntct_id : rv.cohead_billto_cntct_id,\n            cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,\n            cm_location_src : rv.cohead_location_src,\n            cm_location_src_location_name : rv.cohead_location_src_location_name,\n            cm_billto_address : rv.billto_address\n        }\n        \n    },\n        function() { \n         _this.invgrid.ds.load({});\n    });\n   \n}",
2322                                                                 "render" : "function (_self)\n{\n  _this.addInvoiceBtn = _self;\n}"
2323                                                             },
2324                                                             "text" : "Add",
2325                                                             "xtype" : "Button",
2326                                                             "cls" : "x-btn-text-icon",
2327                                                             "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2328                                                             "$ xns" : "Roo.Toolbar"
2329                                                         },
2330                                                         {
2331                                                             "listeners" : {
2332                                                                 "|click" : "function ()\n{\n\n     var sel  = _this.invgrid.getSelectionModel().getSelected();\n    if (!sel) {\n        Roo.MessageBox.alert(\"Error\", \"Select a invoice\");\n        return;\n    }\n    // check current status of shipment..\n    \n    var params =  {\n//        cobmisc_id : sel.data.cobmisc_id,\n        _void : 1\n    };\n    if (sel.data.cobmisc_id * 1) {\n        params.cobmisc_id = sel.data.cobmisc_id * 1 ;\n    }\n    if (sel.data.cobmisc_invchead_id_invchead_id * 1) {    \n        params.invchead_id  =  sel.data.cobmisc_invchead_id_invchead_id * 1;\n    }\n    \n    Roo.MessageBox.confirm(\"Are you sure\", \"Are you sure you want to VOID that invoice?\",\n        function(r) {\n            if (r != 'yes') {\n                return;\n            }\n            new Pman.Request({\n                mask : 'Sending',\n                url : baseURL + '/Roo/cobmisc',\n                method : 'POST',\n                params :  params,\n                success : function() {\n                    _this.invgrid.ds.load({});\n                }\n            })\n            \n        }\n    );\n            \n            \n   \n}"
2333                                                             },
2334                                                             "text" : "Void / Unpost",
2335                                                             "xtype" : "Button",
2336                                                             "cls" : "x-btn-text-icon",
2337                                                             "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2338                                                             "$ xns" : "Roo.Toolbar"
2339                                                         }
2340                                                     ]
2341                                                 },
2342                                                 {
2343                                                     "xtype" : "ColumnModel",
2344                                                     "header" : "Invoice #",
2345                                                     "width" : 100,
2346                                                     "$ renderer" : "function(v,x,r) { \n       if (v && \n             r.data.cobmisc_invchead_id_invchead_id * 1 && \n            !r.data.cobmisc_invchead_id_invchead_posted) {\n           return  '<span style=\"color:red\">' + \n                \"NEEDS Voiding then re-posted: \" + \n                String.format('{0}', v) +\n                '</span>'; \n       }\n\n       if(v && r.data.cobmisc_id == -2){\n            return String.format('<span style=\"margin-left: 10px;\"> - {0} (Credit Memo)</span>', v); \n       }\n       if(v && r.data.cobmisc_id == -3){\n            return String.format('<span style=\"margin-left: 20px;\"> - {0} (Miscellaneous Check)</span>', v); \n       }\n      if(v && r.data.cobmisc_id == -4){\n            return String.format('<span style=\"margin-left: 10px;\"> - {0} (Receive Payment to {2}) [ {1} ]</span>', \n                    v, r.data.cobmisc_cashrcpt_amount, r.json.cashrcpt_bankaccnt_id_bankaccnt_bankname); \n       }\n       \n        return v ? String.format('{0}', v) : \n                '<span style=\"color:red\">' + \"Not Posted\" + '</span>'; \n}",
2347                                                     "$ xns" : "Roo.grid",
2348                                                     "* prop" : "colModel[]",
2349                                                     "dataIndex" : "cobmisc_invchead_id_invchead_invcnumber"
2350                                                 },
2351                                                 {
2352                                                     "xtype" : "ColumnModel",
2353                                                     "header" : "invcdate",
2354                                                     "width" : 75,
2355                                                     "$ renderer" : "function(v,x,r) { \n    \n    return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); \n}",
2356                                                     "$ xns" : "Roo.grid",
2357                                                     "* prop" : "colModel[]",
2358                                                     "dataIndex" : "cobmisc_invcdate",
2359                                                     "# builderCfg" : "{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2360                                                 },
2361                                                 {
2362                                                     "align" : "right",
2363                                                     "xtype" : "ColumnModel",
2364                                                     "header" : "Qty",
2365                                                     "width" : 50,
2366                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? parseInt(v) : 0); }",
2367                                                     "$ xns" : "Roo.grid",
2368                                                     "* prop" : "colModel[]",
2369                                                     "dataIndex" : "cobmisc_qty"
2370                                                 },
2371                                                 {
2372                                                     "align" : "right",
2373                                                     "xtype" : "ColumnModel",
2374                                                     "header" : "Item Cost",
2375                                                     "width" : 75,
2376                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); }",
2377                                                     "$ xns" : "Roo.grid",
2378                                                     "* prop" : "colModel[]",
2379                                                     "dataIndex" : "cobmisc_itemcost"
2380                                                 },
2381                                                 {
2382                                                     "align" : "right",
2383                                                     "xtype" : "ColumnModel",
2384                                                     "header" : "Shipping",
2385                                                     "width" : 75,
2386                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); }",
2387                                                     "$ xns" : "Roo.grid",
2388                                                     "* prop" : "colModel[]",
2389                                                     "dataIndex" : "cobmisc_freight"
2390                                                 },
2391                                                 {
2392                                                     "align" : "right",
2393                                                     "xtype" : "ColumnModel",
2394                                                     "header" : "Tax",
2395                                                     "width" : 75,
2396                                                     "$ renderer" : "function(v,x,r) { \n\n    // tax is based on the % itemcost..\n//    var ic  = r.data.cobmisc_itemcost;\n    /*\n    var ic  =r.data.cobmisc_itemcost - (1* r.data.cobmisc_itemcost_taxfree);\n    \n    var tax= _this.form.findField('cohead_tax').getValue() * 1.0;\n    var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    \n    if (tax < 0.1) {\n        return '';\n    }\n    var taxp = tax / totic;\n    var lv = taxp * ic;\n    */\n    return String.format('{0}', (1.0*v).toFixed(2) );\n    \n    \n }",
2397                                                     "$ xns" : "Roo.grid",
2398                                                     "* prop" : "colModel[]",
2399                                                     "dataIndex" : "cobmisc_tax"
2400                                                 },
2401                                                 {
2402                                                     "align" : "right",
2403                                                     "xtype" : "ColumnModel",
2404                                                     "header" : "Discount (Pretax)",
2405                                                     "width" : 100,
2406                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); }",
2407                                                     "$ xns" : "Roo.grid",
2408                                                     "* prop" : "colModel[]",
2409                                                     "dataIndex" : "cobmisc_cohead_id_cohead_pretax_discount"
2410                                                 },
2411                                                 {
2412                                                     "align" : "right",
2413                                                     "xtype" : "ColumnModel",
2414                                                     "header" : "Discount (Posttax)",
2415                                                     "width" : 100,
2416                                                     "$ renderer" : "function(v,x,r) \n{\n    var vv = v - r.data.cobmisc_cohead_id_cohead_pretax_discount;\n    \n    return String.format('{0}', vv ? (1.0*vv).toFixed(2) : 0); \n}",
2417                                                     "$ xns" : "Roo.grid",
2418                                                     "* prop" : "colModel[]",
2419                                                     "dataIndex" : "cobmisc_misc"
2420                                                 },
2421                                                 {
2422                                                     "align" : "right",
2423                                                     "xtype" : "ColumnModel",
2424                                                     "header" : "Total ",
2425                                                     "width" : 75,
2426                                                     "$ renderer" : "function(v,x,r) { \n\n/*    \n    var ic  = r.data.cobmisc_itemcost;\n    var tax= _this.form.findField('cohead_tax').getValue() * 1.0;\n    var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    \n    var     lv = 0.0;\n    if (tax > 0.0) {\n        var taxp = tax / totic;\n        lv = taxp * ic;\n\n    }\n  */  \n  \n\n    if(v){\n        return String.format('{0}',(v * 1.0).toFixed(2) );\n    }\n    var d= r.data;\n\n    return String.format('{0}',\n       ((d.cobmisc_itemcost * 1.0) + \n       (d.cobmisc_freight * 1.0) + \n       (d.cobmisc_tax * 1.0) +\n       (d.cobmisc_misc * 1.0)  \n\n       ).toFixed(2) );\n}",
2427                                                     "$ xns" : "Roo.grid",
2428                                                     "* prop" : "colModel[]",
2429                                                     "dataIndex" : "cobmisc_total"
2430                                                 },
2431                                                 {
2432                                                     "align" : "right",
2433                                                     "xtype" : "ColumnModel",
2434                                                     "header" : "Outstanding",
2435                                                     "width" : 75,
2436                                                     "$ renderer" : "function(v,x,r) \n{ \n    \n    return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );\n}",
2437                                                     "$ xns" : "Roo.grid",
2438                                                     "* prop" : "colModel[]",
2439                                                     "dataIndex" : "cobmisc_outstanding"
2440                                                 }
2441                                             ]
2442                                         }
2443                                     ]
2444                                 }
2445                             ]
2446                         }
2447                     ]
2448                 },
2449                 {
2450                     "listeners" : {
2451                         "|activate" : "function() {\n    _this.hpanel = this;\n    if (_this.hgrid) {\n        _this.hgrid.footer.onClick('first');\n    }\n}"
2452                     },
2453                     "background" : true,
2454                     "fitToframe" : true,
2455                     "region" : "center",
2456                     "title" : "History",
2457                     "xtype" : "GridPanel",
2458                     "fitContainer" : true,
2459                     "$ xns" : "Roo",
2460                     "# builderCfg" : "{\"cols\":[{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}],\"cols_ex\":[\"remarks\"],\"table\":\"events\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2461                     "tableName" : "events",
2462                     "items" : [
2463                         {
2464                             "listeners" : {
2465                                 "|rowdblclick" : "function (_self, rowIndex, e)\n{\n    if (!_this.dialog) return;\n    _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n        _this.grid.footer.onClick('first');\n    }); \n}\n",
2466                                 "|render" : "function() \n{\n    _this.hgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.hpanel.active) {\n       this.footer.onClick('first');\n    }\n}"
2467                             },
2468                             "autoExpandColumn" : "remarks",
2469                             "xtype" : "Grid",
2470                             "loadMask" : true,
2471                             "$ xns" : "Roo.grid",
2472                             "* prop" : "grid",
2473                             "# builderCfg" : "{\"cols\":[{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}],\"cols_ex\":[\"remarks\"],\"table\":\"events\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2474                             "items" : [
2475                                 {
2476                                     "listeners" : {
2477                                         "beforeload" : "function (_self, options)\n{\n    options.params._related_on_table = 'cohead';\n    options.params._related_on_id = _this.form.findField('cohead_id').getValue();\n}"
2478                                     },
2479                                     "remoteSort" : true,
2480                                     "xtype" : "Store",
2481                                     "$ sortInfo" : "{ field : 'event_when', direction: 'DESC' }",
2482                                     "$ xns" : "Roo.data",
2483                                     "* prop" : "dataSource",
2484                                     "# builderCfg" : "{\"cols\":[{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}],\"cols_ex\":[\"remarks\"],\"table\":\"events\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2485                                     "items" : [
2486                                         {
2487                                             "$ url" : "baseURL + '/Roo/events.php'",
2488                                             "method" : "GET",
2489                                             "xtype" : "HttpProxy",
2490                                             "$ xns" : "Roo.data",
2491                                             "* prop" : "proxy"
2492                                         },
2493                                         {
2494                                             "id" : "id",
2495                                             "root" : "data",
2496                                             "xtype" : "JsonReader",
2497                                             "$ fields" : "[\n    {\n        'name': 'event_when',\n        'type': 'date'\n    },\n    {\n        'name': 'action',\n        'type': 'string'\n    },\n    {\n        'name': 'ipaddr',\n        'type': 'string'\n    },\n    {\n        'name': 'person_id_name',\n        'type': 'string'\n    },\n    {\n        'name': 'remarks',\n        'type': 'string'\n    }\n]",
2498                                             "$ xns" : "Roo.data",
2499                                             "* prop" : "reader",
2500                                             "# builderCfg" : "{\"cols\":[{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"},{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}],\"cols_ex\":[\"remarks\"],\"table\":\"events\",\"xtype\":\"GridPanel\",\"|xns\":\"Roo\"}",
2501                                             "totalProperty" : "total"
2502                                         }
2503                                     ]
2504                                 },
2505                                 {
2506                                     "pageSize" : 25,
2507                                     "xtype" : "PagingToolbar",
2508                                     "emptyMsg" : "No events found",
2509                                     "$ xns" : "Roo",
2510                                     "displayInfo" : true,
2511                                     "displayMsg" : "Displaying events{0} - {1} of {2}",
2512                                     "* prop" : "footer"
2513                                 },
2514                                 {
2515                                     "xtype" : "ColumnModel",
2516                                     "header" : "Changed",
2517                                     "width" : 120,
2518                                     "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }",
2519                                     "$ xns" : "Roo.grid",
2520                                     "* prop" : "colModel[]",
2521                                     "dataIndex" : "event_when",
2522                                     "# builderCfg" : "{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2523                                 },
2524                                 {
2525                                     "xtype" : "ColumnModel",
2526                                     "header" : "action",
2527                                     "width" : 120,
2528                                     "$ renderer" : "function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }",
2529                                     "$ xns" : "Roo.grid",
2530                                     "* prop" : "colModel[]",
2531                                     "dataIndex" : "action",
2532                                     "# builderCfg" : "{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2533                                 },
2534                                 {
2535                                     "xtype" : "ColumnModel",
2536                                     "header" : "IP address",
2537                                     "width" : 120,
2538                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2539                                     "$ xns" : "Roo.grid",
2540                                     "* prop" : "colModel[]",
2541                                     "dataIndex" : "ipaddr",
2542                                     "# builderCfg" : "{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2543                                 },
2544                                 {
2545                                     "xtype" : "ColumnModel",
2546                                     "header" : "Who",
2547                                     "width" : 120,
2548                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2549                                     "$ xns" : "Roo.grid",
2550                                     "* prop" : "colModel[]",
2551                                     "dataIndex" : "person_id_name",
2552                                     "# builderCfg" : "{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2553                                 },
2554                                 {
2555                                     "xtype" : "ColumnModel",
2556                                     "header" : "Notes",
2557                                     "width" : 200,
2558                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2559                                     "$ xns" : "Roo.grid",
2560                                     "* prop" : "colModel[]",
2561                                     "dataIndex" : "remarks",
2562                                     "# builderCfg" : "{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}"
2563                                 }
2564                             ]
2565                         }
2566                     ]
2567                 },
2568                 {
2569                     "region" : "center",
2570                     "xtype" : "NestedLayoutPanel",
2571                     "title" : "Stock Tx",
2572                     "$ xns" : "Roo",
2573                     "items" : [
2574                         {
2575                             "xtype" : "BorderLayout",
2576                             "$ xns" : "Roo",
2577                             "* prop" : "layout",
2578                             "items" : [
2579                                 {
2580                                     "xtype" : "LayoutRegion",
2581                                     "$ xns" : "Roo",
2582                                     "* prop" : "center"
2583                                 },
2584                                 {
2585                                     "xtype" : "LayoutRegion",
2586                                     "width" : 500,
2587                                     "$ xns" : "Roo",
2588                                     "split" : true,
2589                                     "* prop" : "east"
2590                                 },
2591                                 {
2592                                     "listeners" : {
2593                                         "|activate" : "function() {\n    _this.txpanel = this;\n    if (_this.txgrid) {\n        _this.txgrid.footer.onClick('first');\n    }\n}"
2594                                     },
2595                                     "fitToframe" : true,
2596                                     "background" : false,
2597                                     "region" : "center",
2598                                     "title" : "invdetail",
2599                                     "xtype" : "GridPanel",
2600                                     "fitContainer" : true,
2601                                     "$ xns" : "Roo",
2602                                     "tableName" : "invdetail",
2603                                     "items" : [
2604                                         {
2605                                             "listeners" : {
2606                                                 "|render" : "function() \n{\n    _this.txgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.txpanel.active) {\n       this.footer.onClick('first');\n    }\n}"
2607                                             },
2608                                             "autoExpandColumn" : "item_number",
2609                                             "xtype" : "Grid",
2610                                             "loadMask" : true,
2611                                             "$ xns" : "Roo.grid",
2612                                             "* prop" : "grid",
2613                                             "items" : [
2614                                                 {
2615                                                     "xtype" : "Toolbar",
2616                                                     "$ xns" : "Roo",
2617                                                     "* prop" : "toolbar",
2618                                                     "items" : [
2619                                                         {
2620                                                             "listeners" : {
2621                                                                 "click" : "function (_self, e)\n{\n    new Pman.Request({\n        mask : 'applying',\n        url : baseURL + '/Roo/Cohead',\n        method : 'GET',\n        params : {\n            _apply_fifo : _this.form.findField('cohead_id').getValue()\n        },\n        success : function () {\n            Roo.MessageBox.alert(\"Applied\", \"Succesfully Applied\");\n        }\n    });\n}"
2622                                                             },
2623                                                             "text" : "Run Apply Fifo on order",
2624                                                             "xtype" : "Button",
2625                                                             "$ xns" : "Roo.Toolbar"
2626                                                         },
2627                                                         {
2628                                                             "listeners" : {
2629                                                                 "click" : "function (_self, e)\n{\n    new Pman.Request({\n        mask : 'running',\n        url : baseURL + '/Roo/Cohead',\n        method : 'GET',\n        params : {\n            _run_void_fix : _this.form.findField('cohead_id').getValue()\n        },\n        success : function () {\n            Roo.MessageBox.alert(\"Applied\", \"Succesfully Run\");\n        }\n    });\n}"
2630                                                             },
2631                                                             "text" : "Run Void flagger",
2632                                                             "xtype" : "Button",
2633                                                             "$ xns" : "Roo.Toolbar"
2634                                                         },
2635                                                         {
2636                                                             "listeners" : {
2637                                                                 "click" : "function (_self, e)\n{\n    new Pman.Download({\n        newWindow : true,\n        mask : 'running',\n        url : baseURL + '/Roo/Invdetail',\n        method : 'GET',\n        timeout :90000,\n        params : {\n            _post : 1,\n            _reverse_all_bad : _this.form.findField('cohead_id').getValue()\n        },\n        success : function () {\n            Roo.MessageBox.alert(\"Applied\", \"Succesfully Run\");\n        }\n    });\n}"
2638                                                             },
2639                                                             "text" : "Auto Reverse",
2640                                                             "xtype" : "Button",
2641                                                             "$ xns" : "Roo.Toolbar"
2642                                                         }
2643                                                     ]
2644                                                 },
2645                                                 {
2646                                                     "listeners" : {
2647                                                         "selectionchange" : "function (_self)\n{\n    _this.txdgrid.footer.onClick('first');;\n}"
2648                                                     },
2649                                                     "xtype" : "RowSelectionModel",
2650                                                     "singleSelect" : true,
2651                                                     "$ xns" : "Roo.grid",
2652                                                     "* prop" : "sm"
2653                                                 },
2654                                                 {
2655                                                     "listeners" : {
2656                                                         "beforeload" : "function (_self, o)\n{\n    o.params.cohead_id = _this.form.findField('cohead_id').getValue();\n    if (! o.params.cohead_id ) {\n        this.removeAll();\n        return false;\n    }\n}"
2657                                                     },
2658                                                     "xtype" : "Store",
2659                                                     "remoteSort" : true,
2660                                                     "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
2661                                                     "$ xns" : "Roo.data",
2662                                                     "* prop" : "dataSource",
2663                                                     "items" : [
2664                                                         {
2665                                                             "$ url" : "baseURL + '/Roo/invdetail.php'",
2666                                                             "xtype" : "HttpProxy",
2667                                                             "method" : "GET",
2668                                                             "$ xns" : "Roo.data",
2669                                                             "* prop" : "proxy"
2670                                                         },
2671                                                         {
2672                                                             "id" : "id",
2673                                                             "root" : "data",
2674                                                             "xtype" : "JsonReader",
2675                                                             "$ xns" : "Roo.data",
2676                                                             "$ fields" : "[\n    {\n        'name': 'invdetail_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_transtype',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_invhist_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_location_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_qty',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_comments',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_qty_before',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_qty_after',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_invcitem_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_expiration',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_warrpurc',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_ls_id',\n        'type': 'int'\n    }\n]",
2677                                                             "* prop" : "reader",
2678                                                             "totalProperty" : "total"
2679                                                         }
2680                                                     ]
2681                                                 },
2682                                                 {
2683                                                     "pageSize" : 9999,
2684                                                     "xtype" : "PagingToolbar",
2685                                                     "emptyMsg" : "No invdetail found",
2686                                                     "$ xns" : "Roo",
2687                                                     "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
2688                                                     "displayInfo" : true,
2689                                                     "* prop" : "footer"
2690                                                 },
2691                                                 {
2692                                                     "xtype" : "ColumnModel",
2693                                                     "header" : "Item",
2694                                                     "width" : 75,
2695                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2696                                                     "$ xns" : "Roo.grid",
2697                                                     "* prop" : "colModel[]",
2698                                                     "dataIndex" : "item_number"
2699                                                 },
2700                                                 {
2701                                                     "align" : "right",
2702                                                     "xtype" : "ColumnModel",
2703                                                     "header" : "#Ship",
2704                                                     "width" : 50,
2705                                                     "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2706                                                     "$ xns" : "Roo.grid",
2707                                                     "* prop" : "colModel[]",
2708                                                     "dataIndex" : "rec_shipped"
2709                                                 },
2710                                                 {
2711                                                     "align" : "right",
2712                                                     "xtype" : "ColumnModel",
2713                                                     "header" : "#Ret",
2714                                                     "width" : 50,
2715                                                     "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
2716                                                     "$ xns" : "Roo.grid",
2717                                                     "* prop" : "colModel[]",
2718                                                     "dataIndex" : "rec_returned"
2719                                                 },
2720                                                 {
2721                                                     "align" : "right",
2722                                                     "xtype" : "ColumnModel",
2723                                                     "header" : "#TX ship",
2724                                                     "width" : 50,
2725                                                     "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2726                                                     "$ xns" : "Roo.grid",
2727                                                     "* prop" : "colModel[]",
2728                                                     "dataIndex" : "tx_shipped"
2729                                                 },
2730                                                 {
2731                                                     "align" : "right",
2732                                                     "xtype" : "ColumnModel",
2733                                                     "header" : "#TX ret",
2734                                                     "width" : 50,
2735                                                     "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2736                                                     "$ xns" : "Roo.grid",
2737                                                     "* prop" : "colModel[]",
2738                                                     "dataIndex" : "tx_returned"
2739                                                 },
2740                                                 {
2741                                                     "align" : "right",
2742                                                     "xtype" : "ColumnModel",
2743                                                     "header" : "#TX Tot",
2744                                                     "width" : 50,
2745                                                     "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
2746                                                     "$ xns" : "Roo.grid",
2747                                                     "* prop" : "colModel[]",
2748                                                     "dataIndex" : "tx_total"
2749                                                 },
2750                                                 {
2751                                                     "align" : "right",
2752                                                     "xtype" : "ColumnModel",
2753                                                     "header" : "Value",
2754                                                     "width" : 50,
2755                                                     "$ renderer" : "function(v,x,r) { \n\n    return (v*1).toFixed(3);\n}",
2756                                                     "$ xns" : "Roo.grid",
2757                                                     "* prop" : "colModel[]",
2758                                                     "dataIndex" : "total_value"
2759                                                 },
2760                                                 {
2761                                                     "align" : "right",
2762                                                     "xtype" : "ColumnModel",
2763                                                     "header" : "#Diff",
2764                                                     "width" : 50,
2765                                                     "$ renderer" : "function(v,x,r) { \n\n    var cototal = (r.data.rec_returned*1) - (r.data.rec_shipped*1);\n//    Roo.log(cototal);\n    var diff = (v*1) - cototal;\n //   Roo.log(diff);\n    if (diff == 0)  {\n        return '';\n    }\n    return String.format('<span style=\"color:red\">{0}</span>',  diff ); \n    }",
2766                                                     "$ xns" : "Roo.grid",
2767                                                     "* prop" : "colModel[]",
2768                                                     "dataIndex" : "tx_total"
2769                                                 }
2770                                             ]
2771                                         }
2772                                     ]
2773                                 },
2774                                 {
2775                                     "listeners" : {
2776                                         "|activate" : "function() {\n    _this.txdpanel = this;\n    if (_this.txdgrid) {\n        _this.txdgrid.footer.onClick('first');\n    }\n}"
2777                                     },
2778                                     "fitToframe" : true,
2779                                     "background" : false,
2780                                     "region" : "east",
2781                                     "title" : "invdetail",
2782                                     "xtype" : "GridPanel",
2783                                     "fitContainer" : true,
2784                                     "$ xns" : "Roo",
2785                                     "tableName" : "invdetail",
2786                                     "items" : [
2787                                         {
2788                                             "listeners" : {
2789                                                 "|render" : "function() \n{\n    _this.txdgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.txdpanel.active) {\n       this.footer.onClick('first');\n    }\n}",
2790                                                 "rowclick" : "function (_self, rowIndex, e)\n{\n    var s = _this.txdgrid.ds.getAt(rowIndex);\n    var dt = s.data.invhist_transdate.split(' ');\n    \n    _this.dateSel.setValue(new Date(dt[0]));\n}"
2791                                             },
2792                                             "autoExpandColumn" : "invhist_comments",
2793                                             "xtype" : "Grid",
2794                                             "loadMask" : true,
2795                                             "$ xns" : "Roo.grid",
2796                                             "* prop" : "grid",
2797                                             "items" : [
2798                                                 {
2799                                                     "xtype" : "Toolbar",
2800                                                     "$ xns" : "Roo",
2801                                                     "* prop" : "toolbar",
2802                                                     "items" : [
2803                                                         {
2804                                                             "listeners" : {
2805                                                                 "click" : "function (_self, e)\n{\n    var s = _this.txdgrid.selModel.getSelected();\n\n    if (!s) {\n        Roo.MessageBox.alert(\"Error\", \"Select a transaction\");\n        return;\n    }\n    \n    var reverseSel = function() {\n    \n        new Pman.Request({\n            mask : \"Reversing\",\n            url : baseURL + '/Roo/invdetail',\n            method : 'POST',\n            params : {\n                _duplicate : s.data.invdetail_id\n            }, \n            success : function() {\n                _this.txdgrid.footer.onClick('first');\n            }\n        });\n    \n    }\n    \n    \n\n    Roo.MessageBox.confirm(\n        \"Confirm\", \n        \"This should only be used by System Administrators - are you sure you know what you are doing!\",\n        function(x) {\n            if (x != 'yes') {\n                return;\n            }\n            reverseSel();\n        }\n    );\n                        \n    \n    \n    \n}"
2806                                                             },
2807                                                             "text" : "Duplicate Selected",
2808                                                             "xtype" : "Button",
2809                                                             "$ xns" : "Roo.Toolbar"
2810                                                         },
2811                                                         {
2812                                                             "xtype" : "Fill",
2813                                                             "$ xns" : "Roo.Toolbar"
2814                                                         },
2815                                                         {
2816                                                             "text" : "Issue Date",
2817                                                             "xtype" : "TextItem",
2818                                                             "$ xns" : "Roo.Toolbar"
2819                                                         },
2820                                                         {
2821                                                             "listeners" : {
2822                                                                 "render" : "function (_self)\n{\n    _this.dateSel = _self;\n}"
2823                                                             },
2824                                                             "format" : "Y-m-d",
2825                                                             "fieldLabel" : "Issue Date",
2826                                                             "xtype" : "DateField",
2827                                                             "allowBlank" : false,
2828                                                             "width" : 150,
2829                                                             "$ xns" : "Roo.form",
2830                                                             "name" : "issue_date"
2831                                                         },
2832                                                         {
2833                                                             "listeners" : {
2834                                                                 "click" : "function (_self, e)\n{\n    var s = _this.txdgrid.selModel.getSelected();\n    var dt = _this.dateSel.getValue();\n    if (!s) {\n        Roo.MessageBox.alert(\"Error\", \"Select a transaction\");\n        return;\n    }\n    \n    var reverseSel = function(force) {\n    \n        new Pman.Request({\n            mask : \"Reversing\",\n            url : baseURL + '/Roo/invdetail',\n            method : 'POST',\n            params : {\n                _reverse : s.data.invdetail_id,\n                _as_of : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),\n                _force : force\n            }, \n            success : function() {\n                _this.txdgrid.footer.onClick('first');\n            },\n            failure : function(res) {\n                Roo.log(res);\n                try {\n                    if (res.errors.confirm) {\n                                      \n                        Roo.MessageBox.confirm(\n                            \"Confirm\", \n                            \"are you really sure the totals will get messed up.\",\n                            function(x) {\n                                if (x != 'yes') {\n                                    return;\n                                }\n                                reverseSel(1);\n                            }\n                        );\n                        return;\n                    }\n                } catch(e) { }\n                Roo.MessageBox.alert(\"Error\", res.errorMsg);\n                \n                \n            }\n        });\n    \n    }\n    \n    \n\n    Roo.MessageBox.confirm(\n        \"Confirm\", \n        \"This should only be used by System Administrators - are you sure you know what you are doing!\",\n        function(x) {\n            if (x != 'yes') {\n                return;\n            }\n            reverseSel(0);\n        }\n    );\n                        \n    \n    \n    \n}"
2835                                                             },
2836                                                             "text" : "Reverse Selected",
2837                                                             "xtype" : "Button",
2838                                                             "$ xns" : "Roo.Toolbar"
2839                                                         }
2840                                                     ]
2841                                                 },
2842                                                 {
2843                                                     "listeners" : {
2844                                                         "beforeload" : "function (_self, o)\n{\n    o.params.cohead_id = _this.form.findField('cohead_id').getValue();\n    var s = _this.txgrid.selModel.getSelected();\n    if (!s) { \n        this.removeAll();\n        return false;\n    }\n    o.params.itemsite_id = s.data.invhist_itemsite_id;\n    \n}"
2845                                                     },
2846                                                     "xtype" : "Store",
2847                                                     "remoteSort" : true,
2848                                                     "$ sortInfo" : "{ field : 'invdetail_id', direction: 'ASC' }",
2849                                                     "$ xns" : "Roo.data",
2850                                                     "* prop" : "dataSource",
2851                                                     "items" : [
2852                                                         {
2853                                                             "$ url" : "baseURL + '/Roo/invdetail.php'",
2854                                                             "xtype" : "HttpProxy",
2855                                                             "method" : "GET",
2856                                                             "$ xns" : "Roo.data",
2857                                                             "* prop" : "proxy"
2858                                                         },
2859                                                         {
2860                                                             "id" : "id",
2861                                                             "root" : "data",
2862                                                             "xtype" : "JsonReader",
2863                                                             "$ xns" : "Roo.data",
2864                                                             "$ fields" : "[\n    {\n        'name': 'invdetail_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_transtype',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_invhist_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_location_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_qty',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_comments',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_qty_before',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_qty_after',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_invcitem_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_expiration',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_warrpurc',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_ls_id',\n        'type': 'int'\n    }\n]",
2865                                                             "* prop" : "reader",
2866                                                             "totalProperty" : "total"
2867                                                         }
2868                                                     ]
2869                                                 },
2870                                                 {
2871                                                     "pageSize" : 9999,
2872                                                     "xtype" : "PagingToolbar",
2873                                                     "emptyMsg" : "No invdetail found",
2874                                                     "$ xns" : "Roo",
2875                                                     "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
2876                                                     "displayInfo" : true,
2877                                                     "* prop" : "footer"
2878                                                 },
2879                                                 {
2880                                                     "xtype" : "ColumnModel",
2881                                                     "header" : "TX#",
2882                                                     "width" : 60,
2883                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2884                                                     "$ xns" : "Roo.grid",
2885                                                     "* prop" : "colModel[]",
2886                                                     "dataIndex" : "invdetail_id"
2887                                                 },
2888                                                 {
2889                                                     "xtype" : "ColumnModel",
2890                                                     "header" : "Date",
2891                                                     "width" : 75,
2892                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2893                                                     "$ xns" : "Roo.grid",
2894                                                     "* prop" : "colModel[]",
2895                                                     "dataIndex" : "invhist_transdate"
2896                                                 },
2897                                                 {
2898                                                     "xtype" : "ColumnModel",
2899                                                     "header" : "Ref#",
2900                                                     "width" : 75,
2901                                                     "$ renderer" : "function(v,x,r) {\n    if (r.data.invfifo_void *1 != 0) {\n        return String.format('<s>{0}</s>', v); \n    }\n\n     return String.format('{0}', v); \n }",
2902                                                     "$ xns" : "Roo.grid",
2903                                                     "* prop" : "colModel[]",
2904                                                     "dataIndex" : "invhist_ordnumber"
2905                                                 },
2906                                                 {
2907                                                     "xtype" : "ColumnModel",
2908                                                     "header" : "TX#",
2909                                                     "width" : 60,
2910                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2911                                                     "$ xns" : "Roo.grid",
2912                                                     "* prop" : "colModel[]",
2913                                                     "dataIndex" : "location_name"
2914                                                 },
2915                                                 {
2916                                                     "xtype" : "ColumnModel",
2917                                                     "header" : "Notes",
2918                                                     "width" : 75,
2919                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
2920                                                     "$ xns" : "Roo.grid",
2921                                                     "* prop" : "colModel[]",
2922                                                     "dataIndex" : "invhist_comments"
2923                                                 },
2924                                                 {
2925                                                     "align" : "right",
2926                                                     "xtype" : "ColumnModel",
2927                                                     "header" : "Qty Changed",
2928                                                     "width" : 50,
2929                                                     "$ renderer" : "function(v,x,r) {\n    if ( r.data.coitem_shipped != v) {\n        return String.format('{0} <span style=\"color:red\">({1})</span>',\n             Roo.util.Format.number(v,0),\n             r.data.coitem_shipped\n         );\n    \n    }\n     return String.format('{0}', Roo.util.Format.number(v,0));\n}",
2930                                                     "$ xns" : "Roo.grid",
2931                                                     "* prop" : "colModel[]",
2932                                                     "dataIndex" : "invdetail_qty"
2933                                                 },
2934                                                 {
2935                                                     "align" : "right",
2936                                                     "xtype" : "ColumnModel",
2937                                                     "header" : "Qty Changed",
2938                                                     "width" : 75,
2939                                                     "$ renderer" : "function(v,x,r) {\n    var tot = r.data.invhist_value_after*1 - v*1;\n    var f = '{0}';\n    if (r.data.invdetail_qty >0 && tot < 0) {\n        f = '<span style=\"color:red\">{0}</span>';\n    }\n    if (r.data.invdetail_qty < 0 && tot > 0) {\n        f = '<span style=\"color:red\">{0}</span>';\n    }    \n    return String.format(f, Roo.util.Format.number(tot));\n}",
2940                                                     "$ xns" : "Roo.grid",
2941                                                     "* prop" : "colModel[]",
2942                                                     "dataIndex" : "invhist_value_before"
2943                                                 },
2944                                                 {
2945                                                     "xtype" : "ColumnModel",
2946                                                     "header" : "Posted",
2947                                                     "width" : 40,
2948                                                     "$ renderer" : "function(v,x,r) { \n    \n    var state = v   ?  '-checked' : '';\n                                    \n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }",
2949                                                     "$ xns" : "Roo.grid",
2950                                                     "* prop" : "colModel[]",
2951                                                     "dataIndex" : "invhist_posted"
2952                                                 }
2953                                             ]
2954                                         }
2955                                     ]
2956                                 }
2957                             ]
2958                         }
2959                     ]
2960                 },
2961                 {
2962                     "region" : "center",
2963                     "xtype" : "NestedLayoutPanel",
2964                     "title" : "GL Tx",
2965                     "$ xns" : "Roo",
2966                     "items" : [
2967                         {
2968                             "xtype" : "BorderLayout",
2969                             "$ xns" : "Roo",
2970                             "* prop" : "layout",
2971                             "items" : [
2972                                 {
2973                                     "xtype" : "LayoutRegion",
2974                                     "$ xns" : "Roo",
2975                                     "* prop" : "center"
2976                                 },
2977                                 {
2978                                     "xtype" : "LayoutRegion",
2979                                     "width" : 500,
2980                                     "$ xns" : "Roo",
2981                                     "split" : true,
2982                                     "* prop" : "east"
2983                                 },
2984                                 {
2985                                     "listeners" : {
2986                                         "|activate" : "function() {\n    _this.gltxpanel = this;\n    if (_this.gltxgrid) {\n        _this.gltxgrid.footer.onClick('first');\n    }\n}"
2987                                     },
2988                                     "fitToframe" : true,
2989                                     "background" : false,
2990                                     "region" : "center",
2991                                     "title" : "invdetail",
2992                                     "xtype" : "GridPanel",
2993                                     "fitContainer" : true,
2994                                     "$ xns" : "Roo",
2995                                     "tableName" : "invdetail",
2996                                     "items" : [
2997                                         {
2998                                             "listeners" : {
2999                                                 "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    if (columnIndex > 0) {\n        return;\n    }\n    var rec = this.ds.getAt(rowIndex);\n    rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);\n    _this.gltxdgrid.footer.onClick('first');\n}",
3000                                                 "|render" : "function() \n{\n    _this.gltxgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.gltxpanel.active) {\n       this.footer.onClick('first');\n    }\n}"
3001                                             },
3002                                             "autoExpandColumn" : "gltrans_accnt_id_accnt_descrip",
3003                                             "xtype" : "Grid",
3004                                             "loadMask" : true,
3005                                             "$ xns" : "Roo.grid",
3006                                             "* prop" : "grid",
3007                                             "items" : [
3008                                                 {
3009                                                     "listeners" : {
3010                                                         "selectionchange" : "function (_self)\n{\n    _this.gltxdgrid.footer.onClick('first');;\n}"
3011                                                     },
3012                                                     "xtype" : "RowSelectionModel",
3013                                                     "singleSelect" : true,
3014                                                     "$ xns" : "Roo.grid",
3015                                                     "* prop" : "sm"
3016                                                 },
3017                                                 {
3018                                                     "listeners" : {
3019                                                         "beforeload" : "function (_self, o)\n{\n    o.params.cohead_id = _this.form.findField('cohead_id').getValue();\n    if (! o.params.cohead_id ) {\n        this.removeAll();\n        return false;\n    }\n    o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;\n}"
3020                                                     },
3021                                                     "xtype" : "Store",
3022                                                     "remoteSort" : true,
3023                                                     "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
3024                                                     "$ xns" : "Roo.data",
3025                                                     "* prop" : "dataSource",
3026                                                     "items" : [
3027                                                         {
3028                                                             "$ url" : "baseURL + '/Roo/gltrans.php'",
3029                                                             "xtype" : "HttpProxy",
3030                                                             "method" : "GET",
3031                                                             "$ xns" : "Roo.data",
3032                                                             "* prop" : "proxy"
3033                                                         },
3034                                                         {
3035                                                             "id" : "id",
3036                                                             "root" : "data",
3037                                                             "xtype" : "JsonReader",
3038                                                             "$ xns" : "Roo.data",
3039                                                             "$ fields" : "[\n    {\n        'name': 'invdetail_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_transtype',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_invhist_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_location_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_qty',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_comments',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_qty_before',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_qty_after',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_invcitem_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_expiration',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_warrpurc',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_ls_id',\n        'type': 'int'\n    }\n]",
3040                                                             "* prop" : "reader",
3041                                                             "totalProperty" : "total"
3042                                                         }
3043                                                     ]
3044                                                 },
3045                                                 {
3046                                                     "pageSize" : 9999,
3047                                                     "xtype" : "PagingToolbar",
3048                                                     "emptyMsg" : "No invdetail found",
3049                                                     "$ xns" : "Roo",
3050                                                     "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
3051                                                     "displayInfo" : true,
3052                                                     "* prop" : "footer",
3053                                                     "items" : [
3054                                                         {
3055                                                             "listeners" : {
3056                                                                 "render" : "function (_self)\n{\n    _this.glsalesbtn = _self;\n}",
3057                                                                 "click" : "function (_self, e)\n{\n    (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);\n}"
3058                                                             },
3059                                                             "text" : "Split sales",
3060                                                             "enableToggle" : true,
3061                                                             "pressed" : true,
3062                                                             "xtype" : "Button",
3063                                                             "$ xns" : "Roo.Toolbar"
3064                                                         }
3065                                                     ]
3066                                                 },
3067                                                 {
3068                                                     "xtype" : "ColumnModel",
3069                                                     "header" : "Summary",
3070                                                     "width" : 50,
3071                                                     "$ renderer" : "function(v,x,r) { \n    \n    var state = v*1   ?  '-checked' : '';\n                                    \n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }",
3072                                                     "$ xns" : "Roo.grid",
3073                                                     "* prop" : "colModel[]",
3074                                                     "dataIndex" : "gltrans_as_summary"
3075                                                 },
3076                                                 {
3077                                                     "xtype" : "ColumnModel",
3078                                                     "header" : "Account",
3079                                                     "width" : 75,
3080                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
3081                                                     "$ xns" : "Roo.grid",
3082                                                     "* prop" : "colModel[]",
3083                                                     "dataIndex" : "gltrans_accnt_id_accnt_descrip"
3084                                                 },
3085                                                 {
3086                                                     "align" : "right",
3087                                                     "xtype" : "ColumnModel",
3088                                                     "header" : "Credit",
3089                                                     "width" : 75,
3090                                                     "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }",
3091                                                     "$ xns" : "Roo.grid",
3092                                                     "* prop" : "colModel[]",
3093                                                     "dataIndex" : "gltrans_amount_credit"
3094                                                 },
3095                                                 {
3096                                                     "align" : "right",
3097                                                     "xtype" : "ColumnModel",
3098                                                     "header" : "Debit",
3099                                                     "width" : 75,
3100                                                     "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
3101                                                     "$ xns" : "Roo.grid",
3102                                                     "* prop" : "colModel[]",
3103                                                     "dataIndex" : "gltrans_amount_debit"
3104                                                 },
3105                                                 {
3106                                                     "align" : "right",
3107                                                     "xtype" : "ColumnModel",
3108                                                     "header" : "Sum",
3109                                                     "width" : 75,
3110                                                     "$ renderer" : "function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }",
3111                                                     "$ xns" : "Roo.grid",
3112                                                     "* prop" : "colModel[]",
3113                                                     "dataIndex" : "gltrans_amount_total"
3114                                                 },
3115                                                 {
3116                                                     "align" : "right",
3117                                                     "xtype" : "ColumnModel",
3118                                                     "header" : "Unposted",
3119                                                     "width" : 75,
3120                                                     "$ renderer" : "function(v) { return String.format('<span style=\"color:red\">{0}</span>', Roo.util.Format.number(v,3)); }",
3121                                                     "$ xns" : "Roo.grid",
3122                                                     "* prop" : "colModel[]",
3123                                                     "dataIndex" : "gltrans_amount_total_unposted"
3124                                                 }
3125                                             ]
3126                                         }
3127                                     ]
3128                                 },
3129                                 {
3130                                     "listeners" : {
3131                                         "|activate" : "function() {\n    _this.gltxdpanel = this;\n    if (_this.gltxdgrid) {\n        _this.gltxdgrid.footer.onClick('first');\n    }\n}"
3132                                     },
3133                                     "fitToframe" : true,
3134                                     "background" : false,
3135                                     "region" : "east",
3136                                     "title" : "invdetail",
3137                                     "xtype" : "GridPanel",
3138                                     "fitContainer" : true,
3139                                     "$ xns" : "Roo",
3140                                     "tableName" : "invdetail",
3141                                     "items" : [
3142                                         {
3143                                             "listeners" : {
3144                                                 "cellclick" : "function (_self, ri, ci, e)\n{\n    \n      var deleteSel = function() {\n    \n        new Pman.Request({\n            mask : \"Reversing\",\n            url : baseURL + '/Roo/gltrans',\n            method : 'POST',\n            params : {  \n                _void : 1,\n                gltrans_id : rec.data.gltrans_id\n                \n            }, \n            success : function() {\n                rec.set('gltrans_posted', false);\n                rec.set('gltrans_deleted', true);\n                rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);\n               _this.gltxgrid.footer.onClick('first');\n            }\n        });\n    \n    }\n    var undeleteSel = function() {\n    \n        new Pman.Request({\n            mask : \"Reversing\",\n            url : baseURL + '/Roo/gltrans',\n            method : 'POST',\n            params : {  \n                _unvoid : 1,\n                gltrans_id : rec.data.gltrans_id\n                \n            }, \n            success : function() {\n                rec.set('gltrans_posted', true);\n                rec.set('gltrans_deleted', false);\n                rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);\n               _this.gltxgrid.footer.onClick('first');\n            }\n        });\n    \n    }\n    \n    var di = this.colModel.config[ci].dataIndex;\n    if (di != 'gltrans_posted') {\n        return;\n    }\n    \n    \n    \n    var rec = this.ds.getAt(ri);\n    if (rec.data.gltrans_deleted) {\n    \n         Roo.MessageBox.confirm(\n            \"Confirm\", \n            \"This should only be used by System Administrators - are you sure you know what you are doing!\",\n            function(x) {\n                if (x != 'yes') {\n                    return;\n                }\n                undeleteSel();\n            }\n        );\n    \n        return false;\n    }\n\n    \n    \n    if (!rec.data.gltrans_posted) {\n\n        \n        \n        new Pman.Request({\n            method : 'POST',\n            url : baseURL + '/Roo/gltrans',\n            mask : \"Posting\",\n            params : {\n                _post : 1,\n                gltrans_id : rec.data.gltrans_id\n            },\n            success : function (res)\n            {\n                rec.set('gltrans_posted', true);\n                _this.gltxgrid.footer.onClick('first');\n            \n            }\n        \n        \n        });\n        return;\n    }\n    \n    // we have a posted transaction.\n    // only allow recalled to be deleted..\n    if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {\n        return false;\n    }\n    \n    \n \n    \n    \n\n    Roo.MessageBox.confirm(\n        \"Confirm\", \n        \"This should only be used by System Administrators - are you sure you know what you are doing!\",\n        function(x) {\n            if (x != 'yes') {\n                return;\n            }\n            deleteSel();\n        }\n    );\n          \n    \n    \n}",
3145                                                 "|render" : "function() \n{\n    _this.gltxdgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.gltxdpanel.active) {\n       this.footer.onClick('first');\n    }\n}"
3146                                             },
3147                                             "autoExpandColumn" : "gltrans_notes",
3148                                             "xtype" : "Grid",
3149                                             "loadMask" : true,
3150                                             "$ xns" : "Roo.grid",
3151                                             "* prop" : "grid",
3152                                             "items" : [
3153                                                 {
3154                                                     "listeners" : {
3155                                                         "beforeload" : "function (_self, o)\n{\n    o.params.cohead_id = _this.form.findField('cohead_id').getValue();\n    var s = _this.gltxgrid.selModel.getSelected();\n    if (!s) { \n        this.removeAll();\n        return false;\n    }\n    o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;\n    o.params.gltrans_is_ship = s.data.gltrans_is_ship;\n    o.params.gltrans_as_summary =     s.data.gltrans_as_summary;\n    \n    \n}"
3156                                                     },
3157                                                     "xtype" : "Store",
3158                                                     "remoteSort" : true,
3159                                                     "$ sortInfo" : "{ field : 'gltrans_docnumber', direction: 'ASC' }",
3160                                                     "$ xns" : "Roo.data",
3161                                                     "* prop" : "dataSource",
3162                                                     "items" : [
3163                                                         {
3164                                                             "$ url" : "baseURL + '/Roo/gltrans.php'",
3165                                                             "xtype" : "HttpProxy",
3166                                                             "method" : "GET",
3167                                                             "$ xns" : "Roo.data",
3168                                                             "* prop" : "proxy"
3169                                                         },
3170                                                         {
3171                                                             "id" : "id",
3172                                                             "root" : "data",
3173                                                             "xtype" : "JsonReader",
3174                                                             "$ xns" : "Roo.data",
3175                                                             "$ fields" : "[\n    {\n        'name': 'invdetail_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_transtype',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_invhist_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_location_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_qty',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_comments',\n        'type': 'string'\n    },\n    {\n        'name': 'invdetail_qty_before',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_qty_after',\n        'type': 'float'\n    },\n    {\n        'name': 'invdetail_invcitem_id',\n        'type': 'int'\n    },\n    {\n        'name': 'invdetail_expiration',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_warrpurc',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'invdetail_ls_id',\n        'type': 'int'\n    }\n]",
3176                                                             "* prop" : "reader",
3177                                                             "totalProperty" : "total"
3178                                                         }
3179                                                     ]
3180                                                 },
3181                                                 {
3182                                                     "pageSize" : 9999,
3183                                                     "xtype" : "PagingToolbar",
3184                                                     "emptyMsg" : "No invdetail found",
3185                                                     "$ xns" : "Roo",
3186                                                     "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
3187                                                     "displayInfo" : true,
3188                                                     "* prop" : "footer",
3189                                                     "items" : [
3190                                                         {
3191                                                             "listeners" : {
3192                                                                 "click" : "function (_self, e)\n{\n    new Pman.Download( {\n        grid : _this.gltxdgrid\n    \n    });\n}"
3193                                                             },
3194                                                             "text" : "Download",
3195                                                             "xtype" : "Button",
3196                                                             "$ xns" : "Roo.Toolbar"
3197                                                         }
3198                                                     ]
3199                                                 },
3200                                                 {
3201                                                     "xtype" : "ColumnModel",
3202                                                     "sortable" : true,
3203                                                     "header" : "Ref#",
3204                                                     "width" : 75,
3205                                                     "$ renderer" : "function(v) { return String.format('{0}', v ); }",
3206                                                     "$ xns" : "Roo.grid",
3207                                                     "* prop" : "colModel[]",
3208                                                     "dataIndex" : "gltrans_id"
3209                                                 },
3210                                                 {
3211                                                     "xtype" : "ColumnModel",
3212                                                     "header" : "Date",
3213                                                     "width" : 75,
3214                                                     "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
3215                                                     "$ xns" : "Roo.grid",
3216                                                     "* prop" : "colModel[]",
3217                                                     "dataIndex" : "gltrans_date"
3218                                                 },
3219                                                 {
3220                                                     "xtype" : "ColumnModel",
3221                                                     "header" : "Doc#",
3222                                                     "width" : 75,
3223                                                     "$ renderer" : "function(v,x,r) { \n    if (r.data.gltrans_deleted) {\n       return String.format('<s>{0}</s>', v);     \n    }\n    return String.format('{0}', v); \n}",
3224                                                     "$ xns" : "Roo.grid",
3225                                                     "* prop" : "colModel[]",
3226                                                     "dataIndex" : "gltrans_docnumber"
3227                                                 },
3228                                                 {
3229                                                     "xtype" : "ColumnModel",
3230                                                     "header" : "Source",
3231                                                     "width" : 50,
3232                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
3233                                                     "$ xns" : "Roo.grid",
3234                                                     "* prop" : "colModel[]",
3235                                                     "dataIndex" : "gltrans_source"
3236                                                 },
3237                                                 {
3238                                                     "xtype" : "ColumnModel",
3239                                                     "header" : "Notes",
3240                                                     "width" : 75,
3241                                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
3242                                                     "$ xns" : "Roo.grid",
3243                                                     "* prop" : "colModel[]",
3244                                                     "dataIndex" : "gltrans_notes"
3245                                                 },
3246                                                 {
3247                                                     "align" : "right",
3248                                                     "xtype" : "ColumnModel",
3249                                                     "header" : "Amount",
3250                                                     "width" : 75,
3251                                                     "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
3252                                                     "$ xns" : "Roo.grid",
3253                                                     "* prop" : "colModel[]",
3254                                                     "dataIndex" : "gltrans_amount"
3255                                                 },
3256                                                 {
3257                                                     "xtype" : "ColumnModel",
3258                                                     "header" : "Posted",
3259                                                     "width" : 50,
3260                                                     "$ renderer" : "function(v,x,r) { \n    \n    var state = v   ?  '-checked' : '';\n                                    \n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }",
3261                                                     "$ xns" : "Roo.grid",
3262                                                     "* prop" : "colModel[]",
3263                                                     "dataIndex" : "gltrans_posted"
3264                                                 }
3265                                             ]
3266                                         }
3267                                     ]
3268                                 }
3269                             ]
3270                         }
3271                     ]
3272                 },
3273                 {
3274                     "listeners" : {
3275                         "|activate" : "function() {\n    _this.profitpanel = this;\n    \n    try { if (MODULE.isBuilder) {\n        return;\n    } } catch(e) { }\n    \n    var id = _this.form.findField('cohead_id').getValue() * 1;\n    if (id < 1) {\n        Roo.MessageBox.alert(\"Save First\", \"Save the order first, before adding items\");\n        _this.dialog.layout.getRegion('center').showPanel(0);\n        return;\n    }\n    \n    if (_this.profitgrid) {\n        _this.profitgrid.footer.onClick('first');\n     }\n    \n}"
3276                     },
3277                     "fitToframe" : true,
3278                     "background" : true,
3279                     "region" : "center",
3280                     "title" : "Profit",
3281                     "xtype" : "GridPanel",
3282                     "fitContainer" : true,
3283                     "$ xns" : "Roo",
3284                     "tableName" : "coitem",
3285                     "items" : [
3286                         {
3287                             "listeners" : {
3288                                 "|render" : "function() \n{\n    _this.profitgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.profitpanel.active) {\n       this.footer.onClick('first');\n    }\n}"
3289                             },
3290                             "autoExpandColumn" : "item_number",
3291                             "xtype" : "Grid",
3292                             "loadMask" : true,
3293                             "$ xns" : "Roo.grid",
3294                             "* prop" : "grid",
3295                             "items" : [
3296                                 {
3297                                     "listeners" : {
3298                                         "beforeload" : "function (_self,o) {\n\n    try {\n       this.removeAll();\n   } catch (e) { }\n   \n\n    if (!_this.data || !_this.data.cohead_id) {\n        return false;\n    }\n    o.params = o.params || {};\n    \n    o.params.coitem_cohead_id = _this.data.cohead_id;\n    o.params._without_list_discount =1;\n    o.params._with_profit = 1;\n    \n}"
3299                                     },
3300                                     "xtype" : "Store",
3301                                     "remoteSort" : true,
3302                                     "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
3303                                     "$ xns" : "Roo.data",
3304                                     "* prop" : "dataSource",
3305                                     "items" : [
3306                                         {
3307                                             "$ url" : "baseURL + '/Roo/coitem.php'",
3308                                             "xtype" : "HttpProxy",
3309                                             "method" : "GET",
3310                                             "$ xns" : "Roo.data",
3311                                             "* prop" : "proxy"
3312                                         },
3313                                         {
3314                                             "id" : "id",
3315                                             "root" : "data",
3316                                             "xtype" : "JsonReader",
3317                                             "$ xns" : "Roo.data",
3318                                             "$ fields" : "[\n    {\n        'name': 'id',\n        'type': 'int'\n    },\n    {\n        'name': 'name',\n        'type': 'string'\n    },\n    {\n        'name': 'type',\n        'type': 'int'\n    },\n    {\n        'name': 'leader',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_office_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_name',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_phone',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_fax',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_email',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_company_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_role',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_active',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_remarks',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_passwd',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_owner_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_lang',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_no_reset_sent',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_action_type',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_project_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_deleted_by',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_deleted_dt',\n        'type': 'date'\n    },\n    {\n        'name': 'leader_firstname',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_lastname',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_name_facebook',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_url_blog',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_url_twitter',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_url_linkedin',\n        'type': 'string'\n    },\n    {\n        'name': 'leader_crm_lead_percentage',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_crm_industry_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_crm_updated_action_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_crm_created_action_id',\n        'type': 'int'\n    },\n    {\n        'name': 'leader_crm_type_id',\n        'type': 'int'\n    }\n]",
3319                                             "* prop" : "reader",
3320                                             "totalProperty" : "total"
3321                                         }
3322                                     ]
3323                                 },
3324                                 {
3325                                     "pageSize" : 25,
3326                                     "xtype" : "PagingToolbar",
3327                                     "emptyMsg" : "No coitem found",
3328                                     "$ xns" : "Roo",
3329                                     "displayMsg" : "Displaying coitem{0} - {1} of {2}",
3330                                     "displayInfo" : true,
3331                                     "* prop" : "footer"
3332                                 },
3333                                 {
3334                                     "xtype" : "ColumnModel",
3335                                     "header" : "Item Code",
3336                                     "width" : 75,
3337                                     "$ renderer" : "function(v) { return String.format('{0}', v); }",
3338                                     "$ xns" : "Roo.grid",
3339                                     "* prop" : "colModel[]",
3340                                     "dataIndex" : "item_number"
3341                                 },
3342                                 {
3343                                     "xtype" : "ColumnModel",
3344                                     "header" : "SubTotal",
3345                                     "width" : 200,
3346                                     "$ renderer" : "function(v) {\n\n\n     return Roo.util.Format.number( v, 2);\n  }",
3347                                     "$ xns" : "Roo.grid",
3348                                     "* prop" : "colModel[]",
3349                                     "dataIndex" : "calc_subtotal"
3350                                 },
3351                                 {
3352                                     "xtype" : "ColumnModel",
3353                                     "header" : "Cost of goods",
3354                                     "width" : 200,
3355                                     "$ renderer" : "function(v) {\n\n    return Roo.util.Format.number( v, 2);\n  }",
3356                                     "$ xns" : "Roo.grid",
3357                                     "* prop" : "colModel[]",
3358                                     "dataIndex" : "calc_cost_total"
3359                                 },
3360                                 {
3361                                     "xtype" : "ColumnModel",
3362                                     "header" : "Profit",
3363                                     "width" : 200,
3364                                     "$ renderer" : "function(v,x,r) {\n        \n   var profit = r.data.calc_subtotal - r.data.calc_cost_total;\n   \n   if(parseInt(profit) < 1){\n       return String.format('<b style=\"color:red;\">{0}</b>', Roo.util.Format.number(profit,2));      \n   }\n        \n        \n    return Roo.util.Format.number( profit, 2);\n}",
3365                                     "$ xns" : "Roo.grid",
3366                                     "* prop" : "colModel[]",
3367                                     "dataIndex" : "profit"
3368                                 }
3369                             ]
3370                         }
3371                     ]
3372                 },
3373                 {
3374                     "listeners" : {
3375                         "render" : "function (_self)\n{\n    _this.reversalBtn = _self;\n}",
3376                         "click" : "function (_self, e)\n{\n    var id = _this.form.findField('cohead_id').getValue() * 1;\n    \n    if(id < 1){\n        Roo.MessageBox.alert('Error', 'Error occour on getting the sales order id');\n        return;\n    }\n\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure to create a credit memo reversal?\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                method: 'POST',\n                url: baseURL+ '/Roo/cohead',\n                params : {\n                    cohead_id : id,\n                    _cm_reversal : 1\n                },\n                success : function() {\n                    _this.form.load({ method: 'GET', params: { '_id' : id }});\n                }\n            });\n    }); \n      \n}"
3377                     },
3378                     "text" : "Create CM reversal",
3379                     "xtype" : "Button",
3380                     "$ xns" : "Roo",
3381                     "* prop" : "buttons[]"
3382                 },
3383                 {
3384                     "listeners" : {
3385                         "click" : "function (_self, e)\n{\n      if (_this.grid)  _this.grid.stopEditing();\n    _this.dialog.hide();\n}"
3386                     },
3387                     "text" : "Cancel",
3388                     "xtype" : "Button",
3389                     "$ xns" : "Roo",
3390                     "* prop" : "buttons[]"
3391                 },
3392                 {
3393                     "listeners" : {
3394                         "render" : "function (_self)\n{\n    _this.saveBtn = _self;\n}",
3395                         "click" : "function (_self, e)\n{\n    // do some checks?\n     \n      if (_this.grid)  _this.grid.stopEditing();\n \n    _this.form.doAction(\"submit\");\n\n}"
3396                     },
3397                     "text" : "Save",
3398                     "xtype" : "Button",
3399                     "$ xns" : "Roo",
3400                     "* prop" : "buttons[]"
3401                 }
3402             ]
3403         }
3404     ]
3405 }