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