DataObjects/Invhist_transfer.php
[Pman.Xtuple] / Pman.Dialog.XtupleSalesOrder.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.XtupleSalesOrder = {
8
9  _strings : {
10   '58ec392a138714456f83d1288f553099' :"tracknum",
11   '42f6d99a2dddc4858882ed8e9a210b52' :"Invoice #",
12   '249ff431aa95198ad6814dd1d2799883' :"Select taxtype",
13   'fce9a6a1bd2a2050eb86d33103f46fd3' :"Invoices",
14   'a2fdeac60e3c5b6c51a92e027fb9d533' :"Target Delivery",
15   '96b0141273eabab320119c467cdcaf17' :"Total",
16   'd682c376c82f68bc65dcd05570d04dfc' :"Payments / Refunds / Credit Memos",
17   '75ba8d70e3692ba200f0e0df37b4d2ae' :"IP address",
18   '9f4f3d35db49c5c2bba70a321a42fa87' :"Find Products",
19   '9d4ba8f5211a3ba238b2032be5991c14' :"Disc%",
20   'e12167aa0a7698e6ebc92b4ce3909b53' :"To",
21   'c4a0f4ddf926328daa2a350db9f9ca00' :"Qty Changed",
22   '99575a08540e6ee585a7b389e8bde351' :"GL Tx",
23   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
24   'f84e65035f5d2d4a090b8a626c822321' :"List Price",
25   'fc44040a63559bee1157010d4c602422' :"Select location",
26   '62f0de97dd70387d493350e45bfa5583' :"Send Delivery Email",
27   'cc7819055cde3194bb3b136bad5cf58d' :"&nbsp;",
28   '806dca90dbeda894ffb258939f9fef9a' :"Fill empty Ship To",
29   'fce6d3795b41b54dc0dab82df50517c1' :"Select custinfo",
30   'd323a19bad62ff427d0b75dc52674c81' :"#Ret",
31   'c5eae6ea505388a73962c635ac821fba' :"SubTotal",
32   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
33   '418c5509e2171d55b0aee5c2ea4442b5' :"action",
34   '51e07f52ae2192d23a1b43922e5beb90' :"#TX ship",
35   '607ff05a0e4c02c54b2262cd2e381aff' :"Reserve Stock / Shipments",
36   '689202409e48743b914713f96d93947c' :"Value",
37   'd9db367d7e9d6a3d3ca0346dfa1ff9d2' :"Item Description",
38   '16d2b386b2034b9488996466aaae0b57' :"History",
39   'dd7bf230fde8d4836917806aff6a6b27' :"Address",
40   '986b90fb419e5349dd59b691b0e0e9f6' :"Customer PO#",
41   '7d74f3b92b19da5e606d737d339a9679' :"Item",
42   'c5c8ac6bbc6d7f5c95d0a888527554d3' :"Order Details",
43   'fd216b286b94577ac68c112c0dcaf341' :"TX#",
44   '068f80c7519d0528fb08e82137a72131' :"Products",
45   'b166cb3a96bdb966f3288b8599594d0d' :"Sell @",
46   '1243daf593fa297e07ab03bf06d925af' :"Searching...",
47   '151ccf95db9b81c11bb20fbc302af4b6' :"Select terms",
48   '7eb17faabef94701775df7154f30684b' :"#avail",
49   'f31bbdd1b3e85bccd652680e16935819' :"Source",
50   '086247a9b57fde6eefee2a0c4752242d' :"Automatic",
51   '0a90b1bc4078f74b6f0d117ec7df65af' :"Credit",
52   '27f2870eaa01c99fc83105240ad15f7f' :"Delete All",
53   '5f0c1431b38e3d279bf105d48824b7f3' :"Select ship to",
54   '26453198f2ddac444702879a8f6d61a5' :"Auto Reverse",
55   '780c462e85ba4399a5d42e88f69a15ca' :"Billing",
56   '81dffdb31b9576e343d3f7ffcf721d7e' :"Cost of goods",
57   '813f81532d71077e497863ec9faf16c7' :"Confirm Shipment",
58   '46fc12727bf2c5cc79988ab857ad73b4' :"Print Shipping / Commercial Invoice",
59   '8156649b9de8783c15c822b592c3bac6' :"Reverse Selected",
60   '8c6aab77edc5b8e589b36bcf989683e4' :"Print Picking Slip",
61   '69193f49683ba5a928ae8a27328105ba' :"Print Aus - GST included Invoice",
62   '13dba24862cf9128167a59100e154c8d' :"Print",
63   '4b5a5a93e13bd338d40cf4bae2ca51cb' :"Void Credit Memo",
64   'b80f4ed22929b09103f0c5666ad7a7e1' :"Run Apply Fifo on order",
65   '009534719f8c8221440a5629f497a784' :"Debit",
66   '1abe972d603f3bd61eefc9ac39fb7522' :"#TX Tot",
67   '7b09a122e58c067939744c4a96ff2d77' :"Select salesrep",
68   '56d56144d4e4a42ce450446518c4fc00' :"#Diff",
69   '03ab340b3f99e03cff9e84314ead38c0' :"Qty",
70   'f4c6f851b00d5518bf888815de279aba' :"Notes",
71   'c9cc8cce247e49bae79f15173ce97354' :"Save",
72   '386c339d37e737a436499d423a77df0c' :"Currency",
73   'f4757c5aca5e4410b63c6ec4cd0f2363' :"shiphead",
74   'f97f673be4e5f66aca62b35280d8bcde' :"Print Standard Invoice",
75   'acc95aeaee48871da70cc3bce664728c' :"Select shiptoinfo",
76   'ce26601dac0dea138b7295f02b7620a7' :"Customer",
77   'd335d558a8386d20318888b1f034103d' :"Unshipped Total",
78   '2925dda0ec274c20c0a30d8720eb830b' :"Select curr_name",
79   '72d6d7a1885885bb55a565fd1070581a' :"Import",
80   '9aa6071f39d387792476bd70fed66735' :"Void / Unconfirm",
81   '6f1bf85c9ebb3c7fa26251e1e335e032' :"Terms",
82   '53896265ad28c11cb4997b3c3e3e122d' :"#Ship",
83   '5da618e8e4b89c66fe86e32cdafde142' :"From",
84   '158e64bcd08067d26e9c27679eeced88' :"No Items",
85   'd179a904ac10a39ab574fe803cc29fa3' :"Run Void flagger",
86   'f3d90c6982143029487fb00d4ef19526' :"#invoiced",
87   '80092f7900d59aab765d0ddd35dc7231' :"Add Shipment",
88   'a240fa27925a635b08dc28c9e4f9216d' :"Order",
89   '01d35df7886d24900b1ecb65da6bf21d' :"Receive Payment",
90   'f817f797c422f7ac3404b6223db1a1ee' :"invdetail",
91   '50104a28589c5b6099d3580861c2551a' :"Shipments / Invoices",
92   'e23841a1d7427d8a9297142145dff049' :"Select shipto",
93   '9f1a342d0197aac60ed73e921dc4c1f5' :"Price Details",
94   '2142511303396bd51e0cc25ea8ffe47f' :"Void Payment",
95   '88408722ed9d719c44087292bf8a06cf' :"Prices with GST",
96   '236119342501b1e596bc82013c9cfc42' :"SubTotal w/GST",
97   '4b78ac8eb158840e9638a3aeb26c4a9d' :"Tax",
98   'cb02c723b8a159fea3cd7913d3df7fbc' :"Doc#",
99   '6a813cbab5d0c9d33b1a471839935d88' :"Cust#",
100   'b8feb9ee933bc5cc05615860322e9e7a' :"Post Invoice",
101   '70c6ddcd97af88d0aaac48268c459727' :"Download (as xls)",
102   '66b2bba3de9b8c5d6fb94e9458f1b7f5' :"Show Inventory History",
103   '57cdc7bcd2ca327f3267e2f5ecfa8c6d' :"Edit / Create Sales Order",
104   '48e91c2f1cb7b90612ccae2502c7327f' :"Shipment Comments",
105   '47cb03899dc494703b52c37240fa4c17' :"Stock Tx",
106   '72bb7a9ea8714c52b0c0b8369d6a8dc3' :"Issue Date",
107   'e5d63551ca2d2842661e49a25fd12a67' :"Edit Customer",
108   '7608203603437f0513ba8203a2d39a4f' :"Item Code",
109   '08bd40c7543007ad06e4fce31618f6ec' :"Account",
110   'e963218370d6410e1ee0f8e6128c12d4' :"shipdate",
111   '0ee182201463a0ea31cb073b227fbbbe' :"Print Chinese Invoice With GST in line item",
112   '089ba2b5edc96565fc22c584ecfbb1a6' :"Displaying events{0} - {1} of {2}",
113   '0bcef9c45bd8a48eda1b26eb0c61c869' :"%",
114   '81ceb48a978444906d80119200aa358d' :"Void",
115   'a763436d2b30d54e4aff264b1636827a' :"Discount (Pretax)",
116   '4721299f56b6b7d43591156d1d3f3e82' :"List Price w/GST",
117   'f4ac45b9eb622dcb26c0d4fc1c93b27c' :"Order Comments",
118   '7a113dee68a51f4c5f71264fd0ce3781' :"Item#",
119   'a860ed9926b241b7d4dca2d00610ab2c' :"Outstanding",
120   '290612199861c31d1036b185b4e69b75' :"Summary",
121   '786410e93beb0193d89f8608c54feb4b' :"Select item",
122   'b1bc248a7ff2b2e95569f56de68615df' :"number",
123   '07ca5050e697392c9ed47e6453f1453f' :"Completed",
124   '6b15347cbd1bf352b547741a7525c1b4' :"#shipped",
125   'b3c65c9f85b429821cf931b38386a64d' :"Select Tax Type",
126   '5e33fc1550a56738da96fbaaf57e72f0' :"#TX ret",
127   '16cd452dda9d4398bf6240603eee40a9' :"Posted",
128   'b2f40690858b404ed10e62bdf422c704' :"Amount",
129   'e87de1a5d238411ab34a292be599e9f4' :"Apply To All",
130   '40e6e8652d174c7ceef48df46f9cf25a' :"From Location",
131   '9122d60c0550be8ab070b96d8bbc6358' :"Sell @w/GST",
132   '78ca8a8170f2065057507ddcde63d9ca' :"Tax Zone",
133   '757989a16207ab23076685118640adf3' :"Item Cost",
134   '160ab8f9d6c5d2819fff11dea08d4ef8' :"Download Excel",
135   '0ee72ad23c24d7cfc5c13311abdc3f72' :"Staff I.C.",
136   '511b6a78f5503881ba10ff93b7205ade' :"Create CM reversal",
137   '74002cb040b036511b8d031da591364a' :"Ship to",
138   'c6b4fd215b0cdcb7426519edc0ece828' :"Print Bambini Pro Forma Invoice",
139   'b98c34417c412e0c87faa828f26b9123' :"Uninvoiced Total",
140   'a0d036a1d6a00180df168fa86143e5f8' :"No invdetail found",
141   'de3d17fb46f44fdf066581fbb5fe6113' :"Select Staff",
142   'fbb9d6ec5325d0fe63c19431856a0802' :"Select cntct",
143   'c3ce05eb16c5e0075b4a247b2c4b7bba' :"Bill To (select)",
144   'ec53a8c4f07baed5d8825072c89799be' :"Status",
145   '25d81668fca34c83d0720cc6365d62d6' :"Pre Tax discount",
146   'b25f6c965342495f74899e183efe20a4' :"Void / Unpost",
147   '58733ee735e3160c5c9fa5739fb4d056' :"Unposted",
148   '3ec365dd533ddb7ef3d1c111186ce872' :"Details",
149   'c04b33241cc5478500daf178e3720b63' :"No coitem found",
150   'ea9cf7e47ff33b2be14e6dd07cbcefc6' :"Shipping",
151   '871080cb9d00a8bda1b9f1db3c164341' :"Unit Cost",
152   '820dbd2b8f606aff866c0bbfb6b737c1' :"Changed",
153   '7ce96513eec175e6123b56573750b0dd' :"#reserved",
154   'a0ec87054b5e5b7847d0d8780a01a3d5' :"Sum",
155   '26e09a1ee1517389c7b07f42df65561a' :"Ordered",
156   'bdd31bfe5374e3cdc19a10020eae4b49' :"Add Invoice",
157   '801ab24683a4a8c433c6eb40c48bcd9d' :"Download",
158   '44749712dbec183e983dcd78a7736c41' :"Date",
159   '37656f0f6cf5e5befb1ec7abd3db5804' :"shipvia",
160   '4a2a14210d78f0d82db75d0264030169' :"Supply From",
161   '052fbb9431206b4755090dc53fcef300' :"Void Refund",
162   'c4b515058fab313f403ae427ce7e32b3' :"Update Location to match S/O",
163   '87813307f6e7498b30c5b3d9b2f65f56' :"Displaying invdetail{0} - {1} of {2}",
164   '3a6a3353e3b44ad5359c8e3178b66a54' :"invcdate",
165   '4b84bd35233c0d3d3c36b9a6ce6e0745' :"Order Items",
166   '13abfee28b4564e3fb059420fbedbec5' :"Taxed",
167   '94f475efc6722fd13ab78411c1ef7bd7' :"Sales Rep",
168   'bb4af85913879b95661b81570a2c2e83' :"Discount (Posttax)",
169   '526db6366257755024ed2556000871bc' :"Issue Refund",
170   '594f5bdc5e1519ce9934d276e5bf081f' :"No events found",
171   'd0cc96be641673ad48fc74374fda8137' :"Displaying coitem{0} - {1} of {2}",
172   'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
173   'b6dad11e8e2203819164d64fc82b40f1' :"Discount after Tax  Description",
174   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
175   '1b7132f58f9ee9de75e5778ff04f7303' :"Print Delivery Note",
176   '4ee972120bcda675f75222c87cb9d356' :"Who",
177   'a0947dda65e4112f49260243804b6528' :"Xfer all stock to HK",
178   '1d144309cbdf2536723621bf0eac9f33' :"or enter Address",
179   '3d96cc39e5517a284e203ffc8cafcf51' :"Print Bambini Pronto Invoice",
180   '9c9745a343efeacc9efe9b7222b27afb' :"Ref#",
181   'c43b0fbe81e21c0a874a155ce528eebf' :"Apply % Discount of : ",
182   'e8586011952b0d098b0e568f20ca2b1f' :"Select Currency",
183   'fa1cfdb383ea976facbdb20d40d2f811' :"Duplicate Selected",
184   '6ac26fe4e9a39ac45fffe6d6920dac3a' :"Print Chinese Invoice",
185   '182875b6c36a761f1e459624c1d93638' :"Profit",
186   '3ffaf70863d6f46e2719050a37d9ef86' :"Order#",
187   '8fb8fbc1c0bc53b2d01121344410e444' :"Split sales",
188   '09466661df2abefeecf849e52fce8fb4' :"Total "
189  },
190
191  dialog : false,
192  callback:  false,
193
194  show : function(data, cb)
195  {
196   if (!this.dialog) {
197    this.create();
198   }
199
200   this.callback = cb;
201   this.data = data;
202   this.dialog.show(this.data._el);
203   if (this.form) {
204    this.form.reset();
205    this.form.setValues(data);
206    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
207   }
208
209  },
210
211  create : function()
212  {
213    var _this = this;
214    this.dialog = Roo.factory({
215     closable : true,
216     collapsible : false,
217     height : 620,
218     modal : true,
219     resizable : true,
220     title : _this._strings['57cdc7bcd2ca327f3267e2f5ecfa8c6d'] /* Edit / Create Sales Order */,
221     width : 1050,
222     xns : Roo,
223     '|xns' : 'Roo',
224     xtype : 'LayoutDialog',
225     listeners : {
226      show : function () {
227              this.layout.getRegion('center').showPanel(0);
228       }
229     },
230     center : {
231      alwaysShowTabs : true,
232      tabPosition : 'top',
233      xns : Roo,
234      '|xns' : 'Roo',
235      xtype : 'LayoutRegion',
236      toolbar : {
237       xns : Roo,
238       '|xns' : 'Roo',
239       xtype : 'Toolbar',
240       items  : [
241        {
242         xns : Roo.Toolbar,
243         '|xns' : 'Roo.Toolbar',
244         xtype : 'Fill'
245        },
246        {
247         cls : 'x-btn-text-icon',
248         icon : rootURL + '/Pman/templates/images/spreadsheet.gif',
249         text : _this._strings['160ab8f9d6c5d2819fff11dea08d4ef8'] /* Download Excel */,
250         xns : Roo.Toolbar,
251         '|xns' : 'Roo.Toolbar',
252         xtype : 'Button',
253         listeners : {
254          click : function ()
255           {
256               var id = 1* _this.form.findField('cohead_id').getValue();
257               if (!id) {
258                   Roo.MessageBox.alert("Error", "Save Sales order first");
259                   return;
260               
261               }
262               // check current status of shipment..
263           
264                   new Pman.Download({
265                       url : baseURL + '/Roo/cohead',
266                       method : 'GET',
267                       params : {
268                           cohead_id :  id,
269                           _excel : 1
270                       },
271                       success : function() {
272           
273                       }
274                   })
275                       
276                       
277              
278           }
279         }
280        },
281        {
282         cls : 'x-btn-text-icon',
283         icon : rootURL + '/Pman/templates/images/pdf.gif',
284         text : _this._strings['13dba24862cf9128167a59100e154c8d'] /* Print */,
285         xns : Roo.Toolbar,
286         '|xns' : 'Roo.Toolbar',
287         xtype : 'Button',
288         listeners : {
289          click : function ()
290           {
291               var id = 1* _this.form.findField('cohead_id').getValue();
292               if (!id) {
293                   Roo.MessageBox.alert("Error", "Save Sales order first");
294                   return;
295               
296               }
297               // check current status of shipment..
298           
299                   new Pman.Download({
300                       url : baseURL + '/Roo/cohead',
301                       method : 'GET',
302                       params : {
303                           cohead_id :  id,
304                           _print : 1
305                       },
306                       success : function() {
307           
308                       }
309                   })
310                       
311                       
312              
313           }
314         }
315        },
316        {
317         cls : 'x-btn-text-icon',
318         hidden : true,
319         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
320         text : _this._strings['80092f7900d59aab765d0ddd35dc7231'] /* Add Shipment */,
321         xns : Roo.Toolbar,
322         '|xns' : 'Roo.Toolbar',
323         xtype : 'Button',
324         listeners : {
325          click : function (_self, e)
326           {
327           
328               _this.addShipmentBtn.fireEvent('click');
329              
330           }
331         }
332        },
333        {
334         cls : 'x-btn-text-icon',
335         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
336         text : _this._strings['e5d63551ca2d2842661e49a25fd12a67'] /* Edit Customer */,
337         xns : Roo.Toolbar,
338         '|xns' : 'Roo.Toolbar',
339         xtype : 'Button',
340         listeners : {
341          click : function (_self, e)
342           {
343           
344              Pman.Dialog.XtupleCustomer.show({
345                    cust_id : _this.form.findField('cohead_cust_id').getValue()
346             }); 
347           }
348         }
349        },
350        {
351         cls : 'x-btn-text-icon',
352         hidden : true,
353         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
354         text : _this._strings['bdd31bfe5374e3cdc19a10020eae4b49'] /* Add Invoice */,
355         xns : Roo.Toolbar,
356         '|xns' : 'Roo.Toolbar',
357         xtype : 'Button',
358         listeners : {
359          click : function (_self, e)
360           {
361           
362                   _this.addInvoiceBtn.fireEvent('click');
363              
364           }
365         }
366        },
367        {
368         text : _this._strings['81ceb48a978444906d80119200aa358d'] /* Void */,
369         xns : Roo.Toolbar,
370         '|xns' : 'Roo.Toolbar',
371         xtype : 'Button',
372         listeners : {
373          click : function (_self, e)
374           {
375                var p = {         
376                    cohead_id : _this.form.findField('cohead_id').getValue() 
377                };
378               function call() {
379           
380                       
381                  new Pman.Request({
382                       mask : 'Sending',
383                       url: baseURL + '/Roo/cohead',
384                       method : 'POST',
385                       params :  p,
386                       success : function()
387                       {
388                           _this.callback();
389                            if ( _this.data.cohead_status == 'X') {
390                             _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
391                     
392                               return;
393                            }
394           
395            
396                           _this.dialog.hide();
397                       }
398                  });
399              }
400           
401             
402              if (_this.data.cohead_status == 'X') {
403                   p._unvoid = 1;
404                   call();
405                   return;
406               }
407               
408               Roo.MessageBox.confirm("Confirm", "Are you sure you want to void this?", function(r) {
409               
410                   if (r !='yes') {
411                       return;
412                   }
413                   p._void = 1;
414                   call();       
415           
416                 
417               });
418           
419           },
420          render : function (_self, e)
421           {
422               _this.voidBtn = _self;
423           }
424         }
425        },
426        {
427         text : _this._strings['07ca5050e697392c9ed47e6453f1453f'] /* Completed */,
428         xns : Roo.Toolbar,
429         '|xns' : 'Roo.Toolbar',
430         xtype : 'Button',
431         listeners : {
432          click : function (_self, e)
433           {
434               var p = {          cohead_id : _this.form.findField('cohead_id').getValue() };
435               
436               var close = 1;
437               if (_this.data.cohead_status == 'C') {
438                   p._reopen = 1;
439                   close = 0;
440                   } else {
441                           p._close = 1;
442                   }
443                   
444              new Pman.Request({
445               url: baseURL + '/Roo/cohead',
446               method : 'POST',
447               params :  p,
448               mask : 'Sending',
449               success : function()
450               {
451                      _this.callback();
452                     if (!close) {
453                       _this.form.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
454                     
455                       return;
456                     }
457                  
458                   _this.dialog.hide();
459               }
460              });
461               
462           },
463          render : function (_self)
464           {
465              _this.closeBtn = _self;
466           }
467         }
468        }
469       ]
470      }
471     },
472     buttons : [
473      {
474       text : _this._strings['511b6a78f5503881ba10ff93b7205ade'] /* Create CM reversal */,
475       xns : Roo,
476       '|xns' : 'Roo',
477       xtype : 'Button',
478       listeners : {
479        click : function (_self, e)
480         {
481             var id = _this.form.findField('cohead_id').getValue() * 1;
482             
483             if(id < 1){
484                 Roo.MessageBox.alert('Error', 'Error occour on getting the sales order id');
485                 return;
486             }
487         
488             Roo.MessageBox.confirm("Confirm", "Are you sure to create a credit memo reversal?",
489                 function (res) {
490                     if(res!='yes') {
491                         return;
492                     
493                     }
494                     new Pman.Request({
495                         method: 'POST',
496                         url: baseURL+ '/Roo/cohead',
497                         params : {
498                             cohead_id : id,
499                             _cm_reversal : 1
500                         },
501                         success : function() {
502                             _this.form.load({ method: 'GET', params: { '_id' : id }});
503                         }
504                     });
505             }); 
506               
507         },
508        render : function (_self)
509         {
510             _this.reversalBtn = _self;
511         }
512       }
513      },
514      {
515       text : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
516       xns : Roo,
517       '|xns' : 'Roo',
518       xtype : 'Button',
519       listeners : {
520        click : function (_self, e)
521         {
522               if (_this.grid)  _this.grid.stopEditing();
523             _this.dialog.hide();
524         }
525       }
526      },
527      {
528       text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
529       xns : Roo,
530       '|xns' : 'Roo',
531       xtype : 'Button',
532       listeners : {
533        click : function (_self, e)
534         {
535             // do some checks?
536              
537               if (_this.grid)  _this.grid.stopEditing();
538          
539             _this.form.doAction("submit");
540         
541         },
542        render : function (_self)
543         {
544             _this.saveBtn = _self;
545         }
546       }
547      }
548     ],
549     items  : [
550      {
551       region : 'center',
552       title : _this._strings['c5c8ac6bbc6d7f5c95d0a888527554d3'] /* Order Details */,
553       xns : Roo,
554       '|xns' : 'Roo',
555       xtype : 'ContentPanel',
556       listeners : {
557        activate : function (_self)
558         {
559             // we need to reload to find out the subtotal.
560             if (!_this.data || !_this.data.cohead_id) {
561                 return;
562             }
563             new Pman.Request({
564                 method : 'GET',
565                 url : baseURL + '/Roo/cohead',
566                 params : { 
567                     _id : _this.data.cohead_id
568                 },
569                 success : function(res) {
570                     _this.form.findField('cohead_subtotal').setValue(res.data.cohead_subtotal);
571                     _this.form.findField('cohead_tax').setValue(res.data.cohead_tax);
572                     _this.form.findField('cohead_uninvoiced').setValue(res.data.cohead_uninvoiced);
573                     _this.form.findField('cohead_unshipped').setValue(res.data.cohead_unshipped);
574                    _this.form.findField('cohead_pretax_discount').setValue(res.data.cohead_pretax_discount); 
575                     _this.form.findField('cohead_total').recalc(); 
576                     _this.form.findField('cohead_misc').recalc(); 
577                 }
578             });
579         }
580       },
581       items  : [
582        {
583         method : 'POST',
584         style : 'margin:10px;',
585         url : baseURL + '/Roo/cohead.php',
586         xns : Roo.form,
587         '|xns' : 'Roo.form',
588         xtype : 'Form',
589         listeners : {
590          actioncomplete : function(_self,action)
591           {
592               if (action.type == 'setdata') {
593                   // clear the stock level cache...
594                   _this.stockcache = [];
595                   
596                   _this.form.findField('billto_email').setValue('');
597                   
598                   _this.reversalBtn.hide();
599                   
600                   if (_this.data.cohead_id) {
601                      this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
602                      
603                      return;
604                   }
605                   _this.dialog.setTitle("Edit New Sales Order");
606                  
607                   _this.closeBtn.hide();
608                   _this.voidBtn.hide();
609                   _this.saveBtn.show();
610                       
611                   if(_this.data.cohead_billto_cntct_id_cntct_id){
612                       _this.form.findField('billto_address').update();
613                       \r
614                       _this.form.setValues({\r
615                           cohead_billto_cntct_id: _this.data.cohead_billto_cntct_id_cntct_id,\r
616                           cohead_billto_cntct_id_cntct_name : _this.data.cohead_billto_cntct_id_cntct_name,\r
617                           _shipto_same : 1,
618                           _same_as_order : 1
619                           \r
620                       }); \r
621                   }
622                    
623                  return;
624               }
625               if (action.type == 'load') {
626                    
627                   
628                   _this.data = action.result.data;
629           
630                   if (!_this.data.cohead_shipto_id && _this.data.shipto_id*1 > 0) {
631                       _this.form.findField('cohead_shipto_id').setValue(_this.data.shipto_id);
632                       _this.form.findField('cohead_shipto_id_shipto_name').setValue(_this.data.cohead_shipto_cntct_id_cntct_name);
633                   
634                   }
635                   
636                   
637                   _this.dataloading = true;
638                   if (_this.data.cohead_shipto_cntct_id == _this.data.cohead_billto_cntct_id) {
639                       this.findField('_shipto_same').setValue(1);
640                         Roo.log("set shipto 1");
641                   } else {
642                     this.findField('_shipto_same').setValue(0);
643                      Roo.log("set shipto 0");
644                   }
645                   _this.dataloading = false;          
646                   
647                   
648                   this.findField('billto_address').update();
649                   this.findField('shipto_address').update();        
650                   _this.dialog.setTitle("Edit Sales Order - " + this.findField('cohead_number').getValue());
651                    
652                   
653                   if (_this.data.cohead_status == 'C') {
654                       _this.closeBtn.show();
655                       _this.closeBtn.setText('Re-open');
656                        _this.voidBtn.hide();
657                        _this.saveBtn.hide();
658                        _this.reversalBtn.show();
659                   }  else  if (_this.data.cohead_status == 'X') {
660                       _this.closeBtn.hide(); 
661                        _this.voidBtn.show(); 
662                        _this.voidBtn.setText("Un-void / Re-open"); 
663                        _this.saveBtn.hide();
664                   } else {
665                       // it's open
666                        _this.closeBtn.show(); 
667                       _this.closeBtn.setText('Complete and Close');             
668                        _this.voidBtn.setText("Void");             
669                        _this.voidBtn.show(); 
670                        _this.saveBtn.show();        
671                   }
672                   
673                    _this.form.findField('cohead_misc_per').update();
674                  
675                  // finally override the value for discount...
676                  if ((''+ _this.data.cohead_misc_descrip).length) {
677                       _this.form.findField('cohead_misc_descrip').setValue(_this.data.cohead_misc_descrip);
678                  }
679                  
680                  // update the stockcache...
681           
682                  new Pman.Request({
683                       url : baseURL + '/Roo/cohead',
684                       method : 'GET',
685                       params : {
686                           _stockLevel : _this.data.cohead_id
687                       },
688                       success : function(res) 
689                       {
690                           for (var i in res.data) {
691                              
692                               if(typeof(_this.stockcache[res.data[i].item]) == 'undefined'){
693                                   _this.stockcache[res.data[i].item] = res.data[i];
694                               }
695                           }
696                       }
697                   });
698                  
699                   return;
700               }
701               if (action.type =='submit') {
702               
703           
704                   var id = _this.form.findField('cohead_id').getValue() * 1;
705                   if (id < 1) {
706           
707                       _this.data.cohead_id = action.result.data.cohead_id;
708                        this.load({ method: 'GET', params: { '_id' : _this.data.cohead_id }});
709                       return;
710                   }
711               
712                   _this.dialog.hide();
713               
714                    if (_this.callback) {
715                       _this.callback.call(_this, _this.form.getValues());
716                    }
717                    _this.form.reset();
718                    return;
719               }
720           },
721          actionfailed : function (_self, action)
722           {
723               if (action.failureType == 'client') {
724                   Roo.MessageBox.alert("Error", "Fill in all the required fields");
725               }
726               if (action.failureType == 'server') {    
727                   Roo.log(action);
728                   Roo.MessageBox.alert("Error", action.result.errorMsg);
729               }
730               _this.dialog.layout.getRegion('center').showPanel(0);
731           },
732          rendered : function (form)
733           {
734               _this.form= form;
735           }
736         },
737         items  : [
738          {
739           width : 435,
740           xns : Roo.form,
741           '|xns' : 'Roo.form',
742           xtype : 'Column',
743           items  : [
744            {
745             labelWidth : 120,
746             legend : _this._strings['a240fa27925a635b08dc28c9e4f9216d'] /* Order */,
747             style : 'width:420px',
748             xns : Roo.form,
749             '|xns' : 'Roo.form',
750             xtype : 'FieldSet',
751             items  : [
752              {
753               labelWidth : 100,
754               width : 410,
755               xns : Roo.form,
756               '|xns' : 'Roo.form',
757               xtype : 'Column',
758               items  : [
759                {
760                 labelWidth : 100,
761                 width : 400,
762                 xns : Roo.form,
763                 '|xns' : 'Roo.form',
764                 xtype : 'Row',
765                 items  : [
766                  {
767                   allowBlank : true,
768                   emptyText : _this._strings['086247a9b57fde6eefee2a0c4752242d'] /* Automatic */,
769                   fieldLabel : _this._strings['3ffaf70863d6f46e2719050a37d9ef86'] /* Order# */,
770                   name : 'cohead_number',
771                   readOnly : true,
772                   width : 120,
773                   xns : Roo.form,
774                   '|xns' : 'Roo.form',
775                   xtype : 'TextField'
776                  },
777                  {
778                   labelWidth : 50,
779                   style : 'float:left',
780                   width : 150,
781                   xns : Roo.form,
782                   '|xns' : 'Roo.form',
783                   xtype : 'Row',
784                   items  : [
785                    {
786                     allowBlank : true,
787                     fieldLabel : _this._strings['6a813cbab5d0c9d33b1a471839935d88'] /* Cust# */,
788                     name : 'cohead_cust_id_cust_number',
789                     readOnly : true,
790                     width : 110,
791                     xns : Roo.form,
792                     '|xns' : 'Roo.form',
793                     xtype : 'TextField'
794                    }
795                   ]
796                  }
797                 ]
798                },
799                {
800                 editable : false,
801                 fieldLabel : _this._strings['ce26601dac0dea138b7295f02b7620a7'] /* Customer */,
802                 forceSelection : true,
803                 hiddenName : 'cohead_cust_id',
804                 listWidth : 400,
805                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
806                 minChars : 2,
807                 name : 'cohead_cust_id_cust_name',
808                 pageSize : 20,
809                 qtip : _this._strings['fce6d3795b41b54dc0dab82df50517c1'] /* Select custinfo */,
810                 queryParam : 'query[cust_name]',
811                 readOnly : true,
812                 selectOnFocus : true,
813                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cust_name}</b> </div>',
814                 triggerAction : 'all',
815                 typeAhead : true,
816                 valueField : 'cust_id',
817                 width : 300,
818                 xns : Roo.form,
819                 '|xns' : 'Roo.form',
820                 xtype : 'TextField'
821                },
822                {
823                 fieldLabel : _this._strings['986b90fb419e5349dd59b691b0e0e9f6'] /* Customer PO# */,
824                 name : 'cohead_custponumber',
825                 width : 150,
826                 xns : Roo.form,
827                 '|xns' : 'Roo.form',
828                 xtype : 'TextField'
829                },
830                {
831                 allowBlank : false,
832                 fieldLabel : _this._strings['26e09a1ee1517389c7b07f42df65561a'] /* Ordered */,
833                 format : 'Y-m-d',
834                 name : 'cohead_orderdate',
835                 width : 100,
836                 xns : Roo.form,
837                 '|xns' : 'Roo.form',
838                 xtype : 'DateField'
839                },
840                {
841                 labelWidth : 100,
842                 width : 500,
843                 xns : Roo.form,
844                 '|xns' : 'Roo.form',
845                 xtype : 'Row',
846                 items  : [
847                  {
848                   allowBlank : false,
849                   fieldLabel : _this._strings['a2fdeac60e3c5b6c51a92e027fb9d533'] /* Target Delivery */,
850                   format : 'Y-m-d',
851                   name : 'cohead_targetdate',
852                   width : 100,
853                   xns : Roo.form,
854                   '|xns' : 'Roo.form',
855                   xtype : 'DateField'
856                  },
857                  {
858                   hideLabels : true,
859                   xns : Roo.form,
860                   '|xns' : 'Roo.form',
861                   xtype : 'Row',
862                   items  : [
863                    {
864                     boxLabel : 'same as order',
865                     inputValue : 1,
866                     name : '_same_as_order',
867                     xns : Roo.form,
868                     '|xns' : 'Roo.form',
869                     xtype : 'Checkbox',
870                     listeners : {
871                      check : function (_self, checked)
872                       {
873                           if(checked){
874                               _this.form.findField('cohead_targetdate').setValue(_this.form.findField('cohead_orderdate').getValue());
875                           }
876                       }
877                     }
878                    }
879                   ]
880                  }
881                 ]
882                },
883                {
884                 allowBlank : false,
885                 displayField : 'location_name',
886                 editable : true,
887                 emptyText : _this._strings['4a2a14210d78f0d82db75d0264030169'] /* Supply From */,
888                 fieldLabel : _this._strings['4a2a14210d78f0d82db75d0264030169'] /* Supply From */,
889                 forceSelection : true,
890                 hiddenName : 'cohead_location_src',
891                 listWidth : 400,
892                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
893                 minChars : 2,
894                 name : 'cohead_location_src_location_name',
895                 pageSize : 200,
896                 qtip : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
897                 queryParam : 'query[location_name]',
898                 selectOnFocus : true,
899                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> {location_descrip} </div>',
900                 triggerAction : 'all',
901                 typeAhead : false,
902                 valueField : 'location_id',
903                 width : 300,
904                 xns : Roo.form,
905                 '|xns' : 'Roo.form',
906                 xtype : 'ComboBox',
907                 store : {
908                  remoteSort : true,
909                  sortInfo : { direction : 'ASC', field: 'location_name' },
910                  xns : Roo.data,
911                  '|xns' : 'Roo.data',
912                  xtype : 'Store',
913                  listeners : {
914                   beforeload : function (_self, o){
915                        o.params = o.params || {};
916                        // set more here
917                         o.params.location_netable = 1;
918                          o.params.location_restrict = 0;
919                          o.params._notinternalcompany = 1;
920                    }
921                  },
922                  proxy : {
923                   method : 'GET',
924                   url : baseURL + '/Roo/location.php',
925                   xns : Roo.data,
926                   '|xns' : 'Roo.data',
927                   xtype : 'HttpProxy'
928                  },
929                  reader : {
930                   fields : [{"name":"location_id","type":"int"},"location_name"],
931                   id : 'location_id',
932                   root : 'data',
933                   totalProperty : 'total',
934                   xns : Roo.data,
935                   '|xns' : 'Roo.data',
936                   xtype : 'JsonReader'
937                  }
938                 }
939                }
940               ]
941              }
942             ]
943            },
944            {
945             labelWidth : 100,
946             legend : _this._strings['3ec365dd533ddb7ef3d1c111186ce872'] /* Details */,
947             style : 'width:420px',
948             xns : Roo.form,
949             '|xns' : 'Roo.form',
950             xtype : 'FieldSet',
951             items  : [
952              {
953               labelWidth : 100,
954               width : 420,
955               xns : Roo.form,
956               '|xns' : 'Roo.form',
957               xtype : 'Column',
958               items  : [
959                {
960                 allowBlank : false,
961                 displayField : 'terms_descrip',
962                 editable : false,
963                 emptyText : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
964                 fieldLabel : _this._strings['6f1bf85c9ebb3c7fa26251e1e335e032'] /* Terms */,
965                 forceSelection : true,
966                 hiddenName : 'cohead_terms_id',
967                 listWidth : 400,
968                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
969                 minChars : 2,
970                 name : 'cohead_terms_id_terms_descrip',
971                 pageSize : 20,
972                 qtip : _this._strings['151ccf95db9b81c11bb20fbc302af4b6'] /* Select terms */,
973                 queryParam : 'query[terms_descrip]',
974                 selectOnFocus : true,
975                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{terms_descrip}</b> </div>',
976                 triggerAction : 'all',
977                 typeAhead : true,
978                 valueField : 'terms_id',
979                 width : 300,
980                 xns : Roo.form,
981                 '|xns' : 'Roo.form',
982                 xtype : 'ComboBox',
983                 store : {
984                  remoteSort : true,
985                  sortInfo : { direction : 'ASC', field: 'terms_descrip' },
986                  xns : Roo.data,
987                  '|xns' : 'Roo.data',
988                  xtype : 'Store',
989                  listeners : {
990                   beforeload : function (_self, o){
991                        o.params = o.params || {};
992                        // set more here
993                    }
994                  },
995                  proxy : {
996                   method : 'GET',
997                   url : baseURL + '/Roo/terms.php',
998                   xns : Roo.data,
999                   '|xns' : 'Roo.data',
1000                   xtype : 'HttpProxy'
1001                  },
1002                  reader : {
1003                   fields : [{"name":"terms_id","type":"int"},"terms_descrip"],
1004                   id : 'terms_id',
1005                   root : 'data',
1006                   totalProperty : 'total',
1007                   xns : Roo.data,
1008                   '|xns' : 'Roo.data',
1009                   xtype : 'JsonReader'
1010                  }
1011                 }
1012                },
1013                {
1014                 allowBlank : true,
1015                 alwaysQuery : true,
1016                 displayField : 'salesrep_name',
1017                 editable : false,
1018                 emptyText : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
1019                 fieldLabel : _this._strings['94f475efc6722fd13ab78411c1ef7bd7'] /* Sales Rep */,
1020                 forceSelection : true,
1021                 hiddenName : 'cohead_display_salesrep_id',
1022                 listWidth : 400,
1023                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1024                 minChars : 2,
1025                 name : 'cohead_display_salesrep_id_salesrep_name',
1026                 pageSize : 80,
1027                 qtip : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
1028                 queryParam : 'query[salesrep_name]',
1029                 selectOnFocus : true,
1030                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
1031                 triggerAction : 'all',
1032                 typeAhead : true,
1033                 valueField : 'salesrep_id',
1034                 width : 300,
1035                 xns : Roo.form,
1036                 '|xns' : 'Roo.form',
1037                 xtype : 'ComboBox',
1038                 store : {
1039                  remoteSort : true,
1040                  sortInfo : { direction : 'ASC', field: 'salesrep_name' },
1041                  xns : Roo.data,
1042                  '|xns' : 'Roo.data',
1043                  xtype : 'Store',
1044                  listeners : {
1045                   beforeload : function (_self, o){
1046                        o.params = o.params || {};
1047                        // set more here
1048                    }
1049                  },
1050                  proxy : {
1051                   method : 'GET',
1052                   url : baseURL + '/Roo/salesrep.php',
1053                   xns : Roo.data,
1054                   '|xns' : 'Roo.data',
1055                   xtype : 'HttpProxy'
1056                  },
1057                  reader : {
1058                   fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
1059                   id : 'salesrep_id',
1060                   root : 'data',
1061                   totalProperty : 'total',
1062                   xns : Roo.data,
1063                   '|xns' : 'Roo.data',
1064                   xtype : 'JsonReader'
1065                  }
1066                 }
1067                },
1068                {
1069                 allowBlank : false,
1070                 alwaysQuery : true,
1071                 displayField : 'salesrep_name',
1072                 editable : false,
1073                 emptyText : _this._strings['de3d17fb46f44fdf066581fbb5fe6113'] /* Select Staff */,
1074                 fieldLabel : _this._strings['0ee72ad23c24d7cfc5c13311abdc3f72'] /* Staff I.C. */,
1075                 forceSelection : true,
1076                 hiddenName : 'cohead_salesrep_id',
1077                 listWidth : 400,
1078                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1079                 minChars : 2,
1080                 name : 'cohead_salesrep_id_salesrep_name',
1081                 pageSize : 80,
1082                 qtip : _this._strings['7b09a122e58c067939744c4a96ff2d77'] /* Select salesrep */,
1083                 queryParam : 'query[salesrep_name]',
1084                 selectOnFocus : true,
1085                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{salesrep_name}</b> </div>',
1086                 triggerAction : 'all',
1087                 typeAhead : true,
1088                 valueField : 'salesrep_id',
1089                 width : 300,
1090                 xns : Roo.form,
1091                 '|xns' : 'Roo.form',
1092                 xtype : 'ComboBox',
1093                 store : {
1094                  remoteSort : true,
1095                  sortInfo : { direction : 'ASC', field: 'salesrep_name' },
1096                  xns : Roo.data,
1097                  '|xns' : 'Roo.data',
1098                  xtype : 'Store',
1099                  listeners : {
1100                   beforeload : function (_self, o){
1101                        o.params = o.params || {};
1102                        // set more here
1103                    }
1104                  },
1105                  proxy : {
1106                   method : 'GET',
1107                   url : baseURL + '/Roo/salesrep.php',
1108                   xns : Roo.data,
1109                   '|xns' : 'Roo.data',
1110                   xtype : 'HttpProxy'
1111                  },
1112                  reader : {
1113                   fields : [{"name":"salesrep_id","type":"int"},"salesrep_name"],
1114                   id : 'salesrep_id',
1115                   root : 'data',
1116                   totalProperty : 'total',
1117                   xns : Roo.data,
1118                   '|xns' : 'Roo.data',
1119                   xtype : 'JsonReader'
1120                  }
1121                 }
1122                },
1123                {
1124                 fieldLabel : _this._strings['f4ac45b9eb622dcb26c0d4fc1c93b27c'] /* Order Comments */,
1125                 height : 80,
1126                 name : 'cohead_ordercomments',
1127                 width : 300,
1128                 xns : Roo.form,
1129                 '|xns' : 'Roo.form',
1130                 xtype : 'TextArea'
1131                }
1132               ]
1133              }
1134             ]
1135            },
1136            {
1137             legend : _this._strings['780c462e85ba4399a5d42e88f69a15ca'] /* Billing */,
1138             style : 'width:420px',
1139             xns : Roo.form,
1140             '|xns' : 'Roo.form',
1141             xtype : 'FieldSet',
1142             items  : [
1143              {
1144               labelWidth : 50,
1145               width : 420,
1146               xns : Roo.form,
1147               '|xns' : 'Roo.form',
1148               xtype : 'Column',
1149               items  : [
1150                {
1151                 allowBlank : false,
1152                 alwaysQuery : true,
1153                 displayField : 'cntct_name',
1154                 editable : true,
1155                 emptyText : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
1156                 fieldLabel : _this._strings['c3ce05eb16c5e0075b4a247b2c4b7bba'] /* Bill To (select) */,
1157                 forceSelection : true,
1158                 hiddenName : 'cohead_billto_cntct_id',
1159                 listWidth : 400,
1160                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1161                 minChars : 2,
1162                 name : 'cohead_billto_cntct_id_cntct_name',
1163                 pageSize : 20,
1164                 qtip : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
1165                 queryParam : 'query[cntct_name]',
1166                 selectOnFocus : true,
1167                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{cntct_name}</b> {cntct_addr_id_addr_line1}</div>',
1168                 triggerAction : 'all',
1169                 typeAhead : true,
1170                 valueField : 'cntct_id',
1171                 width : 300,
1172                 xns : Roo.form,
1173                 '|xns' : 'Roo.form',
1174                 xtype : 'ComboBox',
1175                 listeners : {
1176                  add : function (combo)
1177                   {
1178                     
1179                     Pman.Dialog.XtupleQuickContact.show( 
1180                               {
1181                                 _id : id,
1182                                 customer_id : _this.form.findField('cohead_cust_id').getValue()
1183                               },
1184                               
1185                               function (data) {
1186                                  
1187                                   for(var i in  data) {
1188                                       
1189                                       _this.data['cohead_billto_cntct_id_' + i] =  data[i];
1190                                   }
1191                                   
1192                                   _this.form.findField('billto_address').update();
1193                                   // fill in the select box..
1194                                   _this.form.setValues( {
1195                                       cohead_billto_cntct_id : data.cntct_id,
1196                                       cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
1197                                               data.cntct_last_name
1198                                       
1199                                   });
1200                               }
1201                           );
1202                           //  Pman.Dialog.XtupleCustomer.show(
1203                               //{ cust_id : _this.form.findField('cohead_cust_id').getValue() }, 
1204                               //function(data) {
1205                           // refresh the data in the pulldown..
1206                       //    }); 
1207                   
1208                   },
1209                  beforeselect : function (combo, record, index)
1210                   {
1211                       // set _this.data values ..
1212                   
1213                       // just add everything...
1214                       for(var i in record.data) {
1215                           _this.data['cohead_billto_cntct_id_' + i] = record.data[i];
1216                       }
1217                       
1218                       _this.form.findField('billto_address').update();
1219                       
1220                       
1221                    
1222                   }
1223                 },
1224                 store : {
1225                  remoteSort : true,
1226                  sortInfo : { direction : 'ASC', field: 'cntct_name' },
1227                  xns : Roo.data,
1228                  '|xns' : 'Roo.data',
1229                  xtype : 'Store',
1230                  listeners : {
1231                   beforeload : function (_self, o){
1232                        o.params = o.params || {};
1233                        // set more here
1234                        o.params._customer_id = _this.data.cohead_cust_id;
1235                    }
1236                  },
1237                  proxy : {
1238                   method : 'GET',
1239                   url : baseURL + '/Roo/cntct.php',
1240                   xns : Roo.data,
1241                   '|xns' : 'Roo.data',
1242                   xtype : 'HttpProxy'
1243                  },
1244                  reader : {
1245                   fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
1246                   id : 'cntct_id',
1247                   root : 'data',
1248                   totalProperty : 'total',
1249                   xns : Roo.data,
1250                   '|xns' : 'Roo.data',
1251                   xtype : 'JsonReader'
1252                  }
1253                 }
1254                },
1255                {
1256                 fieldLabel : _this._strings['1d144309cbdf2536723621bf0eac9f33'] /* or enter Address */,
1257                 name : 'billto_address',
1258                 readOnly : true,
1259                 update : function() {
1260                 
1261                     var c = ['first_name', 'last_name' ] ;
1262                     var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
1263                     var v = [];
1264                     Roo.each(c, function(e) {
1265                         if (_this.data['cohead_billto_cntct_id_cntct_' +e].length) { 
1266                             v.push(_this.data['cohead_billto_cntct_id_cntct_' +e]);
1267                         }
1268                     });
1269                     Roo.each(a, function(e) {
1270                         if (_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e].length) {
1271                             v.push(_this.data['cohead_billto_cntct_id_cntct_addr_id_addr_' +e]);
1272                         }
1273                     });
1274                 
1275                     this.setValue(v.join("\n"));
1276                     
1277                     if(_this.data.cohead_billto_cntct_id_cntct_email.length){
1278                         _this.form.findField('billto_email').setValue(_this.data.cohead_billto_cntct_id_cntct_email);
1279                     }
1280                 },
1281                 xns : Roo.form,
1282                 '|xns' : 'Roo.form',
1283                 xtype : 'TextArea',
1284                 listeners : {
1285                  render : function (_self)
1286                   {
1287                      Roo.log(this.el)
1288                      
1289                      
1290                      
1291                      this.el.on('click', function() { 
1292                          var id = _this.form.findField('cohead_billto_cntct_id').getValue();
1293                           Pman.Dialog.XtupleQuickContact.show( 
1294                               {
1295                                 _id : id,
1296                                 customer_id : _this.form.findField('cohead_cust_id').getValue()
1297                               },
1298                               
1299                               function (data) {
1300                               
1301                                   for(var i in  data) {
1302                                       
1303                                       _this.data['cohead_billto_cntct_id_' + i] =  data[i];
1304                                   }
1305                                   
1306                                   _this.form.findField('billto_address').update();
1307                                   // fill in the select box..
1308                                   _this.form.setValues( {
1309                                       cohead_billto_cntct_id : data.cntct_id,
1310                                       cohead_billto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
1311                                               data.cntct_last_name
1312                                       
1313                                   });
1314                                   
1315                                           
1316                                   Roo.log(data);
1317                               }
1318                           );
1319                      
1320                           Roo.log("Click text");
1321                           
1322                           
1323                        });
1324                   }
1325                 }
1326                },
1327                {
1328                 fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
1329                 name : 'billto_email',
1330                 valueRenderer : function(v)
1331                 {
1332                  
1333                     return v ? String.format('<a href="mailto:{0}" target="_blank">{0}</a>',v) : '';
1334                 },
1335                 xns : Roo.form,
1336                 '|xns' : 'Roo.form',
1337                 xtype : 'DisplayField'
1338                }
1339               ]
1340              }
1341             ]
1342            }
1343           ]
1344          },
1345          {
1346           style : 'margin-left:10px',
1347           width : 435,
1348           xns : Roo.form,
1349           '|xns' : 'Roo.form',
1350           xtype : 'Column',
1351           items  : [
1352            {
1353             labelWidth : 50,
1354             legend : _this._strings['9f1a342d0197aac60ed73e921dc4c1f5'] /* Price Details */,
1355             style : 'width:420px',
1356             xns : Roo.form,
1357             '|xns' : 'Roo.form',
1358             xtype : 'FieldSet',
1359             items  : [
1360              {
1361               labelAlign : 'right',
1362               labelWidth : 300,
1363               width : 420,
1364               xns : Roo.form,
1365               '|xns' : 'Roo.form',
1366               xtype : 'Column',
1367               items  : [
1368                {
1369                 labelAlign : 'top',
1370                 labelSeparator : '&nbsp;',
1371                 width : 500,
1372                 xns : Roo.form,
1373                 '|xns' : 'Roo.form',
1374                 xtype : 'Row',
1375                 items  : [
1376                  {
1377                   allowBlank : false,
1378                   displayField : 'curr_name',
1379                   editable : false,
1380                   emptyText : _this._strings['2925dda0ec274c20c0a30d8720eb830b'] /* Select curr_name */,
1381                   fieldLabel : _this._strings['386c339d37e737a436499d423a77df0c'] /* Currency */,
1382                   forceSelection : true,
1383                   hiddenName : 'cohead_curr_id',
1384                   listWidth : 400,
1385                   loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1386                   minChars : 2,
1387                   name : 'cohead_curr_id_curr_name',
1388                   pageSize : 20,
1389                   qtip : _this._strings['e8586011952b0d098b0e568f20ca2b1f'] /* Select Currency */,
1390                   queryParam : 'query[curr_name]',
1391                   selectOnFocus : true,
1392                   tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>',
1393                   triggerAction : 'all',
1394                   typeAhead : true,
1395                   valueField : 'curr_id',
1396                   width : 285,
1397                   xns : Roo.form,
1398                   '|xns' : 'Roo.form',
1399                   xtype : 'ComboBox',
1400                   listeners : {
1401                    beforequery : function (combo, query, forceAll, cancel, e)
1402                     {
1403                         Roo.log('beforequery');
1404                        
1405                         if (_this.form.findField('cohead_number').getValue().length) {
1406                             Roo.MessageBox.alert("Error", "You can not change the currency of this order");
1407                             if (query) {
1408                                 query.cancel = true;
1409                             }
1410                             return false;
1411                         }
1412                     }
1413                   },
1414                   store : {
1415                    remoteSort : true,
1416                    sortInfo : { direction : 'ASC', field: 'curr_symbol' },
1417                    xns : Roo.data,
1418                    '|xns' : 'Roo.data',
1419                    xtype : 'Store',
1420                    listeners : {
1421                     beforeload : function (_self, o){
1422                          o.params = o.params || {};
1423                          // set more here
1424                         
1425                      }
1426                    },
1427                    proxy : {
1428                     method : 'GET',
1429                     url : baseURL + '/Roo/curr_symbol.php',
1430                     xns : Roo.data,
1431                     '|xns' : 'Roo.data',
1432                     xtype : 'HttpProxy'
1433                    },
1434                    reader : {
1435                     fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
1436                     id : 'curr_id',
1437                     root : 'data',
1438                     totalProperty : 'total',
1439                     xns : Roo.data,
1440                     '|xns' : 'Roo.data',
1441                     xtype : 'JsonReader'
1442                    }
1443                   }
1444                  },
1445                  {
1446                   allowDecimals : true,
1447                   cls : 'roo-align-right',
1448                   decimalPrecision : 3,
1449                   fieldLabel : _this._strings['068f80c7519d0528fb08e82137a72131'] /* Products */,
1450                   name : 'cohead_subtotal',
1451                   readOnly : true,
1452                   width : 100,
1453                   xns : Roo.form,
1454                   '|xns' : 'Roo.form',
1455                   xtype : 'NumberField'
1456                  }
1457                 ]
1458                },
1459                {
1460                 labelAlign : 'top',
1461                 labelSeparator : '&nbsp;',
1462                 width : 500,
1463                 xns : Roo.form,
1464                 '|xns' : 'Roo.form',
1465                 xtype : 'Row',
1466                 items  : [
1467                  {
1468                   allowBlank : false,
1469                   displayField : 'taxzone_descrip',
1470                   editable : false,
1471                   emptyText : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
1472                   fieldLabel : _this._strings['78ca8a8170f2065057507ddcde63d9ca'] /* Tax Zone */,
1473                   forceSelection : true,
1474                   hiddenName : 'cohead_taxzone_id',
1475                   listWidth : 400,
1476                   loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1477                   minChars : 2,
1478                   name : 'cohead_taxzone_id_taxzone_descrip',
1479                   pageSize : 20,
1480                   qtip : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
1481                   queryParam : 'query[taxzone_descrip]',
1482                   selectOnFocus : true,
1483                   tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxzone_descrip}</b> </div>',
1484                   triggerAction : 'all',
1485                   typeAhead : true,
1486                   valueField : 'taxzone_id',
1487                   width : 285,
1488                   xns : Roo.form,
1489                   '|xns' : 'Roo.form',
1490                   xtype : 'ComboBox',
1491                   listeners : {
1492                    select : function (combo, record, index)
1493                     {
1494                          _this.form.findField('cohead_tax').setValue(
1495                                  parseFloat(record.data.taxzone_rate) * 
1496                                  parseFloat(_this.form.findField('cohead_subtotal').getValue())
1497                          );
1498                           _this.form.findField('cohead_total').recalc();
1499                     }
1500                   },
1501                   store : {
1502                    remoteSort : true,
1503                    sortInfo : { direction : 'ASC', field: 'taxzone_descrip' },
1504                    xns : Roo.data,
1505                    '|xns' : 'Roo.data',
1506                    xtype : 'Store',
1507                    listeners : {
1508                     beforeload : function (_self, o){
1509                          o.params = o.params || {};
1510                          // set more here
1511                          
1512                          o.params.with_date = _this.form.findField('cohead_orderdate').getValue().format('Y-m-d'); 
1513                          Roo.log("with date?" + o.params.with_date);
1514                          
1515                          
1516                      }
1517                    },
1518                    proxy : {
1519                     method : 'GET',
1520                     url : baseURL + '/Roo/taxzone.php',
1521                     xns : Roo.data,
1522                     '|xns' : 'Roo.data',
1523                     xtype : 'HttpProxy'
1524                    },
1525                    reader : {
1526                     fields : [{"name":"taxzone_id","type":"int"},"taxzone_descrip"],
1527                     id : 'taxzone_id',
1528                     root : 'data',
1529                     totalProperty : 'total',
1530                     xns : Roo.data,
1531                     '|xns' : 'Roo.data',
1532                     xtype : 'JsonReader'
1533                    }
1534                   }
1535                  },
1536                  {
1537                   allowDecimals : true,
1538                   cls : 'roo-align-right',
1539                   decimalPrecision : 3,
1540                   fieldLabel : _this._strings['4b78ac8eb158840e9638a3aeb26c4a9d'] /* Tax */,
1541                   name : 'cohead_tax',
1542                   readOnly : true,
1543                   width : 100,
1544                   xns : Roo.form,
1545                   '|xns' : 'Roo.form',
1546                   xtype : 'NumberField'
1547                  }
1548                 ]
1549                },
1550                {
1551                 allowDecimals : true,
1552                 cls : 'roo-align-right',
1553                 decimalPrecision : 3,
1554                 fieldLabel : _this._strings['25d81668fca34c83d0720cc6365d62d6'] /* Pre Tax discount */,
1555                 name : 'cohead_pretax_discount',
1556                 readOnly : true,
1557                 width : 100,
1558                 xns : Roo.form,
1559                 '|xns' : 'Roo.form',
1560                 xtype : 'NumberField'
1561                },
1562                {
1563                 labelAlign : 'top',
1564                 labelSeparator : '&nbsp;',
1565                 width : 500,
1566                 xns : Roo.form,
1567                 '|xns' : 'Roo.form',
1568                 xtype : 'Row',
1569                 items  : [
1570                  {
1571                   fieldLabel : _this._strings['b6dad11e8e2203819164d64fc82b40f1'] /* Discount after Tax  Description */,
1572                   name : 'cohead_misc_descrip',
1573                   width : 230,
1574                   xns : Roo.form,
1575                   '|xns' : 'Roo.form',
1576                   xtype : 'TextField'
1577                  },
1578                  {
1579                   allowDecimals : true,
1580                   cls : 'roo-align-right',
1581                   decimalPrecision : 1,
1582                   fieldLabel : _this._strings['0bcef9c45bd8a48eda1b26eb0c61c869'] /* % */,
1583                   name : 'cohead_misc_per',
1584                   update : function() {
1585                       var m = _this.form.findField('cohead_misc_per');
1586                       var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
1587                       var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
1588                       var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
1589                       
1590                       var discount = parseFloat(_this.form.findField('cohead_posttax_discount').getValue());
1591                       
1592                       if (discount > 0.0) {
1593                           this.setValue(0);        
1594                           return;
1595                       }
1596                       if (pv < 0) {
1597                           this.setValue(0);        
1598                           return;
1599                       }
1600                       var val = ((discount) / (pv + tax + pd)) * -100;
1601                       
1602                       //Roo.log("update discount?" + val);
1603                       this.setValue(val.toFixed(1));
1604                       
1605                        if (val > 0.0) {
1606                           _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
1607                       
1608                       }
1609                       
1610                      
1611                   },
1612                   width : 35,
1613                   xns : Roo.form,
1614                   '|xns' : 'Roo.form',
1615                   xtype : 'NumberField',
1616                   listeners : {
1617                    keyup : function (_self, e)
1618                     {
1619                         var pv =  parseFloat(_this.form.findField('cohead_subtotal').getValue());
1620                         var tax = parseFloat(_this.form.findField('cohead_tax').getValue());
1621                         var pd = parseFloat(_this.form.findField('cohead_pretax_discount').getValue());
1622                         
1623                         var n = this.getValue();
1624                         var discount = parseFloat(n * (pv + tax + pd) * 0.01);
1625                         
1626                         _this.form.findField('cohead_posttax_discount').setValue(discount);
1627                     
1628                         _this.form.findField('cohead_total').recalc();
1629                         _this.form.findField('cohead_misc').recalc();
1630                         var val = discount * -1.0;
1631                          if (val > 0) {
1632                             _this.form.findField('cohead_misc_descrip').setValue("Discount of " + val.toFixed(1)+'%');
1633                         }
1634                        
1635                         
1636                     }
1637                   }
1638                  },
1639                  {
1640                   allowDecimals : true,
1641                   cls : 'roo-align-right',
1642                   decimalPrecision : 3,
1643                   fieldLabel : _this._strings['cc7819055cde3194bb3b136bad5cf58d'] /* &nbsp; */,
1644                   name : 'cohead_posttax_discount',
1645                   width : 100,
1646                   xns : Roo.form,
1647                   '|xns' : 'Roo.form',
1648                   xtype : 'NumberField',
1649                   listeners : {
1650                    keyup : function (_self, e)
1651                     {
1652                        _this.form.findField('cohead_misc_per').update();
1653                         _this.form.findField('cohead_total').recalc();
1654                         _this.form.findField('cohead_misc').recalc();
1655                     }
1656                   }
1657                  }
1658                 ]
1659                },
1660                {
1661                 allowDecimals : true,
1662                 cls : 'roo-align-right',
1663                 decimalPrecision : 3,
1664                 fieldLabel : _this._strings['96b0141273eabab320119c467cdcaf17'] /* Total */,
1665                 name : 'cohead_total',
1666                 readOnly : true,
1667                 recalc : function() {
1668                     var d = _this.form.getValues();
1669                     this.setValue( 
1670                                 parseFloat(d.cohead_subtotal) + 
1671                                 parseFloat(d.cohead_pretax_discount) + 
1672                                 parseFloat(d.cohead_posttax_discount) + 
1673                                 parseFloat(d.cohead_tax) + 
1674                                 parseFloat(d.cohead_freight));
1675                 },
1676                 width : 100,
1677                 xns : Roo.form,
1678                 '|xns' : 'Roo.form',
1679                 xtype : 'NumberField'
1680                },
1681                {
1682                 allowDecimals : true,
1683                 cls : 'roo-align-right',
1684                 decimalPrecision : 3,
1685                 fieldLabel : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
1686                 name : 'cohead_freight',
1687                 width : 100,
1688                 xns : Roo.form,
1689                 '|xns' : 'Roo.form',
1690                 xtype : 'NumberField',
1691                 listeners : {
1692                  keyup : function (_self, e)
1693                   {
1694                       _this.form.findField('cohead_total').recalc();
1695                   }
1696                 }
1697                },
1698                {
1699                 allowDecimals : true,
1700                 cls : 'roo-align-right',
1701                 decimalPrecision : 3,
1702                 fieldLabel : _this._strings['d335d558a8386d20318888b1f034103d'] /* Unshipped Total */,
1703                 name : 'cohead_unshipped',
1704                 readOnly : true,
1705                 width : 100,
1706                 xns : Roo.form,
1707                 '|xns' : 'Roo.form',
1708                 xtype : 'NumberField'
1709                },
1710                {
1711                 allowDecimals : true,
1712                 cls : 'roo-align-right',
1713                 decimalPrecision : 3,
1714                 fieldLabel : _this._strings['b98c34417c412e0c87faa828f26b9123'] /* Uninvoiced Total */,
1715                 name : 'cohead_uninvoiced',
1716                 readOnly : true,
1717                 width : 100,
1718                 xns : Roo.form,
1719                 '|xns' : 'Roo.form',
1720                 xtype : 'NumberField'
1721                }
1722               ]
1723              }
1724             ]
1725            },
1726            {
1727             legend : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
1728             style : 'width:420px',
1729             xns : Roo.form,
1730             '|xns' : 'Roo.form',
1731             xtype : 'FieldSet',
1732             items  : [
1733              {
1734               labelWidth : 50,
1735               width : 420,
1736               xns : Roo.form,
1737               '|xns' : 'Roo.form',
1738               xtype : 'Column',
1739               items  : [
1740                {
1741                 labelSeparator : '&nbsp;',
1742                 xns : Roo.form,
1743                 '|xns' : 'Roo.form',
1744                 xtype : 'Row',
1745                 items  : [
1746                  {
1747                   boxLabel : 'Same as Billing',
1748                   name : '_shipto_same',
1749                   xns : Roo.form,
1750                   '|xns' : 'Roo.form',
1751                   xtype : 'Checkbox',
1752                   listeners : {
1753                    check : function (_self, checked)
1754                     {
1755                        if (!_this.form) {
1756                            return;
1757                        }
1758                        
1759                        if (_this.dataloading) {
1760                        
1761                            return;
1762                        }
1763                        
1764                        
1765                        if (checked) {
1766                        
1767                             // copy the cohead_billto_cntct_id
1768                             for (var i in _this.data) {
1769                                 if (!i.match(/^cohead_billto_cntct_id/)) {
1770                                     continue;
1771                                 }
1772                                 var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
1773                                 _this.data[ni] = _this.data[i];
1774                             }
1775                              _this.form.findField('shipto_address').update();
1776                              _this.form.setValues( {
1777                                     cohead_shipto_cntct_id : _this.data.cohead_shipto_cntct_id,
1778                                     cohead_shipto_cntct_id_cntct_name : _this.data.cohead_shipto_cntct_id_cntct_first_name + ' ' + 
1779                                             _this.data.cohead_shipto_cntct_id_cntct_last_name 
1780                                             
1781                                     
1782                                 });
1783                     
1784                        
1785                         } else {
1786                              for (var i in _this.data) {
1787                                 if (!i.match(/^cohead_billto_cntct_id/)) {
1788                                     continue;
1789                                 }
1790                                 var ni = i.replace(/^cohead_billto_cntct_id/, 'cohead_shipto_cntct_id');
1791                                 
1792                                 _this.data[ni] = '';
1793                             }
1794                              _this.form.findField('shipto_address').update();
1795                              
1796                             _this.form.setValues( {
1797                                     cohead_shipto_cntct_id : '',
1798                                     cohead_shipto_cntct_id_cntct_name : '' 
1799                                     
1800                                     
1801                                 });
1802                         }
1803                         
1804                     }
1805                   }
1806                  }
1807                 ]
1808                },
1809                {
1810                 allowBlank : false,
1811                 alwaysQuery : true,
1812                 displayField : 'cntct_name',
1813                 editable : true,
1814                 emptyText : _this._strings['5f0c1431b38e3d279bf105d48824b7f3'] /* Select ship to */,
1815                 fieldLabel : _this._strings['74002cb040b036511b8d031da591364a'] /* Ship to */,
1816                 forceSelection : true,
1817                 hiddenName : 'cohead_shipto_cntct_id',
1818                 listWidth : 400,
1819                 loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
1820                 minChars : 2,
1821                 name : 'cohead_shipto_cntct_id_cntct_name',
1822                 pageSize : 20,
1823                 qtip : _this._strings['acc95aeaee48871da70cc3bce664728c'] /* Select shiptoinfo */,
1824                 queryParam : 'query[cntct_name]',
1825                 selectOnFocus : true,
1826                 tpl : '<div class=\"x-grid-cell-text x-btn button\">{cntct_name} - <b>{cntct_addr_id_addr_line1}</b> </div>',
1827                 triggerAction : 'all',
1828                 typeAhead : true,
1829                 valueField : 'cntct_id',
1830                 width : 300,
1831                 xns : Roo.form,
1832                 '|xns' : 'Roo.form',
1833                 xtype : 'ComboBox',
1834                 listeners : {
1835                  add : function (combo)
1836                   {
1837                    Pman.Dialog.XtupleQuickContact.show( 
1838                               {
1839                                 _id : id,
1840                                 customer_id : _this.form.findField('cohead_cust_id').getValue()
1841                               },
1842                               
1843                               function (data) {
1844                                  
1845                                   for(var i in  data) {
1846                                       
1847                                       _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
1848                                   }
1849                                   
1850                                   _this.form.findField('shipto_address').update();
1851                                   // fill in the select box..
1852                                   _this.form.setValues( {
1853                                       cohead_shipto_cntct_id : data.cntct_id,
1854                                       cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
1855                                               data.cntct_last_name
1856                                       
1857                                   });
1858                               }
1859                           ); 
1860                   },
1861                  beforeselect : function (combo, record, index)
1862                   {
1863                      
1864                       // just add everything...
1865                       for(var i in record.data) {
1866                           //Roo.log('cohead_shipto_cntct_id_' + i +' ='  + record.data[i]);
1867                           _this.data['cohead_shipto_cntct_id_' + i] = record.data[i];
1868                       }
1869                   
1870                       _this.form.findField('shipto_address').update();
1871                       
1872                    
1873                   }
1874                 },
1875                 store : {
1876                  remoteSort : true,
1877                  sortInfo : { direction : 'ASC', field: 'cntct_name' },
1878                  xns : Roo.data,
1879                  '|xns' : 'Roo.data',
1880                  xtype : 'Store',
1881                  listeners : {
1882                   beforeload : function (_self, o){
1883                        o.params = o.params || {};
1884                        // set more here
1885                        o.params._customer_id = _this.data.cohead_cust_id;
1886                    }
1887                  },
1888                  proxy : {
1889                   method : 'GET',
1890                   url : baseURL + '/Roo/cntct.php',
1891                   xns : Roo.data,
1892                   '|xns' : 'Roo.data',
1893                   xtype : 'HttpProxy'
1894                  },
1895                  reader : {
1896                   fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
1897                   id : 'cntct_id',
1898                   root : 'data',
1899                   totalProperty : 'total',
1900                   xns : Roo.data,
1901                   '|xns' : 'Roo.data',
1902                   xtype : 'JsonReader'
1903                  }
1904                 }
1905                },
1906                {
1907                 fieldLabel : _this._strings['dd7bf230fde8d4836917806aff6a6b27'] /* Address */,
1908                 name : 'shipto_address',
1909                 readOnly : true,
1910                 update : function() {
1911                 
1912                     var c = ['first_name', 'last_name' ] ;
1913                     var a = [ 'line1', 'line2', 'line3', 'city', 'state', 'country' ];
1914                     var v = [];
1915                     
1916                     if (_this.data['cohead_shipto_vend_name'] && _this.data['cohead_shipto_vend_name'].length) {
1917                          v.push(_this.data['cohead_shipto_vend_name']);
1918                     }
1919                         if (_this.data['cohead_shipto_vendaddr_code'] && _this.data['cohead_shipto_vendaddr_code'].length) {
1920                          v.push(_this.data['cohead_shipto_vendaddr_code']);
1921                     }
1922                     Roo.each(c, function(e) {
1923                         if (_this.data['cohead_shipto_cntct_id_cntct_' +e] && 
1924                             _this.data['cohead_shipto_cntct_id_cntct_' +e].length) {
1925                             v.push(_this.data['cohead_shipto_cntct_id_cntct_' +e]);
1926                         }
1927                     });
1928                     Roo.each(a, function(e) {
1929                         if (_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e] && 
1930                             _this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e].length) { 
1931                             v.push(_this.data['cohead_shipto_cntct_id_cntct_addr_id_addr_' +e]);
1932                         }
1933                     });
1934                 
1935                     this.setValue(v.join("\n"));
1936                 },
1937                 width : 300,
1938                 xns : Roo.form,
1939                 '|xns' : 'Roo.form',
1940                 xtype : 'TextArea',
1941                 listeners : {
1942                  render : function (_self)
1943                   {
1944                      Roo.log(this.el)
1945                      
1946                      
1947                      
1948                      this.el.on('click', function() { 
1949                          var id = _this.form.findField('cohead_shipto_cntct_id').getValue();
1950                           Pman.Dialog.XtupleQuickContact.show( 
1951                               {
1952                                 _id : id,
1953                                 customer_id : _this.form.findField('cohead_cust_id').getValue()
1954                               },
1955                               
1956                               function (data) {
1957                               
1958                                   for(var i in  data) {
1959                                       
1960                                       _this.data['cohead_shipto_cntct_id_' + i] =  data[i];
1961                                   }
1962                                   
1963                                   _this.form.findField('shipto_address').update();
1964                                   // fill in the select box..
1965                                   _this.form.setValues( {
1966                                       cohead_shipto_cntct_id : data.cntct_id,
1967                                       cohead_shipto_cntct_id_cntct_name : data.cntct_first_name + ' '+ 
1968                                               data.cntct_last_name
1969                                       
1970                                   });
1971                                   
1972                                           
1973                                   //Roo.log(data);
1974                               }
1975                           );
1976                      
1977                         //  Roo.log("Click text");
1978                           
1979                           
1980                        });
1981                   }
1982                 }
1983                },
1984                {
1985                 fieldLabel : _this._strings['48e91c2f1cb7b90612ccae2502c7327f'] /* Shipment Comments */,
1986                 name : 'cohead_shipcomments',
1987                 width : 300,
1988                 xns : Roo.form,
1989                 '|xns' : 'Roo.form',
1990                 xtype : 'TextArea'
1991                }
1992               ]
1993              }
1994             ]
1995            }
1996           ]
1997          },
1998          {
1999           name : 'cohead_id',
2000           xns : Roo.form,
2001           '|xns' : 'Roo.form',
2002           xtype : 'Hidden'
2003          },
2004          {
2005           name : 'cohead_shipto_id',
2006           xns : Roo.form,
2007           '|xns' : 'Roo.form',
2008           xtype : 'Hidden'
2009          },
2010          {
2011           name : 'cohead_shipto_id_shipto_name',
2012           xns : Roo.form,
2013           '|xns' : 'Roo.form',
2014           xtype : 'Hidden'
2015          },
2016          {
2017           name : 'cohead_max_linenumber',
2018           xns : Roo.form,
2019           '|xns' : 'Roo.form',
2020           xtype : 'Hidden'
2021          },
2022          {
2023           name : 'cohead_cust_id',
2024           xns : Roo.form,
2025           '|xns' : 'Roo.form',
2026           xtype : 'Hidden'
2027          },
2028          {
2029           name : 'cohead_misc',
2030           recalc : function() {
2031               var d = _this.form.getValues();
2032               this.setValue( 
2033                   parseFloat(d.cohead_pretax_discount) + 
2034                   parseFloat(d.cohead_posttax_discount) );
2035           },
2036           xns : Roo.form,
2037           '|xns' : 'Roo.form',
2038           xtype : 'Hidden'
2039          },
2040          {
2041           name : 'taxzone_rate',
2042           xns : Roo.form,
2043           '|xns' : 'Roo.form',
2044           xtype : 'Hidden'
2045          }
2046         ]
2047        }
2048       ]
2049      },
2050      {
2051       background : true,
2052       fitContainer : true,
2053       fitToframe : true,
2054       region : 'center',
2055       tableName : 'coitem',
2056       title : _this._strings['4b84bd35233c0d3d3c36b9a6ce6e0745'] /* Order Items */,
2057       xns : Roo,
2058       '|xns' : 'Roo',
2059       xtype : 'GridPanel',
2060       listeners : {
2061        activate : function() {
2062             _this.panel = this;
2063             
2064             try { if (MODULE.isBuilder) {
2065                 return;
2066             } } catch(e) { }
2067             
2068             var id = _this.form.findField('cohead_id').getValue() * 1;
2069             if (id < 1) {
2070                 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
2071                 _this.dialog.layout.getRegion('center').showPanel(0);
2072                 return;
2073             }
2074             
2075             if (_this.grid) {
2076                 _this.grid.footer.onClick('first');
2077             
2078                  //if (_this.form.findField('cohead_cust_id_cust_name').getValue() == 'Bloom and Grow HK') {
2079                  //   _this.xferAll.show();
2080                 // 
2081                 // } else {
2082                 //     _this.xferAll.hide();
2083                 // }
2084              }
2085             
2086         },
2087        deactivate : function (_self)
2088         {
2089             if(_this.grid){
2090                 _this.grid.stopEditing();
2091             }
2092         }
2093       },
2094       grid : {
2095        autoExpandColumn : 'item_descrip1',
2096        clicksToEdit : 1,
2097        loadAvail : function() {
2098            
2099            
2100            this.ds.each(function(r) {
2101                
2102                if(!r.data.item_number.length){
2103                    return;
2104                }
2105                
2106                if(typeof(_this.stockcache[r.data.item_number]) != 'undefined'){
2107                
2108                    r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
2109                    if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
2110                        r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
2111                    }
2112                    return;
2113                }
2114                
2115                var q = [];
2116                
2117                q.push( { 
2118                    item : r.data.item_number, 
2119                    loc: r.data.coitem_location_src_location_name,
2120                    id: r.data.coitem_linenumber + (r.data.coitem_subnumber ? ('.' + r.data.coitem_subnumber) : '')
2121                 } );
2122                 
2123                 new Pman.Request({
2124                    url : baseURL + '/Roo/itemloc',
2125                    method : 'POST',
2126                    params : {
2127                        _availqty : Roo.encode(q),
2128                        curr_name : _this.form.findField('cohead_curr_id').el.dom.value
2129                    },
2130                    success : function(res) 
2131                    {
2132                        for (var i in res.data) {
2133                           _this.stockcache[res.data[i].item] = res.data[i];
2134                        }
2135                        r.set('avail_qty', _this.stockcache[r.data.item_number].qty);
2136                        if (r.data.coitem_unitcost_in_order_cur * 1.0 < 0.1) {
2137                            r.set('coitem_unitcost_in_order_cur', _this.stockcache[r.data.item_number].unitcost);
2138                        }
2139                        //_this.grid.ds.fireEvent("update", _this.grid.ds, r, Roo.data.Record.EDIT);
2140                        return
2141                    }
2142                });
2143            });
2144                
2145                        
2146        },
2147        loadMask : true,
2148        xns : Roo.grid,
2149        '|xns' : 'Roo.grid',
2150        xtype : 'EditorGrid',
2151        listeners : {
2152         afteredit : function (e)
2153          {
2154              Roo.log('afteredit:' + e.record.data.coitem_linenumber);
2155          
2156              
2157             // if ( e.record && e.record.data.coitem_id) {
2158                  // as we disable update to the display on the ajax callback to 
2159                  // allow editing flow to continue, and not refresh - we can only update
2160                  // these values after something has actually been edited.
2161                  // e.record.set('coitem_id', e.record.data.coitem_id);
2162                  // e.record.set('coitem_status', e.record.data.coitem_status);
2163             // }
2164              
2165              if (e.field == 'item_number' || e.originalValue == e.value) {
2166                  // afterselect handles this...
2167                  return;
2168              }
2169              if (e.field == 'item_descrip1') {
2170                  e.record.set('coitem_memo', e.value);
2171              }
2172              var rate = _this.form.findField('taxzone_rate').getValue();
2173              switch(e.field) {
2174                  case 'coitem_linedisc':
2175                     
2176                      var cp = parseFloat(e.record.data.coitem_custprice);
2177                     
2178                      if (isNaN(cp) || cp == 0.0) {
2179                          break;
2180                      }
2181                      
2182                      var dis = parseFloat(e.value);
2183                     
2184                      if (isNaN(dis)) {
2185                          break;
2186                      }
2187                      
2188                      e.record.set(
2189                          'coitem_price',
2190                          Math.max(0,cp * ((100.0 -  parseInt(e.value))/ 100.0) )  
2191                      );
2192                      
2193                     // donot need to set the subtotal here, coz we will render it automatically
2194                     // e.record.set(
2195                     //     'coitem_subtotal',
2196                     //      e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
2197                     // );
2198                      break;
2199                  
2200                  case  'coitem_price': // SELL@ price
2201          
2202                       var cp = parseFloat(e.record.data.coitem_custprice);
2203                       // list price is < price -- update it..
2204                       if (isNaN(cp) || cp == 0.0 || cp < e.value) {
2205                          e.record.set('coitem_custprice', e.value);
2206                          cp = e.value;
2207                       }
2208                       // update the discount calc.
2209                       
2210                       e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( e.value / cp) * 100.0)));  
2211                       
2212                       // donot need to set the subtotal here, coz we will render it automatically
2213                       //e.record.set(
2214                       //   'coitem_subtotal',
2215                        //   e.record.data.coitem_price * 1.0 * e.record.data.coitem_qtyord
2216                       //);
2217                       break;
2218                  
2219                  case 'coitem_custprice':
2220                      // modified customer price...
2221                      // just modify the discount.. -- leave the entered price the same..
2222                        var sp =  parseFloat(e.record.data.coitem_price);
2223                        var cp = parseFloat(e.value);
2224                        if (isNaN(cp) || cp == 0.0 || cp < e.value) {
2225                              break;
2226                        }
2227                        
2228                       e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
2229                       
2230                       break;
2231                       
2232                  case 'coitem_custprice_tax':
2233                        var cp = parseFloat(e.value / ( 1 + rate * 1 ));
2234                        var sp =  parseFloat(e.record.data.coitem_price);
2235                        
2236                        if (isNaN(cp) || cp == 0.0) {
2237                              break;
2238                        }
2239                        e.record.set('coitem_custprice', cp);
2240                        e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
2241                       
2242                       break; 
2243                       
2244                   case  'coitem_price_tax':
2245          
2246                       var cp = parseFloat(e.record.data.coitem_custprice);
2247                       var sp = parseFloat(e.value / ( 1 + rate * 1 ));
2248                       if (isNaN(cp) || cp == 0.0 || cp < sp) {
2249                          e.record.set('coitem_custprice', sp);
2250                          cp = sp;
2251                       }
2252                       e.record.set('coitem_price', sp);
2253                       e.record.set('coitem_linedisc', Math.max(0, 100.0 -  (( sp / cp) * 100.0)));  
2254                       
2255                       break;
2256                
2257              }
2258              
2259               
2260              
2261              
2262              var doupdate = function() { 
2263                 if (!e.record.updatePending) {
2264                      Roo.log('doupdate...'  + e.record.data.coitem_linenumber);
2265                      Roo.log(e.record);
2266                      e.record.commit();
2267                      return;
2268                  }
2269                 Roo.log('doupdate pending...'   + e.record.data.coitem_linenumber);
2270                  // wait until it's not peding an update..
2271                  doupdate.defer(500);
2272              }
2273          
2274              if(e.record.data.coitem_id * 1 < 1 && !e.record.isInserting){ // insert
2275                  e.record.isInserting = 1;
2276                  e.record.isUpdating = 0;
2277                  doupdate();
2278                  return;
2279              }
2280              
2281              // update
2282              if(!e.record.isInserting && !e.record.isUpdating){
2283                  e.record.isUpdating = 1;
2284                  doupdate();
2285                  return;
2286              }
2287              
2288              if(!e.record.updatePending){
2289                  e.record.updatePending = 1;
2290                  doupdate();
2291                  return;
2292              }
2293              Roo.log("got to end without doing an update?"  + e.record.data.coitem_linenumber);
2294              
2295          },
2296         beforeedit : function (e)
2297          {
2298              // we can only edit if nothing is assigned to shipping or invoices..
2299              
2300              var rec = e.record
2301          
2302              if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0 || (rec.data.shipitem_shipped - rec.data.coitem_qtyshipped) > 0 ) {
2303                  Roo.MessageBox.alert("Error", "That item has been shipped, has a draft shipment  or invoices - void the shipments/invoices first");
2304                  e.cancel = true;
2305                  return;
2306              }
2307              
2308              if (rec.data.coitem_subnumber * 1 > 0) {
2309                  Roo.log("Edit container event");
2310                  Roo.log(e); // if it's a tab.. 
2311          
2312                  
2313                  switch(e.field) {
2314                      // allow editing of source / destination..
2315                      case 'coitem_shipto_id':
2316                      case 'coitem_location_src':            
2317                          return;
2318                      default : 
2319                          break;
2320                  }
2321                  Roo.MessageBox.alert("Error", "That is a kit item, edit the container.");
2322                  e.cancel = true;
2323                  return;
2324              }
2325              // zero off values..
2326              //if (e.field == 'coitem_qtyord' && rec.data.coitem_qtyord == 0) {
2327              //        e.value ='';
2328              //    }
2329              //    if (e.field == 'coitem_custprice' && rec.data.coitem_qtyord == 0.0) {
2330              //        e.value ='';
2331              //    }
2332              
2333              if (rec.data.item_type == 'K' && e.field == 'item_number') {
2334                  // you can not change the product type on kits' as it messing things up..
2335                  Roo.MessageBox.alert("Error", "That is a kit item,if you need to change it, delete it first.");
2336                  e.cancel = true;
2337                  return;
2338              }
2339              
2340          },
2341         celldblclick : function (_self, rowIndex, columnIndex, e)
2342          {
2343              var rec = this.ds.getAt(rowIndex);
2344              var di = this.cm.getDataIndex(columnIndex);
2345              if (di != 'avail_qty') {
2346                  return;
2347              }
2348              
2349              Pman.Dialog.XtupleInvHistory.show({
2350                  itemsite_item_id_item_number   : rec.data.item_number,
2351                 // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
2352                  location_name : rec.data.coitem_location_src_location_name,
2353                  location_descrip : rec.data.coitem_location_src_location_descrip,
2354                  
2355                  invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
2356              }); 
2357              
2358          },
2359         render : function() 
2360          {
2361              _this.grid = this; 
2362              //_this.dialog = Pman.Dialog.FILL_IN
2363              
2364              if (_this.panel.active) {
2365                 this.footer.onClick('first');
2366              }
2367          },
2368         rowclass : function (gridview, rowcfg)
2369          {
2370              if (rowcfg.record.data.coitem_status == 'C' &&
2371                  rowcfg.record.data.shipitem_shipped * 1 < 1) {
2372                  
2373                  rowcfg.rowClass = 'strikethrough';
2374              }
2375               if (rowcfg.record.data.coitem_status == 'X'  ) {
2376                  
2377                  rowcfg.rowClass = 'strikethrough';
2378              }
2379              
2380              if (!rowcfg.record.data.coitem_id) { 
2381                      rowcfg.rowClass = 'dragon-not-saved';
2382              }
2383              
2384              
2385             // Roo.log(rowcfg);
2386          //    shipitem_shipped
2387          }
2388        },
2389        footer : {
2390         displayInfo : true,
2391         emptyMsg : _this._strings['158e64bcd08067d26e9c27679eeced88'] /* No Items */,
2392         pageSize : 100,
2393         updateSummary : function() {
2394             var f = this;
2395             new Pman.Request({
2396                 url : baseURL + '/Roo/Coitem',
2397                 method : 'GET',
2398                 params : {
2399                     _totals : 1,
2400                     coitem_cohead_id : _this.form.findField('cohead_id').getValue()
2401                 },
2402                 success : function(d) {
2403                     //Roo.log(d);
2404                     f.displayEl.update(String.format(
2405                         "{0} items |  Subtotal: {2} | Tax: {3} | List Discount {4} | Total : {1}{5}",
2406                         d.data.total_qty,
2407                         _this.form.findField('cohead_curr_id').el.dom.value,
2408                         d.data.total_sub,
2409                         d.data.total_tax,
2410                         d.data.total_list_discount,                
2411                         d.data.total_total
2412                     ));
2413                         
2414                 }
2415             });
2416         },
2417         xns : Roo,
2418         '|xns' : 'Roo',
2419         xtype : 'PagingToolbar',
2420         items  : [
2421          {
2422           text : _this._strings['806dca90dbeda894ffb258939f9fef9a'] /* Fill empty Ship To */,
2423           xns : Roo.Toolbar,
2424           '|xns' : 'Roo.Toolbar',
2425           xtype : 'Button',
2426           listeners : {
2427            click : function (_self, e)
2428             {
2429                 new Pman.Request({
2430                     url : baseURL + '/Roo/Cohead',
2431                     method : 'GET',
2432                     params : {
2433                         _fill_shipto : _this.form.findField('cohead_id').getValue()
2434                     },
2435                     success : function() {
2436                         _this.grid.footer.onClick('first');
2437                     }
2438                 });
2439             }
2440           }
2441          },
2442          {
2443           text : _this._strings['c4b515058fab313f403ae427ce7e32b3'] /* Update Location to match S/O */,
2444           xns : Roo.Toolbar,
2445           '|xns' : 'Roo.Toolbar',
2446           xtype : 'Button',
2447           listeners : {
2448            click : function (_self, e)
2449             {
2450                 Roo.MessageBox.confirm("Confirm", "Are you sure?<BR>"+
2451                     "This will set all the locations to match the Sales Order - and remove all old locations.",
2452                     function (res) {
2453                         if(res!='yes') {
2454                             return;
2455                         
2456                         }
2457                         new Pman.Request({
2458                             url : baseURL + '/Roo/Cohead',
2459                             method : 'GET',
2460                             params : {
2461                                 _fill_location : _this.form.findField('cohead_id').getValue(),
2462                                 _location_id : _this.form.findField('cohead_location_src').getValue()
2463                             },
2464                             success : function() {
2465                                 _this.grid.footer.onClick('first');
2466                             }
2467                         });
2468                 });
2469                 
2470             }
2471           }
2472          },
2473          {
2474           enableToggle : true,
2475           minWidth : 100,
2476           text : _this._strings['88408722ed9d719c44087292bf8a06cf'] /* Prices with GST */,
2477           xns : Roo.Toolbar,
2478           '|xns' : 'Roo.Toolbar',
2479           xtype : 'Button',
2480           listeners : {
2481            render : function (_self)
2482             {
2483                 _this.showgstBtn = _self;
2484             },
2485            toggle : function (_self, pressed)
2486             {
2487                 this.setText(pressed ? "Prices exc GST" : "Prices with GST");
2488                 var cm = _this.grid.getColumnModel();
2489             
2490                 cm.setHidden(cm.getIndexByDataIndex('coitem_price_tax'), pressed ? false : true);
2491                 cm.setHidden(cm.getIndexByDataIndex('coitem_custprice_tax'), pressed ? false : true);
2492                 cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal_tax'), pressed ? false : true);
2493                 
2494                 cm.setHidden(cm.getIndexByDataIndex('coitem_price'), pressed ? true : false);
2495                 cm.setHidden(cm.getIndexByDataIndex('coitem_custprice'), pressed ? true : false);
2496                 cm.setHidden(cm.getIndexByDataIndex('coitem_subtotal'), pressed ? true : false);
2497                 return;
2498             }
2499           }
2500          }
2501         ]
2502        },
2503        toolbar : {
2504         xns : Roo,
2505         '|xns' : 'Roo',
2506         xtype : 'Toolbar',
2507         items  : [
2508          {
2509           cls : 'x-btn-text-icon',
2510           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
2511           text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
2512           xns : Roo.Toolbar,
2513           '|xns' : 'Roo.Toolbar',
2514           xtype : 'Button',
2515           listeners : {
2516            click : function()
2517             {
2518                
2519                 Roo.log("add presed");
2520                  
2521                 // work out last 
2522                 var grid = _this.grid;
2523                 var err = false;
2524                 grid.ds.each(function(r) {
2525                     if (r.data.coitem_qtyord < 1) { 
2526                         Roo.MessageBox.alert("Error", "you must fill in a quantity for " + r.data.item_number);
2527                         err = true;
2528                         return true;
2529                     }
2530                     
2531                 });
2532                 if (err) {
2533                     return;
2534                 }
2535                 
2536             
2537             //    var last = 0;
2538                 var last = _this.form.findField('cohead_max_linenumber').getValue();   
2539                 last++; 
2540                 if(last == 99999){
2541                     last++;
2542                 }
2543                 
2544             
2545                 _this.form.findField('cohead_max_linenumber').setValue(last);    
2546                 
2547                 // this should be getting the previous row..??
2548                  var ct  =    _this.grid.ds.getCount();
2549                  var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;
2550                  
2551                  function lastor(k,d,kk) {
2552                     var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();
2553                     return lastrow ? lastrow.data[kk] : def;
2554                  }
2555                 
2556                 // uses form defaults or last row value.
2557                 var nr = _this.grid.ds.reader.newRow({
2558                     coitem_linenumber : last,
2559                     item_number : '',
2560                     item_descrip1 : '',
2561                     coitem_qtyord : 0,
2562                     coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
2563                     coitem_qtyshipped : 0,
2564                     coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
2565                     coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
2566                     coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
2567                     coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name'),
2568                     coitem_unitcost_in_order_cur  : 0,
2569                     coitem_taxtype_id : _this.data.default_taxtype_id,
2570                     coitem_taxtype_id_taxtype_name : 'Taxable',
2571                     coitem_status : '',
2572                     avail_qty : 0
2573                             
2574                 });
2575                 grid.stopEditing();
2576                 grid.ds.insert(grid.ds.getCount(), nr); 
2577                 grid.startEditing(grid.ds.getCount()-1, 1); // type..
2578                 nr.updatePending = 0;
2579                 nr.isUpdating = 0;
2580                 nr.isInserting =0;
2581                 
2582             },
2583            render : function (_self)
2584             {
2585                 _this.addItemBtn = _self;
2586             }
2587           }
2588          },
2589          {
2590           cls : 'x-btn-text-icon',
2591           icon : rootURL + '/Pman/templates/images/search.gif',
2592           text : _this._strings['9f4f3d35db49c5c2bba70a321a42fa87'] /* Find Products */,
2593           xns : Roo.Toolbar,
2594           '|xns' : 'Roo.Toolbar',
2595           xtype : 'Button',
2596           listeners : {
2597            click : function (_self, e)
2598             {
2599                 var last = _this.form.findField('cohead_max_linenumber').getValue();    \r
2600                 last++;\r
2601                 _this.form.findField('cohead_max_linenumber').setValue(last); 
2602             
2603                 var ct  =    _this.grid.ds.getCount();\r
2604                 var lastrow = ct ?  _this.grid.ds.getAt(ct-1)  : false;\r
2605                      \r
2606                 function lastor(k,d,kk) {\r
2607                    var def = d ? _this.form.findField(k).el.dom.value : _this.form.findField(k).getValue();\r
2608                    return lastrow ? lastrow.data[kk] : def;\r
2609                 }
2610                 
2611                 var cohead_cust_id = _this.form.findField('cohead_cust_id').getValue();
2612                 var cohead_id = _this.form.findField('cohead_id').getValue();
2613                 
2614                 Pman.Dialog.XtupleSalesProductList.show( {cohead_cust_id : cohead_cust_id, cohead_id : cohead_id} , function(res) {
2615             
2616                     _this.grid.stopEditing();
2617             
2618                     if (_this.grid.ds.getCount() > 0) {
2619                         var lr = _this.grid.ds.getAt(_this.grid.ds.getCount()-1);
2620                         if (!lr.data.coitem_itemsite_id) {
2621                             lr.set('coitem_itemsite_id', res.item_itemsite_id_itemsite_id);
2622                             lr.set('item_number',  res.item_number);
2623                             lr.set('item_descrip1', res.item_descrip1);                                
2624                             lr.set('coitem_listprice', res.item_price);                
2625                             lr.set('coitem_price', res.item_price);                                
2626                             lr.set('coitem_custprice', res.item_price);                
2627                             return;
2628                         }
2629                     }
2630                     
2631                     
2632                     
2633                     var nr = _this.grid.ds.reader.newRow({
2634                         coitem_linenumber : last,
2635                         coitem_itemsite_id : res.item_itemsite_id_itemsite_id,
2636                         item_number : res.item_number,
2637                         item_descrip1 : res.item_descrip1,
2638                         coitem_qtyord : 0,
2639                         coitem_cohead_id : _this.form.findField('cohead_id').getValue(),
2640                         coitem_qtyshipped : 0,
2641                         coitem_listprice : res.item_price,
2642                         coitem_price : res.item_price,
2643                         coitem_custprice : res.item_price,
2644                         avail_qty : 0,
2645                         coitem_location_src : lastor('cohead_location_src',false, 'coitem_location_src'),
2646                         coitem_location_src_location_name : lastor('cohead_location_src',true, 'coitem_location_src_location_name'),
2647                         coitem_shipto_id    :  lastor('cohead_shipto_id',false, 'coitem_shipto_id'),
2648                         coitem_shipto_id_shipto_name  : lastor('cohead_shipto_id_shipto_name', false, 'coitem_shipto_id_shipto_name')
2649                                 
2650                     });
2651                     _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
2652             
2653                }); 
2654             }
2655           }
2656          },
2657          {
2658           cls : 'x-btn-text-icon',
2659           hidden : true,
2660           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
2661           text : _this._strings['a0947dda65e4112f49260243804b6528'] /* Xfer all stock to HK */,
2662           xns : Roo.Toolbar,
2663           '|xns' : 'Roo.Toolbar',
2664           xtype : 'Button',
2665           listeners : {
2666            click : function()
2667             {
2668                 // work out last 
2669                 new Pman.Request({
2670                     url : baseURL + '/Roo/coitem',
2671                     mask : 'Loading Data',
2672                     method: 'GET',
2673                     params : {
2674             
2675                         _hk_xfer :_this.form.findField('cohead_id').getValue()
2676                     },
2677                     success : function() {
2678                         _this.grid.ds.load({});
2679                     }
2680                 
2681                 });
2682             },
2683            render : function (_self)
2684             {
2685                 _this.xferAll  = _self;
2686             }
2687           }
2688          },
2689          {
2690           text : _this._strings['66b2bba3de9b8c5d6fb94e9458f1b7f5'] /* Show Inventory History */,
2691           xns : Roo.Toolbar,
2692           '|xns' : 'Roo.Toolbar',
2693           xtype : 'Button',
2694           listeners : {
2695            click : function (_self, e)
2696             {
2697                var c    = _this.grid.getSelectionModel().getSelectedCell();
2698                if (!c) {
2699                     Roo.MessageBox.alert("Error", "Select item to show history (you can also double click on the #avail number) ");
2700                     return;
2701                }
2702                
2703                 var rec = _this.grid.ds.getAt(c[0]);
2704             
2705               Pman.Dialog.XtupleInvHistory.show({
2706                     itemsite_item_id_item_number   : rec.data.item_number,
2707                    // itemsite_item_id_item_descript1 : rec.data.item_descrip1,
2708                     location_name : rec.data.coitem_location_src_location_name,
2709                     location_descrip : rec.data.coitem_location_src_location_descrip,
2710                     
2711                     
2712                     invhist_transdate : _this.form.findField('cohead_targetdate').getValue() 
2713                 }); 
2714                 
2715                
2716             }
2717           }
2718          },
2719          {
2720           xns : Roo.Toolbar,
2721           '|xns' : 'Roo.Toolbar',
2722           xtype : 'Separator'
2723          },
2724          {
2725           text : _this._strings['c43b0fbe81e21c0a874a155ce528eebf'] /* Apply % Discount of :  */,
2726           xns : Roo.Toolbar,
2727           '|xns' : 'Roo.Toolbar',
2728           xtype : 'TextItem'
2729          },
2730          {
2731           width : 40,
2732           xns : Roo.form,
2733           '|xns' : 'Roo.form',
2734           xtype : 'TextField',
2735           listeners : {
2736            render : function (_self)
2737             {
2738                 _this._applyDiscount = _self;
2739             }
2740           }
2741          },
2742          {
2743           text : _this._strings['e87de1a5d238411ab34a292be599e9f4'] /* Apply To All */,
2744           xns : Roo.Toolbar,
2745           '|xns' : 'Roo.Toolbar',
2746           xtype : 'Button',
2747           listeners : {
2748            click : function (_self, e)
2749             {
2750                 var val =  parseFloat(_this._applyDiscount.getValue());
2751                 
2752                 var factor = (100.0 - val)/100.0;
2753                 
2754                 _this.grid.ds.each(function(rec) {
2755                     if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
2756                         return;
2757                     }
2758                 
2759                     rec.set('coitem_price', rec.data.coitem_custprice * factor);
2760                     rec.set('coitem_linedisc', val);
2761                     rec.set('coitem_subtotal', rec.data.coitem_price  & rec.data.ordqty);
2762                     rec.commit();
2763                 
2764                 });
2765                 
2766                 
2767             }
2768           }
2769          },
2770          {
2771           text : _this._strings['72d6d7a1885885bb55a565fd1070581a'] /* Import */,
2772           xns : Roo.Toolbar,
2773           '|xns' : 'Roo.Toolbar',
2774           xtype : 'Button',
2775           listeners : {
2776            click : function (_self, e)
2777             {
2778             
2779                 if (!(1* _this.form.findField('cohead_id').getValue())) {
2780                     Roo.MessageBox.alert("Error", "save the order first");
2781                 }
2782                 
2783             
2784                Pman.Dialog.Image.show(
2785                    {
2786                         timeout : 60000,
2787                         _url : baseURL+'/Xtuple/Import/SalesOrder',
2788                         onid : _this.form.findField('cohead_id').getValue()
2789                     
2790                    },
2791                    function (data) {
2792             
2793                         Roo.MessageBox.alert("Notice", "Uploaded");
2794                         _this.grid.footer.onClick('first');
2795             
2796                    }
2797                );
2798             }
2799           }
2800          },
2801          {
2802           xns : Roo.Toolbar,
2803           '|xns' : 'Roo.Toolbar',
2804           xtype : 'Fill'
2805          },
2806          {
2807           cls : 'x-btn-text-icon',
2808           icon : rootURL + '/Pman/templates/images/trash.gif',
2809           text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
2810           xns : Roo.Toolbar,
2811           '|xns' : 'Roo.Toolbar',
2812           xtype : 'Button',
2813           listeners : {
2814            click : function()
2815             {
2816                  _this.grid.stopEditing();
2817                 // check that no shipments or invoices are done..
2818                 var rc = _this.grid.getSelectionModel().getSelectedCell();
2819                 
2820                 var rec = _this.grid.ds.getAt(rc[0]);
2821                 
2822                 if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
2823                     Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
2824                     return;
2825                 }
2826                if (rec.data.coitem_subnumber*1  > 0) {
2827                     Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
2828                     return;
2829                 }
2830                 if (!rec.data.coitem_id) {
2831                     _this.grid.ds.remove(rec);
2832                     return;
2833                 }
2834                 function remove()
2835                 {
2836                 
2837                     new  Pman.Request({
2838                         url : baseURL + '/Roo/coitem',
2839                         method : 'POST',
2840                         params : {
2841                             _delete : rec.data.coitem_id
2842                         
2843                         },
2844                         success : function() {
2845                             if (rec.data.item_type == 'K') {
2846                                 _this.grid.ds.load({});
2847                                 return;
2848                             }
2849                             _this.grid.ds.remove(rec);
2850                         }
2851                     
2852                     });
2853                 }
2854                 if (rec.data_qtyord * 1 < 1) {
2855                     remove();
2856                 }
2857                 
2858                 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that line?", function(r)
2859                 {
2860                     if (r != 'yes') {
2861                         return;
2862                     }
2863                     remove();
2864                 
2865                 });
2866             
2867                 
2868                 
2869             }
2870           }
2871          },
2872          {
2873           cls : 'x-btn-text-icon',
2874           icon : rootURL + '/Pman/templates/images/trash.gif',
2875           text : _this._strings['27f2870eaa01c99fc83105240ad15f7f'] /* Delete All */,
2876           xns : Roo.Toolbar,
2877           '|xns' : 'Roo.Toolbar',
2878           xtype : 'Button',
2879           listeners : {
2880            click : function()
2881             {
2882                  _this.grid.stopEditing();
2883                 // check that no shipments or invoices are done..
2884                 var ids = [];
2885                 _this.grid.ds.each(function(rec) {
2886                 
2887             
2888                 
2889                     if (rec.data.coitem_qtyshipped > 0 || rec.data.cobill_billed > 0) {
2890                         //Roo.MessageBox.alert("Error", "That item has been shipped or invoices - void the shipments/invoices first");
2891                         return;
2892                     }
2893                     if (rec.data.item_type == 'K') {
2894                         return;
2895                     }
2896             
2897                    if (rec.data.coitem_subnumber*1  > 0) {
2898                         //Roo.MessageBox.alert("Error", "Delete the kit item that that belongs to.");
2899                         return;
2900                     }
2901                     if (!rec.data.coitem_id) {
2902                         _this.grid.ds.remove(rec);
2903                         return;
2904                     }
2905                     ids.push(rec.data.coitem_id);
2906                 });
2907                 function remove()
2908                 {
2909                 
2910                     new  Pman.Request({
2911                         url : baseURL + '/Roo/coitem',
2912                         method : 'POST',
2913                         params : {
2914                             _delete : ids.join(',')
2915                         
2916                         },
2917                         success : function() {
2918             
2919                             _this.grid.footer.onClick('first');
2920                         }
2921                     
2922                     });
2923                 }
2924             //    if (rec.data_qtyord * 1 < 1) {
2925             //        remove();
2926             //    }
2927                 
2928                 Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete everything?", function(r)
2929                 {
2930                     if (r != 'yes') {
2931                         return;
2932                     }
2933                     remove();
2934                 
2935                 });
2936             
2937                 
2938                 
2939             }
2940           }
2941          }
2942         ]
2943        },
2944        dataSource : {
2945         remoteSort : true,
2946         sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
2947         xns : Roo.data,
2948         '|xns' : 'Roo.data',
2949         xtype : 'Store',
2950         listeners : {
2951          beforeload : function (_self,o) {
2952           
2953               try {
2954                  this.removeAll();
2955              } catch (e) { }
2956              
2957           
2958               if (!_this.data || !_this.data.cohead_id) {
2959                   return false;
2960               }
2961               o.params = o.params || {};
2962               
2963               o.params.coitem_cohead_id = _this.data.cohead_id;
2964               o.params._without_list_discount =1;
2965               //o.params.limit = 999;
2966           
2967               
2968           },
2969          load : function (_self, records, options)
2970           {
2971               // need to fetch availablity from master data..
2972               // build a list of what to ask..
2973           
2974               // query: ITEM CODE - LOCATION
2975               _this.grid.footer.updateSummary();
2976               _this.grid.loadAvail.defer(100, _this.grid);
2977           
2978               
2979               
2980               
2981           },
2982          update : function (_self, rec, operation)
2983               {
2984              
2985              if (operation !=  Roo.data.Record.COMMIT) {
2986                  return;
2987              }
2988           
2989              // row has been updated..
2990              // if the qty + item has been filled in, we should try and save it..
2991            
2992               
2993               var setRecord = function(){
2994               
2995                    Roo.log("Clearing update?"  + rec.data.coitem_linenumber);
2996                   rec.updatePending = 0;
2997                   if(rec.isInserting){
2998                       rec.isInserting = 0;
2999                       return;
3000                   }
3001                   rec.isUpdating = 0;
3002           
3003               }
3004               if (!(rec.data.coitem_itemsite_id * 1) || !(rec.data.coitem_qtyord*1)) {
3005                   setRecord();
3006                   return;
3007               }
3008               var     doCommit = function() {
3009                    Roo.log("Sending  data?"  + rec.data.coitem_linenumber);
3010                   
3011                   new Pman.Request({
3012                       url : baseURL+'/Roo/coitem',
3013                       method : 'POST',
3014                       params : rec.data,
3015                       success: function(res)
3016                       {
3017                           try {
3018                               var row = _this.grid.ds.indexOf(rec);
3019                               Roo.get(_this.grid.view.getRow(row)).removeClass('dragon-not-saved');
3020                           } catch(e) {
3021                               Roo.log(e);
3022                           }
3023                               
3024                           
3025                            Roo.log("GOT success: "  + rec.data.coitem_linenumber);
3026                           //Roo.log("GOT success");
3027                           // update the data...
3028                           
3029                           if (rec.data.item_type == 'K') {
3030                                Roo.log("Kit??");
3031                               _this.grid.ds.load({});
3032                               
3033                               return;
3034                           }
3035                           
3036                           // why is this here.??
3037                           
3038                           if (_this.grid.activeEditor) {
3039                                rec.editing = true;
3040                                
3041                                
3042                            } 
3043                            
3044                           rec.set('coitem_id', res.data.coitem_id);
3045                           rec.set('coitem_status', res.data.coitem_status);
3046                            
3047                           
3048                           rec.dirty = false;
3049                           delete rec.modified;
3050                           try {
3051                               _this.grid.footer.updateSummary();          
3052                               _this.grid.loadAvail();
3053                           } catch (e) { }
3054                           
3055           
3056                           setRecord();
3057                       },
3058                       failure : function(res)
3059                       {
3060                           setRecord();
3061                           Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error updating");
3062                       }
3063                       
3064                       
3065                   });
3066                 } ; 
3067              
3068               
3069               doCommit();
3070               
3071               
3072               
3073           }
3074         },
3075         proxy : {
3076          method : 'GET',
3077          url : baseURL + '/Roo/coitem.php',
3078          xns : Roo.data,
3079          '|xns' : 'Roo.data',
3080          xtype : 'HttpProxy'
3081         },
3082         reader : {
3083          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\"}',
3084          fields : [
3085              {
3086                  'name': 'coitem_linenumber',
3087                  'type': 'int'
3088              },
3089              {
3090                  'name': 'coitem_itemsite_id',
3091                  'type': 'int'
3092              },
3093              {
3094                  'name': 'coitem_qtyord'
3095              },
3096              {
3097                  'name': 'coitem_unitcost'
3098              },
3099              {
3100                  'name': 'coitem_price'
3101              },
3102              {
3103                  'name': 'coitem_custprice'
3104              },
3105              {
3106                  'name': 'coitem_qtyreturned'
3107              },
3108              {
3109                  'name': 'coitem_prcost'
3110              },
3111              {
3112                  'name': 'coitem_price_uom_id',
3113                  'type': 'int'
3114              },
3115              {
3116                  'name': 'coitem_qtyreserved'
3117              }
3118          ],
3119          id : 'coitem_id',
3120          root : 'data',
3121          totalProperty : 'total',
3122          xns : Roo.data,
3123          '|xns' : 'Roo.data',
3124          xtype : 'JsonReader'
3125         }
3126        },
3127        sm : {
3128         enter_is_tab : true,
3129         xns : Roo.grid,
3130         '|xns' : 'Roo.grid',
3131         xtype : 'CellSelectionModel',
3132         listeners : {
3133          beforeeditnext : function (eventdata)
3134           {
3135               
3136               return;
3137               // this does not work, as the reload effect cancels editng.
3138               var rec = _this.grid.ds.getAt(eventdata.cell[0]);
3139               if (rec.data.coitem_subnumber *1 < 0 ) {
3140                   return;
3141               }
3142               var r = eventdata.cell[0] + 1;
3143           
3144               while (true) {
3145                   if (r > _this.grid.ds.getCount()-1 ) {
3146                       eventdata.cell = false;
3147                       return;
3148                   }
3149                   rec =  _this.grid.ds.getAt(r);
3150                   if (rec.data.coitem_subnumber *1 < 0 ) {
3151                      eventdata.cell = [ r, eventdata.cell[1] ];
3152                      return;
3153                   }
3154                   r++;
3155               }
3156               
3157               
3158            
3159           
3160           },
3161          tabend : function (_self)
3162           {
3163               _this.addItemBtn.fireEvent('click', _this.addItemBtn);
3164           }
3165         }
3166        },
3167        colModel : [
3168         {
3169          builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_linenumber\",\"columnshort\":\"coitem_linenumber\",\"ctype\":\"int4\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Item#\"}',
3170          dataIndex : 'coitem_linenumber',
3171          header : _this._strings['7a113dee68a51f4c5f71264fd0ce3781'] /* Item# */,
3172          renderer : function(v,x,r) {
3173          
3174              if (r.data.coitem_subnumber * 1 > 0) {
3175                   return String.format('{0}.{1}', v,r.data.coitem_subnumber);
3176               }
3177               return String.format('{0}', v);
3178            },
3179          width : 40,
3180          xns : Roo.grid,
3181          '|xns' : 'Roo.grid',
3182          xtype : 'ColumnModel'
3183         },
3184         {
3185          dataIndex : 'item_number',
3186          header : _this._strings['7608203603437f0513ba8203a2d39a4f'] /* Item Code */,
3187          renderer : function(v) { return String.format('{0}', v); },
3188          width : 75,
3189          xns : Roo.grid,
3190          '|xns' : 'Roo.grid',
3191          xtype : 'ColumnModel',
3192          editor : {
3193           xns : Roo.grid,
3194           '|xns' : 'Roo.grid',
3195           xtype : 'GridEditor',
3196           field : {
3197            allowBlank : false,
3198            displayField : 'itemsite_item_id_item_number',
3199            editable : true,
3200            emptyText : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
3201            forceSelection : true,
3202            hiddenName : 'itemsite_item_id_item_number',
3203            listWidth : 400,
3204            loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
3205            minChars : 2,
3206            name : 'item_number',
3207            pageSize : 20,
3208            qtip : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
3209            queryParam : 'query[number]',
3210            selectOnFocus : true,
3211            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>',
3212            triggerAction : 'all',
3213            typeAhead : false,
3214            valueField : 'item_number',
3215            xns : Roo.form,
3216            '|xns' : 'Roo.form',
3217            xtype : 'ComboBox',
3218            listeners : {
3219             beforeselect : function (combo, record, index)
3220              {
3221                // set _this.data values ..
3222                var ar = _this.grid.activeEditor.record;
3223              //  Roo.log('beforeselect');
3224                
3225                
3226                (function() { 
3227                   //  Roo.log('beforeselect-cb');
3228                    ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
3229                    ar.set('coitem_listprice', record.data.item_listprice);
3230                    ar.set('coitem_price', record.data.item_price);
3231                    ar.set('coitem_custprice', record.data.item_price);
3232                    ar.set('coitem_itemsite_id', record.data.itemsite_id);
3233                    ar.set('item_number', record.data.itemsite_item_id_item_number);
3234                   ar.set('item_type', record.data.itemsite_item_id_item_type);
3235                    ar.set('avail_qty', 0);
3236                    ar.commit();
3237                }).defer(100);
3238                
3239              }
3240            },
3241            store : {
3242             remoteSort : true,
3243             sortInfo : { direction : 'ASC', field: 'item_number' },
3244             xns : Roo.data,
3245             '|xns' : 'Roo.data',
3246             xtype : 'Store',
3247             listeners : {
3248              beforeload : function (_self, o){
3249                   o.params = o.params || {};
3250                   o.params.customer_id = _this.form.findField('cohead_cust_id').getValue();
3251                   o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue();
3252                   //o.params.shipto_cust_id = _this.data.cohead_cust_id;
3253                   // set more here
3254               }
3255             },
3256             proxy : {
3257              method : 'GET',
3258              url : baseURL + '/Roo/itemsite.php',
3259              xns : Roo.data,
3260              '|xns' : 'Roo.data',
3261              xtype : 'HttpProxy'
3262             },
3263             reader : {
3264              fields : [{"name":"item_id","type":"int"},"item_number"],
3265              id : 'shipto_id',
3266              root : 'data',
3267              totalProperty : 'total',
3268              xns : Roo.data,
3269              '|xns' : 'Roo.data',
3270              xtype : 'JsonReader'
3271             }
3272            }
3273           }
3274          }
3275         },
3276         {
3277          dataIndex : 'coitem_location_src',
3278          header : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
3279          renderer : function(v,x,r) { 
3280              return String.format('{0}', r.data.coitem_location_src_location_name); 
3281          },
3282          width : 75,
3283          xns : Roo.grid,
3284          '|xns' : 'Roo.grid',
3285          xtype : 'ColumnModel',
3286          editor : {
3287           xns : Roo.grid,
3288           '|xns' : 'Roo.grid',
3289           xtype : 'GridEditor',
3290           field : {
3291            allowBlank : false,
3292            alwaysQuery : true,
3293            displayField : 'location_name',
3294            editable : true,
3295            emptyText : _this._strings['fc44040a63559bee1157010d4c602422'] /* Select location */,
3296            forceSelection : true,
3297            hiddenName : 'coitem_location_src',
3298            listWidth : 400,
3299            loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
3300            minChars : 2,
3301            name : 'coitem_location_src_location_name',
3302            pageSize : 20,
3303            qtip : _this._strings['786410e93beb0193d89f8608c54feb4b'] /* Select item */,
3304            queryParam : 'query[location_name]',
3305            selectOnFocus : true,
3306            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b> {location_name}</b> {location_descrip}</div>',
3307            triggerAction : 'all',
3308            typeAhead : false,
3309            valueField : 'location_id',
3310            xns : Roo.form,
3311            '|xns' : 'Roo.form',
3312            xtype : 'ComboBox',
3313            listeners : {
3314             beforeselect : function (combo, record, index)
3315              {
3316                // set _this.data values ..
3317                var ar = _this.grid.activeEditor.record;
3318                
3319                
3320                
3321                //Roo.log('beforeselect');
3322               
3323               /*
3324                (function() { 
3325                   //  Roo.log('beforeselect-cb');
3326                    ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
3327                    ar.set('coitem_price', record.data.item_listprice);
3328                    ar.set('coitem_custprice', record.data.item_price);
3329                     ar.set('coitem_itemsite_id', record.data.itemsite_id);
3330                    ar.set('item_number', record.data.itemsite_item_id_item_number);
3331              
3332                    ar.commit();
3333                }).defer(100);
3334                */
3335              }
3336            },
3337            store : {
3338             remoteSort : true,
3339             sortInfo : { direction : 'ASC', field: 'location_name' },
3340             xns : Roo.data,
3341             '|xns' : 'Roo.data',
3342             xtype : 'Store',
3343             listeners : {
3344              beforeload : function (_self, o){
3345                   o.params = o.params || {};
3346                   
3347                   var row = _this.grid.activeEditor.record;
3348                   
3349                   o.params['query[item_itemsite_id]'] = row.data.coitem_itemsite_id;
3350                   // need to know the date to calc the est. delivery time..
3351                   //o.params['query[avail_when]'] = _this.form.findField('cohead_targetdate').getValue().format('Y-m-d');
3352                   //o.params.location_netable = 1;
3353                   o.params['query[cohead_id]'] = _this.form.findField('cohead_id').getValue(); 
3354                   
3355                    o.params.location_restrict = 0;
3356                   o.params._notinternalcompany = 1;
3357                   
3358                 //  _this.grid;
3359               
3360               //    o.params.itemsite_id = _this.form.findField('cohead_cust_id').getValue();
3361                   //o.params.shipto_cust_id = _this.data.cohead_cust_id;
3362                   // set more here
3363               }
3364             },
3365             proxy : {
3366              method : 'GET',
3367              url : baseURL + '/Roo/location.php',
3368              xns : Roo.data,
3369              '|xns' : 'Roo.data',
3370              xtype : 'HttpProxy'
3371             },
3372             reader : {
3373              fields : [{"name":"location_id","type":"int"},"location_name"],
3374              id : 'shipto_id',
3375              root : 'data',
3376              totalProperty : 'total',
3377              xns : Roo.data,
3378              '|xns' : 'Roo.data',
3379              xtype : 'JsonReader'
3380             }
3381            }
3382           }
3383          }
3384         },
3385         {
3386          dataIndex : 'coitem_shipto_id',
3387          header : _this._strings['e12167aa0a7698e6ebc92b4ce3909b53'] /* To */,
3388          renderer : function(v,x,r) { 
3389              return String.format('{0}:{1}', v, r.data.coitem_shipto_id_shipto_name); 
3390          },
3391          width : 75,
3392          xns : Roo.grid,
3393          '|xns' : 'Roo.grid',
3394          xtype : 'ColumnModel',
3395          editor : {
3396           xns : Roo.grid,
3397           '|xns' : 'Roo.grid',
3398           xtype : 'GridEditor',
3399           field : {
3400            allowBlank : false,
3401            alwaysQuery : true,
3402            displayField : 'shipto_name',
3403            editable : false,
3404            emptyText : _this._strings['fbb9d6ec5325d0fe63c19431856a0802'] /* Select cntct */,
3405            forceSelection : true,
3406            hiddenName : 'cohead_shipto_id',
3407            listWidth : 400,
3408            loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
3409            minChars : 2,
3410            name : 'coitem_shipto_id_shipto_name',
3411            pageSize : 20,
3412            qtip : _this._strings['e23841a1d7427d8a9297142145dff049'] /* Select shipto */,
3413            queryParam : 'query[shipto_name]',
3414            selectOnFocus : true,
3415            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{shipto_id}:{shipto_addr_id_addr_name}</b> </div>',
3416            triggerAction : 'all',
3417            typeAhead : false,
3418            valueField : 'shipto_id',
3419            width : 300,
3420            xns : Roo.form,
3421            '|xns' : 'Roo.form',
3422            xtype : 'ComboBox',
3423            listeners : {
3424             add : function (combo)
3425              {
3426              
3427                 Pman.Dialog.XtupleCustomer.show({ cust_id : _this.form.findField('cohead_cust_id').getValue() }, function(data) {
3428                      // refresh the data in the pulldown..
3429                  }); 
3430              },
3431             beforeselect : function (combo, record, index)
3432              {
3433              
3434                  var v = [];
3435                  for(var i = 1; i <4; i++) {
3436                      _this.data['cohead_shiptoaddress'+  i] = record.data['cntct_addr_id_addr_line'+i];
3437                  }
3438                  _this.form.findField('shipto_address').update();
3439                  
3440               
3441              }
3442            },
3443            store : {
3444             remoteSort : true,
3445             sortInfo : { direction : 'ASC', field: 'shipto_name' },
3446             xns : Roo.data,
3447             '|xns' : 'Roo.data',
3448             xtype : 'Store',
3449             listeners : {
3450              beforeload : function (_self, o){
3451                   o.params = o.params || {};
3452                   o.params.shipto_cust_id = _this.data.cohead_cust_id; 
3453                   //o.params['query[with_shipinfo]'] = 1;
3454                   // set more here
3455               }
3456             },
3457             proxy : {
3458              method : 'GET',
3459              url : baseURL + '/Roo/shiptoinfo.php',
3460              xns : Roo.data,
3461              '|xns' : 'Roo.data',
3462              xtype : 'HttpProxy'
3463             },
3464             reader : {
3465              fields : [{"name":"cntct_id","type":"int"},"cntct_name"],
3466              id : 'shipto_id',
3467              root : 'data',
3468              totalProperty : 'total',
3469              xns : Roo.data,
3470              '|xns' : 'Roo.data',
3471              xtype : 'JsonReader'
3472             }
3473            }
3474           }
3475          }
3476         },
3477         {
3478          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\":\"\"}',
3479          dataIndex : 'item_descrip1',
3480          header : _this._strings['d9db367d7e9d6a3d3ca0346dfa1ff9d2'] /* Item Description */,
3481          renderer : function(v,x,r) { 
3482          
3483              if (r.data.coitem_memo && r.data.coitem_memo.length) {
3484                  return String.format('{0}', r.data.coitem_memo);
3485                  if (r.data.coitem_memo != v) {
3486                      r.set('item_descrip1', r.data.coitem_memo);
3487                  }
3488                  
3489              }
3490              if (v && v.length > 49) {
3491                  return String.format('<span style="color:orange" qtip="line may be too long to print">{0}</span>', v);
3492              }
3493              
3494              return String.format('{0}', v); 
3495              
3496          },
3497          width : 150,
3498          xns : Roo.grid,
3499          '|xns' : 'Roo.grid',
3500          xtype : 'ColumnModel',
3501          editor : {
3502           xns : Roo.grid,
3503           '|xns' : 'Roo.grid',
3504           xtype : 'GridEditor',
3505           field : {
3506            allowBlank : false,
3507            xns : Roo.form,
3508            '|xns' : 'Roo.form',
3509            xtype : 'TextField'
3510           }
3511          }
3512         },
3513         {
3514          align : 'right',
3515          builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
3516          dataIndex : 'coitem_status',
3517          header : _this._strings['ec53a8c4f07baed5d8825072c89799be'] /* Status */,
3518          renderer : function(v) { return String.format('{0}', v); },
3519          width : 50,
3520          xns : Roo.grid,
3521          '|xns' : 'Roo.grid',
3522          xtype : 'ColumnModel'
3523         },
3524         {
3525          align : 'right',
3526          dataIndex : 'coitem_qtyord',
3527          header : _this._strings['03ab340b3f99e03cff9e84314ead38c0'] /* Qty */,
3528          renderer : function(v,x,r) { 
3529              var v = parseInt(v);
3530              //var aq = parseInt(r.data.avail_qty);
3531              //aq = isNaN(aq) ? 0 : aq;
3532             
3533              var rate = _this.form.findField('taxzone_rate').getValue();
3534              r.data.coitem_subtotal =  v * r.data.coitem_price;
3535              r.data.coitem_subtotal_tax = v * r.data.coitem_price * ( 1 + rate * 1);
3536              return String.format('{0}', v); 
3537              
3538          },
3539          width : 40,
3540          xns : Roo.grid,
3541          '|xns' : 'Roo.grid',
3542          xtype : 'ColumnModel',
3543          editor : {
3544           xns : Roo.grid,
3545           '|xns' : 'Roo.grid',
3546           xtype : 'GridEditor',
3547           field : {
3548            allowDecimals : false,
3549            decimalPrecision : 0,
3550            minValue : 1,
3551            style : 'text-align:right',
3552            xns : Roo.form,
3553            '|xns' : 'Roo.form',
3554            xtype : 'NumberField',
3555            listeners : {
3556             focus : function (_self)
3557              {
3558                  if (this.value == 0) {
3559                      this.el.dom.value = '';
3560                  }
3561              }
3562            }
3563           }
3564          }
3565         },
3566         {
3567          align : 'right',
3568          dataIndex : 'coitem_price',
3569          header : _this._strings['b166cb3a96bdb966f3288b8599594d0d'] /* Sell @ */,
3570          renderer : function(v,x,r) { 
3571          
3572              var rate = _this.form.findField('taxzone_rate').getValue();
3573              r.data.coitem_subtotal = v * r.data.coitem_qtyord;
3574              r.data.coitem_subtotal_tax = v * ( 1 + rate * 1 ) * r.data.coitem_qtyord;
3575              r.data.coitem_price_tax = v * ( 1 + rate * 1 );
3576              if (parseInt(v) < 1) {
3577                  return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
3578              }
3579              
3580              
3581              //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
3582              
3583              return  String.format('{0}', Roo.util.Format.number(v,3)); 
3584          },
3585          width : 70,
3586          xns : Roo.grid,
3587          '|xns' : 'Roo.grid',
3588          xtype : 'ColumnModel',
3589          editor : {
3590           xns : Roo.grid,
3591           '|xns' : 'Roo.grid',
3592           xtype : 'GridEditor',
3593           field : {
3594            decimalPrecision : 3,
3595            minValue : 0,
3596            style : 'text-align:right',
3597            xns : Roo.form,
3598            '|xns' : 'Roo.form',
3599            xtype : 'NumberField',
3600            listeners : {
3601             focus : function (_self)
3602              {
3603                  if (this.value == 0.0) {
3604                      this.el.dom.value = '';
3605                  }
3606              }
3607            }
3608           }
3609          }
3610         },
3611         {
3612          align : 'right',
3613          dataIndex : 'coitem_price_tax',
3614          header : _this._strings['9122d60c0550be8ab070b96d8bbc6358'] /* Sell @w/GST */,
3615          hidden : true,
3616          renderer : function(v,x,r) { 
3617              
3618              if (parseInt(v) < 1) {
3619                  return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,3)); 
3620              }
3621              
3622              return  String.format('{0}', Roo.util.Format.number(v,3)); 
3623          },
3624          width : 70,
3625          xns : Roo.grid,
3626          '|xns' : 'Roo.grid',
3627          xtype : 'ColumnModel',
3628          editor : {
3629           xns : Roo.grid,
3630           '|xns' : 'Roo.grid',
3631           xtype : 'GridEditor',
3632           field : {
3633            decimalPrecision : 3,
3634            minValue : 0,
3635            style : 'text-align:right',
3636            xns : Roo.form,
3637            '|xns' : 'Roo.form',
3638            xtype : 'NumberField',
3639            listeners : {
3640             focus : function (_self)
3641              {
3642                  if (this.value == 0.0) {
3643                      this.el.dom.value = '';
3644                  }
3645              }
3646            }
3647           }
3648          }
3649         },
3650         {
3651          align : 'right',
3652          dataIndex : 'coitem_linedisc',
3653          header : _this._strings['9d4ba8f5211a3ba238b2032be5991c14'] /* Disc% */,
3654          renderer : function(v,x,r) { 
3655          
3656              // coitem_custprice = coitem_price * ((100 - coitem_disc)/ 100) 
3657              
3658              //                      12 * (( 100 - 0) / 100)
3659              // coitem_custprice / coitem_price = ((100 - coitem_disc)/ 100) 
3660              // 100 - ((coitem_custprice / coitem_price) * 100)  = coitem_disc
3661              //                             100 -  97 =        100 -3 
3662          
3663             // r.data.coitem_linedisc = 100 - (
3664              //           (parseFloat(r.data.coitem_custprice) /
3665               //               parseFloat(r.data.coitem_price)
3666                 //        ) * 100.00);
3667              var fl = parseFloat(r.data.coitem_linedisc);
3668              if ( isNaN(fl) || fl == 0.0 || r.data.coitem_price > r.data.coitem_custprice)  {
3669                  return '';
3670              }
3671              return  String.format('<span style="color:green">{0}%</span>', Roo.util.Format.number( r.data.coitem_linedisc,2)); 
3672          },
3673          width : 50,
3674          xns : Roo.grid,
3675          '|xns' : 'Roo.grid',
3676          xtype : 'ColumnModel',
3677          editor : {
3678           xns : Roo.grid,
3679           '|xns' : 'Roo.grid',
3680           xtype : 'GridEditor',
3681           field : {
3682            decimalPrecision : 2,
3683            maxValue : 100,
3684            minValue : 0,
3685            style : 'text-align:right',
3686            xns : Roo.form,
3687            '|xns' : 'Roo.form',
3688            xtype : 'NumberField',
3689            listeners : {
3690             focus : function (_self)
3691              {
3692                  if (this.value == 0.0) {
3693                      this.el.dom.value = '';
3694                  }
3695              }
3696            }
3697           }
3698          }
3699         },
3700         {
3701          align : 'right',
3702          dataIndex : 'coitem_custprice',
3703          header : _this._strings['f84e65035f5d2d4a090b8a626c822321'] /* List Price */,
3704          renderer : function(v,x,r) { 
3705              
3706              var rate = _this.form.findField('taxzone_rate').getValue();
3707              r.data.coitem_custprice_tax = v * ( 1 + rate * 1 );
3708              
3709              var tip = 'No WRP available';
3710              if ((r.data.coitem_wrpprice * 1) > 0) {
3711                  tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
3712              }
3713              // less than zero, show as red..
3714              if (parseFloat(v) < 1) {
3715                  return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
3716                      Roo.util.Format.number(v,3), tip); 
3717              }
3718              if (r.data.customer_price_each != v) {
3719                    return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
3720                      Roo.util.Format.number(v,3), 
3721                      "List Price = " +  Roo.util.Format.number(r.data.customer_price_each,3)
3722                  ); 
3723              }
3724              
3725              
3726              
3727              //r.data.coitem_subtotal = v * r.data.coitem_qtyord;
3728              
3729              //r.set('coitem_subtotal', v * r.data.coitem_qtyord);
3730              
3731              return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
3732          },
3733          width : 70,
3734          xns : Roo.grid,
3735          '|xns' : 'Roo.grid',
3736          xtype : 'ColumnModel',
3737          editor : {
3738           xns : Roo.grid,
3739           '|xns' : 'Roo.grid',
3740           xtype : 'GridEditor',
3741           field : {
3742            decimalPrecision : 3,
3743            minValue : 0,
3744            style : 'text-align:right',
3745            xns : Roo.form,
3746            '|xns' : 'Roo.form',
3747            xtype : 'NumberField',
3748            listeners : {
3749             focus : function (_self)
3750              {
3751                  if (this.value == 0.0) {
3752                      this.el.dom.value = '';
3753                  }
3754              }
3755            }
3756           }
3757          }
3758         },
3759         {
3760          align : 'right',
3761          dataIndex : 'coitem_custprice_tax',
3762          header : _this._strings['4721299f56b6b7d43591156d1d3f3e82'] /* List Price w/GST */,
3763          hidden : true,
3764          renderer : function(v,x,r) { 
3765              var rate = _this.form.findField('taxzone_rate').getValue();
3766              var tip = 'No WRP available';
3767              if ((r.data.coitem_wrpprice * 1) > 0) {
3768                  tip = "WRP : " + Roo.util.Format.number(r.data.coitem_wrpprice,3);
3769              }
3770              
3771              if (parseFloat(v) < 1) {
3772                  return String.format('<b qtip="{1}" style="color:red;">{0}</b>', 
3773                      Roo.util.Format.number(v,3), tip); 
3774              }
3775              if (r.data.customer_price_each != v) {
3776                    return String.format('<b qtip="{1}" style="color:pink;">{0}</b>', 
3777                      Roo.util.Format.number(v,3), 
3778                      "List Price = " +  Roo.util.Format.number(r.data.customer_price_each * ( 1 + rate * 1 ),3)
3779                  ); 
3780              }
3781              
3782              return  String.format('<span qtip="{1}">{0}</span>', Roo.util.Format.number(v,3), tip); 
3783          },
3784          width : 70,
3785          xns : Roo.grid,
3786          '|xns' : 'Roo.grid',
3787          xtype : 'ColumnModel',
3788          editor : {
3789           xns : Roo.grid,
3790           '|xns' : 'Roo.grid',
3791           xtype : 'GridEditor',
3792           field : {
3793            decimalPrecision : 3,
3794            minValue : 0,
3795            style : 'text-align:right',
3796            xns : Roo.form,
3797            '|xns' : 'Roo.form',
3798            xtype : 'NumberField',
3799            listeners : {
3800             focus : function (_self)
3801              {
3802                  if (this.value == 0.0) {
3803                      this.el.dom.value = '';
3804                  }
3805              }
3806            }
3807           }
3808          }
3809         },
3810         {
3811          align : 'right',
3812          dataIndex : 'coitem_subtotal',
3813          header : _this._strings['c5eae6ea505388a73962c635ac821fba'] /* SubTotal */,
3814          renderer : function(v) {
3815          
3816              if (parseInt(v) < 1) {
3817                  return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
3818              }
3819          
3820              
3821          
3822           return Roo.util.Format.number( v, 2);
3823            },
3824          width : 70,
3825          xns : Roo.grid,
3826          '|xns' : 'Roo.grid',
3827          xtype : 'ColumnModel'
3828         },
3829         {
3830          align : 'right',
3831          dataIndex : 'coitem_subtotal_tax',
3832          header : _this._strings['236119342501b1e596bc82013c9cfc42'] /* SubTotal w/GST */,
3833          hidden : true,
3834          renderer : function(v,x,r) { 
3835             
3836              if (parseInt(v) < 1) {
3837                  return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(v,2)); 
3838              }
3839              
3840              return  String.format('{0}', Roo.util.Format.number(v,2)); 
3841          },
3842          width : 70,
3843          xns : Roo.grid,
3844          '|xns' : 'Roo.grid',
3845          xtype : 'ColumnModel'
3846         },
3847         {
3848          align : 'right',
3849          builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_unitcost\",\"columnshort\":\"coitem_unitcost\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"Unit Cost\"}',
3850          dataIndex : 'coitem_unitcost_in_order_cur',
3851          header : _this._strings['871080cb9d00a8bda1b9f1db3c164341'] /* Unit Cost */,
3852          renderer : function(v) { return Roo.util.Format.number( v, 2); },
3853          width : 50,
3854          xns : Roo.grid,
3855          '|xns' : 'Roo.grid',
3856          xtype : 'ColumnModel'
3857         },
3858         {
3859          align : 'right',
3860          dataIndex : 'coitem_taxtype_id',
3861          header : _this._strings['13abfee28b4564e3fb059420fbedbec5'] /* Taxed */,
3862          renderer : function(v,x,r) { return String.format('{0}', r.data.coitem_taxtype_id_taxtype_name); },
3863          width : 50,
3864          xns : Roo.grid,
3865          '|xns' : 'Roo.grid',
3866          xtype : 'ColumnModel',
3867          editor : {
3868           xns : Roo.grid,
3869           '|xns' : 'Roo.grid',
3870           xtype : 'GridEditor',
3871           field : {
3872            allowBlank : false,
3873            displayField : 'taxtype_name',
3874            editable : false,
3875            emptyText : _this._strings['b3c65c9f85b429821cf931b38386a64d'] /* Select Tax Type */,
3876            forceSelection : true,
3877            hiddenName : 'coitem_taxtype_id',
3878            listWidth : 400,
3879            loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
3880            minChars : 2,
3881            name : 'coitem_taxtype_id_taxtype_name',
3882            pageSize : 20,
3883            qtip : _this._strings['249ff431aa95198ad6814dd1d2799883'] /* Select taxtype */,
3884            queryParam : 'query[taxtype_id]',
3885            selectOnFocus : true,
3886            tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{taxtype_name}</b> </div>',
3887            triggerAction : 'all',
3888            typeAhead : true,
3889            valueField : 'taxtype_id',
3890            width : 40,
3891            xns : Roo.form,
3892            '|xns' : 'Roo.form',
3893            xtype : 'ComboBox',
3894            store : {
3895             remoteSort : true,
3896             sortInfo : { direction : 'ASC', field: 'taxtype_name' },
3897             xns : Roo.data,
3898             '|xns' : 'Roo.data',
3899             xtype : 'Store',
3900             listeners : {
3901              beforeload : function (_self, o){
3902                   o.params = o.params || {};
3903                   // set more here
3904                   
3905                   
3906               }
3907             },
3908             proxy : {
3909              method : 'GET',
3910              url : baseURL + '/Roo/taxtype.php',
3911              xns : Roo.data,
3912              '|xns' : 'Roo.data',
3913              xtype : 'HttpProxy'
3914             },
3915             reader : {
3916              fields : [{"name":"taxtype_id","type":"int"},"taxtype_name"],
3917              id : 'taxtype_id',
3918              root : 'data',
3919              totalProperty : 'total',
3920              xns : Roo.data,
3921              '|xns' : 'Roo.data',
3922              xtype : 'JsonReader'
3923             }
3924            }
3925           }
3926          }
3927         },
3928         {
3929          align : 'right',
3930          dataIndex : 'avail_qty',
3931          header : _this._strings['7eb17faabef94701775df7154f30684b'] /* #avail */,
3932          renderer : function(v,x,r) { 
3933          
3934              var oq  = parseInt(r.data.coitem_qtyord);
3935              var aq = parseInt(r.data.avail_qty);
3936              var sq = parseInt(r.data.coitem_qtyshipped);
3937              aq = isNaN(aq) ? 0 : aq;
3938              oq = isNaN(oq) ? 0 : oq;
3939              sq = isNaN(sq) ? 0 : sq;
3940              
3941              var unshipped = oq - sq;
3942              
3943              if ( aq < 0 || (unshipped > 0  &&  aq < unshipped))  {
3944                 return String.format('<b style="color:red;">{0}</b>', parseInt(aq));
3945              }
3946               
3947              return String.format('{0}', aq); 
3948              
3949          },
3950          width : 50,
3951          xns : Roo.grid,
3952          '|xns' : 'Roo.grid',
3953          xtype : 'ColumnModel'
3954         },
3955         {
3956          align : 'right',
3957          builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
3958          dataIndex : 'shipitem_shipped',
3959          header : _this._strings['7ce96513eec175e6123b56573750b0dd'] /* #reserved */,
3960          renderer : function(v,x,r) { 
3961          
3962              
3963              var vv = parseInt(v);
3964              vv = isNaN(vv) ? 0 : vv;
3965              
3966              var ov = parseInt(r.data.coitem_qtyord);
3967              ov = isNaN(ov) ? 0 : ov;
3968              
3969              var qs = parseInt(r.data.coitem_qtyshipped);
3970              qs = isNaN(qs) ? 0 : qs;
3971              
3972              
3973              
3974              if (vv < ov) {
3975                  // not enough reserved yet.
3976                  return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv - qs);
3977              }
3978              
3979              return String.format('{0}', vv -  qs); 
3980              
3981          },
3982          width : 50,
3983          xns : Roo.grid,
3984          '|xns' : 'Roo.grid',
3985          xtype : 'ColumnModel'
3986         },
3987         {
3988          align : 'right',
3989          builderCfg : '{\"table\":\"coitem\",\"column\":\"coitem_qtyreserved\",\"columnshort\":\"coitem_qtyreserved\",\"ctype\":\"numeric\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"#reserved\"}',
3990          dataIndex : 'coitem_qtyshipped',
3991          header : _this._strings['6b15347cbd1bf352b547741a7525c1b4'] /* #shipped */,
3992          renderer : function(v,x,r) { 
3993              
3994              var vv = parseInt(v);
3995              vv = isNaN(vv) ? 0 : vv;
3996              
3997              var ov = parseInt(r.data.coitem_qtyord);
3998              ov = isNaN(ov) ? 0 : ov;
3999              
4000          
4001              if (vv != ov) {
4002                  // not enought shipped.
4003                  // or too many shipped.
4004                  return String.format('<b style="background-color:red;color:yellow">{0}</b>',  vv);
4005              }
4006          
4007              
4008              
4009              return String.format('{0}', vv); 
4010              
4011          },
4012          width : 50,
4013          xns : Roo.grid,
4014          '|xns' : 'Roo.grid',
4015          xtype : 'ColumnModel'
4016         },
4017         {
4018          align : 'right',
4019          dataIndex : 'cobill_billed',
4020          header : _this._strings['f3d90c6982143029487fb00d4ef19526'] /* #invoiced */,
4021          renderer : function(v,x,r) { 
4022              
4023              var vv = parseInt(v);
4024              vv = isNaN(vv) ? 0 : vv;
4025              
4026              var ov = parseInt(r.data.coitem_qtyord);
4027              ov = isNaN(ov) ? 0 : ov;
4028              
4029          
4030              if (vv !=ov) {
4031                      return String.format('<b style="background-color:red;color:yellow">{0}</b>', vv); 
4032              }
4033              return String.format('{0}', vv); 
4034              
4035          },
4036          width : 50,
4037          xns : Roo.grid,
4038          '|xns' : 'Roo.grid',
4039          xtype : 'ColumnModel'
4040         }
4041        ]
4042       }
4043      },
4044      {
4045       region : 'center',
4046       title : _this._strings['50104a28589c5b6099d3580861c2551a'] /* Shipments / Invoices */,
4047       xns : Roo,
4048       '|xns' : 'Roo',
4049       xtype : 'NestedLayoutPanel',
4050       listeners : {
4051        activate : function (_self)
4052         {
4053             _this.shipinvtab = _self;
4054         }
4055       },
4056       layout : {
4057        xns : Roo,
4058        '|xns' : 'Roo',
4059        xtype : 'BorderLayout',
4060        center : {
4061         titlebar : true,
4062         xns : Roo,
4063         '|xns' : 'Roo',
4064         xtype : 'LayoutRegion'
4065        },
4066        north : {
4067         height : 250,
4068         title : _this._strings['607ff05a0e4c02c54b2262cd2e381aff'] /* Reserve Stock / Shipments */,
4069         xns : Roo,
4070         '|xns' : 'Roo',
4071         xtype : 'LayoutRegion'
4072        },
4073        items  : [
4074         {
4075          background : false,
4076          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\"}',
4077          fitContainer : true,
4078          fitToframe : true,
4079          region : 'north',
4080          tableName : 'shiphead',
4081          title : _this._strings['f4757c5aca5e4410b63c6ec4cd0f2363'] /* shiphead */,
4082          xns : Roo,
4083          '|xns' : 'Roo',
4084          xtype : 'GridPanel',
4085          listeners : {
4086           activate : function() {
4087                _this.shippanel = this;
4088                if (_this.shipgrid) {
4089                    _this.shipgrid.ds.load({});
4090                }
4091            }
4092          },
4093          grid : {
4094           autoExpandColumn : 'shiphead_shipvia',
4095           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\"}',
4096           loadMask : true,
4097           xns : Roo.grid,
4098           '|xns' : 'Roo.grid',
4099           xtype : 'Grid',
4100           listeners : {
4101            render : function() 
4102             {
4103                 _this.shipgrid = this; 
4104                 //_this.dialog = Pman.Dialog.FILL_IN
4105                 if (_this.shippanel.active) {
4106                    this.ds.load({});
4107                 }
4108             },
4109            rowdblclick : function (_self, rowIndex, e)
4110             {
4111                 var rec = this.ds.getAt(rowIndex);
4112                 if (!rec.json.shiphead_shipdate.length) {
4113                      Roo.MessageBox.alert("Error", "You can not edit voided shipments, create a new one, and use the restore feature");
4114                      return;
4115                  }
4116             
4117                Pman.Dialog.XtupleShipment.show({
4118                     shiphead_id : rec.data.shiphead_id
4119             
4120                 }, function() {
4121                     _self.ds.load({});
4122                 
4123                 });
4124                
4125             }
4126           },
4127           toolbar : {
4128            xns : Roo,
4129            '|xns' : 'Roo',
4130            xtype : 'Toolbar',
4131            items  : [
4132             {
4133              cls : 'x-btn-text-icon',
4134              icon : rootURL + '/Pman/templates/images/lock.gif',
4135              text : _this._strings['813f81532d71077e497863ec9faf16c7'] /* Confirm Shipment */,
4136              xns : Roo.Toolbar,
4137              '|xns' : 'Roo.Toolbar',
4138              xtype : 'Button',
4139              listeners : {
4140               click : function()
4141                {
4142                     var sel  = _this.shipgrid.getSelectionModel().getSelected();
4143                    if (!sel) {
4144                        Roo.MessageBox.alert("Error", "Select a shipment");
4145                        return;
4146                    }
4147                    if (sel.data.shiphead_shipped) {
4148                        Roo.MessageBox.alert("Error", "Shipment is already confirmed");
4149                        return;
4150                    }
4151                    
4152                    
4153                    // check current status of shipment..
4154                    
4155                        
4156                    new Pman.Request({ 
4157                           mask : 'Sending',
4158                        url : baseURL + '/Roo/shiphead',
4159                        method : 'POST',
4160                        timeout : 90000,
4161                        params : {
4162                            shiphead_id : sel.data.shiphead_id,
4163                            _confirm : 1
4164                        },
4165                        success : function() {
4166                            _this.shipgrid.ds.load({});
4167                        }
4168                    });
4169                         
4170                     
4171                }
4172              }
4173             },
4174             {
4175              cls : 'x-btn-text-icon',
4176              icon : rootURL + '/Pman/templates/images/save.gif',
4177              text : _this._strings['70c6ddcd97af88d0aaac48268c459727'] /* Download (as xls) */,
4178              xns : Roo.Toolbar,
4179              '|xns' : 'Roo.Toolbar',
4180              xtype : 'Button',
4181              listeners : {
4182               click : function()
4183                {
4184                     var sel  = _this.shipgrid.getSelectionModel().getSelected();
4185                    if (!sel) {
4186                        Roo.MessageBox.alert("Error", "Select a shipment");
4187                        return;
4188                    }
4189                
4190                    
4191                    // check current status of shipment..
4192                    
4193                        
4194                   new Pman.Download({
4195                        url : baseURL + '/Roo/shiphead',
4196                        method : 'GET',
4197                        params : {
4198                           _download :sel.data.shiphead_id
4199                             
4200                        }
4201                    });
4202                         
4203                     
4204                }
4205              }
4206             },
4207             {
4208              cls : 'x-btn-text-icon',
4209              icon : rootURL + '/Pman/templates/images/pdf.gif',
4210              text : _this._strings['8c6aab77edc5b8e589b36bcf989683e4'] /* Print Picking Slip */,
4211              xns : Roo.Toolbar,
4212              '|xns' : 'Roo.Toolbar',
4213              xtype : 'Button',
4214              listeners : {
4215               click : function ()
4216                {
4217                    var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
4218                    if (!sel) {\r
4219                        Roo.MessageBox.alert("Error", "Select a shipment");\r
4220                        return;\r
4221                    }\r
4222                    // check current status of shipment..
4223                 
4224                        new Pman.Download({
4225                            url : baseURL + '/Xtuple/Print',
4226                            method : 'GET',
4227                            params : {
4228                                template : 'picking-slip',
4229                                param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
4230                                filename : 'picking-slip-' + sel.data.shiphead_number
4231                            },
4232                            success : function() {
4233                
4234                            }
4235                        })
4236                            
4237                            
4238                   
4239                }
4240              }
4241             },
4242             {
4243              cls : 'x-btn-text-icon',
4244              icon : rootURL + '/Pman/templates/images/pdf.gif',
4245              text : _this._strings['1b7132f58f9ee9de75e5778ff04f7303'] /* Print Delivery Note */,
4246              xns : Roo.Toolbar,
4247              '|xns' : 'Roo.Toolbar',
4248              xtype : 'Button',
4249              listeners : {
4250               click : function ()
4251                {
4252                    var sel  = _this.shipgrid.getSelectionModel().getSelected();\r
4253                    if (!sel) {\r
4254                        Roo.MessageBox.alert("Error", "Select a shipment");\r
4255                        return;\r
4256                    }\r
4257                    // check current status of shipment..
4258                
4259                        new Pman.Download({
4260                            url : baseURL + '/Xtuple/Print',
4261                            method : 'GET',
4262                            params : {
4263                                template : 'delivery-note-',
4264                                param : "shiphead_id:integer='" + sel.data.shiphead_id + "'",
4265                                filename : 'delivery-note-' + sel.data.shiphead_number
4266                            },
4267                            success : function() {
4268                
4269                            }
4270                        })
4271                            
4272                            
4273                   
4274                }
4275              }
4276             },
4277             {
4278              cls : 'x-btn-text-icon',
4279              icon : Roo.rootURL + 'images/default/dd/email.gif',
4280              text : _this._strings['62f0de97dd70387d493350e45bfa5583'] /* Send Delivery Email */,
4281              xns : Roo.Toolbar,
4282              '|xns' : 'Roo.Toolbar',
4283              xtype : 'Button',
4284              listeners : {
4285               click : function()
4286                {
4287                    var s = _this.shipgrid.getSelectionModel().getSelected();
4288                    
4289                    if(!s || s.data.shiphead_id * 1 < 1){
4290                        Roo.MessageBox.alert('Error', 'Please select a shipment');
4291                        return;
4292                    }
4293                    
4294                    new Pman.Request({
4295                        method: 'POST',
4296                        url: baseURL+ '/Roo/shiphead',
4297                        params : {
4298                            shiphead_id : s.data.shiphead_id,
4299                            _send_delivery : 1
4300                        },
4301                        success : function() {
4302                            Roo.MessageBox.alert('Notice', 'SENT');
4303                        }
4304                    });
4305                    
4306                }
4307              }
4308             },
4309             {
4310              xns : Roo.Toolbar,
4311              '|xns' : 'Roo.Toolbar',
4312              xtype : 'Fill'
4313             },
4314             {
4315              cls : 'x-btn-text-icon',
4316              icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
4317              text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
4318              xns : Roo.Toolbar,
4319              '|xns' : 'Roo.Toolbar',
4320              xtype : 'Button',
4321              listeners : {
4322               click : function()
4323                {   
4324                    if (!_this.form.findField('cohead_id').getValue()) {
4325                        Roo.MessageBox.alert("Error", "Save Order first");
4326                        return;
4327                    }
4328                    var rv = _this.form.getFieldValues();
4329                    
4330                    Pman.Dialog.XtupleShipmentNew.show({
4331                            shiphead_order_id : rv.cohead_id,
4332                            shiphead_shipdate :  _this.form.findField('cohead_targetdate').getValue().format('Y-m-d')
4333                        },
4334                        function() { 
4335                             _this.shipgrid.ds.load({});
4336                        }
4337                    );
4338                },
4339               render : function (_self)
4340                {
4341                  _this.addShipmentBtn = _self;
4342                }
4343              }
4344             },
4345             {
4346              cls : 'x-btn-text-icon',
4347              icon : rootURL + '/Pman/templates/images/trash.gif',
4348              text : _this._strings['9aa6071f39d387792476bd70fed66735'] /* Void / Unconfirm */,
4349              xns : Roo.Toolbar,
4350              '|xns' : 'Roo.Toolbar',
4351              xtype : 'Button',
4352              listeners : {
4353               click : function()
4354                {
4355                    var sel  = _this.shipgrid.getSelectionModel().getSelected();
4356                    if (!sel) {
4357                        Roo.MessageBox.alert("Error", "Select a shipment");
4358                        return;
4359                    }
4360                    // check current status of shipment..
4361                    
4362                    var msg = sel.data.shiphead_shipped ? 
4363                        "Are you sure you want to un-confirm that shipment? - It will remove items from unposted invoices" : 
4364                        "Are you sure you want to void that shipment?";
4365                    
4366                    Roo.MessageBox.confirm("Are you sure", msg,
4367                        function(r) {
4368                            if (r != 'yes') {
4369                                return;
4370                            }
4371                            new Pman.Request({
4372                                mask : 'Sending',
4373                                 timeout : 90000,
4374                                url : baseURL + '/Roo/shiphead',
4375                                method : 'POST',
4376                                
4377                                params : {
4378                                    shiphead_id : sel.data.shiphead_id,
4379                                    _void : 1
4380                                },
4381                                success : function() {
4382                                    _this.shipgrid.ds.load({});
4383                                }
4384                            })
4385                            
4386                        }
4387                    );
4388                            
4389                            
4390                    
4391                    
4392                    
4393                }
4394              }
4395             }
4396            ]
4397           },
4398           dataSource : {
4399            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\"}',
4400            remoteSort : true,
4401            sortInfo : { field : 'shiphead_shipvia', direction: 'ASC' },
4402            xns : Roo.data,
4403            '|xns' : 'Roo.data',
4404            xtype : 'Store',
4405            listeners : {
4406             beforeload : function (_self, options)
4407              {
4408                   options.params = options.params || {};
4409                   options.params.shiphead_order_id = _this.form.findField('cohead_id').getValue() * 1;
4410                  if (options.params.shiphead_order_id < 1) {
4411                      return false;
4412                  }
4413              }
4414            },
4415            proxy : {
4416             method : 'GET',
4417             url : baseURL + '/Roo/shiphead.php',
4418             xns : Roo.data,
4419             '|xns' : 'Roo.data',
4420             xtype : 'HttpProxy'
4421            },
4422            reader : {
4423             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\"}',
4424             fields : [
4425                 {
4426                     'name': 'shiphead_number',
4427                     'type': 'string'
4428                 },
4429                 {
4430                     'name': 'shiphead_shipvia',
4431                     'type': 'string'
4432                 },
4433                 {
4434                     'name': 'shiphead_shipdate',
4435                     'type': 'date'
4436                 },
4437                 {
4438                     'name': 'shiphead_sfstatus'
4439                 },
4440                 {
4441                     'name': 'shiphead_tracknum',
4442                     'type': 'string'
4443                 }
4444             ],
4445             id : 'id',
4446             root : 'data',
4447             totalProperty : 'total',
4448             xns : Roo.data,
4449             '|xns' : 'Roo.data',
4450             xtype : 'JsonReader'
4451            }
4452           },
4453           sm : {
4454            singleSelect : true,
4455            xns : Roo.grid,
4456            '|xns' : 'Roo.grid',
4457            xtype : 'RowSelectionModel'
4458           },
4459           colModel : [
4460            {
4461             builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_number\",\"columnshort\":\"shiphead_number\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
4462             dataIndex : 'shiphead_number',
4463             header : _this._strings['b1bc248a7ff2b2e95569f56de68615df'] /* number */,
4464             renderer : function(v,x,r) {
4465                 if (r.json.shiphead_shipdate.length) {
4466                      return String.format('{0}', v); 
4467                  }
4468                  return String.format('<s>{0}</s>', v); 
4469              },
4470             width : 80,
4471             xns : Roo.grid,
4472             '|xns' : 'Roo.grid',
4473             xtype : 'ColumnModel'
4474            },
4475            {
4476             dataIndex : 'shiphead_location_id_location_name',
4477             header : _this._strings['40e6e8652d174c7ceef48df46f9cf25a'] /* From Location */,
4478             renderer : function(v) { return String.format('{0}', v); },
4479             width : 100,
4480             xns : Roo.grid,
4481             '|xns' : 'Roo.grid',
4482             xtype : 'ColumnModel'
4483            },
4484            {
4485             dataIndex : 'shiphead_shipto_id_shipto_name',
4486             header : _this._strings['74002cb040b036511b8d031da591364a'] /* Ship to */,
4487             renderer : function(v) { return String.format('{0}', v); },
4488             width : 100,
4489             xns : Roo.grid,
4490             '|xns' : 'Roo.grid',
4491             xtype : 'ColumnModel'
4492            },
4493            {
4494             builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipdate\",\"columnshort\":\"shiphead_shipdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
4495             dataIndex : 'shiphead_shipdate',
4496             header : _this._strings['e963218370d6410e1ee0f8e6128c12d4'] /* shipdate */,
4497             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
4498             width : 75,
4499             xns : Roo.grid,
4500             '|xns' : 'Roo.grid',
4501             xtype : 'ColumnModel'
4502            },
4503            {
4504             builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_sfstatus\",\"columnshort\":\"shiphead_sfstatus\",\"ctype\":\"bpchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
4505             dataIndex : 'shiphead_sfstatus',
4506             header : _this._strings['ec53a8c4f07baed5d8825072c89799be'] /* Status */,
4507             renderer : function(v,x,r) { 
4508             
4509             
4510             
4511               
4512                 if (r.json.shiphead_shipdate.length) {
4513                 
4514                     if (r.json.shiphead_shipped) {
4515                         return "Confirmed";
4516                     }
4517                 
4518                      return '<span style="color:red">Draft</span>';
4519                 }
4520                  
4521                 return 'VOID';
4522                
4523             
4524             },
4525             width : 50,
4526             xns : Roo.grid,
4527             '|xns' : 'Roo.grid',
4528             xtype : 'ColumnModel'
4529            },
4530            {
4531             builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_shipvia\",\"columnshort\":\"shiphead_shipvia\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}',
4532             dataIndex : 'shiphead_shipvia',
4533             header : _this._strings['37656f0f6cf5e5befb1ec7abd3db5804'] /* shipvia */,
4534             renderer : function(v) { return String.format('{0}', v); },
4535             width : 200,
4536             xns : Roo.grid,
4537             '|xns' : 'Roo.grid',
4538             xtype : 'ColumnModel'
4539            },
4540            {
4541             builderCfg : '{\"table\":\"shiphead\",\"column\":\"shiphead_tracknum\",\"columnshort\":\"shiphead_tracknum\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
4542             dataIndex : 'shiphead_tracknum',
4543             header : _this._strings['58ec392a138714456f83d1288f553099'] /* tracknum */,
4544             renderer : function(v) { return String.format('{0}', v); },
4545             width : 200,
4546             xns : Roo.grid,
4547             '|xns' : 'Roo.grid',
4548             xtype : 'ColumnModel'
4549            }
4550           ]
4551          }
4552         },
4553         {
4554          background : false,
4555          fitContainer : true,
4556          fitToframe : true,
4557          region : 'center',
4558          tableName : 'cobmisc',
4559          title : _this._strings['fce9a6a1bd2a2050eb86d33103f46fd3'] /* Invoices */,
4560          xns : Roo,
4561          '|xns' : 'Roo',
4562          xtype : 'GridPanel',
4563          listeners : {
4564           activate : function() {
4565                _this.invpanel = this;
4566                if (_this.invgrid) {
4567                    _this.invgrid.ds.load({});
4568                }
4569            }
4570          },
4571          grid : {
4572           autoExpandColumn : 'invchead_invcnumber',
4573           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\"}',
4574           loadMask : true,
4575           xns : Roo.grid,
4576           '|xns' : 'Roo.grid',
4577           xtype : 'Grid',
4578           listeners : {
4579            render : function() 
4580             {
4581                 _this.invgrid = this; 
4582                 //_this.dialog = Pman.Dialog.FILL_IN
4583                 if (_this.invpanel.active) {
4584                    this.ds.load({});
4585                 }
4586             },
4587            rowdblclick : function (_self, rowIndex, e)
4588             {
4589             
4590                 var ri = this.ds.getAt(rowIndex);
4591                 if ( ri.data.cobmisc_id < 0) { // skip summary row..
4592                     return;
4593                 }
4594                 var rv = _this.form.getFieldValues();
4595                Pman.Dialog.XtupleInvoice.show({
4596                     cobmisc_id : ri.data.cobmisc_id,
4597                     // below parms for add credit memo
4598                     cmdata : {
4599                         cm_cust_id : rv.cohead_cust_id,
4600                         cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
4601                         cm_curr_id : rv.cohead_curr_id,
4602                         cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
4603                         cm_terms_id : rv.cohead_terms_id,
4604                         cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
4605                         cm_salesrep_id : rv.cohead_salesrep_id,
4606                         cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
4607                         cm_docdate : new Date(),
4608                         cm_taxzone_id : rv.cohead_taxzone_id,
4609                         cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
4610                         cm_billto_cntct_id : rv.cohead_billto_cntct_id,
4611                         cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
4612                         cm_location_src : rv.cohead_location_src,
4613                         cm_location_src_location_name : rv.cohead_location_src_location_name,
4614                         cm_billto_address : rv.billto_address
4615                     }
4616                 },
4617                     function() { 
4618                      _this.invgrid.ds.load({});
4619                 });
4620                
4621             }
4622           },
4623           toolbar : {
4624            xns : Roo,
4625            '|xns' : 'Roo',
4626            xtype : 'Toolbar',
4627            items  : [
4628             {
4629              cls : 'x-btn-text-icon',
4630              icon : rootURL + '/Pman/templates/images/lock.gif',
4631              text : _this._strings['b8feb9ee933bc5cc05615860322e9e7a'] /* Post Invoice */,
4632              xns : Roo.Toolbar,
4633              '|xns' : 'Roo.Toolbar',
4634              xtype : 'Button',
4635              listeners : {
4636               click : function ()
4637                {
4638                
4639                     var sel  = _this.invgrid.getSelectionModel().getSelected();
4640                    if (!sel) {
4641                        Roo.MessageBox.alert("Error", "Select a invoice");
4642                        return;
4643                    }
4644                    // check current status of shipment..
4645                    
4646                    Roo.MessageBox.confirm("Are you sure", "Are you sure you want to Post that invoice?",
4647                        function(r) {
4648                            if (r != 'yes') {
4649                                return;
4650                            }
4651                            new Pman.Request({
4652                               mask : 'Sending',
4653                                url : baseURL + '/Roo/cobmisc',
4654                                method : 'POST',
4655                                params : {
4656                                    cobmisc_id : sel.data.cobmisc_id,
4657                                    _post : 1
4658                                },
4659                                success : function() {
4660                                    _this.invgrid.ds.load({});
4661                                }
4662                            })
4663                            
4664                        }
4665                    );
4666                            
4667                            
4668                   
4669                }
4670              }
4671             },
4672             {
4673              cls : 'x-btn-text-icon',
4674              icon : rootURL + '/Pman/templates/images/pdf.gif',
4675              text : _this._strings['13dba24862cf9128167a59100e154c8d'] /* Print */,
4676              xns : Roo.Toolbar,
4677              '|xns' : 'Roo.Toolbar',
4678              xtype : 'Button',
4679              menu : {
4680               xns : Roo.menu,
4681               '|xns' : 'Roo.menu',
4682               xtype : 'Menu',
4683               items  : [
4684                {
4685                 text : _this._strings['f97f673be4e5f66aca62b35280d8bcde'] /* Print Standard Invoice */,
4686                 xns : Roo.menu,
4687                 '|xns' : 'Roo.menu',
4688                 xtype : 'Item',
4689                 listeners : {
4690                  click : function ()
4691                   {
4692                   
4693                        var sel  = _this.invgrid.getSelectionModel().getSelected();
4694                       if (!sel) {
4695                           Roo.MessageBox.alert("Error", "Select a invoice");
4696                           return;
4697                       }
4698                       if (!sel.data.cobmisc_invchead_id) {
4699                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4700                           return;
4701                       }
4702                       // check current status of shipment..
4703                   
4704                           new Pman.Download({
4705                               url : baseURL + '/Roo/invchead',
4706                               method : 'GET',
4707                               params : {
4708                                   invchead_id : sel.data.cobmisc_invchead_id,
4709                                   _print : 1
4710                               },
4711                               success : function() {
4712                   
4713                               }
4714                           })
4715                               
4716                               
4717                      
4718                   }
4719                 }
4720                },
4721                {
4722                 hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
4723                 text : _this._strings['0ee182201463a0ea31cb073b227fbbbe'] /* Print Chinese Invoice With GST in line item */,
4724                 xns : Roo.menu,
4725                 '|xns' : 'Roo.menu',
4726                 xtype : 'Item',
4727                 listeners : {
4728                  click : function (_self, e)
4729                   {
4730                   
4731                        var sel  = _this.invgrid.getSelectionModel().getSelected();
4732                       if (!sel) {
4733                           Roo.MessageBox.alert("Error", "Select a invoice");
4734                           return;
4735                       }
4736                       if (!sel.data.cobmisc_invchead_id) {
4737                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4738                           return;
4739                       }
4740                       // check current status of shipment..
4741                   
4742                           new Pman.Download({
4743                               url : baseURL + '/Roo/invchead',
4744                               method : 'GET',
4745                               params : {
4746                                   invchead_id : sel.data.cobmisc_invchead_id,
4747                                   _print : 'cn'
4748                                   
4749                               },
4750                               success : function() {
4751                   
4752                               }
4753                           })
4754                               
4755                             
4756                   }
4757                 }
4758                },
4759                {
4760                 hidden : !(baseURL.match(/(hk\.php|cn\.php)$/)),
4761                 text : _this._strings['6ac26fe4e9a39ac45fffe6d6920dac3a'] /* Print Chinese Invoice */,
4762                 xns : Roo.menu,
4763                 '|xns' : 'Roo.menu',
4764                 xtype : 'Item',
4765                 listeners : {
4766                  click : function (_self, e)
4767                   {
4768                   
4769                        var sel  = _this.invgrid.getSelectionModel().getSelected();
4770                       if (!sel) {
4771                           Roo.MessageBox.alert("Error", "Select a invoice");
4772                           return;
4773                       }
4774                       if (!sel.data.cobmisc_invchead_id) {
4775                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4776                           return;
4777                       }
4778                       // check current status of shipment..
4779                   
4780                           new Pman.Download({
4781                               url : baseURL + '/Roo/invchead',
4782                               method : 'GET',
4783                               params : {
4784                                   invchead_id : sel.data.cobmisc_invchead_id,
4785                                   _print : 'cn-gst'
4786                                   
4787                               },
4788                               success : function() {
4789                   
4790                               }
4791                           })
4792                               
4793                             
4794                   }
4795                 }
4796                },
4797                {
4798                 hidden : !(baseURL.match(/au\.php$/)),
4799                 text : _this._strings['69193f49683ba5a928ae8a27328105ba'] /* Print Aus - GST included Invoice */,
4800                 xns : Roo.menu,
4801                 '|xns' : 'Roo.menu',
4802                 xtype : 'Item',
4803                 listeners : {
4804                  click : function (_self, e)
4805                   {
4806                   
4807                        var sel  = _this.invgrid.getSelectionModel().getSelected();
4808                       if (!sel) {
4809                           Roo.MessageBox.alert("Error", "Select a invoice");
4810                           return;
4811                       }
4812                       if (!sel.data.cobmisc_invchead_id) {
4813                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4814                           return;
4815                       }
4816                       // check current status of shipment..
4817                   
4818                           new Pman.Download({
4819                               url : baseURL + '/Roo/invchead',
4820                               method : 'GET',
4821                               params : {
4822                                   invchead_id : sel.data.cobmisc_invchead_id,
4823                                   _print : 'au-gst'
4824                                   
4825                               },
4826                               success : function() {
4827                   
4828                               }
4829                           })
4830                               
4831                             
4832                   }
4833                 }
4834                },
4835                {
4836                 hidden : !(baseURL.match(/au\.php$/)),
4837                 text : _this._strings['3d96cc39e5517a284e203ffc8cafcf51'] /* Print Bambini Pronto Invoice */,
4838                 xns : Roo.menu,
4839                 '|xns' : 'Roo.menu',
4840                 xtype : 'Item',
4841                 listeners : {
4842                  click : function (_self, e)
4843                   {
4844                     var sel  = _this.invgrid.getSelectionModel().getSelected();
4845                       if (!sel) {
4846                           Roo.MessageBox.alert("Error", "Select a invoice");
4847                           return;
4848                       }
4849                       if (!sel.data.cobmisc_invchead_id) {
4850                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4851                           return;
4852                       }
4853                       // check current status of shipment..
4854                   
4855                           new Pman.Download({
4856                               url : baseURL + '/Roo/invchead',
4857                               method : 'GET',
4858                               params : {
4859                                   invchead_id : sel.data.cobmisc_invchead_id,
4860                   
4861                                   _print : 'au-net',
4862                                  ts: Math.random()
4863                               }
4864                           })
4865                   
4866                   
4867                   }
4868                 }
4869                },
4870                {
4871                 hidden : !(baseURL.match(/au\.php$/)),
4872                 text : _this._strings['c6b4fd215b0cdcb7426519edc0ece828'] /* Print Bambini Pro Forma Invoice */,
4873                 xns : Roo.menu,
4874                 '|xns' : 'Roo.menu',
4875                 xtype : 'Item',
4876                 listeners : {
4877                  click : function (_self, e)
4878                   {
4879                   
4880                        var sel  = _this.invgrid.getSelectionModel().getSelected();
4881                       if (!sel) {
4882                           Roo.MessageBox.alert("Error", "Select a invoice");
4883                           return;
4884                       }
4885                       if (!sel.data.cobmisc_invchead_id) {
4886                           Roo.MessageBox.alert("Error", "Invoice has not been posted");
4887                           return;
4888                       }
4889                       // check current status of shipment..
4890                   
4891                           new Pman.Download({
4892                               url : baseURL + '/Roo/invchead',
4893                               method : 'GET',
4894                               params : {
4895                                   invchead_id : sel.data.cobmisc_invchead_id,
4896                                   _print : 'au-proforma'
4897                                   
4898                               },
4899                               success : function() {
4900                   
4901                               }
4902                           })
4903                               
4904                             
4905                   }
4906                 }
4907                },
4908                {
4909                 hidden : !( baseURL.match(/au\.php$/)),
4910                 text : _this._strings['46fc12727bf2c5cc79988ab857ad73b4'] /* Print Shipping / Commercial Invoice */,
4911                 xns : Roo.menu,
4912                 '|xns' : 'Roo.menu',
4913                 xtype : 'Item',
4914                 listeners : {
4915                  click : function (_self, e)
4916                   {
4917                       var sel  = _this.invgrid.getSelectionModel().getSelected();
4918                       if (!sel) {
4919                           Roo.MessageBox.alert("Error", "Select a invoice");
4920                           return;
4921                       }
4922                       
4923                       Pman.Dialog.XtupleDiscountOfInvoice.show({invchead_id : sel.data.cobmisc_invchead_id}, function(){
4924                   
4925                       });
4926                   }
4927                 }
4928                }
4929               ]
4930              }
4931             },
4932             {
4933              cls : 'x-btn-text-icon',
4934              icon : Roo.rootURL + 'images/default/tree/leaf.gif',
4935              text : _this._strings['d682c376c82f68bc65dcd05570d04dfc'] /* Payments / Refunds / Credit Memos */,
4936              xns : Roo.Toolbar,
4937              '|xns' : 'Roo.Toolbar',
4938              xtype : 'Button',
4939              menu : {
4940               xns : Roo.menu,
4941               '|xns' : 'Roo.menu',
4942               xtype : 'Menu',
4943               items  : [
4944                {
4945                 cls : 'x-btn-text-icon',
4946                 icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
4947                 text : _this._strings['01d35df7886d24900b1ecb65da6bf21d'] /* Receive Payment */,
4948                 xns : Roo.menu,
4949                 '|xns' : 'Roo.menu',
4950                 xtype : 'Item',
4951                 listeners : {
4952                  click : function(_self,e)
4953                       {
4954                       
4955                       var sel  = _this.invgrid.getSelectionModel().getSelected();
4956                       if (!sel || sel.data.cobmisc_id < 1) {
4957                           Roo.MessageBox.alert("Error", "Select a invoice");
4958                           return;
4959                       }
4960                       if(!sel.data.cobmisc_posted){
4961                           Roo.MessageBox.alert("Error", "This invoice has not been posted!");
4962                           return;
4963                       }
4964                       if(sel.data.cobmisc_outstanding == 0){
4965                           Roo.MessageBox.alert("Error", "There is no any outstanding of this invoice!");
4966                           return;
4967                       }
4968                       
4969                       var cust_id = _this.form.findField('cohead_cust_id').getValue();
4970                       if(!cust_id){
4971                           return;
4972                       }
4973                       var data = {
4974                           cashrcpt_amount : sel.data.cobmisc_outstanding,
4975                           cashrcpt_cust_id : cust_id,
4976                           cashrcpt_aropen_id : sel.data.cobmisc_aropen_id_aropen_id,
4977                           cashrcpt_distdate : new Date(),
4978                           cashrcpt_fundstype : 'C',
4979                           cashrcpt_curr_id : sel.data.cobmisc_curr_id_curr_id,
4980                           cashrcpt_curr_id_curr_name : sel.data.cobmisc_curr_id_curr_name,
4981                           cashrcpt_usecustdeposit : true,
4982                           cashrcpt_docdate : new Date(),
4983                           cashrcpt_salescat_id : -1,
4984                           cashrcpt_applydate : new Date(),
4985                           cashrcpt_discount : 0
4986                       };
4987                       Pman.Dialog.XtupleReceivePayment.show( data , function() {
4988                           _this.invgrid.ds.load({});
4989                       }); 
4990                   }
4991                 }
4992                },
4993                {
4994                 cls : 'x-btn-text-icon',
4995                 icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
4996                 text : _this._strings['526db6366257755024ed2556000871bc'] /* Issue Refund */,
4997                 xns : Roo.menu,
4998                 '|xns' : 'Roo.menu',
4999                 xtype : 'Item',
5000                 listeners : {
5001                  click : function(_self,e)
5002                   {
5003                       var sel  = _this.invgrid.getSelectionModel().getSelected();
5004                       if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
5005                           Roo.MessageBox.alert("Error", "Select a credit memo");
5006                           return;
5007                       }
5008                       if(!sel.data.cobmisc_posted){
5009                           Roo.MessageBox.alert("Error", "The invoice that credit memo has been applied to has been not posted");
5010                           return;
5011                       }
5012                       var cust_id = _this.form.findField('cohead_cust_id').getValue();
5013                       if(!cust_id){
5014                           return;
5015                       }
5016                       
5017                       if(!sel.data.cobmisc_outstanding || sel.data.cobmisc_outstanding == 0){
5018                           Roo.MessageBox.alert("Error", "The amount of this credit memo is 0!");
5019                           return;
5020                       }
5021                       
5022                       var d = _this.form.getFieldValues();
5023                       
5024                       var data = {
5025                           'checkhead_recip_id' : cust_id,
5026                           'checkhead_recip_type' : 'C',
5027                           'checkhead_checkdate' : new Date(),
5028                           'checkhead_amount' : sel.data.cobmisc_outstanding,
5029                           'remaining_total' : sel.data.cobmisc_outstanding,
5030                           'checkhead_curr_id' : d.cohead_curr_id,
5031                           'checkhead_curr_id_curr_name' : d.cohead_curr_id_curr_name,
5032                           'checkhead_misc' : true,
5033                           'aropen_id' : sel.data.cobmisc_cobapply_aropen_id,
5034                         'cmhead_number' : sel.data.cobmisc_invchead_id_invchead_invcnumber,
5035                         'cust_name' : d.cohead_cust_id_cust_name,
5036                         '_create_and_post' : 1
5037                   
5038                       };
5039                       
5040                       
5041                       Pman.Dialog.XtupleMiscellaneousCheck.show( data , function() {
5042                           _this.invgrid.ds.load({});
5043                      }); 
5044                   }
5045                 }
5046                },
5047                {
5048                 xns : Roo.menu,
5049                 '|xns' : 'Roo.menu',
5050                 xtype : 'Separator'
5051                },
5052                {
5053                 cls : 'x-btn-text-icon',
5054                 icon : rootURL + '/Pman/templates/images/trash.gif',
5055                 text : _this._strings['2142511303396bd51e0cc25ea8ffe47f'] /* Void Payment */,
5056                 xns : Roo.menu,
5057                 '|xns' : 'Roo.menu',
5058                 xtype : 'Item',
5059                 listeners : {
5060                  click : function(_self,e)
5061                   {
5062                       var sel  = _this.invgrid.getSelectionModel().getSelected();
5063                       if (!sel || sel.data.cobmisc_cashrcpt_id * 1 < 1) {
5064                           Roo.MessageBox.alert("Error", "Select a Receive Payment");
5065                           return;
5066                       }
5067                       
5068                       Roo.MessageBox.confirm("Confirm", "Voiding receipt will mean you will have to re-enter the receipt refund - " + 
5069                                       "please take note of the details so you can enter it again correctly later.", function(r) {
5070                                               
5071                           if (r !='yes') {
5072                               return;
5073                           }
5074                           new Pman.Request({
5075                               url : baseURL + '/Roo/cashrcpt',
5076                               method : 'POST',
5077                               params : {
5078                                   cashrcpt_id : sel.data.cobmisc_cashrcpt_id,
5079                                   _void : 1
5080                               },
5081                               success : function() 
5082                               {
5083                                   _this.invgrid.ds.load({});
5084                               
5085                               }
5086                           });
5087                       
5088                      })
5089                       
5090                        
5091                   }
5092                 }
5093                },
5094                {
5095                 cls : 'x-btn-text-icon',
5096                 icon : rootURL + '/Pman/templates/images/trash.gif',
5097                 text : _this._strings['052fbb9431206b4755090dc53fcef300'] /* Void Refund */,
5098                 xns : Roo.menu,
5099                 '|xns' : 'Roo.menu',
5100                 xtype : 'Item',
5101                 listeners : {
5102                  click : function(_self,e)
5103                   {
5104                       var sel  = _this.invgrid.getSelectionModel().getSelected();
5105                       if (!sel || sel.data.cobmisc_checkhead_id * 1 < 1) {
5106                           Roo.MessageBox.alert("Error", "Select a Miscellaneours Check");
5107                           return;
5108                       }
5109                       
5110                       Roo.MessageBox.confirm("Confirm", "Voiding refund will mean you will have to re-enter the receipt refund - " + 
5111                                       "please take note of the details so you can enter it again correctly later.", function(r) {
5112                                               
5113                           if (r !='yes') {
5114                               return;
5115                           }
5116                           new Pman.Request({
5117                               url : baseURL + '/Roo/checkhead',
5118                               method : 'POST',
5119                               params : {
5120                                   checkhead_id : sel.data.cobmisc_checkhead_id,
5121                                   _voidPosted : 1
5122                               },
5123                               success : function() 
5124                               {
5125                                   _this.invgrid.ds.load({});
5126                               
5127                               }
5128                           });
5129                       
5130                      })
5131                       
5132                        
5133                   }
5134                 }
5135                },
5136                {
5137                 cls : 'x-btn-text-icon',
5138                 icon : rootURL + '/Pman/templates/images/trash.gif',
5139                 text : _this._strings['4b5a5a93e13bd338d40cf4bae2ca51cb'] /* Void Credit Memo */,
5140                 xns : Roo.menu,
5141                 '|xns' : 'Roo.menu',
5142                 xtype : 'Item',
5143                 listeners : {
5144                  click : function(_self,e)
5145                   {
5146                       var sel  = _this.invgrid.getSelectionModel().getSelected();
5147                       if (!sel || sel.data.cobmisc_cobapply_aropen_id < 1) {
5148                           Roo.MessageBox.alert("Error", "Select a credit memo");
5149                           return;
5150                       }
5151                       
5152                       if(sel.data.cobmisc_posted){
5153                           Roo.MessageBox.alert("Error", "You cann't void this credit memo, since the invoice that credit memo has been applied to has been posted");
5154                           return;
5155                       }
5156                       
5157                       if (sel.data.cobmisc_cobapply_id < 1) {
5158                           Roo.MessageBox.alert("Error", "invaild credit memo");
5159                           return;
5160                       }
5161                       Roo.MessageBox.confirm("Confirm", "Are you sure want to void this applied credit memo, " + 
5162                                   "it will also void all the check that belongs to this credit memo ", function(r) {
5163                                               
5164                           if (r !='yes') {
5165                               return;
5166                           }
5167                           new Pman.Request({
5168                               url : baseURL + '/Roo/cobapply',
5169                               method : 'POST',
5170                               params : {
5171                                   _delete : sel.data.cobmisc_cobapply_id,
5172                                   _void : 1
5173                               },
5174                               success : function() 
5175                               {
5176                                   _this.invgrid.ds.load({});
5177                               
5178                               }
5179                           });
5180                       
5181                      })
5182                        
5183                   }
5184                 }
5185                }
5186               ]
5187              }
5188             },
5189             {
5190              xns : Roo.Toolbar,
5191              '|xns' : 'Roo.Toolbar',
5192              xtype : 'Fill'
5193             },
5194             {
5195              cls : 'x-btn-text-icon',
5196              icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
5197              text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
5198              xns : Roo.Toolbar,
5199              '|xns' : 'Roo.Toolbar',
5200              xtype : 'Button',
5201              listeners : {
5202               click : function ()
5203                {
5204                
5205                    if (!_this.form.findField('cohead_id').getValue()) {
5206                        Roo.MessageBox.alert("Error", "Save Order first");
5207                        return;
5208                    }
5209                    
5210                    var rv = _this.form.getFieldValues();
5211                    
5212                   
5213                   Pman.Dialog.XtupleInvoice.show({
5214                        cobmisc_cohead_id : rv.cohead_id,
5215                        cobmisc_shipdate :  _this.form.findField('cohead_targetdate').getValue(),
5216                        cobmisc_invcdate :  _this.form.findField('cohead_targetdate').getValue(),
5217                        cobmisc_curr_id : rv.cohead_curr_id,
5218                        cobmisc_curr_id_curr_name : rv.cohead_curr_id_curr_name,
5219                        // below parms for add credit memo
5220                        cmdata : {
5221                            cm_cust_id : rv.cohead_cust_id,
5222                            cm_cust_id_cust_name : rv.cohead_cust_id_cust_name,
5223                            cm_curr_id : rv.cohead_curr_id,
5224                            cm_curr_id_curr_name : rv.cohead_curr_id_curr_name,
5225                            cm_terms_id : rv.cohead_terms_id,
5226                            cm_terms_id_terms_descrip : rv.cohead_terms_id_terms_descrip,
5227                            cm_salesrep_id : rv.cohead_salesrep_id,
5228                            cm_salesrep_id_salesrep_name : rv.cohead_salesrep_id_salesrep_name,
5229                            cm_docdate : new Date(),
5230                            cm_taxzone_id : rv.cohead_taxzone_id,
5231                            cm_taxzone_id_taxzone_descrip : rv.cohead_taxzone_id_taxzone_descrip,
5232                            cm_billto_cntct_id : rv.cohead_billto_cntct_id,
5233                            cm_billto_cntct_id_cntct_name : rv.cohead_billto_cntct_id_cntct_name,
5234                            cm_location_src : rv.cohead_location_src,
5235                            cm_location_src_location_name : rv.cohead_location_src_location_name,
5236                            cm_billto_address : rv.billto_address
5237                        }
5238                        
5239                    },
5240                        function() { 
5241                         _this.invgrid.ds.load({});
5242                    });
5243                   
5244                },
5245               render : function (_self)
5246                {
5247                  _this.addInvoiceBtn = _self;
5248                }
5249              }
5250             },
5251             {
5252              cls : 'x-btn-text-icon',
5253              icon : rootURL + '/Pman/templates/images/trash.gif',
5254              text : _this._strings['b25f6c965342495f74899e183efe20a4'] /* Void / Unpost */,
5255              xns : Roo.Toolbar,
5256              '|xns' : 'Roo.Toolbar',
5257              xtype : 'Button',
5258              listeners : {
5259               click : function ()
5260                {
5261                
5262                     var sel  = _this.invgrid.getSelectionModel().getSelected();
5263                    if (!sel) {
5264                        Roo.MessageBox.alert("Error", "Select a invoice");
5265                        return;
5266                    }
5267                    // check current status of shipment..
5268                    
5269                    var params =  {
5270                //        cobmisc_id : sel.data.cobmisc_id,
5271                        _void : 1
5272                    };
5273                    if (sel.data.cobmisc_id * 1) {
5274                        params.cobmisc_id = sel.data.cobmisc_id * 1 ;
5275                    }
5276                    if (sel.data.cobmisc_invchead_id_invchead_id * 1) {    
5277                        params.invchead_id  =  sel.data.cobmisc_invchead_id_invchead_id * 1;
5278                    }
5279                    
5280                    Roo.MessageBox.confirm("Are you sure", "Are you sure you want to VOID that invoice?",
5281                        function(r) {
5282                            if (r != 'yes') {
5283                                return;
5284                            }
5285                            new Pman.Request({
5286                                mask : 'Sending',
5287                                url : baseURL + '/Roo/cobmisc',
5288                                method : 'POST',
5289                                params :  params,
5290                                success : function() {
5291                                    _this.invgrid.ds.load({});
5292                                }
5293                            })
5294                            
5295                        }
5296                    );
5297                            
5298                            
5299                   
5300                }
5301              }
5302             }
5303            ]
5304           },
5305           dataSource : {
5306            remoteSort : true,
5307            sortInfo : { field : 'invchead_invcnumber', direction: 'ASC' },
5308            xns : Roo.data,
5309            '|xns' : 'Roo.data',
5310            xtype : 'Store',
5311            listeners : {
5312             beforeload : function (_self, options)
5313              {
5314              
5315                  options.params = options.params || {};
5316                  options.params.cobmisc_cohead_id = _this.form.findField('cohead_id').getValue() * 1;
5317                  if (options.params.cobmisc_cohead_id < 1) {
5318                      return false;
5319                  }
5320                  
5321                  options.params._with_other_payment = 1;
5322                  //options.params['query[invchead_ordernumber]']  = _this.form.findField('cohead_number').getValue()
5323                  
5324              },
5325             load : function (_self, records, options)
5326              {
5327                  var total = 0;
5328                  var done = 0;
5329                  var totalic = 0.0;
5330                  var totalfreight = 0.0;    
5331                  var totalmisc = 0.0;        
5332                  var totaltax = 0.0;        
5333                 
5334                  Roo.each(records, function(r)
5335                  {
5336                      if(r.data.cobmisc_id > 1){
5337                          done += parseInt(r.data.cobmisc_qty);
5338                          totalic += parseFloat(r.data.cobmisc_itemcost).toFixed(2)*1;        
5339                          totalmisc += parseFloat(r.data.cobmisc_misc).toFixed(2)*1;        
5340                          totalfreight += parseFloat(r.data.cobmisc_freight).toFixed(2)*1;                
5341                          totaltax += parseFloat(r.data.cobmisc_tax).toFixed(2)*1;                
5342                          total = parseInt(r.data.cobmisc_total_qty);
5343                      }
5344                     
5345                  });
5346                  
5347                  _this.shipinvtab.layout.getRegion('center').getPanel(0).setTitle(
5348                      (total == done) ?
5349                           "Invoices (Complete)" : 
5350                          ("Invoices prepared for " +    done + '/' + total)
5351                  );
5352              
5353                  
5354                  var frtotal = (parseFloat(_this.form.findField('cohead_freight').getValue())  - totalfreight).toFixed(2);
5355                  var misctotal = (parseFloat(_this.form.findField('cohead_misc').getValue()) - totalmisc).toFixed(2);
5356                  var ictotal =  (parseFloat(_this.form.findField('cohead_subtotal').getValue()) - totalic).toFixed(2);
5357                  var taxtotal =  (parseFloat(_this.form.findField('cohead_tax').getValue())  - totaltax).toFixed(2);
5358                  var remtotal = frtotal*1 + misctotal*1 + ictotal*1 + taxtotal*1;
5359                  
5360                  var nr = this.reader.newRow({
5361                      cobmisc_id : -1,
5362                      cobmisc_invchead_id_invchead_invcnumber : "Total Remaining",
5363                      cobmisc_qty : total - done,
5364                      cobmisc_freight :frtotal,
5365                      cobmisc_misc : misctotal,        
5366                      cobmisc_itemcost  : ictotal,             
5367                      cobmisc_tax : taxtotal,
5368                      cobmisc_total : remtotal
5369              
5370                      
5371                  });
5372                  // do we need to add it somehow??
5373                  _this.invgrid.ds.add(nr);
5374              }
5375            },
5376            proxy : {
5377             method : 'GET',
5378             url : baseURL + '/Roo/cobmisc.php',
5379             xns : Roo.data,
5380             '|xns' : 'Roo.data',
5381             xtype : 'HttpProxy'
5382            },
5383            reader : {
5384             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\"}',
5385             fields : [
5386                 {
5387                     'name': 'invchead_invcnumber',
5388                     'type': 'string'
5389                 },
5390                 {
5391                     'name': 'invchead_invcdate',
5392                     'type': 'date'
5393                 }
5394             ],
5395             id : 'id',
5396             root : 'data',
5397             totalProperty : 'total',
5398             xns : Roo.data,
5399             '|xns' : 'Roo.data',
5400             xtype : 'JsonReader'
5401            }
5402           },
5403           colModel : [
5404            {
5405             dataIndex : 'cobmisc_invchead_id_invchead_invcnumber',
5406             header : _this._strings['42f6d99a2dddc4858882ed8e9a210b52'] /* Invoice # */,
5407             renderer : function(v,x,r) { 
5408                    if (v && 
5409                          r.data.cobmisc_invchead_id_invchead_id * 1 && 
5410                         !r.data.cobmisc_invchead_id_invchead_posted) {
5411                        return  '<span style="color:red">' + 
5412                             "NEEDS Voiding then re-posted: " + 
5413                             String.format('{0}', v) +
5414                             '</span>'; 
5415                    }
5416             
5417                    if(v && r.data.cobmisc_id == -2){
5418                         return String.format('<span style="margin-left: 10px;"> - {0} (Credit Memo)</span>', v); 
5419                    }
5420                    if(v && r.data.cobmisc_id == -3){
5421                         return String.format('<span style="margin-left: 20px;"> - {0} (Miscellaneous Check)</span>', v); 
5422                    }
5423                   if(v && r.data.cobmisc_id == -4){
5424                         return String.format('<span style="margin-left: 10px;"> - {0} (Receive Payment to {2}) [ {1} ]</span>', 
5425                                 v, r.data.cobmisc_cashrcpt_amount, r.json.cashrcpt_bankaccnt_id_bankaccnt_bankname); 
5426                    }
5427                    
5428                     return v ? String.format('{0}', v) : 
5429                             '<span style="color:red">' + "Not Posted" + '</span>'; 
5430             },
5431             width : 100,
5432             xns : Roo.grid,
5433             '|xns' : 'Roo.grid',
5434             xtype : 'ColumnModel'
5435            },
5436            {
5437             builderCfg : '{\"table\":\"invchead\",\"column\":\"invchead_invcdate\",\"columnshort\":\"invchead_invcdate\",\"ctype\":\"date\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
5438             dataIndex : 'cobmisc_invcdate',
5439             header : _this._strings['3a6a3353e3b44ad5359c8e3178b66a54'] /* invcdate */,
5440             renderer : function(v,x,r) { 
5441                 
5442                 return String.format('{0}', v && v.format ? v.format('d/M/Y') : ''); 
5443             },
5444             width : 75,
5445             xns : Roo.grid,
5446             '|xns' : 'Roo.grid',
5447             xtype : 'ColumnModel'
5448            },
5449            {
5450             align : 'right',
5451             dataIndex : 'cobmisc_qty',
5452             header : _this._strings['03ab340b3f99e03cff9e84314ead38c0'] /* Qty */,
5453             renderer : function(v) { return String.format('{0}', v ? parseInt(v) : 0); },
5454             width : 50,
5455             xns : Roo.grid,
5456             '|xns' : 'Roo.grid',
5457             xtype : 'ColumnModel'
5458            },
5459            {
5460             align : 'right',
5461             dataIndex : 'cobmisc_itemcost',
5462             header : _this._strings['757989a16207ab23076685118640adf3'] /* Item Cost */,
5463             renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : 0); },
5464             width : 75,
5465             xns : Roo.grid,
5466             '|xns' : 'Roo.grid',
5467             xtype : 'ColumnModel'
5468            },
5469            {
5470             align : 'right',
5471             dataIndex : 'cobmisc_freight',
5472             header : _this._strings['ea9cf7e47ff33b2be14e6dd07cbcefc6'] /* Shipping */,
5473             renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2)  : ''); },
5474             width : 75,
5475             xns : Roo.grid,
5476             '|xns' : 'Roo.grid',
5477             xtype : 'ColumnModel'
5478            },
5479            {
5480             align : 'right',
5481             dataIndex : 'cobmisc_tax',
5482             header : _this._strings['4b78ac8eb158840e9638a3aeb26c4a9d'] /* Tax */,
5483             renderer : function(v,x,r) { 
5484             
5485                 // tax is based on the % itemcost..
5486             //    var ic  = r.data.cobmisc_itemcost;
5487                 /*
5488                 var ic  =r.data.cobmisc_itemcost - (1* r.data.cobmisc_itemcost_taxfree);
5489                 
5490                 var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
5491                 var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
5492                 if (tax < 0.1) {
5493                     return '';
5494                 }
5495                 var taxp = tax / totic;
5496                 var lv = taxp * ic;
5497                 */
5498                 return String.format('{0}', (1.0*v).toFixed(2) );
5499                 
5500                 
5501              },
5502             width : 75,
5503             xns : Roo.grid,
5504             '|xns' : 'Roo.grid',
5505             xtype : 'ColumnModel'
5506            },
5507            {
5508             align : 'right',
5509             dataIndex : 'cobmisc_cohead_id_cohead_pretax_discount',
5510             header : _this._strings['a763436d2b30d54e4aff264b1636827a'] /* Discount (Pretax) */,
5511             renderer : function(v) { return String.format('{0}', v ? (1.0*v).toFixed(2) : 0); },
5512             width : 100,
5513             xns : Roo.grid,
5514             '|xns' : 'Roo.grid',
5515             xtype : 'ColumnModel'
5516            },
5517            {
5518             align : 'right',
5519             dataIndex : 'cobmisc_misc',
5520             header : _this._strings['bb4af85913879b95661b81570a2c2e83'] /* Discount (Posttax) */,
5521             renderer : function(v,x,r) 
5522             {
5523                 var vv = v - r.data.cobmisc_cohead_id_cohead_pretax_discount;
5524                 
5525                 return String.format('{0}', vv ? (1.0*vv).toFixed(2) : 0); 
5526             },
5527             width : 100,
5528             xns : Roo.grid,
5529             '|xns' : 'Roo.grid',
5530             xtype : 'ColumnModel'
5531            },
5532            {
5533             align : 'right',
5534             dataIndex : 'cobmisc_total',
5535             header : _this._strings['09466661df2abefeecf849e52fce8fb4'] /* Total  */,
5536             renderer : function(v,x,r) { 
5537             
5538             /*    
5539                 var ic  = r.data.cobmisc_itemcost;
5540                 var tax= _this.form.findField('cohead_tax').getValue() * 1.0;
5541                 var totic = _this.form.findField('cohead_subtotal').getValue() * 1.0;    
5542                 var     lv = 0.0;
5543                 if (tax > 0.0) {
5544                     var taxp = tax / totic;
5545                     lv = taxp * ic;
5546             
5547                 }
5548               */  
5549               
5550             
5551                 if(v){
5552                     return String.format('{0}',(v * 1.0).toFixed(2) );
5553                 }
5554                 var d= r.data;
5555             
5556                 return String.format('{0}',
5557                    ((d.cobmisc_itemcost * 1.0) + 
5558                    (d.cobmisc_freight * 1.0) + 
5559                    (d.cobmisc_tax * 1.0) +
5560                    (d.cobmisc_misc * 1.0)  
5561             
5562                    ).toFixed(2) );
5563             },
5564             width : 75,
5565             xns : Roo.grid,
5566             '|xns' : 'Roo.grid',
5567             xtype : 'ColumnModel'
5568            },
5569            {
5570             align : 'right',
5571             dataIndex : 'cobmisc_outstanding',
5572             header : _this._strings['a860ed9926b241b7d4dca2d00610ab2c'] /* Outstanding */,
5573             renderer : function(v,x,r) 
5574             { 
5575                 
5576                 return String.format('{0}', v ? (v * 1.0).toFixed(2) : 0 );
5577             },
5578             width : 75,
5579             xns : Roo.grid,
5580             '|xns' : 'Roo.grid',
5581             xtype : 'ColumnModel'
5582            }
5583           ]
5584          }
5585         }
5586        ]
5587       }
5588      },
5589      {
5590       background : true,
5591       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\"}',
5592       fitContainer : true,
5593       fitToframe : true,
5594       region : 'center',
5595       tableName : 'events',
5596       title : _this._strings['16d2b386b2034b9488996466aaae0b57'] /* History */,
5597       xns : Roo,
5598       '|xns' : 'Roo',
5599       xtype : 'GridPanel',
5600       listeners : {
5601        activate : function() {
5602             _this.hpanel = this;
5603             if (_this.hgrid) {
5604                 _this.hgrid.footer.onClick('first');
5605             }
5606         }
5607       },
5608       grid : {
5609        autoExpandColumn : 'remarks',
5610        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\"}',
5611        loadMask : true,
5612        xns : Roo.grid,
5613        '|xns' : 'Roo.grid',
5614        xtype : 'Grid',
5615        listeners : {
5616         render : function() 
5617          {
5618              _this.hgrid = this; 
5619              //_this.dialog = Pman.Dialog.FILL_IN
5620              if (_this.hpanel.active) {
5621                 this.footer.onClick('first');
5622              }
5623          },
5624         rowdblclick : function (_self, rowIndex, e)
5625          {
5626              if (!_this.dialog) return;
5627              _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
5628                  _this.grid.footer.onClick('first');
5629              }); 
5630          }
5631        },
5632        footer : {
5633         displayInfo : true,
5634         displayMsg : _this._strings['089ba2b5edc96565fc22c584ecfbb1a6'] /* Displaying events{0} - {1} of {2} */,
5635         emptyMsg : _this._strings['594f5bdc5e1519ce9934d276e5bf081f'] /* No events found */,
5636         pageSize : 25,
5637         xns : Roo,
5638         '|xns' : 'Roo',
5639         xtype : 'PagingToolbar'
5640        },
5641        dataSource : {
5642         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\"}',
5643         remoteSort : true,
5644         sortInfo : { field : 'event_when', direction: 'DESC' },
5645         xns : Roo.data,
5646         '|xns' : 'Roo.data',
5647         xtype : 'Store',
5648         listeners : {
5649          beforeload : function (_self, options)
5650           {
5651               options.params._related_on_table = 'cohead';
5652               options.params._related_on_id = _this.form.findField('cohead_id').getValue();
5653           }
5654         },
5655         proxy : {
5656          method : 'GET',
5657          url : baseURL + '/Roo/events.php',
5658          xns : Roo.data,
5659          '|xns' : 'Roo.data',
5660          xtype : 'HttpProxy'
5661         },
5662         reader : {
5663          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\"}',
5664          fields : [
5665              {
5666                  'name': 'event_when',
5667                  'type': 'date'
5668              },
5669              {
5670                  'name': 'action',
5671                  'type': 'string'
5672              },
5673              {
5674                  'name': 'ipaddr',
5675                  'type': 'string'
5676              },
5677              {
5678                  'name': 'person_id_name',
5679                  'type': 'string'
5680              },
5681              {
5682                  'name': 'remarks',
5683                  'type': 'string'
5684              }
5685          ],
5686          id : 'id',
5687          root : 'data',
5688          totalProperty : 'total',
5689          xns : Roo.data,
5690          '|xns' : 'Roo.data',
5691          xtype : 'JsonReader'
5692         }
5693        },
5694        colModel : [
5695         {
5696          builderCfg : '{\"table\":\"events\",\"column\":\"event_when\",\"columnshort\":\"event_when\",\"ctype\":\"timestamp\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
5697          dataIndex : 'event_when',
5698          header : _this._strings['820dbd2b8f606aff866c0bbfb6b737c1'] /* Changed */,
5699          renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
5700          width : 120,
5701          xns : Roo.grid,
5702          '|xns' : 'Roo.grid',
5703          xtype : 'ColumnModel'
5704         },
5705         {
5706          builderCfg : '{\"table\":\"events\",\"column\":\"action\",\"columnshort\":\"action\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
5707          dataIndex : 'action',
5708          header : _this._strings['418c5509e2171d55b0aee5c2ea4442b5'] /* action */,
5709          renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
5710          width : 120,
5711          xns : Roo.grid,
5712          '|xns' : 'Roo.grid',
5713          xtype : 'ColumnModel'
5714         },
5715         {
5716          builderCfg : '{\"table\":\"events\",\"column\":\"ipaddr\",\"columnshort\":\"ipaddr\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
5717          dataIndex : 'ipaddr',
5718          header : _this._strings['75ba8d70e3692ba200f0e0df37b4d2ae'] /* IP address */,
5719          renderer : function(v) { return String.format('{0}', v); },
5720          width : 120,
5721          xns : Roo.grid,
5722          '|xns' : 'Roo.grid',
5723          xtype : 'ColumnModel'
5724         },
5725         {
5726          builderCfg : '{\"table\":\"person\",\"column\":\"person_id_name\",\"columnshort\":\"name\",\"ctype\":\"varchar\",\"desc\":\"\",\"use\":1,\"use_ex\":\"\",\"title\":\"\"}',
5727          dataIndex : 'person_id_name',
5728          header : _this._strings['4ee972120bcda675f75222c87cb9d356'] /* Who */,
5729          renderer : function(v) { return String.format('{0}', v); },
5730          width : 120,
5731          xns : Roo.grid,
5732          '|xns' : 'Roo.grid',
5733          xtype : 'ColumnModel'
5734         },
5735         {
5736          builderCfg : '{\"table\":\"events\",\"column\":\"remarks\",\"columnshort\":\"remarks\",\"ctype\":\"text\",\"desc\":\"\",\"use\":1,\"use_ex\":1,\"title\":\"\"}',
5737          dataIndex : 'remarks',
5738          header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
5739          renderer : function(v) { return String.format('{0}', v); },
5740          width : 200,
5741          xns : Roo.grid,
5742          '|xns' : 'Roo.grid',
5743          xtype : 'ColumnModel'
5744         }
5745        ]
5746       }
5747      },
5748      {
5749       region : 'center',
5750       title : _this._strings['47cb03899dc494703b52c37240fa4c17'] /* Stock Tx */,
5751       xns : Roo,
5752       '|xns' : 'Roo',
5753       xtype : 'NestedLayoutPanel',
5754       layout : {
5755        xns : Roo,
5756        '|xns' : 'Roo',
5757        xtype : 'BorderLayout',
5758        center : {
5759         xns : Roo,
5760         '|xns' : 'Roo',
5761         xtype : 'LayoutRegion'
5762        },
5763        east : {
5764         split : true,
5765         width : 500,
5766         xns : Roo,
5767         '|xns' : 'Roo',
5768         xtype : 'LayoutRegion'
5769        },
5770        items  : [
5771         {
5772          background : false,
5773          fitContainer : true,
5774          fitToframe : true,
5775          region : 'center',
5776          tableName : 'invdetail',
5777          title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
5778          xns : Roo,
5779          '|xns' : 'Roo',
5780          xtype : 'GridPanel',
5781          listeners : {
5782           activate : function() {
5783                _this.txpanel = this;
5784                if (_this.txgrid) {
5785                    _this.txgrid.footer.onClick('first');
5786                }
5787            }
5788          },
5789          grid : {
5790           autoExpandColumn : 'item_number',
5791           loadMask : true,
5792           xns : Roo.grid,
5793           '|xns' : 'Roo.grid',
5794           xtype : 'Grid',
5795           listeners : {
5796            render : function() 
5797             {
5798                 _this.txgrid = this; 
5799                 //_this.dialog = Pman.Dialog.FILL_IN
5800                 if (_this.txpanel.active) {
5801                    this.footer.onClick('first');
5802                 }
5803             }
5804           },
5805           footer : {
5806            displayInfo : true,
5807            displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
5808            emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
5809            pageSize : 9999,
5810            xns : Roo,
5811            '|xns' : 'Roo',
5812            xtype : 'PagingToolbar'
5813           },
5814           toolbar : {
5815            xns : Roo,
5816            '|xns' : 'Roo',
5817            xtype : 'Toolbar',
5818            items  : [
5819             {
5820              text : _this._strings['b80f4ed22929b09103f0c5666ad7a7e1'] /* Run Apply Fifo on order */,
5821              xns : Roo.Toolbar,
5822              '|xns' : 'Roo.Toolbar',
5823              xtype : 'Button',
5824              listeners : {
5825               click : function (_self, e)
5826                {
5827                    new Pman.Request({
5828                        mask : 'applying',
5829                        url : baseURL + '/Roo/Cohead',
5830                        method : 'GET',
5831                        params : {
5832                            _apply_fifo : _this.form.findField('cohead_id').getValue()
5833                        },
5834                        success : function () {
5835                            Roo.MessageBox.alert("Applied", "Succesfully Applied");
5836                        }
5837                    });
5838                }
5839              }
5840             },
5841             {
5842              text : _this._strings['d179a904ac10a39ab574fe803cc29fa3'] /* Run Void flagger */,
5843              xns : Roo.Toolbar,
5844              '|xns' : 'Roo.Toolbar',
5845              xtype : 'Button',
5846              listeners : {
5847               click : function (_self, e)
5848                {
5849                    new Pman.Request({
5850                        mask : 'running',
5851                        url : baseURL + '/Roo/Cohead',
5852                        method : 'GET',
5853                        params : {
5854                            _run_void_fix : _this.form.findField('cohead_id').getValue()
5855                        },
5856                        success : function () {
5857                            Roo.MessageBox.alert("Applied", "Succesfully Run");
5858                        }
5859                    });
5860                }
5861              }
5862             },
5863             {
5864              text : _this._strings['26453198f2ddac444702879a8f6d61a5'] /* Auto Reverse */,
5865              xns : Roo.Toolbar,
5866              '|xns' : 'Roo.Toolbar',
5867              xtype : 'Button',
5868              listeners : {
5869               click : function (_self, e)
5870                {
5871                    new Pman.Download({
5872                        newWindow : true,
5873                        mask : 'running',
5874                        url : baseURL + '/Roo/Invdetail',
5875                        method : 'GET',
5876                        timeout :90000,
5877                        params : {
5878                            _post : 1,
5879                            _reverse_all_bad : _this.form.findField('cohead_id').getValue()
5880                        },
5881                        success : function () {
5882                            Roo.MessageBox.alert("Applied", "Succesfully Run");
5883                        }
5884                    });
5885                }
5886              }
5887             }
5888            ]
5889           },
5890           dataSource : {
5891            remoteSort : true,
5892            sortInfo : { field : 'item_number', direction: 'ASC' },
5893            xns : Roo.data,
5894            '|xns' : 'Roo.data',
5895            xtype : 'Store',
5896            listeners : {
5897             beforeload : function (_self, o)
5898              {
5899                  o.params.cohead_id = _this.form.findField('cohead_id').getValue();
5900                  if (! o.params.cohead_id ) {
5901                      this.removeAll();
5902                      return false;
5903                  }
5904              }
5905            },
5906            proxy : {
5907             method : 'GET',
5908             url : baseURL + '/Roo/invdetail.php',
5909             xns : Roo.data,
5910             '|xns' : 'Roo.data',
5911             xtype : 'HttpProxy'
5912            },
5913            reader : {
5914             fields : [
5915                 {
5916                     'name': 'invdetail_id',
5917                     'type': 'int'
5918                 },
5919                 {
5920                     'name': 'invdetail_transtype',
5921                     'type': 'string'
5922                 },
5923                 {
5924                     'name': 'invdetail_invhist_id',
5925                     'type': 'int'
5926                 },
5927                 {
5928                     'name': 'invdetail_location_id',
5929                     'type': 'int'
5930                 },
5931                 {
5932                     'name': 'invdetail_qty',
5933                     'type': 'float'
5934                 },
5935                 {
5936                     'name': 'invdetail_comments',
5937                     'type': 'string'
5938                 },
5939                 {
5940                     'name': 'invdetail_qty_before',
5941                     'type': 'float'
5942                 },
5943                 {
5944                     'name': 'invdetail_qty_after',
5945                     'type': 'float'
5946                 },
5947                 {
5948                     'name': 'invdetail_invcitem_id',
5949                     'type': 'int'
5950                 },
5951                 {
5952                     'name': 'invdetail_expiration',
5953                     'type': 'date',
5954                     'dateFormat': 'Y-m-d'
5955                 },
5956                 {
5957                     'name': 'invdetail_warrpurc',
5958                     'type': 'date',
5959                     'dateFormat': 'Y-m-d'
5960                 },
5961                 {
5962                     'name': 'invdetail_ls_id',
5963                     'type': 'int'
5964                 }
5965             ],
5966             id : 'id',
5967             root : 'data',
5968             totalProperty : 'total',
5969             xns : Roo.data,
5970             '|xns' : 'Roo.data',
5971             xtype : 'JsonReader'
5972            }
5973           },
5974           sm : {
5975            singleSelect : true,
5976            xns : Roo.grid,
5977            '|xns' : 'Roo.grid',
5978            xtype : 'RowSelectionModel',
5979            listeners : {
5980             selectionchange : function (_self)
5981              {
5982                  _this.txdgrid.footer.onClick('first');;
5983              }
5984            }
5985           },
5986           colModel : [
5987            {
5988             dataIndex : 'item_number',
5989             header : _this._strings['7d74f3b92b19da5e606d737d339a9679'] /* Item */,
5990             renderer : function(v) { return String.format('{0}', v); },
5991             width : 75,
5992             xns : Roo.grid,
5993             '|xns' : 'Roo.grid',
5994             xtype : 'ColumnModel'
5995            },
5996            {
5997             align : 'right',
5998             dataIndex : 'rec_shipped',
5999             header : _this._strings['53896265ad28c11cb4997b3c3e3e122d'] /* #Ship */,
6000             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
6001             width : 50,
6002             xns : Roo.grid,
6003             '|xns' : 'Roo.grid',
6004             xtype : 'ColumnModel'
6005            },
6006            {
6007             align : 'right',
6008             dataIndex : 'rec_returned',
6009             header : _this._strings['d323a19bad62ff427d0b75dc52674c81'] /* #Ret */,
6010             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
6011             width : 50,
6012             xns : Roo.grid,
6013             '|xns' : 'Roo.grid',
6014             xtype : 'ColumnModel'
6015            },
6016            {
6017             align : 'right',
6018             dataIndex : 'tx_shipped',
6019             header : _this._strings['51e07f52ae2192d23a1b43922e5beb90'] /* #TX ship */,
6020             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
6021             width : 50,
6022             xns : Roo.grid,
6023             '|xns' : 'Roo.grid',
6024             xtype : 'ColumnModel'
6025            },
6026            {
6027             align : 'right',
6028             dataIndex : 'tx_returned',
6029             header : _this._strings['5e33fc1550a56738da96fbaaf57e72f0'] /* #TX ret */,
6030             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,0)); },
6031             width : 50,
6032             xns : Roo.grid,
6033             '|xns' : 'Roo.grid',
6034             xtype : 'ColumnModel'
6035            },
6036            {
6037             align : 'right',
6038             dataIndex : 'tx_total',
6039             header : _this._strings['1abe972d603f3bd61eefc9ac39fb7522'] /* #TX Tot */,
6040             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,0)); },
6041             width : 50,
6042             xns : Roo.grid,
6043             '|xns' : 'Roo.grid',
6044             xtype : 'ColumnModel'
6045            },
6046            {
6047             align : 'right',
6048             dataIndex : 'total_value',
6049             header : _this._strings['689202409e48743b914713f96d93947c'] /* Value */,
6050             renderer : function(v,x,r) { 
6051             
6052                 return (v*1).toFixed(3);
6053             },
6054             width : 50,
6055             xns : Roo.grid,
6056             '|xns' : 'Roo.grid',
6057             xtype : 'ColumnModel'
6058            },
6059            {
6060             align : 'right',
6061             dataIndex : 'tx_total',
6062             header : _this._strings['56d56144d4e4a42ce450446518c4fc00'] /* #Diff */,
6063             renderer : function(v,x,r) { 
6064             
6065                 var cototal = (r.data.rec_returned*1) - (r.data.rec_shipped*1);
6066             //    Roo.log(cototal);
6067                 var diff = (v*1) - cototal;
6068              //   Roo.log(diff);
6069                 if (diff == 0)  {
6070                     return '';
6071                 }
6072                 return String.format('<span style="color:red">{0}</span>',  diff ); 
6073                 },
6074             width : 50,
6075             xns : Roo.grid,
6076             '|xns' : 'Roo.grid',
6077             xtype : 'ColumnModel'
6078            }
6079           ]
6080          }
6081         },
6082         {
6083          background : false,
6084          fitContainer : true,
6085          fitToframe : true,
6086          region : 'east',
6087          tableName : 'invdetail',
6088          title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
6089          xns : Roo,
6090          '|xns' : 'Roo',
6091          xtype : 'GridPanel',
6092          listeners : {
6093           activate : function() {
6094                _this.txdpanel = this;
6095                if (_this.txdgrid) {
6096                    _this.txdgrid.footer.onClick('first');
6097                }
6098            }
6099          },
6100          grid : {
6101           autoExpandColumn : 'invhist_comments',
6102           loadMask : true,
6103           xns : Roo.grid,
6104           '|xns' : 'Roo.grid',
6105           xtype : 'Grid',
6106           listeners : {
6107            render : function() 
6108             {
6109                 _this.txdgrid = this; 
6110                 //_this.dialog = Pman.Dialog.FILL_IN
6111                 if (_this.txdpanel.active) {
6112                    this.footer.onClick('first');
6113                 }
6114             },
6115            rowclick : function (_self, rowIndex, e)
6116             {
6117                 var s = _this.txdgrid.ds.getAt(rowIndex);
6118                 var dt = s.data.invhist_transdate.split(' ');
6119                 
6120                 _this.dateSel.setValue(new Date(dt[0]));
6121             }
6122           },
6123           footer : {
6124            displayInfo : true,
6125            displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
6126            emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
6127            pageSize : 9999,
6128            xns : Roo,
6129            '|xns' : 'Roo',
6130            xtype : 'PagingToolbar'
6131           },
6132           toolbar : {
6133            xns : Roo,
6134            '|xns' : 'Roo',
6135            xtype : 'Toolbar',
6136            items  : [
6137             {
6138              text : _this._strings['fa1cfdb383ea976facbdb20d40d2f811'] /* Duplicate Selected */,
6139              xns : Roo.Toolbar,
6140              '|xns' : 'Roo.Toolbar',
6141              xtype : 'Button',
6142              listeners : {
6143               click : function (_self, e)
6144                {
6145                    var s = _this.txdgrid.selModel.getSelected();
6146                
6147                    if (!s) {
6148                        Roo.MessageBox.alert("Error", "Select a transaction");
6149                        return;
6150                    }
6151                    
6152                    var reverseSel = function() {
6153                    
6154                        new Pman.Request({
6155                            mask : "Reversing",
6156                            url : baseURL + '/Roo/invdetail',
6157                            method : 'POST',
6158                            params : {
6159                                _duplicate : s.data.invdetail_id
6160                            }, 
6161                            success : function() {
6162                                _this.txdgrid.footer.onClick('first');
6163                            }
6164                        });
6165                    
6166                    }
6167                    
6168                    
6169                
6170                    Roo.MessageBox.confirm(
6171                        "Confirm", 
6172                        "This should only be used by System Administrators - are you sure you know what you are doing!",
6173                        function(x) {
6174                            if (x != 'yes') {
6175                                return;
6176                            }
6177                            reverseSel();
6178                        }
6179                    );
6180                                        
6181                    
6182                    
6183                    
6184                }
6185              }
6186             },
6187             {
6188              xns : Roo.Toolbar,
6189              '|xns' : 'Roo.Toolbar',
6190              xtype : 'Fill'
6191             },
6192             {
6193              text : _this._strings['72bb7a9ea8714c52b0c0b8369d6a8dc3'] /* Issue Date */,
6194              xns : Roo.Toolbar,
6195              '|xns' : 'Roo.Toolbar',
6196              xtype : 'TextItem'
6197             },
6198             {
6199              allowBlank : false,
6200              fieldLabel : _this._strings['72bb7a9ea8714c52b0c0b8369d6a8dc3'] /* Issue Date */,
6201              format : 'Y-m-d',
6202              name : 'issue_date',
6203              width : 150,
6204              xns : Roo.form,
6205              '|xns' : 'Roo.form',
6206              xtype : 'DateField',
6207              listeners : {
6208               render : function (_self)
6209                {
6210                    _this.dateSel = _self;
6211                }
6212              }
6213             },
6214             {
6215              text : _this._strings['8156649b9de8783c15c822b592c3bac6'] /* Reverse Selected */,
6216              xns : Roo.Toolbar,
6217              '|xns' : 'Roo.Toolbar',
6218              xtype : 'Button',
6219              listeners : {
6220               click : function (_self, e)
6221                {
6222                    var s = _this.txdgrid.selModel.getSelected();
6223                    var dt = _this.dateSel.getValue();
6224                    if (!s) {
6225                        Roo.MessageBox.alert("Error", "Select a transaction");
6226                        return;
6227                    }
6228                    
6229                    var reverseSel = function(force) {
6230                    
6231                        new Pman.Request({
6232                            mask : "Reversing",
6233                            url : baseURL + '/Roo/invdetail',
6234                            method : 'POST',
6235                            params : {
6236                                _reverse : s.data.invdetail_id,
6237                                _as_of : typeof(dt) == 'string' ? dt : dt.format('Y-m-d'),
6238                                _force : force
6239                            }, 
6240                            success : function() {
6241                                _this.txdgrid.footer.onClick('first');
6242                            },
6243                            failure : function(res) {
6244                                Roo.log(res);
6245                                try {
6246                                    if (res.errors.confirm) {
6247                                                      
6248                                        Roo.MessageBox.confirm(
6249                                            "Confirm", 
6250                                            "are you really sure the totals will get messed up.",
6251                                            function(x) {
6252                                                if (x != 'yes') {
6253                                                    return;
6254                                                }
6255                                                reverseSel(1);
6256                                            }
6257                                        );
6258                                        return;
6259                                    }
6260                                } catch(e) { }
6261                                Roo.MessageBox.alert("Error", res.errorMsg);
6262                                
6263                                
6264                            }
6265                        });
6266                    
6267                    }
6268                    
6269                    
6270                
6271                    Roo.MessageBox.confirm(
6272                        "Confirm", 
6273                        "This should only be used by System Administrators - are you sure you know what you are doing!",
6274                        function(x) {
6275                            if (x != 'yes') {
6276                                return;
6277                            }
6278                            reverseSel(0);
6279                        }
6280                    );
6281                                        
6282                    
6283                    
6284                    
6285                }
6286              }
6287             }
6288            ]
6289           },
6290           dataSource : {
6291            remoteSort : true,
6292            sortInfo : { field : 'invdetail_id', direction: 'ASC' },
6293            xns : Roo.data,
6294            '|xns' : 'Roo.data',
6295            xtype : 'Store',
6296            listeners : {
6297             beforeload : function (_self, o)
6298              {
6299                  o.params.cohead_id = _this.form.findField('cohead_id').getValue();
6300                  var s = _this.txgrid.selModel.getSelected();
6301                  if (!s) { 
6302                      this.removeAll();
6303                      return false;
6304                  }
6305                  o.params.itemsite_id = s.data.invhist_itemsite_id;
6306                  
6307              }
6308            },
6309            proxy : {
6310             method : 'GET',
6311             url : baseURL + '/Roo/invdetail.php',
6312             xns : Roo.data,
6313             '|xns' : 'Roo.data',
6314             xtype : 'HttpProxy'
6315            },
6316            reader : {
6317             fields : [
6318                 {
6319                     'name': 'invdetail_id',
6320                     'type': 'int'
6321                 },
6322                 {
6323                     'name': 'invdetail_transtype',
6324                     'type': 'string'
6325                 },
6326                 {
6327                     'name': 'invdetail_invhist_id',
6328                     'type': 'int'
6329                 },
6330                 {
6331                     'name': 'invdetail_location_id',
6332                     'type': 'int'
6333                 },
6334                 {
6335                     'name': 'invdetail_qty',
6336                     'type': 'float'
6337                 },
6338                 {
6339                     'name': 'invdetail_comments',
6340                     'type': 'string'
6341                 },
6342                 {
6343                     'name': 'invdetail_qty_before',
6344                     'type': 'float'
6345                 },
6346                 {
6347                     'name': 'invdetail_qty_after',
6348                     'type': 'float'
6349                 },
6350                 {
6351                     'name': 'invdetail_invcitem_id',
6352                     'type': 'int'
6353                 },
6354                 {
6355                     'name': 'invdetail_expiration',
6356                     'type': 'date',
6357                     'dateFormat': 'Y-m-d'
6358                 },
6359                 {
6360                     'name': 'invdetail_warrpurc',
6361                     'type': 'date',
6362                     'dateFormat': 'Y-m-d'
6363                 },
6364                 {
6365                     'name': 'invdetail_ls_id',
6366                     'type': 'int'
6367                 }
6368             ],
6369             id : 'id',
6370             root : 'data',
6371             totalProperty : 'total',
6372             xns : Roo.data,
6373             '|xns' : 'Roo.data',
6374             xtype : 'JsonReader'
6375            }
6376           },
6377           colModel : [
6378            {
6379             dataIndex : 'invdetail_id',
6380             header : _this._strings['fd216b286b94577ac68c112c0dcaf341'] /* TX# */,
6381             renderer : function(v) { return String.format('{0}', v); },
6382             width : 60,
6383             xns : Roo.grid,
6384             '|xns' : 'Roo.grid',
6385             xtype : 'ColumnModel'
6386            },
6387            {
6388             dataIndex : 'invhist_transdate',
6389             header : _this._strings['44749712dbec183e983dcd78a7736c41'] /* Date */,
6390             renderer : function(v) { return String.format('{0}', v); },
6391             width : 75,
6392             xns : Roo.grid,
6393             '|xns' : 'Roo.grid',
6394             xtype : 'ColumnModel'
6395            },
6396            {
6397             dataIndex : 'invhist_ordnumber',
6398             header : _this._strings['9c9745a343efeacc9efe9b7222b27afb'] /* Ref# */,
6399             renderer : function(v,x,r) {
6400                 if (r.data.invfifo_void *1 != 0) {
6401                     return String.format('<s>{0}</s>', v); 
6402                 }
6403             
6404                  return String.format('{0}', v); 
6405              },
6406             width : 75,
6407             xns : Roo.grid,
6408             '|xns' : 'Roo.grid',
6409             xtype : 'ColumnModel'
6410            },
6411            {
6412             dataIndex : 'location_name',
6413             header : _this._strings['fd216b286b94577ac68c112c0dcaf341'] /* TX# */,
6414             renderer : function(v) { return String.format('{0}', v); },
6415             width : 60,
6416             xns : Roo.grid,
6417             '|xns' : 'Roo.grid',
6418             xtype : 'ColumnModel'
6419            },
6420            {
6421             dataIndex : 'invhist_comments',
6422             header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
6423             renderer : function(v) { return String.format('{0}', v); },
6424             width : 75,
6425             xns : Roo.grid,
6426             '|xns' : 'Roo.grid',
6427             xtype : 'ColumnModel'
6428            },
6429            {
6430             align : 'right',
6431             dataIndex : 'invdetail_qty',
6432             header : _this._strings['c4a0f4ddf926328daa2a350db9f9ca00'] /* Qty Changed */,
6433             renderer : function(v,x,r) {
6434                 if ( r.data.coitem_shipped != v) {
6435                     return String.format('{0} <span style="color:red">({1})</span>',
6436                          Roo.util.Format.number(v,0),
6437                          r.data.coitem_shipped
6438                      );
6439                 
6440                 }
6441                  return String.format('{0}', Roo.util.Format.number(v,0));
6442             },
6443             width : 50,
6444             xns : Roo.grid,
6445             '|xns' : 'Roo.grid',
6446             xtype : 'ColumnModel'
6447            },
6448            {
6449             align : 'right',
6450             dataIndex : 'invhist_value_before',
6451             header : _this._strings['c4a0f4ddf926328daa2a350db9f9ca00'] /* Qty Changed */,
6452             renderer : function(v,x,r) {
6453                 var tot = r.data.invhist_value_after*1 - v*1;
6454                 var f = '{0}';
6455                 if (r.data.invdetail_qty >0 && tot < 0) {
6456                     f = '<span style="color:red">{0}</span>';
6457                 }
6458                 if (r.data.invdetail_qty < 0 && tot > 0) {
6459                     f = '<span style="color:red">{0}</span>';
6460                 }    
6461                 return String.format(f, Roo.util.Format.number(tot));
6462             },
6463             width : 75,
6464             xns : Roo.grid,
6465             '|xns' : 'Roo.grid',
6466             xtype : 'ColumnModel'
6467            },
6468            {
6469             dataIndex : 'invhist_posted',
6470             header : _this._strings['16cd452dda9d4398bf6240603eee40a9'] /* Posted */,
6471             renderer : function(v,x,r) { 
6472                 
6473                 var state = v   ?  '-checked' : '';
6474                                                 
6475                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
6476              },
6477             width : 40,
6478             xns : Roo.grid,
6479             '|xns' : 'Roo.grid',
6480             xtype : 'ColumnModel'
6481            }
6482           ]
6483          }
6484         }
6485        ]
6486       }
6487      },
6488      {
6489       region : 'center',
6490       title : _this._strings['99575a08540e6ee585a7b389e8bde351'] /* GL Tx */,
6491       xns : Roo,
6492       '|xns' : 'Roo',
6493       xtype : 'NestedLayoutPanel',
6494       layout : {
6495        xns : Roo,
6496        '|xns' : 'Roo',
6497        xtype : 'BorderLayout',
6498        center : {
6499         xns : Roo,
6500         '|xns' : 'Roo',
6501         xtype : 'LayoutRegion'
6502        },
6503        east : {
6504         split : true,
6505         width : 500,
6506         xns : Roo,
6507         '|xns' : 'Roo',
6508         xtype : 'LayoutRegion'
6509        },
6510        items  : [
6511         {
6512          background : false,
6513          fitContainer : true,
6514          fitToframe : true,
6515          region : 'center',
6516          tableName : 'invdetail',
6517          title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
6518          xns : Roo,
6519          '|xns' : 'Roo',
6520          xtype : 'GridPanel',
6521          listeners : {
6522           activate : function() {
6523                _this.gltxpanel = this;
6524                if (_this.gltxgrid) {
6525                    _this.gltxgrid.footer.onClick('first');
6526                }
6527            }
6528          },
6529          grid : {
6530           autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
6531           loadMask : true,
6532           xns : Roo.grid,
6533           '|xns' : 'Roo.grid',
6534           xtype : 'Grid',
6535           listeners : {
6536            cellclick : function (_self, rowIndex, columnIndex, e)
6537             {
6538                 if (columnIndex > 0) {
6539                     return;
6540                 }
6541                 var rec = this.ds.getAt(rowIndex);
6542                 rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
6543                 _this.gltxdgrid.footer.onClick('first');
6544             },
6545            render : function() 
6546             {
6547                 _this.gltxgrid = this; 
6548                 //_this.dialog = Pman.Dialog.FILL_IN
6549                 if (_this.gltxpanel.active) {
6550                    this.footer.onClick('first');
6551                 }
6552             }
6553           },
6554           footer : {
6555            displayInfo : true,
6556            displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
6557            emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
6558            pageSize : 9999,
6559            xns : Roo,
6560            '|xns' : 'Roo',
6561            xtype : 'PagingToolbar',
6562            items  : [
6563             {
6564              enableToggle : true,
6565              pressed : true,
6566              text : _this._strings['8fb8fbc1c0bc53b2d01121344410e444'] /* Split sales */,
6567              xns : Roo.Toolbar,
6568              '|xns' : 'Roo.Toolbar',
6569              xtype : 'Button',
6570              listeners : {
6571               click : function (_self, e)
6572                {
6573                    (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
6574                },
6575               render : function (_self)
6576                {
6577                    _this.glsalesbtn = _self;
6578                }
6579              }
6580             }
6581            ]
6582           },
6583           dataSource : {
6584            remoteSort : true,
6585            sortInfo : { field : 'item_number', direction: 'ASC' },
6586            xns : Roo.data,
6587            '|xns' : 'Roo.data',
6588            xtype : 'Store',
6589            listeners : {
6590             beforeload : function (_self, o)
6591              {
6592                  o.params.cohead_id = _this.form.findField('cohead_id').getValue();
6593                  if (! o.params.cohead_id ) {
6594                      this.removeAll();
6595                      return false;
6596                  }
6597                  o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
6598              }
6599            },
6600            proxy : {
6601             method : 'GET',
6602             url : baseURL + '/Roo/gltrans.php',
6603             xns : Roo.data,
6604             '|xns' : 'Roo.data',
6605             xtype : 'HttpProxy'
6606            },
6607            reader : {
6608             fields : [
6609                 {
6610                     'name': 'invdetail_id',
6611                     'type': 'int'
6612                 },
6613                 {
6614                     'name': 'invdetail_transtype',
6615                     'type': 'string'
6616                 },
6617                 {
6618                     'name': 'invdetail_invhist_id',
6619                     'type': 'int'
6620                 },
6621                 {
6622                     'name': 'invdetail_location_id',
6623                     'type': 'int'
6624                 },
6625                 {
6626                     'name': 'invdetail_qty',
6627                     'type': 'float'
6628                 },
6629                 {
6630                     'name': 'invdetail_comments',
6631                     'type': 'string'
6632                 },
6633                 {
6634                     'name': 'invdetail_qty_before',
6635                     'type': 'float'
6636                 },
6637                 {
6638                     'name': 'invdetail_qty_after',
6639                     'type': 'float'
6640                 },
6641                 {
6642                     'name': 'invdetail_invcitem_id',
6643                     'type': 'int'
6644                 },
6645                 {
6646                     'name': 'invdetail_expiration',
6647                     'type': 'date',
6648                     'dateFormat': 'Y-m-d'
6649                 },
6650                 {
6651                     'name': 'invdetail_warrpurc',
6652                     'type': 'date',
6653                     'dateFormat': 'Y-m-d'
6654                 },
6655                 {
6656                     'name': 'invdetail_ls_id',
6657                     'type': 'int'
6658                 }
6659             ],
6660             id : 'id',
6661             root : 'data',
6662             totalProperty : 'total',
6663             xns : Roo.data,
6664             '|xns' : 'Roo.data',
6665             xtype : 'JsonReader'
6666            }
6667           },
6668           sm : {
6669            singleSelect : true,
6670            xns : Roo.grid,
6671            '|xns' : 'Roo.grid',
6672            xtype : 'RowSelectionModel',
6673            listeners : {
6674             selectionchange : function (_self)
6675              {
6676                  _this.gltxdgrid.footer.onClick('first');;
6677              }
6678            }
6679           },
6680           colModel : [
6681            {
6682             dataIndex : 'gltrans_as_summary',
6683             header : _this._strings['290612199861c31d1036b185b4e69b75'] /* Summary */,
6684             renderer : function(v,x,r) { 
6685                 
6686                 var state = v*1   ?  '-checked' : '';
6687                                                 
6688                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
6689              },
6690             width : 50,
6691             xns : Roo.grid,
6692             '|xns' : 'Roo.grid',
6693             xtype : 'ColumnModel'
6694            },
6695            {
6696             dataIndex : 'gltrans_accnt_id_accnt_descrip',
6697             header : _this._strings['08bd40c7543007ad06e4fce31618f6ec'] /* Account */,
6698             renderer : function(v) { return String.format('{0}', v); },
6699             width : 75,
6700             xns : Roo.grid,
6701             '|xns' : 'Roo.grid',
6702             xtype : 'ColumnModel'
6703            },
6704            {
6705             align : 'right',
6706             dataIndex : 'gltrans_amount_credit',
6707             header : _this._strings['0a90b1bc4078f74b6f0d117ec7df65af'] /* Credit */,
6708             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); },
6709             width : 75,
6710             xns : Roo.grid,
6711             '|xns' : 'Roo.grid',
6712             xtype : 'ColumnModel'
6713            },
6714            {
6715             align : 'right',
6716             dataIndex : 'gltrans_amount_debit',
6717             header : _this._strings['009534719f8c8221440a5629f497a784'] /* Debit */,
6718             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
6719             width : 75,
6720             xns : Roo.grid,
6721             '|xns' : 'Roo.grid',
6722             xtype : 'ColumnModel'
6723            },
6724            {
6725             align : 'right',
6726             dataIndex : 'gltrans_amount_total',
6727             header : _this._strings['a0ec87054b5e5b7847d0d8780a01a3d5'] /* Sum */,
6728             renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); },
6729             width : 75,
6730             xns : Roo.grid,
6731             '|xns' : 'Roo.grid',
6732             xtype : 'ColumnModel'
6733            },
6734            {
6735             align : 'right',
6736             dataIndex : 'gltrans_amount_total_unposted',
6737             header : _this._strings['58733ee735e3160c5c9fa5739fb4d056'] /* Unposted */,
6738             renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); },
6739             width : 75,
6740             xns : Roo.grid,
6741             '|xns' : 'Roo.grid',
6742             xtype : 'ColumnModel'
6743            }
6744           ]
6745          }
6746         },
6747         {
6748          background : false,
6749          fitContainer : true,
6750          fitToframe : true,
6751          region : 'east',
6752          tableName : 'invdetail',
6753          title : _this._strings['f817f797c422f7ac3404b6223db1a1ee'] /* invdetail */,
6754          xns : Roo,
6755          '|xns' : 'Roo',
6756          xtype : 'GridPanel',
6757          listeners : {
6758           activate : function() {
6759                _this.gltxdpanel = this;
6760                if (_this.gltxdgrid) {
6761                    _this.gltxdgrid.footer.onClick('first');
6762                }
6763            }
6764          },
6765          grid : {
6766           autoExpandColumn : 'gltrans_notes',
6767           loadMask : true,
6768           xns : Roo.grid,
6769           '|xns' : 'Roo.grid',
6770           xtype : 'Grid',
6771           listeners : {
6772            cellclick : function (_self, ri, ci, e)
6773             {
6774                 
6775                   var deleteSel = function() {
6776                 
6777                     new Pman.Request({
6778                         mask : "Reversing",
6779                         url : baseURL + '/Roo/gltrans',
6780                         method : 'POST',
6781                         params : {  
6782                             _void : 1,
6783                             gltrans_id : rec.data.gltrans_id
6784                             
6785                         }, 
6786                         success : function() {
6787                             rec.set('gltrans_posted', false);
6788                             rec.set('gltrans_deleted', true);
6789                             rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
6790                            _this.gltxgrid.footer.onClick('first');
6791                         }
6792                     });
6793                 
6794                 }
6795                 var undeleteSel = function() {
6796                 
6797                     new Pman.Request({
6798                         mask : "Reversing",
6799                         url : baseURL + '/Roo/gltrans',
6800                         method : 'POST',
6801                         params : {  
6802                             _unvoid : 1,
6803                             gltrans_id : rec.data.gltrans_id
6804                             
6805                         }, 
6806                         success : function() {
6807                             rec.set('gltrans_posted', true);
6808                             rec.set('gltrans_deleted', false);
6809                             rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
6810                            _this.gltxgrid.footer.onClick('first');
6811                         }
6812                     });
6813                 
6814                 }
6815                 
6816                 var di = this.colModel.config[ci].dataIndex;
6817                 if (di != 'gltrans_posted') {
6818                     return;
6819                 }
6820                 
6821                 
6822                 
6823                 var rec = this.ds.getAt(ri);
6824                 if (rec.data.gltrans_deleted) {
6825                 
6826                      Roo.MessageBox.confirm(
6827                         "Confirm", 
6828                         "This should only be used by System Administrators - are you sure you know what you are doing!",
6829                         function(x) {
6830                             if (x != 'yes') {
6831                                 return;
6832                             }
6833                             undeleteSel();
6834                         }
6835                     );
6836                 
6837                     return false;
6838                 }
6839             
6840                 
6841                 
6842                 if (!rec.data.gltrans_posted) {
6843             
6844                     
6845                     
6846                     new Pman.Request({
6847                         method : 'POST',
6848                         url : baseURL + '/Roo/gltrans',
6849                         mask : "Posting",
6850                         params : {
6851                             _post : 1,
6852                             gltrans_id : rec.data.gltrans_id
6853                         },
6854                         success : function (res)
6855                         {
6856                             rec.set('gltrans_posted', true);
6857                             _this.gltxgrid.footer.onClick('first');
6858                         
6859                         }
6860                     
6861                     
6862                     });
6863                     return;
6864                 }
6865                 
6866                 // we have a posted transaction.
6867                 // only allow recalled to be deleted..
6868                 if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
6869                     return false;
6870                 }
6871                 
6872                 
6873              
6874                 
6875                 
6876             
6877                 Roo.MessageBox.confirm(
6878                     "Confirm", 
6879                     "This should only be used by System Administrators - are you sure you know what you are doing!",
6880                     function(x) {
6881                         if (x != 'yes') {
6882                             return;
6883                         }
6884                         deleteSel();
6885                     }
6886                 );
6887                       
6888                 
6889                 
6890             },
6891            render : function() 
6892             {
6893                 _this.gltxdgrid = this; 
6894                 //_this.dialog = Pman.Dialog.FILL_IN
6895                 if (_this.gltxdpanel.active) {
6896                    this.footer.onClick('first');
6897                 }
6898             }
6899           },
6900           footer : {
6901            displayInfo : true,
6902            displayMsg : _this._strings['87813307f6e7498b30c5b3d9b2f65f56'] /* Displaying invdetail{0} - {1} of {2} */,
6903            emptyMsg : _this._strings['a0d036a1d6a00180df168fa86143e5f8'] /* No invdetail found */,
6904            pageSize : 9999,
6905            xns : Roo,
6906            '|xns' : 'Roo',
6907            xtype : 'PagingToolbar',
6908            items  : [
6909             {
6910              text : _this._strings['801ab24683a4a8c433c6eb40c48bcd9d'] /* Download */,
6911              xns : Roo.Toolbar,
6912              '|xns' : 'Roo.Toolbar',
6913              xtype : 'Button',
6914              listeners : {
6915               click : function (_self, e)
6916                {
6917                    new Pman.Download( {
6918                        grid : _this.gltxdgrid
6919                    
6920                    });
6921                }
6922              }
6923             }
6924            ]
6925           },
6926           dataSource : {
6927            remoteSort : true,
6928            sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
6929            xns : Roo.data,
6930            '|xns' : 'Roo.data',
6931            xtype : 'Store',
6932            listeners : {
6933             beforeload : function (_self, o)
6934              {
6935                  o.params.cohead_id = _this.form.findField('cohead_id').getValue();
6936                  var s = _this.gltxgrid.selModel.getSelected();
6937                  if (!s) { 
6938                      this.removeAll();
6939                      return false;
6940                  }
6941                  o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
6942                  o.params.gltrans_is_ship = s.data.gltrans_is_ship;
6943                  o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
6944                  
6945                  
6946              }
6947            },
6948            proxy : {
6949             method : 'GET',
6950             url : baseURL + '/Roo/gltrans.php',
6951             xns : Roo.data,
6952             '|xns' : 'Roo.data',
6953             xtype : 'HttpProxy'
6954            },
6955            reader : {
6956             fields : [
6957                 {
6958                     'name': 'invdetail_id',
6959                     'type': 'int'
6960                 },
6961                 {
6962                     'name': 'invdetail_transtype',
6963                     'type': 'string'
6964                 },
6965                 {
6966                     'name': 'invdetail_invhist_id',
6967                     'type': 'int'
6968                 },
6969                 {
6970                     'name': 'invdetail_location_id',
6971                     'type': 'int'
6972                 },
6973                 {
6974                     'name': 'invdetail_qty',
6975                     'type': 'float'
6976                 },
6977                 {
6978                     'name': 'invdetail_comments',
6979                     'type': 'string'
6980                 },
6981                 {
6982                     'name': 'invdetail_qty_before',
6983                     'type': 'float'
6984                 },
6985                 {
6986                     'name': 'invdetail_qty_after',
6987                     'type': 'float'
6988                 },
6989                 {
6990                     'name': 'invdetail_invcitem_id',
6991                     'type': 'int'
6992                 },
6993                 {
6994                     'name': 'invdetail_expiration',
6995                     'type': 'date',
6996                     'dateFormat': 'Y-m-d'
6997                 },
6998                 {
6999                     'name': 'invdetail_warrpurc',
7000                     'type': 'date',
7001                     'dateFormat': 'Y-m-d'
7002                 },
7003                 {
7004                     'name': 'invdetail_ls_id',
7005                     'type': 'int'
7006                 }
7007             ],
7008             id : 'id',
7009             root : 'data',
7010             totalProperty : 'total',
7011             xns : Roo.data,
7012             '|xns' : 'Roo.data',
7013             xtype : 'JsonReader'
7014            }
7015           },
7016           colModel : [
7017            {
7018             dataIndex : 'gltrans_id',
7019             header : _this._strings['9c9745a343efeacc9efe9b7222b27afb'] /* Ref# */,
7020             renderer : function(v) { return String.format('{0}', v ); },
7021             sortable : true,
7022             width : 75,
7023             xns : Roo.grid,
7024             '|xns' : 'Roo.grid',
7025             xtype : 'ColumnModel'
7026            },
7027            {
7028             dataIndex : 'gltrans_date',
7029             header : _this._strings['44749712dbec183e983dcd78a7736c41'] /* Date */,
7030             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
7031             width : 75,
7032             xns : Roo.grid,
7033             '|xns' : 'Roo.grid',
7034             xtype : 'ColumnModel'
7035            },
7036            {
7037             dataIndex : 'gltrans_docnumber',
7038             header : _this._strings['cb02c723b8a159fea3cd7913d3df7fbc'] /* Doc# */,
7039             renderer : function(v,x,r) { 
7040                 if (r.data.gltrans_deleted) {
7041                    return String.format('<s>{0}</s>', v);     
7042                 }
7043                 return String.format('{0}', v); 
7044             },
7045             width : 75,
7046             xns : Roo.grid,
7047             '|xns' : 'Roo.grid',
7048             xtype : 'ColumnModel'
7049            },
7050            {
7051             dataIndex : 'gltrans_source',
7052             header : _this._strings['f31bbdd1b3e85bccd652680e16935819'] /* Source */,
7053             renderer : function(v) { return String.format('{0}', v); },
7054             width : 50,
7055             xns : Roo.grid,
7056             '|xns' : 'Roo.grid',
7057             xtype : 'ColumnModel'
7058            },
7059            {
7060             dataIndex : 'gltrans_notes',
7061             header : _this._strings['f4c6f851b00d5518bf888815de279aba'] /* Notes */,
7062             renderer : function(v) { return String.format('{0}', v); },
7063             width : 75,
7064             xns : Roo.grid,
7065             '|xns' : 'Roo.grid',
7066             xtype : 'ColumnModel'
7067            },
7068            {
7069             align : 'right',
7070             dataIndex : 'gltrans_amount',
7071             header : _this._strings['b2f40690858b404ed10e62bdf422c704'] /* Amount */,
7072             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); },
7073             width : 75,
7074             xns : Roo.grid,
7075             '|xns' : 'Roo.grid',
7076             xtype : 'ColumnModel'
7077            },
7078            {
7079             dataIndex : 'gltrans_posted',
7080             header : _this._strings['16cd452dda9d4398bf6240603eee40a9'] /* Posted */,
7081             renderer : function(v,x,r) { 
7082                 
7083                 var state = v   ?  '-checked' : '';
7084                                                 
7085                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
7086              },
7087             width : 50,
7088             xns : Roo.grid,
7089             '|xns' : 'Roo.grid',
7090             xtype : 'ColumnModel'
7091            }
7092           ]
7093          }
7094         }
7095        ]
7096       }
7097      },
7098      {
7099       background : true,
7100       fitContainer : true,
7101       fitToframe : true,
7102       region : 'center',
7103       tableName : 'coitem',
7104       title : _this._strings['182875b6c36a761f1e459624c1d93638'] /* Profit */,
7105       xns : Roo,
7106       '|xns' : 'Roo',
7107       xtype : 'GridPanel',
7108       listeners : {
7109        activate : function() {
7110             _this.profitpanel = this;
7111             
7112             try { if (MODULE.isBuilder) {
7113                 return;
7114             } } catch(e) { }
7115             
7116             var id = _this.form.findField('cohead_id').getValue() * 1;
7117             if (id < 1) {
7118                 Roo.MessageBox.alert("Save First", "Save the order first, before adding items");
7119                 _this.dialog.layout.getRegion('center').showPanel(0);
7120                 return;
7121             }
7122             
7123             if (_this.profitgrid) {
7124                 _this.profitgrid.footer.onClick('first');
7125              }
7126             
7127         }
7128       },
7129       grid : {
7130        autoExpandColumn : 'item_number',
7131        loadMask : true,
7132        xns : Roo.grid,
7133        '|xns' : 'Roo.grid',
7134        xtype : 'Grid',
7135        listeners : {
7136         render : function() 
7137          {
7138              _this.profitgrid = this; 
7139              //_this.dialog = Pman.Dialog.FILL_IN
7140              if (_this.profitpanel.active) {
7141                 this.footer.onClick('first');
7142              }
7143          }
7144        },
7145        footer : {
7146         displayInfo : true,
7147         displayMsg : _this._strings['d0cc96be641673ad48fc74374fda8137'] /* Displaying coitem{0} - {1} of {2} */,
7148         emptyMsg : _this._strings['c04b33241cc5478500daf178e3720b63'] /* No coitem found */,
7149         pageSize : 25,
7150         xns : Roo,
7151         '|xns' : 'Roo',
7152         xtype : 'PagingToolbar'
7153        },
7154        dataSource : {
7155         remoteSort : true,
7156         sortInfo : { field : 'coitem_linenumber,coitem_subnumber', direction: 'ASC' },
7157         xns : Roo.data,
7158         '|xns' : 'Roo.data',
7159         xtype : 'Store',
7160         listeners : {
7161          beforeload : function (_self,o) {
7162           
7163               try {
7164                  this.removeAll();
7165              } catch (e) { }
7166              
7167           
7168               if (!_this.data || !_this.data.cohead_id) {
7169                   return false;
7170               }
7171               o.params = o.params || {};
7172               
7173               o.params.coitem_cohead_id = _this.data.cohead_id;
7174               o.params._without_list_discount =1;
7175               o.params._with_profit = 1;
7176               
7177           }
7178         },
7179         proxy : {
7180          method : 'GET',
7181          url : baseURL + '/Roo/coitem.php',
7182          xns : Roo.data,
7183          '|xns' : 'Roo.data',
7184          xtype : 'HttpProxy'
7185         },
7186         reader : {
7187          fields : [
7188              {
7189                  'name': 'id',
7190                  'type': 'int'
7191              },
7192              {
7193                  'name': 'name',
7194                  'type': 'string'
7195              },
7196              {
7197                  'name': 'type',
7198                  'type': 'int'
7199              },
7200              {
7201                  'name': 'leader',
7202                  'type': 'int'
7203              },
7204              {
7205                  'name': 'leader_id',
7206                  'type': 'int'
7207              },
7208              {
7209                  'name': 'leader_office_id',
7210                  'type': 'int'
7211              },
7212              {
7213                  'name': 'leader_name',
7214                  'type': 'string'
7215              },
7216              {
7217                  'name': 'leader_phone',
7218                  'type': 'string'
7219              },
7220              {
7221                  'name': 'leader_fax',
7222                  'type': 'string'
7223              },
7224              {
7225                  'name': 'leader_email',
7226                  'type': 'string'
7227              },
7228              {
7229                  'name': 'leader_company_id',
7230                  'type': 'int'
7231              },
7232              {
7233                  'name': 'leader_role',
7234                  'type': 'string'
7235              },
7236              {
7237                  'name': 'leader_active',
7238                  'type': 'int'
7239              },
7240              {
7241                  'name': 'leader_remarks',
7242                  'type': 'string'
7243              },
7244              {
7245                  'name': 'leader_passwd',
7246                  'type': 'string'
7247              },
7248              {
7249                  'name': 'leader_owner_id',
7250                  'type': 'int'
7251              },
7252              {
7253                  'name': 'leader_lang',
7254                  'type': 'string'
7255              },
7256              {
7257                  'name': 'leader_no_reset_sent',
7258                  'type': 'int'
7259              },
7260              {
7261                  'name': 'leader_action_type',
7262                  'type': 'string'
7263              },
7264              {
7265                  'name': 'leader_project_id',
7266                  'type': 'int'
7267              },
7268              {
7269                  'name': 'leader_deleted_by',
7270                  'type': 'int'
7271              },
7272              {
7273                  'name': 'leader_deleted_dt',
7274                  'type': 'date'
7275              },
7276              {
7277                  'name': 'leader_firstname',
7278                  'type': 'string'
7279              },
7280              {
7281                  'name': 'leader_lastname',
7282                  'type': 'string'
7283              },
7284              {
7285                  'name': 'leader_name_facebook',
7286                  'type': 'string'
7287              },
7288              {
7289                  'name': 'leader_url_blog',
7290                  'type': 'string'
7291              },
7292              {
7293                  'name': 'leader_url_twitter',
7294                  'type': 'string'
7295              },
7296              {
7297                  'name': 'leader_url_linkedin',
7298                  'type': 'string'
7299              },
7300              {
7301                  'name': 'leader_crm_lead_percentage',
7302                  'type': 'int'
7303              },
7304              {
7305                  'name': 'leader_crm_industry_id',
7306                  'type': 'int'
7307              },
7308              {
7309                  'name': 'leader_crm_updated_action_id',
7310                  'type': 'int'
7311              },
7312              {
7313                  'name': 'leader_crm_created_action_id',
7314                  'type': 'int'
7315              },
7316              {
7317                  'name': 'leader_crm_type_id',
7318                  'type': 'int'
7319              }
7320          ],
7321          id : 'id',
7322          root : 'data',
7323          totalProperty : 'total',
7324          xns : Roo.data,
7325          '|xns' : 'Roo.data',
7326          xtype : 'JsonReader'
7327         }
7328        },
7329        colModel : [
7330         {
7331          dataIndex : 'item_number',
7332          header : _this._strings['7608203603437f0513ba8203a2d39a4f'] /* Item Code */,
7333          renderer : function(v) { return String.format('{0}', v); },
7334          width : 75,
7335          xns : Roo.grid,
7336          '|xns' : 'Roo.grid',
7337          xtype : 'ColumnModel'
7338         },
7339         {
7340          dataIndex : 'calc_subtotal',
7341          header : _this._strings['c5eae6ea505388a73962c635ac821fba'] /* SubTotal */,
7342          renderer : function(v) {
7343          
7344          
7345               return Roo.util.Format.number( v, 2);
7346            },
7347          width : 200,
7348          xns : Roo.grid,
7349          '|xns' : 'Roo.grid',
7350          xtype : 'ColumnModel'
7351         },
7352         {
7353          dataIndex : 'calc_cost_total',
7354          header : _this._strings['81dffdb31b9576e343d3f7ffcf721d7e'] /* Cost of goods */,
7355          renderer : function(v) {
7356          
7357              return Roo.util.Format.number( v, 2);
7358            },
7359          width : 200,
7360          xns : Roo.grid,
7361          '|xns' : 'Roo.grid',
7362          xtype : 'ColumnModel'
7363         },
7364         {
7365          dataIndex : 'profit',
7366          header : _this._strings['182875b6c36a761f1e459624c1d93638'] /* Profit */,
7367          renderer : function(v,x,r) {
7368                  
7369             var profit = r.data.calc_subtotal - r.data.calc_cost_total;
7370             
7371             if(parseInt(profit) < 1){
7372                 return String.format('<b style="color:red;">{0}</b>', Roo.util.Format.number(profit,2));      
7373             }
7374                  
7375                  
7376              return Roo.util.Format.number( profit, 2);
7377          },
7378          width : 200,
7379          xns : Roo.grid,
7380          '|xns' : 'Roo.grid',
7381          xtype : 'ColumnModel'
7382         }
7383        ]
7384       }
7385      }
7386     ]
7387    });
7388  }
7389 };