Pman.Dialog.XtupleSalesOrder.bjs
authorEdward <edward@roojs.com>
Thu, 25 Jun 2015 09:14:06 +0000 (17:14 +0800)
committerEdward <edward@roojs.com>
Thu, 25 Jun 2015 09:14:06 +0000 (17:14 +0800)
Pman.Dialog.XtupleSalesOrder.js

Pman.Dialog.XtupleSalesOrder.bjs
Pman.Dialog.XtupleSalesOrder.js

index fae45e6..0a190e8 100644 (file)
 {
-    "name" : "Pman.Dialog.XtupleSalesOrder",
-    "parent" : "",
-    "title" : "",
-    "path" : "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Dialog.XtupleSalesOrder.bjs",
-    "permname" : "",
-    "modOrder" : "001",
-    "items" : [
-        {
-            "listeners" : {
-                "|show" : "function () {\n       this.layout.getRegion('center').showPanel(0);\n}"
-            },
-            "modal" : true,
-            "collapsible" : false,
-            "title" : "Edit / Create Sales Order",
-            "xtype" : "LayoutDialog",
-            "width" : 1050,
-            "$ xns" : "Roo",
-            "closable" : true,
-            "resizable" : true,
-            "height" : 620,
-            "items" : [
+ "name" : "Pman.Dialog.XtupleSalesOrder",
+ "parent" : "",
+ "title" : "",
+ "path" : "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Dialog.XtupleSalesOrder.bjs",
+ "permname" : "",
+ "modOrder" : "001",
+ "strings" : {
+  "58ec392a138714456f83d1288f553099" : "tracknum",
+  "42f6d99a2dddc4858882ed8e9a210b52" : "Invoice #",
+  "249ff431aa95198ad6814dd1d2799883" : "Select taxtype",
+  "fce9a6a1bd2a2050eb86d33103f46fd3" : "Invoices",
+  "a2fdeac60e3c5b6c51a92e027fb9d533" : "Target Delivery",
+  "96b0141273eabab320119c467cdcaf17" : "Total",
+  "d682c376c82f68bc65dcd05570d04dfc" : "Payments / Refunds / Credit Memos",
+  "75ba8d70e3692ba200f0e0df37b4d2ae" : "IP address",
+  "9f4f3d35db49c5c2bba70a321a42fa87" : "Find Products",
+  "9d4ba8f5211a3ba238b2032be5991c14" : "Disc%",
+  "e12167aa0a7698e6ebc92b4ce3909b53" : "To",
+  "c4a0f4ddf926328daa2a350db9f9ca00" : "Qty Changed",
+  "99575a08540e6ee585a7b389e8bde351" : "GL Tx",
+  "ec211f7c20af43e742bf2570c3cb84f9" : "Add",
+  "f84e65035f5d2d4a090b8a626c822321" : "List Price",
+  "fc44040a63559bee1157010d4c602422" : "Select location",
+  "62f0de97dd70387d493350e45bfa5583" : "Send Delivery Email",
+  "cc7819055cde3194bb3b136bad5cf58d" : "&nbsp;",
+  "806dca90dbeda894ffb258939f9fef9a" : "Fill empty Ship To",
+  "fce6d3795b41b54dc0dab82df50517c1" : "Select custinfo",
+  "d323a19bad62ff427d0b75dc52674c81" : "#Ret",
+  "c5eae6ea505388a73962c635ac821fba" : "SubTotal",
+  "f2a6c498fb90ee345d997f888fce3b18" : "Delete",
+  "418c5509e2171d55b0aee5c2ea4442b5" : "action",
+  "51e07f52ae2192d23a1b43922e5beb90" : "#TX ship",
+  "607ff05a0e4c02c54b2262cd2e381aff" : "Reserve Stock / Shipments",
+  "689202409e48743b914713f96d93947c" : "Value",
+  "d9db367d7e9d6a3d3ca0346dfa1ff9d2" : "Item Description",
+  "16d2b386b2034b9488996466aaae0b57" : "History",
+  "dd7bf230fde8d4836917806aff6a6b27" : "Address",
+  "986b90fb419e5349dd59b691b0e0e9f6" : "Customer PO#",
+  "7d74f3b92b19da5e606d737d339a9679" : "Item",
+  "c5c8ac6bbc6d7f5c95d0a888527554d3" : "Order Details",
+  "fd216b286b94577ac68c112c0dcaf341" : "TX#",
+  "068f80c7519d0528fb08e82137a72131" : "Products",
+  "b166cb3a96bdb966f3288b8599594d0d" : "Sell @",
+  "1243daf593fa297e07ab03bf06d925af" : "Searching...",
+  "151ccf95db9b81c11bb20fbc302af4b6" : "Select terms",
+  "7eb17faabef94701775df7154f30684b" : "#avail",
+  "f31bbdd1b3e85bccd652680e16935819" : "Source",
+  "086247a9b57fde6eefee2a0c4752242d" : "Automatic",
+  "0a90b1bc4078f74b6f0d117ec7df65af" : "Credit",
+  "27f2870eaa01c99fc83105240ad15f7f" : "Delete All",
+  "5f0c1431b38e3d279bf105d48824b7f3" : "Select ship to",
+  "26453198f2ddac444702879a8f6d61a5" : "Auto Reverse",
+  "780c462e85ba4399a5d42e88f69a15ca" : "Billing",
+  "81dffdb31b9576e343d3f7ffcf721d7e" : "Cost of goods",
+  "813f81532d71077e497863ec9faf16c7" : "Confirm Shipment",
+  "46fc12727bf2c5cc79988ab857ad73b4" : "Print Shipping / Commercial Invoice",
+  "8156649b9de8783c15c822b592c3bac6" : "Reverse Selected",
+  "8c6aab77edc5b8e589b36bcf989683e4" : "Print Picking Slip",
+  "69193f49683ba5a928ae8a27328105ba" : "Print Aus - GST included Invoice",
+  "13dba24862cf9128167a59100e154c8d" : "Print",
+  "4b5a5a93e13bd338d40cf4bae2ca51cb" : "Void Credit Memo",
+  "b80f4ed22929b09103f0c5666ad7a7e1" : "Run Apply Fifo on order",
+  "009534719f8c8221440a5629f497a784" : "Debit",
+  "1abe972d603f3bd61eefc9ac39fb7522" : "#TX Tot",
+  "7b09a122e58c067939744c4a96ff2d77" : "Select salesrep",
+  "56d56144d4e4a42ce450446518c4fc00" : "#Diff",
+  "03ab340b3f99e03cff9e84314ead38c0" : "Qty",
+  "f4c6f851b00d5518bf888815de279aba" : "Notes",
+  "c9cc8cce247e49bae79f15173ce97354" : "Save",
+  "386c339d37e737a436499d423a77df0c" : "Currency",
+  "f4757c5aca5e4410b63c6ec4cd0f2363" : "shiphead",
+  "f97f673be4e5f66aca62b35280d8bcde" : "Print Standard Invoice",
+  "acc95aeaee48871da70cc3bce664728c" : "Select shiptoinfo",
+  "ce26601dac0dea138b7295f02b7620a7" : "Customer",
+  "d335d558a8386d20318888b1f034103d" : "Unshipped Total",
+  "2925dda0ec274c20c0a30d8720eb830b" : "Select curr_name",
+  "72d6d7a1885885bb55a565fd1070581a" : "Import",
+  "9aa6071f39d387792476bd70fed66735" : "Void / Unconfirm",
+  "6f1bf85c9ebb3c7fa26251e1e335e032" : "Terms",
+  "53896265ad28c11cb4997b3c3e3e122d" : "#Ship",
+  "5da618e8e4b89c66fe86e32cdafde142" : "From",
+  "158e64bcd08067d26e9c27679eeced88" : "No Items",
+  "d179a904ac10a39ab574fe803cc29fa3" : "Run Void flagger",
+  "f3d90c6982143029487fb00d4ef19526" : "#invoiced",
+  "80092f7900d59aab765d0ddd35dc7231" : "Add Shipment",
+  "a240fa27925a635b08dc28c9e4f9216d" : "Order",
+  "01d35df7886d24900b1ecb65da6bf21d" : "Receive Payment",
+  "f817f797c422f7ac3404b6223db1a1ee" : "invdetail",
+  "50104a28589c5b6099d3580861c2551a" : "Shipments / Invoices",
+  "e23841a1d7427d8a9297142145dff049" : "Select shipto",
+  "9f1a342d0197aac60ed73e921dc4c1f5" : "Price Details",
+  "2142511303396bd51e0cc25ea8ffe47f" : "Void Payment",
+  "88408722ed9d719c44087292bf8a06cf" : "Prices with GST",
+  "236119342501b1e596bc82013c9cfc42" : "SubTotal w/GST",
+  "4b78ac8eb158840e9638a3aeb26c4a9d" : "Tax",
+  "cb02c723b8a159fea3cd7913d3df7fbc" : "Doc#",
+  "6a813cbab5d0c9d33b1a471839935d88" : "Cust#",
+  "b8feb9ee933bc5cc05615860322e9e7a" : "Post Invoice",
+  "70c6ddcd97af88d0aaac48268c459727" : "Download (as xls)",
+  "66b2bba3de9b8c5d6fb94e9458f1b7f5" : "Show Inventory History",
+  "57cdc7bcd2ca327f3267e2f5ecfa8c6d" : "Edit / Create Sales Order",
+  "48e91c2f1cb7b90612ccae2502c7327f" : "Shipment Comments",
+  "47cb03899dc494703b52c37240fa4c17" : "Stock Tx",
+  "72bb7a9ea8714c52b0c0b8369d6a8dc3" : "Issue Date",
+  "e5d63551ca2d2842661e49a25fd12a67" : "Edit Customer",
+  "7608203603437f0513ba8203a2d39a4f" : "Item Code",
+  "08bd40c7543007ad06e4fce31618f6ec" : "Account",
+  "e963218370d6410e1ee0f8e6128c12d4" : "shipdate",
+  "0ee182201463a0ea31cb073b227fbbbe" : "Print Chinese Invoice With GST in line item",
+  "089ba2b5edc96565fc22c584ecfbb1a6" : "Displaying events{0} - {1} of {2}",
+  "0bcef9c45bd8a48eda1b26eb0c61c869" : "%",
+  "81ceb48a978444906d80119200aa358d" : "Void",
+  "a763436d2b30d54e4aff264b1636827a" : "Discount (Pretax)",
+  "4721299f56b6b7d43591156d1d3f3e82" : "List Price w/GST",
+  "f4ac45b9eb622dcb26c0d4fc1c93b27c" : "Order Comments",
+  "7a113dee68a51f4c5f71264fd0ce3781" : "Item#",
+  "a860ed9926b241b7d4dca2d00610ab2c" : "Outstanding",
+  "290612199861c31d1036b185b4e69b75" : "Summary",
+  "786410e93beb0193d89f8608c54feb4b" : "Select item",
+  "b1bc248a7ff2b2e95569f56de68615df" : "number",
+  "07ca5050e697392c9ed47e6453f1453f" : "Completed",
+  "6b15347cbd1bf352b547741a7525c1b4" : "#shipped",
+  "b3c65c9f85b429821cf931b38386a64d" : "Select Tax Type",
+  "5e33fc1550a56738da96fbaaf57e72f0" : "#TX ret",
+  "16cd452dda9d4398bf6240603eee40a9" : "Posted",
+  "b2f40690858b404ed10e62bdf422c704" : "Amount",
+  "e87de1a5d238411ab34a292be599e9f4" : "Apply To All",
+  "40e6e8652d174c7ceef48df46f9cf25a" : "From Location",
+  "9122d60c0550be8ab070b96d8bbc6358" : "Sell @w/GST",
+  "78ca8a8170f2065057507ddcde63d9ca" : "Tax Zone",
+  "757989a16207ab23076685118640adf3" : "Item Cost",
+  "160ab8f9d6c5d2819fff11dea08d4ef8" : "Download Excel",
+  "0ee72ad23c24d7cfc5c13311abdc3f72" : "Staff I.C.",
+  "511b6a78f5503881ba10ff93b7205ade" : "Create CM reversal",
+  "74002cb040b036511b8d031da591364a" : "Ship to",
+  "c6b4fd215b0cdcb7426519edc0ece828" : "Print Bambini Pro Forma Invoice",
+  "b98c34417c412e0c87faa828f26b9123" : "Uninvoiced Total",
+  "a0d036a1d6a00180df168fa86143e5f8" : "No invdetail found",
+  "de3d17fb46f44fdf066581fbb5fe6113" : "Select Staff",
+  "fbb9d6ec5325d0fe63c19431856a0802" : "Select cntct",
+  "c3ce05eb16c5e0075b4a247b2c4b7bba" : "Bill To (select)",
+  "ec53a8c4f07baed5d8825072c89799be" : "Status",
+  "25d81668fca34c83d0720cc6365d62d6" : "Pre Tax discount",
+  "b25f6c965342495f74899e183efe20a4" : "Void / Unpost",
+  "58733ee735e3160c5c9fa5739fb4d056" : "Unposted",
+  "3ec365dd533ddb7ef3d1c111186ce872" : "Details",
+  "c04b33241cc5478500daf178e3720b63" : "No coitem found",
+  "ea9cf7e47ff33b2be14e6dd07cbcefc6" : "Shipping",
+  "871080cb9d00a8bda1b9f1db3c164341" : "Unit Cost",
+  "820dbd2b8f606aff866c0bbfb6b737c1" : "Changed",
+  "7ce96513eec175e6123b56573750b0dd" : "#reserved",
+  "a0ec87054b5e5b7847d0d8780a01a3d5" : "Sum",
+  "26e09a1ee1517389c7b07f42df65561a" : "Ordered",
+  "bdd31bfe5374e3cdc19a10020eae4b49" : "Add Invoice",
+  "801ab24683a4a8c433c6eb40c48bcd9d" : "Download",
+  "44749712dbec183e983dcd78a7736c41" : "Date",
+  "37656f0f6cf5e5befb1ec7abd3db5804" : "shipvia",
+  "4a2a14210d78f0d82db75d0264030169" : "Supply From",
+  "052fbb9431206b4755090dc53fcef300" : "Void Refund",
+  "c4b515058fab313f403ae427ce7e32b3" : "Update Location to match S/O",
+  "87813307f6e7498b30c5b3d9b2f65f56" : "Displaying invdetail{0} - {1} of {2}",
+  "3a6a3353e3b44ad5359c8e3178b66a54" : "invcdate",
+  "4b84bd35233c0d3d3c36b9a6ce6e0745" : "Order Items",
+  "13abfee28b4564e3fb059420fbedbec5" : "Taxed",
+  "94f475efc6722fd13ab78411c1ef7bd7" : "Sales Rep",
+  "bb4af85913879b95661b81570a2c2e83" : "Discount (Posttax)",
+  "526db6366257755024ed2556000871bc" : "Issue Refund",
+  "594f5bdc5e1519ce9934d276e5bf081f" : "No events found",
+  "d0cc96be641673ad48fc74374fda8137" : "Displaying coitem{0} - {1} of {2}",
+  "ce8ae9da5b7cd6c3df2929543a9af92d" : "Email",
+  "b6dad11e8e2203819164d64fc82b40f1" : "Discount after Tax  Description",
+  "ea4788705e6873b424c65e91c2846b19" : "Cancel",
+  "1b7132f58f9ee9de75e5778ff04f7303" : "Print Delivery Note",
+  "4ee972120bcda675f75222c87cb9d356" : "Who",
+  "a0947dda65e4112f49260243804b6528" : "Xfer all stock to HK",
+  "1d144309cbdf2536723621bf0eac9f33" : "or enter Address",
+  "3d96cc39e5517a284e203ffc8cafcf51" : "Print Bambini Pronto Invoice",
+  "9c9745a343efeacc9efe9b7222b27afb" : "Ref#",
+  "c43b0fbe81e21c0a874a155ce528eebf" : "Apply % Discount of : ",
+  "e8586011952b0d098b0e568f20ca2b1f" : "Select Currency",
+  "fa1cfdb383ea976facbdb20d40d2f811" : "Duplicate Selected",
+  "6ac26fe4e9a39ac45fffe6d6920dac3a" : "Print Chinese Invoice",
+  "182875b6c36a761f1e459624c1d93638" : "Profit",
+  "3ffaf70863d6f46e2719050a37d9ef86" : "Order#",
+  "8fb8fbc1c0bc53b2d01121344410e444" : "Split sales",
+  "09466661df2abefeecf849e52fce8fb4" : "Total "
+ },
+ "items" : [
+  {
+   "listeners" : {
+    "|show" : "function () {\n       this.layout.getRegion('center').showPanel(0);\n}"
+   },
+   "modal" : true,
+   "collapsible" : false,
+   "title" : "Edit / Create Sales Order",
+   "xtype" : "LayoutDialog",
+   "width" : 1050,
+   "$ xns" : "Roo",
+   "closable" : true,
+   "resizable" : true,
+   "height" : 620,
+   "items" : [
+    {
+     "alwaysShowTabs" : true,
+     "xtype" : "LayoutRegion",
+     "$ xns" : "Roo",
+     "tabPosition" : "top",
+     "* prop" : "center",
+     "items" : [
+      {
+       "xtype" : "Toolbar",
+       "$ xns" : "Roo",
+       "* prop" : "toolbar",
+       "items" : [
+        {
+         "xtype" : "Fill",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "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}"
+         },
+         "text" : "Download Excel",
+         "xtype" : "Button",
+         "cls" : "x-btn-text-icon",
+         "$ icon" : "rootURL + '/Pman/templates/images/spreadsheet.gif'",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "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}"
+         },
+         "text" : "Print",
+         "xtype" : "Button",
+         "cls" : "x-btn-text-icon",
+         "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "click" : "function (_self, e)\n{\n\n    _this.addShipmentBtn.fireEvent('click');\n   \n}"
+         },
+         "text" : "Add Shipment",
+         "hidden" : true,
+         "xtype" : "Button",
+         "cls" : "x-btn-text-icon",
+         "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "click" : "function (_self, e)\n{\n\n   Pman.Dialog.XtupleCustomer.show({\n         cust_id : _this.form.findField('cohead_cust_id').getValue()\n  }); \n}"
+         },
+         "text" : "Edit Customer",
+         "xtype" : "Button",
+         "cls" : "x-btn-text-icon",
+         "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "click" : "function (_self, e)\n{\n\n        _this.addInvoiceBtn.fireEvent('click');\n   \n}"
+         },
+         "text" : "Add Invoice",
+         "hidden" : true,
+         "xtype" : "Button",
+         "cls" : "x-btn-text-icon",
+         "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "render" : "function (_self, e)\n{\n    _this.voidBtn = _self;\n}",
+          "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}"
+         },
+         "text" : "Void",
+         "xtype" : "Button",
+         "$ xns" : "Roo.Toolbar"
+        },
+        {
+         "listeners" : {
+          "render" : "function (_self)\n{\n   _this.closeBtn = _self;\n}",
+          "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}"
+         },
+         "text" : "Completed",
+         "xtype" : "Button",
+         "$ xns" : "Roo.Toolbar"
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "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}"
+     },
+     "region" : "center",
+     "title" : "Order Details",
+     "xtype" : "ContentPanel",
+     "$ xns" : "Roo",
+     "items" : [
+      {
+       "listeners" : {
+        "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}",
+        "|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",
+        "|rendered" : "function (form)\n{\n    _this.form= form;\n}\n"
+       },
+       "$ url" : "baseURL + '/Roo/cohead.php'",
+       "method" : "POST",
+       "xtype" : "Form",
+       "style" : "margin:10px;",
+       "$ xns" : "Roo.form",
+       "items" : [
+        {
+         "xtype" : "Column",
+         "$ xns" : "Roo.form",
+         "width" : 435,
+         "items" : [
+          {
+           "xtype" : "FieldSet",
+           "style" : "width:420px",
+           "legend" : "Order",
+           "labelWidth" : 120,
+           "$ xns" : "Roo.form",
+           "items" : [
+            {
+             "xtype" : "Column",
+             "labelWidth" : 100,
+             "width" : 410,
+             "$ xns" : "Roo.form",
+             "items" : [
+              {
+               "xtype" : "Row",
+               "labelWidth" : 100,
+               "width" : 400,
+               "$ xns" : "Roo.form",
+               "items" : [
                 {
-                    "alwaysShowTabs" : true,
-                    "xtype" : "LayoutRegion",
-                    "$ xns" : "Roo",
-                    "tabPosition" : "top",
-                    "* prop" : "center",
-                    "items" : [
-                        {
-                            "xtype" : "Toolbar",
-                            "$ xns" : "Roo",
-                            "* prop" : "toolbar",
-                            "items" : [
-                                {
-                                    "xtype" : "Fill",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "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}"
-                                    },
-                                    "text" : "Download Excel",
-                                    "xtype" : "Button",
-                                    "cls" : "x-btn-text-icon",
-                                    "$ icon" : "rootURL + '/Pman/templates/images/spreadsheet.gif'",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "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}"
-                                    },
-                                    "text" : "Print",
-                                    "xtype" : "Button",
-                                    "cls" : "x-btn-text-icon",
-                                    "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "click" : "function (_self, e)\n{\n\n    _this.addShipmentBtn.fireEvent('click');\n   \n}"
-                                    },
-                                    "text" : "Add Shipment",
-                                    "hidden" : true,
-                                    "xtype" : "Button",
-                                    "cls" : "x-btn-text-icon",
-                                    "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "click" : "function (_self, e)\n{\n\n   Pman.Dialog.XtupleCustomer.show({\n         cust_id : _this.form.findField('cohead_cust_id').getValue()\n  }); \n}"
-                                    },
-                                    "text" : "Edit Customer",
-                                    "xtype" : "Button",
-                                    "cls" : "x-btn-text-icon",
-                                    "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "click" : "function (_self, e)\n{\n\n        _this.addInvoiceBtn.fireEvent('click');\n   \n}"
-                                    },
-                                    "text" : "Add Invoice",
-                                    "hidden" : true,
-                                    "xtype" : "Button",
-                                    "cls" : "x-btn-text-icon",
-                                    "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "render" : "function (_self, e)\n{\n    _this.voidBtn = _self;\n}",
-                                        "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}"
-                                    },
-                                    "text" : "Void",
-                                    "xtype" : "Button",
-                                    "$ xns" : "Roo.Toolbar"
-                                },
-                                {
-                                    "listeners" : {
-                                        "render" : "function (_self)\n{\n   _this.closeBtn = _self;\n}",
-                                        "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}"
-                                    },
-                                    "text" : "Completed",
-                                    "xtype" : "Button",
-                                    "$ xns" : "Roo.Toolbar"
-                                }
-                            ]
-                        }
-                    ]
+                 "fieldLabel" : "Order#",
+                 "xtype" : "TextField",
+                 "emptyText" : "Automatic",
+                 "allowBlank" : true,
+                 "readOnly" : true,
+                 "width" : 120,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_number"
                 },
                 {
-                    "listeners" : {
-                        "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}"
-                    },
-                    "region" : "center",
-                    "xtype" : "ContentPanel",
-                    "title" : "Order Details",
-                    "$ xns" : "Roo",
-                    "items" : [
-                        {
-                            "listeners" : {
-                                "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}",
-                                "|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",
-                                "|rendered" : "function (form)\n{\n    _this.form= form;\n}\n"
-                            },
-                            "$ url" : "baseURL + '/Roo/cohead.php'",
-                            "xtype" : "Form",
-                            "method" : "POST",
-                            "style" : "margin:10px;",
-                            "$ xns" : "Roo.form",
-                            "items" : [
-                                {
-                                    "xtype" : "Column",
-                                    "width" : 435,
-                                    "$ xns" : "Roo.form",
-                                    "items" : [
-                                        {
-                                            "style" : "width:420px",
-                                            "legend" : "Order",
-                                            "xtype" : "FieldSet",
-                                            "labelWidth" : 120,
-                                            "$ xns" : "Roo.form",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Column",
-                                                    "labelWidth" : 100,
-                                                    "width" : 410,
-                                                    "$ xns" : "Roo.form",
-                                                    "items" : [
-                                                        {
-                                                            "xtype" : "Row",
-                                                            "labelWidth" : 100,
-                                                            "width" : 400,
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "fieldLabel" : "Order#",
-                                                                    "emptyText" : "Automatic",
-                                                                    "xtype" : "TextField",
-                                                                    "allowBlank" : true,
-                                                                    "readOnly" : true,
-                                                                    "width" : 120,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_number"
-                                                                },
-                                                                {
-                                                                    "style" : "float:left",
-                                                                    "xtype" : "Row",
-                                                                    "labelWidth" : 50,
-                                                                    "width" : 150,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "items" : [
-                                                                        {
-                                                                            "fieldLabel" : "Cust#",
-                                                                            "xtype" : "TextField",
-                                                                            "allowBlank" : true,
-                                                                            "readOnly" : true,
-                                                                            "width" : 110,
-                                                                            "$ xns" : "Roo.form",
-                                                                            "name" : "cohead_cust_id_cust_number"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "forceSelection" : true,
-                                                            "fieldLabel" : "Customer",
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 20,
-                                                            "hiddenName" : "cohead_cust_id",
-                                                            "minChars" : 2,
-                                                            "valueField" : "cust_id",
-                                                            "xtype" : "TextField",
-                                                            "readOnly" : true,
-                                                            "typeAhead" : true,
-                                                            "editable" : false,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_cust_id_cust_name",
-                                                            "qtip" : "Select custinfo",
-                                                            "queryParam" : "query[cust_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>",
-                                                            "loadingText" : "Searching..."
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Customer PO#",
-                                                            "xtype" : "TextField",
-                                                            "$ xns" : "Roo.form",
-                                                            "width" : 150,
-                                                            "name" : "cohead_custponumber"
-                                                        },
-                                                        {
-                                                            "format" : "Y-m-d",
-                                                            "fieldLabel" : "Ordered",
-                                                            "xtype" : "DateField",
-                                                            "allowBlank" : false,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_orderdate"
-                                                        },
-                                                        {
-                                                            "xtype" : "Row",
-                                                            "labelWidth" : 100,
-                                                            "width" : 500,
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "format" : "Y-m-d",
-                                                                    "fieldLabel" : "Target Delivery",
-                                                                    "xtype" : "DateField",
-                                                                    "allowBlank" : false,
-                                                                    "width" : 100,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_targetdate"
-                                                                },
-                                                                {
-                                                                    "hideLabels" : true,
-                                                                    "xtype" : "Row",
-                                                                    "$ xns" : "Roo.form",
-                                                                    "items" : [
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "check" : "function (_self, checked)\n{\n    if(checked){\n        _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());\n    }\n}"
-                                                                            },
-                                                                            "inputValue" : 1,
-                                                                            "xtype" : "Checkbox",
-                                                                            "boxLabel" : "same as order",
-                                                                            "$ xns" : "Roo.form",
-                                                                            "name" : "_same_as_order"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "fieldLabel" : "Supply From",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 200,
-                                                            "displayField" : "location_name",
-                                                            "emptyText" : "Supply From",
-                                                            "hiddenName" : "cohead_location_src",
-                                                            "minChars" : 2,
-                                                            "valueField" : "location_id",
-                                                            "xtype" : "ComboBox",
-                                                            "allowBlank" : false,
-                                                            "typeAhead" : false,
-                                                            "editable" : true,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_location_src_location_name",
-                                                            "qtip" : "Select terms",
-                                                            "queryParam" : "query[location_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|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"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/location.php'",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "method" : "GET",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "location_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "style" : "width:420px",
-                                            "legend" : "Details",
-                                            "xtype" : "FieldSet",
-                                            "labelWidth" : 100,
-                                            "$ xns" : "Roo.form",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Column",
-                                                    "labelWidth" : 100,
-                                                    "width" : 420,
-                                                    "$ xns" : "Roo.form",
-                                                    "items" : [
-                                                        {
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "fieldLabel" : "Terms",
-                                                            "pageSize" : 20,
-                                                            "xtype" : "ComboBox",
-                                                            "emptyText" : "Select terms",
-                                                            "minChars" : 2,
-                                                            "valueField" : "terms_id",
-                                                            "displayField" : "terms_descrip",
-                                                            "hiddenName" : "cohead_terms_id",
-                                                            "allowBlank" : false,
-                                                            "typeAhead" : true,
-                                                            "editable" : false,
-                                                            "$ xns" : "Roo.form",
-                                                            "width" : 300,
-                                                            "qtip" : "Select terms",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>",
-                                                            "queryParam" : "query[terms_descrip]",
-                                                            "name" : "cohead_terms_id_terms_descrip",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'terms_descrip' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/terms.php'",
-                                                                            "method" : "GET",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "terms_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "$ fields" : "[{\"name\":\"terms_id\",\"type\":\"int\"},\"terms_descrip\"]",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "alwaysQuery" : true,
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "fieldLabel" : "Sales Rep",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 80,
-                                                            "displayField" : "salesrep_name",
-                                                            "emptyText" : "Select salesrep",
-                                                            "hiddenName" : "cohead_display_salesrep_id",
-                                                            "minChars" : 2,
-                                                            "valueField" : "salesrep_id",
-                                                            "xtype" : "ComboBox",
-                                                            "allowBlank" : true,
-                                                            "typeAhead" : true,
-                                                            "editable" : false,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_display_salesrep_id_salesrep_name",
-                                                            "qtip" : "Select salesrep",
-                                                            "queryParam" : "query[salesrep_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/salesrep.php'",
-                                                                            "method" : "GET",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "salesrep_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "alwaysQuery" : true,
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "fieldLabel" : "Staff I.C.",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 80,
-                                                            "displayField" : "salesrep_name",
-                                                            "emptyText" : "Select Staff",
-                                                            "hiddenName" : "cohead_salesrep_id",
-                                                            "minChars" : 2,
-                                                            "valueField" : "salesrep_id",
-                                                            "xtype" : "ComboBox",
-                                                            "allowBlank" : false,
-                                                            "typeAhead" : true,
-                                                            "editable" : false,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_salesrep_id_salesrep_name",
-                                                            "qtip" : "Select salesrep",
-                                                            "queryParam" : "query[salesrep_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/salesrep.php'",
-                                                                            "method" : "GET",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "salesrep_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Order Comments",
-                                                            "xtype" : "TextArea",
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_ordercomments",
-                                                            "height" : 80
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "style" : "width:420px",
-                                            "xtype" : "FieldSet",
-                                            "legend" : "Billing",
-                                            "$ xns" : "Roo.form",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Column",
-                                                    "labelWidth" : 50,
-                                                    "width" : 420,
-                                                    "$ xns" : "Roo.form",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "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}",
-                                                                "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}"
-                                                            },
-                                                            "alwaysQuery" : true,
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "fieldLabel" : "Bill To (select)",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 20,
-                                                            "displayField" : "cntct_name",
-                                                            "emptyText" : "Select cntct",
-                                                            "hiddenName" : "cohead_billto_cntct_id",
-                                                            "minChars" : 2,
-                                                            "valueField" : "cntct_id",
-                                                            "xtype" : "ComboBox",
-                                                            "allowBlank" : false,
-                                                            "typeAhead" : true,
-                                                            "editable" : true,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_billto_cntct_id_cntct_name",
-                                                            "qtip" : "Select cntct",
-                                                            "queryParam" : "query[cntct_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|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"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/cntct.php'",
-                                                                            "method" : "GET",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "cntct_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "fieldLabel" : "or enter Address",
-                                                            "xtype" : "TextArea",
-                                                            "$ 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",
-                                                            "readOnly" : true,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "billto_address"
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Email",
-                                                            "xtype" : "DisplayField",
-                                                            "$ valueRenderer" : "function(v)\n{\n \n    return v ? String.format('<a href=\"mailto:{0}\" target=\"_blank\">{0}</a>',v) : '';\n}",
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "billto_email"
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "Column",
-                                    "style" : "margin-left:10px",
-                                    "width" : 435,
-                                    "$ xns" : "Roo.form",
-                                    "items" : [
-                                        {
-                                            "legend" : "Price Details",
-                                            "xtype" : "FieldSet",
-                                            "style" : "width:420px",
-                                            "labelWidth" : 50,
-                                            "$ xns" : "Roo.form",
-                                            "items" : [
-                                                {
-                                                    "labelAlign" : "right",
-                                                    "xtype" : "Column",
-                                                    "labelWidth" : 300,
-                                                    "width" : 420,
-                                                    "$ xns" : "Roo.form",
-                                                    "items" : [
-                                                        {
-                                                            "labelAlign" : "top",
-                                                            "xtype" : "Row",
-                                                            "labelSeparator" : "&nbsp;",
-                                                            "width" : 500,
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "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}"
-                                                                    },
-                                                                    "listWidth" : 400,
-                                                                    "triggerAction" : "all",
-                                                                    "fieldLabel" : "Currency",
-                                                                    "forceSelection" : true,
-                                                                    "selectOnFocus" : true,
-                                                                    "pageSize" : 20,
-                                                                    "displayField" : "curr_name",
-                                                                    "emptyText" : "Select curr_name",
-                                                                    "hiddenName" : "cohead_curr_id",
-                                                                    "minChars" : 2,
-                                                                    "valueField" : "curr_id",
-                                                                    "xtype" : "ComboBox",
-                                                                    "allowBlank" : false,
-                                                                    "typeAhead" : true,
-                                                                    "editable" : false,
-                                                                    "width" : 285,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_curr_id_curr_name",
-                                                                    "qtip" : "Select Currency",
-                                                                    "queryParam" : "query[curr_name]",
-                                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>",
-                                                                    "loadingText" : "Searching...",
-                                                                    "items" : [
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n   \n}\n"
-                                                                            },
-                                                                            "xtype" : "Store",
-                                                                            "remoteSort" : true,
-                                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'curr_symbol' }",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "store",
-                                                                            "items" : [
-                                                                                {
-                                                                                    "$ url" : "baseURL + '/Roo/curr_symbol.php'",
-                                                                                    "method" : "GET",
-                                                                                    "xtype" : "HttpProxy",
-                                                                                    "$ xns" : "Roo.data",
-                                                                                    "* prop" : "proxy"
-                                                                                },
-                                                                                {
-                                                                                    "id" : "curr_id",
-                                                                                    "root" : "data",
-                                                                                    "xtype" : "JsonReader",
-                                                                                    "$ xns" : "Roo.data",
-                                                                                    "$ fields" : "[{\"name\":\"curr_id\",\"type\":\"int\"},\"curr_symbol\"]",
-                                                                                    "* prop" : "reader",
-                                                                                    "totalProperty" : "total"
-                                                                                }
-                                                                            ]
-                                                                        }
-                                                                    ]
-                                                                },
-                                                                {
-                                                                    "fieldLabel" : "Products",
-                                                                    "xtype" : "NumberField",
-                                                                    "cls" : "roo-align-right",
-                                                                    "readOnly" : true,
-                                                                    "allowDecimals" : true,
-                                                                    "decimalPrecision" : 3,
-                                                                    "width" : 100,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_subtotal"
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "labelAlign" : "top",
-                                                            "xtype" : "Row",
-                                                            "labelSeparator" : "&nbsp;",
-                                                            "width" : 500,
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "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}"
-                                                                    },
-                                                                    "listWidth" : 400,
-                                                                    "triggerAction" : "all",
-                                                                    "fieldLabel" : "Tax Zone",
-                                                                    "forceSelection" : true,
-                                                                    "selectOnFocus" : true,
-                                                                    "pageSize" : 20,
-                                                                    "displayField" : "taxzone_descrip",
-                                                                    "emptyText" : "Select taxtype",
-                                                                    "hiddenName" : "cohead_taxzone_id",
-                                                                    "minChars" : 2,
-                                                                    "valueField" : "taxzone_id",
-                                                                    "xtype" : "ComboBox",
-                                                                    "allowBlank" : false,
-                                                                    "typeAhead" : true,
-                                                                    "editable" : false,
-                                                                    "width" : 285,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_taxzone_id_taxzone_descrip",
-                                                                    "qtip" : "Select taxtype",
-                                                                    "queryParam" : "query[taxzone_descrip]",
-                                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>",
-                                                                    "loadingText" : "Searching...",
-                                                                    "items" : [
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "|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"
-                                                                            },
-                                                                            "xtype" : "Store",
-                                                                            "remoteSort" : true,
-                                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'taxzone_descrip' }",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "store",
-                                                                            "items" : [
-                                                                                {
-                                                                                    "$ url" : "baseURL + '/Roo/taxzone.php'",
-                                                                                    "xtype" : "HttpProxy",
-                                                                                    "method" : "GET",
-                                                                                    "$ xns" : "Roo.data",
-                                                                                    "* prop" : "proxy"
-                                                                                },
-                                                                                {
-                                                                                    "id" : "taxzone_id",
-                                                                                    "root" : "data",
-                                                                                    "xtype" : "JsonReader",
-                                                                                    "$ fields" : "[{\"name\":\"taxzone_id\",\"type\":\"int\"},\"taxzone_descrip\"]",
-                                                                                    "$ xns" : "Roo.data",
-                                                                                    "* prop" : "reader",
-                                                                                    "totalProperty" : "total"
-                                                                                }
-                                                                            ]
-                                                                        }
-                                                                    ]
-                                                                },
-                                                                {
-                                                                    "fieldLabel" : "Tax",
-                                                                    "xtype" : "NumberField",
-                                                                    "cls" : "roo-align-right",
-                                                                    "readOnly" : true,
-                                                                    "allowDecimals" : true,
-                                                                    "decimalPrecision" : 3,
-                                                                    "width" : 100,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_tax"
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Pre Tax discount",
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "roo-align-right",
-                                                            "readOnly" : true,
-                                                            "allowDecimals" : true,
-                                                            "decimalPrecision" : 3,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_pretax_discount"
-                                                        },
-                                                        {
-                                                            "labelAlign" : "top",
-                                                            "xtype" : "Row",
-                                                            "labelSeparator" : "&nbsp;",
-                                                            "width" : 500,
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "fieldLabel" : "Discount after Tax  Description",
-                                                                    "xtype" : "TextField",
-                                                                    "width" : 230,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_misc_descrip"
-                                                                },
-                                                                {
-                                                                    "listeners" : {
-                                                                        "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}"
-                                                                    },
-                                                                    "fieldLabel" : "%",
-                                                                    "xtype" : "NumberField",
-                                                                    "$ 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",
-                                                                    "cls" : "roo-align-right",
-                                                                    "allowDecimals" : true,
-                                                                    "decimalPrecision" : 1,
-                                                                    "width" : 35,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_misc_per"
-                                                                },
-                                                                {
-                                                                    "listeners" : {
-                                                                        "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}"
-                                                                    },
-                                                                    "fieldLabel" : "&nbsp;",
-                                                                    "xtype" : "NumberField",
-                                                                    "cls" : "roo-align-right",
-                                                                    "allowDecimals" : true,
-                                                                    "decimalPrecision" : 3,
-                                                                    "width" : 100,
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "cohead_posttax_discount"
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Total",
-                                                            "$ 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",
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "roo-align-right",
-                                                            "readOnly" : true,
-                                                            "allowDecimals" : true,
-                                                            "decimalPrecision" : 3,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_total"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "keyup" : "function (_self, e)\n{\n    _this.form.findField('cohead_total').recalc();\n}"
-                                                            },
-                                                            "fieldLabel" : "Shipping",
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "roo-align-right",
-                                                            "allowDecimals" : true,
-                                                            "decimalPrecision" : 3,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_freight"
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Unshipped Total",
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "roo-align-right",
-                                                            "readOnly" : true,
-                                                            "allowDecimals" : true,
-                                                            "decimalPrecision" : 3,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_unshipped"
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Uninvoiced Total",
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "roo-align-right",
-                                                            "readOnly" : true,
-                                                            "allowDecimals" : true,
-                                                            "decimalPrecision" : 3,
-                                                            "width" : 100,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_uninvoiced"
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "style" : "width:420px",
-                                            "xtype" : "FieldSet",
-                                            "legend" : "Shipping",
-                                            "$ xns" : "Roo.form",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Column",
-                                                    "labelWidth" : 50,
-                                                    "width" : 420,
-                                                    "$ xns" : "Roo.form",
-                                                    "items" : [
-                                                        {
-                                                            "xtype" : "Row",
-                                                            "labelSeparator" : "&nbsp;",
-                                                            "$ xns" : "Roo.form",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "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}"
-                                                                    },
-                                                                    "xtype" : "Checkbox",
-                                                                    "boxLabel" : "Same as Billing",
-                                                                    "$ xns" : "Roo.form",
-                                                                    "name" : "_shipto_same"
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}",
-                                                                "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}"
-                                                            },
-                                                            "alwaysQuery" : true,
-                                                            "listWidth" : 400,
-                                                            "triggerAction" : "all",
-                                                            "fieldLabel" : "Ship to",
-                                                            "forceSelection" : true,
-                                                            "selectOnFocus" : true,
-                                                            "pageSize" : 20,
-                                                            "displayField" : "cntct_name",
-                                                            "emptyText" : "Select ship to",
-                                                            "hiddenName" : "cohead_shipto_cntct_id",
-                                                            "minChars" : 2,
-                                                            "valueField" : "cntct_id",
-                                                            "xtype" : "ComboBox",
-                                                            "allowBlank" : false,
-                                                            "typeAhead" : true,
-                                                            "editable" : true,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "cohead_shipto_cntct_id_cntct_name",
-                                                            "qtip" : "Select shiptoinfo",
-                                                            "queryParam" : "query[cntct_name]",
-                                                            "tpl" : "<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>",
-                                                            "loadingText" : "Searching...",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "|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"
-                                                                    },
-                                                                    "xtype" : "Store",
-                                                                    "remoteSort" : true,
-                                                                    "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "store",
-                                                                    "items" : [
-                                                                        {
-                                                                            "$ url" : "baseURL + '/Roo/cntct.php'",
-                                                                            "method" : "GET",
-                                                                            "xtype" : "HttpProxy",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "* prop" : "proxy"
-                                                                        },
-                                                                        {
-                                                                            "id" : "cntct_id",
-                                                                            "root" : "data",
-                                                                            "xtype" : "JsonReader",
-                                                                            "$ xns" : "Roo.data",
-                                                                            "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
-                                                                            "* prop" : "reader",
-                                                                            "totalProperty" : "total"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "fieldLabel" : "Address",
-                                                            "xtype" : "TextArea",
-                                                            "$ 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",
-                                                            "readOnly" : true,
-                                                            "width" : 300,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "shipto_address"
-                                                        },
-                                                        {
-                                                            "fieldLabel" : "Shipment Comments",
-                                                            "xtype" : "TextArea",
-                                                            "$ xns" : "Roo.form",
-                                                            "width" : 300,
-                                                            "name" : "cohead_shipcomments"
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_id"
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_shipto_id"
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_shipto_id_shipto_name"
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_max_linenumber"
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_cust_id"
-                                },
-                                {
-                                    "$ 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",
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "cohead_misc"
-                                },
-                                {
-                                    "xtype" : "Hidden",
-                                    "$ xns" : "Roo.form",
-                                    "name" : "taxzone_rate"
-                                }
-                            ]
-                        }
-                    ]
+                 "style" : "float:left",
+                 "xtype" : "Row",
+                 "labelWidth" : 50,
+                 "width" : 150,
+                 "$ xns" : "Roo.form",
+                 "items" : [
+                  {
+                   "fieldLabel" : "Cust#",
+                   "xtype" : "TextField",
+                   "allowBlank" : true,
+                   "readOnly" : true,
+                   "width" : 110,
+                   "$ xns" : "Roo.form",
+                   "name" : "cohead_cust_id_cust_number"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "forceSelection" : true,
+               "fieldLabel" : "Customer",
+               "selectOnFocus" : true,
+               "pageSize" : 20,
+               "hiddenName" : "cohead_cust_id",
+               "minChars" : 2,
+               "valueField" : "cust_id",
+               "xtype" : "TextField",
+               "readOnly" : true,
+               "typeAhead" : true,
+               "editable" : false,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_cust_id_cust_name",
+               "qtip" : "Select custinfo",
+               "queryParam" : "query[cust_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>",
+               "loadingText" : "Searching..."
+              },
+              {
+               "fieldLabel" : "Customer PO#",
+               "xtype" : "TextField",
+               "$ xns" : "Roo.form",
+               "width" : 150,
+               "name" : "cohead_custponumber"
+              },
+              {
+               "format" : "Y-m-d",
+               "fieldLabel" : "Ordered",
+               "xtype" : "DateField",
+               "allowBlank" : false,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_orderdate"
+              },
+              {
+               "xtype" : "Row",
+               "labelWidth" : 100,
+               "width" : 500,
+               "$ xns" : "Roo.form",
+               "items" : [
+                {
+                 "format" : "Y-m-d",
+                 "fieldLabel" : "Target Delivery",
+                 "xtype" : "DateField",
+                 "allowBlank" : false,
+                 "width" : 100,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_targetdate"
                 },
                 {
-                    "listeners" : {
-                        "deactivate" : "function (_self)\n{\n    if(_this.grid){\n        _this.grid.stopEditing();\n    }\n}",
-                        "|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}"
+                 "hideLabels" : true,
+                 "xtype" : "Row",
+                 "$ xns" : "Roo.form",
+                 "items" : [
+                  {
+                   "listeners" : {
+                    "check" : "function (_self, checked)\n{\n    if(checked){\n        _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());\n    }\n}"
+                   },
+                   "inputValue" : 1,
+                   "xtype" : "Checkbox",
+                   "boxLabel" : "same as order",
+                   "$ xns" : "Roo.form",
+                   "name" : "_same_as_order"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "fieldLabel" : "Supply From",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "pageSize" : 200,
+               "displayField" : "location_name",
+               "emptyText" : "Supply From",
+               "hiddenName" : "cohead_location_src",
+               "minChars" : 2,
+               "valueField" : "location_id",
+               "xtype" : "ComboBox",
+               "allowBlank" : false,
+               "typeAhead" : false,
+               "editable" : true,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_location_src_location_name",
+               "qtip" : "Select terms",
+               "queryParam" : "query[location_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|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"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/location.php'",
+                   "method" : "GET",
+                   "xtype" : "HttpProxy",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "location_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "xtype" : "FieldSet",
+           "style" : "width:420px",
+           "legend" : "Details",
+           "labelWidth" : 100,
+           "$ xns" : "Roo.form",
+           "items" : [
+            {
+             "xtype" : "Column",
+             "labelWidth" : 100,
+             "width" : 420,
+             "$ xns" : "Roo.form",
+             "items" : [
+              {
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "fieldLabel" : "Terms",
+               "pageSize" : 20,
+               "xtype" : "ComboBox",
+               "emptyText" : "Select terms",
+               "minChars" : 2,
+               "valueField" : "terms_id",
+               "displayField" : "terms_descrip",
+               "hiddenName" : "cohead_terms_id",
+               "allowBlank" : false,
+               "typeAhead" : true,
+               "editable" : false,
+               "$ xns" : "Roo.form",
+               "width" : 300,
+               "qtip" : "Select terms",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>",
+               "queryParam" : "query[terms_descrip]",
+               "name" : "cohead_terms_id_terms_descrip",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'terms_descrip' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/terms.php'",
+                   "xtype" : "HttpProxy",
+                   "method" : "GET",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "terms_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ xns" : "Roo.data",
+                   "$ fields" : "[{\"name\":\"terms_id\",\"type\":\"int\"},\"terms_descrip\"]",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "alwaysQuery" : true,
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "fieldLabel" : "Sales Rep",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "pageSize" : 80,
+               "displayField" : "salesrep_name",
+               "emptyText" : "Select salesrep",
+               "hiddenName" : "cohead_display_salesrep_id",
+               "minChars" : 2,
+               "valueField" : "salesrep_id",
+               "xtype" : "ComboBox",
+               "allowBlank" : true,
+               "typeAhead" : true,
+               "editable" : false,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_display_salesrep_id_salesrep_name",
+               "qtip" : "Select salesrep",
+               "queryParam" : "query[salesrep_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/salesrep.php'",
+                   "xtype" : "HttpProxy",
+                   "method" : "GET",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "salesrep_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ xns" : "Roo.data",
+                   "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "alwaysQuery" : true,
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "fieldLabel" : "Staff I.C.",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "pageSize" : 80,
+               "displayField" : "salesrep_name",
+               "emptyText" : "Select Staff",
+               "hiddenName" : "cohead_salesrep_id",
+               "minChars" : 2,
+               "valueField" : "salesrep_id",
+               "xtype" : "ComboBox",
+               "allowBlank" : false,
+               "typeAhead" : true,
+               "editable" : false,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_salesrep_id_salesrep_name",
+               "qtip" : "Select salesrep",
+               "queryParam" : "query[salesrep_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'salesrep_name' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/salesrep.php'",
+                   "xtype" : "HttpProxy",
+                   "method" : "GET",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "salesrep_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ xns" : "Roo.data",
+                   "$ fields" : "[{\"name\":\"salesrep_id\",\"type\":\"int\"},\"salesrep_name\"]",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "fieldLabel" : "Order Comments",
+               "xtype" : "TextArea",
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_ordercomments",
+               "height" : 80
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "legend" : "Billing",
+           "style" : "width:420px",
+           "xtype" : "FieldSet",
+           "$ xns" : "Roo.form",
+           "items" : [
+            {
+             "xtype" : "Column",
+             "labelWidth" : 50,
+             "width" : 420,
+             "$ xns" : "Roo.form",
+             "items" : [
+              {
+               "listeners" : {
+                "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}",
+                "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}"
+               },
+               "alwaysQuery" : true,
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "fieldLabel" : "Bill To (select)",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "pageSize" : 20,
+               "displayField" : "cntct_name",
+               "emptyText" : "Select cntct",
+               "hiddenName" : "cohead_billto_cntct_id",
+               "minChars" : 2,
+               "valueField" : "cntct_id",
+               "xtype" : "ComboBox",
+               "allowBlank" : false,
+               "typeAhead" : true,
+               "editable" : true,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_billto_cntct_id_cntct_name",
+               "qtip" : "Select cntct",
+               "queryParam" : "query[cntct_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|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"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/cntct.php'",
+                   "xtype" : "HttpProxy",
+                   "method" : "GET",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "cntct_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ xns" : "Roo.data",
+                   "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "fieldLabel" : "or enter Address",
+               "$ 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",
+               "xtype" : "TextArea",
+               "readOnly" : true,
+               "$ xns" : "Roo.form",
+               "name" : "billto_address"
+              },
+              {
+               "fieldLabel" : "Email",
+               "xtype" : "DisplayField",
+               "$ valueRenderer" : "function(v)\n{\n \n    return v ? String.format('<a href=\"mailto:{0}\" target=\"_blank\">{0}</a>',v) : '';\n}",
+               "$ xns" : "Roo.form",
+               "name" : "billto_email"
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "xtype" : "Column",
+         "style" : "margin-left:10px",
+         "width" : 435,
+         "$ xns" : "Roo.form",
+         "items" : [
+          {
+           "style" : "width:420px",
+           "legend" : "Price Details",
+           "xtype" : "FieldSet",
+           "labelWidth" : 50,
+           "$ xns" : "Roo.form",
+           "items" : [
+            {
+             "labelAlign" : "right",
+             "xtype" : "Column",
+             "labelWidth" : 300,
+             "width" : 420,
+             "$ xns" : "Roo.form",
+             "items" : [
+              {
+               "labelAlign" : "top",
+               "xtype" : "Row",
+               "labelSeparator" : "&nbsp;",
+               "width" : 500,
+               "$ xns" : "Roo.form",
+               "items" : [
+                {
+                 "listeners" : {
+                  "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}"
+                 },
+                 "listWidth" : 400,
+                 "triggerAction" : "all",
+                 "fieldLabel" : "Currency",
+                 "forceSelection" : true,
+                 "selectOnFocus" : true,
+                 "pageSize" : 20,
+                 "displayField" : "curr_name",
+                 "emptyText" : "Select curr_name",
+                 "hiddenName" : "cohead_curr_id",
+                 "minChars" : 2,
+                 "valueField" : "curr_id",
+                 "xtype" : "ComboBox",
+                 "allowBlank" : false,
+                 "typeAhead" : true,
+                 "editable" : false,
+                 "width" : 285,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_curr_id_curr_name",
+                 "qtip" : "Select Currency",
+                 "queryParam" : "query[curr_name]",
+                 "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>",
+                 "loadingText" : "Searching...",
+                 "items" : [
+                  {
+                   "listeners" : {
+                    "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n   \n}\n"
+                   },
+                   "xtype" : "Store",
+                   "remoteSort" : true,
+                   "$ sortInfo" : "{ direction : 'ASC', field: 'curr_symbol' }",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "store",
+                   "items" : [
+                    {
+                     "$ url" : "baseURL + '/Roo/curr_symbol.php'",
+                     "xtype" : "HttpProxy",
+                     "method" : "GET",
+                     "$ xns" : "Roo.data",
+                     "* prop" : "proxy"
                     },
-                    "fitToframe" : true,
-                    "background" : true,
-                    "region" : "center",
-                    "title" : "Order Items",
-                    "xtype" : "GridPanel",
-                    "fitContainer" : true,
-                    "$ xns" : "Roo",
-                    "tableName" : "coitem",
-                    "items" : [
-                        {
-                            "listeners" : {
-                                "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}",
-                                "|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}",
-                                "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}",
-                                "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",
-                                "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}"
-                            },
-                            "autoExpandColumn" : "item_descrip1",
-                            "xtype" : "EditorGrid",
-                            "loadMask" : true,
-                            "$ 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",
-                            "clicksToEdit" : 1,
-                            "$ xns" : "Roo.grid",
-                            "* prop" : "grid",
-                            "items" : [
-                                {
-                                    "listeners" : {
-                                        "tabend" : "function (_self)\n{\n    _this.addItemBtn.fireEvent('click', _this.addItemBtn);\n}",
-                                        "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}"
-                                    },
-                                    "xtype" : "CellSelectionModel",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "sm",
-                                    "enter_is_tab" : true
-                                },
-                                {
-                                    "pageSize" : 100,
-                                    "xtype" : "PagingToolbar",
-                                    "emptyMsg" : "No Items",
-                                    "$ xns" : "Roo",
-                                    "displayInfo" : true,
-                                    "$ 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",
-                                    "* prop" : "footer",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Fill empty Ship To",
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Update Location to match S/O",
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}",
-                                                "render" : "function (_self)\n{\n    _this.showgstBtn = _self;\n}"
-                                            },
-                                            "text" : "Prices with GST",
-                                            "enableToggle" : true,
-                                            "minWidth" : 100,
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        }
-                                    ]
-                                },
-                                {
-                                    "listeners" : {
-                                        "|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}",
-                                        "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  ",
-                                        "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}"
-                                    },
-                                    "xtype" : "Store",
-                                    "remoteSort" : true,
-                                    "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
-                                    "$ xns" : "Roo.data",
-                                    "* prop" : "dataSource",
-                                    "items" : [
-                                        {
-                                            "$ url" : "baseURL + '/Roo/coitem.php'",
-                                            "xtype" : "HttpProxy",
-                                            "method" : "GET",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "proxy"
-                                        },
-                                        {
-                                            "id" : "coitem_id",
-                                            "root" : "data",
-                                            "xtype" : "JsonReader",
-                                            "$ 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]",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "reader",
-                                            "# 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\"}",
-                                            "totalProperty" : "total"
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "Toolbar",
-                                    "$ xns" : "Roo",
-                                    "* prop" : "toolbar",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "|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",
-                                                "render" : "function (_self)\n{\n    _this.addItemBtn = _self;\n}"
-                                            },
-                                            "text" : "Add",
-                                            "xtype" : "Button",
-                                            "cls" : "x-btn-text-icon",
-                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Find Products",
-                                            "xtype" : "Button",
-                                            "cls" : "x-btn-text-icon",
-                                            "$ icon" : "rootURL + '/Pman/templates/images/search.gif'",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "|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",
-                                                "render" : "function (_self)\n{\n    _this.xferAll  = _self;\n}"
-                                            },
-                                            "text" : "Xfer all stock to HK",
-                                            "hidden" : true,
-                                            "xtype" : "Button",
-                                            "cls" : "x-btn-text-icon",
-                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Show Inventory History",
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "xtype" : "Separator",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "text" : "Apply % Discount of : ",
-                                            "xtype" : "TextItem",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "render" : "function (_self)\n{\n    _this._applyDiscount = _self;\n}"
-                                            },
-                                            "xtype" : "TextField",
-                                            "$ xns" : "Roo.form",
-                                            "width" : 40
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Apply To All",
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "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}"
-                                            },
-                                            "text" : "Import",
-                                            "xtype" : "Button",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "xtype" : "Fill",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "|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        "
-                                            },
-                                            "text" : "Delete",
-                                            "xtype" : "Button",
-                                            "cls" : "x-btn-text-icon",
-                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                            "$ xns" : "Roo.Toolbar"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "|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        "
-                                            },
-                                            "text" : "Delete All",
-                                            "xtype" : "Button",
-                                            "cls" : "x-btn-text-icon",
-                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                            "$ xns" : "Roo.Toolbar"
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Item#",
-                                    "width" : 40,
-                                    "$ 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  }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_linenumber",
-                                    "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Item Code",
-                                    "width" : 75,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "item_number",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "listWidth" : 400,
-                                                    "triggerAction" : "all",
-                                                    "forceSelection" : true,
-                                                    "selectOnFocus" : true,
-                                                    "pageSize" : 20,
-                                                    "displayField" : "itemsite_item_id_item_number",
-                                                    "emptyText" : "Select item",
-                                                    "hiddenName" : "itemsite_item_id_item_number",
-                                                    "minChars" : 2,
-                                                    "valueField" : "item_number",
-                                                    "xtype" : "ComboBox",
-                                                    "allowBlank" : false,
-                                                    "typeAhead" : false,
-                                                    "editable" : true,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field",
-                                                    "name" : "item_number",
-                                                    "qtip" : "Select item",
-                                                    "queryParam" : "query[number]",
-                                                    "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>",
-                                                    "loadingText" : "Searching...",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|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"
-                                                            },
-                                                            "xtype" : "Store",
-                                                            "remoteSort" : true,
-                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'item_number' }",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "store",
-                                                            "items" : [
-                                                                {
-                                                                    "$ url" : "baseURL + '/Roo/itemsite.php'",
-                                                                    "xtype" : "HttpProxy",
-                                                                    "method" : "GET",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "proxy"
-                                                                },
-                                                                {
-                                                                    "id" : "shipto_id",
-                                                                    "root" : "data",
-                                                                    "xtype" : "JsonReader",
-                                                                    "$ fields" : "[{\"name\":\"item_id\",\"type\":\"int\"},\"item_number\"]",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "reader",
-                                                                    "totalProperty" : "total"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "From",
-                                    "width" : 75,
-                                    "$ renderer" : "function(v,x,r) { \n    return String.format('{0}', r.data.coitem_location_src_location_name); \n}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_location_src",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "alwaysQuery" : true,
-                                                    "listWidth" : 400,
-                                                    "triggerAction" : "all",
-                                                    "forceSelection" : true,
-                                                    "selectOnFocus" : true,
-                                                    "pageSize" : 20,
-                                                    "displayField" : "location_name",
-                                                    "emptyText" : "Select location",
-                                                    "hiddenName" : "coitem_location_src",
-                                                    "minChars" : 2,
-                                                    "valueField" : "location_id",
-                                                    "xtype" : "ComboBox",
-                                                    "allowBlank" : false,
-                                                    "typeAhead" : false,
-                                                    "editable" : true,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field",
-                                                    "name" : "coitem_location_src_location_name",
-                                                    "qtip" : "Select item",
-                                                    "queryParam" : "query[location_name]",
-                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>",
-                                                    "loadingText" : "Searching...",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|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"
-                                                            },
-                                                            "xtype" : "Store",
-                                                            "remoteSort" : true,
-                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "store",
-                                                            "items" : [
-                                                                {
-                                                                    "$ url" : "baseURL + '/Roo/location.php'",
-                                                                    "xtype" : "HttpProxy",
-                                                                    "method" : "GET",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "proxy"
-                                                                },
-                                                                {
-                                                                    "id" : "shipto_id",
-                                                                    "root" : "data",
-                                                                    "xtype" : "JsonReader",
-                                                                    "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "reader",
-                                                                    "totalProperty" : "total"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "To",
-                                    "width" : 75,
-                                    "$ renderer" : "function(v,x,r) { \n    return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); \n}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_shipto_id",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "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}",
-                                                        "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}"
-                                                    },
-                                                    "alwaysQuery" : true,
-                                                    "listWidth" : 400,
-                                                    "triggerAction" : "all",
-                                                    "forceSelection" : true,
-                                                    "selectOnFocus" : true,
-                                                    "pageSize" : 20,
-                                                    "displayField" : "shipto_name",
-                                                    "emptyText" : "Select cntct",
-                                                    "hiddenName" : "cohead_shipto_id",
-                                                    "minChars" : 2,
-                                                    "valueField" : "shipto_id",
-                                                    "xtype" : "ComboBox",
-                                                    "allowBlank" : false,
-                                                    "typeAhead" : false,
-                                                    "editable" : false,
-                                                    "width" : 300,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field",
-                                                    "name" : "coitem_shipto_id_shipto_name",
-                                                    "qtip" : "Select shipto",
-                                                    "queryParam" : "query[shipto_name]",
-                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>",
-                                                    "loadingText" : "Searching...",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|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"
-                                                            },
-                                                            "xtype" : "Store",
-                                                            "remoteSort" : true,
-                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'shipto_name' }",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "store",
-                                                            "items" : [
-                                                                {
-                                                                    "$ url" : "baseURL + '/Roo/shiptoinfo.php'",
-                                                                    "xtype" : "HttpProxy",
-                                                                    "method" : "GET",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "proxy"
-                                                                },
-                                                                {
-                                                                    "id" : "shipto_id",
-                                                                    "root" : "data",
-                                                                    "xtype" : "JsonReader",
-                                                                    "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "reader",
-                                                                    "totalProperty" : "total"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Item Description",
-                                    "width" : 150,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "item_descrip1",
-                                    "# 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\":\"\"}",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "TextField",
-                                                    "allowBlank" : false,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Status",
-                                    "width" : 50,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
-                                    "dataIndex" : "coitem_status"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Qty",
-                                    "width" : 40,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_qtyord",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 1,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "allowDecimals" : false,
-                                                    "decimalPrecision" : 0,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Sell @",
-                                    "width" : 70,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_price",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 0,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "decimalPrecision" : 3,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "hidden" : true,
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Sell @w/GST",
-                                    "width" : 70,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_price_tax",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 0,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "decimalPrecision" : 3,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Disc%",
-                                    "width" : 50,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_linedisc",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 0,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "decimalPrecision" : 2,
-                                                    "$ xns" : "Roo.form",
-                                                    "maxValue" : 100,
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "List Price",
-                                    "width" : 70,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_custprice",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 0,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "decimalPrecision" : 3,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "hidden" : true,
-                                    "xtype" : "ColumnModel",
-                                    "header" : "List Price w/GST",
-                                    "width" : 70,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_custprice_tax",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
-                                                    },
-                                                    "minValue" : 0,
-                                                    "style" : "text-align:right",
-                                                    "xtype" : "NumberField",
-                                                    "decimalPrecision" : 3,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "SubTotal",
-                                    "width" : 70,
-                                    "$ 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  }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_subtotal"
-                                },
-                                {
-                                    "align" : "right",
-                                    "hidden" : true,
-                                    "xtype" : "ColumnModel",
-                                    "header" : "SubTotal w/GST",
-                                    "width" : 70,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_subtotal_tax"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Unit Cost",
-                                    "width" : 50,
-                                    "$ renderer" : "function(v) { return Roo.util.Format.number( v, 2); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
-                                    "dataIndex" : "coitem_unitcost_in_order_cur"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Taxed",
-                                    "width" : 50,
-                                    "$ renderer" : "function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "coitem_taxtype_id",
-                                    "items" : [
-                                        {
-                                            "xtype" : "GridEditor",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "editor",
-                                            "items" : [
-                                                {
-                                                    "listWidth" : 400,
-                                                    "triggerAction" : "all",
-                                                    "forceSelection" : true,
-                                                    "selectOnFocus" : true,
-                                                    "pageSize" : 20,
-                                                    "displayField" : "taxtype_name",
-                                                    "emptyText" : "Select Tax Type",
-                                                    "hiddenName" : "coitem_taxtype_id",
-                                                    "minChars" : 2,
-                                                    "valueField" : "taxtype_id",
-                                                    "xtype" : "ComboBox",
-                                                    "allowBlank" : false,
-                                                    "typeAhead" : true,
-                                                    "editable" : false,
-                                                    "width" : 40,
-                                                    "$ xns" : "Roo.form",
-                                                    "* prop" : "field",
-                                                    "name" : "coitem_taxtype_id_taxtype_name",
-                                                    "qtip" : "Select taxtype",
-                                                    "queryParam" : "query[taxtype_id]",
-                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>",
-                                                    "loadingText" : "Searching...",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    \n    \n}\n"
-                                                            },
-                                                            "xtype" : "Store",
-                                                            "remoteSort" : true,
-                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'taxtype_name' }",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "store",
-                                                            "items" : [
-                                                                {
-                                                                    "$ url" : "baseURL + '/Roo/taxtype.php'",
-                                                                    "xtype" : "HttpProxy",
-                                                                    "method" : "GET",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "proxy"
-                                                                },
-                                                                {
-                                                                    "id" : "taxtype_id",
-                                                                    "root" : "data",
-                                                                    "xtype" : "JsonReader",
-                                                                    "$ fields" : "[{\"name\":\"taxtype_id\",\"type\":\"int\"},\"taxtype_name\"]",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "reader",
-                                                                    "totalProperty" : "total"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "#avail",
-                                    "width" : 50,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "avail_qty"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "#reserved",
-                                    "width" : 50,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
-                                    "dataIndex" : "shipitem_shipped"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "#shipped",
-                                    "width" : 50,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
-                                    "dataIndex" : "coitem_qtyshipped"
-                                },
-                                {
-                                    "align" : "right",
-                                    "xtype" : "ColumnModel",
-                                    "header" : "#invoiced",
-                                    "width" : 50,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "cobill_billed"
-                                }
-                            ]
-                        }
-                    ]
+                    {
+                     "id" : "curr_id",
+                     "root" : "data",
+                     "xtype" : "JsonReader",
+                     "$ xns" : "Roo.data",
+                     "$ fields" : "[{\"name\":\"curr_id\",\"type\":\"int\"},\"curr_symbol\"]",
+                     "* prop" : "reader",
+                     "totalProperty" : "total"
+                    }
+                   ]
+                  }
+                 ]
                 },
                 {
-                    "listeners" : {
-                        "activate" : "function (_self)\n{\n    _this.shipinvtab = _self;\n}"
+                 "fieldLabel" : "Products",
+                 "xtype" : "NumberField",
+                 "cls" : "roo-align-right",
+                 "readOnly" : true,
+                 "allowDecimals" : true,
+                 "decimalPrecision" : 3,
+                 "width" : 100,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_subtotal"
+                }
+               ]
+              },
+              {
+               "labelAlign" : "top",
+               "xtype" : "Row",
+               "labelSeparator" : "&nbsp;",
+               "width" : 500,
+               "$ xns" : "Roo.form",
+               "items" : [
+                {
+                 "listeners" : {
+                  "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}"
+                 },
+                 "listWidth" : 400,
+                 "triggerAction" : "all",
+                 "fieldLabel" : "Tax Zone",
+                 "forceSelection" : true,
+                 "selectOnFocus" : true,
+                 "pageSize" : 20,
+                 "displayField" : "taxzone_descrip",
+                 "emptyText" : "Select taxtype",
+                 "hiddenName" : "cohead_taxzone_id",
+                 "minChars" : 2,
+                 "valueField" : "taxzone_id",
+                 "xtype" : "ComboBox",
+                 "allowBlank" : false,
+                 "typeAhead" : true,
+                 "editable" : false,
+                 "width" : 285,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_taxzone_id_taxzone_descrip",
+                 "qtip" : "Select taxtype",
+                 "queryParam" : "query[taxzone_descrip]",
+                 "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>",
+                 "loadingText" : "Searching...",
+                 "items" : [
+                  {
+                   "listeners" : {
+                    "|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"
+                   },
+                   "xtype" : "Store",
+                   "remoteSort" : true,
+                   "$ sortInfo" : "{ direction : 'ASC', field: 'taxzone_descrip' }",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "store",
+                   "items" : [
+                    {
+                     "$ url" : "baseURL + '/Roo/taxzone.php'",
+                     "method" : "GET",
+                     "xtype" : "HttpProxy",
+                     "$ xns" : "Roo.data",
+                     "* prop" : "proxy"
                     },
-                    "region" : "center",
-                    "xtype" : "NestedLayoutPanel",
-                    "title" : "Shipments / Invoices",
-                    "$ xns" : "Roo",
-                    "items" : [
-                        {
-                            "xtype" : "BorderLayout",
-                            "$ xns" : "Roo",
-                            "* prop" : "layout",
-                            "items" : [
-                                {
-                                    "xtype" : "LayoutRegion",
-                                    "$ xns" : "Roo",
-                                    "* prop" : "center",
-                                    "titlebar" : true
-                                },
-                                {
-                                    "title" : "Reserve Stock / Shipments",
-                                    "xtype" : "LayoutRegion",
-                                    "$ xns" : "Roo",
-                                    "* prop" : "north",
-                                    "height" : 250
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.shippanel = this;\n    if (_this.shipgrid) {\n        _this.shipgrid.ds.load({});\n    }\n}"
-                                    },
-                                    "background" : false,
-                                    "fitToframe" : true,
-                                    "region" : "north",
-                                    "title" : "shiphead",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "# 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\"}",
-                                    "tableName" : "shiphead",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "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",
-                                                "|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}"
-                                            },
-                                            "autoExpandColumn" : "shiphead_shipvia",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "# 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\"}",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "RowSelectionModel",
-                                                    "singleSelect" : true,
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "sm"
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "remoteSort" : true,
-                                                    "xtype" : "Store",
-                                                    "$ sortInfo" : "{ field : 'shiphead_shipvia', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "# 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\"}",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/shiphead.php'",
-                                                            "method" : "GET",
-                                                            "xtype" : "HttpProxy",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ xns" : "Roo.data",
-                                                            "$ 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]",
-                                                            "* prop" : "reader",
-                                                            "totalProperty" : "total",
-                                                            "# 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\"}"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "Toolbar",
-                                                    "$ xns" : "Roo",
-                                                    "* prop" : "toolbar",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}"
-                                                            },
-                                                            "text" : "Confirm Shipment",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}"
-                                                            },
-                                                            "text" : "Download (as xls)",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/save.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Print Picking Slip",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Print Delivery Note",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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"
-                                                            },
-                                                            "text" : "Send Delivery Email",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "Roo.rootURL + 'images/default/dd/email.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "xtype" : "Fill",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}",
-                                                                "render" : "function (_self)\n{\n  _this.addShipmentBtn = _self;\n}"
-                                                            },
-                                                            "text" : "Add",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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        "
-                                                            },
-                                                            "text" : "Void / Unconfirm",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "number",
-                                                    "width" : 80,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "shiphead_number",
-                                                    "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "From Location",
-                                                    "width" : 100,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "shiphead_location_id_location_name"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Ship to",
-                                                    "width" : 100,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "shiphead_shipto_id_shipto_name"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "shipdate",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
-                                                    "dataIndex" : "shiphead_shipdate"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Status",
-                                                    "width" : 50,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "shiphead_sfstatus",
-                                                    "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "shipvia",
-                                                    "width" : 200,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}",
-                                                    "dataIndex" : "shiphead_shipvia"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "tracknum",
-                                                    "width" : 200,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
-                                                    "dataIndex" : "shiphead_tracknum"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.invpanel = this;\n    if (_this.invgrid) {\n        _this.invgrid.ds.load({});\n    }\n}"
-                                    },
-                                    "fitToframe" : true,
-                                    "background" : false,
-                                    "region" : "center",
-                                    "title" : "Invoices",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "tableName" : "cobmisc",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "|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",
-                                                "|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}"
-                                            },
-                                            "autoExpandColumn" : "invchead_invcnumber",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "# 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\"}",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "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}",
-                                                        "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}"
-                                                    },
-                                                    "xtype" : "Store",
-                                                    "remoteSort" : true,
-                                                    "$ sortInfo" : "{ field : 'invchead_invcnumber', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/cobmisc.php'",
-                                                            "xtype" : "HttpProxy",
-                                                            "method" : "GET",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ fields" : "[\n    {\n        'name': 'invchead_invcnumber',\n        'type': 'string'\n    },\n    {\n        'name': 'invchead_invcdate',\n        'type': 'date'\n    }\n]",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "reader",
-                                                            "# 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\"}",
-                                                            "totalProperty" : "total"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "Toolbar",
-                                                    "$ xns" : "Roo",
-                                                    "* prop" : "toolbar",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}"
-                                                            },
-                                                            "text" : "Post Invoice",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "text" : "Print",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
-                                                            "$ xns" : "Roo.Toolbar",
-                                                            "items" : [
-                                                                {
-                                                                    "xtype" : "Menu",
-                                                                    "$ xns" : "Roo.menu",
-                                                                    "* prop" : "menu",
-                                                                    "items" : [
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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}"
-                                                                            },
-                                                                            "text" : "Print Standard Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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} "
-                                                                            },
-                                                                            "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
-                                                                            "text" : "Print Chinese Invoice With GST in line item",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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} "
-                                                                            },
-                                                                            "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
-                                                                            "text" : "Print Chinese Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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} "
-                                                                            },
-                                                                            "$ hidden" : "!(baseURL.match(/au\\.php$/))",
-                                                                            "text" : "Print Aus - GST included Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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}"
-                                                                            },
-                                                                            "$ hidden" : "!(baseURL.match(/au\\.php$/))",
-                                                                            "text" : "Print Bambini Pronto Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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} "
-                                                                            },
-                                                                            "$ hidden" : "!(baseURL.match(/au\\.php$/))",
-                                                                            "text" : "Print Bambini Pro Forma Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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}"
-                                                                            },
-                                                                            "$ hidden" : "!( baseURL.match(/au\\.php$/)) ",
-                                                                            "text" : "Print Shipping / Commercial Invoice",
-                                                                            "xtype" : "Item",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "text" : "Payments / Refunds / Credit Memos",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
-                                                            "$ xns" : "Roo.Toolbar",
-                                                            "items" : [
-                                                                {
-                                                                    "xtype" : "Menu",
-                                                                    "$ xns" : "Roo.menu",
-                                                                    "* prop" : "menu",
-                                                                    "items" : [
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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"
-                                                                            },
-                                                                            "text" : "Receive Payment",
-                                                                            "xtype" : "Item",
-                                                                            "cls" : "x-btn-text-icon",
-                                                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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"
-                                                                            },
-                                                                            "text" : "Issue Refund",
-                                                                            "xtype" : "Item",
-                                                                            "cls" : "x-btn-text-icon",
-                                                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "xtype" : "Separator",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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"
-                                                                            },
-                                                                            "text" : "Void Payment",
-                                                                            "xtype" : "Item",
-                                                                            "cls" : "x-btn-text-icon",
-                                                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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"
-                                                                            },
-                                                                            "text" : "Void Refund",
-                                                                            "xtype" : "Item",
-                                                                            "cls" : "x-btn-text-icon",
-                                                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        },
-                                                                        {
-                                                                            "listeners" : {
-                                                                                "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"
-                                                                            },
-                                                                            "text" : "Void Credit Memo",
-                                                                            "xtype" : "Item",
-                                                                            "cls" : "x-btn-text-icon",
-                                                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                                                            "$ xns" : "Roo.menu"
-                                                                        }
-                                                                    ]
-                                                                }
-                                                            ]
-                                                        },
-                                                        {
-                                                            "xtype" : "Fill",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}",
-                                                                "render" : "function (_self)\n{\n  _this.addInvoiceBtn = _self;\n}"
-                                                            },
-                                                            "text" : "Add",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "|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}"
-                                                            },
-                                                            "text" : "Void / Unpost",
-                                                            "xtype" : "Button",
-                                                            "cls" : "x-btn-text-icon",
-                                                            "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Invoice #",
-                                                    "width" : 100,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_invchead_id_invchead_invcnumber"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "invcdate",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v,x,r) { \n    \n    return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); \n}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_invcdate",
-                                                    "# builderCfg" : "{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Qty",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? parseInt(v) : 0); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_qty"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Item Cost",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_itemcost"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Shipping",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_freight"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Tax",
-                                                    "width" : 75,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_tax"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Discount (Pretax)",
-                                                    "width" : 100,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_cohead_id_cohead_pretax_discount"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Discount (Posttax)",
-                                                    "width" : 100,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_misc"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Total ",
-                                                    "width" : 75,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_total"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Outstanding",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v,x,r) \n{ \n    \n    return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );\n}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "cobmisc_outstanding"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                }
-                            ]
-                        }
-                    ]
+                    {
+                     "id" : "taxzone_id",
+                     "root" : "data",
+                     "xtype" : "JsonReader",
+                     "$ fields" : "[{\"name\":\"taxzone_id\",\"type\":\"int\"},\"taxzone_descrip\"]",
+                     "$ xns" : "Roo.data",
+                     "* prop" : "reader",
+                     "totalProperty" : "total"
+                    }
+                   ]
+                  }
+                 ]
                 },
                 {
-                    "listeners" : {
-                        "|activate" : "function() {\n    _this.hpanel = this;\n    if (_this.hgrid) {\n        _this.hgrid.footer.onClick('first');\n    }\n}"
-                    },
-                    "background" : true,
-                    "fitToframe" : true,
-                    "region" : "center",
-                    "title" : "History",
-                    "xtype" : "GridPanel",
-                    "fitContainer" : true,
-                    "$ xns" : "Roo",
-                    "# 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\"}",
-                    "tableName" : "events",
-                    "items" : [
-                        {
-                            "listeners" : {
-                                "|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",
-                                "|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}"
-                            },
-                            "autoExpandColumn" : "remarks",
-                            "xtype" : "Grid",
-                            "loadMask" : true,
-                            "$ xns" : "Roo.grid",
-                            "* prop" : "grid",
-                            "# 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\"}",
-                            "items" : [
-                                {
-                                    "listeners" : {
-                                        "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}"
-                                    },
-                                    "remoteSort" : true,
-                                    "xtype" : "Store",
-                                    "$ sortInfo" : "{ field : 'event_when', direction: 'DESC' }",
-                                    "$ xns" : "Roo.data",
-                                    "* prop" : "dataSource",
-                                    "# 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\"}",
-                                    "items" : [
-                                        {
-                                            "$ url" : "baseURL + '/Roo/events.php'",
-                                            "method" : "GET",
-                                            "xtype" : "HttpProxy",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "proxy"
-                                        },
-                                        {
-                                            "id" : "id",
-                                            "root" : "data",
-                                            "xtype" : "JsonReader",
-                                            "$ 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]",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "reader",
-                                            "# 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\"}",
-                                            "totalProperty" : "total"
-                                        }
-                                    ]
-                                },
-                                {
-                                    "pageSize" : 25,
-                                    "xtype" : "PagingToolbar",
-                                    "emptyMsg" : "No events found",
-                                    "$ xns" : "Roo",
-                                    "displayInfo" : true,
-                                    "displayMsg" : "Displaying events{0} - {1} of {2}",
-                                    "* prop" : "footer"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Changed",
-                                    "width" : 120,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "event_when",
-                                    "# builderCfg" : "{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "action",
-                                    "width" : 120,
-                                    "$ renderer" : "function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "action",
-                                    "# builderCfg" : "{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "IP address",
-                                    "width" : 120,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "ipaddr",
-                                    "# builderCfg" : "{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Who",
-                                    "width" : 120,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "person_id_name",
-                                    "# builderCfg" : "{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Notes",
-                                    "width" : 200,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "remarks",
-                                    "# builderCfg" : "{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}"
-                                }
-                            ]
-                        }
-                    ]
+                 "fieldLabel" : "Tax",
+                 "xtype" : "NumberField",
+                 "cls" : "roo-align-right",
+                 "readOnly" : true,
+                 "allowDecimals" : true,
+                 "decimalPrecision" : 3,
+                 "width" : 100,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_tax"
+                }
+               ]
+              },
+              {
+               "fieldLabel" : "Pre Tax discount",
+               "xtype" : "NumberField",
+               "cls" : "roo-align-right",
+               "readOnly" : true,
+               "allowDecimals" : true,
+               "decimalPrecision" : 3,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_pretax_discount"
+              },
+              {
+               "labelAlign" : "top",
+               "xtype" : "Row",
+               "labelSeparator" : "&nbsp;",
+               "width" : 500,
+               "$ xns" : "Roo.form",
+               "items" : [
+                {
+                 "fieldLabel" : "Discount after Tax  Description",
+                 "xtype" : "TextField",
+                 "width" : 230,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_misc_descrip"
                 },
                 {
-                    "region" : "center",
-                    "xtype" : "NestedLayoutPanel",
-                    "title" : "Stock Tx",
-                    "$ xns" : "Roo",
-                    "items" : [
-                        {
-                            "xtype" : "BorderLayout",
-                            "$ xns" : "Roo",
-                            "* prop" : "layout",
-                            "items" : [
-                                {
-                                    "xtype" : "LayoutRegion",
-                                    "$ xns" : "Roo",
-                                    "* prop" : "center"
-                                },
-                                {
-                                    "xtype" : "LayoutRegion",
-                                    "width" : 500,
-                                    "$ xns" : "Roo",
-                                    "split" : true,
-                                    "* prop" : "east"
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.txpanel = this;\n    if (_this.txgrid) {\n        _this.txgrid.footer.onClick('first');\n    }\n}"
-                                    },
-                                    "fitToframe" : true,
-                                    "background" : false,
-                                    "region" : "center",
-                                    "title" : "invdetail",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "tableName" : "invdetail",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "|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}"
-                                            },
-                                            "autoExpandColumn" : "item_number",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Toolbar",
-                                                    "$ xns" : "Roo",
-                                                    "* prop" : "toolbar",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Run Apply Fifo on order",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Run Void flagger",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Auto Reverse",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "selectionchange" : "function (_self)\n{\n    _this.txdgrid.footer.onClick('first');;\n}"
-                                                    },
-                                                    "xtype" : "RowSelectionModel",
-                                                    "singleSelect" : true,
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "sm"
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "xtype" : "Store",
-                                                    "remoteSort" : true,
-                                                    "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/invdetail.php'",
-                                                            "xtype" : "HttpProxy",
-                                                            "method" : "GET",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ xns" : "Roo.data",
-                                                            "$ 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]",
-                                                            "* prop" : "reader",
-                                                            "totalProperty" : "total"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "pageSize" : 9999,
-                                                    "xtype" : "PagingToolbar",
-                                                    "emptyMsg" : "No invdetail found",
-                                                    "$ xns" : "Roo",
-                                                    "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
-                                                    "displayInfo" : true,
-                                                    "* prop" : "footer"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Item",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "item_number"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#Ship",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "rec_shipped"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#Ret",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "rec_returned"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#TX ship",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "tx_shipped"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#TX ret",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "tx_returned"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#TX Tot",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "tx_total"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Value",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v,x,r) { \n\n    return (v*1).toFixed(3);\n}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "total_value"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "#Diff",
-                                                    "width" : 50,
-                                                    "$ 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    }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "tx_total"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.txdpanel = this;\n    if (_this.txdgrid) {\n        _this.txdgrid.footer.onClick('first');\n    }\n}"
-                                    },
-                                    "fitToframe" : true,
-                                    "background" : false,
-                                    "region" : "east",
-                                    "title" : "invdetail",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "tableName" : "invdetail",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "|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}",
-                                                "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}"
-                                            },
-                                            "autoExpandColumn" : "invhist_comments",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "Toolbar",
-                                                    "$ xns" : "Roo",
-                                                    "* prop" : "toolbar",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Duplicate Selected",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "xtype" : "Fill",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "text" : "Issue Date",
-                                                            "xtype" : "TextItem",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "render" : "function (_self)\n{\n    _this.dateSel = _self;\n}"
-                                                            },
-                                                            "format" : "Y-m-d",
-                                                            "fieldLabel" : "Issue Date",
-                                                            "xtype" : "DateField",
-                                                            "allowBlank" : false,
-                                                            "width" : 150,
-                                                            "$ xns" : "Roo.form",
-                                                            "name" : "issue_date"
-                                                        },
-                                                        {
-                                                            "listeners" : {
-                                                                "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}"
-                                                            },
-                                                            "text" : "Reverse Selected",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "xtype" : "Store",
-                                                    "remoteSort" : true,
-                                                    "$ sortInfo" : "{ field : 'invdetail_id', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/invdetail.php'",
-                                                            "xtype" : "HttpProxy",
-                                                            "method" : "GET",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ xns" : "Roo.data",
-                                                            "$ 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]",
-                                                            "* prop" : "reader",
-                                                            "totalProperty" : "total"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "pageSize" : 9999,
-                                                    "xtype" : "PagingToolbar",
-                                                    "emptyMsg" : "No invdetail found",
-                                                    "$ xns" : "Roo",
-                                                    "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
-                                                    "displayInfo" : true,
-                                                    "* prop" : "footer"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "TX#",
-                                                    "width" : 60,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invdetail_id"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Date",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invhist_transdate"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Ref#",
-                                                    "width" : 75,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invhist_ordnumber"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "TX#",
-                                                    "width" : 60,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "location_name"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Notes",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invhist_comments"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Qty Changed",
-                                                    "width" : 50,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invdetail_qty"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Qty Changed",
-                                                    "width" : 75,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invhist_value_before"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Posted",
-                                                    "width" : 40,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "invhist_posted"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                }
-                            ]
-                        }
-                    ]
+                 "listeners" : {
+                  "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}"
+                 },
+                 "fieldLabel" : "%",
+                 "$ 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",
+                 "xtype" : "NumberField",
+                 "cls" : "roo-align-right",
+                 "allowDecimals" : true,
+                 "decimalPrecision" : 1,
+                 "width" : 35,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_misc_per"
                 },
                 {
-                    "region" : "center",
-                    "xtype" : "NestedLayoutPanel",
-                    "title" : "GL Tx",
-                    "$ xns" : "Roo",
-                    "items" : [
-                        {
-                            "xtype" : "BorderLayout",
-                            "$ xns" : "Roo",
-                            "* prop" : "layout",
-                            "items" : [
-                                {
-                                    "xtype" : "LayoutRegion",
-                                    "$ xns" : "Roo",
-                                    "* prop" : "center"
-                                },
-                                {
-                                    "xtype" : "LayoutRegion",
-                                    "width" : 500,
-                                    "$ xns" : "Roo",
-                                    "split" : true,
-                                    "* prop" : "east"
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.gltxpanel = this;\n    if (_this.gltxgrid) {\n        _this.gltxgrid.footer.onClick('first');\n    }\n}"
-                                    },
-                                    "fitToframe" : true,
-                                    "background" : false,
-                                    "region" : "center",
-                                    "title" : "invdetail",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "tableName" : "invdetail",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "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}",
-                                                "|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}"
-                                            },
-                                            "autoExpandColumn" : "gltrans_accnt_id_accnt_descrip",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "selectionchange" : "function (_self)\n{\n    _this.gltxdgrid.footer.onClick('first');;\n}"
-                                                    },
-                                                    "xtype" : "RowSelectionModel",
-                                                    "singleSelect" : true,
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "sm"
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "xtype" : "Store",
-                                                    "remoteSort" : true,
-                                                    "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/gltrans.php'",
-                                                            "xtype" : "HttpProxy",
-                                                            "method" : "GET",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ xns" : "Roo.data",
-                                                            "$ 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]",
-                                                            "* prop" : "reader",
-                                                            "totalProperty" : "total"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "pageSize" : 9999,
-                                                    "xtype" : "PagingToolbar",
-                                                    "emptyMsg" : "No invdetail found",
-                                                    "$ xns" : "Roo",
-                                                    "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
-                                                    "displayInfo" : true,
-                                                    "* prop" : "footer",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "render" : "function (_self)\n{\n    _this.glsalesbtn = _self;\n}",
-                                                                "click" : "function (_self, e)\n{\n    (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);\n}"
-                                                            },
-                                                            "text" : "Split sales",
-                                                            "enableToggle" : true,
-                                                            "pressed" : true,
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Summary",
-                                                    "width" : 50,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_as_summary"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Account",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_accnt_id_accnt_descrip"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Credit",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_amount_credit"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Debit",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_amount_debit"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Sum",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_amount_total"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Unposted",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('<span style=\"color:red\">{0}</span>', Roo.util.Format.number(v,3)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_amount_total_unposted"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                },
-                                {
-                                    "listeners" : {
-                                        "|activate" : "function() {\n    _this.gltxdpanel = this;\n    if (_this.gltxdgrid) {\n        _this.gltxdgrid.footer.onClick('first');\n    }\n}"
-                                    },
-                                    "fitToframe" : true,
-                                    "background" : false,
-                                    "region" : "east",
-                                    "title" : "invdetail",
-                                    "xtype" : "GridPanel",
-                                    "fitContainer" : true,
-                                    "$ xns" : "Roo",
-                                    "tableName" : "invdetail",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "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}",
-                                                "|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}"
-                                            },
-                                            "autoExpandColumn" : "gltrans_notes",
-                                            "xtype" : "Grid",
-                                            "loadMask" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "grid",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "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}"
-                                                    },
-                                                    "xtype" : "Store",
-                                                    "remoteSort" : true,
-                                                    "$ sortInfo" : "{ field : 'gltrans_docnumber', direction: 'ASC' }",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "dataSource",
-                                                    "items" : [
-                                                        {
-                                                            "$ url" : "baseURL + '/Roo/gltrans.php'",
-                                                            "xtype" : "HttpProxy",
-                                                            "method" : "GET",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "proxy"
-                                                        },
-                                                        {
-                                                            "id" : "id",
-                                                            "root" : "data",
-                                                            "xtype" : "JsonReader",
-                                                            "$ xns" : "Roo.data",
-                                                            "$ 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]",
-                                                            "* prop" : "reader",
-                                                            "totalProperty" : "total"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "pageSize" : 9999,
-                                                    "xtype" : "PagingToolbar",
-                                                    "emptyMsg" : "No invdetail found",
-                                                    "$ xns" : "Roo",
-                                                    "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
-                                                    "displayInfo" : true,
-                                                    "* prop" : "footer",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "click" : "function (_self, e)\n{\n    new Pman.Download( {\n        grid : _this.gltxdgrid\n    \n    });\n}"
-                                                            },
-                                                            "text" : "Download",
-                                                            "xtype" : "Button",
-                                                            "$ xns" : "Roo.Toolbar"
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "sortable" : true,
-                                                    "header" : "Ref#",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_id"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Date",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_date"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Doc#",
-                                                    "width" : 75,
-                                                    "$ 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}",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_docnumber"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Source",
-                                                    "width" : 50,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_source"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Notes",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_notes"
-                                                },
-                                                {
-                                                    "align" : "right",
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Amount",
-                                                    "width" : 75,
-                                                    "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_amount"
-                                                },
-                                                {
-                                                    "xtype" : "ColumnModel",
-                                                    "header" : "Posted",
-                                                    "width" : 50,
-                                                    "$ 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 }",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "colModel[]",
-                                                    "dataIndex" : "gltrans_posted"
-                                                }
-                                            ]
-                                        }
-                                    ]
-                                }
-                            ]
-                        }
-                    ]
+                 "listeners" : {
+                  "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}"
+                 },
+                 "fieldLabel" : "&nbsp;",
+                 "xtype" : "NumberField",
+                 "cls" : "roo-align-right",
+                 "allowDecimals" : true,
+                 "decimalPrecision" : 3,
+                 "width" : 100,
+                 "$ xns" : "Roo.form",
+                 "name" : "cohead_posttax_discount"
+                }
+               ]
+              },
+              {
+               "fieldLabel" : "Total",
+               "$ 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",
+               "xtype" : "NumberField",
+               "cls" : "roo-align-right",
+               "readOnly" : true,
+               "allowDecimals" : true,
+               "decimalPrecision" : 3,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_total"
+              },
+              {
+               "listeners" : {
+                "keyup" : "function (_self, e)\n{\n    _this.form.findField('cohead_total').recalc();\n}"
+               },
+               "fieldLabel" : "Shipping",
+               "xtype" : "NumberField",
+               "cls" : "roo-align-right",
+               "allowDecimals" : true,
+               "decimalPrecision" : 3,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_freight"
+              },
+              {
+               "fieldLabel" : "Unshipped Total",
+               "xtype" : "NumberField",
+               "cls" : "roo-align-right",
+               "readOnly" : true,
+               "allowDecimals" : true,
+               "decimalPrecision" : 3,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_unshipped"
+              },
+              {
+               "fieldLabel" : "Uninvoiced Total",
+               "xtype" : "NumberField",
+               "cls" : "roo-align-right",
+               "readOnly" : true,
+               "allowDecimals" : true,
+               "decimalPrecision" : 3,
+               "width" : 100,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_uninvoiced"
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "legend" : "Shipping",
+           "style" : "width:420px",
+           "xtype" : "FieldSet",
+           "$ xns" : "Roo.form",
+           "items" : [
+            {
+             "xtype" : "Column",
+             "labelWidth" : 50,
+             "width" : 420,
+             "$ xns" : "Roo.form",
+             "items" : [
+              {
+               "xtype" : "Row",
+               "labelSeparator" : "&nbsp;",
+               "$ xns" : "Roo.form",
+               "items" : [
+                {
+                 "listeners" : {
+                  "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}"
+                 },
+                 "xtype" : "Checkbox",
+                 "$ xns" : "Roo.form",
+                 "boxLabel" : "Same as Billing",
+                 "name" : "_shipto_same"
+                }
+               ]
+              },
+              {
+               "listeners" : {
+                "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}",
+                "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}"
+               },
+               "alwaysQuery" : true,
+               "listWidth" : 400,
+               "triggerAction" : "all",
+               "fieldLabel" : "Ship to",
+               "forceSelection" : true,
+               "selectOnFocus" : true,
+               "pageSize" : 20,
+               "displayField" : "cntct_name",
+               "emptyText" : "Select ship to",
+               "hiddenName" : "cohead_shipto_cntct_id",
+               "minChars" : 2,
+               "valueField" : "cntct_id",
+               "xtype" : "ComboBox",
+               "allowBlank" : false,
+               "typeAhead" : true,
+               "editable" : true,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "cohead_shipto_cntct_id_cntct_name",
+               "qtip" : "Select shiptoinfo",
+               "queryParam" : "query[cntct_name]",
+               "tpl" : "<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>",
+               "loadingText" : "Searching...",
+               "items" : [
+                {
+                 "listeners" : {
+                  "|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"
+                 },
+                 "xtype" : "Store",
+                 "remoteSort" : true,
+                 "$ sortInfo" : "{ direction : 'ASC', field: 'cntct_name' }",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "store",
+                 "items" : [
+                  {
+                   "$ url" : "baseURL + '/Roo/cntct.php'",
+                   "xtype" : "HttpProxy",
+                   "method" : "GET",
+                   "$ xns" : "Roo.data",
+                   "* prop" : "proxy"
+                  },
+                  {
+                   "id" : "cntct_id",
+                   "root" : "data",
+                   "xtype" : "JsonReader",
+                   "$ xns" : "Roo.data",
+                   "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
+                   "* prop" : "reader",
+                   "totalProperty" : "total"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "fieldLabel" : "Address",
+               "$ 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",
+               "xtype" : "TextArea",
+               "readOnly" : true,
+               "width" : 300,
+               "$ xns" : "Roo.form",
+               "name" : "shipto_address"
+              },
+              {
+               "fieldLabel" : "Shipment Comments",
+               "xtype" : "TextArea",
+               "$ xns" : "Roo.form",
+               "width" : 300,
+               "name" : "cohead_shipcomments"
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_id"
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_shipto_id"
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_shipto_id_shipto_name"
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_max_linenumber"
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_cust_id"
+        },
+        {
+         "$ 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",
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "cohead_misc"
+        },
+        {
+         "xtype" : "Hidden",
+         "$ xns" : "Roo.form",
+         "name" : "taxzone_rate"
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "deactivate" : "function (_self)\n{\n    if(_this.grid){\n        _this.grid.stopEditing();\n    }\n}",
+      "|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}"
+     },
+     "region" : "center",
+     "fitToframe" : true,
+     "background" : true,
+     "title" : "Order Items",
+     "xtype" : "GridPanel",
+     "fitContainer" : true,
+     "$ xns" : "Roo",
+     "tableName" : "coitem",
+     "items" : [
+      {
+       "listeners" : {
+        "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}",
+        "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}",
+        "|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}",
+        "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",
+        "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}"
+       },
+       "autoExpandColumn" : "item_descrip1",
+       "xtype" : "EditorGrid",
+       "loadMask" : true,
+       "$ 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",
+       "clicksToEdit" : 1,
+       "$ xns" : "Roo.grid",
+       "* prop" : "grid",
+       "items" : [
+        {
+         "listeners" : {
+          "tabend" : "function (_self)\n{\n    _this.addItemBtn.fireEvent('click', _this.addItemBtn);\n}",
+          "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}"
+         },
+         "xtype" : "CellSelectionModel",
+         "$ xns" : "Roo.grid",
+         "* prop" : "sm",
+         "enter_is_tab" : true
+        },
+        {
+         "pageSize" : 100,
+         "xtype" : "PagingToolbar",
+         "emptyMsg" : "No Items",
+         "$ xns" : "Roo",
+         "displayInfo" : true,
+         "$ 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",
+         "* prop" : "footer",
+         "items" : [
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Fill empty Ship To",
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Update Location to match S/O",
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "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}",
+            "render" : "function (_self)\n{\n    _this.showgstBtn = _self;\n}"
+           },
+           "text" : "Prices with GST",
+           "enableToggle" : true,
+           "minWidth" : 100,
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          }
+         ]
+        },
+        {
+         "listeners" : {
+          "|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}",
+          "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  ",
+          "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}"
+         },
+         "xtype" : "Store",
+         "remoteSort" : true,
+         "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
+         "$ xns" : "Roo.data",
+         "* prop" : "dataSource",
+         "items" : [
+          {
+           "$ url" : "baseURL + '/Roo/coitem.php'",
+           "method" : "GET",
+           "xtype" : "HttpProxy",
+           "$ xns" : "Roo.data",
+           "* prop" : "proxy"
+          },
+          {
+           "id" : "coitem_id",
+           "root" : "data",
+           "xtype" : "JsonReader",
+           "$ 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]",
+           "$ xns" : "Roo.data",
+           "* prop" : "reader",
+           "# 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\"}",
+           "totalProperty" : "total"
+          }
+         ]
+        },
+        {
+         "xtype" : "Toolbar",
+         "$ xns" : "Roo",
+         "* prop" : "toolbar",
+         "items" : [
+          {
+           "listeners" : {
+            "|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",
+            "render" : "function (_self)\n{\n    _this.addItemBtn = _self;\n}"
+           },
+           "text" : "Add",
+           "xtype" : "Button",
+           "cls" : "x-btn-text-icon",
+           "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Find Products",
+           "xtype" : "Button",
+           "cls" : "x-btn-text-icon",
+           "$ icon" : "rootURL + '/Pman/templates/images/search.gif'",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "|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",
+            "render" : "function (_self)\n{\n    _this.xferAll  = _self;\n}"
+           },
+           "text" : "Xfer all stock to HK",
+           "hidden" : true,
+           "xtype" : "Button",
+           "cls" : "x-btn-text-icon",
+           "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Show Inventory History",
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "xtype" : "Separator",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "text" : "Apply % Discount of : ",
+           "xtype" : "TextItem",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "render" : "function (_self)\n{\n    _this._applyDiscount = _self;\n}"
+           },
+           "xtype" : "TextField",
+           "width" : 40,
+           "$ xns" : "Roo.form"
+          },
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Apply To All",
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "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}"
+           },
+           "text" : "Import",
+           "xtype" : "Button",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "xtype" : "Fill",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "|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        "
+           },
+           "text" : "Delete",
+           "xtype" : "Button",
+           "cls" : "x-btn-text-icon",
+           "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+           "$ xns" : "Roo.Toolbar"
+          },
+          {
+           "listeners" : {
+            "|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        "
+           },
+           "text" : "Delete All",
+           "xtype" : "Button",
+           "cls" : "x-btn-text-icon",
+           "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+           "$ xns" : "Roo.Toolbar"
+          }
+         ]
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 40,
+         "header" : "Item#",
+         "$ 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  }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_linenumber",
+         "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 75,
+         "header" : "Item Code",
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "item_number",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "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}"
+             },
+             "listWidth" : 400,
+             "triggerAction" : "all",
+             "forceSelection" : true,
+             "selectOnFocus" : true,
+             "pageSize" : 20,
+             "displayField" : "itemsite_item_id_item_number",
+             "emptyText" : "Select item",
+             "hiddenName" : "itemsite_item_id_item_number",
+             "minChars" : 2,
+             "valueField" : "item_number",
+             "xtype" : "ComboBox",
+             "allowBlank" : false,
+             "typeAhead" : false,
+             "editable" : true,
+             "$ xns" : "Roo.form",
+             "* prop" : "field",
+             "name" : "item_number",
+             "qtip" : "Select item",
+             "queryParam" : "query[number]",
+             "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>",
+             "loadingText" : "Searching...",
+             "items" : [
+              {
+               "listeners" : {
+                "|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"
+               },
+               "xtype" : "Store",
+               "remoteSort" : true,
+               "$ sortInfo" : "{ direction : 'ASC', field: 'item_number' }",
+               "$ xns" : "Roo.data",
+               "* prop" : "store",
+               "items" : [
+                {
+                 "$ url" : "baseURL + '/Roo/itemsite.php'",
+                 "method" : "GET",
+                 "xtype" : "HttpProxy",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "proxy"
                 },
                 {
-                    "listeners" : {
-                        "|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}"
-                    },
-                    "fitToframe" : true,
-                    "background" : true,
-                    "region" : "center",
-                    "title" : "Profit",
-                    "xtype" : "GridPanel",
-                    "fitContainer" : true,
-                    "$ xns" : "Roo",
-                    "tableName" : "coitem",
-                    "items" : [
-                        {
-                            "listeners" : {
-                                "|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}"
-                            },
-                            "autoExpandColumn" : "item_number",
-                            "xtype" : "Grid",
-                            "loadMask" : true,
-                            "$ xns" : "Roo.grid",
-                            "* prop" : "grid",
-                            "items" : [
-                                {
-                                    "listeners" : {
-                                        "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}"
-                                    },
-                                    "xtype" : "Store",
-                                    "remoteSort" : true,
-                                    "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
-                                    "$ xns" : "Roo.data",
-                                    "* prop" : "dataSource",
-                                    "items" : [
-                                        {
-                                            "$ url" : "baseURL + '/Roo/coitem.php'",
-                                            "xtype" : "HttpProxy",
-                                            "method" : "GET",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "proxy"
-                                        },
-                                        {
-                                            "id" : "id",
-                                            "root" : "data",
-                                            "xtype" : "JsonReader",
-                                            "$ xns" : "Roo.data",
-                                            "$ 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]",
-                                            "* prop" : "reader",
-                                            "totalProperty" : "total"
-                                        }
-                                    ]
-                                },
-                                {
-                                    "pageSize" : 25,
-                                    "xtype" : "PagingToolbar",
-                                    "emptyMsg" : "No coitem found",
-                                    "$ xns" : "Roo",
-                                    "displayMsg" : "Displaying coitem{0} - {1} of {2}",
-                                    "displayInfo" : true,
-                                    "* prop" : "footer"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Item Code",
-                                    "width" : 75,
-                                    "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "item_number"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "SubTotal",
-                                    "width" : 200,
-                                    "$ renderer" : "function(v) {\n\n\n     return Roo.util.Format.number( v, 2);\n  }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "calc_subtotal"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Cost of goods",
-                                    "width" : 200,
-                                    "$ renderer" : "function(v) {\n\n    return Roo.util.Format.number( v, 2);\n  }",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "calc_cost_total"
-                                },
-                                {
-                                    "xtype" : "ColumnModel",
-                                    "header" : "Profit",
-                                    "width" : 200,
-                                    "$ 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}",
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "colModel[]",
-                                    "dataIndex" : "profit"
-                                }
-                            ]
-                        }
-                    ]
+                 "id" : "shipto_id",
+                 "root" : "data",
+                 "xtype" : "JsonReader",
+                 "$ fields" : "[{\"name\":\"item_id\",\"type\":\"int\"},\"item_number\"]",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "reader",
+                 "totalProperty" : "total"
+                }
+               ]
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 75,
+         "header" : "From",
+         "$ renderer" : "function(v,x,r) { \n    return String.format('{0}', r.data.coitem_location_src_location_name); \n}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_location_src",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "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}"
+             },
+             "alwaysQuery" : true,
+             "listWidth" : 400,
+             "triggerAction" : "all",
+             "forceSelection" : true,
+             "selectOnFocus" : true,
+             "pageSize" : 20,
+             "displayField" : "location_name",
+             "emptyText" : "Select location",
+             "hiddenName" : "coitem_location_src",
+             "minChars" : 2,
+             "valueField" : "location_id",
+             "xtype" : "ComboBox",
+             "allowBlank" : false,
+             "typeAhead" : false,
+             "editable" : true,
+             "$ xns" : "Roo.form",
+             "* prop" : "field",
+             "name" : "coitem_location_src_location_name",
+             "qtip" : "Select item",
+             "queryParam" : "query[location_name]",
+             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>",
+             "loadingText" : "Searching...",
+             "items" : [
+              {
+               "listeners" : {
+                "|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"
+               },
+               "xtype" : "Store",
+               "remoteSort" : true,
+               "$ sortInfo" : "{ direction : 'ASC', field: 'location_name' }",
+               "$ xns" : "Roo.data",
+               "* prop" : "store",
+               "items" : [
+                {
+                 "$ url" : "baseURL + '/Roo/location.php'",
+                 "method" : "GET",
+                 "xtype" : "HttpProxy",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "proxy"
                 },
                 {
-                    "listeners" : {
-                        "render" : "function (_self)\n{\n    _this.reversalBtn = _self;\n}",
-                        "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}"
-                    },
-                    "text" : "Create CM reversal",
-                    "xtype" : "Button",
-                    "$ xns" : "Roo",
-                    "* prop" : "buttons[]"
+                 "id" : "shipto_id",
+                 "root" : "data",
+                 "xtype" : "JsonReader",
+                 "$ fields" : "[{\"name\":\"location_id\",\"type\":\"int\"},\"location_name\"]",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "reader",
+                 "totalProperty" : "total"
+                }
+               ]
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 75,
+         "header" : "To",
+         "$ renderer" : "function(v,x,r) { \n    return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); \n}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_shipto_id",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "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}",
+              "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}"
+             },
+             "alwaysQuery" : true,
+             "listWidth" : 400,
+             "triggerAction" : "all",
+             "forceSelection" : true,
+             "selectOnFocus" : true,
+             "pageSize" : 20,
+             "displayField" : "shipto_name",
+             "emptyText" : "Select cntct",
+             "hiddenName" : "cohead_shipto_id",
+             "minChars" : 2,
+             "valueField" : "shipto_id",
+             "xtype" : "ComboBox",
+             "allowBlank" : false,
+             "typeAhead" : false,
+             "editable" : false,
+             "width" : 300,
+             "$ xns" : "Roo.form",
+             "* prop" : "field",
+             "name" : "coitem_shipto_id_shipto_name",
+             "qtip" : "Select shipto",
+             "queryParam" : "query[shipto_name]",
+             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>",
+             "loadingText" : "Searching...",
+             "items" : [
+              {
+               "listeners" : {
+                "|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"
+               },
+               "xtype" : "Store",
+               "remoteSort" : true,
+               "$ sortInfo" : "{ direction : 'ASC', field: 'shipto_name' }",
+               "$ xns" : "Roo.data",
+               "* prop" : "store",
+               "items" : [
+                {
+                 "$ url" : "baseURL + '/Roo/shiptoinfo.php'",
+                 "method" : "GET",
+                 "xtype" : "HttpProxy",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "proxy"
                 },
                 {
-                    "listeners" : {
-                        "click" : "function (_self, e)\n{\n      if (_this.grid)  _this.grid.stopEditing();\n    _this.dialog.hide();\n}"
-                    },
-                    "text" : "Cancel",
-                    "xtype" : "Button",
-                    "$ xns" : "Roo",
-                    "* prop" : "buttons[]"
+                 "id" : "shipto_id",
+                 "root" : "data",
+                 "xtype" : "JsonReader",
+                 "$ fields" : "[{\"name\":\"cntct_id\",\"type\":\"int\"},\"cntct_name\"]",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "reader",
+                 "totalProperty" : "total"
+                }
+               ]
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 150,
+         "header" : "Item Description",
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "item_descrip1",
+         "# 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\":\"\"}",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "xtype" : "TextField",
+             "allowBlank" : false,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Status",
+         "width" : 50,
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
+         "dataIndex" : "coitem_status"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Qty",
+         "width" : 40,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_qtyord",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 1,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "allowDecimals" : false,
+             "decimalPrecision" : 0,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Sell @",
+         "width" : 70,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_price",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 0,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "decimalPrecision" : 3,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "hidden" : true,
+         "xtype" : "ColumnModel",
+         "header" : "Sell @w/GST",
+         "width" : 70,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_price_tax",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 0,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "decimalPrecision" : 3,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Disc%",
+         "width" : 50,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_linedisc",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 0,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "decimalPrecision" : 2,
+             "$ xns" : "Roo.form",
+             "maxValue" : 100,
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "List Price",
+         "width" : 70,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_custprice",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 0,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "decimalPrecision" : 3,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "hidden" : true,
+         "xtype" : "ColumnModel",
+         "header" : "List Price w/GST",
+         "width" : 70,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_custprice_tax",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listeners" : {
+              "focus" : "function (_self)\n{\n    if (this.value == 0.0) {\n        this.el.dom.value = '';\n    }\n}"
+             },
+             "minValue" : 0,
+             "xtype" : "NumberField",
+             "style" : "text-align:right",
+             "decimalPrecision" : 3,
+             "$ xns" : "Roo.form",
+             "* prop" : "field"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "SubTotal",
+         "width" : 70,
+         "$ 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  }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_subtotal"
+        },
+        {
+         "align" : "right",
+         "hidden" : true,
+         "xtype" : "ColumnModel",
+         "header" : "SubTotal w/GST",
+         "width" : 70,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_subtotal_tax"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Unit Cost",
+         "width" : 50,
+         "$ renderer" : "function(v) { return Roo.util.Format.number( v, 2); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}",
+         "dataIndex" : "coitem_unitcost_in_order_cur"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "Taxed",
+         "width" : 50,
+         "$ renderer" : "function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "coitem_taxtype_id",
+         "items" : [
+          {
+           "xtype" : "GridEditor",
+           "$ xns" : "Roo.grid",
+           "* prop" : "editor",
+           "items" : [
+            {
+             "listWidth" : 400,
+             "triggerAction" : "all",
+             "forceSelection" : true,
+             "selectOnFocus" : true,
+             "pageSize" : 20,
+             "displayField" : "taxtype_name",
+             "emptyText" : "Select Tax Type",
+             "hiddenName" : "coitem_taxtype_id",
+             "minChars" : 2,
+             "valueField" : "taxtype_id",
+             "xtype" : "ComboBox",
+             "allowBlank" : false,
+             "typeAhead" : true,
+             "editable" : false,
+             "width" : 40,
+             "$ xns" : "Roo.form",
+             "* prop" : "field",
+             "name" : "coitem_taxtype_id_taxtype_name",
+             "qtip" : "Select taxtype",
+             "queryParam" : "query[taxtype_id]",
+             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>",
+             "loadingText" : "Searching...",
+             "items" : [
+              {
+               "listeners" : {
+                "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n    \n    \n}\n"
+               },
+               "xtype" : "Store",
+               "remoteSort" : true,
+               "$ sortInfo" : "{ direction : 'ASC', field: 'taxtype_name' }",
+               "$ xns" : "Roo.data",
+               "* prop" : "store",
+               "items" : [
+                {
+                 "$ url" : "baseURL + '/Roo/taxtype.php'",
+                 "method" : "GET",
+                 "xtype" : "HttpProxy",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "proxy"
                 },
                 {
-                    "listeners" : {
-                        "render" : "function (_self)\n{\n    _this.saveBtn = _self;\n}",
-                        "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}"
-                    },
-                    "text" : "Save",
-                    "xtype" : "Button",
-                    "$ xns" : "Roo",
-                    "* prop" : "buttons[]"
+                 "id" : "taxtype_id",
+                 "root" : "data",
+                 "xtype" : "JsonReader",
+                 "$ fields" : "[{\"name\":\"taxtype_id\",\"type\":\"int\"},\"taxtype_name\"]",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "reader",
+                 "totalProperty" : "total"
                 }
-            ]
+               ]
+              }
+             ]
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "#avail",
+         "width" : 50,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "avail_qty"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "#reserved",
+         "width" : 50,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
+         "dataIndex" : "shipitem_shipped"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "#shipped",
+         "width" : 50,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "# builderCfg" : "{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}",
+         "dataIndex" : "coitem_qtyshipped"
+        },
+        {
+         "align" : "right",
+         "xtype" : "ColumnModel",
+         "header" : "#invoiced",
+         "width" : 50,
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "cobill_billed"
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "activate" : "function (_self)\n{\n    _this.shipinvtab = _self;\n}"
+     },
+     "region" : "center",
+     "title" : "Shipments / Invoices",
+     "xtype" : "NestedLayoutPanel",
+     "$ xns" : "Roo",
+     "items" : [
+      {
+       "xtype" : "BorderLayout",
+       "$ xns" : "Roo",
+       "* prop" : "layout",
+       "items" : [
+        {
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "* prop" : "center",
+         "titlebar" : true
+        },
+        {
+         "title" : "Reserve Stock / Shipments",
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "* prop" : "north",
+         "height" : 250
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.shippanel = this;\n    if (_this.shipgrid) {\n        _this.shipgrid.ds.load({});\n    }\n}"
+         },
+         "region" : "north",
+         "background" : false,
+         "fitToframe" : true,
+         "title" : "shiphead",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "# 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\"}",
+         "tableName" : "shiphead",
+         "items" : [
+          {
+           "listeners" : {
+            "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",
+            "|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}"
+           },
+           "autoExpandColumn" : "shiphead_shipvia",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "# 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\"}",
+           "items" : [
+            {
+             "xtype" : "RowSelectionModel",
+             "singleSelect" : true,
+             "$ xns" : "Roo.grid",
+             "* prop" : "sm"
+            },
+            {
+             "listeners" : {
+              "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}"
+             },
+             "remoteSort" : true,
+             "xtype" : "Store",
+             "$ sortInfo" : "{ field : 'shiphead_shipvia', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "# 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\"}",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/shiphead.php'",
+               "xtype" : "HttpProxy",
+               "method" : "GET",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ xns" : "Roo.data",
+               "$ 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]",
+               "* prop" : "reader",
+               "totalProperty" : "total",
+               "# 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\"}"
+              }
+             ]
+            },
+            {
+             "xtype" : "Toolbar",
+             "$ xns" : "Roo",
+             "* prop" : "toolbar",
+             "items" : [
+              {
+               "listeners" : {
+                "|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}"
+               },
+               "text" : "Confirm Shipment",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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}"
+               },
+               "text" : "Download (as xls)",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/save.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Print Picking Slip",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Print Delivery Note",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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"
+               },
+               "text" : "Send Delivery Email",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "Roo.rootURL + 'images/default/dd/email.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "xtype" : "Fill",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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}",
+                "render" : "function (_self)\n{\n  _this.addShipmentBtn = _self;\n}"
+               },
+               "text" : "Add",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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        "
+               },
+               "text" : "Void / Unconfirm",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 80,
+             "header" : "number",
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "shiphead_number",
+             "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 100,
+             "header" : "From Location",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "shiphead_location_id_location_name"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 100,
+             "header" : "Ship to",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "shiphead_shipto_id_shipto_name"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "shipdate",
+             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
+             "dataIndex" : "shiphead_shipdate"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 50,
+             "header" : "Status",
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "shiphead_sfstatus",
+             "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 200,
+             "header" : "shipvia",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}",
+             "dataIndex" : "shiphead_shipvia"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 200,
+             "header" : "tracknum",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "# builderCfg" : "{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}",
+             "dataIndex" : "shiphead_tracknum"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.invpanel = this;\n    if (_this.invgrid) {\n        _this.invgrid.ds.load({});\n    }\n}"
+         },
+         "region" : "center",
+         "fitToframe" : true,
+         "background" : false,
+         "title" : "Invoices",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "tableName" : "cobmisc",
+         "items" : [
+          {
+           "listeners" : {
+            "|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",
+            "|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}"
+           },
+           "autoExpandColumn" : "invchead_invcnumber",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "# 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\"}",
+           "items" : [
+            {
+             "listeners" : {
+              "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}",
+              "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}"
+             },
+             "xtype" : "Store",
+             "remoteSort" : true,
+             "$ sortInfo" : "{ field : 'invchead_invcnumber', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/cobmisc.php'",
+               "method" : "GET",
+               "xtype" : "HttpProxy",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ fields" : "[\n    {\n        'name': 'invchead_invcnumber',\n        'type': 'string'\n    },\n    {\n        'name': 'invchead_invcdate',\n        'type': 'date'\n    }\n]",
+               "$ xns" : "Roo.data",
+               "* prop" : "reader",
+               "# 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\"}",
+               "totalProperty" : "total"
+              }
+             ]
+            },
+            {
+             "xtype" : "Toolbar",
+             "$ xns" : "Roo",
+             "* prop" : "toolbar",
+             "items" : [
+              {
+               "listeners" : {
+                "|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}"
+               },
+               "text" : "Post Invoice",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/lock.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "text" : "Print",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/pdf.gif'",
+               "$ xns" : "Roo.Toolbar",
+               "items" : [
+                {
+                 "xtype" : "Menu",
+                 "$ xns" : "Roo.menu",
+                 "* prop" : "menu",
+                 "items" : [
+                  {
+                   "listeners" : {
+                    "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}"
+                   },
+                   "text" : "Print Standard Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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} "
+                   },
+                   "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
+                   "text" : "Print Chinese Invoice With GST in line item",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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} "
+                   },
+                   "$ hidden" : "!(baseURL.match(/(hk\\.php|cn\\.php)$/))",
+                   "text" : "Print Chinese Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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} "
+                   },
+                   "$ hidden" : "!(baseURL.match(/au\\.php$/))",
+                   "text" : "Print Aus - GST included Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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}"
+                   },
+                   "$ hidden" : "!(baseURL.match(/au\\.php$/))",
+                   "text" : "Print Bambini Pronto Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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} "
+                   },
+                   "$ hidden" : "!(baseURL.match(/au\\.php$/))",
+                   "text" : "Print Bambini Pro Forma Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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}"
+                   },
+                   "$ hidden" : "!( baseURL.match(/au\\.php$/)) ",
+                   "text" : "Print Shipping / Commercial Invoice",
+                   "xtype" : "Item",
+                   "$ xns" : "Roo.menu"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "text" : "Payments / Refunds / Credit Memos",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
+               "$ xns" : "Roo.Toolbar",
+               "items" : [
+                {
+                 "xtype" : "Menu",
+                 "$ xns" : "Roo.menu",
+                 "* prop" : "menu",
+                 "items" : [
+                  {
+                   "listeners" : {
+                    "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"
+                   },
+                   "text" : "Receive Payment",
+                   "xtype" : "Item",
+                   "cls" : "x-btn-text-icon",
+                   "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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"
+                   },
+                   "text" : "Issue Refund",
+                   "xtype" : "Item",
+                   "cls" : "x-btn-text-icon",
+                   "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "xtype" : "Separator",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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"
+                   },
+                   "text" : "Void Payment",
+                   "xtype" : "Item",
+                   "cls" : "x-btn-text-icon",
+                   "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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"
+                   },
+                   "text" : "Void Refund",
+                   "xtype" : "Item",
+                   "cls" : "x-btn-text-icon",
+                   "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+                   "$ xns" : "Roo.menu"
+                  },
+                  {
+                   "listeners" : {
+                    "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"
+                   },
+                   "text" : "Void Credit Memo",
+                   "xtype" : "Item",
+                   "cls" : "x-btn-text-icon",
+                   "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+                   "$ xns" : "Roo.menu"
+                  }
+                 ]
+                }
+               ]
+              },
+              {
+               "xtype" : "Fill",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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}",
+                "render" : "function (_self)\n{\n  _this.addInvoiceBtn = _self;\n}"
+               },
+               "text" : "Add",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "|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}"
+               },
+               "text" : "Void / Unpost",
+               "xtype" : "Button",
+               "cls" : "x-btn-text-icon",
+               "$ icon" : "rootURL + '/Pman/templates/images/trash.gif'",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 100,
+             "header" : "Invoice #",
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_invchead_id_invchead_invcnumber"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "invcdate",
+             "$ renderer" : "function(v,x,r) { \n    \n    return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); \n}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_invcdate",
+             "# builderCfg" : "{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Qty",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}', v ? parseInt(v) : 0); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_qty"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Item Cost",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_itemcost"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Shipping",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_freight"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Tax",
+             "width" : 75,
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_tax"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Discount (Pretax)",
+             "width" : 100,
+             "$ renderer" : "function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_cohead_id_cohead_pretax_discount"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Discount (Posttax)",
+             "width" : 100,
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_misc"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Total ",
+             "width" : 75,
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_total"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Outstanding",
+             "width" : 75,
+             "$ renderer" : "function(v,x,r) \n{ \n    \n    return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );\n}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "cobmisc_outstanding"
+            }
+           ]
+          }
+         ]
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "|activate" : "function() {\n    _this.hpanel = this;\n    if (_this.hgrid) {\n        _this.hgrid.footer.onClick('first');\n    }\n}"
+     },
+     "region" : "center",
+     "background" : true,
+     "fitToframe" : true,
+     "title" : "History",
+     "xtype" : "GridPanel",
+     "fitContainer" : true,
+     "$ xns" : "Roo",
+     "# 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\"}",
+     "tableName" : "events",
+     "items" : [
+      {
+       "listeners" : {
+        "|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",
+        "|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}"
+       },
+       "autoExpandColumn" : "remarks",
+       "xtype" : "Grid",
+       "loadMask" : true,
+       "$ xns" : "Roo.grid",
+       "* prop" : "grid",
+       "# 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\"}",
+       "items" : [
+        {
+         "listeners" : {
+          "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}"
+         },
+         "remoteSort" : true,
+         "xtype" : "Store",
+         "$ sortInfo" : "{ field : 'event_when', direction: 'DESC' }",
+         "$ xns" : "Roo.data",
+         "* prop" : "dataSource",
+         "# 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\"}",
+         "items" : [
+          {
+           "$ url" : "baseURL + '/Roo/events.php'",
+           "xtype" : "HttpProxy",
+           "method" : "GET",
+           "$ xns" : "Roo.data",
+           "* prop" : "proxy"
+          },
+          {
+           "id" : "id",
+           "root" : "data",
+           "xtype" : "JsonReader",
+           "$ 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]",
+           "$ xns" : "Roo.data",
+           "* prop" : "reader",
+           "# 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\"}",
+           "totalProperty" : "total"
+          }
+         ]
+        },
+        {
+         "pageSize" : 25,
+         "xtype" : "PagingToolbar",
+         "emptyMsg" : "No events found",
+         "$ xns" : "Roo",
+         "displayInfo" : true,
+         "displayMsg" : "Displaying events{0} - {1} of {2}",
+         "* prop" : "footer"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 120,
+         "header" : "Changed",
+         "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "event_when",
+         "# builderCfg" : "{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 120,
+         "header" : "action",
+         "$ renderer" : "function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "action",
+         "# builderCfg" : "{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 120,
+         "header" : "IP address",
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "ipaddr",
+         "# builderCfg" : "{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 120,
+         "header" : "Who",
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "person_id_name",
+         "# builderCfg" : "{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 200,
+         "header" : "Notes",
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "remarks",
+         "# builderCfg" : "{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}"
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "region" : "center",
+     "title" : "Stock Tx",
+     "xtype" : "NestedLayoutPanel",
+     "$ xns" : "Roo",
+     "items" : [
+      {
+       "xtype" : "BorderLayout",
+       "$ xns" : "Roo",
+       "* prop" : "layout",
+       "items" : [
+        {
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "* prop" : "center"
+        },
+        {
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "width" : 500,
+         "split" : true,
+         "* prop" : "east"
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.txpanel = this;\n    if (_this.txgrid) {\n        _this.txgrid.footer.onClick('first');\n    }\n}"
+         },
+         "region" : "center",
+         "fitToframe" : true,
+         "background" : false,
+         "title" : "invdetail",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "tableName" : "invdetail",
+         "items" : [
+          {
+           "listeners" : {
+            "|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}"
+           },
+           "autoExpandColumn" : "item_number",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "items" : [
+            {
+             "xtype" : "Toolbar",
+             "$ xns" : "Roo",
+             "* prop" : "toolbar",
+             "items" : [
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Run Apply Fifo on order",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Run Void flagger",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Auto Reverse",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "listeners" : {
+              "selectionchange" : "function (_self)\n{\n    _this.txdgrid.footer.onClick('first');;\n}"
+             },
+             "xtype" : "RowSelectionModel",
+             "singleSelect" : true,
+             "$ xns" : "Roo.grid",
+             "* prop" : "sm"
+            },
+            {
+             "listeners" : {
+              "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}"
+             },
+             "xtype" : "Store",
+             "remoteSort" : true,
+             "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/invdetail.php'",
+               "method" : "GET",
+               "xtype" : "HttpProxy",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ xns" : "Roo.data",
+               "$ 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]",
+               "* prop" : "reader",
+               "totalProperty" : "total"
+              }
+             ]
+            },
+            {
+             "pageSize" : 9999,
+             "xtype" : "PagingToolbar",
+             "emptyMsg" : "No invdetail found",
+             "$ xns" : "Roo",
+             "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
+             "displayInfo" : true,
+             "* prop" : "footer"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Item",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "item_number"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#Ship",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "rec_shipped"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#Ret",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "rec_returned"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#TX ship",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "tx_shipped"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#TX ret",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "tx_returned"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#TX Tot",
+             "width" : 50,
+             "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "tx_total"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Value",
+             "width" : 50,
+             "$ renderer" : "function(v,x,r) { \n\n    return (v*1).toFixed(3);\n}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "total_value"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "#Diff",
+             "width" : 50,
+             "$ 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    }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "tx_total"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.txdpanel = this;\n    if (_this.txdgrid) {\n        _this.txdgrid.footer.onClick('first');\n    }\n}"
+         },
+         "region" : "east",
+         "fitToframe" : true,
+         "background" : false,
+         "title" : "invdetail",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "tableName" : "invdetail",
+         "items" : [
+          {
+           "listeners" : {
+            "|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}",
+            "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}"
+           },
+           "autoExpandColumn" : "invhist_comments",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "items" : [
+            {
+             "xtype" : "Toolbar",
+             "$ xns" : "Roo",
+             "* prop" : "toolbar",
+             "items" : [
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Duplicate Selected",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "xtype" : "Fill",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "text" : "Issue Date",
+               "xtype" : "TextItem",
+               "$ xns" : "Roo.Toolbar"
+              },
+              {
+               "listeners" : {
+                "render" : "function (_self)\n{\n    _this.dateSel = _self;\n}"
+               },
+               "format" : "Y-m-d",
+               "fieldLabel" : "Issue Date",
+               "xtype" : "DateField",
+               "allowBlank" : false,
+               "width" : 150,
+               "$ xns" : "Roo.form",
+               "name" : "issue_date"
+              },
+              {
+               "listeners" : {
+                "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}"
+               },
+               "text" : "Reverse Selected",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "listeners" : {
+              "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}"
+             },
+             "xtype" : "Store",
+             "remoteSort" : true,
+             "$ sortInfo" : "{ field : 'invdetail_id', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/invdetail.php'",
+               "method" : "GET",
+               "xtype" : "HttpProxy",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ xns" : "Roo.data",
+               "$ 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]",
+               "* prop" : "reader",
+               "totalProperty" : "total"
+              }
+             ]
+            },
+            {
+             "pageSize" : 9999,
+             "xtype" : "PagingToolbar",
+             "emptyMsg" : "No invdetail found",
+             "$ xns" : "Roo",
+             "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
+             "displayInfo" : true,
+             "* prop" : "footer"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 60,
+             "header" : "TX#",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invdetail_id"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Date",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invhist_transdate"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Ref#",
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invhist_ordnumber"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 60,
+             "header" : "TX#",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "location_name"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Notes",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invhist_comments"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Qty Changed",
+             "width" : 50,
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invdetail_qty"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Qty Changed",
+             "width" : 75,
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invhist_value_before"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 40,
+             "header" : "Posted",
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "invhist_posted"
+            }
+           ]
+          }
+         ]
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "region" : "center",
+     "title" : "GL Tx",
+     "xtype" : "NestedLayoutPanel",
+     "$ xns" : "Roo",
+     "items" : [
+      {
+       "xtype" : "BorderLayout",
+       "$ xns" : "Roo",
+       "* prop" : "layout",
+       "items" : [
+        {
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "* prop" : "center"
+        },
+        {
+         "xtype" : "LayoutRegion",
+         "$ xns" : "Roo",
+         "width" : 500,
+         "split" : true,
+         "* prop" : "east"
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.gltxpanel = this;\n    if (_this.gltxgrid) {\n        _this.gltxgrid.footer.onClick('first');\n    }\n}"
+         },
+         "region" : "center",
+         "fitToframe" : true,
+         "background" : false,
+         "title" : "invdetail",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "tableName" : "invdetail",
+         "items" : [
+          {
+           "listeners" : {
+            "|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}",
+            "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}"
+           },
+           "autoExpandColumn" : "gltrans_accnt_id_accnt_descrip",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "items" : [
+            {
+             "listeners" : {
+              "selectionchange" : "function (_self)\n{\n    _this.gltxdgrid.footer.onClick('first');;\n}"
+             },
+             "xtype" : "RowSelectionModel",
+             "singleSelect" : true,
+             "$ xns" : "Roo.grid",
+             "* prop" : "sm"
+            },
+            {
+             "listeners" : {
+              "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}"
+             },
+             "xtype" : "Store",
+             "remoteSort" : true,
+             "$ sortInfo" : "{ field : 'item_number', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/gltrans.php'",
+               "method" : "GET",
+               "xtype" : "HttpProxy",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ xns" : "Roo.data",
+               "$ 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]",
+               "* prop" : "reader",
+               "totalProperty" : "total"
+              }
+             ]
+            },
+            {
+             "pageSize" : 9999,
+             "xtype" : "PagingToolbar",
+             "emptyMsg" : "No invdetail found",
+             "$ xns" : "Roo",
+             "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
+             "displayInfo" : true,
+             "* prop" : "footer",
+             "items" : [
+              {
+               "listeners" : {
+                "render" : "function (_self)\n{\n    _this.glsalesbtn = _self;\n}",
+                "click" : "function (_self, e)\n{\n    (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);\n}"
+               },
+               "text" : "Split sales",
+               "enableToggle" : true,
+               "pressed" : true,
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 50,
+             "header" : "Summary",
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_as_summary"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Account",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_accnt_id_accnt_descrip"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Credit",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_amount_credit"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Debit",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_amount_debit"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Sum",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_amount_total"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Unposted",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('<span style=\"color:red\">{0}</span>', Roo.util.Format.number(v,3)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_amount_total_unposted"
+            }
+           ]
+          }
+         ]
+        },
+        {
+         "listeners" : {
+          "|activate" : "function() {\n    _this.gltxdpanel = this;\n    if (_this.gltxdgrid) {\n        _this.gltxdgrid.footer.onClick('first');\n    }\n}"
+         },
+         "region" : "east",
+         "fitToframe" : true,
+         "background" : false,
+         "title" : "invdetail",
+         "xtype" : "GridPanel",
+         "fitContainer" : true,
+         "$ xns" : "Roo",
+         "tableName" : "invdetail",
+         "items" : [
+          {
+           "listeners" : {
+            "|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}",
+            "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}"
+           },
+           "autoExpandColumn" : "gltrans_notes",
+           "xtype" : "Grid",
+           "loadMask" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "grid",
+           "items" : [
+            {
+             "listeners" : {
+              "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}"
+             },
+             "xtype" : "Store",
+             "remoteSort" : true,
+             "$ sortInfo" : "{ field : 'gltrans_docnumber', direction: 'ASC' }",
+             "$ xns" : "Roo.data",
+             "* prop" : "dataSource",
+             "items" : [
+              {
+               "$ url" : "baseURL + '/Roo/gltrans.php'",
+               "method" : "GET",
+               "xtype" : "HttpProxy",
+               "$ xns" : "Roo.data",
+               "* prop" : "proxy"
+              },
+              {
+               "id" : "id",
+               "root" : "data",
+               "xtype" : "JsonReader",
+               "$ xns" : "Roo.data",
+               "$ 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]",
+               "* prop" : "reader",
+               "totalProperty" : "total"
+              }
+             ]
+            },
+            {
+             "pageSize" : 9999,
+             "xtype" : "PagingToolbar",
+             "emptyMsg" : "No invdetail found",
+             "$ xns" : "Roo",
+             "displayMsg" : "Displaying invdetail{0} - {1} of {2}",
+             "displayInfo" : true,
+             "* prop" : "footer",
+             "items" : [
+              {
+               "listeners" : {
+                "click" : "function (_self, e)\n{\n    new Pman.Download( {\n        grid : _this.gltxdgrid\n    \n    });\n}"
+               },
+               "text" : "Download",
+               "xtype" : "Button",
+               "$ xns" : "Roo.Toolbar"
+              }
+             ]
+            },
+            {
+             "xtype" : "ColumnModel",
+             "sortable" : true,
+             "header" : "Ref#",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}', v ); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_id"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Date",
+             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_date"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Doc#",
+             "$ 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}",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_docnumber"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 50,
+             "header" : "Source",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_source"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 75,
+             "header" : "Notes",
+             "$ renderer" : "function(v) { return String.format('{0}', v); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_notes"
+            },
+            {
+             "align" : "right",
+             "xtype" : "ColumnModel",
+             "header" : "Amount",
+             "width" : 75,
+             "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_amount"
+            },
+            {
+             "xtype" : "ColumnModel",
+             "width" : 50,
+             "header" : "Posted",
+             "$ 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 }",
+             "$ xns" : "Roo.grid",
+             "* prop" : "colModel[]",
+             "dataIndex" : "gltrans_posted"
+            }
+           ]
+          }
+         ]
+        }
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "|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}"
+     },
+     "region" : "center",
+     "fitToframe" : true,
+     "background" : true,
+     "title" : "Profit",
+     "xtype" : "GridPanel",
+     "fitContainer" : true,
+     "$ xns" : "Roo",
+     "tableName" : "coitem",
+     "items" : [
+      {
+       "listeners" : {
+        "|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}"
+       },
+       "autoExpandColumn" : "item_number",
+       "xtype" : "Grid",
+       "loadMask" : true,
+       "$ xns" : "Roo.grid",
+       "* prop" : "grid",
+       "items" : [
+        {
+         "listeners" : {
+          "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}"
+         },
+         "xtype" : "Store",
+         "remoteSort" : true,
+         "$ sortInfo" : "{ field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' }",
+         "$ xns" : "Roo.data",
+         "* prop" : "dataSource",
+         "items" : [
+          {
+           "$ url" : "baseURL + '/Roo/coitem.php'",
+           "method" : "GET",
+           "xtype" : "HttpProxy",
+           "$ xns" : "Roo.data",
+           "* prop" : "proxy"
+          },
+          {
+           "id" : "id",
+           "root" : "data",
+           "xtype" : "JsonReader",
+           "$ xns" : "Roo.data",
+           "$ 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]",
+           "* prop" : "reader",
+           "totalProperty" : "total"
+          }
+         ]
+        },
+        {
+         "pageSize" : 25,
+         "xtype" : "PagingToolbar",
+         "emptyMsg" : "No coitem found",
+         "$ xns" : "Roo",
+         "displayMsg" : "Displaying coitem{0} - {1} of {2}",
+         "displayInfo" : true,
+         "* prop" : "footer"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 75,
+         "header" : "Item Code",
+         "$ renderer" : "function(v) { return String.format('{0}', v); }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "item_number"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 200,
+         "header" : "SubTotal",
+         "$ renderer" : "function(v) {\n\n\n     return Roo.util.Format.number( v, 2);\n  }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "calc_subtotal"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 200,
+         "header" : "Cost of goods",
+         "$ renderer" : "function(v) {\n\n    return Roo.util.Format.number( v, 2);\n  }",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "calc_cost_total"
+        },
+        {
+         "xtype" : "ColumnModel",
+         "width" : 200,
+         "header" : "Profit",
+         "$ 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}",
+         "$ xns" : "Roo.grid",
+         "* prop" : "colModel[]",
+         "dataIndex" : "profit"
         }
-    ]
+       ]
+      }
+     ]
+    },
+    {
+     "listeners" : {
+      "render" : "function (_self)\n{\n    _this.reversalBtn = _self;\n}",
+      "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}"
+     },
+     "text" : "Create CM reversal",
+     "xtype" : "Button",
+     "$ xns" : "Roo",
+     "* prop" : "buttons[]"
+    },
+    {
+     "listeners" : {
+      "click" : "function (_self, e)\n{\n      if (_this.grid)  _this.grid.stopEditing();\n    _this.dialog.hide();\n}"
+     },
+     "text" : "Cancel",
+     "xtype" : "Button",
+     "$ xns" : "Roo",
+     "* prop" : "buttons[]"
+    },
+    {
+     "listeners" : {
+      "render" : "function (_self)\n{\n    _this.saveBtn = _self;\n}",
+      "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}"
+     },
+     "text" : "Save",
+     "xtype" : "Button",
+     "$ xns" : "Roo",
+     "* prop" : "buttons[]"
+    }
+   ]
+  }
+ ]
 }
\ No newline at end of file
index 1439d0f..3edc969 100644 (file)
@@ -6,7555 +6,7384 @@ Roo.namespace('Pman.Dialog');
 
 Pman.Dialog.XtupleSalesOrder = {
 
-    dialog : false,
-    callback:  false,
-
-    show : function(data, cb)
-    {
-        if (!this.dialog) {
-            this.create();
+ _strings : {
+  '58ec392a138714456f83d1288f553099' :"tracknum",
+  '42f6d99a2dddc4858882ed8e9a210b52' :"Invoice #",
+  '249ff431aa95198ad6814dd1d2799883' :"Select taxtype",
+  'fce9a6a1bd2a2050eb86d33103f46fd3' :"Invoices",
+  'a2fdeac60e3c5b6c51a92e027fb9d533' :"Target Delivery",
+  '96b0141273eabab320119c467cdcaf17' :"Total",
+  'd682c376c82f68bc65dcd05570d04dfc' :"Payments / Refunds / Credit Memos",
+  '75ba8d70e3692ba200f0e0df37b4d2ae' :"IP address",
+  '9f4f3d35db49c5c2bba70a321a42fa87' :"Find Products",
+  '9d4ba8f5211a3ba238b2032be5991c14' :"Disc%",
+  'e12167aa0a7698e6ebc92b4ce3909b53' :"To",
+  'c4a0f4ddf926328daa2a350db9f9ca00' :"Qty Changed",
+  '99575a08540e6ee585a7b389e8bde351' :"GL Tx",
+  'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
+  'f84e65035f5d2d4a090b8a626c822321' :"List Price",
+  'fc44040a63559bee1157010d4c602422' :"Select location",
+  '62f0de97dd70387d493350e45bfa5583' :"Send Delivery Email",
+  'cc7819055cde3194bb3b136bad5cf58d' :"&nbsp;",
+  '806dca90dbeda894ffb258939f9fef9a' :"Fill empty Ship To",
+  'fce6d3795b41b54dc0dab82df50517c1' :"Select custinfo",
+  'd323a19bad62ff427d0b75dc52674c81' :"#Ret",
+  'c5eae6ea505388a73962c635ac821fba' :"SubTotal",
+  'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
+  '418c5509e2171d55b0aee5c2ea4442b5' :"action",
+  '51e07f52ae2192d23a1b43922e5beb90' :"#TX ship",
+  '607ff05a0e4c02c54b2262cd2e381aff' :"Reserve Stock / Shipments",
+  '689202409e48743b914713f96d93947c' :"Value",
+  'd9db367d7e9d6a3d3ca0346dfa1ff9d2' :"Item Description",
+  '16d2b386b2034b9488996466aaae0b57' :"History",
+  'dd7bf230fde8d4836917806aff6a6b27' :"Address",
+  '986b90fb419e5349dd59b691b0e0e9f6' :"Customer PO#",
+  '7d74f3b92b19da5e606d737d339a9679' :"Item",
+  'c5c8ac6bbc6d7f5c95d0a888527554d3' :"Order Details",
+  'fd216b286b94577ac68c112c0dcaf341' :"TX#",
+  '068f80c7519d0528fb08e82137a72131' :"Products",
+  'b166cb3a96bdb966f3288b8599594d0d' :"Sell @",
+  '1243daf593fa297e07ab03bf06d925af' :"Searching...",
+  '151ccf95db9b81c11bb20fbc302af4b6' :"Select terms",
+  '7eb17faabef94701775df7154f30684b' :"#avail",
+  'f31bbdd1b3e85bccd652680e16935819' :"Source",
+  '086247a9b57fde6eefee2a0c4752242d' :"Automatic",
+  '0a90b1bc4078f74b6f0d117ec7df65af' :"Credit",
+  '27f2870eaa01c99fc83105240ad15f7f' :"Delete All",
+  '5f0c1431b38e3d279bf105d48824b7f3' :"Select ship to",
+  '26453198f2ddac444702879a8f6d61a5' :"Auto Reverse",
+  '780c462e85ba4399a5d42e88f69a15ca' :"Billing",
+  '81dffdb31b9576e343d3f7ffcf721d7e' :"Cost of goods",
+  '813f81532d71077e497863ec9faf16c7' :"Confirm Shipment",
+  '46fc12727bf2c5cc79988ab857ad73b4' :"Print Shipping / Commercial Invoice",
+  '8156649b9de8783c15c822b592c3bac6' :"Reverse Selected",
+  '8c6aab77edc5b8e589b36bcf989683e4' :"Print Picking Slip",
+  '69193f49683ba5a928ae8a27328105ba' :"Print Aus - GST included Invoice",
+  '13dba24862cf9128167a59100e154c8d' :"Print",
+  '4b5a5a93e13bd338d40cf4bae2ca51cb' :"Void Credit Memo",
+  'b80f4ed22929b09103f0c5666ad7a7e1' :"Run Apply Fifo on order",
+  '009534719f8c8221440a5629f497a784' :"Debit",
+  '1abe972d603f3bd61eefc9ac39fb7522' :"#TX Tot",
+  '7b09a122e58c067939744c4a96ff2d77' :"Select salesrep",
+  '56d56144d4e4a42ce450446518c4fc00' :"#Diff",
+  '03ab340b3f99e03cff9e84314ead38c0' :"Qty",
+  'f4c6f851b00d5518bf888815de279aba' :"Notes",
+  'c9cc8cce247e49bae79f15173ce97354' :"Save",
+  '386c339d37e737a436499d423a77df0c' :"Currency",
+  'f4757c5aca5e4410b63c6ec4cd0f2363' :"shiphead",
+  'f97f673be4e5f66aca62b35280d8bcde' :"Print Standard Invoice",
+  'acc95aeaee48871da70cc3bce664728c' :"Select shiptoinfo",
+  'ce26601dac0dea138b7295f02b7620a7' :"Customer",
+  'd335d558a8386d20318888b1f034103d' :"Unshipped Total",
+  '2925dda0ec274c20c0a30d8720eb830b' :"Select curr_name",
+  '72d6d7a1885885bb55a565fd1070581a' :"Import",
+  '9aa6071f39d387792476bd70fed66735' :"Void / Unconfirm",
+  '6f1bf85c9ebb3c7fa26251e1e335e032' :"Terms",
+  '53896265ad28c11cb4997b3c3e3e122d' :"#Ship",
+  '5da618e8e4b89c66fe86e32cdafde142' :"From",
+  '158e64bcd08067d26e9c27679eeced88' :"No Items",
+  'd179a904ac10a39ab574fe803cc29fa3' :"Run Void flagger",
+  'f3d90c6982143029487fb00d4ef19526' :"#invoiced",
+  '80092f7900d59aab765d0ddd35dc7231' :"Add Shipment",
+  'a240fa27925a635b08dc28c9e4f9216d' :"Order",
+  '01d35df7886d24900b1ecb65da6bf21d' :"Receive Payment",
+  'f817f797c422f7ac3404b6223db1a1ee' :"invdetail",
+  '50104a28589c5b6099d3580861c2551a' :"Shipments / Invoices",
+  'e23841a1d7427d8a9297142145dff049' :"Select shipto",
+  '9f1a342d0197aac60ed73e921dc4c1f5' :"Price Details",
+  '2142511303396bd51e0cc25ea8ffe47f' :"Void Payment",
+  '88408722ed9d719c44087292bf8a06cf' :"Prices with GST",
+  '236119342501b1e596bc82013c9cfc42' :"SubTotal w/GST",
+  '4b78ac8eb158840e9638a3aeb26c4a9d' :"Tax",
+  'cb02c723b8a159fea3cd7913d3df7fbc' :"Doc#",
+  '6a813cbab5d0c9d33b1a471839935d88' :"Cust#",
+  'b8feb9ee933bc5cc05615860322e9e7a' :"Post Invoice",
+  '70c6ddcd97af88d0aaac48268c459727' :"Download (as xls)",
+  '66b2bba3de9b8c5d6fb94e9458f1b7f5' :"Show Inventory History",
+  '57cdc7bcd2ca327f3267e2f5ecfa8c6d' :"Edit / Create Sales Order",
+  '48e91c2f1cb7b90612ccae2502c7327f' :"Shipment Comments",
+  '47cb03899dc494703b52c37240fa4c17' :"Stock Tx",
+  '72bb7a9ea8714c52b0c0b8369d6a8dc3' :"Issue Date",
+  'e5d63551ca2d2842661e49a25fd12a67' :"Edit Customer",
+  '7608203603437f0513ba8203a2d39a4f' :"Item Code",
+  '08bd40c7543007ad06e4fce31618f6ec' :"Account",
+  'e963218370d6410e1ee0f8e6128c12d4' :"shipdate",
+  '0ee182201463a0ea31cb073b227fbbbe' :"Print Chinese Invoice With GST in line item",
+  '089ba2b5edc96565fc22c584ecfbb1a6' :"Displaying events{0} - {1} of {2}",
+  '0bcef9c45bd8a48eda1b26eb0c61c869' :"%",
+  '81ceb48a978444906d80119200aa358d' :"Void",
+  'a763436d2b30d54e4aff264b1636827a' :"Discount (Pretax)",
+  '4721299f56b6b7d43591156d1d3f3e82' :"List Price w/GST",
+  'f4ac45b9eb622dcb26c0d4fc1c93b27c' :"Order Comments",
+  '7a113dee68a51f4c5f71264fd0ce3781' :"Item#",
+  'a860ed9926b241b7d4dca2d00610ab2c' :"Outstanding",
+  '290612199861c31d1036b185b4e69b75' :"Summary",
+  '786410e93beb0193d89f8608c54feb4b' :"Select item",
+  'b1bc248a7ff2b2e95569f56de68615df' :"number",
+  '07ca5050e697392c9ed47e6453f1453f' :"Completed",
+  '6b15347cbd1bf352b547741a7525c1b4' :"#shipped",
+  'b3c65c9f85b429821cf931b38386a64d' :"Select Tax Type",
+  '5e33fc1550a56738da96fbaaf57e72f0' :"#TX ret",
+  '16cd452dda9d4398bf6240603eee40a9' :"Posted",
+  'b2f40690858b404ed10e62bdf422c704' :"Amount",
+  'e87de1a5d238411ab34a292be599e9f4' :"Apply To All",
+  '40e6e8652d174c7ceef48df46f9cf25a' :"From Location",
+  '9122d60c0550be8ab070b96d8bbc6358' :"Sell @w/GST",
+  '78ca8a8170f2065057507ddcde63d9ca' :"Tax Zone",
+  '757989a16207ab23076685118640adf3' :"Item Cost",
+  '160ab8f9d6c5d2819fff11dea08d4ef8' :"Download Excel",
+  '0ee72ad23c24d7cfc5c13311abdc3f72' :"Staff I.C.",
+  '511b6a78f5503881ba10ff93b7205ade' :"Create CM reversal",
+  '74002cb040b036511b8d031da591364a' :"Ship to",
+  'c6b4fd215b0cdcb7426519edc0ece828' :"Print Bambini Pro Forma Invoice",
+  'b98c34417c412e0c87faa828f26b9123' :"Uninvoiced Total",
+  'a0d036a1d6a00180df168fa86143e5f8' :"No invdetail found",
+  'de3d17fb46f44fdf066581fbb5fe6113' :"Select Staff",
+  'fbb9d6ec5325d0fe63c19431856a0802' :"Select cntct",
+  'c3ce05eb16c5e0075b4a247b2c4b7bba' :"Bill To (select)",
+  'ec53a8c4f07baed5d8825072c89799be' :"Status",
+  '25d81668fca34c83d0720cc6365d62d6' :"Pre Tax discount",
+  'b25f6c965342495f74899e183efe20a4' :"Void / Unpost",
+  '58733ee735e3160c5c9fa5739fb4d056' :"Unposted",
+  '3ec365dd533ddb7ef3d1c111186ce872' :"Details",
+  'c04b33241cc5478500daf178e3720b63' :"No coitem found",
+  'ea9cf7e47ff33b2be14e6dd07cbcefc6' :"Shipping",
+  '871080cb9d00a8bda1b9f1db3c164341' :"Unit Cost",
+  '820dbd2b8f606aff866c0bbfb6b737c1' :"Changed",
+  '7ce96513eec175e6123b56573750b0dd' :"#reserved",
+  'a0ec87054b5e5b7847d0d8780a01a3d5' :"Sum",
+  '26e09a1ee1517389c7b07f42df65561a' :"Ordered",
+  'bdd31bfe5374e3cdc19a10020eae4b49' :"Add Invoice",
+  '801ab24683a4a8c433c6eb40c48bcd9d' :"Download",
+  '44749712dbec183e983dcd78a7736c41' :"Date",
+  '37656f0f6cf5e5befb1ec7abd3db5804' :"shipvia",
+  '4a2a14210d78f0d82db75d0264030169' :"Supply From",
+  '052fbb9431206b4755090dc53fcef300' :"Void Refund",
+  'c4b515058fab313f403ae427ce7e32b3' :"Update Location to match S/O",
+  '87813307f6e7498b30c5b3d9b2f65f56' :"Displaying invdetail{0} - {1} of {2}",
+  '3a6a3353e3b44ad5359c8e3178b66a54' :"invcdate",
+  '4b84bd35233c0d3d3c36b9a6ce6e0745' :"Order Items",
+  '13abfee28b4564e3fb059420fbedbec5' :"Taxed",
+  '94f475efc6722fd13ab78411c1ef7bd7' :"Sales Rep",
+  'bb4af85913879b95661b81570a2c2e83' :"Discount (Posttax)",
+  '526db6366257755024ed2556000871bc' :"Issue Refund",
+  '594f5bdc5e1519ce9934d276e5bf081f' :"No events found",
+  'd0cc96be641673ad48fc74374fda8137' :"Displaying coitem{0} - {1} of {2}",
+  'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
+  'b6dad11e8e2203819164d64fc82b40f1' :"Discount after Tax  Description",
+  'ea4788705e6873b424c65e91c2846b19' :"Cancel",
+  '1b7132f58f9ee9de75e5778ff04f7303' :"Print Delivery Note",
+  '4ee972120bcda675f75222c87cb9d356' :"Who",
+  'a0947dda65e4112f49260243804b6528' :"Xfer all stock to HK",
+  '1d144309cbdf2536723621bf0eac9f33' :"or enter Address",
+  '3d96cc39e5517a284e203ffc8cafcf51' :"Print Bambini Pronto Invoice",
+  '9c9745a343efeacc9efe9b7222b27afb' :"Ref#",
+  'c43b0fbe81e21c0a874a155ce528eebf' :"Apply % Discount of : ",
+  'e8586011952b0d098b0e568f20ca2b1f' :"Select Currency",
+  'fa1cfdb383ea976facbdb20d40d2f811' :"Duplicate Selected",
+  '6ac26fe4e9a39ac45fffe6d6920dac3a' :"Print Chinese Invoice",
+  '182875b6c36a761f1e459624c1d93638' :"Profit",
+  '3ffaf70863d6f46e2719050a37d9ef86' :"Order#",
+  '8fb8fbc1c0bc53b2d01121344410e444' :"Split sales",
+  '09466661df2abefeecf849e52fce8fb4' :"Total "
+ },
+
+ dialog : false,
+ callback:  false,
+
+ show : function(data, cb)
+ {
+  if (!this.dialog) {
+   this.create();
+  }
+
+  this.callback = cb;
+  this.data = data;
+  this.dialog.show(this.data._el);
+  if (this.form) {
+   this.form.reset();
+   this.form.setValues(data);
+   this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
+  }
+
+ },
+
+ create : function()
+ {
+   var _this = this;
+   this.dialog = Roo.factory({
+    closable : true,
+    collapsible : false,
+    height : 620,
+    modal : true,
+    resizable : true,
+    title : _this._strings['57cdc7bcd2ca327f3267e2f5ecfa8c6d'] /* Edit / Create Sales Order */,
+    width : 1050,
+    xns : Roo,
+    '|xns' : 'Roo',
+    xtype : 'LayoutDialog',
+    listeners : {
+     show : function () {
+             this.layout.getRegion('center').showPanel(0);
+      }
+    },
+    center : {
+     alwaysShowTabs : true,
+     tabPosition : 'top',
+     xns : Roo,
+     '|xns' : 'Roo',
+     xtype : 'LayoutRegion',
+     toolbar : {
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'Toolbar',
+      items  : [
+       {
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Fill'
+       },
+       {
+        cls : 'x-btn-text-icon',
+        icon : rootURL + '/Pman/templates/images/spreadsheet.gif',
+        text : _this._strings['160ab8f9d6c5d2819fff11dea08d4ef8'] /* Download Excel */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function ()
+          {
+              var id = 1* _this.form.findField('cohead_id').getValue();
+              if (!id) {
+                  Roo.MessageBox.alert("Error", "Save Sales order first");
+                  return;
+              
+              }
+              // check current status of shipment..
+          
+                  new Pman.Download({
+                      url : baseURL + '/Roo/cohead',
+                      method : 'GET',
+                      params : {
+                          cohead_id :  id,
+                          _excel : 1
+                      },
+                      success : function() {
+          
+                      }
+                  })
+                      
+                      
+             
+          }
         }
-
-        this.callback = cb;
-        this.data = data;
-        this.dialog.show(this.data._el);
-        if (this.form) {
-           this.form.reset();
-           this.form.setValues(data);
-           this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
+       },
+       {
+        cls : 'x-btn-text-icon',
+        icon : rootURL + '/Pman/templates/images/pdf.gif',
+        text : _this._strings['13dba24862cf9128167a59100e154c8d'] /* Print */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function ()
+          {
+              var id = 1* _this.form.findField('cohead_id').getValue();
+              if (!id) {
+                  Roo.MessageBox.alert("Error", "Save Sales order first");
+                  return;
+              
+              }
+              // check current status of shipment..
+          
+                  new Pman.Download({
+                      url : baseURL + '/Roo/cohead',
+                      method : 'GET',
+                      params : {
+                          cohead_id :  id,
+                          _print : 1
+                      },
+                      success : function() {
+          
+                      }
+                  })
+                      
+                      
+             
+          }
         }
-
+       },
+       {
+        cls : 'x-btn-text-icon',
+        hidden : true,
+        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+        text : _this._strings['80092f7900d59aab765d0ddd35dc7231'] /* Add Shipment */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function (_self, e)
+          {
+          
+              _this.addShipmentBtn.fireEvent('click');
+             
+          }
+        }
+       },
+       {
+        cls : 'x-btn-text-icon',
+        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+        text : _this._strings['e5d63551ca2d2842661e49a25fd12a67'] /* Edit Customer */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function (_self, e)
+          {
+          
+             Pman.Dialog.XtupleCustomer.show({
+                   cust_id : _this.form.findField('cohead_cust_id').getValue()
+            }); 
+          }
+        }
+       },
+       {
+        cls : 'x-btn-text-icon',
+        hidden : true,
+        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+        text : _this._strings['bdd31bfe5374e3cdc19a10020eae4b49'] /* Add Invoice */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function (_self, e)
+          {
+          
+                  _this.addInvoiceBtn.fireEvent('click');
+             
+          }
+        }
+       },
+       {
+        text : _this._strings['81ceb48a978444906d80119200aa358d'] /* Void */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function (_self, e)
+          {
+               var p = {         
+                   cohead_id : _this.form.findField('cohead_id').getValue() 
+               };
+              function call() {
+          
+                      
+                 new Pman.Request({
+                      mask : 'Sending',
+                      url: baseURL + '/Roo/cohead',
+                      method : 'POST',
+                      params :  p,
+                      success : function()
+                      {
+                          _this.callback();
+                           if ( _this.data.cohead_status == 'X') {
+                            _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
+                    
+                              return;
+                           }
+          
+           
+                          _this.dialog.hide();
+                      }
+                 });
+             }
+          
+            
+             if (_this.data.cohead_status == 'X') {
+                  p._unvoid = 1;
+                  call();
+                  return;
+              }
+              
+              Roo.MessageBox.confirm("Confirm", "Are you sure you want to void this?", function(r) {
+              
+                  if (r !='yes') {
+                      return;
+                  }
+                  p._void = 1;
+                  call();       
+          
+                
+              });
+          
+          },
+         render : function (_self, e)
+          {
+              _this.voidBtn = _self;
+          }
+        }
+       },
+       {
+        text : _this._strings['07ca5050e697392c9ed47e6453f1453f'] /* Completed */,
+        xns : Roo.Toolbar,
+        '|xns' : 'Roo.Toolbar',
+        xtype : 'Button',
+        listeners : {
+         click : function (_self, e)
+          {
+              var p = {          cohead_id : _this.form.findField('cohead_id').getValue() };
+              
+              var close = 1;
+              if (_this.data.cohead_status == 'C') {
+                  p._reopen = 1;
+                  close = 0;
+                  } else {
+                          p._close = 1;
+                  }
+                  
+             new Pman.Request({
+              url: baseURL + '/Roo/cohead',
+              method : 'POST',
+              params :  p,
+              mask : 'Sending',
+              success : function()
+              {
+                     _this.callback();
+                    if (!close) {
+                      _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
+                    
+                      return;
+                    }
+                 
+                  _this.dialog.hide();
+              }
+             });
+              
+          },
+         render : function (_self)
+          {
+             _this.closeBtn = _self;
+          }
+        }
+       }
+      ]
+     }
     },
-
-    create : function()
-    {
-        var _this = this;
-        this.dialog = Roo.factory({
-            center : {
-                toolbar : {
-                    '|xns' : 'Roo',
-                    xtype : 'Toolbar',
-                    xns : Roo,
-                    items : [
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            xtype : 'Fill',
-                            xns : Roo.Toolbar
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Download Excel",
-                            xtype : 'Button',
-                            cls : 'x-btn-text-icon',
-                            icon : rootURL + '/Pman/templates/images/spreadsheet.gif',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               click : function ()
-                                  {
-                                      var id = 1* _this.form.findField('cohead_id').getValue();
-                                      if (!id) {
-                                          Roo.MessageBox.alert("Error", "Save Sales order first");
-                                          return;
-                                      
-                                      }
-                                      // check current status of shipment..
-                                  
-                                          new Pman.Download({
-                                              url : baseURL + '/Roo/cohead',
-                                              method : 'GET',
-                                              params : {
-                                                  cohead_id :  id,
-                                                  _excel : 1
-                                              },
-                                              success : function() {
-                                  
-                                              }
-                                          })
-                                              
-                                              
-                                     
-                                  }
-                            }
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Print",
-                            xtype : 'Button',
-                            cls : 'x-btn-text-icon',
-                            icon : rootURL + '/Pman/templates/images/pdf.gif',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               click : function ()
-                                  {
-                                      var id = 1* _this.form.findField('cohead_id').getValue();
-                                      if (!id) {
-                                          Roo.MessageBox.alert("Error", "Save Sales order first");
-                                          return;
-                                      
-                                      }
-                                      // check current status of shipment..
-                                  
-                                          new Pman.Download({
-                                              url : baseURL + '/Roo/cohead',
-                                              method : 'GET',
-                                              params : {
-                                                  cohead_id :  id,
-                                                  _print : 1
-                                              },
-                                              success : function() {
-                                  
-                                              }
-                                          })
-                                              
-                                              
-                                     
-                                  }
-                            }
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Add Shipment",
-                            hidden : true,
-                            xtype : 'Button',
-                            cls : 'x-btn-text-icon',
-                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               click : function (_self, e)
-                                  {
-                                  
-                                      _this.addShipmentBtn.fireEvent('click');
-                                     
-                                  }
-                            }
+    buttons : [
+     {
+      text : _this._strings['511b6a78f5503881ba10ff93b7205ade'] /* Create CM reversal */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'Button',
+      listeners : {
+       click : function (_self, e)
+        {
+            var id = _this.form.findField('cohead_id').getValue() * 1;
+            
+            if(id < 1){
+                Roo.MessageBox.alert('Error', 'Error occour on getting the sales order id');
+                return;
+            }
+        
+            Roo.MessageBox.confirm("Confirm", "Are you sure to create a credit memo reversal?",
+                function (res) {
+                    if(res!='yes') {
+                        return;
+                    
+                    }
+                    new Pman.Request({
+                        method: 'POST',
+                        url: baseURL+ '/Roo/cohead',
+                        params : {
+                            cohead_id : id,
+                            _cm_reversal : 1
                         },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Edit Customer",
-                            xtype : 'Button',
-                            cls : 'x-btn-text-icon',
-                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               click : function (_self, e)
-                                  {
-                                  
-                                     Pman.Dialog.XtupleCustomer.show({
-                                           cust_id : _this.form.findField('cohead_cust_id').getValue()
-                                    }); 
-                                  }
-                            }
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Add Invoice",
-                            hidden : true,
-                            xtype : 'Button',
-                            cls : 'x-btn-text-icon',
-                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               click : function (_self, e)
-                                  {
-                                  
-                                          _this.addInvoiceBtn.fireEvent('click');
-                                     
-                                  }
-                            }
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Void",
-                            xtype : 'Button',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               render : function (_self, e)
-                                  {
-                                      _this.voidBtn = _self;
-                                  },
-                               click : function (_self, e)
-                                  {
-                                       var p = {         
-                                           cohead_id : _this.form.findField('cohead_id').getValue() 
-                                       };
-                                      function call() {
-                                  
-                                              
-                                         new Pman.Request({
-                                              mask : 'Sending',
-                                              url: baseURL + '/Roo/cohead',
-                                              method : 'POST',
-                                              params :  p,
-                                              success : function()
-                                              {
-                                                  _this.callback();
-                                                   if ( _this.data.cohead_status == 'X') {
-                                                    _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
-                                            
-                                                      return;
-                                                   }
-                                  
-                                   
-                                                  _this.dialog.hide();
-                                              }
-                                         });
-                                     }
-                                  
-                                    
-                                     if (_this.data.cohead_status == 'X') {
-                                          p._unvoid = 1;
-                                          call();
-                                          return;
-                                      }
-                                      
-                                      Roo.MessageBox.confirm("Confirm", "Are you sure you want to void this?", function(r) {
-                                      
-                                          if (r !='yes') {
-                                              return;
-                                          }
-                                          p._void = 1;
-                                          call();       
-                                  
-                                        
-                                      });
-                                  
-                                  }
-                            }
-                        },
-                       {
-                            '|xns' : 'Roo.Toolbar',
-                            text : "Completed",
-                            xtype : 'Button',
-                            xns : Roo.Toolbar,
-                            listeners : {
-                               render : function (_self)
-                                  {
-                                     _this.closeBtn = _self;
-                                  },
-                               click : function (_self, e)
-                                  {
-                                      var p = {          cohead_id : _this.form.findField('cohead_id').getValue() };
-                                      
-                                      var close = 1;
-                                      if (_this.data.cohead_status == 'C') {
-                                          p._reopen = 1;
-                                          close = 0;
-                                          } else {
-                                                  p._close = 1;
-                                          }
-                                          
-                                     new Pman.Request({
-                                      url: baseURL + '/Roo/cohead',
-                                      method : 'POST',
-                                      params :  p,
-                                      mask : 'Sending',
-                                      success : function()
-                                      {
-                                             _this.callback();
-                                            if (!close) {
-                                              _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
-                                            
-                                              return;
-                                            }
-                                         
-                                          _this.dialog.hide();
-                                      }
-                                     });
-                                      
-                                  }
-                            }
+                        success : function() {
+                            _this.form.load({ method: 'GET', params: { '_id' : id }});
                         }
-                    ]
-
+                    });
+            }); 
+              
+        },
+       render : function (_self)
+        {
+            _this.reversalBtn = _self;
+        }
+      }
+     },
+     {
+      text : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'Button',
+      listeners : {
+       click : function (_self, e)
+        {
+              if (_this.grid)  _this.grid.stopEditing();
+            _this.dialog.hide();
+        }
+      }
+     },
+     {
+      text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'Button',
+      listeners : {
+       click : function (_self, e)
+        {
+            // do some checks?
+             
+              if (_this.grid)  _this.grid.stopEditing();
+         
+            _this.form.doAction("submit");
+        
+        },
+       render : function (_self)
+        {
+            _this.saveBtn = _self;
+        }
+      }
+     }
+    ],
+    items  : [
+     {
+      region : 'center',
+      title : _this._strings['c5c8ac6bbc6d7f5c95d0a888527554d3'] /* Order Details */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'ContentPanel',
+      listeners : {
+       activate : function (_self)
+        {
+            // we need to reload to find out the subtotal.
+            if (!_this.data || !_this.data.cohead_id) {
+                return;
+            }
+            new Pman.Request({
+                method : 'GET',
+                url : baseURL + '/Roo/cohead',
+                params : { 
+                    _id : _this.data.cohead_id
                 },
-                '|xns' : 'Roo',
-                alwaysShowTabs : true,
-                xtype : 'LayoutRegion',
-                xns : Roo,
-                tabPosition : 'top',
-                items : [
-
+                success : function(res) {
+                    _this.form.findField('cohead_subtotal').setValue(res.data.cohead_subtotal);
+                    _this.form.findField('cohead_tax').setValue(res.data.cohead_tax);
+                    _this.form.findField('cohead_uninvoiced').setValue(res.data.cohead_uninvoiced);
+                    _this.form.findField('cohead_unshipped').setValue(res.data.cohead_unshipped);
+                   _this.form.findField('cohead_pretax_discount').setValue(res.data.cohead_pretax_discount); 
+                    _this.form.findField('cohead_total').recalc(); 
+                    _this.form.findField('cohead_misc').recalc(); 
+                }
+            });
+        }
+      },
+      items  : [
+       {
+        method : 'POST',
+        style : 'margin:10px;',
+        url : baseURL + '/Roo/cohead.php',
+        xns : Roo.form,
+        '|xns' : 'Roo.form',
+        xtype : 'Form',
+        listeners : {
+         actioncomplete : function(_self,action)
+          {
+              if (action.type == 'setdata') {
+                  // clear the stock level cache...
+                  _this.stockcache = [];
+                  
+                  _this.form.findField('billto_email').setValue('');
+                  
+                  _this.reversalBtn.hide();
+                  
+                  if (_this.data.cohead_id) {
+                     this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
+                     
+                     return;
+                  }
+                  _this.dialog.setTitle("Edit New Sales Order");
+                 
+                  _this.closeBtn.hide();
+                  _this.voidBtn.hide();
+                  _this.saveBtn.show();
+                      
+                  if(_this.data.cohead_billto_cntct_id_cntct_id){
+                      _this.form.findField('billto_address').update();
+                      \r
+                      _this.form.setValues({\r
+                          cohead_billto_cntct_id: _this.data.cohead_billto_cntct_id_cntct_id,\r
+                          cohead_billto_cntct_id_cntct_name : _this.data.cohead_billto_cntct_id_cntct_name,\r
+                          _shipto_same : 1,
+                          _same_as_order : 1
+                          \r
+                      }); \r
+                  }
+                   
+                 return;
+              }
+              if (action.type == 'load') {
+                   
+                  
+                  _this.data = action.result.data;
+          
+                  if (!_this.data.cohead_shipto_id && _this.data.shipto_id*1 > 0) {
+                      _this.form.findField('cohead_shipto_id').setValue(_this.data.shipto_id);
+                      _this.form.findField('cohead_shipto_id_shipto_name').setValue(_this.data.cohead_shipto_cntct_id_cntct_name);
+                  
+                  }
+                  
+                  
+                  _this.dataloading = true;
+                  if (_this.data.cohead_shipto_cntct_id == _this.data.cohead_billto_cntct_id) {
+                      this.findField('_shipto_same').setValue(1);
+                        Roo.log("set shipto 1");
+                  } else {
+                    this.findField('_shipto_same').setValue(0);
+                     Roo.log("set shipto 0");
+                  }
+                  _this.dataloading = false;          
+                  
+                  
+                  this.findField('billto_address').update();
+                  this.findField('shipto_address').update();        
+                  _this.dialog.setTitle("Edit Sales Order - " + this.findField('cohead_number').getValue());
+                   
+                  
+                  if (_this.data.cohead_status == 'C') {
+                      _this.closeBtn.show();
+                      _this.closeBtn.setText('Re-open');
+                       _this.voidBtn.hide();
+                       _this.saveBtn.hide();
+                       _this.reversalBtn.show();
+                  }  else  if (_this.data.cohead_status == 'X') {
+                      _this.closeBtn.hide(); 
+                       _this.voidBtn.show(); 
+                       _this.voidBtn.setText("Un-void / Re-open"); 
+                       _this.saveBtn.hide();
+                  } else {
+                      // it's open
+                       _this.closeBtn.show(); 
+                      _this.closeBtn.setText('Complete and Close');             
+                       _this.voidBtn.setText("Void");             
+                       _this.voidBtn.show(); 
+                       _this.saveBtn.show();        
+                  }
+                  
+                   _this.form.findField('cohead_misc_per').update();
+                 
+                 // finally override the value for discount...
+                 if ((''+ _this.data.cohead_misc_descrip).length) {
+                      _this.form.findField('cohead_misc_descrip').setValue(_this.data.cohead_misc_descrip);
+                 }
+                 
+                 // update the stockcache...
+          
+                 new Pman.Request({
+                      url : baseURL + '/Roo/cohead',
+                      method : 'GET',
+                      params : {
+                          _stockLevel : _this.data.cohead_id
+                      },
+                      success : function(res) 
+                      {
+                          for (var i in res.data) {
+                             
+                              if(typeof(_this.stockcache[res.data[i].item]) == 'undefined'){
+                                  _this.stockcache[res.data[i].item] = res.data[i];
+                              }
+                          }
+                      }
+                  });
+                 
+                  return;
+              }
+              if (action.type =='submit') {
+              
+          
+                  var id = _this.form.findField('cohead_id').getValue() * 1;
+                  if (id < 1) {
+          
+                      _this.data.cohead_id = action.result.data.cohead_id;
+                       this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
+                      return;
+                  }
+              
+                  _this.dialog.hide();
+              
+                   if (_this.callback) {
+                      _this.callback.call(_this, _this.form.getValues());
+                   }
+                   _this.form.reset();
+                   return;
+              }
+          },
+         actionfailed : function (_self, action)
+          {
+              if (action.failureType == 'client') {
+                  Roo.MessageBox.alert("Error", "Fill in all the required fields");
+              }
+              if (action.failureType == 'server') {    
+                  Roo.log(action);
+                  Roo.MessageBox.alert("Error", action.result.errorMsg);
+              }
+              _this.dialog.layout.getRegion('center').showPanel(0);
+          },
+         rendered : function (form)
+          {
+              _this.form= form;
+          }
+        },
+        items  : [
+         {
+          width : 435,
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Column',
+          items  : [
+           {
+            labelWidth : 120,
+            legend : _this._strings['a240fa27925a635b08dc28c9e4f9216d'] /* Order */,
+            style : 'width:420px',
+            xns : Roo.form,
+            '|xns' : 'Roo.form',
+            xtype : 'FieldSet',
+            items  : [
+             {
+              labelWidth : 100,
+              width : 410,
+              xns : Roo.form,
+              '|xns' : 'Roo.form',
+              xtype : 'Column',
+              items  : [
+               {
+                labelWidth : 100,
+                width : 400,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  allowBlank : true,
+                  emptyText : _this._strings['086247a9b57fde6eefee2a0c4752242d'] /* Automatic */,
+                  fieldLabel : _this._strings['3ffaf70863d6f46e2719050a37d9ef86'] /* Order# */,
+                  name : 'cohead_number',
+                  readOnly : true,
+                  width : 120,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'TextField'
+                 },
+                 {
+                  labelWidth : 50,
+                  style : 'float:left',
+                  width : 150,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'Row',
+                  items  : [
+                   {
+                    allowBlank : true,
+                    fieldLabel : _this._strings['6a813cbab5d0c9d33b1a471839935d88'] /* Cust# */,
+                    name : 'cohead_cust_id_cust_number',
+                    readOnly : true,
+                    width : 110,
+                    xns : Roo.form,
+                    '|xns' : 'Roo.form',
+                    xtype : 'TextField'
+                   }
+                  ]
+                 }
                 ]
-
-            },
-            '|xns' : 'Roo',
-            modal : true,
-            collapsible : false,
-            title : "Edit / Create Sales Order",
-            xtype : 'LayoutDialog',
-            width : 1050,
-            xns : Roo,
-            closable : true,
-            resizable : true,
-            height : 620,
-            buttons : [
-                {
-                       '|xns' : 'Roo',
-                       text : "Create CM reversal",
-                       xtype : 'Button',
-                       xns : Roo,
-                       listeners : {
-                               render : function (_self)
-                                  {
-                                      _this.reversalBtn = _self;
-                                  },
-                               click : function (_self, e)
-                                  {
-                                      var id = _this.form.findField('cohead_id').getValue() * 1;
-                                      
-                                      if(id < 1){
-                                          Roo.MessageBox.alert('Error', 'Error occour on getting the sales order id');
-                                          return;
-                                      }
-                                  
-                                      Roo.MessageBox.confirm("Confirm", "Are you sure to create a credit memo reversal?",
-                                          function (res) {
-                                              if(res!='yes') {
-                                                  return;
-                                              
-                                              }
-                                              new Pman.Request({
-                                                  method: 'POST',
-                                                  url: baseURL+ '/Roo/cohead',
-                                                  params : {
-                                                      cohead_id : id,
-                                                      _cm_reversal : 1
-                                                  },
-                                                  success : function() {
-                                                      _this.form.load({ method: 'GET', params: { '_id' : id }});
-                                                  }
-                                              });
-                                      }); 
-                                        
-                                  }
-                       }
-                   },
-{
-                       '|xns' : 'Roo',
-                       text : "Cancel",
-                       xtype : 'Button',
-                       xns : Roo,
-                       listeners : {
-                               click : function (_self, e)
-                                  {
-                                        if (_this.grid)  _this.grid.stopEditing();
-                                      _this.dialog.hide();
-                                  }
-                       }
-                   },
-{
-                       '|xns' : 'Roo',
-                       text : "Save",
-                       xtype : 'Button',
-                       xns : Roo,
-                       listeners : {
-                               render : function (_self)
-                                  {
-                                      _this.saveBtn = _self;
-                                  },
-                               click : function (_self, e)
-                                  {
-                                      // do some checks?
-                                       
-                                        if (_this.grid)  _this.grid.stopEditing();
-                                   
-                                      _this.form.doAction("submit");
-                                  
-                                  }
-                       }
-                   }
-            ],
-            listeners : {
-               show : function () {
-                         this.layout.getRegion('center').showPanel(0);
-                  }
-            },
-            items : [
-               {
-                    '|xns' : 'Roo',
-                    region : 'center',
-                    xtype : 'ContentPanel',
-                    title : "Order Details",
-                    xns : Roo,
+               },
+               {
+                editable : false,
+                fieldLabel : _this._strings['ce26601dac0dea138b7295f02b7620a7'] /* Customer */,
+                forceSelection : true,
+                hiddenName : 'cohead_cust_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_cust_id_cust_name',
+                pageSize : 20,
+                qtip : _this._strings['fce6d3795b41b54dc0dab82df50517c1'] /* Select custinfo */,
+                queryParam : 'query[cust_name]',
+                readOnly : true,
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'cust_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextField'
+               },
+               {
+                fieldLabel : _this._strings['986b90fb419e5349dd59b691b0e0e9f6'] /* Customer PO# */,
+                name : 'cohead_custponumber',
+                width : 150,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextField'
+               },
+               {
+                allowBlank : false,
+                fieldLabel : _this._strings['26e09a1ee1517389c7b07f42df65561a'] /* Ordered */,
+                format : 'Y-m-d',
+                name : 'cohead_orderdate',
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'DateField'
+               },
+               {
+                labelWidth : 100,
+                width : 500,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  allowBlank : false,
+                  fieldLabel : _this._strings['a2fdeac60e3c5b6c51a92e027fb9d533'] /* Target Delivery */,
+                  format : 'Y-m-d',
+                  name : 'cohead_targetdate',
+                  width : 100,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'DateField'
+                 },
+                 {
+                  hideLabels : true,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'Row',
+                  items  : [
+                   {
+                    boxLabel : 'same as order',
+                    inputValue : 1,
+                    name : '_same_as_order',
+                    xns : Roo.form,
+                    '|xns' : 'Roo.form',
+                    xtype : 'Checkbox',
                     listeners : {
-                       activate : function (_self)
-                          {
-                              // we need to reload to find out the subtotal.
-                              if (!_this.data || !_this.data.cohead_id) {
-                                  return;
-                              }
-                              new Pman.Request({
-                                  method : 'GET',
-                                  url : baseURL + '/Roo/cohead',
-                                  params : { 
-                                      _id : _this.data.cohead_id
-                                  },
-                                  success : function(res) {
-                                      _this.form.findField('cohead_subtotal').setValue(res.data.cohead_subtotal);
-                                      _this.form.findField('cohead_tax').setValue(res.data.cohead_tax);
-                                      _this.form.findField('cohead_uninvoiced').setValue(res.data.cohead_uninvoiced);
-                                      _this.form.findField('cohead_unshipped').setValue(res.data.cohead_unshipped);
-                                     _this.form.findField('cohead_pretax_discount').setValue(res.data.cohead_pretax_discount); 
-                                      _this.form.findField('cohead_total').recalc(); 
-                                      _this.form.findField('cohead_misc').recalc(); 
-                                  }
-                              });
-                          }
-                    },
-                    items : [
-                       {
-                            '|xns' : 'Roo.form',
-                            url : baseURL + '/Roo/cohead.php',
-                            xtype : 'Form',
-                            method : 'POST',
-                            style : 'margin:10px;',
-                            xns : Roo.form,
-                            listeners : {
-                               actionfailed : function (_self, action)
-                                  {
-                                      if (action.failureType == 'client') {
-                                          Roo.MessageBox.alert("Error", "Fill in all the required fields");
-                                      }
-                                      if (action.failureType == 'server') {    
-                                          Roo.log(action);
-                                          Roo.MessageBox.alert("Error", action.result.errorMsg);
-                                      }
-                                      _this.dialog.layout.getRegion('center').showPanel(0);
-                                  },
-                               actioncomplete : function(_self,action)
-                                  {
-                                      if (action.type == 'setdata') {
-                                          // clear the stock level cache...
-                                          _this.stockcache = [];
-                                          
-                                          _this.form.findField('billto_email').setValue('');
-                                          
-                                          _this.reversalBtn.hide();
-                                          
-                                          if (_this.data.cohead_id) {
-                                             this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
-                                             
-                                             return;
-                                          }
-                                          _this.dialog.setTitle("Edit New Sales Order");
-                                         
-                                          _this.closeBtn.hide();
-                                          _this.voidBtn.hide();
-                                          _this.saveBtn.show();
-                                              
-                                          if(_this.data.cohead_billto_cntct_id_cntct_id){
-                                              _this.form.findField('billto_address').update();
-                                              \r
-                                              _this.form.setValues({\r
-                                                  cohead_billto_cntct_id: _this.data.cohead_billto_cntct_id_cntct_id,\r
-                                                  cohead_billto_cntct_id_cntct_name : _this.data.cohead_billto_cntct_id_cntct_name,\r
-                                                  _shipto_same : 1,
-                                                  _same_as_order : 1
-                                                  \r
-                                              }); \r
-                                          }
-                                           
-                                         return;
-                                      }
-                                      if (action.type == 'load') {
-                                           
-                                          
-                                          _this.data = action.result.data;
-                                  
-                                          if (!_this.data.cohead_shipto_id && _this.data.shipto_id*1 > 0) {
-                                              _this.form.findField('cohead_shipto_id').setValue(_this.data.shipto_id);
-                                              _this.form.findField('cohead_shipto_id_shipto_name').setValue(_this.data.cohead_shipto_cntct_id_cntct_name);
-                                          
-                                          }
-                                          
-                                          
-                                          _this.dataloading = true;
-                                          if (_this.data.cohead_shipto_cntct_id == _this.data.cohead_billto_cntct_id) {
-                                              this.findField('_shipto_same').setValue(1);
-                                                Roo.log("set shipto 1");
-                                          } else {
-                                            this.findField('_shipto_same').setValue(0);
-                                             Roo.log("set shipto 0");
-                                          }
-                                          _this.dataloading = false;          
-                                          
-                                          
-                                          this.findField('billto_address').update();
-                                          this.findField('shipto_address').update();        
-                                          _this.dialog.setTitle("Edit Sales Order - " + this.findField('cohead_number').getValue());
-                                           
-                                          
-                                          if (_this.data.cohead_status == 'C') {
-                                              _this.closeBtn.show();
-                                              _this.closeBtn.setText('Re-open');
-                                               _this.voidBtn.hide();
-                                               _this.saveBtn.hide();
-                                               _this.reversalBtn.show();
-                                          }  else  if (_this.data.cohead_status == 'X') {
-                                              _this.closeBtn.hide(); 
-                                               _this.voidBtn.show(); 
-                                               _this.voidBtn.setText("Un-void / Re-open"); 
-                                               _this.saveBtn.hide();
-                                          } else {
-                                              // it's open
-                                               _this.closeBtn.show(); 
-                                              _this.closeBtn.setText('Complete and Close');             
-                                               _this.voidBtn.setText("Void");             
-                                               _this.voidBtn.show(); 
-                                               _this.saveBtn.show();        
-                                          }
-                                          
-                                           _this.form.findField('cohead_misc_per').update();
-                                         
-                                         // finally override the value for discount...
-                                         if ((''+ _this.data.cohead_misc_descrip).length) {
-                                              _this.form.findField('cohead_misc_descrip').setValue(_this.data.cohead_misc_descrip);
-                                         }
-                                         
-                                         // update the stockcache...
-                                  
-                                         new Pman.Request({
-                                              url : baseURL + '/Roo/cohead',
-                                              method : 'GET',
-                                              params : {
-                                                  _stockLevel : _this.data.cohead_id
-                                              },
-                                              success : function(res) 
-                                              {
-                                                  for (var i in res.data) {
-                                                     
-                                                      if(typeof(_this.stockcache[res.data[i].item]) == 'undefined'){
-                                                          _this.stockcache[res.data[i].item] = res.data[i];
-                                                      }
-                                                  }
-                                              }
-                                          });
-                                         
-                                          return;
-                                      }
-                                      if (action.type =='submit') {
-                                      
-                                  
-                                          var id = _this.form.findField('cohead_id').getValue() * 1;
-                                          if (id < 1) {
-                                  
-                                              _this.data.cohead_id = action.result.data.cohead_id;
-                                               this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
-                                              return;
-                                          }
-                                      
-                                          _this.dialog.hide();
-                                      
-                                           if (_this.callback) {
-                                              _this.callback.call(_this, _this.form.getValues());
-                                           }
-                                           _this.form.reset();
-                                           return;
-                                      }
-                                  },
-                               rendered : function (form)
-                                  {
-                                      _this.form= form;
-                                  }
-                            },
-                            items : [
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Column',
-                                    width : 435,
-                                    xns : Roo.form,
-                                    items : [
-                                       {
-                                            '|xns' : 'Roo.form',
-                                            style : 'width:420px',
-                                            legend : "Order",
-                                            xtype : 'FieldSet',
-                                            labelWidth : 120,
-                                            xns : Roo.form,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.form',
-                                                    xtype : 'Column',
-                                                    labelWidth : 100,
-                                                    width : 410,
-                                                    xns : Roo.form,
-                                                    items : [
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            xtype : 'Row',
-                                                            labelWidth : 100,
-                                                            width : 400,
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : 'Order#',
-                                                                    emptyText : "Automatic",
-                                                                    xtype : 'TextField',
-                                                                    allowBlank : true,
-                                                                    readOnly : true,
-                                                                    width : 120,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_number'
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    style : 'float:left',
-                                                                    xtype : 'Row',
-                                                                    labelWidth : 50,
-                                                                    width : 150,
-                                                                    xns : Roo.form,
-                                                                    items : [
-                                                                       {
-                                                                            '|xns' : 'Roo.form',
-                                                                            fieldLabel : 'Cust#',
-                                                                            xtype : 'TextField',
-                                                                            allowBlank : true,
-                                                                            readOnly : true,
-                                                                            width : 110,
-                                                                            xns : Roo.form,
-                                                                            name : 'cohead_cust_id_cust_number'
-                                                                        }
-                                                                    ]
-
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            forceSelection : true,
-                                                            fieldLabel : 'Customer',
-                                                            selectOnFocus : true,
-                                                            pageSize : 20,
-                                                            hiddenName : 'cohead_cust_id',
-                                                            minChars : 2,
-                                                            valueField : 'cust_id',
-                                                            xtype : 'TextField',
-                                                            readOnly : true,
-                                                            typeAhead : true,
-                                                            editable : false,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_cust_id_cust_name',
-                                                            qtip : "Select custinfo",
-                                                            queryParam : 'query[cust_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>',
-                                                            loadingText : "Searching..."
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Customer PO#',
-                                                            xtype : 'TextField',
-                                                            xns : Roo.form,
-                                                            width : 150,
-                                                            name : 'cohead_custponumber'
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            format : 'Y-m-d',
-                                                            fieldLabel : 'Ordered',
-                                                            xtype : 'DateField',
-                                                            allowBlank : false,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_orderdate'
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            xtype : 'Row',
-                                                            labelWidth : 100,
-                                                            width : 500,
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    format : 'Y-m-d',
-                                                                    fieldLabel : 'Target Delivery',
-                                                                    xtype : 'DateField',
-                                                                    allowBlank : false,
-                                                                    width : 100,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_targetdate'
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    hideLabels : true,
-                                                                    xtype : 'Row',
-                                                                    xns : Roo.form,
-                                                                    items : [
-                                                                       {
-                                                                            '|xns' : 'Roo.form',
-                                                                            inputValue : 1,
-                                                                            xtype : 'Checkbox',
-                                                                            boxLabel : 'same as order',
-                                                                            xns : Roo.form,
-                                                                            name : '_same_as_order',
-                                                                            listeners : {
-                                                                               check : function (_self, checked)
-                                                                                  {
-                                                                                      if(checked){
-                                                                                          _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());
-                                                                                      }
-                                                                                  }
-                                                                            }
-                                                                        }
-                                                                    ]
-
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/location.php',
-                                                                    xtype : 'HttpProxy',
-                                                                    method : 'GET',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'location_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    fields : [{"name":"location_id","type":"int"},"location_name"],
-                                                                    xns : Roo.data,
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'location_name' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                               o.params.location_netable = 1;
-                                                                                o.params.location_restrict = 0;
-                                                                                o.params._notinternalcompany = 1;
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            fieldLabel : 'Supply From',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            pageSize : 200,
-                                                            displayField : 'location_name',
-                                                            emptyText : "Supply From",
-                                                            hiddenName : 'cohead_location_src',
-                                                            minChars : 2,
-                                                            valueField : 'location_id',
-                                                            xtype : 'ComboBox',
-                                                            allowBlank : false,
-                                                            typeAhead : false,
-                                                            editable : true,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_location_src_location_name',
-                                                            qtip : "Select terms",
-                                                            queryParam : 'query[location_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>',
-                                                            loadingText : "Searching...",
-                                                            items : [
-
-                                                            ]
-
-                                                        }
-                                                    ]
-
-                                                }
-                                            ]
-
-                                        },
-                                       {
-                                            '|xns' : 'Roo.form',
-                                            style : 'width:420px',
-                                            legend : "Details",
-                                            xtype : 'FieldSet',
-                                            labelWidth : 100,
-                                            xns : Roo.form,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.form',
-                                                    xtype : 'Column',
-                                                    labelWidth : 100,
-                                                    width : 420,
-                                                    xns : Roo.form,
-                                                    items : [
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/terms.php',
-                                                                    method : 'GET',
-                                                                    xtype : 'HttpProxy',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'terms_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    xns : Roo.data,
-                                                                    fields : [{"name":"terms_id","type":"int"},"terms_descrip"],
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'terms_descrip' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            fieldLabel : 'Terms',
-                                                            pageSize : 20,
-                                                            xtype : 'ComboBox',
-                                                            emptyText : "Select terms",
-                                                            minChars : 2,
-                                                            valueField : 'terms_id',
-                                                            displayField : 'terms_descrip',
-                                                            hiddenName : 'cohead_terms_id',
-                                                            allowBlank : false,
-                                                            typeAhead : true,
-                                                            editable : false,
-                                                            xns : Roo.form,
-                                                            width : 300,
-                                                            qtip : "Select terms",
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>',
-                                                            queryParam : 'query[terms_descrip]',
-                                                            name : 'cohead_terms_id_terms_descrip',
-                                                            loadingText : "Searching...",
-                                                            items : [
-
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/salesrep.php',
-                                                                    method : 'GET',
-                                                                    xtype : 'HttpProxy',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'salesrep_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    xns : Roo.data,
-                                                                    fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'salesrep_name' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            alwaysQuery : true,
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            fieldLabel : 'Sales Rep',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            pageSize : 80,
-                                                            displayField : 'salesrep_name',
-                                                            emptyText : "Select salesrep",
-                                                            hiddenName : 'cohead_display_salesrep_id',
-                                                            minChars : 2,
-                                                            valueField : 'salesrep_id',
-                                                            xtype : 'ComboBox',
-                                                            allowBlank : true,
-                                                            typeAhead : true,
-                                                            editable : false,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_display_salesrep_id_salesrep_name',
-                                                            qtip : "Select salesrep",
-                                                            queryParam : 'query[salesrep_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
-                                                            loadingText : "Searching...",
-                                                            items : [
-
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/salesrep.php',
-                                                                    method : 'GET',
-                                                                    xtype : 'HttpProxy',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'salesrep_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    xns : Roo.data,
-                                                                    fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'salesrep_name' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            alwaysQuery : true,
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            fieldLabel : 'Staff I.C.',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            pageSize : 80,
-                                                            displayField : 'salesrep_name',
-                                                            emptyText : "Select Staff",
-                                                            hiddenName : 'cohead_salesrep_id',
-                                                            minChars : 2,
-                                                            valueField : 'salesrep_id',
-                                                            xtype : 'ComboBox',
-                                                            allowBlank : false,
-                                                            typeAhead : true,
-                                                            editable : false,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_salesrep_id_salesrep_name',
-                                                            qtip : "Select salesrep",
-                                                            queryParam : 'query[salesrep_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
-                                                            loadingText : "Searching...",
-                                                            items : [
-
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Order Comments',
-                                                            xtype : 'TextArea',
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_ordercomments',
-                                                            height : 80
-                                                        }
-                                                    ]
-
-                                                }
-                                            ]
-
-                                        },
-                                       {
-                                            '|xns' : 'Roo.form',
-                                            style : 'width:420px',
-                                            xtype : 'FieldSet',
-                                            legend : "Billing",
-                                            xns : Roo.form,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.form',
-                                                    xtype : 'Column',
-                                                    labelWidth : 50,
-                                                    width : 420,
-                                                    xns : Roo.form,
-                                                    items : [
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/cntct.php',
-                                                                    method : 'GET',
-                                                                    xtype : 'HttpProxy',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'cntct_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    xns : Roo.data,
-                                                                    fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'cntct_name' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                              o.params._customer_id = _this.data.cohead_cust_id;
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            alwaysQuery : true,
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            fieldLabel : 'Bill To (select)',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            pageSize : 20,
-                                                            displayField : 'cntct_name',
-                                                            emptyText : "Select cntct",
-                                                            hiddenName : 'cohead_billto_cntct_id',
-                                                            minChars : 2,
-                                                            valueField : 'cntct_id',
-                                                            xtype : 'ComboBox',
-                                                            allowBlank : false,
-                                                            typeAhead : true,
-                                                            editable : true,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_billto_cntct_id_cntct_name',
-                                                            qtip : "Select cntct",
-                                                            queryParam : 'query[cntct_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
-                                                            loadingText : "Searching...",
-                                                            listeners : {
-                                                               add : function (combo)
-                                                                  {
-                                                                    
-                                                                    Pman.Dialog.XtupleQuickContact.show( 
-                                                                              {
-                                                                                _id : id,
-                                                                                customer_id : _this.form.findField('cohead_cust_id').getValue()
-                                                                              },
-                                                                              
-                                                                              function (data) {
-                                                                                 
-                                                                                  for(var i in  data) {
-                                                                                      
-                                                                                      _this.data['cohead_billto_cntct_id_' + i] =  data[i];
-                                                                                  }
-                                                                                  
-                                                                                  _this.form.findField('billto_address').update();
-                                                                                  // fill in the select box..
-                                                                                  _this.form.setValues( {
-                                                                                      cohead_billto_cntct_id : data.cntct_id,
-                                                                                      cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
-                                                                                              data.cntct_last_name
-                                                                                      
-                                                                                  });
-                                                                              }
-                                                                          );
-                                                                          //  Pman.Dialog.XtupleCustomer.show(
-                                                                              //{ cust_id : _this.form.findField('cohead_cust_id').getValue() }, 
-                                                                              //function(data) {
-                                                                          // refresh the data in the pulldown..
-                                                                      //    }); 
-                                                                  
-                                                                  },
-                                                               beforeselect : function (combo, record, index)
-                                                                  {
-                                                                      // set _this.data values ..
-                                                                  
-                                                                      // just add everything...
-                                                                      for(var i in record.data) {
-                                                                          _this.data['cohead_billto_cntct_id_' + i] = record.data[i];
-                                                                      }
-                                                                      
-                                                                      _this.form.findField('billto_address').update();
-                                                                      
-                                                                      
-                                                                   
-                                                                  }
-                                                            },
-                                                            items : [
-
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'or enter Address',
-                                                            xtype : 'TextArea',
-                                                            update : function() {
-                                                            
-                                                                var c = ['first_name', 'last_name' ] ;
-                                                                var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
-                                                                var v = [];
-                                                                Roo.each(c, function(e) {
-                                                                    if (_this.data['cohead_billto_cntct_id_cntct_' +e].length) { 
-                                                                        v.push(_this.data['cohead_billto_cntct_id_cntct_' +e]);
-                                                                    }
-                                                                });
-                                                                Roo.each(a, function(e) {
-                                                                    if (_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
-                                                                        v.push(_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e]);
-                                                                    }
-                                                                });
-                                                            
-                                                                this.setValue(v.join("\n"));
-                                                                
-                                                                if(_this.data.cohead_billto_cntct_id_cntct_email.length){
-                                                                    _this.form.findField('billto_email').setValue(_this.data.cohead_billto_cntct_id_cntct_email);
-                                                                }
-                                                            },
-                                                            readOnly : true,
-                                                            xns : Roo.form,
-                                                            name : 'billto_address',
-                                                            listeners : {
-                                                               render : function (_self)
-                                                                  {
-                                                                     Roo.log(this.el)
-                                                                     
-                                                                     
-                                                                     
-                                                                     this.el.on('click', function() { 
-                                                                         var id = _this.form.findField('cohead_billto_cntct_id').getValue();
-                                                                          Pman.Dialog.XtupleQuickContact.show( 
-                                                                              {
-                                                                                _id : id,
-                                                                                customer_id : _this.form.findField('cohead_cust_id').getValue()
-                                                                              },
-                                                                              
-                                                                              function (data) {
-                                                                              
-                                                                                  for(var i in  data) {
-                                                                                      
-                                                                                      _this.data['cohead_billto_cntct_id_' + i] =  data[i];
-                                                                                  }
-                                                                                  
-                                                                                  _this.form.findField('billto_address').update();
-                                                                                  // fill in the select box..
-                                                                                  _this.form.setValues( {
-                                                                                      cohead_billto_cntct_id : data.cntct_id,
-                                                                                      cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
-                                                                                              data.cntct_last_name
-                                                                                      
-                                                                                  });
-                                                                                  
-                                                                                          
-                                                                                  Roo.log(data);
-                                                                              }
-                                                                          );
-                                                                     
-                                                                          Roo.log("Click text");
-                                                                          
-                                                                          
-                                                                       });
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Email',
-                                                            xtype : 'DisplayField',
-                                                            valueRenderer : function(v)
-                                                            {
-                                                             
-                                                                return v ? String.format('<a href="mailto:{0}" target="_blank">{0}</a>',v) : '';
-                                                            },
-                                                            xns : Roo.form,
-                                                            name : 'billto_email'
-                                                        }
-                                                    ]
-
-                                                }
-                                            ]
-
-                                        }
-                                    ]
-
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Column',
-                                    style : 'margin-left:10px',
-                                    width : 435,
-                                    xns : Roo.form,
-                                    items : [
-                                       {
-                                            '|xns' : 'Roo.form',
-                                            legend : "Price Details",
-                                            xtype : 'FieldSet',
-                                            style : 'width:420px',
-                                            labelWidth : 50,
-                                            xns : Roo.form,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.form',
-                                                    labelAlign : 'right',
-                                                    xtype : 'Column',
-                                                    labelWidth : 300,
-                                                    width : 420,
-                                                    xns : Roo.form,
-                                                    items : [
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            labelAlign : 'top',
-                                                            xtype : 'Row',
-                                                            labelSeparator : '&nbsp;',
-                                                            width : 500,
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    store : {
-                                                                        proxy : {
-                                                                            '|xns' : 'Roo.data',
-                                                                            url : baseURL + '/Roo/curr_symbol.php',
-                                                                            method : 'GET',
-                                                                            xtype : 'HttpProxy',
-                                                                            xns : Roo.data
-                                                                        },
-                                                                        reader : {
-                                                                            '|xns' : 'Roo.data',
-                                                                            id : 'curr_id',
-                                                                            root : 'data',
-                                                                            xtype : 'JsonReader',
-                                                                            xns : Roo.data,
-                                                                            fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
-                                                                            totalProperty : 'total'
-                                                                        },
-                                                                        '|xns' : 'Roo.data',
-                                                                        xtype : 'Store',
-                                                                        remoteSort : true,
-                                                                        sortInfo : { direction : 'ASC', field: 'curr_symbol' },
-                                                                        xns : Roo.data,
-                                                                        listeners : {
-                                                                               beforeload : function (_self, o){
-                                                                                      o.params = o.params || {};
-                                                                                      // set more here
-                                                                                     
-                                                                                  }
-                                                                        },
-                                                                        items : [
-
-                                                                        ]
-
-                                                                    },
-                                                                    '|xns' : 'Roo.form',
-                                                                    listWidth : 400,
-                                                                    triggerAction : 'all',
-                                                                    fieldLabel : 'Currency',
-                                                                    forceSelection : true,
-                                                                    selectOnFocus : true,
-                                                                    pageSize : 20,
-                                                                    displayField : 'curr_name',
-                                                                    emptyText : "Select curr_name",
-                                                                    hiddenName : 'cohead_curr_id',
-                                                                    minChars : 2,
-                                                                    valueField : 'curr_id',
-                                                                    xtype : 'ComboBox',
-                                                                    allowBlank : false,
-                                                                    typeAhead : true,
-                                                                    editable : false,
-                                                                    width : 285,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_curr_id_curr_name',
-                                                                    qtip : "Select Currency",
-                                                                    queryParam : 'query[curr_name]',
-                                                                    tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>',
-                                                                    loadingText : "Searching...",
-                                                                    listeners : {
-                                                                       beforequery : function (combo, query, forceAll, cancel, e)
-                                                                          {
-                                                                              Roo.log('beforequery');
-                                                                             
-                                                                              if (_this.form.findField('cohead_number').getValue().length) {
-                                                                                  Roo.MessageBox.alert("Error", "You can not change the currency of this order");
-                                                                                  if (query) {
-                                                                                      query.cancel = true;
-                                                                                  }
-                                                                                  return false;
-                                                                              }
-                                                                          }
-                                                                    },
-                                                                    items : [
-
-                                                                    ]
-
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : 'Products',
-                                                                    xtype : 'NumberField',
-                                                                    cls : 'roo-align-right',
-                                                                    readOnly : true,
-                                                                    allowDecimals : true,
-                                                                    decimalPrecision : 3,
-                                                                    width : 100,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_subtotal'
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            labelAlign : 'top',
-                                                            xtype : 'Row',
-                                                            labelSeparator : '&nbsp;',
-                                                            width : 500,
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    store : {
-                                                                        proxy : {
-                                                                            '|xns' : 'Roo.data',
-                                                                            url : baseURL + '/Roo/taxzone.php',
-                                                                            xtype : 'HttpProxy',
-                                                                            method : 'GET',
-                                                                            xns : Roo.data
-                                                                        },
-                                                                        reader : {
-                                                                            '|xns' : 'Roo.data',
-                                                                            id : 'taxzone_id',
-                                                                            root : 'data',
-                                                                            xtype : 'JsonReader',
-                                                                            fields : [{"name":"taxzone_id","type":"int"},"taxzone_descrip"],
-                                                                            xns : Roo.data,
-                                                                            totalProperty : 'total'
-                                                                        },
-                                                                        '|xns' : 'Roo.data',
-                                                                        xtype : 'Store',
-                                                                        remoteSort : true,
-                                                                        sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
-                                                                        xns : Roo.data,
-                                                                        listeners : {
-                                                                               beforeload : function (_self, o){
-                                                                                      o.params = o.params || {};
-                                                                                      // set more here
-                                                                                      
-                                                                                      o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d'); 
-                                                                                      Roo.log("with date?" + o.params.with_date);
-                                                                                      
-                                                                                      
-                                                                                  }
-                                                                        },
-                                                                        items : [
-
-                                                                        ]
-
-                                                                    },
-                                                                    '|xns' : 'Roo.form',
-                                                                    listWidth : 400,
-                                                                    triggerAction : 'all',
-                                                                    fieldLabel : 'Tax Zone',
-                                                                    forceSelection : true,
-                                                                    selectOnFocus : true,
-                                                                    pageSize : 20,
-                                                                    displayField : 'taxzone_descrip',
-                                                                    emptyText : "Select taxtype",
-                                                                    hiddenName : 'cohead_taxzone_id',
-                                                                    minChars : 2,
-                                                                    valueField : 'taxzone_id',
-                                                                    xtype : 'ComboBox',
-                                                                    allowBlank : false,
-                                                                    typeAhead : true,
-                                                                    editable : false,
-                                                                    width : 285,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_taxzone_id_taxzone_descrip',
-                                                                    qtip : "Select taxtype",
-                                                                    queryParam : 'query[taxzone_descrip]',
-                                                                    tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>',
-                                                                    loadingText : "Searching...",
-                                                                    listeners : {
-                                                                       select : function (combo, record, index)
-                                                                          {
-                                                                               _this.form.findField('cohead_tax').setValue(
-                                                                                       parseFloat(record.data.taxzone_rate) * 
-                                                                                       parseFloat(_this.form.findField('cohead_subtotal').getValue())
-                                                                               );
-                                                                                _this.form.findField('cohead_total').recalc();
-                                                                          }
-                                                                    },
-                                                                    items : [
-
-                                                                    ]
-
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : 'Tax',
-                                                                    xtype : 'NumberField',
-                                                                    cls : 'roo-align-right',
-                                                                    readOnly : true,
-                                                                    allowDecimals : true,
-                                                                    decimalPrecision : 3,
-                                                                    width : 100,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_tax'
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Pre Tax discount',
-                                                            xtype : 'NumberField',
-                                                            cls : 'roo-align-right',
-                                                            readOnly : true,
-                                                            allowDecimals : true,
-                                                            decimalPrecision : 3,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_pretax_discount'
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            labelAlign : 'top',
-                                                            xtype : 'Row',
-                                                            labelSeparator : '&nbsp;',
-                                                            width : 500,
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : 'Discount after Tax  Description',
-                                                                    xtype : 'TextField',
-                                                                    width : 230,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_misc_descrip'
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : '%',
-                                                                    xtype : 'NumberField',
-                                                                    update : function() {
-                                                                        var m = _this.form.findField('cohead_misc_per');
-                                                                        var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
-                                                                        var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
-                                                                        var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
-                                                                        
-                                                                        var discount = parseFloat(_this.form.findField('cohead_posttax_discount').getValue());
-                                                                        
-                                                                        if (discount > 0.0) {
-                                                                            this.setValue(0);        
-                                                                            return;
-                                                                        }
-                                                                        if (pv < 0) {
-                                                                            this.setValue(0);        
-                                                                            return;
-                                                                        }
-                                                                        var val = ((discount) / (pv + tax + pd)) * -100;
-                                                                        
-                                                                        //Roo.log("update discount?" + val);
-                                                                        this.setValue(val.toFixed(1));
-                                                                        
-                                                                         if (val > 0.0) {
-                                                                            _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
-                                                                        
-                                                                        }
-                                                                        
-                                                                       
-                                                                    },
-                                                                    cls : 'roo-align-right',
-                                                                    allowDecimals : true,
-                                                                    decimalPrecision : 1,
-                                                                    width : 35,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_misc_per',
-                                                                    listeners : {
-                                                                       keyup : function (_self, e)
-                                                                          {
-                                                                              var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
-                                                                              var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
-                                                                              var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
-                                                                              
-                                                                              var n = this.getValue();
-                                                                              var discount = parseFloat(n * (pv + tax + pd) * 0.01);
-                                                                              
-                                                                              _this.form.findField('cohead_posttax_discount').setValue(discount);
-                                                                          
-                                                                              _this.form.findField('cohead_total').recalc();
-                                                                              _this.form.findField('cohead_misc').recalc();
-                                                                              var val = discount * -1.0;
-                                                                               if (val > 0) {
-                                                                                  _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
-                                                                              }
-                                                                             
-                                                                              
-                                                                          }
-                                                                    }
-                                                                },
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    fieldLabel : '&nbsp;',
-                                                                    xtype : 'NumberField',
-                                                                    cls : 'roo-align-right',
-                                                                    allowDecimals : true,
-                                                                    decimalPrecision : 3,
-                                                                    width : 100,
-                                                                    xns : Roo.form,
-                                                                    name : 'cohead_posttax_discount',
-                                                                    listeners : {
-                                                                       keyup : function (_self, e)
-                                                                          {
-                                                                             _this.form.findField('cohead_misc_per').update();
-                                                                              _this.form.findField('cohead_total').recalc();
-                                                                              _this.form.findField('cohead_misc').recalc();
-                                                                          }
-                                                                    }
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Total',
-                                                            recalc : function() {
-                                                                var d = _this.form.getValues();
-                                                                this.setValue( 
-                                                                            parseFloat(d.cohead_subtotal) + 
-                                                                            parseFloat(d.cohead_pretax_discount) + 
-                                                                            parseFloat(d.cohead_posttax_discount) + 
-                                                                            parseFloat(d.cohead_tax) + 
-                                                                            parseFloat(d.cohead_freight));
-                                                            },
-                                                            xtype : 'NumberField',
-                                                            cls : 'roo-align-right',
-                                                            readOnly : true,
-                                                            allowDecimals : true,
-                                                            decimalPrecision : 3,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_total'
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Shipping',
-                                                            xtype : 'NumberField',
-                                                            cls : 'roo-align-right',
-                                                            allowDecimals : true,
-                                                            decimalPrecision : 3,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_freight',
-                                                            listeners : {
-                                                               keyup : function (_self, e)
-                                                                  {
-                                                                      _this.form.findField('cohead_total').recalc();
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Unshipped Total',
-                                                            xtype : 'NumberField',
-                                                            cls : 'roo-align-right',
-                                                            readOnly : true,
-                                                            allowDecimals : true,
-                                                            decimalPrecision : 3,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_unshipped'
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Uninvoiced Total',
-                                                            xtype : 'NumberField',
-                                                            cls : 'roo-align-right',
-                                                            readOnly : true,
-                                                            allowDecimals : true,
-                                                            decimalPrecision : 3,
-                                                            width : 100,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_uninvoiced'
-                                                        }
-                                                    ]
-
-                                                }
-                                            ]
-
-                                        },
-                                       {
-                                            '|xns' : 'Roo.form',
-                                            style : 'width:420px',
-                                            xtype : 'FieldSet',
-                                            legend : "Shipping",
-                                            xns : Roo.form,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.form',
-                                                    xtype : 'Column',
-                                                    labelWidth : 50,
-                                                    width : 420,
-                                                    xns : Roo.form,
-                                                    items : [
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            xtype : 'Row',
-                                                            labelSeparator : '&nbsp;',
-                                                            xns : Roo.form,
-                                                            items : [
-                                                               {
-                                                                    '|xns' : 'Roo.form',
-                                                                    xtype : 'Checkbox',
-                                                                    boxLabel : 'Same as Billing',
-                                                                    xns : Roo.form,
-                                                                    name : '_shipto_same',
-                                                                    listeners : {
-                                                                       check : function (_self, checked)
-                                                                          {
-                                                                             if (!_this.form) {
-                                                                                 return;
-                                                                             }
-                                                                             
-                                                                             if (_this.dataloading) {
-                                                                             
-                                                                                 return;
-                                                                             }
-                                                                             
-                                                                             
-                                                                             if (checked) {
-                                                                             
-                                                                                  // copy the cohead_billto_cntct_id
-                                                                                  for (var i in _this.data) {
-                                                                                      if (!i.match(/^cohead_billto_cntct_id/)) {
-                                                                                          continue;
-                                                                                      }
-                                                                                      var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
-                                                                                      _this.data[ni] = _this.data[i];
-                                                                                  }
-                                                                                   _this.form.findField('shipto_address').update();
-                                                                                   _this.form.setValues( {
-                                                                                          cohead_shipto_cntct_id : _this.data.cohead_shipto_cntct_id,
-                                                                                          cohead_shipto_cntct_id_cntct_name : _this.data.cohead_shipto_cntct_id_cntct_first_name + ' ' + 
-                                                                                                  _this.data.cohead_shipto_cntct_id_cntct_last_name 
-                                                                                                  
-                                                                                          
-                                                                                      });
-                                                                          
-                                                                             
-                                                                              } else {
-                                                                                   for (var i in _this.data) {
-                                                                                      if (!i.match(/^cohead_billto_cntct_id/)) {
-                                                                                          continue;
-                                                                                      }
-                                                                                      var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
-                                                                                      
-                                                                                      _this.data[ni] = '';
-                                                                                  }
-                                                                                   _this.form.findField('shipto_address').update();
-                                                                                   
-                                                                                  _this.form.setValues( {
-                                                                                          cohead_shipto_cntct_id : '',
-                                                                                          cohead_shipto_cntct_id_cntct_name : '' 
-                                                                                          
-                                                                                          
-                                                                                      });
-                                                                              }
-                                                                              
-                                                                          }
-                                                                    }
-                                                                }
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            store : {
-                                                                proxy : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    url : baseURL + '/Roo/cntct.php',
-                                                                    method : 'GET',
-                                                                    xtype : 'HttpProxy',
-                                                                    xns : Roo.data
-                                                                },
-                                                                reader : {
-                                                                    '|xns' : 'Roo.data',
-                                                                    id : 'cntct_id',
-                                                                    root : 'data',
-                                                                    xtype : 'JsonReader',
-                                                                    xns : Roo.data,
-                                                                    fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
-                                                                    totalProperty : 'total'
-                                                                },
-                                                                '|xns' : 'Roo.data',
-                                                                xtype : 'Store',
-                                                                remoteSort : true,
-                                                                sortInfo : { direction : 'ASC', field: 'cntct_name' },
-                                                                xns : Roo.data,
-                                                                listeners : {
-                                                                       beforeload : function (_self, o){
-                                                                              o.params = o.params || {};
-                                                                              // set more here
-                                                                              o.params._customer_id = _this.data.cohead_cust_id;
-                                                                          }
-                                                                },
-                                                                items : [
-
-                                                                ]
-
-                                                            },
-                                                            '|xns' : 'Roo.form',
-                                                            alwaysQuery : true,
-                                                            listWidth : 400,
-                                                            triggerAction : 'all',
-                                                            fieldLabel : 'Ship to',
-                                                            forceSelection : true,
-                                                            selectOnFocus : true,
-                                                            pageSize : 20,
-                                                            displayField : 'cntct_name',
-                                                            emptyText : "Select ship to",
-                                                            hiddenName : 'cohead_shipto_cntct_id',
-                                                            minChars : 2,
-                                                            valueField : 'cntct_id',
-                                                            xtype : 'ComboBox',
-                                                            allowBlank : false,
-                                                            typeAhead : true,
-                                                            editable : true,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'cohead_shipto_cntct_id_cntct_name',
-                                                            qtip : "Select shiptoinfo",
-                                                            queryParam : 'query[cntct_name]',
-                                                            tpl : '<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>',
-                                                            loadingText : "Searching...",
-                                                            listeners : {
-                                                               add : function (combo)
-                                                                  {
-                                                                   Pman.Dialog.XtupleQuickContact.show( 
-                                                                              {
-                                                                                _id : id,
-                                                                                customer_id : _this.form.findField('cohead_cust_id').getValue()
-                                                                              },
-                                                                              
-                                                                              function (data) {
-                                                                                 
-                                                                                  for(var i in  data) {
-                                                                                      
-                                                                                      _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
-                                                                                  }
-                                                                                  
-                                                                                  _this.form.findField('shipto_address').update();
-                                                                                  // fill in the select box..
-                                                                                  _this.form.setValues( {
-                                                                                      cohead_shipto_cntct_id : data.cntct_id,
-                                                                                      cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
-                                                                                              data.cntct_last_name
-                                                                                      
-                                                                                  });
-                                                                              }
-                                                                          ); 
-                                                                  },
-                                                               beforeselect : function (combo, record, index)
-                                                                  {
-                                                                     
-                                                                      // just add everything...
-                                                                      for(var i in record.data) {
-                                                                          //Roo.log('cohead_shipto_cntct_id_' + i +' ='  + record.data[i]);
-                                                                          _this.data['cohead_shipto_cntct_id_' + i] = record.data[i];
-                                                                      }
-                                                                  
-                                                                      _this.form.findField('shipto_address').update();
-                                                                      
-                                                                   
-                                                                  }
-                                                            },
-                                                            items : [
-
-                                                            ]
-
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Address',
-                                                            xtype : 'TextArea',
-                                                            update : function() {
-                                                            
-                                                                var c = ['first_name', 'last_name' ] ;
-                                                                var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
-                                                                var v = [];
-                                                                
-                                                                if (_this.data['cohead_shipto_vend_name'] && _this.data['cohead_shipto_vend_name'].length) {
-                                                                     v.push(_this.data['cohead_shipto_vend_name']);
-                                                                }
-                                                                    if (_this.data['cohead_shipto_vendaddr_code'] && _this.data['cohead_shipto_vendaddr_code'].length) {
-                                                                     v.push(_this.data['cohead_shipto_vendaddr_code']);
-                                                                }
-                                                                Roo.each(c, function(e) {
-                                                                    if (_this.data['cohead_shipto_cntct_id_cntct_' +e] && 
-                                                                        _this.data['cohead_shipto_cntct_id_cntct_' +e].length) {
-                                                                        v.push(_this.data['cohead_shipto_cntct_id_cntct_' +e]);
-                                                                    }
-                                                                });
-                                                                Roo.each(a, function(e) {
-                                                                    if (_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e] && 
-                                                                        _this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e].length) { 
-                                                                        v.push(_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e]);
-                                                                    }
-                                                                });
-                                                            
-                                                                this.setValue(v.join("\n"));
-                                                            },
-                                                            readOnly : true,
-                                                            width : 300,
-                                                            xns : Roo.form,
-                                                            name : 'shipto_address',
-                                                            listeners : {
-                                                               render : function (_self)
-                                                                  {
-                                                                     Roo.log(this.el)
-                                                                     
-                                                                     
-                                                                     
-                                                                     this.el.on('click', function() { 
-                                                                         var id = _this.form.findField('cohead_shipto_cntct_id').getValue();
-                                                                          Pman.Dialog.XtupleQuickContact.show( 
-                                                                              {
-                                                                                _id : id,
-                                                                                customer_id : _this.form.findField('cohead_cust_id').getValue()
-                                                                              },
-                                                                              
-                                                                              function (data) {
-                                                                              
-                                                                                  for(var i in  data) {
-                                                                                      
-                                                                                      _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
-                                                                                  }
-                                                                                  
-                                                                                  _this.form.findField('shipto_address').update();
-                                                                                  // fill in the select box..
-                                                                                  _this.form.setValues( {
-                                                                                      cohead_shipto_cntct_id : data.cntct_id,
-                                                                                      cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
-                                                                                              data.cntct_last_name
-                                                                                      
-                                                                                  });
-                                                                                  
-                                                                                          
-                                                                                  //Roo.log(data);
-                                                                              }
-                                                                          );
-                                                                     
-                                                                        //  Roo.log("Click text");
-                                                                          
-                                                                          
-                                                                       });
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.form',
-                                                            fieldLabel : 'Shipment Comments',
-                                                            xtype : 'TextArea',
-                                                            xns : Roo.form,
-                                                            width : 300,
-                                                            name : 'cohead_shipcomments'
-                                                        }
-                                                    ]
-
-                                                }
-                                            ]
-
-                                        }
-                                    ]
-
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_id'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_shipto_id'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_shipto_id_shipto_name'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_max_linenumber'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_cust_id'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    recalc : function() {
-                                        var d = _this.form.getValues();
-                                        this.setValue( 
-                                            parseFloat(d.cohead_pretax_discount) + 
-                                            parseFloat(d.cohead_posttax_discount) );
-                                    },
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'cohead_misc'
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'Hidden',
-                                    xns : Roo.form,
-                                    name : 'taxzone_rate'
-                                }
-                            ]
-
+                     check : function (_self, checked)
+                      {
+                          if(checked){
+                              _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());
+                          }
+                      }
+                    }
+                   }
+                  ]
+                 }
+                ]
+               },
+               {
+                allowBlank : false,
+                displayField : 'location_name',
+                editable : true,
+                emptyText : _this._strings['4a2a14210d78f0d82db75d0264030169'] /* Supply From */,
+                fieldLabel : _this._strings['4a2a14210d78f0d82db75d0264030169'] /* Supply From */,
+                forceSelection : true,
+                hiddenName : 'cohead_location_src',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_location_src_location_name',
+                pageSize : 200,
+                qtip : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
+                queryParam : 'query[location_name]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>',
+                triggerAction : 'all',
+                typeAhead : false,
+                valueField : 'location_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'location_name' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                        o.params.location_netable = 1;
+                         o.params.location_restrict = 0;
+                         o.params._notinternalcompany = 1;
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/location.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"location_id","type":"int"},"location_name"],
+                  id : 'location_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               }
+              ]
+             }
+            ]
+           },
+           {
+            labelWidth : 100,
+            legend : _this._strings['3ec365dd533ddb7ef3d1c111186ce872'] /* Details */,
+            style : 'width:420px',
+            xns : Roo.form,
+            '|xns' : 'Roo.form',
+            xtype : 'FieldSet',
+            items  : [
+             {
+              labelWidth : 100,
+              width : 420,
+              xns : Roo.form,
+              '|xns' : 'Roo.form',
+              xtype : 'Column',
+              items  : [
+               {
+                allowBlank : false,
+                displayField : 'terms_descrip',
+                editable : false,
+                emptyText : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
+                fieldLabel : _this._strings['6f1bf85c9ebb3c7fa26251e1e335e032'] /* Terms */,
+                forceSelection : true,
+                hiddenName : 'cohead_terms_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_terms_id_terms_descrip',
+                pageSize : 20,
+                qtip : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
+                queryParam : 'query[terms_descrip]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'terms_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'terms_descrip' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/terms.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"terms_id","type":"int"},"terms_descrip"],
+                  id : 'terms_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               },
+               {
+                allowBlank : true,
+                alwaysQuery : true,
+                displayField : 'salesrep_name',
+                editable : false,
+                emptyText : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
+                fieldLabel : _this._strings['94f475efc6722fd13ab78411c1ef7bd7'] /* Sales Rep */,
+                forceSelection : true,
+                hiddenName : 'cohead_display_salesrep_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_display_salesrep_id_salesrep_name',
+                pageSize : 80,
+                qtip : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
+                queryParam : 'query[salesrep_name]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'salesrep_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'salesrep_name' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/salesrep.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
+                  id : 'salesrep_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               },
+               {
+                allowBlank : false,
+                alwaysQuery : true,
+                displayField : 'salesrep_name',
+                editable : false,
+                emptyText : _this._strings['de3d17fb46f44fdf066581fbb5fe6113'] /* Select Staff */,
+                fieldLabel : _this._strings['0ee72ad23c24d7cfc5c13311abdc3f72'] /* Staff I.C. */,
+                forceSelection : true,
+                hiddenName : 'cohead_salesrep_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_salesrep_id_salesrep_name',
+                pageSize : 80,
+                qtip : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
+                queryParam : 'query[salesrep_name]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'salesrep_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'salesrep_name' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/salesrep.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
+                  id : 'salesrep_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               },
+               {
+                fieldLabel : _this._strings['f4ac45b9eb622dcb26c0d4fc1c93b27c'] /* Order Comments */,
+                height : 80,
+                name : 'cohead_ordercomments',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextArea'
+               }
+              ]
+             }
+            ]
+           },
+           {
+            legend : _this._strings['780c462e85ba4399a5d42e88f69a15ca'] /* Billing */,
+            style : 'width:420px',
+            xns : Roo.form,
+            '|xns' : 'Roo.form',
+            xtype : 'FieldSet',
+            items  : [
+             {
+              labelWidth : 50,
+              width : 420,
+              xns : Roo.form,
+              '|xns' : 'Roo.form',
+              xtype : 'Column',
+              items  : [
+               {
+                allowBlank : false,
+                alwaysQuery : true,
+                displayField : 'cntct_name',
+                editable : true,
+                emptyText : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
+                fieldLabel : _this._strings['c3ce05eb16c5e0075b4a247b2c4b7bba'] /* Bill To (select) */,
+                forceSelection : true,
+                hiddenName : 'cohead_billto_cntct_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_billto_cntct_id_cntct_name',
+                pageSize : 20,
+                qtip : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
+                queryParam : 'query[cntct_name]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'cntct_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                listeners : {
+                 add : function (combo)
+                  {
+                    
+                    Pman.Dialog.XtupleQuickContact.show( 
+                              {
+                                _id : id,
+                                customer_id : _this.form.findField('cohead_cust_id').getValue()
+                              },
+                              
+                              function (data) {
+                                 
+                                  for(var i in  data) {
+                                      
+                                      _this.data['cohead_billto_cntct_id_' + i] =  data[i];
+                                  }
+                                  
+                                  _this.form.findField('billto_address').update();
+                                  // fill in the select box..
+                                  _this.form.setValues( {
+                                      cohead_billto_cntct_id : data.cntct_id,
+                                      cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
+                                              data.cntct_last_name
+                                      
+                                  });
+                              }
+                          );
+                          //  Pman.Dialog.XtupleCustomer.show(
+                              //{ cust_id : _this.form.findField('cohead_cust_id').getValue() }, 
+                              //function(data) {
+                          // refresh the data in the pulldown..
+                      //    }); 
+                  
+                  },
+                 beforeselect : function (combo, record, index)
+                  {
+                      // set _this.data values ..
+                  
+                      // just add everything...
+                      for(var i in record.data) {
+                          _this.data['cohead_billto_cntct_id_' + i] = record.data[i];
+                      }
+                      
+                      _this.form.findField('billto_address').update();
+                      
+                      
+                   
+                  }
+                },
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'cntct_name' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                       o.params._customer_id = _this.data.cohead_cust_id;
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/cntct.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
+                  id : 'cntct_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               },
+               {
+                fieldLabel : _this._strings['1d144309cbdf2536723621bf0eac9f33'] /* or enter Address */,
+                name : 'billto_address',
+                readOnly : true,
+                update : function() {
+                
+                    var c = ['first_name', 'last_name' ] ;
+                    var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
+                    var v = [];
+                    Roo.each(c, function(e) {
+                        if (_this.data['cohead_billto_cntct_id_cntct_' +e].length) { 
+                            v.push(_this.data['cohead_billto_cntct_id_cntct_' +e]);
                         }
-                    ]
-
+                    });
+                    Roo.each(a, function(e) {
+                        if (_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
+                            v.push(_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e]);
+                        }
+                    });
+                
+                    this.setValue(v.join("\n"));
+                    
+                    if(_this.data.cohead_billto_cntct_id_cntct_email.length){
+                        _this.form.findField('billto_email').setValue(_this.data.cohead_billto_cntct_id_cntct_email);
+                    }
+                },
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextArea',
+                listeners : {
+                 render : function (_self)
+                  {
+                     Roo.log(this.el)
+                     
+                     
+                     
+                     this.el.on('click', function() { 
+                         var id = _this.form.findField('cohead_billto_cntct_id').getValue();
+                          Pman.Dialog.XtupleQuickContact.show( 
+                              {
+                                _id : id,
+                                customer_id : _this.form.findField('cohead_cust_id').getValue()
+                              },
+                              
+                              function (data) {
+                              
+                                  for(var i in  data) {
+                                      
+                                      _this.data['cohead_billto_cntct_id_' + i] =  data[i];
+                                  }
+                                  
+                                  _this.form.findField('billto_address').update();
+                                  // fill in the select box..
+                                  _this.form.setValues( {
+                                      cohead_billto_cntct_id : data.cntct_id,
+                                      cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
+                                              data.cntct_last_name
+                                      
+                                  });
+                                  
+                                          
+                                  Roo.log(data);
+                              }
+                          );
+                     
+                          Roo.log("Click text");
+                          
+                          
+                       });
+                  }
+                }
+               },
+               {
+                fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
+                name : 'billto_email',
+                valueRenderer : function(v)
+                {
+                 
+                    return v ? String.format('<a href="mailto:{0}" target="_blank">{0}</a>',v) : '';
                 },
-               {
-                    grid : {
-                        sm : {
-                            '|xns' : 'Roo.grid',
-                            xtype : 'CellSelectionModel',
-                            xns : Roo.grid,
-                            enter_is_tab : true,
-                            listeners : {
-                               tabend : function (_self)
-                                  {
-                                      _this.addItemBtn.fireEvent('click', _this.addItemBtn);
-                                  },
-                               beforeeditnext : function (eventdata)
-                                  {
-                                      
-                                      return;
-                                      // this does not work, as the reload effect cancels editng.
-                                      var rec = _this.grid.ds.getAt(eventdata.cell[0]);
-                                      if (rec.data.coitem_subnumber *1 < 0 ) {
-                                          return;
-                                      }
-                                      var r = eventdata.cell[0] + 1;
-                                  
-                                      while (true) {
-                                          if (r > _this.grid.ds.getCount()-1 ) {
-                                              eventdata.cell = false;
-                                              return;
-                                          }
-                                          rec =  _this.grid.ds.getAt(r);
-                                          if (rec.data.coitem_subnumber *1 < 0 ) {
-                                             eventdata.cell = [ r, eventdata.cell[1] ];
-                                             return;
-                                          }
-                                          r++;
-                                      }
-                                      
-                                      
-                                   
-                                  
-                                  }
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'DisplayField'
+               }
+              ]
+             }
+            ]
+           }
+          ]
+         },
+         {
+          style : 'margin-left:10px',
+          width : 435,
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Column',
+          items  : [
+           {
+            labelWidth : 50,
+            legend : _this._strings['9f1a342d0197aac60ed73e921dc4c1f5'] /* Price Details */,
+            style : 'width:420px',
+            xns : Roo.form,
+            '|xns' : 'Roo.form',
+            xtype : 'FieldSet',
+            items  : [
+             {
+              labelAlign : 'right',
+              labelWidth : 300,
+              width : 420,
+              xns : Roo.form,
+              '|xns' : 'Roo.form',
+              xtype : 'Column',
+              items  : [
+               {
+                labelAlign : 'top',
+                labelSeparator : '&nbsp;',
+                width : 500,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  allowBlank : false,
+                  displayField : 'curr_name',
+                  editable : false,
+                  emptyText : _this._strings['2925dda0ec274c20c0a30d8720eb830b'] /* Select curr_name */,
+                  fieldLabel : _this._strings['386c339d37e737a436499d423a77df0c'] /* Currency */,
+                  forceSelection : true,
+                  hiddenName : 'cohead_curr_id',
+                  listWidth : 400,
+                  loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                  minChars : 2,
+                  name : 'cohead_curr_id_curr_name',
+                  pageSize : 20,
+                  qtip : _this._strings['e8586011952b0d098b0e568f20ca2b1f'] /* Select Currency */,
+                  queryParam : 'query[curr_name]',
+                  selectOnFocus : true,
+                  tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>',
+                  triggerAction : 'all',
+                  typeAhead : true,
+                  valueField : 'curr_id',
+                  width : 285,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'ComboBox',
+                  listeners : {
+                   beforequery : function (combo, query, forceAll, cancel, e)
+                    {
+                        Roo.log('beforequery');
+                       
+                        if (_this.form.findField('cohead_number').getValue().length) {
+                            Roo.MessageBox.alert("Error", "You can not change the currency of this order");
+                            if (query) {
+                                query.cancel = true;
                             }
-                        },
-                        footer : {
-                            '|xns' : 'Roo',
-                            pageSize : 100,
-                            xtype : 'PagingToolbar',
-                            emptyMsg : "No Items",
-                            xns : Roo,
-                            displayInfo : true,
-                            updateSummary : function() {
-                                var f = this;
-                                new Pman.Request({
-                                    url : baseURL + '/Roo/Coitem',
-                                    method : 'GET',
-                                    params : {
-                                        _totals : 1,
-                                        coitem_cohead_id : _this.form.findField('cohead_id').getValue()
-                                    },
-                                    success : function(d) {
-                                        //Roo.log(d);
-                                        f.displayEl.update(String.format(
-                                            "{0} items |  Subtotal: {2} | Tax: {3} | List Discount {4} | Total : {1}{5}",
-                                            d.data.total_qty,
-                                            _this.form.findField('cohead_curr_id').el.dom.value,
-                                            d.data.total_sub,
-                                            d.data.total_tax,
-                                            d.data.total_list_discount,                
-                                            d.data.total_total
-                                        ));
+                            return false;
+                        }
+                    }
+                  },
+                  store : {
+                   remoteSort : true,
+                   sortInfo : { direction : 'ASC', field: 'curr_symbol' },
+                   xns : Roo.data,
+                   '|xns' : 'Roo.data',
+                   xtype : 'Store',
+                   listeners : {
+                    beforeload : function (_self, o){
+                         o.params = o.params || {};
+                         // set more here
+                        
+                     }
+                   },
+                   proxy : {
+                    method : 'GET',
+                    url : baseURL + '/Roo/curr_symbol.php',
+                    xns : Roo.data,
+                    '|xns' : 'Roo.data',
+                    xtype : 'HttpProxy'
+                   },
+                   reader : {
+                    fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
+                    id : 'curr_id',
+                    root : 'data',
+                    totalProperty : 'total',
+                    xns : Roo.data,
+                    '|xns' : 'Roo.data',
+                    xtype : 'JsonReader'
+                   }
+                  }
+                 },
+                 {
+                  allowDecimals : true,
+                  cls : 'roo-align-right',
+                  decimalPrecision : 3,
+                  fieldLabel : _this._strings['068f80c7519d0528fb08e82137a72131'] /* Products */,
+                  name : 'cohead_subtotal',
+                  readOnly : true,
+                  width : 100,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'NumberField'
+                 }
+                ]
+               },
+               {
+                labelAlign : 'top',
+                labelSeparator : '&nbsp;',
+                width : 500,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  allowBlank : false,
+                  displayField : 'taxzone_descrip',
+                  editable : false,
+                  emptyText : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
+                  fieldLabel : _this._strings['78ca8a8170f2065057507ddcde63d9ca'] /* Tax Zone */,
+                  forceSelection : true,
+                  hiddenName : 'cohead_taxzone_id',
+                  listWidth : 400,
+                  loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                  minChars : 2,
+                  name : 'cohead_taxzone_id_taxzone_descrip',
+                  pageSize : 20,
+                  qtip : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
+                  queryParam : 'query[taxzone_descrip]',
+                  selectOnFocus : true,
+                  tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>',
+                  triggerAction : 'all',
+                  typeAhead : true,
+                  valueField : 'taxzone_id',
+                  width : 285,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'ComboBox',
+                  listeners : {
+                   select : function (combo, record, index)
+                    {
+                         _this.form.findField('cohead_tax').setValue(
+                                 parseFloat(record.data.taxzone_rate) * 
+                                 parseFloat(_this.form.findField('cohead_subtotal').getValue())
+                         );
+                          _this.form.findField('cohead_total').recalc();
+                    }
+                  },
+                  store : {
+                   remoteSort : true,
+                   sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
+                   xns : Roo.data,
+                   '|xns' : 'Roo.data',
+                   xtype : 'Store',
+                   listeners : {
+                    beforeload : function (_self, o){
+                         o.params = o.params || {};
+                         // set more here
+                         
+                         o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d'); 
+                         Roo.log("with date?" + o.params.with_date);
+                         
+                         
+                     }
+                   },
+                   proxy : {
+                    method : 'GET',
+                    url : baseURL + '/Roo/taxzone.php',
+                    xns : Roo.data,
+                    '|xns' : 'Roo.data',
+                    xtype : 'HttpProxy'
+                   },
+                   reader : {
+                    fields : [{"name":"taxzone_id","type":"int"},"taxzone_descrip"],
+                    id : 'taxzone_id',
+                    root : 'data',
+                    totalProperty : 'total',
+                    xns : Roo.data,
+                    '|xns' : 'Roo.data',
+                    xtype : 'JsonReader'
+                   }
+                  }
+                 },
+                 {
+                  allowDecimals : true,
+                  cls : 'roo-align-right',
+                  decimalPrecision : 3,
+                  fieldLabel : _this._strings['4b78ac8eb158840e9638a3aeb26c4a9d'] /* Tax */,
+                  name : 'cohead_tax',
+                  readOnly : true,
+                  width : 100,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'NumberField'
+                 }
+                ]
+               },
+               {
+                allowDecimals : true,
+                cls : 'roo-align-right',
+                decimalPrecision : 3,
+                fieldLabel : _this._strings['25d81668fca34c83d0720cc6365d62d6'] /* Pre Tax discount */,
+                name : 'cohead_pretax_discount',
+                readOnly : true,
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'NumberField'
+               },
+               {
+                labelAlign : 'top',
+                labelSeparator : '&nbsp;',
+                width : 500,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  fieldLabel : _this._strings['b6dad11e8e2203819164d64fc82b40f1'] /* Discount after Tax  Description */,
+                  name : 'cohead_misc_descrip',
+                  width : 230,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'TextField'
+                 },
+                 {
+                  allowDecimals : true,
+                  cls : 'roo-align-right',
+                  decimalPrecision : 1,
+                  fieldLabel : _this._strings['0bcef9c45bd8a48eda1b26eb0c61c869'] /* % */,
+                  name : 'cohead_misc_per',
+                  update : function() {
+                      var m = _this.form.findField('cohead_misc_per');
+                      var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
+                      var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
+                      var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
+                      
+                      var discount = parseFloat(_this.form.findField('cohead_posttax_discount').getValue());
+                      
+                      if (discount > 0.0) {
+                          this.setValue(0);        
+                          return;
+                      }
+                      if (pv < 0) {
+                          this.setValue(0);        
+                          return;
+                      }
+                      var val = ((discount) / (pv + tax + pd)) * -100;
+                      
+                      //Roo.log("update discount?" + val);
+                      this.setValue(val.toFixed(1));
+                      
+                       if (val > 0.0) {
+                          _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
+                      
+                      }
+                      
+                     
+                  },
+                  width : 35,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'NumberField',
+                  listeners : {
+                   keyup : function (_self, e)
+                    {
+                        var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
+                        var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
+                        var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
+                        
+                        var n = this.getValue();
+                        var discount = parseFloat(n * (pv + tax + pd) * 0.01);
+                        
+                        _this.form.findField('cohead_posttax_discount').setValue(discount);
+                    
+                        _this.form.findField('cohead_total').recalc();
+                        _this.form.findField('cohead_misc').recalc();
+                        var val = discount * -1.0;
+                         if (val > 0) {
+                            _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
+                        }
+                       
+                        
+                    }
+                  }
+                 },
+                 {
+                  allowDecimals : true,
+                  cls : 'roo-align-right',
+                  decimalPrecision : 3,
+                  fieldLabel : _this._strings['cc7819055cde3194bb3b136bad5cf58d'] /* &nbsp; */,
+                  name : 'cohead_posttax_discount',
+                  width : 100,
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'NumberField',
+                  listeners : {
+                   keyup : function (_self, e)
+                    {
+                       _this.form.findField('cohead_misc_per').update();
+                        _this.form.findField('cohead_total').recalc();
+                        _this.form.findField('cohead_misc').recalc();
+                    }
+                  }
+                 }
+                ]
+               },
+               {
+                allowDecimals : true,
+                cls : 'roo-align-right',
+                decimalPrecision : 3,
+                fieldLabel : _this._strings['96b0141273eabab320119c467cdcaf17'] /* Total */,
+                name : 'cohead_total',
+                readOnly : true,
+                recalc : function() {
+                    var d = _this.form.getValues();
+                    this.setValue( 
+                                parseFloat(d.cohead_subtotal) + 
+                                parseFloat(d.cohead_pretax_discount) + 
+                                parseFloat(d.cohead_posttax_discount) + 
+                                parseFloat(d.cohead_tax) + 
+                                parseFloat(d.cohead_freight));
+                },
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'NumberField'
+               },
+               {
+                allowDecimals : true,
+                cls : 'roo-align-right',
+                decimalPrecision : 3,
+                fieldLabel : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
+                name : 'cohead_freight',
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'NumberField',
+                listeners : {
+                 keyup : function (_self, e)
+                  {
+                      _this.form.findField('cohead_total').recalc();
+                  }
+                }
+               },
+               {
+                allowDecimals : true,
+                cls : 'roo-align-right',
+                decimalPrecision : 3,
+                fieldLabel : _this._strings['d335d558a8386d20318888b1f034103d'] /* Unshipped Total */,
+                name : 'cohead_unshipped',
+                readOnly : true,
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'NumberField'
+               },
+               {
+                allowDecimals : true,
+                cls : 'roo-align-right',
+                decimalPrecision : 3,
+                fieldLabel : _this._strings['b98c34417c412e0c87faa828f26b9123'] /* Uninvoiced Total */,
+                name : 'cohead_uninvoiced',
+                readOnly : true,
+                width : 100,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'NumberField'
+               }
+              ]
+             }
+            ]
+           },
+           {
+            legend : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
+            style : 'width:420px',
+            xns : Roo.form,
+            '|xns' : 'Roo.form',
+            xtype : 'FieldSet',
+            items  : [
+             {
+              labelWidth : 50,
+              width : 420,
+              xns : Roo.form,
+              '|xns' : 'Roo.form',
+              xtype : 'Column',
+              items  : [
+               {
+                labelSeparator : '&nbsp;',
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'Row',
+                items  : [
+                 {
+                  boxLabel : 'Same as Billing',
+                  name : '_shipto_same',
+                  xns : Roo.form,
+                  '|xns' : 'Roo.form',
+                  xtype : 'Checkbox',
+                  listeners : {
+                   check : function (_self, checked)
+                    {
+                       if (!_this.form) {
+                           return;
+                       }
+                       
+                       if (_this.dataloading) {
+                       
+                           return;
+                       }
+                       
+                       
+                       if (checked) {
+                       
+                            // copy the cohead_billto_cntct_id
+                            for (var i in _this.data) {
+                                if (!i.match(/^cohead_billto_cntct_id/)) {
+                                    continue;
+                                }
+                                var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
+                                _this.data[ni] = _this.data[i];
+                            }
+                             _this.form.findField('shipto_address').update();
+                             _this.form.setValues( {
+                                    cohead_shipto_cntct_id : _this.data.cohead_shipto_cntct_id,
+                                    cohead_shipto_cntct_id_cntct_name : _this.data.cohead_shipto_cntct_id_cntct_first_name + ' ' + 
+                                            _this.data.cohead_shipto_cntct_id_cntct_last_name 
                                             
-                                    }
+                                    
                                 });
-                            },
-                            items : [
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Fill empty Ship To",
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                              new Pman.Request({
-                                                  url : baseURL + '/Roo/Cohead',
-                                                  method : 'GET',
-                                                  params : {
-                                                      _fill_shipto : _this.form.findField('cohead_id').getValue()
-                                                  },
-                                                  success : function() {
-                                                      _this.grid.footer.onClick('first');
-                                                  }
-                                              });
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Update Location to match S/O",
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                              Roo.MessageBox.confirm("Confirm", "Are you sure?<BR>"+
-                                                  "This will set all the locations to match the Sales Order - and remove all old locations.",
-                                                  function (res) {
-                                                      if(res!='yes') {
-                                                          return;
-                                                      
-                                                      }
-                                                      new Pman.Request({
-                                                          url : baseURL + '/Roo/Cohead',
-                                                          method : 'GET',
-                                                          params : {
-                                                              _fill_location : _this.form.findField('cohead_id').getValue(),
-                                                              _location_id : _this.form.findField('cohead_location_src').getValue()
-                                                          },
-                                                          success : function() {
-                                                              _this.grid.footer.onClick('first');
-                                                          }
-                                                      });
-                                              });
-                                              
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Prices with GST",
-                                    enableToggle : true,
-                                    minWidth : 100,
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       toggle : function (_self, pressed)
-                                          {
-                                              this.setText(pressed ? "Prices exc GST" : "Prices with GST");
-                                              var cm = _this.grid.getColumnModel();
-                                          
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_price_tax'), pressed ? false : true);
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_custprice_tax'), pressed ? false : true);
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal_tax'), pressed ? false : true);
-                                              
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_price'), pressed ? true : false);
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_custprice'), pressed ? true : false);
-                                              cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal'), pressed ? true : false);
-                                              return;
-                                          },
-                                       render : function (_self)
-                                          {
-                                              _this.showgstBtn = _self;
-                                          }
-                                    }
-                                }
-                            ]
-
-                        },
-                        dataSource : {
-                            proxy : {
-                                '|xns' : 'Roo.data',
-                                url : baseURL + '/Roo/coitem.php',
-                                xtype : 'HttpProxy',
-                                method : 'GET',
-                                xns : Roo.data
-                            },
-                            reader : {
-                                '|xns' : 'Roo.data',
-                                id : 'coitem_id',
-                                root : 'data',
-                                xtype : 'JsonReader',
-                                fields : [
-                                    {
-                                        'name': 'coitem_linenumber',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'coitem_itemsite_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'coitem_qtyord'
-                                    },
-                                    {
-                                        'name': 'coitem_unitcost'
-                                    },
-                                    {
-                                        'name': 'coitem_price'
-                                    },
-                                    {
-                                        'name': 'coitem_custprice'
-                                    },
-                                    {
-                                        'name': 'coitem_qtyreturned'
-                                    },
-                                    {
-                                        'name': 'coitem_prcost'
-                                    },
-                                    {
-                                        'name': 'coitem_price_uom_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'coitem_qtyreserved'
-                                    }
-                                ],
-                                xns : Roo.data,
-                                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\"}',
-                                totalProperty : 'total'
-                            },
-                            '|xns' : 'Roo.data',
-                            xtype : 'Store',
-                            remoteSort : true,
-                            sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
-                            xns : Roo.data,
-                            listeners : {
-                               beforeload : function (_self,o) {
-                                  
-                                      try {
-                                         this.removeAll();
-                                     } catch (e) { }
-                                     
-                                  
-                                      if (!_this.data || !_this.data.cohead_id) {
-                                          return false;
-                                      }
-                                      o.params = o.params || {};
-                                      
-                                      o.params.coitem_cohead_id = _this.data.cohead_id;
-                                      o.params._without_list_discount =1;
-                                      //o.params.limit = 999;
-                                  
-                                      
-                                  },
-                               update : function (_self, rec, operation)
-                                      {
-                                     
-                                     if (operation !=  Roo.data.Record.COMMIT) {
-                                         return;
-                                     }
-                                  
-                                     // row has been updated..
-                                     // if the qty + item has been filled in, we should try and save it..
-                                   
-                                      
-                                      var setRecord = function(){
-                                      
-                                           Roo.log("Clearing update?"  + rec.data.coitem_linenumber);
-                                          rec.updatePending = 0;
-                                          if(rec.isInserting){
-                                              rec.isInserting = 0;
-                                              return;
-                                          }
-                                          rec.isUpdating = 0;
-                                  
-                                      }
-                                      if (!(rec.data.coitem_itemsite_id * 1) || !(rec.data.coitem_qtyord*1)) {
-                                          setRecord();
-                                          return;
-                                      }
-                                      var     doCommit = function() {
-                                           Roo.log("Sending  data?"  + rec.data.coitem_linenumber);
-                                          
-                                          new Pman.Request({
-                                              url : baseURL+'/Roo/coitem',
-                                              method : 'POST',
-                                              params : rec.data,
-                                              success: function(res)
-                                              {
-                                                  try {
-                                                      var row = _this.grid.ds.indexOf(rec);
-                                                      Roo.get(_this.grid.view.getRow(row)).removeClass('dragon-not-saved');
-                                                  } catch(e) {
-                                                      Roo.log(e);
-                                                  }
-                                                      
-                                                  
-                                                   Roo.log("GOT success: "  + rec.data.coitem_linenumber);
-                                                  //Roo.log("GOT success");
-                                                  // update the data...
-                                                  
-                                                  if (rec.data.item_type == 'K') {
-                                                       Roo.log("Kit??");
-                                                      _this.grid.ds.load({});
-                                                      
-                                                      return;
-                                                  }
-                                                  
-                                                  // why is this here.??
-                                                  
-                                                  if (_this.grid.activeEditor) {
-                                                       rec.editing = true;
-                                                       
-                                                       
-                                                   } 
-                                                   
-                                                  rec.set('coitem_id', res.data.coitem_id);
-                                                  rec.set('coitem_status', res.data.coitem_status);
-                                                   
-                                                  
-                                                  rec.dirty = false;
-                                                  delete rec.modified;
-                                                  try {
-                                                      _this.grid.footer.updateSummary();          
-                                                      _this.grid.loadAvail();
-                                                  } catch (e) { }
-                                                  
-                                  
-                                                  setRecord();
-                                              },
-                                              failure : function(res)
-                                              {
-                                                  setRecord();
-                                                  Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error updating");
-                                              }
-                                              
-                                              
-                                          });
-                                        } ; 
-                                     
-                                      
-                                      doCommit();
-                                      
-                                      
-                                      
-                                  },
-                               load : function (_self, records, options)
-                                  {
-                                      // need to fetch availablity from master data..
-                                      // build a list of what to ask..
-                                  
-                                      // query: ITEM CODE - LOCATION
-                                      _this.grid.footer.updateSummary();
-                                      _this.grid.loadAvail.defer(100, _this.grid);
-                                  
-                                      
-                                      
-                                      
-                                  }
-                            },
-                            items : [
-
-                            ]
-
-                        },
-                        toolbar : {
-                            '|xns' : 'Roo',
-                            xtype : 'Toolbar',
-                            xns : Roo,
-                            items : [
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Add",
-                                    xtype : 'Button',
-                                    cls : 'x-btn-text-icon',
-                                    icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function()
-                                          {
-                                             
-                                              Roo.log("add presed");
-                                               
-                                              // work out last 
-                                              var grid = _this.grid;
-                                              var err = false;
-                                              grid.ds.each(function(r) {
-                                                  if (r.data.coitem_qtyord < 1) { 
-                                                      Roo.MessageBox.alert("Error", "you must fill in a quantity for " + r.data.item_number);
-                                                      err = true;
-                                                      return true;
-                                                  }
-                                                  
-                                              });
-                                              if (err) {
-                                                  return;
-                                              }
-                                              
-                                          
-                                          //    var last = 0;
-                                              var last = _this.form.findField('cohead_max_linenumber').getValue();   
-                                              last++; 
-                                              if(last == 99999){
-                                                  last++;
-                                              }
-                                              
-                                          
-                                              _this.form.findField('cohead_max_linenumber').setValue(last);    
-                                              
-                                              // this should be getting the previous row..??
-                                               var ct  =    _this.grid.ds.getCount();
-                                               var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;
-                                               
-                                               function lastor(k,d,kk) {
-                                                  var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();
-                                                  return lastrow ? lastrow.data[kk] : def;
-                                               }
-                                              
-                                              // uses form defaults or last row value.
-                                              var nr = _this.grid.ds.reader.newRow({
-                                                  coitem_linenumber : last,
-                                                  item_number : '',
-                                                  item_descrip1 : '',
-                                                  coitem_qtyord : 0,
-                                                  coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
-                                                  coitem_qtyshipped : 0,
-                                                  coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
-                                                  coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
-                                                  coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
-                                                  coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name'),
-                                                  coitem_unitcost_in_order_cur  : 0,
-                                                  coitem_taxtype_id : _this.data.default_taxtype_id,
-                                                  coitem_taxtype_id_taxtype_name : 'Taxable',
-                                                  coitem_status : '',
-                                                  avail_qty : 0
-                                                          
-                                              });
-                                              grid.stopEditing();
-                                              grid.ds.insert(grid.ds.getCount(), nr); 
-                                              grid.startEditing(grid.ds.getCount()-1, 1); // type..
-                                              nr.updatePending = 0;
-                                              nr.isUpdating = 0;
-                                              nr.isInserting =0;
-                                              
-                                          },
-                                       render : function (_self)
-                                          {
-                                              _this.addItemBtn = _self;
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Find Products",
-                                    xtype : 'Button',
-                                    cls : 'x-btn-text-icon',
-                                    icon : rootURL + '/Pman/templates/images/search.gif',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                              var last = _this.form.findField('cohead_max_linenumber').getValue();    \r
-                                              last++;\r
-                                              _this.form.findField('cohead_max_linenumber').setValue(last); 
-                                          
-                                              var ct  =    _this.grid.ds.getCount();\r
-                                              var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;\r
-                                                   \r
-                                              function lastor(k,d,kk) {\r
-                                                 var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();\r
-                                                 return lastrow ? lastrow.data[kk] : def;\r
-                                              }
-                                              
-                                              var cohead_cust_id = _this.form.findField('cohead_cust_id').getValue();
-                                              var cohead_id = _this.form.findField('cohead_id').getValue();
-                                              
-                                              Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cohead_cust_id, cohead_id : cohead_id} , function(res) {
-                                          
-                                                  _this.grid.stopEditing();
-                                          
-                                                  if (_this.grid.ds.getCount() > 0) {
-                                                      var lr = _this.grid.ds.getAt(_this.grid.ds.getCount()-1);
-                                                      if (!lr.data.coitem_itemsite_id) {
-                                                          lr.set('coitem_itemsite_id', res.item_itemsite_id_itemsite_id);
-                                                          lr.set('item_number',  res.item_number);
-                                                          lr.set('item_descrip1', res.item_descrip1);                                
-                                                          lr.set('coitem_listprice', res.item_price);                
-                                                          lr.set('coitem_price', res.item_price);                                
-                                                          lr.set('coitem_custprice', res.item_price);                
-                                                          return;
-                                                      }
-                                                  }
-                                                  
-                                                  
-                                                  
-                                                  var nr = _this.grid.ds.reader.newRow({
-                                                      coitem_linenumber : last,
-                                                      coitem_itemsite_id : res.item_itemsite_id_itemsite_id,
-                                                      item_number : res.item_number,
-                                                      item_descrip1 : res.item_descrip1,
-                                                      coitem_qtyord : 0,
-                                                      coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
-                                                      coitem_qtyshipped : 0,
-                                                      coitem_listprice : res.item_price,
-                                                      coitem_price : res.item_price,
-                                                      coitem_custprice : res.item_price,
-                                                      avail_qty : 0,
-                                                      coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
-                                                      coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
-                                                      coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
-                                                      coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name')
-                                                              
-                                                  });
-                                                  _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
-                                          
-                                             }); 
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Xfer all stock to HK",
-                                    hidden : true,
-                                    xtype : 'Button',
-                                    cls : 'x-btn-text-icon',
-                                    icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function()
-                                          {
-                                              // work out last 
-                                              new Pman.Request({
-                                                  url : baseURL + '/Roo/coitem',
-                                                  mask : 'Loading Data',
-                                                  method: 'GET',
-                                                  params : {
-                                          
-                                                      _hk_xfer :_this.form.findField('cohead_id').getValue()
-                                                  },
-                                                  success : function() {
-                                                      _this.grid.ds.load({});
-                                                  }
-                                              
-                                              });
-                                          },
-                                       render : function (_self)
-                                          {
-                                              _this.xferAll  = _self;
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Show Inventory History",
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                             var c    = _this.grid.getSelectionModel().getSelectedCell();
-                                             if (!c) {
-                                                  Roo.MessageBox.alert("Error", "Select item to show history (you can also double click on the #avail number) ");
-                                                  return;
-                                             }
-                                             
-                                              var rec = _this.grid.ds.getAt(c[0]);
-                                          
-                                            Pman.Dialog.XtupleInvHistory.show({
-                                                  itemsite_item_id_item_number   : rec.data.item_number,
-                                                 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
-                                                  location_name : rec.data.coitem_location_src_location_name,
-                                                  location_descrip : rec.data.coitem_location_src_location_descrip,
-                                                  
-                                                  
-                                                  invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
-                                              }); 
-                                              
-                                             
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    xtype : 'Separator',
-                                    xns : Roo.Toolbar
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Apply % Discount of : ",
-                                    xtype : 'TextItem',
-                                    xns : Roo.Toolbar
-                                },
-                               {
-                                    '|xns' : 'Roo.form',
-                                    xtype : 'TextField',
-                                    xns : Roo.form,
-                                    width : 40,
-                                    listeners : {
-                                       render : function (_self)
-                                          {
-                                              _this._applyDiscount = _self;
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Apply To All",
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                              var val =  parseFloat(_this._applyDiscount.getValue());
-                                              
-                                              var factor = (100.0 - val)/100.0;
-                                              
-                                              _this.grid.ds.each(function(rec) {
-                                                  if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
-                                                      return;
-                                                  }
-                                              
-                                                  rec.set('coitem_price', rec.data.coitem_custprice * factor);
-                                                  rec.set('coitem_linedisc', val);
-                                                  rec.set('coitem_subtotal', rec.data.coitem_price  & rec.data.ordqty);
-                                                  rec.commit();
-                                              
-                                              });
-                                              
-                                              
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Import",
-                                    xtype : 'Button',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function (_self, e)
-                                          {
-                                          
-                                              if (!(1* _this.form.findField('cohead_id').getValue())) {
-                                                  Roo.MessageBox.alert("Error", "save the order first");
-                                              }
-                                              
-                                          
-                                             Pman.Dialog.Image.show(
-                                                 {
-                                                      timeout : 60000,
-                                                      _url : baseURL+'/Xtuple/Import/SalesOrder',
-                                                      onid : _this.form.findField('cohead_id').getValue()
-                                                  
-                                                 },
-                                                 function (data) {
-                                          
-                                                      Roo.MessageBox.alert("Notice", "Uploaded");
-                                                      _this.grid.footer.onClick('first');
-                                          
-                                                 }
-                                             );
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    xtype : 'Fill',
-                                    xns : Roo.Toolbar
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Delete",
-                                    xtype : 'Button',
-                                    cls : 'x-btn-text-icon',
-                                    icon : rootURL + '/Pman/templates/images/trash.gif',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function()
-                                          {
-                                               _this.grid.stopEditing();
-                                              // check that no shipments or invoices are done..
-                                              var rc = _this.grid.getSelectionModel().getSelectedCell();
-                                              
-                                              var rec = _this.grid.ds.getAt(rc[0]);
-                                              
-                                              if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
-                                                  Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
-                                                  return;
-                                              }
-                                             if (rec.data.coitem_subnumber*1  > 0) {
-                                                  Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
-                                                  return;
-                                              }
-                                              if (!rec.data.coitem_id) {
-                                                  _this.grid.ds.remove(rec);
-                                                  return;
-                                              }
-                                              function remove()
-                                              {
-                                              
-                                                  new  Pman.Request({
-                                                      url : baseURL + '/Roo/coitem',
-                                                      method : 'POST',
-                                                      params : {
-                                                          _delete : rec.data.coitem_id
-                                                      
-                                                      },
-                                                      success : function() {
-                                                          if (rec.data.item_type == 'K') {
-                                                              _this.grid.ds.load({});
-                                                              return;
-                                                          }
-                                                          _this.grid.ds.remove(rec);
-                                                      }
-                                                  
-                                                  });
-                                              }
-                                              if (rec.data_qtyord * 1 < 1) {
-                                                  remove();
-                                              }
-                                              
-                                              Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
-                                              {
-                                                  if (r != 'yes') {
-                                                      return;
-                                                  }
-                                                  remove();
-                                              
-                                              });
-                                          
-                                              
-                                              
-                                          }
-                                    }
-                                },
-                               {
-                                    '|xns' : 'Roo.Toolbar',
-                                    text : "Delete All",
-                                    xtype : 'Button',
-                                    cls : 'x-btn-text-icon',
-                                    icon : rootURL + '/Pman/templates/images/trash.gif',
-                                    xns : Roo.Toolbar,
-                                    listeners : {
-                                       click : function()
-                                          {
-                                               _this.grid.stopEditing();
-                                              // check that no shipments or invoices are done..
-                                              var ids = [];
-                                              _this.grid.ds.each(function(rec) {
-                                              
-                                          
-                                              
-                                                  if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
-                                                      //Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
-                                                      return;
-                                                  }
-                                                  if (rec.data.item_type == 'K') {
-                                                      return;
-                                                  }
-                                          
-                                                 if (rec.data.coitem_subnumber*1  > 0) {
-                                                      //Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
-                                                      return;
-                                                  }
-                                                  if (!rec.data.coitem_id) {
-                                                      _this.grid.ds.remove(rec);
-                                                      return;
-                                                  }
-                                                  ids.push(rec.data.coitem_id);
-                                              });
-                                              function remove()
-                                              {
-                                              
-                                                  new  Pman.Request({
-                                                      url : baseURL + '/Roo/coitem',
-                                                      method : 'POST',
-                                                      params : {
-                                                          _delete : ids.join(',')
-                                                      
-                                                      },
-                                                      success : function() {
-                                          
-                                                          _this.grid.footer.onClick('first');
-                                                      }
-                                                  
-                                                  });
-                                              }
-                                          //    if (rec.data_qtyord * 1 < 1) {
-                                          //        remove();
-                                          //    }
-                                              
-                                              Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete everything?", function(r)
-                                              {
-                                                  if (r != 'yes') {
-                                                      return;
-                                                  }
-                                                  remove();
-                                              
-                                              });
-                                          
-                                              
-                                              
-                                          }
-                                    }
+                    
+                       
+                        } else {
+                             for (var i in _this.data) {
+                                if (!i.match(/^cohead_billto_cntct_id/)) {
+                                    continue;
                                 }
-                            ]
-
-                        },
-                        '|xns' : 'Roo.grid',
-                        autoExpandColumn : 'item_descrip1',
-                        xtype : 'EditorGrid',
-                        loadMask : true,
-                        loadAvail : function() {
-                            
-                            
-                            this.ds.each(function(r) {
-                                
-                                if(!r.data.item_number.length){
-                                    return;
-                                }
-                                
-                                if(typeof(_this.stockcache[r.data.item_number]) != 'undefined'){
-                                
-                                    r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
-                                    if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
-                                        r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
-                                    }
-                                    return;
-                                }
-                                
-                                var q = [];
+                                var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
                                 
-                                q.push( { 
-                                    item : r.data.item_number, 
-                                    loc: r.data.coitem_location_src_location_name,
-                                    id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
-                                 } );
-                                 
-                                 new Pman.Request({
-                                    url : baseURL + '/Roo/itemloc',
-                                    method : 'POST',
-                                    params : {
-                                        _availqty : Roo.encode(q),
-                                        curr_name : _this.form.findField('cohead_curr_id').el.dom.value
-                                    },
-                                    success : function(res) 
-                                    {
-                                        for (var i in res.data) {
-                                           _this.stockcache[res.data[i].item] = res.data[i];
-                                        }
-                                        r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
-                                        if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
-                                            r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
-                                        }
-                                        //_this.grid.ds.fireEvent("update", _this.grid.ds, r, Roo.data.Record.EDIT);
-                                        return
-                                    }
+                                _this.data[ni] = '';
+                            }
+                             _this.form.findField('shipto_address').update();
+                             
+                            _this.form.setValues( {
+                                    cohead_shipto_cntct_id : '',
+                                    cohead_shipto_cntct_id_cntct_name : '' 
+                                    
+                                    
                                 });
-                            });
-                                
-                                        
-                        },
-                        clicksToEdit : 1,
-                        xns : Roo.grid,
-                        colModel : [
-                                {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Item#',
-                                       width : 40,
-                                       renderer : function(v,x,r) {
-                                       
-                                           if (r.data.coitem_subnumber * 1 > 0) {
-                                                return String.format('{0}.{1}', v,r.data.coitem_subnumber);
-                                            }
-                                            return String.format('{0}', v);
-                                         },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_linenumber',
-                                       builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}'
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               store : {
-                                                   proxy : {
-                                                       '|xns' : 'Roo.data',
-                                                       url : baseURL + '/Roo/itemsite.php',
-                                                       xtype : 'HttpProxy',
-                                                       method : 'GET',
-                                                       xns : Roo.data
-                                                   },
-                                                   reader : {
-                                                       '|xns' : 'Roo.data',
-                                                       id : 'shipto_id',
-                                                       root : 'data',
-                                                       xtype : 'JsonReader',
-                                                       fields : [{"name":"item_id","type":"int"},"item_number"],
-                                                       xns : Roo.data,
-                                                       totalProperty : 'total'
-                                                   },
-                                                   '|xns' : 'Roo.data',
-                                                   xtype : 'Store',
-                                                   remoteSort : true,
-                                                   sortInfo : { direction : 'ASC', field: 'item_number' },
-                                                   xns : Roo.data,
-                                                   listeners : {
-                                                       beforeload : function (_self, o){
-                                                              o.params = o.params || {};
-                                                              o.params.customer_id = _this.form.findField('cohead_cust_id').getValue();
-                                                              o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue();
-                                                              //o.params.shipto_cust_id = _this.data.cohead_cust_id;
-                                                              // set more here
-                                                          }
-                                                   },
-                                                   items : [
-
-                                                   ]
-
-                                               },
-                                               '|xns' : 'Roo.form',
-                                               listWidth : 400,
-                                               triggerAction : 'all',
-                                               forceSelection : true,
-                                               selectOnFocus : true,
-                                               pageSize : 20,
-                                               displayField : 'itemsite_item_id_item_number',
-                                               emptyText : "Select item",
-                                               hiddenName : 'itemsite_item_id_item_number',
-                                               minChars : 2,
-                                               valueField : 'item_number',
-                                               xtype : 'ComboBox',
-                                               allowBlank : false,
-                                               typeAhead : false,
-                                               editable : true,
-                                               xns : Roo.form,
-                                               name : 'item_number',
-                                               qtip : "Select item",
-                                               queryParam : 'query[number]',
-                                               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>',
-                                               loadingText : "Searching...",
-                                               listeners : {
-                                                       beforeselect : function (combo, record, index)
-                                                          {
-                                                            // set _this.data values ..
-                                                            var ar = _this.grid.activeEditor.record;
-                                                          //  Roo.log('beforeselect');
-                                                            
-                                                            
-                                                            (function() { 
-                                                               //  Roo.log('beforeselect-cb');
-                                                                ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
-                                                                ar.set('coitem_listprice', record.data.item_listprice);
-                                                                ar.set('coitem_price', record.data.item_price);
-                                                                ar.set('coitem_custprice', record.data.item_price);
-                                                                ar.set('coitem_itemsite_id', record.data.itemsite_id);
-                                                                ar.set('item_number', record.data.itemsite_item_id_item_number);
-                                                               ar.set('item_type', record.data.itemsite_item_id_item_type);
-                                                                ar.set('avail_qty', 0);
-                                                                ar.commit();
-                                                            }).defer(100);
-                                                            
-                                                          }
-                                               },
-                                               items : [
-
-                                               ]
-
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Item Code',
-                                       width : 75,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'item_number',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               store : {
-                                                   proxy : {
-                                                       '|xns' : 'Roo.data',
-                                                       url : baseURL + '/Roo/location.php',
-                                                       xtype : 'HttpProxy',
-                                                       method : 'GET',
-                                                       xns : Roo.data
-                                                   },
-                                                   reader : {
-                                                       '|xns' : 'Roo.data',
-                                                       id : 'shipto_id',
-                                                       root : 'data',
-                                                       xtype : 'JsonReader',
-                                                       fields : [{"name":"location_id","type":"int"},"location_name"],
-                                                       xns : Roo.data,
-                                                       totalProperty : 'total'
-                                                   },
-                                                   '|xns' : 'Roo.data',
-                                                   xtype : 'Store',
-                                                   remoteSort : true,
-                                                   sortInfo : { direction : 'ASC', field: 'location_name' },
-                                                   xns : Roo.data,
-                                                   listeners : {
-                                                       beforeload : function (_self, o){
-                                                              o.params = o.params || {};
-                                                              
-                                                              var row = _this.grid.activeEditor.record;
-                                                              
-                                                              o.params['query[item_itemsite_id]'] = row.data.coitem_itemsite_id;
-                                                              // need to know the date to calc the est. delivery time..
-                                                              //o.params['query[avail_when]'] = _this.form.findField('cohead_targetdate').getValue().format('Y-m-d');
-                                                              //o.params.location_netable = 1;
-                                                              o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue(); 
-                                                              
-                                                               o.params.location_restrict = 0;
-                                                              o.params._notinternalcompany = 1;
-                                                              
-                                                            //  _this.grid;
-                                                          
-                                                          //    o.params.itemsite_id = _this.form.findField('cohead_cust_id').getValue();
-                                                              //o.params.shipto_cust_id = _this.data.cohead_cust_id;
-                                                              // set more here
-                                                          }
-                                                   },
-                                                   items : [
-
-                                                   ]
-
-                                               },
-                                               '|xns' : 'Roo.form',
-                                               alwaysQuery : true,
-                                               listWidth : 400,
-                                               triggerAction : 'all',
-                                               forceSelection : true,
-                                               selectOnFocus : true,
-                                               pageSize : 20,
-                                               displayField : 'location_name',
-                                               emptyText : "Select location",
-                                               hiddenName : 'coitem_location_src',
-                                               minChars : 2,
-                                               valueField : 'location_id',
-                                               xtype : 'ComboBox',
-                                               allowBlank : false,
-                                               typeAhead : false,
-                                               editable : true,
-                                               xns : Roo.form,
-                                               name : 'coitem_location_src_location_name',
-                                               qtip : "Select item",
-                                               queryParam : 'query[location_name]',
-                                               tpl : '<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>',
-                                               loadingText : "Searching...",
-                                               listeners : {
-                                                       beforeselect : function (combo, record, index)
-                                                          {
-                                                            // set _this.data values ..
-                                                            var ar = _this.grid.activeEditor.record;
-                                                            
-                                                            
-                                                            
-                                                            //Roo.log('beforeselect');
-                                                           
-                                                           /*
-                                                            (function() { 
-                                                               //  Roo.log('beforeselect-cb');
-                                                                ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
-                                                                ar.set('coitem_price', record.data.item_listprice);
-                                                                ar.set('coitem_custprice', record.data.item_price);
-                                                                 ar.set('coitem_itemsite_id', record.data.itemsite_id);
-                                                                ar.set('item_number', record.data.itemsite_item_id_item_number);
-                                                          
-                                                                ar.commit();
-                                                            }).defer(100);
-                                                            */
-                                                          }
-                                               },
-                                               items : [
-
-                                               ]
-
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'From',
-                                       width : 75,
-                                       renderer : function(v,x,r) { 
-                                           return String.format('{0}', r.data.coitem_location_src_location_name); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_location_src',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               store : {
-                                                   proxy : {
-                                                       '|xns' : 'Roo.data',
-                                                       url : baseURL + '/Roo/shiptoinfo.php',
-                                                       xtype : 'HttpProxy',
-                                                       method : 'GET',
-                                                       xns : Roo.data
-                                                   },
-                                                   reader : {
-                                                       '|xns' : 'Roo.data',
-                                                       id : 'shipto_id',
-                                                       root : 'data',
-                                                       xtype : 'JsonReader',
-                                                       fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
-                                                       xns : Roo.data,
-                                                       totalProperty : 'total'
-                                                   },
-                                                   '|xns' : 'Roo.data',
-                                                   xtype : 'Store',
-                                                   remoteSort : true,
-                                                   sortInfo : { direction : 'ASC', field: 'shipto_name' },
-                                                   xns : Roo.data,
-                                                   listeners : {
-                                                       beforeload : function (_self, o){
-                                                              o.params = o.params || {};
-                                                              o.params.shipto_cust_id = _this.data.cohead_cust_id; 
-                                                              //o.params['query[with_shipinfo]'] = 1;
-                                                              // set more here
-                                                          }
-                                                   },
-                                                   items : [
-
-                                                   ]
-
-                                               },
-                                               '|xns' : 'Roo.form',
-                                               alwaysQuery : true,
-                                               listWidth : 400,
-                                               triggerAction : 'all',
-                                               forceSelection : true,
-                                               selectOnFocus : true,
-                                               pageSize : 20,
-                                               displayField : 'shipto_name',
-                                               emptyText : "Select cntct",
-                                               hiddenName : 'cohead_shipto_id',
-                                               minChars : 2,
-                                               valueField : 'shipto_id',
-                                               xtype : 'ComboBox',
-                                               allowBlank : false,
-                                               typeAhead : false,
-                                               editable : false,
-                                               width : 300,
-                                               xns : Roo.form,
-                                               name : 'coitem_shipto_id_shipto_name',
-                                               qtip : "Select shipto",
-                                               queryParam : 'query[shipto_name]',
-                                               tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>',
-                                               loadingText : "Searching...",
-                                               listeners : {
-                                                       add : function (combo)
-                                                          {
-                                                          
-                                                             Pman.Dialog.XtupleCustomer.show({ cust_id : _this.form.findField('cohead_cust_id').getValue() }, function(data) {
-                                                                  // refresh the data in the pulldown..
-                                                              }); 
-                                                          },
-                                                       beforeselect : function (combo, record, index)
-                                                          {
-                                                          
-                                                              var v = [];
-                                                              for(var i = 1; i <4; i++) {
-                                                                  _this.data['cohead_shiptoaddress'+  i] = record.data['cntct_addr_id_addr_line'+i];
-                                                              }
-                                                              _this.form.findField('shipto_address').update();
-                                                              
-                                                           
-                                                          }
-                                               },
-                                               items : [
-
-                                               ]
-
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'To',
-                                       width : 75,
-                                       renderer : function(v,x,r) { 
-                                           return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_shipto_id',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               xtype : 'TextField',
-                                               allowBlank : false,
-                                               xns : Roo.form
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Item Description',
-                                       width : 150.00,
-                                       renderer : function(v,x,r) { 
-                                       
-                                           if (r.data.coitem_memo && r.data.coitem_memo.length) {
-                                               return String.format('{0}', r.data.coitem_memo);
-                                               if (r.data.coitem_memo != v) {
-                                                   r.set('item_descrip1', r.data.coitem_memo);
-                                               }
-                                               
-                                           }
-                                           if (v && v.length > 49) {
-                                               return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
-                                           }
-                                           
-                                           return String.format('{0}', v); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'item_descrip1',
-                                       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\":\"\"}',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Status',
-                                       width : 50,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
-                                       dataIndex : 'coitem_status'
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 1,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               allowDecimals : false,
-                                               decimalPrecision : 0,
-                                               xns : Roo.form,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Qty',
-                                       width : 40,
-                                       renderer : function(v,x,r) { 
-                                           var v = parseInt(v);
-                                           //var aq = parseInt(r.data.avail_qty);
-                                           //aq = isNaN(aq) ? 0 : aq;
-                                          
-                                           var rate = _this.form.findField('taxzone_rate').getValue();
-                                           r.data.coitem_subtotal =  v * r.data.coitem_price;
-                                           r.data.coitem_subtotal_tax = v * r.data.coitem_price * ( 1 + rate * 1);
-                                           return String.format('{0}', v); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_qtyord',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 0,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               decimalPrecision : 3,
-                                               xns : Roo.form,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0.0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Sell @',
-                                       width : 70,
-                                       renderer : function(v,x,r) { 
-                                       
-                                           var rate = _this.form.findField('taxzone_rate').getValue();
-                                           r.data.coitem_subtotal = v * r.data.coitem_qtyord;
-                                           r.data.coitem_subtotal_tax = v * ( 1 + rate * 1 ) * r.data.coitem_qtyord;
-                                           r.data.coitem_price_tax = v * ( 1 + rate * 1 );
-                                           if (parseInt(v) < 1) {
-                                               return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
-                                           }
-                                           
-                                           
-                                           //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
-                                           
-                                           return  String.format('{0}', Roo.util.Format.number(v,3)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_price',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 0,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               decimalPrecision : 3,
-                                               xns : Roo.form,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0.0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       hidden : true,
-                                       xtype : 'ColumnModel',
-                                       header : 'Sell @w/GST',
-                                       width : 70,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           if (parseInt(v) < 1) {
-                                               return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
-                                           }
-                                           
-                                           return  String.format('{0}', Roo.util.Format.number(v,3)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_price_tax',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 0,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               decimalPrecision : 2,
-                                               xns : Roo.form,
-                                               maxValue : 100,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0.0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Disc%',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                       
-                                           // coitem_custprice = coitem_price * ((100 - coitem_disc)/ 100) 
-                                           
-                                           //                      12 * (( 100 - 0) / 100)
-                                           // coitem_custprice / coitem_price = ((100 - coitem_disc)/ 100) 
-                                           // 100 - ((coitem_custprice / coitem_price) * 100)  = coitem_disc
-                                           //                             100 -  97 =        100 -3 
-                                       
-                                          // r.data.coitem_linedisc = 100 - (
-                                           //           (parseFloat(r.data.coitem_custprice) /
-                                            //               parseFloat(r.data.coitem_price)
-                                              //        ) * 100.00);
-                                           var fl = parseFloat(r.data.coitem_linedisc);
-                                           if ( isNaN(fl) || fl == 0.0 || r.data.coitem_price > r.data.coitem_custprice)  {
-                                               return '';
-                                           }
-                                           return  String.format('<span style="color:green">{0}%</span>', Roo.util.Format.number( r.data.coitem_linedisc,2)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_linedisc',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 0,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               decimalPrecision : 3,
-                                               xns : Roo.form,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0.0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'List Price',
-                                       width : 70,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           var rate = _this.form.findField('taxzone_rate').getValue();
-                                           r.data.coitem_custprice_tax = v * ( 1 + rate * 1 );
-                                           
-                                           var tip = 'No WRP available';
-                                           if ((r.data.coitem_wrpprice * 1) > 0) {
-                                               tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
-                                           }
-                                           // less than zero, show as red..
-                                           if (parseFloat(v) < 1) {
-                                               return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
-                                                   Roo.util.Format.number(v,3), tip); 
-                                           }
-                                           if (r.data.customer_price_each != v) {
-                                                 return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
-                                                   Roo.util.Format.number(v,3), 
-                                                   "List Price = " +  Roo.util.Format.number(r.data.customer_price_each,3)
-                                               ); 
-                                           }
-                                           
-                                           
-                                           
-                                           //r.data.coitem_subtotal = v * r.data.coitem_qtyord;
-                                           
-                                           //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
-                                           
-                                           return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_custprice',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               minValue : 0,
-                                               style : 'text-align:right',
-                                               xtype : 'NumberField',
-                                               decimalPrecision : 3,
-                                               xns : Roo.form,
-                                               listeners : {
-                                                       focus : function (_self)
-                                                          {
-                                                              if (this.value == 0.0) {
-                                                                  this.el.dom.value = '';
-                                                              }
-                                                          }
-                                               }
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       hidden : true,
-                                       xtype : 'ColumnModel',
-                                       header : 'List Price w/GST',
-                                       width : 70,
-                                       renderer : function(v,x,r) { 
-                                           var rate = _this.form.findField('taxzone_rate').getValue();
-                                           var tip = 'No WRP available';
-                                           if ((r.data.coitem_wrpprice * 1) > 0) {
-                                               tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
-                                           }
-                                           
-                                           if (parseFloat(v) < 1) {
-                                               return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
-                                                   Roo.util.Format.number(v,3), tip); 
-                                           }
-                                           if (r.data.customer_price_each != v) {
-                                                 return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
-                                                   Roo.util.Format.number(v,3), 
-                                                   "List Price = " +  Roo.util.Format.number(r.data.customer_price_each * ( 1 + rate * 1 ),3)
-                                               ); 
-                                           }
-                                           
-                                           return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_custprice_tax',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'SubTotal',
-                                       width : 70,
-                                       renderer : function(v) {
-                                       
-                                           if (parseInt(v) < 1) {
-                                               return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
-                                           }
-                                       
-                                           
-                                       
-                                        return Roo.util.Format.number( v, 2);
-                                         },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_subtotal'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       hidden : true,
-                                       xtype : 'ColumnModel',
-                                       header : 'SubTotal w/GST',
-                                       width : 70,
-                                       renderer : function(v,x,r) { 
-                                          
-                                           if (parseInt(v) < 1) {
-                                               return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
-                                           }
-                                           
-                                           return  String.format('{0}', Roo.util.Format.number(v,2)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_subtotal_tax'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Unit Cost',
-                                       width : 50,
-                                       renderer : function(v) { return Roo.util.Format.number( v, 2); },
-                                       xns : Roo.grid,
-                                       builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
-                                       dataIndex : 'coitem_unitcost_in_order_cur'
-                                   },
-{
-                                       editor : {
-                                           field : {
-                                               store : {
-                                                   proxy : {
-                                                       '|xns' : 'Roo.data',
-                                                       url : baseURL + '/Roo/taxtype.php',
-                                                       xtype : 'HttpProxy',
-                                                       method : 'GET',
-                                                       xns : Roo.data
-                                                   },
-                                                   reader : {
-                                                       '|xns' : 'Roo.data',
-                                                       id : 'taxtype_id',
-                                                       root : 'data',
-                                                       xtype : 'JsonReader',
-                                                       fields : [{"name":"taxtype_id","type":"int"},"taxtype_name"],
-                                                       xns : Roo.data,
-                                                       totalProperty : 'total'
-                                                   },
-                                                   '|xns' : 'Roo.data',
-                                                   xtype : 'Store',
-                                                   remoteSort : true,
-                                                   sortInfo : { direction : 'ASC', field: 'taxtype_name' },
-                                                   xns : Roo.data,
-                                                   listeners : {
-                                                       beforeload : function (_self, o){
-                                                              o.params = o.params || {};
-                                                              // set more here
-                                                              
-                                                              
-                                                          }
-                                                   },
-                                                   items : [
-
-                                                   ]
-
-                                               },
-                                               '|xns' : 'Roo.form',
-                                               listWidth : 400,
-                                               triggerAction : 'all',
-                                               forceSelection : true,
-                                               selectOnFocus : true,
-                                               pageSize : 20,
-                                               displayField : 'taxtype_name',
-                                               emptyText : "Select Tax Type",
-                                               hiddenName : 'coitem_taxtype_id',
-                                               minChars : 2,
-                                               valueField : 'taxtype_id',
-                                               xtype : 'ComboBox',
-                                               allowBlank : false,
-                                               typeAhead : true,
-                                               editable : false,
-                                               width : 40,
-                                               xns : Roo.form,
-                                               name : 'coitem_taxtype_id_taxtype_name',
-                                               qtip : "Select taxtype",
-                                               queryParam : 'query[taxtype_id]',
-                                               tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>',
-                                               loadingText : "Searching...",
-                                               items : [
-
-                                               ]
-
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
-
-                                           ]
-
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Taxed',
-                                       width : 50,
-                                       renderer : function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'coitem_taxtype_id',
-                                       items : [
-
-                                       ]
-
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : '#avail',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                       
-                                           var oq  = parseInt(r.data.coitem_qtyord);
-                                           var aq = parseInt(r.data.avail_qty);
-                                           var sq = parseInt(r.data.coitem_qtyshipped);
-                                           aq = isNaN(aq) ? 0 : aq;
-                                           oq = isNaN(oq) ? 0 : oq;
-                                           sq = isNaN(sq) ? 0 : sq;
-                                           
-                                           var unshipped = oq - sq;
-                                           
-                                           if ( aq < 0 || (unshipped > 0  &&  aq < unshipped))  {
-                                              return String.format('<b style="color:red;">{0}</b>', parseInt(aq));
-                                           }
-                                            
-                                           return String.format('{0}', aq); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'avail_qty'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : '#reserved',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                       
-                                           
-                                           var vv = parseInt(v);
-                                           vv = isNaN(vv) ? 0 : vv;
-                                           
-                                           var ov = parseInt(r.data.coitem_qtyord);
-                                           ov = isNaN(ov) ? 0 : ov;
-                                           
-                                           var qs = parseInt(r.data.coitem_qtyshipped);
-                                           qs = isNaN(qs) ? 0 : qs;
-                                           
-                                           
-                                           
-                                           if (vv < ov) {
-                                               // not enough reserved yet.
-                                               return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv - qs);
-                                           }
-                                           
-                                           return String.format('{0}', vv -  qs); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
-                                       dataIndex : 'shipitem_shipped'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : '#shipped',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           var vv = parseInt(v);
-                                           vv = isNaN(vv) ? 0 : vv;
-                                           
-                                           var ov = parseInt(r.data.coitem_qtyord);
-                                           ov = isNaN(ov) ? 0 : ov;
-                                           
-                                       
-                                           if (vv != ov) {
-                                               // not enought shipped.
-                                               // or too many shipped.
-                                               return String.format('<b style="background-color:red;color:yellow">{0}</b>',  vv);
-                                           }
-                                       
-                                           
-                                           
-                                           return String.format('{0}', vv); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
-                                       dataIndex : 'coitem_qtyshipped'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : '#invoiced',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           var vv = parseInt(v);
-                                           vv = isNaN(vv) ? 0 : vv;
-                                           
-                                           var ov = parseInt(r.data.coitem_qtyord);
-                                           ov = isNaN(ov) ? 0 : ov;
-                                           
-                                       
-                                           if (vv !=ov) {
-                                                   return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv); 
-                                           }
-                                           return String.format('{0}', vv); 
-                                           
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'cobill_billed'
-                                   }
-                        ],
-                        listeners : {
-                               beforeedit : function (e)
-                                  {
-                                      // we can only edit if nothing is assigned to shipping or invoices..
-                                      
-                                      var rec = e.record
-                                  
-                                      if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0 || (rec.data.shipitem_shipped - rec.data.coitem_qtyshipped) > 0 ) {
-                                          Roo.MessageBox.alert("Error", "That item has been shipped, has a draft shipment  or invoices - void the shipments/invoices first");
-                                          e.cancel = true;
-                                          return;
-                                      }
-                                      
-                                      if (rec.data.coitem_subnumber * 1 > 0) {
-                                          Roo.log("Edit container event");
-                                          Roo.log(e); // if it's a tab.. 
-                                  
-                                          
-                                          switch(e.field) {
-                                              // allow editing of source / destination..
-                                              case 'coitem_shipto_id':
-                                              case 'coitem_location_src':            
-                                                  return;
-                                              default : 
-                                                  break;
-                                          }
-                                          Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
-                                          e.cancel = true;
-                                          return;
-                                      }
-                                      // zero off values..
-                                      //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
-                                      //        e.value ='';
-                                      //    }
-                                      //    if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
-                                      //        e.value ='';
-                                      //    }
-                                      
-                                      if (rec.data.item_type == 'K' && e.field == 'item_number') {
-                                          // you can not change the product type on kits' as it messing things up..
-                                          Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
-                                          e.cancel = true;
-                                          return;
-                                      }
-                                      
-                                  },
-                               render : function() 
-                                  {
-                                      _this.grid = this; 
-                                      //_this.dialog = Pman.Dialog.FILL_IN
-                                      
-                                      if (_this.panel.active) {
-                                         this.footer.onClick('first');
-                                      }
-                                  },
-                               celldblclick : function (_self, rowIndex, columnIndex, e)
-                                  {
-                                      var rec = this.ds.getAt(rowIndex);
-                                      var di = this.cm.getDataIndex(columnIndex);
-                                      if (di != 'avail_qty') {
-                                          return;
-                                      }
-                                      
-                                      Pman.Dialog.XtupleInvHistory.show({
-                                          itemsite_item_id_item_number   : rec.data.item_number,
-                                         // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
-                                          location_name : rec.data.coitem_location_src_location_name,
-                                          location_descrip : rec.data.coitem_location_src_location_descrip,
-                                          
-                                          invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
-                                      }); 
-                                      
-                                  },
-                               afteredit : function (e)
-                                  {
-                                      Roo.log('afteredit:' + e.record.data.coitem_linenumber);
-                                  
-                                      
-                                     // if ( e.record && e.record.data.coitem_id) {
-                                          // as we disable update to the display on the ajax callback to 
-                                          // allow editing flow to continue, and not refresh - we can only update
-                                          // these values after something has actually been edited.
-                                          // e.record.set('coitem_id', e.record.data.coitem_id);
-                                          // e.record.set('coitem_status', e.record.data.coitem_status);
-                                     // }
-                                      
-                                      if (e.field == 'item_number' || e.originalValue == e.value) {
-                                          // afterselect handles this...
-                                          return;
-                                      }
-                                      if (e.field == 'item_descrip1') {
-                                          e.record.set('coitem_memo', e.value);
-                                      }
-                                      var rate = _this.form.findField('taxzone_rate').getValue();
-                                      switch(e.field) {
-                                          case 'coitem_linedisc':
-                                             
-                                              var cp = parseFloat(e.record.data.coitem_custprice);
-                                             
-                                              if (isNaN(cp) || cp == 0.0) {
-                                                  break;
-                                              }
-                                              
-                                              var dis = parseFloat(e.value);
-                                             
-                                              if (isNaN(dis)) {
-                                                  break;
-                                              }
-                                              
-                                              e.record.set(
-                                                  'coitem_price',
-                                                  Math.max(0,cp * ((100.0 -  parseInt(e.value))/ 100.0) )  
-                                              );
-                                              
-                                             // donot need to set the subtotal here, coz we will render it automatically
-                                             // e.record.set(
-                                             //     'coitem_subtotal',
-                                             //      e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
-                                             // );
-                                              break;
-                                          
-                                          case  'coitem_price': // SELL@ price
-                                  
-                                               var cp = parseFloat(e.record.data.coitem_custprice);
-                                               // list price is < price -- update it..
-                                               if (isNaN(cp) || cp == 0.0 || cp < e.value) {
-                                                  e.record.set('coitem_custprice', e.value);
-                                                  cp = e.value;
-                                               }
-                                               // update the discount calc.
-                                               
-                                               e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( e.value / cp) * 100.0)));  
-                                               
-                                               // donot need to set the subtotal here, coz we will render it automatically
-                                               //e.record.set(
-                                               //   'coitem_subtotal',
-                                                //   e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
-                                               //);
-                                               break;
-                                          
-                                          case 'coitem_custprice':
-                                              // modified customer price...
-                                              // just modify the discount.. -- leave the entered price the same..
-                                                var sp =  parseFloat(e.record.data.coitem_price);
-                                                var cp = parseFloat(e.value);
-                                                if (isNaN(cp) || cp == 0.0 || cp < e.value) {
-                                                      break;
-                                                }
-                                                
-                                               e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
-                                               
-                                               break;
-                                               
-                                          case 'coitem_custprice_tax':
-                                                var cp = parseFloat(e.value / ( 1 + rate * 1 ));
-                                                var sp =  parseFloat(e.record.data.coitem_price);
-                                                
-                                                if (isNaN(cp) || cp == 0.0) {
-                                                      break;
-                                                }
-                                                e.record.set('coitem_custprice', cp);
-                                                e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
-                                               
-                                               break; 
-                                               
-                                           case  'coitem_price_tax':
-                                  
-                                               var cp = parseFloat(e.record.data.coitem_custprice);
-                                               var sp = parseFloat(e.value / ( 1 + rate * 1 ));
-                                               if (isNaN(cp) || cp == 0.0 || cp < sp) {
-                                                  e.record.set('coitem_custprice', sp);
-                                                  cp = sp;
-                                               }
-                                               e.record.set('coitem_price', sp);
-                                               e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
-                                               
-                                               break;
-                                        
-                                      }
-                                      
-                                       
-                                      
-                                      
-                                      var doupdate = function() { 
-                                         if (!e.record.updatePending) {
-                                              Roo.log('doupdate...'  + e.record.data.coitem_linenumber);
-                                              Roo.log(e.record);
-                                              e.record.commit();
-                                              return;
-                                          }
-                                         Roo.log('doupdate pending...'   + e.record.data.coitem_linenumber);
-                                          // wait until it's not peding an update..
-                                          doupdate.defer(500);
-                                      }
-                                  
-                                      if(e.record.data.coitem_id * 1 < 1 && !e.record.isInserting){ // insert
-                                          e.record.isInserting = 1;
-                                          e.record.isUpdating = 0;
-                                          doupdate();
-                                          return;
-                                      }
-                                      
-                                      // update
-                                      if(!e.record.isInserting && !e.record.isUpdating){
-                                          e.record.isUpdating = 1;
-                                          doupdate();
-                                          return;
-                                      }
-                                      
-                                      if(!e.record.updatePending){
-                                          e.record.updatePending = 1;
-                                          doupdate();
-                                          return;
-                                      }
-                                      Roo.log("got to end without doing an update?"  + e.record.data.coitem_linenumber);
-                                      
-                                  },
-                               rowclass : function (gridview, rowcfg)
-                                  {
-                                      if (rowcfg.record.data.coitem_status == 'C' &&
-                                          rowcfg.record.data.shipitem_shipped * 1 < 1) {
-                                          
-                                          rowcfg.rowClass = 'strikethrough';
-                                      }
-                                       if (rowcfg.record.data.coitem_status == 'X'  ) {
-                                          
-                                          rowcfg.rowClass = 'strikethrough';
-                                      }
-                                      
-                                      if (!rowcfg.record.data.coitem_id) { 
-                                              rowcfg.rowClass = 'dragon-not-saved';
-                                      }
-                                      
-                                      
-                                     // Roo.log(rowcfg);
-                                  //    shipitem_shipped
-                                  }
-                        },
-                        items : [
-
-                        ]
-
-                    },
-                    '|xns' : 'Roo',
-                    fitToframe : true,
-                    background : true,
-                    region : 'center',
-                    title : "Order Items",
-                    xtype : 'GridPanel',
-                    fitContainer : true,
-                    xns : Roo,
-                    tableName : 'coitem',
-                    listeners : {
-                       deactivate : function (_self)
-                          {
-                              if(_this.grid){
-                                  _this.grid.stopEditing();
-                              }
-                          },
-                       activate : function() {
-                              _this.panel = this;
-                              
-                              try { if (MODULE.isBuilder) {
-                                  return;
-                              } } catch(e) { }
-                              
-                              var id = _this.form.findField('cohead_id').getValue() * 1;
-                              if (id < 1) {
-                                  Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
-                                  _this.dialog.layout.getRegion('center').showPanel(0);
-                                  return;
-                              }
-                              
-                              if (_this.grid) {
-                                  _this.grid.footer.onClick('first');
-                              
-                                   //if (_this.form.findField('cohead_cust_id_cust_name').getValue() == 'Bloom and Grow HK') {
-                                   //   _this.xferAll.show();
-                                  // 
-                                  // } else {
-                                  //     _this.xferAll.hide();
-                                  // }
-                               }
-                              
-                          }
-                    },
-                    items : [
-
-                    ]
-
+                        }
+                        
+                    }
+                  }
+                 }
+                ]
+               },
+               {
+                allowBlank : false,
+                alwaysQuery : true,
+                displayField : 'cntct_name',
+                editable : true,
+                emptyText : _this._strings['5f0c1431b38e3d279bf105d48824b7f3'] /* Select ship to */,
+                fieldLabel : _this._strings['74002cb040b036511b8d031da591364a'] /* Ship to */,
+                forceSelection : true,
+                hiddenName : 'cohead_shipto_cntct_id',
+                listWidth : 400,
+                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+                minChars : 2,
+                name : 'cohead_shipto_cntct_id_cntct_name',
+                pageSize : 20,
+                qtip : _this._strings['acc95aeaee48871da70cc3bce664728c'] /* Select shiptoinfo */,
+                queryParam : 'query[cntct_name]',
+                selectOnFocus : true,
+                tpl : '<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>',
+                triggerAction : 'all',
+                typeAhead : true,
+                valueField : 'cntct_id',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'ComboBox',
+                listeners : {
+                 add : function (combo)
+                  {
+                   Pman.Dialog.XtupleQuickContact.show( 
+                              {
+                                _id : id,
+                                customer_id : _this.form.findField('cohead_cust_id').getValue()
+                              },
+                              
+                              function (data) {
+                                 
+                                  for(var i in  data) {
+                                      
+                                      _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
+                                  }
+                                  
+                                  _this.form.findField('shipto_address').update();
+                                  // fill in the select box..
+                                  _this.form.setValues( {
+                                      cohead_shipto_cntct_id : data.cntct_id,
+                                      cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
+                                              data.cntct_last_name
+                                      
+                                  });
+                              }
+                          ); 
+                  },
+                 beforeselect : function (combo, record, index)
+                  {
+                     
+                      // just add everything...
+                      for(var i in record.data) {
+                          //Roo.log('cohead_shipto_cntct_id_' + i +' ='  + record.data[i]);
+                          _this.data['cohead_shipto_cntct_id_' + i] = record.data[i];
+                      }
+                  
+                      _this.form.findField('shipto_address').update();
+                      
+                   
+                  }
                 },
-               {
-                    layout : {
-                        center : {
-                            '|xns' : 'Roo',
-                            xtype : 'LayoutRegion',
-                            xns : Roo,
-                            titlebar : true
-                        },
-                        north : {
-                            '|xns' : 'Roo',
-                            title : "Reserve Stock / Shipments",
-                            xtype : 'LayoutRegion',
-                            xns : Roo,
-                            height : 250
-                        },
-                        '|xns' : 'Roo',
-                        xtype : 'BorderLayout',
-                        xns : Roo,
-                        items : [
-                               {
-                                grid : {
-                                    sm : {
-                                        '|xns' : 'Roo.grid',
-                                        xtype : 'RowSelectionModel',
-                                        singleSelect : true,
-                                        xns : Roo.grid
-                                    },
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/shiphead.php',
-                                            method : 'GET',
-                                            xtype : 'HttpProxy',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            xns : Roo.data,
-                                            fields : [
-                                                {
-                                                    'name': 'shiphead_number',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'shiphead_shipvia',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'shiphead_shipdate',
-                                                    'type': 'date'
-                                                },
-                                                {
-                                                    'name': 'shiphead_sfstatus'
-                                                },
-                                                {
-                                                    'name': 'shiphead_tracknum',
-                                                    'type': 'string'
-                                                }
-                                            ],
-                                            totalProperty : 'total',
-                                            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\"}'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        remoteSort : true,
-                                        xtype : 'Store',
-                                        sortInfo : { field : 'shiphead_shipvia', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        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\"}',
-                                        listeners : {
-                                               beforeload : function (_self, options)
-                                                  {
-                                                       options.params = options.params || {};
-                                                       options.params.shiphead_order_id = _this.form.findField('cohead_id').getValue() * 1;
-                                                      if (options.params.shiphead_order_id < 1) {
-                                                          return false;
-                                                      }
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    toolbar : {
-                                        '|xns' : 'Roo',
-                                        xtype : 'Toolbar',
-                                        xns : Roo,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Confirm Shipment",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/lock.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function()
-                                                          {
-                                                               var sel  = _this.shipgrid.getSelectionModel().getSelected();
-                                                              if (!sel) {
-                                                                  Roo.MessageBox.alert("Error", "Select a shipment");
-                                                                  return;
-                                                              }
-                                                              if (sel.data.shiphead_shipped) {
-                                                                  Roo.MessageBox.alert("Error", "Shipment is already confirmed");
-                                                                  return;
-                                                              }
-                                                              
-                                                              
-                                                              // check current status of shipment..
-                                                              
-                                                                  
-                                                              new Pman.Request({ 
-                                                                     mask : 'Sending',
-                                                                  url : baseURL + '/Roo/shiphead',
-                                                                  method : 'POST',
-                                                                  timeout : 90000,
-                                                                  params : {
-                                                                      shiphead_id : sel.data.shiphead_id,
-                                                                      _confirm : 1
-                                                                  },
-                                                                  success : function() {
-                                                                      _this.shipgrid.ds.load({});
-                                                                  }
-                                                              });
-                                                                   
-                                                               
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Download (as xls)",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/save.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function()
-                                                          {
-                                                               var sel  = _this.shipgrid.getSelectionModel().getSelected();
-                                                              if (!sel) {
-                                                                  Roo.MessageBox.alert("Error", "Select a shipment");
-                                                                  return;
-                                                              }
-                                                          
-                                                              
-                                                              // check current status of shipment..
-                                                              
-                                                                  
-                                                             new Pman.Download({
-                                                                  url : baseURL + '/Roo/shiphead',
-                                                                  method : 'GET',
-                                                                  params : {
-                                                                     _download :sel.data.shiphead_id
-                                                                       
-                                                                  }
-                                                              });
-                                                                   
-                                                               
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Print Picking Slip",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/pdf.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function ()
-                                                          {
-                                                              var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
-                                                              if (!sel) {\r
-                                                                  Roo.MessageBox.alert("Error", "Select a shipment");\r
-                                                                  return;\r
-                                                              }\r
-                                                              // check current status of shipment..
-                                                           
-                                                                  new Pman.Download({
-                                                                      url : baseURL + '/Xtuple/Print',
-                                                                      method : 'GET',
-                                                                      params : {
-                                                                          template : 'picking-slip',
-                                                                          param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
-                                                                          filename : 'picking-slip-' + sel.data.shiphead_number
-                                                                      },
-                                                                      success : function() {
-                                                          
-                                                                      }
-                                                                  })
-                                                                      
-                                                                      
-                                                             
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Print Delivery Note",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/pdf.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function ()
-                                                          {
-                                                              var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
-                                                              if (!sel) {\r
-                                                                  Roo.MessageBox.alert("Error", "Select a shipment");\r
-                                                                  return;\r
-                                                              }\r
-                                                              // check current status of shipment..
-                                                          
-                                                                  new Pman.Download({
-                                                                      url : baseURL + '/Xtuple/Print',
-                                                                      method : 'GET',
-                                                                      params : {
-                                                                          template : 'delivery-note-',
-                                                                          param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
-                                                                          filename : 'delivery-note-' + sel.data.shiphead_number
-                                                                      },
-                                                                      success : function() {
-                                                          
-                                                                      }
-                                                                  })
-                                                                      
-                                                                      
-                                                             
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Send Delivery Email",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : Roo.rootURL + 'images/default/dd/email.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function()
-                                                          {
-                                                              var s = _this.shipgrid.getSelectionModel().getSelected();
-                                                              
-                                                              if(!s || s.data.shiphead_id * 1 < 1){
-                                                                  Roo.MessageBox.alert('Error', 'Please select a shipment');
-                                                                  return;
-                                                              }
-                                                              
-                                                              new Pman.Request({
-                                                                  method: 'POST',
-                                                                  url: baseURL+ '/Roo/shiphead',
-                                                                  params : {
-                                                                      shiphead_id : s.data.shiphead_id,
-                                                                      _send_delivery : 1
-                                                                  },
-                                                                  success : function() {
-                                                                      Roo.MessageBox.alert('Notice', 'SENT');
-                                                                  }
-                                                              });
-                                                              
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                xtype : 'Fill',
-                                                xns : Roo.Toolbar
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Add",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function()
-                                                          {   
-                                                              if (!_this.form.findField('cohead_id').getValue()) {
-                                                                  Roo.MessageBox.alert("Error", "Save Order first");
-                                                                  return;
-                                                              }
-                                                              var rv = _this.form.getFieldValues();
-                                                              
-                                                              Pman.Dialog.XtupleShipmentNew.show({
-                                                                      shiphead_order_id : rv.cohead_id,
-                                                                      shiphead_shipdate :  _this.form.findField('cohead_targetdate').getValue().format('Y-m-d')
-                                                                  },
-                                                                  function() { 
-                                                                       _this.shipgrid.ds.load({});
-                                                                  }
-                                                              );
-                                                          },
-                                                       render : function (_self)
-                                                          {
-                                                            _this.addShipmentBtn = _self;
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Void / Unconfirm",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/trash.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function()
-                                                          {
-                                                              var sel  = _this.shipgrid.getSelectionModel().getSelected();
-                                                              if (!sel) {
-                                                                  Roo.MessageBox.alert("Error", "Select a shipment");
-                                                                  return;
-                                                              }
-                                                              // check current status of shipment..
-                                                              
-                                                              var msg = sel.data.shiphead_shipped ? 
-                                                                  "Are you sure you want to un-confirm that shipment? - It will remove items from unposted invoices" : 
-                                                                  "Are you sure you want to void that shipment?";
-                                                              
-                                                              Roo.MessageBox.confirm("Are you sure", msg,
-                                                                  function(r) {
-                                                                      if (r != 'yes') {
-                                                                          return;
-                                                                      }
-                                                                      new Pman.Request({
-                                                                          mask : 'Sending',
-                                                                           timeout : 90000,
-                                                                          url : baseURL + '/Roo/shiphead',
-                                                                          method : 'POST',
-                                                                          
-                                                                          params : {
-                                                                              shiphead_id : sel.data.shiphead_id,
-                                                                              _void : 1
-                                                                          },
-                                                                          success : function() {
-                                                                              _this.shipgrid.ds.load({});
-                                                                          }
-                                                                      })
-                                                                      
-                                                                  }
-                                                              );
-                                                                      
-                                                                      
-                                                              
-                                                              
-                                                              
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'shiphead_shipvia',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    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\"}',
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'number',
-                                               width : 80,
-                                               renderer : function(v,x,r) {
-                                                   if (r.json.shiphead_shipdate.length) {
-                                                        return String.format('{0}', v); 
-                                                    }
-                                                    return String.format('<s>{0}</s>', v); 
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'shiphead_number',
-                                               builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'From Location',
-                                               width : 100,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'shiphead_location_id_location_name'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Ship to',
-                                               width : 100,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'shiphead_shipto_id_shipto_name'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'shipdate',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
-                                               xns : Roo.grid,
-                                               builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
-                                               dataIndex : 'shiphead_shipdate'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Status',
-                                               width : 50,
-                                               renderer : function(v,x,r) { 
-                                               
-                                               
-                                               
-                                                 
-                                                   if (r.json.shiphead_shipdate.length) {
-                                                   
-                                                       if (r.json.shiphead_shipped) {
-                                                           return "Confirmed";
-                                                       }
-                                                   
-                                                        return '<span style="color:red">Draft</span>';
-                                                   }
-                                                    
-                                                   return 'VOID';
-                                                  
-                                               
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'shiphead_sfstatus',
-                                               builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'shipvia',
-                                               width : 200,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}',
-                                               dataIndex : 'shiphead_shipvia'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'tracknum',
-                                               width : 200,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
-                                               dataIndex : 'shiphead_tracknum'
-                                           }
-                                    ],
-                                    listeners : {
-                                       rowdblclick : function (_self, rowIndex, e)
-                                          {
-                                              var rec = this.ds.getAt(rowIndex);
-                                              if (!rec.json.shiphead_shipdate.length) {
-                                                   Roo.MessageBox.alert("Error", "You can not edit voided shipments, create a new one, and use the restore feature");
-                                                   return;
-                                               }
-                                          
-                                             Pman.Dialog.XtupleShipment.show({
-                                                  shiphead_id : rec.data.shiphead_id
-                                          
-                                              }, function() {
-                                                  _self.ds.load({});
-                                              
-                                              });
-                                             
-                                          },
-                                       render : function() 
-                                          {
-                                              _this.shipgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.shippanel.active) {
-                                                 this.ds.load({});
-                                              }
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                background : false,
-                                fitToframe : true,
-                                region : 'north',
-                                title : "shiphead",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                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\"}',
-                                tableName : 'shiphead',
-                                listeners : {
-                                       activate : function() {
-                                              _this.shippanel = this;
-                                              if (_this.shipgrid) {
-                                                  _this.shipgrid.ds.load({});
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
-                            },
-                               {
-                                grid : {
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/cobmisc.php',
-                                            xtype : 'HttpProxy',
-                                            method : 'GET',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            fields : [
-                                                {
-                                                    'name': 'invchead_invcnumber',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invchead_invcdate',
-                                                    'type': 'date'
-                                                }
-                                            ],
-                                            xns : Roo.data,
-                                            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\"}',
-                                            totalProperty : 'total'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        xtype : 'Store',
-                                        remoteSort : true,
-                                        sortInfo : { field : 'invchead_invcnumber', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        listeners : {
-                                               beforeload : function (_self, options)
-                                                  {
-                                                  
-                                                      options.params = options.params || {};
-                                                      options.params.cobmisc_cohead_id = _this.form.findField('cohead_id').getValue() * 1;
-                                                      if (options.params.cobmisc_cohead_id < 1) {
-                                                          return false;
-                                                      }
-                                                      
-                                                      options.params._with_other_payment = 1;
-                                                      //options.params['query[invchead_ordernumber]']  = _this.form.findField('cohead_number').getValue()
-                                                      
-                                                  },
-                                               load : function (_self, records, options)
-                                                  {
-                                                      var total = 0;
-                                                      var done = 0;
-                                                      var totalic = 0.0;
-                                                      var totalfreight = 0.0;    
-                                                      var totalmisc = 0.0;        
-                                                      var totaltax = 0.0;        
-                                                     
-                                                      Roo.each(records, function(r)
-                                                      {
-                                                          if(r.data.cobmisc_id > 1){
-                                                              done += parseInt(r.data.cobmisc_qty);
-                                                              totalic += parseFloat(r.data.cobmisc_itemcost).toFixed(2)*1;        
-                                                              totalmisc += parseFloat(r.data.cobmisc_misc).toFixed(2)*1;        
-                                                              totalfreight += parseFloat(r.data.cobmisc_freight).toFixed(2)*1;                
-                                                              totaltax += parseFloat(r.data.cobmisc_tax).toFixed(2)*1;                
-                                                              total = parseInt(r.data.cobmisc_total_qty);
-                                                          }
-                                                         
-                                                      });
-                                                      
-                                                      _this.shipinvtab.layout.getRegion('center').getPanel(0).setTitle(
-                                                          (total == done) ?
-                                                               "Invoices (Complete)" : 
-                                                              ("Invoices prepared for " +    done + '/' + total)
-                                                      );
-                                                  
-                                                      
-                                                      var frtotal = (parseFloat(_this.form.findField('cohead_freight').getValue())  - totalfreight).toFixed(2);
-                                                      var misctotal = (parseFloat(_this.form.findField('cohead_misc').getValue()) - totalmisc).toFixed(2);
-                                                      var ictotal =  (parseFloat(_this.form.findField('cohead_subtotal').getValue()) - totalic).toFixed(2);
-                                                      var taxtotal =  (parseFloat(_this.form.findField('cohead_tax').getValue())  - totaltax).toFixed(2);
-                                                      var remtotal = frtotal*1 + misctotal*1 + ictotal*1 + taxtotal*1;
-                                                      
-                                                      var nr = this.reader.newRow({
-                                                          cobmisc_id : -1,
-                                                          cobmisc_invchead_id_invchead_invcnumber : "Total Remaining",
-                                                          cobmisc_qty : total - done,
-                                                          cobmisc_freight :frtotal,
-                                                          cobmisc_misc : misctotal,        
-                                                          cobmisc_itemcost  : ictotal,             
-                                                          cobmisc_tax : taxtotal,
-                                                          cobmisc_total : remtotal
-                                                  
-                                                          
-                                                      });
-                                                      // do we need to add it somehow??
-                                                      _this.invgrid.ds.add(nr);
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    toolbar : {
-                                        '|xns' : 'Roo',
-                                        xtype : 'Toolbar',
-                                        xns : Roo,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Post Invoice",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/lock.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function ()
-                                                          {
-                                                          
-                                                               var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                              if (!sel) {
-                                                                  Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                  return;
-                                                              }
-                                                              // check current status of shipment..
-                                                              
-                                                              Roo.MessageBox.confirm("Are you sure", "Are you sure you want to Post that invoice?",
-                                                                  function(r) {
-                                                                      if (r != 'yes') {
-                                                                          return;
-                                                                      }
-                                                                      new Pman.Request({
-                                                                         mask : 'Sending',
-                                                                          url : baseURL + '/Roo/cobmisc',
-                                                                          method : 'POST',
-                                                                          params : {
-                                                                              cobmisc_id : sel.data.cobmisc_id,
-                                                                              _post : 1
-                                                                          },
-                                                                          success : function() {
-                                                                              _this.invgrid.ds.load({});
-                                                                          }
-                                                                      })
-                                                                      
-                                                                  }
-                                                              );
-                                                                      
-                                                                      
-                                                             
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                menu : {
-                                                    '|xns' : 'Roo.menu',
-                                                    xtype : 'Menu',
-                                                    xns : Roo.menu,
-                                                    items : [
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Print Standard Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function ()
-                                                                  {
-                                                                  
-                                                                       var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                                  _print : 1
-                                                                              },
-                                                                              success : function() {
-                                                                  
-                                                                              }
-                                                                          })
-                                                                              
-                                                                              
-                                                                     
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
-                                                            text : "Print Chinese Invoice With GST in line item",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                  
-                                                                       var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                                  _print : 'cn'
-                                                                                  
-                                                                              },
-                                                                              success : function() {
-                                                                  
-                                                                              }
-                                                                          })
-                                                                              
-                                                                            
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
-                                                            text : "Print Chinese Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                  
-                                                                       var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                                  _print : 'cn-gst'
-                                                                                  
-                                                                              },
-                                                                              success : function() {
-                                                                  
-                                                                              }
-                                                                          })
-                                                                              
-                                                                            
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !(baseURL.match(/au\.php$/)),
-                                                            text : "Print Aus - GST included Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                  
-                                                                       var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                                  _print : 'au-gst'
-                                                                                  
-                                                                              },
-                                                                              success : function() {
-                                                                  
-                                                                              }
-                                                                          })
-                                                                              
-                                                                            
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !(baseURL.match(/au\.php$/)),
-                                                            text : "Print Bambini Pronto Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                    var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                  
-                                                                                  _print : 'au-net',
-                                                                                 ts: Math.random()
-                                                                              }
-                                                                          })
-                                                                  
-                                                                  
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !(baseURL.match(/au\.php$/)),
-                                                            text : "Print Bambini Pro Forma Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                  
-                                                                       var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if (!sel.data.cobmisc_invchead_id) {
-                                                                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
-                                                                          return;
-                                                                      }
-                                                                      // check current status of shipment..
-                                                                  
-                                                                          new Pman.Download({
-                                                                              url : baseURL + '/Roo/invchead',
-                                                                              method : 'GET',
-                                                                              params : {
-                                                                                  invchead_id : sel.data.cobmisc_invchead_id,
-                                                                                  _print : 'au-proforma'
-                                                                                  
-                                                                              },
-                                                                              success : function() {
-                                                                  
-                                                                              }
-                                                                          })
-                                                                              
-                                                                            
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            hidden : !( baseURL.match(/au\.php$/)),
-                                                            text : "Print Shipping / Commercial Invoice",
-                                                            xtype : 'Item',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function (_self, e)
-                                                                  {
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      Pman.Dialog.XtupleDiscountOfInvoice.show({invchead_id : sel.data.cobmisc_invchead_id}, function(){
-                                                                  
-                                                                      });
-                                                                  }
-                                                            }
-                                                        }
-                                                    ]
-
-                                                },
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Print",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/pdf.gif',
-                                                xns : Roo.Toolbar,
-                                                items : [
-
-                                                ]
-
-                                            },
-                                               {
-                                                menu : {
-                                                    '|xns' : 'Roo.menu',
-                                                    xtype : 'Menu',
-                                                    xns : Roo.menu,
-                                                    items : [
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Receive Payment",
-                                                            xtype : 'Item',
-                                                            cls : 'x-btn-text-icon',
-                                                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function(_self,e)
-                                                                      {
-                                                                      
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel || sel.data.cobmisc_id < 1) {
-                                                                          Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                          return;
-                                                                      }
-                                                                      if(!sel.data.cobmisc_posted){
-                                                                          Roo.MessageBox.alert("Error", "This invoice has not been posted!");
-                                                                          return;
-                                                                      }
-                                                                      if(sel.data.cobmisc_outstanding == 0){
-                                                                          Roo.MessageBox.alert("Error", "There is no any outstanding of this invoice!");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      var cust_id = _this.form.findField('cohead_cust_id').getValue();
-                                                                      if(!cust_id){
-                                                                          return;
-                                                                      }
-                                                                      var data = {
-                                                                          cashrcpt_amount : sel.data.cobmisc_outstanding,
-                                                                          cashrcpt_cust_id : cust_id,
-                                                                          cashrcpt_aropen_id : sel.data.cobmisc_aropen_id_aropen_id,
-                                                                          cashrcpt_distdate : new Date(),
-                                                                          cashrcpt_fundstype : 'C',
-                                                                          cashrcpt_curr_id : sel.data.cobmisc_curr_id_curr_id,
-                                                                          cashrcpt_curr_id_curr_name : sel.data.cobmisc_curr_id_curr_name,
-                                                                          cashrcpt_usecustdeposit : true,
-                                                                          cashrcpt_docdate : new Date(),
-                                                                          cashrcpt_salescat_id : -1,
-                                                                          cashrcpt_applydate : new Date(),
-                                                                          cashrcpt_discount : 0
-                                                                      };
-                                                                      Pman.Dialog.XtupleReceivePayment.show( data , function() {
-                                                                          _this.invgrid.ds.load({});
-                                                                      }); 
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Issue Refund",
-                                                            xtype : 'Item',
-                                                            cls : 'x-btn-text-icon',
-                                                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function(_self,e)
-                                                                  {
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
-                                                                          Roo.MessageBox.alert("Error", "Select a credit memo");
-                                                                          return;
-                                                                      }
-                                                                      if(!sel.data.cobmisc_posted){
-                                                                          Roo.MessageBox.alert("Error", "The invoice that credit memo has been applied to has been not posted");
-                                                                          return;
-                                                                      }
-                                                                      var cust_id = _this.form.findField('cohead_cust_id').getValue();
-                                                                      if(!cust_id){
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      if(!sel.data.cobmisc_outstanding || sel.data.cobmisc_outstanding == 0){
-                                                                          Roo.MessageBox.alert("Error", "The amount of this credit memo is 0!");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      var d = _this.form.getFieldValues();
-                                                                      
-                                                                      var data = {
-                                                                          'checkhead_recip_id' : cust_id,
-                                                                          'checkhead_recip_type' : 'C',
-                                                                          'checkhead_checkdate' : new Date(),
-                                                                          'checkhead_amount' : sel.data.cobmisc_outstanding,
-                                                                          'remaining_total' : sel.data.cobmisc_outstanding,
-                                                                          'checkhead_curr_id' : d.cohead_curr_id,
-                                                                          'checkhead_curr_id_curr_name' : d.cohead_curr_id_curr_name,
-                                                                          'checkhead_misc' : true,
-                                                                          'aropen_id' : sel.data.cobmisc_cobapply_aropen_id,
-                                                                       'cmhead_number' : sel.data.cobmisc_invchead_id_invchead_invcnumber,
-                                                                       'cust_name' : d.cohead_cust_id_cust_name,
-                                                                       '_create_and_post' : 1
-                                                                  
-                                                                      };
-                                                                      
-                                                                      
-                                                                      Pman.Dialog.XtupleMiscellaneousCheck.show( data , function() {
-                                                                          _this.invgrid.ds.load({});
-                                                                     }); 
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            xtype : 'Separator',
-                                                            xns : Roo.menu
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Void Payment",
-                                                            xtype : 'Item',
-                                                            cls : 'x-btn-text-icon',
-                                                            icon : rootURL + '/Pman/templates/images/trash.gif',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function(_self,e)
-                                                                  {
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel || sel.data.cobmisc_cashrcpt_id * 1 < 1) {
-                                                                          Roo.MessageBox.alert("Error", "Select a Receive Payment");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      Roo.MessageBox.confirm("Confirm", "Voiding receipt will mean you will have to re-enter the receipt refund - " + 
-                                                                                      "please take note of the details so you can enter it again correctly later.", function(r) {
-                                                                                              
-                                                                          if (r !='yes') {
-                                                                              return;
-                                                                          }
-                                                                          new Pman.Request({
-                                                                              url : baseURL + '/Roo/cashrcpt',
-                                                                              method : 'POST',
-                                                                              params : {
-                                                                                  cashrcpt_id : sel.data.cobmisc_cashrcpt_id,
-                                                                                  _void : 1
-                                                                              },
-                                                                              success : function() 
-                                                                              {
-                                                                                  _this.invgrid.ds.load({});
-                                                                              
-                                                                              }
-                                                                          });
-                                                                      
-                                                                     })
-                                                                      
-                                                                       
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Void Refund",
-                                                            xtype : 'Item',
-                                                            cls : 'x-btn-text-icon',
-                                                            icon : rootURL + '/Pman/templates/images/trash.gif',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function(_self,e)
-                                                                  {
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel || sel.data.cobmisc_checkhead_id * 1 < 1) {
-                                                                          Roo.MessageBox.alert("Error", "Select a Miscellaneours Check");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      Roo.MessageBox.confirm("Confirm", "Voiding refund will mean you will have to re-enter the receipt refund - " + 
-                                                                                      "please take note of the details so you can enter it again correctly later.", function(r) {
-                                                                                              
-                                                                          if (r !='yes') {
-                                                                              return;
-                                                                          }
-                                                                          new Pman.Request({
-                                                                              url : baseURL + '/Roo/checkhead',
-                                                                              method : 'POST',
-                                                                              params : {
-                                                                                  checkhead_id : sel.data.cobmisc_checkhead_id,
-                                                                                  _voidPosted : 1
-                                                                              },
-                                                                              success : function() 
-                                                                              {
-                                                                                  _this.invgrid.ds.load({});
-                                                                              
-                                                                              }
-                                                                          });
-                                                                      
-                                                                     })
-                                                                      
-                                                                       
-                                                                  }
-                                                            }
-                                                        },
-                                                       {
-                                                            '|xns' : 'Roo.menu',
-                                                            text : "Void Credit Memo",
-                                                            xtype : 'Item',
-                                                            cls : 'x-btn-text-icon',
-                                                            icon : rootURL + '/Pman/templates/images/trash.gif',
-                                                            xns : Roo.menu,
-                                                            listeners : {
-                                                               click : function(_self,e)
-                                                                  {
-                                                                      var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                                      if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
-                                                                          Roo.MessageBox.alert("Error", "Select a credit memo");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      if(sel.data.cobmisc_posted){
-                                                                          Roo.MessageBox.alert("Error", "You cann't void this credit memo, since the invoice that credit memo has been applied to has been posted");
-                                                                          return;
-                                                                      }
-                                                                      
-                                                                      if (sel.data.cobmisc_cobapply_id < 1) {
-                                                                          Roo.MessageBox.alert("Error", "invaild credit memo");
-                                                                          return;
-                                                                      }
-                                                                      Roo.MessageBox.confirm("Confirm", "Are you sure want to void this applied credit memo, " + 
-                                                                                  "it will also void all the check that belongs to this credit memo ", function(r) {
-                                                                                              
-                                                                          if (r !='yes') {
-                                                                              return;
-                                                                          }
-                                                                          new Pman.Request({
-                                                                              url : baseURL + '/Roo/cobapply',
-                                                                              method : 'POST',
-                                                                              params : {
-                                                                                  _delete : sel.data.cobmisc_cobapply_id,
-                                                                                  _void : 1
-                                                                              },
-                                                                              success : function() 
-                                                                              {
-                                                                                  _this.invgrid.ds.load({});
-                                                                              
-                                                                              }
-                                                                          });
-                                                                      
-                                                                     })
-                                                                       
-                                                                  }
-                                                            }
-                                                        }
-                                                    ]
-
-                                                },
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Payments / Refunds / Credit Memos",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                                xns : Roo.Toolbar,
-                                                items : [
-
-                                                ]
-
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                xtype : 'Fill',
-                                                xns : Roo.Toolbar
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Add",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function ()
-                                                          {
-                                                          
-                                                              if (!_this.form.findField('cohead_id').getValue()) {
-                                                                  Roo.MessageBox.alert("Error", "Save Order first");
-                                                                  return;
-                                                              }
-                                                              
-                                                              var rv = _this.form.getFieldValues();
-                                                              
-                                                             
-                                                             Pman.Dialog.XtupleInvoice.show({
-                                                                  cobmisc_cohead_id : rv.cohead_id,
-                                                                  cobmisc_shipdate :  _this.form.findField('cohead_targetdate').getValue(),
-                                                                  cobmisc_invcdate :  _this.form.findField('cohead_targetdate').getValue(),
-                                                                  cobmisc_curr_id : rv.cohead_curr_id,
-                                                                  cobmisc_curr_id_curr_name : rv.cohead_curr_id_curr_name,
-                                                                  // below parms for add credit memo
-                                                                  cmdata : {
-                                                                      cm_cust_id : rv.cohead_cust_id,
-                                                                      cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
-                                                                      cm_curr_id : rv.cohead_curr_id,
-                                                                      cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
-                                                                      cm_terms_id : rv.cohead_terms_id,
-                                                                      cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
-                                                                      cm_salesrep_id : rv.cohead_salesrep_id,
-                                                                      cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
-                                                                      cm_docdate : new Date(),
-                                                                      cm_taxzone_id : rv.cohead_taxzone_id,
-                                                                      cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
-                                                                      cm_billto_cntct_id : rv.cohead_billto_cntct_id,
-                                                                      cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
-                                                                      cm_location_src : rv.cohead_location_src,
-                                                                      cm_location_src_location_name : rv.cohead_location_src_location_name,
-                                                                      cm_billto_address : rv.billto_address
-                                                                  }
-                                                                  
-                                                              },
-                                                                  function() { 
-                                                                   _this.invgrid.ds.load({});
-                                                              });
-                                                             
-                                                          },
-                                                       render : function (_self)
-                                                          {
-                                                            _this.addInvoiceBtn = _self;
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Void / Unpost",
-                                                xtype : 'Button',
-                                                cls : 'x-btn-text-icon',
-                                                icon : rootURL + '/Pman/templates/images/trash.gif',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function ()
-                                                          {
-                                                          
-                                                               var sel  = _this.invgrid.getSelectionModel().getSelected();
-                                                              if (!sel) {
-                                                                  Roo.MessageBox.alert("Error", "Select a invoice");
-                                                                  return;
-                                                              }
-                                                              // check current status of shipment..
-                                                              
-                                                              var params =  {
-                                                          //        cobmisc_id : sel.data.cobmisc_id,
-                                                                  _void : 1
-                                                              };
-                                                              if (sel.data.cobmisc_id * 1) {
-                                                                  params.cobmisc_id = sel.data.cobmisc_id * 1 ;
-                                                              }
-                                                              if (sel.data.cobmisc_invchead_id_invchead_id * 1) {    
-                                                                  params.invchead_id  =  sel.data.cobmisc_invchead_id_invchead_id * 1;
-                                                              }
-                                                              
-                                                              Roo.MessageBox.confirm("Are you sure", "Are you sure you want to VOID that invoice?",
-                                                                  function(r) {
-                                                                      if (r != 'yes') {
-                                                                          return;
-                                                                      }
-                                                                      new Pman.Request({
-                                                                          mask : 'Sending',
-                                                                          url : baseURL + '/Roo/cobmisc',
-                                                                          method : 'POST',
-                                                                          params :  params,
-                                                                          success : function() {
-                                                                              _this.invgrid.ds.load({});
-                                                                          }
-                                                                      })
-                                                                      
-                                                                  }
-                                                              );
-                                                                      
-                                                                      
-                                                             
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'invchead_invcnumber',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    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\"}',
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Invoice #',
-                                               width : 100,
-                                               renderer : function(v,x,r) { 
-                                                      if (v && 
-                                                            r.data.cobmisc_invchead_id_invchead_id * 1 && 
-                                                           !r.data.cobmisc_invchead_id_invchead_posted) {
-                                                          return  '<span style="color:red">' + 
-                                                               "NEEDS Voiding then re-posted: " + 
-                                                               String.format('{0}', v) +
-                                                               '</span>'; 
-                                                      }
-                                               
-                                                      if(v && r.data.cobmisc_id == -2){
-                                                           return String.format('<span style="margin-left: 10px;"> - {0} (Credit Memo)</span>', v); 
-                                                      }
-                                                      if(v && r.data.cobmisc_id == -3){
-                                                           return String.format('<span style="margin-left: 20px;"> - {0} (Miscellaneous Check)</span>', v); 
-                                                      }
-                                                     if(v && r.data.cobmisc_id == -4){
-                                                           return String.format('<span style="margin-left: 10px;"> - {0} (Receive Payment to {2}) [ {1} ]</span>', 
-                                                                   v, r.data.cobmisc_cashrcpt_amount, r.json.cashrcpt_bankaccnt_id_bankaccnt_bankname); 
-                                                      }
-                                                      
-                                                       return v ? String.format('{0}', v) : 
-                                                               '<span style="color:red">' + "Not Posted" + '</span>'; 
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_invchead_id_invchead_invcnumber'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'invcdate',
-                                               width : 75,
-                                               renderer : function(v,x,r) { 
-                                                   
-                                                   return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); 
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_invcdate',
-                                               builderCfg : '{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Qty',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}', v ? parseInt(v) : 0); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_qty'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Item Cost',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_itemcost'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Shipping',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_freight'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Tax',
-                                               width : 75,
-                                               renderer : function(v,x,r) { 
-                                               
-                                                   // tax is based on the % itemcost..
-                                               //    var ic  = r.data.cobmisc_itemcost;
-                                                   /*
-                                                   var ic  =r.data.cobmisc_itemcost - (1* r.data.cobmisc_itemcost_taxfree);
-                                                   
-                                                   var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
-                                                   var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
-                                                   if (tax < 0.1) {
-                                                       return '';
-                                                   }
-                                                   var taxp = tax / totic;
-                                                   var lv = taxp * ic;
-                                                   */
-                                                   return String.format('{0}', (1.0*v).toFixed(2) );
-                                                   
-                                                   
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_tax'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Discount (Pretax)',
-                                               width : 100,
-                                               renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_cohead_id_cohead_pretax_discount'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Discount (Posttax)',
-                                               width : 100,
-                                               renderer : function(v,x,r) 
-                                               {
-                                                   var vv = v - r.data.cobmisc_cohead_id_cohead_pretax_discount;
-                                                   
-                                                   return String.format('{0}', vv ? (1.0*vv).toFixed(2) : 0); 
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_misc'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Total ',
-                                               width : 75,
-                                               renderer : function(v,x,r) { 
-                                               
-                                               /*    
-                                                   var ic  = r.data.cobmisc_itemcost;
-                                                   var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
-                                                   var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
-                                                   var     lv = 0.0;
-                                                   if (tax > 0.0) {
-                                                       var taxp = tax / totic;
-                                                       lv = taxp * ic;
-                                               
-                                                   }
-                                                 */  
-                                                 
-                                               
-                                                   if(v){
-                                                       return String.format('{0}',(v * 1.0).toFixed(2) );
-                                                   }
-                                                   var d= r.data;
-                                               
-                                                   return String.format('{0}',
-                                                      ((d.cobmisc_itemcost * 1.0) + 
-                                                      (d.cobmisc_freight * 1.0) + 
-                                                      (d.cobmisc_tax * 1.0) +
-                                                      (d.cobmisc_misc * 1.0)  
-                                               
-                                                      ).toFixed(2) );
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_total'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Outstanding',
-                                               width : 75,
-                                               renderer : function(v,x,r) 
-                                               { 
-                                                   
-                                                   return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'cobmisc_outstanding'
-                                           }
-                                    ],
-                                    listeners : {
-                                       rowdblclick : function (_self, rowIndex, e)
-                                          {
-                                          
-                                              var ri = this.ds.getAt(rowIndex);
-                                              if ( ri.data.cobmisc_id < 0) { // skip summary row..
-                                                  return;
-                                              }
-                                              var rv = _this.form.getFieldValues();
-                                             Pman.Dialog.XtupleInvoice.show({
-                                                  cobmisc_id : ri.data.cobmisc_id,
-                                                  // below parms for add credit memo
-                                                  cmdata : {
-                                                      cm_cust_id : rv.cohead_cust_id,
-                                                      cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
-                                                      cm_curr_id : rv.cohead_curr_id,
-                                                      cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
-                                                      cm_terms_id : rv.cohead_terms_id,
-                                                      cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
-                                                      cm_salesrep_id : rv.cohead_salesrep_id,
-                                                      cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
-                                                      cm_docdate : new Date(),
-                                                      cm_taxzone_id : rv.cohead_taxzone_id,
-                                                      cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
-                                                      cm_billto_cntct_id : rv.cohead_billto_cntct_id,
-                                                      cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
-                                                      cm_location_src : rv.cohead_location_src,
-                                                      cm_location_src_location_name : rv.cohead_location_src_location_name,
-                                                      cm_billto_address : rv.billto_address
-                                                  }
-                                              },
-                                                  function() { 
-                                                   _this.invgrid.ds.load({});
-                                              });
-                                             
-                                          },
-                                       render : function() 
-                                          {
-                                              _this.invgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.invpanel.active) {
-                                                 this.ds.load({});
-                                              }
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                fitToframe : true,
-                                background : false,
-                                region : 'center',
-                                title : "Invoices",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                tableName : 'cobmisc',
-                                listeners : {
-                                       activate : function() {
-                                              _this.invpanel = this;
-                                              if (_this.invgrid) {
-                                                  _this.invgrid.ds.load({});
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
-                            }
-                        ]
-
-                    },
-                    '|xns' : 'Roo',
-                    region : 'center',
-                    xtype : 'NestedLayoutPanel',
-                    title : "Shipments / Invoices",
-                    xns : Roo,
-                    listeners : {
-                       activate : function (_self)
-                          {
-                              _this.shipinvtab = _self;
-                          }
-                    },
-                    items : [
-
-                    ]
-
+                store : {
+                 remoteSort : true,
+                 sortInfo : { direction : 'ASC', field: 'cntct_name' },
+                 xns : Roo.data,
+                 '|xns' : 'Roo.data',
+                 xtype : 'Store',
+                 listeners : {
+                  beforeload : function (_self, o){
+                       o.params = o.params || {};
+                       // set more here
+                       o.params._customer_id = _this.data.cohead_cust_id;
+                   }
+                 },
+                 proxy : {
+                  method : 'GET',
+                  url : baseURL + '/Roo/cntct.php',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'HttpProxy'
+                 },
+                 reader : {
+                  fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
+                  id : 'cntct_id',
+                  root : 'data',
+                  totalProperty : 'total',
+                  xns : Roo.data,
+                  '|xns' : 'Roo.data',
+                  xtype : 'JsonReader'
+                 }
+                }
+               },
+               {
+                fieldLabel : _this._strings['dd7bf230fde8d4836917806aff6a6b27'] /* Address */,
+                name : 'shipto_address',
+                readOnly : true,
+                update : function() {
+                
+                    var c = ['first_name', 'last_name' ] ;
+                    var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
+                    var v = [];
+                    
+                    if (_this.data['cohead_shipto_vend_name'] && _this.data['cohead_shipto_vend_name'].length) {
+                         v.push(_this.data['cohead_shipto_vend_name']);
+                    }
+                        if (_this.data['cohead_shipto_vendaddr_code'] && _this.data['cohead_shipto_vendaddr_code'].length) {
+                         v.push(_this.data['cohead_shipto_vendaddr_code']);
+                    }
+                    Roo.each(c, function(e) {
+                        if (_this.data['cohead_shipto_cntct_id_cntct_' +e] && 
+                            _this.data['cohead_shipto_cntct_id_cntct_' +e].length) {
+                            v.push(_this.data['cohead_shipto_cntct_id_cntct_' +e]);
+                        }
+                    });
+                    Roo.each(a, function(e) {
+                        if (_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e] && 
+                            _this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e].length) { 
+                            v.push(_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e]);
+                        }
+                    });
+                
+                    this.setValue(v.join("\n"));
                 },
-               {
-                    grid : {
-                        dataSource : {
-                            proxy : {
-                                '|xns' : 'Roo.data',
-                                url : baseURL + '/Roo/events.php',
-                                method : 'GET',
-                                xtype : 'HttpProxy',
-                                xns : Roo.data
-                            },
-                            reader : {
-                                '|xns' : 'Roo.data',
-                                id : 'id',
-                                root : 'data',
-                                xtype : 'JsonReader',
-                                fields : [
-                                    {
-                                        'name': 'event_when',
-                                        'type': 'date'
-                                    },
-                                    {
-                                        'name': 'action',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'ipaddr',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'person_id_name',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'remarks',
-                                        'type': 'string'
-                                    }
-                                ],
-                                xns : Roo.data,
-                                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\"}',
-                                totalProperty : 'total'
-                            },
-                            '|xns' : 'Roo.data',
-                            remoteSort : true,
-                            xtype : 'Store',
-                            sortInfo : { field : 'event_when', direction: 'DESC' },
-                            xns : Roo.data,
-                            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\"}',
-                            listeners : {
-                               beforeload : function (_self, options)
-                                  {
-                                      options.params._related_on_table = 'cohead';
-                                      options.params._related_on_id = _this.form.findField('cohead_id').getValue();
-                                  }
-                            },
-                            items : [
-
-                            ]
-
-                        },
-                        footer : {
-                            '|xns' : 'Roo',
-                            pageSize : 25,
-                            xtype : 'PagingToolbar',
-                            emptyMsg : "No events found",
-                            xns : Roo,
-                            displayInfo : true,
-                            displayMsg : "Displaying events{0} - {1} of {2}"
-                        },
-                        '|xns' : 'Roo.grid',
-                        autoExpandColumn : 'remarks',
-                        xtype : 'Grid',
-                        loadMask : true,
-                        xns : Roo.grid,
-                        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\"}',
-                        colModel : [
-                                {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Changed',
-                                       width : 120,
-                                       renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'event_when',
-                                       builderCfg : '{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'action',
-                                       width : 120,
-                                       renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'action',
-                                       builderCfg : '{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'IP address',
-                                       width : 120,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'ipaddr',
-                                       builderCfg : '{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Who',
-                                       width : 120,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'person_id_name',
-                                       builderCfg : '{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Notes',
-                                       width : 200,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'remarks',
-                                       builderCfg : '{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}'
-                                   }
-                        ],
-                        listeners : {
-                               rowdblclick : function (_self, rowIndex, e)
-                                  {
-                                      if (!_this.dialog) return;
-                                      _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
-                                          _this.grid.footer.onClick('first');
-                                      }); 
-                                  },
-                               render : function() 
-                                  {
-                                      _this.hgrid = this; 
-                                      //_this.dialog = Pman.Dialog.FILL_IN
-                                      if (_this.hpanel.active) {
-                                         this.footer.onClick('first');
-                                      }
-                                  }
-                        },
-                        items : [
-
-                        ]
-
-                    },
-                    '|xns' : 'Roo',
-                    background : true,
-                    fitToframe : true,
-                    region : 'center',
-                    title : "History",
-                    xtype : 'GridPanel',
-                    fitContainer : true,
-                    xns : Roo,
-                    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\"}',
-                    tableName : 'events',
-                    listeners : {
-                       activate : function() {
-                              _this.hpanel = this;
-                              if (_this.hgrid) {
-                                  _this.hgrid.footer.onClick('first');
-                              }
-                          }
-                    },
-                    items : [
-
-                    ]
-
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextArea',
+                listeners : {
+                 render : function (_self)
+                  {
+                     Roo.log(this.el)
+                     
+                     
+                     
+                     this.el.on('click', function() { 
+                         var id = _this.form.findField('cohead_shipto_cntct_id').getValue();
+                          Pman.Dialog.XtupleQuickContact.show( 
+                              {
+                                _id : id,
+                                customer_id : _this.form.findField('cohead_cust_id').getValue()
+                              },
+                              
+                              function (data) {
+                              
+                                  for(var i in  data) {
+                                      
+                                      _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
+                                  }
+                                  
+                                  _this.form.findField('shipto_address').update();
+                                  // fill in the select box..
+                                  _this.form.setValues( {
+                                      cohead_shipto_cntct_id : data.cntct_id,
+                                      cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
+                                              data.cntct_last_name
+                                      
+                                  });
+                                  
+                                          
+                                  //Roo.log(data);
+                              }
+                          );
+                     
+                        //  Roo.log("Click text");
+                          
+                          
+                       });
+                  }
+                }
+               },
+               {
+                fieldLabel : _this._strings['48e91c2f1cb7b90612ccae2502c7327f'] /* Shipment Comments */,
+                name : 'cohead_shipcomments',
+                width : 300,
+                xns : Roo.form,
+                '|xns' : 'Roo.form',
+                xtype : 'TextArea'
+               }
+              ]
+             }
+            ]
+           }
+          ]
+         },
+         {
+          name : 'cohead_id',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'cohead_shipto_id',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'cohead_shipto_id_shipto_name',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'cohead_max_linenumber',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'cohead_cust_id',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'cohead_misc',
+          recalc : function() {
+              var d = _this.form.getValues();
+              this.setValue( 
+                  parseFloat(d.cohead_pretax_discount) + 
+                  parseFloat(d.cohead_posttax_discount) );
+          },
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         },
+         {
+          name : 'taxzone_rate',
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'Hidden'
+         }
+        ]
+       }
+      ]
+     },
+     {
+      background : true,
+      fitContainer : true,
+      fitToframe : true,
+      region : 'center',
+      tableName : 'coitem',
+      title : _this._strings['4b84bd35233c0d3d3c36b9a6ce6e0745'] /* Order Items */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'GridPanel',
+      listeners : {
+       activate : function() {
+            _this.panel = this;
+            
+            try { if (MODULE.isBuilder) {
+                return;
+            } } catch(e) { }
+            
+            var id = _this.form.findField('cohead_id').getValue() * 1;
+            if (id < 1) {
+                Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
+                _this.dialog.layout.getRegion('center').showPanel(0);
+                return;
+            }
+            
+            if (_this.grid) {
+                _this.grid.footer.onClick('first');
+            
+                 //if (_this.form.findField('cohead_cust_id_cust_name').getValue() == 'Bloom and Grow HK') {
+                 //   _this.xferAll.show();
+                // 
+                // } else {
+                //     _this.xferAll.hide();
+                // }
+             }
+            
+        },
+       deactivate : function (_self)
+        {
+            if(_this.grid){
+                _this.grid.stopEditing();
+            }
+        }
+      },
+      grid : {
+       autoExpandColumn : 'item_descrip1',
+       clicksToEdit : 1,
+       loadAvail : function() {
+           
+           
+           this.ds.each(function(r) {
+               
+               if(!r.data.item_number.length){
+                   return;
+               }
+               
+               if(typeof(_this.stockcache[r.data.item_number]) != 'undefined'){
+               
+                   r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
+                   if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
+                       r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
+                   }
+                   return;
+               }
+               
+               var q = [];
+               
+               q.push( { 
+                   item : r.data.item_number, 
+                   loc: r.data.coitem_location_src_location_name,
+                   id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
+                } );
+                
+                new Pman.Request({
+                   url : baseURL + '/Roo/itemloc',
+                   method : 'POST',
+                   params : {
+                       _availqty : Roo.encode(q),
+                       curr_name : _this.form.findField('cohead_curr_id').el.dom.value
+                   },
+                   success : function(res) 
+                   {
+                       for (var i in res.data) {
+                          _this.stockcache[res.data[i].item] = res.data[i];
+                       }
+                       r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
+                       if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
+                           r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
+                       }
+                       //_this.grid.ds.fireEvent("update", _this.grid.ds, r, Roo.data.Record.EDIT);
+                       return
+                   }
+               });
+           });
+               
+                       
+       },
+       loadMask : true,
+       xns : Roo.grid,
+       '|xns' : 'Roo.grid',
+       xtype : 'EditorGrid',
+       listeners : {
+        afteredit : function (e)
+         {
+             Roo.log('afteredit:' + e.record.data.coitem_linenumber);
+         
+             
+            // if ( e.record && e.record.data.coitem_id) {
+                 // as we disable update to the display on the ajax callback to 
+                 // allow editing flow to continue, and not refresh - we can only update
+                 // these values after something has actually been edited.
+                 // e.record.set('coitem_id', e.record.data.coitem_id);
+                 // e.record.set('coitem_status', e.record.data.coitem_status);
+            // }
+             
+             if (e.field == 'item_number' || e.originalValue == e.value) {
+                 // afterselect handles this...
+                 return;
+             }
+             if (e.field == 'item_descrip1') {
+                 e.record.set('coitem_memo', e.value);
+             }
+             var rate = _this.form.findField('taxzone_rate').getValue();
+             switch(e.field) {
+                 case 'coitem_linedisc':
+                    
+                     var cp = parseFloat(e.record.data.coitem_custprice);
+                    
+                     if (isNaN(cp) || cp == 0.0) {
+                         break;
+                     }
+                     
+                     var dis = parseFloat(e.value);
+                    
+                     if (isNaN(dis)) {
+                         break;
+                     }
+                     
+                     e.record.set(
+                         'coitem_price',
+                         Math.max(0,cp * ((100.0 -  parseInt(e.value))/ 100.0) )  
+                     );
+                     
+                    // donot need to set the subtotal here, coz we will render it automatically
+                    // e.record.set(
+                    //     'coitem_subtotal',
+                    //      e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
+                    // );
+                     break;
+                 
+                 case  'coitem_price': // SELL@ price
+         
+                      var cp = parseFloat(e.record.data.coitem_custprice);
+                      // list price is < price -- update it..
+                      if (isNaN(cp) || cp == 0.0 || cp < e.value) {
+                         e.record.set('coitem_custprice', e.value);
+                         cp = e.value;
+                      }
+                      // update the discount calc.
+                      
+                      e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( e.value / cp) * 100.0)));  
+                      
+                      // donot need to set the subtotal here, coz we will render it automatically
+                      //e.record.set(
+                      //   'coitem_subtotal',
+                       //   e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
+                      //);
+                      break;
+                 
+                 case 'coitem_custprice':
+                     // modified customer price...
+                     // just modify the discount.. -- leave the entered price the same..
+                       var sp =  parseFloat(e.record.data.coitem_price);
+                       var cp = parseFloat(e.value);
+                       if (isNaN(cp) || cp == 0.0 || cp < e.value) {
+                             break;
+                       }
+                       
+                      e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
+                      
+                      break;
+                      
+                 case 'coitem_custprice_tax':
+                       var cp = parseFloat(e.value / ( 1 + rate * 1 ));
+                       var sp =  parseFloat(e.record.data.coitem_price);
+                       
+                       if (isNaN(cp) || cp == 0.0) {
+                             break;
+                       }
+                       e.record.set('coitem_custprice', cp);
+                       e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
+                      
+                      break; 
+                      
+                  case  'coitem_price_tax':
+         
+                      var cp = parseFloat(e.record.data.coitem_custprice);
+                      var sp = parseFloat(e.value / ( 1 + rate * 1 ));
+                      if (isNaN(cp) || cp == 0.0 || cp < sp) {
+                         e.record.set('coitem_custprice', sp);
+                         cp = sp;
+                      }
+                      e.record.set('coitem_price', sp);
+                      e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
+                      
+                      break;
+               
+             }
+             
+              
+             
+             
+             var doupdate = function() { 
+                if (!e.record.updatePending) {
+                     Roo.log('doupdate...'  + e.record.data.coitem_linenumber);
+                     Roo.log(e.record);
+                     e.record.commit();
+                     return;
+                 }
+                Roo.log('doupdate pending...'   + e.record.data.coitem_linenumber);
+                 // wait until it's not peding an update..
+                 doupdate.defer(500);
+             }
+         
+             if(e.record.data.coitem_id * 1 < 1 && !e.record.isInserting){ // insert
+                 e.record.isInserting = 1;
+                 e.record.isUpdating = 0;
+                 doupdate();
+                 return;
+             }
+             
+             // update
+             if(!e.record.isInserting && !e.record.isUpdating){
+                 e.record.isUpdating = 1;
+                 doupdate();
+                 return;
+             }
+             
+             if(!e.record.updatePending){
+                 e.record.updatePending = 1;
+                 doupdate();
+                 return;
+             }
+             Roo.log("got to end without doing an update?"  + e.record.data.coitem_linenumber);
+             
+         },
+        beforeedit : function (e)
+         {
+             // we can only edit if nothing is assigned to shipping or invoices..
+             
+             var rec = e.record
+         
+             if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0 || (rec.data.shipitem_shipped - rec.data.coitem_qtyshipped) > 0 ) {
+                 Roo.MessageBox.alert("Error", "That item has been shipped, has a draft shipment  or invoices - void the shipments/invoices first");
+                 e.cancel = true;
+                 return;
+             }
+             
+             if (rec.data.coitem_subnumber * 1 > 0) {
+                 Roo.log("Edit container event");
+                 Roo.log(e); // if it's a tab.. 
+         
+                 
+                 switch(e.field) {
+                     // allow editing of source / destination..
+                     case 'coitem_shipto_id':
+                     case 'coitem_location_src':            
+                         return;
+                     default : 
+                         break;
+                 }
+                 Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
+                 e.cancel = true;
+                 return;
+             }
+             // zero off values..
+             //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
+             //        e.value ='';
+             //    }
+             //    if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
+             //        e.value ='';
+             //    }
+             
+             if (rec.data.item_type == 'K' && e.field == 'item_number') {
+                 // you can not change the product type on kits' as it messing things up..
+                 Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
+                 e.cancel = true;
+                 return;
+             }
+             
+         },
+        celldblclick : function (_self, rowIndex, columnIndex, e)
+         {
+             var rec = this.ds.getAt(rowIndex);
+             var di = this.cm.getDataIndex(columnIndex);
+             if (di != 'avail_qty') {
+                 return;
+             }
+             
+             Pman.Dialog.XtupleInvHistory.show({
+                 itemsite_item_id_item_number   : rec.data.item_number,
+                // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
+                 location_name : rec.data.coitem_location_src_location_name,
+                 location_descrip : rec.data.coitem_location_src_location_descrip,
+                 
+                 invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
+             }); 
+             
+         },
+        render : function() 
+         {
+             _this.grid = this; 
+             //_this.dialog = Pman.Dialog.FILL_IN
+             
+             if (_this.panel.active) {
+                this.footer.onClick('first');
+             }
+         },
+        rowclass : function (gridview, rowcfg)
+         {
+             if (rowcfg.record.data.coitem_status == 'C' &&
+                 rowcfg.record.data.shipitem_shipped * 1 < 1) {
+                 
+                 rowcfg.rowClass = 'strikethrough';
+             }
+              if (rowcfg.record.data.coitem_status == 'X'  ) {
+                 
+                 rowcfg.rowClass = 'strikethrough';
+             }
+             
+             if (!rowcfg.record.data.coitem_id) { 
+                     rowcfg.rowClass = 'dragon-not-saved';
+             }
+             
+             
+            // Roo.log(rowcfg);
+         //    shipitem_shipped
+         }
+       },
+       footer : {
+        displayInfo : true,
+        emptyMsg : _this._strings['158e64bcd08067d26e9c27679eeced88'] /* No Items */,
+        pageSize : 100,
+        updateSummary : function() {
+            var f = this;
+            new Pman.Request({
+                url : baseURL + '/Roo/Coitem',
+                method : 'GET',
+                params : {
+                    _totals : 1,
+                    coitem_cohead_id : _this.form.findField('cohead_id').getValue()
                 },
-               {
-                    layout : {
-                        center : {
-                            '|xns' : 'Roo',
-                            xtype : 'LayoutRegion',
-                            xns : Roo
-                        },
-                        east : {
-                            '|xns' : 'Roo',
-                            xtype : 'LayoutRegion',
-                            width : 500,
-                            xns : Roo,
-                            split : true
-                        },
-                        '|xns' : 'Roo',
-                        xtype : 'BorderLayout',
-                        xns : Roo,
-                        items : [
-                               {
-                                grid : {
-                                    toolbar : {
-                                        '|xns' : 'Roo',
-                                        xtype : 'Toolbar',
-                                        xns : Roo,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Run Apply Fifo on order",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              new Pman.Request({
-                                                                  mask : 'applying',
-                                                                  url : baseURL + '/Roo/Cohead',
-                                                                  method : 'GET',
-                                                                  params : {
-                                                                      _apply_fifo : _this.form.findField('cohead_id').getValue()
-                                                                  },
-                                                                  success : function () {
-                                                                      Roo.MessageBox.alert("Applied", "Succesfully Applied");
-                                                                  }
-                                                              });
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Run Void flagger",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              new Pman.Request({
-                                                                  mask : 'running',
-                                                                  url : baseURL + '/Roo/Cohead',
-                                                                  method : 'GET',
-                                                                  params : {
-                                                                      _run_void_fix : _this.form.findField('cohead_id').getValue()
-                                                                  },
-                                                                  success : function () {
-                                                                      Roo.MessageBox.alert("Applied", "Succesfully Run");
-                                                                  }
-                                                              });
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Auto Reverse",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              new Pman.Download({
-                                                                  newWindow : true,
-                                                                  mask : 'running',
-                                                                  url : baseURL + '/Roo/Invdetail',
-                                                                  method : 'GET',
-                                                                  timeout :90000,
-                                                                  params : {
-                                                                      _post : 1,
-                                                                      _reverse_all_bad : _this.form.findField('cohead_id').getValue()
-                                                                  },
-                                                                  success : function () {
-                                                                      Roo.MessageBox.alert("Applied", "Succesfully Run");
-                                                                  }
-                                                              });
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    sm : {
-                                        '|xns' : 'Roo.grid',
-                                        xtype : 'RowSelectionModel',
-                                        singleSelect : true,
-                                        xns : Roo.grid,
-                                        listeners : {
-                                               selectionchange : function (_self)
-                                                  {
-                                                      _this.txdgrid.footer.onClick('first');;
-                                                  }
-                                        }
-                                    },
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/invdetail.php',
-                                            xtype : 'HttpProxy',
-                                            method : 'GET',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            xns : Roo.data,
-                                            fields : [
-                                                {
-                                                    'name': 'invdetail_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_transtype',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invhist_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_location_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_comments',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_before',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_after',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invcitem_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_expiration',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_warrpurc',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_ls_id',
-                                                    'type': 'int'
-                                                }
-                                            ],
-                                            totalProperty : 'total'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        xtype : 'Store',
-                                        remoteSort : true,
-                                        sortInfo : { field : 'item_number', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        listeners : {
-                                               beforeload : function (_self, o)
-                                                  {
-                                                      o.params.cohead_id = _this.form.findField('cohead_id').getValue();
-                                                      if (! o.params.cohead_id ) {
-                                                          this.removeAll();
-                                                          return false;
-                                                      }
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    footer : {
-                                        '|xns' : 'Roo',
-                                        pageSize : 9999,
-                                        xtype : 'PagingToolbar',
-                                        emptyMsg : "No invdetail found",
-                                        xns : Roo,
-                                        displayMsg : "Displaying invdetail{0} - {1} of {2}",
-                                        displayInfo : true
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'item_number',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Item',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'item_number'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#Ship',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'rec_shipped'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#Ret',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'rec_returned'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#TX ship',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'tx_shipped'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#TX ret',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'tx_returned'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#TX Tot',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'tx_total'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Value',
-                                               width : 50,
-                                               renderer : function(v,x,r) { 
-                                               
-                                                   return (v*1).toFixed(3);
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'total_value'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : '#Diff',
-                                               width : 50,
-                                               renderer : function(v,x,r) { 
-                                               
-                                                   var cototal = (r.data.rec_returned*1) - (r.data.rec_shipped*1);
-                                               //    Roo.log(cototal);
-                                                   var diff = (v*1) - cototal;
-                                                //   Roo.log(diff);
-                                                   if (diff == 0)  {
-                                                       return '';
-                                                   }
-                                                   return String.format('<span style="color:red">{0}</span>',  diff ); 
-                                                   },
-                                               xns : Roo.grid,
-                                               dataIndex : 'tx_total'
-                                           }
-                                    ],
-                                    listeners : {
-                                       render : function() 
-                                          {
-                                              _this.txgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.txpanel.active) {
-                                                 this.footer.onClick('first');
-                                              }
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                fitToframe : true,
-                                background : false,
-                                region : 'center',
-                                title : "invdetail",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                tableName : 'invdetail',
-                                listeners : {
-                                       activate : function() {
-                                              _this.txpanel = this;
-                                              if (_this.txgrid) {
-                                                  _this.txgrid.footer.onClick('first');
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
-                            },
-                               {
-                                grid : {
-                                    toolbar : {
-                                        '|xns' : 'Roo',
-                                        xtype : 'Toolbar',
-                                        xns : Roo,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Duplicate Selected",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              var s = _this.txdgrid.selModel.getSelected();
-                                                          
-                                                              if (!s) {
-                                                                  Roo.MessageBox.alert("Error", "Select a transaction");
-                                                                  return;
-                                                              }
-                                                              
-                                                              var reverseSel = function() {
-                                                              
-                                                                  new Pman.Request({
-                                                                      mask : "Reversing",
-                                                                      url : baseURL + '/Roo/invdetail',
-                                                                      method : 'POST',
-                                                                      params : {
-                                                                          _duplicate : s.data.invdetail_id
-                                                                      }, 
-                                                                      success : function() {
-                                                                          _this.txdgrid.footer.onClick('first');
-                                                                      }
-                                                                  });
-                                                              
-                                                              }
-                                                              
-                                                              
-                                                          
-                                                              Roo.MessageBox.confirm(
-                                                                  "Confirm", 
-                                                                  "This should only be used by System Administrators - are you sure you know what you are doing!",
-                                                                  function(x) {
-                                                                      if (x != 'yes') {
-                                                                          return;
-                                                                      }
-                                                                      reverseSel();
-                                                                  }
-                                                              );
-                                                                                  
-                                                              
-                                                              
-                                                              
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                xtype : 'Fill',
-                                                xns : Roo.Toolbar
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Issue Date",
-                                                xtype : 'TextItem',
-                                                xns : Roo.Toolbar
-                                            },
-                                               {
-                                                '|xns' : 'Roo.form',
-                                                format : 'Y-m-d',
-                                                fieldLabel : 'Issue Date',
-                                                xtype : 'DateField',
-                                                allowBlank : false,
-                                                width : 150,
-                                                xns : Roo.form,
-                                                name : 'issue_date',
-                                                listeners : {
-                                                       render : function (_self)
-                                                          {
-                                                              _this.dateSel = _self;
-                                                          }
-                                                }
-                                            },
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Reverse Selected",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              var s = _this.txdgrid.selModel.getSelected();
-                                                              var dt = _this.dateSel.getValue();
-                                                              if (!s) {
-                                                                  Roo.MessageBox.alert("Error", "Select a transaction");
-                                                                  return;
-                                                              }
-                                                              
-                                                              var reverseSel = function(force) {
-                                                              
-                                                                  new Pman.Request({
-                                                                      mask : "Reversing",
-                                                                      url : baseURL + '/Roo/invdetail',
-                                                                      method : 'POST',
-                                                                      params : {
-                                                                          _reverse : s.data.invdetail_id,
-                                                                          _as_of : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
-                                                                          _force : force
-                                                                      }, 
-                                                                      success : function() {
-                                                                          _this.txdgrid.footer.onClick('first');
-                                                                      },
-                                                                      failure : function(res) {
-                                                                          Roo.log(res);
-                                                                          try {
-                                                                              if (res.errors.confirm) {
-                                                                                                
-                                                                                  Roo.MessageBox.confirm(
-                                                                                      "Confirm", 
-                                                                                      "are you really sure the totals will get messed up.",
-                                                                                      function(x) {
-                                                                                          if (x != 'yes') {
-                                                                                              return;
-                                                                                          }
-                                                                                          reverseSel(1);
-                                                                                      }
-                                                                                  );
-                                                                                  return;
-                                                                              }
-                                                                          } catch(e) { }
-                                                                          Roo.MessageBox.alert("Error", res.errorMsg);
-                                                                          
-                                                                          
-                                                                      }
-                                                                  });
-                                                              
-                                                              }
-                                                              
-                                                              
-                                                          
-                                                              Roo.MessageBox.confirm(
-                                                                  "Confirm", 
-                                                                  "This should only be used by System Administrators - are you sure you know what you are doing!",
-                                                                  function(x) {
-                                                                      if (x != 'yes') {
-                                                                          return;
-                                                                      }
-                                                                      reverseSel(0);
-                                                                  }
-                                                              );
-                                                                                  
-                                                              
-                                                              
-                                                              
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/invdetail.php',
-                                            xtype : 'HttpProxy',
-                                            method : 'GET',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            xns : Roo.data,
-                                            fields : [
-                                                {
-                                                    'name': 'invdetail_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_transtype',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invhist_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_location_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_comments',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_before',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_after',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invcitem_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_expiration',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_warrpurc',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_ls_id',
-                                                    'type': 'int'
-                                                }
-                                            ],
-                                            totalProperty : 'total'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        xtype : 'Store',
-                                        remoteSort : true,
-                                        sortInfo : { field : 'invdetail_id', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        listeners : {
-                                               beforeload : function (_self, o)
-                                                  {
-                                                      o.params.cohead_id = _this.form.findField('cohead_id').getValue();
-                                                      var s = _this.txgrid.selModel.getSelected();
-                                                      if (!s) { 
-                                                          this.removeAll();
-                                                          return false;
-                                                      }
-                                                      o.params.itemsite_id = s.data.invhist_itemsite_id;
-                                                      
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    footer : {
-                                        '|xns' : 'Roo',
-                                        pageSize : 9999,
-                                        xtype : 'PagingToolbar',
-                                        emptyMsg : "No invdetail found",
-                                        xns : Roo,
-                                        displayMsg : "Displaying invdetail{0} - {1} of {2}",
-                                        displayInfo : true
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'invhist_comments',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'TX#',
-                                               width : 60,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invdetail_id'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Date',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invhist_transdate'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Ref#',
-                                               width : 75,
-                                               renderer : function(v,x,r) {
-                                                   if (r.data.invfifo_void *1 != 0) {
-                                                       return String.format('<s>{0}</s>', v); 
-                                                   }
-                                               
-                                                    return String.format('{0}', v); 
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invhist_ordnumber'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'TX#',
-                                               width : 60,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'location_name'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Notes',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invhist_comments'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Qty Changed',
-                                               width : 50,
-                                               renderer : function(v,x,r) {
-                                                   if ( r.data.coitem_shipped != v) {
-                                                       return String.format('{0} <span style="color:red">({1})</span>',
-                                                            Roo.util.Format.number(v,0),
-                                                            r.data.coitem_shipped
-                                                        );
-                                                   
-                                                   }
-                                                    return String.format('{0}', Roo.util.Format.number(v,0));
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invdetail_qty'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Qty Changed',
-                                               width : 75,
-                                               renderer : function(v,x,r) {
-                                                   var tot = r.data.invhist_value_after*1 - v*1;
-                                                   var f = '{0}';
-                                                   if (r.data.invdetail_qty >0 && tot < 0) {
-                                                       f = '<span style="color:red">{0}</span>';
-                                                   }
-                                                   if (r.data.invdetail_qty < 0 && tot > 0) {
-                                                       f = '<span style="color:red">{0}</span>';
-                                                   }    
-                                                   return String.format(f, Roo.util.Format.number(tot));
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invhist_value_before'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Posted',
-                                               width : 40,
-                                               renderer : function(v,x,r) { 
-                                                   
-                                                   var state = v   ?  '-checked' : '';
-                                                                                   
-                                                   return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'invhist_posted'
-                                           }
-                                    ],
-                                    listeners : {
-                                       render : function() 
-                                          {
-                                              _this.txdgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.txdpanel.active) {
-                                                 this.footer.onClick('first');
-                                              }
-                                          },
-                                       rowclick : function (_self, rowIndex, e)
-                                          {
-                                              var s = _this.txdgrid.ds.getAt(rowIndex);
-                                              var dt = s.data.invhist_transdate.split(' ');
-                                              
-                                              _this.dateSel.setValue(new Date(dt[0]));
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                fitToframe : true,
-                                background : false,
-                                region : 'east',
-                                title : "invdetail",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                tableName : 'invdetail',
-                                listeners : {
-                                       activate : function() {
-                                              _this.txdpanel = this;
-                                              if (_this.txdgrid) {
-                                                  _this.txdgrid.footer.onClick('first');
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
-                            }
-                        ]
-
+                success : function(d) {
+                    //Roo.log(d);
+                    f.displayEl.update(String.format(
+                        "{0} items |  Subtotal: {2} | Tax: {3} | List Discount {4} | Total : {1}{5}",
+                        d.data.total_qty,
+                        _this.form.findField('cohead_curr_id').el.dom.value,
+                        d.data.total_sub,
+                        d.data.total_tax,
+                        d.data.total_list_discount,                
+                        d.data.total_total
+                    ));
+                        
+                }
+            });
+        },
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'PagingToolbar',
+        items  : [
+         {
+          text : _this._strings['806dca90dbeda894ffb258939f9fef9a'] /* Fill empty Ship To */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+                new Pman.Request({
+                    url : baseURL + '/Roo/Cohead',
+                    method : 'GET',
+                    params : {
+                        _fill_shipto : _this.form.findField('cohead_id').getValue()
                     },
-                    '|xns' : 'Roo',
-                    region : 'center',
-                    xtype : 'NestedLayoutPanel',
-                    title : "Stock Tx",
-                    xns : Roo,
-                    items : [
-
-                    ]
-
-                },
-               {
-                    layout : {
-                        center : {
-                            '|xns' : 'Roo',
-                            xtype : 'LayoutRegion',
-                            xns : Roo
-                        },
-                        east : {
-                            '|xns' : 'Roo',
-                            xtype : 'LayoutRegion',
-                            width : 500,
-                            xns : Roo,
-                            split : true
-                        },
-                        '|xns' : 'Roo',
-                        xtype : 'BorderLayout',
-                        xns : Roo,
-                        items : [
-                               {
-                                grid : {
-                                    sm : {
-                                        '|xns' : 'Roo.grid',
-                                        xtype : 'RowSelectionModel',
-                                        singleSelect : true,
-                                        xns : Roo.grid,
-                                        listeners : {
-                                               selectionchange : function (_self)
-                                                  {
-                                                      _this.gltxdgrid.footer.onClick('first');;
-                                                  }
-                                        }
-                                    },
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/gltrans.php',
-                                            xtype : 'HttpProxy',
-                                            method : 'GET',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            xns : Roo.data,
-                                            fields : [
-                                                {
-                                                    'name': 'invdetail_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_transtype',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invhist_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_location_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_comments',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_before',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_after',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invcitem_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_expiration',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_warrpurc',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_ls_id',
-                                                    'type': 'int'
-                                                }
-                                            ],
-                                            totalProperty : 'total'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        xtype : 'Store',
-                                        remoteSort : true,
-                                        sortInfo : { field : 'item_number', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        listeners : {
-                                               beforeload : function (_self, o)
-                                                  {
-                                                      o.params.cohead_id = _this.form.findField('cohead_id').getValue();
-                                                      if (! o.params.cohead_id ) {
-                                                          this.removeAll();
-                                                          return false;
-                                                      }
-                                                      o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    footer : {
-                                        '|xns' : 'Roo',
-                                        pageSize : 9999,
-                                        xtype : 'PagingToolbar',
-                                        emptyMsg : "No invdetail found",
-                                        xns : Roo,
-                                        displayMsg : "Displaying invdetail{0} - {1} of {2}",
-                                        displayInfo : true,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Split sales",
-                                                enableToggle : true,
-                                                pressed : true,
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       render : function (_self)
-                                                          {
-                                                              _this.glsalesbtn = _self;
-                                                          },
-                                                       click : function (_self, e)
-                                                          {
-                                                              (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Summary',
-                                               width : 50,
-                                               renderer : function(v,x,r) { 
-                                                   
-                                                   var state = v*1   ?  '-checked' : '';
-                                                                                   
-                                                   return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_as_summary'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Account',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_accnt_id_accnt_descrip'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Credit',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_amount_credit'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Debit',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_amount_debit'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Sum',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_amount_total'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Unposted',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_amount_total_unposted'
-                                           }
-                                    ],
-                                    listeners : {
-                                       cellclick : function (_self, rowIndex, columnIndex, e)
-                                          {
-                                              if (columnIndex > 0) {
-                                                  return;
-                                              }
-                                              var rec = this.ds.getAt(rowIndex);
-                                              rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
-                                              _this.gltxdgrid.footer.onClick('first');
-                                          },
-                                       render : function() 
-                                          {
-                                              _this.gltxgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.gltxpanel.active) {
-                                                 this.footer.onClick('first');
-                                              }
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                fitToframe : true,
-                                background : false,
-                                region : 'center',
-                                title : "invdetail",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                tableName : 'invdetail',
-                                listeners : {
-                                       activate : function() {
-                                              _this.gltxpanel = this;
-                                              if (_this.gltxgrid) {
-                                                  _this.gltxgrid.footer.onClick('first');
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
+                    success : function() {
+                        _this.grid.footer.onClick('first');
+                    }
+                });
+            }
+          }
+         },
+         {
+          text : _this._strings['c4b515058fab313f403ae427ce7e32b3'] /* Update Location to match S/O */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+                Roo.MessageBox.confirm("Confirm", "Are you sure?<BR>"+
+                    "This will set all the locations to match the Sales Order - and remove all old locations.",
+                    function (res) {
+                        if(res!='yes') {
+                            return;
+                        
+                        }
+                        new Pman.Request({
+                            url : baseURL + '/Roo/Cohead',
+                            method : 'GET',
+                            params : {
+                                _fill_location : _this.form.findField('cohead_id').getValue(),
+                                _location_id : _this.form.findField('cohead_location_src').getValue()
                             },
-                               {
-                                grid : {
-                                    dataSource : {
-                                        proxy : {
-                                            '|xns' : 'Roo.data',
-                                            url : baseURL + '/Roo/gltrans.php',
-                                            xtype : 'HttpProxy',
-                                            method : 'GET',
-                                            xns : Roo.data
-                                        },
-                                        reader : {
-                                            '|xns' : 'Roo.data',
-                                            id : 'id',
-                                            root : 'data',
-                                            xtype : 'JsonReader',
-                                            xns : Roo.data,
-                                            fields : [
-                                                {
-                                                    'name': 'invdetail_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_transtype',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invhist_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_location_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_comments',
-                                                    'type': 'string'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_before',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_qty_after',
-                                                    'type': 'float'
-                                                },
-                                                {
-                                                    'name': 'invdetail_invcitem_id',
-                                                    'type': 'int'
-                                                },
-                                                {
-                                                    'name': 'invdetail_expiration',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_warrpurc',
-                                                    'type': 'date',
-                                                    'dateFormat': 'Y-m-d'
-                                                },
-                                                {
-                                                    'name': 'invdetail_ls_id',
-                                                    'type': 'int'
-                                                }
-                                            ],
-                                            totalProperty : 'total'
-                                        },
-                                        '|xns' : 'Roo.data',
-                                        xtype : 'Store',
-                                        remoteSort : true,
-                                        sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
-                                        xns : Roo.data,
-                                        listeners : {
-                                               beforeload : function (_self, o)
-                                                  {
-                                                      o.params.cohead_id = _this.form.findField('cohead_id').getValue();
-                                                      var s = _this.gltxgrid.selModel.getSelected();
-                                                      if (!s) { 
-                                                          this.removeAll();
-                                                          return false;
-                                                      }
-                                                      o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
-                                                      o.params.gltrans_is_ship = s.data.gltrans_is_ship;
-                                                      o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
-                                                      
-                                                      
-                                                  }
-                                        },
-                                        items : [
-
-                                        ]
-
-                                    },
-                                    footer : {
-                                        '|xns' : 'Roo',
-                                        pageSize : 9999,
-                                        xtype : 'PagingToolbar',
-                                        emptyMsg : "No invdetail found",
-                                        xns : Roo,
-                                        displayMsg : "Displaying invdetail{0} - {1} of {2}",
-                                        displayInfo : true,
-                                        items : [
-                                               {
-                                                '|xns' : 'Roo.Toolbar',
-                                                text : "Download",
-                                                xtype : 'Button',
-                                                xns : Roo.Toolbar,
-                                                listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                              new Pman.Download( {
-                                                                  grid : _this.gltxdgrid
-                                                              
-                                                              });
-                                                          }
-                                                }
-                                            }
-                                        ]
-
-                                    },
-                                    '|xns' : 'Roo.grid',
-                                    autoExpandColumn : 'gltrans_notes',
-                                    xtype : 'Grid',
-                                    loadMask : true,
-                                    xns : Roo.grid,
-                                    colModel : [
-                                        {
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               sortable : true,
-                                               header : 'Ref#',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v ); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_id'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Date',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_date'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Doc#',
-                                               width : 75,
-                                               renderer : function(v,x,r) { 
-                                                   if (r.data.gltrans_deleted) {
-                                                      return String.format('<s>{0}</s>', v);     
-                                                   }
-                                                   return String.format('{0}', v); 
-                                               },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_docnumber'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Source',
-                                               width : 50,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_source'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Notes',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', v); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_notes'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               align : 'right',
-                                               xtype : 'ColumnModel',
-                                               header : 'Amount',
-                                               width : 75,
-                                               renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_amount'
-                                           },
-{
-                                               '|xns' : 'Roo.grid',
-                                               xtype : 'ColumnModel',
-                                               header : 'Posted',
-                                               width : 50,
-                                               renderer : function(v,x,r) { 
-                                                   
-                                                   var state = v   ?  '-checked' : '';
-                                                                                   
-                                                   return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                                },
-                                               xns : Roo.grid,
-                                               dataIndex : 'gltrans_posted'
-                                           }
-                                    ],
-                                    listeners : {
-                                       cellclick : function (_self, ri, ci, e)
-                                          {
-                                              
-                                                var deleteSel = function() {
-                                              
-                                                  new Pman.Request({
-                                                      mask : "Reversing",
-                                                      url : baseURL + '/Roo/gltrans',
-                                                      method : 'POST',
-                                                      params : {  
-                                                          _void : 1,
-                                                          gltrans_id : rec.data.gltrans_id
-                                                          
-                                                      }, 
-                                                      success : function() {
-                                                          rec.set('gltrans_posted', false);
-                                                          rec.set('gltrans_deleted', true);
-                                                          rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
-                                                         _this.gltxgrid.footer.onClick('first');
-                                                      }
-                                                  });
-                                              
-                                              }
-                                              var undeleteSel = function() {
-                                              
-                                                  new Pman.Request({
-                                                      mask : "Reversing",
-                                                      url : baseURL + '/Roo/gltrans',
-                                                      method : 'POST',
-                                                      params : {  
-                                                          _unvoid : 1,
-                                                          gltrans_id : rec.data.gltrans_id
-                                                          
-                                                      }, 
-                                                      success : function() {
-                                                          rec.set('gltrans_posted', true);
-                                                          rec.set('gltrans_deleted', false);
-                                                          rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
-                                                         _this.gltxgrid.footer.onClick('first');
-                                                      }
-                                                  });
-                                              
-                                              }
-                                              
-                                              var di = this.colModel.config[ci].dataIndex;
-                                              if (di != 'gltrans_posted') {
-                                                  return;
-                                              }
-                                              
-                                              
-                                              
-                                              var rec = this.ds.getAt(ri);
-                                              if (rec.data.gltrans_deleted) {
-                                              
-                                                   Roo.MessageBox.confirm(
-                                                      "Confirm", 
-                                                      "This should only be used by System Administrators - are you sure you know what you are doing!",
-                                                      function(x) {
-                                                          if (x != 'yes') {
-                                                              return;
-                                                          }
-                                                          undeleteSel();
-                                                      }
-                                                  );
-                                              
-                                                  return false;
-                                              }
-                                          
-                                              
-                                              
-                                              if (!rec.data.gltrans_posted) {
-                                          
-                                                  
-                                                  
-                                                  new Pman.Request({
-                                                      method : 'POST',
-                                                      url : baseURL + '/Roo/gltrans',
-                                                      mask : "Posting",
-                                                      params : {
-                                                          _post : 1,
-                                                          gltrans_id : rec.data.gltrans_id
-                                                      },
-                                                      success : function (res)
-                                                      {
-                                                          rec.set('gltrans_posted', true);
-                                                          _this.gltxgrid.footer.onClick('first');
-                                                      
-                                                      }
-                                                  
-                                                  
-                                                  });
-                                                  return;
-                                              }
-                                              
-                                              // we have a posted transaction.
-                                              // only allow recalled to be deleted..
-                                              if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
-                                                  return false;
-                                              }
-                                              
-                                              
-                                           
-                                              
-                                              
-                                          
-                                              Roo.MessageBox.confirm(
-                                                  "Confirm", 
-                                                  "This should only be used by System Administrators - are you sure you know what you are doing!",
-                                                  function(x) {
-                                                      if (x != 'yes') {
-                                                          return;
-                                                      }
-                                                      deleteSel();
-                                                  }
-                                              );
-                                                    
-                                              
-                                              
-                                          },
-                                       render : function() 
-                                          {
-                                              _this.gltxdgrid = this; 
-                                              //_this.dialog = Pman.Dialog.FILL_IN
-                                              if (_this.gltxdpanel.active) {
-                                                 this.footer.onClick('first');
-                                              }
-                                          }
-                                    },
-                                    items : [
-
-                                    ]
-
-                                },
-                                '|xns' : 'Roo',
-                                fitToframe : true,
-                                background : false,
-                                region : 'east',
-                                title : "invdetail",
-                                xtype : 'GridPanel',
-                                fitContainer : true,
-                                xns : Roo,
-                                tableName : 'invdetail',
-                                listeners : {
-                                       activate : function() {
-                                              _this.gltxdpanel = this;
-                                              if (_this.gltxdgrid) {
-                                                  _this.gltxdgrid.footer.onClick('first');
-                                              }
-                                          }
-                                },
-                                items : [
-
-                                ]
-
+                            success : function() {
+                                _this.grid.footer.onClick('first');
                             }
-                        ]
-
+                        });
+                });
+                
+            }
+          }
+         },
+         {
+          enableToggle : true,
+          minWidth : 100,
+          text : _this._strings['88408722ed9d719c44087292bf8a06cf'] /* Prices with GST */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           render : function (_self)
+            {
+                _this.showgstBtn = _self;
+            },
+           toggle : function (_self, pressed)
+            {
+                this.setText(pressed ? "Prices exc GST" : "Prices with GST");
+                var cm = _this.grid.getColumnModel();
+            
+                cm.setHidden(cm.getIndexByDataIndex('coitem_price_tax'), pressed ? false : true);
+                cm.setHidden(cm.getIndexByDataIndex('coitem_custprice_tax'), pressed ? false : true);
+                cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal_tax'), pressed ? false : true);
+                
+                cm.setHidden(cm.getIndexByDataIndex('coitem_price'), pressed ? true : false);
+                cm.setHidden(cm.getIndexByDataIndex('coitem_custprice'), pressed ? true : false);
+                cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal'), pressed ? true : false);
+                return;
+            }
+          }
+         }
+        ]
+       },
+       toolbar : {
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'Toolbar',
+        items  : [
+         {
+          cls : 'x-btn-text-icon',
+          icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+          text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function()
+            {
+               
+                Roo.log("add presed");
+                 
+                // work out last 
+                var grid = _this.grid;
+                var err = false;
+                grid.ds.each(function(r) {
+                    if (r.data.coitem_qtyord < 1) { 
+                        Roo.MessageBox.alert("Error", "you must fill in a quantity for " + r.data.item_number);
+                        err = true;
+                        return true;
+                    }
+                    
+                });
+                if (err) {
+                    return;
+                }
+                
+            
+            //    var last = 0;
+                var last = _this.form.findField('cohead_max_linenumber').getValue();   
+                last++; 
+                if(last == 99999){
+                    last++;
+                }
+                
+            
+                _this.form.findField('cohead_max_linenumber').setValue(last);    
+                
+                // this should be getting the previous row..??
+                 var ct  =    _this.grid.ds.getCount();
+                 var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;
+                 
+                 function lastor(k,d,kk) {
+                    var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();
+                    return lastrow ? lastrow.data[kk] : def;
+                 }
+                
+                // uses form defaults or last row value.
+                var nr = _this.grid.ds.reader.newRow({
+                    coitem_linenumber : last,
+                    item_number : '',
+                    item_descrip1 : '',
+                    coitem_qtyord : 0,
+                    coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
+                    coitem_qtyshipped : 0,
+                    coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
+                    coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
+                    coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
+                    coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name'),
+                    coitem_unitcost_in_order_cur  : 0,
+                    coitem_taxtype_id : _this.data.default_taxtype_id,
+                    coitem_taxtype_id_taxtype_name : 'Taxable',
+                    coitem_status : '',
+                    avail_qty : 0
+                            
+                });
+                grid.stopEditing();
+                grid.ds.insert(grid.ds.getCount(), nr); 
+                grid.startEditing(grid.ds.getCount()-1, 1); // type..
+                nr.updatePending = 0;
+                nr.isUpdating = 0;
+                nr.isInserting =0;
+                
+            },
+           render : function (_self)
+            {
+                _this.addItemBtn = _self;
+            }
+          }
+         },
+         {
+          cls : 'x-btn-text-icon',
+          icon : rootURL + '/Pman/templates/images/search.gif',
+          text : _this._strings['9f4f3d35db49c5c2bba70a321a42fa87'] /* Find Products */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+                var last = _this.form.findField('cohead_max_linenumber').getValue();    \r
+                last++;\r
+                _this.form.findField('cohead_max_linenumber').setValue(last); 
+            
+                var ct  =    _this.grid.ds.getCount();\r
+                var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;\r
+                     \r
+                function lastor(k,d,kk) {\r
+                   var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();\r
+                   return lastrow ? lastrow.data[kk] : def;\r
+                }
+                
+                var cohead_cust_id = _this.form.findField('cohead_cust_id').getValue();
+                var cohead_id = _this.form.findField('cohead_id').getValue();
+                
+                Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cohead_cust_id, cohead_id : cohead_id} , function(res) {
+            
+                    _this.grid.stopEditing();
+            
+                    if (_this.grid.ds.getCount() > 0) {
+                        var lr = _this.grid.ds.getAt(_this.grid.ds.getCount()-1);
+                        if (!lr.data.coitem_itemsite_id) {
+                            lr.set('coitem_itemsite_id', res.item_itemsite_id_itemsite_id);
+                            lr.set('item_number',  res.item_number);
+                            lr.set('item_descrip1', res.item_descrip1);                                
+                            lr.set('coitem_listprice', res.item_price);                
+                            lr.set('coitem_price', res.item_price);                                
+                            lr.set('coitem_custprice', res.item_price);                
+                            return;
+                        }
+                    }
+                    
+                    
+                    
+                    var nr = _this.grid.ds.reader.newRow({
+                        coitem_linenumber : last,
+                        coitem_itemsite_id : res.item_itemsite_id_itemsite_id,
+                        item_number : res.item_number,
+                        item_descrip1 : res.item_descrip1,
+                        coitem_qtyord : 0,
+                        coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
+                        coitem_qtyshipped : 0,
+                        coitem_listprice : res.item_price,
+                        coitem_price : res.item_price,
+                        coitem_custprice : res.item_price,
+                        avail_qty : 0,
+                        coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
+                        coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
+                        coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
+                        coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name')
+                                
+                    });
+                    _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
+            
+               }); 
+            }
+          }
+         },
+         {
+          cls : 'x-btn-text-icon',
+          hidden : true,
+          icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+          text : _this._strings['a0947dda65e4112f49260243804b6528'] /* Xfer all stock to HK */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function()
+            {
+                // work out last 
+                new Pman.Request({
+                    url : baseURL + '/Roo/coitem',
+                    mask : 'Loading Data',
+                    method: 'GET',
+                    params : {
+            
+                        _hk_xfer :_this.form.findField('cohead_id').getValue()
                     },
-                    '|xns' : 'Roo',
-                    region : 'center',
-                    xtype : 'NestedLayoutPanel',
-                    title : "GL Tx",
-                    xns : Roo,
-                    items : [
-
-                    ]
-
-                },
-               {
-                    grid : {
-                        dataSource : {
-                            proxy : {
-                                '|xns' : 'Roo.data',
-                                url : baseURL + '/Roo/coitem.php',
-                                xtype : 'HttpProxy',
-                                method : 'GET',
-                                xns : Roo.data
-                            },
-                            reader : {
-                                '|xns' : 'Roo.data',
-                                id : 'id',
-                                root : 'data',
-                                xtype : 'JsonReader',
-                                xns : Roo.data,
-                                fields : [
-                                    {
-                                        'name': 'id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'name',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'type',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_office_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_name',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_phone',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_fax',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_email',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_company_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_role',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_active',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_remarks',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_passwd',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_owner_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_lang',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_no_reset_sent',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_action_type',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_project_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_deleted_by',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_deleted_dt',
-                                        'type': 'date'
-                                    },
-                                    {
-                                        'name': 'leader_firstname',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_lastname',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_name_facebook',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_url_blog',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_url_twitter',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_url_linkedin',
-                                        'type': 'string'
-                                    },
-                                    {
-                                        'name': 'leader_crm_lead_percentage',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_crm_industry_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_crm_updated_action_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_crm_created_action_id',
-                                        'type': 'int'
-                                    },
-                                    {
-                                        'name': 'leader_crm_type_id',
-                                        'type': 'int'
-                                    }
-                                ],
-                                totalProperty : 'total'
-                            },
-                            '|xns' : 'Roo.data',
-                            xtype : 'Store',
-                            remoteSort : true,
-                            sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
-                            xns : Roo.data,
-                            listeners : {
-                               beforeload : function (_self,o) {
-                                  
-                                      try {
-                                         this.removeAll();
-                                     } catch (e) { }
-                                     
-                                  
-                                      if (!_this.data || !_this.data.cohead_id) {
-                                          return false;
-                                      }
-                                      o.params = o.params || {};
-                                      
-                                      o.params.coitem_cohead_id = _this.data.cohead_id;
-                                      o.params._without_list_discount =1;
-                                      o.params._with_profit = 1;
-                                      
-                                  }
-                            },
-                            items : [
-
-                            ]
-
+                    success : function() {
+                        _this.grid.ds.load({});
+                    }
+                
+                });
+            },
+           render : function (_self)
+            {
+                _this.xferAll  = _self;
+            }
+          }
+         },
+         {
+          text : _this._strings['66b2bba3de9b8c5d6fb94e9458f1b7f5'] /* Show Inventory History */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+               var c    = _this.grid.getSelectionModel().getSelectedCell();
+               if (!c) {
+                    Roo.MessageBox.alert("Error", "Select item to show history (you can also double click on the #avail number) ");
+                    return;
+               }
+               
+                var rec = _this.grid.ds.getAt(c[0]);
+            
+              Pman.Dialog.XtupleInvHistory.show({
+                    itemsite_item_id_item_number   : rec.data.item_number,
+                   // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
+                    location_name : rec.data.coitem_location_src_location_name,
+                    location_descrip : rec.data.coitem_location_src_location_descrip,
+                    
+                    
+                    invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
+                }); 
+                
+               
+            }
+          }
+         },
+         {
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Separator'
+         },
+         {
+          text : _this._strings['c43b0fbe81e21c0a874a155ce528eebf'] /* Apply % Discount of :  */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'TextItem'
+         },
+         {
+          width : 40,
+          xns : Roo.form,
+          '|xns' : 'Roo.form',
+          xtype : 'TextField',
+          listeners : {
+           render : function (_self)
+            {
+                _this._applyDiscount = _self;
+            }
+          }
+         },
+         {
+          text : _this._strings['e87de1a5d238411ab34a292be599e9f4'] /* Apply To All */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+                var val =  parseFloat(_this._applyDiscount.getValue());
+                
+                var factor = (100.0 - val)/100.0;
+                
+                _this.grid.ds.each(function(rec) {
+                    if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
+                        return;
+                    }
+                
+                    rec.set('coitem_price', rec.data.coitem_custprice * factor);
+                    rec.set('coitem_linedisc', val);
+                    rec.set('coitem_subtotal', rec.data.coitem_price  & rec.data.ordqty);
+                    rec.commit();
+                
+                });
+                
+                
+            }
+          }
+         },
+         {
+          text : _this._strings['72d6d7a1885885bb55a565fd1070581a'] /* Import */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function (_self, e)
+            {
+            
+                if (!(1* _this.form.findField('cohead_id').getValue())) {
+                    Roo.MessageBox.alert("Error", "save the order first");
+                }
+                
+            
+               Pman.Dialog.Image.show(
+                   {
+                        timeout : 60000,
+                        _url : baseURL+'/Xtuple/Import/SalesOrder',
+                        onid : _this.form.findField('cohead_id').getValue()
+                    
+                   },
+                   function (data) {
+            
+                        Roo.MessageBox.alert("Notice", "Uploaded");
+                        _this.grid.footer.onClick('first');
+            
+                   }
+               );
+            }
+          }
+         },
+         {
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Fill'
+         },
+         {
+          cls : 'x-btn-text-icon',
+          icon : rootURL + '/Pman/templates/images/trash.gif',
+          text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function()
+            {
+                 _this.grid.stopEditing();
+                // check that no shipments or invoices are done..
+                var rc = _this.grid.getSelectionModel().getSelectedCell();
+                
+                var rec = _this.grid.ds.getAt(rc[0]);
+                
+                if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
+                    Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
+                    return;
+                }
+               if (rec.data.coitem_subnumber*1  > 0) {
+                    Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
+                    return;
+                }
+                if (!rec.data.coitem_id) {
+                    _this.grid.ds.remove(rec);
+                    return;
+                }
+                function remove()
+                {
+                
+                    new  Pman.Request({
+                        url : baseURL + '/Roo/coitem',
+                        method : 'POST',
+                        params : {
+                            _delete : rec.data.coitem_id
+                        
                         },
-                        footer : {
-                            '|xns' : 'Roo',
-                            pageSize : 25,
-                            xtype : 'PagingToolbar',
-                            emptyMsg : "No coitem found",
-                            xns : Roo,
-                            displayMsg : "Displaying coitem{0} - {1} of {2}",
-                            displayInfo : true
+                        success : function() {
+                            if (rec.data.item_type == 'K') {
+                                _this.grid.ds.load({});
+                                return;
+                            }
+                            _this.grid.ds.remove(rec);
+                        }
+                    
+                    });
+                }
+                if (rec.data_qtyord * 1 < 1) {
+                    remove();
+                }
+                
+                Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
+                {
+                    if (r != 'yes') {
+                        return;
+                    }
+                    remove();
+                
+                });
+            
+                
+                
+            }
+          }
+         },
+         {
+          cls : 'x-btn-text-icon',
+          icon : rootURL + '/Pman/templates/images/trash.gif',
+          text : _this._strings['27f2870eaa01c99fc83105240ad15f7f'] /* Delete All */,
+          xns : Roo.Toolbar,
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          listeners : {
+           click : function()
+            {
+                 _this.grid.stopEditing();
+                // check that no shipments or invoices are done..
+                var ids = [];
+                _this.grid.ds.each(function(rec) {
+                
+            
+                
+                    if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
+                        //Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
+                        return;
+                    }
+                    if (rec.data.item_type == 'K') {
+                        return;
+                    }
+            
+                   if (rec.data.coitem_subnumber*1  > 0) {
+                        //Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
+                        return;
+                    }
+                    if (!rec.data.coitem_id) {
+                        _this.grid.ds.remove(rec);
+                        return;
+                    }
+                    ids.push(rec.data.coitem_id);
+                });
+                function remove()
+                {
+                
+                    new  Pman.Request({
+                        url : baseURL + '/Roo/coitem',
+                        method : 'POST',
+                        params : {
+                            _delete : ids.join(',')
+                        
                         },
-                        '|xns' : 'Roo.grid',
-                        autoExpandColumn : 'item_number',
-                        xtype : 'Grid',
-                        loadMask : true,
-                        xns : Roo.grid,
-                        colModel : [
-                                {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Item Code',
-                                       width : 75,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'item_number'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'SubTotal',
-                                       width : 200,
-                                       renderer : function(v) {
-                                       
-                                       
-                                            return Roo.util.Format.number( v, 2);
-                                         },
-                                       xns : Roo.grid,
-                                       dataIndex : 'calc_subtotal'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Cost of goods',
-                                       width : 200,
-                                       renderer : function(v) {
-                                       
-                                           return Roo.util.Format.number( v, 2);
-                                         },
-                                       xns : Roo.grid,
-                                       dataIndex : 'calc_cost_total'
-                                   },
-{
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Profit',
-                                       width : 200,
-                                       renderer : function(v,x,r) {
-                                               
-                                          var profit = r.data.calc_subtotal - r.data.calc_cost_total;
-                                          
-                                          if(parseInt(profit) < 1){
-                                              return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(profit,2));      
-                                          }
-                                               
-                                               
-                                           return Roo.util.Format.number( profit, 2);
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'profit'
-                                   }
-                        ],
-                        listeners : {
-                               render : function() 
-                                  {
-                                      _this.profitgrid = this; 
-                                      //_this.dialog = Pman.Dialog.FILL_IN
-                                      if (_this.profitpanel.active) {
-                                         this.footer.onClick('first');
-                                      }
-                                  }
+                        success : function() {
+            
+                            _this.grid.footer.onClick('first');
+                        }
+                    
+                    });
+                }
+            //    if (rec.data_qtyord * 1 < 1) {
+            //        remove();
+            //    }
+                
+                Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete everything?", function(r)
+                {
+                    if (r != 'yes') {
+                        return;
+                    }
+                    remove();
+                
+                });
+            
+                
+                
+            }
+          }
+         }
+        ]
+       },
+       dataSource : {
+        remoteSort : true,
+        sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
+        xns : Roo.data,
+        '|xns' : 'Roo.data',
+        xtype : 'Store',
+        listeners : {
+         beforeload : function (_self,o) {
+          
+              try {
+                 this.removeAll();
+             } catch (e) { }
+             
+          
+              if (!_this.data || !_this.data.cohead_id) {
+                  return false;
+              }
+              o.params = o.params || {};
+              
+              o.params.coitem_cohead_id = _this.data.cohead_id;
+              o.params._without_list_discount =1;
+              //o.params.limit = 999;
+          
+              
+          },
+         load : function (_self, records, options)
+          {
+              // need to fetch availablity from master data..
+              // build a list of what to ask..
+          
+              // query: ITEM CODE - LOCATION
+              _this.grid.footer.updateSummary();
+              _this.grid.loadAvail.defer(100, _this.grid);
+          
+              
+              
+              
+          },
+         update : function (_self, rec, operation)
+              {
+             
+             if (operation !=  Roo.data.Record.COMMIT) {
+                 return;
+             }
+          
+             // row has been updated..
+             // if the qty + item has been filled in, we should try and save it..
+           
+              
+              var setRecord = function(){
+              
+                   Roo.log("Clearing update?"  + rec.data.coitem_linenumber);
+                  rec.updatePending = 0;
+                  if(rec.isInserting){
+                      rec.isInserting = 0;
+                      return;
+                  }
+                  rec.isUpdating = 0;
+          
+              }
+              if (!(rec.data.coitem_itemsite_id * 1) || !(rec.data.coitem_qtyord*1)) {
+                  setRecord();
+                  return;
+              }
+              var     doCommit = function() {
+                   Roo.log("Sending  data?"  + rec.data.coitem_linenumber);
+                  
+                  new Pman.Request({
+                      url : baseURL+'/Roo/coitem',
+                      method : 'POST',
+                      params : rec.data,
+                      success: function(res)
+                      {
+                          try {
+                              var row = _this.grid.ds.indexOf(rec);
+                              Roo.get(_this.grid.view.getRow(row)).removeClass('dragon-not-saved');
+                          } catch(e) {
+                              Roo.log(e);
+                          }
+                              
+                          
+                           Roo.log("GOT success: "  + rec.data.coitem_linenumber);
+                          //Roo.log("GOT success");
+                          // update the data...
+                          
+                          if (rec.data.item_type == 'K') {
+                               Roo.log("Kit??");
+                              _this.grid.ds.load({});
+                              
+                              return;
+                          }
+                          
+                          // why is this here.??
+                          
+                          if (_this.grid.activeEditor) {
+                               rec.editing = true;
+                               
+                               
+                           } 
+                           
+                          rec.set('coitem_id', res.data.coitem_id);
+                          rec.set('coitem_status', res.data.coitem_status);
+                           
+                          
+                          rec.dirty = false;
+                          delete rec.modified;
+                          try {
+                              _this.grid.footer.updateSummary();          
+                              _this.grid.loadAvail();
+                          } catch (e) { }
+                          
+          
+                          setRecord();
+                      },
+                      failure : function(res)
+                      {
+                          setRecord();
+                          Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error updating");
+                      }
+                      
+                      
+                  });
+                } ; 
+             
+              
+              doCommit();
+              
+              
+              
+          }
+        },
+        proxy : {
+         method : 'GET',
+         url : baseURL + '/Roo/coitem.php',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'HttpProxy'
+        },
+        reader : {
+         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\"}',
+         fields : [
+             {
+                 'name': 'coitem_linenumber',
+                 'type': 'int'
+             },
+             {
+                 'name': 'coitem_itemsite_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'coitem_qtyord'
+             },
+             {
+                 'name': 'coitem_unitcost'
+             },
+             {
+                 'name': 'coitem_price'
+             },
+             {
+                 'name': 'coitem_custprice'
+             },
+             {
+                 'name': 'coitem_qtyreturned'
+             },
+             {
+                 'name': 'coitem_prcost'
+             },
+             {
+                 'name': 'coitem_price_uom_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'coitem_qtyreserved'
+             }
+         ],
+         id : 'coitem_id',
+         root : 'data',
+         totalProperty : 'total',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'JsonReader'
+        }
+       },
+       sm : {
+        enter_is_tab : true,
+        xns : Roo.grid,
+        '|xns' : 'Roo.grid',
+        xtype : 'CellSelectionModel',
+        listeners : {
+         beforeeditnext : function (eventdata)
+          {
+              
+              return;
+              // this does not work, as the reload effect cancels editng.
+              var rec = _this.grid.ds.getAt(eventdata.cell[0]);
+              if (rec.data.coitem_subnumber *1 < 0 ) {
+                  return;
+              }
+              var r = eventdata.cell[0] + 1;
+          
+              while (true) {
+                  if (r > _this.grid.ds.getCount()-1 ) {
+                      eventdata.cell = false;
+                      return;
+                  }
+                  rec =  _this.grid.ds.getAt(r);
+                  if (rec.data.coitem_subnumber *1 < 0 ) {
+                     eventdata.cell = [ r, eventdata.cell[1] ];
+                     return;
+                  }
+                  r++;
+              }
+              
+              
+           
+          
+          },
+         tabend : function (_self)
+          {
+              _this.addItemBtn.fireEvent('click', _this.addItemBtn);
+          }
+        }
+       },
+       colModel : [
+        {
+         builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}',
+         dataIndex : 'coitem_linenumber',
+         header : _this._strings['7a113dee68a51f4c5f71264fd0ce3781'] /* Item# */,
+         renderer : function(v,x,r) {
+         
+             if (r.data.coitem_subnumber * 1 > 0) {
+                  return String.format('{0}.{1}', v,r.data.coitem_subnumber);
+              }
+              return String.format('{0}', v);
+           },
+         width : 40,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         dataIndex : 'item_number',
+         header : _this._strings['7608203603437f0513ba8203a2d39a4f'] /* Item Code */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 75,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowBlank : false,
+           displayField : 'itemsite_item_id_item_number',
+           editable : true,
+           emptyText : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
+           forceSelection : true,
+           hiddenName : 'itemsite_item_id_item_number',
+           listWidth : 400,
+           loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+           minChars : 2,
+           name : 'item_number',
+           pageSize : 20,
+           qtip : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
+           queryParam : 'query[number]',
+           selectOnFocus : true,
+           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>',
+           triggerAction : 'all',
+           typeAhead : false,
+           valueField : 'item_number',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'ComboBox',
+           listeners : {
+            beforeselect : function (combo, record, index)
+             {
+               // set _this.data values ..
+               var ar = _this.grid.activeEditor.record;
+             //  Roo.log('beforeselect');
+               
+               
+               (function() { 
+                  //  Roo.log('beforeselect-cb');
+                   ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
+                   ar.set('coitem_listprice', record.data.item_listprice);
+                   ar.set('coitem_price', record.data.item_price);
+                   ar.set('coitem_custprice', record.data.item_price);
+                   ar.set('coitem_itemsite_id', record.data.itemsite_id);
+                   ar.set('item_number', record.data.itemsite_item_id_item_number);
+                  ar.set('item_type', record.data.itemsite_item_id_item_type);
+                   ar.set('avail_qty', 0);
+                   ar.commit();
+               }).defer(100);
+               
+             }
+           },
+           store : {
+            remoteSort : true,
+            sortInfo : { direction : 'ASC', field: 'item_number' },
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'Store',
+            listeners : {
+             beforeload : function (_self, o){
+                  o.params = o.params || {};
+                  o.params.customer_id = _this.form.findField('cohead_cust_id').getValue();
+                  o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue();
+                  //o.params.shipto_cust_id = _this.data.cohead_cust_id;
+                  // set more here
+              }
+            },
+            proxy : {
+             method : 'GET',
+             url : baseURL + '/Roo/itemsite.php',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'HttpProxy'
+            },
+            reader : {
+             fields : [{"name":"item_id","type":"int"},"item_number"],
+             id : 'shipto_id',
+             root : 'data',
+             totalProperty : 'total',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'JsonReader'
+            }
+           }
+          }
+         }
+        },
+        {
+         dataIndex : 'coitem_location_src',
+         header : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
+         renderer : function(v,x,r) { 
+             return String.format('{0}', r.data.coitem_location_src_location_name); 
+         },
+         width : 75,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowBlank : false,
+           alwaysQuery : true,
+           displayField : 'location_name',
+           editable : true,
+           emptyText : _this._strings['fc44040a63559bee1157010d4c602422'] /* Select location */,
+           forceSelection : true,
+           hiddenName : 'coitem_location_src',
+           listWidth : 400,
+           loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+           minChars : 2,
+           name : 'coitem_location_src_location_name',
+           pageSize : 20,
+           qtip : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
+           queryParam : 'query[location_name]',
+           selectOnFocus : true,
+           tpl : '<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>',
+           triggerAction : 'all',
+           typeAhead : false,
+           valueField : 'location_id',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'ComboBox',
+           listeners : {
+            beforeselect : function (combo, record, index)
+             {
+               // set _this.data values ..
+               var ar = _this.grid.activeEditor.record;
+               
+               
+               
+               //Roo.log('beforeselect');
+              
+              /*
+               (function() { 
+                  //  Roo.log('beforeselect-cb');
+                   ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
+                   ar.set('coitem_price', record.data.item_listprice);
+                   ar.set('coitem_custprice', record.data.item_price);
+                    ar.set('coitem_itemsite_id', record.data.itemsite_id);
+                   ar.set('item_number', record.data.itemsite_item_id_item_number);
+             
+                   ar.commit();
+               }).defer(100);
+               */
+             }
+           },
+           store : {
+            remoteSort : true,
+            sortInfo : { direction : 'ASC', field: 'location_name' },
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'Store',
+            listeners : {
+             beforeload : function (_self, o){
+                  o.params = o.params || {};
+                  
+                  var row = _this.grid.activeEditor.record;
+                  
+                  o.params['query[item_itemsite_id]'] = row.data.coitem_itemsite_id;
+                  // need to know the date to calc the est. delivery time..
+                  //o.params['query[avail_when]'] = _this.form.findField('cohead_targetdate').getValue().format('Y-m-d');
+                  //o.params.location_netable = 1;
+                  o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue(); 
+                  
+                   o.params.location_restrict = 0;
+                  o.params._notinternalcompany = 1;
+                  
+                //  _this.grid;
+              
+              //    o.params.itemsite_id = _this.form.findField('cohead_cust_id').getValue();
+                  //o.params.shipto_cust_id = _this.data.cohead_cust_id;
+                  // set more here
+              }
+            },
+            proxy : {
+             method : 'GET',
+             url : baseURL + '/Roo/location.php',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'HttpProxy'
+            },
+            reader : {
+             fields : [{"name":"location_id","type":"int"},"location_name"],
+             id : 'shipto_id',
+             root : 'data',
+             totalProperty : 'total',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'JsonReader'
+            }
+           }
+          }
+         }
+        },
+        {
+         dataIndex : 'coitem_shipto_id',
+         header : _this._strings['e12167aa0a7698e6ebc92b4ce3909b53'] /* To */,
+         renderer : function(v,x,r) { 
+             return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); 
+         },
+         width : 75,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowBlank : false,
+           alwaysQuery : true,
+           displayField : 'shipto_name',
+           editable : false,
+           emptyText : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
+           forceSelection : true,
+           hiddenName : 'cohead_shipto_id',
+           listWidth : 400,
+           loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+           minChars : 2,
+           name : 'coitem_shipto_id_shipto_name',
+           pageSize : 20,
+           qtip : _this._strings['e23841a1d7427d8a9297142145dff049'] /* Select shipto */,
+           queryParam : 'query[shipto_name]',
+           selectOnFocus : true,
+           tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>',
+           triggerAction : 'all',
+           typeAhead : false,
+           valueField : 'shipto_id',
+           width : 300,
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'ComboBox',
+           listeners : {
+            add : function (combo)
+             {
+             
+                Pman.Dialog.XtupleCustomer.show({ cust_id : _this.form.findField('cohead_cust_id').getValue() }, function(data) {
+                     // refresh the data in the pulldown..
+                 }); 
+             },
+            beforeselect : function (combo, record, index)
+             {
+             
+                 var v = [];
+                 for(var i = 1; i <4; i++) {
+                     _this.data['cohead_shiptoaddress'+  i] = record.data['cntct_addr_id_addr_line'+i];
+                 }
+                 _this.form.findField('shipto_address').update();
+                 
+              
+             }
+           },
+           store : {
+            remoteSort : true,
+            sortInfo : { direction : 'ASC', field: 'shipto_name' },
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'Store',
+            listeners : {
+             beforeload : function (_self, o){
+                  o.params = o.params || {};
+                  o.params.shipto_cust_id = _this.data.cohead_cust_id; 
+                  //o.params['query[with_shipinfo]'] = 1;
+                  // set more here
+              }
+            },
+            proxy : {
+             method : 'GET',
+             url : baseURL + '/Roo/shiptoinfo.php',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'HttpProxy'
+            },
+            reader : {
+             fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
+             id : 'shipto_id',
+             root : 'data',
+             totalProperty : 'total',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'JsonReader'
+            }
+           }
+          }
+         }
+        },
+        {
+         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\":\"\"}',
+         dataIndex : 'item_descrip1',
+         header : _this._strings['d9db367d7e9d6a3d3ca0346dfa1ff9d2'] /* Item Description */,
+         renderer : function(v,x,r) { 
+         
+             if (r.data.coitem_memo && r.data.coitem_memo.length) {
+                 return String.format('{0}', r.data.coitem_memo);
+                 if (r.data.coitem_memo != v) {
+                     r.set('item_descrip1', r.data.coitem_memo);
+                 }
+                 
+             }
+             if (v && v.length > 49) {
+                 return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
+             }
+             
+             return String.format('{0}', v); 
+             
+         },
+         width : 150,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowBlank : false,
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'TextField'
+          }
+         }
+        },
+        {
+         align : 'right',
+         builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
+         dataIndex : 'coitem_status',
+         header : _this._strings['ec53a8c4f07baed5d8825072c89799be'] /* Status */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_qtyord',
+         header : _this._strings['03ab340b3f99e03cff9e84314ead38c0'] /* Qty */,
+         renderer : function(v,x,r) { 
+             var v = parseInt(v);
+             //var aq = parseInt(r.data.avail_qty);
+             //aq = isNaN(aq) ? 0 : aq;
+            
+             var rate = _this.form.findField('taxzone_rate').getValue();
+             r.data.coitem_subtotal =  v * r.data.coitem_price;
+             r.data.coitem_subtotal_tax = v * r.data.coitem_price * ( 1 + rate * 1);
+             return String.format('{0}', v); 
+             
+         },
+         width : 40,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowDecimals : false,
+           decimalPrecision : 0,
+           minValue : 1,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_price',
+         header : _this._strings['b166cb3a96bdb966f3288b8599594d0d'] /* Sell @ */,
+         renderer : function(v,x,r) { 
+         
+             var rate = _this.form.findField('taxzone_rate').getValue();
+             r.data.coitem_subtotal = v * r.data.coitem_qtyord;
+             r.data.coitem_subtotal_tax = v * ( 1 + rate * 1 ) * r.data.coitem_qtyord;
+             r.data.coitem_price_tax = v * ( 1 + rate * 1 );
+             if (parseInt(v) < 1) {
+                 return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
+             }
+             
+             
+             //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
+             
+             return  String.format('{0}', Roo.util.Format.number(v,3)); 
+         },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           decimalPrecision : 3,
+           minValue : 0,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0.0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_price_tax',
+         header : _this._strings['9122d60c0550be8ab070b96d8bbc6358'] /* Sell @w/GST */,
+         hidden : true,
+         renderer : function(v,x,r) { 
+             
+             if (parseInt(v) < 1) {
+                 return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
+             }
+             
+             return  String.format('{0}', Roo.util.Format.number(v,3)); 
+         },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           decimalPrecision : 3,
+           minValue : 0,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0.0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_linedisc',
+         header : _this._strings['9d4ba8f5211a3ba238b2032be5991c14'] /* Disc% */,
+         renderer : function(v,x,r) { 
+         
+             // coitem_custprice = coitem_price * ((100 - coitem_disc)/ 100) 
+             
+             //                      12 * (( 100 - 0) / 100)
+             // coitem_custprice / coitem_price = ((100 - coitem_disc)/ 100) 
+             // 100 - ((coitem_custprice / coitem_price) * 100)  = coitem_disc
+             //                             100 -  97 =        100 -3 
+         
+            // r.data.coitem_linedisc = 100 - (
+             //           (parseFloat(r.data.coitem_custprice) /
+              //               parseFloat(r.data.coitem_price)
+                //        ) * 100.00);
+             var fl = parseFloat(r.data.coitem_linedisc);
+             if ( isNaN(fl) || fl == 0.0 || r.data.coitem_price > r.data.coitem_custprice)  {
+                 return '';
+             }
+             return  String.format('<span style="color:green">{0}%</span>', Roo.util.Format.number( r.data.coitem_linedisc,2)); 
+         },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           decimalPrecision : 2,
+           maxValue : 100,
+           minValue : 0,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0.0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_custprice',
+         header : _this._strings['f84e65035f5d2d4a090b8a626c822321'] /* List Price */,
+         renderer : function(v,x,r) { 
+             
+             var rate = _this.form.findField('taxzone_rate').getValue();
+             r.data.coitem_custprice_tax = v * ( 1 + rate * 1 );
+             
+             var tip = 'No WRP available';
+             if ((r.data.coitem_wrpprice * 1) > 0) {
+                 tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
+             }
+             // less than zero, show as red..
+             if (parseFloat(v) < 1) {
+                 return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
+                     Roo.util.Format.number(v,3), tip); 
+             }
+             if (r.data.customer_price_each != v) {
+                   return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
+                     Roo.util.Format.number(v,3), 
+                     "List Price = " +  Roo.util.Format.number(r.data.customer_price_each,3)
+                 ); 
+             }
+             
+             
+             
+             //r.data.coitem_subtotal = v * r.data.coitem_qtyord;
+             
+             //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
+             
+             return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
+         },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           decimalPrecision : 3,
+           minValue : 0,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0.0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_custprice_tax',
+         header : _this._strings['4721299f56b6b7d43591156d1d3f3e82'] /* List Price w/GST */,
+         hidden : true,
+         renderer : function(v,x,r) { 
+             var rate = _this.form.findField('taxzone_rate').getValue();
+             var tip = 'No WRP available';
+             if ((r.data.coitem_wrpprice * 1) > 0) {
+                 tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
+             }
+             
+             if (parseFloat(v) < 1) {
+                 return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
+                     Roo.util.Format.number(v,3), tip); 
+             }
+             if (r.data.customer_price_each != v) {
+                   return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
+                     Roo.util.Format.number(v,3), 
+                     "List Price = " +  Roo.util.Format.number(r.data.customer_price_each * ( 1 + rate * 1 ),3)
+                 ); 
+             }
+             
+             return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
+         },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           decimalPrecision : 3,
+           minValue : 0,
+           style : 'text-align:right',
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'NumberField',
+           listeners : {
+            focus : function (_self)
+             {
+                 if (this.value == 0.0) {
+                     this.el.dom.value = '';
+                 }
+             }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_subtotal',
+         header : _this._strings['c5eae6ea505388a73962c635ac821fba'] /* SubTotal */,
+         renderer : function(v) {
+         
+             if (parseInt(v) < 1) {
+                 return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
+             }
+         
+             
+         
+          return Roo.util.Format.number( v, 2);
+           },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_subtotal_tax',
+         header : _this._strings['236119342501b1e596bc82013c9cfc42'] /* SubTotal w/GST */,
+         hidden : true,
+         renderer : function(v,x,r) { 
+            
+             if (parseInt(v) < 1) {
+                 return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
+             }
+             
+             return  String.format('{0}', Roo.util.Format.number(v,2)); 
+         },
+         width : 70,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
+         dataIndex : 'coitem_unitcost_in_order_cur',
+         header : _this._strings['871080cb9d00a8bda1b9f1db3c164341'] /* Unit Cost */,
+         renderer : function(v) { return Roo.util.Format.number( v, 2); },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         dataIndex : 'coitem_taxtype_id',
+         header : _this._strings['13abfee28b4564e3fb059420fbedbec5'] /* Taxed */,
+         renderer : function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel',
+         editor : {
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'GridEditor',
+          field : {
+           allowBlank : false,
+           displayField : 'taxtype_name',
+           editable : false,
+           emptyText : _this._strings['b3c65c9f85b429821cf931b38386a64d'] /* Select Tax Type */,
+           forceSelection : true,
+           hiddenName : 'coitem_taxtype_id',
+           listWidth : 400,
+           loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
+           minChars : 2,
+           name : 'coitem_taxtype_id_taxtype_name',
+           pageSize : 20,
+           qtip : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
+           queryParam : 'query[taxtype_id]',
+           selectOnFocus : true,
+           tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>',
+           triggerAction : 'all',
+           typeAhead : true,
+           valueField : 'taxtype_id',
+           width : 40,
+           xns : Roo.form,
+           '|xns' : 'Roo.form',
+           xtype : 'ComboBox',
+           store : {
+            remoteSort : true,
+            sortInfo : { direction : 'ASC', field: 'taxtype_name' },
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'Store',
+            listeners : {
+             beforeload : function (_self, o){
+                  o.params = o.params || {};
+                  // set more here
+                  
+                  
+              }
+            },
+            proxy : {
+             method : 'GET',
+             url : baseURL + '/Roo/taxtype.php',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'HttpProxy'
+            },
+            reader : {
+             fields : [{"name":"taxtype_id","type":"int"},"taxtype_name"],
+             id : 'taxtype_id',
+             root : 'data',
+             totalProperty : 'total',
+             xns : Roo.data,
+             '|xns' : 'Roo.data',
+             xtype : 'JsonReader'
+            }
+           }
+          }
+         }
+        },
+        {
+         align : 'right',
+         dataIndex : 'avail_qty',
+         header : _this._strings['7eb17faabef94701775df7154f30684b'] /* #avail */,
+         renderer : function(v,x,r) { 
+         
+             var oq  = parseInt(r.data.coitem_qtyord);
+             var aq = parseInt(r.data.avail_qty);
+             var sq = parseInt(r.data.coitem_qtyshipped);
+             aq = isNaN(aq) ? 0 : aq;
+             oq = isNaN(oq) ? 0 : oq;
+             sq = isNaN(sq) ? 0 : sq;
+             
+             var unshipped = oq - sq;
+             
+             if ( aq < 0 || (unshipped > 0  &&  aq < unshipped))  {
+                return String.format('<b style="color:red;">{0}</b>', parseInt(aq));
+             }
+              
+             return String.format('{0}', aq); 
+             
+         },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
+         dataIndex : 'shipitem_shipped',
+         header : _this._strings['7ce96513eec175e6123b56573750b0dd'] /* #reserved */,
+         renderer : function(v,x,r) { 
+         
+             
+             var vv = parseInt(v);
+             vv = isNaN(vv) ? 0 : vv;
+             
+             var ov = parseInt(r.data.coitem_qtyord);
+             ov = isNaN(ov) ? 0 : ov;
+             
+             var qs = parseInt(r.data.coitem_qtyshipped);
+             qs = isNaN(qs) ? 0 : qs;
+             
+             
+             
+             if (vv < ov) {
+                 // not enough reserved yet.
+                 return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv - qs);
+             }
+             
+             return String.format('{0}', vv -  qs); 
+             
+         },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
+         dataIndex : 'coitem_qtyshipped',
+         header : _this._strings['6b15347cbd1bf352b547741a7525c1b4'] /* #shipped */,
+         renderer : function(v,x,r) { 
+             
+             var vv = parseInt(v);
+             vv = isNaN(vv) ? 0 : vv;
+             
+             var ov = parseInt(r.data.coitem_qtyord);
+             ov = isNaN(ov) ? 0 : ov;
+             
+         
+             if (vv != ov) {
+                 // not enought shipped.
+                 // or too many shipped.
+                 return String.format('<b style="background-color:red;color:yellow">{0}</b>',  vv);
+             }
+         
+             
+             
+             return String.format('{0}', vv); 
+             
+         },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         align : 'right',
+         dataIndex : 'cobill_billed',
+         header : _this._strings['f3d90c6982143029487fb00d4ef19526'] /* #invoiced */,
+         renderer : function(v,x,r) { 
+             
+             var vv = parseInt(v);
+             vv = isNaN(vv) ? 0 : vv;
+             
+             var ov = parseInt(r.data.coitem_qtyord);
+             ov = isNaN(ov) ? 0 : ov;
+             
+         
+             if (vv !=ov) {
+                     return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv); 
+             }
+             return String.format('{0}', vv); 
+             
+         },
+         width : 50,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        }
+       ]
+      }
+     },
+     {
+      region : 'center',
+      title : _this._strings['50104a28589c5b6099d3580861c2551a'] /* Shipments / Invoices */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'NestedLayoutPanel',
+      listeners : {
+       activate : function (_self)
+        {
+            _this.shipinvtab = _self;
+        }
+      },
+      layout : {
+       xns : Roo,
+       '|xns' : 'Roo',
+       xtype : 'BorderLayout',
+       center : {
+        titlebar : true,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       north : {
+        height : 250,
+        title : _this._strings['607ff05a0e4c02c54b2262cd2e381aff'] /* Reserve Stock / Shipments */,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       items  : [
+        {
+         background : false,
+         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\"}',
+         fitContainer : true,
+         fitToframe : true,
+         region : 'north',
+         tableName : 'shiphead',
+         title : _this._strings['f4757c5aca5e4410b63c6ec4cd0f2363'] /* shiphead */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.shippanel = this;
+               if (_this.shipgrid) {
+                   _this.shipgrid.ds.load({});
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'shiphead_shipvia',
+          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\"}',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           render : function() 
+            {
+                _this.shipgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.shippanel.active) {
+                   this.ds.load({});
+                }
+            },
+           rowdblclick : function (_self, rowIndex, e)
+            {
+                var rec = this.ds.getAt(rowIndex);
+                if (!rec.json.shiphead_shipdate.length) {
+                     Roo.MessageBox.alert("Error", "You can not edit voided shipments, create a new one, and use the restore feature");
+                     return;
+                 }
+            
+               Pman.Dialog.XtupleShipment.show({
+                    shiphead_id : rec.data.shiphead_id
+            
+                }, function() {
+                    _self.ds.load({});
+                
+                });
+               
+            }
+          },
+          toolbar : {
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'Toolbar',
+           items  : [
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/lock.gif',
+             text : _this._strings['813f81532d71077e497863ec9faf16c7'] /* Confirm Shipment */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function()
+               {
+                    var sel  = _this.shipgrid.getSelectionModel().getSelected();
+                   if (!sel) {
+                       Roo.MessageBox.alert("Error", "Select a shipment");
+                       return;
+                   }
+                   if (sel.data.shiphead_shipped) {
+                       Roo.MessageBox.alert("Error", "Shipment is already confirmed");
+                       return;
+                   }
+                   
+                   
+                   // check current status of shipment..
+                   
+                       
+                   new Pman.Request({ 
+                          mask : 'Sending',
+                       url : baseURL + '/Roo/shiphead',
+                       method : 'POST',
+                       timeout : 90000,
+                       params : {
+                           shiphead_id : sel.data.shiphead_id,
+                           _confirm : 1
+                       },
+                       success : function() {
+                           _this.shipgrid.ds.load({});
+                       }
+                   });
+                        
+                    
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/save.gif',
+             text : _this._strings['70c6ddcd97af88d0aaac48268c459727'] /* Download (as xls) */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function()
+               {
+                    var sel  = _this.shipgrid.getSelectionModel().getSelected();
+                   if (!sel) {
+                       Roo.MessageBox.alert("Error", "Select a shipment");
+                       return;
+                   }
+               
+                   
+                   // check current status of shipment..
+                   
+                       
+                  new Pman.Download({
+                       url : baseURL + '/Roo/shiphead',
+                       method : 'GET',
+                       params : {
+                          _download :sel.data.shiphead_id
+                            
+                       }
+                   });
+                        
+                    
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/pdf.gif',
+             text : _this._strings['8c6aab77edc5b8e589b36bcf989683e4'] /* Print Picking Slip */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function ()
+               {
+                   var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
+                   if (!sel) {\r
+                       Roo.MessageBox.alert("Error", "Select a shipment");\r
+                       return;\r
+                   }\r
+                   // check current status of shipment..
+                
+                       new Pman.Download({
+                           url : baseURL + '/Xtuple/Print',
+                           method : 'GET',
+                           params : {
+                               template : 'picking-slip',
+                               param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
+                               filename : 'picking-slip-' + sel.data.shiphead_number
+                           },
+                           success : function() {
+               
+                           }
+                       })
+                           
+                           
+                  
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/pdf.gif',
+             text : _this._strings['1b7132f58f9ee9de75e5778ff04f7303'] /* Print Delivery Note */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function ()
+               {
+                   var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
+                   if (!sel) {\r
+                       Roo.MessageBox.alert("Error", "Select a shipment");\r
+                       return;\r
+                   }\r
+                   // check current status of shipment..
+               
+                       new Pman.Download({
+                           url : baseURL + '/Xtuple/Print',
+                           method : 'GET',
+                           params : {
+                               template : 'delivery-note-',
+                               param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
+                               filename : 'delivery-note-' + sel.data.shiphead_number
+                           },
+                           success : function() {
+               
+                           }
+                       })
+                           
+                           
+                  
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/dd/email.gif',
+             text : _this._strings['62f0de97dd70387d493350e45bfa5583'] /* Send Delivery Email */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function()
+               {
+                   var s = _this.shipgrid.getSelectionModel().getSelected();
+                   
+                   if(!s || s.data.shiphead_id * 1 < 1){
+                       Roo.MessageBox.alert('Error', 'Please select a shipment');
+                       return;
+                   }
+                   
+                   new Pman.Request({
+                       method: 'POST',
+                       url: baseURL+ '/Roo/shiphead',
+                       params : {
+                           shiphead_id : s.data.shiphead_id,
+                           _send_delivery : 1
+                       },
+                       success : function() {
+                           Roo.MessageBox.alert('Notice', 'SENT');
+                       }
+                   });
+                   
+               }
+             }
+            },
+            {
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Fill'
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+             text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function()
+               {   
+                   if (!_this.form.findField('cohead_id').getValue()) {
+                       Roo.MessageBox.alert("Error", "Save Order first");
+                       return;
+                   }
+                   var rv = _this.form.getFieldValues();
+                   
+                   Pman.Dialog.XtupleShipmentNew.show({
+                           shiphead_order_id : rv.cohead_id,
+                           shiphead_shipdate :  _this.form.findField('cohead_targetdate').getValue().format('Y-m-d')
+                       },
+                       function() { 
+                            _this.shipgrid.ds.load({});
+                       }
+                   );
+               },
+              render : function (_self)
+               {
+                 _this.addShipmentBtn = _self;
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/trash.gif',
+             text : _this._strings['9aa6071f39d387792476bd70fed66735'] /* Void / Unconfirm */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function()
+               {
+                   var sel  = _this.shipgrid.getSelectionModel().getSelected();
+                   if (!sel) {
+                       Roo.MessageBox.alert("Error", "Select a shipment");
+                       return;
+                   }
+                   // check current status of shipment..
+                   
+                   var msg = sel.data.shiphead_shipped ? 
+                       "Are you sure you want to un-confirm that shipment? - It will remove items from unposted invoices" : 
+                       "Are you sure you want to void that shipment?";
+                   
+                   Roo.MessageBox.confirm("Are you sure", msg,
+                       function(r) {
+                           if (r != 'yes') {
+                               return;
+                           }
+                           new Pman.Request({
+                               mask : 'Sending',
+                                timeout : 90000,
+                               url : baseURL + '/Roo/shiphead',
+                               method : 'POST',
+                               
+                               params : {
+                                   shiphead_id : sel.data.shiphead_id,
+                                   _void : 1
+                               },
+                               success : function() {
+                                   _this.shipgrid.ds.load({});
+                               }
+                           })
+                           
+                       }
+                   );
+                           
+                           
+                   
+                   
+                   
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           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\"}',
+           remoteSort : true,
+           sortInfo : { field : 'shiphead_shipvia', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, options)
+             {
+                  options.params = options.params || {};
+                  options.params.shiphead_order_id = _this.form.findField('cohead_id').getValue() * 1;
+                 if (options.params.shiphead_order_id < 1) {
+                     return false;
+                 }
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/shiphead.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            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\"}',
+            fields : [
+                {
+                    'name': 'shiphead_number',
+                    'type': 'string'
+                },
+                {
+                    'name': 'shiphead_shipvia',
+                    'type': 'string'
+                },
+                {
+                    'name': 'shiphead_shipdate',
+                    'type': 'date'
+                },
+                {
+                    'name': 'shiphead_sfstatus'
+                },
+                {
+                    'name': 'shiphead_tracknum',
+                    'type': 'string'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          sm : {
+           singleSelect : true,
+           xns : Roo.grid,
+           '|xns' : 'Roo.grid',
+           xtype : 'RowSelectionModel'
+          },
+          colModel : [
+           {
+            builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+            dataIndex : 'shiphead_number',
+            header : _this._strings['b1bc248a7ff2b2e95569f56de68615df'] /* number */,
+            renderer : function(v,x,r) {
+                if (r.json.shiphead_shipdate.length) {
+                     return String.format('{0}', v); 
+                 }
+                 return String.format('<s>{0}</s>', v); 
+             },
+            width : 80,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'shiphead_location_id_location_name',
+            header : _this._strings['40e6e8652d174c7ceef48df46f9cf25a'] /* From Location */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 100,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'shiphead_shipto_id_shipto_name',
+            header : _this._strings['74002cb040b036511b8d031da591364a'] /* Ship to */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 100,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+            dataIndex : 'shiphead_shipdate',
+            header : _this._strings['e963218370d6410e1ee0f8e6128c12d4'] /* shipdate */,
+            renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+            dataIndex : 'shiphead_sfstatus',
+            header : _this._strings['ec53a8c4f07baed5d8825072c89799be'] /* Status */,
+            renderer : function(v,x,r) { 
+            
+            
+            
+              
+                if (r.json.shiphead_shipdate.length) {
+                
+                    if (r.json.shiphead_shipped) {
+                        return "Confirmed";
+                    }
+                
+                     return '<span style="color:red">Draft</span>';
+                }
+                 
+                return 'VOID';
+               
+            
+            },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}',
+            dataIndex : 'shiphead_shipvia',
+            header : _this._strings['37656f0f6cf5e5befb1ec7abd3db5804'] /* shipvia */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 200,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+            dataIndex : 'shiphead_tracknum',
+            header : _this._strings['58ec392a138714456f83d1288f553099'] /* tracknum */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 200,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        },
+        {
+         background : false,
+         fitContainer : true,
+         fitToframe : true,
+         region : 'center',
+         tableName : 'cobmisc',
+         title : _this._strings['fce9a6a1bd2a2050eb86d33103f46fd3'] /* Invoices */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.invpanel = this;
+               if (_this.invgrid) {
+                   _this.invgrid.ds.load({});
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'invchead_invcnumber',
+          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\"}',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           render : function() 
+            {
+                _this.invgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.invpanel.active) {
+                   this.ds.load({});
+                }
+            },
+           rowdblclick : function (_self, rowIndex, e)
+            {
+            
+                var ri = this.ds.getAt(rowIndex);
+                if ( ri.data.cobmisc_id < 0) { // skip summary row..
+                    return;
+                }
+                var rv = _this.form.getFieldValues();
+               Pman.Dialog.XtupleInvoice.show({
+                    cobmisc_id : ri.data.cobmisc_id,
+                    // below parms for add credit memo
+                    cmdata : {
+                        cm_cust_id : rv.cohead_cust_id,
+                        cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
+                        cm_curr_id : rv.cohead_curr_id,
+                        cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
+                        cm_terms_id : rv.cohead_terms_id,
+                        cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
+                        cm_salesrep_id : rv.cohead_salesrep_id,
+                        cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
+                        cm_docdate : new Date(),
+                        cm_taxzone_id : rv.cohead_taxzone_id,
+                        cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
+                        cm_billto_cntct_id : rv.cohead_billto_cntct_id,
+                        cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
+                        cm_location_src : rv.cohead_location_src,
+                        cm_location_src_location_name : rv.cohead_location_src_location_name,
+                        cm_billto_address : rv.billto_address
+                    }
+                },
+                    function() { 
+                     _this.invgrid.ds.load({});
+                });
+               
+            }
+          },
+          toolbar : {
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'Toolbar',
+           items  : [
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/lock.gif',
+             text : _this._strings['b8feb9ee933bc5cc05615860322e9e7a'] /* Post Invoice */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function ()
+               {
+               
+                    var sel  = _this.invgrid.getSelectionModel().getSelected();
+                   if (!sel) {
+                       Roo.MessageBox.alert("Error", "Select a invoice");
+                       return;
+                   }
+                   // check current status of shipment..
+                   
+                   Roo.MessageBox.confirm("Are you sure", "Are you sure you want to Post that invoice?",
+                       function(r) {
+                           if (r != 'yes') {
+                               return;
+                           }
+                           new Pman.Request({
+                              mask : 'Sending',
+                               url : baseURL + '/Roo/cobmisc',
+                               method : 'POST',
+                               params : {
+                                   cobmisc_id : sel.data.cobmisc_id,
+                                   _post : 1
+                               },
+                               success : function() {
+                                   _this.invgrid.ds.load({});
+                               }
+                           })
+                           
+                       }
+                   );
+                           
+                           
+                  
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/pdf.gif',
+             text : _this._strings['13dba24862cf9128167a59100e154c8d'] /* Print */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             menu : {
+              xns : Roo.menu,
+              '|xns' : 'Roo.menu',
+              xtype : 'Menu',
+              items  : [
+               {
+                text : _this._strings['f97f673be4e5f66aca62b35280d8bcde'] /* Print Standard Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function ()
+                  {
+                  
+                       var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                                  _print : 1
+                              },
+                              success : function() {
+                  
+                              }
+                          })
+                              
+                              
+                     
+                  }
+                }
+               },
+               {
+                hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
+                text : _this._strings['0ee182201463a0ea31cb073b227fbbbe'] /* Print Chinese Invoice With GST in line item */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                  
+                       var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                                  _print : 'cn'
+                                  
+                              },
+                              success : function() {
+                  
+                              }
+                          })
+                              
+                            
+                  }
+                }
+               },
+               {
+                hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
+                text : _this._strings['6ac26fe4e9a39ac45fffe6d6920dac3a'] /* Print Chinese Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                  
+                       var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                                  _print : 'cn-gst'
+                                  
+                              },
+                              success : function() {
+                  
+                              }
+                          })
+                              
+                            
+                  }
+                }
+               },
+               {
+                hidden : !(baseURL.match(/au\.php$/)),
+                text : _this._strings['69193f49683ba5a928ae8a27328105ba'] /* Print Aus - GST included Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                  
+                       var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                                  _print : 'au-gst'
+                                  
+                              },
+                              success : function() {
+                  
+                              }
+                          })
+                              
+                            
+                  }
+                }
+               },
+               {
+                hidden : !(baseURL.match(/au\.php$/)),
+                text : _this._strings['3d96cc39e5517a284e203ffc8cafcf51'] /* Print Bambini Pronto Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                    var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                  
+                                  _print : 'au-net',
+                                 ts: Math.random()
+                              }
+                          })
+                  
+                  
+                  }
+                }
+               },
+               {
+                hidden : !(baseURL.match(/au\.php$/)),
+                text : _this._strings['c6b4fd215b0cdcb7426519edc0ece828'] /* Print Bambini Pro Forma Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                  
+                       var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if (!sel.data.cobmisc_invchead_id) {
+                          Roo.MessageBox.alert("Error", "Invoice has not been posted");
+                          return;
+                      }
+                      // check current status of shipment..
+                  
+                          new Pman.Download({
+                              url : baseURL + '/Roo/invchead',
+                              method : 'GET',
+                              params : {
+                                  invchead_id : sel.data.cobmisc_invchead_id,
+                                  _print : 'au-proforma'
+                                  
+                              },
+                              success : function() {
+                  
+                              }
+                          })
+                              
+                            
+                  }
+                }
+               },
+               {
+                hidden : !( baseURL.match(/au\.php$/)),
+                text : _this._strings['46fc12727bf2c5cc79988ab857ad73b4'] /* Print Shipping / Commercial Invoice */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function (_self, e)
+                  {
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      
+                      Pman.Dialog.XtupleDiscountOfInvoice.show({invchead_id : sel.data.cobmisc_invchead_id}, function(){
+                  
+                      });
+                  }
+                }
+               }
+              ]
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+             text : _this._strings['d682c376c82f68bc65dcd05570d04dfc'] /* Payments / Refunds / Credit Memos */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             menu : {
+              xns : Roo.menu,
+              '|xns' : 'Roo.menu',
+              xtype : 'Menu',
+              items  : [
+               {
+                cls : 'x-btn-text-icon',
+                icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+                text : _this._strings['01d35df7886d24900b1ecb65da6bf21d'] /* Receive Payment */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function(_self,e)
+                      {
+                      
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel || sel.data.cobmisc_id < 1) {
+                          Roo.MessageBox.alert("Error", "Select a invoice");
+                          return;
+                      }
+                      if(!sel.data.cobmisc_posted){
+                          Roo.MessageBox.alert("Error", "This invoice has not been posted!");
+                          return;
+                      }
+                      if(sel.data.cobmisc_outstanding == 0){
+                          Roo.MessageBox.alert("Error", "There is no any outstanding of this invoice!");
+                          return;
+                      }
+                      
+                      var cust_id = _this.form.findField('cohead_cust_id').getValue();
+                      if(!cust_id){
+                          return;
+                      }
+                      var data = {
+                          cashrcpt_amount : sel.data.cobmisc_outstanding,
+                          cashrcpt_cust_id : cust_id,
+                          cashrcpt_aropen_id : sel.data.cobmisc_aropen_id_aropen_id,
+                          cashrcpt_distdate : new Date(),
+                          cashrcpt_fundstype : 'C',
+                          cashrcpt_curr_id : sel.data.cobmisc_curr_id_curr_id,
+                          cashrcpt_curr_id_curr_name : sel.data.cobmisc_curr_id_curr_name,
+                          cashrcpt_usecustdeposit : true,
+                          cashrcpt_docdate : new Date(),
+                          cashrcpt_salescat_id : -1,
+                          cashrcpt_applydate : new Date(),
+                          cashrcpt_discount : 0
+                      };
+                      Pman.Dialog.XtupleReceivePayment.show( data , function() {
+                          _this.invgrid.ds.load({});
+                      }); 
+                  }
+                }
+               },
+               {
+                cls : 'x-btn-text-icon',
+                icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+                text : _this._strings['526db6366257755024ed2556000871bc'] /* Issue Refund */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function(_self,e)
+                  {
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
+                          Roo.MessageBox.alert("Error", "Select a credit memo");
+                          return;
+                      }
+                      if(!sel.data.cobmisc_posted){
+                          Roo.MessageBox.alert("Error", "The invoice that credit memo has been applied to has been not posted");
+                          return;
+                      }
+                      var cust_id = _this.form.findField('cohead_cust_id').getValue();
+                      if(!cust_id){
+                          return;
+                      }
+                      
+                      if(!sel.data.cobmisc_outstanding || sel.data.cobmisc_outstanding == 0){
+                          Roo.MessageBox.alert("Error", "The amount of this credit memo is 0!");
+                          return;
+                      }
+                      
+                      var d = _this.form.getFieldValues();
+                      
+                      var data = {
+                          'checkhead_recip_id' : cust_id,
+                          'checkhead_recip_type' : 'C',
+                          'checkhead_checkdate' : new Date(),
+                          'checkhead_amount' : sel.data.cobmisc_outstanding,
+                          'remaining_total' : sel.data.cobmisc_outstanding,
+                          'checkhead_curr_id' : d.cohead_curr_id,
+                          'checkhead_curr_id_curr_name' : d.cohead_curr_id_curr_name,
+                          'checkhead_misc' : true,
+                          'aropen_id' : sel.data.cobmisc_cobapply_aropen_id,
+                       'cmhead_number' : sel.data.cobmisc_invchead_id_invchead_invcnumber,
+                       'cust_name' : d.cohead_cust_id_cust_name,
+                       '_create_and_post' : 1
+                  
+                      };
+                      
+                      
+                      Pman.Dialog.XtupleMiscellaneousCheck.show( data , function() {
+                          _this.invgrid.ds.load({});
+                     }); 
+                  }
+                }
+               },
+               {
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Separator'
+               },
+               {
+                cls : 'x-btn-text-icon',
+                icon : rootURL + '/Pman/templates/images/trash.gif',
+                text : _this._strings['2142511303396bd51e0cc25ea8ffe47f'] /* Void Payment */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function(_self,e)
+                  {
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel || sel.data.cobmisc_cashrcpt_id * 1 < 1) {
+                          Roo.MessageBox.alert("Error", "Select a Receive Payment");
+                          return;
+                      }
+                      
+                      Roo.MessageBox.confirm("Confirm", "Voiding receipt will mean you will have to re-enter the receipt refund - " + 
+                                      "please take note of the details so you can enter it again correctly later.", function(r) {
+                                              
+                          if (r !='yes') {
+                              return;
+                          }
+                          new Pman.Request({
+                              url : baseURL + '/Roo/cashrcpt',
+                              method : 'POST',
+                              params : {
+                                  cashrcpt_id : sel.data.cobmisc_cashrcpt_id,
+                                  _void : 1
+                              },
+                              success : function() 
+                              {
+                                  _this.invgrid.ds.load({});
+                              
+                              }
+                          });
+                      
+                     })
+                      
+                       
+                  }
+                }
+               },
+               {
+                cls : 'x-btn-text-icon',
+                icon : rootURL + '/Pman/templates/images/trash.gif',
+                text : _this._strings['052fbb9431206b4755090dc53fcef300'] /* Void Refund */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function(_self,e)
+                  {
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel || sel.data.cobmisc_checkhead_id * 1 < 1) {
+                          Roo.MessageBox.alert("Error", "Select a Miscellaneours Check");
+                          return;
+                      }
+                      
+                      Roo.MessageBox.confirm("Confirm", "Voiding refund will mean you will have to re-enter the receipt refund - " + 
+                                      "please take note of the details so you can enter it again correctly later.", function(r) {
+                                              
+                          if (r !='yes') {
+                              return;
+                          }
+                          new Pman.Request({
+                              url : baseURL + '/Roo/checkhead',
+                              method : 'POST',
+                              params : {
+                                  checkhead_id : sel.data.cobmisc_checkhead_id,
+                                  _voidPosted : 1
+                              },
+                              success : function() 
+                              {
+                                  _this.invgrid.ds.load({});
+                              
+                              }
+                          });
+                      
+                     })
+                      
+                       
+                  }
+                }
+               },
+               {
+                cls : 'x-btn-text-icon',
+                icon : rootURL + '/Pman/templates/images/trash.gif',
+                text : _this._strings['4b5a5a93e13bd338d40cf4bae2ca51cb'] /* Void Credit Memo */,
+                xns : Roo.menu,
+                '|xns' : 'Roo.menu',
+                xtype : 'Item',
+                listeners : {
+                 click : function(_self,e)
+                  {
+                      var sel  = _this.invgrid.getSelectionModel().getSelected();
+                      if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
+                          Roo.MessageBox.alert("Error", "Select a credit memo");
+                          return;
+                      }
+                      
+                      if(sel.data.cobmisc_posted){
+                          Roo.MessageBox.alert("Error", "You cann't void this credit memo, since the invoice that credit memo has been applied to has been posted");
+                          return;
+                      }
+                      
+                      if (sel.data.cobmisc_cobapply_id < 1) {
+                          Roo.MessageBox.alert("Error", "invaild credit memo");
+                          return;
+                      }
+                      Roo.MessageBox.confirm("Confirm", "Are you sure want to void this applied credit memo, " + 
+                                  "it will also void all the check that belongs to this credit memo ", function(r) {
+                                              
+                          if (r !='yes') {
+                              return;
+                          }
+                          new Pman.Request({
+                              url : baseURL + '/Roo/cobapply',
+                              method : 'POST',
+                              params : {
+                                  _delete : sel.data.cobmisc_cobapply_id,
+                                  _void : 1
+                              },
+                              success : function() 
+                              {
+                                  _this.invgrid.ds.load({});
+                              
+                              }
+                          });
+                      
+                     })
+                       
+                  }
+                }
+               }
+              ]
+             }
+            },
+            {
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Fill'
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+             text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function ()
+               {
+               
+                   if (!_this.form.findField('cohead_id').getValue()) {
+                       Roo.MessageBox.alert("Error", "Save Order first");
+                       return;
+                   }
+                   
+                   var rv = _this.form.getFieldValues();
+                   
+                  
+                  Pman.Dialog.XtupleInvoice.show({
+                       cobmisc_cohead_id : rv.cohead_id,
+                       cobmisc_shipdate :  _this.form.findField('cohead_targetdate').getValue(),
+                       cobmisc_invcdate :  _this.form.findField('cohead_targetdate').getValue(),
+                       cobmisc_curr_id : rv.cohead_curr_id,
+                       cobmisc_curr_id_curr_name : rv.cohead_curr_id_curr_name,
+                       // below parms for add credit memo
+                       cmdata : {
+                           cm_cust_id : rv.cohead_cust_id,
+                           cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
+                           cm_curr_id : rv.cohead_curr_id,
+                           cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
+                           cm_terms_id : rv.cohead_terms_id,
+                           cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
+                           cm_salesrep_id : rv.cohead_salesrep_id,
+                           cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
+                           cm_docdate : new Date(),
+                           cm_taxzone_id : rv.cohead_taxzone_id,
+                           cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
+                           cm_billto_cntct_id : rv.cohead_billto_cntct_id,
+                           cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
+                           cm_location_src : rv.cohead_location_src,
+                           cm_location_src_location_name : rv.cohead_location_src_location_name,
+                           cm_billto_address : rv.billto_address
+                       }
+                       
+                   },
+                       function() { 
+                        _this.invgrid.ds.load({});
+                   });
+                  
+               },
+              render : function (_self)
+               {
+                 _this.addInvoiceBtn = _self;
+               }
+             }
+            },
+            {
+             cls : 'x-btn-text-icon',
+             icon : rootURL + '/Pman/templates/images/trash.gif',
+             text : _this._strings['b25f6c965342495f74899e183efe20a4'] /* Void / Unpost */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function ()
+               {
+               
+                    var sel  = _this.invgrid.getSelectionModel().getSelected();
+                   if (!sel) {
+                       Roo.MessageBox.alert("Error", "Select a invoice");
+                       return;
+                   }
+                   // check current status of shipment..
+                   
+                   var params =  {
+               //        cobmisc_id : sel.data.cobmisc_id,
+                       _void : 1
+                   };
+                   if (sel.data.cobmisc_id * 1) {
+                       params.cobmisc_id = sel.data.cobmisc_id * 1 ;
+                   }
+                   if (sel.data.cobmisc_invchead_id_invchead_id * 1) {    
+                       params.invchead_id  =  sel.data.cobmisc_invchead_id_invchead_id * 1;
+                   }
+                   
+                   Roo.MessageBox.confirm("Are you sure", "Are you sure you want to VOID that invoice?",
+                       function(r) {
+                           if (r != 'yes') {
+                               return;
+                           }
+                           new Pman.Request({
+                               mask : 'Sending',
+                               url : baseURL + '/Roo/cobmisc',
+                               method : 'POST',
+                               params :  params,
+                               success : function() {
+                                   _this.invgrid.ds.load({});
+                               }
+                           })
+                           
+                       }
+                   );
+                           
+                           
+                  
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           remoteSort : true,
+           sortInfo : { field : 'invchead_invcnumber', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, options)
+             {
+             
+                 options.params = options.params || {};
+                 options.params.cobmisc_cohead_id = _this.form.findField('cohead_id').getValue() * 1;
+                 if (options.params.cobmisc_cohead_id < 1) {
+                     return false;
+                 }
+                 
+                 options.params._with_other_payment = 1;
+                 //options.params['query[invchead_ordernumber]']  = _this.form.findField('cohead_number').getValue()
+                 
+             },
+            load : function (_self, records, options)
+             {
+                 var total = 0;
+                 var done = 0;
+                 var totalic = 0.0;
+                 var totalfreight = 0.0;    
+                 var totalmisc = 0.0;        
+                 var totaltax = 0.0;        
+                
+                 Roo.each(records, function(r)
+                 {
+                     if(r.data.cobmisc_id > 1){
+                         done += parseInt(r.data.cobmisc_qty);
+                         totalic += parseFloat(r.data.cobmisc_itemcost).toFixed(2)*1;        
+                         totalmisc += parseFloat(r.data.cobmisc_misc).toFixed(2)*1;        
+                         totalfreight += parseFloat(r.data.cobmisc_freight).toFixed(2)*1;                
+                         totaltax += parseFloat(r.data.cobmisc_tax).toFixed(2)*1;                
+                         total = parseInt(r.data.cobmisc_total_qty);
+                     }
+                    
+                 });
+                 
+                 _this.shipinvtab.layout.getRegion('center').getPanel(0).setTitle(
+                     (total == done) ?
+                          "Invoices (Complete)" : 
+                         ("Invoices prepared for " +    done + '/' + total)
+                 );
+             
+                 
+                 var frtotal = (parseFloat(_this.form.findField('cohead_freight').getValue())  - totalfreight).toFixed(2);
+                 var misctotal = (parseFloat(_this.form.findField('cohead_misc').getValue()) - totalmisc).toFixed(2);
+                 var ictotal =  (parseFloat(_this.form.findField('cohead_subtotal').getValue()) - totalic).toFixed(2);
+                 var taxtotal =  (parseFloat(_this.form.findField('cohead_tax').getValue())  - totaltax).toFixed(2);
+                 var remtotal = frtotal*1 + misctotal*1 + ictotal*1 + taxtotal*1;
+                 
+                 var nr = this.reader.newRow({
+                     cobmisc_id : -1,
+                     cobmisc_invchead_id_invchead_invcnumber : "Total Remaining",
+                     cobmisc_qty : total - done,
+                     cobmisc_freight :frtotal,
+                     cobmisc_misc : misctotal,        
+                     cobmisc_itemcost  : ictotal,             
+                     cobmisc_tax : taxtotal,
+                     cobmisc_total : remtotal
+             
+                     
+                 });
+                 // do we need to add it somehow??
+                 _this.invgrid.ds.add(nr);
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/cobmisc.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            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\"}',
+            fields : [
+                {
+                    'name': 'invchead_invcnumber',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invchead_invcdate',
+                    'type': 'date'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          colModel : [
+           {
+            dataIndex : 'cobmisc_invchead_id_invchead_invcnumber',
+            header : _this._strings['42f6d99a2dddc4858882ed8e9a210b52'] /* Invoice # */,
+            renderer : function(v,x,r) { 
+                   if (v && 
+                         r.data.cobmisc_invchead_id_invchead_id * 1 && 
+                        !r.data.cobmisc_invchead_id_invchead_posted) {
+                       return  '<span style="color:red">' + 
+                            "NEEDS Voiding then re-posted: " + 
+                            String.format('{0}', v) +
+                            '</span>'; 
+                   }
+            
+                   if(v && r.data.cobmisc_id == -2){
+                        return String.format('<span style="margin-left: 10px;"> - {0} (Credit Memo)</span>', v); 
+                   }
+                   if(v && r.data.cobmisc_id == -3){
+                        return String.format('<span style="margin-left: 20px;"> - {0} (Miscellaneous Check)</span>', v); 
+                   }
+                  if(v && r.data.cobmisc_id == -4){
+                        return String.format('<span style="margin-left: 10px;"> - {0} (Receive Payment to {2}) [ {1} ]</span>', 
+                                v, r.data.cobmisc_cashrcpt_amount, r.json.cashrcpt_bankaccnt_id_bankaccnt_bankname); 
+                   }
+                   
+                    return v ? String.format('{0}', v) : 
+                            '<span style="color:red">' + "Not Posted" + '</span>'; 
+            },
+            width : 100,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            builderCfg : '{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+            dataIndex : 'cobmisc_invcdate',
+            header : _this._strings['3a6a3353e3b44ad5359c8e3178b66a54'] /* invcdate */,
+            renderer : function(v,x,r) { 
+                
+                return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); 
+            },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_qty',
+            header : _this._strings['03ab340b3f99e03cff9e84314ead38c0'] /* Qty */,
+            renderer : function(v) { return String.format('{0}', v ? parseInt(v) : 0); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_itemcost',
+            header : _this._strings['757989a16207ab23076685118640adf3'] /* Item Cost */,
+            renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_freight',
+            header : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
+            renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_tax',
+            header : _this._strings['4b78ac8eb158840e9638a3aeb26c4a9d'] /* Tax */,
+            renderer : function(v,x,r) { 
+            
+                // tax is based on the % itemcost..
+            //    var ic  = r.data.cobmisc_itemcost;
+                /*
+                var ic  =r.data.cobmisc_itemcost - (1* r.data.cobmisc_itemcost_taxfree);
+                
+                var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
+                var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
+                if (tax < 0.1) {
+                    return '';
+                }
+                var taxp = tax / totic;
+                var lv = taxp * ic;
+                */
+                return String.format('{0}', (1.0*v).toFixed(2) );
+                
+                
+             },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_cohead_id_cohead_pretax_discount',
+            header : _this._strings['a763436d2b30d54e4aff264b1636827a'] /* Discount (Pretax) */,
+            renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); },
+            width : 100,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_misc',
+            header : _this._strings['bb4af85913879b95661b81570a2c2e83'] /* Discount (Posttax) */,
+            renderer : function(v,x,r) 
+            {
+                var vv = v - r.data.cobmisc_cohead_id_cohead_pretax_discount;
+                
+                return String.format('{0}', vv ? (1.0*vv).toFixed(2) : 0); 
+            },
+            width : 100,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_total',
+            header : _this._strings['09466661df2abefeecf849e52fce8fb4'] /* Total  */,
+            renderer : function(v,x,r) { 
+            
+            /*    
+                var ic  = r.data.cobmisc_itemcost;
+                var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
+                var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
+                var     lv = 0.0;
+                if (tax > 0.0) {
+                    var taxp = tax / totic;
+                    lv = taxp * ic;
+            
+                }
+              */  
+              
+            
+                if(v){
+                    return String.format('{0}',(v * 1.0).toFixed(2) );
+                }
+                var d= r.data;
+            
+                return String.format('{0}',
+                   ((d.cobmisc_itemcost * 1.0) + 
+                   (d.cobmisc_freight * 1.0) + 
+                   (d.cobmisc_tax * 1.0) +
+                   (d.cobmisc_misc * 1.0)  
+            
+                   ).toFixed(2) );
+            },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'cobmisc_outstanding',
+            header : _this._strings['a860ed9926b241b7d4dca2d00610ab2c'] /* Outstanding */,
+            renderer : function(v,x,r) 
+            { 
+                
+                return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );
+            },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        }
+       ]
+      }
+     },
+     {
+      background : true,
+      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\"}',
+      fitContainer : true,
+      fitToframe : true,
+      region : 'center',
+      tableName : 'events',
+      title : _this._strings['16d2b386b2034b9488996466aaae0b57'] /* History */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'GridPanel',
+      listeners : {
+       activate : function() {
+            _this.hpanel = this;
+            if (_this.hgrid) {
+                _this.hgrid.footer.onClick('first');
+            }
+        }
+      },
+      grid : {
+       autoExpandColumn : 'remarks',
+       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\"}',
+       loadMask : true,
+       xns : Roo.grid,
+       '|xns' : 'Roo.grid',
+       xtype : 'Grid',
+       listeners : {
+        render : function() 
+         {
+             _this.hgrid = this; 
+             //_this.dialog = Pman.Dialog.FILL_IN
+             if (_this.hpanel.active) {
+                this.footer.onClick('first');
+             }
+         },
+        rowdblclick : function (_self, rowIndex, e)
+         {
+             if (!_this.dialog) return;
+             _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
+                 _this.grid.footer.onClick('first');
+             }); 
+         }
+       },
+       footer : {
+        displayInfo : true,
+        displayMsg : _this._strings['089ba2b5edc96565fc22c584ecfbb1a6'] /* Displaying events{0} - {1} of {2} */,
+        emptyMsg : _this._strings['594f5bdc5e1519ce9934d276e5bf081f'] /* No events found */,
+        pageSize : 25,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'PagingToolbar'
+       },
+       dataSource : {
+        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\"}',
+        remoteSort : true,
+        sortInfo : { field : 'event_when', direction: 'DESC' },
+        xns : Roo.data,
+        '|xns' : 'Roo.data',
+        xtype : 'Store',
+        listeners : {
+         beforeload : function (_self, options)
+          {
+              options.params._related_on_table = 'cohead';
+              options.params._related_on_id = _this.form.findField('cohead_id').getValue();
+          }
+        },
+        proxy : {
+         method : 'GET',
+         url : baseURL + '/Roo/events.php',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'HttpProxy'
+        },
+        reader : {
+         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\"}',
+         fields : [
+             {
+                 'name': 'event_when',
+                 'type': 'date'
+             },
+             {
+                 'name': 'action',
+                 'type': 'string'
+             },
+             {
+                 'name': 'ipaddr',
+                 'type': 'string'
+             },
+             {
+                 'name': 'person_id_name',
+                 'type': 'string'
+             },
+             {
+                 'name': 'remarks',
+                 'type': 'string'
+             }
+         ],
+         id : 'id',
+         root : 'data',
+         totalProperty : 'total',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'JsonReader'
+        }
+       },
+       colModel : [
+        {
+         builderCfg : '{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+         dataIndex : 'event_when',
+         header : _this._strings['820dbd2b8f606aff866c0bbfb6b737c1'] /* Changed */,
+         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
+         width : 120,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         builderCfg : '{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+         dataIndex : 'action',
+         header : _this._strings['418c5509e2171d55b0aee5c2ea4442b5'] /* action */,
+         renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
+         width : 120,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         builderCfg : '{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+         dataIndex : 'ipaddr',
+         header : _this._strings['75ba8d70e3692ba200f0e0df37b4d2ae'] /* IP address */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 120,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         builderCfg : '{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
+         dataIndex : 'person_id_name',
+         header : _this._strings['4ee972120bcda675f75222c87cb9d356'] /* Who */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 120,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         builderCfg : '{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}',
+         dataIndex : 'remarks',
+         header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 200,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        }
+       ]
+      }
+     },
+     {
+      region : 'center',
+      title : _this._strings['47cb03899dc494703b52c37240fa4c17'] /* Stock Tx */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'NestedLayoutPanel',
+      layout : {
+       xns : Roo,
+       '|xns' : 'Roo',
+       xtype : 'BorderLayout',
+       center : {
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       east : {
+        split : true,
+        width : 500,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       items  : [
+        {
+         background : false,
+         fitContainer : true,
+         fitToframe : true,
+         region : 'center',
+         tableName : 'invdetail',
+         title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.txpanel = this;
+               if (_this.txgrid) {
+                   _this.txgrid.footer.onClick('first');
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'item_number',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           render : function() 
+            {
+                _this.txgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.txpanel.active) {
+                   this.footer.onClick('first');
+                }
+            }
+          },
+          footer : {
+           displayInfo : true,
+           displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
+           emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
+           pageSize : 9999,
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'PagingToolbar'
+          },
+          toolbar : {
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'Toolbar',
+           items  : [
+            {
+             text : _this._strings['b80f4ed22929b09103f0c5666ad7a7e1'] /* Run Apply Fifo on order */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   new Pman.Request({
+                       mask : 'applying',
+                       url : baseURL + '/Roo/Cohead',
+                       method : 'GET',
+                       params : {
+                           _apply_fifo : _this.form.findField('cohead_id').getValue()
+                       },
+                       success : function () {
+                           Roo.MessageBox.alert("Applied", "Succesfully Applied");
+                       }
+                   });
+               }
+             }
+            },
+            {
+             text : _this._strings['d179a904ac10a39ab574fe803cc29fa3'] /* Run Void flagger */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   new Pman.Request({
+                       mask : 'running',
+                       url : baseURL + '/Roo/Cohead',
+                       method : 'GET',
+                       params : {
+                           _run_void_fix : _this.form.findField('cohead_id').getValue()
+                       },
+                       success : function () {
+                           Roo.MessageBox.alert("Applied", "Succesfully Run");
+                       }
+                   });
+               }
+             }
+            },
+            {
+             text : _this._strings['26453198f2ddac444702879a8f6d61a5'] /* Auto Reverse */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   new Pman.Download({
+                       newWindow : true,
+                       mask : 'running',
+                       url : baseURL + '/Roo/Invdetail',
+                       method : 'GET',
+                       timeout :90000,
+                       params : {
+                           _post : 1,
+                           _reverse_all_bad : _this.form.findField('cohead_id').getValue()
+                       },
+                       success : function () {
+                           Roo.MessageBox.alert("Applied", "Succesfully Run");
+                       }
+                   });
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           remoteSort : true,
+           sortInfo : { field : 'item_number', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, o)
+             {
+                 o.params.cohead_id = _this.form.findField('cohead_id').getValue();
+                 if (! o.params.cohead_id ) {
+                     this.removeAll();
+                     return false;
+                 }
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/invdetail.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            fields : [
+                {
+                    'name': 'invdetail_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_transtype',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_invhist_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_location_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_qty',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_comments',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_qty_before',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_qty_after',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_invcitem_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_expiration',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_warrpurc',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_ls_id',
+                    'type': 'int'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          sm : {
+           singleSelect : true,
+           xns : Roo.grid,
+           '|xns' : 'Roo.grid',
+           xtype : 'RowSelectionModel',
+           listeners : {
+            selectionchange : function (_self)
+             {
+                 _this.txdgrid.footer.onClick('first');;
+             }
+           }
+          },
+          colModel : [
+           {
+            dataIndex : 'item_number',
+            header : _this._strings['7d74f3b92b19da5e606d737d339a9679'] /* Item */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'rec_shipped',
+            header : _this._strings['53896265ad28c11cb4997b3c3e3e122d'] /* #Ship */,
+            renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'rec_returned',
+            header : _this._strings['d323a19bad62ff427d0b75dc52674c81'] /* #Ret */,
+            renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'tx_shipped',
+            header : _this._strings['51e07f52ae2192d23a1b43922e5beb90'] /* #TX ship */,
+            renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'tx_returned',
+            header : _this._strings['5e33fc1550a56738da96fbaaf57e72f0'] /* #TX ret */,
+            renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'tx_total',
+            header : _this._strings['1abe972d603f3bd61eefc9ac39fb7522'] /* #TX Tot */,
+            renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'total_value',
+            header : _this._strings['689202409e48743b914713f96d93947c'] /* Value */,
+            renderer : function(v,x,r) { 
+            
+                return (v*1).toFixed(3);
+            },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'tx_total',
+            header : _this._strings['56d56144d4e4a42ce450446518c4fc00'] /* #Diff */,
+            renderer : function(v,x,r) { 
+            
+                var cototal = (r.data.rec_returned*1) - (r.data.rec_shipped*1);
+            //    Roo.log(cototal);
+                var diff = (v*1) - cototal;
+             //   Roo.log(diff);
+                if (diff == 0)  {
+                    return '';
+                }
+                return String.format('<span style="color:red">{0}</span>',  diff ); 
+                },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        },
+        {
+         background : false,
+         fitContainer : true,
+         fitToframe : true,
+         region : 'east',
+         tableName : 'invdetail',
+         title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.txdpanel = this;
+               if (_this.txdgrid) {
+                   _this.txdgrid.footer.onClick('first');
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'invhist_comments',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           render : function() 
+            {
+                _this.txdgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.txdpanel.active) {
+                   this.footer.onClick('first');
+                }
+            },
+           rowclick : function (_self, rowIndex, e)
+            {
+                var s = _this.txdgrid.ds.getAt(rowIndex);
+                var dt = s.data.invhist_transdate.split(' ');
+                
+                _this.dateSel.setValue(new Date(dt[0]));
+            }
+          },
+          footer : {
+           displayInfo : true,
+           displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
+           emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
+           pageSize : 9999,
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'PagingToolbar'
+          },
+          toolbar : {
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'Toolbar',
+           items  : [
+            {
+             text : _this._strings['fa1cfdb383ea976facbdb20d40d2f811'] /* Duplicate Selected */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   var s = _this.txdgrid.selModel.getSelected();
+               
+                   if (!s) {
+                       Roo.MessageBox.alert("Error", "Select a transaction");
+                       return;
+                   }
+                   
+                   var reverseSel = function() {
+                   
+                       new Pman.Request({
+                           mask : "Reversing",
+                           url : baseURL + '/Roo/invdetail',
+                           method : 'POST',
+                           params : {
+                               _duplicate : s.data.invdetail_id
+                           }, 
+                           success : function() {
+                               _this.txdgrid.footer.onClick('first');
+                           }
+                       });
+                   
+                   }
+                   
+                   
+               
+                   Roo.MessageBox.confirm(
+                       "Confirm", 
+                       "This should only be used by System Administrators - are you sure you know what you are doing!",
+                       function(x) {
+                           if (x != 'yes') {
+                               return;
+                           }
+                           reverseSel();
+                       }
+                   );
+                                       
+                   
+                   
+                   
+               }
+             }
+            },
+            {
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Fill'
+            },
+            {
+             text : _this._strings['72bb7a9ea8714c52b0c0b8369d6a8dc3'] /* Issue Date */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'TextItem'
+            },
+            {
+             allowBlank : false,
+             fieldLabel : _this._strings['72bb7a9ea8714c52b0c0b8369d6a8dc3'] /* Issue Date */,
+             format : 'Y-m-d',
+             name : 'issue_date',
+             width : 150,
+             xns : Roo.form,
+             '|xns' : 'Roo.form',
+             xtype : 'DateField',
+             listeners : {
+              render : function (_self)
+               {
+                   _this.dateSel = _self;
+               }
+             }
+            },
+            {
+             text : _this._strings['8156649b9de8783c15c822b592c3bac6'] /* Reverse Selected */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   var s = _this.txdgrid.selModel.getSelected();
+                   var dt = _this.dateSel.getValue();
+                   if (!s) {
+                       Roo.MessageBox.alert("Error", "Select a transaction");
+                       return;
+                   }
+                   
+                   var reverseSel = function(force) {
+                   
+                       new Pman.Request({
+                           mask : "Reversing",
+                           url : baseURL + '/Roo/invdetail',
+                           method : 'POST',
+                           params : {
+                               _reverse : s.data.invdetail_id,
+                               _as_of : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
+                               _force : force
+                           }, 
+                           success : function() {
+                               _this.txdgrid.footer.onClick('first');
+                           },
+                           failure : function(res) {
+                               Roo.log(res);
+                               try {
+                                   if (res.errors.confirm) {
+                                                     
+                                       Roo.MessageBox.confirm(
+                                           "Confirm", 
+                                           "are you really sure the totals will get messed up.",
+                                           function(x) {
+                                               if (x != 'yes') {
+                                                   return;
+                                               }
+                                               reverseSel(1);
+                                           }
+                                       );
+                                       return;
+                                   }
+                               } catch(e) { }
+                               Roo.MessageBox.alert("Error", res.errorMsg);
+                               
+                               
+                           }
+                       });
+                   
+                   }
+                   
+                   
+               
+                   Roo.MessageBox.confirm(
+                       "Confirm", 
+                       "This should only be used by System Administrators - are you sure you know what you are doing!",
+                       function(x) {
+                           if (x != 'yes') {
+                               return;
+                           }
+                           reverseSel(0);
+                       }
+                   );
+                                       
+                   
+                   
+                   
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           remoteSort : true,
+           sortInfo : { field : 'invdetail_id', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, o)
+             {
+                 o.params.cohead_id = _this.form.findField('cohead_id').getValue();
+                 var s = _this.txgrid.selModel.getSelected();
+                 if (!s) { 
+                     this.removeAll();
+                     return false;
+                 }
+                 o.params.itemsite_id = s.data.invhist_itemsite_id;
+                 
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/invdetail.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            fields : [
+                {
+                    'name': 'invdetail_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_transtype',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_invhist_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_location_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_qty',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_comments',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_qty_before',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_qty_after',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_invcitem_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_expiration',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_warrpurc',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_ls_id',
+                    'type': 'int'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          colModel : [
+           {
+            dataIndex : 'invdetail_id',
+            header : _this._strings['fd216b286b94577ac68c112c0dcaf341'] /* TX# */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 60,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'invhist_transdate',
+            header : _this._strings['44749712dbec183e983dcd78a7736c41'] /* Date */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'invhist_ordnumber',
+            header : _this._strings['9c9745a343efeacc9efe9b7222b27afb'] /* Ref# */,
+            renderer : function(v,x,r) {
+                if (r.data.invfifo_void *1 != 0) {
+                    return String.format('<s>{0}</s>', v); 
+                }
+            
+                 return String.format('{0}', v); 
+             },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'location_name',
+            header : _this._strings['fd216b286b94577ac68c112c0dcaf341'] /* TX# */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 60,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'invhist_comments',
+            header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'invdetail_qty',
+            header : _this._strings['c4a0f4ddf926328daa2a350db9f9ca00'] /* Qty Changed */,
+            renderer : function(v,x,r) {
+                if ( r.data.coitem_shipped != v) {
+                    return String.format('{0} <span style="color:red">({1})</span>',
+                         Roo.util.Format.number(v,0),
+                         r.data.coitem_shipped
+                     );
+                
+                }
+                 return String.format('{0}', Roo.util.Format.number(v,0));
+            },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'invhist_value_before',
+            header : _this._strings['c4a0f4ddf926328daa2a350db9f9ca00'] /* Qty Changed */,
+            renderer : function(v,x,r) {
+                var tot = r.data.invhist_value_after*1 - v*1;
+                var f = '{0}';
+                if (r.data.invdetail_qty >0 && tot < 0) {
+                    f = '<span style="color:red">{0}</span>';
+                }
+                if (r.data.invdetail_qty < 0 && tot > 0) {
+                    f = '<span style="color:red">{0}</span>';
+                }    
+                return String.format(f, Roo.util.Format.number(tot));
+            },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'invhist_posted',
+            header : _this._strings['16cd452dda9d4398bf6240603eee40a9'] /* Posted */,
+            renderer : function(v,x,r) { 
+                
+                var state = v   ?  '-checked' : '';
+                                                
+                return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+             },
+            width : 40,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        }
+       ]
+      }
+     },
+     {
+      region : 'center',
+      title : _this._strings['99575a08540e6ee585a7b389e8bde351'] /* GL Tx */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'NestedLayoutPanel',
+      layout : {
+       xns : Roo,
+       '|xns' : 'Roo',
+       xtype : 'BorderLayout',
+       center : {
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       east : {
+        split : true,
+        width : 500,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'LayoutRegion'
+       },
+       items  : [
+        {
+         background : false,
+         fitContainer : true,
+         fitToframe : true,
+         region : 'center',
+         tableName : 'invdetail',
+         title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.gltxpanel = this;
+               if (_this.gltxgrid) {
+                   _this.gltxgrid.footer.onClick('first');
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           cellclick : function (_self, rowIndex, columnIndex, e)
+            {
+                if (columnIndex > 0) {
+                    return;
+                }
+                var rec = this.ds.getAt(rowIndex);
+                rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
+                _this.gltxdgrid.footer.onClick('first');
+            },
+           render : function() 
+            {
+                _this.gltxgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.gltxpanel.active) {
+                   this.footer.onClick('first');
+                }
+            }
+          },
+          footer : {
+           displayInfo : true,
+           displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
+           emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
+           pageSize : 9999,
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'PagingToolbar',
+           items  : [
+            {
+             enableToggle : true,
+             pressed : true,
+             text : _this._strings['8fb8fbc1c0bc53b2d01121344410e444'] /* Split sales */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
+               },
+              render : function (_self)
+               {
+                   _this.glsalesbtn = _self;
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           remoteSort : true,
+           sortInfo : { field : 'item_number', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, o)
+             {
+                 o.params.cohead_id = _this.form.findField('cohead_id').getValue();
+                 if (! o.params.cohead_id ) {
+                     this.removeAll();
+                     return false;
+                 }
+                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/gltrans.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            fields : [
+                {
+                    'name': 'invdetail_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_transtype',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_invhist_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_location_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_qty',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_comments',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_qty_before',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_qty_after',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_invcitem_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_expiration',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_warrpurc',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_ls_id',
+                    'type': 'int'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          sm : {
+           singleSelect : true,
+           xns : Roo.grid,
+           '|xns' : 'Roo.grid',
+           xtype : 'RowSelectionModel',
+           listeners : {
+            selectionchange : function (_self)
+             {
+                 _this.gltxdgrid.footer.onClick('first');;
+             }
+           }
+          },
+          colModel : [
+           {
+            dataIndex : 'gltrans_as_summary',
+            header : _this._strings['290612199861c31d1036b185b4e69b75'] /* Summary */,
+            renderer : function(v,x,r) { 
+                
+                var state = v*1   ?  '-checked' : '';
+                                                
+                return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+             },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_accnt_id_accnt_descrip',
+            header : _this._strings['08bd40c7543007ad06e4fce31618f6ec'] /* Account */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'gltrans_amount_credit',
+            header : _this._strings['0a90b1bc4078f74b6f0d117ec7df65af'] /* Credit */,
+            renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'gltrans_amount_debit',
+            header : _this._strings['009534719f8c8221440a5629f497a784'] /* Debit */,
+            renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'gltrans_amount_total',
+            header : _this._strings['a0ec87054b5e5b7847d0d8780a01a3d5'] /* Sum */,
+            renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'gltrans_amount_total_unposted',
+            header : _this._strings['58733ee735e3160c5c9fa5739fb4d056'] /* Unposted */,
+            renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        },
+        {
+         background : false,
+         fitContainer : true,
+         fitToframe : true,
+         region : 'east',
+         tableName : 'invdetail',
+         title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
+         xns : Roo,
+         '|xns' : 'Roo',
+         xtype : 'GridPanel',
+         listeners : {
+          activate : function() {
+               _this.gltxdpanel = this;
+               if (_this.gltxdgrid) {
+                   _this.gltxdgrid.footer.onClick('first');
+               }
+           }
+         },
+         grid : {
+          autoExpandColumn : 'gltrans_notes',
+          loadMask : true,
+          xns : Roo.grid,
+          '|xns' : 'Roo.grid',
+          xtype : 'Grid',
+          listeners : {
+           cellclick : function (_self, ri, ci, e)
+            {
+                
+                  var deleteSel = function() {
+                
+                    new Pman.Request({
+                        mask : "Reversing",
+                        url : baseURL + '/Roo/gltrans',
+                        method : 'POST',
+                        params : {  
+                            _void : 1,
+                            gltrans_id : rec.data.gltrans_id
+                            
+                        }, 
+                        success : function() {
+                            rec.set('gltrans_posted', false);
+                            rec.set('gltrans_deleted', true);
+                            rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
+                           _this.gltxgrid.footer.onClick('first');
+                        }
+                    });
+                
+                }
+                var undeleteSel = function() {
+                
+                    new Pman.Request({
+                        mask : "Reversing",
+                        url : baseURL + '/Roo/gltrans',
+                        method : 'POST',
+                        params : {  
+                            _unvoid : 1,
+                            gltrans_id : rec.data.gltrans_id
+                            
+                        }, 
+                        success : function() {
+                            rec.set('gltrans_posted', true);
+                            rec.set('gltrans_deleted', false);
+                            rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
+                           _this.gltxgrid.footer.onClick('first');
+                        }
+                    });
+                
+                }
+                
+                var di = this.colModel.config[ci].dataIndex;
+                if (di != 'gltrans_posted') {
+                    return;
+                }
+                
+                
+                
+                var rec = this.ds.getAt(ri);
+                if (rec.data.gltrans_deleted) {
+                
+                     Roo.MessageBox.confirm(
+                        "Confirm", 
+                        "This should only be used by System Administrators - are you sure you know what you are doing!",
+                        function(x) {
+                            if (x != 'yes') {
+                                return;
+                            }
+                            undeleteSel();
+                        }
+                    );
+                
+                    return false;
+                }
+            
+                
+                
+                if (!rec.data.gltrans_posted) {
+            
+                    
+                    
+                    new Pman.Request({
+                        method : 'POST',
+                        url : baseURL + '/Roo/gltrans',
+                        mask : "Posting",
+                        params : {
+                            _post : 1,
+                            gltrans_id : rec.data.gltrans_id
                         },
-                        items : [
-
-                        ]
-
-                    },
-                    '|xns' : 'Roo',
-                    fitToframe : true,
-                    background : true,
-                    region : 'center',
-                    title : "Profit",
-                    xtype : 'GridPanel',
-                    fitContainer : true,
-                    xns : Roo,
-                    tableName : 'coitem',
-                    listeners : {
-                       activate : function() {
-                              _this.profitpanel = this;
-                              
-                              try { if (MODULE.isBuilder) {
-                                  return;
-                              } } catch(e) { }
-                              
-                              var id = _this.form.findField('cohead_id').getValue() * 1;
-                              if (id < 1) {
-                                  Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
-                                  _this.dialog.layout.getRegion('center').showPanel(0);
-                                  return;
-                              }
-                              
-                              if (_this.profitgrid) {
-                                  _this.profitgrid.footer.onClick('first');
-                               }
-                              
-                          }
-                    },
-                    items : [
-
-                    ]
-
+                        success : function (res)
+                        {
+                            rec.set('gltrans_posted', true);
+                            _this.gltxgrid.footer.onClick('first');
+                        
+                        }
+                    
+                    
+                    });
+                    return;
                 }
-            ]
-
-        });
-    }
+                
+                // we have a posted transaction.
+                // only allow recalled to be deleted..
+                if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
+                    return false;
+                }
+                
+                
+             
+                
+                
+            
+                Roo.MessageBox.confirm(
+                    "Confirm", 
+                    "This should only be used by System Administrators - are you sure you know what you are doing!",
+                    function(x) {
+                        if (x != 'yes') {
+                            return;
+                        }
+                        deleteSel();
+                    }
+                );
+                      
+                
+                
+            },
+           render : function() 
+            {
+                _this.gltxdgrid = this; 
+                //_this.dialog = Pman.Dialog.FILL_IN
+                if (_this.gltxdpanel.active) {
+                   this.footer.onClick('first');
+                }
+            }
+          },
+          footer : {
+           displayInfo : true,
+           displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
+           emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
+           pageSize : 9999,
+           xns : Roo,
+           '|xns' : 'Roo',
+           xtype : 'PagingToolbar',
+           items  : [
+            {
+             text : _this._strings['801ab24683a4a8c433c6eb40c48bcd9d'] /* Download */,
+             xns : Roo.Toolbar,
+             '|xns' : 'Roo.Toolbar',
+             xtype : 'Button',
+             listeners : {
+              click : function (_self, e)
+               {
+                   new Pman.Download( {
+                       grid : _this.gltxdgrid
+                   
+                   });
+               }
+             }
+            }
+           ]
+          },
+          dataSource : {
+           remoteSort : true,
+           sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
+           xns : Roo.data,
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           listeners : {
+            beforeload : function (_self, o)
+             {
+                 o.params.cohead_id = _this.form.findField('cohead_id').getValue();
+                 var s = _this.gltxgrid.selModel.getSelected();
+                 if (!s) { 
+                     this.removeAll();
+                     return false;
+                 }
+                 o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
+                 o.params.gltrans_is_ship = s.data.gltrans_is_ship;
+                 o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
+                 
+                 
+             }
+           },
+           proxy : {
+            method : 'GET',
+            url : baseURL + '/Roo/gltrans.php',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'HttpProxy'
+           },
+           reader : {
+            fields : [
+                {
+                    'name': 'invdetail_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_transtype',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_invhist_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_location_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_qty',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_comments',
+                    'type': 'string'
+                },
+                {
+                    'name': 'invdetail_qty_before',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_qty_after',
+                    'type': 'float'
+                },
+                {
+                    'name': 'invdetail_invcitem_id',
+                    'type': 'int'
+                },
+                {
+                    'name': 'invdetail_expiration',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_warrpurc',
+                    'type': 'date',
+                    'dateFormat': 'Y-m-d'
+                },
+                {
+                    'name': 'invdetail_ls_id',
+                    'type': 'int'
+                }
+            ],
+            id : 'id',
+            root : 'data',
+            totalProperty : 'total',
+            xns : Roo.data,
+            '|xns' : 'Roo.data',
+            xtype : 'JsonReader'
+           }
+          },
+          colModel : [
+           {
+            dataIndex : 'gltrans_id',
+            header : _this._strings['9c9745a343efeacc9efe9b7222b27afb'] /* Ref# */,
+            renderer : function(v) { return String.format('{0}', v ); },
+            sortable : true,
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_date',
+            header : _this._strings['44749712dbec183e983dcd78a7736c41'] /* Date */,
+            renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_docnumber',
+            header : _this._strings['cb02c723b8a159fea3cd7913d3df7fbc'] /* Doc# */,
+            renderer : function(v,x,r) { 
+                if (r.data.gltrans_deleted) {
+                   return String.format('<s>{0}</s>', v);     
+                }
+                return String.format('{0}', v); 
+            },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_source',
+            header : _this._strings['f31bbdd1b3e85bccd652680e16935819'] /* Source */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_notes',
+            header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
+            renderer : function(v) { return String.format('{0}', v); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            align : 'right',
+            dataIndex : 'gltrans_amount',
+            header : _this._strings['b2f40690858b404ed10e62bdf422c704'] /* Amount */,
+            renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
+            width : 75,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           },
+           {
+            dataIndex : 'gltrans_posted',
+            header : _this._strings['16cd452dda9d4398bf6240603eee40a9'] /* Posted */,
+            renderer : function(v,x,r) { 
+                
+                var state = v   ?  '-checked' : '';
+                                                
+                return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+             },
+            width : 50,
+            xns : Roo.grid,
+            '|xns' : 'Roo.grid',
+            xtype : 'ColumnModel'
+           }
+          ]
+         }
+        }
+       ]
+      }
+     },
+     {
+      background : true,
+      fitContainer : true,
+      fitToframe : true,
+      region : 'center',
+      tableName : 'coitem',
+      title : _this._strings['182875b6c36a761f1e459624c1d93638'] /* Profit */,
+      xns : Roo,
+      '|xns' : 'Roo',
+      xtype : 'GridPanel',
+      listeners : {
+       activate : function() {
+            _this.profitpanel = this;
+            
+            try { if (MODULE.isBuilder) {
+                return;
+            } } catch(e) { }
+            
+            var id = _this.form.findField('cohead_id').getValue() * 1;
+            if (id < 1) {
+                Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
+                _this.dialog.layout.getRegion('center').showPanel(0);
+                return;
+            }
+            
+            if (_this.profitgrid) {
+                _this.profitgrid.footer.onClick('first');
+             }
+            
+        }
+      },
+      grid : {
+       autoExpandColumn : 'item_number',
+       loadMask : true,
+       xns : Roo.grid,
+       '|xns' : 'Roo.grid',
+       xtype : 'Grid',
+       listeners : {
+        render : function() 
+         {
+             _this.profitgrid = this; 
+             //_this.dialog = Pman.Dialog.FILL_IN
+             if (_this.profitpanel.active) {
+                this.footer.onClick('first');
+             }
+         }
+       },
+       footer : {
+        displayInfo : true,
+        displayMsg : _this._strings['d0cc96be641673ad48fc74374fda8137'] /* Displaying coitem{0} - {1} of {2} */,
+        emptyMsg : _this._strings['c04b33241cc5478500daf178e3720b63'] /* No coitem found */,
+        pageSize : 25,
+        xns : Roo,
+        '|xns' : 'Roo',
+        xtype : 'PagingToolbar'
+       },
+       dataSource : {
+        remoteSort : true,
+        sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
+        xns : Roo.data,
+        '|xns' : 'Roo.data',
+        xtype : 'Store',
+        listeners : {
+         beforeload : function (_self,o) {
+          
+              try {
+                 this.removeAll();
+             } catch (e) { }
+             
+          
+              if (!_this.data || !_this.data.cohead_id) {
+                  return false;
+              }
+              o.params = o.params || {};
+              
+              o.params.coitem_cohead_id = _this.data.cohead_id;
+              o.params._without_list_discount =1;
+              o.params._with_profit = 1;
+              
+          }
+        },
+        proxy : {
+         method : 'GET',
+         url : baseURL + '/Roo/coitem.php',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'HttpProxy'
+        },
+        reader : {
+         fields : [
+             {
+                 'name': 'id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'name',
+                 'type': 'string'
+             },
+             {
+                 'name': 'type',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_office_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_name',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_phone',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_fax',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_email',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_company_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_role',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_active',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_remarks',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_passwd',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_owner_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_lang',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_no_reset_sent',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_action_type',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_project_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_deleted_by',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_deleted_dt',
+                 'type': 'date'
+             },
+             {
+                 'name': 'leader_firstname',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_lastname',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_name_facebook',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_url_blog',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_url_twitter',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_url_linkedin',
+                 'type': 'string'
+             },
+             {
+                 'name': 'leader_crm_lead_percentage',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_crm_industry_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_crm_updated_action_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_crm_created_action_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'leader_crm_type_id',
+                 'type': 'int'
+             }
+         ],
+         id : 'id',
+         root : 'data',
+         totalProperty : 'total',
+         xns : Roo.data,
+         '|xns' : 'Roo.data',
+         xtype : 'JsonReader'
+        }
+       },
+       colModel : [
+        {
+         dataIndex : 'item_number',
+         header : _this._strings['7608203603437f0513ba8203a2d39a4f'] /* Item Code */,
+         renderer : function(v) { return String.format('{0}', v); },
+         width : 75,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         dataIndex : 'calc_subtotal',
+         header : _this._strings['c5eae6ea505388a73962c635ac821fba'] /* SubTotal */,
+         renderer : function(v) {
+         
+         
+              return Roo.util.Format.number( v, 2);
+           },
+         width : 200,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         dataIndex : 'calc_cost_total',
+         header : _this._strings['81dffdb31b9576e343d3f7ffcf721d7e'] /* Cost of goods */,
+         renderer : function(v) {
+         
+             return Roo.util.Format.number( v, 2);
+           },
+         width : 200,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        },
+        {
+         dataIndex : 'profit',
+         header : _this._strings['182875b6c36a761f1e459624c1d93638'] /* Profit */,
+         renderer : function(v,x,r) {
+                 
+            var profit = r.data.calc_subtotal - r.data.calc_cost_total;
+            
+            if(parseInt(profit) < 1){
+                return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(profit,2));      
+            }
+                 
+                 
+             return Roo.util.Format.number( profit, 2);
+         },
+         width : 200,
+         xns : Roo.grid,
+         '|xns' : 'Roo.grid',
+         xtype : 'ColumnModel'
+        }
+       ]
+      }
+     }
+    ]
+   });
+ }
 };