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