Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleSalesOrder.bjs
1 {
2  "name" : "Pman.Dialog.XtupleSalesOrder",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/edward/gitlive/Pman.Xtuple/Pman.Dialog.XtupleSalesOrder.bjs",
6  "permname" : "",
7  "modOrder" : "001",
8  "strings" : {
9   "58ec392a138714456f83d1288f553099" : "tracknum",
10   "42f6d99a2dddc4858882ed8e9a210b52" : "Invoice #",
11   "249ff431aa95198ad6814dd1d2799883" : "Select taxtype",
12   "fce9a6a1bd2a2050eb86d33103f46fd3" : "Invoices",
13   "a2fdeac60e3c5b6c51a92e027fb9d533" : "Target Delivery",
14   "96b0141273eabab320119c467cdcaf17" : "Total ",
15   "d682c376c82f68bc65dcd05570d04dfc" : "Payments / Refunds / Credit Memos",
16   "75ba8d70e3692ba200f0e0df37b4d2ae" : "IP address",
17   "9f4f3d35db49c5c2bba70a321a42fa87" : "Find Products",
18   "9d4ba8f5211a3ba238b2032be5991c14" : "Disc%",
19   "e12167aa0a7698e6ebc92b4ce3909b53" : "To",
20   "c4a0f4ddf926328daa2a350db9f9ca00" : "Qty Changed",
21   "99575a08540e6ee585a7b389e8bde351" : "GL Tx",
22   "ec211f7c20af43e742bf2570c3cb84f9" : "Add",
23   "f84e65035f5d2d4a090b8a626c822321" : "List Price",
24   "fc44040a63559bee1157010d4c602422" : "Select location",
25   "62f0de97dd70387d493350e45bfa5583" : "Send Delivery Email",
26   "cc7819055cde3194bb3b136bad5cf58d" : " ",
27   "806dca90dbeda894ffb258939f9fef9a" : "Fill empty Ship To",
28   "fce6d3795b41b54dc0dab82df50517c1" : "Select custinfo",
29   "d323a19bad62ff427d0b75dc52674c81" : "#Ret",
30   "c5eae6ea505388a73962c635ac821fba" : "SubTotal",
31   "f2a6c498fb90ee345d997f888fce3b18" : "Delete",
32   "418c5509e2171d55b0aee5c2ea4442b5" : "action",
33   "51e07f52ae2192d23a1b43922e5beb90" : "#TX ship",
34   "607ff05a0e4c02c54b2262cd2e381aff" : "Reserve Stock / Shipments",
35   "689202409e48743b914713f96d93947c" : "Value",
36   "d9db367d7e9d6a3d3ca0346dfa1ff9d2" : "Item Description",
37   "16d2b386b2034b9488996466aaae0b57" : "History",
38   "dd7bf230fde8d4836917806aff6a6b27" : "Address",
39   "986b90fb419e5349dd59b691b0e0e9f6" : "Customer PO#",
40   "7d74f3b92b19da5e606d737d339a9679" : "Item",
41   "c5c8ac6bbc6d7f5c95d0a888527554d3" : "Order Details",
42   "fd216b286b94577ac68c112c0dcaf341" : "TX#",
43   "068f80c7519d0528fb08e82137a72131" : "Products",
44   "b166cb3a96bdb966f3288b8599594d0d" : "Sell @",
45   "1243daf593fa297e07ab03bf06d925af" : "Searching...",
46   "151ccf95db9b81c11bb20fbc302af4b6" : "Select terms",
47   "7eb17faabef94701775df7154f30684b" : "#avail",
48   "f31bbdd1b3e85bccd652680e16935819" : "Source",
49   "086247a9b57fde6eefee2a0c4752242d" : "Automatic",
50   "0a90b1bc4078f74b6f0d117ec7df65af" : "Credit",
51   "27f2870eaa01c99fc83105240ad15f7f" : "Delete All",
52   "5f0c1431b38e3d279bf105d48824b7f3" : "Select ship to",
53   "26453198f2ddac444702879a8f6d61a5" : "Auto Reverse",
54   "780c462e85ba4399a5d42e88f69a15ca" : "Billing",
55   "81dffdb31b9576e343d3f7ffcf721d7e" : "Cost of goods",
56   "813f81532d71077e497863ec9faf16c7" : "Confirm Shipment",
57   "46fc12727bf2c5cc79988ab857ad73b4" : "Print Shipping / Commercial Invoice",
58   "8156649b9de8783c15c822b592c3bac6" : "Reverse Selected",
59   "8c6aab77edc5b8e589b36bcf989683e4" : "Print Picking Slip",
60   "69193f49683ba5a928ae8a27328105ba" : "Print Aus - GST included Invoice",
61   "13dba24862cf9128167a59100e154c8d" : "Print",
62   "4b5a5a93e13bd338d40cf4bae2ca51cb" : "Void Credit Memo",
63   "b80f4ed22929b09103f0c5666ad7a7e1" : "Run Apply Fifo on order",
64   "009534719f8c8221440a5629f497a784" : "Debit",
65   "1abe972d603f3bd61eefc9ac39fb7522" : "#TX Tot",
66   "7b09a122e58c067939744c4a96ff2d77" : "Select salesrep",
67   "56d56144d4e4a42ce450446518c4fc00" : "#Diff",
68   "03ab340b3f99e03cff9e84314ead38c0" : "Qty",
69   "f4c6f851b00d5518bf888815de279aba" : "Notes",
70   "c9cc8cce247e49bae79f15173ce97354" : "Save",
71   "386c339d37e737a436499d423a77df0c" : "Currency",
72   "f4757c5aca5e4410b63c6ec4cd0f2363" : "shiphead",
73   "f97f673be4e5f66aca62b35280d8bcde" : "Print Standard Invoice",
74   "acc95aeaee48871da70cc3bce664728c" : "Select shiptoinfo",
75   "ce26601dac0dea138b7295f02b7620a7" : "Customer",
76   "d335d558a8386d20318888b1f034103d" : "Unshipped Total",
77   "2925dda0ec274c20c0a30d8720eb830b" : "Select curr_name",
78   "72d6d7a1885885bb55a565fd1070581a" : "Import",
79   "9aa6071f39d387792476bd70fed66735" : "Void / Unconfirm",
80   "6f1bf85c9ebb3c7fa26251e1e335e032" : "Terms",
81   "53896265ad28c11cb4997b3c3e3e122d" : "#Ship",
82   "5da618e8e4b89c66fe86e32cdafde142" : "From",
83   "158e64bcd08067d26e9c27679eeced88" : "No Items",
84   "d179a904ac10a39ab574fe803cc29fa3" : "Run Void flagger",
85   "f3d90c6982143029487fb00d4ef19526" : "#invoiced",
86   "80092f7900d59aab765d0ddd35dc7231" : "Add Shipment",
87   "a240fa27925a635b08dc28c9e4f9216d" : "Order",
88   "01d35df7886d24900b1ecb65da6bf21d" : "Receive Payment",
89   "f817f797c422f7ac3404b6223db1a1ee" : "invdetail",
90   "50104a28589c5b6099d3580861c2551a" : "Shipments / Invoices",
91   "e23841a1d7427d8a9297142145dff049" : "Select shipto",
92   "9f1a342d0197aac60ed73e921dc4c1f5" : "Price Details",
93   "2142511303396bd51e0cc25ea8ffe47f" : "Void Payment",
94   "88408722ed9d719c44087292bf8a06cf" : "Prices with GST",
95   "236119342501b1e596bc82013c9cfc42" : "SubTotal w/GST",
96   "4b78ac8eb158840e9638a3aeb26c4a9d" : "Tax",
97   "cb02c723b8a159fea3cd7913d3df7fbc" : "Doc#",
98   "6a813cbab5d0c9d33b1a471839935d88" : "Cust#",
99   "b8feb9ee933bc5cc05615860322e9e7a" : "Post Invoice",
100   "70c6ddcd97af88d0aaac48268c459727" : "Download (as xls)",
101   "66b2bba3de9b8c5d6fb94e9458f1b7f5" : "Show Inventory History",
102   "57cdc7bcd2ca327f3267e2f5ecfa8c6d" : "Edit / Create Sales Order",
103   "48e91c2f1cb7b90612ccae2502c7327f" : "Shipment Comments",
104   "47cb03899dc494703b52c37240fa4c17" : "Stock Tx",
105   "72bb7a9ea8714c52b0c0b8369d6a8dc3" : "Issue Date",
106   "e5d63551ca2d2842661e49a25fd12a67" : "Edit Customer",
107   "7608203603437f0513ba8203a2d39a4f" : "Item Code",
108   "08bd40c7543007ad06e4fce31618f6ec" : "Account",
109   "e963218370d6410e1ee0f8e6128c12d4" : "shipdate",
110   "0ee182201463a0ea31cb073b227fbbbe" : "Print Chinese Invoice With GST in line item",
111   "089ba2b5edc96565fc22c584ecfbb1a6" : "Displaying events{0} - {1} of {2}",
112   "0bcef9c45bd8a48eda1b26eb0c61c869" : "%",
113   "81ceb48a978444906d80119200aa358d" : "Void",
114   "a763436d2b30d54e4aff264b1636827a" : "Discount (Pretax)",
115   "4721299f56b6b7d43591156d1d3f3e82" : "List Price w/GST",
116   "f4ac45b9eb622dcb26c0d4fc1c93b27c" : "Order Comments",
117   "7a113dee68a51f4c5f71264fd0ce3781" : "Item#",
118   "a860ed9926b241b7d4dca2d00610ab2c" : "Outstanding",
119   "290612199861c31d1036b185b4e69b75" : "Summary",
120   "786410e93beb0193d89f8608c54feb4b" : "Select item",
121   "b1bc248a7ff2b2e95569f56de68615df" : "number",
122   "07ca5050e697392c9ed47e6453f1453f" : "Completed",
123   "6b15347cbd1bf352b547741a7525c1b4" : "#shipped",
124   "b3c65c9f85b429821cf931b38386a64d" : "Select Tax Type",
125   "5e33fc1550a56738da96fbaaf57e72f0" : "#TX ret",
126   "16cd452dda9d4398bf6240603eee40a9" : "Posted",
127   "b2f40690858b404ed10e62bdf422c704" : "Amount",
128   "e87de1a5d238411ab34a292be599e9f4" : "Apply To All",
129   "40e6e8652d174c7ceef48df46f9cf25a" : "From Location",
130   "9122d60c0550be8ab070b96d8bbc6358" : "Sell @w/GST",
131   "78ca8a8170f2065057507ddcde63d9ca" : "Tax Zone",
132   "757989a16207ab23076685118640adf3" : "Item Cost",
133   "160ab8f9d6c5d2819fff11dea08d4ef8" : "Download Excel",
134   "0ee72ad23c24d7cfc5c13311abdc3f72" : "Staff I.C.",
135   "511b6a78f5503881ba10ff93b7205ade" : "Create CM reversal",
136   "74002cb040b036511b8d031da591364a" : "Ship to",
137   "c6b4fd215b0cdcb7426519edc0ece828" : "Print Bambini Pro Forma Invoice",
138   "b98c34417c412e0c87faa828f26b9123" : "Uninvoiced Total",
139   "a0d036a1d6a00180df168fa86143e5f8" : "No invdetail found",
140   "de3d17fb46f44fdf066581fbb5fe6113" : "Select Staff",
141   "fbb9d6ec5325d0fe63c19431856a0802" : "Select cntct",
142   "c3ce05eb16c5e0075b4a247b2c4b7bba" : "Bill To (select)",
143   "ec53a8c4f07baed5d8825072c89799be" : "Status",
144   "25d81668fca34c83d0720cc6365d62d6" : "Pre Tax discount",
145   "b25f6c965342495f74899e183efe20a4" : "Void / Unpost",
146   "58733ee735e3160c5c9fa5739fb4d056" : "Unposted",
147   "3ec365dd533ddb7ef3d1c111186ce872" : "Details",
148   "c04b33241cc5478500daf178e3720b63" : "No coitem found",
149   "ea9cf7e47ff33b2be14e6dd07cbcefc6" : "Shipping",
150   "871080cb9d00a8bda1b9f1db3c164341" : "Unit Cost",
151   "820dbd2b8f606aff866c0bbfb6b737c1" : "Changed",
152   "7ce96513eec175e6123b56573750b0dd" : "#reserved",
153   "a0ec87054b5e5b7847d0d8780a01a3d5" : "Sum",
154   "26e09a1ee1517389c7b07f42df65561a" : "Ordered",
155   "bdd31bfe5374e3cdc19a10020eae4b49" : "Add Invoice",
156   "801ab24683a4a8c433c6eb40c48bcd9d" : "Download",
157   "44749712dbec183e983dcd78a7736c41" : "Date",
158   "37656f0f6cf5e5befb1ec7abd3db5804" : "shipvia",
159   "4a2a14210d78f0d82db75d0264030169" : "Supply From",
160   "052fbb9431206b4755090dc53fcef300" : "Void Refund",
161   "c4b515058fab313f403ae427ce7e32b3" : "Update Location to match S/O",
162   "87813307f6e7498b30c5b3d9b2f65f56" : "Displaying invdetail{0} - {1} of {2}",
163   "3a6a3353e3b44ad5359c8e3178b66a54" : "invcdate",
164   "4b84bd35233c0d3d3c36b9a6ce6e0745" : "Order Items",
165   "13abfee28b4564e3fb059420fbedbec5" : "Taxed",
166   "94f475efc6722fd13ab78411c1ef7bd7" : "Sales Rep",
167   "bb4af85913879b95661b81570a2c2e83" : "Discount (Posttax)",
168   "526db6366257755024ed2556000871bc" : "Issue Refund",
169   "594f5bdc5e1519ce9934d276e5bf081f" : "No events found",
170   "d0cc96be641673ad48fc74374fda8137" : "Displaying coitem{0} - {1} of {2}",
171   "ce8ae9da5b7cd6c3df2929543a9af92d" : "Email",
172   "b6dad11e8e2203819164d64fc82b40f1" : "Discount after Tax  Description",
173   "ea4788705e6873b424c65e91c2846b19" : "Cancel",
174   "1b7132f58f9ee9de75e5778ff04f7303" : "Print Delivery Note",
175   "4ee972120bcda675f75222c87cb9d356" : "Who",
176   "a0947dda65e4112f49260243804b6528" : "Xfer all stock to HK",
177   "1d144309cbdf2536723621bf0eac9f33" : "or enter Address",
178   "3d96cc39e5517a284e203ffc8cafcf51" : "Print Bambini Pronto Invoice",
179   "9c9745a343efeacc9efe9b7222b27afb" : "Ref#",
180   "900eb3dcf3a7d639acbd2528ca5bbd52" : "Apply % Discount of : ",
181   "e8586011952b0d098b0e568f20ca2b1f" : "Select Currency",
182   "fa1cfdb383ea976facbdb20d40d2f811" : "Duplicate Selected",
183   "6ac26fe4e9a39ac45fffe6d6920dac3a" : "Print Chinese Invoice",
184   "182875b6c36a761f1e459624c1d93638" : "Profit",
185   "3ffaf70863d6f46e2719050a37d9ef86" : "Order#",
186   "8fb8fbc1c0bc53b2d01121344410e444" : "Split sales"
187  },
188  "items" : [
189   {
190    "listeners" : {
191     "|show" : "function () {\n       this.layout.getRegion('center').showPanel(0);\n}"
192    },
193    "modal" : true,
194    "collapsible" : false,
195    "title" : "Edit / Create Sales Order",
196    "xtype" : "LayoutDialog",
197    "width" : 1050,
198    "$ xns" : "Roo",
199    "closable" : true,
200    "resizable" : true,
201    "height" : 620,
202    "items" : [
203     {
204      "alwaysShowTabs" : true,
205      "xtype" : "LayoutRegion",
206      "$ xns" : "Roo",
207      "tabPosition" : "top",
208      "* prop" : "center",
209      "items" : [
210       {
211        "xtype" : "Toolbar",
212        "$ xns" : "Roo",
213        "* prop" : "toolbar",
214        "items" : [
215         {
216          "xtype" : "Fill",
217          "$ xns" : "Roo.Toolbar"
218         },
219         {
220          "listeners" : {
221           "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}"
222          },
223          "text" : "Download Excel",
224          "xtype" : "Button",
225          "cls" : "x-btn-text-icon",
226          "$ icon" : "rootURL + '/Pman/templates/images/spreadsheet.gif'",
227          "$ xns" : "Roo.Toolbar"
228         },
229         {
230          "listeners" : {
231           "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}"
232          },
233          "text" : "Print",
234          "xtype" : "Button",
235          "cls" : "x-btn-text-icon",
236          "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
237          "$ xns" : "Roo.Toolbar"
238         },
239         {
240          "listeners" : {
241           "click" : "function (_self, e)\n{\n\n    _this.addShipmentBtn.fireEvent('click');\n   \n}"
242          },
243          "text" : "Add Shipment",
244          "hidden" : true,
245          "xtype" : "Button",
246          "cls" : "x-btn-text-icon",
247          "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
248          "$ xns" : "Roo.Toolbar"
249         },
250         {
251          "listeners" : {
252           "click" : "function (_self, e)\n{\n\n   Pman.Dialog.XtupleCustomer.show({\n         cust_id : _this.form.findField('cohead_cust_id').getValue()\n  }); \n}"
253          },
254          "text" : "Edit Customer",
255          "xtype" : "Button",
256          "cls" : "x-btn-text-icon",
257          "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
258          "$ xns" : "Roo.Toolbar"
259         },
260         {
261          "listeners" : {
262           "click" : "function (_self, e)\n{\n\n        _this.addInvoiceBtn.fireEvent('click');\n   \n}"
263          },
264          "text" : "Add Invoice",
265          "hidden" : true,
266          "xtype" : "Button",
267          "cls" : "x-btn-text-icon",
268          "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
269          "$ xns" : "Roo.Toolbar"
270         },
271         {
272          "listeners" : {
273           "render" : "function (_self, e)\n{\n    _this.voidBtn = _self;\n}",
274           "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}"
275          },
276          "text" : "Void",
277          "xtype" : "Button",
278          "$ xns" : "Roo.Toolbar"
279         },
280         {
281          "listeners" : {
282           "render" : "function (_self)\n{\n   _this.closeBtn = _self;\n}",
283           "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}"
284          },
285          "text" : "Completed",
286          "xtype" : "Button",
287          "$ xns" : "Roo.Toolbar"
288         }
289        ]
290       }
291      ]
292     },
293     {
294      "listeners" : {
295       "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}"
296      },
297      "region" : "center",
298      "xtype" : "ContentPanel",
299      "title" : "Order Details",
300      "$ xns" : "Roo",
301      "items" : [
302       {
303        "listeners" : {
304         "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}",
305         "|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",
306         "|rendered" : "function (form)\n{\n    _this.form= form;\n}\n"
307        },
308        "$ url" : "baseURL + '/Roo/cohead.php'",
309        "xtype" : "Form",
310        "method" : "POST",
311        "style" : "margin:10px;",
312        "$ xns" : "Roo.form",
313        "items" : [
314         {
315          "xtype" : "Column",
316          "width" : 435,
317          "$ xns" : "Roo.form",
318          "items" : [
319           {
320            "legend" : "Order",
321            "xtype" : "FieldSet",
322            "style" : "width:420px",
323            "labelWidth" : 120,
324            "$ xns" : "Roo.form",
325            "items" : [
326             {
327              "xtype" : "Column",
328              "labelWidth" : 100,
329              "width" : 410,
330              "$ xns" : "Roo.form",
331              "items" : [
332               {
333                "xtype" : "Row",
334                "labelWidth" : 100,
335                "width" : 400,
336                "$ xns" : "Roo.form",
337                "items" : [
338                 {
339                  "fieldLabel" : "Order#",
340                  "emptyText" : "Automatic",
341                  "xtype" : "TextField",
342                  "allowBlank" : true,
343                  "readOnly" : true,
344                  "width" : 120,
345                  "$ xns" : "Roo.form",
346                  "name" : "cohead_number"
347                 },
348                 {
349                  "style" : "float:left",
350                  "xtype" : "Row",
351                  "labelWidth" : 50,
352                  "width" : 150,
353                  "$ xns" : "Roo.form",
354                  "items" : [
355                   {
356                    "fieldLabel" : "Cust#",
357                    "xtype" : "TextField",
358                    "allowBlank" : true,
359                    "readOnly" : true,
360                    "width" : 110,
361                    "$ xns" : "Roo.form",
362                    "name" : "cohead_cust_id_cust_number"
363                   }
364                  ]
365                 }
366                ]
367               },
368               {
369                "listWidth" : 400,
370                "triggerAction" : "all",
371                "forceSelection" : true,
372                "fieldLabel" : "Customer",
373                "selectOnFocus" : true,
374                "pageSize" : 20,
375                "hiddenName" : "cohead_cust_id",
376                "minChars" : 2,
377                "valueField" : "cust_id",
378                "xtype" : "TextField",
379                "readOnly" : true,
380                "typeAhead" : true,
381                "editable" : false,
382                "width" : 300,
383                "$ xns" : "Roo.form",
384                "name" : "cohead_cust_id_cust_name",
385                "qtip" : "Select custinfo",
386                "queryParam" : "query[cust_name]",
387                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>",
388                "loadingText" : "Searching..."
389               },
390               {
391                "fieldLabel" : "Customer PO#",
392                "xtype" : "TextField",
393                "$ xns" : "Roo.form",
394                "width" : 150,
395                "name" : "cohead_custponumber"
396               },
397               {
398                "format" : "Y-m-d",
399                "fieldLabel" : "Ordered",
400                "xtype" : "DateField",
401                "allowBlank" : false,
402                "width" : 100,
403                "$ xns" : "Roo.form",
404                "name" : "cohead_orderdate"
405               },
406               {
407                "xtype" : "Row",
408                "labelWidth" : 100,
409                "width" : 500,
410                "$ xns" : "Roo.form",
411                "items" : [
412                 {
413                  "format" : "Y-m-d",
414                  "fieldLabel" : "Target Delivery",
415                  "xtype" : "DateField",
416                  "allowBlank" : false,
417                  "width" : 100,
418                  "$ xns" : "Roo.form",
419                  "name" : "cohead_targetdate"
420                 },
421                 {
422                  "hideLabels" : true,
423                  "xtype" : "Row",
424                  "$ xns" : "Roo.form",
425                  "items" : [
426                   {
427                    "listeners" : {
428                     "check" : "function (_self, checked)\n{\n    if(checked){\n        _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());\n    }\n}"
429                    },
430                    "inputValue" : 1,
431                    "xtype" : "Checkbox",
432                    "boxLabel" : "same as order",
433                    "$ xns" : "Roo.form",
434                    "name" : "_same_as_order"
435                   }
436                  ]
437                 }
438                ]
439               },
440               {
441                "listWidth" : 400,
442                "triggerAction" : "all",
443                "fieldLabel" : "Supply From",
444                "forceSelection" : true,
445                "selectOnFocus" : true,
446                "pageSize" : 200,
447                "displayField" : "location_name",
448                "emptyText" : "Supply From",
449                "hiddenName" : "cohead_location_src",
450                "minChars" : 2,
451                "valueField" : "location_id",
452                "xtype" : "ComboBox",
453                "allowBlank" : false,
454                "typeAhead" : false,
455                "editable" : true,
456                "width" : 300,
457                "$ xns" : "Roo.form",
458                "name" : "cohead_location_src_location_name",
459                "qtip" : "Select terms",
460                "queryParam" : "query[location_name]",
461                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>",
462                "loadingText" : "Searching...",
463                "items" : [
464                 {
465                  "listeners" : {
466                   "|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"
467                  },
468                  "xtype" : "Store",
469                  "remoteSort" : true,
470                  "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
471                  "$ xns" : "Roo.data",
472                  "* prop" : "store",
473                  "items" : [
474                   {
475                    "$ url" : "baseURL + '/Roo/location.php'",
476                    "xtype" : "HttpProxy",
477                    "method" : "GET",
478                    "$ xns" : "Roo.data",
479                    "* prop" : "proxy"
480                   },
481                   {
482                    "id" : "location_id",
483                    "root" : "data",
484                    "xtype" : "JsonReader",
485                    "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
486                    "$ xns" : "Roo.data",
487                    "* prop" : "reader",
488                    "totalProperty" : "total"
489                   }
490                  ]
491                 }
492                ]
493               }
494              ]
495             }
496            ]
497           },
498           {
499            "legend" : "Details",
500            "xtype" : "FieldSet",
501            "style" : "width:420px",
502            "labelWidth" : 100,
503            "$ xns" : "Roo.form",
504            "items" : [
505             {
506              "xtype" : "Column",
507              "labelWidth" : 100,
508              "width" : 420,
509              "$ xns" : "Roo.form",
510              "items" : [
511               {
512                "listWidth" : 400,
513                "triggerAction" : "all",
514                "forceSelection" : true,
515                "selectOnFocus" : true,
516                "fieldLabel" : "Terms",
517                "pageSize" : 20,
518                "xtype" : "ComboBox",
519                "emptyText" : "Select terms",
520                "minChars" : 2,
521                "valueField" : "terms_id",
522                "displayField" : "terms_descrip",
523                "hiddenName" : "cohead_terms_id",
524                "allowBlank" : false,
525                "typeAhead" : true,
526                "editable" : false,
527                "$ xns" : "Roo.form",
528                "width" : 300,
529                "qtip" : "Select terms",
530                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>",
531                "queryParam" : "query[terms_descrip]",
532                "name" : "cohead_terms_id_terms_descrip",
533                "loadingText" : "Searching...",
534                "items" : [
535                 {
536                  "listeners" : {
537                   "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
538                  },
539                  "xtype" : "Store",
540                  "remoteSort" : true,
541                  "$ sortInfo" : "{ direction : 'ASC', field: 'terms_descrip' }",
542                  "$ xns" : "Roo.data",
543                  "* prop" : "store",
544                  "items" : [
545                   {
546                    "$ url" : "baseURL + '/Roo/terms.php'",
547                    "method" : "GET",
548                    "xtype" : "HttpProxy",
549                    "$ xns" : "Roo.data",
550                    "* prop" : "proxy"
551                   },
552                   {
553                    "id" : "terms_id",
554                    "root" : "data",
555                    "xtype" : "JsonReader",
556                    "$ xns" : "Roo.data",
557                    "$ fields" : "[{\"name\":\"terms_id\",\"type\":\"int\"},\"terms_descrip\"]",
558                    "* prop" : "reader",
559                    "totalProperty" : "total"
560                   }
561                  ]
562                 }
563                ]
564               },
565               {
566                "alwaysQuery" : true,
567                "listWidth" : 400,
568                "triggerAction" : "all",
569                "fieldLabel" : "Sales Rep",
570                "forceSelection" : true,
571                "selectOnFocus" : true,
572                "pageSize" : 80,
573                "displayField" : "salesrep_name",
574                "emptyText" : "Select salesrep",
575                "hiddenName" : "cohead_display_salesrep_id",
576                "minChars" : 2,
577                "valueField" : "salesrep_id",
578                "xtype" : "ComboBox",
579                "allowBlank" : true,
580                "typeAhead" : true,
581                "editable" : false,
582                "width" : 300,
583                "$ xns" : "Roo.form",
584                "name" : "cohead_display_salesrep_id_salesrep_name",
585                "qtip" : "Select salesrep",
586                "queryParam" : "query[salesrep_name]",
587                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
588                "loadingText" : "Searching...",
589                "items" : [
590                 {
591                  "listeners" : {
592                   "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
593                  },
594                  "xtype" : "Store",
595                  "remoteSort" : true,
596                  "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
597                  "$ xns" : "Roo.data",
598                  "* prop" : "store",
599                  "items" : [
600                   {
601                    "$ url" : "baseURL + '/Roo/salesrep.php'",
602                    "method" : "GET",
603                    "xtype" : "HttpProxy",
604                    "$ xns" : "Roo.data",
605                    "* prop" : "proxy"
606                   },
607                   {
608                    "id" : "salesrep_id",
609                    "root" : "data",
610                    "xtype" : "JsonReader",
611                    "$ xns" : "Roo.data",
612                    "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
613                    "* prop" : "reader",
614                    "totalProperty" : "total"
615                   }
616                  ]
617                 }
618                ]
619               },
620               {
621                "alwaysQuery" : true,
622                "listWidth" : 400,
623                "triggerAction" : "all",
624                "fieldLabel" : "Staff I.C.",
625                "forceSelection" : true,
626                "selectOnFocus" : true,
627                "pageSize" : 80,
628                "displayField" : "salesrep_name",
629                "emptyText" : "Select Staff",
630                "hiddenName" : "cohead_salesrep_id",
631                "minChars" : 2,
632                "valueField" : "salesrep_id",
633                "xtype" : "ComboBox",
634                "allowBlank" : false,
635                "typeAhead" : true,
636                "editable" : false,
637                "width" : 300,
638                "$ xns" : "Roo.form",
639                "name" : "cohead_salesrep_id_salesrep_name",
640                "qtip" : "Select salesrep",
641                "queryParam" : "query[salesrep_name]",
642                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
643                "loadingText" : "Searching...",
644                "items" : [
645                 {
646                  "listeners" : {
647                   "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
648                  },
649                  "xtype" : "Store",
650                  "remoteSort" : true,
651                  "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
652                  "$ xns" : "Roo.data",
653                  "* prop" : "store",
654                  "items" : [
655                   {
656                    "$ url" : "baseURL + '/Roo/salesrep.php'",
657                    "method" : "GET",
658                    "xtype" : "HttpProxy",
659                    "$ xns" : "Roo.data",
660                    "* prop" : "proxy"
661                   },
662                   {
663                    "id" : "salesrep_id",
664                    "root" : "data",
665                    "xtype" : "JsonReader",
666                    "$ xns" : "Roo.data",
667                    "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
668                    "* prop" : "reader",
669                    "totalProperty" : "total"
670                   }
671                  ]
672                 }
673                ]
674               },
675               {
676                "fieldLabel" : "Order Comments",
677                "xtype" : "TextArea",
678                "width" : 300,
679                "$ xns" : "Roo.form",
680                "name" : "cohead_ordercomments",
681                "height" : 80
682               }
683              ]
684             }
685            ]
686           },
687           {
688            "xtype" : "FieldSet",
689            "legend" : "Billing",
690            "style" : "width:420px",
691            "$ xns" : "Roo.form",
692            "items" : [
693             {
694              "xtype" : "Column",
695              "labelWidth" : 50,
696              "width" : 420,
697              "$ xns" : "Roo.form",
698              "items" : [
699               {
700                "listeners" : {
701                 "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}",
702                 "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}"
703                },
704                "alwaysQuery" : true,
705                "listWidth" : 400,
706                "triggerAction" : "all",
707                "fieldLabel" : "Bill To (select)",
708                "forceSelection" : true,
709                "selectOnFocus" : true,
710                "pageSize" : 20,
711                "displayField" : "cntct_name",
712                "emptyText" : "Select cntct",
713                "hiddenName" : "cohead_billto_cntct_id",
714                "minChars" : 2,
715                "valueField" : "cntct_id",
716                "xtype" : "ComboBox",
717                "allowBlank" : false,
718                "typeAhead" : true,
719                "editable" : true,
720                "width" : 300,
721                "$ xns" : "Roo.form",
722                "name" : "cohead_billto_cntct_id_cntct_name",
723                "qtip" : "Select cntct",
724                "queryParam" : "query[cntct_name]",
725                "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>",
726                "loadingText" : "Searching...",
727                "items" : [
728                 {
729                  "listeners" : {
730                   "|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"
731                  },
732                  "xtype" : "Store",
733                  "remoteSort" : true,
734                  "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
735                  "$ xns" : "Roo.data",
736                  "* prop" : "store",
737                  "items" : [
738                   {
739                    "$ url" : "baseURL + '/Roo/cntct.php'",
740                    "method" : "GET",
741                    "xtype" : "HttpProxy",
742                    "$ xns" : "Roo.data",
743                    "* prop" : "proxy"
744                   },
745                   {
746                    "id" : "cntct_id",
747                    "root" : "data",
748                    "xtype" : "JsonReader",
749                    "$ xns" : "Roo.data",
750                    "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
751                    "* prop" : "reader",
752                    "totalProperty" : "total"
753                   }
754                  ]
755                 }
756                ]
757               },
758               {
759                "listeners" : {
760                 "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}"
761                },
762                "fieldLabel" : "or enter Address",
763                "xtype" : "TextArea",
764                "$ 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",
765                "readOnly" : true,
766                "$ xns" : "Roo.form",
767                "name" : "billto_address"
768               },
769               {
770                "fieldLabel" : "Email",
771                "xtype" : "DisplayField",
772                "$ valueRenderer" : "function(v)\n{\n \n    return v ? String.format('<a href=\"mailto:{0}\" target=\"_blank\">{0}</a>',v) : '';\n}",
773                "$ xns" : "Roo.form",
774                "name" : "billto_email"
775               }
776              ]
777             }
778            ]
779           }
780          ]
781         },
782         {
783          "xtype" : "Column",
784          "style" : "margin-left:10px",
785          "width" : 435,
786          "$ xns" : "Roo.form",
787          "items" : [
788           {
789            "xtype" : "FieldSet",
790            "style" : "width:420px",
791            "legend" : "Price Details",
792            "labelWidth" : 50,
793            "$ xns" : "Roo.form",
794            "items" : [
795             {
796              "labelAlign" : "right",
797              "xtype" : "Column",
798              "labelWidth" : 300,
799              "width" : 420,
800              "$ xns" : "Roo.form",
801              "items" : [
802               {
803                "labelAlign" : "top",
804                "xtype" : "Row",
805                "labelSeparator" : "&nbsp;",
806                "width" : 500,
807                "$ xns" : "Roo.form",
808                "items" : [
809                 {
810                  "listeners" : {
811                   "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}"
812                  },
813                  "listWidth" : 400,
814                  "triggerAction" : "all",
815                  "fieldLabel" : "Currency",
816                  "forceSelection" : true,
817                  "selectOnFocus" : true,
818                  "pageSize" : 20,
819                  "displayField" : "curr_name",
820                  "emptyText" : "Select curr_name",
821                  "hiddenName" : "cohead_curr_id",
822                  "minChars" : 2,
823                  "valueField" : "curr_id",
824                  "xtype" : "ComboBox",
825                  "allowBlank" : false,
826                  "typeAhead" : true,
827                  "editable" : false,
828                  "width" : 285,
829                  "$ xns" : "Roo.form",
830                  "name" : "cohead_curr_id_curr_name",
831                  "qtip" : "Select Currency",
832                  "queryParam" : "query[curr_name]",
833                  "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>",
834                  "loadingText" : "Searching...",
835                  "items" : [
836                   {
837                    "listeners" : {
838                     "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n   \n}\n"
839                    },
840                    "xtype" : "Store",
841                    "remoteSort" : true,
842                    "$ sortInfo" : "{ direction : 'ASC', field: 'curr_symbol' }",
843                    "$ xns" : "Roo.data",
844                    "* prop" : "store",
845                    "items" : [
846                     {
847                      "$ url" : "baseURL + '/Roo/curr_symbol.php'",
848                      "method" : "GET",
849                      "xtype" : "HttpProxy",
850                      "$ xns" : "Roo.data",
851                      "* prop" : "proxy"
852                     },
853                     {
854                      "id" : "curr_id",
855                      "root" : "data",
856                      "xtype" : "JsonReader",
857                      "$ xns" : "Roo.data",
858                      "$ fields" : "[{\"name\":\"curr_id\",\"type\":\"int\"},\"curr_symbol\"]",
859                      "* prop" : "reader",
860                      "totalProperty" : "total"
861                     }
862                    ]
863                   }
864                  ]
865                 },
866                 {
867                  "fieldLabel" : "Products",
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_subtotal"
876                 }
877                ]
878               },
879               {
880                "labelAlign" : "top",
881                "xtype" : "Row",
882                "labelSeparator" : "&nbsp;",
883                "width" : 500,
884                "$ xns" : "Roo.form",
885                "items" : [
886                 {
887                  "listeners" : {
888                   "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}"
889                  },
890                  "listWidth" : 400,
891                  "triggerAction" : "all",
892                  "fieldLabel" : "Tax Zone",
893                  "forceSelection" : true,
894                  "selectOnFocus" : true,
895                  "pageSize" : 20,
896                  "displayField" : "taxzone_descrip",
897                  "emptyText" : "Select taxtype",
898                  "hiddenName" : "cohead_taxzone_id",
899                  "minChars" : 2,
900                  "valueField" : "taxzone_id",
901                  "xtype" : "ComboBox",
902                  "allowBlank" : false,
903                  "typeAhead" : true,
904                  "editable" : false,
905                  "width" : 285,
906                  "$ xns" : "Roo.form",
907                  "name" : "cohead_taxzone_id_taxzone_descrip",
908                  "qtip" : "Select taxtype",
909                  "queryParam" : "query[taxzone_descrip]",
910                  "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>",
911                  "loadingText" : "Searching...",
912                  "items" : [
913                   {
914                    "listeners" : {
915                     "|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"
916                    },
917                    "xtype" : "Store",
918                    "remoteSort" : true,
919                    "$ sortInfo" : "{ direction : 'ASC', field: 'taxzone_descrip' }",
920                    "$ xns" : "Roo.data",
921                    "* prop" : "store",
922                    "items" : [
923                     {
924                      "$ url" : "baseURL + '/Roo/taxzone.php'",
925                      "xtype" : "HttpProxy",
926                      "method" : "GET",
927                      "$ xns" : "Roo.data",
928                      "* prop" : "proxy"
929                     },
930                     {
931                      "id" : "taxzone_id",
932                      "root" : "data",
933                      "xtype" : "JsonReader",
934                      "$ fields" : "[{\"name\":\"taxzone_id\",\"type\":\"int\"},\"taxzone_descrip\"]",
935                      "$ xns" : "Roo.data",
936                      "* prop" : "reader",
937                      "totalProperty" : "total"
938                     }
939                    ]
940                   }
941                  ]
942                 },
943                 {
944                  "fieldLabel" : "Tax",
945                  "xtype" : "NumberField",
946                  "cls" : "roo-align-right",
947                  "readOnly" : true,
948                  "allowDecimals" : true,
949                  "decimalPrecision" : 3,
950                  "width" : 100,
951                  "$ xns" : "Roo.form",
952                  "name" : "cohead_tax"
953                 }
954                ]
955               },
956               {
957                "fieldLabel" : "Pre Tax discount",
958                "xtype" : "NumberField",
959                "cls" : "roo-align-right",
960                "readOnly" : true,
961                "allowDecimals" : true,
962                "decimalPrecision" : 3,
963                "width" : 100,
964                "$ xns" : "Roo.form",
965                "name" : "cohead_pretax_discount"
966               },
967               {
968                "labelAlign" : "top",
969                "xtype" : "Row",
970                "labelSeparator" : "&nbsp;",
971                "width" : 500,
972                "$ xns" : "Roo.form",
973                "items" : [
974                 {
975                  "fieldLabel" : "Discount after Tax  Description",
976                  "xtype" : "TextField",
977                  "width" : 230,
978                  "$ xns" : "Roo.form",
979                  "name" : "cohead_misc_descrip"
980                 },
981                 {
982                  "listeners" : {
983                   "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}"
984                  },
985                  "fieldLabel" : "%",
986                  "xtype" : "NumberField",
987                  "$ 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",
988                  "cls" : "roo-align-right",
989                  "allowDecimals" : true,
990                  "decimalPrecision" : 1,
991                  "width" : 35,
992                  "$ xns" : "Roo.form",
993                  "name" : "cohead_misc_per"
994                 },
995                 {
996                  "listeners" : {
997                   "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}"
998                  },
999                  "fieldLabel" : "&nbsp;",
1000                  "xtype" : "NumberField",
1001                  "cls" : "roo-align-right",
1002                  "allowDecimals" : true,
1003                  "decimalPrecision" : 3,
1004                  "width" : 100,
1005                  "$ xns" : "Roo.form",
1006                  "name" : "cohead_posttax_discount"
1007                 }
1008                ]
1009               },
1010               {
1011                "fieldLabel" : "Total",
1012                "$ 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",
1013                "xtype" : "NumberField",
1014                "cls" : "roo-align-right",
1015                "readOnly" : true,
1016                "allowDecimals" : true,
1017                "decimalPrecision" : 3,
1018                "width" : 100,
1019                "$ xns" : "Roo.form",
1020                "name" : "cohead_total"
1021               },
1022               {
1023                "listeners" : {
1024                 "keyup" : "function (_self, e)\n{\n    _this.form.findField('cohead_total').recalc();\n}"
1025                },
1026                "fieldLabel" : "Shipping",
1027                "xtype" : "NumberField",
1028                "cls" : "roo-align-right",
1029                "allowDecimals" : true,
1030                "decimalPrecision" : 3,
1031                "width" : 100,
1032                "$ xns" : "Roo.form",
1033                "name" : "cohead_freight"
1034               },
1035               {
1036                "fieldLabel" : "Unshipped Total",
1037                "xtype" : "NumberField",
1038                "cls" : "roo-align-right",
1039                "readOnly" : true,
1040                "allowDecimals" : true,
1041                "decimalPrecision" : 3,
1042                "width" : 100,
1043                "$ xns" : "Roo.form",
1044                "name" : "cohead_unshipped"
1045               },
1046               {
1047                "fieldLabel" : "Uninvoiced Total",
1048                "xtype" : "NumberField",
1049                "cls" : "roo-align-right",
1050                "readOnly" : true,
1051                "allowDecimals" : true,
1052                "decimalPrecision" : 3,
1053                "width" : 100,
1054                "$ xns" : "Roo.form",
1055                "name" : "cohead_uninvoiced"
1056               }
1057              ]
1058             }
1059            ]
1060           },
1061           {
1062            "xtype" : "FieldSet",
1063            "legend" : "Shipping",
1064            "style" : "width:420px",
1065            "$ xns" : "Roo.form",
1066            "items" : [
1067             {
1068              "xtype" : "Column",
1069              "labelWidth" : 50,
1070              "width" : 420,
1071              "$ xns" : "Roo.form",
1072              "items" : [
1073               {
1074                "xtype" : "Row",
1075                "labelSeparator" : "&nbsp;",
1076                "$ xns" : "Roo.form",
1077                "items" : [
1078                 {
1079                  "listeners" : {
1080                   "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}"
1081                  },
1082                  "xtype" : "Checkbox",
1083                  "boxLabel" : "Same as Billing",
1084                  "$ xns" : "Roo.form",
1085                  "name" : "_shipto_same"
1086                 }
1087                ]
1088               },
1089               {
1090                "listeners" : {
1091                 "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}",
1092                 "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}"
1093                },
1094                "alwaysQuery" : true,
1095                "listWidth" : 400,
1096                "triggerAction" : "all",
1097                "fieldLabel" : "Ship to",
1098                "forceSelection" : true,
1099                "selectOnFocus" : true,
1100                "pageSize" : 20,
1101                "displayField" : "cntct_name",
1102                "emptyText" : "Select ship to",
1103                "hiddenName" : "cohead_shipto_cntct_id",
1104                "minChars" : 2,
1105                "valueField" : "cntct_id",
1106                "xtype" : "ComboBox",
1107                "allowBlank" : false,
1108                "typeAhead" : true,
1109                "editable" : true,
1110                "width" : 300,
1111                "$ xns" : "Roo.form",
1112                "name" : "cohead_shipto_cntct_id_cntct_name",
1113                "qtip" : "Select shiptoinfo",
1114                "queryParam" : "query[cntct_name]",
1115                "tpl" : "<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>",
1116                "loadingText" : "Searching...",
1117                "items" : [
1118                 {
1119                  "listeners" : {
1120                   "|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"
1121                  },
1122                  "xtype" : "Store",
1123                  "remoteSort" : true,
1124                  "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
1125                  "$ xns" : "Roo.data",
1126                  "* prop" : "store",
1127                  "items" : [
1128                   {
1129                    "$ url" : "baseURL + '/Roo/cntct.php'",
1130                    "method" : "GET",
1131                    "xtype" : "HttpProxy",
1132                    "$ xns" : "Roo.data",
1133                    "* prop" : "proxy"
1134                   },
1135                   {
1136                    "id" : "cntct_id",
1137                    "root" : "data",
1138                    "xtype" : "JsonReader",
1139                    "$ xns" : "Roo.data",
1140                    "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
1141                    "* prop" : "reader",
1142                    "totalProperty" : "total"
1143                   }
1144                  ]
1145                 }
1146                ]
1147               },
1148               {
1149                "listeners" : {
1150                 "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}"
1151                },
1152                "fieldLabel" : "Address",
1153                "xtype" : "TextArea",
1154                "$ 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",
1155                "readOnly" : true,
1156                "width" : 300,
1157                "$ xns" : "Roo.form",
1158                "name" : "shipto_address"
1159               },
1160               {
1161                "fieldLabel" : "Shipment Comments",
1162                "xtype" : "TextArea",
1163                "$ xns" : "Roo.form",
1164                "width" : 300,
1165                "name" : "cohead_shipcomments"
1166               }
1167              ]
1168             }
1169            ]
1170           }
1171          ]
1172         },
1173         {
1174          "xtype" : "Hidden",
1175          "$ xns" : "Roo.form",
1176          "name" : "cohead_id"
1177         },
1178         {
1179          "xtype" : "Hidden",
1180          "$ xns" : "Roo.form",
1181          "name" : "cohead_shipto_id"
1182         },
1183         {
1184          "xtype" : "Hidden",
1185          "$ xns" : "Roo.form",
1186          "name" : "cohead_shipto_id_shipto_name"
1187         },
1188         {
1189          "xtype" : "Hidden",
1190          "$ xns" : "Roo.form",
1191          "name" : "cohead_max_linenumber"
1192         },
1193         {
1194          "xtype" : "Hidden",
1195          "$ xns" : "Roo.form",
1196          "name" : "cohead_cust_id"
1197         },
1198         {
1199          "$ 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",
1200          "xtype" : "Hidden",
1201          "$ xns" : "Roo.form",
1202          "name" : "cohead_misc"
1203         },
1204         {
1205          "xtype" : "Hidden",
1206          "$ xns" : "Roo.form",
1207          "name" : "taxzone_rate"
1208         }
1209        ]
1210       }
1211      ]
1212     },
1213     {
1214      "listeners" : {
1215       "deactivate" : "function (_self)\n{\n    if(_this.grid){\n        _this.grid.stopEditing();\n    }\n}",
1216       "|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}"
1217      },
1218      "background" : true,
1219      "region" : "center",
1220      "fitToframe" : true,
1221      "title" : "Order Items",
1222      "xtype" : "GridPanel",
1223      "fitContainer" : true,
1224      "$ xns" : "Roo",
1225      "tableName" : "coitem",
1226      "items" : [
1227       {
1228        "listeners" : {
1229         "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}",
1230         "|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}",
1231         "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}",
1232         "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",
1233         "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}"
1234        },
1235        "autoExpandColumn" : "item_descrip1",
1236        "xtype" : "EditorGrid",
1237        "loadMask" : true,
1238        "$ 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",
1239        "clicksToEdit" : 1,
1240        "$ xns" : "Roo.grid",
1241        "* prop" : "grid",
1242        "items" : [
1243         {
1244          "listeners" : {
1245           "tabend" : "function (_self)\n{\n    _this.addItemBtn.fireEvent('click', _this.addItemBtn);\n}",
1246           "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}"
1247          },
1248          "xtype" : "CellSelectionModel",
1249          "$ xns" : "Roo.grid",
1250          "* prop" : "sm",
1251          "enter_is_tab" : true
1252         },
1253         {
1254          "pageSize" : 100,
1255          "xtype" : "PagingToolbar",
1256          "emptyMsg" : "No Items",
1257          "$ xns" : "Roo",
1258          "displayInfo" : true,
1259          "$ 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",
1260          "* prop" : "footer",
1261          "items" : [
1262           {
1263            "listeners" : {
1264             "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}"
1265            },
1266            "text" : "Fill empty Ship To",
1267            "xtype" : "Button",
1268            "$ xns" : "Roo.Toolbar"
1269           },
1270           {
1271            "listeners" : {
1272             "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}"
1273            },
1274            "text" : "Update Location to match S/O",
1275            "xtype" : "Button",
1276            "$ xns" : "Roo.Toolbar"
1277           },
1278           {
1279            "listeners" : {
1280             "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}",
1281             "render" : "function (_self)\n{\n    _this.showgstBtn = _self;\n}"
1282            },
1283            "text" : "Prices with GST",
1284            "enableToggle" : true,
1285            "minWidth" : 100,
1286            "xtype" : "Button",
1287            "$ xns" : "Roo.Toolbar"
1288           }
1289          ]
1290         },
1291         {
1292          "listeners" : {
1293           "|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}",
1294           "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  ",
1295           "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}"
1296          },
1297          "xtype" : "Store",
1298          "remoteSort" : true,
1299          "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
1300          "$ xns" : "Roo.data",
1301          "* prop" : "dataSource",
1302          "items" : [
1303           {
1304            "$ url" : "baseURL + '/Roo/coitem.php'",
1305            "xtype" : "HttpProxy",
1306            "method" : "GET",
1307            "$ xns" : "Roo.data",
1308            "* prop" : "proxy"
1309           },
1310           {
1311            "id" : "coitem_id",
1312            "root" : "data",
1313            "xtype" : "JsonReader",
1314            "$ 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]",
1315            "$ xns" : "Roo.data",
1316            "* prop" : "reader",
1317            "# 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\"}",
1318            "totalProperty" : "total"
1319           }
1320          ]
1321         },
1322         {
1323          "xtype" : "Toolbar",
1324          "$ xns" : "Roo",
1325          "* prop" : "toolbar",
1326          "items" : [
1327           {
1328            "listeners" : {
1329             "|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",
1330             "render" : "function (_self)\n{\n    _this.addItemBtn = _self;\n}"
1331            },
1332            "text" : "Add",
1333            "xtype" : "Button",
1334            "cls" : "x-btn-text-icon",
1335            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
1336            "$ xns" : "Roo.Toolbar"
1337           },
1338           {
1339            "listeners" : {
1340             "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}"
1341            },
1342            "text" : "Find Products",
1343            "xtype" : "Button",
1344            "cls" : "x-btn-text-icon",
1345            "$ icon" : "rootURL + '/Pman/templates/images/search.gif'",
1346            "$ xns" : "Roo.Toolbar"
1347           },
1348           {
1349            "listeners" : {
1350             "|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",
1351             "render" : "function (_self)\n{\n    _this.xferAll  = _self;\n}"
1352            },
1353            "text" : "Xfer all stock to HK",
1354            "hidden" : true,
1355            "xtype" : "Button",
1356            "cls" : "x-btn-text-icon",
1357            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
1358            "$ xns" : "Roo.Toolbar"
1359           },
1360           {
1361            "listeners" : {
1362             "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}"
1363            },
1364            "text" : "Show Inventory History",
1365            "xtype" : "Button",
1366            "$ xns" : "Roo.Toolbar"
1367           },
1368           {
1369            "xtype" : "Separator",
1370            "$ xns" : "Roo.Toolbar"
1371           },
1372           {
1373            "text" : "Apply % Discount of : ",
1374            "xtype" : "TextItem",
1375            "$ xns" : "Roo.Toolbar"
1376           },
1377           {
1378            "listeners" : {
1379             "render" : "function (_self)\n{\n    _this._applyDiscount = _self;\n}"
1380            },
1381            "xtype" : "TextField",
1382            "$ xns" : "Roo.form",
1383            "width" : 40
1384           },
1385           {
1386            "listeners" : {
1387             "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}"
1388            },
1389            "text" : "Apply To All",
1390            "xtype" : "Button",
1391            "$ xns" : "Roo.Toolbar"
1392           },
1393           {
1394            "listeners" : {
1395             "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}"
1396            },
1397            "text" : "Import",
1398            "xtype" : "Button",
1399            "$ xns" : "Roo.Toolbar"
1400           },
1401           {
1402            "xtype" : "Fill",
1403            "$ xns" : "Roo.Toolbar"
1404           },
1405           {
1406            "listeners" : {
1407             "|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        "
1408            },
1409            "text" : "Delete",
1410            "xtype" : "Button",
1411            "cls" : "x-btn-text-icon",
1412            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
1413            "$ xns" : "Roo.Toolbar"
1414           },
1415           {
1416            "listeners" : {
1417             "|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        "
1418            },
1419            "text" : "Delete All",
1420            "xtype" : "Button",
1421            "cls" : "x-btn-text-icon",
1422            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
1423            "$ xns" : "Roo.Toolbar"
1424           }
1425          ]
1426         },
1427         {
1428          "xtype" : "ColumnModel",
1429          "header" : "Item#",
1430          "width" : 40,
1431          "$ 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  }",
1432          "$ xns" : "Roo.grid",
1433          "* prop" : "colModel[]",
1434          "dataIndex" : "coitem_linenumber",
1435          "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}"
1436         },
1437         {
1438          "xtype" : "ColumnModel",
1439          "header" : "Item Code",
1440          "width" : 75,
1441          "$ renderer" : "function(v) { return String.format('{0}', v); }",
1442          "$ xns" : "Roo.grid",
1443          "* prop" : "colModel[]",
1444          "dataIndex" : "item_number",
1445          "items" : [
1446           {
1447            "xtype" : "GridEditor",
1448            "$ xns" : "Roo.grid",
1449            "* prop" : "editor",
1450            "items" : [
1451             {
1452              "listeners" : {
1453               "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}"
1454              },
1455              "listWidth" : 400,
1456              "triggerAction" : "all",
1457              "forceSelection" : true,
1458              "selectOnFocus" : true,
1459              "pageSize" : 20,
1460              "displayField" : "itemsite_item_id_item_number",
1461              "emptyText" : "Select item",
1462              "hiddenName" : "itemsite_item_id_item_number",
1463              "minChars" : 2,
1464              "valueField" : "item_number",
1465              "xtype" : "ComboBox",
1466              "allowBlank" : false,
1467              "typeAhead" : false,
1468              "editable" : true,
1469              "$ xns" : "Roo.form",
1470              "* prop" : "field",
1471              "name" : "item_number",
1472              "qtip" : "Select item",
1473              "queryParam" : "query[number]",
1474              "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>",
1475              "loadingText" : "Searching...",
1476              "items" : [
1477               {
1478                "listeners" : {
1479                 "|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"
1480                },
1481                "xtype" : "Store",
1482                "remoteSort" : true,
1483                "$ sortInfo" : "{ direction : 'ASC', field: 'item_number' }",
1484                "$ xns" : "Roo.data",
1485                "* prop" : "store",
1486                "items" : [
1487                 {
1488                  "$ url" : "baseURL + '/Roo/itemsite.php'",
1489                  "xtype" : "HttpProxy",
1490                  "method" : "GET",
1491                  "$ xns" : "Roo.data",
1492                  "* prop" : "proxy"
1493                 },
1494                 {
1495                  "id" : "shipto_id",
1496                  "root" : "data",
1497                  "xtype" : "JsonReader",
1498                  "$ fields" : "[{\"name\":\"item_id\",\"type\":\"int\"},\"item_number\"]",
1499                  "$ xns" : "Roo.data",
1500                  "* prop" : "reader",
1501                  "totalProperty" : "total"
1502                 }
1503                ]
1504               }
1505              ]
1506             }
1507            ]
1508           }
1509          ]
1510         },
1511         {
1512          "xtype" : "ColumnModel",
1513          "header" : "From",
1514          "width" : 75,
1515          "$ renderer" : "function(v,x,r) { \n    return String.format('{0}', r.data.coitem_location_src_location_name); \n}",
1516          "$ xns" : "Roo.grid",
1517          "* prop" : "colModel[]",
1518          "dataIndex" : "coitem_location_src",
1519          "items" : [
1520           {
1521            "xtype" : "GridEditor",
1522            "$ xns" : "Roo.grid",
1523            "* prop" : "editor",
1524            "items" : [
1525             {
1526              "listeners" : {
1527               "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}"
1528              },
1529              "alwaysQuery" : true,
1530              "listWidth" : 400,
1531              "triggerAction" : "all",
1532              "forceSelection" : true,
1533              "selectOnFocus" : true,
1534              "pageSize" : 20,
1535              "displayField" : "location_name",
1536              "emptyText" : "Select location",
1537              "hiddenName" : "coitem_location_src",
1538              "minChars" : 2,
1539              "valueField" : "location_id",
1540              "xtype" : "ComboBox",
1541              "allowBlank" : false,
1542              "typeAhead" : false,
1543              "editable" : true,
1544              "$ xns" : "Roo.form",
1545              "* prop" : "field",
1546              "name" : "coitem_location_src_location_name",
1547              "qtip" : "Select item",
1548              "queryParam" : "query[location_name]",
1549              "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>",
1550              "loadingText" : "Searching...",
1551              "items" : [
1552               {
1553                "listeners" : {
1554                 "|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"
1555                },
1556                "xtype" : "Store",
1557                "remoteSort" : true,
1558                "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
1559                "$ xns" : "Roo.data",
1560                "* prop" : "store",
1561                "items" : [
1562                 {
1563                  "$ url" : "baseURL + '/Roo/location.php'",
1564                  "xtype" : "HttpProxy",
1565                  "method" : "GET",
1566                  "$ xns" : "Roo.data",
1567                  "* prop" : "proxy"
1568                 },
1569                 {
1570                  "id" : "shipto_id",
1571                  "root" : "data",
1572                  "xtype" : "JsonReader",
1573                  "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
1574                  "$ xns" : "Roo.data",
1575                  "* prop" : "reader",
1576                  "totalProperty" : "total"
1577                 }
1578                ]
1579               }
1580              ]
1581             }
1582            ]
1583           }
1584          ]
1585         },
1586         {
1587          "xtype" : "ColumnModel",
1588          "header" : "To",
1589          "width" : 75,
1590          "$ renderer" : "function(v,x,r) { \n    return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); \n}",
1591          "$ xns" : "Roo.grid",
1592          "* prop" : "colModel[]",
1593          "dataIndex" : "coitem_shipto_id",
1594          "items" : [
1595           {
1596            "xtype" : "GridEditor",
1597            "$ xns" : "Roo.grid",
1598            "* prop" : "editor",
1599            "items" : [
1600             {
1601              "listeners" : {
1602               "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}",
1603               "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}"
1604              },
1605              "alwaysQuery" : true,
1606              "listWidth" : 400,
1607              "triggerAction" : "all",
1608              "forceSelection" : true,
1609              "selectOnFocus" : true,
1610              "pageSize" : 20,
1611              "displayField" : "shipto_name",
1612              "emptyText" : "Select cntct",
1613              "hiddenName" : "cohead_shipto_id",
1614              "minChars" : 2,
1615              "valueField" : "shipto_id",
1616              "xtype" : "ComboBox",
1617              "allowBlank" : false,
1618              "typeAhead" : false,
1619              "editable" : false,
1620              "width" : 300,
1621              "$ xns" : "Roo.form",
1622              "* prop" : "field",
1623              "name" : "coitem_shipto_id_shipto_name",
1624              "qtip" : "Select shipto",
1625              "queryParam" : "query[shipto_name]",
1626              "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>",
1627              "loadingText" : "Searching...",
1628              "items" : [
1629               {
1630                "listeners" : {
1631                 "|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"
1632                },
1633                "xtype" : "Store",
1634                "remoteSort" : true,
1635                "$ sortInfo" : "{ direction : 'ASC', field: 'shipto_name' }",
1636                "$ xns" : "Roo.data",
1637                "* prop" : "store",
1638                "items" : [
1639                 {
1640                  "$ url" : "baseURL + '/Roo/shiptoinfo.php'",
1641                  "xtype" : "HttpProxy",
1642                  "method" : "GET",
1643                  "$ xns" : "Roo.data",
1644                  "* prop" : "proxy"
1645                 },
1646                 {
1647                  "id" : "shipto_id",
1648                  "root" : "data",
1649                  "xtype" : "JsonReader",
1650                  "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
1651                  "$ xns" : "Roo.data",
1652                  "* prop" : "reader",
1653                  "totalProperty" : "total"
1654                 }
1655                ]
1656               }
1657              ]
1658             }
1659            ]
1660           }
1661          ]
1662         },
1663         {
1664          "xtype" : "ColumnModel",
1665          "header" : "Item Description",
1666          "width" : 150,
1667          "$ 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}",
1668          "$ xns" : "Roo.grid",
1669          "* prop" : "colModel[]",
1670          "dataIndex" : "item_descrip1",
1671          "# 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\":\"\"}",
1672          "items" : [
1673           {
1674            "xtype" : "GridEditor",
1675            "$ xns" : "Roo.grid",
1676            "* prop" : "editor",
1677            "items" : [
1678             {
1679              "xtype" : "TextField",
1680              "allowBlank" : false,
1681              "$ xns" : "Roo.form",
1682              "* prop" : "field"
1683             }
1684            ]
1685           }
1686          ]
1687         },
1688         {
1689          "align" : "right",
1690          "xtype" : "ColumnModel",
1691          "header" : "Status",
1692          "width" : 50,
1693          "$ renderer" : "function(v) { return String.format('{0}', v); }",
1694          "$ xns" : "Roo.grid",
1695          "* prop" : "colModel[]",
1696          "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
1697          "dataIndex" : "coitem_status"
1698         },
1699         {
1700          "align" : "right",
1701          "xtype" : "ColumnModel",
1702          "header" : "Qty",
1703          "width" : 40,
1704          "$ 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}",
1705          "$ xns" : "Roo.grid",
1706          "* prop" : "colModel[]",
1707          "dataIndex" : "coitem_qtyord",
1708          "items" : [
1709           {
1710            "xtype" : "GridEditor",
1711            "$ xns" : "Roo.grid",
1712            "* prop" : "editor",
1713            "items" : [
1714             {
1715              "listeners" : {
1716               "focus" : "function (_self)\n{\n    if (this.value == 0) {\n        this.el.dom.value = '';\n    }\n}"
1717              },
1718              "minValue" : 1,
1719              "style" : "text-align:right",
1720              "xtype" : "NumberField",
1721              "allowDecimals" : false,
1722              "decimalPrecision" : 0,
1723              "$ xns" : "Roo.form",
1724              "* prop" : "field"
1725             }
1726            ]
1727           }
1728          ]
1729         },
1730         {
1731          "align" : "right",
1732          "xtype" : "ColumnModel",
1733          "header" : "Sell @",
1734          "width" : 70,
1735          "$ 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}",
1736          "$ xns" : "Roo.grid",
1737          "* prop" : "colModel[]",
1738          "dataIndex" : "coitem_price",
1739          "items" : [
1740           {
1741            "xtype" : "GridEditor",
1742            "$ xns" : "Roo.grid",
1743            "* prop" : "editor",
1744            "items" : [
1745             {
1746              "listeners" : {
1747               "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1748              },
1749              "minValue" : 0,
1750              "style" : "text-align:right",
1751              "xtype" : "NumberField",
1752              "decimalPrecision" : 3,
1753              "$ xns" : "Roo.form",
1754              "* prop" : "field"
1755             }
1756            ]
1757           }
1758          ]
1759         },
1760         {
1761          "align" : "right",
1762          "hidden" : true,
1763          "xtype" : "ColumnModel",
1764          "header" : "Sell @w/GST",
1765          "width" : 70,
1766          "$ 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}",
1767          "$ xns" : "Roo.grid",
1768          "* prop" : "colModel[]",
1769          "dataIndex" : "coitem_price_tax",
1770          "items" : [
1771           {
1772            "xtype" : "GridEditor",
1773            "$ xns" : "Roo.grid",
1774            "* prop" : "editor",
1775            "items" : [
1776             {
1777              "listeners" : {
1778               "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1779              },
1780              "minValue" : 0,
1781              "style" : "text-align:right",
1782              "xtype" : "NumberField",
1783              "decimalPrecision" : 3,
1784              "$ xns" : "Roo.form",
1785              "* prop" : "field"
1786             }
1787            ]
1788           }
1789          ]
1790         },
1791         {
1792          "align" : "right",
1793          "xtype" : "ColumnModel",
1794          "header" : "Disc%",
1795          "width" : 50,
1796          "$ 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}",
1797          "$ xns" : "Roo.grid",
1798          "* prop" : "colModel[]",
1799          "dataIndex" : "coitem_linedisc",
1800          "items" : [
1801           {
1802            "xtype" : "GridEditor",
1803            "$ xns" : "Roo.grid",
1804            "* prop" : "editor",
1805            "items" : [
1806             {
1807              "listeners" : {
1808               "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1809              },
1810              "minValue" : 0,
1811              "style" : "text-align:right",
1812              "xtype" : "NumberField",
1813              "decimalPrecision" : 2,
1814              "$ xns" : "Roo.form",
1815              "maxValue" : 100,
1816              "* prop" : "field"
1817             }
1818            ]
1819           }
1820          ]
1821         },
1822         {
1823          "align" : "right",
1824          "xtype" : "ColumnModel",
1825          "header" : "List Price",
1826          "width" : 70,
1827          "$ 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}",
1828          "$ xns" : "Roo.grid",
1829          "* prop" : "colModel[]",
1830          "dataIndex" : "coitem_custprice",
1831          "items" : [
1832           {
1833            "xtype" : "GridEditor",
1834            "$ xns" : "Roo.grid",
1835            "* prop" : "editor",
1836            "items" : [
1837             {
1838              "listeners" : {
1839               "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1840              },
1841              "minValue" : 0,
1842              "style" : "text-align:right",
1843              "xtype" : "NumberField",
1844              "decimalPrecision" : 3,
1845              "$ xns" : "Roo.form",
1846              "* prop" : "field"
1847             }
1848            ]
1849           }
1850          ]
1851         },
1852         {
1853          "align" : "right",
1854          "hidden" : true,
1855          "xtype" : "ColumnModel",
1856          "header" : "List Price w/GST",
1857          "width" : 70,
1858          "$ 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}",
1859          "$ xns" : "Roo.grid",
1860          "* prop" : "colModel[]",
1861          "dataIndex" : "coitem_custprice_tax",
1862          "items" : [
1863           {
1864            "xtype" : "GridEditor",
1865            "$ xns" : "Roo.grid",
1866            "* prop" : "editor",
1867            "items" : [
1868             {
1869              "listeners" : {
1870               "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
1871              },
1872              "minValue" : 0,
1873              "style" : "text-align:right",
1874              "xtype" : "NumberField",
1875              "decimalPrecision" : 3,
1876              "$ xns" : "Roo.form",
1877              "* prop" : "field"
1878             }
1879            ]
1880           }
1881          ]
1882         },
1883         {
1884          "align" : "right",
1885          "xtype" : "ColumnModel",
1886          "header" : "SubTotal",
1887          "width" : 70,
1888          "$ 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  }",
1889          "$ xns" : "Roo.grid",
1890          "* prop" : "colModel[]",
1891          "dataIndex" : "coitem_subtotal"
1892         },
1893         {
1894          "align" : "right",
1895          "hidden" : true,
1896          "xtype" : "ColumnModel",
1897          "header" : "SubTotal w/GST",
1898          "width" : 70,
1899          "$ 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}",
1900          "$ xns" : "Roo.grid",
1901          "* prop" : "colModel[]",
1902          "dataIndex" : "coitem_subtotal_tax"
1903         },
1904         {
1905          "align" : "right",
1906          "xtype" : "ColumnModel",
1907          "header" : "Unit Cost",
1908          "width" : 50,
1909          "$ renderer" : "function(v) { return Roo.util.Format.number( v, 2); }",
1910          "$ xns" : "Roo.grid",
1911          "* prop" : "colModel[]",
1912          "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
1913          "dataIndex" : "coitem_unitcost_in_order_cur"
1914         },
1915         {
1916          "align" : "right",
1917          "xtype" : "ColumnModel",
1918          "header" : "Taxed",
1919          "width" : 50,
1920          "$ renderer" : "function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); }",
1921          "$ xns" : "Roo.grid",
1922          "* prop" : "colModel[]",
1923          "dataIndex" : "coitem_taxtype_id",
1924          "items" : [
1925           {
1926            "xtype" : "GridEditor",
1927            "$ xns" : "Roo.grid",
1928            "* prop" : "editor",
1929            "items" : [
1930             {
1931              "listWidth" : 400,
1932              "triggerAction" : "all",
1933              "forceSelection" : true,
1934              "selectOnFocus" : true,
1935              "pageSize" : 20,
1936              "displayField" : "taxtype_name",
1937              "emptyText" : "Select Tax Type",
1938              "hiddenName" : "coitem_taxtype_id",
1939              "minChars" : 2,
1940              "valueField" : "taxtype_id",
1941              "xtype" : "ComboBox",
1942              "allowBlank" : false,
1943              "typeAhead" : true,
1944              "editable" : false,
1945              "width" : 40,
1946              "$ xns" : "Roo.form",
1947              "* prop" : "field",
1948              "name" : "coitem_taxtype_id_taxtype_name",
1949              "qtip" : "Select taxtype",
1950              "queryParam" : "query[taxtype_id]",
1951              "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>",
1952              "loadingText" : "Searching...",
1953              "items" : [
1954               {
1955                "listeners" : {
1956                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    \n    \n}\n"
1957                },
1958                "xtype" : "Store",
1959                "remoteSort" : true,
1960                "$ sortInfo" : "{ direction : 'ASC', field: 'taxtype_name' }",
1961                "$ xns" : "Roo.data",
1962                "* prop" : "store",
1963                "items" : [
1964                 {
1965                  "$ url" : "baseURL + '/Roo/taxtype.php'",
1966                  "xtype" : "HttpProxy",
1967                  "method" : "GET",
1968                  "$ xns" : "Roo.data",
1969                  "* prop" : "proxy"
1970                 },
1971                 {
1972                  "id" : "taxtype_id",
1973                  "root" : "data",
1974                  "xtype" : "JsonReader",
1975                  "$ fields" : "[{\"name\":\"taxtype_id\",\"type\":\"int\"},\"taxtype_name\"]",
1976                  "$ xns" : "Roo.data",
1977                  "* prop" : "reader",
1978                  "totalProperty" : "total"
1979                 }
1980                ]
1981               }
1982              ]
1983             }
1984            ]
1985           }
1986          ]
1987         },
1988         {
1989          "align" : "right",
1990          "xtype" : "ColumnModel",
1991          "header" : "#avail",
1992          "width" : 50,
1993          "$ 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}",
1994          "$ xns" : "Roo.grid",
1995          "* prop" : "colModel[]",
1996          "dataIndex" : "avail_qty"
1997         },
1998         {
1999          "align" : "right",
2000          "xtype" : "ColumnModel",
2001          "header" : "#reserved",
2002          "width" : 50,
2003          "$ 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}",
2004          "$ xns" : "Roo.grid",
2005          "* prop" : "colModel[]",
2006          "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
2007          "dataIndex" : "shipitem_shipped"
2008         },
2009         {
2010          "align" : "right",
2011          "xtype" : "ColumnModel",
2012          "header" : "#shipped",
2013          "width" : 50,
2014          "$ 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}",
2015          "$ xns" : "Roo.grid",
2016          "* prop" : "colModel[]",
2017          "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
2018          "dataIndex" : "coitem_qtyshipped"
2019         },
2020         {
2021          "align" : "right",
2022          "xtype" : "ColumnModel",
2023          "header" : "#invoiced",
2024          "width" : 50,
2025          "$ 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}",
2026          "$ xns" : "Roo.grid",
2027          "* prop" : "colModel[]",
2028          "dataIndex" : "cobill_billed"
2029         }
2030        ]
2031       }
2032      ]
2033     },
2034     {
2035      "listeners" : {
2036       "activate" : "function (_self)\n{\n    _this.shipinvtab = _self;\n}"
2037      },
2038      "region" : "center",
2039      "xtype" : "NestedLayoutPanel",
2040      "title" : "Shipments / Invoices",
2041      "$ xns" : "Roo",
2042      "items" : [
2043       {
2044        "xtype" : "BorderLayout",
2045        "$ xns" : "Roo",
2046        "* prop" : "layout",
2047        "items" : [
2048         {
2049          "xtype" : "LayoutRegion",
2050          "$ xns" : "Roo",
2051          "* prop" : "center",
2052          "titlebar" : true
2053         },
2054         {
2055          "title" : "Reserve Stock / Shipments",
2056          "xtype" : "LayoutRegion",
2057          "$ xns" : "Roo",
2058          "* prop" : "north",
2059          "height" : 250
2060         },
2061         {
2062          "listeners" : {
2063           "|activate" : "function() {\n    _this.shippanel = this;\n    if (_this.shipgrid) {\n        _this.shipgrid.ds.load({});\n    }\n}"
2064          },
2065          "fitToframe" : true,
2066          "region" : "north",
2067          "background" : false,
2068          "title" : "shiphead",
2069          "xtype" : "GridPanel",
2070          "fitContainer" : true,
2071          "$ xns" : "Roo",
2072          "# 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\"}",
2073          "tableName" : "shiphead",
2074          "items" : [
2075           {
2076            "listeners" : {
2077             "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",
2078             "|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}"
2079            },
2080            "autoExpandColumn" : "shiphead_shipvia",
2081            "xtype" : "Grid",
2082            "loadMask" : true,
2083            "$ xns" : "Roo.grid",
2084            "* prop" : "grid",
2085            "# 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\"}",
2086            "items" : [
2087             {
2088              "xtype" : "RowSelectionModel",
2089              "singleSelect" : true,
2090              "$ xns" : "Roo.grid",
2091              "* prop" : "sm"
2092             },
2093             {
2094              "listeners" : {
2095               "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}"
2096              },
2097              "remoteSort" : true,
2098              "xtype" : "Store",
2099              "$ sortInfo" : "{ field : 'shiphead_shipvia', direction: 'ASC' }",
2100              "$ xns" : "Roo.data",
2101              "* prop" : "dataSource",
2102              "# 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\"}",
2103              "items" : [
2104               {
2105                "$ url" : "baseURL + '/Roo/shiphead.php'",
2106                "method" : "GET",
2107                "xtype" : "HttpProxy",
2108                "$ xns" : "Roo.data",
2109                "* prop" : "proxy"
2110               },
2111               {
2112                "id" : "id",
2113                "root" : "data",
2114                "xtype" : "JsonReader",
2115                "$ xns" : "Roo.data",
2116                "$ 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]",
2117                "* prop" : "reader",
2118                "totalProperty" : "total",
2119                "# 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\"}"
2120               }
2121              ]
2122             },
2123             {
2124              "xtype" : "Toolbar",
2125              "$ xns" : "Roo",
2126              "* prop" : "toolbar",
2127              "items" : [
2128               {
2129                "listeners" : {
2130                 "|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}"
2131                },
2132                "text" : "Confirm Shipment",
2133                "xtype" : "Button",
2134                "cls" : "x-btn-text-icon",
2135                "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
2136                "$ xns" : "Roo.Toolbar"
2137               },
2138               {
2139                "listeners" : {
2140                 "|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}"
2141                },
2142                "text" : "Download (as xls)",
2143                "xtype" : "Button",
2144                "cls" : "x-btn-text-icon",
2145                "$ icon" : "rootURL + '/Pman/templates/images/save.gif'",
2146                "$ xns" : "Roo.Toolbar"
2147               },
2148               {
2149                "listeners" : {
2150                 "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}"
2151                },
2152                "text" : "Print Picking Slip",
2153                "xtype" : "Button",
2154                "cls" : "x-btn-text-icon",
2155                "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
2156                "$ xns" : "Roo.Toolbar"
2157               },
2158               {
2159                "listeners" : {
2160                 "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}"
2161                },
2162                "text" : "Print Delivery Note",
2163                "xtype" : "Button",
2164                "cls" : "x-btn-text-icon",
2165                "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
2166                "$ xns" : "Roo.Toolbar"
2167               },
2168               {
2169                "listeners" : {
2170                 "|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"
2171                },
2172                "text" : "Send Delivery Email",
2173                "xtype" : "Button",
2174                "cls" : "x-btn-text-icon",
2175                "$ icon" : "Roo.rootURL + 'images/default/dd/email.gif'",
2176                "$ xns" : "Roo.Toolbar"
2177               },
2178               {
2179                "xtype" : "Fill",
2180                "$ xns" : "Roo.Toolbar"
2181               },
2182               {
2183                "listeners" : {
2184                 "|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}",
2185                 "render" : "function (_self)\n{\n  _this.addShipmentBtn = _self;\n}"
2186                },
2187                "text" : "Add",
2188                "xtype" : "Button",
2189                "cls" : "x-btn-text-icon",
2190                "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2191                "$ xns" : "Roo.Toolbar"
2192               },
2193               {
2194                "listeners" : {
2195                 "|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        "
2196                },
2197                "text" : "Void / Unconfirm",
2198                "xtype" : "Button",
2199                "cls" : "x-btn-text-icon",
2200                "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2201                "$ xns" : "Roo.Toolbar"
2202               }
2203              ]
2204             },
2205             {
2206              "xtype" : "ColumnModel",
2207              "header" : "number",
2208              "width" : 80,
2209              "$ 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 }",
2210              "$ xns" : "Roo.grid",
2211              "* prop" : "colModel[]",
2212              "dataIndex" : "shiphead_number",
2213              "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2214             },
2215             {
2216              "xtype" : "ColumnModel",
2217              "header" : "From Location",
2218              "width" : 100,
2219              "$ renderer" : "function(v) { return String.format('{0}', v); }",
2220              "$ xns" : "Roo.grid",
2221              "* prop" : "colModel[]",
2222              "dataIndex" : "shiphead_location_id_location_name"
2223             },
2224             {
2225              "xtype" : "ColumnModel",
2226              "header" : "Ship to",
2227              "width" : 100,
2228              "$ renderer" : "function(v) { return String.format('{0}', v); }",
2229              "$ xns" : "Roo.grid",
2230              "* prop" : "colModel[]",
2231              "dataIndex" : "shiphead_shipto_id_shipto_name"
2232             },
2233             {
2234              "xtype" : "ColumnModel",
2235              "header" : "shipdate",
2236              "width" : 75,
2237              "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
2238              "$ xns" : "Roo.grid",
2239              "* prop" : "colModel[]",
2240              "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
2241              "dataIndex" : "shiphead_shipdate"
2242             },
2243             {
2244              "xtype" : "ColumnModel",
2245              "header" : "Status",
2246              "width" : 50,
2247              "$ 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}",
2248              "$ xns" : "Roo.grid",
2249              "* prop" : "colModel[]",
2250              "dataIndex" : "shiphead_sfstatus",
2251              "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2252             },
2253             {
2254              "xtype" : "ColumnModel",
2255              "header" : "shipvia",
2256              "width" : 200,
2257              "$ renderer" : "function(v) { return String.format('{0}', v); }",
2258              "$ xns" : "Roo.grid",
2259              "* prop" : "colModel[]",
2260              "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}",
2261              "dataIndex" : "shiphead_shipvia"
2262             },
2263             {
2264              "xtype" : "ColumnModel",
2265              "header" : "tracknum",
2266              "width" : 200,
2267              "$ renderer" : "function(v) { return String.format('{0}', v); }",
2268              "$ xns" : "Roo.grid",
2269              "* prop" : "colModel[]",
2270              "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
2271              "dataIndex" : "shiphead_tracknum"
2272             }
2273            ]
2274           }
2275          ]
2276         },
2277         {
2278          "listeners" : {
2279           "|activate" : "function() {\n    _this.invpanel = this;\n    if (_this.invgrid) {\n        _this.invgrid.ds.load({});\n    }\n}"
2280          },
2281          "background" : false,
2282          "region" : "center",
2283          "fitToframe" : true,
2284          "title" : "Invoices",
2285          "xtype" : "GridPanel",
2286          "fitContainer" : true,
2287          "$ xns" : "Roo",
2288          "tableName" : "cobmisc",
2289          "items" : [
2290           {
2291            "listeners" : {
2292             "|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",
2293             "|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}"
2294            },
2295            "autoExpandColumn" : "invchead_invcnumber",
2296            "xtype" : "Grid",
2297            "loadMask" : true,
2298            "$ xns" : "Roo.grid",
2299            "* prop" : "grid",
2300            "# 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\"}",
2301            "items" : [
2302             {
2303              "listeners" : {
2304               "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}",
2305               "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}"
2306              },
2307              "xtype" : "Store",
2308              "remoteSort" : true,
2309              "$ sortInfo" : "{ field : 'invchead_invcnumber', direction: 'ASC' }",
2310              "$ xns" : "Roo.data",
2311              "* prop" : "dataSource",
2312              "items" : [
2313               {
2314                "$ url" : "baseURL + '/Roo/cobmisc.php'",
2315                "xtype" : "HttpProxy",
2316                "method" : "GET",
2317                "$ xns" : "Roo.data",
2318                "* prop" : "proxy"
2319               },
2320               {
2321                "id" : "id",
2322                "root" : "data",
2323                "xtype" : "JsonReader",
2324                "$ fields" : "[\n    {\n        'name': 'invchead_invcnumber',\n        'type': 'string'\n    },\n    {\n        'name': 'invchead_invcdate',\n        'type': 'date'\n    }\n]",
2325                "$ xns" : "Roo.data",
2326                "* prop" : "reader",
2327                "# 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\"}",
2328                "totalProperty" : "total"
2329               }
2330              ]
2331             },
2332             {
2333              "xtype" : "Toolbar",
2334              "$ xns" : "Roo",
2335              "* prop" : "toolbar",
2336              "items" : [
2337               {
2338                "listeners" : {
2339                 "|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}"
2340                },
2341                "text" : "Post Invoice",
2342                "xtype" : "Button",
2343                "cls" : "x-btn-text-icon",
2344                "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
2345                "$ xns" : "Roo.Toolbar"
2346               },
2347               {
2348                "text" : "Print",
2349                "xtype" : "Button",
2350                "cls" : "x-btn-text-icon",
2351                "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
2352                "$ xns" : "Roo.Toolbar",
2353                "items" : [
2354                 {
2355                  "xtype" : "Menu",
2356                  "$ xns" : "Roo.menu",
2357                  "* prop" : "menu",
2358                  "items" : [
2359                   {
2360                    "listeners" : {
2361                     "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}"
2362                    },
2363                    "text" : "Print Standard Invoice",
2364                    "xtype" : "Item",
2365                    "$ xns" : "Roo.menu"
2366                   },
2367                   {
2368                    "listeners" : {
2369                     "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} "
2370                    },
2371                    "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
2372                    "text" : "Print Chinese Invoice With GST in line item",
2373                    "xtype" : "Item",
2374                    "$ xns" : "Roo.menu"
2375                   },
2376                   {
2377                    "listeners" : {
2378                     "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} "
2379                    },
2380                    "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
2381                    "text" : "Print Chinese Invoice",
2382                    "xtype" : "Item",
2383                    "$ xns" : "Roo.menu"
2384                   },
2385                   {
2386                    "listeners" : {
2387                     "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} "
2388                    },
2389                    "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2390                    "text" : "Print Aus - GST included Invoice",
2391                    "xtype" : "Item",
2392                    "$ xns" : "Roo.menu"
2393                   },
2394                   {
2395                    "listeners" : {
2396                     "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}"
2397                    },
2398                    "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2399                    "text" : "Print Bambini Pronto Invoice",
2400                    "xtype" : "Item",
2401                    "$ xns" : "Roo.menu"
2402                   },
2403                   {
2404                    "listeners" : {
2405                     "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} "
2406                    },
2407                    "$ hidden" : "!(baseURL.match(/au\\.php$/))",
2408                    "text" : "Print Bambini Pro Forma Invoice",
2409                    "xtype" : "Item",
2410                    "$ xns" : "Roo.menu"
2411                   },
2412                   {
2413                    "listeners" : {
2414                     "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}"
2415                    },
2416                    "$ hidden" : "!( baseURL.match(/au\\.php$/)) ",
2417                    "text" : "Print Shipping / Commercial Invoice",
2418                    "xtype" : "Item",
2419                    "$ xns" : "Roo.menu"
2420                   }
2421                  ]
2422                 }
2423                ]
2424               },
2425               {
2426                "text" : "Payments / Refunds / Credit Memos",
2427                "xtype" : "Button",
2428                "cls" : "x-btn-text-icon",
2429                "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
2430                "$ xns" : "Roo.Toolbar",
2431                "items" : [
2432                 {
2433                  "xtype" : "Menu",
2434                  "$ xns" : "Roo.menu",
2435                  "* prop" : "menu",
2436                  "items" : [
2437                   {
2438                    "listeners" : {
2439                     "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"
2440                    },
2441                    "text" : "Receive Payment",
2442                    "xtype" : "Item",
2443                    "cls" : "x-btn-text-icon",
2444                    "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2445                    "$ xns" : "Roo.menu"
2446                   },
2447                   {
2448                    "listeners" : {
2449                     "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"
2450                    },
2451                    "text" : "Issue Refund",
2452                    "xtype" : "Item",
2453                    "cls" : "x-btn-text-icon",
2454                    "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2455                    "$ xns" : "Roo.menu"
2456                   },
2457                   {
2458                    "xtype" : "Separator",
2459                    "$ xns" : "Roo.menu"
2460                   },
2461                   {
2462                    "listeners" : {
2463                     "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"
2464                    },
2465                    "text" : "Void Payment",
2466                    "xtype" : "Item",
2467                    "cls" : "x-btn-text-icon",
2468                    "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2469                    "$ xns" : "Roo.menu"
2470                   },
2471                   {
2472                    "listeners" : {
2473                     "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"
2474                    },
2475                    "text" : "Void Refund",
2476                    "xtype" : "Item",
2477                    "cls" : "x-btn-text-icon",
2478                    "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2479                    "$ xns" : "Roo.menu"
2480                   },
2481                   {
2482                    "listeners" : {
2483                     "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"
2484                    },
2485                    "text" : "Void Credit Memo",
2486                    "xtype" : "Item",
2487                    "cls" : "x-btn-text-icon",
2488                    "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2489                    "$ xns" : "Roo.menu"
2490                   }
2491                  ]
2492                 }
2493                ]
2494               },
2495               {
2496                "xtype" : "Fill",
2497                "$ xns" : "Roo.Toolbar"
2498               },
2499               {
2500                "listeners" : {
2501                 "|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}",
2502                 "render" : "function (_self)\n{\n  _this.addInvoiceBtn = _self;\n}"
2503                },
2504                "text" : "Add",
2505                "xtype" : "Button",
2506                "cls" : "x-btn-text-icon",
2507                "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
2508                "$ xns" : "Roo.Toolbar"
2509               },
2510               {
2511                "listeners" : {
2512                 "|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}"
2513                },
2514                "text" : "Void / Unpost",
2515                "xtype" : "Button",
2516                "cls" : "x-btn-text-icon",
2517                "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
2518                "$ xns" : "Roo.Toolbar"
2519               }
2520              ]
2521             },
2522             {
2523              "xtype" : "ColumnModel",
2524              "header" : "Invoice #",
2525              "width" : 100,
2526              "$ 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}",
2527              "$ xns" : "Roo.grid",
2528              "* prop" : "colModel[]",
2529              "dataIndex" : "cobmisc_invchead_id_invchead_invcnumber"
2530             },
2531             {
2532              "xtype" : "ColumnModel",
2533              "header" : "invcdate",
2534              "width" : 75,
2535              "$ renderer" : "function(v,x,r) { \n    \n    return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); \n}",
2536              "$ xns" : "Roo.grid",
2537              "* prop" : "colModel[]",
2538              "dataIndex" : "cobmisc_invcdate",
2539              "# builderCfg" : "{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2540             },
2541             {
2542              "align" : "right",
2543              "xtype" : "ColumnModel",
2544              "header" : "Qty",
2545              "width" : 50,
2546              "$ renderer" : "function(v) { return String.format('{0}', v ? parseInt(v) : 0); }",
2547              "$ xns" : "Roo.grid",
2548              "* prop" : "colModel[]",
2549              "dataIndex" : "cobmisc_qty"
2550             },
2551             {
2552              "align" : "right",
2553              "xtype" : "ColumnModel",
2554              "header" : "Item Cost",
2555              "width" : 75,
2556              "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); }",
2557              "$ xns" : "Roo.grid",
2558              "* prop" : "colModel[]",
2559              "dataIndex" : "cobmisc_itemcost"
2560             },
2561             {
2562              "align" : "right",
2563              "xtype" : "ColumnModel",
2564              "header" : "Shipping",
2565              "width" : 75,
2566              "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); }",
2567              "$ xns" : "Roo.grid",
2568              "* prop" : "colModel[]",
2569              "dataIndex" : "cobmisc_freight"
2570             },
2571             {
2572              "align" : "right",
2573              "xtype" : "ColumnModel",
2574              "header" : "Tax",
2575              "width" : 75,
2576              "$ 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 }",
2577              "$ xns" : "Roo.grid",
2578              "* prop" : "colModel[]",
2579              "dataIndex" : "cobmisc_tax"
2580             },
2581             {
2582              "align" : "right",
2583              "xtype" : "ColumnModel",
2584              "header" : "Discount (Pretax)",
2585              "width" : 100,
2586              "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); }",
2587              "$ xns" : "Roo.grid",
2588              "* prop" : "colModel[]",
2589              "dataIndex" : "cobmisc_cohead_id_cohead_pretax_discount"
2590             },
2591             {
2592              "align" : "right",
2593              "xtype" : "ColumnModel",
2594              "header" : "Discount (Posttax)",
2595              "width" : 100,
2596              "$ 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}",
2597              "$ xns" : "Roo.grid",
2598              "* prop" : "colModel[]",
2599              "dataIndex" : "cobmisc_misc"
2600             },
2601             {
2602              "align" : "right",
2603              "xtype" : "ColumnModel",
2604              "header" : "Total ",
2605              "width" : 75,
2606              "$ 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}",
2607              "$ xns" : "Roo.grid",
2608              "* prop" : "colModel[]",
2609              "dataIndex" : "cobmisc_total"
2610             },
2611             {
2612              "align" : "right",
2613              "xtype" : "ColumnModel",
2614              "header" : "Outstanding",
2615              "width" : 75,
2616              "$ renderer" : "function(v,x,r) \n{ \n    \n    return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );\n}",
2617              "$ xns" : "Roo.grid",
2618              "* prop" : "colModel[]",
2619              "dataIndex" : "cobmisc_outstanding"
2620             }
2621            ]
2622           }
2623          ]
2624         }
2625        ]
2626       }
2627      ]
2628     },
2629     {
2630      "listeners" : {
2631       "|activate" : "function() {\n    _this.hpanel = this;\n    if (_this.hgrid) {\n        _this.hgrid.footer.onClick('first');\n    }\n}"
2632      },
2633      "fitToframe" : true,
2634      "region" : "center",
2635      "background" : true,
2636      "title" : "History",
2637      "xtype" : "GridPanel",
2638      "fitContainer" : true,
2639      "$ xns" : "Roo",
2640      "# 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\"}",
2641      "tableName" : "events",
2642      "items" : [
2643       {
2644        "listeners" : {
2645         "|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",
2646         "|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}"
2647        },
2648        "autoExpandColumn" : "remarks",
2649        "xtype" : "Grid",
2650        "loadMask" : true,
2651        "$ xns" : "Roo.grid",
2652        "* prop" : "grid",
2653        "# 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\"}",
2654        "items" : [
2655         {
2656          "listeners" : {
2657           "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}"
2658          },
2659          "remoteSort" : true,
2660          "xtype" : "Store",
2661          "$ sortInfo" : "{ field : 'event_when', direction: 'DESC' }",
2662          "$ xns" : "Roo.data",
2663          "* prop" : "dataSource",
2664          "# 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\"}",
2665          "items" : [
2666           {
2667            "$ url" : "baseURL + '/Roo/events.php'",
2668            "method" : "GET",
2669            "xtype" : "HttpProxy",
2670            "$ xns" : "Roo.data",
2671            "* prop" : "proxy"
2672           },
2673           {
2674            "id" : "id",
2675            "root" : "data",
2676            "xtype" : "JsonReader",
2677            "$ 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]",
2678            "$ xns" : "Roo.data",
2679            "* prop" : "reader",
2680            "# 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\"}",
2681            "totalProperty" : "total"
2682           }
2683          ]
2684         },
2685         {
2686          "pageSize" : 25,
2687          "xtype" : "PagingToolbar",
2688          "emptyMsg" : "No events found",
2689          "$ xns" : "Roo",
2690          "displayInfo" : true,
2691          "displayMsg" : "Displaying events{0} - {1} of {2}",
2692          "* prop" : "footer"
2693         },
2694         {
2695          "xtype" : "ColumnModel",
2696          "header" : "Changed",
2697          "width" : 120,
2698          "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }",
2699          "$ xns" : "Roo.grid",
2700          "* prop" : "colModel[]",
2701          "dataIndex" : "event_when",
2702          "# builderCfg" : "{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2703         },
2704         {
2705          "xtype" : "ColumnModel",
2706          "header" : "action",
2707          "width" : 120,
2708          "$ renderer" : "function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }",
2709          "$ xns" : "Roo.grid",
2710          "* prop" : "colModel[]",
2711          "dataIndex" : "action",
2712          "# builderCfg" : "{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2713         },
2714         {
2715          "xtype" : "ColumnModel",
2716          "header" : "IP address",
2717          "width" : 120,
2718          "$ renderer" : "function(v) { return String.format('{0}', v); }",
2719          "$ xns" : "Roo.grid",
2720          "* prop" : "colModel[]",
2721          "dataIndex" : "ipaddr",
2722          "# builderCfg" : "{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2723         },
2724         {
2725          "xtype" : "ColumnModel",
2726          "header" : "Who",
2727          "width" : 120,
2728          "$ renderer" : "function(v) { return String.format('{0}', v); }",
2729          "$ xns" : "Roo.grid",
2730          "* prop" : "colModel[]",
2731          "dataIndex" : "person_id_name",
2732          "# builderCfg" : "{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
2733         },
2734         {
2735          "xtype" : "ColumnModel",
2736          "header" : "Notes",
2737          "width" : 200,
2738          "$ renderer" : "function(v) { return String.format('{0}', v); }",
2739          "$ xns" : "Roo.grid",
2740          "* prop" : "colModel[]",
2741          "dataIndex" : "remarks",
2742          "# builderCfg" : "{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}"
2743         }
2744        ]
2745       }
2746      ]
2747     },
2748     {
2749      "region" : "center",
2750      "xtype" : "NestedLayoutPanel",
2751      "title" : "Stock Tx",
2752      "$ xns" : "Roo",
2753      "items" : [
2754       {
2755        "xtype" : "BorderLayout",
2756        "$ xns" : "Roo",
2757        "* prop" : "layout",
2758        "items" : [
2759         {
2760          "xtype" : "LayoutRegion",
2761          "$ xns" : "Roo",
2762          "* prop" : "center"
2763         },
2764         {
2765          "xtype" : "LayoutRegion",
2766          "width" : 500,
2767          "$ xns" : "Roo",
2768          "split" : true,
2769          "* prop" : "east"
2770         },
2771         {
2772          "listeners" : {
2773           "|activate" : "function() {\n    _this.txpanel = this;\n    if (_this.txgrid) {\n        _this.txgrid.footer.onClick('first');\n    }\n}"
2774          },
2775          "background" : false,
2776          "region" : "center",
2777          "fitToframe" : true,
2778          "title" : "invdetail",
2779          "xtype" : "GridPanel",
2780          "fitContainer" : true,
2781          "$ xns" : "Roo",
2782          "tableName" : "invdetail",
2783          "items" : [
2784           {
2785            "listeners" : {
2786             "|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}"
2787            },
2788            "autoExpandColumn" : "item_number",
2789            "xtype" : "Grid",
2790            "loadMask" : true,
2791            "$ xns" : "Roo.grid",
2792            "* prop" : "grid",
2793            "items" : [
2794             {
2795              "xtype" : "Toolbar",
2796              "$ xns" : "Roo",
2797              "* prop" : "toolbar",
2798              "items" : [
2799               {
2800                "listeners" : {
2801                 "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}"
2802                },
2803                "text" : "Run Apply Fifo on order",
2804                "xtype" : "Button",
2805                "$ xns" : "Roo.Toolbar"
2806               },
2807               {
2808                "listeners" : {
2809                 "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}"
2810                },
2811                "text" : "Run Void flagger",
2812                "xtype" : "Button",
2813                "$ xns" : "Roo.Toolbar"
2814               },
2815               {
2816                "listeners" : {
2817                 "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}"
2818                },
2819                "text" : "Auto Reverse",
2820                "xtype" : "Button",
2821                "$ xns" : "Roo.Toolbar"
2822               }
2823              ]
2824             },
2825             {
2826              "listeners" : {
2827               "selectionchange" : "function (_self)\n{\n    _this.txdgrid.footer.onClick('first');;\n}"
2828              },
2829              "xtype" : "RowSelectionModel",
2830              "singleSelect" : true,
2831              "$ xns" : "Roo.grid",
2832              "* prop" : "sm"
2833             },
2834             {
2835              "listeners" : {
2836               "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}"
2837              },
2838              "xtype" : "Store",
2839              "remoteSort" : true,
2840              "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
2841              "$ xns" : "Roo.data",
2842              "* prop" : "dataSource",
2843              "items" : [
2844               {
2845                "$ url" : "baseURL + '/Roo/invdetail.php'",
2846                "xtype" : "HttpProxy",
2847                "method" : "GET",
2848                "$ xns" : "Roo.data",
2849                "* prop" : "proxy"
2850               },
2851               {
2852                "id" : "id",
2853                "root" : "data",
2854                "xtype" : "JsonReader",
2855                "$ xns" : "Roo.data",
2856                "$ 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]",
2857                "* prop" : "reader",
2858                "totalProperty" : "total"
2859               }
2860              ]
2861             },
2862             {
2863              "pageSize" : 9999,
2864              "xtype" : "PagingToolbar",
2865              "emptyMsg" : "No invdetail found",
2866              "$ xns" : "Roo",
2867              "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
2868              "displayInfo" : true,
2869              "* prop" : "footer"
2870             },
2871             {
2872              "xtype" : "ColumnModel",
2873              "header" : "Item",
2874              "width" : 75,
2875              "$ renderer" : "function(v) { return String.format('{0}', v); }",
2876              "$ xns" : "Roo.grid",
2877              "* prop" : "colModel[]",
2878              "dataIndex" : "item_number"
2879             },
2880             {
2881              "align" : "right",
2882              "xtype" : "ColumnModel",
2883              "header" : "#Ship",
2884              "width" : 50,
2885              "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2886              "$ xns" : "Roo.grid",
2887              "* prop" : "colModel[]",
2888              "dataIndex" : "rec_shipped"
2889             },
2890             {
2891              "align" : "right",
2892              "xtype" : "ColumnModel",
2893              "header" : "#Ret",
2894              "width" : 50,
2895              "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
2896              "$ xns" : "Roo.grid",
2897              "* prop" : "colModel[]",
2898              "dataIndex" : "rec_returned"
2899             },
2900             {
2901              "align" : "right",
2902              "xtype" : "ColumnModel",
2903              "header" : "#TX ship",
2904              "width" : 50,
2905              "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2906              "$ xns" : "Roo.grid",
2907              "* prop" : "colModel[]",
2908              "dataIndex" : "tx_shipped"
2909             },
2910             {
2911              "align" : "right",
2912              "xtype" : "ColumnModel",
2913              "header" : "#TX ret",
2914              "width" : 50,
2915              "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
2916              "$ xns" : "Roo.grid",
2917              "* prop" : "colModel[]",
2918              "dataIndex" : "tx_returned"
2919             },
2920             {
2921              "align" : "right",
2922              "xtype" : "ColumnModel",
2923              "header" : "#TX Tot",
2924              "width" : 50,
2925              "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
2926              "$ xns" : "Roo.grid",
2927              "* prop" : "colModel[]",
2928              "dataIndex" : "tx_total"
2929             },
2930             {
2931              "align" : "right",
2932              "xtype" : "ColumnModel",
2933              "header" : "Value",
2934              "width" : 50,
2935              "$ renderer" : "function(v,x,r) { \n\n    return (v*1).toFixed(3);\n}",
2936              "$ xns" : "Roo.grid",
2937              "* prop" : "colModel[]",
2938              "dataIndex" : "total_value"
2939             },
2940             {
2941              "align" : "right",
2942              "xtype" : "ColumnModel",
2943              "header" : "#Diff",
2944              "width" : 50,
2945              "$ 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    }",
2946              "$ xns" : "Roo.grid",
2947              "* prop" : "colModel[]",
2948              "dataIndex" : "tx_total"
2949             }
2950            ]
2951           }
2952          ]
2953         },
2954         {
2955          "listeners" : {
2956           "|activate" : "function() {\n    _this.txdpanel = this;\n    if (_this.txdgrid) {\n        _this.txdgrid.footer.onClick('first');\n    }\n}"
2957          },
2958          "background" : false,
2959          "region" : "east",
2960          "fitToframe" : true,
2961          "title" : "invdetail",
2962          "xtype" : "GridPanel",
2963          "fitContainer" : true,
2964          "$ xns" : "Roo",
2965          "tableName" : "invdetail",
2966          "items" : [
2967           {
2968            "listeners" : {
2969             "|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}",
2970             "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}"
2971            },
2972            "autoExpandColumn" : "invhist_comments",
2973            "xtype" : "Grid",
2974            "loadMask" : true,
2975            "$ xns" : "Roo.grid",
2976            "* prop" : "grid",
2977            "items" : [
2978             {
2979              "xtype" : "Toolbar",
2980              "$ xns" : "Roo",
2981              "* prop" : "toolbar",
2982              "items" : [
2983               {
2984                "listeners" : {
2985                 "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}"
2986                },
2987                "text" : "Duplicate Selected",
2988                "xtype" : "Button",
2989                "$ xns" : "Roo.Toolbar"
2990               },
2991               {
2992                "xtype" : "Fill",
2993                "$ xns" : "Roo.Toolbar"
2994               },
2995               {
2996                "text" : "Issue Date",
2997                "xtype" : "TextItem",
2998                "$ xns" : "Roo.Toolbar"
2999               },
3000               {
3001                "listeners" : {
3002                 "render" : "function (_self)\n{\n    _this.dateSel = _self;\n}"
3003                },
3004                "format" : "Y-m-d",
3005                "fieldLabel" : "Issue Date",
3006                "xtype" : "DateField",
3007                "allowBlank" : false,
3008                "width" : 150,
3009                "$ xns" : "Roo.form",
3010                "name" : "issue_date"
3011               },
3012               {
3013                "listeners" : {
3014                 "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}"
3015                },
3016                "text" : "Reverse Selected",
3017                "xtype" : "Button",
3018                "$ xns" : "Roo.Toolbar"
3019               }
3020              ]
3021             },
3022             {
3023              "listeners" : {
3024               "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}"
3025              },
3026              "xtype" : "Store",
3027              "remoteSort" : true,
3028              "$ sortInfo" : "{ field : 'invdetail_id', direction: 'ASC' }",
3029              "$ xns" : "Roo.data",
3030              "* prop" : "dataSource",
3031              "items" : [
3032               {
3033                "$ url" : "baseURL + '/Roo/invdetail.php'",
3034                "xtype" : "HttpProxy",
3035                "method" : "GET",
3036                "$ xns" : "Roo.data",
3037                "* prop" : "proxy"
3038               },
3039               {
3040                "id" : "id",
3041                "root" : "data",
3042                "xtype" : "JsonReader",
3043                "$ xns" : "Roo.data",
3044                "$ 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]",
3045                "* prop" : "reader",
3046                "totalProperty" : "total"
3047               }
3048              ]
3049             },
3050             {
3051              "pageSize" : 9999,
3052              "xtype" : "PagingToolbar",
3053              "emptyMsg" : "No invdetail found",
3054              "$ xns" : "Roo",
3055              "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
3056              "displayInfo" : true,
3057              "* prop" : "footer"
3058             },
3059             {
3060              "xtype" : "ColumnModel",
3061              "header" : "TX#",
3062              "width" : 60,
3063              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3064              "$ xns" : "Roo.grid",
3065              "* prop" : "colModel[]",
3066              "dataIndex" : "invdetail_id"
3067             },
3068             {
3069              "xtype" : "ColumnModel",
3070              "header" : "Date",
3071              "width" : 75,
3072              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3073              "$ xns" : "Roo.grid",
3074              "* prop" : "colModel[]",
3075              "dataIndex" : "invhist_transdate"
3076             },
3077             {
3078              "xtype" : "ColumnModel",
3079              "header" : "Ref#",
3080              "width" : 75,
3081              "$ 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 }",
3082              "$ xns" : "Roo.grid",
3083              "* prop" : "colModel[]",
3084              "dataIndex" : "invhist_ordnumber"
3085             },
3086             {
3087              "xtype" : "ColumnModel",
3088              "header" : "TX#",
3089              "width" : 60,
3090              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3091              "$ xns" : "Roo.grid",
3092              "* prop" : "colModel[]",
3093              "dataIndex" : "location_name"
3094             },
3095             {
3096              "xtype" : "ColumnModel",
3097              "header" : "Notes",
3098              "width" : 75,
3099              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3100              "$ xns" : "Roo.grid",
3101              "* prop" : "colModel[]",
3102              "dataIndex" : "invhist_comments"
3103             },
3104             {
3105              "align" : "right",
3106              "xtype" : "ColumnModel",
3107              "header" : "Qty Changed",
3108              "width" : 50,
3109              "$ 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}",
3110              "$ xns" : "Roo.grid",
3111              "* prop" : "colModel[]",
3112              "dataIndex" : "invdetail_qty"
3113             },
3114             {
3115              "align" : "right",
3116              "xtype" : "ColumnModel",
3117              "header" : "Qty Changed",
3118              "width" : 75,
3119              "$ 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}",
3120              "$ xns" : "Roo.grid",
3121              "* prop" : "colModel[]",
3122              "dataIndex" : "invhist_value_before"
3123             },
3124             {
3125              "xtype" : "ColumnModel",
3126              "header" : "Posted",
3127              "width" : 40,
3128              "$ 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 }",
3129              "$ xns" : "Roo.grid",
3130              "* prop" : "colModel[]",
3131              "dataIndex" : "invhist_posted"
3132             }
3133            ]
3134           }
3135          ]
3136         }
3137        ]
3138       }
3139      ]
3140     },
3141     {
3142      "region" : "center",
3143      "xtype" : "NestedLayoutPanel",
3144      "title" : "GL Tx",
3145      "$ xns" : "Roo",
3146      "items" : [
3147       {
3148        "xtype" : "BorderLayout",
3149        "$ xns" : "Roo",
3150        "* prop" : "layout",
3151        "items" : [
3152         {
3153          "xtype" : "LayoutRegion",
3154          "$ xns" : "Roo",
3155          "* prop" : "center"
3156         },
3157         {
3158          "xtype" : "LayoutRegion",
3159          "width" : 500,
3160          "$ xns" : "Roo",
3161          "split" : true,
3162          "* prop" : "east"
3163         },
3164         {
3165          "listeners" : {
3166           "|activate" : "function() {\n    _this.gltxpanel = this;\n    if (_this.gltxgrid) {\n        _this.gltxgrid.footer.onClick('first');\n    }\n}"
3167          },
3168          "background" : false,
3169          "region" : "center",
3170          "fitToframe" : true,
3171          "title" : "invdetail",
3172          "xtype" : "GridPanel",
3173          "fitContainer" : true,
3174          "$ xns" : "Roo",
3175          "tableName" : "invdetail",
3176          "items" : [
3177           {
3178            "listeners" : {
3179             "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}",
3180             "|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}"
3181            },
3182            "autoExpandColumn" : "gltrans_accnt_id_accnt_descrip",
3183            "xtype" : "Grid",
3184            "loadMask" : true,
3185            "$ xns" : "Roo.grid",
3186            "* prop" : "grid",
3187            "items" : [
3188             {
3189              "listeners" : {
3190               "selectionchange" : "function (_self)\n{\n    _this.gltxdgrid.footer.onClick('first');;\n}"
3191              },
3192              "xtype" : "RowSelectionModel",
3193              "singleSelect" : true,
3194              "$ xns" : "Roo.grid",
3195              "* prop" : "sm"
3196             },
3197             {
3198              "listeners" : {
3199               "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}"
3200              },
3201              "xtype" : "Store",
3202              "remoteSort" : true,
3203              "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
3204              "$ xns" : "Roo.data",
3205              "* prop" : "dataSource",
3206              "items" : [
3207               {
3208                "$ url" : "baseURL + '/Roo/gltrans.php'",
3209                "xtype" : "HttpProxy",
3210                "method" : "GET",
3211                "$ xns" : "Roo.data",
3212                "* prop" : "proxy"
3213               },
3214               {
3215                "id" : "id",
3216                "root" : "data",
3217                "xtype" : "JsonReader",
3218                "$ xns" : "Roo.data",
3219                "$ 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]",
3220                "* prop" : "reader",
3221                "totalProperty" : "total"
3222               }
3223              ]
3224             },
3225             {
3226              "pageSize" : 9999,
3227              "xtype" : "PagingToolbar",
3228              "emptyMsg" : "No invdetail found",
3229              "$ xns" : "Roo",
3230              "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
3231              "displayInfo" : true,
3232              "* prop" : "footer",
3233              "items" : [
3234               {
3235                "listeners" : {
3236                 "render" : "function (_self)\n{\n    _this.glsalesbtn = _self;\n}",
3237                 "click" : "function (_self, e)\n{\n    (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);\n}"
3238                },
3239                "text" : "Split sales",
3240                "enableToggle" : true,
3241                "pressed" : true,
3242                "xtype" : "Button",
3243                "$ xns" : "Roo.Toolbar"
3244               }
3245              ]
3246             },
3247             {
3248              "xtype" : "ColumnModel",
3249              "header" : "Summary",
3250              "width" : 50,
3251              "$ 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 }",
3252              "$ xns" : "Roo.grid",
3253              "* prop" : "colModel[]",
3254              "dataIndex" : "gltrans_as_summary"
3255             },
3256             {
3257              "xtype" : "ColumnModel",
3258              "header" : "Account",
3259              "width" : 75,
3260              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3261              "$ xns" : "Roo.grid",
3262              "* prop" : "colModel[]",
3263              "dataIndex" : "gltrans_accnt_id_accnt_descrip"
3264             },
3265             {
3266              "align" : "right",
3267              "xtype" : "ColumnModel",
3268              "header" : "Credit",
3269              "width" : 75,
3270              "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }",
3271              "$ xns" : "Roo.grid",
3272              "* prop" : "colModel[]",
3273              "dataIndex" : "gltrans_amount_credit"
3274             },
3275             {
3276              "align" : "right",
3277              "xtype" : "ColumnModel",
3278              "header" : "Debit",
3279              "width" : 75,
3280              "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
3281              "$ xns" : "Roo.grid",
3282              "* prop" : "colModel[]",
3283              "dataIndex" : "gltrans_amount_debit"
3284             },
3285             {
3286              "align" : "right",
3287              "xtype" : "ColumnModel",
3288              "header" : "Sum",
3289              "width" : 75,
3290              "$ renderer" : "function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }",
3291              "$ xns" : "Roo.grid",
3292              "* prop" : "colModel[]",
3293              "dataIndex" : "gltrans_amount_total"
3294             },
3295             {
3296              "align" : "right",
3297              "xtype" : "ColumnModel",
3298              "header" : "Unposted",
3299              "width" : 75,
3300              "$ renderer" : "function(v) { return String.format('<span style=\"color:red\">{0}</span>', Roo.util.Format.number(v,3)); }",
3301              "$ xns" : "Roo.grid",
3302              "* prop" : "colModel[]",
3303              "dataIndex" : "gltrans_amount_total_unposted"
3304             }
3305            ]
3306           }
3307          ]
3308         },
3309         {
3310          "listeners" : {
3311           "|activate" : "function() {\n    _this.gltxdpanel = this;\n    if (_this.gltxdgrid) {\n        _this.gltxdgrid.footer.onClick('first');\n    }\n}"
3312          },
3313          "background" : false,
3314          "region" : "east",
3315          "fitToframe" : true,
3316          "title" : "invdetail",
3317          "xtype" : "GridPanel",
3318          "fitContainer" : true,
3319          "$ xns" : "Roo",
3320          "tableName" : "invdetail",
3321          "items" : [
3322           {
3323            "listeners" : {
3324             "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}",
3325             "|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}"
3326            },
3327            "autoExpandColumn" : "gltrans_notes",
3328            "xtype" : "Grid",
3329            "loadMask" : true,
3330            "$ xns" : "Roo.grid",
3331            "* prop" : "grid",
3332            "items" : [
3333             {
3334              "listeners" : {
3335               "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}"
3336              },
3337              "xtype" : "Store",
3338              "remoteSort" : true,
3339              "$ sortInfo" : "{ field : 'gltrans_docnumber', direction: 'ASC' }",
3340              "$ xns" : "Roo.data",
3341              "* prop" : "dataSource",
3342              "items" : [
3343               {
3344                "$ url" : "baseURL + '/Roo/gltrans.php'",
3345                "xtype" : "HttpProxy",
3346                "method" : "GET",
3347                "$ xns" : "Roo.data",
3348                "* prop" : "proxy"
3349               },
3350               {
3351                "id" : "id",
3352                "root" : "data",
3353                "xtype" : "JsonReader",
3354                "$ xns" : "Roo.data",
3355                "$ 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]",
3356                "* prop" : "reader",
3357                "totalProperty" : "total"
3358               }
3359              ]
3360             },
3361             {
3362              "pageSize" : 9999,
3363              "xtype" : "PagingToolbar",
3364              "emptyMsg" : "No invdetail found",
3365              "$ xns" : "Roo",
3366              "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
3367              "displayInfo" : true,
3368              "* prop" : "footer",
3369              "items" : [
3370               {
3371                "listeners" : {
3372                 "click" : "function (_self, e)\n{\n    new Pman.Download( {\n        grid : _this.gltxdgrid\n    \n    });\n}"
3373                },
3374                "text" : "Download",
3375                "xtype" : "Button",
3376                "$ xns" : "Roo.Toolbar"
3377               }
3378              ]
3379             },
3380             {
3381              "xtype" : "ColumnModel",
3382              "sortable" : true,
3383              "header" : "Ref#",
3384              "width" : 75,
3385              "$ renderer" : "function(v) { return String.format('{0}', v ); }",
3386              "$ xns" : "Roo.grid",
3387              "* prop" : "colModel[]",
3388              "dataIndex" : "gltrans_id"
3389             },
3390             {
3391              "xtype" : "ColumnModel",
3392              "header" : "Date",
3393              "width" : 75,
3394              "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
3395              "$ xns" : "Roo.grid",
3396              "* prop" : "colModel[]",
3397              "dataIndex" : "gltrans_date"
3398             },
3399             {
3400              "xtype" : "ColumnModel",
3401              "header" : "Doc#",
3402              "width" : 75,
3403              "$ 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}",
3404              "$ xns" : "Roo.grid",
3405              "* prop" : "colModel[]",
3406              "dataIndex" : "gltrans_docnumber"
3407             },
3408             {
3409              "xtype" : "ColumnModel",
3410              "header" : "Source",
3411              "width" : 50,
3412              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3413              "$ xns" : "Roo.grid",
3414              "* prop" : "colModel[]",
3415              "dataIndex" : "gltrans_source"
3416             },
3417             {
3418              "xtype" : "ColumnModel",
3419              "header" : "Notes",
3420              "width" : 75,
3421              "$ renderer" : "function(v) { return String.format('{0}', v); }",
3422              "$ xns" : "Roo.grid",
3423              "* prop" : "colModel[]",
3424              "dataIndex" : "gltrans_notes"
3425             },
3426             {
3427              "align" : "right",
3428              "xtype" : "ColumnModel",
3429              "header" : "Amount",
3430              "width" : 75,
3431              "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
3432              "$ xns" : "Roo.grid",
3433              "* prop" : "colModel[]",
3434              "dataIndex" : "gltrans_amount"
3435             },
3436             {
3437              "xtype" : "ColumnModel",
3438              "header" : "Posted",
3439              "width" : 50,
3440              "$ 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 }",
3441              "$ xns" : "Roo.grid",
3442              "* prop" : "colModel[]",
3443              "dataIndex" : "gltrans_posted"
3444             }
3445            ]
3446           }
3447          ]
3448         }
3449        ]
3450       }
3451      ]
3452     },
3453     {
3454      "listeners" : {
3455       "|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}"
3456      },
3457      "background" : true,
3458      "region" : "center",
3459      "fitToframe" : true,
3460      "title" : "Profit",
3461      "xtype" : "GridPanel",
3462      "fitContainer" : true,
3463      "$ xns" : "Roo",
3464      "tableName" : "coitem",
3465      "items" : [
3466       {
3467        "listeners" : {
3468         "|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}"
3469        },
3470        "autoExpandColumn" : "item_number",
3471        "xtype" : "Grid",
3472        "loadMask" : true,
3473        "$ xns" : "Roo.grid",
3474        "* prop" : "grid",
3475        "items" : [
3476         {
3477          "listeners" : {
3478           "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}"
3479          },
3480          "xtype" : "Store",
3481          "remoteSort" : true,
3482          "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
3483          "$ xns" : "Roo.data",
3484          "* prop" : "dataSource",
3485          "items" : [
3486           {
3487            "$ url" : "baseURL + '/Roo/coitem.php'",
3488            "xtype" : "HttpProxy",
3489            "method" : "GET",
3490            "$ xns" : "Roo.data",
3491            "* prop" : "proxy"
3492           },
3493           {
3494            "id" : "id",
3495            "root" : "data",
3496            "xtype" : "JsonReader",
3497            "$ xns" : "Roo.data",
3498            "$ 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]",
3499            "* prop" : "reader",
3500            "totalProperty" : "total"
3501           }
3502          ]
3503         },
3504         {
3505          "pageSize" : 25,
3506          "xtype" : "PagingToolbar",
3507          "emptyMsg" : "No coitem found",
3508          "$ xns" : "Roo",
3509          "displayMsg" : "Displaying coitem{0} - {1} of {2}",
3510          "displayInfo" : true,
3511          "* prop" : "footer"
3512         },
3513         {
3514          "xtype" : "ColumnModel",
3515          "header" : "Item Code",
3516          "width" : 75,
3517          "$ renderer" : "function(v) { return String.format('{0}', v); }",
3518          "$ xns" : "Roo.grid",
3519          "* prop" : "colModel[]",
3520          "dataIndex" : "item_number"
3521         },
3522         {
3523          "xtype" : "ColumnModel",
3524          "header" : "SubTotal",
3525          "width" : 200,
3526          "$ renderer" : "function(v) {\n\n\n     return Roo.util.Format.number( v, 2);\n  }",
3527          "$ xns" : "Roo.grid",
3528          "* prop" : "colModel[]",
3529          "dataIndex" : "calc_subtotal"
3530         },
3531         {
3532          "xtype" : "ColumnModel",
3533          "header" : "Cost of goods",
3534          "width" : 200,
3535          "$ renderer" : "function(v) {\n\n    return Roo.util.Format.number( v, 2);\n  }",
3536          "$ xns" : "Roo.grid",
3537          "* prop" : "colModel[]",
3538          "dataIndex" : "calc_cost_total"
3539         },
3540         {
3541          "xtype" : "ColumnModel",
3542          "header" : "Profit",
3543          "width" : 200,
3544          "$ 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}",
3545          "$ xns" : "Roo.grid",
3546          "* prop" : "colModel[]",
3547          "dataIndex" : "profit"
3548         }
3549        ]
3550       }
3551      ]
3552     },
3553     {
3554      "listeners" : {
3555       "render" : "function (_self)\n{\n    _this.reversalBtn = _self;\n}",
3556       "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}"
3557      },
3558      "text" : "Create CM reversal",
3559      "xtype" : "Button",
3560      "$ xns" : "Roo",
3561      "* prop" : "buttons[]"
3562     },
3563     {
3564      "listeners" : {
3565       "click" : "function (_self, e)\n{\n      if (_this.grid)  _this.grid.stopEditing();\n    _this.dialog.hide();\n}"
3566      },
3567      "text" : "Cancel",
3568      "xtype" : "Button",
3569      "$ xns" : "Roo",
3570      "* prop" : "buttons[]"
3571     },
3572     {
3573      "listeners" : {
3574       "render" : "function (_self)\n{\n    _this.saveBtn = _self;\n}",
3575       "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}"
3576      },
3577      "text" : "Save",
3578      "xtype" : "Button",
3579      "$ xns" : "Roo",
3580      "* prop" : "buttons[]"
3581     }
3582    ]
3583   }
3584  ]
3585 }